mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-01 15:47:41 +08:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { type AgentIntegrationConfig } from '@n8n/api-types';
|
|
import type { Logger } from '@n8n/backend-common';
|
|
import { Container } from '@n8n/di';
|
|
|
|
import type { Agent } from '../entities/agent.entity';
|
|
|
|
/**
|
|
* Reconcile chat platform connections after the builder writes a new
|
|
* integrations array: changes are diffed and routed to connect/disconnect on
|
|
* ChatIntegrationService.
|
|
*
|
|
* Failures are logged but never thrown — config writes during a builder turn
|
|
* must not be rolled back if e.g. the Slack API is briefly unavailable.
|
|
*
|
|
* Lazy `Container.get(...)` avoids a circular DI dependency between config
|
|
* persistence and the chat integration runtime.
|
|
*/
|
|
export async function syncAgentIntegrations(
|
|
agent: Agent,
|
|
previous: AgentIntegrationConfig[],
|
|
next: AgentIntegrationConfig[],
|
|
logger: Logger,
|
|
): Promise<void> {
|
|
try {
|
|
// eslint-disable-next-line import-x/no-cycle
|
|
const { ChatIntegrationService } = await import('./chat-integration.service.js');
|
|
await Container.get(ChatIntegrationService).syncToConfig(agent, previous, next);
|
|
} catch (error) {
|
|
logger.warn('Failed to sync chat integrations', {
|
|
agentId: agent.id,
|
|
error,
|
|
});
|
|
}
|
|
}
|