UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) • 2.24 kB
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as AgentHarnessPreflightError } from "./errors-0Ou7CzqA.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./agent-harness-registration-CZFtccsZ.mjs"; import OpenAI from "openai"; //#region extensions/agentsapi/agentsapi-errors.ts /** Customer-safe native failure facts remain available to host result classification. */ var AgentsApiError = class extends Error { constructor(e, t = {}) { super(e); this.name = "AgentsApiError"; this.code = t.code; this.status = t.status; this.type = t.type; this.param = t.param; } }; function resolveAgentsApiSessionAccessError(e, t) { if (!t || !(e instanceof OpenAI.APIError)) return e; const n = asOptionalRecord(e.error)?.message; let r; if (e instanceof OpenAI.NotFoundError && n === `No managed agent resource found: ${t}`) r = "Agents API could not find the saved session or this API key cannot access it. Check that the key belongs to the session's project and has the required permissions, then retry."; else if (e instanceof OpenAI.PermissionDeniedError && n === "hosted session input requires the API key that created its CCA thread") r = "Agents API currently requires the original API key to send input to this hosted session. Restore that key, then retry to continue the same session."; else return e; return new AgentHarnessPreflightError(e.message, { cause: e, userMessage: r }); } function isAgentsApiTransportDisconnect(e) { if (!(e instanceof Error) || e instanceof AgentsApiError) return false; const t = asOptionalRecord(e)?.code; if (typeof t === "string" && [ "ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "UND_ERR_SOCKET" ].includes(t) || e instanceof TypeError && ["terminated", "fetch failed"].includes(e.message)) return true; return e.cause instanceof Error && isAgentsApiTransportDisconnect(e.cause); } function isAgentsApiOptionalHistoryReadFailure(e) { return e instanceof OpenAI.APIConnectionError || e instanceof OpenAI.APIError && (e.status === 429 || (e.status ?? 0) >= 500); } //#endregion export { resolveAgentsApiSessionAccessError as i, isAgentsApiOptionalHistoryReadFailure as n, isAgentsApiTransportDisconnect as r, AgentsApiError as t };