UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

139 lines (138 loc) • 10.5 kB
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { C as isGenericProviderInternalError, T as parseApiErrorInfo, _ as extractLeadingHttpStatus, b as formatRawAssistantErrorForUi, g as extractErrorHttpStatus, m as CONTEXT_OVERFLOW_ERROR_MESSAGE, w as isKnownTransportErrorCode, x as formatTransportErrorCopy, y as formatProviderRefusalText } from "./redact-Mj7pppxC.mjs"; import { t as classifyGatewayStorageFailure } from "./sqlite-error-diagnostics-6_hREUnq.mjs"; import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs"; import { a as REPETITIVE_OUTPUT_ERROR_CODE } from "./types-iq-cNLsd.mjs"; import { h as isTimeoutErrorMessage, u as isProviderCompletedErrorFinishReasonMessage, v as resolveExecutionApprovalFailureMessage } from "./message-patterns-xrpp7Aip.mjs"; import { a as readRepeatedToolErrorSummary } from "./tool-error-summary-BTwB17cj.mjs"; import { a as TLS_CERTIFICATE_ERROR_USER_TEXT, b as renderRateLimitOrOverloadedCopy, d as isRawApiErrorPayload, f as isStreamingJsonParseError, l as isInvalidStreamingEventOrderError, o as formatBillingErrorMessage, r as OAUTH_REFRESH_CONTENTION_USER_TEXT, s as formatDiskSpaceErrorCopy, t as AUTH_INVALID_TOKEN_USER_TEXT, u as isLikelyHttpErrorText } from "./user-copy-DFvWpx47.mjs"; import { r as isReasoningConstraintErrorMessage } from "./context-overflow-tables-CeoOZL8Z.mjs"; import { a as failoverReasonFromClassification } from "./classification-rules-DfXxEGkP.mjs"; import { a as renderAssistantRequestFailureCopy, i as renderAssistantFormatFailureCopy, o as renderFormatErrorCopy, r as PROVIDER_SCHEMA_REJECTION_USER_TEXT, s as renderModelLoadFailureCopy } from "./assistant-request-failure-copy-CDAkRIru.mjs"; import { t as formatSandboxToolPolicyBlockedMessage } from "./runtime-status-C5ZOG7YR.mjs"; import { n as classifyFailoverSignal } from "./classify-o7Whl-By.mjs"; import { n as REPEATED_TOOL_ERROR_MESSAGE, r as REPETITIVE_OUTPUT_ERROR_MESSAGE, t as REPEATED_TOOL_ERROR_CODE } from "./errors-D_CW6sfd.mjs"; import { t as buildAssistantFailoverSignal } from "./assistant-message-failures-Cv3Qnsh5.mjs"; import { t as classifyProviderRuntimeFailureKind } from "./provider-runtime-failure-C2I9s5Fv.mjs"; //#region src/agents/embedded-agent-helpers/error-text.ts const log = createSubsystemLogger("errors"); const sandboxToolPolicyAuditMessages = /* @__PURE__ */ new WeakSet(); const GENERIC_ASSISTANT_ERROR_TEXT = "LLM request failed."; const SYNTHESIZED_TIMEOUT_ERROR_TEXT = "LLM request timed out."; const RUNTIME_FAILURE_COPY = { auth_refresh: "Couldn't sign in to the AI service. Sign in again under Models in the Control UI or run `openclaw configure`.", refresh_contention: OAUTH_REFRESH_CONTENTION_USER_TEXT, refresh_timeout: "Signing in took too long. Try again in a moment. If it keeps happening, sign in again under Models in the Control UI.", callback_timeout: "Sign-in wasn't completed. Try signing in again. If asked for a link, paste the full link from your browser.", callback_validation: "The sign-in link wasn't accepted. Try signing in again. If asked for a link, paste the full link from your browser.", auth_scope: "This login doesn't have the access OpenClaw needs. Sign in again under Models in the Control UI.", auth_html: "Couldn't sign in to the AI service. Sign in again under Models in the Control UI or run `openclaw configure`.", auth_invalid_token: AUTH_INVALID_TOKEN_USER_TEXT, upstream_html: "Couldn't reach the AI service. Try again in a moment. If it continues, open Settings → Logs in the Control UI or run `openclaw logs --follow`.", proxy: "Couldn't connect to the AI service. For details, open Settings → Logs in the Control UI or run `openclaw logs --follow`.", tls_certificate: TLS_CERTIFICATE_ERROR_USER_TEXT, model_not_found: "This model was not found. Choose another model in the Control UI." }; const TOOL_CALL_INPUT_MISSING_RE = /tool_(?:use|call)\.(?:input|arguments).*?(?:field required|required)/i; const TOOL_CALL_INPUT_PATH_RE = /messages\.\d+\.content\.\d+\.tool_(?:use|call)\.(?:input|arguments)/i; function classifyAssistantErrorFacts(e, t) { const n = buildAssistantFailoverSignal(e, { provider: t?.providerOwner?.id ?? t?.provider }); const r = t?.providerOwner ?? null; const i = classifyFailoverSignal(n, { providerPlugin: r }); return { provider: t?.provider ?? e.provider ?? t?.providerOwner?.id, model: t?.model ?? e.model, reason: failoverReasonFromClassification(i), status: n.status ?? extractErrorHttpStatus(n.message ?? "")?.code, providerRuntimeFailureKind: classifyProviderRuntimeFailureKind(n, { providerPlugin: r }), storageFailure: classifyGatewayStorageFailure(e), code: n.code }; } function formatAssistantErrorText(e, t, n) { const r = (e.errorMessage ?? "").trim(); if (e.stopReason !== "error" && !r) return; const i = formatProviderRefusalText(e); if (i) return i; const a = renderFormatErrorCopy(r); const o = n ?? classifyAssistantErrorFacts(e, t); if (o.storageFailure) return renderAssistantRequestFailureCopy(o); const { reason: s, status: c, providerRuntimeFailureKind: l } = o; if (c === 403 && (e.errorType ?? parseApiErrorInfo(r)?.type) === "FreeTierError") return "This model's free tier is limited to the provider's own client. Choose another model or use a paid plan."; const u = r.match(/unknown tool[:\s]+["']?([a-z0-9_-]+)["']?/i) ?? r.match(/tool\s+["']?([a-z0-9_-]+)["']?\s+(?:not found|is not available)/i); if (u?.[1] && t?.sandboxRuntime) { const n = !sandboxToolPolicyAuditMessages.has(e); const r = formatSandboxToolPolicyBlockedMessage({ cfg: t?.cfg, sessionKey: t?.sessionKey, agentId: t?.agentId, toolName: u[1], preparedRuntimeStatus: t.sandboxRuntime, audit: n }); if (r) { if (n) sandboxToolPolicyAuditMessages.add(e); return r; } } const d = formatDiskSpaceErrorCopy(r); if (d) return d; const f = RUNTIME_FAILURE_COPY[l]; if (f) return f; if (s === "billing") return formatBillingErrorMessage(t?.provider, t?.model ?? e.model, t?.authMode); const p = s === "rate_limit" || s === "overloaded" ? renderRateLimitOrOverloadedCopy({ reason: s, raw: r }) : void 0; if (p) return p; if ((c === 400 || c === 422) && a !== "The AI service couldn't accept this request. Try a new conversation with /new, or choose another model in the Control UI." && !a.startsWith("LLM request rejected:")) return a; if (s === "context_overflow") return CONTEXT_OVERFLOW_ERROR_MESSAGE; if (isReasoningConstraintErrorMessage(r)) return "Reasoning is required for this model endpoint. Use /think minimal (or any non-off level) and try again."; if (isInvalidStreamingEventOrderError(r)) return "LLM request failed: provider returned an invalid streaming response. Please try again."; if (/incorrect role information|roles must alternate|400.*role|"message".*role.*information/i.test(r)) return "Message ordering conflict - please try again. If this persists, use /new to start a fresh session."; if (r && (TOOL_CALL_INPUT_MISSING_RE.test(r) || TOOL_CALL_INPUT_PATH_RE.test(r))) return "Session history looks corrupted (tool call input missing). Use /new to start a fresh session. If this keeps happening, reset the session or delete the corrupted session transcript."; if (l === "replay_invalid") return "Session history or replay state is invalid. Use /new to start a fresh session and try again."; const m = parseApiErrorInfo(r); if (l === "schema" && m?.type?.toLowerCase().includes("invalid_request") && m.message?.trim()) return `LLM request rejected: ${m.message.trim()}`; if (isGenericProviderInternalError(r)) return formatRawAssistantErrorForUi(r); const h = formatTransportErrorCopy(e.errorCode && isKnownTransportErrorCode(e.errorCode) ? `${r} ${e.errorCode}` : r); if (h) return h; if (isProviderCompletedErrorFinishReasonMessage(r)) return formatRawAssistantErrorForUi(r); if (isTimeoutErrorMessage(r) && !(n?.status !== void 0 && n.status >= 500)) return SYNTHESIZED_TIMEOUT_ERROR_TEXT; if (l === "schema" || s === "format") return a; if (!r) return s ? renderAssistantRequestFailureCopy(o) : "LLM request failed with an unknown error."; if (isRawApiErrorPayload(r) || isLikelyHttpErrorText(r)) return formatRawAssistantErrorForUi(r); if (isStreamingJsonParseError(r)) return "LLM streaming response contained a malformed fragment. Please try again."; if (r.length > 600) log.warn(`Long error truncated: ${truncateUtf16Safe(r, 200)}`); return r.length > 600 ? `${truncateUtf16Safe(r, 600)}…` : r; } function isRawAssistantErrorPassthrough(e) { const t = e.friendlyError?.trim(); const n = e.rawError?.trim(); if (!t || !n) return false; const r = parseApiErrorInfo(n)?.message?.trim(); const i = extractLeadingHttpStatus(n)?.rest?.trim(); const a = t.startsWith("LLM request rejected:") || t.startsWith("LLM error") || t.startsWith("HTTP "); return t === n && t !== "LLM request timed out." || n.length > 600 && t === `${truncateUtf16Safe(n, 600)}…` || Boolean(r && a) || Boolean(i && t.startsWith("HTTP ")); } function formatUserFacingAssistantErrorText(e, t) { if (e.errorCode === "openclaw_repetitive_output") return REPETITIVE_OUTPUT_ERROR_MESSAGE; if (e.errorCode === "openclaw_repeated_tool_error") return readRepeatedToolErrorSummary(e.errorMessage) ?? "OpenClaw stopped this turn after 3 consecutive identical tool failures. Check the tool inputs or service, then use a changed request."; const n = renderModelLoadFailureCopy(e); if (n) return n; const r = e.errorMessage?.trim(); const i = resolveExecutionApprovalFailureMessage(r); if (i) return `⚠️ ${i}`; const a = classifyAssistantErrorFacts(e, t); const o = formatAssistantErrorText(e, t, a); const s = isRawAssistantErrorPassthrough({ friendlyError: o, rawError: r }); const c = o === "The AI service couldn't accept this request. Try a new conversation with /new, or choose another model in the Control UI." || o?.startsWith("LLM request rejected:"); const l = (c ? renderAssistantFormatFailureCopy(e, a.reason) : void 0) ?? (s ? c ? "The AI service couldn't accept this request. Try a new conversation with /new, or choose another model in the Control UI." : void 0 : o); if (l) return l.trim(); return renderAssistantRequestFailureCopy(a) ?? "LLM request failed."; } //#endregion export { formatUserFacingAssistantErrorText as i, SYNTHESIZED_TIMEOUT_ERROR_TEXT as n, formatAssistantErrorText as r, GENERIC_ASSISTANT_ERROR_TEXT as t };