@n8n-plus/n8n-plus
Version:
n8n Workflow Automation Tool (plus edition)
161 lines (160 loc) • 8.68 kB
TypeScript
import type { CredentialProvider, StreamChunk, ToolDescriptor } from '@n8n/agents';
import { type AgentCredentialIntegrationConfig, type AgentJsonConfig, type AgentSkill, type AgentSkillMutationResponse, type ChatIntegrationDescriptor, AgentPersistedMessageDto } from '@n8n/api-types';
import { Logger } from '@n8n/backend-common';
import { AgentsConfig, GlobalConfig } from '@n8n/config';
import { ExecutionRepository, ProjectRelationRepository, User, UserRepository, WorkflowRepository } from '@n8n/db';
import { type ExecuteAgentData } from 'n8n-workflow';
import { ActiveExecutions } from '../../active-executions';
import { EphemeralNodeExecutor } from '../../node-execution';
import type { PubSubCommandMap } from '../../scaling/pubsub/pubsub.event-map';
import { Publisher } from '../../scaling/pubsub/publisher.service';
import { UrlService } from '../../services/url.service';
import { Telemetry } from '../../telemetry';
import { WorkflowRunner } from '../../workflow-runner';
import { WorkflowFinderService } from '../../workflows/workflow-finder.service';
import { AgentExecutionService } from './agent-execution.service';
import { AgentSkillsService } from './agent-skills.service';
import { AgentsToolsService } from './agents-tools.service';
import { Agent } from './entities/agent.entity';
import { N8NCheckpointStorage } from './integrations/n8n-checkpoint-storage';
import { N8nMemory } from './integrations/n8n-memory';
import { AgentHistoryRepository } from './repositories/agent-history.repository';
import { AgentRepository } from './repositories/agent.repository';
import { AgentSecureRuntime } from './runtime/agent-secure-runtime';
import { ChatIntegrationService } from './integrations/chat-integration.service';
export declare function chatThreadId(agentId: string, userId?: string): string;
export interface AgentMemoryScope {
threadId: string;
resourceId: string;
}
export interface ExecuteForChatConfig {
agentId: string;
projectId: string;
message: string;
userId: string;
memory: AgentMemoryScope;
}
export interface ExecuteForChatPublishedConfig {
agentId: string;
projectId: string;
message: string;
memory: AgentMemoryScope;
integrationType?: string;
}
export interface ResumeForChatConfig {
agentId: string;
projectId: string;
runId: string;
toolCallId: string;
resumeData: unknown;
integrationType?: string;
}
export interface ExecuteForSchedulePublishedConfig {
agentId: string;
projectId: string;
message: string;
memory: AgentMemoryScope;
}
export declare class AgentsService {
private readonly logger;
private readonly agentRepository;
private readonly projectRelationRepository;
private readonly workflowRunner;
private readonly activeExecutions;
private readonly executionRepository;
private readonly workflowRepository;
private readonly userRepository;
private readonly workflowFinderService;
private readonly urlService;
private readonly n8nCheckpointStorage;
private readonly secureRuntime;
private readonly ephemeralNodeExecutor;
private readonly agentsToolsService;
private readonly n8nMemory;
private readonly agentExecutionService;
private readonly agentHistoryRepository;
private readonly agentSkillsService;
private readonly publisher;
private readonly agentsConfig;
private readonly globalConfig;
private readonly telemetry;
private readonly chatIntegrationService;
private readonly runtimes;
private computeRuntimeCacheKey;
private clearRuntimes;
handleAgentConfigChanged(payload: PubSubCommandMap['agent-config-changed']): void;
constructor(logger: Logger, agentRepository: AgentRepository, projectRelationRepository: ProjectRelationRepository, workflowRunner: WorkflowRunner, activeExecutions: ActiveExecutions, executionRepository: ExecutionRepository, workflowRepository: WorkflowRepository, userRepository: UserRepository, workflowFinderService: WorkflowFinderService, urlService: UrlService, n8nCheckpointStorage: N8NCheckpointStorage, secureRuntime: AgentSecureRuntime, ephemeralNodeExecutor: EphemeralNodeExecutor, agentsToolsService: AgentsToolsService, n8nMemory: N8nMemory, agentExecutionService: AgentExecutionService, agentHistoryRepository: AgentHistoryRepository, agentSkillsService: AgentSkillsService, publisher: Publisher, agentsConfig: AgentsConfig, globalConfig: GlobalConfig, telemetry: Telemetry, chatIntegrationService: ChatIntegrationService);
private isNodeToolsModuleEnabled;
private createAgentExecutionCounter;
private shouldAttachNodeTools;
listChatIntegrations(): ChatIntegrationDescriptor[];
create(projectId: string, name: string): Promise<Agent>;
findByProjectId(projectId: string): Promise<Agent[]>;
findById(agentId: string, projectId: string): Promise<Agent | null>;
updateName(agentId: string, projectId: string, name: string): Promise<Agent | null>;
updateDescription(agentId: string, projectId: string, description: string, updatedAt?: string): Promise<Agent | null>;
findByUser(userId: string): Promise<Agent[]>;
findPublishedByUser(userId: string): Promise<Agent[]>;
publishAgent(agentId: string, projectId: string, user: User, versionId?: string): Promise<Agent>;
unpublishAgent(agentId: string, projectId: string): Promise<Agent>;
revertToPublishedAgent(agentId: string, projectId: string): Promise<Agent>;
delete(agentId: string, projectId: string): Promise<boolean>;
getConversationHistory(params: {
threadId: string;
projectId: string;
agentId: string;
}): Promise<AgentPersistedMessageDto[] | null>;
private getMemoryFactory;
private createCredentialProvider;
private getRuntime;
private makeToolResolver;
private injectRuntimeDependencies;
private attachNodeToolChain;
resumeForChat(config: ResumeForChatConfig): AsyncGenerator<StreamChunk>;
validateAgentIsRunnable(agentId: string, projectId: string, credentialProvider: CredentialProvider): Promise<{
missing: string[];
}>;
executeForChat(config: ExecuteForChatConfig): AsyncGenerator<StreamChunk>;
getTestChatMessages(agentId: string, userId: string): Promise<import("@n8n/agents").AgentDbMessage[]>;
clearTestChatMessages(agentId: string, userId: string): Promise<void>;
clearAllTestChatMessages(agentId: string): Promise<void>;
executeForChatPublished(config: ExecuteForChatPublishedConfig): AsyncGenerator<StreamChunk>;
executeForSchedulePublished(config: ExecuteForSchedulePublishedConfig): AsyncGenerator<StreamChunk>;
private streamChatResponse;
private compileIsolated;
executeForWorkflow(agentId: string, message: string, executionId: string, threadId: string, userId: string, projectId: string, telemetryUserId?: string): Promise<ExecuteAgentData>;
getConfig(agentId: string, projectId: string): Promise<AgentJsonConfig>;
validateConfig(raw: unknown): Promise<{
valid: true;
config: AgentJsonConfig;
} | {
valid: false;
error: string;
}>;
private validateNodeToolExpressions;
updateConfig(agentId: string, projectId: string, config: unknown): Promise<{
config: AgentJsonConfig;
updatedAt: string;
versionId: string | null;
}>;
saveCredentialIntegration(agent: Agent, integration: AgentCredentialIntegrationConfig): Promise<Agent>;
removeCredentialIntegration(agent: Agent, type: string, credentialId: string): Promise<Agent>;
private validateIntegrationRefs;
buildCustomTool(agentId: string, projectId: string, code: string, descriptor: ToolDescriptor): Promise<{
ok: boolean;
id: string;
descriptor: ToolDescriptor;
}>;
listSkills(agentId: string, projectId: string): Promise<Record<string, AgentSkill>>;
getSkill(agentId: string, projectId: string, skillId: string): Promise<AgentSkill>;
createSkill(agentId: string, projectId: string, skill: AgentSkill): Promise<AgentSkillMutationResponse>;
createAndAttachSkill(agentId: string, projectId: string, skill: AgentSkill): Promise<AgentSkillMutationResponse>;
updateSkill(agentId: string, projectId: string, skillId: string, updates: Partial<AgentSkill>): Promise<AgentSkillMutationResponse>;
deleteCustomTool(agentId: string, projectId: string, toolId: string): Promise<void>;
deleteSkill(agentId: string, projectId: string, skillId: string): Promise<void>;
private validateNodeToolConfigs;
private validateConfigRefs;
private getMissingCustomToolIds;
private snapshotConfiguredTools;
private reconstructFromConfig;
}