import { type IAdminForth } from "adminforth"; import type { AgentSessionStore } from "../persistence/sessionStore.js"; import type { SteerBuffer } from "../domain/steerBuffer.js"; import type { PluginOptions } from "../types.js"; import type { LlmPort } from "./ports.js"; import type { BaseAgentTurnInput, DebugSink, HandleTurnInput, HandleEditTurnInput, PendingInterrupt, RunAndPersistAgentResponseInput, RunAndPersistAgentResponseResult } from "../domain/turnTypes.js"; /** * Build the provider-agnostic resume payload for a human-in-the-loop turn. * Exported for unit testing; the LLM port wraps it into a LangGraph Command. */ export declare function buildResumeValue(input: { decision: "approve" | "reject"; interrupts?: PendingInterrupt[]; prompt?: string; }): { decisions: ({ type: "approve"; message?: undefined; } | { type: "reject"; message: string; })[]; } | { [k: string]: { decisions: ({ type: "approve"; message?: undefined; } | { type: "reject"; message: string; })[]; }; }; export type RunTurnUseCaseDeps = { llm: LlmPort; sessions: AgentSessionStore; /** Per-session buffer of mid-turn steering instructions; cleared when a turn ends unconsumed. */ steerBuffer: SteerBuffer; modes: PluginOptions["modes"]; getAdminforth: () => IAdminForth; getAgentSystemPrompt: () => Promise; /** True when a persistent checkpointer is configured (not the in-memory MemorySaver). */ hasPersistentCheckpointer: boolean; /** * True when `turnResource.checkpointIdField` is configured — the tip checkpoint id * is then recorded per turn, enabling message editing / branching. */ turnCheckpointsEnabled: boolean; /** Resource config used for the edit ownership check + turn lookups. */ sessionResource: PluginOptions["sessionResource"]; /** Factory for the per-turn debug sink; the concrete impl lives in the llm layer. */ createDebugSink: () => DebugSink; }; /** * Single entry point for running an agent turn: prepare (start/resume) → build * the prompt → stream from the LLM port → consume the typed stream into SSE * events → persist the result. Replaces the former AgentTurnService plus the * TurnLifecycle/Context/Prompt/Persistence/StreamConsumer + ModeResolver stack. */ export declare class RunTurnUseCase { private readonly deps; private readonly pendingInterrupts; private readonly lastDetectedLanguage; constructor(deps: RunTurnUseCaseDeps); private resolveMode; private buildContext; /** * Resolve the pending HITL interrupts for a resume. With a persistent checkpointer the * checkpoint is authoritative (correct across instances and restarts); with the in-memory * MemorySaver the in-process cache is authoritative (single process, cannot be stale). */ private resolvePendingInterrupts; private requiresSessionOwnership; /** Verify the session exists and belongs to the requesting admin user. */ assertSessionOwnership(sessionId: string, adminUser: BaseAgentTurnInput["adminUser"]): Promise; /** * Prepare an edit/branch turn: resolve the fork checkpoint from the previous turn, * truncate the conversation after the edited turn, and reuse the edited turn's id * for the regenerated response. Ownership is already asserted by `prepareTurn`. */ private prepareEditTurn; private prepareTurn; private resolveUserLanguage; private buildMessages; private handleInterrupt; private runAgentTurn; runAndPersistAgentResponse(input: RunAndPersistAgentResponseInput): Promise; handleTurn(input: HandleTurnInput): Promise; handleEditTurn(input: HandleEditTurnInput): Promise; }