UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

60 lines (59 loc) • 2.06 kB
import { i as asOptionalObjectRecord } from "./record-coerce-CVPuDqcc.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import { createHash } from "node:crypto"; //#region extensions/github-copilot/connection-bound-ids.ts function looksLikeConnectionBoundId(e) { if (e.length < 24) return false; if (/^(?:rs|msg|fc)_[A-Za-z0-9_-]+$/.test(e)) return false; if (!/^[A-Za-z0-9+/_-]+=*$/.test(e)) return false; return Buffer.from(e, "base64").length >= 16; } function deriveReplacementId(e, t) { return `${e === "function_call" ? "fc" : "msg"}_${createHash("sha256").update(t).digest("hex").slice(0, 16)}`; } function isValidReasoningReplayId(e) { return typeof e === "string" && e.length <= 64 && /^rs_[A-Za-z0-9_-]+$/.test(e); } function dropReasoningItem(e, t) { e.splice(t, 1); const n = asOptionalObjectRecord(e[t]); if (n && n.type === "message" && n.role === "assistant") delete n.id; } function sanitizeCopilotReplayResponseIds(e) { if (!Array.isArray(e)) return false; let t = false; for (let n = e.length - 1; n >= 0; n -= 1) { const r = asOptionalObjectRecord(e[n]); if (!r) continue; const i = r.id; if (r.type === "reasoning") { if (r.status === null) { delete r.status; t = true; } if (!(typeof r.encrypted_content === "string" && r.encrypted_content.length > 0 && (r.status === void 0 || r.status === "completed"))) { dropReasoningItem(e, n); t = true; } else if (i === void 0 || isValidReasoningReplayId(i)) continue; else if (typeof i === "string" && looksLikeConnectionBoundId(i)) { delete r.id; t = true; } else { dropReasoningItem(e, n); t = true; } continue; } if (typeof i !== "string" || i.length === 0) continue; if (looksLikeConnectionBoundId(i)) { r.id = deriveReplacementId(typeof r.type === "string" ? r.type : void 0, i); t = true; } } return t; } function sanitizeCopilotReplayResponsePayload(e) { return sanitizeCopilotReplayResponseIds(asOptionalObjectRecord(e)?.input); } //#endregion export { sanitizeCopilotReplayResponsePayload as t };