From da5c8ff3c5a2ecdf99ad57d48b8d94e00040fd61 Mon Sep 17 00:00:00 2001 From: Jaakko Husso Date: Thu, 20 Nov 2025 17:00:08 +0200 Subject: [PATCH] feat(core): Add Cohere provider support for chat hub (no-changelog) (#22068) --- packages/@n8n/api-types/src/chat-hub.ts | 11 ++++ .../chat-hub/chat-hub-workflow.service.ts | 9 +++ .../modules/chat-hub/chat-hub.constants.ts | 4 ++ .../src/modules/chat-hub/chat-hub.service.ts | 59 +++++++++++++++++++ .../src/modules/chat-hub/context-limits.ts | 1 + .../src/features/ai/chatHub/constants.ts | 1 + 6 files changed, 85 insertions(+) diff --git a/packages/@n8n/api-types/src/chat-hub.ts b/packages/@n8n/api-types/src/chat-hub.ts index 486fae50ddc..11442748210 100644 --- a/packages/@n8n/api-types/src/chat-hub.ts +++ b/packages/@n8n/api-types/src/chat-hub.ts @@ -18,6 +18,7 @@ export const chatHubLLMProviderSchema = z.enum([ 'azureOpenAi', 'ollama', 'awsBedrock', + 'cohere', 'mistralCloud', ]); export type ChatHubLLMProvider = z.infer; @@ -43,6 +44,7 @@ export const PROVIDER_CREDENTIAL_TYPE_MAP: Record< ollama: 'ollamaApi', azureOpenAi: 'azureOpenAiApi', awsBedrock: 'aws', + cohere: 'cohereApi', mistralCloud: 'mistralCloudApi', }; @@ -81,6 +83,11 @@ const awsBedrockModelSchema = z.object({ model: z.string(), }); +const cohereModelSchema = z.object({ + provider: z.literal('cohere'), + model: z.string(), +}); + const mistralCloudModelSchema = z.object({ provider: z.literal('mistralCloud'), model: z.string(), @@ -103,6 +110,7 @@ export const chatHubConversationModelSchema = z.discriminatedUnion('provider', [ azureOpenAIModelSchema, ollamaModelSchema, awsBedrockModelSchema, + cohereModelSchema, mistralCloudModelSchema, n8nModelSchema, chatAgentSchema, @@ -114,6 +122,7 @@ export type ChatHubGoogleModel = z.infer; export type ChatHubAzureOpenAIModel = z.infer; export type ChatHubOllamaModel = z.infer; export type ChatHubAwsBedrockModel = z.infer; +export type ChatHubCohereModel = z.infer; export type ChatHubMistralCloudModel = z.infer; export type ChatHubBaseLLMModel = | ChatHubOpenAIModel @@ -122,6 +131,7 @@ export type ChatHubBaseLLMModel = | ChatHubAzureOpenAIModel | ChatHubOllamaModel | ChatHubAwsBedrockModel + | ChatHubCohereModel | ChatHubMistralCloudModel; export type ChatHubN8nModel = z.infer; @@ -165,6 +175,7 @@ export const emptyChatModelsResponse: ChatModelsResponse = { azureOpenAi: { models: [] }, ollama: { models: [] }, awsBedrock: { models: [] }, + cohere: { models: [] }, mistralCloud: { models: [] }, n8n: { models: [] }, // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/packages/cli/src/modules/chat-hub/chat-hub-workflow.service.ts b/packages/cli/src/modules/chat-hub/chat-hub-workflow.service.ts index ab5fb8041ad..136488c735f 100644 --- a/packages/cli/src/modules/chat-hub/chat-hub-workflow.service.ts +++ b/packages/cli/src/modules/chat-hub/chat-hub-workflow.service.ts @@ -510,6 +510,15 @@ export class ChatHubWorkflowService { }, }; } + case 'cohere': { + return { + ...common, + parameters: { + model, + options: {}, + }, + }; + } case 'mistralCloud': { return { ...common, diff --git a/packages/cli/src/modules/chat-hub/chat-hub.constants.ts b/packages/cli/src/modules/chat-hub/chat-hub.constants.ts index b19b647ae0a..1baffd57120 100644 --- a/packages/cli/src/modules/chat-hub/chat-hub.constants.ts +++ b/packages/cli/src/modules/chat-hub/chat-hub.constants.ts @@ -36,6 +36,10 @@ export const PROVIDER_NODE_TYPE_MAP: Record { + const results = await this.nodeParametersService.getOptionsViaLoadOptions( + { + routing: { + request: { + method: 'GET', + url: '/v1/models?page_size=100&endpoint=chat', + }, + output: { + postReceive: [ + { + type: 'rootProperty', + properties: { + property: 'models', + }, + }, + { + type: 'setKeyValue', + properties: { + name: '={{$responseItem.name}}', + value: '={{$responseItem.name}}', + description: '={{$responseItem.description}}', + }, + }, + { + type: 'sort', + properties: { + key: 'name', + }, + }, + ], + }, + }, + }, + additionalData, + PROVIDER_NODE_TYPE_MAP.cohere, + {}, + credentials, + ); + + return { + models: results.map((result) => ({ + name: result.name, + description: result.description ?? null, + model: { + provider: 'cohere', + model: String(result.value), + }, + createdAt: null, + updatedAt: null, + })), + }; + } + private async fetchAgentWorkflowsAsModels(user: User): Promise { const nodeTypes = [CHAT_TRIGGER_NODE_TYPE]; const workflows = await this.workflowService.getWorkflowsWithNodesIncluded( diff --git a/packages/cli/src/modules/chat-hub/context-limits.ts b/packages/cli/src/modules/chat-hub/context-limits.ts index 272c08f4381..64953d0b4d7 100644 --- a/packages/cli/src/modules/chat-hub/context-limits.ts +++ b/packages/cli/src/modules/chat-hub/context-limits.ts @@ -140,6 +140,7 @@ export const maxContextWindowTokens: Record = { azureOpenAi: 'Azure OpenAI', ollama: 'Ollama', awsBedrock: 'AWS Bedrock', + cohere: 'Cohere', mistralCloud: 'Mistral Cloud', n8n: 'n8n', 'custom-agent': 'Custom Agent',