UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

48 lines (47 loc) • 2.18 kB
import { n as isTruthyEnvValue } from "./env-HehwidXj.mjs"; import { a as extractErrorCode } from "./error-coercion-hDrHOSGy.mjs"; import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs"; import { n as diagnosticErrorFailureKind, t as diagnosticErrorCategory } from "./diagnostic-error-metadata-Cc4dyoSL.mjs"; import { createHash } from "node:crypto"; //#region src/logging/code-mode-diagnostic.ts const MAX_NAMES = 24; const MAX_NAME_LENGTH = 80; const failureLog = createSubsystemLogger("agents/code-mode"); /** Record failure categories and correlation without message or tool content. */ function logCodeModeFailure(e, t) { const n = e instanceof Error && e.cause instanceof Error ? e.cause : e; const r = t.failurePhase === "guest" || t.failurePhase === "input" || t.failureCode === "invalid_input" || t.failureCode === "input_contract" || t.failureCode === "store_range" || t.failureCode === "store_type" ? "warn" : "error"; failureLog[r]("Code Mode execution failed", { ...t, errorCode: extractErrorCode(n) === "ERR_WORKER_OUT_OF_MEMORY" ? "ERR_WORKER_OUT_OF_MEMORY" : void 0, errorCategory: diagnosticErrorCategory(n), failureKind: diagnosticErrorFailureKind(n) }); } function isCodeModeDiagnosticEnabled() { return isTruthyEnvValue(process.env.OPENCLAW_DEBUG_CODE_MODE); } function logCodeModeDiagnostic(e, t, n) { if (!isCodeModeDiagnosticEnabled()) return; const r = Object.fromEntries(Object.entries(n).map(([e, t]) => { if (Array.isArray(t)) { const n = [...new Set(t.map((e) => e.slice(0, MAX_NAME_LENGTH)))]; n.sort((e, t) => e.localeCompare(t)); return [e, n.slice(0, MAX_NAMES)]; } return [e, typeof t === "string" ? t.slice(0, MAX_NAME_LENGTH) : t]; })); e.info(`code-mode diagnostic ${JSON.stringify({ boundary: t, ...r })}`); } /** Prepare only correlation metadata; never send the session key into a guest worker. */ function codeModeGcAttribution(e, t) { return { runId: e, sessionKeyHash: t ? createHash("sha256").update(t).digest("hex").slice(0, 16) : void 0 }; } //#endregion export { logCodeModeFailure as i, isCodeModeDiagnosticEnabled as n, logCodeModeDiagnostic as r, codeModeGcAttribution as t };