UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

108 lines (107 loc) • 3.37 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { r as jsonUtf8Bytes } from "./json-utf8-bytes-DNwtq2cu.mjs"; import { r as CHAT_PENDING_INPUT_MESSAGE_PREFIX } from "./chat-history-constants-BGgHv5E_.mjs"; import { o as projectChatDisplayMessage } from "./chat-display-projection.core-ApUvO4fQ.mjs"; //#region src/gateway/chat-history-reply-messages.ts /** Batch label projection includes quoted originals without recursively following their replies. */ async function projectChatHistoryWithReplies(e, t) { const n = []; const r = e.map((e) => { const t = asOptionalRecord(asOptionalRecord(e["__openclaw"])?.replyToMessage); const r = asOptionalRecord(t?.message); return r ? { reply: t, index: n.push(r) - 1 } : void 0; }); const i = await t([...e, ...n]); const a = i.slice(0, e.length); for (const [t, n] of a.entries()) { const o = r[t]; if (!o) continue; const s = i[e.length + o.index]; a[t] = { ...n, __openclaw: { ...asOptionalRecord(n["__openclaw"]), replyToMessage: jsonUtf8Bytes(s) > 8192 ? { ok: false, unavailableReason: "oversized" } : { ...o.reply, message: s } } }; } return a; } function readChatHistoryReplyMessageId(e) { const t = asOptionalRecord(e); return normalizeOptionalString(asOptionalRecord(t?.["__openclaw"])?.replyToId) ?? (t?.role === "assistant" ? normalizeOptionalString(asOptionalRecord(t.openclawDelivery)?.replyToId) : void 0); } /** Page-local reads share the admitted transcript owner and never start client RPCs. */ async function attachChatHistoryReplyMessages(e, t, n) { const r = /* @__PURE__ */ new Map(); const i = []; for (const a of e) { const e = asOptionalRecord(a); const o = asOptionalRecord(e?.["__openclaw"]); const s = readChatHistoryReplyMessageId(a); if (!e || !s || !t.sessionId) { i.push(a); continue; } let c = r.get(s); if (!c && s.startsWith("pending:")) c = { ok: false, unavailableReason: "not_found" }; if (!c) { const e = await n.readers.readSessionMessageByIdAsync({ agentId: t.sessionAgentId, sessionId: t.sessionId, sessionKey: t.canonicalKey, storePath: t.storePath, sessionEntry: t.entry }, s, { allowResetArchiveFallback: true, historyVisibility: { sessionStartedAt: t.entry?.sessionStartedAt } }); const i = e.message ? projectChatDisplayMessage(e.message, { maxChars: 500, includePluginSteering: t.includePluginSteering, subagentCoordination: n.readers.subagentCoordination, resolveCronJobName: n.resolveCronJobName, ...n.deferProfileDisplay ? {} : { resolveCurrentUserProfileDisplay: n.resolveCurrentUserProfileDisplay } }) : void 0; const a = i ? { ...i } : void 0; if (a) { delete a.provider; delete a.model; } c = e.oversized || a && jsonUtf8Bytes(a) > 8192 ? { ok: false, unavailableReason: "oversized" } : a ? { ok: true, message: a } : { ok: false, unavailableReason: e.found ? "not_visible" : "not_found" }; r.set(s, c); } i.push({ ...e, __openclaw: { ...o, replyToMessage: c } }); } return i; } //#endregion export { projectChatHistoryWithReplies as n, readChatHistoryReplyMessageId as r, attachChatHistoryReplyMessages as t };