UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) • 1.59 kB
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { a as memoizeFrozenPlainDataProjection } from "./immutable-data-Y7xVjZoy.mjs"; import { n as SYNTHETIC_MISSING_TOOL_RESULT_DETAIL_KEY } from "./tool-result-pairing-gfPySfH_.mjs"; //#region src/shared/model-context-message.ts const MODEL_CONTEXT_PRIVATE_METADATA_KEYS = ["upstreamUserText"]; const stripDetails = memoizeFrozenPlainDataProjection((e) => { const t = asOptionalRecord(e.details); if (t?.["openclawSyntheticMissingToolResult"] === true && Object.keys(t).length === 1) return e; const n = { ...e }; if (t?.["openclawSyntheticMissingToolResult"] === true) n.details = { [SYNTHETIC_MISSING_TOOL_RESULT_DETAIL_KEY]: true }; else delete n.details; return n; }); function stripToolResultDetails(e) { let t = false; const n = e.map((e) => { const n = asOptionalRecord(e); if (n?.role !== "toolResult" || !("details" in n)) return e; const r = stripDetails(n); t ||= r !== e; return r; }); return t ? n : e; } function projectModelContextMessages(e, t) { const n = []; for (const r of stripToolResultDetails(e)) { const e = asOptionalRecord(r); const i = asOptionalRecord(e?.["__openclaw"]); if (!i || !MODEL_CONTEXT_PRIVATE_METADATA_KEYS.some((e) => e in i)) { n.push(r); continue; } const a = { ...i }; for (const e of MODEL_CONTEXT_PRIVATE_METADATA_KEYS) delete a[e]; t?.(a); n.push({ ...e, __openclaw: a }); } return n; } //#endregion export { projectModelContextMessages as n, stripToolResultDetails as r, MODEL_CONTEXT_PRIVATE_METADATA_KEYS as t };