import { AgentIntegrationConfig, type AgentIntegrationSettings } from '@n8n/api-types'; import { Logger } from '@n8n/backend-common'; import { GlobalConfig } from '@n8n/config'; import type { Channel, Thread, UserInfo } from 'chat'; import { InstanceSettings } from 'n8n-core'; import { CredentialsService } from '../../../credentials/credentials.service'; import { Publisher } from '../../../scaling/pubsub/publisher.service'; import type { PubSubCommandMap } from '../../../scaling/pubsub/pubsub.event-map'; import { UrlService } from '../../../services/url.service'; import { AgentChatBridge } from './agent-chat-bridge'; import { ChatIntegrationRegistry } from './agent-chat-integration'; import { AgentChatSubscriptionStateService } from './agent-chat-subscription-state.service'; import type { CallbackMetadata } from './callback-store'; import { type ShortenCallback } from './component-mapper'; import { LeaderChannelRelayService } from './leader-channel-relay.service'; import type { Agent } from '../entities/agent.entity'; import type { AgentChannelRef } from '../repositories/agent-channel-status.repository'; import { AgentRepository } from '../repositories/agent.repository'; import { AgentChannelStatusReporter } from './agent-channel-status-reporter'; type WebhookHandler = (request: Request, options?: { waitUntil?: (task: Promise) => void; }) => Promise; export interface ChatInstance { initialize(): Promise; shutdown(): Promise; webhooks: Record; onNewMention: (handler: unknown) => void; onSubscribedMessage: (handler: unknown) => void; onAction: (handler: unknown) => void; getAdapter(name: string): unknown; openDM(user: string): Promise; thread(threadId: string): Thread; channel(channelId: string): Channel; getUser(user: string): Promise; } interface ConnectOptions { ingressEnabled?: boolean; skipExternalHooks?: boolean; settings?: AgentIntegrationSettings; } interface DisconnectOptions { skipExternalHooks?: boolean; } interface DisconnectChannelOptions { deleteSubscriptions?: boolean; } export declare class ChatIntegrationService { private readonly logger; private readonly agentRepository; private readonly credentialsService; private readonly urlService; private readonly integrationRegistry; private readonly instanceSettings; private readonly publisher; private readonly globalConfig; private readonly chatSubscriptionStateService; private readonly statusReporter; private readonly leaderChannelRelay; private readonly connections; private readonly outboundConnections; private readonly outboundConnectionInitializations; private readonly leaderOperations; constructor(logger: Logger, agentRepository: AgentRepository, credentialsService: CredentialsService, urlService: UrlService, integrationRegistry: ChatIntegrationRegistry, instanceSettings: InstanceSettings, publisher: Publisher, globalConfig: GlobalConfig, chatSubscriptionStateService: AgentChatSubscriptionStateService, statusReporter: AgentChannelStatusReporter, leaderChannelRelay: LeaderChannelRelayService); broadcastIntegrationChange(agentId: string, integration: AgentIntegrationConfig, action: 'connect' | 'disconnect'): Promise; private connectionKey; private integrationFromConnectionKey; assertStartupPreconditions(agentId: string, integration: AgentIntegrationConfig, projectId: string): Promise; validateBeforeConnect(agentId: string, integration: AgentIntegrationConfig, projectId: string): Promise; connect(agentId: string, integration: AgentIntegrationConfig, projectId: string, options?: ConnectOptions): Promise; private connectLocal; private establishConnection; disconnect(agentId: string, integration?: { credentialId: string; type: string; }, options?: DisconnectOptions): Promise; releaseChannelLocally(agentId: string, integration: { credentialId: string; type: string; }): Promise; disconnectChannel(agentId: string, integration: AgentIntegrationConfig, options?: DisconnectChannelOptions): Promise; disconnectAll(): Promise; disconnectLeaderOnlyIntegrations(): Promise; syncToConfig(agent: Agent, previous: AgentIntegrationConfig[], next: AgentIntegrationConfig[]): Promise; getChatInstance(agentId: string, integration?: { type: string; credentialId: string; }): ChatInstance | undefined; getBridge(agentId: string, integrationType: string, credentialId?: string): AgentChatBridge | undefined; private findConnection; isChannelLive(agentId: string, integration: { type: string; credentialId: string; }): boolean; getChatInstanceForTools(agentId: string, integration: { type: string; credentialId: string; }): Promise; getShortenCallback(agentId: string, integration: { type: string; credentialId: string; }, metadata?: CallbackMetadata): ShortenCallback | undefined; getWebhookHandler(agentId: string, platform: string, connectionSelector?: string): WebhookHandler | undefined; listLiveChannels(): AgentChannelRef[]; hasLiveChannel(ref: AgentChannelRef): boolean; startChannel(agent: Agent, integration: AgentIntegrationConfig): Promise; handleIntegrationChanged(payload: PubSubCommandMap['agent-chat-integration-changed']): Promise; handleLeaderChannelRequest(payload: PubSubCommandMap['agent-chat-leader-channel-request']): Promise; private channelRef; private shouldRouteToLeader; private runLeaderOperation; private settleLeaderOperations; private disconnectLocal; private disconnectOutboundOne; private disposeOutboundConnection; private disconnectOne; private runDisconnectedHook; private decryptCredentialForProject; private buildWebhookUrl; private connectOptionsFor; } export {};