import { type InstanceAiAttachment, type InstanceAiBuildMode, type InstanceAiHandoffContext, type InstanceAiConfirmRequest, type InstanceAiCredits, type InstanceAiConfirmResponse, type InstanceAiThreadStatusResponse, type InstanceAiEvalThreadMemoryResponse, type InstanceAiThreadArtifactsContext } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { EventService, Publisher } from '@n8n/backend-services'; import { GlobalConfig } from '@n8n/config'; import { UserRepository, type User } from '@n8n/db'; import { type PubSubCommandMap } from '@n8n/decorators'; import { type ModelConfig, type RunDebugRecord } from '@n8n/instance-ai'; import { ErrorReporter, InstanceSettings } from 'n8n-core'; import { AiService } from '../../services/ai.service'; import { Telemetry } from '../../telemetry'; import { InstanceAiBrowserSessionService } from './browser/instance-ai-browser-session.service'; import { EvalThreadCredentialAllowlistService } from './eval/thread-credential-allowlist.service'; import { DurableEventLog } from './event-bus/durable-event-log'; import { InProcessEventBus } from './event-bus/in-process-event-bus'; import { InterruptedRunSweeper } from './event-bus/interrupted-run-sweeper'; import { InstanceAiCreditService } from './instance-ai-credit.service'; import { InstanceAiErrorReporterService } from './instance-ai-error-reporter.service'; import { InstanceAiMemoryService } from './instance-ai-memory.service'; import { InstanceAiModelService } from './instance-ai-model.service'; import { InstanceAiRunProbe } from './instance-ai-run-probe'; import { InstanceAiSettingsService } from './instance-ai-settings.service'; import { InstanceAiTemporaryWorkflowService } from './instance-ai-temporary-workflow.service'; import { InstanceAiThreadTabsService } from './instance-ai-thread-tabs.service'; import { InstanceAiAdapterService } from './instance-ai.adapter.service'; import { InstanceAiEventLogRepository } from './repositories/instance-ai-event-log.repository'; import { InstanceAiObservationCursorRepository } from './repositories/instance-ai-observation-cursor.repository'; import { InstanceAiObservationRepository } from './repositories/instance-ai-observation.repository'; import { InstanceAiPendingConfirmationRepository } from './repositories/instance-ai-pending-confirmation.repository'; import { InstanceAiThreadGrantRepository } from './repositories/instance-ai-thread-grant.repository'; import { SelfHealingAgentService, type SelfHealingRunInput, type SelfHealingRunLifecycle, type SelfHealingRunResult } from './self-healing/self-healing-agent.service'; import { TypeORMAgentCheckpointStore } from './storage/typeorm-agent-checkpoint-store'; import { TypeORMAgentMemory } from './storage/typeorm-agent-memory'; import { AssistantAgentFactory } from './turn-setup/assistant-agent.factory'; import { AssistantTurnEnvironmentFactory } from './turn-setup/assistant-turn-environment.factory'; import { AssistantTurnInputBuilder } from './turn-setup/assistant-turn-input.builder'; export { isAssistantCreditBalanceExhausted, QuotaExhaustedStreamError, } from './turn-setup/assistant-credits'; export declare class InstanceAiService { private readonly instanceSettings; private readonly adapterService; private readonly eventBus; private readonly eventLog; private readonly interruptedRunSweeper; private readonly settingsService; private readonly browserSessionService; private readonly memoryService; private readonly agentMemory; private readonly checkpointStore; private readonly aiService; private readonly threadGrantRepo; private readonly pendingConfirmationRepo; private readonly observationRepo; private readonly observationCursorRepo; private readonly eventLogRepository; private readonly telemetry; private readonly userRepository; private readonly temporaryWorkflowService; private readonly errorReporter; private readonly eventService; private readonly evalCredentialAllowlists; private readonly modelService; private readonly creditService; private readonly publisher; private readonly instanceAiErrorReporter; private readonly threadTabsService; private readonly selfHealingAgent; private readonly turnEnvironment; private readonly turnInput; private readonly agentFactory; private readonly instanceAiConfig; private readonly aiConfig; private readonly runState; private readonly finalizingSelfHealingRuns; private readonly backgroundTasks; private readonly memoryTaskRegistry; private readonly tracing; private readonly sandboxService; private readonly domainAccessTrackersByThread; private readonly threadPushRef; private readonly pendingBrowserCredentialSetups; private readonly failedInternalFollowUpStreaks; private readonly terminalOutcome; private readonly liveness; private readonly suspendedThreads; private readonly suspendedRunRestorer; private readonly runDebugBuffer; private readonly defaultTimeZone; private readonly logger; private readonly workflowObligations; private readonly taskProjector; private readonly inFlightExecutions; private readonly preserveHitlOnShutdown; constructor(logger: Logger, globalConfig: GlobalConfig, instanceSettings: InstanceSettings, adapterService: InstanceAiAdapterService, eventBus: InProcessEventBus, eventLog: DurableEventLog, interruptedRunSweeper: InterruptedRunSweeper, settingsService: InstanceAiSettingsService, browserSessionService: InstanceAiBrowserSessionService, memoryService: InstanceAiMemoryService, agentMemory: TypeORMAgentMemory, checkpointStore: TypeORMAgentCheckpointStore, aiService: AiService, threadGrantRepo: InstanceAiThreadGrantRepository, pendingConfirmationRepo: InstanceAiPendingConfirmationRepository, observationRepo: InstanceAiObservationRepository, observationCursorRepo: InstanceAiObservationCursorRepository, eventLogRepository: InstanceAiEventLogRepository, telemetry: Telemetry, userRepository: UserRepository, temporaryWorkflowService: InstanceAiTemporaryWorkflowService, errorReporter: ErrorReporter, eventService: EventService, evalCredentialAllowlists: EvalThreadCredentialAllowlistService, runProbe: InstanceAiRunProbe, modelService: InstanceAiModelService, creditService: InstanceAiCreditService, publisher: Publisher, instanceAiErrorReporter: InstanceAiErrorReporterService, threadTabsService: InstanceAiThreadTabsService, selfHealingAgent: SelfHealingAgentService, turnEnvironment: AssistantTurnEnvironmentFactory, turnInput: AssistantTurnInputBuilder, agentFactory: AssistantAgentFactory); private createProxyRunConfig; resolveAgentModelConfig(user: User): Promise; private loadThreadSessionGrants; private persistThreadSessionGrant; private revokeThreadSessionGrant; isProxyEnabled(): boolean; getCredits(user: User): Promise; private dropTurnAttachments; private shouldDropTurnAttachments; private assertAssistantCreditsAvailable; private reclassifyMaskedStreamFailure; isEnabled(): boolean; hasActiveRun(threadId: string): boolean; isRunLive(threadId: string, runId: string): boolean; getThreadStatus(threadId: string): InstanceAiThreadStatusResponse; private memoryTaskObserverFor; isRunDebugEnabled(): boolean; private buildOrchestratorAgentStreamOptions; private buildOrchestratorResumeAgentOptions; getThreadMemory(userId: string, threadId: string): Promise; getRunDebug(runId: string): RunDebugRecord | undefined; listThreadDebugRuns(threadId: string): { runId: string; threadId: string; startedAt: number; stepCount: number; workflowCodeCount: number; label: string | undefined; }[]; clearTraceContextsForTest(): void; submitLangsmithFeedback(user: User, threadId: string, responseId: string, payload: { rating: 'up' | 'down'; comment?: string; }): Promise; private assertRunAdmissible; startSelfHealingRun(input: SelfHealingRunInput, lifecycle: SelfHealingRunLifecycle): Promise; startRun(user: User, threadId: string, message: string, attachments?: InstanceAiAttachment[], context?: InstanceAiHandoffContext, timeZone?: string, pushRef?: string, mode?: InstanceAiBuildMode, promptVersion?: string, browserUseAvailable?: boolean, threadArtifacts?: InstanceAiThreadArtifactsContext, observerThresholdTokens?: number): string; getMessageGroupId(threadId: string): string | undefined; getLiveMessageGroupId(threadId: string): string | undefined; getRunIdsForMessageGroup(messageGroupId: string): string[]; getActiveRunId(threadId: string): string | undefined; private stopRunsForQuotaExhaustion; cancelRun(threadId: string, reason?: string): void; private settleCancelledSuspension; sendCorrectionToTask(threadId: string, taskId: string, correction: string): 'queued' | 'task-completed' | 'task-not-found'; cancelBackgroundTask(threadId: string, taskId: string): void; private broadcastTaskControl; private applyTaskControlLocally; private routeTaskControl; routeCorrectionToTask(threadId: string, taskId: string, correction: string): Promise; routeCancelBackgroundTask(threadId: string, taskId: string): Promise; routeCancelRun(threadId: string): Promise; routeClearThreadState(threadId: string, userId?: string): Promise; handleRelayTaskControl(payload: PubSubCommandMap['relay-instance-ai-task-control']): Promise; 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, userId?: string): Promise; private deleteAgentBuilderSessions; shutdown(): Promise; private trackInFlightExecution; private startExecuteRun; private startProcessResumedStream; private shouldPreserveHitlOnShutdown; private drainInFlightExecutions; pruneExpiredData(now?: number, signal?: AbortSignal): Promise; private hardDeleteExpiredCheckpoints; private pruneExpiredThreads; private trackWorkflowVerificationObligation; replayUndeliveredTerminalOutcomes(threadId: string): Promise; areMcpConnectionsAvailable(): boolean; private createExecutionEnvironment; private createTurnRuntime; private buildWorkflowSetupFollowUpMessage; private getWorkflowSetupSuspensionWorkflowId; private markWorkflowSetupHandled; private maybeStartWorkflowSetupFollowUp; private listWorkflowLoopRecords; private createWorkflowSetupRoutingClaim; private claimWorkItemSetupRouting; private markWorkItemSetupRouted; private releaseWorkItemSetupRoutingClaim; private updateInternalFollowUpFailureStreak; private startInternalFollowUpRun; private persistInterruptedUserMessage; private resolveContextAttachments; private readThreadProvenance; private executeRun; resolveConfirmation(requestingUserId: string, requestId: string, request: InstanceAiConfirmRequest): Promise; private createAgentFromEnvironment; private buildFreshInstanceAgent; private rebuildSuspendedRunFromCheckpoint; private revalidateActiveUser; private rebuildAgentForResume; private resumeSuspendedRun; private processResumedStream; private settleUnclaimedResume; private emitTerminalRun; private bestEffort; private snapshotAttachedAgents; private trackConfirmationRequest; private finalizeCancelledSuspendedRun; private publishRunFinish; private telemetryModelId; private createBrowserCredentialSetupTracker; private emitBrowserCredentialSetupOutcomes; private finalizeRun; private static readonly BLOCK_CHARS_PER_TOKEN; private persistSuspendedInstanceContext; private instanceContextTurnBinding; private createRunEventBus; private emitInstanceContextTurn; private emitRunMetrics; private refineTitleIfNeeded; private readRunEvents; }