n8n
Version:
n8n Workflow Automation Tool
194 lines (193 loc) • 9.54 kB
TypeScript
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, SsrfProtectionConfig } from '@n8n/config';
import { ErrorReporter } from 'n8n-core';
import { SsrfProtectionService } from '../../services/ssrf/ssrf-protection.service';
import { AiBuilderTemporaryWorkflowRepository, UserRepository, type User } from '@n8n/db';
import { UrlService } from '../../services/url.service';
import { type ModelConfig } from '@n8n/instance-ai';
import { EventService } from '../../events/event.service';
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 eventService;
private readonly mcpClientManager;
private readonly instanceAiConfig;
private readonly oauth2CallbackUrl;
private readonly webhookBaseUrl;
private readonly formBaseUrl;
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 readonly pendingTerminalOutcomes;
private terminalOutcomeStorage?;
private readonly liveness;
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, ssrfProtectionConfig: SsrfProtectionConfig, ssrfProtectionService: SsrfProtectionService, eventService: EventService);
private getSandboxConfigFromEnv;
private resolveSandboxConfig;
private createBuilderFactory;
private getOrCreateWorkspace;
private destroySandbox;
private getProxyAuth;
resolveAgentModelConfig(user: User): Promise<ModelConfig>;
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<void>;
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, reason?: string): void;
sendCorrectionToTask(threadId: string, taskId: string, correction: string): 'queued' | 'task-completed' | 'task-not-found';
cancelBackgroundTask(threadId: string, taskId: string): void;
private revalidateActiveUser;
cancelAllBackgroundTasks(): number;
startStuckBackgroundTaskForTest(user: User, threadId: string): Promise<{
threadId: string;
runId: string;
messageGroupId: string;
taskId: string;
agentId: string;
timeoutAt: number;
}>;
runLivenessSweepForTest(now?: number): Promise<void>;
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;
getGatewayApiKeyExpiresAt(userId: string, key: string): Date | null;
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<void>;
shutdown(): Promise<void>;
private createMemoryConfig;
private ensureThreadExists;
private projectPlannedTaskList;
private buildPlannedTaskFollowUpMessage;
private createPlannedTaskState;
private evaluateTerminalResponse;
private evaluateWaitingResponse;
private getTerminalGuardEvents;
private handleTerminalResponseDecision;
private createTerminalOutcomeStorage;
private finishInvalidConfirmationRun;
private buildBackgroundTerminalOutcome;
replayUndeliveredTerminalOutcomes(threadId: string, options?: {
delivery?: 'snapshot' | 'event';
}): Promise<void>;
private persistTerminalOutcomeLineToSnapshot;
private publishTerminalOutcomeLine;
private recordBackgroundTerminalOutcome;
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<boolean>;
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;
}