openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
79 lines (78 loc) • 3.25 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as createChatHistoryRecoveryProjection } from "./chat-display-projection.core-ApUvO4fQ.mjs";
import { m as prepareSessionHistorySubagentFacts, t as createSessionActorTranscriptReader } from "./session-transcript-memory-reader-_afqDL9S.mjs";
import { n as projectChatHistoryWithReplies } from "./chat-history-reply-messages-DT8sCO_d.mjs";
//#region src/gateway/cli-session-history.process-held.ts
/** Read canonical memory history from its actor while CLI matching stays in a compute worker. */
async function readProcessHeldCliHistory(e, t, n) {
const r = await readProcessHeldCliHistoryQuery({
kind: "rpc",
params: e
}, t, n);
if (r.kind !== "rpc") throw new Error("Unexpected process-held history page");
return r.page;
}
async function readProcessHeldCliHistoryMessage(e, t) {
const n = await readProcessHeldCliHistoryQuery({
kind: "rpc-message",
params: e
}, void 0, t);
if (n.kind !== "rpc-message") throw new Error("Unexpected process-held history message");
return n.result;
}
async function readProcessHeldCliHistoryQuery(e, t, n) {
const r = structuredClone(e);
const i = r.params;
i.encodeResponse = false;
if (!n) throw new Error("Process-held history requires a memory session actor");
if (i.entry) i.entry.incognito = true;
const { runProcessHeldHistoryTask: a } = await import("./session-transcript-worker-runtime-DDFIs0FH.mjs");
const o = createSessionActorTranscriptReader(n);
const s = {
agentId: i.sessionAgentId,
sessionId: i.sessionId,
sessionKey: i.canonicalKey,
storePath: i.storePath,
sessionEntry: i.entry
};
const assertCurrent = () => {
t?.throwIfAborted();
n.assertCurrent();
};
const c = await a(r, async (e, { signal: t }) => {
t.throwIfAborted();
assertCurrent();
const n = e;
const r = n.kind === "page" ? await o.readSessionMessagesPageWithStatsAsync(s, n.options, t) : n.kind === "around" ? await o.readSessionMessagesAroundIdWithStatsAsync(s, n.options, t) : await o.readSessionMessageByIdAsync(s, n.messageId, n.options, t);
t.throwIfAborted();
if (r === void 0) throw new Error("Unsupported process-held history request");
assertCurrent();
const i = "messages" in r ? r.messages : r.message === void 0 ? [] : [r.message];
return {
input: {
result: r,
facts: prepareSessionHistorySubagentFacts(o.subagentCoordination, (e) => {
for (const t of i) createChatHistoryRecoveryProjection({ subagentCoordination: e }).append([t]);
})
},
timeoutMs: 6e4
};
}, t);
assertCurrent();
if (c.kind === "rpc-message") return c;
const l = c.page;
const [{ createCurrentUserProfileMessageProjector: u }, { resolveCurrentUserProfileDisplay: d }, { getUserProfileDisplay: f }] = await Promise.all([
import("./chat-display-projection.core-BlrAFjic.mjs"),
import("./current-user-profile-display-DaLsCZRW.mjs"),
import("./user-profile-list-Dg7EGtJd.mjs")
]);
const p = u((e) => d(e, f));
l.messages = await projectChatHistoryWithReplies(l.messages.filter((e) => Boolean(asOptionalRecord(e))), (e) => e.map(p));
assertCurrent();
return {
kind: "rpc",
page: l
};
}
//#endregion
export { readProcessHeldCliHistory, readProcessHeldCliHistoryMessage };