UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

62 lines (61 loc) • 3.4 kB
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { a as resolveSystemAgentVerifiedInferenceRoute } from "./verified-inference-B9tngoud.mjs"; //#region src/system-agent/inference-error.ts const INFERENCE_GUIDANCE = { setup: "OpenClaw could not reach working inference. Run `openclaw onboard` on the machine running OpenClaw to reconnect — it live-tests the route before saving it. Then try again.", retry: "The inference request failed or returned no usable reply. Try again; if it persists, check the model runtime logs.", timeout: "The inference request timed out. Try again; if it persists, check the model runtime and its timeout settings.", superseded: "The inference runtime was superseded during this turn. Try again after the current runtime settles.", "runtime-unavailable": "The prepared inference runtime became unavailable or was superseded during this turn. Try again; if it persists, check the model runtime logs.", "route-changed": "The verified inference route changed or could not be reverified during this turn. Start a new OpenClaw conversation to verify the current route.", "compatible-route": "The configured CLI runtime cannot enforce OpenClaw's tool restrictions. Select a compatible model/runtime route and try again." }; const INFERENCE_FAILURE_SUMMARY_MAX_CHARS = 300; function inferenceUnavailableMessage(e, t) { const n = e.length > 0 ? formatErrorMessage(e[0]).trim() : ""; if (!n) return INFERENCE_GUIDANCE[t]; const r = n.length > INFERENCE_FAILURE_SUMMARY_MAX_CHARS ? `${truncateUtf16Safe(n, 299)}…` : n; return `${INFERENCE_GUIDANCE[t]} Cause: ${r}`; } /** Safe public error for an OpenClaw turn that could not complete with intelligence. */ var SystemAgentInferenceUnavailableError = class extends Error { constructor(e, t = [], n = e === "conversation" ? "setup" : "retry") { super(inferenceUnavailableMessage(t, n)); this.stage = e; this.failures = t; this.code = "SYSTEM_AGENT_INFERENCE_UNAVAILABLE"; this.name = "SystemAgentInferenceUnavailableError"; } }; function isSystemAgentInferenceUnavailableError(e) { return e instanceof SystemAgentInferenceUnavailableError || e instanceof Error && "code" in e && e.code === "SYSTEM_AGENT_INFERENCE_UNAVAILABLE"; } //#endregion //#region src/system-agent/inference-guard.ts /** The host retains error presentation and conversation cleanup at the write boundary. */ async function requireSystemAgentPersistentApplyInference(e, t) { if (!e.binding) throw new SystemAgentInferenceUnavailableError("conversation"); try { const { resolvePersistentApplyInference: t } = await import("./system-agent/setup-inference.js"); const n = await t(e); if (n) return n; } catch (e) { return t([e]); } return t([]); } /** Read guards share failure classification; the conversation retains cleanup ownership. */ async function requireSystemAgentInferenceRoute(e, t, n) { let r = []; if (e) try { const t = await resolveSystemAgentVerifiedInferenceRoute(e); if (t) return t; } catch (e) { r = [e]; } n?.(r); throw new SystemAgentInferenceUnavailableError(t, r, e ? "route-changed" : "setup"); } //#endregion export { isSystemAgentInferenceUnavailableError as i, requireSystemAgentPersistentApplyInference as n, SystemAgentInferenceUnavailableError as r, requireSystemAgentInferenceRoute as t };