import type { Agent as RuntimeAgent, ExecutionOptions, ResumeOptions, RunOptions } from '@n8n/agents'; import type { AgentBackgroundJobSignal } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import type { AgentChatSurface, AgentSessionMode } from './utils/agent-thread-access'; import { AgentChatExecutionService } from './agent-chat-execution.service'; import { AgentKnowledgeUsageTracker } from './agent-knowledge-usage-tracker'; import { AgentMessageQueueService } from './agent-message-queue.service'; import { AgentMessageSteeringService } from './agent-message-steering.service'; import type { AgentExecutionStreamChunk } from './types/agent-steering'; import type { AgentTurnFinalizeOutcome, FormattedTurnError } from './types/agent-turn-outcome'; import { AgentSandboxFilesService } from './agent-sandbox-files.service'; import { AgentToolApprovalService } from './agent-tool-approval.service'; import { type AgentExecutionAdmission } from './types/agent-queued-message'; import { AgentExecutionService, type RecordMessageParams, type StartExecutionParams } from './agent-execution.service'; import { ExecutionRecorder } from './execution-recorder'; import type { ToolRegistry } from './tool-registry'; type RecordingContext = Pick; export type AgentTurnRequest = { recording: StartExecutionParams; } & ({ type: 'start'; input: Parameters[0]; options: RunOptions & ExecutionOptions; } | { type: 'resume'; resumeData: unknown; options: ResumeOptions & ExecutionOptions; }); interface ExecuteTurnConfig { admittedExecution?: AgentExecutionAdmission; onAdmitted?: () => Promise; agentInstance: RuntimeAgent; toolRegistry: ToolRegistry; mcpServerAttributions: Map; context: RecordingContext; prepare: () => Promise; backgroundJobSignal?: AgentBackgroundJobSignal; chatSurface?: AgentChatSurface; acceptsSteering?: boolean; chatController?: AbortController; automaticPreviewContinuation?: boolean; onExecutionStarted?: (executionId: string, sessionId: string, inputMessageIds: string[]) => void; onExecutionRecorded?: (executionId: string) => void; onSettled?: (suspended: boolean) => Promise; onBeforeFinalize?: (outcome: AgentTurnFinalizeOutcome) => Promise; formatError?: (error: unknown) => Promise; onRecorderCreated?: (recorder: ExecutionRecorder) => void; } export declare class AgentTurnExecutionService { private readonly logger; private readonly agentExecutionService; private readonly chatExecutionService; private readonly messageQueue; private readonly steering; private readonly toolApprovalService; private readonly knowledgeUsageTracker; private readonly sandboxFiles; constructor(logger: Logger, agentExecutionService: AgentExecutionService, chatExecutionService: AgentChatExecutionService, messageQueue: AgentMessageQueueService, steering: AgentMessageSteeringService, toolApprovalService: AgentToolApprovalService, knowledgeUsageTracker: AgentKnowledgeUsageTracker, sandboxFiles: AgentSandboxFilesService); getSessionMode(threadId: string): Promise; execute(config: ExecuteTurnConfig): AsyncGenerator; private isStoppedTurn; private createChatExecutionControl; private startTurn; private streamTurn; private settleTurn; private finalizeTurn; private sendKnowledgeUsage; private isCancelled; private syncSandboxOutputs; private runBeforeFinalize; createRecorder(toolRegistry?: ToolRegistry, getExecutionId?: () => string | undefined, context?: RecordingContext, backgroundJobSignal?: AgentBackgroundJobSignal, startedAt?: Date): ExecutionRecorder; startExecution(params: StartExecutionParams, startedAt: Date, executionError?: unknown): Promise; finalizeExecution(args: { executionId: string; executionStarted: boolean; executionError?: unknown; onExecutionRecorded?: (executionId: string) => void; params: RecordMessageParams; runId?: string; }): Promise; recordFailedAdmission(admission: AgentExecutionAdmission, params: StartExecutionParams, executionError: unknown): Promise; recordFailedStart(params: StartExecutionParams, executionError: unknown, onExecutionRecorded?: (executionId: string) => void, options?: { previewChat?: boolean; automaticContinuationRunId?: string; }): Promise; private admitTurn; private recordTurnStart; private startAcceptedTurn; private streamStartTurnNotices; } export {};