import { AgentIntegrationConfig, type AgentIntegrationDisconnectWarning, type RichCardComponentType } from '@n8n/api-types'; import type { User } from '@n8n/db'; import type { Thread, Author, Message } from 'chat'; import type { Logger } from 'n8n-workflow'; import type { ChatInstance } from './chat-integration.service'; import type { SuspendComponent } from './component-mapper'; import type { IntegrationAction, IntegrationActionDefinition, IntegrationActionResult, IntegrationContextQuery, IntegrationContextQueryDefinition, IntegrationMessageContext, IntegrationPlatformMessageContext, IntegrationToolConnectionDescriptor, ReplyExpectation } from './integration-tools'; export interface AgentChannelPreconditionContext { agentId: string; projectId: string; credentialId: string; } export interface AgentChatIntegrationContext extends AgentChannelPreconditionContext { integration: AgentIntegrationConfig; credential: Record; ingressEnabled: boolean; webhookUrlFor: (platform: string) => string; } export interface AgentIntegrationRemovalContext { agentId: string; projectId: string; credentialId: string; user: User; deleteExternalResource?: boolean; } export interface UnauthenticatedWebhookResponse { status: number; body: unknown; } export interface WebhookRequestContext { headers: Readonly>; body: unknown; } export type WebhookRequestResolution = { type: 'reject'; response: UnauthenticatedWebhookResponse; } | { type: 'select'; connectionSelector: string; } | { type: 'no_match'; }; export interface AgentChatIntegrationBuilderGuidance { capabilities: string[]; useIntegrationWhen: string[]; useNodeToolWhen: string[]; } export interface PlatformAgentContext { agentUserId?: string; } export interface BridgeStatusHandle { clearBeforeResponse(): Promise; } export declare function onceStatusHandle(handle: BridgeStatusHandle | undefined): BridgeStatusHandle | undefined; export interface BridgeExecutionContext { platformAgentContext: PlatformAgentContext; platformMessage?: IntegrationPlatformMessageContext; forceBuffered?: boolean; statusHandle?: BridgeStatusHandle; historyContext?: string; } export type BridgeResumeExecutionContext = Pick; export interface BridgeMessageContextParams { chat: ChatInstance; thread: Thread; message: Message; integration: AgentIntegrationConfig; logger: Logger; agentId: string; statusRetry?: AbortController; isNewMention: boolean; replyExpectation: ReplyExpectation; } export interface ActionDecisionMessageParams { approved?: boolean; selectedLabel?: string; raw: unknown; user: Author; } export type ActionDecisionMessageFormatter = (params: ActionDecisionMessageParams) => string | undefined; export interface SettleActionMessageParams { agentId: string; integration: AgentIntegrationConfig; threadId: string; messageId: string; content: string; } export type SettleActionMessage = (params: SettleActionMessageParams) => Promise; 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?: readonly RichCardComponentType[]; readonly contextToolDefinitions: IntegrationContextQueryDefinition[]; readonly actionToolDefinitions: IntegrationActionDefinition[]; readonly contextToolGuidance?: string[]; readonly actionToolGuidance?: string[]; get contextQueries(): IntegrationContextQuery[]; get actions(): IntegrationAction[]; readonly needsShortCallbackData: boolean; readonly deleteActionMessageBeforeResume: boolean; readonly disableStreaming: boolean; readonly internal: boolean; readonly requiresChatInstance: boolean; requiresLeader(_options?: { ingressEnabled: boolean; }): boolean; abstract createAdapter(ctx: AgentChatIntegrationContext): Promise; validateConfig?(integration: AgentIntegrationConfig): void; handleUnauthenticatedWebhook?(body: unknown): UnauthenticatedWebhookResponse | undefined; resolveWebhookRequest?(request: WebhookRequestContext): WebhookRequestResolution; matchesWebhookConnection?(credential: Record, connectionSelector: string): boolean; onBeforeConnect?(ctx: AgentChatIntegrationContext): Promise; assertStartupPreconditions?(ctx: AgentChannelPreconditionContext): Promise; onAfterConnect?(ctx: AgentChatIntegrationContext): Promise; onBeforeDisconnect?(ctx: AgentChatIntegrationContext): Promise; onRemove?(ctx: AgentIntegrationRemovalContext): Promise; prepareSentThread?(thread: Thread, integration: AgentIntegrationConfig): Promise; onConnected?(ctx: AgentChatIntegrationContext): Promise; onDisconnected?(ctx: AgentChatIntegrationContext): Promise; normalizeComponents?(components: SuspendComponent[]): SuspendComponent[]; formatThreadId?: { fromSdk: (thread: Thread) => string; toSdk: (threadId: string) => string; }; messageThreadId?(message: { id: string; threadId: string; raw?: unknown; }, context?: { inbound?: boolean; }): string | undefined; isUserAllowed?(author: Author, settings: AgentIntegrationConfig | undefined): boolean; getPlatformAgentContext?(chat: ChatInstance): PlatformAgentContext; prepareInboundText?(text: string, context: PlatformAgentContext): string; getReplyExpectation?(params: { message: Message; isNewMention: boolean; platformAgentContext: PlatformAgentContext; }): ReplyExpectation; formatActionDecisionMessage?(params: ActionDecisionMessageParams): string | undefined; settleActionMessage?(params: SettleActionMessageParams): Promise; shouldSubscribeToNewMention?(params: { thread: Thread; message: Message; }): boolean; createBridgeExecutionContext?(params: BridgeMessageContextParams): Promise; createResumeExecutionContext?(params: { chat: ChatInstance; thread: Thread; logger: Logger; agentId: string; }): Promise; executeContextQuery?(params: PlatformContextQueryParams): Promise; executeAction?(params: PlatformActionParams): Promise; } export interface PlatformContextQueryParams { chat: ChatInstance | undefined; descriptor: IntegrationToolConnectionDescriptor; query: IntegrationContextQuery; input: Record; } export interface PlatformActionParams { chat: ChatInstance | undefined; descriptor: IntegrationToolConnectionDescriptor; action: IntegrationAction; input: Record; currentMessageContext?: IntegrationMessageContext; } export declare class ChatIntegrationRegistry { private readonly integrations; register(integration: AgentChatIntegration): void; get(type: string): AgentChatIntegration | undefined; require(type: string): AgentChatIntegration; list(): AgentChatIntegration[]; listPublic(): AgentChatIntegration[]; }