import { type InstanceAiAttachment, type InstanceAiConfirmRequest, type InstanceAiThreadStatusResponse, type InstanceAiGatewayCapabilities, type McpToolCallResult, type ToolCategory } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { GlobalConfig } from '@n8n/config'; import { ErrorReporter } from 'n8n-core'; import { AiBuilderTemporaryWorkflowRepository, UserRepository, type User } from '@n8n/db'; import { UrlService } from '../../services/url.service'; import { type ModelConfig } from '@n8n/instance-ai'; import { SourceControlPreferencesService } from '../../modules/source-control.ee/source-control-preferences.service.ee'; import { AiService } from '../../services/ai.service'; import { Push } from '../../push'; import { Telemetry } from '../../telemetry'; import { InProcessEventBus } from './event-bus/in-process-event-bus'; import type { LocalGateway } from './filesystem'; import { InstanceAiSettingsService } from './instance-ai-settings.service'; import { InstanceAiAdapterService } from './instance-ai.adapter.service'; import { TypeORMCompositeStore } from './storage/typeorm-composite-store'; import { DbSnapshotStorage } from './storage/db-snapshot-storage'; import { DbIterationLogStorage } from './storage/db-iteration-log-storage'; import { InstanceAiCompactionService } from './compaction.service'; import { InstanceAiThreadRepository } from './repositories/instance-ai-thread.repository'; export declare class InstanceAiService { private readonly adapterService; private readonly eventBus; private readonly settingsService; private readonly compositeStore; private readonly compactionService; private readonly aiService; private readonly push; private readonly threadRepo; private readonly urlService; private readonly dbSnapshotStorage; private readonly dbIterationLogStorage; private readonly sourceControlPreferencesService; private readonly telemetry; private readonly userRepository; private readonly aiBuilderTemporaryWorkflowRepository; private readonly errorReporter; private readonly mcpClientManager; private readonly instanceAiConfig; private readonly oauth2CallbackUrl; private readonly webhookBaseUrl; private readonly runState; private readonly backgroundTasks; private readonly builderSandboxSessions; private readonly traceContextsByRunId; private readonly sandboxes; private readonly gatewayRegistry; private readonly domainAccessTrackersByThread; private readonly threadPushRef; private readonly schedulerLocks; private readonly pendingCheckpointReentries; private confirmationTimeoutInterval?; private readonly creditedThreads; private readonly traceReplay; private readonly defaultTimeZone; private readonly logger; constructor(logger: Logger, globalConfig: GlobalConfig, adapterService: InstanceAiAdapterService, eventBus: InProcessEventBus, settingsService: InstanceAiSettingsService, compositeStore: TypeORMCompositeStore, compactionService: InstanceAiCompactionService, aiService: AiService, push: Push, threadRepo: InstanceAiThreadRepository, urlService: UrlService, dbSnapshotStorage: DbSnapshotStorage, dbIterationLogStorage: DbIterationLogStorage, sourceControlPreferencesService: SourceControlPreferencesService, telemetry: Telemetry, userRepository: UserRepository, aiBuilderTemporaryWorkflowRepository: AiBuilderTemporaryWorkflowRepository, errorReporter: ErrorReporter); private startConfirmationTimeoutSweep; private getSandboxConfigFromEnv; private resolveSandboxConfig; private createBuilderFactory; private getOrCreateWorkspace; private destroySandbox; 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 configureTraceReplayMode; private finalizeMessageTraceRoot; private maybeFinalizeRunTraceRoot; private finalizeRemainingMessageTraceRoots; private deleteTraceContextsForThread; 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, researchMode?: boolean, 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): void; sendCorrectionToTask(threadId: string, taskId: string, correction: string): 'queued' | 'task-completed' | 'task-not-found'; cancelBackgroundTask(threadId: string, taskId: string): void; cancelAllBackgroundTasks(): number; loadTraceEvents(slug: string, events: unknown[]): void; getTraceEvents(slug: string): unknown[]; activateTraceSlug(slug: string): void; clearTraceEvents(slug: string): void; getUserIdForApiKey(key: string): string | undefined; generatePairingToken(userId: string): string; getPairingToken(userId: string): string | null; consumePairingToken(userId: string, token: string): string | null; getActiveSessionKey(userId: string): string | null; clearActiveSessionKey(userId: string): void; getLocalGateway(userId: string): LocalGateway; initGateway(userId: string, data: InstanceAiGatewayCapabilities): void; resolveGatewayRequest(userId: string, requestId: string, result?: McpToolCallResult, error?: string): boolean; disconnectGateway(userId: string): void; disconnectAllGateways(): string[]; isLocalGatewayDisabled(): boolean; getGatewayStatus(userId: string): { connected: boolean; connectedAt: string | null; directory: string | null; hostIdentifier: string | null; toolCategories: ToolCategory[]; }; startDisconnectTimer(userId: string, onDisconnect: () => void): void; clearDisconnectTimer(userId: string): void; clearThreadState(threadId: string): Promise; shutdown(): Promise; private createMemoryConfig; private ensureThreadExists; private projectPlannedTaskList; private buildPlannedTaskFollowUpMessage; private createPlannedTaskState; private syncPlannedTasksToUi; private cancelAwaitingApprovalPlan; private createExecutionEnvironment; private dispatchPlannedTask; private createPlannedTaskContext; private getCheckpointAllowedWorkflowIds; private handlePlannedTaskSettlement; private startInternalFollowUpRun; private schedulePlannedTasks; private doSchedulePlannedTasks; private executeRun; private queuePendingCheckpointReentry; private drainPendingCheckpointReentries; private reenterCheckpointById; private maybeReenterParentCheckpoint; private finalizeCheckpointFollowUp; resolveConfirmation(requestingUserId: string, requestId: string, request: InstanceAiConfirmRequest): Promise; 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 cleanupMastraSnapshots; private saveAgentTreeSnapshot; private parseMcpServers; }