openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
24 lines (23 loc) • 1.19 kB
JavaScript
import { n as markInboundContextLabel } from "./inbound-context-marker-CxvFQl8I.mjs";
import { createHash } from "node:crypto";
//#region src/agents/cli-image-turn-correlation.ts
const CLI_IMAGE_TURN_HEADER = markInboundContextLabel("Image turn:");
const CLI_IMAGE_TURN_BLOCK_PATTERN = new RegExp(`${CLI_IMAGE_TURN_HEADER}\\n\`\`\`json\\n\\{"turnKey":"([a-f0-9]{64})"\\}\\n\`\`\``, "g");
function hashCliImageTurnEntryId(e) {
return createHash("sha256").update(e).digest("hex");
}
function formatCliImageTurnContext(e) {
return `${CLI_IMAGE_TURN_HEADER}\n\`\`\`json\n${JSON.stringify({ turnKey: e })}\n\`\`\``;
}
function readCliImageTurnContext(e) {
const t = Array.from(e.matchAll(CLI_IMAGE_TURN_BLOCK_PATTERN), (e) => e[1]);
if (t.length !== e.split(CLI_IMAGE_TURN_HEADER).length - 1) return;
const n = t[0];
return n && t.every((e) => e === n) ? n : void 0;
}
function stripCliImageTurnContext(e, t) {
const n = formatCliImageTurnContext(t);
return e.replace(`\n\n${n}\n\n`, "\n\n").replace(`${n}\n\n`, "").replace(`\n\n${n}`, "");
}
//#endregion
export { stripCliImageTurnContext as i, hashCliImageTurnEntryId as n, readCliImageTurnContext as r, formatCliImageTurnContext as t };