UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

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