@ai-sdk/xai 4.0.0-beta.4 → 4.0.0-beta.40
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 +311 -8
- package/README.md +2 -0
- package/dist/index.d.ts +126 -50
- package/dist/index.js +1169 -749
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +173 -381
- package/package.json +8 -10
- package/src/convert-to-xai-chat-messages.ts +22 -6
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/files/xai-files-api.ts +16 -0
- package/src/files/xai-files-options.ts +15 -0
- package/src/files/xai-files.ts +93 -0
- package/src/index.ts +1 -0
- package/src/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +63 -8
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +3 -2
- package/src/responses/xai-responses-api.ts +31 -1
- package/src/responses/xai-responses-language-model.ts +134 -48
- package/src/responses/xai-responses-options.ts +6 -0
- package/src/responses/xai-responses-prepare-tools.ts +6 -6
- package/src/xai-chat-language-model.ts +61 -25
- package/src/xai-chat-options.ts +3 -6
- package/src/xai-chat-prompt.ts +2 -1
- package/src/xai-image-model.ts +25 -8
- package/src/xai-image-settings.ts +0 -2
- package/src/xai-prepare-tools.ts +6 -6
- package/src/xai-provider.ts +34 -21
- package/src/xai-video-model.ts +127 -20
- package/src/xai-video-options.ts +136 -14
- package/dist/index.d.mts +0 -375
- package/dist/index.mjs +0 -3061
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,50 +1,43 @@
|
|
|
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 src_exports = {};
|
|
22
|
-
__export(src_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(src_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
|
+
serializeModelOptions,
|
|
27
|
+
WORKFLOW_SERIALIZE,
|
|
28
|
+
WORKFLOW_DESERIALIZE
|
|
29
|
+
} from "@ai-sdk/provider-utils";
|
|
30
|
+
import { z as z3 } from "zod/v4";
|
|
44
31
|
|
|
45
32
|
// src/convert-to-xai-chat-messages.ts
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
import {
|
|
34
|
+
UnsupportedFunctionalityError
|
|
35
|
+
} from "@ai-sdk/provider";
|
|
36
|
+
import {
|
|
37
|
+
convertToBase64,
|
|
38
|
+
isProviderReference,
|
|
39
|
+
resolveProviderReference
|
|
40
|
+
} from "@ai-sdk/provider-utils";
|
|
48
41
|
function convertToXaiChatMessages(prompt) {
|
|
49
42
|
var _a;
|
|
50
43
|
const messages = [];
|
|
@@ -68,16 +61,27 @@ function convertToXaiChatMessages(prompt) {
|
|
|
68
61
|
return { type: "text", text: part.text };
|
|
69
62
|
}
|
|
70
63
|
case "file": {
|
|
64
|
+
if (isProviderReference(part.data)) {
|
|
65
|
+
return {
|
|
66
|
+
type: "file",
|
|
67
|
+
file: {
|
|
68
|
+
file_id: resolveProviderReference({
|
|
69
|
+
reference: part.data,
|
|
70
|
+
provider: "xai"
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
71
75
|
if (part.mediaType.startsWith("image/")) {
|
|
72
76
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
73
77
|
return {
|
|
74
78
|
type: "image_url",
|
|
75
79
|
image_url: {
|
|
76
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
80
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
77
81
|
}
|
|
78
82
|
};
|
|
79
83
|
} else {
|
|
80
|
-
throw new
|
|
84
|
+
throw new UnsupportedFunctionalityError({
|
|
81
85
|
functionality: `file part media type ${part.mediaType}`
|
|
82
86
|
});
|
|
83
87
|
}
|
|
@@ -209,79 +213,79 @@ function mapXaiFinishReason(finishReason) {
|
|
|
209
213
|
}
|
|
210
214
|
|
|
211
215
|
// src/xai-chat-options.ts
|
|
212
|
-
|
|
213
|
-
var webSourceSchema =
|
|
214
|
-
type:
|
|
215
|
-
country:
|
|
216
|
-
excludedWebsites:
|
|
217
|
-
allowedWebsites:
|
|
218
|
-
safeSearch:
|
|
216
|
+
import { z } from "zod/v4";
|
|
217
|
+
var webSourceSchema = z.object({
|
|
218
|
+
type: z.literal("web"),
|
|
219
|
+
country: z.string().length(2).optional(),
|
|
220
|
+
excludedWebsites: z.array(z.string()).max(5).optional(),
|
|
221
|
+
allowedWebsites: z.array(z.string()).max(5).optional(),
|
|
222
|
+
safeSearch: z.boolean().optional()
|
|
219
223
|
});
|
|
220
|
-
var xSourceSchema =
|
|
221
|
-
type:
|
|
222
|
-
excludedXHandles:
|
|
223
|
-
includedXHandles:
|
|
224
|
-
postFavoriteCount:
|
|
225
|
-
postViewCount:
|
|
224
|
+
var xSourceSchema = z.object({
|
|
225
|
+
type: z.literal("x"),
|
|
226
|
+
excludedXHandles: z.array(z.string()).optional(),
|
|
227
|
+
includedXHandles: z.array(z.string()).optional(),
|
|
228
|
+
postFavoriteCount: z.number().int().optional(),
|
|
229
|
+
postViewCount: z.number().int().optional(),
|
|
226
230
|
/**
|
|
227
231
|
* @deprecated use `includedXHandles` instead
|
|
228
232
|
*/
|
|
229
|
-
xHandles:
|
|
233
|
+
xHandles: z.array(z.string()).optional()
|
|
230
234
|
});
|
|
231
|
-
var newsSourceSchema =
|
|
232
|
-
type:
|
|
233
|
-
country:
|
|
234
|
-
excludedWebsites:
|
|
235
|
-
safeSearch:
|
|
235
|
+
var newsSourceSchema = z.object({
|
|
236
|
+
type: z.literal("news"),
|
|
237
|
+
country: z.string().length(2).optional(),
|
|
238
|
+
excludedWebsites: z.array(z.string()).max(5).optional(),
|
|
239
|
+
safeSearch: z.boolean().optional()
|
|
236
240
|
});
|
|
237
|
-
var rssSourceSchema =
|
|
238
|
-
type:
|
|
239
|
-
links:
|
|
241
|
+
var rssSourceSchema = z.object({
|
|
242
|
+
type: z.literal("rss"),
|
|
243
|
+
links: z.array(z.string().url()).max(1)
|
|
240
244
|
// currently only supports one RSS link
|
|
241
245
|
});
|
|
242
|
-
var searchSourceSchema =
|
|
246
|
+
var searchSourceSchema = z.discriminatedUnion("type", [
|
|
243
247
|
webSourceSchema,
|
|
244
248
|
xSourceSchema,
|
|
245
249
|
newsSourceSchema,
|
|
246
250
|
rssSourceSchema
|
|
247
251
|
]);
|
|
248
|
-
var xaiLanguageModelChatOptions =
|
|
249
|
-
reasoningEffort:
|
|
250
|
-
logprobs:
|
|
251
|
-
topLogprobs:
|
|
252
|
+
var xaiLanguageModelChatOptions = z.object({
|
|
253
|
+
reasoningEffort: z.enum(["low", "high"]).optional(),
|
|
254
|
+
logprobs: z.boolean().optional(),
|
|
255
|
+
topLogprobs: z.number().int().min(0).max(8).optional(),
|
|
252
256
|
/**
|
|
253
257
|
* Whether to enable parallel function calling during tool use.
|
|
254
258
|
* When true, the model can call multiple functions in parallel.
|
|
255
259
|
* When false, the model will call functions sequentially.
|
|
256
260
|
* Defaults to true.
|
|
257
261
|
*/
|
|
258
|
-
parallel_function_calling:
|
|
259
|
-
searchParameters:
|
|
262
|
+
parallel_function_calling: z.boolean().optional(),
|
|
263
|
+
searchParameters: z.object({
|
|
260
264
|
/**
|
|
261
265
|
* search mode preference
|
|
262
266
|
* - "off": disables search completely
|
|
263
267
|
* - "auto": model decides whether to search (default)
|
|
264
268
|
* - "on": always enables search
|
|
265
269
|
*/
|
|
266
|
-
mode:
|
|
270
|
+
mode: z.enum(["off", "auto", "on"]),
|
|
267
271
|
/**
|
|
268
272
|
* whether to return citations in the response
|
|
269
273
|
* defaults to true
|
|
270
274
|
*/
|
|
271
|
-
returnCitations:
|
|
275
|
+
returnCitations: z.boolean().optional(),
|
|
272
276
|
/**
|
|
273
277
|
* start date for search data (ISO8601 format: YYYY-MM-DD)
|
|
274
278
|
*/
|
|
275
|
-
fromDate:
|
|
279
|
+
fromDate: z.string().optional(),
|
|
276
280
|
/**
|
|
277
281
|
* end date for search data (ISO8601 format: YYYY-MM-DD)
|
|
278
282
|
*/
|
|
279
|
-
toDate:
|
|
283
|
+
toDate: z.string().optional(),
|
|
280
284
|
/**
|
|
281
285
|
* maximum number of search results to consider
|
|
282
286
|
* defaults to 20
|
|
283
287
|
*/
|
|
284
|
-
maxSearchResults:
|
|
288
|
+
maxSearchResults: z.number().min(1).max(50).optional(),
|
|
285
289
|
/**
|
|
286
290
|
* data sources to search from.
|
|
287
291
|
* defaults to [{ type: 'web' }, { type: 'x' }] if not specified.
|
|
@@ -289,28 +293,30 @@ var xaiLanguageModelChatOptions = import_v4.z.object({
|
|
|
289
293
|
* @example
|
|
290
294
|
* sources: [{ type: 'web', country: 'US' }, { type: 'x' }]
|
|
291
295
|
*/
|
|
292
|
-
sources:
|
|
296
|
+
sources: z.array(searchSourceSchema).optional()
|
|
293
297
|
}).optional()
|
|
294
298
|
});
|
|
295
299
|
|
|
296
300
|
// src/xai-error.ts
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
var xaiErrorDataSchema =
|
|
300
|
-
error:
|
|
301
|
-
message:
|
|
302
|
-
type:
|
|
303
|
-
param:
|
|
304
|
-
code:
|
|
301
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
302
|
+
import { z as z2 } from "zod/v4";
|
|
303
|
+
var xaiErrorDataSchema = z2.object({
|
|
304
|
+
error: z2.object({
|
|
305
|
+
message: z2.string(),
|
|
306
|
+
type: z2.string().nullish(),
|
|
307
|
+
param: z2.any().nullish(),
|
|
308
|
+
code: z2.union([z2.string(), z2.number()]).nullish()
|
|
305
309
|
})
|
|
306
310
|
});
|
|
307
|
-
var xaiFailedResponseHandler =
|
|
311
|
+
var xaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
308
312
|
errorSchema: xaiErrorDataSchema,
|
|
309
313
|
errorToMessage: (data) => data.error.message
|
|
310
314
|
});
|
|
311
315
|
|
|
312
316
|
// src/xai-prepare-tools.ts
|
|
313
|
-
|
|
317
|
+
import {
|
|
318
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
319
|
+
} from "@ai-sdk/provider";
|
|
314
320
|
function prepareTools({
|
|
315
321
|
tools,
|
|
316
322
|
toolChoice
|
|
@@ -360,7 +366,7 @@ function prepareTools({
|
|
|
360
366
|
};
|
|
361
367
|
default: {
|
|
362
368
|
const _exhaustiveCheck = type;
|
|
363
|
-
throw new
|
|
369
|
+
throw new UnsupportedFunctionalityError2({
|
|
364
370
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
365
371
|
});
|
|
366
372
|
}
|
|
@@ -368,15 +374,24 @@ function prepareTools({
|
|
|
368
374
|
}
|
|
369
375
|
|
|
370
376
|
// src/xai-chat-language-model.ts
|
|
371
|
-
var XaiChatLanguageModel = class {
|
|
377
|
+
var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
372
378
|
constructor(modelId, config) {
|
|
373
|
-
this.specificationVersion = "
|
|
379
|
+
this.specificationVersion = "v4";
|
|
374
380
|
this.supportedUrls = {
|
|
375
381
|
"image/*": [/^https?:\/\/.*$/]
|
|
376
382
|
};
|
|
377
383
|
this.modelId = modelId;
|
|
378
384
|
this.config = config;
|
|
379
385
|
}
|
|
386
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
387
|
+
return serializeModelOptions({
|
|
388
|
+
modelId: model.modelId,
|
|
389
|
+
config: model.config
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
393
|
+
return new _XaiChatLanguageModel(options.modelId, options.config);
|
|
394
|
+
}
|
|
380
395
|
get provider() {
|
|
381
396
|
return this.config.provider;
|
|
382
397
|
}
|
|
@@ -390,14 +405,15 @@ var XaiChatLanguageModel = class {
|
|
|
390
405
|
presencePenalty,
|
|
391
406
|
stopSequences,
|
|
392
407
|
seed,
|
|
408
|
+
reasoning,
|
|
393
409
|
responseFormat,
|
|
394
410
|
providerOptions,
|
|
395
411
|
tools,
|
|
396
412
|
toolChoice
|
|
397
413
|
}) {
|
|
398
|
-
var _a, _b, _c;
|
|
414
|
+
var _a, _b, _c, _d;
|
|
399
415
|
const warnings = [];
|
|
400
|
-
const options = (_a = await
|
|
416
|
+
const options = (_a = await parseProviderOptions({
|
|
401
417
|
provider: "xai",
|
|
402
418
|
providerOptions,
|
|
403
419
|
schema: xaiLanguageModelChatOptions
|
|
@@ -435,14 +451,24 @@ var XaiChatLanguageModel = class {
|
|
|
435
451
|
temperature,
|
|
436
452
|
top_p: topP,
|
|
437
453
|
seed,
|
|
438
|
-
reasoning_effort: options.reasoningEffort
|
|
454
|
+
reasoning_effort: (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort({
|
|
455
|
+
reasoning,
|
|
456
|
+
effortMap: {
|
|
457
|
+
minimal: "low",
|
|
458
|
+
low: "low",
|
|
459
|
+
medium: "low",
|
|
460
|
+
high: "high",
|
|
461
|
+
xhigh: "high"
|
|
462
|
+
},
|
|
463
|
+
warnings
|
|
464
|
+
}) : void 0,
|
|
439
465
|
// parallel function calling
|
|
440
466
|
parallel_function_calling: options.parallel_function_calling,
|
|
441
467
|
// response format
|
|
442
468
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
443
469
|
type: "json_schema",
|
|
444
470
|
json_schema: {
|
|
445
|
-
name: (
|
|
471
|
+
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
446
472
|
schema: responseFormat.schema,
|
|
447
473
|
strict: true
|
|
448
474
|
}
|
|
@@ -454,7 +480,7 @@ var XaiChatLanguageModel = class {
|
|
|
454
480
|
from_date: options.searchParameters.fromDate,
|
|
455
481
|
to_date: options.searchParameters.toDate,
|
|
456
482
|
max_search_results: options.searchParameters.maxSearchResults,
|
|
457
|
-
sources: (
|
|
483
|
+
sources: (_d = options.searchParameters.sources) == null ? void 0 : _d.map((source) => {
|
|
458
484
|
var _a2;
|
|
459
485
|
return {
|
|
460
486
|
type: source.type,
|
|
@@ -493,26 +519,26 @@ var XaiChatLanguageModel = class {
|
|
|
493
519
|
};
|
|
494
520
|
}
|
|
495
521
|
async doGenerate(options) {
|
|
496
|
-
var _a, _b;
|
|
522
|
+
var _a, _b, _c, _d;
|
|
497
523
|
const { args: body, warnings } = await this.getArgs(options);
|
|
498
524
|
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
499
525
|
const {
|
|
500
526
|
responseHeaders,
|
|
501
527
|
value: response,
|
|
502
528
|
rawValue: rawResponse
|
|
503
|
-
} = await
|
|
529
|
+
} = await postJsonToApi({
|
|
504
530
|
url,
|
|
505
|
-
headers: (
|
|
531
|
+
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
506
532
|
body,
|
|
507
533
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
508
|
-
successfulResponseHandler:
|
|
534
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
509
535
|
xaiChatResponseSchema
|
|
510
536
|
),
|
|
511
537
|
abortSignal: options.abortSignal,
|
|
512
538
|
fetch: this.config.fetch
|
|
513
539
|
});
|
|
514
540
|
if (response.error != null) {
|
|
515
|
-
throw new
|
|
541
|
+
throw new APICallError({
|
|
516
542
|
message: response.error,
|
|
517
543
|
url,
|
|
518
544
|
requestBodyValues: body,
|
|
@@ -564,7 +590,7 @@ var XaiChatLanguageModel = class {
|
|
|
564
590
|
content,
|
|
565
591
|
finishReason: {
|
|
566
592
|
unified: mapXaiFinishReason(choice.finish_reason),
|
|
567
|
-
raw: (
|
|
593
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
568
594
|
},
|
|
569
595
|
usage: response.usage ? convertXaiChatUsage(response.usage) : {
|
|
570
596
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -580,7 +606,7 @@ var XaiChatLanguageModel = class {
|
|
|
580
606
|
};
|
|
581
607
|
}
|
|
582
608
|
async doStream(options) {
|
|
583
|
-
var _a;
|
|
609
|
+
var _a, _b, _c;
|
|
584
610
|
const { args, warnings } = await this.getArgs(options);
|
|
585
611
|
const body = {
|
|
586
612
|
...args,
|
|
@@ -590,22 +616,22 @@ var XaiChatLanguageModel = class {
|
|
|
590
616
|
}
|
|
591
617
|
};
|
|
592
618
|
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
593
|
-
const { responseHeaders, value: response } = await
|
|
619
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
594
620
|
url,
|
|
595
|
-
headers: (
|
|
621
|
+
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
596
622
|
body,
|
|
597
623
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
598
624
|
successfulResponseHandler: async ({ response: response2 }) => {
|
|
599
|
-
const responseHeaders2 =
|
|
625
|
+
const responseHeaders2 = extractResponseHeaders(response2);
|
|
600
626
|
const contentType = response2.headers.get("content-type");
|
|
601
627
|
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
602
628
|
const responseBody = await response2.text();
|
|
603
|
-
const parsedError = await
|
|
629
|
+
const parsedError = await safeParseJSON({
|
|
604
630
|
text: responseBody,
|
|
605
631
|
schema: xaiStreamErrorSchema
|
|
606
632
|
});
|
|
607
633
|
if (parsedError.success) {
|
|
608
|
-
throw new
|
|
634
|
+
throw new APICallError({
|
|
609
635
|
message: parsedError.value.error,
|
|
610
636
|
url,
|
|
611
637
|
requestBodyValues: body,
|
|
@@ -615,7 +641,7 @@ var XaiChatLanguageModel = class {
|
|
|
615
641
|
isRetryable: parsedError.value.code === "The service is currently unavailable"
|
|
616
642
|
});
|
|
617
643
|
}
|
|
618
|
-
throw new
|
|
644
|
+
throw new APICallError({
|
|
619
645
|
message: "Invalid JSON response",
|
|
620
646
|
url,
|
|
621
647
|
requestBodyValues: body,
|
|
@@ -624,7 +650,7 @@ var XaiChatLanguageModel = class {
|
|
|
624
650
|
responseBody
|
|
625
651
|
});
|
|
626
652
|
}
|
|
627
|
-
return
|
|
653
|
+
return createEventSourceResponseHandler(xaiChatChunkSchema)({
|
|
628
654
|
response: response2,
|
|
629
655
|
url,
|
|
630
656
|
requestBodyValues: body
|
|
@@ -802,113 +828,134 @@ var XaiChatLanguageModel = class {
|
|
|
802
828
|
};
|
|
803
829
|
}
|
|
804
830
|
};
|
|
805
|
-
var xaiUsageSchema =
|
|
806
|
-
prompt_tokens:
|
|
807
|
-
completion_tokens:
|
|
808
|
-
total_tokens:
|
|
809
|
-
prompt_tokens_details:
|
|
810
|
-
text_tokens:
|
|
811
|
-
audio_tokens:
|
|
812
|
-
image_tokens:
|
|
813
|
-
cached_tokens:
|
|
831
|
+
var xaiUsageSchema = z3.object({
|
|
832
|
+
prompt_tokens: z3.number(),
|
|
833
|
+
completion_tokens: z3.number(),
|
|
834
|
+
total_tokens: z3.number(),
|
|
835
|
+
prompt_tokens_details: z3.object({
|
|
836
|
+
text_tokens: z3.number().nullish(),
|
|
837
|
+
audio_tokens: z3.number().nullish(),
|
|
838
|
+
image_tokens: z3.number().nullish(),
|
|
839
|
+
cached_tokens: z3.number().nullish()
|
|
814
840
|
}).nullish(),
|
|
815
|
-
completion_tokens_details:
|
|
816
|
-
reasoning_tokens:
|
|
817
|
-
audio_tokens:
|
|
818
|
-
accepted_prediction_tokens:
|
|
819
|
-
rejected_prediction_tokens:
|
|
841
|
+
completion_tokens_details: z3.object({
|
|
842
|
+
reasoning_tokens: z3.number().nullish(),
|
|
843
|
+
audio_tokens: z3.number().nullish(),
|
|
844
|
+
accepted_prediction_tokens: z3.number().nullish(),
|
|
845
|
+
rejected_prediction_tokens: z3.number().nullish()
|
|
820
846
|
}).nullish()
|
|
821
847
|
});
|
|
822
|
-
var xaiChatResponseSchema =
|
|
823
|
-
id:
|
|
824
|
-
created:
|
|
825
|
-
model:
|
|
826
|
-
choices:
|
|
827
|
-
|
|
828
|
-
message:
|
|
829
|
-
role:
|
|
830
|
-
content:
|
|
831
|
-
reasoning_content:
|
|
832
|
-
tool_calls:
|
|
833
|
-
|
|
834
|
-
id:
|
|
835
|
-
type:
|
|
836
|
-
function:
|
|
837
|
-
name:
|
|
838
|
-
arguments:
|
|
848
|
+
var xaiChatResponseSchema = z3.object({
|
|
849
|
+
id: z3.string().nullish(),
|
|
850
|
+
created: z3.number().nullish(),
|
|
851
|
+
model: z3.string().nullish(),
|
|
852
|
+
choices: z3.array(
|
|
853
|
+
z3.object({
|
|
854
|
+
message: z3.object({
|
|
855
|
+
role: z3.literal("assistant"),
|
|
856
|
+
content: z3.string().nullish(),
|
|
857
|
+
reasoning_content: z3.string().nullish(),
|
|
858
|
+
tool_calls: z3.array(
|
|
859
|
+
z3.object({
|
|
860
|
+
id: z3.string(),
|
|
861
|
+
type: z3.literal("function"),
|
|
862
|
+
function: z3.object({
|
|
863
|
+
name: z3.string(),
|
|
864
|
+
arguments: z3.string()
|
|
839
865
|
})
|
|
840
866
|
})
|
|
841
867
|
).nullish()
|
|
842
868
|
}),
|
|
843
|
-
index:
|
|
844
|
-
finish_reason:
|
|
869
|
+
index: z3.number(),
|
|
870
|
+
finish_reason: z3.string().nullish()
|
|
845
871
|
})
|
|
846
872
|
).nullish(),
|
|
847
|
-
object:
|
|
873
|
+
object: z3.literal("chat.completion").nullish(),
|
|
848
874
|
usage: xaiUsageSchema.nullish(),
|
|
849
|
-
citations:
|
|
850
|
-
code:
|
|
851
|
-
error:
|
|
875
|
+
citations: z3.array(z3.string().url()).nullish(),
|
|
876
|
+
code: z3.string().nullish(),
|
|
877
|
+
error: z3.string().nullish()
|
|
852
878
|
});
|
|
853
|
-
var xaiChatChunkSchema =
|
|
854
|
-
id:
|
|
855
|
-
created:
|
|
856
|
-
model:
|
|
857
|
-
choices:
|
|
858
|
-
|
|
859
|
-
delta:
|
|
860
|
-
role:
|
|
861
|
-
content:
|
|
862
|
-
reasoning_content:
|
|
863
|
-
tool_calls:
|
|
864
|
-
|
|
865
|
-
id:
|
|
866
|
-
type:
|
|
867
|
-
function:
|
|
868
|
-
name:
|
|
869
|
-
arguments:
|
|
879
|
+
var xaiChatChunkSchema = z3.object({
|
|
880
|
+
id: z3.string().nullish(),
|
|
881
|
+
created: z3.number().nullish(),
|
|
882
|
+
model: z3.string().nullish(),
|
|
883
|
+
choices: z3.array(
|
|
884
|
+
z3.object({
|
|
885
|
+
delta: z3.object({
|
|
886
|
+
role: z3.enum(["assistant"]).optional(),
|
|
887
|
+
content: z3.string().nullish(),
|
|
888
|
+
reasoning_content: z3.string().nullish(),
|
|
889
|
+
tool_calls: z3.array(
|
|
890
|
+
z3.object({
|
|
891
|
+
id: z3.string(),
|
|
892
|
+
type: z3.literal("function"),
|
|
893
|
+
function: z3.object({
|
|
894
|
+
name: z3.string(),
|
|
895
|
+
arguments: z3.string()
|
|
870
896
|
})
|
|
871
897
|
})
|
|
872
898
|
).nullish()
|
|
873
899
|
}),
|
|
874
|
-
finish_reason:
|
|
875
|
-
index:
|
|
900
|
+
finish_reason: z3.string().nullish(),
|
|
901
|
+
index: z3.number()
|
|
876
902
|
})
|
|
877
903
|
),
|
|
878
904
|
usage: xaiUsageSchema.nullish(),
|
|
879
|
-
citations:
|
|
905
|
+
citations: z3.array(z3.string().url()).nullish()
|
|
880
906
|
});
|
|
881
|
-
var xaiStreamErrorSchema =
|
|
882
|
-
code:
|
|
883
|
-
error:
|
|
907
|
+
var xaiStreamErrorSchema = z3.object({
|
|
908
|
+
code: z3.string(),
|
|
909
|
+
error: z3.string()
|
|
884
910
|
});
|
|
885
911
|
|
|
886
912
|
// src/xai-image-model.ts
|
|
887
|
-
|
|
888
|
-
|
|
913
|
+
import {
|
|
914
|
+
combineHeaders as combineHeaders2,
|
|
915
|
+
convertImageModelFileToDataUri,
|
|
916
|
+
createBinaryResponseHandler,
|
|
917
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
918
|
+
createStatusCodeErrorResponseHandler,
|
|
919
|
+
getFromApi,
|
|
920
|
+
parseProviderOptions as parseProviderOptions2,
|
|
921
|
+
postJsonToApi as postJsonToApi2,
|
|
922
|
+
serializeModelOptions as serializeModelOptions2,
|
|
923
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
924
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
925
|
+
} from "@ai-sdk/provider-utils";
|
|
926
|
+
import { z as z5 } from "zod/v4";
|
|
889
927
|
|
|
890
928
|
// src/xai-image-options.ts
|
|
891
|
-
|
|
892
|
-
var xaiImageModelOptions =
|
|
893
|
-
aspect_ratio:
|
|
894
|
-
output_format:
|
|
895
|
-
sync_mode:
|
|
896
|
-
resolution:
|
|
897
|
-
quality:
|
|
898
|
-
user:
|
|
929
|
+
import { z as z4 } from "zod/v4";
|
|
930
|
+
var xaiImageModelOptions = z4.object({
|
|
931
|
+
aspect_ratio: z4.string().optional(),
|
|
932
|
+
output_format: z4.string().optional(),
|
|
933
|
+
sync_mode: z4.boolean().optional(),
|
|
934
|
+
resolution: z4.enum(["1k", "2k"]).optional(),
|
|
935
|
+
quality: z4.enum(["low", "medium", "high"]).optional(),
|
|
936
|
+
user: z4.string().optional()
|
|
899
937
|
});
|
|
900
938
|
|
|
901
939
|
// src/xai-image-model.ts
|
|
902
|
-
var XaiImageModel = class {
|
|
940
|
+
var XaiImageModel = class _XaiImageModel {
|
|
903
941
|
constructor(modelId, config) {
|
|
904
942
|
this.modelId = modelId;
|
|
905
943
|
this.config = config;
|
|
906
|
-
this.specificationVersion = "
|
|
944
|
+
this.specificationVersion = "v4";
|
|
907
945
|
this.maxImagesPerCall = 3;
|
|
908
946
|
}
|
|
909
947
|
get provider() {
|
|
910
948
|
return this.config.provider;
|
|
911
949
|
}
|
|
950
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
951
|
+
return serializeModelOptions2({
|
|
952
|
+
modelId: model.modelId,
|
|
953
|
+
config: model.config
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
957
|
+
return new _XaiImageModel(options.modelId, options.config);
|
|
958
|
+
}
|
|
912
959
|
async doGenerate({
|
|
913
960
|
prompt,
|
|
914
961
|
n,
|
|
@@ -921,7 +968,7 @@ var XaiImageModel = class {
|
|
|
921
968
|
files,
|
|
922
969
|
mask
|
|
923
970
|
}) {
|
|
924
|
-
var _a, _b, _c, _d, _e;
|
|
971
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
925
972
|
const warnings = [];
|
|
926
973
|
if (size != null) {
|
|
927
974
|
warnings.push({
|
|
@@ -942,13 +989,13 @@ var XaiImageModel = class {
|
|
|
942
989
|
feature: "mask"
|
|
943
990
|
});
|
|
944
991
|
}
|
|
945
|
-
const xaiOptions = await (
|
|
992
|
+
const xaiOptions = await parseProviderOptions2({
|
|
946
993
|
provider: "xai",
|
|
947
994
|
providerOptions,
|
|
948
995
|
schema: xaiImageModelOptions
|
|
949
996
|
});
|
|
950
997
|
const hasFiles = files != null && files.length > 0;
|
|
951
|
-
const imageUrls = hasFiles ? files.map((file) =>
|
|
998
|
+
const imageUrls = hasFiles ? files.map((file) => convertImageModelFileToDataUri(file)) : [];
|
|
952
999
|
const endpoint = hasFiles ? "/images/edits" : "/images/generations";
|
|
953
1000
|
const body = {
|
|
954
1001
|
model: this.modelId,
|
|
@@ -984,12 +1031,12 @@ var XaiImageModel = class {
|
|
|
984
1031
|
}
|
|
985
1032
|
const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
|
|
986
1033
|
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
987
|
-
const { value: response, responseHeaders } = await (
|
|
1034
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
988
1035
|
url: `${baseURL}${endpoint}`,
|
|
989
|
-
headers: (
|
|
1036
|
+
headers: combineHeaders2((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
|
|
990
1037
|
body,
|
|
991
1038
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
992
|
-
successfulResponseHandler: (
|
|
1039
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
993
1040
|
xaiImageResponseSchema
|
|
994
1041
|
),
|
|
995
1042
|
abortSignal,
|
|
@@ -1014,45 +1061,62 @@ var XaiImageModel = class {
|
|
|
1014
1061
|
images: response.data.map((item) => ({
|
|
1015
1062
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
|
|
1016
1063
|
})),
|
|
1017
|
-
...((
|
|
1064
|
+
...((_g = response.usage) == null ? void 0 : _g.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
1018
1065
|
}
|
|
1019
1066
|
}
|
|
1020
1067
|
};
|
|
1021
1068
|
}
|
|
1022
1069
|
async downloadImage(url, abortSignal) {
|
|
1023
|
-
const { value } = await
|
|
1070
|
+
const { value } = await getFromApi({
|
|
1024
1071
|
url,
|
|
1025
1072
|
abortSignal,
|
|
1026
|
-
failedResponseHandler:
|
|
1027
|
-
successfulResponseHandler:
|
|
1073
|
+
failedResponseHandler: createStatusCodeErrorResponseHandler(),
|
|
1074
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
1028
1075
|
fetch: this.config.fetch
|
|
1029
1076
|
});
|
|
1030
1077
|
return value;
|
|
1031
1078
|
}
|
|
1032
1079
|
};
|
|
1033
|
-
var xaiImageResponseSchema =
|
|
1034
|
-
data:
|
|
1035
|
-
|
|
1036
|
-
url:
|
|
1037
|
-
b64_json:
|
|
1038
|
-
revised_prompt:
|
|
1080
|
+
var xaiImageResponseSchema = z5.object({
|
|
1081
|
+
data: z5.array(
|
|
1082
|
+
z5.object({
|
|
1083
|
+
url: z5.string().nullish(),
|
|
1084
|
+
b64_json: z5.string().nullish(),
|
|
1085
|
+
revised_prompt: z5.string().nullish()
|
|
1039
1086
|
})
|
|
1040
1087
|
),
|
|
1041
|
-
usage:
|
|
1042
|
-
cost_in_usd_ticks:
|
|
1088
|
+
usage: z5.object({
|
|
1089
|
+
cost_in_usd_ticks: z5.number().nullish()
|
|
1043
1090
|
}).nullish()
|
|
1044
1091
|
});
|
|
1045
1092
|
|
|
1046
1093
|
// src/responses/xai-responses-language-model.ts
|
|
1047
|
-
|
|
1094
|
+
import {
|
|
1095
|
+
combineHeaders as combineHeaders3,
|
|
1096
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
1097
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1098
|
+
isCustomReasoning as isCustomReasoning2,
|
|
1099
|
+
mapReasoningToProviderEffort as mapReasoningToProviderEffort2,
|
|
1100
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1101
|
+
postJsonToApi as postJsonToApi3,
|
|
1102
|
+
serializeModelOptions as serializeModelOptions3,
|
|
1103
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
1104
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
|
|
1105
|
+
} from "@ai-sdk/provider-utils";
|
|
1048
1106
|
|
|
1049
1107
|
// src/responses/convert-to-xai-responses-input.ts
|
|
1050
|
-
|
|
1051
|
-
|
|
1108
|
+
import {
|
|
1109
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1110
|
+
} from "@ai-sdk/provider";
|
|
1111
|
+
import {
|
|
1112
|
+
convertToBase64 as convertToBase642,
|
|
1113
|
+
isProviderReference as isProviderReference2,
|
|
1114
|
+
resolveProviderReference as resolveProviderReference2
|
|
1115
|
+
} from "@ai-sdk/provider-utils";
|
|
1052
1116
|
async function convertToXaiResponsesInput({
|
|
1053
1117
|
prompt
|
|
1054
1118
|
}) {
|
|
1055
|
-
var _a, _b, _c, _d, _e;
|
|
1119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1056
1120
|
const input = [];
|
|
1057
1121
|
const inputWarnings = [];
|
|
1058
1122
|
for (const message of prompt) {
|
|
@@ -1073,12 +1137,20 @@ async function convertToXaiResponsesInput({
|
|
|
1073
1137
|
break;
|
|
1074
1138
|
}
|
|
1075
1139
|
case "file": {
|
|
1076
|
-
if (block.
|
|
1140
|
+
if (isProviderReference2(block.data)) {
|
|
1141
|
+
contentParts.push({
|
|
1142
|
+
type: "input_file",
|
|
1143
|
+
file_id: resolveProviderReference2({
|
|
1144
|
+
reference: block.data,
|
|
1145
|
+
provider: "xai"
|
|
1146
|
+
})
|
|
1147
|
+
});
|
|
1148
|
+
} else if (block.mediaType.startsWith("image/")) {
|
|
1077
1149
|
const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
|
|
1078
|
-
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(
|
|
1150
|
+
const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${convertToBase642(block.data)}`;
|
|
1079
1151
|
contentParts.push({ type: "input_image", image_url: imageUrl });
|
|
1080
1152
|
} else {
|
|
1081
|
-
throw new
|
|
1153
|
+
throw new UnsupportedFunctionalityError3({
|
|
1082
1154
|
functionality: `file part media type ${block.mediaType}`
|
|
1083
1155
|
});
|
|
1084
1156
|
}
|
|
@@ -1129,7 +1201,36 @@ async function convertToXaiResponsesInput({
|
|
|
1129
1201
|
case "tool-result": {
|
|
1130
1202
|
break;
|
|
1131
1203
|
}
|
|
1132
|
-
case "reasoning":
|
|
1204
|
+
case "reasoning": {
|
|
1205
|
+
const itemId = typeof ((_f = (_e = part.providerOptions) == null ? void 0 : _e.xai) == null ? void 0 : _f.itemId) === "string" ? part.providerOptions.xai.itemId : void 0;
|
|
1206
|
+
const encryptedContent = typeof ((_h = (_g = part.providerOptions) == null ? void 0 : _g.xai) == null ? void 0 : _h.reasoningEncryptedContent) === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
|
|
1207
|
+
if (itemId != null || encryptedContent != null) {
|
|
1208
|
+
const summaryParts = [];
|
|
1209
|
+
if (part.text.length > 0) {
|
|
1210
|
+
summaryParts.push({
|
|
1211
|
+
type: "summary_text",
|
|
1212
|
+
text: part.text
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
input.push({
|
|
1216
|
+
type: "reasoning",
|
|
1217
|
+
id: itemId != null ? itemId : "",
|
|
1218
|
+
summary: summaryParts,
|
|
1219
|
+
status: "completed",
|
|
1220
|
+
...encryptedContent != null && {
|
|
1221
|
+
encrypted_content: encryptedContent
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
} else {
|
|
1225
|
+
inputWarnings.push({
|
|
1226
|
+
type: "other",
|
|
1227
|
+
message: "Reasoning parts without itemId or encrypted content cannot be sent back to xAI. Skipping."
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
case "reasoning-file":
|
|
1233
|
+
case "custom":
|
|
1133
1234
|
case "file": {
|
|
1134
1235
|
inputWarnings.push({
|
|
1135
1236
|
type: "other",
|
|
@@ -1161,7 +1262,7 @@ async function convertToXaiResponsesInput({
|
|
|
1161
1262
|
outputValue = output.value;
|
|
1162
1263
|
break;
|
|
1163
1264
|
case "execution-denied":
|
|
1164
|
-
outputValue = (
|
|
1265
|
+
outputValue = (_i = output.reason) != null ? _i : "tool execution denied";
|
|
1165
1266
|
break;
|
|
1166
1267
|
case "json":
|
|
1167
1268
|
case "error-json":
|
|
@@ -1229,6 +1330,7 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1229
1330
|
case "completed":
|
|
1230
1331
|
return "stop";
|
|
1231
1332
|
case "length":
|
|
1333
|
+
case "max_output_tokens":
|
|
1232
1334
|
return "length";
|
|
1233
1335
|
case "tool_calls":
|
|
1234
1336
|
case "function_call":
|
|
@@ -1241,568 +1343,614 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1241
1343
|
}
|
|
1242
1344
|
|
|
1243
1345
|
// src/responses/xai-responses-api.ts
|
|
1244
|
-
|
|
1245
|
-
var annotationSchema =
|
|
1246
|
-
|
|
1247
|
-
type:
|
|
1248
|
-
url:
|
|
1249
|
-
title:
|
|
1346
|
+
import { z as z6 } from "zod/v4";
|
|
1347
|
+
var annotationSchema = z6.union([
|
|
1348
|
+
z6.object({
|
|
1349
|
+
type: z6.literal("url_citation"),
|
|
1350
|
+
url: z6.string(),
|
|
1351
|
+
title: z6.string().optional()
|
|
1250
1352
|
}),
|
|
1251
|
-
|
|
1252
|
-
type:
|
|
1353
|
+
z6.object({
|
|
1354
|
+
type: z6.string()
|
|
1253
1355
|
})
|
|
1254
1356
|
]);
|
|
1255
|
-
var messageContentPartSchema =
|
|
1256
|
-
type:
|
|
1257
|
-
text:
|
|
1258
|
-
logprobs:
|
|
1259
|
-
annotations:
|
|
1357
|
+
var messageContentPartSchema = z6.object({
|
|
1358
|
+
type: z6.string(),
|
|
1359
|
+
text: z6.string().optional(),
|
|
1360
|
+
logprobs: z6.array(z6.any()).optional(),
|
|
1361
|
+
annotations: z6.array(annotationSchema).optional()
|
|
1260
1362
|
});
|
|
1261
|
-
var reasoningSummaryPartSchema =
|
|
1262
|
-
type:
|
|
1263
|
-
text:
|
|
1363
|
+
var reasoningSummaryPartSchema = z6.object({
|
|
1364
|
+
type: z6.string(),
|
|
1365
|
+
text: z6.string()
|
|
1264
1366
|
});
|
|
1265
|
-
var toolCallSchema =
|
|
1266
|
-
name:
|
|
1267
|
-
arguments:
|
|
1268
|
-
input:
|
|
1269
|
-
call_id:
|
|
1270
|
-
id:
|
|
1271
|
-
status:
|
|
1272
|
-
action:
|
|
1367
|
+
var toolCallSchema = z6.object({
|
|
1368
|
+
name: z6.string().optional(),
|
|
1369
|
+
arguments: z6.string().optional(),
|
|
1370
|
+
input: z6.string().optional(),
|
|
1371
|
+
call_id: z6.string().optional(),
|
|
1372
|
+
id: z6.string(),
|
|
1373
|
+
status: z6.string(),
|
|
1374
|
+
action: z6.any().optional()
|
|
1273
1375
|
});
|
|
1274
|
-
var mcpCallSchema =
|
|
1275
|
-
name:
|
|
1276
|
-
arguments:
|
|
1277
|
-
output:
|
|
1278
|
-
error:
|
|
1279
|
-
id:
|
|
1280
|
-
status:
|
|
1281
|
-
server_label:
|
|
1376
|
+
var mcpCallSchema = z6.object({
|
|
1377
|
+
name: z6.string().optional(),
|
|
1378
|
+
arguments: z6.string().optional(),
|
|
1379
|
+
output: z6.string().optional(),
|
|
1380
|
+
error: z6.string().optional(),
|
|
1381
|
+
id: z6.string(),
|
|
1382
|
+
status: z6.string(),
|
|
1383
|
+
server_label: z6.string().optional()
|
|
1282
1384
|
});
|
|
1283
|
-
var outputItemSchema =
|
|
1284
|
-
|
|
1285
|
-
type:
|
|
1385
|
+
var outputItemSchema = z6.discriminatedUnion("type", [
|
|
1386
|
+
z6.object({
|
|
1387
|
+
type: z6.literal("web_search_call"),
|
|
1286
1388
|
...toolCallSchema.shape
|
|
1287
1389
|
}),
|
|
1288
|
-
|
|
1289
|
-
type:
|
|
1390
|
+
z6.object({
|
|
1391
|
+
type: z6.literal("x_search_call"),
|
|
1290
1392
|
...toolCallSchema.shape
|
|
1291
1393
|
}),
|
|
1292
|
-
|
|
1293
|
-
type:
|
|
1394
|
+
z6.object({
|
|
1395
|
+
type: z6.literal("code_interpreter_call"),
|
|
1294
1396
|
...toolCallSchema.shape
|
|
1295
1397
|
}),
|
|
1296
|
-
|
|
1297
|
-
type:
|
|
1398
|
+
z6.object({
|
|
1399
|
+
type: z6.literal("code_execution_call"),
|
|
1298
1400
|
...toolCallSchema.shape
|
|
1299
1401
|
}),
|
|
1300
|
-
|
|
1301
|
-
type:
|
|
1402
|
+
z6.object({
|
|
1403
|
+
type: z6.literal("view_image_call"),
|
|
1302
1404
|
...toolCallSchema.shape
|
|
1303
1405
|
}),
|
|
1304
|
-
|
|
1305
|
-
type:
|
|
1406
|
+
z6.object({
|
|
1407
|
+
type: z6.literal("view_x_video_call"),
|
|
1306
1408
|
...toolCallSchema.shape
|
|
1307
1409
|
}),
|
|
1308
|
-
|
|
1309
|
-
type:
|
|
1310
|
-
id:
|
|
1311
|
-
status:
|
|
1312
|
-
queries:
|
|
1313
|
-
results:
|
|
1314
|
-
|
|
1315
|
-
file_id:
|
|
1316
|
-
filename:
|
|
1317
|
-
score:
|
|
1318
|
-
text:
|
|
1410
|
+
z6.object({
|
|
1411
|
+
type: z6.literal("file_search_call"),
|
|
1412
|
+
id: z6.string(),
|
|
1413
|
+
status: z6.string(),
|
|
1414
|
+
queries: z6.array(z6.string()).optional(),
|
|
1415
|
+
results: z6.array(
|
|
1416
|
+
z6.object({
|
|
1417
|
+
file_id: z6.string(),
|
|
1418
|
+
filename: z6.string(),
|
|
1419
|
+
score: z6.number(),
|
|
1420
|
+
text: z6.string()
|
|
1319
1421
|
})
|
|
1320
1422
|
).nullish()
|
|
1321
1423
|
}),
|
|
1322
|
-
|
|
1323
|
-
type:
|
|
1424
|
+
z6.object({
|
|
1425
|
+
type: z6.literal("custom_tool_call"),
|
|
1324
1426
|
...toolCallSchema.shape
|
|
1325
1427
|
}),
|
|
1326
|
-
|
|
1327
|
-
type:
|
|
1428
|
+
z6.object({
|
|
1429
|
+
type: z6.literal("mcp_call"),
|
|
1328
1430
|
...mcpCallSchema.shape
|
|
1329
1431
|
}),
|
|
1330
|
-
|
|
1331
|
-
type:
|
|
1332
|
-
role:
|
|
1333
|
-
content:
|
|
1334
|
-
id:
|
|
1335
|
-
status:
|
|
1432
|
+
z6.object({
|
|
1433
|
+
type: z6.literal("message"),
|
|
1434
|
+
role: z6.string(),
|
|
1435
|
+
content: z6.array(messageContentPartSchema),
|
|
1436
|
+
id: z6.string(),
|
|
1437
|
+
status: z6.string()
|
|
1336
1438
|
}),
|
|
1337
|
-
|
|
1338
|
-
type:
|
|
1339
|
-
name:
|
|
1340
|
-
arguments:
|
|
1341
|
-
call_id:
|
|
1342
|
-
id:
|
|
1439
|
+
z6.object({
|
|
1440
|
+
type: z6.literal("function_call"),
|
|
1441
|
+
name: z6.string(),
|
|
1442
|
+
arguments: z6.string(),
|
|
1443
|
+
call_id: z6.string(),
|
|
1444
|
+
id: z6.string()
|
|
1343
1445
|
}),
|
|
1344
|
-
|
|
1345
|
-
type:
|
|
1346
|
-
id:
|
|
1347
|
-
summary:
|
|
1348
|
-
|
|
1349
|
-
|
|
1446
|
+
z6.object({
|
|
1447
|
+
type: z6.literal("reasoning"),
|
|
1448
|
+
id: z6.string(),
|
|
1449
|
+
summary: z6.array(reasoningSummaryPartSchema),
|
|
1450
|
+
content: z6.array(z6.object({ type: z6.string(), text: z6.string() })).nullish(),
|
|
1451
|
+
status: z6.string(),
|
|
1452
|
+
encrypted_content: z6.string().nullish()
|
|
1350
1453
|
})
|
|
1351
1454
|
]);
|
|
1352
|
-
var xaiResponsesUsageSchema =
|
|
1353
|
-
input_tokens:
|
|
1354
|
-
output_tokens:
|
|
1355
|
-
total_tokens:
|
|
1356
|
-
input_tokens_details:
|
|
1357
|
-
cached_tokens:
|
|
1455
|
+
var xaiResponsesUsageSchema = z6.object({
|
|
1456
|
+
input_tokens: z6.number(),
|
|
1457
|
+
output_tokens: z6.number(),
|
|
1458
|
+
total_tokens: z6.number().optional(),
|
|
1459
|
+
input_tokens_details: z6.object({
|
|
1460
|
+
cached_tokens: z6.number().optional()
|
|
1358
1461
|
}).optional(),
|
|
1359
|
-
output_tokens_details:
|
|
1360
|
-
reasoning_tokens:
|
|
1462
|
+
output_tokens_details: z6.object({
|
|
1463
|
+
reasoning_tokens: z6.number().optional()
|
|
1361
1464
|
}).optional(),
|
|
1362
|
-
num_sources_used:
|
|
1363
|
-
num_server_side_tools_used:
|
|
1465
|
+
num_sources_used: z6.number().optional(),
|
|
1466
|
+
num_server_side_tools_used: z6.number().optional()
|
|
1364
1467
|
});
|
|
1365
|
-
var xaiResponsesResponseSchema =
|
|
1366
|
-
id:
|
|
1367
|
-
created_at:
|
|
1368
|
-
model:
|
|
1369
|
-
object:
|
|
1370
|
-
output:
|
|
1468
|
+
var xaiResponsesResponseSchema = z6.object({
|
|
1469
|
+
id: z6.string().nullish(),
|
|
1470
|
+
created_at: z6.number().nullish(),
|
|
1471
|
+
model: z6.string().nullish(),
|
|
1472
|
+
object: z6.literal("response"),
|
|
1473
|
+
output: z6.array(outputItemSchema),
|
|
1371
1474
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1372
|
-
status:
|
|
1475
|
+
status: z6.string()
|
|
1373
1476
|
});
|
|
1374
|
-
var xaiResponsesChunkSchema =
|
|
1375
|
-
|
|
1376
|
-
type:
|
|
1477
|
+
var xaiResponsesChunkSchema = z6.union([
|
|
1478
|
+
z6.object({
|
|
1479
|
+
type: z6.literal("response.created"),
|
|
1377
1480
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1378
1481
|
}),
|
|
1379
|
-
|
|
1380
|
-
type:
|
|
1482
|
+
z6.object({
|
|
1483
|
+
type: z6.literal("response.in_progress"),
|
|
1381
1484
|
response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
|
|
1382
1485
|
}),
|
|
1383
|
-
|
|
1384
|
-
type:
|
|
1486
|
+
z6.object({
|
|
1487
|
+
type: z6.literal("response.output_item.added"),
|
|
1385
1488
|
item: outputItemSchema,
|
|
1386
|
-
output_index:
|
|
1489
|
+
output_index: z6.number()
|
|
1387
1490
|
}),
|
|
1388
|
-
|
|
1389
|
-
type:
|
|
1491
|
+
z6.object({
|
|
1492
|
+
type: z6.literal("response.output_item.done"),
|
|
1390
1493
|
item: outputItemSchema,
|
|
1391
|
-
output_index:
|
|
1494
|
+
output_index: z6.number()
|
|
1392
1495
|
}),
|
|
1393
|
-
|
|
1394
|
-
type:
|
|
1395
|
-
item_id:
|
|
1396
|
-
output_index:
|
|
1397
|
-
content_index:
|
|
1496
|
+
z6.object({
|
|
1497
|
+
type: z6.literal("response.content_part.added"),
|
|
1498
|
+
item_id: z6.string(),
|
|
1499
|
+
output_index: z6.number(),
|
|
1500
|
+
content_index: z6.number(),
|
|
1398
1501
|
part: messageContentPartSchema
|
|
1399
1502
|
}),
|
|
1400
|
-
|
|
1401
|
-
type:
|
|
1402
|
-
item_id:
|
|
1403
|
-
output_index:
|
|
1404
|
-
content_index:
|
|
1503
|
+
z6.object({
|
|
1504
|
+
type: z6.literal("response.content_part.done"),
|
|
1505
|
+
item_id: z6.string(),
|
|
1506
|
+
output_index: z6.number(),
|
|
1507
|
+
content_index: z6.number(),
|
|
1405
1508
|
part: messageContentPartSchema
|
|
1406
1509
|
}),
|
|
1407
|
-
|
|
1408
|
-
type:
|
|
1409
|
-
item_id:
|
|
1410
|
-
output_index:
|
|
1411
|
-
content_index:
|
|
1412
|
-
delta:
|
|
1413
|
-
logprobs:
|
|
1510
|
+
z6.object({
|
|
1511
|
+
type: z6.literal("response.output_text.delta"),
|
|
1512
|
+
item_id: z6.string(),
|
|
1513
|
+
output_index: z6.number(),
|
|
1514
|
+
content_index: z6.number(),
|
|
1515
|
+
delta: z6.string(),
|
|
1516
|
+
logprobs: z6.array(z6.any()).optional()
|
|
1414
1517
|
}),
|
|
1415
|
-
|
|
1416
|
-
type:
|
|
1417
|
-
item_id:
|
|
1418
|
-
output_index:
|
|
1419
|
-
content_index:
|
|
1420
|
-
text:
|
|
1421
|
-
logprobs:
|
|
1422
|
-
annotations:
|
|
1518
|
+
z6.object({
|
|
1519
|
+
type: z6.literal("response.output_text.done"),
|
|
1520
|
+
item_id: z6.string(),
|
|
1521
|
+
output_index: z6.number(),
|
|
1522
|
+
content_index: z6.number(),
|
|
1523
|
+
text: z6.string(),
|
|
1524
|
+
logprobs: z6.array(z6.any()).optional(),
|
|
1525
|
+
annotations: z6.array(annotationSchema).optional()
|
|
1423
1526
|
}),
|
|
1424
|
-
|
|
1425
|
-
type:
|
|
1426
|
-
item_id:
|
|
1427
|
-
output_index:
|
|
1428
|
-
content_index:
|
|
1429
|
-
annotation_index:
|
|
1527
|
+
z6.object({
|
|
1528
|
+
type: z6.literal("response.output_text.annotation.added"),
|
|
1529
|
+
item_id: z6.string(),
|
|
1530
|
+
output_index: z6.number(),
|
|
1531
|
+
content_index: z6.number(),
|
|
1532
|
+
annotation_index: z6.number(),
|
|
1430
1533
|
annotation: annotationSchema
|
|
1431
1534
|
}),
|
|
1432
|
-
|
|
1433
|
-
type:
|
|
1434
|
-
item_id:
|
|
1435
|
-
output_index:
|
|
1436
|
-
summary_index:
|
|
1535
|
+
z6.object({
|
|
1536
|
+
type: z6.literal("response.reasoning_summary_part.added"),
|
|
1537
|
+
item_id: z6.string(),
|
|
1538
|
+
output_index: z6.number(),
|
|
1539
|
+
summary_index: z6.number(),
|
|
1437
1540
|
part: reasoningSummaryPartSchema
|
|
1438
1541
|
}),
|
|
1439
|
-
|
|
1440
|
-
type:
|
|
1441
|
-
item_id:
|
|
1442
|
-
output_index:
|
|
1443
|
-
summary_index:
|
|
1542
|
+
z6.object({
|
|
1543
|
+
type: z6.literal("response.reasoning_summary_part.done"),
|
|
1544
|
+
item_id: z6.string(),
|
|
1545
|
+
output_index: z6.number(),
|
|
1546
|
+
summary_index: z6.number(),
|
|
1444
1547
|
part: reasoningSummaryPartSchema
|
|
1445
1548
|
}),
|
|
1446
|
-
|
|
1447
|
-
type:
|
|
1448
|
-
item_id:
|
|
1449
|
-
output_index:
|
|
1450
|
-
summary_index:
|
|
1451
|
-
delta:
|
|
1549
|
+
z6.object({
|
|
1550
|
+
type: z6.literal("response.reasoning_summary_text.delta"),
|
|
1551
|
+
item_id: z6.string(),
|
|
1552
|
+
output_index: z6.number(),
|
|
1553
|
+
summary_index: z6.number(),
|
|
1554
|
+
delta: z6.string()
|
|
1452
1555
|
}),
|
|
1453
|
-
|
|
1454
|
-
type:
|
|
1455
|
-
item_id:
|
|
1456
|
-
output_index:
|
|
1457
|
-
summary_index:
|
|
1458
|
-
text:
|
|
1556
|
+
z6.object({
|
|
1557
|
+
type: z6.literal("response.reasoning_summary_text.done"),
|
|
1558
|
+
item_id: z6.string(),
|
|
1559
|
+
output_index: z6.number(),
|
|
1560
|
+
summary_index: z6.number(),
|
|
1561
|
+
text: z6.string()
|
|
1459
1562
|
}),
|
|
1460
|
-
|
|
1461
|
-
type:
|
|
1462
|
-
item_id:
|
|
1463
|
-
output_index:
|
|
1464
|
-
content_index:
|
|
1465
|
-
delta:
|
|
1563
|
+
z6.object({
|
|
1564
|
+
type: z6.literal("response.reasoning_text.delta"),
|
|
1565
|
+
item_id: z6.string(),
|
|
1566
|
+
output_index: z6.number(),
|
|
1567
|
+
content_index: z6.number(),
|
|
1568
|
+
delta: z6.string()
|
|
1466
1569
|
}),
|
|
1467
|
-
|
|
1468
|
-
type:
|
|
1469
|
-
item_id:
|
|
1470
|
-
output_index:
|
|
1471
|
-
content_index:
|
|
1472
|
-
text:
|
|
1570
|
+
z6.object({
|
|
1571
|
+
type: z6.literal("response.reasoning_text.done"),
|
|
1572
|
+
item_id: z6.string(),
|
|
1573
|
+
output_index: z6.number(),
|
|
1574
|
+
content_index: z6.number(),
|
|
1575
|
+
text: z6.string()
|
|
1473
1576
|
}),
|
|
1474
|
-
|
|
1475
|
-
type:
|
|
1476
|
-
item_id:
|
|
1477
|
-
output_index:
|
|
1577
|
+
z6.object({
|
|
1578
|
+
type: z6.literal("response.web_search_call.in_progress"),
|
|
1579
|
+
item_id: z6.string(),
|
|
1580
|
+
output_index: z6.number()
|
|
1478
1581
|
}),
|
|
1479
|
-
|
|
1480
|
-
type:
|
|
1481
|
-
item_id:
|
|
1482
|
-
output_index:
|
|
1582
|
+
z6.object({
|
|
1583
|
+
type: z6.literal("response.web_search_call.searching"),
|
|
1584
|
+
item_id: z6.string(),
|
|
1585
|
+
output_index: z6.number()
|
|
1483
1586
|
}),
|
|
1484
|
-
|
|
1485
|
-
type:
|
|
1486
|
-
item_id:
|
|
1487
|
-
output_index:
|
|
1587
|
+
z6.object({
|
|
1588
|
+
type: z6.literal("response.web_search_call.completed"),
|
|
1589
|
+
item_id: z6.string(),
|
|
1590
|
+
output_index: z6.number()
|
|
1488
1591
|
}),
|
|
1489
|
-
|
|
1490
|
-
type:
|
|
1491
|
-
item_id:
|
|
1492
|
-
output_index:
|
|
1592
|
+
z6.object({
|
|
1593
|
+
type: z6.literal("response.x_search_call.in_progress"),
|
|
1594
|
+
item_id: z6.string(),
|
|
1595
|
+
output_index: z6.number()
|
|
1493
1596
|
}),
|
|
1494
|
-
|
|
1495
|
-
type:
|
|
1496
|
-
item_id:
|
|
1497
|
-
output_index:
|
|
1597
|
+
z6.object({
|
|
1598
|
+
type: z6.literal("response.x_search_call.searching"),
|
|
1599
|
+
item_id: z6.string(),
|
|
1600
|
+
output_index: z6.number()
|
|
1498
1601
|
}),
|
|
1499
|
-
|
|
1500
|
-
type:
|
|
1501
|
-
item_id:
|
|
1502
|
-
output_index:
|
|
1602
|
+
z6.object({
|
|
1603
|
+
type: z6.literal("response.x_search_call.completed"),
|
|
1604
|
+
item_id: z6.string(),
|
|
1605
|
+
output_index: z6.number()
|
|
1503
1606
|
}),
|
|
1504
|
-
|
|
1505
|
-
type:
|
|
1506
|
-
item_id:
|
|
1507
|
-
output_index:
|
|
1607
|
+
z6.object({
|
|
1608
|
+
type: z6.literal("response.file_search_call.in_progress"),
|
|
1609
|
+
item_id: z6.string(),
|
|
1610
|
+
output_index: z6.number()
|
|
1508
1611
|
}),
|
|
1509
|
-
|
|
1510
|
-
type:
|
|
1511
|
-
item_id:
|
|
1512
|
-
output_index:
|
|
1612
|
+
z6.object({
|
|
1613
|
+
type: z6.literal("response.file_search_call.searching"),
|
|
1614
|
+
item_id: z6.string(),
|
|
1615
|
+
output_index: z6.number()
|
|
1513
1616
|
}),
|
|
1514
|
-
|
|
1515
|
-
type:
|
|
1516
|
-
item_id:
|
|
1517
|
-
output_index:
|
|
1617
|
+
z6.object({
|
|
1618
|
+
type: z6.literal("response.file_search_call.completed"),
|
|
1619
|
+
item_id: z6.string(),
|
|
1620
|
+
output_index: z6.number()
|
|
1518
1621
|
}),
|
|
1519
|
-
|
|
1520
|
-
type:
|
|
1521
|
-
item_id:
|
|
1522
|
-
output_index:
|
|
1622
|
+
z6.object({
|
|
1623
|
+
type: z6.literal("response.code_execution_call.in_progress"),
|
|
1624
|
+
item_id: z6.string(),
|
|
1625
|
+
output_index: z6.number()
|
|
1523
1626
|
}),
|
|
1524
|
-
|
|
1525
|
-
type:
|
|
1526
|
-
item_id:
|
|
1527
|
-
output_index:
|
|
1627
|
+
z6.object({
|
|
1628
|
+
type: z6.literal("response.code_execution_call.executing"),
|
|
1629
|
+
item_id: z6.string(),
|
|
1630
|
+
output_index: z6.number()
|
|
1528
1631
|
}),
|
|
1529
|
-
|
|
1530
|
-
type:
|
|
1531
|
-
item_id:
|
|
1532
|
-
output_index:
|
|
1632
|
+
z6.object({
|
|
1633
|
+
type: z6.literal("response.code_execution_call.completed"),
|
|
1634
|
+
item_id: z6.string(),
|
|
1635
|
+
output_index: z6.number()
|
|
1533
1636
|
}),
|
|
1534
|
-
|
|
1535
|
-
type:
|
|
1536
|
-
item_id:
|
|
1537
|
-
output_index:
|
|
1637
|
+
z6.object({
|
|
1638
|
+
type: z6.literal("response.code_interpreter_call.in_progress"),
|
|
1639
|
+
item_id: z6.string(),
|
|
1640
|
+
output_index: z6.number()
|
|
1538
1641
|
}),
|
|
1539
|
-
|
|
1540
|
-
type:
|
|
1541
|
-
item_id:
|
|
1542
|
-
output_index:
|
|
1642
|
+
z6.object({
|
|
1643
|
+
type: z6.literal("response.code_interpreter_call.executing"),
|
|
1644
|
+
item_id: z6.string(),
|
|
1645
|
+
output_index: z6.number()
|
|
1543
1646
|
}),
|
|
1544
|
-
|
|
1545
|
-
type:
|
|
1546
|
-
item_id:
|
|
1547
|
-
output_index:
|
|
1647
|
+
z6.object({
|
|
1648
|
+
type: z6.literal("response.code_interpreter_call.interpreting"),
|
|
1649
|
+
item_id: z6.string(),
|
|
1650
|
+
output_index: z6.number()
|
|
1548
1651
|
}),
|
|
1549
|
-
|
|
1550
|
-
type:
|
|
1551
|
-
item_id:
|
|
1552
|
-
output_index:
|
|
1652
|
+
z6.object({
|
|
1653
|
+
type: z6.literal("response.code_interpreter_call.completed"),
|
|
1654
|
+
item_id: z6.string(),
|
|
1655
|
+
output_index: z6.number()
|
|
1553
1656
|
}),
|
|
1554
1657
|
// Code interpreter code streaming events
|
|
1555
|
-
|
|
1556
|
-
type:
|
|
1557
|
-
item_id:
|
|
1558
|
-
output_index:
|
|
1559
|
-
delta:
|
|
1658
|
+
z6.object({
|
|
1659
|
+
type: z6.literal("response.code_interpreter_call_code.delta"),
|
|
1660
|
+
item_id: z6.string(),
|
|
1661
|
+
output_index: z6.number(),
|
|
1662
|
+
delta: z6.string()
|
|
1560
1663
|
}),
|
|
1561
|
-
|
|
1562
|
-
type:
|
|
1563
|
-
item_id:
|
|
1564
|
-
output_index:
|
|
1565
|
-
code:
|
|
1664
|
+
z6.object({
|
|
1665
|
+
type: z6.literal("response.code_interpreter_call_code.done"),
|
|
1666
|
+
item_id: z6.string(),
|
|
1667
|
+
output_index: z6.number(),
|
|
1668
|
+
code: z6.string()
|
|
1566
1669
|
}),
|
|
1567
|
-
|
|
1568
|
-
type:
|
|
1569
|
-
item_id:
|
|
1570
|
-
output_index:
|
|
1571
|
-
delta:
|
|
1670
|
+
z6.object({
|
|
1671
|
+
type: z6.literal("response.custom_tool_call_input.delta"),
|
|
1672
|
+
item_id: z6.string(),
|
|
1673
|
+
output_index: z6.number(),
|
|
1674
|
+
delta: z6.string()
|
|
1572
1675
|
}),
|
|
1573
|
-
|
|
1574
|
-
type:
|
|
1575
|
-
item_id:
|
|
1576
|
-
output_index:
|
|
1577
|
-
input:
|
|
1676
|
+
z6.object({
|
|
1677
|
+
type: z6.literal("response.custom_tool_call_input.done"),
|
|
1678
|
+
item_id: z6.string(),
|
|
1679
|
+
output_index: z6.number(),
|
|
1680
|
+
input: z6.string()
|
|
1578
1681
|
}),
|
|
1579
1682
|
// Function call arguments streaming events (standard function tools)
|
|
1580
|
-
|
|
1581
|
-
type:
|
|
1582
|
-
item_id:
|
|
1583
|
-
output_index:
|
|
1584
|
-
delta:
|
|
1683
|
+
z6.object({
|
|
1684
|
+
type: z6.literal("response.function_call_arguments.delta"),
|
|
1685
|
+
item_id: z6.string(),
|
|
1686
|
+
output_index: z6.number(),
|
|
1687
|
+
delta: z6.string()
|
|
1688
|
+
}),
|
|
1689
|
+
z6.object({
|
|
1690
|
+
type: z6.literal("response.function_call_arguments.done"),
|
|
1691
|
+
item_id: z6.string(),
|
|
1692
|
+
output_index: z6.number(),
|
|
1693
|
+
arguments: z6.string()
|
|
1585
1694
|
}),
|
|
1586
|
-
|
|
1587
|
-
type:
|
|
1588
|
-
item_id:
|
|
1589
|
-
output_index:
|
|
1590
|
-
arguments: import_v46.z.string()
|
|
1695
|
+
z6.object({
|
|
1696
|
+
type: z6.literal("response.mcp_call.in_progress"),
|
|
1697
|
+
item_id: z6.string(),
|
|
1698
|
+
output_index: z6.number()
|
|
1591
1699
|
}),
|
|
1592
|
-
|
|
1593
|
-
type:
|
|
1594
|
-
item_id:
|
|
1595
|
-
output_index:
|
|
1700
|
+
z6.object({
|
|
1701
|
+
type: z6.literal("response.mcp_call.executing"),
|
|
1702
|
+
item_id: z6.string(),
|
|
1703
|
+
output_index: z6.number()
|
|
1596
1704
|
}),
|
|
1597
|
-
|
|
1598
|
-
type:
|
|
1599
|
-
item_id:
|
|
1600
|
-
output_index:
|
|
1705
|
+
z6.object({
|
|
1706
|
+
type: z6.literal("response.mcp_call.completed"),
|
|
1707
|
+
item_id: z6.string(),
|
|
1708
|
+
output_index: z6.number()
|
|
1601
1709
|
}),
|
|
1602
|
-
|
|
1603
|
-
type:
|
|
1604
|
-
item_id:
|
|
1605
|
-
output_index:
|
|
1710
|
+
z6.object({
|
|
1711
|
+
type: z6.literal("response.mcp_call.failed"),
|
|
1712
|
+
item_id: z6.string(),
|
|
1713
|
+
output_index: z6.number()
|
|
1606
1714
|
}),
|
|
1607
|
-
|
|
1608
|
-
type:
|
|
1609
|
-
item_id:
|
|
1610
|
-
output_index:
|
|
1715
|
+
z6.object({
|
|
1716
|
+
type: z6.literal("response.mcp_call_arguments.delta"),
|
|
1717
|
+
item_id: z6.string(),
|
|
1718
|
+
output_index: z6.number(),
|
|
1719
|
+
delta: z6.string()
|
|
1611
1720
|
}),
|
|
1612
|
-
|
|
1613
|
-
type:
|
|
1614
|
-
item_id:
|
|
1615
|
-
output_index:
|
|
1616
|
-
|
|
1721
|
+
z6.object({
|
|
1722
|
+
type: z6.literal("response.mcp_call_arguments.done"),
|
|
1723
|
+
item_id: z6.string(),
|
|
1724
|
+
output_index: z6.number(),
|
|
1725
|
+
arguments: z6.string().optional()
|
|
1617
1726
|
}),
|
|
1618
|
-
|
|
1619
|
-
type:
|
|
1620
|
-
item_id:
|
|
1621
|
-
output_index:
|
|
1622
|
-
|
|
1727
|
+
z6.object({
|
|
1728
|
+
type: z6.literal("response.mcp_call_output.delta"),
|
|
1729
|
+
item_id: z6.string(),
|
|
1730
|
+
output_index: z6.number(),
|
|
1731
|
+
delta: z6.string()
|
|
1623
1732
|
}),
|
|
1624
|
-
|
|
1625
|
-
type:
|
|
1626
|
-
item_id:
|
|
1627
|
-
output_index:
|
|
1628
|
-
|
|
1733
|
+
z6.object({
|
|
1734
|
+
type: z6.literal("response.mcp_call_output.done"),
|
|
1735
|
+
item_id: z6.string(),
|
|
1736
|
+
output_index: z6.number(),
|
|
1737
|
+
output: z6.string().optional()
|
|
1629
1738
|
}),
|
|
1630
|
-
|
|
1631
|
-
type:
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1739
|
+
z6.object({
|
|
1740
|
+
type: z6.literal("response.incomplete"),
|
|
1741
|
+
response: z6.object({
|
|
1742
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1743
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1744
|
+
})
|
|
1635
1745
|
}),
|
|
1636
|
-
|
|
1637
|
-
type:
|
|
1746
|
+
z6.object({
|
|
1747
|
+
type: z6.literal("response.failed"),
|
|
1748
|
+
response: z6.object({
|
|
1749
|
+
error: z6.object({
|
|
1750
|
+
code: z6.string().nullish(),
|
|
1751
|
+
message: z6.string()
|
|
1752
|
+
}).nullish(),
|
|
1753
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1754
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1755
|
+
})
|
|
1756
|
+
}),
|
|
1757
|
+
z6.object({
|
|
1758
|
+
type: z6.literal("error"),
|
|
1759
|
+
code: z6.string().nullish(),
|
|
1760
|
+
message: z6.string(),
|
|
1761
|
+
param: z6.string().nullish()
|
|
1762
|
+
}),
|
|
1763
|
+
z6.object({
|
|
1764
|
+
type: z6.literal("response.done"),
|
|
1638
1765
|
response: xaiResponsesResponseSchema
|
|
1639
1766
|
}),
|
|
1640
|
-
|
|
1641
|
-
type:
|
|
1767
|
+
z6.object({
|
|
1768
|
+
type: z6.literal("response.completed"),
|
|
1642
1769
|
response: xaiResponsesResponseSchema
|
|
1643
1770
|
})
|
|
1644
1771
|
]);
|
|
1645
1772
|
|
|
1646
1773
|
// src/responses/xai-responses-options.ts
|
|
1647
|
-
|
|
1648
|
-
var xaiLanguageModelResponsesOptions =
|
|
1774
|
+
import { z as z7 } from "zod/v4";
|
|
1775
|
+
var xaiLanguageModelResponsesOptions = z7.object({
|
|
1649
1776
|
/**
|
|
1650
1777
|
* Constrains how hard a reasoning model thinks before responding.
|
|
1651
1778
|
* Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
|
|
1652
1779
|
*/
|
|
1653
|
-
reasoningEffort:
|
|
1654
|
-
|
|
1655
|
-
|
|
1780
|
+
reasoningEffort: z7.enum(["low", "medium", "high"]).optional(),
|
|
1781
|
+
reasoningSummary: z7.enum(["auto", "concise", "detailed"]).optional(),
|
|
1782
|
+
logprobs: z7.boolean().optional(),
|
|
1783
|
+
topLogprobs: z7.number().int().min(0).max(8).optional(),
|
|
1656
1784
|
/**
|
|
1657
1785
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
1786
|
+
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
1787
|
+
* otherwise the API will return an error.
|
|
1658
1788
|
* @default true
|
|
1659
1789
|
*/
|
|
1660
|
-
store:
|
|
1790
|
+
store: z7.boolean().optional(),
|
|
1661
1791
|
/**
|
|
1662
1792
|
* The ID of the previous response from the model.
|
|
1663
1793
|
*/
|
|
1664
|
-
previousResponseId:
|
|
1794
|
+
previousResponseId: z7.string().optional(),
|
|
1665
1795
|
/**
|
|
1666
1796
|
* Specify additional output data to include in the model response.
|
|
1667
1797
|
* Example values: 'file_search_call.results'.
|
|
1668
1798
|
*/
|
|
1669
|
-
include:
|
|
1799
|
+
include: z7.array(z7.enum(["file_search_call.results"])).nullish()
|
|
1670
1800
|
});
|
|
1671
1801
|
|
|
1672
1802
|
// src/responses/xai-responses-prepare-tools.ts
|
|
1673
|
-
|
|
1674
|
-
|
|
1803
|
+
import {
|
|
1804
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1805
|
+
} from "@ai-sdk/provider";
|
|
1806
|
+
import { validateTypes } from "@ai-sdk/provider-utils";
|
|
1675
1807
|
|
|
1676
1808
|
// src/tool/file-search.ts
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1809
|
+
import {
|
|
1810
|
+
createProviderToolFactoryWithOutputSchema,
|
|
1811
|
+
lazySchema,
|
|
1812
|
+
zodSchema
|
|
1813
|
+
} from "@ai-sdk/provider-utils";
|
|
1814
|
+
import { z as z8 } from "zod/v4";
|
|
1815
|
+
var fileSearchArgsSchema = lazySchema(
|
|
1816
|
+
() => zodSchema(
|
|
1817
|
+
z8.object({
|
|
1818
|
+
vectorStoreIds: z8.array(z8.string()),
|
|
1819
|
+
maxNumResults: z8.number().optional()
|
|
1684
1820
|
})
|
|
1685
1821
|
)
|
|
1686
1822
|
);
|
|
1687
|
-
var fileSearchOutputSchema =
|
|
1688
|
-
() =>
|
|
1689
|
-
|
|
1690
|
-
queries:
|
|
1691
|
-
results:
|
|
1692
|
-
|
|
1693
|
-
fileId:
|
|
1694
|
-
filename:
|
|
1695
|
-
score:
|
|
1696
|
-
text:
|
|
1823
|
+
var fileSearchOutputSchema = lazySchema(
|
|
1824
|
+
() => zodSchema(
|
|
1825
|
+
z8.object({
|
|
1826
|
+
queries: z8.array(z8.string()),
|
|
1827
|
+
results: z8.array(
|
|
1828
|
+
z8.object({
|
|
1829
|
+
fileId: z8.string(),
|
|
1830
|
+
filename: z8.string(),
|
|
1831
|
+
score: z8.number().min(0).max(1),
|
|
1832
|
+
text: z8.string()
|
|
1697
1833
|
})
|
|
1698
1834
|
).nullable()
|
|
1699
1835
|
})
|
|
1700
1836
|
)
|
|
1701
1837
|
);
|
|
1702
|
-
var fileSearchToolFactory =
|
|
1838
|
+
var fileSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1703
1839
|
id: "xai.file_search",
|
|
1704
|
-
inputSchema:
|
|
1840
|
+
inputSchema: lazySchema(() => zodSchema(z8.object({}))),
|
|
1705
1841
|
outputSchema: fileSearchOutputSchema
|
|
1706
1842
|
});
|
|
1707
1843
|
var fileSearch = (args) => fileSearchToolFactory(args);
|
|
1708
1844
|
|
|
1709
1845
|
// src/tool/mcp-server.ts
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1846
|
+
import {
|
|
1847
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema2,
|
|
1848
|
+
lazySchema as lazySchema2,
|
|
1849
|
+
zodSchema as zodSchema2
|
|
1850
|
+
} from "@ai-sdk/provider-utils";
|
|
1851
|
+
import { z as z9 } from "zod/v4";
|
|
1852
|
+
var mcpServerArgsSchema = lazySchema2(
|
|
1853
|
+
() => zodSchema2(
|
|
1854
|
+
z9.object({
|
|
1855
|
+
serverUrl: z9.string().describe("The URL of the MCP server"),
|
|
1856
|
+
serverLabel: z9.string().optional().describe("A label for the MCP server"),
|
|
1857
|
+
serverDescription: z9.string().optional().describe("Description of the MCP server"),
|
|
1858
|
+
allowedTools: z9.array(z9.string()).optional().describe("List of allowed tool names"),
|
|
1859
|
+
headers: z9.record(z9.string(), z9.string()).optional().describe("Custom headers to send"),
|
|
1860
|
+
authorization: z9.string().optional().describe("Authorization header value")
|
|
1721
1861
|
})
|
|
1722
1862
|
)
|
|
1723
1863
|
);
|
|
1724
|
-
var mcpServerOutputSchema = (
|
|
1725
|
-
() => (
|
|
1726
|
-
|
|
1727
|
-
name:
|
|
1728
|
-
arguments:
|
|
1729
|
-
result:
|
|
1864
|
+
var mcpServerOutputSchema = lazySchema2(
|
|
1865
|
+
() => zodSchema2(
|
|
1866
|
+
z9.object({
|
|
1867
|
+
name: z9.string(),
|
|
1868
|
+
arguments: z9.string(),
|
|
1869
|
+
result: z9.unknown()
|
|
1730
1870
|
})
|
|
1731
1871
|
)
|
|
1732
1872
|
);
|
|
1733
|
-
var mcpServerToolFactory = (
|
|
1873
|
+
var mcpServerToolFactory = createProviderToolFactoryWithOutputSchema2({
|
|
1734
1874
|
id: "xai.mcp",
|
|
1735
|
-
inputSchema: (
|
|
1875
|
+
inputSchema: lazySchema2(() => zodSchema2(z9.object({}))),
|
|
1736
1876
|
outputSchema: mcpServerOutputSchema
|
|
1737
1877
|
});
|
|
1738
1878
|
var mcpServer = (args) => mcpServerToolFactory(args);
|
|
1739
1879
|
|
|
1740
1880
|
// src/tool/web-search.ts
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1881
|
+
import {
|
|
1882
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema3,
|
|
1883
|
+
lazySchema as lazySchema3,
|
|
1884
|
+
zodSchema as zodSchema3
|
|
1885
|
+
} from "@ai-sdk/provider-utils";
|
|
1886
|
+
import { z as z10 } from "zod/v4";
|
|
1887
|
+
var webSearchArgsSchema = lazySchema3(
|
|
1888
|
+
() => zodSchema3(
|
|
1889
|
+
z10.object({
|
|
1890
|
+
allowedDomains: z10.array(z10.string()).max(5).optional(),
|
|
1891
|
+
excludedDomains: z10.array(z10.string()).max(5).optional(),
|
|
1892
|
+
enableImageUnderstanding: z10.boolean().optional()
|
|
1749
1893
|
})
|
|
1750
1894
|
)
|
|
1751
1895
|
);
|
|
1752
|
-
var webSearchOutputSchema = (
|
|
1753
|
-
() => (
|
|
1754
|
-
|
|
1755
|
-
query:
|
|
1756
|
-
sources:
|
|
1757
|
-
|
|
1758
|
-
title:
|
|
1759
|
-
url:
|
|
1760
|
-
snippet:
|
|
1896
|
+
var webSearchOutputSchema = lazySchema3(
|
|
1897
|
+
() => zodSchema3(
|
|
1898
|
+
z10.object({
|
|
1899
|
+
query: z10.string(),
|
|
1900
|
+
sources: z10.array(
|
|
1901
|
+
z10.object({
|
|
1902
|
+
title: z10.string(),
|
|
1903
|
+
url: z10.string(),
|
|
1904
|
+
snippet: z10.string()
|
|
1761
1905
|
})
|
|
1762
1906
|
)
|
|
1763
1907
|
})
|
|
1764
1908
|
)
|
|
1765
1909
|
);
|
|
1766
|
-
var webSearchToolFactory = (
|
|
1910
|
+
var webSearchToolFactory = createProviderToolFactoryWithOutputSchema3({
|
|
1767
1911
|
id: "xai.web_search",
|
|
1768
|
-
inputSchema: (
|
|
1912
|
+
inputSchema: lazySchema3(() => zodSchema3(z10.object({}))),
|
|
1769
1913
|
outputSchema: webSearchOutputSchema
|
|
1770
1914
|
});
|
|
1771
1915
|
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
1772
1916
|
|
|
1773
1917
|
// src/tool/x-search.ts
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1918
|
+
import {
|
|
1919
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema4,
|
|
1920
|
+
lazySchema as lazySchema4,
|
|
1921
|
+
zodSchema as zodSchema4
|
|
1922
|
+
} from "@ai-sdk/provider-utils";
|
|
1923
|
+
import { z as z11 } from "zod/v4";
|
|
1924
|
+
var xSearchArgsSchema = lazySchema4(
|
|
1925
|
+
() => zodSchema4(
|
|
1926
|
+
z11.object({
|
|
1927
|
+
allowedXHandles: z11.array(z11.string()).max(10).optional(),
|
|
1928
|
+
excludedXHandles: z11.array(z11.string()).max(10).optional(),
|
|
1929
|
+
fromDate: z11.string().optional(),
|
|
1930
|
+
toDate: z11.string().optional(),
|
|
1931
|
+
enableImageUnderstanding: z11.boolean().optional(),
|
|
1932
|
+
enableVideoUnderstanding: z11.boolean().optional()
|
|
1785
1933
|
})
|
|
1786
1934
|
)
|
|
1787
1935
|
);
|
|
1788
|
-
var xSearchOutputSchema = (
|
|
1789
|
-
() => (
|
|
1790
|
-
|
|
1791
|
-
query:
|
|
1792
|
-
posts:
|
|
1793
|
-
|
|
1794
|
-
author:
|
|
1795
|
-
text:
|
|
1796
|
-
url:
|
|
1797
|
-
likes:
|
|
1936
|
+
var xSearchOutputSchema = lazySchema4(
|
|
1937
|
+
() => zodSchema4(
|
|
1938
|
+
z11.object({
|
|
1939
|
+
query: z11.string(),
|
|
1940
|
+
posts: z11.array(
|
|
1941
|
+
z11.object({
|
|
1942
|
+
author: z11.string(),
|
|
1943
|
+
text: z11.string(),
|
|
1944
|
+
url: z11.string(),
|
|
1945
|
+
likes: z11.number()
|
|
1798
1946
|
})
|
|
1799
1947
|
)
|
|
1800
1948
|
})
|
|
1801
1949
|
)
|
|
1802
1950
|
);
|
|
1803
|
-
var xSearchToolFactory = (
|
|
1951
|
+
var xSearchToolFactory = createProviderToolFactoryWithOutputSchema4({
|
|
1804
1952
|
id: "xai.x_search",
|
|
1805
|
-
inputSchema: (
|
|
1953
|
+
inputSchema: lazySchema4(() => zodSchema4(z11.object({}))),
|
|
1806
1954
|
outputSchema: xSearchOutputSchema
|
|
1807
1955
|
});
|
|
1808
1956
|
var xSearch = (args = {}) => xSearchToolFactory(args);
|
|
@@ -1824,7 +1972,7 @@ async function prepareResponsesTools({
|
|
|
1824
1972
|
if (tool.type === "provider") {
|
|
1825
1973
|
switch (tool.id) {
|
|
1826
1974
|
case "xai.web_search": {
|
|
1827
|
-
const args = await
|
|
1975
|
+
const args = await validateTypes({
|
|
1828
1976
|
value: tool.args,
|
|
1829
1977
|
schema: webSearchArgsSchema
|
|
1830
1978
|
});
|
|
@@ -1837,7 +1985,7 @@ async function prepareResponsesTools({
|
|
|
1837
1985
|
break;
|
|
1838
1986
|
}
|
|
1839
1987
|
case "xai.x_search": {
|
|
1840
|
-
const args = await
|
|
1988
|
+
const args = await validateTypes({
|
|
1841
1989
|
value: tool.args,
|
|
1842
1990
|
schema: xSearchArgsSchema
|
|
1843
1991
|
});
|
|
@@ -1871,7 +2019,7 @@ async function prepareResponsesTools({
|
|
|
1871
2019
|
break;
|
|
1872
2020
|
}
|
|
1873
2021
|
case "xai.file_search": {
|
|
1874
|
-
const args = await
|
|
2022
|
+
const args = await validateTypes({
|
|
1875
2023
|
value: tool.args,
|
|
1876
2024
|
schema: fileSearchArgsSchema
|
|
1877
2025
|
});
|
|
@@ -1883,7 +2031,7 @@ async function prepareResponsesTools({
|
|
|
1883
2031
|
break;
|
|
1884
2032
|
}
|
|
1885
2033
|
case "xai.mcp": {
|
|
1886
|
-
const args = await
|
|
2034
|
+
const args = await validateTypes({
|
|
1887
2035
|
value: tool.args,
|
|
1888
2036
|
schema: mcpServerArgsSchema
|
|
1889
2037
|
});
|
|
@@ -1950,7 +2098,7 @@ async function prepareResponsesTools({
|
|
|
1950
2098
|
}
|
|
1951
2099
|
default: {
|
|
1952
2100
|
const _exhaustiveCheck = type;
|
|
1953
|
-
throw new
|
|
2101
|
+
throw new UnsupportedFunctionalityError4({
|
|
1954
2102
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1955
2103
|
});
|
|
1956
2104
|
}
|
|
@@ -1958,15 +2106,24 @@ async function prepareResponsesTools({
|
|
|
1958
2106
|
}
|
|
1959
2107
|
|
|
1960
2108
|
// src/responses/xai-responses-language-model.ts
|
|
1961
|
-
var XaiResponsesLanguageModel = class {
|
|
2109
|
+
var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
1962
2110
|
constructor(modelId, config) {
|
|
1963
|
-
this.specificationVersion = "
|
|
2111
|
+
this.specificationVersion = "v4";
|
|
1964
2112
|
this.supportedUrls = {
|
|
1965
2113
|
"image/*": [/^https?:\/\/.*$/]
|
|
1966
2114
|
};
|
|
1967
2115
|
this.modelId = modelId;
|
|
1968
2116
|
this.config = config;
|
|
1969
2117
|
}
|
|
2118
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
2119
|
+
return serializeModelOptions3({
|
|
2120
|
+
modelId: model.modelId,
|
|
2121
|
+
config: model.config
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
2125
|
+
return new _XaiResponsesLanguageModel(options.modelId, options.config);
|
|
2126
|
+
}
|
|
1970
2127
|
get provider() {
|
|
1971
2128
|
return this.config.provider;
|
|
1972
2129
|
}
|
|
@@ -1980,11 +2137,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
1980
2137
|
responseFormat,
|
|
1981
2138
|
providerOptions,
|
|
1982
2139
|
tools,
|
|
1983
|
-
toolChoice
|
|
2140
|
+
toolChoice,
|
|
2141
|
+
reasoning
|
|
1984
2142
|
}) {
|
|
1985
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2143
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1986
2144
|
const warnings = [];
|
|
1987
|
-
const options = (_a = await (
|
|
2145
|
+
const options = (_a = await parseProviderOptions3({
|
|
1988
2146
|
provider: "xai",
|
|
1989
2147
|
providerOptions,
|
|
1990
2148
|
schema: xaiLanguageModelResponsesOptions
|
|
@@ -2009,7 +2167,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2009
2167
|
)) == null ? void 0 : _f.name;
|
|
2010
2168
|
const { input, inputWarnings } = await convertToXaiResponsesInput({
|
|
2011
2169
|
prompt,
|
|
2012
|
-
store: true
|
|
2170
|
+
store: (_g = options.store) != null ? _g : true
|
|
2013
2171
|
});
|
|
2014
2172
|
warnings.push(...inputWarnings);
|
|
2015
2173
|
const {
|
|
@@ -2029,6 +2187,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2029
2187
|
include = [...include, "reasoning.encrypted_content"];
|
|
2030
2188
|
}
|
|
2031
2189
|
}
|
|
2190
|
+
const resolvedReasoningEffort = (_h = options.reasoningEffort) != null ? _h : isCustomReasoning2(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort2({
|
|
2191
|
+
reasoning,
|
|
2192
|
+
effortMap: {
|
|
2193
|
+
minimal: "low",
|
|
2194
|
+
low: "low",
|
|
2195
|
+
medium: "medium",
|
|
2196
|
+
high: "high",
|
|
2197
|
+
xhigh: "high"
|
|
2198
|
+
},
|
|
2199
|
+
warnings
|
|
2200
|
+
}) : void 0;
|
|
2032
2201
|
const baseArgs = {
|
|
2033
2202
|
model: this.modelId,
|
|
2034
2203
|
input,
|
|
@@ -2043,14 +2212,21 @@ var XaiResponsesLanguageModel = class {
|
|
|
2043
2212
|
format: responseFormat.schema != null ? {
|
|
2044
2213
|
type: "json_schema",
|
|
2045
2214
|
strict: true,
|
|
2046
|
-
name: (
|
|
2215
|
+
name: (_i = responseFormat.name) != null ? _i : "response",
|
|
2047
2216
|
description: responseFormat.description,
|
|
2048
2217
|
schema: responseFormat.schema
|
|
2049
2218
|
} : { type: "json_object" }
|
|
2050
2219
|
}
|
|
2051
2220
|
},
|
|
2052
|
-
...options.
|
|
2053
|
-
reasoning: {
|
|
2221
|
+
...(resolvedReasoningEffort != null || options.reasoningSummary != null) && {
|
|
2222
|
+
reasoning: {
|
|
2223
|
+
...resolvedReasoningEffort != null && {
|
|
2224
|
+
effort: resolvedReasoningEffort
|
|
2225
|
+
},
|
|
2226
|
+
...options.reasoningSummary != null && {
|
|
2227
|
+
summary: options.reasoningSummary
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2054
2230
|
},
|
|
2055
2231
|
...options.store === false && {
|
|
2056
2232
|
store: options.store
|
|
@@ -2079,7 +2255,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2079
2255
|
};
|
|
2080
2256
|
}
|
|
2081
2257
|
async doGenerate(options) {
|
|
2082
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2258
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2083
2259
|
const {
|
|
2084
2260
|
args: body,
|
|
2085
2261
|
warnings,
|
|
@@ -2093,18 +2269,19 @@ var XaiResponsesLanguageModel = class {
|
|
|
2093
2269
|
responseHeaders,
|
|
2094
2270
|
value: response,
|
|
2095
2271
|
rawValue: rawResponse
|
|
2096
|
-
} = await (
|
|
2272
|
+
} = await postJsonToApi3({
|
|
2097
2273
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2098
|
-
headers: (
|
|
2274
|
+
headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2099
2275
|
body,
|
|
2100
2276
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2101
|
-
successfulResponseHandler: (
|
|
2277
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
2102
2278
|
xaiResponsesResponseSchema
|
|
2103
2279
|
),
|
|
2104
2280
|
abortSignal: options.abortSignal,
|
|
2105
2281
|
fetch: this.config.fetch
|
|
2106
2282
|
});
|
|
2107
2283
|
const content = [];
|
|
2284
|
+
let hasFunctionCall = false;
|
|
2108
2285
|
const webSearchSubTools = [
|
|
2109
2286
|
"web_search",
|
|
2110
2287
|
"web_search_with_snippets",
|
|
@@ -2131,29 +2308,29 @@ var XaiResponsesLanguageModel = class {
|
|
|
2131
2308
|
toolCallId: part.id,
|
|
2132
2309
|
toolName,
|
|
2133
2310
|
result: {
|
|
2134
|
-
queries: (
|
|
2135
|
-
results: (
|
|
2311
|
+
queries: (_d = part.queries) != null ? _d : [],
|
|
2312
|
+
results: (_f = (_e = part.results) == null ? void 0 : _e.map((result) => ({
|
|
2136
2313
|
fileId: result.file_id,
|
|
2137
2314
|
filename: result.filename,
|
|
2138
2315
|
score: result.score,
|
|
2139
2316
|
text: result.text
|
|
2140
|
-
}))) != null ?
|
|
2317
|
+
}))) != null ? _f : null
|
|
2141
2318
|
}
|
|
2142
2319
|
});
|
|
2143
2320
|
continue;
|
|
2144
2321
|
}
|
|
2145
2322
|
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call" || part.type === "mcp_call") {
|
|
2146
|
-
let toolName = (
|
|
2147
|
-
if (webSearchSubTools.includes((
|
|
2323
|
+
let toolName = (_g = part.name) != null ? _g : "";
|
|
2324
|
+
if (webSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "web_search_call") {
|
|
2148
2325
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2149
|
-
} else if (xSearchSubTools.includes((
|
|
2326
|
+
} else if (xSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "x_search_call") {
|
|
2150
2327
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2151
2328
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2152
2329
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2153
2330
|
} else if (part.type === "mcp_call") {
|
|
2154
|
-
toolName = (
|
|
2331
|
+
toolName = (_j = mcpToolName != null ? mcpToolName : part.name) != null ? _j : "mcp";
|
|
2155
2332
|
}
|
|
2156
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2333
|
+
const toolInput = part.type === "custom_tool_call" ? (_k = part.input) != null ? _k : "" : part.type === "mcp_call" ? (_l = part.arguments) != null ? _l : "" : (_m = part.arguments) != null ? _m : "";
|
|
2157
2334
|
content.push({
|
|
2158
2335
|
type: "tool-call",
|
|
2159
2336
|
toolCallId: part.id,
|
|
@@ -2180,7 +2357,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2180
2357
|
sourceType: "url",
|
|
2181
2358
|
id: this.config.generateId(),
|
|
2182
2359
|
url: annotation.url,
|
|
2183
|
-
title: (
|
|
2360
|
+
title: (_n = annotation.title) != null ? _n : annotation.url
|
|
2184
2361
|
});
|
|
2185
2362
|
}
|
|
2186
2363
|
}
|
|
@@ -2189,6 +2366,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2189
2366
|
break;
|
|
2190
2367
|
}
|
|
2191
2368
|
case "function_call": {
|
|
2369
|
+
hasFunctionCall = true;
|
|
2192
2370
|
content.push({
|
|
2193
2371
|
type: "tool-call",
|
|
2194
2372
|
toolCallId: part.call_id,
|
|
@@ -2198,13 +2376,14 @@ var XaiResponsesLanguageModel = class {
|
|
|
2198
2376
|
break;
|
|
2199
2377
|
}
|
|
2200
2378
|
case "reasoning": {
|
|
2201
|
-
const
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2379
|
+
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((_o = part.content) != null ? _o : []).map((c) => c.text);
|
|
2380
|
+
const reasoningText = texts.filter((text) => text && text.length > 0).join("");
|
|
2381
|
+
if (reasoningText || part.encrypted_content) {
|
|
2382
|
+
const hasMetadata = part.encrypted_content || part.id;
|
|
2383
|
+
content.push({
|
|
2384
|
+
type: "reasoning",
|
|
2385
|
+
text: reasoningText,
|
|
2386
|
+
...hasMetadata && {
|
|
2208
2387
|
providerMetadata: {
|
|
2209
2388
|
xai: {
|
|
2210
2389
|
...part.encrypted_content && {
|
|
@@ -2213,13 +2392,8 @@ var XaiResponsesLanguageModel = class {
|
|
|
2213
2392
|
...part.id && { itemId: part.id }
|
|
2214
2393
|
}
|
|
2215
2394
|
}
|
|
2216
|
-
}
|
|
2217
|
-
}
|
|
2218
|
-
content.push({
|
|
2219
|
-
type: "reasoning",
|
|
2220
|
-
text: reasoningText
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2395
|
+
}
|
|
2396
|
+
});
|
|
2223
2397
|
}
|
|
2224
2398
|
break;
|
|
2225
2399
|
}
|
|
@@ -2231,8 +2405,8 @@ var XaiResponsesLanguageModel = class {
|
|
|
2231
2405
|
return {
|
|
2232
2406
|
content,
|
|
2233
2407
|
finishReason: {
|
|
2234
|
-
unified: mapXaiResponsesFinishReason(response.status),
|
|
2235
|
-
raw: (
|
|
2408
|
+
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
|
|
2409
|
+
raw: (_p = response.status) != null ? _p : void 0
|
|
2236
2410
|
},
|
|
2237
2411
|
usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
|
|
2238
2412
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -2248,7 +2422,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2248
2422
|
};
|
|
2249
2423
|
}
|
|
2250
2424
|
async doStream(options) {
|
|
2251
|
-
var _a;
|
|
2425
|
+
var _a, _b, _c;
|
|
2252
2426
|
const {
|
|
2253
2427
|
args,
|
|
2254
2428
|
warnings,
|
|
@@ -2262,12 +2436,12 @@ var XaiResponsesLanguageModel = class {
|
|
|
2262
2436
|
...args,
|
|
2263
2437
|
stream: true
|
|
2264
2438
|
};
|
|
2265
|
-
const { responseHeaders, value: response } = await (
|
|
2439
|
+
const { responseHeaders, value: response } = await postJsonToApi3({
|
|
2266
2440
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2267
|
-
headers: (
|
|
2441
|
+
headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2268
2442
|
body,
|
|
2269
2443
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2270
|
-
successfulResponseHandler: (
|
|
2444
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
2271
2445
|
xaiResponsesChunkSchema
|
|
2272
2446
|
),
|
|
2273
2447
|
abortSignal: options.abortSignal,
|
|
@@ -2277,6 +2451,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2277
2451
|
unified: "other",
|
|
2278
2452
|
raw: void 0
|
|
2279
2453
|
};
|
|
2454
|
+
let hasFunctionCall = false;
|
|
2280
2455
|
let usage = void 0;
|
|
2281
2456
|
let isFirstChunk = true;
|
|
2282
2457
|
const contentBlocks = {};
|
|
@@ -2291,7 +2466,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2291
2466
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2292
2467
|
},
|
|
2293
2468
|
transform(chunk, controller) {
|
|
2294
|
-
var _a2,
|
|
2469
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2295
2470
|
if (options.includeRawChunks) {
|
|
2296
2471
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2297
2472
|
}
|
|
@@ -2409,24 +2584,45 @@ var XaiResponsesLanguageModel = class {
|
|
|
2409
2584
|
sourceType: "url",
|
|
2410
2585
|
id: self.config.generateId(),
|
|
2411
2586
|
url: annotation.url,
|
|
2412
|
-
title: (
|
|
2587
|
+
title: (_b2 = annotation.title) != null ? _b2 : annotation.url
|
|
2413
2588
|
});
|
|
2414
2589
|
}
|
|
2415
2590
|
return;
|
|
2416
2591
|
}
|
|
2417
|
-
if (event.type === "response.done" || event.type === "response.completed") {
|
|
2592
|
+
if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
|
|
2418
2593
|
const response2 = event.response;
|
|
2419
2594
|
if (response2.usage) {
|
|
2420
2595
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2421
2596
|
}
|
|
2422
|
-
if (
|
|
2597
|
+
if (event.type === "response.incomplete") {
|
|
2598
|
+
const reason = "incomplete_details" in response2 ? (_c2 = response2.incomplete_details) == null ? void 0 : _c2.reason : void 0;
|
|
2599
|
+
finishReason = {
|
|
2600
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2601
|
+
raw: reason != null ? reason : "incomplete"
|
|
2602
|
+
};
|
|
2603
|
+
} else if ("status" in response2 && response2.status) {
|
|
2423
2604
|
finishReason = {
|
|
2424
|
-
unified: mapXaiResponsesFinishReason(response2.status),
|
|
2605
|
+
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
|
|
2425
2606
|
raw: response2.status
|
|
2426
2607
|
};
|
|
2427
2608
|
}
|
|
2428
2609
|
return;
|
|
2429
2610
|
}
|
|
2611
|
+
if (event.type === "response.failed") {
|
|
2612
|
+
const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
|
|
2613
|
+
finishReason = {
|
|
2614
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2615
|
+
raw: reason != null ? reason : "error"
|
|
2616
|
+
};
|
|
2617
|
+
if (event.response.usage) {
|
|
2618
|
+
usage = convertXaiResponsesUsage(event.response.usage);
|
|
2619
|
+
}
|
|
2620
|
+
return;
|
|
2621
|
+
}
|
|
2622
|
+
if (event.type === "error") {
|
|
2623
|
+
controller.enqueue({ type: "error", error: event });
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2430
2626
|
if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
|
|
2431
2627
|
return;
|
|
2432
2628
|
}
|
|
@@ -2509,13 +2705,13 @@ var XaiResponsesLanguageModel = class {
|
|
|
2509
2705
|
toolCallId: part.id,
|
|
2510
2706
|
toolName,
|
|
2511
2707
|
result: {
|
|
2512
|
-
queries: (
|
|
2513
|
-
results: (
|
|
2708
|
+
queries: (_e = part.queries) != null ? _e : [],
|
|
2709
|
+
results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
|
|
2514
2710
|
fileId: result.file_id,
|
|
2515
2711
|
filename: result.filename,
|
|
2516
2712
|
score: result.score,
|
|
2517
2713
|
text: result.text
|
|
2518
|
-
}))) != null ?
|
|
2714
|
+
}))) != null ? _g : null
|
|
2519
2715
|
}
|
|
2520
2716
|
});
|
|
2521
2717
|
}
|
|
@@ -2533,17 +2729,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2533
2729
|
"x_semantic_search",
|
|
2534
2730
|
"x_thread_fetch"
|
|
2535
2731
|
];
|
|
2536
|
-
let toolName = (
|
|
2537
|
-
if (webSearchSubTools.includes((
|
|
2732
|
+
let toolName = (_h = part.name) != null ? _h : "";
|
|
2733
|
+
if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
|
|
2538
2734
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2539
|
-
} else if (xSearchSubTools.includes((
|
|
2735
|
+
} else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
|
|
2540
2736
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2541
2737
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2542
2738
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2543
2739
|
} else if (part.type === "mcp_call") {
|
|
2544
|
-
toolName = (
|
|
2740
|
+
toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
|
|
2545
2741
|
}
|
|
2546
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2742
|
+
const toolInput = part.type === "custom_tool_call" ? (_l = part.input) != null ? _l : "" : part.type === "mcp_call" ? (_m = part.arguments) != null ? _m : "" : (_n = part.arguments) != null ? _n : "";
|
|
2547
2743
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2548
2744
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2549
2745
|
seenToolCalls.add(part.id);
|
|
@@ -2596,7 +2792,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2596
2792
|
sourceType: "url",
|
|
2597
2793
|
id: self.config.generateId(),
|
|
2598
2794
|
url: annotation.url,
|
|
2599
|
-
title: (
|
|
2795
|
+
title: (_o = annotation.title) != null ? _o : annotation.url
|
|
2600
2796
|
});
|
|
2601
2797
|
}
|
|
2602
2798
|
}
|
|
@@ -2614,6 +2810,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2614
2810
|
toolName: part.name
|
|
2615
2811
|
});
|
|
2616
2812
|
} else if (event.type === "response.output_item.done") {
|
|
2813
|
+
hasFunctionCall = true;
|
|
2617
2814
|
ongoingToolCalls[event.output_index] = void 0;
|
|
2618
2815
|
controller.enqueue({
|
|
2619
2816
|
type: "tool-input-end",
|
|
@@ -2661,44 +2858,44 @@ var XaiResponsesLanguageModel = class {
|
|
|
2661
2858
|
};
|
|
2662
2859
|
|
|
2663
2860
|
// src/tool/code-execution.ts
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
var codeExecutionOutputSchema =
|
|
2667
|
-
output:
|
|
2668
|
-
error:
|
|
2861
|
+
import { createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema5 } from "@ai-sdk/provider-utils";
|
|
2862
|
+
import { z as z12 } from "zod/v4";
|
|
2863
|
+
var codeExecutionOutputSchema = z12.object({
|
|
2864
|
+
output: z12.string().describe("the output of the code execution"),
|
|
2865
|
+
error: z12.string().optional().describe("any error that occurred")
|
|
2669
2866
|
});
|
|
2670
|
-
var codeExecutionToolFactory = (
|
|
2867
|
+
var codeExecutionToolFactory = createProviderToolFactoryWithOutputSchema5({
|
|
2671
2868
|
id: "xai.code_execution",
|
|
2672
|
-
inputSchema:
|
|
2869
|
+
inputSchema: z12.object({}).describe("no input parameters"),
|
|
2673
2870
|
outputSchema: codeExecutionOutputSchema
|
|
2674
2871
|
});
|
|
2675
2872
|
var codeExecution = (args = {}) => codeExecutionToolFactory(args);
|
|
2676
2873
|
|
|
2677
2874
|
// src/tool/view-image.ts
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
var viewImageOutputSchema =
|
|
2681
|
-
description:
|
|
2682
|
-
objects:
|
|
2875
|
+
import { createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema6 } from "@ai-sdk/provider-utils";
|
|
2876
|
+
import { z as z13 } from "zod/v4";
|
|
2877
|
+
var viewImageOutputSchema = z13.object({
|
|
2878
|
+
description: z13.string().describe("description of the image"),
|
|
2879
|
+
objects: z13.array(z13.string()).optional().describe("objects detected in the image")
|
|
2683
2880
|
});
|
|
2684
|
-
var viewImageToolFactory = (
|
|
2881
|
+
var viewImageToolFactory = createProviderToolFactoryWithOutputSchema6({
|
|
2685
2882
|
id: "xai.view_image",
|
|
2686
|
-
inputSchema:
|
|
2883
|
+
inputSchema: z13.object({}).describe("no input parameters"),
|
|
2687
2884
|
outputSchema: viewImageOutputSchema
|
|
2688
2885
|
});
|
|
2689
2886
|
var viewImage = (args = {}) => viewImageToolFactory(args);
|
|
2690
2887
|
|
|
2691
2888
|
// src/tool/view-x-video.ts
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
var viewXVideoOutputSchema =
|
|
2695
|
-
transcript:
|
|
2696
|
-
description:
|
|
2697
|
-
duration:
|
|
2889
|
+
import { createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema7 } from "@ai-sdk/provider-utils";
|
|
2890
|
+
import { z as z14 } from "zod/v4";
|
|
2891
|
+
var viewXVideoOutputSchema = z14.object({
|
|
2892
|
+
transcript: z14.string().optional().describe("transcript of the video"),
|
|
2893
|
+
description: z14.string().describe("description of the video content"),
|
|
2894
|
+
duration: z14.number().optional().describe("duration in seconds")
|
|
2698
2895
|
});
|
|
2699
|
-
var viewXVideoToolFactory = (
|
|
2896
|
+
var viewXVideoToolFactory = createProviderToolFactoryWithOutputSchema7({
|
|
2700
2897
|
id: "xai.view_x_video",
|
|
2701
|
-
inputSchema:
|
|
2898
|
+
inputSchema: z14.object({}).describe("no input parameters"),
|
|
2702
2899
|
outputSchema: viewXVideoOutputSchema
|
|
2703
2900
|
});
|
|
2704
2901
|
var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
@@ -2715,53 +2912,213 @@ var xaiTools = {
|
|
|
2715
2912
|
};
|
|
2716
2913
|
|
|
2717
2914
|
// src/version.ts
|
|
2718
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2915
|
+
var VERSION = true ? "4.0.0-beta.40" : "0.0.0-test";
|
|
2719
2916
|
|
|
2720
|
-
// src/xai-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2917
|
+
// src/files/xai-files.ts
|
|
2918
|
+
import {
|
|
2919
|
+
combineHeaders as combineHeaders4,
|
|
2920
|
+
convertBase64ToUint8Array,
|
|
2921
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2922
|
+
parseProviderOptions as parseProviderOptions4,
|
|
2923
|
+
postFormDataToApi
|
|
2924
|
+
} from "@ai-sdk/provider-utils";
|
|
2724
2925
|
|
|
2725
|
-
// src/xai-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
var
|
|
2729
|
-
() => (
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2926
|
+
// src/files/xai-files-api.ts
|
|
2927
|
+
import { lazySchema as lazySchema5, zodSchema as zodSchema5 } from "@ai-sdk/provider-utils";
|
|
2928
|
+
import { z as z15 } from "zod/v4";
|
|
2929
|
+
var xaiFilesResponseSchema = lazySchema5(
|
|
2930
|
+
() => zodSchema5(
|
|
2931
|
+
z15.object({
|
|
2932
|
+
id: z15.string(),
|
|
2933
|
+
object: z15.string().nullish(),
|
|
2934
|
+
bytes: z15.number().nullish(),
|
|
2935
|
+
created_at: z15.number().nullish(),
|
|
2936
|
+
filename: z15.string().nullish(),
|
|
2937
|
+
purpose: z15.string().nullish(),
|
|
2938
|
+
status: z15.string().nullish()
|
|
2939
|
+
})
|
|
2940
|
+
)
|
|
2941
|
+
);
|
|
2942
|
+
|
|
2943
|
+
// src/files/xai-files-options.ts
|
|
2944
|
+
import { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
|
|
2945
|
+
import { z as z16 } from "zod/v4";
|
|
2946
|
+
var xaiFilesOptionsSchema = lazySchema6(
|
|
2947
|
+
() => zodSchema6(
|
|
2948
|
+
z16.object({
|
|
2949
|
+
teamId: z16.string().optional(),
|
|
2950
|
+
filePath: z16.string().optional()
|
|
2735
2951
|
}).passthrough()
|
|
2736
2952
|
)
|
|
2737
2953
|
);
|
|
2738
2954
|
|
|
2955
|
+
// src/files/xai-files.ts
|
|
2956
|
+
var XaiFiles = class {
|
|
2957
|
+
constructor(config) {
|
|
2958
|
+
this.config = config;
|
|
2959
|
+
this.specificationVersion = "v4";
|
|
2960
|
+
}
|
|
2961
|
+
get provider() {
|
|
2962
|
+
return this.config.provider;
|
|
2963
|
+
}
|
|
2964
|
+
async uploadFile({
|
|
2965
|
+
data,
|
|
2966
|
+
mediaType,
|
|
2967
|
+
filename,
|
|
2968
|
+
providerOptions
|
|
2969
|
+
}) {
|
|
2970
|
+
var _a, _b;
|
|
2971
|
+
const xaiOptions = await parseProviderOptions4({
|
|
2972
|
+
provider: "xai",
|
|
2973
|
+
providerOptions,
|
|
2974
|
+
schema: xaiFilesOptionsSchema
|
|
2975
|
+
});
|
|
2976
|
+
const fileBytes = data instanceof Uint8Array ? data : convertBase64ToUint8Array(data);
|
|
2977
|
+
const blob = new Blob([fileBytes], {
|
|
2978
|
+
type: mediaType
|
|
2979
|
+
});
|
|
2980
|
+
const formData = new FormData();
|
|
2981
|
+
if (filename != null) {
|
|
2982
|
+
formData.append("file", blob, filename);
|
|
2983
|
+
} else {
|
|
2984
|
+
formData.append("file", blob);
|
|
2985
|
+
}
|
|
2986
|
+
if ((xaiOptions == null ? void 0 : xaiOptions.teamId) != null) {
|
|
2987
|
+
formData.append("team_id", xaiOptions.teamId);
|
|
2988
|
+
}
|
|
2989
|
+
const { value: response } = await postFormDataToApi({
|
|
2990
|
+
url: `${this.config.baseURL}/files`,
|
|
2991
|
+
headers: combineHeaders4(this.config.headers()),
|
|
2992
|
+
formData,
|
|
2993
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
2994
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
2995
|
+
xaiFilesResponseSchema
|
|
2996
|
+
),
|
|
2997
|
+
fetch: this.config.fetch
|
|
2998
|
+
});
|
|
2999
|
+
return {
|
|
3000
|
+
warnings: [],
|
|
3001
|
+
providerReference: { xai: response.id },
|
|
3002
|
+
...((_a = response.filename) != null ? _a : filename) ? { filename: (_b = response.filename) != null ? _b : filename } : {},
|
|
3003
|
+
...mediaType != null ? { mediaType } : {},
|
|
3004
|
+
providerMetadata: {
|
|
3005
|
+
xai: {
|
|
3006
|
+
...response.filename != null ? { filename: response.filename } : {},
|
|
3007
|
+
...response.bytes != null ? { bytes: response.bytes } : {},
|
|
3008
|
+
...response.created_at != null ? { createdAt: response.created_at } : {}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
|
|
3015
|
+
// src/xai-video-model.ts
|
|
3016
|
+
import {
|
|
3017
|
+
AISDKError
|
|
3018
|
+
} from "@ai-sdk/provider";
|
|
3019
|
+
import {
|
|
3020
|
+
combineHeaders as combineHeaders5,
|
|
3021
|
+
convertUint8ArrayToBase64,
|
|
3022
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3023
|
+
delay,
|
|
3024
|
+
getFromApi as getFromApi2,
|
|
3025
|
+
parseProviderOptions as parseProviderOptions5,
|
|
3026
|
+
postJsonToApi as postJsonToApi4
|
|
3027
|
+
} from "@ai-sdk/provider-utils";
|
|
3028
|
+
import { z as z18 } from "zod/v4";
|
|
3029
|
+
|
|
3030
|
+
// src/xai-video-options.ts
|
|
3031
|
+
import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
|
|
3032
|
+
import { z as z17 } from "zod/v4";
|
|
3033
|
+
var nonEmptyStringSchema = z17.string().min(1);
|
|
3034
|
+
var resolutionSchema = z17.enum(["480p", "720p"]);
|
|
3035
|
+
var modeSchema = z17.enum(["edit-video", "extend-video", "reference-to-video"]);
|
|
3036
|
+
var baseFields = {
|
|
3037
|
+
pollIntervalMs: z17.number().positive().nullish(),
|
|
3038
|
+
pollTimeoutMs: z17.number().positive().nullish(),
|
|
3039
|
+
resolution: resolutionSchema.nullish()
|
|
3040
|
+
};
|
|
3041
|
+
var editVideoSchema = z17.object({
|
|
3042
|
+
...baseFields,
|
|
3043
|
+
mode: z17.literal("edit-video"),
|
|
3044
|
+
videoUrl: nonEmptyStringSchema,
|
|
3045
|
+
referenceImageUrls: z17.undefined().optional()
|
|
3046
|
+
});
|
|
3047
|
+
var extendVideoSchema = z17.object({
|
|
3048
|
+
...baseFields,
|
|
3049
|
+
mode: z17.literal("extend-video"),
|
|
3050
|
+
videoUrl: nonEmptyStringSchema,
|
|
3051
|
+
referenceImageUrls: z17.undefined().optional()
|
|
3052
|
+
});
|
|
3053
|
+
var referenceToVideoSchema = z17.object({
|
|
3054
|
+
...baseFields,
|
|
3055
|
+
mode: z17.literal("reference-to-video"),
|
|
3056
|
+
referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7),
|
|
3057
|
+
videoUrl: z17.undefined().optional()
|
|
3058
|
+
});
|
|
3059
|
+
var autoDetectSchema = z17.object({
|
|
3060
|
+
...baseFields,
|
|
3061
|
+
mode: z17.undefined().optional(),
|
|
3062
|
+
videoUrl: nonEmptyStringSchema.optional(),
|
|
3063
|
+
referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7).optional()
|
|
3064
|
+
});
|
|
3065
|
+
var xaiVideoModelOptions = z17.union([
|
|
3066
|
+
editVideoSchema,
|
|
3067
|
+
extendVideoSchema,
|
|
3068
|
+
referenceToVideoSchema,
|
|
3069
|
+
autoDetectSchema
|
|
3070
|
+
]);
|
|
3071
|
+
var runtimeSchema = z17.object({
|
|
3072
|
+
mode: modeSchema.optional(),
|
|
3073
|
+
videoUrl: nonEmptyStringSchema.optional(),
|
|
3074
|
+
referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
3075
|
+
...baseFields
|
|
3076
|
+
}).passthrough();
|
|
3077
|
+
var xaiVideoModelOptionsSchema = lazySchema7(
|
|
3078
|
+
() => zodSchema7(runtimeSchema)
|
|
3079
|
+
);
|
|
3080
|
+
|
|
2739
3081
|
// src/xai-video-model.ts
|
|
2740
3082
|
var RESOLUTION_MAP = {
|
|
2741
3083
|
"1280x720": "720p",
|
|
2742
3084
|
"854x480": "480p",
|
|
2743
3085
|
"640x480": "480p"
|
|
2744
3086
|
};
|
|
3087
|
+
function resolveVideoMode(options) {
|
|
3088
|
+
if ((options == null ? void 0 : options.mode) != null) {
|
|
3089
|
+
return options.mode;
|
|
3090
|
+
}
|
|
3091
|
+
if ((options == null ? void 0 : options.videoUrl) != null) {
|
|
3092
|
+
return "edit-video";
|
|
3093
|
+
}
|
|
3094
|
+
if ((options == null ? void 0 : options.referenceImageUrls) != null && options.referenceImageUrls.length > 0) {
|
|
3095
|
+
return "reference-to-video";
|
|
3096
|
+
}
|
|
3097
|
+
return void 0;
|
|
3098
|
+
}
|
|
2745
3099
|
var XaiVideoModel = class {
|
|
2746
3100
|
constructor(modelId, config) {
|
|
2747
3101
|
this.modelId = modelId;
|
|
2748
3102
|
this.config = config;
|
|
2749
|
-
this.specificationVersion = "
|
|
3103
|
+
this.specificationVersion = "v4";
|
|
2750
3104
|
this.maxVideosPerCall = 1;
|
|
2751
3105
|
}
|
|
2752
3106
|
get provider() {
|
|
2753
3107
|
return this.config.provider;
|
|
2754
3108
|
}
|
|
2755
3109
|
async doGenerate(options) {
|
|
2756
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3110
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2757
3111
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2758
3112
|
const warnings = [];
|
|
2759
|
-
const xaiOptions = await (
|
|
3113
|
+
const xaiOptions = await parseProviderOptions5({
|
|
2760
3114
|
provider: "xai",
|
|
2761
3115
|
providerOptions: options.providerOptions,
|
|
2762
3116
|
schema: xaiVideoModelOptionsSchema
|
|
2763
3117
|
});
|
|
2764
|
-
const
|
|
3118
|
+
const effectiveMode = resolveVideoMode(xaiOptions);
|
|
3119
|
+
const isEdit = effectiveMode === "edit-video";
|
|
3120
|
+
const isExtension = effectiveMode === "extend-video";
|
|
3121
|
+
const hasReferenceImages = effectiveMode === "reference-to-video";
|
|
2765
3122
|
if (options.fps != null) {
|
|
2766
3123
|
warnings.push({
|
|
2767
3124
|
type: "unsupported",
|
|
@@ -2804,19 +3161,36 @@ var XaiVideoModel = class {
|
|
|
2804
3161
|
details: "xAI video editing does not support custom resolution."
|
|
2805
3162
|
});
|
|
2806
3163
|
}
|
|
3164
|
+
if (isExtension && options.aspectRatio != null) {
|
|
3165
|
+
warnings.push({
|
|
3166
|
+
type: "unsupported",
|
|
3167
|
+
feature: "aspectRatio",
|
|
3168
|
+
details: "xAI video extension does not support custom aspect ratio."
|
|
3169
|
+
});
|
|
3170
|
+
}
|
|
3171
|
+
if (isExtension && ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null || options.resolution != null)) {
|
|
3172
|
+
warnings.push({
|
|
3173
|
+
type: "unsupported",
|
|
3174
|
+
feature: "resolution",
|
|
3175
|
+
details: "xAI video extension does not support custom resolution."
|
|
3176
|
+
});
|
|
3177
|
+
}
|
|
2807
3178
|
const body = {
|
|
2808
3179
|
model: this.modelId,
|
|
2809
3180
|
prompt: options.prompt
|
|
2810
3181
|
};
|
|
2811
|
-
|
|
3182
|
+
const allowDuration = !isEdit;
|
|
3183
|
+
const allowAspectRatio = !isEdit && !isExtension;
|
|
3184
|
+
const allowResolution = !isEdit && !isExtension;
|
|
3185
|
+
if (allowDuration && options.duration != null) {
|
|
2812
3186
|
body.duration = options.duration;
|
|
2813
3187
|
}
|
|
2814
|
-
if (
|
|
3188
|
+
if (allowAspectRatio && options.aspectRatio != null) {
|
|
2815
3189
|
body.aspect_ratio = options.aspectRatio;
|
|
2816
3190
|
}
|
|
2817
|
-
if (
|
|
3191
|
+
if (allowResolution && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
|
|
2818
3192
|
body.resolution = xaiOptions.resolution;
|
|
2819
|
-
} else if (
|
|
3193
|
+
} else if (allowResolution && options.resolution != null) {
|
|
2820
3194
|
const mapped = RESOLUTION_MAP[options.resolution];
|
|
2821
3195
|
if (mapped != null) {
|
|
2822
3196
|
body.resolution = mapped;
|
|
@@ -2828,38 +3202,56 @@ var XaiVideoModel = class {
|
|
|
2828
3202
|
});
|
|
2829
3203
|
}
|
|
2830
3204
|
}
|
|
2831
|
-
if (
|
|
3205
|
+
if (isEdit) {
|
|
3206
|
+
body.video = { url: xaiOptions.videoUrl };
|
|
3207
|
+
}
|
|
3208
|
+
if (isExtension) {
|
|
2832
3209
|
body.video = { url: xaiOptions.videoUrl };
|
|
2833
3210
|
}
|
|
2834
3211
|
if (options.image != null) {
|
|
2835
3212
|
if (options.image.type === "url") {
|
|
2836
3213
|
body.image = { url: options.image.url };
|
|
2837
3214
|
} else {
|
|
2838
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
3215
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
2839
3216
|
body.image = {
|
|
2840
3217
|
url: `data:${options.image.mediaType};base64,${base64Data}`
|
|
2841
3218
|
};
|
|
2842
3219
|
}
|
|
2843
3220
|
}
|
|
3221
|
+
if (hasReferenceImages) {
|
|
3222
|
+
body.reference_images = xaiOptions.referenceImageUrls.map((url) => ({
|
|
3223
|
+
url
|
|
3224
|
+
}));
|
|
3225
|
+
}
|
|
2844
3226
|
if (xaiOptions != null) {
|
|
2845
3227
|
for (const [key, value] of Object.entries(xaiOptions)) {
|
|
2846
3228
|
if (![
|
|
3229
|
+
"mode",
|
|
2847
3230
|
"pollIntervalMs",
|
|
2848
3231
|
"pollTimeoutMs",
|
|
2849
3232
|
"resolution",
|
|
2850
|
-
"videoUrl"
|
|
3233
|
+
"videoUrl",
|
|
3234
|
+
"referenceImageUrls"
|
|
2851
3235
|
].includes(key)) {
|
|
2852
3236
|
body[key] = value;
|
|
2853
3237
|
}
|
|
2854
3238
|
}
|
|
2855
3239
|
}
|
|
2856
3240
|
const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
3241
|
+
let endpoint;
|
|
3242
|
+
if (isEdit) {
|
|
3243
|
+
endpoint = `${baseURL}/videos/edits`;
|
|
3244
|
+
} else if (isExtension) {
|
|
3245
|
+
endpoint = `${baseURL}/videos/extensions`;
|
|
3246
|
+
} else {
|
|
3247
|
+
endpoint = `${baseURL}/videos/generations`;
|
|
3248
|
+
}
|
|
3249
|
+
const { value: createResponse } = await postJsonToApi4({
|
|
3250
|
+
url: endpoint,
|
|
3251
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
2860
3252
|
body,
|
|
2861
3253
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2862
|
-
successfulResponseHandler: (
|
|
3254
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
2863
3255
|
xaiCreateVideoResponseSchema
|
|
2864
3256
|
),
|
|
2865
3257
|
abortSignal: options.abortSignal,
|
|
@@ -2867,7 +3259,7 @@ var XaiVideoModel = class {
|
|
|
2867
3259
|
});
|
|
2868
3260
|
const requestId = createResponse.request_id;
|
|
2869
3261
|
if (!requestId) {
|
|
2870
|
-
throw new
|
|
3262
|
+
throw new AISDKError({
|
|
2871
3263
|
name: "XAI_VIDEO_GENERATION_ERROR",
|
|
2872
3264
|
message: `No request_id returned from xAI API. Response: ${JSON.stringify(createResponse)}`
|
|
2873
3265
|
});
|
|
@@ -2877,17 +3269,17 @@ var XaiVideoModel = class {
|
|
|
2877
3269
|
const startTime = Date.now();
|
|
2878
3270
|
let responseHeaders;
|
|
2879
3271
|
while (true) {
|
|
2880
|
-
await
|
|
3272
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
2881
3273
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
2882
|
-
throw new
|
|
3274
|
+
throw new AISDKError({
|
|
2883
3275
|
name: "XAI_VIDEO_GENERATION_TIMEOUT",
|
|
2884
3276
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
2885
3277
|
});
|
|
2886
3278
|
}
|
|
2887
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await (
|
|
3279
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi2({
|
|
2888
3280
|
url: `${baseURL}/videos/${requestId}`,
|
|
2889
|
-
headers: (
|
|
2890
|
-
successfulResponseHandler: (
|
|
3281
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
3282
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
2891
3283
|
xaiVideoStatusResponseSchema
|
|
2892
3284
|
),
|
|
2893
3285
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -2896,8 +3288,14 @@ var XaiVideoModel = class {
|
|
|
2896
3288
|
});
|
|
2897
3289
|
responseHeaders = pollHeaders;
|
|
2898
3290
|
if (statusResponse.status === "done" || statusResponse.status == null && ((_g = statusResponse.video) == null ? void 0 : _g.url)) {
|
|
2899
|
-
if (
|
|
2900
|
-
throw new
|
|
3291
|
+
if (((_h = statusResponse.video) == null ? void 0 : _h.respect_moderation) === false) {
|
|
3292
|
+
throw new AISDKError({
|
|
3293
|
+
name: "XAI_VIDEO_MODERATION_ERROR",
|
|
3294
|
+
message: "Video generation was blocked due to a content policy violation."
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
if (!((_i = statusResponse.video) == null ? void 0 : _i.url)) {
|
|
3298
|
+
throw new AISDKError({
|
|
2901
3299
|
name: "XAI_VIDEO_GENERATION_ERROR",
|
|
2902
3300
|
message: "Video generation completed but no video URL was returned."
|
|
2903
3301
|
});
|
|
@@ -2920,42 +3318,58 @@ var XaiVideoModel = class {
|
|
|
2920
3318
|
xai: {
|
|
2921
3319
|
requestId,
|
|
2922
3320
|
videoUrl: statusResponse.video.url,
|
|
2923
|
-
...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {}
|
|
3321
|
+
...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {},
|
|
3322
|
+
...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
|
|
3323
|
+
...statusResponse.progress != null ? { progress: statusResponse.progress } : {}
|
|
2924
3324
|
}
|
|
2925
3325
|
}
|
|
2926
3326
|
};
|
|
2927
3327
|
}
|
|
2928
3328
|
if (statusResponse.status === "expired") {
|
|
2929
|
-
throw new
|
|
3329
|
+
throw new AISDKError({
|
|
2930
3330
|
name: "XAI_VIDEO_GENERATION_EXPIRED",
|
|
2931
3331
|
message: "Video generation request expired."
|
|
2932
3332
|
});
|
|
2933
3333
|
}
|
|
3334
|
+
if (statusResponse.status === "failed") {
|
|
3335
|
+
throw new AISDKError({
|
|
3336
|
+
name: "XAI_VIDEO_GENERATION_FAILED",
|
|
3337
|
+
message: "Video generation failed."
|
|
3338
|
+
});
|
|
3339
|
+
}
|
|
2934
3340
|
}
|
|
2935
3341
|
}
|
|
2936
3342
|
};
|
|
2937
|
-
var xaiCreateVideoResponseSchema =
|
|
2938
|
-
request_id:
|
|
3343
|
+
var xaiCreateVideoResponseSchema = z18.object({
|
|
3344
|
+
request_id: z18.string().nullish()
|
|
2939
3345
|
});
|
|
2940
|
-
var xaiVideoStatusResponseSchema =
|
|
2941
|
-
status:
|
|
2942
|
-
video:
|
|
2943
|
-
url:
|
|
2944
|
-
duration:
|
|
2945
|
-
respect_moderation:
|
|
3346
|
+
var xaiVideoStatusResponseSchema = z18.object({
|
|
3347
|
+
status: z18.string().nullish(),
|
|
3348
|
+
video: z18.object({
|
|
3349
|
+
url: z18.string(),
|
|
3350
|
+
duration: z18.number().nullish(),
|
|
3351
|
+
respect_moderation: z18.boolean().nullish()
|
|
2946
3352
|
}).nullish(),
|
|
2947
|
-
model:
|
|
3353
|
+
model: z18.string().nullish(),
|
|
3354
|
+
usage: z18.object({
|
|
3355
|
+
cost_in_usd_ticks: z18.number().nullish()
|
|
3356
|
+
}).nullish(),
|
|
3357
|
+
progress: z18.number().nullish(),
|
|
3358
|
+
error: z18.object({
|
|
3359
|
+
code: z18.string().nullish(),
|
|
3360
|
+
message: z18.string().nullish()
|
|
3361
|
+
}).nullish()
|
|
2948
3362
|
});
|
|
2949
3363
|
|
|
2950
3364
|
// src/xai-provider.ts
|
|
2951
3365
|
function createXai(options = {}) {
|
|
2952
3366
|
var _a;
|
|
2953
|
-
const baseURL =
|
|
3367
|
+
const baseURL = withoutTrailingSlash(
|
|
2954
3368
|
(_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
|
|
2955
3369
|
);
|
|
2956
|
-
const getHeaders = () =>
|
|
3370
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
2957
3371
|
{
|
|
2958
|
-
Authorization: `Bearer ${
|
|
3372
|
+
Authorization: `Bearer ${loadApiKey({
|
|
2959
3373
|
apiKey: options.apiKey,
|
|
2960
3374
|
environmentVariableName: "XAI_API_KEY",
|
|
2961
3375
|
description: "xAI API key"
|
|
@@ -2969,7 +3383,7 @@ function createXai(options = {}) {
|
|
|
2969
3383
|
provider: "xai.chat",
|
|
2970
3384
|
baseURL,
|
|
2971
3385
|
headers: getHeaders,
|
|
2972
|
-
generateId
|
|
3386
|
+
generateId,
|
|
2973
3387
|
fetch: options.fetch
|
|
2974
3388
|
});
|
|
2975
3389
|
};
|
|
@@ -2978,7 +3392,7 @@ function createXai(options = {}) {
|
|
|
2978
3392
|
provider: "xai.responses",
|
|
2979
3393
|
baseURL,
|
|
2980
3394
|
headers: getHeaders,
|
|
2981
|
-
generateId
|
|
3395
|
+
generateId,
|
|
2982
3396
|
fetch: options.fetch
|
|
2983
3397
|
});
|
|
2984
3398
|
};
|
|
@@ -2998,25 +3412,31 @@ function createXai(options = {}) {
|
|
|
2998
3412
|
fetch: options.fetch
|
|
2999
3413
|
});
|
|
3000
3414
|
};
|
|
3001
|
-
const
|
|
3002
|
-
|
|
3003
|
-
|
|
3415
|
+
const createFiles = () => new XaiFiles({
|
|
3416
|
+
provider: "xai.files",
|
|
3417
|
+
baseURL,
|
|
3418
|
+
headers: getHeaders,
|
|
3419
|
+
fetch: options.fetch
|
|
3420
|
+
});
|
|
3421
|
+
const provider = (modelId) => createResponsesLanguageModel(modelId);
|
|
3422
|
+
provider.specificationVersion = "v4";
|
|
3423
|
+
provider.languageModel = createResponsesLanguageModel;
|
|
3004
3424
|
provider.chat = createChatLanguageModel;
|
|
3005
3425
|
provider.responses = createResponsesLanguageModel;
|
|
3006
3426
|
provider.embeddingModel = (modelId) => {
|
|
3007
|
-
throw new
|
|
3427
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
3008
3428
|
};
|
|
3009
3429
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
3010
3430
|
provider.imageModel = createImageModel;
|
|
3011
3431
|
provider.image = createImageModel;
|
|
3012
3432
|
provider.videoModel = createVideoModel;
|
|
3013
3433
|
provider.video = createVideoModel;
|
|
3434
|
+
provider.files = createFiles;
|
|
3014
3435
|
provider.tools = xaiTools;
|
|
3015
3436
|
return provider;
|
|
3016
3437
|
}
|
|
3017
3438
|
var xai = createXai();
|
|
3018
|
-
|
|
3019
|
-
0 && (module.exports = {
|
|
3439
|
+
export {
|
|
3020
3440
|
VERSION,
|
|
3021
3441
|
codeExecution,
|
|
3022
3442
|
createXai,
|
|
@@ -3027,5 +3447,5 @@ var xai = createXai();
|
|
|
3027
3447
|
xSearch,
|
|
3028
3448
|
xai,
|
|
3029
3449
|
xaiTools
|
|
3030
|
-
}
|
|
3450
|
+
};
|
|
3031
3451
|
//# sourceMappingURL=index.js.map
|