@ai-sdk/xai 4.0.0-beta.6 → 4.0.0-beta.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +667 -9
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +218 -68
  4. package/dist/index.js +2081 -779
  5. package/dist/index.js.map +1 -1
  6. package/docs/01-xai.mdx +445 -54
  7. package/package.json +15 -15
  8. package/src/convert-to-xai-chat-messages.ts +48 -27
  9. package/src/convert-xai-chat-usage.ts +3 -3
  10. package/src/files/xai-files-api.ts +16 -0
  11. package/src/files/xai-files-options.ts +19 -0
  12. package/src/files/xai-files.ts +94 -0
  13. package/src/index.ts +9 -4
  14. package/src/map-xai-finish-reason.ts +2 -2
  15. package/src/realtime/index.ts +2 -0
  16. package/src/realtime/xai-realtime-event-mapper.ts +399 -0
  17. package/src/realtime/xai-realtime-model-options.ts +3 -0
  18. package/src/realtime/xai-realtime-model.ts +101 -0
  19. package/src/remove-additional-properties.ts +24 -0
  20. package/src/responses/convert-to-xai-responses-input.ts +100 -23
  21. package/src/responses/convert-xai-responses-usage.ts +3 -3
  22. package/src/responses/map-xai-responses-finish-reason.ts +3 -2
  23. package/src/responses/xai-responses-api.ts +34 -1
  24. package/src/responses/{xai-responses-options.ts → xai-responses-language-model-options.ts} +13 -7
  25. package/src/responses/xai-responses-language-model.ts +173 -64
  26. package/src/responses/xai-responses-prepare-tools.ts +10 -8
  27. package/src/tool/code-execution.ts +2 -2
  28. package/src/tool/file-search.ts +2 -2
  29. package/src/tool/mcp-server.ts +2 -2
  30. package/src/tool/view-image.ts +2 -2
  31. package/src/tool/view-x-video.ts +2 -2
  32. package/src/tool/web-search.ts +4 -2
  33. package/src/tool/x-search.ts +2 -2
  34. package/src/{xai-chat-options.ts → xai-chat-language-model-options.ts} +28 -13
  35. package/src/xai-chat-language-model.ts +65 -29
  36. package/src/xai-chat-prompt.ts +2 -1
  37. package/src/xai-error.ts +13 -3
  38. package/src/xai-image-model.ts +28 -11
  39. package/src/xai-prepare-tools.ts +9 -8
  40. package/src/xai-provider.ts +115 -19
  41. package/src/xai-speech-model-options.ts +55 -0
  42. package/src/xai-speech-model.ts +167 -0
  43. package/src/xai-transcription-model-options.ts +70 -0
  44. package/src/xai-transcription-model.ts +166 -0
  45. package/src/xai-video-model-options.ts +145 -0
  46. package/src/xai-video-model.ts +129 -22
  47. package/dist/index.d.mts +0 -372
  48. package/dist/index.mjs +0 -3061
  49. package/dist/index.mjs.map +0 -1
  50. package/src/xai-video-options.ts +0 -23
  51. /package/src/{xai-image-options.ts → xai-image-model-options.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,50 +1,44 @@
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
- var import_provider7 = require("@ai-sdk/provider");
38
- var import_provider_utils17 = require("@ai-sdk/provider-utils");
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
- var import_provider3 = require("@ai-sdk/provider");
42
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
43
- var import_v43 = require("zod/v4");
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
- var import_provider = require("@ai-sdk/provider");
47
- var import_provider_utils = require("@ai-sdk/provider-utils");
33
+ import {
34
+ UnsupportedFunctionalityError
35
+ } from "@ai-sdk/provider";
36
+ import {
37
+ convertToBase64,
38
+ getTopLevelMediaType,
39
+ resolveFullMediaType,
40
+ resolveProviderReference
41
+ } from "@ai-sdk/provider-utils";
48
42
  function convertToXaiChatMessages(prompt) {
49
43
  var _a;
50
44
  const messages = [];
@@ -68,18 +62,38 @@ function convertToXaiChatMessages(prompt) {
68
62
  return { type: "text", text: part.text };
69
63
  }
70
64
  case "file": {
71
- if (part.mediaType.startsWith("image/")) {
72
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
73
- return {
74
- type: "image_url",
75
- image_url: {
76
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
65
+ switch (part.data.type) {
66
+ case "reference": {
67
+ return {
68
+ type: "file",
69
+ file: {
70
+ file_id: resolveProviderReference({
71
+ reference: part.data.reference,
72
+ provider: "xai"
73
+ })
74
+ }
75
+ };
76
+ }
77
+ case "text": {
78
+ throw new UnsupportedFunctionalityError({
79
+ functionality: "text file parts"
80
+ });
81
+ }
82
+ case "url":
83
+ case "data": {
84
+ if (getTopLevelMediaType(part.mediaType) === "image") {
85
+ return {
86
+ type: "image_url",
87
+ image_url: {
88
+ url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
89
+ }
90
+ };
91
+ } else {
92
+ throw new UnsupportedFunctionalityError({
93
+ functionality: `file part media type ${part.mediaType}`
94
+ });
77
95
  }
78
- };
79
- } else {
80
- throw new import_provider.UnsupportedFunctionalityError({
81
- functionality: `file part media type ${part.mediaType}`
82
- });
96
+ }
83
97
  }
84
98
  }
85
99
  }
@@ -129,7 +143,7 @@ function convertToXaiChatMessages(prompt) {
129
143
  contentValue = output.value;
130
144
  break;
131
145
  case "execution-denied":
132
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
146
+ contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
133
147
  break;
134
148
  case "content":
135
149
  case "json":
@@ -208,80 +222,103 @@ function mapXaiFinishReason(finishReason) {
208
222
  }
209
223
  }
210
224
 
211
- // src/xai-chat-options.ts
212
- var import_v4 = require("zod/v4");
213
- var webSourceSchema = import_v4.z.object({
214
- type: import_v4.z.literal("web"),
215
- country: import_v4.z.string().length(2).optional(),
216
- excludedWebsites: import_v4.z.array(import_v4.z.string()).max(5).optional(),
217
- allowedWebsites: import_v4.z.array(import_v4.z.string()).max(5).optional(),
218
- safeSearch: import_v4.z.boolean().optional()
225
+ // src/xai-chat-language-model-options.ts
226
+ import { z } from "zod/v4";
227
+ var webSourceSchema = z.object({
228
+ type: z.literal("web"),
229
+ country: z.string().length(2).optional(),
230
+ excludedWebsites: z.array(z.string()).max(5).optional(),
231
+ allowedWebsites: z.array(z.string()).max(5).optional(),
232
+ safeSearch: z.boolean().optional()
219
233
  });
220
- var xSourceSchema = import_v4.z.object({
221
- type: import_v4.z.literal("x"),
222
- excludedXHandles: import_v4.z.array(import_v4.z.string()).optional(),
223
- includedXHandles: import_v4.z.array(import_v4.z.string()).optional(),
224
- postFavoriteCount: import_v4.z.number().int().optional(),
225
- postViewCount: import_v4.z.number().int().optional(),
234
+ var xSourceSchema = z.object({
235
+ type: z.literal("x"),
236
+ excludedXHandles: z.array(z.string()).optional(),
237
+ includedXHandles: z.array(z.string()).optional(),
238
+ postFavoriteCount: z.number().int().optional(),
239
+ postViewCount: z.number().int().optional(),
226
240
  /**
227
241
  * @deprecated use `includedXHandles` instead
228
242
  */
229
- xHandles: import_v4.z.array(import_v4.z.string()).optional()
243
+ xHandles: z.array(z.string()).optional()
230
244
  });
231
- var newsSourceSchema = import_v4.z.object({
232
- type: import_v4.z.literal("news"),
233
- country: import_v4.z.string().length(2).optional(),
234
- excludedWebsites: import_v4.z.array(import_v4.z.string()).max(5).optional(),
235
- safeSearch: import_v4.z.boolean().optional()
245
+ var newsSourceSchema = z.object({
246
+ type: z.literal("news"),
247
+ country: z.string().length(2).optional(),
248
+ excludedWebsites: z.array(z.string()).max(5).optional(),
249
+ safeSearch: z.boolean().optional()
236
250
  });
237
- var rssSourceSchema = import_v4.z.object({
238
- type: import_v4.z.literal("rss"),
239
- links: import_v4.z.array(import_v4.z.string().url()).max(1)
251
+ var rssSourceSchema = z.object({
252
+ type: z.literal("rss"),
253
+ links: z.array(z.string().url()).max(1)
240
254
  // currently only supports one RSS link
241
255
  });
242
- var searchSourceSchema = import_v4.z.discriminatedUnion("type", [
256
+ var searchSourceSchema = z.discriminatedUnion("type", [
243
257
  webSourceSchema,
244
258
  xSourceSchema,
245
259
  newsSourceSchema,
246
260
  rssSourceSchema
247
261
  ]);
248
- var xaiLanguageModelChatOptions = import_v4.z.object({
249
- reasoningEffort: import_v4.z.enum(["low", "high"]).optional(),
250
- logprobs: import_v4.z.boolean().optional(),
251
- topLogprobs: import_v4.z.number().int().min(0).max(8).optional(),
262
+ var xaiLanguageModelChatOptions = z.object({
263
+ /**
264
+ * Constrains how hard a reasoning model thinks before responding.
265
+ *
266
+ * - `none`: Disables reasoning entirely (supported by `grok-4.3` and newer
267
+ * reasoning models). When set, no thinking tokens are used.
268
+ * - `low` (default): Uses some reasoning tokens, but still fast.
269
+ * - `medium`: More thinking for less-latency-sensitive applications.
270
+ * - `high`: Uses more reasoning tokens for deeper thinking.
271
+ *
272
+ * Note: Not every Grok model accepts every value. Refer to xAI's docs for
273
+ * the values supported by your selected model.
274
+ *
275
+ * @see https://docs.x.ai/docs/guides/reasoning
276
+ */
277
+ reasoningEffort: z.enum(["none", "low", "medium", "high"]).optional(),
278
+ logprobs: z.boolean().optional(),
279
+ topLogprobs: z.number().int().min(0).max(8).optional(),
252
280
  /**
253
281
  * Whether to enable parallel function calling during tool use.
254
282
  * When true, the model can call multiple functions in parallel.
255
283
  * When false, the model will call functions sequentially.
256
284
  * Defaults to true.
257
285
  */
258
- parallel_function_calling: import_v4.z.boolean().optional(),
259
- searchParameters: import_v4.z.object({
286
+ parallel_function_calling: z.boolean().optional(),
287
+ /**
288
+ * @deprecated xAI has deprecated Live Search (`search_parameters`) in favor
289
+ * of the Agent Tools API. Requests using this option now return a "Live
290
+ * search is deprecated" error. Use the `web_search` / `x_search` tools
291
+ * instead (e.g. `xai.tools.webSearch()`, `xai.tools.xSearch()`) with
292
+ * `xai.responses(modelId)`.
293
+ *
294
+ * @see https://docs.x.ai/docs/guides/tools/overview
295
+ */
296
+ searchParameters: z.object({
260
297
  /**
261
298
  * search mode preference
262
299
  * - "off": disables search completely
263
300
  * - "auto": model decides whether to search (default)
264
301
  * - "on": always enables search
265
302
  */
266
- mode: import_v4.z.enum(["off", "auto", "on"]),
303
+ mode: z.enum(["off", "auto", "on"]),
267
304
  /**
268
305
  * whether to return citations in the response
269
306
  * defaults to true
270
307
  */
271
- returnCitations: import_v4.z.boolean().optional(),
308
+ returnCitations: z.boolean().optional(),
272
309
  /**
273
310
  * start date for search data (ISO8601 format: YYYY-MM-DD)
274
311
  */
275
- fromDate: import_v4.z.string().optional(),
312
+ fromDate: z.string().optional(),
276
313
  /**
277
314
  * end date for search data (ISO8601 format: YYYY-MM-DD)
278
315
  */
279
- toDate: import_v4.z.string().optional(),
316
+ toDate: z.string().optional(),
280
317
  /**
281
318
  * maximum number of search results to consider
282
319
  * defaults to 20
283
320
  */
284
- maxSearchResults: import_v4.z.number().min(1).max(50).optional(),
321
+ maxSearchResults: z.number().min(1).max(50).optional(),
285
322
  /**
286
323
  * data sources to search from.
287
324
  * defaults to [{ type: 'web' }, { type: 'x' }] if not specified.
@@ -289,28 +326,58 @@ var xaiLanguageModelChatOptions = import_v4.z.object({
289
326
  * @example
290
327
  * sources: [{ type: 'web', country: 'US' }, { type: 'x' }]
291
328
  */
292
- sources: import_v4.z.array(searchSourceSchema).optional()
329
+ sources: z.array(searchSourceSchema).optional()
293
330
  }).optional()
294
331
  });
295
332
 
296
333
  // src/xai-error.ts
297
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
298
- var import_v42 = require("zod/v4");
299
- var xaiErrorDataSchema = import_v42.z.object({
300
- error: import_v42.z.object({
301
- message: import_v42.z.string(),
302
- type: import_v42.z.string().nullish(),
303
- param: import_v42.z.any().nullish(),
304
- code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
334
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
335
+ import { z as z2 } from "zod/v4";
336
+ var chatCompletionsErrorSchema = z2.object({
337
+ error: z2.object({
338
+ message: z2.string(),
339
+ type: z2.string().nullish(),
340
+ param: z2.any().nullish(),
341
+ code: z2.union([z2.string(), z2.number()]).nullish()
305
342
  })
306
343
  });
307
- var xaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
344
+ var responsesErrorSchema = z2.object({
345
+ code: z2.string(),
346
+ error: z2.string()
347
+ });
348
+ var xaiErrorDataSchema = z2.union([
349
+ chatCompletionsErrorSchema,
350
+ responsesErrorSchema
351
+ ]);
352
+ var xaiFailedResponseHandler = createJsonErrorResponseHandler({
308
353
  errorSchema: xaiErrorDataSchema,
309
- errorToMessage: (data) => data.error.message
354
+ errorToMessage: (data) => "code" in data ? `${data.code}: ${data.error}` : data.error.message
310
355
  });
311
356
 
312
357
  // src/xai-prepare-tools.ts
313
- var import_provider2 = require("@ai-sdk/provider");
358
+ import {
359
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
360
+ } from "@ai-sdk/provider";
361
+
362
+ // src/remove-additional-properties.ts
363
+ function removeAdditionalPropertiesFalse(value) {
364
+ if (Array.isArray(value)) {
365
+ return value.map(removeAdditionalPropertiesFalse);
366
+ }
367
+ if (value == null || typeof value !== "object") {
368
+ return value;
369
+ }
370
+ const result = {};
371
+ for (const [key, propertyValue] of Object.entries(value)) {
372
+ if (key === "additionalProperties" && propertyValue === false) {
373
+ continue;
374
+ }
375
+ result[key] = removeAdditionalPropertiesFalse(propertyValue);
376
+ }
377
+ return result;
378
+ }
379
+
380
+ // src/xai-prepare-tools.ts
314
381
  function prepareTools({
315
382
  tools,
316
383
  toolChoice
@@ -333,7 +400,7 @@ function prepareTools({
333
400
  function: {
334
401
  name: tool.name,
335
402
  description: tool.description,
336
- parameters: tool.inputSchema,
403
+ parameters: removeAdditionalPropertiesFalse(tool.inputSchema),
337
404
  ...tool.strict != null ? { strict: tool.strict } : {}
338
405
  }
339
406
  });
@@ -360,7 +427,7 @@ function prepareTools({
360
427
  };
361
428
  default: {
362
429
  const _exhaustiveCheck = type;
363
- throw new import_provider2.UnsupportedFunctionalityError({
430
+ throw new UnsupportedFunctionalityError2({
364
431
  functionality: `tool choice type: ${_exhaustiveCheck}`
365
432
  });
366
433
  }
@@ -368,15 +435,24 @@ function prepareTools({
368
435
  }
369
436
 
370
437
  // src/xai-chat-language-model.ts
371
- var XaiChatLanguageModel = class {
438
+ var XaiChatLanguageModel = class _XaiChatLanguageModel {
372
439
  constructor(modelId, config) {
373
- this.specificationVersion = "v3";
440
+ this.specificationVersion = "v4";
374
441
  this.supportedUrls = {
375
442
  "image/*": [/^https?:\/\/.*$/]
376
443
  };
377
444
  this.modelId = modelId;
378
445
  this.config = config;
379
446
  }
447
+ static [WORKFLOW_SERIALIZE](model) {
448
+ return serializeModelOptions({
449
+ modelId: model.modelId,
450
+ config: model.config
451
+ });
452
+ }
453
+ static [WORKFLOW_DESERIALIZE](options) {
454
+ return new _XaiChatLanguageModel(options.modelId, options.config);
455
+ }
380
456
  get provider() {
381
457
  return this.config.provider;
382
458
  }
@@ -390,14 +466,15 @@ var XaiChatLanguageModel = class {
390
466
  presencePenalty,
391
467
  stopSequences,
392
468
  seed,
469
+ reasoning,
393
470
  responseFormat,
394
471
  providerOptions,
395
472
  tools,
396
473
  toolChoice
397
474
  }) {
398
- var _a, _b, _c;
475
+ var _a, _b, _c, _d;
399
476
  const warnings = [];
400
- const options = (_a = await (0, import_provider_utils3.parseProviderOptions)({
477
+ const options = (_a = await parseProviderOptions({
401
478
  provider: "xai",
402
479
  providerOptions,
403
480
  schema: xaiLanguageModelChatOptions
@@ -435,14 +512,24 @@ var XaiChatLanguageModel = class {
435
512
  temperature,
436
513
  top_p: topP,
437
514
  seed,
438
- reasoning_effort: options.reasoningEffort,
515
+ reasoning_effort: (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort({
516
+ reasoning,
517
+ effortMap: {
518
+ minimal: "low",
519
+ low: "low",
520
+ medium: "medium",
521
+ high: "high",
522
+ xhigh: "high"
523
+ },
524
+ warnings
525
+ }) : void 0,
439
526
  // parallel function calling
440
527
  parallel_function_calling: options.parallel_function_calling,
441
528
  // response format
442
529
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
443
530
  type: "json_schema",
444
531
  json_schema: {
445
- name: (_b = responseFormat.name) != null ? _b : "response",
532
+ name: (_c = responseFormat.name) != null ? _c : "response",
446
533
  schema: responseFormat.schema,
447
534
  strict: true
448
535
  }
@@ -454,7 +541,7 @@ var XaiChatLanguageModel = class {
454
541
  from_date: options.searchParameters.fromDate,
455
542
  to_date: options.searchParameters.toDate,
456
543
  max_search_results: options.searchParameters.maxSearchResults,
457
- sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
544
+ sources: (_d = options.searchParameters.sources) == null ? void 0 : _d.map((source) => {
458
545
  var _a2;
459
546
  return {
460
547
  type: source.type,
@@ -493,26 +580,26 @@ var XaiChatLanguageModel = class {
493
580
  };
494
581
  }
495
582
  async doGenerate(options) {
496
- var _a, _b;
583
+ var _a, _b, _c, _d;
497
584
  const { args: body, warnings } = await this.getArgs(options);
498
585
  const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
499
586
  const {
500
587
  responseHeaders,
501
588
  value: response,
502
589
  rawValue: rawResponse
503
- } = await (0, import_provider_utils3.postJsonToApi)({
590
+ } = await postJsonToApi({
504
591
  url,
505
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
592
+ headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
506
593
  body,
507
594
  failedResponseHandler: xaiFailedResponseHandler,
508
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
595
+ successfulResponseHandler: createJsonResponseHandler(
509
596
  xaiChatResponseSchema
510
597
  ),
511
598
  abortSignal: options.abortSignal,
512
599
  fetch: this.config.fetch
513
600
  });
514
601
  if (response.error != null) {
515
- throw new import_provider3.APICallError({
602
+ throw new APICallError({
516
603
  message: response.error,
517
604
  url,
518
605
  requestBodyValues: body,
@@ -564,7 +651,7 @@ var XaiChatLanguageModel = class {
564
651
  content,
565
652
  finishReason: {
566
653
  unified: mapXaiFinishReason(choice.finish_reason),
567
- raw: (_b = choice.finish_reason) != null ? _b : void 0
654
+ raw: (_d = choice.finish_reason) != null ? _d : void 0
568
655
  },
569
656
  usage: response.usage ? convertXaiChatUsage(response.usage) : {
570
657
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
@@ -580,7 +667,7 @@ var XaiChatLanguageModel = class {
580
667
  };
581
668
  }
582
669
  async doStream(options) {
583
- var _a;
670
+ var _a, _b, _c;
584
671
  const { args, warnings } = await this.getArgs(options);
585
672
  const body = {
586
673
  ...args,
@@ -590,22 +677,22 @@ var XaiChatLanguageModel = class {
590
677
  }
591
678
  };
592
679
  const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
593
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
680
+ const { responseHeaders, value: response } = await postJsonToApi({
594
681
  url,
595
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
682
+ headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
596
683
  body,
597
684
  failedResponseHandler: xaiFailedResponseHandler,
598
685
  successfulResponseHandler: async ({ response: response2 }) => {
599
- const responseHeaders2 = (0, import_provider_utils3.extractResponseHeaders)(response2);
686
+ const responseHeaders2 = extractResponseHeaders(response2);
600
687
  const contentType = response2.headers.get("content-type");
601
688
  if (contentType == null ? void 0 : contentType.includes("application/json")) {
602
689
  const responseBody = await response2.text();
603
- const parsedError = await (0, import_provider_utils3.safeParseJSON)({
690
+ const parsedError = await safeParseJSON({
604
691
  text: responseBody,
605
692
  schema: xaiStreamErrorSchema
606
693
  });
607
694
  if (parsedError.success) {
608
- throw new import_provider3.APICallError({
695
+ throw new APICallError({
609
696
  message: parsedError.value.error,
610
697
  url,
611
698
  requestBodyValues: body,
@@ -615,7 +702,7 @@ var XaiChatLanguageModel = class {
615
702
  isRetryable: parsedError.value.code === "The service is currently unavailable"
616
703
  });
617
704
  }
618
- throw new import_provider3.APICallError({
705
+ throw new APICallError({
619
706
  message: "Invalid JSON response",
620
707
  url,
621
708
  requestBodyValues: body,
@@ -624,7 +711,7 @@ var XaiChatLanguageModel = class {
624
711
  responseBody
625
712
  });
626
713
  }
627
- return (0, import_provider_utils3.createEventSourceResponseHandler)(xaiChatChunkSchema)({
714
+ return createEventSourceResponseHandler(xaiChatChunkSchema)({
628
715
  response: response2,
629
716
  url,
630
717
  requestBodyValues: body
@@ -802,113 +889,134 @@ var XaiChatLanguageModel = class {
802
889
  };
803
890
  }
804
891
  };
805
- var xaiUsageSchema = import_v43.z.object({
806
- prompt_tokens: import_v43.z.number(),
807
- completion_tokens: import_v43.z.number(),
808
- total_tokens: import_v43.z.number(),
809
- prompt_tokens_details: import_v43.z.object({
810
- text_tokens: import_v43.z.number().nullish(),
811
- audio_tokens: import_v43.z.number().nullish(),
812
- image_tokens: import_v43.z.number().nullish(),
813
- cached_tokens: import_v43.z.number().nullish()
892
+ var xaiUsageSchema = z3.object({
893
+ prompt_tokens: z3.number(),
894
+ completion_tokens: z3.number(),
895
+ total_tokens: z3.number(),
896
+ prompt_tokens_details: z3.object({
897
+ text_tokens: z3.number().nullish(),
898
+ audio_tokens: z3.number().nullish(),
899
+ image_tokens: z3.number().nullish(),
900
+ cached_tokens: z3.number().nullish()
814
901
  }).nullish(),
815
- completion_tokens_details: import_v43.z.object({
816
- reasoning_tokens: import_v43.z.number().nullish(),
817
- audio_tokens: import_v43.z.number().nullish(),
818
- accepted_prediction_tokens: import_v43.z.number().nullish(),
819
- rejected_prediction_tokens: import_v43.z.number().nullish()
902
+ completion_tokens_details: z3.object({
903
+ reasoning_tokens: z3.number().nullish(),
904
+ audio_tokens: z3.number().nullish(),
905
+ accepted_prediction_tokens: z3.number().nullish(),
906
+ rejected_prediction_tokens: z3.number().nullish()
820
907
  }).nullish()
821
908
  });
822
- var xaiChatResponseSchema = import_v43.z.object({
823
- id: import_v43.z.string().nullish(),
824
- created: import_v43.z.number().nullish(),
825
- model: import_v43.z.string().nullish(),
826
- choices: import_v43.z.array(
827
- import_v43.z.object({
828
- message: import_v43.z.object({
829
- role: import_v43.z.literal("assistant"),
830
- content: import_v43.z.string().nullish(),
831
- reasoning_content: import_v43.z.string().nullish(),
832
- tool_calls: import_v43.z.array(
833
- import_v43.z.object({
834
- id: import_v43.z.string(),
835
- type: import_v43.z.literal("function"),
836
- function: import_v43.z.object({
837
- name: import_v43.z.string(),
838
- arguments: import_v43.z.string()
909
+ var xaiChatResponseSchema = z3.object({
910
+ id: z3.string().nullish(),
911
+ created: z3.number().nullish(),
912
+ model: z3.string().nullish(),
913
+ choices: z3.array(
914
+ z3.object({
915
+ message: z3.object({
916
+ role: z3.literal("assistant"),
917
+ content: z3.string().nullish(),
918
+ reasoning_content: z3.string().nullish(),
919
+ tool_calls: z3.array(
920
+ z3.object({
921
+ id: z3.string(),
922
+ type: z3.literal("function"),
923
+ function: z3.object({
924
+ name: z3.string(),
925
+ arguments: z3.string()
839
926
  })
840
927
  })
841
928
  ).nullish()
842
929
  }),
843
- index: import_v43.z.number(),
844
- finish_reason: import_v43.z.string().nullish()
930
+ index: z3.number(),
931
+ finish_reason: z3.string().nullish()
845
932
  })
846
933
  ).nullish(),
847
- object: import_v43.z.literal("chat.completion").nullish(),
934
+ object: z3.literal("chat.completion").nullish(),
848
935
  usage: xaiUsageSchema.nullish(),
849
- citations: import_v43.z.array(import_v43.z.string().url()).nullish(),
850
- code: import_v43.z.string().nullish(),
851
- error: import_v43.z.string().nullish()
936
+ citations: z3.array(z3.string().url()).nullish(),
937
+ code: z3.string().nullish(),
938
+ error: z3.string().nullish()
852
939
  });
853
- var xaiChatChunkSchema = import_v43.z.object({
854
- id: import_v43.z.string().nullish(),
855
- created: import_v43.z.number().nullish(),
856
- model: import_v43.z.string().nullish(),
857
- choices: import_v43.z.array(
858
- import_v43.z.object({
859
- delta: import_v43.z.object({
860
- role: import_v43.z.enum(["assistant"]).optional(),
861
- content: import_v43.z.string().nullish(),
862
- reasoning_content: import_v43.z.string().nullish(),
863
- tool_calls: import_v43.z.array(
864
- import_v43.z.object({
865
- id: import_v43.z.string(),
866
- type: import_v43.z.literal("function"),
867
- function: import_v43.z.object({
868
- name: import_v43.z.string(),
869
- arguments: import_v43.z.string()
940
+ var xaiChatChunkSchema = z3.object({
941
+ id: z3.string().nullish(),
942
+ created: z3.number().nullish(),
943
+ model: z3.string().nullish(),
944
+ choices: z3.array(
945
+ z3.object({
946
+ delta: z3.object({
947
+ role: z3.enum(["assistant"]).optional(),
948
+ content: z3.string().nullish(),
949
+ reasoning_content: z3.string().nullish(),
950
+ tool_calls: z3.array(
951
+ z3.object({
952
+ id: z3.string(),
953
+ type: z3.literal("function"),
954
+ function: z3.object({
955
+ name: z3.string(),
956
+ arguments: z3.string()
870
957
  })
871
958
  })
872
959
  ).nullish()
873
960
  }),
874
- finish_reason: import_v43.z.string().nullish(),
875
- index: import_v43.z.number()
961
+ finish_reason: z3.string().nullish(),
962
+ index: z3.number()
876
963
  })
877
964
  ),
878
965
  usage: xaiUsageSchema.nullish(),
879
- citations: import_v43.z.array(import_v43.z.string().url()).nullish()
966
+ citations: z3.array(z3.string().url()).nullish()
880
967
  });
881
- var xaiStreamErrorSchema = import_v43.z.object({
882
- code: import_v43.z.string(),
883
- error: import_v43.z.string()
968
+ var xaiStreamErrorSchema = z3.object({
969
+ code: z3.string(),
970
+ error: z3.string()
884
971
  });
885
972
 
886
973
  // src/xai-image-model.ts
887
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
888
- var import_v45 = require("zod/v4");
974
+ import {
975
+ combineHeaders as combineHeaders2,
976
+ convertImageModelFileToDataUri,
977
+ createBinaryResponseHandler,
978
+ createJsonResponseHandler as createJsonResponseHandler2,
979
+ createStatusCodeErrorResponseHandler,
980
+ getFromApi,
981
+ parseProviderOptions as parseProviderOptions2,
982
+ postJsonToApi as postJsonToApi2,
983
+ serializeModelOptions as serializeModelOptions2,
984
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
985
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
986
+ } from "@ai-sdk/provider-utils";
987
+ import { z as z5 } from "zod/v4";
889
988
 
890
- // src/xai-image-options.ts
891
- var import_v44 = require("zod/v4");
892
- var xaiImageModelOptions = import_v44.z.object({
893
- aspect_ratio: import_v44.z.string().optional(),
894
- output_format: import_v44.z.string().optional(),
895
- sync_mode: import_v44.z.boolean().optional(),
896
- resolution: import_v44.z.enum(["1k", "2k"]).optional(),
897
- quality: import_v44.z.enum(["low", "medium", "high"]).optional(),
898
- user: import_v44.z.string().optional()
989
+ // src/xai-image-model-options.ts
990
+ import { z as z4 } from "zod/v4";
991
+ var xaiImageModelOptions = z4.object({
992
+ aspect_ratio: z4.string().optional(),
993
+ output_format: z4.string().optional(),
994
+ sync_mode: z4.boolean().optional(),
995
+ resolution: z4.enum(["1k", "2k"]).optional(),
996
+ quality: z4.enum(["low", "medium", "high"]).optional(),
997
+ user: z4.string().optional()
899
998
  });
900
999
 
901
1000
  // src/xai-image-model.ts
902
- var XaiImageModel = class {
1001
+ var XaiImageModel = class _XaiImageModel {
903
1002
  constructor(modelId, config) {
904
1003
  this.modelId = modelId;
905
1004
  this.config = config;
906
- this.specificationVersion = "v3";
1005
+ this.specificationVersion = "v4";
907
1006
  this.maxImagesPerCall = 3;
908
1007
  }
909
1008
  get provider() {
910
1009
  return this.config.provider;
911
1010
  }
1011
+ static [WORKFLOW_SERIALIZE2](model) {
1012
+ return serializeModelOptions2({
1013
+ modelId: model.modelId,
1014
+ config: model.config
1015
+ });
1016
+ }
1017
+ static [WORKFLOW_DESERIALIZE2](options) {
1018
+ return new _XaiImageModel(options.modelId, options.config);
1019
+ }
912
1020
  async doGenerate({
913
1021
  prompt,
914
1022
  n,
@@ -921,7 +1029,7 @@ var XaiImageModel = class {
921
1029
  files,
922
1030
  mask
923
1031
  }) {
924
- var _a, _b, _c, _d, _e;
1032
+ var _a, _b, _c, _d, _e, _f, _g;
925
1033
  const warnings = [];
926
1034
  if (size != null) {
927
1035
  warnings.push({
@@ -942,13 +1050,13 @@ var XaiImageModel = class {
942
1050
  feature: "mask"
943
1051
  });
944
1052
  }
945
- const xaiOptions = await (0, import_provider_utils4.parseProviderOptions)({
1053
+ const xaiOptions = await parseProviderOptions2({
946
1054
  provider: "xai",
947
1055
  providerOptions,
948
1056
  schema: xaiImageModelOptions
949
1057
  });
950
1058
  const hasFiles = files != null && files.length > 0;
951
- const imageUrls = hasFiles ? files.map((file) => (0, import_provider_utils4.convertImageModelFileToDataUri)(file)) : [];
1059
+ const imageUrls = hasFiles ? files.map((file) => convertImageModelFileToDataUri(file)) : [];
952
1060
  const endpoint = hasFiles ? "/images/edits" : "/images/generations";
953
1061
  const body = {
954
1062
  model: this.modelId,
@@ -984,12 +1092,12 @@ var XaiImageModel = class {
984
1092
  }
985
1093
  const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
986
1094
  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 (0, import_provider_utils4.postJsonToApi)({
1095
+ const { value: response, responseHeaders } = await postJsonToApi2({
988
1096
  url: `${baseURL}${endpoint}`,
989
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), headers),
1097
+ headers: combineHeaders2((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
990
1098
  body,
991
1099
  failedResponseHandler: xaiFailedResponseHandler,
992
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1100
+ successfulResponseHandler: createJsonResponseHandler2(
993
1101
  xaiImageResponseSchema
994
1102
  ),
995
1103
  abortSignal,
@@ -1014,45 +1122,63 @@ var XaiImageModel = class {
1014
1122
  images: response.data.map((item) => ({
1015
1123
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
1016
1124
  })),
1017
- ...((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
1125
+ ...((_g = response.usage) == null ? void 0 : _g.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
1018
1126
  }
1019
1127
  }
1020
1128
  };
1021
1129
  }
1022
1130
  async downloadImage(url, abortSignal) {
1023
- const { value } = await (0, import_provider_utils4.getFromApi)({
1131
+ const { value } = await getFromApi({
1024
1132
  url,
1025
1133
  abortSignal,
1026
- failedResponseHandler: (0, import_provider_utils4.createStatusCodeErrorResponseHandler)(),
1027
- successfulResponseHandler: (0, import_provider_utils4.createBinaryResponseHandler)(),
1134
+ failedResponseHandler: createStatusCodeErrorResponseHandler(),
1135
+ successfulResponseHandler: createBinaryResponseHandler(),
1028
1136
  fetch: this.config.fetch
1029
1137
  });
1030
1138
  return value;
1031
1139
  }
1032
1140
  };
1033
- var xaiImageResponseSchema = import_v45.z.object({
1034
- data: import_v45.z.array(
1035
- import_v45.z.object({
1036
- url: import_v45.z.string().nullish(),
1037
- b64_json: import_v45.z.string().nullish(),
1038
- revised_prompt: import_v45.z.string().nullish()
1141
+ var xaiImageResponseSchema = z5.object({
1142
+ data: z5.array(
1143
+ z5.object({
1144
+ url: z5.string().nullish(),
1145
+ b64_json: z5.string().nullish(),
1146
+ revised_prompt: z5.string().nullish()
1039
1147
  })
1040
1148
  ),
1041
- usage: import_v45.z.object({
1042
- cost_in_usd_ticks: import_v45.z.number().nullish()
1149
+ usage: z5.object({
1150
+ cost_in_usd_ticks: z5.number().nullish()
1043
1151
  }).nullish()
1044
1152
  });
1045
1153
 
1046
1154
  // src/responses/xai-responses-language-model.ts
1047
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
1155
+ import {
1156
+ combineHeaders as combineHeaders3,
1157
+ createEventSourceResponseHandler as createEventSourceResponseHandler2,
1158
+ createJsonResponseHandler as createJsonResponseHandler3,
1159
+ isCustomReasoning as isCustomReasoning2,
1160
+ mapReasoningToProviderEffort as mapReasoningToProviderEffort2,
1161
+ parseProviderOptions as parseProviderOptions3,
1162
+ postJsonToApi as postJsonToApi3,
1163
+ serializeModelOptions as serializeModelOptions3,
1164
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
1165
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
1166
+ } from "@ai-sdk/provider-utils";
1048
1167
 
1049
1168
  // src/responses/convert-to-xai-responses-input.ts
1050
- var import_provider4 = require("@ai-sdk/provider");
1051
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1169
+ import {
1170
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError3
1171
+ } from "@ai-sdk/provider";
1172
+ import {
1173
+ convertToBase64 as convertToBase642,
1174
+ getTopLevelMediaType as getTopLevelMediaType2,
1175
+ resolveFullMediaType as resolveFullMediaType2,
1176
+ resolveProviderReference as resolveProviderReference2
1177
+ } from "@ai-sdk/provider-utils";
1052
1178
  async function convertToXaiResponsesInput({
1053
1179
  prompt
1054
1180
  }) {
1055
- var _a, _b, _c, _d, _e;
1181
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1056
1182
  const input = [];
1057
1183
  const inputWarnings = [];
1058
1184
  for (const message of prompt) {
@@ -1073,14 +1199,42 @@ async function convertToXaiResponsesInput({
1073
1199
  break;
1074
1200
  }
1075
1201
  case "file": {
1076
- if (block.mediaType.startsWith("image/")) {
1077
- const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
1078
- const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`;
1079
- contentParts.push({ type: "input_image", image_url: imageUrl });
1080
- } else {
1081
- throw new import_provider4.UnsupportedFunctionalityError({
1082
- functionality: `file part media type ${block.mediaType}`
1083
- });
1202
+ switch (block.data.type) {
1203
+ case "reference": {
1204
+ contentParts.push({
1205
+ type: "input_file",
1206
+ file_id: resolveProviderReference2({
1207
+ reference: block.data.reference,
1208
+ provider: "xai"
1209
+ })
1210
+ });
1211
+ break;
1212
+ }
1213
+ case "text": {
1214
+ throw new UnsupportedFunctionalityError3({
1215
+ functionality: "text file parts"
1216
+ });
1217
+ }
1218
+ case "url":
1219
+ case "data": {
1220
+ if (getTopLevelMediaType2(block.mediaType) === "image") {
1221
+ const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${resolveFullMediaType2({ part: block })};base64,${convertToBase642(block.data.data)}`;
1222
+ contentParts.push({
1223
+ type: "input_image",
1224
+ image_url: imageUrl
1225
+ });
1226
+ } else if (block.data.type === "url") {
1227
+ contentParts.push({
1228
+ type: "input_file",
1229
+ file_url: block.data.url.toString()
1230
+ });
1231
+ } else {
1232
+ throw new UnsupportedFunctionalityError3({
1233
+ functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
1234
+ });
1235
+ }
1236
+ break;
1237
+ }
1084
1238
  }
1085
1239
  break;
1086
1240
  }
@@ -1129,7 +1283,36 @@ async function convertToXaiResponsesInput({
1129
1283
  case "tool-result": {
1130
1284
  break;
1131
1285
  }
1132
- case "reasoning":
1286
+ case "reasoning": {
1287
+ const itemId = typeof ((_f = (_e = part.providerOptions) == null ? void 0 : _e.xai) == null ? void 0 : _f.itemId) === "string" ? part.providerOptions.xai.itemId : void 0;
1288
+ const encryptedContent = typeof ((_h = (_g = part.providerOptions) == null ? void 0 : _g.xai) == null ? void 0 : _h.reasoningEncryptedContent) === "string" ? part.providerOptions.xai.reasoningEncryptedContent : void 0;
1289
+ if (itemId != null || encryptedContent != null) {
1290
+ const summaryParts = [];
1291
+ if (part.text.length > 0) {
1292
+ summaryParts.push({
1293
+ type: "summary_text",
1294
+ text: part.text
1295
+ });
1296
+ }
1297
+ input.push({
1298
+ type: "reasoning",
1299
+ id: itemId != null ? itemId : "",
1300
+ summary: summaryParts,
1301
+ status: "completed",
1302
+ ...encryptedContent != null && {
1303
+ encrypted_content: encryptedContent
1304
+ }
1305
+ });
1306
+ } else {
1307
+ inputWarnings.push({
1308
+ type: "other",
1309
+ message: "Reasoning parts without itemId or encrypted content cannot be sent back to xAI. Skipping."
1310
+ });
1311
+ }
1312
+ break;
1313
+ }
1314
+ case "reasoning-file":
1315
+ case "custom":
1133
1316
  case "file": {
1134
1317
  inputWarnings.push({
1135
1318
  type: "other",
@@ -1161,7 +1344,7 @@ async function convertToXaiResponsesInput({
1161
1344
  outputValue = output.value;
1162
1345
  break;
1163
1346
  case "execution-denied":
1164
- outputValue = (_e = output.reason) != null ? _e : "tool execution denied";
1347
+ outputValue = (_i = output.reason) != null ? _i : "tool execution denied";
1165
1348
  break;
1166
1349
  case "json":
1167
1350
  case "error-json":
@@ -1229,6 +1412,7 @@ function mapXaiResponsesFinishReason(finishReason) {
1229
1412
  case "completed":
1230
1413
  return "stop";
1231
1414
  case "length":
1415
+ case "max_output_tokens":
1232
1416
  return "length";
1233
1417
  case "tool_calls":
1234
1418
  case "function_call":
@@ -1241,568 +1425,620 @@ function mapXaiResponsesFinishReason(finishReason) {
1241
1425
  }
1242
1426
 
1243
1427
  // src/responses/xai-responses-api.ts
1244
- var import_v46 = require("zod/v4");
1245
- var annotationSchema = import_v46.z.union([
1246
- import_v46.z.object({
1247
- type: import_v46.z.literal("url_citation"),
1248
- url: import_v46.z.string(),
1249
- title: import_v46.z.string().optional()
1428
+ import { z as z6 } from "zod/v4";
1429
+ var annotationSchema = z6.union([
1430
+ z6.object({
1431
+ type: z6.literal("url_citation"),
1432
+ url: z6.string(),
1433
+ title: z6.string().optional()
1250
1434
  }),
1251
- import_v46.z.object({
1252
- type: import_v46.z.string()
1435
+ z6.object({
1436
+ type: z6.string()
1253
1437
  })
1254
1438
  ]);
1255
- var messageContentPartSchema = import_v46.z.object({
1256
- type: import_v46.z.string(),
1257
- text: import_v46.z.string().optional(),
1258
- logprobs: import_v46.z.array(import_v46.z.any()).optional(),
1259
- annotations: import_v46.z.array(annotationSchema).optional()
1439
+ var messageContentPartSchema = z6.object({
1440
+ type: z6.string(),
1441
+ text: z6.string().optional(),
1442
+ logprobs: z6.array(z6.any()).optional(),
1443
+ annotations: z6.array(annotationSchema).optional()
1260
1444
  });
1261
- var reasoningSummaryPartSchema = import_v46.z.object({
1262
- type: import_v46.z.string(),
1263
- text: import_v46.z.string()
1445
+ var reasoningSummaryPartSchema = z6.object({
1446
+ type: z6.string(),
1447
+ text: z6.string()
1264
1448
  });
1265
- var toolCallSchema = import_v46.z.object({
1266
- name: import_v46.z.string().optional(),
1267
- arguments: import_v46.z.string().optional(),
1268
- input: import_v46.z.string().optional(),
1269
- call_id: import_v46.z.string().optional(),
1270
- id: import_v46.z.string(),
1271
- status: import_v46.z.string(),
1272
- action: import_v46.z.any().optional()
1449
+ var toolCallSchema = z6.object({
1450
+ name: z6.string().optional(),
1451
+ arguments: z6.string().optional(),
1452
+ input: z6.string().optional(),
1453
+ call_id: z6.string().optional(),
1454
+ id: z6.string(),
1455
+ status: z6.string(),
1456
+ action: z6.any().optional()
1273
1457
  });
1274
- var mcpCallSchema = import_v46.z.object({
1275
- name: import_v46.z.string().optional(),
1276
- arguments: import_v46.z.string().optional(),
1277
- output: import_v46.z.string().optional(),
1278
- error: import_v46.z.string().optional(),
1279
- id: import_v46.z.string(),
1280
- status: import_v46.z.string(),
1281
- server_label: import_v46.z.string().optional()
1458
+ var mcpCallSchema = z6.object({
1459
+ name: z6.string().optional(),
1460
+ arguments: z6.string().optional(),
1461
+ output: z6.string().optional(),
1462
+ error: z6.string().optional(),
1463
+ id: z6.string(),
1464
+ status: z6.string(),
1465
+ server_label: z6.string().optional()
1282
1466
  });
1283
- var outputItemSchema = import_v46.z.discriminatedUnion("type", [
1284
- import_v46.z.object({
1285
- type: import_v46.z.literal("web_search_call"),
1467
+ var outputItemSchema = z6.discriminatedUnion("type", [
1468
+ z6.object({
1469
+ type: z6.literal("web_search_call"),
1286
1470
  ...toolCallSchema.shape
1287
1471
  }),
1288
- import_v46.z.object({
1289
- type: import_v46.z.literal("x_search_call"),
1472
+ z6.object({
1473
+ type: z6.literal("x_search_call"),
1290
1474
  ...toolCallSchema.shape
1291
1475
  }),
1292
- import_v46.z.object({
1293
- type: import_v46.z.literal("code_interpreter_call"),
1476
+ z6.object({
1477
+ type: z6.literal("code_interpreter_call"),
1294
1478
  ...toolCallSchema.shape
1295
1479
  }),
1296
- import_v46.z.object({
1297
- type: import_v46.z.literal("code_execution_call"),
1480
+ z6.object({
1481
+ type: z6.literal("code_execution_call"),
1298
1482
  ...toolCallSchema.shape
1299
1483
  }),
1300
- import_v46.z.object({
1301
- type: import_v46.z.literal("view_image_call"),
1484
+ z6.object({
1485
+ type: z6.literal("view_image_call"),
1302
1486
  ...toolCallSchema.shape
1303
1487
  }),
1304
- import_v46.z.object({
1305
- type: import_v46.z.literal("view_x_video_call"),
1488
+ z6.object({
1489
+ type: z6.literal("view_x_video_call"),
1306
1490
  ...toolCallSchema.shape
1307
1491
  }),
1308
- import_v46.z.object({
1309
- type: import_v46.z.literal("file_search_call"),
1310
- id: import_v46.z.string(),
1311
- status: import_v46.z.string(),
1312
- queries: import_v46.z.array(import_v46.z.string()).optional(),
1313
- results: import_v46.z.array(
1314
- import_v46.z.object({
1315
- file_id: import_v46.z.string(),
1316
- filename: import_v46.z.string(),
1317
- score: import_v46.z.number(),
1318
- text: import_v46.z.string()
1492
+ z6.object({
1493
+ type: z6.literal("file_search_call"),
1494
+ id: z6.string(),
1495
+ status: z6.string(),
1496
+ queries: z6.array(z6.string()).optional(),
1497
+ results: z6.array(
1498
+ z6.object({
1499
+ file_id: z6.string(),
1500
+ filename: z6.string(),
1501
+ score: z6.number(),
1502
+ text: z6.string()
1319
1503
  })
1320
1504
  ).nullish()
1321
1505
  }),
1322
- import_v46.z.object({
1323
- type: import_v46.z.literal("custom_tool_call"),
1506
+ z6.object({
1507
+ type: z6.literal("custom_tool_call"),
1324
1508
  ...toolCallSchema.shape
1325
1509
  }),
1326
- import_v46.z.object({
1327
- type: import_v46.z.literal("mcp_call"),
1510
+ z6.object({
1511
+ type: z6.literal("mcp_call"),
1328
1512
  ...mcpCallSchema.shape
1329
1513
  }),
1330
- import_v46.z.object({
1331
- type: import_v46.z.literal("message"),
1332
- role: import_v46.z.string(),
1333
- content: import_v46.z.array(messageContentPartSchema),
1334
- id: import_v46.z.string(),
1335
- status: import_v46.z.string()
1514
+ z6.object({
1515
+ type: z6.literal("message"),
1516
+ role: z6.string(),
1517
+ content: z6.array(messageContentPartSchema),
1518
+ id: z6.string(),
1519
+ status: z6.string()
1336
1520
  }),
1337
- import_v46.z.object({
1338
- type: import_v46.z.literal("function_call"),
1339
- name: import_v46.z.string(),
1340
- arguments: import_v46.z.string(),
1341
- call_id: import_v46.z.string(),
1342
- id: import_v46.z.string()
1521
+ z6.object({
1522
+ type: z6.literal("function_call"),
1523
+ name: z6.string(),
1524
+ arguments: z6.string(),
1525
+ call_id: z6.string(),
1526
+ id: z6.string()
1343
1527
  }),
1344
- import_v46.z.object({
1345
- type: import_v46.z.literal("reasoning"),
1346
- id: import_v46.z.string(),
1347
- summary: import_v46.z.array(reasoningSummaryPartSchema),
1348
- status: import_v46.z.string(),
1349
- encrypted_content: import_v46.z.string().nullish()
1528
+ z6.object({
1529
+ type: z6.literal("reasoning"),
1530
+ id: z6.string(),
1531
+ summary: z6.array(reasoningSummaryPartSchema),
1532
+ content: z6.array(z6.object({ type: z6.string(), text: z6.string() })).nullish(),
1533
+ status: z6.string(),
1534
+ encrypted_content: z6.string().nullish()
1350
1535
  })
1351
1536
  ]);
1352
- var xaiResponsesUsageSchema = import_v46.z.object({
1353
- input_tokens: import_v46.z.number(),
1354
- output_tokens: import_v46.z.number(),
1355
- total_tokens: import_v46.z.number().optional(),
1356
- input_tokens_details: import_v46.z.object({
1357
- cached_tokens: import_v46.z.number().optional()
1537
+ var xaiResponsesUsageSchema = z6.object({
1538
+ input_tokens: z6.number(),
1539
+ output_tokens: z6.number(),
1540
+ total_tokens: z6.number().optional(),
1541
+ input_tokens_details: z6.object({
1542
+ cached_tokens: z6.number().optional()
1358
1543
  }).optional(),
1359
- output_tokens_details: import_v46.z.object({
1360
- reasoning_tokens: import_v46.z.number().optional()
1544
+ output_tokens_details: z6.object({
1545
+ reasoning_tokens: z6.number().optional()
1361
1546
  }).optional(),
1362
- num_sources_used: import_v46.z.number().optional(),
1363
- num_server_side_tools_used: import_v46.z.number().optional()
1547
+ num_sources_used: z6.number().optional(),
1548
+ num_server_side_tools_used: z6.number().optional(),
1549
+ cost_in_usd_ticks: z6.number().nullish()
1364
1550
  });
1365
- var xaiResponsesResponseSchema = import_v46.z.object({
1366
- id: import_v46.z.string().nullish(),
1367
- created_at: import_v46.z.number().nullish(),
1368
- model: import_v46.z.string().nullish(),
1369
- object: import_v46.z.literal("response"),
1370
- output: import_v46.z.array(outputItemSchema),
1551
+ var xaiResponsesResponseSchema = z6.object({
1552
+ id: z6.string().nullish(),
1553
+ created_at: z6.number().nullish(),
1554
+ model: z6.string().nullish(),
1555
+ object: z6.literal("response"),
1556
+ output: z6.array(outputItemSchema),
1371
1557
  usage: xaiResponsesUsageSchema.nullish(),
1372
- status: import_v46.z.string()
1558
+ status: z6.string()
1373
1559
  });
1374
- var xaiResponsesChunkSchema = import_v46.z.union([
1375
- import_v46.z.object({
1376
- type: import_v46.z.literal("response.created"),
1560
+ var xaiResponsesChunkSchema = z6.union([
1561
+ z6.object({
1562
+ type: z6.literal("response.created"),
1377
1563
  response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
1378
1564
  }),
1379
- import_v46.z.object({
1380
- type: import_v46.z.literal("response.in_progress"),
1565
+ z6.object({
1566
+ type: z6.literal("response.in_progress"),
1381
1567
  response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
1382
1568
  }),
1383
- import_v46.z.object({
1384
- type: import_v46.z.literal("response.output_item.added"),
1569
+ z6.object({
1570
+ type: z6.literal("response.output_item.added"),
1385
1571
  item: outputItemSchema,
1386
- output_index: import_v46.z.number()
1572
+ output_index: z6.number()
1387
1573
  }),
1388
- import_v46.z.object({
1389
- type: import_v46.z.literal("response.output_item.done"),
1574
+ z6.object({
1575
+ type: z6.literal("response.output_item.done"),
1390
1576
  item: outputItemSchema,
1391
- output_index: import_v46.z.number()
1577
+ output_index: z6.number()
1392
1578
  }),
1393
- import_v46.z.object({
1394
- type: import_v46.z.literal("response.content_part.added"),
1395
- item_id: import_v46.z.string(),
1396
- output_index: import_v46.z.number(),
1397
- content_index: import_v46.z.number(),
1579
+ z6.object({
1580
+ type: z6.literal("response.content_part.added"),
1581
+ item_id: z6.string(),
1582
+ output_index: z6.number(),
1583
+ content_index: z6.number(),
1398
1584
  part: messageContentPartSchema
1399
1585
  }),
1400
- import_v46.z.object({
1401
- type: import_v46.z.literal("response.content_part.done"),
1402
- item_id: import_v46.z.string(),
1403
- output_index: import_v46.z.number(),
1404
- content_index: import_v46.z.number(),
1586
+ z6.object({
1587
+ type: z6.literal("response.content_part.done"),
1588
+ item_id: z6.string(),
1589
+ output_index: z6.number(),
1590
+ content_index: z6.number(),
1405
1591
  part: messageContentPartSchema
1406
1592
  }),
1407
- import_v46.z.object({
1408
- type: import_v46.z.literal("response.output_text.delta"),
1409
- item_id: import_v46.z.string(),
1410
- output_index: import_v46.z.number(),
1411
- content_index: import_v46.z.number(),
1412
- delta: import_v46.z.string(),
1413
- logprobs: import_v46.z.array(import_v46.z.any()).optional()
1593
+ z6.object({
1594
+ type: z6.literal("response.output_text.delta"),
1595
+ item_id: z6.string(),
1596
+ output_index: z6.number(),
1597
+ content_index: z6.number(),
1598
+ delta: z6.string(),
1599
+ logprobs: z6.array(z6.any()).optional()
1414
1600
  }),
1415
- import_v46.z.object({
1416
- type: import_v46.z.literal("response.output_text.done"),
1417
- item_id: import_v46.z.string(),
1418
- output_index: import_v46.z.number(),
1419
- content_index: import_v46.z.number(),
1420
- text: import_v46.z.string(),
1421
- logprobs: import_v46.z.array(import_v46.z.any()).optional(),
1422
- annotations: import_v46.z.array(annotationSchema).optional()
1601
+ z6.object({
1602
+ type: z6.literal("response.output_text.done"),
1603
+ item_id: z6.string(),
1604
+ output_index: z6.number(),
1605
+ content_index: z6.number(),
1606
+ text: z6.string(),
1607
+ logprobs: z6.array(z6.any()).optional(),
1608
+ annotations: z6.array(annotationSchema).optional()
1423
1609
  }),
1424
- import_v46.z.object({
1425
- type: import_v46.z.literal("response.output_text.annotation.added"),
1426
- item_id: import_v46.z.string(),
1427
- output_index: import_v46.z.number(),
1428
- content_index: import_v46.z.number(),
1429
- annotation_index: import_v46.z.number(),
1610
+ z6.object({
1611
+ type: z6.literal("response.output_text.annotation.added"),
1612
+ item_id: z6.string(),
1613
+ output_index: z6.number(),
1614
+ content_index: z6.number(),
1615
+ annotation_index: z6.number(),
1430
1616
  annotation: annotationSchema
1431
1617
  }),
1432
- import_v46.z.object({
1433
- type: import_v46.z.literal("response.reasoning_summary_part.added"),
1434
- item_id: import_v46.z.string(),
1435
- output_index: import_v46.z.number(),
1436
- summary_index: import_v46.z.number(),
1618
+ z6.object({
1619
+ type: z6.literal("response.reasoning_summary_part.added"),
1620
+ item_id: z6.string(),
1621
+ output_index: z6.number(),
1622
+ summary_index: z6.number(),
1437
1623
  part: reasoningSummaryPartSchema
1438
1624
  }),
1439
- import_v46.z.object({
1440
- type: import_v46.z.literal("response.reasoning_summary_part.done"),
1441
- item_id: import_v46.z.string(),
1442
- output_index: import_v46.z.number(),
1443
- summary_index: import_v46.z.number(),
1625
+ z6.object({
1626
+ type: z6.literal("response.reasoning_summary_part.done"),
1627
+ item_id: z6.string(),
1628
+ output_index: z6.number(),
1629
+ summary_index: z6.number(),
1444
1630
  part: reasoningSummaryPartSchema
1445
1631
  }),
1446
- import_v46.z.object({
1447
- type: import_v46.z.literal("response.reasoning_summary_text.delta"),
1448
- item_id: import_v46.z.string(),
1449
- output_index: import_v46.z.number(),
1450
- summary_index: import_v46.z.number(),
1451
- delta: import_v46.z.string()
1632
+ z6.object({
1633
+ type: z6.literal("response.reasoning_summary_text.delta"),
1634
+ item_id: z6.string(),
1635
+ output_index: z6.number(),
1636
+ summary_index: z6.number(),
1637
+ delta: z6.string()
1452
1638
  }),
1453
- import_v46.z.object({
1454
- type: import_v46.z.literal("response.reasoning_summary_text.done"),
1455
- item_id: import_v46.z.string(),
1456
- output_index: import_v46.z.number(),
1457
- summary_index: import_v46.z.number(),
1458
- text: import_v46.z.string()
1639
+ z6.object({
1640
+ type: z6.literal("response.reasoning_summary_text.done"),
1641
+ item_id: z6.string(),
1642
+ output_index: z6.number(),
1643
+ summary_index: z6.number(),
1644
+ text: z6.string()
1459
1645
  }),
1460
- import_v46.z.object({
1461
- type: import_v46.z.literal("response.reasoning_text.delta"),
1462
- item_id: import_v46.z.string(),
1463
- output_index: import_v46.z.number(),
1464
- content_index: import_v46.z.number(),
1465
- delta: import_v46.z.string()
1646
+ z6.object({
1647
+ type: z6.literal("response.reasoning_text.delta"),
1648
+ item_id: z6.string(),
1649
+ output_index: z6.number(),
1650
+ content_index: z6.number(),
1651
+ delta: z6.string()
1466
1652
  }),
1467
- import_v46.z.object({
1468
- type: import_v46.z.literal("response.reasoning_text.done"),
1469
- item_id: import_v46.z.string(),
1470
- output_index: import_v46.z.number(),
1471
- content_index: import_v46.z.number(),
1472
- text: import_v46.z.string()
1653
+ z6.object({
1654
+ type: z6.literal("response.reasoning_text.done"),
1655
+ item_id: z6.string(),
1656
+ output_index: z6.number(),
1657
+ content_index: z6.number(),
1658
+ text: z6.string()
1473
1659
  }),
1474
- import_v46.z.object({
1475
- type: import_v46.z.literal("response.web_search_call.in_progress"),
1476
- item_id: import_v46.z.string(),
1477
- output_index: import_v46.z.number()
1660
+ z6.object({
1661
+ type: z6.literal("response.web_search_call.in_progress"),
1662
+ item_id: z6.string(),
1663
+ output_index: z6.number()
1478
1664
  }),
1479
- import_v46.z.object({
1480
- type: import_v46.z.literal("response.web_search_call.searching"),
1481
- item_id: import_v46.z.string(),
1482
- output_index: import_v46.z.number()
1665
+ z6.object({
1666
+ type: z6.literal("response.web_search_call.searching"),
1667
+ item_id: z6.string(),
1668
+ output_index: z6.number()
1483
1669
  }),
1484
- import_v46.z.object({
1485
- type: import_v46.z.literal("response.web_search_call.completed"),
1486
- item_id: import_v46.z.string(),
1487
- output_index: import_v46.z.number()
1670
+ z6.object({
1671
+ type: z6.literal("response.web_search_call.completed"),
1672
+ item_id: z6.string(),
1673
+ output_index: z6.number()
1488
1674
  }),
1489
- import_v46.z.object({
1490
- type: import_v46.z.literal("response.x_search_call.in_progress"),
1491
- item_id: import_v46.z.string(),
1492
- output_index: import_v46.z.number()
1675
+ z6.object({
1676
+ type: z6.literal("response.x_search_call.in_progress"),
1677
+ item_id: z6.string(),
1678
+ output_index: z6.number()
1493
1679
  }),
1494
- import_v46.z.object({
1495
- type: import_v46.z.literal("response.x_search_call.searching"),
1496
- item_id: import_v46.z.string(),
1497
- output_index: import_v46.z.number()
1680
+ z6.object({
1681
+ type: z6.literal("response.x_search_call.searching"),
1682
+ item_id: z6.string(),
1683
+ output_index: z6.number()
1498
1684
  }),
1499
- import_v46.z.object({
1500
- type: import_v46.z.literal("response.x_search_call.completed"),
1501
- item_id: import_v46.z.string(),
1502
- output_index: import_v46.z.number()
1685
+ z6.object({
1686
+ type: z6.literal("response.x_search_call.completed"),
1687
+ item_id: z6.string(),
1688
+ output_index: z6.number()
1503
1689
  }),
1504
- import_v46.z.object({
1505
- type: import_v46.z.literal("response.file_search_call.in_progress"),
1506
- item_id: import_v46.z.string(),
1507
- output_index: import_v46.z.number()
1690
+ z6.object({
1691
+ type: z6.literal("response.file_search_call.in_progress"),
1692
+ item_id: z6.string(),
1693
+ output_index: z6.number()
1508
1694
  }),
1509
- import_v46.z.object({
1510
- type: import_v46.z.literal("response.file_search_call.searching"),
1511
- item_id: import_v46.z.string(),
1512
- output_index: import_v46.z.number()
1695
+ z6.object({
1696
+ type: z6.literal("response.file_search_call.searching"),
1697
+ item_id: z6.string(),
1698
+ output_index: z6.number()
1513
1699
  }),
1514
- import_v46.z.object({
1515
- type: import_v46.z.literal("response.file_search_call.completed"),
1516
- item_id: import_v46.z.string(),
1517
- output_index: import_v46.z.number()
1700
+ z6.object({
1701
+ type: z6.literal("response.file_search_call.completed"),
1702
+ item_id: z6.string(),
1703
+ output_index: z6.number()
1518
1704
  }),
1519
- import_v46.z.object({
1520
- type: import_v46.z.literal("response.code_execution_call.in_progress"),
1521
- item_id: import_v46.z.string(),
1522
- output_index: import_v46.z.number()
1705
+ z6.object({
1706
+ type: z6.literal("response.code_execution_call.in_progress"),
1707
+ item_id: z6.string(),
1708
+ output_index: z6.number()
1523
1709
  }),
1524
- import_v46.z.object({
1525
- type: import_v46.z.literal("response.code_execution_call.executing"),
1526
- item_id: import_v46.z.string(),
1527
- output_index: import_v46.z.number()
1710
+ z6.object({
1711
+ type: z6.literal("response.code_execution_call.executing"),
1712
+ item_id: z6.string(),
1713
+ output_index: z6.number()
1528
1714
  }),
1529
- import_v46.z.object({
1530
- type: import_v46.z.literal("response.code_execution_call.completed"),
1531
- item_id: import_v46.z.string(),
1532
- output_index: import_v46.z.number()
1715
+ z6.object({
1716
+ type: z6.literal("response.code_execution_call.completed"),
1717
+ item_id: z6.string(),
1718
+ output_index: z6.number()
1533
1719
  }),
1534
- import_v46.z.object({
1535
- type: import_v46.z.literal("response.code_interpreter_call.in_progress"),
1536
- item_id: import_v46.z.string(),
1537
- output_index: import_v46.z.number()
1720
+ z6.object({
1721
+ type: z6.literal("response.code_interpreter_call.in_progress"),
1722
+ item_id: z6.string(),
1723
+ output_index: z6.number()
1538
1724
  }),
1539
- import_v46.z.object({
1540
- type: import_v46.z.literal("response.code_interpreter_call.executing"),
1541
- item_id: import_v46.z.string(),
1542
- output_index: import_v46.z.number()
1725
+ z6.object({
1726
+ type: z6.literal("response.code_interpreter_call.executing"),
1727
+ item_id: z6.string(),
1728
+ output_index: z6.number()
1543
1729
  }),
1544
- import_v46.z.object({
1545
- type: import_v46.z.literal("response.code_interpreter_call.interpreting"),
1546
- item_id: import_v46.z.string(),
1547
- output_index: import_v46.z.number()
1730
+ z6.object({
1731
+ type: z6.literal("response.code_interpreter_call.interpreting"),
1732
+ item_id: z6.string(),
1733
+ output_index: z6.number()
1548
1734
  }),
1549
- import_v46.z.object({
1550
- type: import_v46.z.literal("response.code_interpreter_call.completed"),
1551
- item_id: import_v46.z.string(),
1552
- output_index: import_v46.z.number()
1735
+ z6.object({
1736
+ type: z6.literal("response.code_interpreter_call.completed"),
1737
+ item_id: z6.string(),
1738
+ output_index: z6.number()
1553
1739
  }),
1554
1740
  // Code interpreter code streaming events
1555
- import_v46.z.object({
1556
- type: import_v46.z.literal("response.code_interpreter_call_code.delta"),
1557
- item_id: import_v46.z.string(),
1558
- output_index: import_v46.z.number(),
1559
- delta: import_v46.z.string()
1741
+ z6.object({
1742
+ type: z6.literal("response.code_interpreter_call_code.delta"),
1743
+ item_id: z6.string(),
1744
+ output_index: z6.number(),
1745
+ delta: z6.string()
1560
1746
  }),
1561
- import_v46.z.object({
1562
- type: import_v46.z.literal("response.code_interpreter_call_code.done"),
1563
- item_id: import_v46.z.string(),
1564
- output_index: import_v46.z.number(),
1565
- code: import_v46.z.string()
1747
+ z6.object({
1748
+ type: z6.literal("response.code_interpreter_call_code.done"),
1749
+ item_id: z6.string(),
1750
+ output_index: z6.number(),
1751
+ code: z6.string()
1566
1752
  }),
1567
- import_v46.z.object({
1568
- type: import_v46.z.literal("response.custom_tool_call_input.delta"),
1569
- item_id: import_v46.z.string(),
1570
- output_index: import_v46.z.number(),
1571
- delta: import_v46.z.string()
1753
+ z6.object({
1754
+ type: z6.literal("response.custom_tool_call_input.delta"),
1755
+ item_id: z6.string(),
1756
+ output_index: z6.number(),
1757
+ delta: z6.string()
1572
1758
  }),
1573
- import_v46.z.object({
1574
- type: import_v46.z.literal("response.custom_tool_call_input.done"),
1575
- item_id: import_v46.z.string(),
1576
- output_index: import_v46.z.number(),
1577
- input: import_v46.z.string()
1759
+ z6.object({
1760
+ type: z6.literal("response.custom_tool_call_input.done"),
1761
+ item_id: z6.string(),
1762
+ output_index: z6.number(),
1763
+ input: z6.string()
1578
1764
  }),
1579
1765
  // Function call arguments streaming events (standard function tools)
1580
- import_v46.z.object({
1581
- type: import_v46.z.literal("response.function_call_arguments.delta"),
1582
- item_id: import_v46.z.string(),
1583
- output_index: import_v46.z.number(),
1584
- delta: import_v46.z.string()
1766
+ z6.object({
1767
+ type: z6.literal("response.function_call_arguments.delta"),
1768
+ item_id: z6.string(),
1769
+ output_index: z6.number(),
1770
+ delta: z6.string()
1771
+ }),
1772
+ z6.object({
1773
+ type: z6.literal("response.function_call_arguments.done"),
1774
+ item_id: z6.string(),
1775
+ output_index: z6.number(),
1776
+ arguments: z6.string()
1585
1777
  }),
1586
- import_v46.z.object({
1587
- type: import_v46.z.literal("response.function_call_arguments.done"),
1588
- item_id: import_v46.z.string(),
1589
- output_index: import_v46.z.number(),
1590
- arguments: import_v46.z.string()
1778
+ z6.object({
1779
+ type: z6.literal("response.mcp_call.in_progress"),
1780
+ item_id: z6.string(),
1781
+ output_index: z6.number()
1591
1782
  }),
1592
- import_v46.z.object({
1593
- type: import_v46.z.literal("response.mcp_call.in_progress"),
1594
- item_id: import_v46.z.string(),
1595
- output_index: import_v46.z.number()
1783
+ z6.object({
1784
+ type: z6.literal("response.mcp_call.executing"),
1785
+ item_id: z6.string(),
1786
+ output_index: z6.number()
1596
1787
  }),
1597
- import_v46.z.object({
1598
- type: import_v46.z.literal("response.mcp_call.executing"),
1599
- item_id: import_v46.z.string(),
1600
- output_index: import_v46.z.number()
1788
+ z6.object({
1789
+ type: z6.literal("response.mcp_call.completed"),
1790
+ item_id: z6.string(),
1791
+ output_index: z6.number()
1601
1792
  }),
1602
- import_v46.z.object({
1603
- type: import_v46.z.literal("response.mcp_call.completed"),
1604
- item_id: import_v46.z.string(),
1605
- output_index: import_v46.z.number()
1793
+ z6.object({
1794
+ type: z6.literal("response.mcp_call.failed"),
1795
+ item_id: z6.string(),
1796
+ output_index: z6.number()
1606
1797
  }),
1607
- import_v46.z.object({
1608
- type: import_v46.z.literal("response.mcp_call.failed"),
1609
- item_id: import_v46.z.string(),
1610
- output_index: import_v46.z.number()
1798
+ z6.object({
1799
+ type: z6.literal("response.mcp_call_arguments.delta"),
1800
+ item_id: z6.string(),
1801
+ output_index: z6.number(),
1802
+ delta: z6.string()
1611
1803
  }),
1612
- import_v46.z.object({
1613
- type: import_v46.z.literal("response.mcp_call_arguments.delta"),
1614
- item_id: import_v46.z.string(),
1615
- output_index: import_v46.z.number(),
1616
- delta: import_v46.z.string()
1804
+ z6.object({
1805
+ type: z6.literal("response.mcp_call_arguments.done"),
1806
+ item_id: z6.string(),
1807
+ output_index: z6.number(),
1808
+ arguments: z6.string().optional()
1617
1809
  }),
1618
- import_v46.z.object({
1619
- type: import_v46.z.literal("response.mcp_call_arguments.done"),
1620
- item_id: import_v46.z.string(),
1621
- output_index: import_v46.z.number(),
1622
- arguments: import_v46.z.string().optional()
1810
+ z6.object({
1811
+ type: z6.literal("response.mcp_call_output.delta"),
1812
+ item_id: z6.string(),
1813
+ output_index: z6.number(),
1814
+ delta: z6.string()
1623
1815
  }),
1624
- import_v46.z.object({
1625
- type: import_v46.z.literal("response.mcp_call_output.delta"),
1626
- item_id: import_v46.z.string(),
1627
- output_index: import_v46.z.number(),
1628
- delta: import_v46.z.string()
1816
+ z6.object({
1817
+ type: z6.literal("response.mcp_call_output.done"),
1818
+ item_id: z6.string(),
1819
+ output_index: z6.number(),
1820
+ output: z6.string().optional()
1629
1821
  }),
1630
- import_v46.z.object({
1631
- type: import_v46.z.literal("response.mcp_call_output.done"),
1632
- item_id: import_v46.z.string(),
1633
- output_index: import_v46.z.number(),
1634
- output: import_v46.z.string().optional()
1822
+ z6.object({
1823
+ type: z6.literal("response.incomplete"),
1824
+ response: z6.object({
1825
+ incomplete_details: z6.object({ reason: z6.string() }).nullish(),
1826
+ usage: xaiResponsesUsageSchema.nullish()
1827
+ })
1635
1828
  }),
1636
- import_v46.z.object({
1637
- type: import_v46.z.literal("response.done"),
1829
+ z6.object({
1830
+ type: z6.literal("response.failed"),
1831
+ response: z6.object({
1832
+ error: z6.object({
1833
+ code: z6.string().nullish(),
1834
+ message: z6.string()
1835
+ }).nullish(),
1836
+ incomplete_details: z6.object({ reason: z6.string() }).nullish(),
1837
+ usage: xaiResponsesUsageSchema.nullish()
1838
+ })
1839
+ }),
1840
+ z6.object({
1841
+ type: z6.literal("error"),
1842
+ code: z6.string().nullish(),
1843
+ message: z6.string(),
1844
+ param: z6.string().nullish()
1845
+ }),
1846
+ z6.object({
1847
+ type: z6.literal("response.done"),
1638
1848
  response: xaiResponsesResponseSchema
1639
1849
  }),
1640
- import_v46.z.object({
1641
- type: import_v46.z.literal("response.completed"),
1850
+ z6.object({
1851
+ type: z6.literal("response.completed"),
1642
1852
  response: xaiResponsesResponseSchema
1643
1853
  })
1644
1854
  ]);
1645
1855
 
1646
- // src/responses/xai-responses-options.ts
1647
- var import_v47 = require("zod/v4");
1648
- var xaiLanguageModelResponsesOptions = import_v47.z.object({
1856
+ // src/responses/xai-responses-language-model-options.ts
1857
+ import { z as z7 } from "zod/v4";
1858
+ var xaiLanguageModelResponsesOptions = z7.object({
1649
1859
  /**
1650
1860
  * Constrains how hard a reasoning model thinks before responding.
1651
- * Possible values are `low` (uses fewer reasoning tokens), `medium` and `high` (uses more reasoning tokens).
1861
+ * Possible values are `none` (disables reasoning entirely; supported by
1862
+ * `grok-4.3` and newer reasoning models), `low` (uses fewer reasoning
1863
+ * tokens), `medium`, and `high` (uses more reasoning tokens).
1864
+ *
1865
+ * @see https://docs.x.ai/docs/guides/reasoning
1652
1866
  */
1653
- reasoningEffort: import_v47.z.enum(["low", "medium", "high"]).optional(),
1654
- logprobs: import_v47.z.boolean().optional(),
1655
- topLogprobs: import_v47.z.number().int().min(0).max(8).optional(),
1867
+ reasoningEffort: z7.enum(["none", "low", "medium", "high"]).optional(),
1868
+ reasoningSummary: z7.enum(["auto", "concise", "detailed"]).optional(),
1869
+ logprobs: z7.boolean().optional(),
1870
+ topLogprobs: z7.number().int().min(0).max(8).optional(),
1656
1871
  /**
1657
1872
  * Whether to store the input message(s) and model response for later retrieval.
1873
+ * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
1874
+ * otherwise the API will return an error.
1658
1875
  * @default true
1659
1876
  */
1660
- store: import_v47.z.boolean().optional(),
1877
+ store: z7.boolean().optional(),
1661
1878
  /**
1662
1879
  * The ID of the previous response from the model.
1663
1880
  */
1664
- previousResponseId: import_v47.z.string().optional(),
1881
+ previousResponseId: z7.string().optional(),
1665
1882
  /**
1666
1883
  * Specify additional output data to include in the model response.
1667
1884
  * Example values: 'file_search_call.results'.
1668
1885
  */
1669
- include: import_v47.z.array(import_v47.z.enum(["file_search_call.results"])).nullish()
1886
+ include: z7.array(z7.enum(["file_search_call.results"])).nullish()
1670
1887
  });
1671
1888
 
1672
1889
  // src/responses/xai-responses-prepare-tools.ts
1673
- var import_provider5 = require("@ai-sdk/provider");
1674
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
1890
+ import {
1891
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError4
1892
+ } from "@ai-sdk/provider";
1893
+ import { validateTypes } from "@ai-sdk/provider-utils";
1675
1894
 
1676
1895
  // src/tool/file-search.ts
1677
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1678
- var import_v48 = require("zod/v4");
1679
- var fileSearchArgsSchema = (0, import_provider_utils6.lazySchema)(
1680
- () => (0, import_provider_utils6.zodSchema)(
1681
- import_v48.z.object({
1682
- vectorStoreIds: import_v48.z.array(import_v48.z.string()),
1683
- maxNumResults: import_v48.z.number().optional()
1896
+ import {
1897
+ createProviderExecutedToolFactory,
1898
+ lazySchema,
1899
+ zodSchema
1900
+ } from "@ai-sdk/provider-utils";
1901
+ import { z as z8 } from "zod/v4";
1902
+ var fileSearchArgsSchema = lazySchema(
1903
+ () => zodSchema(
1904
+ z8.object({
1905
+ vectorStoreIds: z8.array(z8.string()),
1906
+ maxNumResults: z8.number().optional()
1684
1907
  })
1685
1908
  )
1686
1909
  );
1687
- var fileSearchOutputSchema = (0, import_provider_utils6.lazySchema)(
1688
- () => (0, import_provider_utils6.zodSchema)(
1689
- import_v48.z.object({
1690
- queries: import_v48.z.array(import_v48.z.string()),
1691
- results: import_v48.z.array(
1692
- import_v48.z.object({
1693
- fileId: import_v48.z.string(),
1694
- filename: import_v48.z.string(),
1695
- score: import_v48.z.number().min(0).max(1),
1696
- text: import_v48.z.string()
1910
+ var fileSearchOutputSchema = lazySchema(
1911
+ () => zodSchema(
1912
+ z8.object({
1913
+ queries: z8.array(z8.string()),
1914
+ results: z8.array(
1915
+ z8.object({
1916
+ fileId: z8.string(),
1917
+ filename: z8.string(),
1918
+ score: z8.number().min(0).max(1),
1919
+ text: z8.string()
1697
1920
  })
1698
1921
  ).nullable()
1699
1922
  })
1700
1923
  )
1701
1924
  );
1702
- var fileSearchToolFactory = (0, import_provider_utils6.createProviderToolFactoryWithOutputSchema)({
1925
+ var fileSearchToolFactory = createProviderExecutedToolFactory({
1703
1926
  id: "xai.file_search",
1704
- inputSchema: (0, import_provider_utils6.lazySchema)(() => (0, import_provider_utils6.zodSchema)(import_v48.z.object({}))),
1927
+ inputSchema: lazySchema(() => zodSchema(z8.object({}))),
1705
1928
  outputSchema: fileSearchOutputSchema
1706
1929
  });
1707
1930
  var fileSearch = (args) => fileSearchToolFactory(args);
1708
1931
 
1709
1932
  // src/tool/mcp-server.ts
1710
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1711
- var import_v49 = require("zod/v4");
1712
- var mcpServerArgsSchema = (0, import_provider_utils7.lazySchema)(
1713
- () => (0, import_provider_utils7.zodSchema)(
1714
- import_v49.z.object({
1715
- serverUrl: import_v49.z.string().describe("The URL of the MCP server"),
1716
- serverLabel: import_v49.z.string().optional().describe("A label for the MCP server"),
1717
- serverDescription: import_v49.z.string().optional().describe("Description of the MCP server"),
1718
- allowedTools: import_v49.z.array(import_v49.z.string()).optional().describe("List of allowed tool names"),
1719
- headers: import_v49.z.record(import_v49.z.string(), import_v49.z.string()).optional().describe("Custom headers to send"),
1720
- authorization: import_v49.z.string().optional().describe("Authorization header value")
1933
+ import {
1934
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory2,
1935
+ lazySchema as lazySchema2,
1936
+ zodSchema as zodSchema2
1937
+ } from "@ai-sdk/provider-utils";
1938
+ import { z as z9 } from "zod/v4";
1939
+ var mcpServerArgsSchema = lazySchema2(
1940
+ () => zodSchema2(
1941
+ z9.object({
1942
+ serverUrl: z9.string().describe("The URL of the MCP server"),
1943
+ serverLabel: z9.string().optional().describe("A label for the MCP server"),
1944
+ serverDescription: z9.string().optional().describe("Description of the MCP server"),
1945
+ allowedTools: z9.array(z9.string()).optional().describe("List of allowed tool names"),
1946
+ headers: z9.record(z9.string(), z9.string()).optional().describe("Custom headers to send"),
1947
+ authorization: z9.string().optional().describe("Authorization header value")
1721
1948
  })
1722
1949
  )
1723
1950
  );
1724
- var mcpServerOutputSchema = (0, import_provider_utils7.lazySchema)(
1725
- () => (0, import_provider_utils7.zodSchema)(
1726
- import_v49.z.object({
1727
- name: import_v49.z.string(),
1728
- arguments: import_v49.z.string(),
1729
- result: import_v49.z.unknown()
1951
+ var mcpServerOutputSchema = lazySchema2(
1952
+ () => zodSchema2(
1953
+ z9.object({
1954
+ name: z9.string(),
1955
+ arguments: z9.string(),
1956
+ result: z9.unknown()
1730
1957
  })
1731
1958
  )
1732
1959
  );
1733
- var mcpServerToolFactory = (0, import_provider_utils7.createProviderToolFactoryWithOutputSchema)({
1960
+ var mcpServerToolFactory = createProviderExecutedToolFactory2({
1734
1961
  id: "xai.mcp",
1735
- inputSchema: (0, import_provider_utils7.lazySchema)(() => (0, import_provider_utils7.zodSchema)(import_v49.z.object({}))),
1962
+ inputSchema: lazySchema2(() => zodSchema2(z9.object({}))),
1736
1963
  outputSchema: mcpServerOutputSchema
1737
1964
  });
1738
1965
  var mcpServer = (args) => mcpServerToolFactory(args);
1739
1966
 
1740
1967
  // src/tool/web-search.ts
1741
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1742
- var import_v410 = require("zod/v4");
1743
- var webSearchArgsSchema = (0, import_provider_utils8.lazySchema)(
1744
- () => (0, import_provider_utils8.zodSchema)(
1745
- import_v410.z.object({
1746
- allowedDomains: import_v410.z.array(import_v410.z.string()).max(5).optional(),
1747
- excludedDomains: import_v410.z.array(import_v410.z.string()).max(5).optional(),
1748
- enableImageUnderstanding: import_v410.z.boolean().optional()
1968
+ import {
1969
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory3,
1970
+ lazySchema as lazySchema3,
1971
+ zodSchema as zodSchema3
1972
+ } from "@ai-sdk/provider-utils";
1973
+ import { z as z10 } from "zod/v4";
1974
+ var webSearchArgsSchema = lazySchema3(
1975
+ () => zodSchema3(
1976
+ z10.object({
1977
+ allowedDomains: z10.array(z10.string()).max(5).optional(),
1978
+ excludedDomains: z10.array(z10.string()).max(5).optional(),
1979
+ enableImageSearch: z10.boolean().optional(),
1980
+ enableImageUnderstanding: z10.boolean().optional()
1749
1981
  })
1750
1982
  )
1751
1983
  );
1752
- var webSearchOutputSchema = (0, import_provider_utils8.lazySchema)(
1753
- () => (0, import_provider_utils8.zodSchema)(
1754
- import_v410.z.object({
1755
- query: import_v410.z.string(),
1756
- sources: import_v410.z.array(
1757
- import_v410.z.object({
1758
- title: import_v410.z.string(),
1759
- url: import_v410.z.string(),
1760
- snippet: import_v410.z.string()
1984
+ var webSearchOutputSchema = lazySchema3(
1985
+ () => zodSchema3(
1986
+ z10.object({
1987
+ query: z10.string(),
1988
+ sources: z10.array(
1989
+ z10.object({
1990
+ title: z10.string(),
1991
+ url: z10.string(),
1992
+ snippet: z10.string()
1761
1993
  })
1762
1994
  )
1763
1995
  })
1764
1996
  )
1765
1997
  );
1766
- var webSearchToolFactory = (0, import_provider_utils8.createProviderToolFactoryWithOutputSchema)({
1998
+ var webSearchToolFactory = createProviderExecutedToolFactory3({
1767
1999
  id: "xai.web_search",
1768
- inputSchema: (0, import_provider_utils8.lazySchema)(() => (0, import_provider_utils8.zodSchema)(import_v410.z.object({}))),
2000
+ inputSchema: lazySchema3(() => zodSchema3(z10.object({}))),
1769
2001
  outputSchema: webSearchOutputSchema
1770
2002
  });
1771
2003
  var webSearch = (args = {}) => webSearchToolFactory(args);
1772
2004
 
1773
2005
  // src/tool/x-search.ts
1774
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
1775
- var import_v411 = require("zod/v4");
1776
- var xSearchArgsSchema = (0, import_provider_utils9.lazySchema)(
1777
- () => (0, import_provider_utils9.zodSchema)(
1778
- import_v411.z.object({
1779
- allowedXHandles: import_v411.z.array(import_v411.z.string()).max(10).optional(),
1780
- excludedXHandles: import_v411.z.array(import_v411.z.string()).max(10).optional(),
1781
- fromDate: import_v411.z.string().optional(),
1782
- toDate: import_v411.z.string().optional(),
1783
- enableImageUnderstanding: import_v411.z.boolean().optional(),
1784
- enableVideoUnderstanding: import_v411.z.boolean().optional()
2006
+ import {
2007
+ createProviderExecutedToolFactory as createProviderExecutedToolFactory4,
2008
+ lazySchema as lazySchema4,
2009
+ zodSchema as zodSchema4
2010
+ } from "@ai-sdk/provider-utils";
2011
+ import { z as z11 } from "zod/v4";
2012
+ var xSearchArgsSchema = lazySchema4(
2013
+ () => zodSchema4(
2014
+ z11.object({
2015
+ allowedXHandles: z11.array(z11.string()).max(10).optional(),
2016
+ excludedXHandles: z11.array(z11.string()).max(10).optional(),
2017
+ fromDate: z11.string().optional(),
2018
+ toDate: z11.string().optional(),
2019
+ enableImageUnderstanding: z11.boolean().optional(),
2020
+ enableVideoUnderstanding: z11.boolean().optional()
1785
2021
  })
1786
2022
  )
1787
2023
  );
1788
- var xSearchOutputSchema = (0, import_provider_utils9.lazySchema)(
1789
- () => (0, import_provider_utils9.zodSchema)(
1790
- import_v411.z.object({
1791
- query: import_v411.z.string(),
1792
- posts: import_v411.z.array(
1793
- import_v411.z.object({
1794
- author: import_v411.z.string(),
1795
- text: import_v411.z.string(),
1796
- url: import_v411.z.string(),
1797
- likes: import_v411.z.number()
2024
+ var xSearchOutputSchema = lazySchema4(
2025
+ () => zodSchema4(
2026
+ z11.object({
2027
+ query: z11.string(),
2028
+ posts: z11.array(
2029
+ z11.object({
2030
+ author: z11.string(),
2031
+ text: z11.string(),
2032
+ url: z11.string(),
2033
+ likes: z11.number()
1798
2034
  })
1799
2035
  )
1800
2036
  })
1801
2037
  )
1802
2038
  );
1803
- var xSearchToolFactory = (0, import_provider_utils9.createProviderToolFactoryWithOutputSchema)({
2039
+ var xSearchToolFactory = createProviderExecutedToolFactory4({
1804
2040
  id: "xai.x_search",
1805
- inputSchema: (0, import_provider_utils9.lazySchema)(() => (0, import_provider_utils9.zodSchema)(import_v411.z.object({}))),
2041
+ inputSchema: lazySchema4(() => zodSchema4(z11.object({}))),
1806
2042
  outputSchema: xSearchOutputSchema
1807
2043
  });
1808
2044
  var xSearch = (args = {}) => xSearchToolFactory(args);
@@ -1824,7 +2060,7 @@ async function prepareResponsesTools({
1824
2060
  if (tool.type === "provider") {
1825
2061
  switch (tool.id) {
1826
2062
  case "xai.web_search": {
1827
- const args = await (0, import_provider_utils10.validateTypes)({
2063
+ const args = await validateTypes({
1828
2064
  value: tool.args,
1829
2065
  schema: webSearchArgsSchema
1830
2066
  });
@@ -1832,12 +2068,13 @@ async function prepareResponsesTools({
1832
2068
  type: "web_search",
1833
2069
  allowed_domains: args.allowedDomains,
1834
2070
  excluded_domains: args.excludedDomains,
2071
+ enable_image_search: args.enableImageSearch,
1835
2072
  enable_image_understanding: args.enableImageUnderstanding
1836
2073
  });
1837
2074
  break;
1838
2075
  }
1839
2076
  case "xai.x_search": {
1840
- const args = await (0, import_provider_utils10.validateTypes)({
2077
+ const args = await validateTypes({
1841
2078
  value: tool.args,
1842
2079
  schema: xSearchArgsSchema
1843
2080
  });
@@ -1871,7 +2108,7 @@ async function prepareResponsesTools({
1871
2108
  break;
1872
2109
  }
1873
2110
  case "xai.file_search": {
1874
- const args = await (0, import_provider_utils10.validateTypes)({
2111
+ const args = await validateTypes({
1875
2112
  value: tool.args,
1876
2113
  schema: fileSearchArgsSchema
1877
2114
  });
@@ -1883,7 +2120,7 @@ async function prepareResponsesTools({
1883
2120
  break;
1884
2121
  }
1885
2122
  case "xai.mcp": {
1886
- const args = await (0, import_provider_utils10.validateTypes)({
2123
+ const args = await validateTypes({
1887
2124
  value: tool.args,
1888
2125
  schema: mcpServerArgsSchema
1889
2126
  });
@@ -1911,7 +2148,7 @@ async function prepareResponsesTools({
1911
2148
  type: "function",
1912
2149
  name: tool.name,
1913
2150
  description: tool.description,
1914
- parameters: tool.inputSchema,
2151
+ parameters: removeAdditionalPropertiesFalse(tool.inputSchema),
1915
2152
  ...tool.strict != null ? { strict: tool.strict } : {}
1916
2153
  });
1917
2154
  }
@@ -1950,7 +2187,7 @@ async function prepareResponsesTools({
1950
2187
  }
1951
2188
  default: {
1952
2189
  const _exhaustiveCheck = type;
1953
- throw new import_provider5.UnsupportedFunctionalityError({
2190
+ throw new UnsupportedFunctionalityError4({
1954
2191
  functionality: `tool choice type: ${_exhaustiveCheck}`
1955
2192
  });
1956
2193
  }
@@ -1958,15 +2195,29 @@ async function prepareResponsesTools({
1958
2195
  }
1959
2196
 
1960
2197
  // src/responses/xai-responses-language-model.ts
1961
- var XaiResponsesLanguageModel = class {
2198
+ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
1962
2199
  constructor(modelId, config) {
1963
- this.specificationVersion = "v3";
2200
+ this.specificationVersion = "v4";
1964
2201
  this.supportedUrls = {
1965
- "image/*": [/^https?:\/\/.*$/]
2202
+ "image/*": [/^https?:\/\/.*$/],
2203
+ // xAI's Responses API accepts non-image documents (PDF, plain text, CSV, etc.) as
2204
+ // `{ type: 'input_file', file_url }`. Keeping these URLs intact here lets them pass
2205
+ // through to the converter instead of being downloaded to bytes by the SDK.
2206
+ "application/pdf": [/^https?:\/\/.*$/],
2207
+ "text/*": [/^https?:\/\/.*$/]
1966
2208
  };
1967
2209
  this.modelId = modelId;
1968
2210
  this.config = config;
1969
2211
  }
2212
+ static [WORKFLOW_SERIALIZE3](model) {
2213
+ return serializeModelOptions3({
2214
+ modelId: model.modelId,
2215
+ config: model.config
2216
+ });
2217
+ }
2218
+ static [WORKFLOW_DESERIALIZE3](options) {
2219
+ return new _XaiResponsesLanguageModel(options.modelId, options.config);
2220
+ }
1970
2221
  get provider() {
1971
2222
  return this.config.provider;
1972
2223
  }
@@ -1980,11 +2231,12 @@ var XaiResponsesLanguageModel = class {
1980
2231
  responseFormat,
1981
2232
  providerOptions,
1982
2233
  tools,
1983
- toolChoice
2234
+ toolChoice,
2235
+ reasoning
1984
2236
  }) {
1985
- var _a, _b, _c, _d, _e, _f, _g;
2237
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1986
2238
  const warnings = [];
1987
- const options = (_a = await (0, import_provider_utils11.parseProviderOptions)({
2239
+ const options = (_a = await parseProviderOptions3({
1988
2240
  provider: "xai",
1989
2241
  providerOptions,
1990
2242
  schema: xaiLanguageModelResponsesOptions
@@ -2009,7 +2261,7 @@ var XaiResponsesLanguageModel = class {
2009
2261
  )) == null ? void 0 : _f.name;
2010
2262
  const { input, inputWarnings } = await convertToXaiResponsesInput({
2011
2263
  prompt,
2012
- store: true
2264
+ store: (_g = options.store) != null ? _g : true
2013
2265
  });
2014
2266
  warnings.push(...inputWarnings);
2015
2267
  const {
@@ -2029,6 +2281,17 @@ var XaiResponsesLanguageModel = class {
2029
2281
  include = [...include, "reasoning.encrypted_content"];
2030
2282
  }
2031
2283
  }
2284
+ const resolvedReasoningEffort = (_h = options.reasoningEffort) != null ? _h : isCustomReasoning2(reasoning) ? reasoning === "none" ? void 0 : mapReasoningToProviderEffort2({
2285
+ reasoning,
2286
+ effortMap: {
2287
+ minimal: "low",
2288
+ low: "low",
2289
+ medium: "medium",
2290
+ high: "high",
2291
+ xhigh: "high"
2292
+ },
2293
+ warnings
2294
+ }) : void 0;
2032
2295
  const baseArgs = {
2033
2296
  model: this.modelId,
2034
2297
  input,
@@ -2043,14 +2306,21 @@ var XaiResponsesLanguageModel = class {
2043
2306
  format: responseFormat.schema != null ? {
2044
2307
  type: "json_schema",
2045
2308
  strict: true,
2046
- name: (_g = responseFormat.name) != null ? _g : "response",
2309
+ name: (_i = responseFormat.name) != null ? _i : "response",
2047
2310
  description: responseFormat.description,
2048
2311
  schema: responseFormat.schema
2049
2312
  } : { type: "json_object" }
2050
2313
  }
2051
2314
  },
2052
- ...options.reasoningEffort != null && {
2053
- reasoning: { effort: options.reasoningEffort }
2315
+ ...(resolvedReasoningEffort != null || options.reasoningSummary != null) && {
2316
+ reasoning: {
2317
+ ...resolvedReasoningEffort != null && {
2318
+ effort: resolvedReasoningEffort
2319
+ },
2320
+ ...options.reasoningSummary != null && {
2321
+ summary: options.reasoningSummary
2322
+ }
2323
+ }
2054
2324
  },
2055
2325
  ...options.store === false && {
2056
2326
  store: options.store
@@ -2079,7 +2349,7 @@ var XaiResponsesLanguageModel = class {
2079
2349
  };
2080
2350
  }
2081
2351
  async doGenerate(options) {
2082
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2352
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2083
2353
  const {
2084
2354
  args: body,
2085
2355
  warnings,
@@ -2093,18 +2363,19 @@ var XaiResponsesLanguageModel = class {
2093
2363
  responseHeaders,
2094
2364
  value: response,
2095
2365
  rawValue: rawResponse
2096
- } = await (0, import_provider_utils11.postJsonToApi)({
2366
+ } = await postJsonToApi3({
2097
2367
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
2098
- headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
2368
+ headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
2099
2369
  body,
2100
2370
  failedResponseHandler: xaiFailedResponseHandler,
2101
- successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
2371
+ successfulResponseHandler: createJsonResponseHandler3(
2102
2372
  xaiResponsesResponseSchema
2103
2373
  ),
2104
2374
  abortSignal: options.abortSignal,
2105
2375
  fetch: this.config.fetch
2106
2376
  });
2107
2377
  const content = [];
2378
+ let hasFunctionCall = false;
2108
2379
  const webSearchSubTools = [
2109
2380
  "web_search",
2110
2381
  "web_search_with_snippets",
@@ -2131,29 +2402,29 @@ var XaiResponsesLanguageModel = class {
2131
2402
  toolCallId: part.id,
2132
2403
  toolName,
2133
2404
  result: {
2134
- queries: (_b = part.queries) != null ? _b : [],
2135
- results: (_d = (_c = part.results) == null ? void 0 : _c.map((result) => ({
2405
+ queries: (_d = part.queries) != null ? _d : [],
2406
+ results: (_f = (_e = part.results) == null ? void 0 : _e.map((result) => ({
2136
2407
  fileId: result.file_id,
2137
2408
  filename: result.filename,
2138
2409
  score: result.score,
2139
2410
  text: result.text
2140
- }))) != null ? _d : null
2411
+ }))) != null ? _f : null
2141
2412
  }
2142
2413
  });
2143
2414
  continue;
2144
2415
  }
2145
2416
  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 = (_e = part.name) != null ? _e : "";
2147
- if (webSearchSubTools.includes((_f = part.name) != null ? _f : "") || part.type === "web_search_call") {
2417
+ let toolName = (_g = part.name) != null ? _g : "";
2418
+ if (webSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "web_search_call") {
2148
2419
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2149
- } else if (xSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "x_search_call") {
2420
+ } else if (xSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "x_search_call") {
2150
2421
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2151
2422
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2152
2423
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2153
2424
  } else if (part.type === "mcp_call") {
2154
- toolName = (_h = mcpToolName != null ? mcpToolName : part.name) != null ? _h : "mcp";
2425
+ toolName = (_j = mcpToolName != null ? mcpToolName : part.name) != null ? _j : "mcp";
2155
2426
  }
2156
- const toolInput = part.type === "custom_tool_call" ? (_i = part.input) != null ? _i : "" : part.type === "mcp_call" ? (_j = part.arguments) != null ? _j : "" : (_k = part.arguments) != null ? _k : "";
2427
+ 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
2428
  content.push({
2158
2429
  type: "tool-call",
2159
2430
  toolCallId: part.id,
@@ -2180,7 +2451,7 @@ var XaiResponsesLanguageModel = class {
2180
2451
  sourceType: "url",
2181
2452
  id: this.config.generateId(),
2182
2453
  url: annotation.url,
2183
- title: (_l = annotation.title) != null ? _l : annotation.url
2454
+ title: (_n = annotation.title) != null ? _n : annotation.url
2184
2455
  });
2185
2456
  }
2186
2457
  }
@@ -2189,6 +2460,7 @@ var XaiResponsesLanguageModel = class {
2189
2460
  break;
2190
2461
  }
2191
2462
  case "function_call": {
2463
+ hasFunctionCall = true;
2192
2464
  content.push({
2193
2465
  type: "tool-call",
2194
2466
  toolCallId: part.call_id,
@@ -2198,13 +2470,14 @@ var XaiResponsesLanguageModel = class {
2198
2470
  break;
2199
2471
  }
2200
2472
  case "reasoning": {
2201
- const summaryTexts = part.summary.map((s) => s.text).filter((text) => text && text.length > 0);
2202
- if (summaryTexts.length > 0) {
2203
- const reasoningText = summaryTexts.join("");
2204
- if (part.encrypted_content || part.id) {
2205
- content.push({
2206
- type: "reasoning",
2207
- text: reasoningText,
2473
+ const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((_o = part.content) != null ? _o : []).map((c) => c.text);
2474
+ const reasoningText = texts.filter((text) => text && text.length > 0).join("");
2475
+ if (reasoningText || part.encrypted_content) {
2476
+ const hasMetadata = part.encrypted_content || part.id;
2477
+ content.push({
2478
+ type: "reasoning",
2479
+ text: reasoningText,
2480
+ ...hasMetadata && {
2208
2481
  providerMetadata: {
2209
2482
  xai: {
2210
2483
  ...part.encrypted_content && {
@@ -2213,13 +2486,8 @@ var XaiResponsesLanguageModel = class {
2213
2486
  ...part.id && { itemId: part.id }
2214
2487
  }
2215
2488
  }
2216
- });
2217
- } else {
2218
- content.push({
2219
- type: "reasoning",
2220
- text: reasoningText
2221
- });
2222
- }
2489
+ }
2490
+ });
2223
2491
  }
2224
2492
  break;
2225
2493
  }
@@ -2231,13 +2499,20 @@ var XaiResponsesLanguageModel = class {
2231
2499
  return {
2232
2500
  content,
2233
2501
  finishReason: {
2234
- unified: mapXaiResponsesFinishReason(response.status),
2235
- raw: (_m = response.status) != null ? _m : void 0
2502
+ unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
2503
+ raw: (_p = response.status) != null ? _p : void 0
2236
2504
  },
2237
2505
  usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
2238
2506
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
2239
2507
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2240
2508
  },
2509
+ ...((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null && {
2510
+ providerMetadata: {
2511
+ xai: {
2512
+ costInUsdTicks: response.usage.cost_in_usd_ticks
2513
+ }
2514
+ }
2515
+ },
2241
2516
  request: { body },
2242
2517
  response: {
2243
2518
  ...getResponseMetadata(response),
@@ -2248,7 +2523,7 @@ var XaiResponsesLanguageModel = class {
2248
2523
  };
2249
2524
  }
2250
2525
  async doStream(options) {
2251
- var _a;
2526
+ var _a, _b, _c;
2252
2527
  const {
2253
2528
  args,
2254
2529
  warnings,
@@ -2262,12 +2537,12 @@ var XaiResponsesLanguageModel = class {
2262
2537
  ...args,
2263
2538
  stream: true
2264
2539
  };
2265
- const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
2540
+ const { responseHeaders, value: response } = await postJsonToApi3({
2266
2541
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
2267
- headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
2542
+ headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
2268
2543
  body,
2269
2544
  failedResponseHandler: xaiFailedResponseHandler,
2270
- successfulResponseHandler: (0, import_provider_utils11.createEventSourceResponseHandler)(
2545
+ successfulResponseHandler: createEventSourceResponseHandler2(
2271
2546
  xaiResponsesChunkSchema
2272
2547
  ),
2273
2548
  abortSignal: options.abortSignal,
@@ -2277,7 +2552,9 @@ var XaiResponsesLanguageModel = class {
2277
2552
  unified: "other",
2278
2553
  raw: void 0
2279
2554
  };
2555
+ let hasFunctionCall = false;
2280
2556
  let usage = void 0;
2557
+ let costInUsdTicks = void 0;
2281
2558
  let isFirstChunk = true;
2282
2559
  const contentBlocks = {};
2283
2560
  const seenToolCalls = /* @__PURE__ */ new Set();
@@ -2291,7 +2568,7 @@ var XaiResponsesLanguageModel = class {
2291
2568
  controller.enqueue({ type: "stream-start", warnings });
2292
2569
  },
2293
2570
  transform(chunk, controller) {
2294
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2571
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2295
2572
  if (options.includeRawChunks) {
2296
2573
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2297
2574
  }
@@ -2312,16 +2589,18 @@ var XaiResponsesLanguageModel = class {
2312
2589
  }
2313
2590
  if (event.type === "response.reasoning_summary_part.added") {
2314
2591
  const blockId = `reasoning-${event.item_id}`;
2315
- activeReasoning[event.item_id] = {};
2316
- controller.enqueue({
2317
- type: "reasoning-start",
2318
- id: blockId,
2319
- providerMetadata: {
2320
- xai: {
2321
- itemId: event.item_id
2592
+ if (activeReasoning[event.item_id] == null) {
2593
+ activeReasoning[event.item_id] = {};
2594
+ controller.enqueue({
2595
+ type: "reasoning-start",
2596
+ id: blockId,
2597
+ providerMetadata: {
2598
+ xai: {
2599
+ itemId: event.item_id
2600
+ }
2322
2601
  }
2323
- }
2324
- });
2602
+ });
2603
+ }
2325
2604
  }
2326
2605
  if (event.type === "response.reasoning_summary_text.delta") {
2327
2606
  const blockId = `reasoning-${event.item_id}`;
@@ -2409,24 +2688,46 @@ var XaiResponsesLanguageModel = class {
2409
2688
  sourceType: "url",
2410
2689
  id: self.config.generateId(),
2411
2690
  url: annotation.url,
2412
- title: (_b = annotation.title) != null ? _b : annotation.url
2691
+ title: (_b2 = annotation.title) != null ? _b2 : annotation.url
2413
2692
  });
2414
2693
  }
2415
2694
  return;
2416
2695
  }
2417
- if (event.type === "response.done" || event.type === "response.completed") {
2696
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2418
2697
  const response2 = event.response;
2419
2698
  if (response2.usage) {
2420
2699
  usage = convertXaiResponsesUsage(response2.usage);
2700
+ costInUsdTicks = (_c2 = response2.usage.cost_in_usd_ticks) != null ? _c2 : void 0;
2421
2701
  }
2422
- if (response2.status) {
2702
+ if (event.type === "response.incomplete") {
2703
+ const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
2704
+ finishReason = {
2705
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2706
+ raw: reason != null ? reason : "incomplete"
2707
+ };
2708
+ } else if ("status" in response2 && response2.status) {
2423
2709
  finishReason = {
2424
- unified: mapXaiResponsesFinishReason(response2.status),
2710
+ unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
2425
2711
  raw: response2.status
2426
2712
  };
2427
2713
  }
2428
2714
  return;
2429
2715
  }
2716
+ if (event.type === "response.failed") {
2717
+ const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
2718
+ finishReason = {
2719
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2720
+ raw: reason != null ? reason : "error"
2721
+ };
2722
+ if (event.response.usage) {
2723
+ usage = convertXaiResponsesUsage(event.response.usage);
2724
+ }
2725
+ return;
2726
+ }
2727
+ if (event.type === "error") {
2728
+ controller.enqueue({ type: "error", error: event });
2729
+ return;
2730
+ }
2430
2731
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2431
2732
  return;
2432
2733
  }
@@ -2509,13 +2810,13 @@ var XaiResponsesLanguageModel = class {
2509
2810
  toolCallId: part.id,
2510
2811
  toolName,
2511
2812
  result: {
2512
- queries: (_c = part.queries) != null ? _c : [],
2513
- results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2813
+ queries: (_f = part.queries) != null ? _f : [],
2814
+ results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
2514
2815
  fileId: result.file_id,
2515
2816
  filename: result.filename,
2516
2817
  score: result.score,
2517
2818
  text: result.text
2518
- }))) != null ? _e : null
2819
+ }))) != null ? _h : null
2519
2820
  }
2520
2821
  });
2521
2822
  }
@@ -2533,17 +2834,17 @@ var XaiResponsesLanguageModel = class {
2533
2834
  "x_semantic_search",
2534
2835
  "x_thread_fetch"
2535
2836
  ];
2536
- let toolName = (_f = part.name) != null ? _f : "";
2537
- if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2837
+ let toolName = (_i = part.name) != null ? _i : "";
2838
+ if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
2538
2839
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2539
- } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2840
+ } else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
2540
2841
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2541
2842
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2542
2843
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2543
2844
  } else if (part.type === "mcp_call") {
2544
- toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2845
+ toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
2545
2846
  }
2546
- const toolInput = part.type === "custom_tool_call" ? (_j = part.input) != null ? _j : "" : part.type === "mcp_call" ? (_k = part.arguments) != null ? _k : "" : (_l = part.arguments) != null ? _l : "";
2847
+ const toolInput = part.type === "custom_tool_call" ? (_m = part.input) != null ? _m : "" : part.type === "mcp_call" ? (_n = part.arguments) != null ? _n : "" : (_o = part.arguments) != null ? _o : "";
2547
2848
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2548
2849
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2549
2850
  seenToolCalls.add(part.id);
@@ -2596,7 +2897,7 @@ var XaiResponsesLanguageModel = class {
2596
2897
  sourceType: "url",
2597
2898
  id: self.config.generateId(),
2598
2899
  url: annotation.url,
2599
- title: (_m = annotation.title) != null ? _m : annotation.url
2900
+ title: (_p = annotation.title) != null ? _p : annotation.url
2600
2901
  });
2601
2902
  }
2602
2903
  }
@@ -2614,6 +2915,7 @@ var XaiResponsesLanguageModel = class {
2614
2915
  toolName: part.name
2615
2916
  });
2616
2917
  } else if (event.type === "response.output_item.done") {
2918
+ hasFunctionCall = true;
2617
2919
  ongoingToolCalls[event.output_index] = void 0;
2618
2920
  controller.enqueue({
2619
2921
  type: "tool-input-end",
@@ -2649,6 +2951,13 @@ var XaiResponsesLanguageModel = class {
2649
2951
  cacheWrite: 0
2650
2952
  },
2651
2953
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2954
+ },
2955
+ ...costInUsdTicks != null && {
2956
+ providerMetadata: {
2957
+ xai: {
2958
+ costInUsdTicks
2959
+ }
2960
+ }
2652
2961
  }
2653
2962
  });
2654
2963
  }
@@ -2660,45 +2969,414 @@ var XaiResponsesLanguageModel = class {
2660
2969
  }
2661
2970
  };
2662
2971
 
2972
+ // src/realtime/xai-realtime-event-mapper.ts
2973
+ function parseXaiRealtimeServerEvent(raw) {
2974
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2975
+ const event = raw;
2976
+ const type = event.type;
2977
+ switch (type) {
2978
+ case "session.created":
2979
+ return {
2980
+ type: "session-created",
2981
+ sessionId: (_a = event.session) == null ? void 0 : _a.id,
2982
+ raw
2983
+ };
2984
+ case "session.updated":
2985
+ return { type: "session-updated", raw };
2986
+ case "conversation.created":
2987
+ return { type: "custom", rawType: type, raw };
2988
+ case "input_audio_buffer.speech_started":
2989
+ return {
2990
+ type: "speech-started",
2991
+ itemId: event.item_id,
2992
+ raw
2993
+ };
2994
+ case "input_audio_buffer.speech_stopped":
2995
+ return {
2996
+ type: "speech-stopped",
2997
+ itemId: event.item_id,
2998
+ raw
2999
+ };
3000
+ case "input_audio_buffer.committed":
3001
+ return {
3002
+ type: "audio-committed",
3003
+ itemId: event.item_id,
3004
+ previousItemId: event.previous_item_id,
3005
+ raw
3006
+ };
3007
+ case "conversation.item.added":
3008
+ return {
3009
+ type: "conversation-item-added",
3010
+ itemId: (_c = (_b = event.item) == null ? void 0 : _b.id) != null ? _c : event.item_id,
3011
+ item: event.item,
3012
+ raw
3013
+ };
3014
+ case "conversation.item.input_audio_transcription.completed":
3015
+ return {
3016
+ type: "input-transcription-completed",
3017
+ itemId: event.item_id,
3018
+ transcript: (_d = event.transcript) != null ? _d : "",
3019
+ raw
3020
+ };
3021
+ case "response.created":
3022
+ return {
3023
+ type: "response-created",
3024
+ responseId: (_f = (_e = event.response) == null ? void 0 : _e.id) != null ? _f : event.response_id,
3025
+ raw
3026
+ };
3027
+ case "response.done":
3028
+ return {
3029
+ type: "response-done",
3030
+ responseId: (_h = (_g = event.response) == null ? void 0 : _g.id) != null ? _h : event.response_id,
3031
+ status: (_j = (_i = event.response) == null ? void 0 : _i.status) != null ? _j : "completed",
3032
+ raw
3033
+ };
3034
+ case "response.output_item.added":
3035
+ return {
3036
+ type: "output-item-added",
3037
+ responseId: event.response_id,
3038
+ itemId: (_l = (_k = event.item) == null ? void 0 : _k.id) != null ? _l : event.item_id,
3039
+ raw
3040
+ };
3041
+ case "response.output_item.done":
3042
+ return {
3043
+ type: "output-item-done",
3044
+ responseId: event.response_id,
3045
+ itemId: (_n = (_m = event.item) == null ? void 0 : _m.id) != null ? _n : event.item_id,
3046
+ raw
3047
+ };
3048
+ case "response.content_part.added":
3049
+ return {
3050
+ type: "content-part-added",
3051
+ responseId: event.response_id,
3052
+ itemId: event.item_id,
3053
+ raw
3054
+ };
3055
+ case "response.content_part.done":
3056
+ return {
3057
+ type: "content-part-done",
3058
+ responseId: event.response_id,
3059
+ itemId: event.item_id,
3060
+ raw
3061
+ };
3062
+ case "response.output_audio.delta":
3063
+ return {
3064
+ type: "audio-delta",
3065
+ responseId: event.response_id,
3066
+ itemId: event.item_id,
3067
+ delta: event.delta,
3068
+ raw
3069
+ };
3070
+ case "response.output_audio.done":
3071
+ return {
3072
+ type: "audio-done",
3073
+ responseId: event.response_id,
3074
+ itemId: event.item_id,
3075
+ raw
3076
+ };
3077
+ case "response.output_audio_transcript.delta":
3078
+ return {
3079
+ type: "audio-transcript-delta",
3080
+ responseId: event.response_id,
3081
+ itemId: event.item_id,
3082
+ delta: event.delta,
3083
+ raw
3084
+ };
3085
+ case "response.output_audio_transcript.done":
3086
+ return {
3087
+ type: "audio-transcript-done",
3088
+ responseId: event.response_id,
3089
+ itemId: event.item_id,
3090
+ transcript: event.transcript,
3091
+ raw
3092
+ };
3093
+ case "response.text.delta":
3094
+ return {
3095
+ type: "text-delta",
3096
+ responseId: event.response_id,
3097
+ itemId: event.item_id,
3098
+ delta: event.delta,
3099
+ raw
3100
+ };
3101
+ case "response.text.done":
3102
+ return {
3103
+ type: "text-done",
3104
+ responseId: event.response_id,
3105
+ itemId: event.item_id,
3106
+ text: event.text,
3107
+ raw
3108
+ };
3109
+ case "response.function_call_arguments.delta":
3110
+ return {
3111
+ type: "function-call-arguments-delta",
3112
+ responseId: event.response_id,
3113
+ itemId: event.item_id,
3114
+ callId: event.call_id,
3115
+ delta: event.delta,
3116
+ raw
3117
+ };
3118
+ case "response.function_call_arguments.done":
3119
+ return {
3120
+ type: "function-call-arguments-done",
3121
+ responseId: event.response_id,
3122
+ itemId: event.item_id,
3123
+ callId: event.call_id,
3124
+ name: event.name,
3125
+ arguments: event.arguments,
3126
+ raw
3127
+ };
3128
+ case "mcp_list_tools.in_progress":
3129
+ case "mcp_list_tools.completed":
3130
+ case "mcp_list_tools.failed":
3131
+ case "response.mcp_call_arguments.delta":
3132
+ case "response.mcp_call_arguments.done":
3133
+ case "response.mcp_call.in_progress":
3134
+ case "response.mcp_call.completed":
3135
+ case "response.mcp_call.failed":
3136
+ return { type: "custom", rawType: type, raw };
3137
+ case "error":
3138
+ return {
3139
+ type: "error",
3140
+ message: (_q = (_p = (_o = event.error) == null ? void 0 : _o.message) != null ? _p : event.message) != null ? _q : "Unknown error",
3141
+ code: (_s = (_r = event.error) == null ? void 0 : _r.code) != null ? _s : event.code,
3142
+ raw
3143
+ };
3144
+ default:
3145
+ return { type: "custom", rawType: type, raw };
3146
+ }
3147
+ }
3148
+ function serializeXaiRealtimeClientEvent(event) {
3149
+ switch (event.type) {
3150
+ case "session-update":
3151
+ return {
3152
+ type: "session.update",
3153
+ session: buildXaiSessionConfig(event.config)
3154
+ };
3155
+ case "input-audio-append":
3156
+ return {
3157
+ type: "input_audio_buffer.append",
3158
+ audio: event.audio
3159
+ };
3160
+ case "input-audio-commit":
3161
+ return { type: "input_audio_buffer.commit" };
3162
+ case "input-audio-clear":
3163
+ return { type: "input_audio_buffer.clear" };
3164
+ case "conversation-item-create": {
3165
+ const item = event.item;
3166
+ switch (item.type) {
3167
+ case "text-message":
3168
+ return {
3169
+ type: "conversation.item.create",
3170
+ item: {
3171
+ type: "message",
3172
+ role: item.role,
3173
+ content: [{ type: "input_text", text: item.text }]
3174
+ }
3175
+ };
3176
+ case "audio-message":
3177
+ return {
3178
+ type: "conversation.item.create",
3179
+ item: {
3180
+ type: "message",
3181
+ role: item.role,
3182
+ content: [{ type: "input_audio", audio: item.audio }]
3183
+ }
3184
+ };
3185
+ case "function-call-output":
3186
+ return {
3187
+ type: "conversation.item.create",
3188
+ item: {
3189
+ type: "function_call_output",
3190
+ call_id: item.callId,
3191
+ output: item.output
3192
+ }
3193
+ };
3194
+ }
3195
+ break;
3196
+ }
3197
+ case "conversation-item-truncate":
3198
+ return void 0;
3199
+ case "response-create":
3200
+ return {
3201
+ type: "response.create",
3202
+ ...event.options != null ? {
3203
+ response: {
3204
+ ...event.options.modalities != null ? { modalities: event.options.modalities } : {},
3205
+ ...event.options.instructions != null ? { instructions: event.options.instructions } : {}
3206
+ }
3207
+ } : {}
3208
+ };
3209
+ case "response-cancel":
3210
+ return { type: "response.cancel" };
3211
+ }
3212
+ }
3213
+ function buildXaiSessionConfig(config) {
3214
+ var _a;
3215
+ const session = {};
3216
+ if (config.instructions != null) {
3217
+ session.instructions = config.instructions;
3218
+ }
3219
+ if (config.voice != null) {
3220
+ session.voice = config.voice;
3221
+ }
3222
+ const audio = {};
3223
+ if (config.inputAudioFormat != null) {
3224
+ audio.input = {
3225
+ format: {
3226
+ type: config.inputAudioFormat.type,
3227
+ ...config.inputAudioFormat.rate != null ? { rate: config.inputAudioFormat.rate } : {}
3228
+ }
3229
+ };
3230
+ }
3231
+ if (config.outputAudioFormat != null) {
3232
+ audio.output = {
3233
+ format: {
3234
+ type: config.outputAudioFormat.type,
3235
+ ...config.outputAudioFormat.rate != null ? { rate: config.outputAudioFormat.rate } : {}
3236
+ }
3237
+ };
3238
+ }
3239
+ if (Object.keys(audio).length > 0) {
3240
+ session.audio = audio;
3241
+ }
3242
+ if (config.turnDetection != null) {
3243
+ if (config.turnDetection.type === "disabled") {
3244
+ session.turn_detection = null;
3245
+ } else {
3246
+ const td = {
3247
+ type: "server_vad"
3248
+ };
3249
+ if (config.turnDetection.threshold != null) {
3250
+ td.threshold = config.turnDetection.threshold;
3251
+ }
3252
+ if (config.turnDetection.silenceDurationMs != null) {
3253
+ td.silence_duration_ms = config.turnDetection.silenceDurationMs;
3254
+ }
3255
+ if (config.turnDetection.prefixPaddingMs != null) {
3256
+ td.prefix_padding_ms = config.turnDetection.prefixPaddingMs;
3257
+ }
3258
+ session.turn_detection = td;
3259
+ }
3260
+ }
3261
+ if (config.tools != null && config.tools.length > 0) {
3262
+ session.tools = config.tools.map((tool) => ({
3263
+ type: tool.type,
3264
+ name: tool.name,
3265
+ description: tool.description,
3266
+ parameters: tool.parameters
3267
+ }));
3268
+ }
3269
+ if (config.providerOptions != null) {
3270
+ const xaiOptions = config.providerOptions;
3271
+ if (Array.isArray(xaiOptions.tools)) {
3272
+ const existingTools = (_a = session.tools) != null ? _a : [];
3273
+ session.tools = [...existingTools, ...xaiOptions.tools];
3274
+ }
3275
+ for (const [key, value] of Object.entries(xaiOptions)) {
3276
+ if (key !== "tools") {
3277
+ session[key] = value;
3278
+ }
3279
+ }
3280
+ }
3281
+ return session;
3282
+ }
3283
+
3284
+ // src/realtime/xai-realtime-model.ts
3285
+ var XaiRealtimeModel = class {
3286
+ constructor(modelId, config) {
3287
+ this.specificationVersion = "v4";
3288
+ this.modelId = modelId;
3289
+ this.provider = config.provider;
3290
+ this.config = config;
3291
+ }
3292
+ async doCreateClientSecret(options) {
3293
+ var _a;
3294
+ const fetchFn = (_a = this.config.fetch) != null ? _a : fetch;
3295
+ const url = `${this.config.baseURL}/realtime/client_secrets`;
3296
+ const body = {};
3297
+ if (options.expiresAfterSeconds != null) {
3298
+ body.expires_after = { seconds: options.expiresAfterSeconds };
3299
+ }
3300
+ const response = await fetchFn(url, {
3301
+ method: "POST",
3302
+ headers: {
3303
+ ...this.config.headers(),
3304
+ "Content-Type": "application/json"
3305
+ },
3306
+ body: JSON.stringify(body)
3307
+ });
3308
+ if (!response.ok) {
3309
+ const text = await response.text();
3310
+ throw new Error(
3311
+ `xAI realtime client secret request failed: ${response.status} ${text}`
3312
+ );
3313
+ }
3314
+ const data = await response.json();
3315
+ return {
3316
+ token: data.value,
3317
+ // xAI selects the voice model from the `model` query parameter on the
3318
+ // WebSocket URL. Without it the model choice is silently ignored and the
3319
+ // server falls back to its default voice model.
3320
+ url: `wss://${new URL(this.config.baseURL).host}/v1/realtime?model=${encodeURIComponent(this.modelId)}`,
3321
+ expiresAt: data.expires_at
3322
+ };
3323
+ }
3324
+ getWebSocketConfig(options) {
3325
+ return {
3326
+ url: options.url,
3327
+ protocols: [`xai-client-secret.${options.token}`]
3328
+ };
3329
+ }
3330
+ parseServerEvent(raw) {
3331
+ return parseXaiRealtimeServerEvent(raw);
3332
+ }
3333
+ serializeClientEvent(event) {
3334
+ return serializeXaiRealtimeClientEvent(event);
3335
+ }
3336
+ buildSessionConfig(config) {
3337
+ return buildXaiSessionConfig(config);
3338
+ }
3339
+ };
3340
+
2663
3341
  // src/tool/code-execution.ts
2664
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
2665
- var import_v412 = require("zod/v4");
2666
- var codeExecutionOutputSchema = import_v412.z.object({
2667
- output: import_v412.z.string().describe("the output of the code execution"),
2668
- error: import_v412.z.string().optional().describe("any error that occurred")
3342
+ import { createProviderExecutedToolFactory as createProviderExecutedToolFactory5 } from "@ai-sdk/provider-utils";
3343
+ import { z as z12 } from "zod/v4";
3344
+ var codeExecutionOutputSchema = z12.object({
3345
+ output: z12.string().describe("the output of the code execution"),
3346
+ error: z12.string().optional().describe("any error that occurred")
2669
3347
  });
2670
- var codeExecutionToolFactory = (0, import_provider_utils12.createProviderToolFactoryWithOutputSchema)({
3348
+ var codeExecutionToolFactory = createProviderExecutedToolFactory5({
2671
3349
  id: "xai.code_execution",
2672
- inputSchema: import_v412.z.object({}).describe("no input parameters"),
3350
+ inputSchema: z12.object({}).describe("no input parameters"),
2673
3351
  outputSchema: codeExecutionOutputSchema
2674
3352
  });
2675
3353
  var codeExecution = (args = {}) => codeExecutionToolFactory(args);
2676
3354
 
2677
3355
  // src/tool/view-image.ts
2678
- var import_provider_utils13 = require("@ai-sdk/provider-utils");
2679
- var import_v413 = require("zod/v4");
2680
- var viewImageOutputSchema = import_v413.z.object({
2681
- description: import_v413.z.string().describe("description of the image"),
2682
- objects: import_v413.z.array(import_v413.z.string()).optional().describe("objects detected in the image")
3356
+ import { createProviderExecutedToolFactory as createProviderExecutedToolFactory6 } from "@ai-sdk/provider-utils";
3357
+ import { z as z13 } from "zod/v4";
3358
+ var viewImageOutputSchema = z13.object({
3359
+ description: z13.string().describe("description of the image"),
3360
+ objects: z13.array(z13.string()).optional().describe("objects detected in the image")
2683
3361
  });
2684
- var viewImageToolFactory = (0, import_provider_utils13.createProviderToolFactoryWithOutputSchema)({
3362
+ var viewImageToolFactory = createProviderExecutedToolFactory6({
2685
3363
  id: "xai.view_image",
2686
- inputSchema: import_v413.z.object({}).describe("no input parameters"),
3364
+ inputSchema: z13.object({}).describe("no input parameters"),
2687
3365
  outputSchema: viewImageOutputSchema
2688
3366
  });
2689
3367
  var viewImage = (args = {}) => viewImageToolFactory(args);
2690
3368
 
2691
3369
  // src/tool/view-x-video.ts
2692
- var import_provider_utils14 = require("@ai-sdk/provider-utils");
2693
- var import_v414 = require("zod/v4");
2694
- var viewXVideoOutputSchema = import_v414.z.object({
2695
- transcript: import_v414.z.string().optional().describe("transcript of the video"),
2696
- description: import_v414.z.string().describe("description of the video content"),
2697
- duration: import_v414.z.number().optional().describe("duration in seconds")
3370
+ import { createProviderExecutedToolFactory as createProviderExecutedToolFactory7 } from "@ai-sdk/provider-utils";
3371
+ import { z as z14 } from "zod/v4";
3372
+ var viewXVideoOutputSchema = z14.object({
3373
+ transcript: z14.string().optional().describe("transcript of the video"),
3374
+ description: z14.string().describe("description of the video content"),
3375
+ duration: z14.number().optional().describe("duration in seconds")
2698
3376
  });
2699
- var viewXVideoToolFactory = (0, import_provider_utils14.createProviderToolFactoryWithOutputSchema)({
3377
+ var viewXVideoToolFactory = createProviderExecutedToolFactory7({
2700
3378
  id: "xai.view_x_video",
2701
- inputSchema: import_v414.z.object({}).describe("no input parameters"),
3379
+ inputSchema: z14.object({}).describe("no input parameters"),
2702
3380
  outputSchema: viewXVideoOutputSchema
2703
3381
  });
2704
3382
  var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
@@ -2715,53 +3393,216 @@ var xaiTools = {
2715
3393
  };
2716
3394
 
2717
3395
  // src/version.ts
2718
- var VERSION = true ? "4.0.0-beta.6" : "0.0.0-test";
3396
+ var VERSION = true ? "4.0.0-beta.75" : "0.0.0-test";
2719
3397
 
2720
- // src/xai-video-model.ts
2721
- var import_provider6 = require("@ai-sdk/provider");
2722
- var import_provider_utils16 = require("@ai-sdk/provider-utils");
2723
- var import_v416 = require("zod/v4");
3398
+ // src/files/xai-files.ts
3399
+ import {
3400
+ combineHeaders as combineHeaders4,
3401
+ convertInlineFileDataToUint8Array,
3402
+ createJsonResponseHandler as createJsonResponseHandler4,
3403
+ parseProviderOptions as parseProviderOptions4,
3404
+ postFormDataToApi
3405
+ } from "@ai-sdk/provider-utils";
2724
3406
 
2725
- // src/xai-video-options.ts
2726
- var import_provider_utils15 = require("@ai-sdk/provider-utils");
2727
- var import_v415 = require("zod/v4");
2728
- var xaiVideoModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
2729
- () => (0, import_provider_utils15.zodSchema)(
2730
- import_v415.z.object({
2731
- pollIntervalMs: import_v415.z.number().positive().nullish(),
2732
- pollTimeoutMs: import_v415.z.number().positive().nullish(),
2733
- resolution: import_v415.z.enum(["480p", "720p"]).nullish(),
2734
- videoUrl: import_v415.z.string().nullish()
3407
+ // src/files/xai-files-api.ts
3408
+ import { lazySchema as lazySchema5, zodSchema as zodSchema5 } from "@ai-sdk/provider-utils";
3409
+ import { z as z15 } from "zod/v4";
3410
+ var xaiFilesResponseSchema = lazySchema5(
3411
+ () => zodSchema5(
3412
+ z15.object({
3413
+ id: z15.string(),
3414
+ object: z15.string().nullish(),
3415
+ bytes: z15.number().nullish(),
3416
+ created_at: z15.number().nullish(),
3417
+ filename: z15.string().nullish(),
3418
+ purpose: z15.string().nullish(),
3419
+ status: z15.string().nullish()
3420
+ })
3421
+ )
3422
+ );
3423
+
3424
+ // src/files/xai-files-options.ts
3425
+ import {
3426
+ lazySchema as lazySchema6,
3427
+ zodSchema as zodSchema6
3428
+ } from "@ai-sdk/provider-utils";
3429
+ import { z as z16 } from "zod/v4";
3430
+ var xaiFilesOptionsSchema = lazySchema6(
3431
+ () => zodSchema6(
3432
+ z16.object({
3433
+ teamId: z16.string().optional(),
3434
+ filePath: z16.string().optional()
2735
3435
  }).passthrough()
2736
3436
  )
2737
3437
  );
2738
3438
 
3439
+ // src/files/xai-files.ts
3440
+ var XaiFiles = class {
3441
+ constructor(config) {
3442
+ this.config = config;
3443
+ this.specificationVersion = "v4";
3444
+ }
3445
+ get provider() {
3446
+ return this.config.provider;
3447
+ }
3448
+ async uploadFile({
3449
+ data,
3450
+ mediaType,
3451
+ filename,
3452
+ providerOptions
3453
+ }) {
3454
+ var _a, _b;
3455
+ const xaiOptions = await parseProviderOptions4({
3456
+ provider: "xai",
3457
+ providerOptions,
3458
+ schema: xaiFilesOptionsSchema
3459
+ });
3460
+ const fileBytes = convertInlineFileDataToUint8Array(data);
3461
+ const blob = new Blob([fileBytes], {
3462
+ type: mediaType
3463
+ });
3464
+ const formData = new FormData();
3465
+ if (filename != null) {
3466
+ formData.append("file", blob, filename);
3467
+ } else {
3468
+ formData.append("file", blob);
3469
+ }
3470
+ if ((xaiOptions == null ? void 0 : xaiOptions.teamId) != null) {
3471
+ formData.append("team_id", xaiOptions.teamId);
3472
+ }
3473
+ const { value: response } = await postFormDataToApi({
3474
+ url: `${this.config.baseURL}/files`,
3475
+ headers: combineHeaders4(this.config.headers()),
3476
+ formData,
3477
+ failedResponseHandler: xaiFailedResponseHandler,
3478
+ successfulResponseHandler: createJsonResponseHandler4(
3479
+ xaiFilesResponseSchema
3480
+ ),
3481
+ fetch: this.config.fetch
3482
+ });
3483
+ return {
3484
+ warnings: [],
3485
+ providerReference: { xai: response.id },
3486
+ ...((_a = response.filename) != null ? _a : filename) ? { filename: (_b = response.filename) != null ? _b : filename } : {},
3487
+ ...mediaType != null ? { mediaType } : {},
3488
+ providerMetadata: {
3489
+ xai: {
3490
+ ...response.filename != null ? { filename: response.filename } : {},
3491
+ ...response.bytes != null ? { bytes: response.bytes } : {},
3492
+ ...response.created_at != null ? { createdAt: response.created_at } : {}
3493
+ }
3494
+ }
3495
+ };
3496
+ }
3497
+ };
3498
+
3499
+ // src/xai-video-model.ts
3500
+ import {
3501
+ AISDKError
3502
+ } from "@ai-sdk/provider";
3503
+ import {
3504
+ combineHeaders as combineHeaders5,
3505
+ convertUint8ArrayToBase64,
3506
+ createJsonResponseHandler as createJsonResponseHandler5,
3507
+ delay,
3508
+ getFromApi as getFromApi2,
3509
+ parseProviderOptions as parseProviderOptions5,
3510
+ postJsonToApi as postJsonToApi4
3511
+ } from "@ai-sdk/provider-utils";
3512
+ import { z as z18 } from "zod/v4";
3513
+
3514
+ // src/xai-video-model-options.ts
3515
+ import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
3516
+ import { z as z17 } from "zod/v4";
3517
+ var nonEmptyStringSchema = z17.string().min(1);
3518
+ var resolutionSchema = z17.enum(["480p", "720p"]);
3519
+ var modeSchema = z17.enum(["edit-video", "extend-video", "reference-to-video"]);
3520
+ var baseFields = {
3521
+ pollIntervalMs: z17.number().positive().nullish(),
3522
+ pollTimeoutMs: z17.number().positive().nullish(),
3523
+ resolution: resolutionSchema.nullish()
3524
+ };
3525
+ var editVideoSchema = z17.object({
3526
+ ...baseFields,
3527
+ mode: z17.literal("edit-video"),
3528
+ videoUrl: nonEmptyStringSchema,
3529
+ referenceImageUrls: z17.undefined().optional()
3530
+ });
3531
+ var extendVideoSchema = z17.object({
3532
+ ...baseFields,
3533
+ mode: z17.literal("extend-video"),
3534
+ videoUrl: nonEmptyStringSchema,
3535
+ referenceImageUrls: z17.undefined().optional()
3536
+ });
3537
+ var referenceToVideoSchema = z17.object({
3538
+ ...baseFields,
3539
+ mode: z17.literal("reference-to-video"),
3540
+ referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7),
3541
+ videoUrl: z17.undefined().optional()
3542
+ });
3543
+ var autoDetectSchema = z17.object({
3544
+ ...baseFields,
3545
+ mode: z17.undefined().optional(),
3546
+ videoUrl: nonEmptyStringSchema.optional(),
3547
+ referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7).optional()
3548
+ });
3549
+ var xaiVideoModelOptions = z17.union([
3550
+ editVideoSchema,
3551
+ extendVideoSchema,
3552
+ referenceToVideoSchema,
3553
+ autoDetectSchema
3554
+ ]);
3555
+ var runtimeSchema = z17.object({
3556
+ mode: modeSchema.optional(),
3557
+ videoUrl: nonEmptyStringSchema.optional(),
3558
+ referenceImageUrls: z17.array(nonEmptyStringSchema).min(1).max(7).optional(),
3559
+ ...baseFields
3560
+ }).passthrough();
3561
+ var xaiVideoModelOptionsSchema = lazySchema7(
3562
+ () => zodSchema7(runtimeSchema)
3563
+ );
3564
+
2739
3565
  // src/xai-video-model.ts
2740
3566
  var RESOLUTION_MAP = {
2741
3567
  "1280x720": "720p",
2742
3568
  "854x480": "480p",
2743
3569
  "640x480": "480p"
2744
3570
  };
3571
+ function resolveVideoMode(options) {
3572
+ if ((options == null ? void 0 : options.mode) != null) {
3573
+ return options.mode;
3574
+ }
3575
+ if ((options == null ? void 0 : options.videoUrl) != null) {
3576
+ return "edit-video";
3577
+ }
3578
+ if ((options == null ? void 0 : options.referenceImageUrls) != null && options.referenceImageUrls.length > 0) {
3579
+ return "reference-to-video";
3580
+ }
3581
+ return void 0;
3582
+ }
2745
3583
  var XaiVideoModel = class {
2746
3584
  constructor(modelId, config) {
2747
3585
  this.modelId = modelId;
2748
3586
  this.config = config;
2749
- this.specificationVersion = "v3";
3587
+ this.specificationVersion = "v4";
2750
3588
  this.maxVideosPerCall = 1;
2751
3589
  }
2752
3590
  get provider() {
2753
3591
  return this.config.provider;
2754
3592
  }
2755
3593
  async doGenerate(options) {
2756
- var _a, _b, _c, _d, _e, _f, _g, _h;
3594
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2757
3595
  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
3596
  const warnings = [];
2759
- const xaiOptions = await (0, import_provider_utils16.parseProviderOptions)({
3597
+ const xaiOptions = await parseProviderOptions5({
2760
3598
  provider: "xai",
2761
3599
  providerOptions: options.providerOptions,
2762
3600
  schema: xaiVideoModelOptionsSchema
2763
3601
  });
2764
- const isEdit = (xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null;
3602
+ const effectiveMode = resolveVideoMode(xaiOptions);
3603
+ const isEdit = effectiveMode === "edit-video";
3604
+ const isExtension = effectiveMode === "extend-video";
3605
+ const hasReferenceImages = effectiveMode === "reference-to-video";
2765
3606
  if (options.fps != null) {
2766
3607
  warnings.push({
2767
3608
  type: "unsupported",
@@ -2804,19 +3645,36 @@ var XaiVideoModel = class {
2804
3645
  details: "xAI video editing does not support custom resolution."
2805
3646
  });
2806
3647
  }
3648
+ if (isExtension && options.aspectRatio != null) {
3649
+ warnings.push({
3650
+ type: "unsupported",
3651
+ feature: "aspectRatio",
3652
+ details: "xAI video extension does not support custom aspect ratio."
3653
+ });
3654
+ }
3655
+ if (isExtension && ((xaiOptions == null ? void 0 : xaiOptions.resolution) != null || options.resolution != null)) {
3656
+ warnings.push({
3657
+ type: "unsupported",
3658
+ feature: "resolution",
3659
+ details: "xAI video extension does not support custom resolution."
3660
+ });
3661
+ }
2807
3662
  const body = {
2808
3663
  model: this.modelId,
2809
3664
  prompt: options.prompt
2810
3665
  };
2811
- if (!isEdit && options.duration != null) {
3666
+ const allowDuration = !isEdit;
3667
+ const allowAspectRatio = !isEdit && !isExtension;
3668
+ const allowResolution = !isEdit && !isExtension;
3669
+ if (allowDuration && options.duration != null) {
2812
3670
  body.duration = options.duration;
2813
3671
  }
2814
- if (!isEdit && options.aspectRatio != null) {
3672
+ if (allowAspectRatio && options.aspectRatio != null) {
2815
3673
  body.aspect_ratio = options.aspectRatio;
2816
3674
  }
2817
- if (!isEdit && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
3675
+ if (allowResolution && (xaiOptions == null ? void 0 : xaiOptions.resolution) != null) {
2818
3676
  body.resolution = xaiOptions.resolution;
2819
- } else if (!isEdit && options.resolution != null) {
3677
+ } else if (allowResolution && options.resolution != null) {
2820
3678
  const mapped = RESOLUTION_MAP[options.resolution];
2821
3679
  if (mapped != null) {
2822
3680
  body.resolution = mapped;
@@ -2828,38 +3686,56 @@ var XaiVideoModel = class {
2828
3686
  });
2829
3687
  }
2830
3688
  }
2831
- if ((xaiOptions == null ? void 0 : xaiOptions.videoUrl) != null) {
3689
+ if (isEdit) {
3690
+ body.video = { url: xaiOptions.videoUrl };
3691
+ }
3692
+ if (isExtension) {
2832
3693
  body.video = { url: xaiOptions.videoUrl };
2833
3694
  }
2834
3695
  if (options.image != null) {
2835
3696
  if (options.image.type === "url") {
2836
3697
  body.image = { url: options.image.url };
2837
3698
  } else {
2838
- const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils16.convertUint8ArrayToBase64)(options.image.data);
3699
+ const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
2839
3700
  body.image = {
2840
3701
  url: `data:${options.image.mediaType};base64,${base64Data}`
2841
3702
  };
2842
3703
  }
2843
3704
  }
3705
+ if (hasReferenceImages) {
3706
+ body.reference_images = xaiOptions.referenceImageUrls.map((url) => ({
3707
+ url
3708
+ }));
3709
+ }
2844
3710
  if (xaiOptions != null) {
2845
3711
  for (const [key, value] of Object.entries(xaiOptions)) {
2846
3712
  if (![
3713
+ "mode",
2847
3714
  "pollIntervalMs",
2848
3715
  "pollTimeoutMs",
2849
3716
  "resolution",
2850
- "videoUrl"
3717
+ "videoUrl",
3718
+ "referenceImageUrls"
2851
3719
  ].includes(key)) {
2852
3720
  body[key] = value;
2853
3721
  }
2854
3722
  }
2855
3723
  }
2856
3724
  const baseURL = (_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1";
2857
- const { value: createResponse } = await (0, import_provider_utils16.postJsonToApi)({
2858
- url: `${baseURL}/videos/${isEdit ? "edits" : "generations"}`,
2859
- headers: (0, import_provider_utils16.combineHeaders)(this.config.headers(), options.headers),
3725
+ let endpoint;
3726
+ if (isEdit) {
3727
+ endpoint = `${baseURL}/videos/edits`;
3728
+ } else if (isExtension) {
3729
+ endpoint = `${baseURL}/videos/extensions`;
3730
+ } else {
3731
+ endpoint = `${baseURL}/videos/generations`;
3732
+ }
3733
+ const { value: createResponse } = await postJsonToApi4({
3734
+ url: endpoint,
3735
+ headers: combineHeaders5(this.config.headers(), options.headers),
2860
3736
  body,
2861
3737
  failedResponseHandler: xaiFailedResponseHandler,
2862
- successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
3738
+ successfulResponseHandler: createJsonResponseHandler5(
2863
3739
  xaiCreateVideoResponseSchema
2864
3740
  ),
2865
3741
  abortSignal: options.abortSignal,
@@ -2867,7 +3743,7 @@ var XaiVideoModel = class {
2867
3743
  });
2868
3744
  const requestId = createResponse.request_id;
2869
3745
  if (!requestId) {
2870
- throw new import_provider6.AISDKError({
3746
+ throw new AISDKError({
2871
3747
  name: "XAI_VIDEO_GENERATION_ERROR",
2872
3748
  message: `No request_id returned from xAI API. Response: ${JSON.stringify(createResponse)}`
2873
3749
  });
@@ -2877,17 +3753,17 @@ var XaiVideoModel = class {
2877
3753
  const startTime = Date.now();
2878
3754
  let responseHeaders;
2879
3755
  while (true) {
2880
- await (0, import_provider_utils16.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
3756
+ await delay(pollIntervalMs, { abortSignal: options.abortSignal });
2881
3757
  if (Date.now() - startTime > pollTimeoutMs) {
2882
- throw new import_provider6.AISDKError({
3758
+ throw new AISDKError({
2883
3759
  name: "XAI_VIDEO_GENERATION_TIMEOUT",
2884
3760
  message: `Video generation timed out after ${pollTimeoutMs}ms`
2885
3761
  });
2886
3762
  }
2887
- const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils16.getFromApi)({
3763
+ const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi2({
2888
3764
  url: `${baseURL}/videos/${requestId}`,
2889
- headers: (0, import_provider_utils16.combineHeaders)(this.config.headers(), options.headers),
2890
- successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
3765
+ headers: combineHeaders5(this.config.headers(), options.headers),
3766
+ successfulResponseHandler: createJsonResponseHandler5(
2891
3767
  xaiVideoStatusResponseSchema
2892
3768
  ),
2893
3769
  failedResponseHandler: xaiFailedResponseHandler,
@@ -2896,8 +3772,14 @@ var XaiVideoModel = class {
2896
3772
  });
2897
3773
  responseHeaders = pollHeaders;
2898
3774
  if (statusResponse.status === "done" || statusResponse.status == null && ((_g = statusResponse.video) == null ? void 0 : _g.url)) {
2899
- if (!((_h = statusResponse.video) == null ? void 0 : _h.url)) {
2900
- throw new import_provider6.AISDKError({
3775
+ if (((_h = statusResponse.video) == null ? void 0 : _h.respect_moderation) === false) {
3776
+ throw new AISDKError({
3777
+ name: "XAI_VIDEO_MODERATION_ERROR",
3778
+ message: "Video generation was blocked due to a content policy violation."
3779
+ });
3780
+ }
3781
+ if (!((_i = statusResponse.video) == null ? void 0 : _i.url)) {
3782
+ throw new AISDKError({
2901
3783
  name: "XAI_VIDEO_GENERATION_ERROR",
2902
3784
  message: "Video generation completed but no video URL was returned."
2903
3785
  });
@@ -2920,42 +3802,409 @@ var XaiVideoModel = class {
2920
3802
  xai: {
2921
3803
  requestId,
2922
3804
  videoUrl: statusResponse.video.url,
2923
- ...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {}
3805
+ ...statusResponse.video.duration != null ? { duration: statusResponse.video.duration } : {},
3806
+ ...((_j = statusResponse.usage) == null ? void 0 : _j.cost_in_usd_ticks) != null ? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks } : {},
3807
+ ...statusResponse.progress != null ? { progress: statusResponse.progress } : {}
2924
3808
  }
2925
3809
  }
2926
3810
  };
2927
3811
  }
2928
3812
  if (statusResponse.status === "expired") {
2929
- throw new import_provider6.AISDKError({
3813
+ throw new AISDKError({
2930
3814
  name: "XAI_VIDEO_GENERATION_EXPIRED",
2931
3815
  message: "Video generation request expired."
2932
3816
  });
2933
3817
  }
3818
+ if (statusResponse.status === "failed") {
3819
+ throw new AISDKError({
3820
+ name: "XAI_VIDEO_GENERATION_FAILED",
3821
+ message: "Video generation failed."
3822
+ });
3823
+ }
2934
3824
  }
2935
3825
  }
2936
3826
  };
2937
- var xaiCreateVideoResponseSchema = import_v416.z.object({
2938
- request_id: import_v416.z.string().nullish()
3827
+ var xaiCreateVideoResponseSchema = z18.object({
3828
+ request_id: z18.string().nullish()
2939
3829
  });
2940
- var xaiVideoStatusResponseSchema = import_v416.z.object({
2941
- status: import_v416.z.string().nullish(),
2942
- video: import_v416.z.object({
2943
- url: import_v416.z.string(),
2944
- duration: import_v416.z.number().nullish(),
2945
- respect_moderation: import_v416.z.boolean().nullish()
3830
+ var xaiVideoStatusResponseSchema = z18.object({
3831
+ status: z18.string().nullish(),
3832
+ video: z18.object({
3833
+ url: z18.string(),
3834
+ duration: z18.number().nullish(),
3835
+ respect_moderation: z18.boolean().nullish()
2946
3836
  }).nullish(),
2947
- model: import_v416.z.string().nullish()
3837
+ model: z18.string().nullish(),
3838
+ usage: z18.object({
3839
+ cost_in_usd_ticks: z18.number().nullish()
3840
+ }).nullish(),
3841
+ progress: z18.number().nullish(),
3842
+ error: z18.object({
3843
+ code: z18.string().nullish(),
3844
+ message: z18.string().nullish()
3845
+ }).nullish()
3846
+ });
3847
+
3848
+ // src/xai-speech-model.ts
3849
+ import {
3850
+ combineHeaders as combineHeaders6,
3851
+ createBinaryResponseHandler as createBinaryResponseHandler2,
3852
+ parseProviderOptions as parseProviderOptions6,
3853
+ postJsonToApi as postJsonToApi5,
3854
+ resolve,
3855
+ serializeModelOptions as serializeModelOptions4,
3856
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
3857
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
3858
+ } from "@ai-sdk/provider-utils";
3859
+
3860
+ // src/xai-speech-model-options.ts
3861
+ import {
3862
+ lazySchema as lazySchema8,
3863
+ zodSchema as zodSchema8
3864
+ } from "@ai-sdk/provider-utils";
3865
+ import { z as z19 } from "zod/v4";
3866
+ var xaiSpeechModelOptionsSchema = lazySchema8(
3867
+ () => zodSchema8(
3868
+ z19.object({
3869
+ /**
3870
+ * Sample rate of the generated audio in Hz.
3871
+ */
3872
+ sampleRate: z19.union([
3873
+ z19.literal(8e3),
3874
+ z19.literal(16e3),
3875
+ z19.literal(22050),
3876
+ z19.literal(24e3),
3877
+ z19.literal(44100),
3878
+ z19.literal(48e3)
3879
+ ]).nullish(),
3880
+ /**
3881
+ * MP3 bit rate in bits per second. Only applies when outputFormat is mp3.
3882
+ */
3883
+ bitRate: z19.union([
3884
+ z19.literal(32e3),
3885
+ z19.literal(64e3),
3886
+ z19.literal(96e3),
3887
+ z19.literal(128e3),
3888
+ z19.literal(192e3)
3889
+ ]).nullish(),
3890
+ /**
3891
+ * Reduce time to first audio chunk, trading some quality for latency.
3892
+ */
3893
+ optimizeStreamingLatency: z19.union([z19.literal(0), z19.literal(1), z19.literal(2)]).nullish(),
3894
+ /**
3895
+ * Normalize written-form text into spoken-form text before synthesis.
3896
+ */
3897
+ textNormalization: z19.boolean().nullish()
3898
+ })
3899
+ )
3900
+ );
3901
+
3902
+ // src/xai-speech-model.ts
3903
+ var XaiSpeechModel = class _XaiSpeechModel {
3904
+ constructor(modelId, config) {
3905
+ this.modelId = modelId;
3906
+ this.config = config;
3907
+ this.specificationVersion = "v4";
3908
+ }
3909
+ static [WORKFLOW_SERIALIZE4](model) {
3910
+ return serializeModelOptions4({
3911
+ modelId: model.modelId,
3912
+ config: model.config
3913
+ });
3914
+ }
3915
+ static [WORKFLOW_DESERIALIZE4](options) {
3916
+ return new _XaiSpeechModel(options.modelId, options.config);
3917
+ }
3918
+ get provider() {
3919
+ return this.config.provider;
3920
+ }
3921
+ async getArgs({
3922
+ text,
3923
+ voice = "eve",
3924
+ outputFormat = "mp3",
3925
+ instructions,
3926
+ speed,
3927
+ language = "auto",
3928
+ providerOptions
3929
+ }) {
3930
+ const warnings = [];
3931
+ const xaiOptions = await parseProviderOptions6({
3932
+ provider: "xai",
3933
+ providerOptions,
3934
+ schema: xaiSpeechModelOptionsSchema
3935
+ });
3936
+ let codec = "mp3";
3937
+ if (["mp3", "wav", "pcm", "mulaw", "alaw"].includes(outputFormat)) {
3938
+ codec = outputFormat;
3939
+ } else {
3940
+ warnings.push({
3941
+ type: "unsupported",
3942
+ feature: "outputFormat",
3943
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3944
+ });
3945
+ }
3946
+ if (instructions != null) {
3947
+ warnings.push({
3948
+ type: "unsupported",
3949
+ feature: "instructions",
3950
+ details: "xAI speech models do not support the `instructions` option. Use xAI speech tags in `text` to control delivery."
3951
+ });
3952
+ }
3953
+ const output_format = {
3954
+ codec
3955
+ };
3956
+ if ((xaiOptions == null ? void 0 : xaiOptions.sampleRate) != null) {
3957
+ output_format.sample_rate = xaiOptions.sampleRate;
3958
+ }
3959
+ if ((xaiOptions == null ? void 0 : xaiOptions.bitRate) != null) {
3960
+ if (codec === "mp3") {
3961
+ output_format.bit_rate = xaiOptions.bitRate;
3962
+ } else {
3963
+ warnings.push({
3964
+ type: "unsupported",
3965
+ feature: "providerOptions",
3966
+ details: "xAI `bitRate` is supported only for mp3 output. It was ignored."
3967
+ });
3968
+ }
3969
+ }
3970
+ const requestBody = {
3971
+ text,
3972
+ voice_id: voice,
3973
+ language,
3974
+ output_format,
3975
+ speed,
3976
+ optimize_streaming_latency: xaiOptions == null ? void 0 : xaiOptions.optimizeStreamingLatency,
3977
+ text_normalization: xaiOptions == null ? void 0 : xaiOptions.textNormalization
3978
+ };
3979
+ return { requestBody, warnings };
3980
+ }
3981
+ async doGenerate(options) {
3982
+ var _a, _b, _c;
3983
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
3984
+ const { requestBody, warnings } = await this.getArgs(options);
3985
+ const {
3986
+ value: audio,
3987
+ responseHeaders,
3988
+ rawValue: rawResponse
3989
+ } = await postJsonToApi5({
3990
+ url: `${this.config.baseURL}/tts`,
3991
+ headers: combineHeaders6(
3992
+ this.config.headers ? await resolve(this.config.headers) : void 0,
3993
+ options.headers
3994
+ ),
3995
+ body: requestBody,
3996
+ failedResponseHandler: xaiFailedResponseHandler,
3997
+ successfulResponseHandler: createBinaryResponseHandler2(),
3998
+ abortSignal: options.abortSignal,
3999
+ fetch: this.config.fetch
4000
+ });
4001
+ return {
4002
+ audio,
4003
+ warnings,
4004
+ request: {
4005
+ body: JSON.stringify(requestBody)
4006
+ },
4007
+ response: {
4008
+ timestamp: currentDate,
4009
+ modelId: this.modelId,
4010
+ headers: responseHeaders,
4011
+ body: rawResponse
4012
+ }
4013
+ };
4014
+ }
4015
+ };
4016
+
4017
+ // src/xai-transcription-model.ts
4018
+ import {
4019
+ combineHeaders as combineHeaders7,
4020
+ convertBase64ToUint8Array,
4021
+ createJsonResponseHandler as createJsonResponseHandler6,
4022
+ mediaTypeToExtension,
4023
+ parseProviderOptions as parseProviderOptions7,
4024
+ postFormDataToApi as postFormDataToApi2,
4025
+ serializeModelOptions as serializeModelOptions5,
4026
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
4027
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
4028
+ } from "@ai-sdk/provider-utils";
4029
+ import { z as z21 } from "zod/v4";
4030
+
4031
+ // src/xai-transcription-model-options.ts
4032
+ import {
4033
+ lazySchema as lazySchema9,
4034
+ zodSchema as zodSchema9
4035
+ } from "@ai-sdk/provider-utils";
4036
+ import { z as z20 } from "zod/v4";
4037
+ var xaiTranscriptionModelOptionsSchema = lazySchema9(
4038
+ () => zodSchema9(
4039
+ z20.object({
4040
+ /**
4041
+ * Audio encoding for raw, headerless input audio.
4042
+ */
4043
+ audioFormat: z20.enum(["pcm", "mulaw", "alaw"]).nullish(),
4044
+ /**
4045
+ * Sample rate of the input audio in Hz.
4046
+ */
4047
+ sampleRate: z20.union([
4048
+ z20.literal(8e3),
4049
+ z20.literal(16e3),
4050
+ z20.literal(22050),
4051
+ z20.literal(24e3),
4052
+ z20.literal(44100),
4053
+ z20.literal(48e3)
4054
+ ]).nullish(),
4055
+ /**
4056
+ * Language code used for inverse text normalization.
4057
+ */
4058
+ language: z20.string().nullish(),
4059
+ /**
4060
+ * Enable inverse text normalization. Requires `language`.
4061
+ */
4062
+ format: z20.boolean().nullish(),
4063
+ /**
4064
+ * Enable per-channel transcription for multichannel audio.
4065
+ */
4066
+ multichannel: z20.boolean().nullish(),
4067
+ /**
4068
+ * Number of interleaved audio channels.
4069
+ */
4070
+ channels: z20.number().int().min(2).max(8).nullish(),
4071
+ /**
4072
+ * Enable speaker diarization.
4073
+ */
4074
+ diarize: z20.boolean().nullish(),
4075
+ /**
4076
+ * Terms to bias transcription toward.
4077
+ */
4078
+ keyterm: z20.union([z20.string(), z20.array(z20.string())]).nullish(),
4079
+ /**
4080
+ * Include filler words such as "uh" and "um" in the transcript.
4081
+ */
4082
+ fillerWords: z20.boolean().nullish()
4083
+ })
4084
+ )
4085
+ );
4086
+
4087
+ // src/xai-transcription-model.ts
4088
+ var XaiTranscriptionModel = class _XaiTranscriptionModel {
4089
+ constructor(modelId, config) {
4090
+ this.modelId = modelId;
4091
+ this.config = config;
4092
+ this.specificationVersion = "v4";
4093
+ }
4094
+ static [WORKFLOW_SERIALIZE5](model) {
4095
+ return serializeModelOptions5({
4096
+ modelId: model.modelId,
4097
+ config: model.config
4098
+ });
4099
+ }
4100
+ static [WORKFLOW_DESERIALIZE5](options) {
4101
+ return new _XaiTranscriptionModel(options.modelId, options.config);
4102
+ }
4103
+ get provider() {
4104
+ return this.config.provider;
4105
+ }
4106
+ async getArgs({
4107
+ audio,
4108
+ mediaType,
4109
+ providerOptions
4110
+ }) {
4111
+ const warnings = [];
4112
+ const xaiOptions = await parseProviderOptions7({
4113
+ provider: "xai",
4114
+ providerOptions,
4115
+ schema: xaiTranscriptionModelOptionsSchema
4116
+ });
4117
+ const formData = new FormData();
4118
+ const transcriptionOptions = {
4119
+ audio_format: xaiOptions == null ? void 0 : xaiOptions.audioFormat,
4120
+ sample_rate: xaiOptions == null ? void 0 : xaiOptions.sampleRate,
4121
+ language: xaiOptions == null ? void 0 : xaiOptions.language,
4122
+ format: xaiOptions == null ? void 0 : xaiOptions.format,
4123
+ multichannel: xaiOptions == null ? void 0 : xaiOptions.multichannel,
4124
+ channels: xaiOptions == null ? void 0 : xaiOptions.channels,
4125
+ diarize: xaiOptions == null ? void 0 : xaiOptions.diarize,
4126
+ filler_words: xaiOptions == null ? void 0 : xaiOptions.fillerWords
4127
+ };
4128
+ for (const [key, value] of Object.entries(transcriptionOptions)) {
4129
+ if (value != null) {
4130
+ formData.append(key, String(value));
4131
+ }
4132
+ }
4133
+ if ((xaiOptions == null ? void 0 : xaiOptions.keyterm) != null) {
4134
+ const keyterms = Array.isArray(xaiOptions.keyterm) ? xaiOptions.keyterm : [xaiOptions.keyterm];
4135
+ for (const keyterm of keyterms) {
4136
+ formData.append("keyterm", keyterm);
4137
+ }
4138
+ }
4139
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
4140
+ const fileExtension = mediaTypeToExtension(mediaType);
4141
+ formData.append(
4142
+ "file",
4143
+ new File([blob], "audio", { type: mediaType }),
4144
+ `audio.${fileExtension}`
4145
+ );
4146
+ return { formData, warnings };
4147
+ }
4148
+ async doGenerate(options) {
4149
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4150
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
4151
+ const { formData, warnings } = await this.getArgs(options);
4152
+ const {
4153
+ value: response,
4154
+ responseHeaders,
4155
+ rawValue: rawResponse
4156
+ } = await postFormDataToApi2({
4157
+ url: `${(_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1"}/stt`,
4158
+ headers: combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers),
4159
+ formData,
4160
+ failedResponseHandler: xaiFailedResponseHandler,
4161
+ successfulResponseHandler: createJsonResponseHandler6(
4162
+ xaiTranscriptionResponseSchema
4163
+ ),
4164
+ abortSignal: options.abortSignal,
4165
+ fetch: this.config.fetch
4166
+ });
4167
+ return {
4168
+ text: response.text,
4169
+ segments: (_h = (_g = response.words) == null ? void 0 : _g.map((word) => ({
4170
+ text: word.text,
4171
+ startSecond: word.start,
4172
+ endSecond: word.end
4173
+ }))) != null ? _h : [],
4174
+ language: response.language || void 0,
4175
+ durationInSeconds: (_i = response.duration) != null ? _i : void 0,
4176
+ warnings,
4177
+ response: {
4178
+ timestamp: currentDate,
4179
+ modelId: this.modelId,
4180
+ headers: responseHeaders,
4181
+ body: rawResponse
4182
+ }
4183
+ };
4184
+ }
4185
+ };
4186
+ var xaiTranscriptionResponseSchema = z21.object({
4187
+ text: z21.string(),
4188
+ language: z21.string().nullish(),
4189
+ duration: z21.number().nullish(),
4190
+ words: z21.array(
4191
+ z21.object({
4192
+ text: z21.string(),
4193
+ start: z21.number(),
4194
+ end: z21.number()
4195
+ })
4196
+ ).nullish()
2948
4197
  });
2949
4198
 
2950
4199
  // src/xai-provider.ts
2951
4200
  function createXai(options = {}) {
2952
4201
  var _a;
2953
- const baseURL = (0, import_provider_utils17.withoutTrailingSlash)(
4202
+ const baseURL = withoutTrailingSlash(
2954
4203
  (_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
2955
4204
  );
2956
- const getHeaders = () => (0, import_provider_utils17.withUserAgentSuffix)(
4205
+ const getHeaders = () => withUserAgentSuffix(
2957
4206
  {
2958
- Authorization: `Bearer ${(0, import_provider_utils17.loadApiKey)({
4207
+ Authorization: `Bearer ${loadApiKey({
2959
4208
  apiKey: options.apiKey,
2960
4209
  environmentVariableName: "XAI_API_KEY",
2961
4210
  description: "xAI API key"
@@ -2969,7 +4218,7 @@ function createXai(options = {}) {
2969
4218
  provider: "xai.chat",
2970
4219
  baseURL,
2971
4220
  headers: getHeaders,
2972
- generateId: import_provider_utils17.generateId,
4221
+ generateId,
2973
4222
  fetch: options.fetch
2974
4223
  });
2975
4224
  };
@@ -2978,7 +4227,7 @@ function createXai(options = {}) {
2978
4227
  provider: "xai.responses",
2979
4228
  baseURL,
2980
4229
  headers: getHeaders,
2981
- generateId: import_provider_utils17.generateId,
4230
+ generateId,
2982
4231
  fetch: options.fetch
2983
4232
  });
2984
4233
  };
@@ -2998,25 +4247,78 @@ function createXai(options = {}) {
2998
4247
  fetch: options.fetch
2999
4248
  });
3000
4249
  };
4250
+ const createRealtimeModel = (modelId) => {
4251
+ return new XaiRealtimeModel(modelId, {
4252
+ provider: "xai.realtime",
4253
+ baseURL: baseURL != null ? baseURL : "https://api.x.ai/v1",
4254
+ headers: getHeaders,
4255
+ fetch: options.fetch
4256
+ });
4257
+ };
4258
+ const createSpeechModel = () => {
4259
+ return new XaiSpeechModel("", {
4260
+ provider: "xai.speech",
4261
+ baseURL,
4262
+ headers: getHeaders,
4263
+ fetch: options.fetch
4264
+ });
4265
+ };
4266
+ const createTranscriptionModel = () => {
4267
+ return new XaiTranscriptionModel("", {
4268
+ provider: "xai.transcription",
4269
+ baseURL,
4270
+ headers: getHeaders,
4271
+ fetch: options.fetch
4272
+ });
4273
+ };
4274
+ const experimentalRealtimeFactory = Object.assign(
4275
+ (modelId) => createRealtimeModel(modelId),
4276
+ {
4277
+ getToken: async (tokenOptions) => {
4278
+ const model = createRealtimeModel(tokenOptions.model);
4279
+ const secret = await model.doCreateClientSecret({
4280
+ sessionConfig: tokenOptions.sessionConfig,
4281
+ expiresAfterSeconds: tokenOptions.expiresAfterSeconds
4282
+ });
4283
+ return {
4284
+ token: secret.token,
4285
+ url: secret.url,
4286
+ expiresAt: secret.expiresAt
4287
+ };
4288
+ }
4289
+ }
4290
+ );
4291
+ const createFiles = () => new XaiFiles({
4292
+ provider: "xai.files",
4293
+ baseURL,
4294
+ headers: getHeaders,
4295
+ fetch: options.fetch
4296
+ });
3001
4297
  const provider = (modelId) => createResponsesLanguageModel(modelId);
3002
- provider.specificationVersion = "v3";
4298
+ provider.specificationVersion = "v4";
3003
4299
  provider.languageModel = createResponsesLanguageModel;
3004
4300
  provider.chat = createChatLanguageModel;
3005
4301
  provider.responses = createResponsesLanguageModel;
3006
4302
  provider.embeddingModel = (modelId) => {
3007
- throw new import_provider7.NoSuchModelError({ modelId, modelType: "embeddingModel" });
4303
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
3008
4304
  };
3009
4305
  provider.textEmbeddingModel = provider.embeddingModel;
3010
4306
  provider.imageModel = createImageModel;
3011
4307
  provider.image = createImageModel;
3012
4308
  provider.videoModel = createVideoModel;
3013
4309
  provider.video = createVideoModel;
4310
+ provider.experimental_realtime = experimentalRealtimeFactory;
4311
+ provider.speechModel = createSpeechModel;
4312
+ provider.speech = createSpeechModel;
4313
+ provider.transcriptionModel = createTranscriptionModel;
4314
+ provider.transcription = createTranscriptionModel;
4315
+ provider.files = createFiles;
3014
4316
  provider.tools = xaiTools;
3015
4317
  return provider;
3016
4318
  }
3017
4319
  var xai = createXai();
3018
- // Annotate the CommonJS export names for ESM import in node:
3019
- 0 && (module.exports = {
4320
+ export {
4321
+ XaiRealtimeModel as Experimental_XaiRealtimeModel,
3020
4322
  VERSION,
3021
4323
  codeExecution,
3022
4324
  createXai,
@@ -3027,5 +4329,5 @@ var xai = createXai();
3027
4329
  xSearch,
3028
4330
  xai,
3029
4331
  xaiTools
3030
- });
4332
+ };
3031
4333
  //# sourceMappingURL=index.js.map