mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
Agents: share embedded run runtime state
This commit is contained in:
@@ -11,12 +11,27 @@ type EmbeddedPiQueueHandle = {
|
||||
abort: () => void;
|
||||
};
|
||||
|
||||
const ACTIVE_EMBEDDED_RUNS = new Map<string, EmbeddedPiQueueHandle>();
|
||||
type EmbeddedRunWaiter = {
|
||||
resolve: (ended: boolean) => void;
|
||||
timer: NodeJS.Timeout;
|
||||
};
|
||||
const EMBEDDED_RUN_WAITERS = new Map<string, Set<EmbeddedRunWaiter>>();
|
||||
|
||||
/**
|
||||
* Use global singleton state so busy/streaming checks stay consistent even
|
||||
* when the bundler emits multiple copies of this module into separate chunks.
|
||||
*/
|
||||
const _g = globalThis as typeof globalThis & {
|
||||
__openclaw_embedded_run_state__?: {
|
||||
activeRuns: Map<string, EmbeddedPiQueueHandle>;
|
||||
waiters: Map<string, Set<EmbeddedRunWaiter>>;
|
||||
};
|
||||
};
|
||||
const embeddedRunState = (_g.__openclaw_embedded_run_state__ ??= {
|
||||
activeRuns: new Map<string, EmbeddedPiQueueHandle>(),
|
||||
waiters: new Map<string, Set<EmbeddedRunWaiter>>(),
|
||||
});
|
||||
const ACTIVE_EMBEDDED_RUNS = embeddedRunState.activeRuns;
|
||||
const EMBEDDED_RUN_WAITERS = embeddedRunState.waiters;
|
||||
|
||||
export function queueEmbeddedPiMessage(sessionId: string, text: string): boolean {
|
||||
const handle = ACTIVE_EMBEDDED_RUNS.get(sessionId);
|
||||
|
||||
Reference in New Issue
Block a user