fix: guard session tool results

This commit is contained in:
Peter Steinberger
2026-01-12 17:28:39 +00:00
parent f83fb70360
commit f5d5661adf
8 changed files with 414 additions and 13 deletions

View File

@@ -0,0 +1,26 @@
import type { SessionManager } from "@mariozechner/pi-coding-agent";
import { installSessionToolResultGuard } from "./session-tool-result-guard.js";
export type GuardedSessionManager = SessionManager & {
/** Flush any synthetic tool results for pending tool calls. Idempotent. */
flushPendingToolResults?: () => void;
};
/**
* Apply the tool-result guard to a SessionManager exactly once and expose
* a flush method on the instance for easy teardown handling.
*/
export function guardSessionManager(
sessionManager: SessionManager,
): GuardedSessionManager {
if (typeof (sessionManager as GuardedSessionManager).flushPendingToolResults === "function") {
return sessionManager as GuardedSessionManager;
}
const guard = installSessionToolResultGuard(sessionManager);
(sessionManager as GuardedSessionManager).flushPendingToolResults =
guard.flushPendingToolResults;
return sessionManager as GuardedSessionManager;
}