UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

105 lines (104 loc) • 3.08 kB
import { l as resolveAgentIdFromSessionKey, y as isAcpSessionKey } from "./session-key-CqAyZeVk.mjs"; import { d as resolveAcpSessionTarget } from "./manager.utils-CiSXdCbv.mjs"; import { n as readAcpSessionEntryAsync } from "./session-meta-read-BC53uDBL.mjs"; import "./session-meta-CupK_5Fp.mjs"; import { a as resolveConfiguredAcpBindingSpecFromRecord } from "./persistent-bindings.types-CertbPM0.mjs"; import { n as resolveConfiguredAcpBindingSpecBySessionKey } from "./persistent-bindings.resolve-BGQ5AMbv.mjs"; import { n as ensureConfiguredAcpBindingSession } from "./persistent-bindings.lifecycle-DllFKy9p.mjs"; import { n as performGatewaySessionReset } from "./session-reset-service-DH7-Rpxw.mjs"; //#region src/channels/plugins/acp-stateful-target-driver.ts async function resolveAcpBindingTargetBySessionKey(e) { const t = e.sessionKey.trim(); if (!t) return null; const n = resolveAcpSessionTarget({ ...e, sessionKey: t }); if ((await readAcpSessionEntryAsync({ cfg: e.cfg, ...n }))?.acp) return { kind: "stateful", driverId: "acp", ...n }; const r = resolveConfiguredAcpBindingSpecBySessionKey({ ...e, sessionKey: t }); if (!r) { if (!isAcpSessionKey(t)) return null; return { kind: "stateful", driverId: "acp", sessionKey: t, agentId: resolveAgentIdFromSessionKey(t) }; } return { kind: "stateful", driverId: "acp", sessionKey: t, agentId: r.agentId, ...r.label ? { label: r.label } : {} }; } async function ensureConfiguredAcpBindingTargetReady(e) { const t = resolveConfiguredAcpBindingSpecFromRecord(e.bindingResolution.record); if (!t) return { ok: false, error: "Configured ACP binding unavailable" }; const n = await ensureConfiguredAcpBindingSession({ ...e.assertActive ? { assertActive: e.assertActive } : {}, cfg: e.cfg, spec: t }); return n.ok ? { ok: true } : { ok: false, error: n.error }; } async function resetConfiguredAcpBindingTargetInPlace(e) { const t = await readAcpSessionEntryAsync({ cfg: e.cfg, sessionKey: e.sessionKey, agentId: e.bindingTarget.agentId }); if (t?.storeReadFailed) return { ok: false, error: "Session metadata is unavailable; retry after storage is ready." }; if (t?.entry?.incognito === true) return { ok: false, error: "Incognito sessions cannot reset in place." }; const n = await performGatewaySessionReset({ key: e.sessionKey, agentId: e.bindingTarget.agentId, operatorRoleActor: { kind: "system" }, reason: e.reason, commandSource: e.commandSource ?? "stateful-target:acp-reset-in-place", armSessionDiffBaselineCapture: true }); if (n.ok) { if ("incognitoDeleted" in n) return { ok: true, sessionKey: n.key, storePath: n.storePath }; return { ok: true, sessionKey: n.key, sessionId: n.entry.sessionId, lifecycleRevision: n.entry.lifecycleRevision, storePath: n.storePath }; } return { ok: false, error: n.error.message }; } //#endregion export { ensureConfiguredAcpBindingTargetReady, resetConfiguredAcpBindingTargetInPlace, resolveAcpBindingTargetBySessionKey };