




















@@ -6,7 +6,10 @@ import {
66applyInputProvenanceToUserMessage,
77type InputProvenance,
88} from "../sessions/input-provenance.js";
9-import type { PersistedUserTurnMessage } from "../sessions/user-turn-transcript.js";
9+import {
10+mergePreparedUserTurnMessageForRuntime,
11+type PersistedUserTurnMessage,
12+} from "../sessions/user-turn-transcript.js";
1013import { resolveLiveToolResultMaxChars } from "./pi-embedded-runner/tool-result-truncation.js";
1114import { installSessionToolResultGuard } from "./session-tool-result-guard.js";
1215import { redactTranscriptMessage } from "./transcript-redact.js";
@@ -18,16 +21,6 @@ type GuardedSessionManager = SessionManager & {
1821clearPendingToolResults?: () => void;
1922};
202321-function isUserMessage(message: AgentMessage): message is Extract<AgentMessage, { role: "user" }> {
22-return (message as { role?: unknown }).role === "user";
23-}
24-25-function isBeforeAgentRunBlockedMessage(message: AgentMessage): boolean {
26-const marker = (message as { __openclaw?: { beforeAgentRunBlocked?: unknown } })["__openclaw"]
27-?.beforeAgentRunBlocked;
28-return marker !== undefined;
29-}
30-3124/**
3225 * Apply the tool-result guard to a SessionManager exactly once and expose
3326 * a flush method on the instance for easy teardown handling.
@@ -115,20 +108,15 @@ export function guardSessionManager(
115108sessionKey: opts?.sessionKey,
116109transformMessageForPersistence: (message) => {
117110const withProvenance = applyInputProvenanceToUserMessage(message, opts?.inputProvenance);
118-if (
119-!pendingUserMessageForPersistence ||
120-!isUserMessage(withProvenance) ||
121-isBeforeAgentRunBlockedMessage(withProvenance)
122-) {
123-return withProvenance;
124-}
125-126111const prepared = pendingUserMessageForPersistence;
127-pendingUserMessageForPersistence = undefined;
128-return {
129- ...(withProvenance as unknown as Record<string, unknown>),
130- ...(prepared as unknown as Record<string, unknown>),
131-} as unknown as AgentMessage;
112+const merged = mergePreparedUserTurnMessageForRuntime({
113+runtimeMessage: withProvenance,
114+ ...(prepared ? { preparedMessage: prepared } : {}),
115+});
116+if (merged !== withProvenance) {
117+pendingUserMessageForPersistence = undefined;
118+}
119+return merged;
132120},
133121transformToolResultForPersistence: transform,
134122allowSyntheticToolResults: opts?.allowSyntheticToolResults,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。