@ai-sdk/xai 4.0.0-beta.2 → 4.0.0-beta.21
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.
- package/CHANGELOG.md +156 -8
- package/README.md +2 -0
- package/dist/index.d.mts +51 -43
- package/dist/index.d.ts +51 -43
- package/dist/index.js +110 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -50
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +30 -336
- package/package.json +4 -6
- package/src/convert-to-xai-chat-messages.ts +5 -5
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +7 -5
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +2 -2
- package/src/responses/xai-responses-api.ts +3 -0
- package/src/responses/xai-responses-language-model.ts +71 -30
- package/src/responses/xai-responses-options.ts +4 -0
- package/src/responses/xai-responses-prepare-tools.ts +6 -6
- package/src/xai-chat-language-model.ts +41 -22
- package/src/xai-chat-options.ts +3 -6
- package/src/xai-image-model.ts +43 -28
- package/src/xai-image-options.ts +2 -0
- package/src/xai-image-settings.ts +0 -2
- package/src/xai-prepare-tools.ts +6 -6
- package/src/xai-provider.ts +18 -21
- package/src/xai-video-model.ts +23 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderV4, LanguageModelV4, ImageModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
-
type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-
|
|
6
|
+
type XaiChatModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-0309-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-code-fast-1' | 'grok-4' | 'grok-4-0709' | 'grok-4-latest' | 'grok-3' | 'grok-3-latest' | 'grok-3-mini' | 'grok-3-mini-latest' | (string & {});
|
|
7
7
|
declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
8
8
|
reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
9
9
|
low: "low";
|
|
@@ -58,7 +58,7 @@ declare const xaiErrorDataSchema: z.ZodObject<{
|
|
|
58
58
|
}, z.core.$strip>;
|
|
59
59
|
type XaiErrorData = z.infer<typeof xaiErrorDataSchema>;
|
|
60
60
|
|
|
61
|
-
type XaiResponsesModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | (string & {});
|
|
61
|
+
type XaiResponsesModelId = 'grok-4-1-fast-reasoning' | 'grok-4-1-fast-non-reasoning' | 'grok-4' | 'grok-4-fast-non-reasoning' | 'grok-4-fast-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-0309-reasoning' | 'grok-4.20-multi-agent-0309' | (string & {});
|
|
62
62
|
/**
|
|
63
63
|
* @see https://docs.x.ai/docs/api-reference#create-new-response
|
|
64
64
|
*/
|
|
@@ -68,6 +68,11 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
|
68
68
|
high: "high";
|
|
69
69
|
medium: "medium";
|
|
70
70
|
}>>;
|
|
71
|
+
reasoningSummary: z.ZodOptional<z.ZodEnum<{
|
|
72
|
+
auto: "auto";
|
|
73
|
+
concise: "concise";
|
|
74
|
+
detailed: "detailed";
|
|
75
|
+
}>>;
|
|
71
76
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
72
77
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
73
78
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -86,6 +91,12 @@ declare const xaiImageModelOptions: z.ZodObject<{
|
|
|
86
91
|
"1k": "1k";
|
|
87
92
|
"2k": "2k";
|
|
88
93
|
}>>;
|
|
94
|
+
quality: z.ZodOptional<z.ZodEnum<{
|
|
95
|
+
low: "low";
|
|
96
|
+
high: "high";
|
|
97
|
+
medium: "medium";
|
|
98
|
+
}>>;
|
|
99
|
+
user: z.ZodOptional<z.ZodString>;
|
|
89
100
|
}, z.core.$strip>;
|
|
90
101
|
type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
|
|
91
102
|
|
|
@@ -99,16 +110,16 @@ type XaiVideoModelOptions = {
|
|
|
99
110
|
[key: string]: unknown;
|
|
100
111
|
};
|
|
101
112
|
|
|
102
|
-
type XaiImageModelId = 'grok-
|
|
113
|
+
type XaiImageModelId = 'grok-imagine-image' | 'grok-imagine-image-pro' | (string & {});
|
|
103
114
|
|
|
104
115
|
declare const codeExecutionToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
|
|
105
116
|
output: string;
|
|
106
117
|
error?: string | undefined;
|
|
107
|
-
}, object>;
|
|
118
|
+
}, object, {}>;
|
|
108
119
|
declare const codeExecution: (args?: Parameters<typeof codeExecutionToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
109
120
|
output: string;
|
|
110
121
|
error?: string | undefined;
|
|
111
|
-
}>;
|
|
122
|
+
}, {}>;
|
|
112
123
|
|
|
113
124
|
declare const mcpServerToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
114
125
|
name: string;
|
|
@@ -121,32 +132,32 @@ declare const mcpServerToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWi
|
|
|
121
132
|
allowedTools?: string[];
|
|
122
133
|
headers?: Record<string, string>;
|
|
123
134
|
authorization?: string;
|
|
124
|
-
}>;
|
|
135
|
+
}, {}>;
|
|
125
136
|
declare const mcpServer: (args: Parameters<typeof mcpServerToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
126
137
|
name: string;
|
|
127
138
|
arguments: string;
|
|
128
139
|
result: unknown;
|
|
129
|
-
}>;
|
|
140
|
+
}, {}>;
|
|
130
141
|
|
|
131
142
|
declare const viewImageToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
|
|
132
143
|
description: string;
|
|
133
144
|
objects?: string[] | undefined;
|
|
134
|
-
}, object>;
|
|
145
|
+
}, object, {}>;
|
|
135
146
|
declare const viewImage: (args?: Parameters<typeof viewImageToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
136
147
|
description: string;
|
|
137
148
|
objects?: string[] | undefined;
|
|
138
|
-
}>;
|
|
149
|
+
}, {}>;
|
|
139
150
|
|
|
140
151
|
declare const viewXVideoToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
|
|
141
152
|
description: string;
|
|
142
153
|
transcript?: string | undefined;
|
|
143
154
|
duration?: number | undefined;
|
|
144
|
-
}, object>;
|
|
155
|
+
}, object, {}>;
|
|
145
156
|
declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
146
157
|
description: string;
|
|
147
158
|
transcript?: string | undefined;
|
|
148
159
|
duration?: number | undefined;
|
|
149
|
-
}>;
|
|
160
|
+
}, {}>;
|
|
150
161
|
|
|
151
162
|
declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
152
163
|
query: string;
|
|
@@ -159,7 +170,7 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWi
|
|
|
159
170
|
allowedDomains?: string[];
|
|
160
171
|
excludedDomains?: string[];
|
|
161
172
|
enableImageUnderstanding?: boolean;
|
|
162
|
-
}>;
|
|
173
|
+
}, {}>;
|
|
163
174
|
declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
164
175
|
query: string;
|
|
165
176
|
sources: Array<{
|
|
@@ -167,7 +178,7 @@ declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) =>
|
|
|
167
178
|
url: string;
|
|
168
179
|
snippet: string;
|
|
169
180
|
}>;
|
|
170
|
-
}>;
|
|
181
|
+
}, {}>;
|
|
171
182
|
|
|
172
183
|
declare const xSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
173
184
|
query: string;
|
|
@@ -184,7 +195,7 @@ declare const xSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWith
|
|
|
184
195
|
toDate?: string;
|
|
185
196
|
enableImageUnderstanding?: boolean;
|
|
186
197
|
enableVideoUnderstanding?: boolean;
|
|
187
|
-
}>;
|
|
198
|
+
}, {}>;
|
|
188
199
|
declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
189
200
|
query: string;
|
|
190
201
|
posts: Array<{
|
|
@@ -193,16 +204,16 @@ declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_
|
|
|
193
204
|
url: string;
|
|
194
205
|
likes: number;
|
|
195
206
|
}>;
|
|
196
|
-
}>;
|
|
207
|
+
}, {}>;
|
|
197
208
|
|
|
198
209
|
declare const xaiTools: {
|
|
199
210
|
codeExecution: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
|
|
200
211
|
output: string;
|
|
201
212
|
error?: string | undefined;
|
|
202
|
-
}, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
213
|
+
}, object, {}>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
203
214
|
output: string;
|
|
204
215
|
error?: string | undefined;
|
|
205
|
-
}>;
|
|
216
|
+
}, {}>;
|
|
206
217
|
fileSearch: (args: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
207
218
|
queries: string[];
|
|
208
219
|
results: null | {
|
|
@@ -214,7 +225,7 @@ declare const xaiTools: {
|
|
|
214
225
|
}, {
|
|
215
226
|
vectorStoreIds: string[];
|
|
216
227
|
maxNumResults?: number;
|
|
217
|
-
}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
228
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
218
229
|
queries: string[];
|
|
219
230
|
results: null | {
|
|
220
231
|
fileId: string;
|
|
@@ -222,7 +233,7 @@ declare const xaiTools: {
|
|
|
222
233
|
score: number;
|
|
223
234
|
text: string;
|
|
224
235
|
}[];
|
|
225
|
-
}>;
|
|
236
|
+
}, {}>;
|
|
226
237
|
mcpServer: (args: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
227
238
|
name: string;
|
|
228
239
|
arguments: string;
|
|
@@ -234,27 +245,27 @@ declare const xaiTools: {
|
|
|
234
245
|
allowedTools?: string[];
|
|
235
246
|
headers?: Record<string, string>;
|
|
236
247
|
authorization?: string;
|
|
237
|
-
}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
248
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
238
249
|
name: string;
|
|
239
250
|
arguments: string;
|
|
240
251
|
result: unknown;
|
|
241
|
-
}>;
|
|
252
|
+
}, {}>;
|
|
242
253
|
viewImage: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
|
|
243
254
|
description: string;
|
|
244
255
|
objects?: string[] | undefined;
|
|
245
|
-
}, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
256
|
+
}, object, {}>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
246
257
|
description: string;
|
|
247
258
|
objects?: string[] | undefined;
|
|
248
|
-
}>;
|
|
259
|
+
}, {}>;
|
|
249
260
|
viewXVideo: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<Record<string, never>, {
|
|
250
261
|
description: string;
|
|
251
262
|
transcript?: string | undefined;
|
|
252
263
|
duration?: number | undefined;
|
|
253
|
-
}, object>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
264
|
+
}, object, {}>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
|
|
254
265
|
description: string;
|
|
255
266
|
transcript?: string | undefined;
|
|
256
267
|
duration?: number | undefined;
|
|
257
|
-
}>;
|
|
268
|
+
}, {}>;
|
|
258
269
|
webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
259
270
|
query: string;
|
|
260
271
|
sources: Array<{
|
|
@@ -266,14 +277,14 @@ declare const xaiTools: {
|
|
|
266
277
|
allowedDomains?: string[];
|
|
267
278
|
excludedDomains?: string[];
|
|
268
279
|
enableImageUnderstanding?: boolean;
|
|
269
|
-
}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
280
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
270
281
|
query: string;
|
|
271
282
|
sources: Array<{
|
|
272
283
|
title: string;
|
|
273
284
|
url: string;
|
|
274
285
|
snippet: string;
|
|
275
286
|
}>;
|
|
276
|
-
}>;
|
|
287
|
+
}, {}>;
|
|
277
288
|
xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
|
|
278
289
|
query: string;
|
|
279
290
|
posts: Array<{
|
|
@@ -289,7 +300,7 @@ declare const xaiTools: {
|
|
|
289
300
|
toDate?: string;
|
|
290
301
|
enableImageUnderstanding?: boolean;
|
|
291
302
|
enableVideoUnderstanding?: boolean;
|
|
292
|
-
}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
303
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
|
|
293
304
|
query: string;
|
|
294
305
|
posts: Array<{
|
|
295
306
|
author: string;
|
|
@@ -297,42 +308,39 @@ declare const xaiTools: {
|
|
|
297
308
|
url: string;
|
|
298
309
|
likes: number;
|
|
299
310
|
}>;
|
|
300
|
-
}>;
|
|
311
|
+
}, {}>;
|
|
301
312
|
};
|
|
302
313
|
|
|
303
|
-
interface XaiProvider extends
|
|
304
|
-
|
|
305
|
-
* Creates an Xai chat model for text generation.
|
|
306
|
-
*/
|
|
307
|
-
(modelId: XaiChatModelId): LanguageModelV3;
|
|
314
|
+
interface XaiProvider extends ProviderV4 {
|
|
315
|
+
(modelId: XaiResponsesModelId): LanguageModelV4;
|
|
308
316
|
/**
|
|
309
317
|
* Creates an Xai language model for text generation.
|
|
310
318
|
*/
|
|
311
|
-
languageModel(modelId:
|
|
319
|
+
languageModel(modelId: XaiResponsesModelId): LanguageModelV4;
|
|
312
320
|
/**
|
|
313
321
|
* Creates an Xai chat model for text generation.
|
|
314
322
|
*/
|
|
315
|
-
chat: (modelId: XaiChatModelId) =>
|
|
323
|
+
chat: (modelId: XaiChatModelId) => LanguageModelV4;
|
|
316
324
|
/**
|
|
317
|
-
* Creates an Xai responses model for
|
|
325
|
+
* Creates an Xai responses model for text generation.
|
|
318
326
|
*/
|
|
319
|
-
responses: (modelId: XaiResponsesModelId) =>
|
|
327
|
+
responses: (modelId: XaiResponsesModelId) => LanguageModelV4;
|
|
320
328
|
/**
|
|
321
329
|
* Creates an Xai image model for image generation.
|
|
322
330
|
*/
|
|
323
|
-
image(modelId: XaiImageModelId):
|
|
331
|
+
image(modelId: XaiImageModelId): ImageModelV4;
|
|
324
332
|
/**
|
|
325
333
|
* Creates an Xai image model for image generation.
|
|
326
334
|
*/
|
|
327
|
-
imageModel(modelId: XaiImageModelId):
|
|
335
|
+
imageModel(modelId: XaiImageModelId): ImageModelV4;
|
|
328
336
|
/**
|
|
329
337
|
* Creates an Xai video model for video generation.
|
|
330
338
|
*/
|
|
331
|
-
video(modelId: XaiVideoModelId):
|
|
339
|
+
video(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
332
340
|
/**
|
|
333
341
|
* Creates an Xai video model for video generation.
|
|
334
342
|
*/
|
|
335
|
-
videoModel(modelId: XaiVideoModelId):
|
|
343
|
+
videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
336
344
|
/**
|
|
337
345
|
* Server-side agentic tools for use with the responses API.
|
|
338
346
|
*/
|