UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

74 lines (73 loc) • 2.35 kB
import { a as extractErrorCode } from "./error-coercion-hDrHOSGy.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { r as isPluginTrustRefusalError } from "./plugin-trust-CpqJ5Gqw.mjs"; import { n as isChannelIngressUnavailableError } from "./ingress-unavailable-Bv8Q1CAX.mjs"; //#region src/gateway/channel-status-patches.ts /** Creates a connected-channel status patch with matching connection/event timestamps. */ function createConnectedChannelStatusPatch(e = Date.now()) { return { connected: true, lastConnectedAt: e, lastEventAt: e }; } /** Creates a transport-activity patch for health/activity monitors. */ function createTransportActivityStatusPatch(e = Date.now()) { return { lastTransportActivityAt: e }; } function channelReadyPatch(e = {}) { return { running: true, connected: true, lifecycle: "ready", lastConnectedAt: Date.now(), lastError: null, terminalDisconnect: void 0, ...e }; } function channelBlockedPatch(e, t = {}) { return { lifecycle: "blocked", terminalDisconnect: true, lastError: e, ...t }; } /** Classifies startup failures before transport cleanup or retry policy can hide their cause. */ function channelStartFailurePatch(e) { const t = formatErrorMessage(e); const n = isPluginTrustRefusalError(e); return { lastError: t, ...extractErrorCode(e) === "AGENT_SELECTION_REQUIRED" || n ? channelBlockedPatch(t, n ? { healthState: "plugin-trust-refused" } : {}) : {}, ...isChannelIngressUnavailableError(e) ? { ingressUnavailable: true } : {} }; } function channelStoppedPatch(e = {}) { return { running: false, connected: false, lifecycle: "stopped", ...e }; } function sanitizeAbortedTaskStatusPatch(e, t) { const n = { ...e }; delete n.running; delete n.restartPending; delete n.reconnectAttempts; delete n.lastStartAt; delete n.lastStopAt; delete n.lifecycle; if (n.connected === true) { delete n.connected; delete n.lastConnectedAt; delete n.lastEventAt; delete n.lastTransportActivityAt; } if (n.lastError === null && t.lastError) delete n.lastError; return n; } //#endregion export { createConnectedChannelStatusPatch as a, channelStoppedPatch as i, channelReadyPatch as n, createTransportActivityStatusPatch as o, channelStartFailurePatch as r, sanitizeAbortedTaskStatusPatch as s, channelBlockedPatch as t };