@node-llm/core 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +11 -10
  2. package/dist/aliases.d.ts +187 -63
  3. package/dist/aliases.d.ts.map +1 -1
  4. package/dist/aliases.js +245 -121
  5. package/dist/config.d.ts +16 -0
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +29 -1
  8. package/dist/constants.d.ts +2 -0
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/constants.js +2 -0
  11. package/dist/llm.d.ts.map +1 -1
  12. package/dist/llm.js +4 -2
  13. package/dist/models/models.json +2919 -867
  14. package/dist/models/types.d.ts +1 -1
  15. package/dist/models/types.d.ts.map +1 -1
  16. package/dist/providers/mistral/Capabilities.d.ts +19 -0
  17. package/dist/providers/mistral/Capabilities.d.ts.map +1 -0
  18. package/dist/providers/mistral/Capabilities.js +113 -0
  19. package/dist/providers/mistral/Chat.d.ts +8 -0
  20. package/dist/providers/mistral/Chat.d.ts.map +1 -0
  21. package/dist/providers/mistral/Chat.js +149 -0
  22. package/dist/providers/mistral/Embedding.d.ts +8 -0
  23. package/dist/providers/mistral/Embedding.d.ts.map +1 -0
  24. package/dist/providers/mistral/Embedding.js +44 -0
  25. package/dist/providers/mistral/Errors.d.ts +2 -0
  26. package/dist/providers/mistral/Errors.d.ts.map +1 -0
  27. package/dist/providers/mistral/Errors.js +57 -0
  28. package/dist/providers/mistral/MistralProvider.d.ts +40 -0
  29. package/dist/providers/mistral/MistralProvider.d.ts.map +1 -0
  30. package/dist/providers/mistral/MistralProvider.js +82 -0
  31. package/dist/providers/mistral/Models.d.ts +8 -0
  32. package/dist/providers/mistral/Models.d.ts.map +1 -0
  33. package/dist/providers/mistral/Models.js +71 -0
  34. package/dist/providers/mistral/Moderation.d.ts +8 -0
  35. package/dist/providers/mistral/Moderation.d.ts.map +1 -0
  36. package/dist/providers/mistral/Moderation.js +49 -0
  37. package/dist/providers/mistral/Streaming.d.ts +8 -0
  38. package/dist/providers/mistral/Streaming.d.ts.map +1 -0
  39. package/dist/providers/mistral/Streaming.js +203 -0
  40. package/dist/providers/mistral/Transcription.d.ts +9 -0
  41. package/dist/providers/mistral/Transcription.d.ts.map +1 -0
  42. package/dist/providers/mistral/Transcription.js +76 -0
  43. package/dist/providers/mistral/index.d.ts +10 -0
  44. package/dist/providers/mistral/index.d.ts.map +1 -0
  45. package/dist/providers/mistral/index.js +26 -0
  46. package/dist/providers/registry.d.ts +3 -1
  47. package/dist/providers/registry.d.ts.map +1 -1
  48. package/dist/providers/registry.js +3 -1
  49. package/dist/providers/xai/Capabilities.d.ts +12 -0
  50. package/dist/providers/xai/Capabilities.d.ts.map +1 -0
  51. package/dist/providers/xai/Capabilities.js +79 -0
  52. package/dist/providers/xai/Chat.d.ts +8 -0
  53. package/dist/providers/xai/Chat.d.ts.map +1 -0
  54. package/dist/providers/xai/Chat.js +69 -0
  55. package/dist/providers/xai/Errors.d.ts +2 -0
  56. package/dist/providers/xai/Errors.d.ts.map +1 -0
  57. package/dist/providers/xai/Errors.js +33 -0
  58. package/dist/providers/xai/Image.d.ts +8 -0
  59. package/dist/providers/xai/Image.d.ts.map +1 -0
  60. package/dist/providers/xai/Image.js +47 -0
  61. package/dist/providers/xai/Models.d.ts +8 -0
  62. package/dist/providers/xai/Models.d.ts.map +1 -0
  63. package/dist/providers/xai/Models.js +47 -0
  64. package/dist/providers/xai/Streaming.d.ts +8 -0
  65. package/dist/providers/xai/Streaming.d.ts.map +1 -0
  66. package/dist/providers/xai/Streaming.js +167 -0
  67. package/dist/providers/xai/XAIProvider.d.ts +37 -0
  68. package/dist/providers/xai/XAIProvider.d.ts.map +1 -0
  69. package/dist/providers/xai/XAIProvider.js +66 -0
  70. package/dist/providers/xai/index.d.ts +7 -0
  71. package/dist/providers/xai/index.d.ts.map +1 -0
  72. package/dist/providers/xai/index.js +19 -0
  73. package/package.json +1 -1
@@ -0,0 +1,33 @@
1
+ import { APIError, AuthenticationError, BadRequestError, RateLimitError, ServerError, NotFoundError } from "../../errors/index.js";
2
+ export async function handleXAIError(response, model) {
3
+ const status = response.status;
4
+ let errorMessage = `xAI API identification failed with status ${status}`;
5
+ let errorData = {};
6
+ try {
7
+ const text = await response.text();
8
+ console.error("XAI ERROR RESPONSE:", text);
9
+ errorData = JSON.parse(text);
10
+ errorMessage = errorData.error?.message || errorMessage;
11
+ }
12
+ catch (_e) {
13
+ // Ignore JSON parsing errors
14
+ }
15
+ const provider = "xai";
16
+ switch (status) {
17
+ case 401:
18
+ throw new AuthenticationError(errorMessage, status, errorData, provider);
19
+ case 400:
20
+ throw new BadRequestError(errorMessage, errorData, provider, model);
21
+ case 404:
22
+ throw new NotFoundError(errorMessage, status, errorData, provider, model);
23
+ case 429:
24
+ throw new RateLimitError(errorMessage, errorData, provider, model);
25
+ case 500:
26
+ case 502:
27
+ case 503:
28
+ case 504:
29
+ throw new ServerError(errorMessage, status, errorData, provider, model);
30
+ default:
31
+ throw new APIError(errorMessage, status, errorData, provider, model);
32
+ }
33
+ }
@@ -0,0 +1,8 @@
1
+ import { ImageRequest, ImageResponse } from "../Provider.js";
2
+ export declare class XAIImage {
3
+ private readonly baseUrl;
4
+ private readonly apiKey;
5
+ constructor(baseUrl: string, apiKey: string);
6
+ execute(request: ImageRequest): Promise<ImageResponse>;
7
+ }
8
+ //# sourceMappingURL=Image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAY7D,qBAAa,QAAQ;IAEjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CA6C7D"}
@@ -0,0 +1,47 @@
1
+ import { handleXAIError } from "./Errors.js";
2
+ import { logger } from "../../utils/logger.js";
3
+ import { fetchWithTimeout } from "../../utils/fetch.js";
4
+ export class XAIImage {
5
+ baseUrl;
6
+ apiKey;
7
+ constructor(baseUrl, apiKey) {
8
+ this.baseUrl = baseUrl;
9
+ this.apiKey = apiKey;
10
+ }
11
+ async execute(request) {
12
+ const body = {
13
+ model: request.model || "grok-imagine-image",
14
+ prompt: request.prompt
15
+ };
16
+ if (request.size)
17
+ body.size = request.size;
18
+ if (request.n)
19
+ body.n = request.n;
20
+ if (request.quality)
21
+ body.quality = request.quality;
22
+ const url = `${this.baseUrl}/images/generations`;
23
+ logger.logRequest("xAI", "POST", url, body);
24
+ const response = await fetchWithTimeout(url, {
25
+ method: "POST",
26
+ headers: {
27
+ Authorization: `Bearer ${this.apiKey}`,
28
+ "Content-Type": "application/json"
29
+ },
30
+ body: JSON.stringify(body)
31
+ }, request.requestTimeout);
32
+ if (!response.ok) {
33
+ await handleXAIError(response, request.model);
34
+ }
35
+ const json = (await response.json());
36
+ logger.logResponse("xAI", response.status, response.statusText, json);
37
+ const data = json.data?.[0];
38
+ if (!data) {
39
+ throw new Error("xAI returned empty image response");
40
+ }
41
+ return {
42
+ url: data.url,
43
+ revised_prompt: data.revised_prompt,
44
+ mime_type: "image/png"
45
+ };
46
+ }
47
+ }
@@ -0,0 +1,8 @@
1
+ import { ModelInfo } from "../Provider.js";
2
+ export declare class XAIModels {
3
+ private readonly baseUrl;
4
+ private readonly apiKey;
5
+ constructor(baseUrl: string, apiKey: string);
6
+ execute(): Promise<ModelInfo[]>;
7
+ }
8
+ //# sourceMappingURL=Models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/Models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAa3C,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAoCtC"}
@@ -0,0 +1,47 @@
1
+ import { fetchWithTimeout } from "../../utils/fetch.js";
2
+ import { handleXAIError } from "./Errors.js";
3
+ import { Capabilities } from "./Capabilities.js";
4
+ export class XAIModels {
5
+ baseUrl;
6
+ apiKey;
7
+ constructor(baseUrl, apiKey) {
8
+ this.baseUrl = baseUrl;
9
+ this.apiKey = apiKey;
10
+ }
11
+ async execute() {
12
+ const url = `${this.baseUrl}/models`;
13
+ const response = await fetchWithTimeout(url, {
14
+ method: "GET",
15
+ headers: {
16
+ Authorization: `Bearer ${this.apiKey}`,
17
+ "Content-Type": "application/json"
18
+ }
19
+ });
20
+ if (!response.ok) {
21
+ await handleXAIError(response);
22
+ }
23
+ const json = (await response.json());
24
+ return json.data.map((m) => {
25
+ const caps = [];
26
+ if (Capabilities.supportsVision(m.id))
27
+ caps.push("vision");
28
+ if (Capabilities.supportsTools(m.id))
29
+ caps.push("tools");
30
+ if (Capabilities.supportsStructuredOutput(m.id))
31
+ caps.push("structured_output");
32
+ if (Capabilities.supportsReasoning(m.id))
33
+ caps.push("reasoning");
34
+ return {
35
+ id: m.id,
36
+ name: m.id,
37
+ provider: "xai",
38
+ family: "grok",
39
+ context_window: Capabilities.getContextWindow(m.id),
40
+ max_output_tokens: null,
41
+ modalities: { input: ["text", "image"], output: ["text"] },
42
+ capabilities: caps,
43
+ pricing: {}
44
+ };
45
+ });
46
+ }
47
+ }
@@ -0,0 +1,8 @@
1
+ import { ChatRequest, ChatChunk } from "../Provider.js";
2
+ export declare class XAIStreaming {
3
+ private readonly baseUrl;
4
+ private readonly apiKey;
5
+ constructor(baseUrl: string, apiKey: string);
6
+ execute(request: ChatRequest, controller?: AbortController): AsyncGenerator<ChatChunk>;
7
+ }
8
+ //# sourceMappingURL=Streaming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CA2L9F"}
@@ -0,0 +1,167 @@
1
+ import { APIError } from "../../errors/index.js";
2
+ import { logger } from "../../utils/logger.js";
3
+ import { handleXAIError } from "./Errors.js";
4
+ import { mapSystemMessages } from "../utils.js";
5
+ import { fetchWithTimeout } from "../../utils/fetch.js";
6
+ export class XAIStreaming {
7
+ baseUrl;
8
+ apiKey;
9
+ constructor(baseUrl, apiKey) {
10
+ this.baseUrl = baseUrl;
11
+ this.apiKey = apiKey;
12
+ }
13
+ async *execute(request, controller) {
14
+ const abortController = controller || new AbortController();
15
+ const { model, messages, tools, max_tokens, response_format, thinking: _thinking, headers: _headers, requestTimeout, ...rest } = request;
16
+ const mappedMessages = mapSystemMessages(messages, false);
17
+ const body = {
18
+ model,
19
+ messages: mappedMessages,
20
+ stream: true,
21
+ ...rest
22
+ };
23
+ if (max_tokens)
24
+ body.max_tokens = max_tokens;
25
+ if (tools && tools.length > 0)
26
+ body.tools = tools;
27
+ if (response_format)
28
+ body.response_format = response_format;
29
+ // xAI supports include_usage
30
+ body.stream_options = { include_usage: true };
31
+ let done = false;
32
+ // Track tool calls being built across chunks
33
+ const toolCallsMap = new Map();
34
+ try {
35
+ const url = `${this.baseUrl}/chat/completions`;
36
+ logger.logRequest("xAI", "POST", url, body);
37
+ const response = await fetchWithTimeout(url, {
38
+ method: "POST",
39
+ headers: {
40
+ Authorization: `Bearer ${this.apiKey}`,
41
+ "Content-Type": "application/json",
42
+ ...request.headers
43
+ },
44
+ body: JSON.stringify(body),
45
+ signal: abortController.signal
46
+ }, requestTimeout);
47
+ if (!response.ok) {
48
+ await handleXAIError(response, model);
49
+ }
50
+ logger.debug("xAI streaming started", {
51
+ status: response.status,
52
+ statusText: response.statusText
53
+ });
54
+ if (!response.body) {
55
+ throw new Error("No response body for streaming");
56
+ }
57
+ const reader = response.body.getReader();
58
+ const decoder = new TextDecoder();
59
+ let buffer = "";
60
+ while (true) {
61
+ const { value, done: readerDone } = await reader.read();
62
+ if (readerDone)
63
+ break;
64
+ const chunk = decoder.decode(value, { stream: true });
65
+ buffer += chunk;
66
+ const lines = buffer.split("\n\n");
67
+ buffer = lines.pop() || "";
68
+ for (const line of lines) {
69
+ let trimmed = line.trim();
70
+ // Handle carriage returns
71
+ if (trimmed.endsWith("\r")) {
72
+ trimmed = trimmed.substring(0, trimmed.length - 1);
73
+ }
74
+ if (!trimmed.startsWith("data: "))
75
+ continue;
76
+ const data = trimmed.replace("data: ", "").trim();
77
+ if (data === "[DONE]") {
78
+ done = true;
79
+ // Yield final tool calls if any were accumulated
80
+ if (toolCallsMap.size > 0) {
81
+ const toolCalls = Array.from(toolCallsMap.values()).map((tc) => ({
82
+ id: tc.id,
83
+ type: "function",
84
+ function: {
85
+ name: tc.function.name,
86
+ arguments: tc.function.arguments
87
+ }
88
+ }));
89
+ yield { content: "", tool_calls: toolCalls, done: true };
90
+ }
91
+ return;
92
+ }
93
+ try {
94
+ const json = JSON.parse(data);
95
+ // Check for errors in the data
96
+ if (json.error) {
97
+ throw new APIError("xAI", response.status, json.error.message || "Stream error");
98
+ }
99
+ const delta = json.choices?.[0]?.delta;
100
+ const deltaContent = delta?.content;
101
+ if (deltaContent) {
102
+ yield {
103
+ content: deltaContent || ""
104
+ };
105
+ }
106
+ // Handle tool calls delta
107
+ if (delta?.tool_calls) {
108
+ for (const toolCallDelta of delta.tool_calls) {
109
+ const index = toolCallDelta.index;
110
+ if (!toolCallsMap.has(index)) {
111
+ toolCallsMap.set(index, {
112
+ id: toolCallDelta.id || "",
113
+ type: "function",
114
+ function: {
115
+ name: toolCallDelta.function?.name || "",
116
+ arguments: toolCallDelta.function?.arguments || ""
117
+ }
118
+ });
119
+ }
120
+ else {
121
+ const existing = toolCallsMap.get(index);
122
+ if (toolCallDelta.id)
123
+ existing.id = toolCallDelta.id;
124
+ if (toolCallDelta.function?.name) {
125
+ existing.function.name += toolCallDelta.function.name;
126
+ }
127
+ if (toolCallDelta.function?.arguments) {
128
+ existing.function.arguments += toolCallDelta.function.arguments;
129
+ }
130
+ }
131
+ }
132
+ }
133
+ // Handle usage
134
+ if (json.usage) {
135
+ const usage = {
136
+ input_tokens: json.usage.prompt_tokens,
137
+ output_tokens: json.usage.completion_tokens,
138
+ total_tokens: json.usage.total_tokens
139
+ };
140
+ yield { content: "", usage };
141
+ }
142
+ }
143
+ catch (e) {
144
+ // Re-throw APIError
145
+ if (e instanceof APIError)
146
+ throw e;
147
+ // Ignore other parse errors
148
+ }
149
+ }
150
+ }
151
+ done = true;
152
+ }
153
+ catch (e) {
154
+ // Graceful exit on abort
155
+ if (e instanceof Error && e.name === "AbortError") {
156
+ return;
157
+ }
158
+ throw e;
159
+ }
160
+ finally {
161
+ // Cleanup: abort if user breaks early
162
+ if (!done) {
163
+ abortController.abort();
164
+ }
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,37 @@
1
+ import { Provider, ChatRequest, ChatResponse, ModelInfo, ChatChunk, ImageRequest, ImageResponse } from "../Provider.js";
2
+ import { BaseProvider } from "../BaseProvider.js";
3
+ export interface XAIProviderOptions {
4
+ apiKey: string;
5
+ baseUrl?: string;
6
+ }
7
+ export declare class XAIProvider extends BaseProvider implements Provider {
8
+ private readonly options;
9
+ private readonly baseUrl;
10
+ private readonly chatHandler;
11
+ private readonly streamingHandler;
12
+ private readonly modelsHandler;
13
+ private readonly imageHandler;
14
+ capabilities: {
15
+ supportsVision: (model: string) => boolean;
16
+ supportsTools: (model: string) => boolean;
17
+ supportsStructuredOutput: (model: string) => boolean;
18
+ supportsEmbeddings: (model: string) => boolean;
19
+ supportsImageGeneration: (model: string) => boolean;
20
+ supportsTranscription: (model: string) => boolean;
21
+ supportsModeration: (model: string) => boolean;
22
+ supportsReasoning: (model: string) => boolean;
23
+ supportsDeveloperRole: (_model: string) => boolean;
24
+ getContextWindow: (model: string) => number;
25
+ };
26
+ constructor(options: XAIProviderOptions);
27
+ get id(): string;
28
+ apiBase(): string;
29
+ headers(): Record<string, string>;
30
+ protected providerName(): string;
31
+ defaultModel(_feature?: string): string;
32
+ chat(request: ChatRequest): Promise<ChatResponse>;
33
+ stream(request: ChatRequest): AsyncGenerator<ChatChunk>;
34
+ listModels(): Promise<ModelInfo[]>;
35
+ paint(request: ImageRequest): Promise<ImageResponse>;
36
+ }
37
+ //# sourceMappingURL=XAIProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XAIProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/XAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAQlD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAY,SAAQ,YAAa,YAAW,QAAQ;IAoBnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAnBpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAe;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAY;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAW;IAEjC,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;oCACZ,MAAM;yCACD,MAAM;uCACR,MAAM;oCACT,MAAM;mCACP,MAAM;wCACD,MAAM;kCACZ,MAAM;MAChC;gBAE2B,OAAO,EAAE,kBAAkB;IASxD,IAAW,EAAE,IAAI,MAAM,CAEtB;IAEM,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAIjD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAG3D"}
@@ -0,0 +1,66 @@
1
+ import { BaseProvider } from "../BaseProvider.js";
2
+ import { DEFAULT_XAI_BASE_URL } from "../../constants.js";
3
+ import { XAIChat } from "./Chat.js";
4
+ import { XAIModels } from "./Models.js";
5
+ import { XAIStreaming } from "./Streaming.js";
6
+ import { Capabilities } from "./Capabilities.js";
7
+ import { XAIImage } from "./Image.js";
8
+ export class XAIProvider extends BaseProvider {
9
+ options;
10
+ baseUrl;
11
+ chatHandler;
12
+ streamingHandler;
13
+ modelsHandler;
14
+ imageHandler;
15
+ capabilities = {
16
+ supportsVision: (model) => Capabilities.supportsVision(model),
17
+ supportsTools: (model) => Capabilities.supportsTools(model),
18
+ supportsStructuredOutput: (model) => Capabilities.supportsStructuredOutput(model),
19
+ supportsEmbeddings: (model) => Capabilities.supportsEmbeddings(model),
20
+ supportsImageGeneration: (model) => Capabilities.supportsImageGeneration(model),
21
+ supportsTranscription: (model) => Capabilities.supportsTranscription(model),
22
+ supportsModeration: (model) => Capabilities.supportsModeration(model),
23
+ supportsReasoning: (model) => Capabilities.supportsReasoning(model),
24
+ supportsDeveloperRole: (_model) => false,
25
+ getContextWindow: (model) => Capabilities.getContextWindow(model)
26
+ };
27
+ constructor(options) {
28
+ super();
29
+ this.options = options;
30
+ this.baseUrl = options.baseUrl ?? DEFAULT_XAI_BASE_URL;
31
+ this.chatHandler = new XAIChat(this.baseUrl, options.apiKey);
32
+ this.streamingHandler = new XAIStreaming(this.baseUrl, options.apiKey);
33
+ this.modelsHandler = new XAIModels(this.baseUrl, options.apiKey);
34
+ this.imageHandler = new XAIImage(this.baseUrl, options.apiKey);
35
+ }
36
+ get id() {
37
+ return "xai";
38
+ }
39
+ apiBase() {
40
+ return this.baseUrl;
41
+ }
42
+ headers() {
43
+ return {
44
+ Authorization: `Bearer ${this.options.apiKey}`,
45
+ "Content-Type": "application/json"
46
+ };
47
+ }
48
+ providerName() {
49
+ return "xAI";
50
+ }
51
+ defaultModel(_feature) {
52
+ return "grok-2";
53
+ }
54
+ async chat(request) {
55
+ return this.chatHandler.execute(request);
56
+ }
57
+ async *stream(request) {
58
+ yield* this.streamingHandler.execute(request);
59
+ }
60
+ async listModels() {
61
+ return this.modelsHandler.execute();
62
+ }
63
+ async paint(request) {
64
+ return this.imageHandler.execute(request);
65
+ }
66
+ }
@@ -0,0 +1,7 @@
1
+ import { NodeLLMConfig } from "../../config.js";
2
+ export * from "./XAIProvider.js";
3
+ /**
4
+ * Register the xAI provider.
5
+ */
6
+ export declare function registerXAIProvider(config?: NodeLLMConfig): void;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,cAAc,kBAAkB,CAAC;AAEjC;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,aAAa,QAgBzD"}
@@ -0,0 +1,19 @@
1
+ import { providerRegistry } from "../registry.js";
2
+ import { XAIProvider } from "./XAIProvider.js";
3
+ export * from "./XAIProvider.js";
4
+ /**
5
+ * Register the xAI provider.
6
+ */
7
+ export function registerXAIProvider(config) {
8
+ providerRegistry.register("xai", (cfg) => {
9
+ const activeConfig = cfg || config;
10
+ const apiKey = activeConfig?.xaiApiKey;
11
+ if (!apiKey) {
12
+ throw new Error("xAI API key not found. Please provide 'xaiApiKey' in config or set XAI_API_KEY environment variable.");
13
+ }
14
+ return new XAIProvider({
15
+ apiKey,
16
+ baseUrl: activeConfig?.xaiApiBase
17
+ });
18
+ });
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-llm/core",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",