feat(core): Add xAI Grok provider support for chat hub (no-changelog) (#22084)

This commit is contained in:
Jaakko Husso 2025-11-21 13:28:51 +02:00 committed by GitHub
parent 72cdca23d6
commit fde05ce697
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 84 additions and 0 deletions

View File

@ -18,6 +18,7 @@ export const chatHubLLMProviderSchema = z.enum([
'azureOpenAi',
'ollama',
'awsBedrock',
'xAiGrok',
'groq',
'openRouter',
'deepSeek',
@ -47,6 +48,7 @@ export const PROVIDER_CREDENTIAL_TYPE_MAP: Record<
ollama: 'ollamaApi',
azureOpenAi: 'azureOpenAiApi',
awsBedrock: 'aws',
xAiGrok: 'xAiApi',
groq: 'groqApi',
openRouter: 'openRouterApi',
deepSeek: 'deepSeekApi',
@ -89,6 +91,11 @@ const awsBedrockModelSchema = z.object({
model: z.string(),
});
const xAiGrokModelSchema = z.object({
provider: z.literal('xAiGrok'),
model: z.string(),
});
const groqModelSchema = z.object({
provider: z.literal('groq'),
model: z.string(),
@ -131,6 +138,7 @@ export const chatHubConversationModelSchema = z.discriminatedUnion('provider', [
azureOpenAIModelSchema,
ollamaModelSchema,
awsBedrockModelSchema,
xAiGrokModelSchema,
groqModelSchema,
openRouterModelSchema,
deepSeekModelSchema,
@ -146,6 +154,7 @@ export type ChatHubGoogleModel = z.infer<typeof googleModelSchema>;
export type ChatHubAzureOpenAIModel = z.infer<typeof azureOpenAIModelSchema>;
export type ChatHubOllamaModel = z.infer<typeof ollamaModelSchema>;
export type ChatHubAwsBedrockModel = z.infer<typeof awsBedrockModelSchema>;
export type ChatHubXAiGrokModel = z.infer<typeof xAiGrokModelSchema>;
export type ChatHubGroqModel = z.infer<typeof groqModelSchema>;
export type ChatHubOpenRouterModel = z.infer<typeof openRouterModelSchema>;
export type ChatHubDeepSeekModel = z.infer<typeof deepSeekModelSchema>;
@ -158,6 +167,7 @@ export type ChatHubBaseLLMModel =
| ChatHubAzureOpenAIModel
| ChatHubOllamaModel
| ChatHubAwsBedrockModel
| ChatHubXAiGrokModel
| ChatHubGroqModel
| ChatHubOpenRouterModel
| ChatHubDeepSeekModel
@ -205,6 +215,7 @@ export const emptyChatModelsResponse: ChatModelsResponse = {
azureOpenAi: { models: [] },
ollama: { models: [] },
awsBedrock: { models: [] },
xAiGrok: { models: [] },
groq: { models: [] },
openRouter: { models: [] },
deepSeek: { models: [] },

View File

@ -512,6 +512,15 @@ export class ChatHubWorkflowService {
},
};
}
case 'xAiGrok': {
return {
...common,
parameters: {
model,
options: {},
},
};
}
case 'groq': {
return {
...common,

View File

@ -36,6 +36,10 @@ export const PROVIDER_NODE_TYPE_MAP: Record<ChatHubLLMProvider, INodeTypeNameVer
name: '@n8n/n8n-nodes-langchain.lmChatAwsBedrock',
version: 1.1,
},
xAiGrok: {
name: '@n8n/n8n-nodes-langchain.lmChatXAiGrok',
version: 1,
},
groq: {
name: '@n8n/n8n-nodes-langchain.lmChatGroq',
version: 1,

View File

@ -166,6 +166,8 @@ export class ChatHubService {
return await this.fetchAzureOpenAiModels(credentials, additionalData);
case 'awsBedrock':
return await this.fetchAwsBedrockModels(credentials, additionalData);
case 'xAiGrok':
return await this.fetchXAiGrokModels(credentials, additionalData);
case 'groq':
return await this.fetchGroqModels(credentials, additionalData);
case 'openRouter':
@ -769,6 +771,62 @@ export class ChatHubService {
};
}
private async fetchXAiGrokModels(
credentials: INodeCredentials,
additionalData: IWorkflowExecuteAdditionalData,
): Promise<ChatModelsResponse['xAiGrok']> {
const results = await this.nodeParametersService.getOptionsViaLoadOptions(
{
routing: {
request: {
method: 'GET',
url: '/models',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'data',
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.id}}',
value: '={{$responseItem.id}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
additionalData,
PROVIDER_NODE_TYPE_MAP.xAiGrok,
{},
credentials,
);
return {
models: results.map((result) => ({
name: result.name,
description: result.description ?? null,
model: {
provider: 'xAiGrok',
model: String(result.value),
},
createdAt: null,
updatedAt: null,
})),
};
}
private async fetchAgentWorkflowsAsModels(user: User): Promise<ChatModelsResponse['n8n']> {
const nodeTypes = [CHAT_TRIGGER_NODE_TYPE];
const workflows = await this.workflowService.getWorkflowsWithNodesIncluded(

View File

@ -140,6 +140,7 @@ export const maxContextWindowTokens: Record<ChatHubLLMProvider, Record<string, n
azureOpenAi: {},
ollama: {},
awsBedrock: {},
xAiGrok: {},
groq: {},
openRouter: {},
deepSeek: {},

View File

@ -15,6 +15,7 @@ export const providerDisplayNames: Record<ChatHubProvider, string> = {
azureOpenAi: 'Azure OpenAI',
ollama: 'Ollama',
awsBedrock: 'AWS Bedrock',
xAiGrok: 'xAI Grok',
groq: 'Groq',
openRouter: 'OpenRouter',
deepSeek: 'DeepSeek',