import type { AgentMessageAuthor, AgentSessionQueryFilters, AgentSessionStatus } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { ErrorReporter, StorageConfig } from 'n8n-core'; import type { AgentRunTelemetryType, IAgentConfigurationTelemetryProperties } from '../../interfaces'; import { Telemetry } from '../../telemetry'; import { AgentChatAttachmentService, type StoredAttachmentRef } from './agent-chat-attachment.service'; import { AgentExecutionUpdateBroadcaster } from './agent-execution-update-broadcaster'; import { AgentExecutionThread } from './entities/agent-execution-thread.entity'; import { AgentExecution } from './entities/agent-execution.entity'; import type { MessageRecord, TimelineEvent } from './execution-recorder'; import { AgentExecutionLogStore } from './execution-log/agent-execution-log-store'; import { N8nMemory } from './integrations/n8n-memory'; import { AgentExecutionThreadRepository } from './repositories/agent-execution-thread.repository'; import type { AgentExecutionThreadMetadata } from './repositories/agent-execution-thread.repository'; import { AgentExecutionRepository, type RunningAgentExecution } from './repositories/agent-execution.repository'; import { type ThreadFailureSummary } from './utils/execution-failure-summary'; export interface RecordMessageParams { threadId: string; agentId: string; agentName: string; projectId: string; userMessage: string | null; author?: AgentMessageAuthor; attachments?: StoredAttachmentRef[]; record: MessageRecord; hitlStatus?: 'suspended' | 'resumed'; source?: string; threadMetadata?: AgentExecutionThreadMetadata; taskId?: string; taskVersionId?: string; telemetry?: { userId?: string; runType: AgentRunTelemetryType; configuration: IAgentConfigurationTelemetryProperties; }; } export interface StartExecutionParams extends Omit { initialTimeline?: TimelineEvent[]; } interface TimelineSnapshotParams { executionId: string; projectId: string; agentId: string; threadId: string; timeline: TimelineEvent[]; } export interface ThreadDetail { thread: AgentExecutionThread; executions: AgentExecution[]; } export interface ThreadListItem extends Omit { firstMessage: string | null; source: string | null; failureSummary: ThreadFailureSummary | null; status: AgentSessionStatus | null; } export declare class AgentExecutionService { private readonly logger; private readonly agentExecutionRepository; private readonly agentExecutionThreadRepository; private readonly n8nMemory; private readonly telemetry; private readonly agentChatAttachmentService; private readonly agentExecutionLogStore; private readonly storageConfig; private readonly errorReporter; private readonly executionUpdateBroadcaster; private static readonly logDeletionBatchSize; private static readonly heartbeatIntervalMs; private readonly heartbeatTimers; private readonly pendingTimelineSnapshots; private readonly timelineSnapshotWrites; private readonly executionsNeedingTitleSync; constructor(logger: Logger, agentExecutionRepository: AgentExecutionRepository, agentExecutionThreadRepository: AgentExecutionThreadRepository, n8nMemory: N8nMemory, telemetry: Telemetry, agentChatAttachmentService: AgentChatAttachmentService, agentExecutionLogStore: AgentExecutionLogStore, storageConfig: StorageConfig, errorReporter: ErrorReporter, executionUpdateBroadcaster: AgentExecutionUpdateBroadcaster); startExecutionRecording(params: StartExecutionParams, startedAt: Date): Promise; recordTimelineSnapshot({ executionId, ...snapshot }: TimelineSnapshotParams): void; finalizeExecution(executionId: string, params: RecordMessageParams): Promise; private deleteUnreferencedTimelineBlob; finalizeInterruptedExecution(execution: RunningAgentExecution): Promise; private notifyInterruptedExecution; private startHeartbeat; private stopHeartbeat; private ensureTimelineSnapshotWrite; private drainTimelineSnapshots; private prepareThread; private completeRecordedExecution; findLatestSuspendedRun(threadId: string): Promise; private backfillSuspendedExecutions; private syncTitleFromMemory; deleteThread(projectId: string, agentId: string, threadId: string): Promise; deleteExecutionLogsForAgent(agentId: string): Promise; getThreads(projectId: string, agentId: string, limit: number, cursor?: string, filters?: AgentSessionQueryFilters): Promise<{ threads: ThreadListItem[]; nextCursor: string | null; }>; getThreadDetail(threadId: string, projectId: string, agentId: string): Promise; private hydrateTimelines; findThreadById(threadId: string): Promise; private toBlobRefs; } export declare function threadBelongsTo(thread: AgentExecutionThread, projectId: string, agentId: string): boolean; export {};