UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

95 lines (94 loc) • 3.97 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import "./src-H3RMXyFL.mjs"; import { t as stableStringify } from "./stable-stringify-vqde_3tT.mjs"; import { r as filterStringEntries } from "./string-normalization-DLmfYZXI.mjs"; import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { I as readLoggingConfig, T as parseApiErrorInfo, s as redactSensitiveText, t as getDefaultRedactPatterns } from "./redact-Mj7pppxC.mjs"; import { t as redactIdentifier } from "./node-crypto-B6yuTjmm.mjs"; import { c as getApiErrorPayloadFingerprint } from "./user-copy-DFvWpx47.mjs"; import { t as classifyProviderRuntimeFailureKind } from "./provider-runtime-failure-C2I9s5Fv.mjs"; //#region src/agents/embedded-agent-error-observation.ts const MAX_OBSERVATION_INPUT_CHARS = 64e3; const MAX_FINGERPRINT_MESSAGE_CHARS = 8e3; const RAW_ERROR_PREVIEW_MAX_CHARS = 400; const PROVIDER_ERROR_PREVIEW_MAX_CHARS = 200; const REQUEST_ID_RE = /\brequest[_ ]?id\b\s*[:=]\s*["'()]*([A-Za-z0-9._:-]+)/i; const OBSERVATION_EXTRA_REDACT_PATTERNS = [ String.raw`\b(?:x-)?api[-_]?key\b\s*[:=]\s*(["']?)([^\s"'\\;]+)\1`, String.raw`"(?:api[-_]?key|api_key)"\s*:\s*"([^"]+)"`, String.raw`(?:\bCookie\b\s*[:=]\s*[^;=\s]+=|;\s*[^;=\s]+=)([^;\s\r\n]+)` ]; function truncateForObservation(e, t) { const n = e?.trim(); if (!n) return; return n.length > t ? `${truncateUtf16Safe(n, t)}…` : n; } function boundObservationInput(e) { const t = normalizeOptionalString(e); return t ? truncateUtf16Safe(t, MAX_OBSERVATION_INPUT_CHARS) : void 0; } function replaceRequestIdPreview(e, t) { if (!e || !t) return e; return e.split(t).join(redactIdentifier(t, { len: 12 })); } function redactObservationText(e) { if (!e) return e; const t = filterStringEntries(readLoggingConfig()?.redactPatterns); return redactSensitiveText(e, { mode: "tools", patterns: [ ...getDefaultRedactPatterns(), ...t, ...OBSERVATION_EXTRA_REDACT_PATTERNS ] }); } function buildApiErrorObservationFields(e, t) { const n = boundObservationInput(e); if (!n) return {}; try { const e = parseApiErrorInfo(n); const r = e?.requestId ?? normalizeOptionalString(n.match(REQUEST_ID_RE)?.[1]); const i = r ? redactIdentifier(r, { len: 12 }) : void 0; const a = e?.message && truncateUtf16Safe(e.message, MAX_FINGERPRINT_MESSAGE_CHARS); const o = (e?.httpCode || e?.type || a ? stableStringify({ httpCode: e?.httpCode, type: e?.type, message: a }) : null) || (r ? n.split(r).join("<request_id>") : getApiErrorPayloadFingerprint(n)); const s = replaceRequestIdPreview(redactObservationText(n), r); const c = replaceRequestIdPreview(redactObservationText(e?.message), r); return { rawErrorPreview: truncateForObservation(s, RAW_ERROR_PREVIEW_MAX_CHARS), rawErrorHash: redactIdentifier(n, { len: 12 }), rawErrorFingerprint: o ? redactIdentifier(o, { len: 12 }) : void 0, httpCode: e?.httpCode, providerRuntimeFailureKind: classifyProviderRuntimeFailureKind({ status: e?.httpCode ? Number(e.httpCode) : void 0, message: n, provider: t?.providerOwner?.id ?? t?.provider }, { providerPlugin: t?.providerOwner ?? null }), providerErrorCode: redactObservationText(t?.code ?? e?.code), providerErrorType: redactObservationText(e?.type), providerErrorMessagePreview: truncateForObservation(c, PROVIDER_ERROR_PREVIEW_MAX_CHARS), requestIdHash: i }; } catch { return {}; } } function buildTextObservationFields(e, t) { const n = buildApiErrorObservationFields(e, t); return { textPreview: n.rawErrorPreview, textHash: n.rawErrorHash, textFingerprint: n.rawErrorFingerprint, httpCode: n.httpCode, providerRuntimeFailureKind: n.providerRuntimeFailureKind, providerErrorType: n.providerErrorType, providerErrorMessagePreview: n.providerErrorMessagePreview, requestIdHash: n.requestIdHash }; } //#endregion export { buildTextObservationFields as n, buildApiErrorObservationFields as t };