n8n
Version:
n8n Workflow Automation Tool
68 lines (67 loc) • 3 kB
TypeScript
import type { Thread, Author } from 'chat';
import { AgentIntegrationConfig } from '@n8n/api-types';
import type { ChatInstance } from './chat-integration.service';
import type { SuspendComponent } from './component-mapper';
import type { IntegrationAction, IntegrationActionResult, IntegrationContextQuery, IntegrationMessageContext, IntegrationToolConnectionDescriptor } from './integration-tools';
export interface AgentChatIntegrationContext {
agentId: string;
projectId: string;
credentialId: string;
credential: Record<string, unknown>;
webhookUrlFor: (platform: string) => string;
}
export interface UnauthenticatedWebhookResponse {
status: number;
body: unknown;
}
export interface AgentChatIntegrationBuilderGuidance {
capabilities: string[];
useIntegrationWhen: string[];
useNodeToolWhen: string[];
}
export declare abstract class AgentChatIntegration {
abstract readonly type: string;
abstract readonly credentialTypes: string[];
abstract readonly displayLabel: string;
abstract readonly displayIcon: string;
readonly builderGuidance?: AgentChatIntegrationBuilderGuidance;
readonly supportedComponents?: string[];
readonly contextQueries: IntegrationContextQuery[];
readonly actions: IntegrationAction[];
readonly needsShortCallbackData: boolean;
readonly disableStreaming: boolean;
requiresLeader(): boolean;
abstract createAdapter(ctx: AgentChatIntegrationContext): Promise<unknown>;
handleUnauthenticatedWebhook?(body: unknown): UnauthenticatedWebhookResponse | undefined;
onBeforeConnect?(ctx: AgentChatIntegrationContext): Promise<void>;
onAfterConnect?(ctx: AgentChatIntegrationContext): Promise<void>;
onBeforeDisconnect?(ctx: AgentChatIntegrationContext): Promise<void>;
normalizeComponents?(components: SuspendComponent[]): SuspendComponent[];
formatThreadId?: {
fromSdk: (thread: Thread<unknown, unknown>) => string;
toSdk: (threadId: string) => string;
};
isUserAllowed?(author: Author, settings: AgentIntegrationConfig | undefined): boolean;
executeContextQuery?(params: PlatformContextQueryParams): Promise<unknown>;
executeAction?(params: PlatformActionParams): Promise<IntegrationActionResult | undefined>;
}
export interface PlatformContextQueryParams {
chat: ChatInstance;
descriptor: IntegrationToolConnectionDescriptor;
query: IntegrationContextQuery;
input: Record<string, unknown>;
}
export interface PlatformActionParams {
chat: ChatInstance;
descriptor: IntegrationToolConnectionDescriptor;
action: IntegrationAction;
input: Record<string, unknown>;
currentMessageContext?: IntegrationMessageContext;
}
export declare class ChatIntegrationRegistry {
private readonly integrations;
register(integration: AgentChatIntegration): void;
get(type: string): AgentChatIntegration | undefined;
require(type: string): AgentChatIntegration;
list(): AgentChatIntegration[];
}