UNPKG

n8n

Version:

n8n Workflow Automation Tool

94 lines (93 loc) 4.74 kB
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'; export interface RecordMessageParams { threadId: string; agentId: string; agentName: string; projectId: string; userMessage: string | null; attachments?: StoredAttachmentRef[]; record: MessageRecord; hitlStatus?: 'suspended' | 'resumed'; source?: string; threadMetadata?: AgentExecutionThreadMetadata; taskId?: string; taskVersionId?: string; telemetry?: { runType: AgentRunTelemetryType; configuration: IAgentConfigurationTelemetryProperties; }; } export type StartExecutionParams = Omit<RecordMessageParams, 'record' | 'hitlStatus'>; interface TimelineSnapshotParams { executionId: string; projectId: string; agentId: string; threadId: string; timeline: TimelineEvent[]; } export interface ThreadDetail { thread: AgentExecutionThread; executions: AgentExecution[]; } export interface ThreadListItem extends Omit<AgentExecutionThread, 'generateId' | 'setUpdateDate'> { firstMessage: string | null; source: string | 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<string>; recordTimelineSnapshot({ executionId, ...snapshot }: TimelineSnapshotParams): void; finalizeExecution(executionId: string, params: RecordMessageParams): Promise<string>; finalizeInterruptedExecution(execution: RunningAgentExecution): Promise<boolean>; private notifyInterruptedExecution; private startHeartbeat; private stopHeartbeat; private ensureTimelineSnapshotWrite; private drainTimelineSnapshots; private prepareThread; private completeRecordedExecution; findLatestSuspendedRun(threadId: string): Promise<AgentExecution | null>; private backfillSuspendedExecutions; private syncTitleFromMemory; deleteThread(projectId: string, agentId: string, threadId: string): Promise<boolean>; deleteExecutionLogsForAgent(agentId: string): Promise<void>; getThreads(projectId: string, agentId: string, limit: number, cursor?: string): Promise<{ threads: ThreadListItem[]; nextCursor: string | null; }>; getThreadDetail(threadId: string, projectId: string, agentId: string): Promise<ThreadDetail | null>; private hydrateTimelines; findThreadById(threadId: string): Promise<AgentExecutionThread | null>; private toBlobRefs; } export declare function threadBelongsTo(thread: AgentExecutionThread, projectId: string, agentId: string): boolean; export {};