import { AgentIntegrationConfig, type AgentIntegrationDisconnectWarning, type AgentMessageAuthor, type AgentMessageIntegrationOrigin, type RichCardComponentType } from '@n8n/api-types'; import type { ResolvedEpisodicScope } from '@n8n/agents'; import type { User } from '@n8n/db'; import type { ActionEvent, Attachment, Thread, Author, Message } from 'chat'; import type { Logger } from 'n8n-workflow'; import { UserError } from '@n8n/errors'; import type { ChatInstance } from './chat-integration.service'; import type { NormalizeComponentsContext, SuspendComponent } from './component-mapper'; import type { IntegrationErrorCode } from './integration-error-codes'; import type { SlackThreadContext } from './platforms/slack/slack-bridge-behavior'; import type { IntegrationAction, IntegrationActionDefinition, IntegrationActionParams, IntegrationActionResult, IntegrationContextQuery, IntegrationContextQueryDefinition, IntegrationContextQueryParams, IntegrationPlatformMessageContext, ReplyExpectation } from './integration-tools'; import type { DecodedThread, OriginDraft, OriginInput, OriginNames } from './integration-origin-support'; export declare class InboundAttachmentAccessError extends UserError { } export interface VerifiedSender { userId: string; userName?: string; } export interface AgentChannelPreconditionContext { agentId: string; projectId: string; credentialId: string; } export interface EpisodicScopeContext { agentId: string; credentialId: string; integrationType: string; threadId: string; author: AgentMessageAuthor; origin?: AgentMessageIntegrationOrigin; } 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; raw?: boolean; } export interface UnauthenticatedWebhookContext { agentId: string; method: string; query: Readonly>; headers: Readonly>; 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 declare const MAX_FILE_MESSAGES_PER_SEND = 3; export interface FileUploadLimits { maxFiles: number; maxFileBytes: number; maxCaptionLength?: number; maxImageBytes?: number; } export interface PlatformAgentContext { agentUserId?: string; } export interface BridgeStatusHandle { clearBeforeResponse(): Promise; keepDuringResponse?: boolean; resumeAfterResponse?(): Promise; } export declare function onceStatusHandle(handle: BridgeStatusHandle | undefined): BridgeStatusHandle | undefined; type EphemeralPostable = Parameters['postEphemeral']>[1]; export declare function postToUserOrThread(thread: Thread, user: string | Author, payload: EphemeralPostable): Promise; export interface BridgeExecutionContext { platformAgentContext: PlatformAgentContext; slackThreadContext?: SlackThreadContext; platformMessage?: IntegrationPlatformMessageContext; forceBuffered?: boolean; statusHandle?: BridgeStatusHandle; historyContext?: string; } export type BridgeResumeExecutionContext = Pick; export interface BridgeMessageContextParams { startStatus?: boolean; chat: ChatInstance; thread: Thread; message: Message; integration: AgentIntegrationConfig; logger: Logger; agentId: string; statusRetry?: AbortController; isNewMention: boolean; inSubscribedThread?: 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[]; readonly fileUploadLimits?: FileUploadLimits; readonly sendFilesAsAttachments: boolean; groupOutboundFiles?(files: T[]): T[][]; get contextQueries(): IntegrationContextQuery[]; get actions(): IntegrationAction[]; readonly needsShortCallbackData: boolean; readonly deleteActionMessageBeforeResume: boolean; readonly defaultSessionIdleTimeoutMinutes: number | null; readonly targetSuspensionCardAtActingUser: boolean; readonly disableStreaming: boolean; readonly singleStreamedRunPerTurn: boolean; readonly maxMessageLength: number | undefined; readonly internal: boolean; readonly singleConnectionPerAgent: boolean; readonly requiresChatInstance: boolean; requiresLeader(_options?: { ingressEnabled: boolean; }): boolean; abstract createAdapter(ctx: AgentChatIntegrationContext): Promise; abstract buildOriginDraft(input: OriginInput, decoded: DecodedThread): Promise | OriginDraft | undefined; fetchOriginNames?(input: OriginInput, origin: AgentMessageIntegrationOrigin): Promise; abstract resolveEpisodicScope(context: EpisodicScopeContext): Promise | ResolvedEpisodicScope | null; validateConfig?(integration: AgentIntegrationConfig): void; handleUnauthenticatedWebhook?(context: UnauthenticatedWebhookContext): 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; normalizeChannelId(channelId: string, _adapter: unknown): string; describeActionError?(action: IntegrationAction, error: unknown): { code: IntegrationErrorCode; message: string; } | undefined; onConnected?(ctx: AgentChatIntegrationContext): Promise; onDisconnected?(ctx: AgentChatIntegrationContext): Promise; normalizeComponents?(components: SuspendComponent[], context: NormalizeComponentsContext): SuspendComponent[] | Promise; claimAction?(event: ActionEvent): Promise; 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, sender?: VerifiedSender): boolean; verifiedSender?(raw: unknown): VerifiedSender | undefined; getPlatformAgentContext?(chat: ChatInstance): PlatformAgentContext; prepareInboundText?(text: string, context: PlatformAgentContext): string; fetchInboundAttachments?(params: { thread: Thread; message: Message; }): Promise; getReplyExpectation?(params: { message: Message; isNewMention: boolean; platformAgentContext: PlatformAgentContext; }): ReplyExpectation; getFailedSendReport?(message: Message): { messageId: string; chatNotice: string; } | undefined; formatActionDecisionMessage?(params: ActionDecisionMessageParams): string | undefined; settleActionMessage?(params: SettleActionMessageParams): Promise; shouldHandleInboundMessage?(params: { message: Message; integration: AgentIntegrationConfig; }): boolean; shouldSubscribeToNewMention?(params: { thread: Thread; message: Message; }): boolean; shouldHandleUnmentionedMessage?(params: { thread: Thread; message: Message; integration: AgentIntegrationConfig; }): boolean; createBridgeExecutionContext?(params: BridgeMessageContextParams): Promise; createResumeExecutionContext?(params: { chat: ChatInstance; thread: Thread; logger: Logger; agentId: string; slackThreadContext?: BridgeExecutionContext['slackThreadContext']; integration?: AgentIntegrationConfig; }): Promise; shouldDownloadAttachments?(integration: AgentIntegrationConfig): boolean; executeContextQuery?(params: PlatformContextQueryParams): Promise; executeAction?(params: PlatformActionParams): Promise; } export interface PlatformContextQueryParams extends Omit { chat: ChatInstance | undefined; } export interface PlatformActionParams extends Omit { chat: ChatInstance | undefined; } export declare class ChatIntegrationRegistry { private readonly integrations; register(integration: AgentChatIntegration): void; get(type: string): AgentChatIntegration | undefined; require(type: string): AgentChatIntegration; list(): AgentChatIntegration[]; listPublic(): AgentChatIntegration[]; } export {};