@ai-sdk/xai 4.0.0-beta.34 → 4.0.0-beta.35
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 +13 -0
- package/dist/index.js +787 -739
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/index.d.mts +0 -451
- package/dist/index.mjs +0 -3390
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,50 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
codeExecution: () => codeExecution,
|
|
25
|
-
createXai: () => createXai,
|
|
26
|
-
mcpServer: () => mcpServer,
|
|
27
|
-
viewImage: () => viewImage,
|
|
28
|
-
viewXVideo: () => viewXVideo,
|
|
29
|
-
webSearch: () => webSearch,
|
|
30
|
-
xSearch: () => xSearch,
|
|
31
|
-
xai: () => xai,
|
|
32
|
-
xaiTools: () => xaiTools
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
|
|
36
1
|
// src/xai-provider.ts
|
|
37
|
-
|
|
38
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
generateId,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash,
|
|
9
|
+
withUserAgentSuffix
|
|
10
|
+
} from "@ai-sdk/provider-utils";
|
|
39
11
|
|
|
40
12
|
// src/xai-chat-language-model.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
13
|
+
import {
|
|
14
|
+
APICallError
|
|
15
|
+
} from "@ai-sdk/provider";
|
|
16
|
+
import {
|
|
17
|
+
combineHeaders,
|
|
18
|
+
createEventSourceResponseHandler,
|
|
19
|
+
createJsonResponseHandler,
|
|
20
|
+
extractResponseHeaders,
|
|
21
|
+
isCustomReasoning,
|
|
22
|
+
mapReasoningToProviderEffort,
|
|
23
|
+
parseProviderOptions,
|
|
24
|
+
postJsonToApi,
|
|
25
|
+
safeParseJSON
|
|
26
|
+
} from "@ai-sdk/provider-utils";
|
|
27
|
+
import { z as z3 } from "zod/v4";
|
|
44
28
|
|
|
45
29
|
// src/convert-to-xai-chat-messages.ts
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
import {
|
|
31
|
+
UnsupportedFunctionalityError
|
|
32
|
+
} from "@ai-sdk/provider";
|
|
33
|
+
import {
|
|
34
|
+
convertToBase64,
|
|
35
|
+
isProviderReference,
|
|
36
|
+
resolveProviderReference
|
|
37
|
+
} from "@ai-sdk/provider-utils";
|
|
48
38
|
function convertToXaiChatMessages(prompt) {
|
|
49
39
|
var _a;
|
|
50
40
|
const messages = [];
|
|
@@ -68,11 +58,11 @@ function convertToXaiChatMessages(prompt) {
|
|
|
68
58
|
return { type: "text", text: part.text };
|
|
69
59
|
}
|
|
70
60
|
case "file": {
|
|
71
|
-
if (
|
|
61
|
+
if (isProviderReference(part.data)) {
|
|
72
62
|
return {
|
|
73
63
|
type: "file",
|
|
74
64
|
file: {
|
|
75
|
-
file_id:
|
|
65
|
+
file_id: resolveProviderReference({
|
|
76
66
|
reference: part.data,
|
|
77
67
|
provider: "xai"
|
|
78
68
|
})
|
|
@@ -84,11 +74,11 @@ function convertToXaiChatMessages(prompt) {
|
|
|
84
74
|
return {
|
|
85
75
|
type: "image_url",
|
|
86
76
|
image_url: {
|
|
87
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
77
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
88
78
|
}
|
|
89
79
|
};
|
|
90
80
|
} else {
|
|
91
|
-
throw new
|
|
81
|
+
throw new UnsupportedFunctionalityError({
|
|
92
82
|
functionality: `file part media type ${part.mediaType}`
|
|
93
83
|
});
|
|
94
84
|
}
|
|
@@ -220,79 +210,79 @@ function mapXaiFinishReason(finishReason) {
|
|
|
220
210
|
}
|
|
221
211
|
|
|
222
212
|
// src/xai-chat-options.ts
|
|
223
|
-
|
|
224
|
-
var webSourceSchema =
|
|
225
|
-
type:
|
|
226
|
-
country:
|
|
227
|
-
excludedWebsites:
|
|
228
|
-
allowedWebsites:
|
|
229
|
-
safeSearch:
|
|
213
|
+
import { z } from "zod/v4";
|
|
214
|
+
var webSourceSchema = z.object({
|
|
215
|
+
type: z.literal("web"),
|
|
216
|
+
country: z.string().length(2).optional(),
|
|
217
|
+
excludedWebsites: z.array(z.string()).max(5).optional(),
|
|
218
|
+
allowedWebsites: z.array(z.string()).max(5).optional(),
|
|
219
|
+
safeSearch: z.boolean().optional()
|
|
230
220
|
});
|
|
231
|
-
var xSourceSchema =
|
|
232
|
-
type:
|
|
233
|
-
excludedXHandles:
|
|
234
|
-
includedXHandles:
|
|
235
|
-
postFavoriteCount:
|
|
236
|
-
postViewCount:
|
|
221
|
+
var xSourceSchema = z.object({
|
|
222
|
+
type: z.literal("x"),
|
|
223
|
+
excludedXHandles: z.array(z.string()).optional(),
|
|
224
|
+
includedXHandles: z.array(z.string()).optional(),
|
|
225
|
+
postFavoriteCount: z.number().int().optional(),
|
|
226
|
+
postViewCount: z.number().int().optional(),
|
|
237
227
|
/**
|
|
238
228
|
* @deprecated use `includedXHandles` instead
|
|
239
229
|
*/
|
|
240
|
-
xHandles:
|
|
230
|
+
xHandles: z.array(z.string()).optional()
|
|
241
231
|
});
|
|
242
|
-
var newsSourceSchema =
|
|
243
|
-
type:
|
|
244
|
-
country:
|
|
245
|
-
excludedWebsites:
|
|
246
|
-
safeSearch:
|
|
232
|
+
var newsSourceSchema = z.object({
|
|
233
|
+
type: z.literal("news"),
|
|
234
|
+
country: z.string().length(2).optional(),
|
|
235
|
+
excludedWebsites: z.array(z.string()).max(5).optional(),
|
|
236
|
+
safeSearch: z.boolean().optional()
|
|
247
237
|
});
|
|
248
|
-
var rssSourceSchema =
|
|
249
|
-
type:
|
|
250
|
-
links:
|
|
238
|
+
var rssSourceSchema = z.object({
|
|
239
|
+
type: z.literal("rss"),
|
|
240
|
+
links: z.array(z.string().url()).max(1)
|
|
251
241
|
// currently only supports one RSS link
|
|
252
242
|
});
|
|
253
|
-
var searchSourceSchema =
|
|
243
|
+
var searchSourceSchema = z.discriminatedUnion("type", [
|
|
254
244
|
webSourceSchema,
|
|
255
245
|
xSourceSchema,
|
|
256
246
|
newsSourceSchema,
|
|
257
247
|
rssSourceSchema
|
|
258
248
|
]);
|
|
259
|
-
var xaiLanguageModelChatOptions =
|
|
260
|
-
reasoningEffort:
|
|
261
|
-
logprobs:
|
|
262
|
-
topLogprobs:
|
|
249
|
+
var xaiLanguageModelChatOptions = z.object({
|
|
250
|
+
reasoningEffort: z.enum(["low", "high"]).optional(),
|
|
251
|
+
logprobs: z.boolean().optional(),
|
|
252
|
+
topLogprobs: z.number().int().min(0).max(8).optional(),
|
|
263
253
|
/**
|
|
264
254
|
* Whether to enable parallel function calling during tool use.
|
|
265
255
|
* When true, the model can call multiple functions in parallel.
|
|
266
256
|
* When false, the model will call functions sequentially.
|
|
267
257
|
* Defaults to true.
|
|
268
258
|
*/
|
|
269
|
-
parallel_function_calling:
|
|
270
|
-
searchParameters:
|
|
259
|
+
parallel_function_calling: z.boolean().optional(),
|
|
260
|
+
searchParameters: z.object({
|
|
271
261
|
/**
|
|
272
262
|
* search mode preference
|
|
273
263
|
* - "off": disables search completely
|
|
274
264
|
* - "auto": model decides whether to search (default)
|
|
275
265
|
* - "on": always enables search
|
|
276
266
|
*/
|
|
277
|
-
mode:
|
|
267
|
+
mode: z.enum(["off", "auto", "on"]),
|
|
278
268
|
/**
|
|
279
269
|
* whether to return citations in the response
|
|
280
270
|
* defaults to true
|
|
281
271
|
*/
|
|
282
|
-
returnCitations:
|
|
272
|
+
returnCitations: z.boolean().optional(),
|
|
283
273
|
/**
|
|
284
274
|
* start date for search data (ISO8601 format: YYYY-MM-DD)
|
|
285
275
|
*/
|
|
286
|
-
fromDate:
|
|
276
|
+
fromDate: z.string().optional(),
|
|
287
277
|
/**
|
|
288
278
|
* end date for search data (ISO8601 format: YYYY-MM-DD)
|
|
289
279
|
*/
|
|
290
|
-
toDate:
|
|
280
|
+
toDate: z.string().optional(),
|
|
291
281
|
/**
|
|
292
282
|
* maximum number of search results to consider
|
|
293
283
|
* defaults to 20
|
|
294
284
|
*/
|
|
295
|
-
maxSearchResults:
|
|
285
|
+
maxSearchResults: z.number().min(1).max(50).optional(),
|
|
296
286
|
/**
|
|
297
287
|
* data sources to search from.
|
|
298
288
|
* defaults to [{ type: 'web' }, { type: 'x' }] if not specified.
|
|
@@ -300,28 +290,30 @@ var xaiLanguageModelChatOptions = import_v4.z.object({
|
|
|
300
290
|
* @example
|
|
301
291
|
* sources: [{ type: 'web', country: 'US' }, { type: 'x' }]
|
|
302
292
|
*/
|
|
303
|
-
sources:
|
|
293
|
+
sources: z.array(searchSourceSchema).optional()
|
|
304
294
|
}).optional()
|
|
305
295
|
});
|
|
306
296
|
|
|
307
297
|
// src/xai-error.ts
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
var xaiErrorDataSchema =
|
|
311
|
-
error:
|
|
312
|
-
message:
|
|
313
|
-
type:
|
|
314
|
-
param:
|
|
315
|
-
code:
|
|
298
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
299
|
+
import { z as z2 } from "zod/v4";
|
|
300
|
+
var xaiErrorDataSchema = z2.object({
|
|
301
|
+
error: z2.object({
|
|
302
|
+
message: z2.string(),
|
|
303
|
+
type: z2.string().nullish(),
|
|
304
|
+
param: z2.any().nullish(),
|
|
305
|
+
code: z2.union([z2.string(), z2.number()]).nullish()
|
|
316
306
|
})
|
|
317
307
|
});
|
|
318
|
-
var xaiFailedResponseHandler =
|
|
308
|
+
var xaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
319
309
|
errorSchema: xaiErrorDataSchema,
|
|
320
310
|
errorToMessage: (data) => data.error.message
|
|
321
311
|
});
|
|
322
312
|
|
|
323
313
|
// src/xai-prepare-tools.ts
|
|
324
|
-
|
|
314
|
+
import {
|
|
315
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
316
|
+
} from "@ai-sdk/provider";
|
|
325
317
|
function prepareTools({
|
|
326
318
|
tools,
|
|
327
319
|
toolChoice
|
|
@@ -371,7 +363,7 @@ function prepareTools({
|
|
|
371
363
|
};
|
|
372
364
|
default: {
|
|
373
365
|
const _exhaustiveCheck = type;
|
|
374
|
-
throw new
|
|
366
|
+
throw new UnsupportedFunctionalityError2({
|
|
375
367
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
376
368
|
});
|
|
377
369
|
}
|
|
@@ -409,7 +401,7 @@ var XaiChatLanguageModel = class {
|
|
|
409
401
|
}) {
|
|
410
402
|
var _a, _b, _c, _d;
|
|
411
403
|
const warnings = [];
|
|
412
|
-
const options = (_a = await
|
|
404
|
+
const options = (_a = await parseProviderOptions({
|
|
413
405
|
provider: "xai",
|
|
414
406
|
providerOptions,
|
|
415
407
|
schema: xaiLanguageModelChatOptions
|
|
@@ -447,7 +439,7 @@ var XaiChatLanguageModel = class {
|
|
|
447
439
|
temperature,
|
|
448
440
|
top_p: topP,
|
|
449
441
|
seed,
|
|
450
|
-
reasoning_effort: (_b = options.reasoningEffort) != null ? _b :
|
|
442
|
+
reasoning_effort: (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort({
|
|
451
443
|
reasoning,
|
|
452
444
|
effortMap: {
|
|
453
445
|
minimal: "low",
|
|
@@ -522,19 +514,19 @@ var XaiChatLanguageModel = class {
|
|
|
522
514
|
responseHeaders,
|
|
523
515
|
value: response,
|
|
524
516
|
rawValue: rawResponse
|
|
525
|
-
} = await
|
|
517
|
+
} = await postJsonToApi({
|
|
526
518
|
url,
|
|
527
|
-
headers:
|
|
519
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
528
520
|
body,
|
|
529
521
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
530
|
-
successfulResponseHandler:
|
|
522
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
531
523
|
xaiChatResponseSchema
|
|
532
524
|
),
|
|
533
525
|
abortSignal: options.abortSignal,
|
|
534
526
|
fetch: this.config.fetch
|
|
535
527
|
});
|
|
536
528
|
if (response.error != null) {
|
|
537
|
-
throw new
|
|
529
|
+
throw new APICallError({
|
|
538
530
|
message: response.error,
|
|
539
531
|
url,
|
|
540
532
|
requestBodyValues: body,
|
|
@@ -612,22 +604,22 @@ var XaiChatLanguageModel = class {
|
|
|
612
604
|
}
|
|
613
605
|
};
|
|
614
606
|
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
615
|
-
const { responseHeaders, value: response } = await
|
|
607
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
616
608
|
url,
|
|
617
|
-
headers:
|
|
609
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
618
610
|
body,
|
|
619
611
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
620
612
|
successfulResponseHandler: async ({ response: response2 }) => {
|
|
621
|
-
const responseHeaders2 =
|
|
613
|
+
const responseHeaders2 = extractResponseHeaders(response2);
|
|
622
614
|
const contentType = response2.headers.get("content-type");
|
|
623
615
|
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
624
616
|
const responseBody = await response2.text();
|
|
625
|
-
const parsedError = await
|
|
617
|
+
const parsedError = await safeParseJSON({
|
|
626
618
|
text: responseBody,
|
|
627
619
|
schema: xaiStreamErrorSchema
|
|
628
620
|
});
|
|
629
621
|
if (parsedError.success) {
|
|
630
|
-
throw new
|
|
622
|
+
throw new APICallError({
|
|
631
623
|
message: parsedError.value.error,
|
|
632
624
|
url,
|
|
633
625
|
requestBodyValues: body,
|
|
@@ -637,7 +629,7 @@ var XaiChatLanguageModel = class {
|
|
|
637
629
|
isRetryable: parsedError.value.code === "The service is currently unavailable"
|
|
638
630
|
});
|
|
639
631
|
}
|
|
640
|
-
throw new
|
|
632
|
+
throw new APICallError({
|
|
641
633
|
message: "Invalid JSON response",
|
|
642
634
|
url,
|
|
643
635
|
requestBodyValues: body,
|
|
@@ -646,7 +638,7 @@ var XaiChatLanguageModel = class {
|
|
|
646
638
|
responseBody
|
|
647
639
|
});
|
|
648
640
|
}
|
|
649
|
-
return
|
|
641
|
+
return createEventSourceResponseHandler(xaiChatChunkSchema)({
|
|
650
642
|
response: response2,
|
|
651
643
|
url,
|
|
652
644
|
requestBodyValues: body
|
|
@@ -824,100 +816,109 @@ var XaiChatLanguageModel = class {
|
|
|
824
816
|
};
|
|
825
817
|
}
|
|
826
818
|
};
|
|
827
|
-
var xaiUsageSchema =
|
|
828
|
-
prompt_tokens:
|
|
829
|
-
completion_tokens:
|
|
830
|
-
total_tokens:
|
|
831
|
-
prompt_tokens_details:
|
|
832
|
-
text_tokens:
|
|
833
|
-
audio_tokens:
|
|
834
|
-
image_tokens:
|
|
835
|
-
cached_tokens:
|
|
819
|
+
var xaiUsageSchema = z3.object({
|
|
820
|
+
prompt_tokens: z3.number(),
|
|
821
|
+
completion_tokens: z3.number(),
|
|
822
|
+
total_tokens: z3.number(),
|
|
823
|
+
prompt_tokens_details: z3.object({
|
|
824
|
+
text_tokens: z3.number().nullish(),
|
|
825
|
+
audio_tokens: z3.number().nullish(),
|
|
826
|
+
image_tokens: z3.number().nullish(),
|
|
827
|
+
cached_tokens: z3.number().nullish()
|
|
836
828
|
}).nullish(),
|
|
837
|
-
completion_tokens_details:
|
|
838
|
-
reasoning_tokens:
|
|
839
|
-
audio_tokens:
|
|
840
|
-
accepted_prediction_tokens:
|
|
841
|
-
rejected_prediction_tokens:
|
|
829
|
+
completion_tokens_details: z3.object({
|
|
830
|
+
reasoning_tokens: z3.number().nullish(),
|
|
831
|
+
audio_tokens: z3.number().nullish(),
|
|
832
|
+
accepted_prediction_tokens: z3.number().nullish(),
|
|
833
|
+
rejected_prediction_tokens: z3.number().nullish()
|
|
842
834
|
}).nullish()
|
|
843
835
|
});
|
|
844
|
-
var xaiChatResponseSchema =
|
|
845
|
-
id:
|
|
846
|
-
created:
|
|
847
|
-
model:
|
|
848
|
-
choices:
|
|
849
|
-
|
|
850
|
-
message:
|
|
851
|
-
role:
|
|
852
|
-
content:
|
|
853
|
-
reasoning_content:
|
|
854
|
-
tool_calls:
|
|
855
|
-
|
|
856
|
-
id:
|
|
857
|
-
type:
|
|
858
|
-
function:
|
|
859
|
-
name:
|
|
860
|
-
arguments:
|
|
836
|
+
var xaiChatResponseSchema = z3.object({
|
|
837
|
+
id: z3.string().nullish(),
|
|
838
|
+
created: z3.number().nullish(),
|
|
839
|
+
model: z3.string().nullish(),
|
|
840
|
+
choices: z3.array(
|
|
841
|
+
z3.object({
|
|
842
|
+
message: z3.object({
|
|
843
|
+
role: z3.literal("assistant"),
|
|
844
|
+
content: z3.string().nullish(),
|
|
845
|
+
reasoning_content: z3.string().nullish(),
|
|
846
|
+
tool_calls: z3.array(
|
|
847
|
+
z3.object({
|
|
848
|
+
id: z3.string(),
|
|
849
|
+
type: z3.literal("function"),
|
|
850
|
+
function: z3.object({
|
|
851
|
+
name: z3.string(),
|
|
852
|
+
arguments: z3.string()
|
|
861
853
|
})
|
|
862
854
|
})
|
|
863
855
|
).nullish()
|
|
864
856
|
}),
|
|
865
|
-
index:
|
|
866
|
-
finish_reason:
|
|
857
|
+
index: z3.number(),
|
|
858
|
+
finish_reason: z3.string().nullish()
|
|
867
859
|
})
|
|
868
860
|
).nullish(),
|
|
869
|
-
object:
|
|
861
|
+
object: z3.literal("chat.completion").nullish(),
|
|
870
862
|
usage: xaiUsageSchema.nullish(),
|
|
871
|
-
citations:
|
|
872
|
-
code:
|
|
873
|
-
error:
|
|
863
|
+
citations: z3.array(z3.string().url()).nullish(),
|
|
864
|
+
code: z3.string().nullish(),
|
|
865
|
+
error: z3.string().nullish()
|
|
874
866
|
});
|
|
875
|
-
var xaiChatChunkSchema =
|
|
876
|
-
id:
|
|
877
|
-
created:
|
|
878
|
-
model:
|
|
879
|
-
choices:
|
|
880
|
-
|
|
881
|
-
delta:
|
|
882
|
-
role:
|
|
883
|
-
content:
|
|
884
|
-
reasoning_content:
|
|
885
|
-
tool_calls:
|
|
886
|
-
|
|
887
|
-
id:
|
|
888
|
-
type:
|
|
889
|
-
function:
|
|
890
|
-
name:
|
|
891
|
-
arguments:
|
|
867
|
+
var xaiChatChunkSchema = z3.object({
|
|
868
|
+
id: z3.string().nullish(),
|
|
869
|
+
created: z3.number().nullish(),
|
|
870
|
+
model: z3.string().nullish(),
|
|
871
|
+
choices: z3.array(
|
|
872
|
+
z3.object({
|
|
873
|
+
delta: z3.object({
|
|
874
|
+
role: z3.enum(["assistant"]).optional(),
|
|
875
|
+
content: z3.string().nullish(),
|
|
876
|
+
reasoning_content: z3.string().nullish(),
|
|
877
|
+
tool_calls: z3.array(
|
|
878
|
+
z3.object({
|
|
879
|
+
id: z3.string(),
|
|
880
|
+
type: z3.literal("function"),
|
|
881
|
+
function: z3.object({
|
|
882
|
+
name: z3.string(),
|
|
883
|
+
arguments: z3.string()
|
|
892
884
|
})
|
|
893
885
|
})
|
|
894
886
|
).nullish()
|
|
895
887
|
}),
|
|
896
|
-
finish_reason:
|
|
897
|
-
index:
|
|
888
|
+
finish_reason: z3.string().nullish(),
|
|
889
|
+
index: z3.number()
|
|
898
890
|
})
|
|
899
891
|
),
|
|
900
892
|
usage: xaiUsageSchema.nullish(),
|
|
901
|
-
citations:
|
|
893
|
+
citations: z3.array(z3.string().url()).nullish()
|
|
902
894
|
});
|
|
903
|
-
var xaiStreamErrorSchema =
|
|
904
|
-
code:
|
|
905
|
-
error:
|
|
895
|
+
var xaiStreamErrorSchema = z3.object({
|
|
896
|
+
code: z3.string(),
|
|
897
|
+
error: z3.string()
|
|
906
898
|
});
|
|
907
899
|
|
|
908
900
|
// src/xai-image-model.ts
|
|
909
|
-
|
|
910
|
-
|
|
901
|
+
import {
|
|
902
|
+
combineHeaders as combineHeaders2,
|
|
903
|
+
convertImageModelFileToDataUri,
|
|
904
|
+
createBinaryResponseHandler,
|
|
905
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
906
|
+
createStatusCodeErrorResponseHandler,
|
|
907
|
+
getFromApi,
|
|
908
|
+
parseProviderOptions as parseProviderOptions2,
|
|
909
|
+
postJsonToApi as postJsonToApi2
|
|
910
|
+
} from "@ai-sdk/provider-utils";
|
|
911
|
+
import { z as z5 } from "zod/v4";
|
|
911
912
|
|
|
912
913
|
// src/xai-image-options.ts
|
|
913
|
-
|
|
914
|
-
var xaiImageModelOptions =
|
|
915
|
-
aspect_ratio:
|
|
916
|
-
output_format:
|
|
917
|
-
sync_mode:
|
|
918
|
-
resolution:
|
|
919
|
-
quality:
|
|
920
|
-
user:
|
|
914
|
+
import { z as z4 } from "zod/v4";
|
|
915
|
+
var xaiImageModelOptions = z4.object({
|
|
916
|
+
aspect_ratio: z4.string().optional(),
|
|
917
|
+
output_format: z4.string().optional(),
|
|
918
|
+
sync_mode: z4.boolean().optional(),
|
|
919
|
+
resolution: z4.enum(["1k", "2k"]).optional(),
|
|
920
|
+
quality: z4.enum(["low", "medium", "high"]).optional(),
|
|
921
|
+
user: z4.string().optional()
|
|
921
922
|
});
|
|
922
923
|
|
|
923
924
|
// src/xai-image-model.ts
|
|
@@ -964,13 +965,13 @@ var XaiImageModel = class {
|
|
|
964
965
|
feature: "mask"
|
|
965
966
|
});
|
|
966
967
|
}
|
|
967
|
-
const xaiOptions = await (
|
|
968
|
+
const xaiOptions = await parseProviderOptions2({
|
|
968
969
|
provider: "xai",
|
|
969
970
|
providerOptions,
|
|
970
971
|
schema: xaiImageModelOptions
|
|
971
972
|
});
|
|
972
973
|
const hasFiles = files != null && files.length > 0;
|
|
973
|
-
const imageUrls = hasFiles ? files.map((file) =>
|
|
974
|
+
const imageUrls = hasFiles ? files.map((file) => convertImageModelFileToDataUri(file)) : [];
|
|
974
975
|
const endpoint = hasFiles ? "/images/edits" : "/images/generations";
|
|
975
976
|
const body = {
|
|
976
977
|
model: this.modelId,
|
|
@@ -1006,12 +1007,12 @@ var XaiImageModel = class {
|
|
|
1006
1007
|
}
|
|
1007
1008
|
const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
|
|
1008
1009
|
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
1009
|
-
const { value: response, responseHeaders } = await (
|
|
1010
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
1010
1011
|
url: `${baseURL}${endpoint}`,
|
|
1011
|
-
headers: (
|
|
1012
|
+
headers: combineHeaders2(this.config.headers(), headers),
|
|
1012
1013
|
body,
|
|
1013
1014
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1014
|
-
successfulResponseHandler: (
|
|
1015
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
1015
1016
|
xaiImageResponseSchema
|
|
1016
1017
|
),
|
|
1017
1018
|
abortSignal,
|
|
@@ -1042,35 +1043,49 @@ var XaiImageModel = class {
|
|
|
1042
1043
|
};
|
|
1043
1044
|
}
|
|
1044
1045
|
async downloadImage(url, abortSignal) {
|
|
1045
|
-
const { value } = await
|
|
1046
|
+
const { value } = await getFromApi({
|
|
1046
1047
|
url,
|
|
1047
1048
|
abortSignal,
|
|
1048
|
-
failedResponseHandler:
|
|
1049
|
-
successfulResponseHandler:
|
|
1049
|
+
failedResponseHandler: createStatusCodeErrorResponseHandler(),
|
|
1050
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
1050
1051
|
fetch: this.config.fetch
|
|
1051
1052
|
});
|
|
1052
1053
|
return value;
|
|
1053
1054
|
}
|
|
1054
1055
|
};
|
|
1055
|
-
var xaiImageResponseSchema =
|
|
1056
|
-
data:
|
|
1057
|
-
|
|
1058
|
-
url:
|
|
1059
|
-
b64_json:
|
|
1060
|
-
revised_prompt:
|
|
1056
|
+
var xaiImageResponseSchema = z5.object({
|
|
1057
|
+
data: z5.array(
|
|
1058
|
+
z5.object({
|
|
1059
|
+
url: z5.string().nullish(),
|
|
1060
|
+
b64_json: z5.string().nullish(),
|
|
1061
|
+
revised_prompt: z5.string().nullish()
|
|
1061
1062
|
})
|
|
1062
1063
|
),
|
|
1063
|
-
usage:
|
|
1064
|
-
cost_in_usd_ticks:
|
|
1064
|
+
usage: z5.object({
|
|
1065
|
+
cost_in_usd_ticks: z5.number().nullish()
|
|
1065
1066
|
}).nullish()
|
|
1066
1067
|
});
|
|
1067
1068
|
|
|
1068
1069
|
// src/responses/xai-responses-language-model.ts
|
|
1069
|
-
|
|
1070
|
+
import {
|
|
1071
|
+
combineHeaders as combineHeaders3,
|
|
1072
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
1073
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1074
|
+
isCustomReasoning as isCustomReasoning2,
|
|
1075
|
+
mapReasoningToProviderEffort as mapReasoningToProviderEffort2,
|
|
1076
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1077
|
+
postJsonToApi as postJsonToApi3
|
|
1078
|
+
} from "@ai-sdk/provider-utils";
|
|
1070
1079
|
|
|
1071
1080
|
// src/responses/convert-to-xai-responses-input.ts
|
|
1072
|
-
|
|
1073
|
-
|
|
1081
|
+
import {
|
|
1082
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1083
|
+
} from "@ai-sdk/provider";
|
|
1084
|
+
import {
|
|
1085
|
+
convertToBase64 as convertToBase642,
|
|
1086
|
+
isProviderReference as isProviderReference2,
|
|
1087
|
+
resolveProviderReference as resolveProviderReference2
|
|
1088
|
+
} from "@ai-sdk/provider-utils";
|
|
1074
1089
|
async function convertToXaiResponsesInput({
|
|
1075
1090
|
prompt
|
|
1076
1091
|
}) {
|
|
@@ -1095,20 +1110,20 @@ async function convertToXaiResponsesInput({
|
|
|
1095
1110
|
break;
|
|
1096
1111
|
}
|
|
1097
1112
|
case "file": {
|
|
1098
|
-
if ((
|
|
1113
|
+
if (isProviderReference2(block.data)) {
|
|
1099
1114
|
contentParts.push({
|
|
1100
1115
|
type: "input_file",
|
|
1101
|
-
file_id: (
|
|
1116
|
+
file_id: resolveProviderReference2({
|
|
1102
1117
|
reference: block.data,
|
|
1103
1118
|
provider: "xai"
|
|
1104
1119
|
})
|
|
1105
1120
|
});
|
|
1106
1121
|
} else if (block.mediaType.startsWith("image/")) {
|
|
1107
1122
|
const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
|
|
1108
|
-
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(
|
|
1123
|
+
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${convertToBase642(block.data)}`;
|
|
1109
1124
|
contentParts.push({ type: "input_image", image_url: imageUrl });
|
|
1110
1125
|
} else {
|
|
1111
|
-
throw new
|
|
1126
|
+
throw new UnsupportedFunctionalityError3({
|
|
1112
1127
|
functionality: `file part media type ${block.mediaType}`
|
|
1113
1128
|
});
|
|
1114
1129
|
}
|
|
@@ -1274,594 +1289,612 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1274
1289
|
}
|
|
1275
1290
|
|
|
1276
1291
|
// src/responses/xai-responses-api.ts
|
|
1277
|
-
|
|
1278
|
-
var annotationSchema =
|
|
1279
|
-
|
|
1280
|
-
type:
|
|
1281
|
-
url:
|
|
1282
|
-
title:
|
|
1292
|
+
import { z as z6 } from "zod/v4";
|
|
1293
|
+
var annotationSchema = z6.union([
|
|
1294
|
+
z6.object({
|
|
1295
|
+
type: z6.literal("url_citation"),
|
|
1296
|
+
url: z6.string(),
|
|
1297
|
+
title: z6.string().optional()
|
|
1283
1298
|
}),
|
|
1284
|
-
|
|
1285
|
-
type:
|
|
1299
|
+
z6.object({
|
|
1300
|
+
type: z6.string()
|
|
1286
1301
|
})
|
|
1287
1302
|
]);
|
|
1288
|
-
var messageContentPartSchema =
|
|
1289
|
-
type:
|
|
1290
|
-
text:
|
|
1291
|
-
logprobs:
|
|
1292
|
-
annotations:
|
|
1303
|
+
var messageContentPartSchema = z6.object({
|
|
1304
|
+
type: z6.string(),
|
|
1305
|
+
text: z6.string().optional(),
|
|
1306
|
+
logprobs: z6.array(z6.any()).optional(),
|
|
1307
|
+
annotations: z6.array(annotationSchema).optional()
|
|
1293
1308
|
});
|
|
1294
|
-
var reasoningSummaryPartSchema =
|
|
1295
|
-
type:
|
|
1296
|
-
text:
|
|
1309
|
+
var reasoningSummaryPartSchema = z6.object({
|
|
1310
|
+
type: z6.string(),
|
|
1311
|
+
text: z6.string()
|
|
1297
1312
|
});
|
|
1298
|
-
var toolCallSchema =
|
|
1299
|
-
name:
|
|
1300
|
-
arguments:
|
|
1301
|
-
input:
|
|
1302
|
-
call_id:
|
|
1303
|
-
id:
|
|
1304
|
-
status:
|
|
1305
|
-
action:
|
|
1313
|
+
var toolCallSchema = z6.object({
|
|
1314
|
+
name: z6.string().optional(),
|
|
1315
|
+
arguments: z6.string().optional(),
|
|
1316
|
+
input: z6.string().optional(),
|
|
1317
|
+
call_id: z6.string().optional(),
|
|
1318
|
+
id: z6.string(),
|
|
1319
|
+
status: z6.string(),
|
|
1320
|
+
action: z6.any().optional()
|
|
1306
1321
|
});
|
|
1307
|
-
var mcpCallSchema =
|
|
1308
|
-
name:
|
|
1309
|
-
arguments:
|
|
1310
|
-
output:
|
|
1311
|
-
error:
|
|
1312
|
-
id:
|
|
1313
|
-
status:
|
|
1314
|
-
server_label:
|
|
1322
|
+
var mcpCallSchema = z6.object({
|
|
1323
|
+
name: z6.string().optional(),
|
|
1324
|
+
arguments: z6.string().optional(),
|
|
1325
|
+
output: z6.string().optional(),
|
|
1326
|
+
error: z6.string().optional(),
|
|
1327
|
+
id: z6.string(),
|
|
1328
|
+
status: z6.string(),
|
|
1329
|
+
server_label: z6.string().optional()
|
|
1315
1330
|
});
|
|
1316
|
-
var outputItemSchema =
|
|
1317
|
-
|
|
1318
|
-
type:
|
|
1331
|
+
var outputItemSchema = z6.discriminatedUnion("type", [
|
|
1332
|
+
z6.object({
|
|
1333
|
+
type: z6.literal("web_search_call"),
|
|
1319
1334
|
...toolCallSchema.shape
|
|
1320
1335
|
}),
|
|
1321
|
-
|
|
1322
|
-
type:
|
|
1336
|
+
z6.object({
|
|
1337
|
+
type: z6.literal("x_search_call"),
|
|
1323
1338
|
...toolCallSchema.shape
|
|
1324
1339
|
}),
|
|
1325
|
-
|
|
1326
|
-
type:
|
|
1340
|
+
z6.object({
|
|
1341
|
+
type: z6.literal("code_interpreter_call"),
|
|
1327
1342
|
...toolCallSchema.shape
|
|
1328
1343
|
}),
|
|
1329
|
-
|
|
1330
|
-
type:
|
|
1344
|
+
z6.object({
|
|
1345
|
+
type: z6.literal("code_execution_call"),
|
|
1331
1346
|
...toolCallSchema.shape
|
|
1332
1347
|
}),
|
|
1333
|
-
|
|
1334
|
-
type:
|
|
1348
|
+
z6.object({
|
|
1349
|
+
type: z6.literal("view_image_call"),
|
|
1335
1350
|
...toolCallSchema.shape
|
|
1336
1351
|
}),
|
|
1337
|
-
|
|
1338
|
-
type:
|
|
1352
|
+
z6.object({
|
|
1353
|
+
type: z6.literal("view_x_video_call"),
|
|
1339
1354
|
...toolCallSchema.shape
|
|
1340
1355
|
}),
|
|
1341
|
-
|
|
1342
|
-
type:
|
|
1343
|
-
id:
|
|
1344
|
-
status:
|
|
1345
|
-
queries:
|
|
1346
|
-
results:
|
|
1347
|
-
|
|
1348
|
-
file_id:
|
|
1349
|
-
filename:
|
|
1350
|
-
score:
|
|
1351
|
-
text:
|
|
1356
|
+
z6.object({
|
|
1357
|
+
type: z6.literal("file_search_call"),
|
|
1358
|
+
id: z6.string(),
|
|
1359
|
+
status: z6.string(),
|
|
1360
|
+
queries: z6.array(z6.string()).optional(),
|
|
1361
|
+
results: z6.array(
|
|
1362
|
+
z6.object({
|
|
1363
|
+
file_id: z6.string(),
|
|
1364
|
+
filename: z6.string(),
|
|
1365
|
+
score: z6.number(),
|
|
1366
|
+
text: z6.string()
|
|
1352
1367
|
})
|
|
1353
1368
|
).nullish()
|
|
1354
1369
|
}),
|
|
1355
|
-
|
|
1356
|
-
type:
|
|
1370
|
+
z6.object({
|
|
1371
|
+
type: z6.literal("custom_tool_call"),
|
|
1357
1372
|
...toolCallSchema.shape
|
|
1358
1373
|
}),
|
|
1359
|
-
|
|
1360
|
-
type:
|
|
1374
|
+
z6.object({
|
|
1375
|
+
type: z6.literal("mcp_call"),
|
|
1361
1376
|
...mcpCallSchema.shape
|
|
1362
1377
|
}),
|
|
1363
|
-
|
|
1364
|
-
type:
|
|
1365
|
-
role:
|
|
1366
|
-
content:
|
|
1367
|
-
id:
|
|
1368
|
-
status:
|
|
1378
|
+
z6.object({
|
|
1379
|
+
type: z6.literal("message"),
|
|
1380
|
+
role: z6.string(),
|
|
1381
|
+
content: z6.array(messageContentPartSchema),
|
|
1382
|
+
id: z6.string(),
|
|
1383
|
+
status: z6.string()
|
|
1369
1384
|
}),
|
|
1370
|
-
|
|
1371
|
-
type:
|
|
1372
|
-
name:
|
|
1373
|
-
arguments:
|
|
1374
|
-
call_id:
|
|
1375
|
-
id:
|
|
1385
|
+
z6.object({
|
|
1386
|
+
type: z6.literal("function_call"),
|
|
1387
|
+
name: z6.string(),
|
|
1388
|
+
arguments: z6.string(),
|
|
1389
|
+
call_id: z6.string(),
|
|
1390
|
+
id: z6.string()
|
|
1376
1391
|
}),
|
|
1377
|
-
|
|
1378
|
-
type:
|
|
1379
|
-
id:
|
|
1380
|
-
summary:
|
|
1381
|
-
content:
|
|
1382
|
-
status:
|
|
1383
|
-
encrypted_content:
|
|
1392
|
+
z6.object({
|
|
1393
|
+
type: z6.literal("reasoning"),
|
|
1394
|
+
id: z6.string(),
|
|
1395
|
+
summary: z6.array(reasoningSummaryPartSchema),
|
|
1396
|
+
content: z6.array(z6.object({ type: z6.string(), text: z6.string() })).nullish(),
|
|
1397
|
+
status: z6.string(),
|
|
1398
|
+
encrypted_content: z6.string().nullish()
|
|
1384
1399
|
})
|
|
1385
1400
|
]);
|
|
1386
|
-
var xaiResponsesUsageSchema =
|
|
1387
|
-
input_tokens:
|
|
1388
|
-
output_tokens:
|
|
1389
|
-
total_tokens:
|
|
1390
|
-
input_tokens_details:
|
|
1391
|
-
cached_tokens:
|
|
1401
|
+
var xaiResponsesUsageSchema = z6.object({
|
|
1402
|
+
input_tokens: z6.number(),
|
|
1403
|
+
output_tokens: z6.number(),
|
|
1404
|
+
total_tokens: z6.number().optional(),
|
|
1405
|
+
input_tokens_details: z6.object({
|
|
1406
|
+
cached_tokens: z6.number().optional()
|
|
1392
1407
|
}).optional(),
|
|
1393
|
-
output_tokens_details:
|
|
1394
|
-
reasoning_tokens:
|
|
1408
|
+
output_tokens_details: z6.object({
|
|
1409
|
+
reasoning_tokens: z6.number().optional()
|
|
1395
1410
|
}).optional(),
|
|
1396
|
-
num_sources_used:
|
|
1397
|
-
num_server_side_tools_used:
|
|
1411
|
+
num_sources_used: z6.number().optional(),
|
|
1412
|
+
num_server_side_tools_used: z6.number().optional()
|
|
1398
1413
|
});
|
|
1399
|
-
var xaiResponsesResponseSchema =
|
|
1400
|
-
id:
|
|
1401
|
-
created_at:
|
|
1402
|
-
model:
|
|
1403
|
-
object:
|
|
1404
|
-
output:
|
|
1414
|
+
var xaiResponsesResponseSchema = z6.object({
|
|
1415
|
+
id: z6.string().nullish(),
|
|
1416
|
+
created_at: z6.number().nullish(),
|
|
1417
|
+
model: z6.string().nullish(),
|
|
1418
|
+
object: z6.literal("response"),
|
|
1419
|
+
output: z6.array(outputItemSchema),
|
|
1405
1420
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1406
|
-
status:
|
|
1421
|
+
status: z6.string()
|
|
1407
1422
|
});
|
|
1408
|
-
var xaiResponsesChunkSchema =
|
|
1409
|
-
|
|
1410
|
-
type:
|
|
1423
|
+
var xaiResponsesChunkSchema = z6.union([
|
|
1424
|
+
z6.object({
|
|
1425
|
+
type: z6.literal("response.created"),
|
|
1411
1426
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1412
1427
|
}),
|
|
1413
|
-
|
|
1414
|
-
type:
|
|
1428
|
+
z6.object({
|
|
1429
|
+
type: z6.literal("response.in_progress"),
|
|
1415
1430
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1416
1431
|
}),
|
|
1417
|
-
|
|
1418
|
-
type:
|
|
1432
|
+
z6.object({
|
|
1433
|
+
type: z6.literal("response.output_item.added"),
|
|
1419
1434
|
item: outputItemSchema,
|
|
1420
|
-
output_index:
|
|
1435
|
+
output_index: z6.number()
|
|
1421
1436
|
}),
|
|
1422
|
-
|
|
1423
|
-
type:
|
|
1437
|
+
z6.object({
|
|
1438
|
+
type: z6.literal("response.output_item.done"),
|
|
1424
1439
|
item: outputItemSchema,
|
|
1425
|
-
output_index:
|
|
1440
|
+
output_index: z6.number()
|
|
1426
1441
|
}),
|
|
1427
|
-
|
|
1428
|
-
type:
|
|
1429
|
-
item_id:
|
|
1430
|
-
output_index:
|
|
1431
|
-
content_index:
|
|
1442
|
+
z6.object({
|
|
1443
|
+
type: z6.literal("response.content_part.added"),
|
|
1444
|
+
item_id: z6.string(),
|
|
1445
|
+
output_index: z6.number(),
|
|
1446
|
+
content_index: z6.number(),
|
|
1432
1447
|
part: messageContentPartSchema
|
|
1433
1448
|
}),
|
|
1434
|
-
|
|
1435
|
-
type:
|
|
1436
|
-
item_id:
|
|
1437
|
-
output_index:
|
|
1438
|
-
content_index:
|
|
1449
|
+
z6.object({
|
|
1450
|
+
type: z6.literal("response.content_part.done"),
|
|
1451
|
+
item_id: z6.string(),
|
|
1452
|
+
output_index: z6.number(),
|
|
1453
|
+
content_index: z6.number(),
|
|
1439
1454
|
part: messageContentPartSchema
|
|
1440
1455
|
}),
|
|
1441
|
-
|
|
1442
|
-
type:
|
|
1443
|
-
item_id:
|
|
1444
|
-
output_index:
|
|
1445
|
-
content_index:
|
|
1446
|
-
delta:
|
|
1447
|
-
logprobs:
|
|
1456
|
+
z6.object({
|
|
1457
|
+
type: z6.literal("response.output_text.delta"),
|
|
1458
|
+
item_id: z6.string(),
|
|
1459
|
+
output_index: z6.number(),
|
|
1460
|
+
content_index: z6.number(),
|
|
1461
|
+
delta: z6.string(),
|
|
1462
|
+
logprobs: z6.array(z6.any()).optional()
|
|
1448
1463
|
}),
|
|
1449
|
-
|
|
1450
|
-
type:
|
|
1451
|
-
item_id:
|
|
1452
|
-
output_index:
|
|
1453
|
-
content_index:
|
|
1454
|
-
text:
|
|
1455
|
-
logprobs:
|
|
1456
|
-
annotations:
|
|
1464
|
+
z6.object({
|
|
1465
|
+
type: z6.literal("response.output_text.done"),
|
|
1466
|
+
item_id: z6.string(),
|
|
1467
|
+
output_index: z6.number(),
|
|
1468
|
+
content_index: z6.number(),
|
|
1469
|
+
text: z6.string(),
|
|
1470
|
+
logprobs: z6.array(z6.any()).optional(),
|
|
1471
|
+
annotations: z6.array(annotationSchema).optional()
|
|
1457
1472
|
}),
|
|
1458
|
-
|
|
1459
|
-
type:
|
|
1460
|
-
item_id:
|
|
1461
|
-
output_index:
|
|
1462
|
-
content_index:
|
|
1463
|
-
annotation_index:
|
|
1473
|
+
z6.object({
|
|
1474
|
+
type: z6.literal("response.output_text.annotation.added"),
|
|
1475
|
+
item_id: z6.string(),
|
|
1476
|
+
output_index: z6.number(),
|
|
1477
|
+
content_index: z6.number(),
|
|
1478
|
+
annotation_index: z6.number(),
|
|
1464
1479
|
annotation: annotationSchema
|
|
1465
1480
|
}),
|
|
1466
|
-
|
|
1467
|
-
type:
|
|
1468
|
-
item_id:
|
|
1469
|
-
output_index:
|
|
1470
|
-
summary_index:
|
|
1481
|
+
z6.object({
|
|
1482
|
+
type: z6.literal("response.reasoning_summary_part.added"),
|
|
1483
|
+
item_id: z6.string(),
|
|
1484
|
+
output_index: z6.number(),
|
|
1485
|
+
summary_index: z6.number(),
|
|
1471
1486
|
part: reasoningSummaryPartSchema
|
|
1472
1487
|
}),
|
|
1473
|
-
|
|
1474
|
-
type:
|
|
1475
|
-
item_id:
|
|
1476
|
-
output_index:
|
|
1477
|
-
summary_index:
|
|
1488
|
+
z6.object({
|
|
1489
|
+
type: z6.literal("response.reasoning_summary_part.done"),
|
|
1490
|
+
item_id: z6.string(),
|
|
1491
|
+
output_index: z6.number(),
|
|
1492
|
+
summary_index: z6.number(),
|
|
1478
1493
|
part: reasoningSummaryPartSchema
|
|
1479
1494
|
}),
|
|
1480
|
-
|
|
1481
|
-
type:
|
|
1482
|
-
item_id:
|
|
1483
|
-
output_index:
|
|
1484
|
-
summary_index:
|
|
1485
|
-
delta:
|
|
1495
|
+
z6.object({
|
|
1496
|
+
type: z6.literal("response.reasoning_summary_text.delta"),
|
|
1497
|
+
item_id: z6.string(),
|
|
1498
|
+
output_index: z6.number(),
|
|
1499
|
+
summary_index: z6.number(),
|
|
1500
|
+
delta: z6.string()
|
|
1486
1501
|
}),
|
|
1487
|
-
|
|
1488
|
-
type:
|
|
1489
|
-
item_id:
|
|
1490
|
-
output_index:
|
|
1491
|
-
summary_index:
|
|
1492
|
-
text:
|
|
1502
|
+
z6.object({
|
|
1503
|
+
type: z6.literal("response.reasoning_summary_text.done"),
|
|
1504
|
+
item_id: z6.string(),
|
|
1505
|
+
output_index: z6.number(),
|
|
1506
|
+
summary_index: z6.number(),
|
|
1507
|
+
text: z6.string()
|
|
1493
1508
|
}),
|
|
1494
|
-
|
|
1495
|
-
type:
|
|
1496
|
-
item_id:
|
|
1497
|
-
output_index:
|
|
1498
|
-
content_index:
|
|
1499
|
-
delta:
|
|
1509
|
+
z6.object({
|
|
1510
|
+
type: z6.literal("response.reasoning_text.delta"),
|
|
1511
|
+
item_id: z6.string(),
|
|
1512
|
+
output_index: z6.number(),
|
|
1513
|
+
content_index: z6.number(),
|
|
1514
|
+
delta: z6.string()
|
|
1500
1515
|
}),
|
|
1501
|
-
|
|
1502
|
-
type:
|
|
1503
|
-
item_id:
|
|
1504
|
-
output_index:
|
|
1505
|
-
content_index:
|
|
1506
|
-
text:
|
|
1516
|
+
z6.object({
|
|
1517
|
+
type: z6.literal("response.reasoning_text.done"),
|
|
1518
|
+
item_id: z6.string(),
|
|
1519
|
+
output_index: z6.number(),
|
|
1520
|
+
content_index: z6.number(),
|
|
1521
|
+
text: z6.string()
|
|
1507
1522
|
}),
|
|
1508
|
-
|
|
1509
|
-
type:
|
|
1510
|
-
item_id:
|
|
1511
|
-
output_index:
|
|
1523
|
+
z6.object({
|
|
1524
|
+
type: z6.literal("response.web_search_call.in_progress"),
|
|
1525
|
+
item_id: z6.string(),
|
|
1526
|
+
output_index: z6.number()
|
|
1512
1527
|
}),
|
|
1513
|
-
|
|
1514
|
-
type:
|
|
1515
|
-
item_id:
|
|
1516
|
-
output_index:
|
|
1528
|
+
z6.object({
|
|
1529
|
+
type: z6.literal("response.web_search_call.searching"),
|
|
1530
|
+
item_id: z6.string(),
|
|
1531
|
+
output_index: z6.number()
|
|
1517
1532
|
}),
|
|
1518
|
-
|
|
1519
|
-
type:
|
|
1520
|
-
item_id:
|
|
1521
|
-
output_index:
|
|
1533
|
+
z6.object({
|
|
1534
|
+
type: z6.literal("response.web_search_call.completed"),
|
|
1535
|
+
item_id: z6.string(),
|
|
1536
|
+
output_index: z6.number()
|
|
1522
1537
|
}),
|
|
1523
|
-
|
|
1524
|
-
type:
|
|
1525
|
-
item_id:
|
|
1526
|
-
output_index:
|
|
1538
|
+
z6.object({
|
|
1539
|
+
type: z6.literal("response.x_search_call.in_progress"),
|
|
1540
|
+
item_id: z6.string(),
|
|
1541
|
+
output_index: z6.number()
|
|
1527
1542
|
}),
|
|
1528
|
-
|
|
1529
|
-
type:
|
|
1530
|
-
item_id:
|
|
1531
|
-
output_index:
|
|
1543
|
+
z6.object({
|
|
1544
|
+
type: z6.literal("response.x_search_call.searching"),
|
|
1545
|
+
item_id: z6.string(),
|
|
1546
|
+
output_index: z6.number()
|
|
1532
1547
|
}),
|
|
1533
|
-
|
|
1534
|
-
type:
|
|
1535
|
-
item_id:
|
|
1536
|
-
output_index:
|
|
1548
|
+
z6.object({
|
|
1549
|
+
type: z6.literal("response.x_search_call.completed"),
|
|
1550
|
+
item_id: z6.string(),
|
|
1551
|
+
output_index: z6.number()
|
|
1537
1552
|
}),
|
|
1538
|
-
|
|
1539
|
-
type:
|
|
1540
|
-
item_id:
|
|
1541
|
-
output_index:
|
|
1553
|
+
z6.object({
|
|
1554
|
+
type: z6.literal("response.file_search_call.in_progress"),
|
|
1555
|
+
item_id: z6.string(),
|
|
1556
|
+
output_index: z6.number()
|
|
1542
1557
|
}),
|
|
1543
|
-
|
|
1544
|
-
type:
|
|
1545
|
-
item_id:
|
|
1546
|
-
output_index:
|
|
1558
|
+
z6.object({
|
|
1559
|
+
type: z6.literal("response.file_search_call.searching"),
|
|
1560
|
+
item_id: z6.string(),
|
|
1561
|
+
output_index: z6.number()
|
|
1547
1562
|
}),
|
|
1548
|
-
|
|
1549
|
-
type:
|
|
1550
|
-
item_id:
|
|
1551
|
-
output_index:
|
|
1563
|
+
z6.object({
|
|
1564
|
+
type: z6.literal("response.file_search_call.completed"),
|
|
1565
|
+
item_id: z6.string(),
|
|
1566
|
+
output_index: z6.number()
|
|
1552
1567
|
}),
|
|
1553
|
-
|
|
1554
|
-
type:
|
|
1555
|
-
item_id:
|
|
1556
|
-
output_index:
|
|
1568
|
+
z6.object({
|
|
1569
|
+
type: z6.literal("response.code_execution_call.in_progress"),
|
|
1570
|
+
item_id: z6.string(),
|
|
1571
|
+
output_index: z6.number()
|
|
1557
1572
|
}),
|
|
1558
|
-
|
|
1559
|
-
type:
|
|
1560
|
-
item_id:
|
|
1561
|
-
output_index:
|
|
1573
|
+
z6.object({
|
|
1574
|
+
type: z6.literal("response.code_execution_call.executing"),
|
|
1575
|
+
item_id: z6.string(),
|
|
1576
|
+
output_index: z6.number()
|
|
1562
1577
|
}),
|
|
1563
|
-
|
|
1564
|
-
type:
|
|
1565
|
-
item_id:
|
|
1566
|
-
output_index:
|
|
1578
|
+
z6.object({
|
|
1579
|
+
type: z6.literal("response.code_execution_call.completed"),
|
|
1580
|
+
item_id: z6.string(),
|
|
1581
|
+
output_index: z6.number()
|
|
1567
1582
|
}),
|
|
1568
|
-
|
|
1569
|
-
type:
|
|
1570
|
-
item_id:
|
|
1571
|
-
output_index:
|
|
1583
|
+
z6.object({
|
|
1584
|
+
type: z6.literal("response.code_interpreter_call.in_progress"),
|
|
1585
|
+
item_id: z6.string(),
|
|
1586
|
+
output_index: z6.number()
|
|
1572
1587
|
}),
|
|
1573
|
-
|
|
1574
|
-
type:
|
|
1575
|
-
item_id:
|
|
1576
|
-
output_index:
|
|
1588
|
+
z6.object({
|
|
1589
|
+
type: z6.literal("response.code_interpreter_call.executing"),
|
|
1590
|
+
item_id: z6.string(),
|
|
1591
|
+
output_index: z6.number()
|
|
1577
1592
|
}),
|
|
1578
|
-
|
|
1579
|
-
type:
|
|
1580
|
-
item_id:
|
|
1581
|
-
output_index:
|
|
1593
|
+
z6.object({
|
|
1594
|
+
type: z6.literal("response.code_interpreter_call.interpreting"),
|
|
1595
|
+
item_id: z6.string(),
|
|
1596
|
+
output_index: z6.number()
|
|
1582
1597
|
}),
|
|
1583
|
-
|
|
1584
|
-
type:
|
|
1585
|
-
item_id:
|
|
1586
|
-
output_index:
|
|
1598
|
+
z6.object({
|
|
1599
|
+
type: z6.literal("response.code_interpreter_call.completed"),
|
|
1600
|
+
item_id: z6.string(),
|
|
1601
|
+
output_index: z6.number()
|
|
1587
1602
|
}),
|
|
1588
1603
|
// Code interpreter code streaming events
|
|
1589
|
-
|
|
1590
|
-
type:
|
|
1591
|
-
item_id:
|
|
1592
|
-
output_index:
|
|
1593
|
-
delta:
|
|
1604
|
+
z6.object({
|
|
1605
|
+
type: z6.literal("response.code_interpreter_call_code.delta"),
|
|
1606
|
+
item_id: z6.string(),
|
|
1607
|
+
output_index: z6.number(),
|
|
1608
|
+
delta: z6.string()
|
|
1594
1609
|
}),
|
|
1595
|
-
|
|
1596
|
-
type:
|
|
1597
|
-
item_id:
|
|
1598
|
-
output_index:
|
|
1599
|
-
code:
|
|
1610
|
+
z6.object({
|
|
1611
|
+
type: z6.literal("response.code_interpreter_call_code.done"),
|
|
1612
|
+
item_id: z6.string(),
|
|
1613
|
+
output_index: z6.number(),
|
|
1614
|
+
code: z6.string()
|
|
1600
1615
|
}),
|
|
1601
|
-
|
|
1602
|
-
type:
|
|
1603
|
-
item_id:
|
|
1604
|
-
output_index:
|
|
1605
|
-
delta:
|
|
1616
|
+
z6.object({
|
|
1617
|
+
type: z6.literal("response.custom_tool_call_input.delta"),
|
|
1618
|
+
item_id: z6.string(),
|
|
1619
|
+
output_index: z6.number(),
|
|
1620
|
+
delta: z6.string()
|
|
1606
1621
|
}),
|
|
1607
|
-
|
|
1608
|
-
type:
|
|
1609
|
-
item_id:
|
|
1610
|
-
output_index:
|
|
1611
|
-
input:
|
|
1622
|
+
z6.object({
|
|
1623
|
+
type: z6.literal("response.custom_tool_call_input.done"),
|
|
1624
|
+
item_id: z6.string(),
|
|
1625
|
+
output_index: z6.number(),
|
|
1626
|
+
input: z6.string()
|
|
1612
1627
|
}),
|
|
1613
1628
|
// Function call arguments streaming events (standard function tools)
|
|
1614
|
-
|
|
1615
|
-
type:
|
|
1616
|
-
item_id:
|
|
1617
|
-
output_index:
|
|
1618
|
-
delta:
|
|
1629
|
+
z6.object({
|
|
1630
|
+
type: z6.literal("response.function_call_arguments.delta"),
|
|
1631
|
+
item_id: z6.string(),
|
|
1632
|
+
output_index: z6.number(),
|
|
1633
|
+
delta: z6.string()
|
|
1619
1634
|
}),
|
|
1620
|
-
|
|
1621
|
-
type:
|
|
1622
|
-
item_id:
|
|
1623
|
-
output_index:
|
|
1624
|
-
arguments:
|
|
1635
|
+
z6.object({
|
|
1636
|
+
type: z6.literal("response.function_call_arguments.done"),
|
|
1637
|
+
item_id: z6.string(),
|
|
1638
|
+
output_index: z6.number(),
|
|
1639
|
+
arguments: z6.string()
|
|
1625
1640
|
}),
|
|
1626
|
-
|
|
1627
|
-
type:
|
|
1628
|
-
item_id:
|
|
1629
|
-
output_index:
|
|
1641
|
+
z6.object({
|
|
1642
|
+
type: z6.literal("response.mcp_call.in_progress"),
|
|
1643
|
+
item_id: z6.string(),
|
|
1644
|
+
output_index: z6.number()
|
|
1630
1645
|
}),
|
|
1631
|
-
|
|
1632
|
-
type:
|
|
1633
|
-
item_id:
|
|
1634
|
-
output_index:
|
|
1646
|
+
z6.object({
|
|
1647
|
+
type: z6.literal("response.mcp_call.executing"),
|
|
1648
|
+
item_id: z6.string(),
|
|
1649
|
+
output_index: z6.number()
|
|
1635
1650
|
}),
|
|
1636
|
-
|
|
1637
|
-
type:
|
|
1638
|
-
item_id:
|
|
1639
|
-
output_index:
|
|
1651
|
+
z6.object({
|
|
1652
|
+
type: z6.literal("response.mcp_call.completed"),
|
|
1653
|
+
item_id: z6.string(),
|
|
1654
|
+
output_index: z6.number()
|
|
1640
1655
|
}),
|
|
1641
|
-
|
|
1642
|
-
type:
|
|
1643
|
-
item_id:
|
|
1644
|
-
output_index:
|
|
1656
|
+
z6.object({
|
|
1657
|
+
type: z6.literal("response.mcp_call.failed"),
|
|
1658
|
+
item_id: z6.string(),
|
|
1659
|
+
output_index: z6.number()
|
|
1645
1660
|
}),
|
|
1646
|
-
|
|
1647
|
-
type:
|
|
1648
|
-
item_id:
|
|
1649
|
-
output_index:
|
|
1650
|
-
delta:
|
|
1661
|
+
z6.object({
|
|
1662
|
+
type: z6.literal("response.mcp_call_arguments.delta"),
|
|
1663
|
+
item_id: z6.string(),
|
|
1664
|
+
output_index: z6.number(),
|
|
1665
|
+
delta: z6.string()
|
|
1651
1666
|
}),
|
|
1652
|
-
|
|
1653
|
-
type:
|
|
1654
|
-
item_id:
|
|
1655
|
-
output_index:
|
|
1656
|
-
arguments:
|
|
1667
|
+
z6.object({
|
|
1668
|
+
type: z6.literal("response.mcp_call_arguments.done"),
|
|
1669
|
+
item_id: z6.string(),
|
|
1670
|
+
output_index: z6.number(),
|
|
1671
|
+
arguments: z6.string().optional()
|
|
1657
1672
|
}),
|
|
1658
|
-
|
|
1659
|
-
type:
|
|
1660
|
-
item_id:
|
|
1661
|
-
output_index:
|
|
1662
|
-
delta:
|
|
1673
|
+
z6.object({
|
|
1674
|
+
type: z6.literal("response.mcp_call_output.delta"),
|
|
1675
|
+
item_id: z6.string(),
|
|
1676
|
+
output_index: z6.number(),
|
|
1677
|
+
delta: z6.string()
|
|
1663
1678
|
}),
|
|
1664
|
-
|
|
1665
|
-
type:
|
|
1666
|
-
item_id:
|
|
1667
|
-
output_index:
|
|
1668
|
-
output:
|
|
1679
|
+
z6.object({
|
|
1680
|
+
type: z6.literal("response.mcp_call_output.done"),
|
|
1681
|
+
item_id: z6.string(),
|
|
1682
|
+
output_index: z6.number(),
|
|
1683
|
+
output: z6.string().optional()
|
|
1669
1684
|
}),
|
|
1670
|
-
|
|
1671
|
-
type:
|
|
1672
|
-
response:
|
|
1673
|
-
incomplete_details:
|
|
1685
|
+
z6.object({
|
|
1686
|
+
type: z6.literal("response.incomplete"),
|
|
1687
|
+
response: z6.object({
|
|
1688
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1674
1689
|
usage: xaiResponsesUsageSchema.nullish()
|
|
1675
1690
|
})
|
|
1676
1691
|
}),
|
|
1677
|
-
|
|
1678
|
-
type:
|
|
1679
|
-
response:
|
|
1680
|
-
error:
|
|
1681
|
-
code:
|
|
1682
|
-
message:
|
|
1692
|
+
z6.object({
|
|
1693
|
+
type: z6.literal("response.failed"),
|
|
1694
|
+
response: z6.object({
|
|
1695
|
+
error: z6.object({
|
|
1696
|
+
code: z6.string().nullish(),
|
|
1697
|
+
message: z6.string()
|
|
1683
1698
|
}).nullish(),
|
|
1684
|
-
incomplete_details:
|
|
1699
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1685
1700
|
usage: xaiResponsesUsageSchema.nullish()
|
|
1686
1701
|
})
|
|
1687
1702
|
}),
|
|
1688
|
-
|
|
1689
|
-
type:
|
|
1690
|
-
code:
|
|
1691
|
-
message:
|
|
1692
|
-
param:
|
|
1703
|
+
z6.object({
|
|
1704
|
+
type: z6.literal("error"),
|
|
1705
|
+
code: z6.string().nullish(),
|
|
1706
|
+
message: z6.string(),
|
|
1707
|
+
param: z6.string().nullish()
|
|
1693
1708
|
}),
|
|
1694
|
-
|
|
1695
|
-
type:
|
|
1709
|
+
z6.object({
|
|
1710
|
+
type: z6.literal("response.done"),
|
|
1696
1711
|
response: xaiResponsesResponseSchema
|
|
1697
1712
|
}),
|
|
1698
|
-
|
|
1699
|
-
type:
|
|
1713
|
+
z6.object({
|
|
1714
|
+
type: z6.literal("response.completed"),
|
|
1700
1715
|
response: xaiResponsesResponseSchema
|
|
1701
1716
|
})
|
|
1702
1717
|
]);
|
|
1703
1718
|
|
|
1704
1719
|
// src/responses/xai-responses-options.ts
|
|
1705
|
-
|
|
1706
|
-
var xaiLanguageModelResponsesOptions =
|
|
1720
|
+
import { z as z7 } from "zod/v4";
|
|
1721
|
+
var xaiLanguageModelResponsesOptions = z7.object({
|
|
1707
1722
|
/**
|
|
1708
1723
|
* Constrains how hard a reasoning model thinks before responding.
|
|
1709
1724
|
* Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
|
|
1710
1725
|
*/
|
|
1711
|
-
reasoningEffort:
|
|
1712
|
-
reasoningSummary:
|
|
1713
|
-
logprobs:
|
|
1714
|
-
topLogprobs:
|
|
1726
|
+
reasoningEffort: z7.enum(["low", "medium", "high"]).optional(),
|
|
1727
|
+
reasoningSummary: z7.enum(["auto", "concise", "detailed"]).optional(),
|
|
1728
|
+
logprobs: z7.boolean().optional(),
|
|
1729
|
+
topLogprobs: z7.number().int().min(0).max(8).optional(),
|
|
1715
1730
|
/**
|
|
1716
1731
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
1717
1732
|
* @default true
|
|
1718
1733
|
*/
|
|
1719
|
-
store:
|
|
1734
|
+
store: z7.boolean().optional(),
|
|
1720
1735
|
/**
|
|
1721
1736
|
* The ID of the previous response from the model.
|
|
1722
1737
|
*/
|
|
1723
|
-
previousResponseId:
|
|
1738
|
+
previousResponseId: z7.string().optional(),
|
|
1724
1739
|
/**
|
|
1725
1740
|
* Specify additional output data to include in the model response.
|
|
1726
1741
|
* Example values: 'file_search_call.results'.
|
|
1727
1742
|
*/
|
|
1728
|
-
include:
|
|
1743
|
+
include: z7.array(z7.enum(["file_search_call.results"])).nullish()
|
|
1729
1744
|
});
|
|
1730
1745
|
|
|
1731
1746
|
// src/responses/xai-responses-prepare-tools.ts
|
|
1732
|
-
|
|
1733
|
-
|
|
1747
|
+
import {
|
|
1748
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1749
|
+
} from "@ai-sdk/provider";
|
|
1750
|
+
import { validateTypes } from "@ai-sdk/provider-utils";
|
|
1734
1751
|
|
|
1735
1752
|
// src/tool/file-search.ts
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1753
|
+
import {
|
|
1754
|
+
createProviderToolFactoryWithOutputSchema,
|
|
1755
|
+
lazySchema,
|
|
1756
|
+
zodSchema
|
|
1757
|
+
} from "@ai-sdk/provider-utils";
|
|
1758
|
+
import { z as z8 } from "zod/v4";
|
|
1759
|
+
var fileSearchArgsSchema = lazySchema(
|
|
1760
|
+
() => zodSchema(
|
|
1761
|
+
z8.object({
|
|
1762
|
+
vectorStoreIds: z8.array(z8.string()),
|
|
1763
|
+
maxNumResults: z8.number().optional()
|
|
1743
1764
|
})
|
|
1744
1765
|
)
|
|
1745
1766
|
);
|
|
1746
|
-
var fileSearchOutputSchema =
|
|
1747
|
-
() =>
|
|
1748
|
-
|
|
1749
|
-
queries:
|
|
1750
|
-
results:
|
|
1751
|
-
|
|
1752
|
-
fileId:
|
|
1753
|
-
filename:
|
|
1754
|
-
score:
|
|
1755
|
-
text:
|
|
1767
|
+
var fileSearchOutputSchema = lazySchema(
|
|
1768
|
+
() => zodSchema(
|
|
1769
|
+
z8.object({
|
|
1770
|
+
queries: z8.array(z8.string()),
|
|
1771
|
+
results: z8.array(
|
|
1772
|
+
z8.object({
|
|
1773
|
+
fileId: z8.string(),
|
|
1774
|
+
filename: z8.string(),
|
|
1775
|
+
score: z8.number().min(0).max(1),
|
|
1776
|
+
text: z8.string()
|
|
1756
1777
|
})
|
|
1757
1778
|
).nullable()
|
|
1758
1779
|
})
|
|
1759
1780
|
)
|
|
1760
1781
|
);
|
|
1761
|
-
var fileSearchToolFactory =
|
|
1782
|
+
var fileSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1762
1783
|
id: "xai.file_search",
|
|
1763
|
-
inputSchema:
|
|
1784
|
+
inputSchema: lazySchema(() => zodSchema(z8.object({}))),
|
|
1764
1785
|
outputSchema: fileSearchOutputSchema
|
|
1765
1786
|
});
|
|
1766
1787
|
var fileSearch = (args) => fileSearchToolFactory(args);
|
|
1767
1788
|
|
|
1768
1789
|
// src/tool/mcp-server.ts
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1790
|
+
import {
|
|
1791
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema2,
|
|
1792
|
+
lazySchema as lazySchema2,
|
|
1793
|
+
zodSchema as zodSchema2
|
|
1794
|
+
} from "@ai-sdk/provider-utils";
|
|
1795
|
+
import { z as z9 } from "zod/v4";
|
|
1796
|
+
var mcpServerArgsSchema = lazySchema2(
|
|
1797
|
+
() => zodSchema2(
|
|
1798
|
+
z9.object({
|
|
1799
|
+
serverUrl: z9.string().describe("The URL of the MCP server"),
|
|
1800
|
+
serverLabel: z9.string().optional().describe("A label for the MCP server"),
|
|
1801
|
+
serverDescription: z9.string().optional().describe("Description of the MCP server"),
|
|
1802
|
+
allowedTools: z9.array(z9.string()).optional().describe("List of allowed tool names"),
|
|
1803
|
+
headers: z9.record(z9.string(), z9.string()).optional().describe("Custom headers to send"),
|
|
1804
|
+
authorization: z9.string().optional().describe("Authorization header value")
|
|
1780
1805
|
})
|
|
1781
1806
|
)
|
|
1782
1807
|
);
|
|
1783
|
-
var mcpServerOutputSchema = (
|
|
1784
|
-
() => (
|
|
1785
|
-
|
|
1786
|
-
name:
|
|
1787
|
-
arguments:
|
|
1788
|
-
result:
|
|
1808
|
+
var mcpServerOutputSchema = lazySchema2(
|
|
1809
|
+
() => zodSchema2(
|
|
1810
|
+
z9.object({
|
|
1811
|
+
name: z9.string(),
|
|
1812
|
+
arguments: z9.string(),
|
|
1813
|
+
result: z9.unknown()
|
|
1789
1814
|
})
|
|
1790
1815
|
)
|
|
1791
1816
|
);
|
|
1792
|
-
var mcpServerToolFactory = (
|
|
1817
|
+
var mcpServerToolFactory = createProviderToolFactoryWithOutputSchema2({
|
|
1793
1818
|
id: "xai.mcp",
|
|
1794
|
-
inputSchema: (
|
|
1819
|
+
inputSchema: lazySchema2(() => zodSchema2(z9.object({}))),
|
|
1795
1820
|
outputSchema: mcpServerOutputSchema
|
|
1796
1821
|
});
|
|
1797
1822
|
var mcpServer = (args) => mcpServerToolFactory(args);
|
|
1798
1823
|
|
|
1799
1824
|
// src/tool/web-search.ts
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1825
|
+
import {
|
|
1826
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema3,
|
|
1827
|
+
lazySchema as lazySchema3,
|
|
1828
|
+
zodSchema as zodSchema3
|
|
1829
|
+
} from "@ai-sdk/provider-utils";
|
|
1830
|
+
import { z as z10 } from "zod/v4";
|
|
1831
|
+
var webSearchArgsSchema = lazySchema3(
|
|
1832
|
+
() => zodSchema3(
|
|
1833
|
+
z10.object({
|
|
1834
|
+
allowedDomains: z10.array(z10.string()).max(5).optional(),
|
|
1835
|
+
excludedDomains: z10.array(z10.string()).max(5).optional(),
|
|
1836
|
+
enableImageUnderstanding: z10.boolean().optional()
|
|
1808
1837
|
})
|
|
1809
1838
|
)
|
|
1810
1839
|
);
|
|
1811
|
-
var webSearchOutputSchema = (
|
|
1812
|
-
() => (
|
|
1813
|
-
|
|
1814
|
-
query:
|
|
1815
|
-
sources:
|
|
1816
|
-
|
|
1817
|
-
title:
|
|
1818
|
-
url:
|
|
1819
|
-
snippet:
|
|
1840
|
+
var webSearchOutputSchema = lazySchema3(
|
|
1841
|
+
() => zodSchema3(
|
|
1842
|
+
z10.object({
|
|
1843
|
+
query: z10.string(),
|
|
1844
|
+
sources: z10.array(
|
|
1845
|
+
z10.object({
|
|
1846
|
+
title: z10.string(),
|
|
1847
|
+
url: z10.string(),
|
|
1848
|
+
snippet: z10.string()
|
|
1820
1849
|
})
|
|
1821
1850
|
)
|
|
1822
1851
|
})
|
|
1823
1852
|
)
|
|
1824
1853
|
);
|
|
1825
|
-
var webSearchToolFactory = (
|
|
1854
|
+
var webSearchToolFactory = createProviderToolFactoryWithOutputSchema3({
|
|
1826
1855
|
id: "xai.web_search",
|
|
1827
|
-
inputSchema: (
|
|
1856
|
+
inputSchema: lazySchema3(() => zodSchema3(z10.object({}))),
|
|
1828
1857
|
outputSchema: webSearchOutputSchema
|
|
1829
1858
|
});
|
|
1830
1859
|
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
1831
1860
|
|
|
1832
1861
|
// src/tool/x-search.ts
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1862
|
+
import {
|
|
1863
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema4,
|
|
1864
|
+
lazySchema as lazySchema4,
|
|
1865
|
+
zodSchema as zodSchema4
|
|
1866
|
+
} from "@ai-sdk/provider-utils";
|
|
1867
|
+
import { z as z11 } from "zod/v4";
|
|
1868
|
+
var xSearchArgsSchema = lazySchema4(
|
|
1869
|
+
() => zodSchema4(
|
|
1870
|
+
z11.object({
|
|
1871
|
+
allowedXHandles: z11.array(z11.string()).max(10).optional(),
|
|
1872
|
+
excludedXHandles: z11.array(z11.string()).max(10).optional(),
|
|
1873
|
+
fromDate: z11.string().optional(),
|
|
1874
|
+
toDate: z11.string().optional(),
|
|
1875
|
+
enableImageUnderstanding: z11.boolean().optional(),
|
|
1876
|
+
enableVideoUnderstanding: z11.boolean().optional()
|
|
1844
1877
|
})
|
|
1845
1878
|
)
|
|
1846
1879
|
);
|
|
1847
|
-
var xSearchOutputSchema = (
|
|
1848
|
-
() => (
|
|
1849
|
-
|
|
1850
|
-
query:
|
|
1851
|
-
posts:
|
|
1852
|
-
|
|
1853
|
-
author:
|
|
1854
|
-
text:
|
|
1855
|
-
url:
|
|
1856
|
-
likes:
|
|
1880
|
+
var xSearchOutputSchema = lazySchema4(
|
|
1881
|
+
() => zodSchema4(
|
|
1882
|
+
z11.object({
|
|
1883
|
+
query: z11.string(),
|
|
1884
|
+
posts: z11.array(
|
|
1885
|
+
z11.object({
|
|
1886
|
+
author: z11.string(),
|
|
1887
|
+
text: z11.string(),
|
|
1888
|
+
url: z11.string(),
|
|
1889
|
+
likes: z11.number()
|
|
1857
1890
|
})
|
|
1858
1891
|
)
|
|
1859
1892
|
})
|
|
1860
1893
|
)
|
|
1861
1894
|
);
|
|
1862
|
-
var xSearchToolFactory = (
|
|
1895
|
+
var xSearchToolFactory = createProviderToolFactoryWithOutputSchema4({
|
|
1863
1896
|
id: "xai.x_search",
|
|
1864
|
-
inputSchema: (
|
|
1897
|
+
inputSchema: lazySchema4(() => zodSchema4(z11.object({}))),
|
|
1865
1898
|
outputSchema: xSearchOutputSchema
|
|
1866
1899
|
});
|
|
1867
1900
|
var xSearch = (args = {}) => xSearchToolFactory(args);
|
|
@@ -1883,7 +1916,7 @@ async function prepareResponsesTools({
|
|
|
1883
1916
|
if (tool.type === "provider") {
|
|
1884
1917
|
switch (tool.id) {
|
|
1885
1918
|
case "xai.web_search": {
|
|
1886
|
-
const args = await
|
|
1919
|
+
const args = await validateTypes({
|
|
1887
1920
|
value: tool.args,
|
|
1888
1921
|
schema: webSearchArgsSchema
|
|
1889
1922
|
});
|
|
@@ -1896,7 +1929,7 @@ async function prepareResponsesTools({
|
|
|
1896
1929
|
break;
|
|
1897
1930
|
}
|
|
1898
1931
|
case "xai.x_search": {
|
|
1899
|
-
const args = await
|
|
1932
|
+
const args = await validateTypes({
|
|
1900
1933
|
value: tool.args,
|
|
1901
1934
|
schema: xSearchArgsSchema
|
|
1902
1935
|
});
|
|
@@ -1930,7 +1963,7 @@ async function prepareResponsesTools({
|
|
|
1930
1963
|
break;
|
|
1931
1964
|
}
|
|
1932
1965
|
case "xai.file_search": {
|
|
1933
|
-
const args = await
|
|
1966
|
+
const args = await validateTypes({
|
|
1934
1967
|
value: tool.args,
|
|
1935
1968
|
schema: fileSearchArgsSchema
|
|
1936
1969
|
});
|
|
@@ -1942,7 +1975,7 @@ async function prepareResponsesTools({
|
|
|
1942
1975
|
break;
|
|
1943
1976
|
}
|
|
1944
1977
|
case "xai.mcp": {
|
|
1945
|
-
const args = await
|
|
1978
|
+
const args = await validateTypes({
|
|
1946
1979
|
value: tool.args,
|
|
1947
1980
|
schema: mcpServerArgsSchema
|
|
1948
1981
|
});
|
|
@@ -2009,7 +2042,7 @@ async function prepareResponsesTools({
|
|
|
2009
2042
|
}
|
|
2010
2043
|
default: {
|
|
2011
2044
|
const _exhaustiveCheck = type;
|
|
2012
|
-
throw new
|
|
2045
|
+
throw new UnsupportedFunctionalityError4({
|
|
2013
2046
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
2014
2047
|
});
|
|
2015
2048
|
}
|
|
@@ -2044,7 +2077,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2044
2077
|
}) {
|
|
2045
2078
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2046
2079
|
const warnings = [];
|
|
2047
|
-
const options = (_a = await (
|
|
2080
|
+
const options = (_a = await parseProviderOptions3({
|
|
2048
2081
|
provider: "xai",
|
|
2049
2082
|
providerOptions,
|
|
2050
2083
|
schema: xaiLanguageModelResponsesOptions
|
|
@@ -2089,7 +2122,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2089
2122
|
include = [...include, "reasoning.encrypted_content"];
|
|
2090
2123
|
}
|
|
2091
2124
|
}
|
|
2092
|
-
const resolvedReasoningEffort = (_g = options.reasoningEffort) != null ? _g : (
|
|
2125
|
+
const resolvedReasoningEffort = (_g = options.reasoningEffort) != null ? _g : isCustomReasoning2(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort2({
|
|
2093
2126
|
reasoning,
|
|
2094
2127
|
effortMap: {
|
|
2095
2128
|
minimal: "low",
|
|
@@ -2171,12 +2204,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
2171
2204
|
responseHeaders,
|
|
2172
2205
|
value: response,
|
|
2173
2206
|
rawValue: rawResponse
|
|
2174
|
-
} = await (
|
|
2207
|
+
} = await postJsonToApi3({
|
|
2175
2208
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2176
|
-
headers: (
|
|
2209
|
+
headers: combineHeaders3(this.config.headers(), options.headers),
|
|
2177
2210
|
body,
|
|
2178
2211
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2179
|
-
successfulResponseHandler: (
|
|
2212
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
2180
2213
|
xaiResponsesResponseSchema
|
|
2181
2214
|
),
|
|
2182
2215
|
abortSignal: options.abortSignal,
|
|
@@ -2342,12 +2375,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
2342
2375
|
...args,
|
|
2343
2376
|
stream: true
|
|
2344
2377
|
};
|
|
2345
|
-
const { responseHeaders, value: response } = await (
|
|
2378
|
+
const { responseHeaders, value: response } = await postJsonToApi3({
|
|
2346
2379
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2347
|
-
headers: (
|
|
2380
|
+
headers: combineHeaders3(this.config.headers(), options.headers),
|
|
2348
2381
|
body,
|
|
2349
2382
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2350
|
-
successfulResponseHandler: (
|
|
2383
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
2351
2384
|
xaiResponsesChunkSchema
|
|
2352
2385
|
),
|
|
2353
2386
|
abortSignal: options.abortSignal,
|
|
@@ -2764,44 +2797,44 @@ var XaiResponsesLanguageModel = class {
|
|
|
2764
2797
|
};
|
|
2765
2798
|
|
|
2766
2799
|
// src/tool/code-execution.ts
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
var codeExecutionOutputSchema =
|
|
2770
|
-
output:
|
|
2771
|
-
error:
|
|
2800
|
+
import { createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema5 } from "@ai-sdk/provider-utils";
|
|
2801
|
+
import { z as z12 } from "zod/v4";
|
|
2802
|
+
var codeExecutionOutputSchema = z12.object({
|
|
2803
|
+
output: z12.string().describe("the output of the code execution"),
|
|
2804
|
+
error: z12.string().optional().describe("any error that occurred")
|
|
2772
2805
|
});
|
|
2773
|
-
var codeExecutionToolFactory = (
|
|
2806
|
+
var codeExecutionToolFactory = createProviderToolFactoryWithOutputSchema5({
|
|
2774
2807
|
id: "xai.code_execution",
|
|
2775
|
-
inputSchema:
|
|
2808
|
+
inputSchema: z12.object({}).describe("no input parameters"),
|
|
2776
2809
|
outputSchema: codeExecutionOutputSchema
|
|
2777
2810
|
});
|
|
2778
2811
|
var codeExecution = (args = {}) => codeExecutionToolFactory(args);
|
|
2779
2812
|
|
|
2780
2813
|
// src/tool/view-image.ts
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
var viewImageOutputSchema =
|
|
2784
|
-
description:
|
|
2785
|
-
objects:
|
|
2814
|
+
import { createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema6 } from "@ai-sdk/provider-utils";
|
|
2815
|
+
import { z as z13 } from "zod/v4";
|
|
2816
|
+
var viewImageOutputSchema = z13.object({
|
|
2817
|
+
description: z13.string().describe("description of the image"),
|
|
2818
|
+
objects: z13.array(z13.string()).optional().describe("objects detected in the image")
|
|
2786
2819
|
});
|
|
2787
|
-
var viewImageToolFactory = (
|
|
2820
|
+
var viewImageToolFactory = createProviderToolFactoryWithOutputSchema6({
|
|
2788
2821
|
id: "xai.view_image",
|
|
2789
|
-
inputSchema:
|
|
2822
|
+
inputSchema: z13.object({}).describe("no input parameters"),
|
|
2790
2823
|
outputSchema: viewImageOutputSchema
|
|
2791
2824
|
});
|
|
2792
2825
|
var viewImage = (args = {}) => viewImageToolFactory(args);
|
|
2793
2826
|
|
|
2794
2827
|
// src/tool/view-x-video.ts
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
var viewXVideoOutputSchema =
|
|
2798
|
-
transcript:
|
|
2799
|
-
description:
|
|
2800
|
-
duration:
|
|
2828
|
+
import { createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema7 } from "@ai-sdk/provider-utils";
|
|
2829
|
+
import { z as z14 } from "zod/v4";
|
|
2830
|
+
var viewXVideoOutputSchema = z14.object({
|
|
2831
|
+
transcript: z14.string().optional().describe("transcript of the video"),
|
|
2832
|
+
description: z14.string().describe("description of the video content"),
|
|
2833
|
+
duration: z14.number().optional().describe("duration in seconds")
|
|
2801
2834
|
});
|
|
2802
|
-
var viewXVideoToolFactory = (
|
|
2835
|
+
var viewXVideoToolFactory = createProviderToolFactoryWithOutputSchema7({
|
|
2803
2836
|
id: "xai.view_x_video",
|
|
2804
|
-
inputSchema:
|
|
2837
|
+
inputSchema: z14.object({}).describe("no input parameters"),
|
|
2805
2838
|
outputSchema: viewXVideoOutputSchema
|
|
2806
2839
|
});
|
|
2807
2840
|
var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
@@ -2818,36 +2851,42 @@ var xaiTools = {
|
|
|
2818
2851
|
};
|
|
2819
2852
|
|
|
2820
2853
|
// src/version.ts
|
|
2821
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2854
|
+
var VERSION = true ? "4.0.0-beta.35" : "0.0.0-test";
|
|
2822
2855
|
|
|
2823
2856
|
// src/files/xai-files.ts
|
|
2824
|
-
|
|
2857
|
+
import {
|
|
2858
|
+
combineHeaders as combineHeaders4,
|
|
2859
|
+
convertBase64ToUint8Array,
|
|
2860
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2861
|
+
parseProviderOptions as parseProviderOptions4,
|
|
2862
|
+
postFormDataToApi
|
|
2863
|
+
} from "@ai-sdk/provider-utils";
|
|
2825
2864
|
|
|
2826
2865
|
// src/files/xai-files-api.ts
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
var xaiFilesResponseSchema = (
|
|
2830
|
-
() => (
|
|
2831
|
-
|
|
2832
|
-
id:
|
|
2833
|
-
object:
|
|
2834
|
-
bytes:
|
|
2835
|
-
created_at:
|
|
2836
|
-
filename:
|
|
2837
|
-
purpose:
|
|
2838
|
-
status:
|
|
2866
|
+
import { lazySchema as lazySchema5, zodSchema as zodSchema5 } from "@ai-sdk/provider-utils";
|
|
2867
|
+
import { z as z15 } from "zod/v4";
|
|
2868
|
+
var xaiFilesResponseSchema = lazySchema5(
|
|
2869
|
+
() => zodSchema5(
|
|
2870
|
+
z15.object({
|
|
2871
|
+
id: z15.string(),
|
|
2872
|
+
object: z15.string().nullish(),
|
|
2873
|
+
bytes: z15.number().nullish(),
|
|
2874
|
+
created_at: z15.number().nullish(),
|
|
2875
|
+
filename: z15.string().nullish(),
|
|
2876
|
+
purpose: z15.string().nullish(),
|
|
2877
|
+
status: z15.string().nullish()
|
|
2839
2878
|
})
|
|
2840
2879
|
)
|
|
2841
2880
|
);
|
|
2842
2881
|
|
|
2843
2882
|
// src/files/xai-files-options.ts
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
var xaiFilesOptionsSchema = (
|
|
2847
|
-
() => (
|
|
2848
|
-
|
|
2849
|
-
teamId:
|
|
2850
|
-
filePath:
|
|
2883
|
+
import { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
|
|
2884
|
+
import { z as z16 } from "zod/v4";
|
|
2885
|
+
var xaiFilesOptionsSchema = lazySchema6(
|
|
2886
|
+
() => zodSchema6(
|
|
2887
|
+
z16.object({
|
|
2888
|
+
teamId: z16.string().optional(),
|
|
2889
|
+
filePath: z16.string().optional()
|
|
2851
2890
|
}).passthrough()
|
|
2852
2891
|
)
|
|
2853
2892
|
);
|
|
@@ -2868,12 +2907,12 @@ var XaiFiles = class {
|
|
|
2868
2907
|
providerOptions
|
|
2869
2908
|
}) {
|
|
2870
2909
|
var _a, _b;
|
|
2871
|
-
const xaiOptions = await (
|
|
2910
|
+
const xaiOptions = await parseProviderOptions4({
|
|
2872
2911
|
provider: "xai",
|
|
2873
2912
|
providerOptions,
|
|
2874
2913
|
schema: xaiFilesOptionsSchema
|
|
2875
2914
|
});
|
|
2876
|
-
const fileBytes = data instanceof Uint8Array ? data :
|
|
2915
|
+
const fileBytes = data instanceof Uint8Array ? data : convertBase64ToUint8Array(data);
|
|
2877
2916
|
const blob = new Blob([fileBytes], {
|
|
2878
2917
|
type: mediaType
|
|
2879
2918
|
});
|
|
@@ -2886,12 +2925,12 @@ var XaiFiles = class {
|
|
|
2886
2925
|
if ((xaiOptions == null ? void 0 : xaiOptions.teamId) != null) {
|
|
2887
2926
|
formData.append("team_id", xaiOptions.teamId);
|
|
2888
2927
|
}
|
|
2889
|
-
const { value: response } = await
|
|
2928
|
+
const { value: response } = await postFormDataToApi({
|
|
2890
2929
|
url: `${this.config.baseURL}/files`,
|
|
2891
|
-
headers: (
|
|
2930
|
+
headers: combineHeaders4(this.config.headers()),
|
|
2892
2931
|
formData,
|
|
2893
2932
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2894
|
-
successfulResponseHandler: (
|
|
2933
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2895
2934
|
xaiFilesResponseSchema
|
|
2896
2935
|
),
|
|
2897
2936
|
fetch: this.config.fetch
|
|
@@ -2913,59 +2952,69 @@ var XaiFiles = class {
|
|
|
2913
2952
|
};
|
|
2914
2953
|
|
|
2915
2954
|
// src/xai-video-model.ts
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2955
|
+
import {
|
|
2956
|
+
AISDKError
|
|
2957
|
+
} from "@ai-sdk/provider";
|
|
2958
|
+
import {
|
|
2959
|
+
combineHeaders as combineHeaders5,
|
|
2960
|
+
convertUint8ArrayToBase64,
|
|
2961
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
2962
|
+
delay,
|
|
2963
|
+
getFromApi as getFromApi2,
|
|
2964
|
+
parseProviderOptions as parseProviderOptions5,
|
|
2965
|
+
postJsonToApi as postJsonToApi4
|
|
2966
|
+
} from "@ai-sdk/provider-utils";
|
|
2967
|
+
import { z as z18 } from "zod/v4";
|
|
2919
2968
|
|
|
2920
2969
|
// src/xai-video-options.ts
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
var nonEmptyStringSchema =
|
|
2924
|
-
var resolutionSchema =
|
|
2925
|
-
var modeSchema =
|
|
2970
|
+
import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
|
|
2971
|
+
import { z as z17 } from "zod/v4";
|
|
2972
|
+
var nonEmptyStringSchema = z17.string().min(1);
|
|
2973
|
+
var resolutionSchema = z17.enum(["480p", "720p"]);
|
|
2974
|
+
var modeSchema = z17.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
2926
2975
|
var baseFields = {
|
|
2927
|
-
pollIntervalMs:
|
|
2928
|
-
pollTimeoutMs:
|
|
2976
|
+
pollIntervalMs: z17.number().positive().nullish(),
|
|
2977
|
+
pollTimeoutMs: z17.number().positive().nullish(),
|
|
2929
2978
|
resolution: resolutionSchema.nullish()
|
|
2930
2979
|
};
|
|
2931
|
-
var editVideoSchema =
|
|
2980
|
+
var editVideoSchema = z17.object({
|
|
2932
2981
|
...baseFields,
|
|
2933
|
-
mode:
|
|
2982
|
+
mode: z17.literal("edit-video"),
|
|
2934
2983
|
videoUrl: nonEmptyStringSchema,
|
|
2935
|
-
referenceImageUrls:
|
|
2984
|
+
referenceImageUrls: z17.undefined().optional()
|
|
2936
2985
|
});
|
|
2937
|
-
var extendVideoSchema =
|
|
2986
|
+
var extendVideoSchema = z17.object({
|
|
2938
2987
|
...baseFields,
|
|
2939
|
-
mode:
|
|
2988
|
+
mode: z17.literal("extend-video"),
|
|
2940
2989
|
videoUrl: nonEmptyStringSchema,
|
|
2941
|
-
referenceImageUrls:
|
|
2990
|
+
referenceImageUrls: z17.undefined().optional()
|
|
2942
2991
|
});
|
|
2943
|
-
var referenceToVideoSchema =
|
|
2992
|
+
var referenceToVideoSchema = z17.object({
|
|
2944
2993
|
...baseFields,
|
|
2945
|
-
mode:
|
|
2946
|
-
referenceImageUrls:
|
|
2947
|
-
videoUrl:
|
|
2994
|
+
mode: z17.literal("reference-to-video"),
|
|
2995
|
+
referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7),
|
|
2996
|
+
videoUrl: z17.undefined().optional()
|
|
2948
2997
|
});
|
|
2949
|
-
var autoDetectSchema =
|
|
2998
|
+
var autoDetectSchema = z17.object({
|
|
2950
2999
|
...baseFields,
|
|
2951
|
-
mode:
|
|
3000
|
+
mode: z17.undefined().optional(),
|
|
2952
3001
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
2953
|
-
referenceImageUrls:
|
|
3002
|
+
referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7).optional()
|
|
2954
3003
|
});
|
|
2955
|
-
var xaiVideoModelOptions =
|
|
3004
|
+
var xaiVideoModelOptions = z17.union([
|
|
2956
3005
|
editVideoSchema,
|
|
2957
3006
|
extendVideoSchema,
|
|
2958
3007
|
referenceToVideoSchema,
|
|
2959
3008
|
autoDetectSchema
|
|
2960
3009
|
]);
|
|
2961
|
-
var runtimeSchema =
|
|
3010
|
+
var runtimeSchema = z17.object({
|
|
2962
3011
|
mode: modeSchema.optional(),
|
|
2963
3012
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
2964
|
-
referenceImageUrls:
|
|
3013
|
+
referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
2965
3014
|
...baseFields
|
|
2966
3015
|
}).passthrough();
|
|
2967
|
-
var xaiVideoModelOptionsSchema = (
|
|
2968
|
-
() => (
|
|
3016
|
+
var xaiVideoModelOptionsSchema = lazySchema7(
|
|
3017
|
+
() => zodSchema7(runtimeSchema)
|
|
2969
3018
|
);
|
|
2970
3019
|
|
|
2971
3020
|
// src/xai-video-model.ts
|
|
@@ -3000,7 +3049,7 @@ var XaiVideoModel = class {
|
|
|
3000
3049
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3001
3050
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3002
3051
|
const warnings = [];
|
|
3003
|
-
const xaiOptions = await (
|
|
3052
|
+
const xaiOptions = await parseProviderOptions5({
|
|
3004
3053
|
provider: "xai",
|
|
3005
3054
|
providerOptions: options.providerOptions,
|
|
3006
3055
|
schema: xaiVideoModelOptionsSchema
|
|
@@ -3102,7 +3151,7 @@ var XaiVideoModel = class {
|
|
|
3102
3151
|
if (options.image.type === "url") {
|
|
3103
3152
|
body.image = { url: options.image.url };
|
|
3104
3153
|
} else {
|
|
3105
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
3154
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
3106
3155
|
body.image = {
|
|
3107
3156
|
url: `data:${options.image.mediaType};base64,${base64Data}`
|
|
3108
3157
|
};
|
|
@@ -3136,12 +3185,12 @@ var XaiVideoModel = class {
|
|
|
3136
3185
|
} else {
|
|
3137
3186
|
endpoint = `${baseURL}/videos/generations`;
|
|
3138
3187
|
}
|
|
3139
|
-
const { value: createResponse } = await (
|
|
3188
|
+
const { value: createResponse } = await postJsonToApi4({
|
|
3140
3189
|
url: endpoint,
|
|
3141
|
-
headers: (
|
|
3190
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
3142
3191
|
body,
|
|
3143
3192
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3144
|
-
successfulResponseHandler: (
|
|
3193
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3145
3194
|
xaiCreateVideoResponseSchema
|
|
3146
3195
|
),
|
|
3147
3196
|
abortSignal: options.abortSignal,
|
|
@@ -3149,7 +3198,7 @@ var XaiVideoModel = class {
|
|
|
3149
3198
|
});
|
|
3150
3199
|
const requestId = createResponse.request_id;
|
|
3151
3200
|
if (!requestId) {
|
|
3152
|
-
throw new
|
|
3201
|
+
throw new AISDKError({
|
|
3153
3202
|
name: "XAI_VIDEO_GENERATION_ERROR",
|
|
3154
3203
|
message: `No request_id returned from xAI API. Response: ${JSON.stringify(createResponse)}`
|
|
3155
3204
|
});
|
|
@@ -3159,17 +3208,17 @@ var XaiVideoModel = class {
|
|
|
3159
3208
|
const startTime = Date.now();
|
|
3160
3209
|
let responseHeaders;
|
|
3161
3210
|
while (true) {
|
|
3162
|
-
await
|
|
3211
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
3163
3212
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
3164
|
-
throw new
|
|
3213
|
+
throw new AISDKError({
|
|
3165
3214
|
name: "XAI_VIDEO_GENERATION_TIMEOUT",
|
|
3166
3215
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
3167
3216
|
});
|
|
3168
3217
|
}
|
|
3169
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await (
|
|
3218
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi2({
|
|
3170
3219
|
url: `${baseURL}/videos/${requestId}`,
|
|
3171
|
-
headers: (
|
|
3172
|
-
successfulResponseHandler: (
|
|
3220
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
3221
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
3173
3222
|
xaiVideoStatusResponseSchema
|
|
3174
3223
|
),
|
|
3175
3224
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -3179,13 +3228,13 @@ var XaiVideoModel = class {
|
|
|
3179
3228
|
responseHeaders = pollHeaders;
|
|
3180
3229
|
if (statusResponse.status === "done" || statusResponse.status == null && ((_g = statusResponse.video) == null ? void 0 : _g.url)) {
|
|
3181
3230
|
if (((_h = statusResponse.video) == null ? void 0 : _h.respect_moderation) === false) {
|
|
3182
|
-
throw new
|
|
3231
|
+
throw new AISDKError({
|
|
3183
3232
|
name: "XAI_VIDEO_MODERATION_ERROR",
|
|
3184
3233
|
message: "Video generation was blocked due to a content policy violation."
|
|
3185
3234
|
});
|
|
3186
3235
|
}
|
|
3187
3236
|
if (!((_i = statusResponse.video) == null ? void 0 : _i.url)) {
|
|
3188
|
-
throw new
|
|
3237
|
+
throw new AISDKError({
|
|
3189
3238
|
name: "XAI_VIDEO_GENERATION_ERROR",
|
|
3190
3239
|
message: "Video generation completed but no video URL was returned."
|
|
3191
3240
|
});
|
|
@@ -3216,13 +3265,13 @@ var XaiVideoModel = class {
|
|
|
3216
3265
|
};
|
|
3217
3266
|
}
|
|
3218
3267
|
if (statusResponse.status === "expired") {
|
|
3219
|
-
throw new
|
|
3268
|
+
throw new AISDKError({
|
|
3220
3269
|
name: "XAI_VIDEO_GENERATION_EXPIRED",
|
|
3221
3270
|
message: "Video generation request expired."
|
|
3222
3271
|
});
|
|
3223
3272
|
}
|
|
3224
3273
|
if (statusResponse.status === "failed") {
|
|
3225
|
-
throw new
|
|
3274
|
+
throw new AISDKError({
|
|
3226
3275
|
name: "XAI_VIDEO_GENERATION_FAILED",
|
|
3227
3276
|
message: "Video generation failed."
|
|
3228
3277
|
});
|
|
@@ -3230,36 +3279,36 @@ var XaiVideoModel = class {
|
|
|
3230
3279
|
}
|
|
3231
3280
|
}
|
|
3232
3281
|
};
|
|
3233
|
-
var xaiCreateVideoResponseSchema =
|
|
3234
|
-
request_id:
|
|
3282
|
+
var xaiCreateVideoResponseSchema = z18.object({
|
|
3283
|
+
request_id: z18.string().nullish()
|
|
3235
3284
|
});
|
|
3236
|
-
var xaiVideoStatusResponseSchema =
|
|
3237
|
-
status:
|
|
3238
|
-
video:
|
|
3239
|
-
url:
|
|
3240
|
-
duration:
|
|
3241
|
-
respect_moderation:
|
|
3285
|
+
var xaiVideoStatusResponseSchema = z18.object({
|
|
3286
|
+
status: z18.string().nullish(),
|
|
3287
|
+
video: z18.object({
|
|
3288
|
+
url: z18.string(),
|
|
3289
|
+
duration: z18.number().nullish(),
|
|
3290
|
+
respect_moderation: z18.boolean().nullish()
|
|
3242
3291
|
}).nullish(),
|
|
3243
|
-
model:
|
|
3244
|
-
usage:
|
|
3245
|
-
cost_in_usd_ticks:
|
|
3292
|
+
model: z18.string().nullish(),
|
|
3293
|
+
usage: z18.object({
|
|
3294
|
+
cost_in_usd_ticks: z18.number().nullish()
|
|
3246
3295
|
}).nullish(),
|
|
3247
|
-
progress:
|
|
3248
|
-
error:
|
|
3249
|
-
code:
|
|
3250
|
-
message:
|
|
3296
|
+
progress: z18.number().nullish(),
|
|
3297
|
+
error: z18.object({
|
|
3298
|
+
code: z18.string().nullish(),
|
|
3299
|
+
message: z18.string().nullish()
|
|
3251
3300
|
}).nullish()
|
|
3252
3301
|
});
|
|
3253
3302
|
|
|
3254
3303
|
// src/xai-provider.ts
|
|
3255
3304
|
function createXai(options = {}) {
|
|
3256
3305
|
var _a;
|
|
3257
|
-
const baseURL =
|
|
3306
|
+
const baseURL = withoutTrailingSlash(
|
|
3258
3307
|
(_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
|
|
3259
3308
|
);
|
|
3260
|
-
const getHeaders = () =>
|
|
3309
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
3261
3310
|
{
|
|
3262
|
-
Authorization: `Bearer ${
|
|
3311
|
+
Authorization: `Bearer ${loadApiKey({
|
|
3263
3312
|
apiKey: options.apiKey,
|
|
3264
3313
|
environmentVariableName: "XAI_API_KEY",
|
|
3265
3314
|
description: "xAI API key"
|
|
@@ -3273,7 +3322,7 @@ function createXai(options = {}) {
|
|
|
3273
3322
|
provider: "xai.chat",
|
|
3274
3323
|
baseURL,
|
|
3275
3324
|
headers: getHeaders,
|
|
3276
|
-
generateId
|
|
3325
|
+
generateId,
|
|
3277
3326
|
fetch: options.fetch
|
|
3278
3327
|
});
|
|
3279
3328
|
};
|
|
@@ -3282,7 +3331,7 @@ function createXai(options = {}) {
|
|
|
3282
3331
|
provider: "xai.responses",
|
|
3283
3332
|
baseURL,
|
|
3284
3333
|
headers: getHeaders,
|
|
3285
|
-
generateId
|
|
3334
|
+
generateId,
|
|
3286
3335
|
fetch: options.fetch
|
|
3287
3336
|
});
|
|
3288
3337
|
};
|
|
@@ -3314,7 +3363,7 @@ function createXai(options = {}) {
|
|
|
3314
3363
|
provider.chat = createChatLanguageModel;
|
|
3315
3364
|
provider.responses = createResponsesLanguageModel;
|
|
3316
3365
|
provider.embeddingModel = (modelId) => {
|
|
3317
|
-
throw new
|
|
3366
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
3318
3367
|
};
|
|
3319
3368
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
3320
3369
|
provider.imageModel = createImageModel;
|
|
@@ -3326,8 +3375,7 @@ function createXai(options = {}) {
|
|
|
3326
3375
|
return provider;
|
|
3327
3376
|
}
|
|
3328
3377
|
var xai = createXai();
|
|
3329
|
-
|
|
3330
|
-
0 && (module.exports = {
|
|
3378
|
+
export {
|
|
3331
3379
|
VERSION,
|
|
3332
3380
|
codeExecution,
|
|
3333
3381
|
createXai,
|
|
@@ -3338,5 +3386,5 @@ var xai = createXai();
|
|
|
3338
3386
|
xSearch,
|
|
3339
3387
|
xai,
|
|
3340
3388
|
xaiTools
|
|
3341
|
-
}
|
|
3389
|
+
};
|
|
3342
3390
|
//# sourceMappingURL=index.js.map
|