UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

40 lines (39 loc) • 1.11 kB
import { t as isPromiseLike } from "./promise-like-aMoWEh5w.mjs"; //#region src/agents/embedded-agent-subscribe.callback.ts /** Shares callback ordering across every model call and subscription in one run. */ function serializeAgentEventCallback(e) { if (!e) return; let t; return (n) => { const r = t ? t.then(() => e(n)) : e(n); if (!isPromiseLike(r)) return; const i = Promise.resolve(r); const a = i.then(() => {}, () => {}); t = a; a.then(() => { if (t === a) t = void 0; }); return i; }; } /** Contains callback failures and tracks completion for delivery owners that join it. */ function runBestEffortCallback(e) { const failed = (t) => { e.onError?.(t); e.log.warn(`${e.label} callback failed: ${String(t)}`); }; try { const t = e.callback(); if (isPromiseLike(t)) { const n = Promise.resolve(t).then(() => e.onSuccess?.(), failed); if (e.pending) { e.pending.add(n); n.finally(() => e.pending?.delete(n)); } } else e.onSuccess?.(); } catch (e) { failed(e); } } //#endregion export { serializeAgentEventCallback as n, runBestEffortCallback as t };