mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 05:29:44 +02:00
Map the agents.scope column on the Agent entity. An instance agent is code-defined and belongs to no project. AgentRepository.ensureInstanceAgent creates its row with an insert that ignores a concurrent duplicate. Type Agent.projectId as string | null. Project-scoped repository queries and writes filter on scope = 'project'. The queries return ProjectAgent, which has a non-null projectId. The project-agent APIs do not see instance agents and report them as not found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { type AgentIntegrationConfig } from '@n8n/api-types';
|
|
import type { Logger } from '@n8n/backend-common';
|
|
import { Container } from '@n8n/di';
|
|
|
|
import type { ProjectAgent } 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: ProjectAgent,
|
|
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,
|
|
});
|
|
}
|
|
}
|