openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.51 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import"./src-0ci69Prg.mjs";import{t as stableStringify}from"./stable-stringify-Cy0VZ0ci.mjs";import{r as filterStringEntries}from"./string-normalization-D_oBUpO3.mjs";import{r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{A as parseApiErrorInfo,V as readLoggingConfig,c as redactSensitiveText,t as getDefaultRedactPatterns}from"./redact-BT59pdZ_.mjs";import{t as redactIdentifier}from"./node-crypto-DPk8agfR.mjs";import{c as getApiErrorPayloadFingerprint}from"./user-copy-B1CccoqG.mjs";import{t as classifyProviderRuntimeFailureKind}from"./provider-runtime-failure-CoLwQkt4.mjs";
//!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}}export{buildTextObservationFields as n,buildApiErrorObservationFields as t};