openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
52 lines (51 loc) • 2.05 kB
JavaScript
import { l as resolveSessionStorePathCore } from "./paths-DvQ5AJvD.mjs";
import { i as readSessionEntryReadOnlyInWorker } from "./session-entry-read-runtime-1Fp1sybj.mjs";
import "./sessions-D5Vvu3AE.mjs";
import { n as resolveAcpSessionCwd } from "./session-identifiers-dCLUDxk0.mjs";
import { t as persistAcpTurnTranscript } from "./transcript-persistence-Cl9VvHA4.mjs";
//#region src/auto-reply/reply/dispatch-acp-transcript.runtime.ts
async function persistAcpDispatchTranscript(e) {
const t = e.promptText.trim();
const n = e.finalText.trim();
if (!t && !n) return;
const r = e.agentId;
const i = resolveSessionStorePathCore(e.cfg.session?.store, { agentId: r });
const a = await readSessionEntryReadOnlyInWorker({
agentId: r,
sessionKey: e.sessionKey,
storePath: i
});
const o = a?.sessionId;
if (!o) throw new Error(`unknown ACP session key: ${e.sessionKey}`);
if (e.expectedSessionId && o !== e.expectedSessionId) throw new Error("ACP transcript session changed before the turn could be persisted.");
const s = await persistAcpTurnTranscript({
body: t,
transcriptBody: t,
finalText: n,
terminalOutcome: e.terminalOutcome,
sessionId: o,
expectedSessionId: e.expectedSessionId,
sessionKey: e.sessionKey,
sessionEntry: a,
storePath: i,
sessionAgentId: r,
threadId: e.threadId,
sessionCwd: resolveAcpSessionCwd(e.meta) ?? process.cwd(),
config: e.cfg,
userTurnTranscriptRecorder: e.userTurnTranscriptRecorder,
prepareAssistantTranscriptMessage: e.prepareAssistantTranscriptMessage,
assistantIdempotencyKey: e.assistantIdempotencyKey
});
if (s.kind === "session-rebound") throw new Error("ACP transcript session changed before the turn could be persisted.");
return s.assistantTranscript && e.assistantIdempotencyKey ? {
agentId: r,
sessionId: o,
sessionKey: e.sessionKey,
storePath: i,
messageId: s.assistantTranscript.messageId,
anchor: s.assistantTranscript.anchor,
idempotencyKey: e.assistantIdempotencyKey
} : void 0;
}
//#endregion
export { persistAcpDispatchTranscript };