UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

68 lines (67 loc) • 2.09 kB
import { l as getAgentRunContext } from "./agent-run-registry-D7vkrqFT.mjs"; import { d as getAgentEventLifecycleGeneration } from "./agent-events-BdfWYmot.mjs"; import { a as getRpcSourceIdentity, h as isRpcSourceQueued, r as getRpcSourceForGateway } from "./session-controller.rpc-sources-CTFbRW2t.mjs"; import { a as waitForAgentJob, n as getAgentJobSession, r as projectAgentJobObservation, t as captureAgentJobSession } from "./agent-job-mP_hfXWa.mjs"; import { c as resolveAgentWaitSource } from "./agent-dedupe-DvejJfx2.mjs"; //#region src/gateway/agent-turn/agent-wait.ts /** Capture an agent wait's initial session and defer its terminal or queued result. */ function prepareAgentWaitForTurn(e, t, n = {}) { const r = n.exactTurnSource ? t.runId : t.runId.trim(); const i = t.timeoutMs ?? 3e4; const a = resolveAgentWaitSource(e, r); const o = getAgentEventLifecycleGeneration(); const queuedResult = () => { const t = getRpcSourceForGateway(r, e.resolveGatewayContext); return t && t.input.custody.enqueued === true && isRpcSourceQueued(t) ? { session: captureAgentJobSession({ ...getRpcSourceIdentity(t), lifecycleGeneration: o }), result: { runId: r, status: "pending", timeoutPhase: "queue", providerStarted: false } } : void 0; }; const s = queuedResult(); const c = getAgentRunContext(r); const l = s?.session ?? getAgentJobSession(r, a === "chat" ? "chat" : void 0) ?? captureAgentJobSession(c); const wait = async () => { if (s) return s; let e; const t = await waitForAgentJob({ runId: r, timeoutMs: i, source: a, stopWaiting: () => { e = queuedResult(); return e !== void 0; } }); const n = e ?? queuedResult(); if (n) return n; if (!t) return { result: { runId: r, status: "timeout" }, session: captureAgentJobSession(c) ?? l }; const { session: o, ...u } = projectAgentJobObservation(t); return { session: o, result: { runId: r, ...u } }; }; return { session: l, wait }; } //#endregion export { prepareAgentWaitForTurn as t };