openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
27 lines (26 loc) • 1.63 kB
JavaScript
import { t as formatErrorMessage } from "./errors-BSdPMFao.mjs";
import { r as logVerbose } from "./globals-D2Pr1KIl.mjs";
import { n as getAcpSessionManager } from "./manager-B5S0BBNN.mjs";
import { c as readAcpSessionEntryAsync } from "./session-meta-BsPMgDdM.mjs";
import { i as listSessionBindingsBySessionAsync, t as getSessionBindingService } from "./session-binding-service-BxjdmbUW.mjs";
//#region src/auto-reply/reply/dispatch-acp-manager.runtime.ts
/** Runtime ACP manager dependencies and stale-binding cleanup used by reply dispatch. */
const ACP_STALE_BINDING_UNBIND_REASON = "acp-session-init-failed";
function isStaleSessionInitError(params) {
if (params.code !== "ACP_SESSION_INIT_FAILED") return false;
return /(ACP (session )?metadata is missing|missing ACP metadata|Session is not ACP-enabled|Resource not found)/i.test(params.message);
}
async function maybeUnbindStaleBoundConversations(params) {
if (!isStaleSessionInitError(params.error)) return;
try {
const removed = await getSessionBindingService().unbind({
targetSessionKey: params.targetSessionKey,
reason: ACP_STALE_BINDING_UNBIND_REASON
});
if (removed.length > 0) logVerbose(`dispatch-acp: removed ${removed.length} stale bound conversation(s) for ${params.targetSessionKey} after ${params.error.code}: ${params.error.message}`);
} catch (error) {
logVerbose(`dispatch-acp: failed to unbind stale bound conversations for ${params.targetSessionKey}: ${formatErrorMessage(error)}`);
}
}
//#endregion
export { getAcpSessionManager, listSessionBindingsBySessionAsync, maybeUnbindStaleBoundConversations, readAcpSessionEntryAsync };