import type { SerializableAgentState } from '@n8n/agents'; import type { AgentSseEvent, AgentThreadUsageResponse } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { TransactionRunner, type User } from '@n8n/db'; import { AgentChatAttachmentService } from '../agent-chat-attachment.service'; import { AgentChatExecutionService } from '../agent-chat-execution.service'; import { AgentConversationStateService } from '../agent-conversation-state.service'; import { AgentExecutionService } from '../agent-execution.service'; import type { ClaimedAgentMessage } from '../agent-message-queue.service'; import { AgentMessageQueueService } from '../agent-message-queue.service'; import { AgentTurnExecutionService } from '../agent-turn-execution.service'; import type { AgentExecutionThread } from '../entities/agent-execution-thread.entity'; import { N8NCheckpointStorage } from '../integrations/n8n-checkpoint-storage'; import { N8nMemory } from '../integrations/n8n-memory'; import { AgentExecutionRepository } from '../repositories/agent-execution.repository'; import { AgentExecutionThreadRepository, type AgentExecutionThreadKeyset, type AgentExecutionThreadKeysetPage } from '../repositories/agent-execution-thread.repository'; import { AgentThreadGrantRepository } from '../repositories/agent-thread-grant.repository'; import type { StoredAttachmentRef } from '../types/agent-chat-attachment'; import { SystemAgentRegistry } from './system-agent-registry'; import type { SystemAgentProvider, SystemAgentTurnOptions } from './system-agent.types'; export type SystemAgentThreadStatus = 'running' | 'suspended' | 'idle'; type SystemQueueInput = Parameters[0]; interface SystemMessageInput { message: string; attachments?: StoredAttachmentRef[]; options?: SystemAgentTurnOptions; messageId?: string; hidden?: boolean; } interface ResumeParams { agentId: string; user: User; threadId: string; resumeData: unknown; runId?: string; toolCallId?: string; send?: (event: AgentSseEvent) => void; onExecutionStarted?: ExecutionStartedCallback; } type ExecutionStartedCallback = (executionId: string, threadId: string, inputMessageIds: string[]) => void; interface ResumeHandle { runId: string; toolCallId: string; done: Promise; } export declare class SystemAgentExecutionService { private readonly logger; private readonly registry; private readonly threadRepository; private readonly executionRepository; private readonly executionService; private readonly turnExecutionService; private readonly messageQueue; private readonly chatExecutionService; private readonly checkpointStorage; private readonly txRunner; private readonly attachmentService; private readonly conversationState; private readonly n8nMemory; private readonly threadGrants; constructor(logger: Logger, registry: SystemAgentRegistry, threadRepository: AgentExecutionThreadRepository, executionRepository: AgentExecutionRepository, executionService: AgentExecutionService, turnExecutionService: AgentTurnExecutionService, messageQueue: AgentMessageQueueService, chatExecutionService: AgentChatExecutionService, checkpointStorage: N8NCheckpointStorage, txRunner: TransactionRunner, attachmentService: AgentChatAttachmentService, conversationState: AgentConversationStateService, n8nMemory: N8nMemory, threadGrants: AgentThreadGrantRepository); resourceIdFor(user: Pick): string; getProvider(agentId: string): SystemAgentProvider; assertRegistered(agentId: string): void; assertCanUse(agentId: string, user: User, projectId: string): Promise; getUsableThread(agentId: string, user: User, threadId: string): Promise; findUsableThread(agentId: string, user: User, threadId: string): Promise; private findOwnedThread; createThread(params: { agentId: string; user: User; projectId: string; threadId?: string; title?: string; }): Promise; private resolveSession; listThreads(agentId: string, user: User, options: { limit: number; search?: string; before?: AgentExecutionThreadKeyset; }): Promise; getThread(agentId: string, user: User, threadId: string): Promise; updateThread(agentId: string, user: User, threadId: string, changes: { title?: string; projectId?: string; }): Promise; deleteThread(agentId: string, user: User, threadId: string): Promise; stopThreadsOfUser(userId: string): Promise; deleteThreadsOfUser(userId: string): Promise; private findDescendantSessions; private stopRunningTurn; private deleteOwnedThread; destroyThreadWorkspace(agentId: string, threadId: string, userId?: string): Promise; getStatus(thread: AgentExecutionThread): Promise<{ status: SystemAgentThreadStatus; latestExecutionId: string | null; checkpoint: SerializableAgentState | null; }>; private resolveStatus; getUsage(thread: AgentExecutionThread): Promise; sendMessage(params: SystemMessageInput & { agentId: string; user: User; threadId: string; }): Promise<{ status: 'accepted'; item: import("../entities/agent-message-queue.entity").AgentMessageQueue; } | { status: 'duplicate'; }>; steerIntoRunningTurn(thread: AgentExecutionThread, user: User, queueId: string): Promise; consume(claim: ClaimedAgentMessage, user: User, signal: AbortSignal, send: (event: AgentSseEvent) => void): Promise; resume(params: ResumeParams): Promise; private startResume; prepareChatMessage(params: { agentId: string; user: User; projectId?: string; sessionId?: string; message: string; messageId?: string; clientContext?: Record; storeAttachments?: (threadId: string, projectId: string) => Promise; }): Promise; private queueInput; resumeRun(params: { agentId: string; user: User; runId: string; toolCallId: string; resumeData: unknown; send: (event: AgentSseEvent) => void; onExecutionStarted?: ExecutionStartedCallback; }): Promise; cancel(agentId: string, user: User, threadId: string): Promise; private turnStateOf; private readTurnAttachment; private readThreadFile; private attachFileStore; private acquireWorkspace; private prepareOrRelease; private formatSetupError; private createHostEventChannel; private runTurn; private turnErrorFormatter; private formatTurnError; } export {};