import { type Agent as RuntimeAgent, type StreamChunk } from '@n8n/agents'; import type { AgentBackgroundJobSignal, AgentMessageAuthor, AgentPersistedMessageDto } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { AiConfig } from '@n8n/config'; import type { User } from '@n8n/db'; import { ExternalHooks } from '../../external-hooks'; import type { AgentRunTelemetryType, IAgentConfigurationTelemetryProperties } from '../../interfaces'; import { Telemetry } from '../../telemetry'; import { AgentExecutionService } from './agent-execution.service'; import { AgentRunTracingService } from './agent-run-tracing.service'; import { AgentRuntimeCacheService } from './agent-runtime-cache.service'; import { type AgentSandboxPrincipalHash } from './agent-sandbox-principal'; import { AgentSandboxRuntimeService } from './agent-sandbox-runtime.service'; import { AgentTurnExecutionService } from './agent-turn-execution.service'; import type { IntegrationMessageContext, SessionBinding } from './integrations/integration-tool-types'; import { IntegrationMessageContextService } from './integrations/integration-message-context.service'; import { N8NCheckpointStorage } from './integrations/n8n-checkpoint-storage'; import { AgentRepository } from './repositories/agent.repository'; import type { ToolRegistry } from './tool-registry'; import type { StoredAttachmentRef } from './agent-chat-attachment.service'; export interface AgentMemoryScope { threadId: string; resourceId: string; } export interface ExecuteForChatConfig { agentId: string; projectId: string; message: string; user: User; memory: AgentMemoryScope; attachments?: StoredAttachmentRef[]; source?: string; previewChat?: boolean; onExecutionRecorded?: (executionId: string) => void; abortSignal?: AbortSignal; } export interface ExecuteForChatPublishedConfig { messageContext?: IntegrationMessageContext | null; contextConversation?: SessionBinding; agentId: string; projectId: string; message: string; modelMessage?: string; author?: AgentMessageAuthor; memory: AgentMemoryScope; attachments?: StoredAttachmentRef[]; integrationType?: string; sandboxPrincipalHash: AgentSandboxPrincipalHash; } export interface ResumeForChatConfig { messageContext?: IntegrationMessageContext | null; contextConversation?: SessionBinding; agentId: string; projectId: string; runId: string; toolCallId: string; resumeData: unknown; expectedMemory?: Partial; source?: string; user?: User; usePublishedVersion?: boolean; integrationType?: string; previewChat?: boolean; onExecutionRecorded?: (executionId: string) => void; abortSignal?: AbortSignal; } export interface ExecuteForTaskPublishedConfig { agentId: string; projectId: string; message: string; memory: AgentMemoryScope; taskId: string; taskVersionId: string; } export interface ExecuteForTaskNowConfig { agentId: string; projectId: string; user: User; message: string; memory: AgentMemoryScope; taskId: string; } export interface ExecuteForWakeConfig { backgroundJobSignal: AgentBackgroundJobSignal; agentId: string; projectId: string; message: string; memory: AgentMemoryScope; abortSignal: AbortSignal; identity: { type: 'draft'; user: User; principalHash: AgentSandboxPrincipalHash; } | { type: 'published'; integrationType: string; principalHash: AgentSandboxPrincipalHash; }; } export interface StreamChatResponseConfig { messageContext?: IntegrationMessageContext | null; agentInstance: RuntimeAgent; toolRegistry: ToolRegistry; mcpServerAttributions: Map; agentId: string; userId?: string; message: string; modelMessage?: string; author?: AgentMessageAuthor; attachments?: StoredAttachmentRef[]; memory: AgentMemoryScope; projectId: string; source?: string; taskId?: string; taskVersionId?: string; telemetry: { runType: AgentRunTelemetryType; configuration: IAgentConfigurationTelemetryProperties; }; onExecutionRecorded?: (executionId: string) => void; abortSignal?: AbortSignal; includeHitlToolDetails?: boolean; sandboxPrincipalHash: AgentSandboxPrincipalHash; hideUserMessageFromTranscript?: boolean; isWakeRun?: boolean; backgroundJobSignal?: AgentBackgroundJobSignal; } export declare class AgentExecutionOrchestratorService { private readonly logger; private readonly n8nCheckpointStorage; private readonly agentExecutionService; private readonly turnExecutionService; private readonly telemetry; private readonly runtimeCacheService; private readonly integrationMessageContextService; private readonly agentRunTracingService; private readonly externalHooks; private readonly agentSandboxRuntimeService; private readonly agentRepository; private readonly aiConfig; constructor(logger: Logger, n8nCheckpointStorage: N8NCheckpointStorage, agentExecutionService: AgentExecutionService, turnExecutionService: AgentTurnExecutionService, telemetry: Telemetry, runtimeCacheService: AgentRuntimeCacheService, integrationMessageContextService: IntegrationMessageContextService, agentRunTracingService: AgentRunTracingService, externalHooks: ExternalHooks, agentSandboxRuntimeService: AgentSandboxRuntimeService, agentRepository: AgentRepository, aiConfig: AiConfig); getConversationHistory(params: { threadId: string; projectId: string; agentId: string; }): Promise; cancelChatRun(params: { agentId: string; runId: string; resourceId: string; }): Promise; private loadResumeCheckpoint; resumeForChat(config: ResumeForChatConfig): AsyncGenerator; executeForChat(config: ExecuteForChatConfig): AsyncGenerator; executeForChatPublished(config: ExecuteForChatPublishedConfig): AsyncGenerator; executeForTaskPublished(config: ExecuteForTaskPublishedConfig): AsyncGenerator; executeForTaskNow(config: ExecuteForTaskNowConfig): AsyncGenerator; executeForWake(config: ExecuteForWakeConfig): Promise; private streamWakeResponse; private getWakeDelivery; streamChatResponse(config: StreamChatResponseConfig): AsyncGenerator; private withRuntimeLease; private requestPendingBackgroundWake; private getRuntimeOrRecordFailure; }