import { type InstanceAiAttachment, type InstanceAiConfirmRequest, type InstanceAiThreadStatusResponse } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { GlobalConfig, SsrfProtectionConfig } from '@n8n/config'; import { AiBuilderTemporaryWorkflowRepository, UserRepository, type User } from '@n8n/db'; import { type ModelConfig } from '@n8n/instance-ai'; import { ErrorReporter, InstanceSettings, SsrfProtectionService } from 'n8n-core'; import { InProcessEventBus } from './event-bus/in-process-event-bus'; import { InstanceAiGatewayService } from './instance-ai-gateway.service'; import { InstanceAiMemoryService } from './instance-ai-memory.service'; import { InstanceAiSettingsService } from './instance-ai-settings.service'; import { InstanceAiAdapterService } from './instance-ai.adapter.service'; import { InstanceAiMcpRegistryService } from './mcp'; import { InstanceAiPendingConfirmationRepository } from './repositories/instance-ai-pending-confirmation.repository'; import { InstanceAiThreadRepository } from './repositories/instance-ai-thread.repository'; import { DbIterationLogStorage } from './storage/db-iteration-log-storage'; import { DbSnapshotStorage } from './storage/db-snapshot-storage'; import { TypeORMAgentCheckpointStore } from './storage/typeorm-agent-checkpoint-store'; import { TypeORMAgentMemory } from './storage/typeorm-agent-memory'; import { EventService } from '../../events/event.service'; import { SourceControlPreferencesService } from '../../modules/source-control.ee/source-control-preferences.service.ee'; import { Push } from '../../push'; import { AiService } from '../../services/ai.service'; import { UrlService } from '../../services/url.service'; import { Telemetry } from '../../telemetry'; export declare class InstanceAiService { private readonly instanceSettings; private readonly adapterService; private readonly eventBus; private readonly settingsService; private readonly gatewayService; private readonly memoryService; private readonly agentMemory; private readonly checkpointStore; private readonly aiService; private readonly push; private readonly threadRepo; private readonly pendingConfirmationRepo; private readonly urlService; private readonly dbSnapshotStorage; private readonly dbIterationLogStorage; private readonly sourceControlPreferencesService; private readonly telemetry; private readonly mcpRegistryService; private readonly userRepository; private readonly aiBuilderTemporaryWorkflowRepository; private readonly errorReporter; private readonly eventService; private _mcpClientManager?; private readonly _ssrfProtectionConfig; private readonly _ssrfProtectionService; private get mcpClientManager(); private readonly instanceAiConfig; private readonly oauth2CallbackUrl; private readonly webhookBaseUrl; private readonly formBaseUrl; private readonly runState; private readonly backgroundTasks; private readonly traceContextsByRunId; private readonly sandboxes; private readonly sandboxCreations; private readonly domainAccessTrackersByThread; private readonly threadPushRef; private readonly planRequestsByThread; private readonly schedulerLocks; private readonly pendingCheckpointReentries; private readonly pendingTerminalOutcomes; private terminalOutcomeStorage?; private readonly liveness; private readonly creditedThreads; private readonly traceReplay; private readonly defaultTimeZone; private readonly logger; private readonly workflowObligations; private readonly taskProjector; private checkpointPruneTimer; private checkpointPruningStopped; private readonly inFlightExecutions; private readonly preserveHitlOnShutdown; private readonly userMessagePersistenceByRun; constructor(logger: Logger, globalConfig: GlobalConfig, instanceSettings: InstanceSettings, adapterService: InstanceAiAdapterService, eventBus: InProcessEventBus, settingsService: InstanceAiSettingsService, gatewayService: InstanceAiGatewayService, memoryService: InstanceAiMemoryService, agentMemory: TypeORMAgentMemory, checkpointStore: TypeORMAgentCheckpointStore, aiService: AiService, push: Push, threadRepo: InstanceAiThreadRepository, pendingConfirmationRepo: InstanceAiPendingConfirmationRepository, urlService: UrlService, dbSnapshotStorage: DbSnapshotStorage, dbIterationLogStorage: DbIterationLogStorage, sourceControlPreferencesService: SourceControlPreferencesService, telemetry: Telemetry, mcpRegistryService: InstanceAiMcpRegistryService, userRepository: UserRepository, aiBuilderTemporaryWorkflowRepository: AiBuilderTemporaryWorkflowRepository, errorReporter: ErrorReporter, ssrfProtectionConfig: SsrfProtectionConfig, ssrfProtectionService: SsrfProtectionService, eventService: EventService); private getSandboxConfigFromEnv; private resolveSandboxConfig; private getOrCreateWorkspaceEntry; private getOrCreateWorkspace; private ensureWorkspaceSetup; private createWorkspaceEntry; private evictSandboxEntry; private destroySandbox; private get sandboxTtlMs(); private nextSandboxExpiry; private isSandboxEntryExpired; private touchSandboxEntry; private isSandboxInUse; private scheduleSandboxExpiry; private stopSandboxExpiryTimers; private getProxyAuth; resolveAgentModelConfig(user: User): Promise; private resolveProxyModel; private resolveHttpProxyModel; private countCreditsIfFirst; isProxyEnabled(): boolean; getCredits(user: User): Promise<{ creditsQuota: number; creditsClaimed: number; }>; isEnabled(): boolean; hasActiveRun(threadId: string): boolean; getThreadStatus(threadId: string): InstanceAiThreadStatusResponse; private storeTraceContext; private getTraceContext; private getTraceContextForContinuation; private createOrchestratorResumeTraceContext; private configureTraceReplayMode; private finalizeMessageTraceRoot; private maybeFinalizeRunTraceRoot; private buildMessageTraceMetadata; private finalizeRemainingMessageTraceRoots; private deleteTraceContextsForThread; private deleteTraceContextsForSlug; clearTraceContextsForTest(): void; private finalizeDetachedTraceRun; private finalizeRunTracing; private finalizeBackgroundTaskTracing; submitLangsmithFeedback(user: User, threadId: string, responseId: string, payload: { rating: 'up' | 'down'; comment?: string; }): Promise; startRun(user: User, threadId: string, message: string, attachments?: InstanceAiAttachment[], timeZone?: string, pushRef?: string): string; getMessageGroupId(threadId: string): string | undefined; getLiveMessageGroupId(threadId: string): string | undefined; getRunIdsForMessageGroup(messageGroupId: string): string[]; getActiveRunId(threadId: string): string | undefined; cancelRun(threadId: string, reason?: string): void; sendCorrectionToTask(threadId: string, taskId: string, correction: string): 'queued' | 'task-completed' | 'task-not-found'; cancelBackgroundTask(threadId: string, taskId: string): void; cancelAllBackgroundTasks(): number; startStuckBackgroundTaskForTest(user: User, threadId: string): Promise<{ threadId: string; runId: string; messageGroupId: string; taskId: string; agentId: string; timeoutAt: number; }>; runLivenessSweepForTest(now?: number): Promise; loadTraceEvents(slug: string, events: unknown[]): void; getTraceEvents(slug: string): unknown[]; hasRunningWorkForTest(): boolean; activateTraceSlug(slug: string): void; clearTraceEvents(slug: string): void; clearThreadState(threadId: string): Promise; shutdown(): Promise; startCheckpointPruning(): void; stopCheckpointPruning(): void; private scheduleCheckpointPrune; private trackInFlightExecution; private startExecuteRun; private startProcessResumedStream; private shouldPreserveHitlOnShutdown; private persistUserMessageOnFirstSuspend; private drainInFlightExecutions; private runScheduledPrune; private pruneExpiredThreads; private pruneStalePendingConfirmations; private computePendingConfirmationExpiresAt; private persistPendingConfirmation; private dropPendingConfirmation; private dropPendingConfirmationsForThread; private persistUserMessageOnSuspend; private persistShutdownSnapshot; private createAgentMemoryOptions; private createWorkflowTaskServiceWithUiSync; private trackWorkflowVerificationObligation; private buildPlannedTaskFollowUpMessage; private buildWorkflowVerificationFollowUpMessage; private createPlannedTaskState; private evaluateTerminalResponse; private evaluateWaitingResponse; private getTerminalGuardEvents; private handleTerminalResponseDecision; private createTerminalOutcomeStorage; private finishInvalidConfirmationRun; private buildBackgroundTerminalOutcome; replayUndeliveredTerminalOutcomes(threadId: string, options?: { delivery?: 'snapshot' | 'event'; }): Promise; private persistTerminalOutcomeLineToSnapshot; private publishTerminalOutcomeLine; private recordBackgroundTerminalOutcome; private syncPlannedTasksToUi; private cancelAwaitingApprovalPlan; private createExecutionEnvironment; private dispatchPlannedTask; private createPlannedTaskContext; private collectWorkflowIds; private getBuildTaskWorkflowName; private checkpointRequiresRunApproval; private getCheckpointRunPolicy; private handlePlannedTaskSettlement; private maybeStartWorkflowVerificationFollowUp; private buildWorkflowSetupFollowUpMessage; private maybeStartWorkflowSetupFollowUp; private listWorkflowLoopRecords; private createWorkflowSetupRoutingClaim; private claimWorkItemSetupRouting; private markWorkItemSetupRouted; private releaseWorkItemSetupRoutingClaim; private startInternalFollowUpRun; private schedulePlannedTasks; private createPlannedTaskActionRunner; private createPlannedTaskView; private createPlannedTaskRunGate; private createPlannedTaskDispatcher; private createPlannedTaskFollowUps; private createPlannedWorkflowVerificationGate; private toWorkflowVerificationSourceTask; private createPlannedWorkflowVerificationTracker; private createPlannedTaskDispatchContext; private doSchedulePlannedTasks; private executeRun; private queuePendingCheckpointReentry; private drainPendingCheckpointReentries; private reenterCheckpointById; private maybeReenterParentCheckpoint; private finalizeCheckpointFollowUp; private finalizePlannedBuildFollowUp; resolveConfirmation(requestingUserId: string, requestId: string, request: InstanceAiConfirmRequest): Promise; private resolveOrphanedConfirmation; private canResumeOrphan; private finalizeUnresumableOrphan; private tryResumeFromOrphan; private rebuildSuspendedRunFromCheckpoint; private revalidateActiveUser; private resumeSuspendedRun; private processResumedStream; private spawnBackgroundTask; private buildMessageWithRunningTasks; private trackConfirmationRequest; private reapAiTemporaryFromRun; private archiveAiTemporaryWorkflows; private finalizeCancelledSuspendedRun; private reapAiTemporaryForThreadCleanup; private publishRunFinish; private finalizeRun; private refineTitleIfNeeded; private extractStoredMessageText; private saveAgentTreeSnapshot; private parseMcpServers; }