@ai-sdk/xai 4.0.59 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,1051 +9,64 @@ import {
9
9
  withUserAgentSuffix
10
10
  } from "@ai-sdk/provider-utils";
11
11
 
12
- // src/xai-chat-language-model.ts
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 as parseProviderOptions2,
24
- postJsonToApi,
25
- safeParseJSON,
26
- serializeModelOptions,
27
- WORKFLOW_SERIALIZE,
28
- WORKFLOW_DESERIALIZE
29
- } from "@ai-sdk/provider-utils";
30
- import { z as z4 } from "zod/v4";
31
-
32
- // src/convert-to-xai-chat-messages.ts
33
- import {
34
- UnsupportedFunctionalityError
35
- } from "@ai-sdk/provider";
36
- import {
37
- convertToBase64,
38
- getTopLevelMediaType,
39
- parseProviderOptions,
40
- resolveFullMediaType,
41
- resolveProviderReference
42
- } from "@ai-sdk/provider-utils";
43
-
44
- // src/xai-file-part-options.ts
45
- import { z } from "zod/v4";
46
- var xaiFilePartProviderOptions = z.object({
47
- /**
48
- * Controls the resolution at which the model processes the image.
49
- * `low` processes the image at reduced resolution and consumes fewer
50
- * input tokens, `high` processes the image at full resolution, and
51
- * `auto` lets the API decide. Defaults to full resolution when not set.
52
- *
53
- * Note: the xAI API silently ignores invalid values, so the value is
54
- * validated client-side.
55
- *
56
- * @see https://docs.x.ai/developers/model-capabilities/images/understanding
57
- */
58
- imageDetail: z.enum(["low", "high", "auto"]).optional()
59
- });
60
-
61
- // src/convert-to-xai-chat-messages.ts
62
- async function convertToXaiChatMessages(prompt) {
63
- var _a;
64
- const messages = [];
65
- const warnings = [];
66
- for (const { role, content } of prompt) {
67
- switch (role) {
68
- case "system": {
69
- messages.push({ role: "system", content });
70
- break;
71
- }
72
- case "user": {
73
- if (content.length === 1 && content[0].type === "text") {
74
- messages.push({ role: "user", content: content[0].text });
75
- break;
76
- }
77
- const userContent = [];
78
- for (const part of content) {
79
- switch (part.type) {
80
- case "text": {
81
- userContent.push({ type: "text", text: part.text });
82
- break;
83
- }
84
- case "file": {
85
- switch (part.data.type) {
86
- case "reference": {
87
- userContent.push({
88
- type: "file",
89
- file: {
90
- file_id: resolveProviderReference({
91
- reference: part.data.reference,
92
- provider: "xai"
93
- })
94
- }
95
- });
96
- break;
97
- }
98
- case "text": {
99
- throw new UnsupportedFunctionalityError({
100
- functionality: "text file parts"
101
- });
102
- }
103
- case "url":
104
- case "data": {
105
- if (getTopLevelMediaType(part.mediaType) === "image") {
106
- const filePartOptions = await parseProviderOptions({
107
- provider: "xai",
108
- providerOptions: part.providerOptions,
109
- schema: xaiFilePartProviderOptions
110
- });
111
- userContent.push({
112
- type: "image_url",
113
- image_url: {
114
- url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
115
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
116
- detail: filePartOptions.imageDetail
117
- }
118
- }
119
- });
120
- } else {
121
- throw new UnsupportedFunctionalityError({
122
- functionality: `file part media type ${part.mediaType}`
123
- });
124
- }
125
- break;
126
- }
127
- }
128
- break;
129
- }
130
- }
131
- }
132
- messages.push({ role: "user", content: userContent });
133
- break;
134
- }
135
- case "assistant": {
136
- let text = "";
137
- const toolCalls = [];
138
- for (const part of content) {
139
- switch (part.type) {
140
- case "text": {
141
- text += part.text;
142
- break;
143
- }
144
- case "tool-call": {
145
- toolCalls.push({
146
- id: part.toolCallId,
147
- type: "function",
148
- function: {
149
- name: part.toolName,
150
- arguments: JSON.stringify(part.input)
151
- }
152
- });
153
- break;
154
- }
155
- }
156
- }
157
- messages.push({
158
- role: "assistant",
159
- content: text,
160
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
161
- });
162
- break;
163
- }
164
- case "tool": {
165
- for (const toolResponse of content) {
166
- if (toolResponse.type === "tool-approval-response") {
167
- continue;
168
- }
169
- const output = toolResponse.output;
170
- let contentValue;
171
- switch (output.type) {
172
- case "text":
173
- case "error-text":
174
- contentValue = output.value;
175
- break;
176
- case "execution-denied":
177
- contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
178
- break;
179
- case "content":
180
- case "json":
181
- case "error-json":
182
- contentValue = JSON.stringify(output.value);
183
- break;
184
- }
185
- messages.push({
186
- role: "tool",
187
- tool_call_id: toolResponse.toolCallId,
188
- content: contentValue
189
- });
190
- }
191
- break;
192
- }
193
- default: {
194
- const _exhaustiveCheck = role;
195
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
196
- }
197
- }
198
- }
199
- return { messages, warnings };
200
- }
201
-
202
- // src/convert-xai-chat-usage.ts
203
- function convertXaiChatUsage(usage) {
204
- var _a, _b, _c, _d;
205
- const cacheReadTokens = (_b = (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
206
- const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
207
- const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
208
- return {
209
- inputTokens: {
210
- total: promptTokensIncludesCached ? usage.prompt_tokens : usage.prompt_tokens + cacheReadTokens,
211
- noCache: promptTokensIncludesCached ? usage.prompt_tokens - cacheReadTokens : usage.prompt_tokens,
212
- cacheRead: cacheReadTokens,
213
- cacheWrite: void 0
214
- },
215
- outputTokens: {
216
- total: usage.completion_tokens + reasoningTokens,
217
- text: usage.completion_tokens,
218
- reasoning: reasoningTokens
219
- },
220
- raw: usage
221
- };
222
- }
223
-
224
- // src/get-response-metadata.ts
225
- import { createLanguageModelResponseMetadata } from "@ai-sdk/provider-utils";
226
- function getResponseMetadata({
227
- id,
228
- model,
229
- created,
230
- created_at
231
- }) {
232
- return createLanguageModelResponseMetadata({
233
- id,
234
- model,
235
- created: created != null ? created : created_at
236
- });
237
- }
238
-
239
- // src/map-xai-finish-reason.ts
240
- function mapXaiFinishReason(finishReason) {
241
- switch (finishReason) {
242
- case "stop":
243
- return "stop";
244
- case "length":
245
- return "length";
246
- case "tool_calls":
247
- case "function_call":
248
- return "tool-calls";
249
- case "content_filter":
250
- return "content-filter";
251
- default:
252
- return "other";
253
- }
254
- }
255
-
256
- // src/supports-reasoning-effort.ts
257
- var modelsWithoutReasoningEffort = /^grok-4\.20(-\d{4})?-(non-)?reasoning$/;
258
- function supportsReasoningEffort(modelId) {
259
- return !modelsWithoutReasoningEffort.test(modelId);
260
- }
261
-
262
- // src/xai-chat-language-model-options.ts
263
- import { z as z2 } from "zod/v4";
264
- var webSourceSchema = z2.object({
265
- type: z2.literal("web"),
266
- country: z2.string().length(2).optional(),
267
- excludedWebsites: z2.array(z2.string()).max(5).optional(),
268
- allowedWebsites: z2.array(z2.string()).max(5).optional(),
269
- safeSearch: z2.boolean().optional()
270
- });
271
- var xSourceSchema = z2.object({
272
- type: z2.literal("x"),
273
- excludedXHandles: z2.array(z2.string()).optional(),
274
- includedXHandles: z2.array(z2.string()).optional(),
275
- postFavoriteCount: z2.number().int().optional(),
276
- postViewCount: z2.number().int().optional(),
277
- /**
278
- * @deprecated use `includedXHandles` instead
279
- */
280
- xHandles: z2.array(z2.string()).optional()
281
- });
282
- var newsSourceSchema = z2.object({
283
- type: z2.literal("news"),
284
- country: z2.string().length(2).optional(),
285
- excludedWebsites: z2.array(z2.string()).max(5).optional(),
286
- safeSearch: z2.boolean().optional()
287
- });
288
- var rssSourceSchema = z2.object({
289
- type: z2.literal("rss"),
290
- links: z2.array(z2.string().url()).max(1)
291
- // currently only supports one RSS link
292
- });
293
- var searchSourceSchema = z2.discriminatedUnion("type", [
294
- webSourceSchema,
295
- xSourceSchema,
296
- newsSourceSchema,
297
- rssSourceSchema
298
- ]);
299
- var xaiLanguageModelChatOptions = z2.object({
300
- /**
301
- * Constrains how hard a reasoning model thinks before responding.
302
- *
303
- * - `none`: Disables reasoning entirely (supported by `grok-4.3` and newer
304
- * reasoning models). When set, no thinking tokens are used.
305
- * - `low` (default): Uses some reasoning tokens, but still fast.
306
- * - `medium`: More thinking for less-latency-sensitive applications.
307
- * - `high`: Uses more reasoning tokens for deeper thinking.
308
- * - `xhigh`: Uses the most reasoning tokens (supported by `grok-4.6`).
309
- *
310
- * Note: Not every Grok model accepts every value. Refer to xAI's docs for
311
- * the values supported by your selected model.
312
- *
313
- * @see https://docs.x.ai/docs/guides/reasoning
314
- */
315
- reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
316
- logprobs: z2.boolean().optional(),
317
- topLogprobs: z2.number().int().min(0).max(8).optional(),
318
- serviceTier: z2.enum(["default", "priority"]).optional(),
319
- /**
320
- * Whether to enable parallel function calling during tool use.
321
- * When true, the model can call multiple functions in parallel.
322
- * When false, the model will call functions sequentially.
323
- * Defaults to true.
324
- */
325
- parallel_function_calling: z2.boolean().optional(),
326
- /**
327
- * @deprecated xAI has deprecated Live Search (`search_parameters`) in favor
328
- * of the Agent Tools API. Requests using this option now return a "Live
329
- * search is deprecated" error. Use the `web_search` / `x_search` tools
330
- * instead (e.g. `xai.tools.webSearch()`, `xai.tools.xSearch()`) with
331
- * `xai.responses(modelId)`.
332
- *
333
- * @see https://docs.x.ai/docs/guides/tools/overview
334
- */
335
- searchParameters: z2.object({
336
- /**
337
- * search mode preference
338
- * - "off": disables search completely
339
- * - "auto": model decides whether to search (default)
340
- * - "on": always enables search
341
- */
342
- mode: z2.enum(["off", "auto", "on"]),
343
- /**
344
- * whether to return citations in the response
345
- * defaults to true
346
- */
347
- returnCitations: z2.boolean().optional(),
348
- /**
349
- * start date for search data (ISO8601 format: YYYY-MM-DD)
350
- */
351
- fromDate: z2.string().optional(),
352
- /**
353
- * end date for search data (ISO8601 format: YYYY-MM-DD)
354
- */
355
- toDate: z2.string().optional(),
356
- /**
357
- * maximum number of search results to consider
358
- * defaults to 20
359
- */
360
- maxSearchResults: z2.number().min(1).max(50).optional(),
361
- /**
362
- * data sources to search from.
363
- * defaults to [{ type: 'web' }, { type: 'x' }] if not specified.
364
- *
365
- * @example
366
- * sources: [{ type: 'web', country: 'US' }, { type: 'x' }]
367
- */
368
- sources: z2.array(searchSourceSchema).optional()
369
- }).optional()
370
- });
371
-
372
- // src/xai-error.ts
373
- import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
374
- import { z as z3 } from "zod/v4";
375
- var chatCompletionsErrorSchema = z3.object({
376
- error: z3.object({
377
- message: z3.string(),
378
- type: z3.string().nullish(),
379
- param: z3.any().nullish(),
380
- code: z3.union([z3.string(), z3.number()]).nullish()
381
- })
382
- });
383
- var responsesErrorSchema = z3.object({
384
- code: z3.string(),
385
- error: z3.string()
386
- });
387
- var speechErrorSchema = z3.object({
388
- error: z3.string()
389
- });
390
- var xaiErrorDataSchema = z3.union([
391
- chatCompletionsErrorSchema,
392
- responsesErrorSchema,
393
- speechErrorSchema
394
- ]);
395
- var xaiFailedResponseHandler = createJsonErrorResponseHandler({
396
- errorSchema: xaiErrorDataSchema,
397
- errorToMessage: (data) => {
398
- if (typeof data.error === "string") {
399
- return "code" in data ? `${data.code}: ${data.error}` : data.error;
400
- }
401
- return data.error.message;
402
- }
403
- });
404
-
405
- // src/xai-prepare-tools.ts
406
- import {
407
- UnsupportedFunctionalityError as UnsupportedFunctionalityError2
408
- } from "@ai-sdk/provider";
409
- function prepareTools({
410
- tools,
411
- toolChoice
412
- }) {
413
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
414
- const toolWarnings = [];
415
- if (tools == null) {
416
- return { tools: void 0, toolChoice: void 0, toolWarnings };
417
- }
418
- const xaiTools2 = [];
419
- for (const tool of tools) {
420
- if (tool.type === "provider") {
421
- toolWarnings.push({
422
- type: "unsupported",
423
- feature: `provider-defined tool ${tool.name}`
424
- });
425
- } else {
426
- xaiTools2.push({
427
- type: "function",
428
- function: {
429
- name: tool.name,
430
- description: tool.description,
431
- parameters: tool.inputSchema,
432
- ...tool.strict != null ? { strict: tool.strict } : {}
433
- }
434
- });
435
- }
436
- }
437
- if (toolChoice == null) {
438
- return { tools: xaiTools2, toolChoice: void 0, toolWarnings };
439
- }
440
- const type = toolChoice.type;
441
- switch (type) {
442
- case "auto":
443
- case "none":
444
- return { tools: xaiTools2, toolChoice: type, toolWarnings };
445
- case "required":
446
- return { tools: xaiTools2, toolChoice: "required", toolWarnings };
447
- case "tool":
448
- return {
449
- tools: xaiTools2,
450
- toolChoice: {
451
- type: "function",
452
- function: { name: toolChoice.toolName }
453
- },
454
- toolWarnings
455
- };
456
- default: {
457
- const _exhaustiveCheck = type;
458
- throw new UnsupportedFunctionalityError2({
459
- functionality: `tool choice type: ${_exhaustiveCheck}`
460
- });
461
- }
462
- }
463
- }
464
-
465
- // src/xai-chat-language-model.ts
466
- var XaiChatLanguageModel = class _XaiChatLanguageModel {
467
- constructor(modelId, config) {
468
- this.specificationVersion = "v4";
469
- this.supportedUrls = {
470
- "image/*": [/^https?:\/\/.*$/]
471
- };
472
- this.modelId = modelId;
473
- this.config = config;
474
- }
475
- static [WORKFLOW_SERIALIZE](model) {
476
- return serializeModelOptions({
477
- modelId: model.modelId,
478
- config: model.config
479
- });
480
- }
481
- static [WORKFLOW_DESERIALIZE](options) {
482
- return new _XaiChatLanguageModel(options.modelId, options.config);
483
- }
484
- get provider() {
485
- return this.config.provider;
486
- }
487
- async getArgs({
488
- prompt,
489
- maxOutputTokens,
490
- temperature,
491
- topP,
492
- topK,
493
- frequencyPenalty,
494
- presencePenalty,
495
- stopSequences,
496
- seed,
497
- reasoning,
498
- responseFormat,
499
- providerOptions,
500
- tools,
501
- toolChoice
502
- }) {
503
- var _a, _b, _c;
504
- const warnings = [];
505
- const options = (_a = await parseProviderOptions2({
506
- provider: "xai",
507
- providerOptions,
508
- schema: xaiLanguageModelChatOptions
509
- })) != null ? _a : {};
510
- if (topK != null) {
511
- warnings.push({ type: "unsupported", feature: "topK" });
512
- }
513
- if (frequencyPenalty != null) {
514
- warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
515
- }
516
- if (presencePenalty != null) {
517
- warnings.push({ type: "unsupported", feature: "presencePenalty" });
518
- }
519
- if (stopSequences != null) {
520
- warnings.push({ type: "unsupported", feature: "stopSequences" });
521
- }
522
- const { messages, warnings: messageWarnings } = await convertToXaiChatMessages(prompt);
523
- warnings.push(...messageWarnings);
524
- const {
525
- tools: xaiTools2,
526
- toolChoice: xaiToolChoice,
527
- toolWarnings
528
- } = prepareTools({
529
- tools,
530
- toolChoice
531
- });
532
- warnings.push(...toolWarnings);
533
- let reasoningEffort = options.reasoningEffort;
534
- if (reasoningEffort == null && isCustomReasoning(reasoning)) {
535
- if (!supportsReasoningEffort(this.modelId)) {
536
- warnings.push({
537
- type: "unsupported",
538
- feature: "reasoning",
539
- details: `reasoning "${reasoning}" is not supported by this model.`
540
- });
541
- } else if (reasoning === "none") {
542
- reasoningEffort = "none";
543
- } else {
544
- reasoningEffort = mapReasoningToProviderEffort({
545
- reasoning,
546
- effortMap: {
547
- minimal: "low",
548
- low: "low",
549
- medium: "medium",
550
- high: "high",
551
- xhigh: this.modelId === "grok-4.6" ? "xhigh" : "high"
552
- },
553
- warnings
554
- });
555
- }
556
- }
557
- const baseArgs = {
558
- // model id
559
- model: this.modelId,
560
- // standard generation settings
561
- logprobs: options.logprobs === true || options.topLogprobs != null ? true : void 0,
562
- top_logprobs: options.topLogprobs,
563
- max_completion_tokens: maxOutputTokens,
564
- temperature,
565
- top_p: topP,
566
- seed,
567
- reasoning_effort: reasoningEffort,
568
- // scheduling priority
569
- service_tier: options.serviceTier,
570
- // parallel function calling
571
- parallel_function_calling: options.parallel_function_calling,
572
- // response format
573
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
574
- type: "json_schema",
575
- json_schema: {
576
- name: (_b = responseFormat.name) != null ? _b : "response",
577
- schema: responseFormat.schema,
578
- strict: true
579
- }
580
- } : { type: "json_object" } : void 0,
581
- // search parameters
582
- search_parameters: options.searchParameters ? {
583
- mode: options.searchParameters.mode,
584
- return_citations: options.searchParameters.returnCitations,
585
- from_date: options.searchParameters.fromDate,
586
- to_date: options.searchParameters.toDate,
587
- max_search_results: options.searchParameters.maxSearchResults,
588
- sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
589
- var _a2;
590
- return {
591
- type: source.type,
592
- ...source.type === "web" && {
593
- country: source.country,
594
- excluded_websites: source.excludedWebsites,
595
- allowed_websites: source.allowedWebsites,
596
- safe_search: source.safeSearch
597
- },
598
- ...source.type === "x" && {
599
- excluded_x_handles: source.excludedXHandles,
600
- included_x_handles: (_a2 = source.includedXHandles) != null ? _a2 : source.xHandles,
601
- post_favorite_count: source.postFavoriteCount,
602
- post_view_count: source.postViewCount
603
- },
604
- ...source.type === "news" && {
605
- country: source.country,
606
- excluded_websites: source.excludedWebsites,
607
- safe_search: source.safeSearch
608
- },
609
- ...source.type === "rss" && {
610
- links: source.links
611
- }
612
- };
613
- })
614
- } : void 0,
615
- // messages in xai format
616
- messages,
617
- // tools in xai format
618
- tools: xaiTools2,
619
- tool_choice: xaiToolChoice
620
- };
621
- return {
622
- args: baseArgs,
623
- warnings
624
- };
625
- }
626
- async doGenerate(options) {
627
- var _a, _b, _c, _d;
628
- const { args: body, warnings } = await this.getArgs(options);
629
- const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
630
- const {
631
- responseHeaders,
632
- value: response,
633
- rawValue: rawResponse
634
- } = await postJsonToApi({
635
- url,
636
- headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
637
- body,
638
- failedResponseHandler: xaiFailedResponseHandler,
639
- successfulResponseHandler: createJsonResponseHandler(
640
- xaiChatResponseSchema
641
- ),
642
- abortSignal: options.abortSignal,
643
- fetch: this.config.fetch
644
- });
645
- if (response.error != null) {
646
- throw new APICallError({
647
- message: response.error,
648
- url,
649
- requestBodyValues: body,
650
- statusCode: 200,
651
- responseHeaders,
652
- responseBody: JSON.stringify(rawResponse),
653
- isRetryable: response.code === "The service is currently unavailable"
654
- });
655
- }
656
- const choice = response.choices[0];
657
- const content = [];
658
- if (choice.message.content != null && choice.message.content.length > 0) {
659
- let text = choice.message.content;
660
- const lastMessage = body.messages[body.messages.length - 1];
661
- if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && text === lastMessage.content) {
662
- text = "";
663
- }
664
- if (text.length > 0) {
665
- content.push({ type: "text", text });
666
- }
667
- }
668
- if (choice.message.reasoning_content != null && choice.message.reasoning_content.length > 0) {
669
- content.push({
670
- type: "reasoning",
671
- text: choice.message.reasoning_content
672
- });
673
- }
674
- if (choice.message.tool_calls != null) {
675
- for (const toolCall of choice.message.tool_calls) {
676
- content.push({
677
- type: "tool-call",
678
- toolCallId: toolCall.id,
679
- toolName: toolCall.function.name,
680
- input: toolCall.function.arguments
681
- });
682
- }
683
- }
684
- if (response.citations != null) {
685
- for (const url2 of response.citations) {
686
- content.push({
687
- type: "source",
688
- sourceType: "url",
689
- id: this.config.generateId(),
690
- url: url2
691
- });
692
- }
693
- }
694
- return {
695
- content,
696
- finishReason: {
697
- unified: mapXaiFinishReason(choice.finish_reason),
698
- raw: (_d = choice.finish_reason) != null ? _d : void 0
699
- },
700
- usage: response.usage ? convertXaiChatUsage(response.usage) : {
701
- inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
702
- outputTokens: { total: 0, text: 0, reasoning: 0 }
703
- },
704
- ...response.service_tier != null && {
705
- providerMetadata: {
706
- xai: { serviceTier: response.service_tier }
707
- }
708
- },
709
- request: { body },
710
- response: {
711
- ...getResponseMetadata(response),
712
- headers: responseHeaders,
713
- body: rawResponse
714
- },
715
- warnings
716
- };
717
- }
718
- async doStream(options) {
719
- var _a, _b, _c;
720
- const { args, warnings } = await this.getArgs(options);
721
- const body = {
722
- ...args,
723
- stream: true,
724
- stream_options: {
725
- include_usage: true
726
- }
727
- };
728
- const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
729
- const { responseHeaders, value: response } = await postJsonToApi({
730
- url,
731
- headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
732
- body,
733
- failedResponseHandler: xaiFailedResponseHandler,
734
- successfulResponseHandler: async ({ response: response2 }) => {
735
- const responseHeaders2 = extractResponseHeaders(response2);
736
- const contentType = response2.headers.get("content-type");
737
- if (contentType == null ? void 0 : contentType.includes("application/json")) {
738
- const responseBody = await response2.text();
739
- const parsedError = await safeParseJSON({
740
- text: responseBody,
741
- schema: xaiStreamErrorSchema
742
- });
743
- if (parsedError.success) {
744
- throw new APICallError({
745
- message: parsedError.value.error,
746
- url,
747
- requestBodyValues: body,
748
- statusCode: 200,
749
- responseHeaders: responseHeaders2,
750
- responseBody,
751
- isRetryable: parsedError.value.code === "The service is currently unavailable"
752
- });
753
- }
754
- throw new APICallError({
755
- message: "Invalid JSON response",
756
- url,
757
- requestBodyValues: body,
758
- statusCode: 200,
759
- responseHeaders: responseHeaders2,
760
- responseBody
761
- });
762
- }
763
- return createEventSourceResponseHandler(xaiChatChunkSchema)({
764
- response: response2,
765
- url,
766
- requestBodyValues: body
767
- });
768
- },
769
- abortSignal: options.abortSignal,
770
- fetch: this.config.fetch
771
- });
772
- let finishReason = {
773
- unified: "other",
774
- raw: void 0
775
- };
776
- let usage = void 0;
777
- let serviceTier = void 0;
778
- let isFirstChunk = true;
779
- const contentBlocks = {};
780
- const lastReasoningDeltas = {};
781
- let activeReasoningBlockId = void 0;
782
- const self = this;
783
- return {
784
- stream: response.pipeThrough(
785
- new TransformStream({
786
- start(controller) {
787
- controller.enqueue({ type: "stream-start", warnings });
788
- },
789
- transform(chunk, controller) {
790
- if (options.includeRawChunks) {
791
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
792
- }
793
- if (!chunk.success) {
794
- controller.enqueue({ type: "error", error: chunk.error });
795
- return;
796
- }
797
- const value = chunk.value;
798
- if (isFirstChunk) {
799
- controller.enqueue({
800
- type: "response-metadata",
801
- ...getResponseMetadata(value)
802
- });
803
- isFirstChunk = false;
804
- }
805
- if (value.citations != null) {
806
- for (const url2 of value.citations) {
807
- controller.enqueue({
808
- type: "source",
809
- sourceType: "url",
810
- id: self.config.generateId(),
811
- url: url2
812
- });
813
- }
814
- }
815
- if (value.usage != null) {
816
- usage = convertXaiChatUsage(value.usage);
817
- }
818
- if (value.service_tier != null) {
819
- serviceTier = value.service_tier;
820
- }
821
- const choice = value.choices[0];
822
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
823
- finishReason = {
824
- unified: mapXaiFinishReason(choice.finish_reason),
825
- raw: choice.finish_reason
826
- };
827
- }
828
- if ((choice == null ? void 0 : choice.delta) == null) {
829
- return;
830
- }
831
- const delta = choice.delta;
832
- const choiceIndex = choice.index;
833
- if (delta.content != null && delta.content.length > 0) {
834
- const textContent = delta.content;
835
- if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
836
- controller.enqueue({
837
- type: "reasoning-end",
838
- id: activeReasoningBlockId
839
- });
840
- contentBlocks[activeReasoningBlockId].ended = true;
841
- activeReasoningBlockId = void 0;
842
- }
843
- const lastMessage = body.messages[body.messages.length - 1];
844
- if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
845
- return;
846
- }
847
- const blockId = `text-${value.id || choiceIndex}`;
848
- if (contentBlocks[blockId] == null) {
849
- contentBlocks[blockId] = { type: "text", ended: false };
850
- controller.enqueue({
851
- type: "text-start",
852
- id: blockId
853
- });
854
- }
855
- controller.enqueue({
856
- type: "text-delta",
857
- id: blockId,
858
- delta: textContent
859
- });
860
- }
861
- if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
862
- const blockId = `reasoning-${value.id || choiceIndex}`;
863
- if (lastReasoningDeltas[blockId] === delta.reasoning_content) {
864
- return;
865
- }
866
- lastReasoningDeltas[blockId] = delta.reasoning_content;
867
- if (contentBlocks[blockId] == null) {
868
- contentBlocks[blockId] = { type: "reasoning", ended: false };
869
- activeReasoningBlockId = blockId;
870
- controller.enqueue({
871
- type: "reasoning-start",
872
- id: blockId
873
- });
874
- }
875
- controller.enqueue({
876
- type: "reasoning-delta",
877
- id: blockId,
878
- delta: delta.reasoning_content
879
- });
880
- }
881
- if (delta.tool_calls != null && delta.tool_calls.length > 0) {
882
- if (activeReasoningBlockId != null && !contentBlocks[activeReasoningBlockId].ended) {
883
- controller.enqueue({
884
- type: "reasoning-end",
885
- id: activeReasoningBlockId
886
- });
887
- contentBlocks[activeReasoningBlockId].ended = true;
888
- activeReasoningBlockId = void 0;
889
- }
890
- for (const toolCall of delta.tool_calls) {
891
- const toolCallId = toolCall.id;
892
- controller.enqueue({
893
- type: "tool-input-start",
894
- id: toolCallId,
895
- toolName: toolCall.function.name
896
- });
897
- controller.enqueue({
898
- type: "tool-input-delta",
899
- id: toolCallId,
900
- delta: toolCall.function.arguments
901
- });
902
- controller.enqueue({
903
- type: "tool-input-end",
904
- id: toolCallId
905
- });
906
- controller.enqueue({
907
- type: "tool-call",
908
- toolCallId,
909
- toolName: toolCall.function.name,
910
- input: toolCall.function.arguments
911
- });
912
- }
913
- }
914
- },
915
- flush(controller) {
916
- for (const [blockId, block] of Object.entries(contentBlocks)) {
917
- if (!block.ended) {
918
- controller.enqueue({
919
- type: block.type === "text" ? "text-end" : "reasoning-end",
920
- id: blockId
921
- });
922
- }
923
- }
924
- controller.enqueue({
925
- type: "finish",
926
- finishReason,
927
- usage: usage != null ? usage : {
928
- inputTokens: {
929
- total: 0,
930
- noCache: 0,
931
- cacheRead: 0,
932
- cacheWrite: 0
933
- },
934
- outputTokens: { total: 0, text: 0, reasoning: 0 }
935
- },
936
- ...serviceTier != null && {
937
- providerMetadata: { xai: { serviceTier } }
938
- }
939
- });
940
- }
941
- })
942
- ),
943
- request: { body },
944
- response: { headers: responseHeaders }
945
- };
946
- }
947
- };
948
- var xaiUsageSchema = z4.object({
949
- prompt_tokens: z4.number(),
950
- completion_tokens: z4.number(),
951
- total_tokens: z4.number(),
952
- cost_in_usd_ticks: z4.number().nullish(),
953
- prompt_tokens_details: z4.object({
954
- text_tokens: z4.number().nullish(),
955
- audio_tokens: z4.number().nullish(),
956
- image_tokens: z4.number().nullish(),
957
- cached_tokens: z4.number().nullish()
958
- }).catchall(z4.json()).nullish(),
959
- completion_tokens_details: z4.object({
960
- reasoning_tokens: z4.number().nullish(),
961
- audio_tokens: z4.number().nullish(),
962
- accepted_prediction_tokens: z4.number().nullish(),
963
- rejected_prediction_tokens: z4.number().nullish()
964
- }).catchall(z4.json()).nullish()
965
- }).catchall(z4.json());
966
- var xaiChatResponseSchema = z4.object({
967
- id: z4.string().nullish(),
968
- created: z4.number().nullish(),
969
- model: z4.string().nullish(),
970
- choices: z4.array(
971
- z4.object({
972
- message: z4.object({
973
- role: z4.enum(["assistant", "tool"]),
974
- content: z4.string().nullish(),
975
- reasoning_content: z4.string().nullish(),
976
- tool_calls: z4.array(
977
- z4.object({
978
- id: z4.string(),
979
- type: z4.literal("function"),
980
- function: z4.object({
981
- name: z4.string(),
982
- arguments: z4.string()
983
- })
984
- })
985
- ).nullish()
986
- }),
987
- index: z4.number(),
988
- finish_reason: z4.string().nullish()
989
- })
990
- ).nullish(),
991
- object: z4.literal("chat.completion").nullish(),
992
- usage: xaiUsageSchema.nullish(),
993
- citations: z4.array(z4.string().url()).nullish(),
994
- service_tier: z4.string().nullish(),
995
- code: z4.string().nullish(),
996
- error: z4.string().nullish()
997
- });
998
- var xaiChatChunkSchema = z4.object({
999
- id: z4.string().nullish(),
1000
- created: z4.number().nullish(),
1001
- model: z4.string().nullish(),
1002
- choices: z4.array(
1003
- z4.object({
1004
- delta: z4.object({
1005
- role: z4.enum(["assistant"]).optional(),
1006
- content: z4.string().nullish(),
1007
- reasoning_content: z4.string().nullish(),
1008
- tool_calls: z4.array(
1009
- z4.object({
1010
- id: z4.string(),
1011
- type: z4.literal("function"),
1012
- function: z4.object({
1013
- name: z4.string(),
1014
- arguments: z4.string()
1015
- })
1016
- })
1017
- ).nullish()
1018
- }),
1019
- finish_reason: z4.string().nullish(),
1020
- index: z4.number()
1021
- })
1022
- ),
1023
- usage: xaiUsageSchema.nullish(),
1024
- citations: z4.array(z4.string().url()).nullish(),
1025
- service_tier: z4.string().nullish()
1026
- });
1027
- var xaiStreamErrorSchema = z4.object({
1028
- code: z4.string(),
1029
- error: z4.string()
1030
- });
1031
-
1032
12
  // src/xai-image-model.ts
1033
13
  import {
1034
- combineHeaders as combineHeaders2,
14
+ combineHeaders,
1035
15
  convertImageModelFileToDataUri,
1036
16
  createBinaryResponseHandler,
1037
- createJsonResponseHandler as createJsonResponseHandler2,
17
+ createJsonResponseHandler,
1038
18
  createStatusCodeErrorResponseHandler,
1039
19
  getFromApi,
1040
- parseProviderOptions as parseProviderOptions3,
1041
- postJsonToApi as postJsonToApi2,
1042
- serializeModelOptions as serializeModelOptions2,
1043
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
1044
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
20
+ parseProviderOptions,
21
+ postJsonToApi,
22
+ serializeModelOptions,
23
+ WORKFLOW_SERIALIZE,
24
+ WORKFLOW_DESERIALIZE
1045
25
  } from "@ai-sdk/provider-utils";
1046
- import { z as z6 } from "zod/v4";
26
+ import { z as z3 } from "zod/v4";
27
+
28
+ // src/xai-error.ts
29
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
30
+ import { z } from "zod/v4";
31
+ var apiErrorSchema = z.object({
32
+ error: z.object({
33
+ message: z.string(),
34
+ type: z.string().nullish(),
35
+ param: z.any().nullish(),
36
+ code: z.union([z.string(), z.number()]).nullish()
37
+ })
38
+ });
39
+ var responsesErrorSchema = z.object({
40
+ code: z.string(),
41
+ error: z.string()
42
+ });
43
+ var speechErrorSchema = z.object({
44
+ error: z.string()
45
+ });
46
+ var xaiErrorDataSchema = z.union([
47
+ apiErrorSchema,
48
+ responsesErrorSchema,
49
+ speechErrorSchema
50
+ ]);
51
+ var xaiFailedResponseHandler = createJsonErrorResponseHandler({
52
+ errorSchema: xaiErrorDataSchema,
53
+ errorToMessage: (data) => {
54
+ if (typeof data.error === "string") {
55
+ return "code" in data ? `${data.code}: ${data.error}` : data.error;
56
+ }
57
+ return data.error.message;
58
+ }
59
+ });
1047
60
 
1048
61
  // src/xai-image-model-options.ts
1049
- import { z as z5 } from "zod/v4";
1050
- var xaiImageModelOptions = z5.object({
1051
- aspect_ratio: z5.string().optional(),
1052
- output_format: z5.string().optional(),
1053
- sync_mode: z5.boolean().optional(),
1054
- resolution: z5.enum(["1k", "2k"]).optional(),
1055
- quality: z5.enum(["low", "medium", "high"]).optional(),
1056
- user: z5.string().optional()
62
+ import { z as z2 } from "zod/v4";
63
+ var xaiImageModelOptions = z2.object({
64
+ aspect_ratio: z2.string().optional(),
65
+ output_format: z2.string().optional(),
66
+ sync_mode: z2.boolean().optional(),
67
+ resolution: z2.enum(["1k", "2k"]).optional(),
68
+ quality: z2.enum(["low", "medium", "high"]).optional(),
69
+ user: z2.string().optional()
1057
70
  });
1058
71
 
1059
72
  // src/xai-image-model.ts
@@ -1067,13 +80,13 @@ var XaiImageModel = class _XaiImageModel {
1067
80
  get provider() {
1068
81
  return this.config.provider;
1069
82
  }
1070
- static [WORKFLOW_SERIALIZE2](model) {
1071
- return serializeModelOptions2({
83
+ static [WORKFLOW_SERIALIZE](model) {
84
+ return serializeModelOptions({
1072
85
  modelId: model.modelId,
1073
86
  config: model.config
1074
87
  });
1075
88
  }
1076
- static [WORKFLOW_DESERIALIZE2](options) {
89
+ static [WORKFLOW_DESERIALIZE](options) {
1077
90
  return new _XaiImageModel(options.modelId, options.config);
1078
91
  }
1079
92
  async doGenerate({
@@ -1109,7 +122,7 @@ var XaiImageModel = class _XaiImageModel {
1109
122
  feature: "mask"
1110
123
  });
1111
124
  }
1112
- const xaiOptions = await parseProviderOptions3({
125
+ const xaiOptions = await parseProviderOptions({
1113
126
  provider: "xai",
1114
127
  providerOptions,
1115
128
  schema: xaiImageModelOptions
@@ -1151,12 +164,12 @@ var XaiImageModel = class _XaiImageModel {
1151
164
  }
1152
165
  const baseURL = (_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1";
1153
166
  const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
1154
- const { value: response, responseHeaders } = await postJsonToApi2({
167
+ const { value: response, responseHeaders } = await postJsonToApi({
1155
168
  url: `${baseURL}${endpoint}`,
1156
- headers: combineHeaders2((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
169
+ headers: combineHeaders((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
1157
170
  body,
1158
171
  failedResponseHandler: xaiFailedResponseHandler,
1159
- successfulResponseHandler: createJsonResponseHandler2(
172
+ successfulResponseHandler: createJsonResponseHandler(
1160
173
  xaiImageResponseSchema
1161
174
  ),
1162
175
  abortSignal,
@@ -1205,97 +218,154 @@ var XaiImageModel = class _XaiImageModel {
1205
218
  return value;
1206
219
  }
1207
220
  };
1208
- var xaiImageResponseSchema = z6.object({
1209
- data: z6.array(
1210
- z6.object({
1211
- url: z6.string().nullish(),
1212
- b64_json: z6.string().nullish(),
1213
- revised_prompt: z6.string().nullish(),
1214
- respect_moderation: z6.boolean().nullish()
221
+ var xaiImageResponseSchema = z3.object({
222
+ data: z3.array(
223
+ z3.object({
224
+ url: z3.string().nullish(),
225
+ b64_json: z3.string().nullish(),
226
+ revised_prompt: z3.string().nullish(),
227
+ respect_moderation: z3.boolean().nullish()
1215
228
  })
1216
229
  ),
1217
- usage: z6.object({
1218
- cost_in_usd_ticks: z6.number().nullish()
230
+ usage: z3.object({
231
+ cost_in_usd_ticks: z3.number().nullish()
1219
232
  }).nullish()
1220
233
  });
1221
234
 
1222
235
  // src/xai-batch.ts
1223
236
  import {
1224
237
  InvalidArgumentError,
1225
- UnsupportedFunctionalityError as UnsupportedFunctionalityError5
238
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError3
1226
239
  } from "@ai-sdk/provider";
1227
240
  import {
1228
- combineHeaders as combineHeaders4,
241
+ combineHeaders as combineHeaders3,
1229
242
  convertImageModelFileToDataUri as convertImageModelFileToDataUri2,
1230
243
  convertBase64ToUint8Array,
1231
244
  convertAsyncIteratorToReadableStream,
1232
- createJsonResponseHandler as createJsonResponseHandler4,
245
+ createJsonResponseHandler as createJsonResponseHandler3,
1233
246
  createBinaryResponseHandler as createBinaryResponseHandler2,
1234
247
  createNullLanguageModelUsage,
1235
248
  getFromApi as getFromApi2,
1236
249
  lazySchema as lazySchema7,
1237
250
  normalizeBatchRequestCounts,
1238
- parseProviderOptions as parseProviderOptions6,
251
+ parseProviderOptions as parseProviderOptions4,
1239
252
  postFormDataToApi,
1240
- postJsonToApi as postJsonToApi4,
253
+ postJsonToApi as postJsonToApi3,
1241
254
  safeValidateTypes,
1242
255
  zodSchema as zodSchema7
1243
256
  } from "@ai-sdk/provider-utils";
1244
- import { z as z15 } from "zod/v4";
257
+ import { z as z13 } from "zod/v4";
258
+
259
+ // src/get-response-metadata.ts
260
+ import { createLanguageModelResponseMetadata } from "@ai-sdk/provider-utils";
261
+ function getResponseMetadata({
262
+ id,
263
+ model,
264
+ created,
265
+ created_at
266
+ }) {
267
+ return createLanguageModelResponseMetadata({
268
+ id,
269
+ model,
270
+ created: created != null ? created : created_at
271
+ });
272
+ }
273
+
274
+ // src/map-xai-finish-reason.ts
275
+ function mapXaiFinishReason(finishReason) {
276
+ switch (finishReason) {
277
+ case "stop":
278
+ return "stop";
279
+ case "length":
280
+ return "length";
281
+ case "tool_calls":
282
+ case "function_call":
283
+ return "tool-calls";
284
+ case "content_filter":
285
+ return "content-filter";
286
+ default:
287
+ return "other";
288
+ }
289
+ }
1245
290
 
1246
291
  // src/files/xai-files-api.ts
1247
292
  import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
1248
- import { z as z7 } from "zod/v4";
293
+ import { z as z4 } from "zod/v4";
1249
294
  var xaiFilesResponseSchema = lazySchema(
1250
295
  () => zodSchema(
1251
- z7.object({
1252
- id: z7.string(),
1253
- object: z7.string().nullish(),
1254
- bytes: z7.number().nullish(),
1255
- created_at: z7.number().nullish(),
1256
- expires_at: z7.number().nullish(),
1257
- filename: z7.string().nullish(),
1258
- purpose: z7.string().nullish(),
1259
- status: z7.string().nullish()
296
+ z4.object({
297
+ id: z4.string(),
298
+ object: z4.string().nullish(),
299
+ bytes: z4.number().nullish(),
300
+ created_at: z4.number().nullish(),
301
+ expires_at: z4.number().nullish(),
302
+ filename: z4.string().nullish(),
303
+ purpose: z4.string().nullish(),
304
+ status: z4.string().nullish()
1260
305
  })
1261
306
  )
1262
307
  );
1263
308
  var xaiFileDeleteResponseSchema = lazySchema(
1264
309
  () => zodSchema(
1265
- z7.object({
1266
- id: z7.string(),
1267
- object: z7.string().nullish(),
1268
- deleted: z7.boolean()
310
+ z4.object({
311
+ id: z4.string(),
312
+ object: z4.string().nullish(),
313
+ deleted: z4.boolean()
1269
314
  })
1270
315
  )
1271
316
  );
1272
317
 
1273
318
  // src/responses/xai-responses-language-model.ts
1274
319
  import {
1275
- combineHeaders as combineHeaders3,
1276
- createEventSourceResponseHandler as createEventSourceResponseHandler2,
1277
- createJsonResponseHandler as createJsonResponseHandler3,
320
+ combineHeaders as combineHeaders2,
321
+ createEventSourceResponseHandler,
322
+ createJsonResponseHandler as createJsonResponseHandler2,
1278
323
  createProviderStreamError,
1279
- isCustomReasoning as isCustomReasoning2,
1280
- mapReasoningToProviderEffort as mapReasoningToProviderEffort2,
1281
- parseProviderOptions as parseProviderOptions5,
1282
- postJsonToApi as postJsonToApi3,
1283
- serializeModelOptions as serializeModelOptions3,
1284
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
1285
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
324
+ isCustomReasoning,
325
+ mapReasoningToProviderEffort,
326
+ parseProviderOptions as parseProviderOptions3,
327
+ postJsonToApi as postJsonToApi2,
328
+ serializeModelOptions as serializeModelOptions2,
329
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
330
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
1286
331
  } from "@ai-sdk/provider-utils";
1287
332
 
333
+ // src/supports-reasoning-effort.ts
334
+ var modelsWithoutReasoningEffort = /^grok-4\.20(-\d{4})?-(non-)?reasoning$/;
335
+ function supportsReasoningEffort(modelId) {
336
+ return !modelsWithoutReasoningEffort.test(modelId);
337
+ }
338
+
1288
339
  // src/responses/convert-to-xai-responses-input.ts
1289
340
  import {
1290
- UnsupportedFunctionalityError as UnsupportedFunctionalityError3
341
+ UnsupportedFunctionalityError
1291
342
  } from "@ai-sdk/provider";
1292
343
  import {
1293
- convertToBase64 as convertToBase642,
1294
- getTopLevelMediaType as getTopLevelMediaType2,
1295
- parseProviderOptions as parseProviderOptions4,
1296
- resolveFullMediaType as resolveFullMediaType2,
1297
- resolveProviderReference as resolveProviderReference2
344
+ convertToBase64,
345
+ getTopLevelMediaType,
346
+ parseProviderOptions as parseProviderOptions2,
347
+ resolveFullMediaType,
348
+ resolveProviderReference
1298
349
  } from "@ai-sdk/provider-utils";
350
+
351
+ // src/xai-file-part-options.ts
352
+ import { z as z5 } from "zod/v4";
353
+ var xaiFilePartProviderOptions = z5.object({
354
+ /**
355
+ * Controls the resolution at which the model processes the image.
356
+ * `low` processes the image at reduced resolution and consumes fewer
357
+ * input tokens, `high` processes the image at full resolution, and
358
+ * `auto` lets the API decide. Defaults to full resolution when not set.
359
+ *
360
+ * Note: the xAI API silently ignores invalid values, so the value is
361
+ * validated client-side.
362
+ *
363
+ * @see https://docs.x.ai/developers/model-capabilities/images/understanding
364
+ */
365
+ imageDetail: z5.enum(["low", "high", "auto"]).optional()
366
+ });
367
+
368
+ // src/responses/convert-to-xai-responses-input.ts
1299
369
  async function convertToXaiResponsesInput({
1300
370
  prompt
1301
371
  }) {
@@ -1324,7 +394,7 @@ async function convertToXaiResponsesInput({
1324
394
  case "reference": {
1325
395
  contentParts.push({
1326
396
  type: "input_file",
1327
- file_id: resolveProviderReference2({
397
+ file_id: resolveProviderReference({
1328
398
  reference: block.data.reference,
1329
399
  provider: "xai"
1330
400
  })
@@ -1332,15 +402,15 @@ async function convertToXaiResponsesInput({
1332
402
  break;
1333
403
  }
1334
404
  case "text": {
1335
- throw new UnsupportedFunctionalityError3({
405
+ throw new UnsupportedFunctionalityError({
1336
406
  functionality: "text file parts"
1337
407
  });
1338
408
  }
1339
409
  case "url":
1340
410
  case "data": {
1341
- if (getTopLevelMediaType2(block.mediaType) === "image") {
1342
- const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${resolveFullMediaType2({ part: block })};base64,${convertToBase642(block.data.data)}`;
1343
- const filePartOptions = await parseProviderOptions4({
411
+ if (getTopLevelMediaType(block.mediaType) === "image") {
412
+ const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${resolveFullMediaType({ part: block })};base64,${convertToBase64(block.data.data)}`;
413
+ const filePartOptions = await parseProviderOptions2({
1344
414
  provider: "xai",
1345
415
  providerOptions: block.providerOptions,
1346
416
  schema: xaiFilePartProviderOptions
@@ -1358,7 +428,7 @@ async function convertToXaiResponsesInput({
1358
428
  file_url: block.data.url.toString()
1359
429
  });
1360
430
  } else {
1361
- throw new UnsupportedFunctionalityError3({
431
+ throw new UnsupportedFunctionalityError({
1362
432
  functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
1363
433
  });
1364
434
  }
@@ -1491,10 +561,10 @@ async function convertToXaiResponsesInput({
1491
561
  break;
1492
562
  }
1493
563
  case "file": {
1494
- if (getTopLevelMediaType2(item.mediaType) === "image" && (item.data.type === "data" || item.data.type === "url")) {
564
+ if (getTopLevelMediaType(item.mediaType) === "image" && (item.data.type === "data" || item.data.type === "url")) {
1495
565
  outputValue.push({
1496
566
  type: "input_image",
1497
- image_url: item.data.type === "url" ? item.data.url.toString() : `data:${resolveFullMediaType2({ part: item })};base64,${convertToBase642(item.data.data)}`
567
+ image_url: item.data.type === "url" ? item.data.url.toString() : `data:${resolveFullMediaType({ part: item })};base64,${convertToBase64(item.data.data)}`
1498
568
  });
1499
569
  }
1500
570
  break;
@@ -1575,484 +645,484 @@ function mapXaiResponsesFinishReason(finishReason) {
1575
645
  }
1576
646
 
1577
647
  // src/responses/xai-responses-api.ts
1578
- import { z as z8 } from "zod/v4";
1579
- var annotationSchema = z8.union([
1580
- z8.object({
1581
- type: z8.literal("url_citation"),
1582
- url: z8.string(),
1583
- title: z8.string().optional()
648
+ import { z as z6 } from "zod/v4";
649
+ var annotationSchema = z6.union([
650
+ z6.object({
651
+ type: z6.literal("url_citation"),
652
+ url: z6.string(),
653
+ title: z6.string().optional()
1584
654
  }),
1585
- z8.object({
1586
- type: z8.string()
655
+ z6.object({
656
+ type: z6.string()
1587
657
  })
1588
658
  ]);
1589
- var messageContentPartSchema = z8.object({
1590
- type: z8.string(),
1591
- text: z8.string().optional(),
1592
- logprobs: z8.array(z8.any()).optional(),
1593
- annotations: z8.array(annotationSchema).optional()
659
+ var messageContentPartSchema = z6.object({
660
+ type: z6.string(),
661
+ text: z6.string().optional(),
662
+ logprobs: z6.array(z6.any()).optional(),
663
+ annotations: z6.array(annotationSchema).optional()
1594
664
  });
1595
- var reasoningSummaryPartSchema = z8.object({
1596
- type: z8.string(),
1597
- text: z8.string()
665
+ var reasoningSummaryPartSchema = z6.object({
666
+ type: z6.string(),
667
+ text: z6.string()
1598
668
  });
1599
- var toolCallSchema = z8.object({
1600
- name: z8.string().optional(),
1601
- arguments: z8.string().optional(),
1602
- input: z8.string().optional(),
1603
- call_id: z8.string().optional(),
1604
- id: z8.string(),
1605
- status: z8.string(),
1606
- action: z8.any().optional()
669
+ var toolCallSchema = z6.object({
670
+ name: z6.string().optional(),
671
+ arguments: z6.string().optional(),
672
+ input: z6.string().optional(),
673
+ call_id: z6.string().optional(),
674
+ id: z6.string(),
675
+ status: z6.string(),
676
+ action: z6.any().optional()
1607
677
  });
1608
- var webSearchWireSourceSchema = z8.object({
1609
- type: z8.literal("url"),
1610
- url: z8.string()
678
+ var webSearchWireSourceSchema = z6.object({
679
+ type: z6.literal("url"),
680
+ url: z6.string()
1611
681
  });
1612
- var webSearchWireActionSchema = z8.discriminatedUnion("type", [
1613
- z8.object({
1614
- type: z8.literal("search"),
1615
- query: z8.string().nullish(),
1616
- queries: z8.array(z8.string()).nullish(),
1617
- sources: z8.array(z8.unknown()).nullish()
682
+ var webSearchWireActionSchema = z6.discriminatedUnion("type", [
683
+ z6.object({
684
+ type: z6.literal("search"),
685
+ query: z6.string().nullish(),
686
+ queries: z6.array(z6.string()).nullish(),
687
+ sources: z6.array(z6.unknown()).nullish()
1618
688
  }),
1619
- z8.object({
1620
- type: z8.literal("open_page"),
1621
- url: z8.string().nullish(),
1622
- sources: z8.array(z8.unknown()).nullish()
689
+ z6.object({
690
+ type: z6.literal("open_page"),
691
+ url: z6.string().nullish(),
692
+ sources: z6.array(z6.unknown()).nullish()
1623
693
  }),
1624
- z8.object({
1625
- type: z8.literal("find_in_page"),
1626
- url: z8.string().nullish(),
1627
- pattern: z8.string().nullish(),
1628
- sources: z8.array(z8.unknown()).nullish()
694
+ z6.object({
695
+ type: z6.literal("find_in_page"),
696
+ url: z6.string().nullish(),
697
+ pattern: z6.string().nullish(),
698
+ sources: z6.array(z6.unknown()).nullish()
1629
699
  })
1630
700
  ]);
1631
- var mcpCallSchema = z8.object({
1632
- name: z8.string().optional(),
1633
- arguments: z8.string().optional(),
1634
- output: z8.string().optional(),
1635
- error: z8.string().optional(),
1636
- id: z8.string(),
1637
- status: z8.string(),
1638
- server_label: z8.string().optional()
701
+ var mcpCallSchema = z6.object({
702
+ name: z6.string().optional(),
703
+ arguments: z6.string().optional(),
704
+ output: z6.string().optional(),
705
+ error: z6.string().optional(),
706
+ id: z6.string(),
707
+ status: z6.string(),
708
+ server_label: z6.string().optional()
1639
709
  });
1640
- var outputItemSchema = z8.discriminatedUnion("type", [
1641
- z8.object({
1642
- type: z8.literal("web_search_call"),
710
+ var outputItemSchema = z6.discriminatedUnion("type", [
711
+ z6.object({
712
+ type: z6.literal("web_search_call"),
1643
713
  ...toolCallSchema.shape
1644
714
  }),
1645
- z8.object({
1646
- type: z8.literal("x_search_call"),
715
+ z6.object({
716
+ type: z6.literal("x_search_call"),
1647
717
  ...toolCallSchema.shape
1648
718
  }),
1649
- z8.object({
1650
- type: z8.literal("code_interpreter_call"),
719
+ z6.object({
720
+ type: z6.literal("code_interpreter_call"),
1651
721
  ...toolCallSchema.shape
1652
722
  }),
1653
- z8.object({
1654
- type: z8.literal("code_execution_call"),
723
+ z6.object({
724
+ type: z6.literal("code_execution_call"),
1655
725
  ...toolCallSchema.shape
1656
726
  }),
1657
- z8.object({
1658
- type: z8.literal("view_image_call"),
727
+ z6.object({
728
+ type: z6.literal("view_image_call"),
1659
729
  ...toolCallSchema.shape
1660
730
  }),
1661
- z8.object({
1662
- type: z8.literal("view_x_video_call"),
731
+ z6.object({
732
+ type: z6.literal("view_x_video_call"),
1663
733
  ...toolCallSchema.shape
1664
734
  }),
1665
- z8.object({
1666
- type: z8.literal("file_search_call"),
1667
- id: z8.string(),
1668
- status: z8.string(),
1669
- queries: z8.array(z8.string()).optional(),
1670
- results: z8.array(
1671
- z8.object({
1672
- file_id: z8.string(),
1673
- filename: z8.string(),
1674
- score: z8.number(),
1675
- text: z8.string()
735
+ z6.object({
736
+ type: z6.literal("file_search_call"),
737
+ id: z6.string(),
738
+ status: z6.string(),
739
+ queries: z6.array(z6.string()).optional(),
740
+ results: z6.array(
741
+ z6.object({
742
+ file_id: z6.string(),
743
+ filename: z6.string(),
744
+ score: z6.number(),
745
+ text: z6.string()
1676
746
  })
1677
747
  ).nullish()
1678
748
  }),
1679
- z8.object({
1680
- type: z8.literal("image_generation_call"),
1681
- id: z8.string(),
1682
- status: z8.string(),
1683
- prompt: z8.string().nullish(),
1684
- result: z8.string().nullish()
749
+ z6.object({
750
+ type: z6.literal("image_generation_call"),
751
+ id: z6.string(),
752
+ status: z6.string(),
753
+ prompt: z6.string().nullish(),
754
+ result: z6.string().nullish()
1685
755
  }),
1686
- z8.object({
1687
- type: z8.literal("custom_tool_call"),
756
+ z6.object({
757
+ type: z6.literal("custom_tool_call"),
1688
758
  ...toolCallSchema.shape
1689
759
  }),
1690
- z8.object({
1691
- type: z8.literal("mcp_call"),
760
+ z6.object({
761
+ type: z6.literal("mcp_call"),
1692
762
  ...mcpCallSchema.shape
1693
763
  }),
1694
- z8.object({
1695
- type: z8.literal("message"),
1696
- role: z8.string(),
1697
- content: z8.array(messageContentPartSchema),
1698
- id: z8.string(),
1699
- status: z8.string()
764
+ z6.object({
765
+ type: z6.literal("message"),
766
+ role: z6.string(),
767
+ content: z6.array(messageContentPartSchema),
768
+ id: z6.string(),
769
+ status: z6.string()
1700
770
  }),
1701
- z8.object({
1702
- type: z8.literal("function_call"),
1703
- name: z8.string(),
1704
- arguments: z8.string(),
1705
- call_id: z8.string(),
1706
- id: z8.string()
771
+ z6.object({
772
+ type: z6.literal("function_call"),
773
+ name: z6.string(),
774
+ arguments: z6.string(),
775
+ call_id: z6.string(),
776
+ id: z6.string()
1707
777
  }),
1708
- z8.object({
1709
- type: z8.literal("reasoning"),
1710
- id: z8.string(),
1711
- summary: z8.array(reasoningSummaryPartSchema),
1712
- content: z8.array(z8.object({ type: z8.string(), text: z8.string() })).nullish(),
1713
- status: z8.string(),
1714
- encrypted_content: z8.string().nullish()
778
+ z6.object({
779
+ type: z6.literal("reasoning"),
780
+ id: z6.string(),
781
+ summary: z6.array(reasoningSummaryPartSchema),
782
+ content: z6.array(z6.object({ type: z6.string(), text: z6.string() })).nullish(),
783
+ status: z6.string(),
784
+ encrypted_content: z6.string().nullish()
1715
785
  })
1716
786
  ]);
1717
- var xaiResponsesUsageSchema = z8.object({
1718
- input_tokens: z8.number(),
1719
- output_tokens: z8.number(),
1720
- total_tokens: z8.number().optional(),
1721
- input_tokens_details: z8.object({
1722
- cached_tokens: z8.number().optional()
1723
- }).catchall(z8.json()).optional(),
1724
- output_tokens_details: z8.object({
1725
- reasoning_tokens: z8.number().optional()
1726
- }).catchall(z8.json()).optional(),
1727
- num_sources_used: z8.number().optional(),
1728
- num_server_side_tools_used: z8.number().optional(),
1729
- cost_in_usd_ticks: z8.number().nullish()
1730
- }).catchall(z8.json());
1731
- var xaiResponsesResponseSchema = z8.object({
1732
- id: z8.string().nullish(),
1733
- created_at: z8.number().nullish(),
1734
- model: z8.string().nullish(),
1735
- object: z8.literal("response"),
1736
- output: z8.array(outputItemSchema),
787
+ var xaiResponsesUsageSchema = z6.object({
788
+ input_tokens: z6.number(),
789
+ output_tokens: z6.number(),
790
+ total_tokens: z6.number().optional(),
791
+ input_tokens_details: z6.object({
792
+ cached_tokens: z6.number().optional()
793
+ }).catchall(z6.json()).optional(),
794
+ output_tokens_details: z6.object({
795
+ reasoning_tokens: z6.number().optional()
796
+ }).catchall(z6.json()).optional(),
797
+ num_sources_used: z6.number().optional(),
798
+ num_server_side_tools_used: z6.number().optional(),
799
+ cost_in_usd_ticks: z6.number().nullish()
800
+ }).catchall(z6.json());
801
+ var xaiResponsesResponseSchema = z6.object({
802
+ id: z6.string().nullish(),
803
+ created_at: z6.number().nullish(),
804
+ model: z6.string().nullish(),
805
+ object: z6.literal("response"),
806
+ output: z6.array(outputItemSchema),
1737
807
  usage: xaiResponsesUsageSchema.nullish(),
1738
- status: z8.string(),
1739
- service_tier: z8.string().nullish()
808
+ status: z6.string(),
809
+ service_tier: z6.string().nullish()
1740
810
  });
1741
- var xaiResponsesChunkSchema = z8.union([
1742
- z8.object({
1743
- type: z8.literal("response.created"),
811
+ var xaiResponsesChunkSchema = z6.union([
812
+ z6.object({
813
+ type: z6.literal("response.created"),
1744
814
  response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
1745
815
  }),
1746
- z8.object({
1747
- type: z8.literal("response.in_progress"),
816
+ z6.object({
817
+ type: z6.literal("response.in_progress"),
1748
818
  response: xaiResponsesResponseSchema.partial({ usage: true, status: true })
1749
819
  }),
1750
- z8.object({
1751
- type: z8.literal("response.output_item.added"),
820
+ z6.object({
821
+ type: z6.literal("response.output_item.added"),
1752
822
  item: outputItemSchema,
1753
- output_index: z8.number()
823
+ output_index: z6.number()
1754
824
  }),
1755
- z8.object({
1756
- type: z8.literal("response.output_item.done"),
825
+ z6.object({
826
+ type: z6.literal("response.output_item.done"),
1757
827
  item: outputItemSchema,
1758
- output_index: z8.number()
828
+ output_index: z6.number()
1759
829
  }),
1760
- z8.object({
1761
- type: z8.literal("response.content_part.added"),
1762
- item_id: z8.string(),
1763
- output_index: z8.number(),
1764
- content_index: z8.number(),
830
+ z6.object({
831
+ type: z6.literal("response.content_part.added"),
832
+ item_id: z6.string(),
833
+ output_index: z6.number(),
834
+ content_index: z6.number(),
1765
835
  part: messageContentPartSchema
1766
836
  }),
1767
- z8.object({
1768
- type: z8.literal("response.content_part.done"),
1769
- item_id: z8.string(),
1770
- output_index: z8.number(),
1771
- content_index: z8.number(),
837
+ z6.object({
838
+ type: z6.literal("response.content_part.done"),
839
+ item_id: z6.string(),
840
+ output_index: z6.number(),
841
+ content_index: z6.number(),
1772
842
  part: messageContentPartSchema
1773
843
  }),
1774
- z8.object({
1775
- type: z8.literal("response.output_text.delta"),
1776
- item_id: z8.string(),
1777
- output_index: z8.number(),
1778
- content_index: z8.number(),
1779
- delta: z8.string(),
1780
- logprobs: z8.array(z8.any()).optional()
844
+ z6.object({
845
+ type: z6.literal("response.output_text.delta"),
846
+ item_id: z6.string(),
847
+ output_index: z6.number(),
848
+ content_index: z6.number(),
849
+ delta: z6.string(),
850
+ logprobs: z6.array(z6.any()).optional()
1781
851
  }),
1782
- z8.object({
1783
- type: z8.literal("response.output_text.done"),
1784
- item_id: z8.string(),
1785
- output_index: z8.number(),
1786
- content_index: z8.number(),
1787
- text: z8.string(),
1788
- logprobs: z8.array(z8.any()).optional(),
1789
- annotations: z8.array(annotationSchema).optional()
852
+ z6.object({
853
+ type: z6.literal("response.output_text.done"),
854
+ item_id: z6.string(),
855
+ output_index: z6.number(),
856
+ content_index: z6.number(),
857
+ text: z6.string(),
858
+ logprobs: z6.array(z6.any()).optional(),
859
+ annotations: z6.array(annotationSchema).optional()
1790
860
  }),
1791
- z8.object({
1792
- type: z8.literal("response.output_text.annotation.added"),
1793
- item_id: z8.string(),
1794
- output_index: z8.number(),
1795
- content_index: z8.number(),
1796
- annotation_index: z8.number(),
861
+ z6.object({
862
+ type: z6.literal("response.output_text.annotation.added"),
863
+ item_id: z6.string(),
864
+ output_index: z6.number(),
865
+ content_index: z6.number(),
866
+ annotation_index: z6.number(),
1797
867
  annotation: annotationSchema
1798
868
  }),
1799
- z8.object({
1800
- type: z8.literal("response.reasoning_summary_part.added"),
1801
- item_id: z8.string(),
1802
- output_index: z8.number(),
1803
- summary_index: z8.number(),
869
+ z6.object({
870
+ type: z6.literal("response.reasoning_summary_part.added"),
871
+ item_id: z6.string(),
872
+ output_index: z6.number(),
873
+ summary_index: z6.number(),
1804
874
  part: reasoningSummaryPartSchema
1805
875
  }),
1806
- z8.object({
1807
- type: z8.literal("response.reasoning_summary_part.done"),
1808
- item_id: z8.string(),
1809
- output_index: z8.number(),
1810
- summary_index: z8.number(),
876
+ z6.object({
877
+ type: z6.literal("response.reasoning_summary_part.done"),
878
+ item_id: z6.string(),
879
+ output_index: z6.number(),
880
+ summary_index: z6.number(),
1811
881
  part: reasoningSummaryPartSchema
1812
882
  }),
1813
- z8.object({
1814
- type: z8.literal("response.reasoning_summary_text.delta"),
1815
- item_id: z8.string(),
1816
- output_index: z8.number(),
1817
- summary_index: z8.number(),
1818
- delta: z8.string()
883
+ z6.object({
884
+ type: z6.literal("response.reasoning_summary_text.delta"),
885
+ item_id: z6.string(),
886
+ output_index: z6.number(),
887
+ summary_index: z6.number(),
888
+ delta: z6.string()
1819
889
  }),
1820
- z8.object({
1821
- type: z8.literal("response.reasoning_summary_text.done"),
1822
- item_id: z8.string(),
1823
- output_index: z8.number(),
1824
- summary_index: z8.number(),
1825
- text: z8.string()
890
+ z6.object({
891
+ type: z6.literal("response.reasoning_summary_text.done"),
892
+ item_id: z6.string(),
893
+ output_index: z6.number(),
894
+ summary_index: z6.number(),
895
+ text: z6.string()
1826
896
  }),
1827
- z8.object({
1828
- type: z8.literal("response.reasoning_text.delta"),
1829
- item_id: z8.string(),
1830
- output_index: z8.number(),
1831
- content_index: z8.number(),
1832
- delta: z8.string()
897
+ z6.object({
898
+ type: z6.literal("response.reasoning_text.delta"),
899
+ item_id: z6.string(),
900
+ output_index: z6.number(),
901
+ content_index: z6.number(),
902
+ delta: z6.string()
1833
903
  }),
1834
- z8.object({
1835
- type: z8.literal("response.reasoning_text.done"),
1836
- item_id: z8.string(),
1837
- output_index: z8.number(),
1838
- content_index: z8.number(),
1839
- text: z8.string()
904
+ z6.object({
905
+ type: z6.literal("response.reasoning_text.done"),
906
+ item_id: z6.string(),
907
+ output_index: z6.number(),
908
+ content_index: z6.number(),
909
+ text: z6.string()
1840
910
  }),
1841
- z8.object({
1842
- type: z8.literal("response.web_search_call.in_progress"),
1843
- item_id: z8.string(),
1844
- output_index: z8.number()
911
+ z6.object({
912
+ type: z6.literal("response.web_search_call.in_progress"),
913
+ item_id: z6.string(),
914
+ output_index: z6.number()
1845
915
  }),
1846
- z8.object({
1847
- type: z8.literal("response.web_search_call.searching"),
1848
- item_id: z8.string(),
1849
- output_index: z8.number()
916
+ z6.object({
917
+ type: z6.literal("response.web_search_call.searching"),
918
+ item_id: z6.string(),
919
+ output_index: z6.number()
1850
920
  }),
1851
- z8.object({
1852
- type: z8.literal("response.web_search_call.completed"),
1853
- item_id: z8.string(),
1854
- output_index: z8.number()
921
+ z6.object({
922
+ type: z6.literal("response.web_search_call.completed"),
923
+ item_id: z6.string(),
924
+ output_index: z6.number()
1855
925
  }),
1856
- z8.object({
1857
- type: z8.literal("response.x_search_call.in_progress"),
1858
- item_id: z8.string(),
1859
- output_index: z8.number()
926
+ z6.object({
927
+ type: z6.literal("response.x_search_call.in_progress"),
928
+ item_id: z6.string(),
929
+ output_index: z6.number()
1860
930
  }),
1861
- z8.object({
1862
- type: z8.literal("response.x_search_call.searching"),
1863
- item_id: z8.string(),
1864
- output_index: z8.number()
931
+ z6.object({
932
+ type: z6.literal("response.x_search_call.searching"),
933
+ item_id: z6.string(),
934
+ output_index: z6.number()
1865
935
  }),
1866
- z8.object({
1867
- type: z8.literal("response.x_search_call.completed"),
1868
- item_id: z8.string(),
1869
- output_index: z8.number()
936
+ z6.object({
937
+ type: z6.literal("response.x_search_call.completed"),
938
+ item_id: z6.string(),
939
+ output_index: z6.number()
1870
940
  }),
1871
- z8.object({
1872
- type: z8.literal("response.file_search_call.in_progress"),
1873
- item_id: z8.string(),
1874
- output_index: z8.number()
941
+ z6.object({
942
+ type: z6.literal("response.file_search_call.in_progress"),
943
+ item_id: z6.string(),
944
+ output_index: z6.number()
1875
945
  }),
1876
- z8.object({
1877
- type: z8.literal("response.file_search_call.searching"),
1878
- item_id: z8.string(),
1879
- output_index: z8.number()
946
+ z6.object({
947
+ type: z6.literal("response.file_search_call.searching"),
948
+ item_id: z6.string(),
949
+ output_index: z6.number()
1880
950
  }),
1881
- z8.object({
1882
- type: z8.literal("response.file_search_call.completed"),
1883
- item_id: z8.string(),
1884
- output_index: z8.number()
951
+ z6.object({
952
+ type: z6.literal("response.file_search_call.completed"),
953
+ item_id: z6.string(),
954
+ output_index: z6.number()
1885
955
  }),
1886
- z8.object({
1887
- type: z8.literal("response.image_generation_call.in_progress"),
1888
- item_id: z8.string(),
1889
- output_index: z8.number()
956
+ z6.object({
957
+ type: z6.literal("response.image_generation_call.in_progress"),
958
+ item_id: z6.string(),
959
+ output_index: z6.number()
1890
960
  }),
1891
- z8.object({
1892
- type: z8.literal("response.image_generation_call.generating"),
1893
- item_id: z8.string(),
1894
- output_index: z8.number()
961
+ z6.object({
962
+ type: z6.literal("response.image_generation_call.generating"),
963
+ item_id: z6.string(),
964
+ output_index: z6.number()
1895
965
  }),
1896
- z8.object({
1897
- type: z8.literal("response.image_generation_call.completed"),
1898
- item_id: z8.string(),
1899
- output_index: z8.number()
966
+ z6.object({
967
+ type: z6.literal("response.image_generation_call.completed"),
968
+ item_id: z6.string(),
969
+ output_index: z6.number()
1900
970
  }),
1901
- z8.object({
1902
- type: z8.literal("response.code_execution_call.in_progress"),
1903
- item_id: z8.string(),
1904
- output_index: z8.number()
971
+ z6.object({
972
+ type: z6.literal("response.code_execution_call.in_progress"),
973
+ item_id: z6.string(),
974
+ output_index: z6.number()
1905
975
  }),
1906
- z8.object({
1907
- type: z8.literal("response.code_execution_call.executing"),
1908
- item_id: z8.string(),
1909
- output_index: z8.number()
976
+ z6.object({
977
+ type: z6.literal("response.code_execution_call.executing"),
978
+ item_id: z6.string(),
979
+ output_index: z6.number()
1910
980
  }),
1911
- z8.object({
1912
- type: z8.literal("response.code_execution_call.completed"),
1913
- item_id: z8.string(),
1914
- output_index: z8.number()
981
+ z6.object({
982
+ type: z6.literal("response.code_execution_call.completed"),
983
+ item_id: z6.string(),
984
+ output_index: z6.number()
1915
985
  }),
1916
- z8.object({
1917
- type: z8.literal("response.code_interpreter_call.in_progress"),
1918
- item_id: z8.string(),
1919
- output_index: z8.number()
986
+ z6.object({
987
+ type: z6.literal("response.code_interpreter_call.in_progress"),
988
+ item_id: z6.string(),
989
+ output_index: z6.number()
1920
990
  }),
1921
- z8.object({
1922
- type: z8.literal("response.code_interpreter_call.executing"),
1923
- item_id: z8.string(),
1924
- output_index: z8.number()
991
+ z6.object({
992
+ type: z6.literal("response.code_interpreter_call.executing"),
993
+ item_id: z6.string(),
994
+ output_index: z6.number()
1925
995
  }),
1926
- z8.object({
1927
- type: z8.literal("response.code_interpreter_call.interpreting"),
1928
- item_id: z8.string(),
1929
- output_index: z8.number()
996
+ z6.object({
997
+ type: z6.literal("response.code_interpreter_call.interpreting"),
998
+ item_id: z6.string(),
999
+ output_index: z6.number()
1930
1000
  }),
1931
- z8.object({
1932
- type: z8.literal("response.code_interpreter_call.completed"),
1933
- item_id: z8.string(),
1934
- output_index: z8.number()
1001
+ z6.object({
1002
+ type: z6.literal("response.code_interpreter_call.completed"),
1003
+ item_id: z6.string(),
1004
+ output_index: z6.number()
1935
1005
  }),
1936
1006
  // Code interpreter code streaming events
1937
- z8.object({
1938
- type: z8.literal("response.code_interpreter_call_code.delta"),
1939
- item_id: z8.string(),
1940
- output_index: z8.number(),
1941
- delta: z8.string()
1007
+ z6.object({
1008
+ type: z6.literal("response.code_interpreter_call_code.delta"),
1009
+ item_id: z6.string(),
1010
+ output_index: z6.number(),
1011
+ delta: z6.string()
1942
1012
  }),
1943
- z8.object({
1944
- type: z8.literal("response.code_interpreter_call_code.done"),
1945
- item_id: z8.string(),
1946
- output_index: z8.number(),
1947
- code: z8.string()
1013
+ z6.object({
1014
+ type: z6.literal("response.code_interpreter_call_code.done"),
1015
+ item_id: z6.string(),
1016
+ output_index: z6.number(),
1017
+ code: z6.string()
1948
1018
  }),
1949
- z8.object({
1950
- type: z8.literal("response.custom_tool_call_input.delta"),
1951
- item_id: z8.string(),
1952
- output_index: z8.number(),
1953
- delta: z8.string()
1019
+ z6.object({
1020
+ type: z6.literal("response.custom_tool_call_input.delta"),
1021
+ item_id: z6.string(),
1022
+ output_index: z6.number(),
1023
+ delta: z6.string()
1954
1024
  }),
1955
- z8.object({
1956
- type: z8.literal("response.custom_tool_call_input.done"),
1957
- item_id: z8.string(),
1958
- output_index: z8.number(),
1959
- input: z8.string()
1025
+ z6.object({
1026
+ type: z6.literal("response.custom_tool_call_input.done"),
1027
+ item_id: z6.string(),
1028
+ output_index: z6.number(),
1029
+ input: z6.string()
1960
1030
  }),
1961
1031
  // Function call arguments streaming events (standard function tools)
1962
- z8.object({
1963
- type: z8.literal("response.function_call_arguments.delta"),
1964
- item_id: z8.string(),
1965
- output_index: z8.number(),
1966
- delta: z8.string()
1032
+ z6.object({
1033
+ type: z6.literal("response.function_call_arguments.delta"),
1034
+ item_id: z6.string(),
1035
+ output_index: z6.number(),
1036
+ delta: z6.string()
1967
1037
  }),
1968
- z8.object({
1969
- type: z8.literal("response.function_call_arguments.done"),
1970
- item_id: z8.string(),
1971
- output_index: z8.number(),
1972
- arguments: z8.string()
1038
+ z6.object({
1039
+ type: z6.literal("response.function_call_arguments.done"),
1040
+ item_id: z6.string(),
1041
+ output_index: z6.number(),
1042
+ arguments: z6.string()
1973
1043
  }),
1974
- z8.object({
1975
- type: z8.literal("response.mcp_call.in_progress"),
1976
- item_id: z8.string(),
1977
- output_index: z8.number()
1044
+ z6.object({
1045
+ type: z6.literal("response.mcp_call.in_progress"),
1046
+ item_id: z6.string(),
1047
+ output_index: z6.number()
1978
1048
  }),
1979
- z8.object({
1980
- type: z8.literal("response.mcp_call.executing"),
1981
- item_id: z8.string(),
1982
- output_index: z8.number()
1049
+ z6.object({
1050
+ type: z6.literal("response.mcp_call.executing"),
1051
+ item_id: z6.string(),
1052
+ output_index: z6.number()
1983
1053
  }),
1984
- z8.object({
1985
- type: z8.literal("response.mcp_call.completed"),
1986
- item_id: z8.string(),
1987
- output_index: z8.number()
1054
+ z6.object({
1055
+ type: z6.literal("response.mcp_call.completed"),
1056
+ item_id: z6.string(),
1057
+ output_index: z6.number()
1988
1058
  }),
1989
- z8.object({
1990
- type: z8.literal("response.mcp_call.failed"),
1991
- item_id: z8.string(),
1992
- output_index: z8.number()
1059
+ z6.object({
1060
+ type: z6.literal("response.mcp_call.failed"),
1061
+ item_id: z6.string(),
1062
+ output_index: z6.number()
1993
1063
  }),
1994
- z8.object({
1995
- type: z8.literal("response.mcp_call_arguments.delta"),
1996
- item_id: z8.string(),
1997
- output_index: z8.number(),
1998
- delta: z8.string()
1064
+ z6.object({
1065
+ type: z6.literal("response.mcp_call_arguments.delta"),
1066
+ item_id: z6.string(),
1067
+ output_index: z6.number(),
1068
+ delta: z6.string()
1999
1069
  }),
2000
- z8.object({
2001
- type: z8.literal("response.mcp_call_arguments.done"),
2002
- item_id: z8.string(),
2003
- output_index: z8.number(),
2004
- arguments: z8.string().optional()
1070
+ z6.object({
1071
+ type: z6.literal("response.mcp_call_arguments.done"),
1072
+ item_id: z6.string(),
1073
+ output_index: z6.number(),
1074
+ arguments: z6.string().optional()
2005
1075
  }),
2006
- z8.object({
2007
- type: z8.literal("response.mcp_call_output.delta"),
2008
- item_id: z8.string(),
2009
- output_index: z8.number(),
2010
- delta: z8.string()
1076
+ z6.object({
1077
+ type: z6.literal("response.mcp_call_output.delta"),
1078
+ item_id: z6.string(),
1079
+ output_index: z6.number(),
1080
+ delta: z6.string()
2011
1081
  }),
2012
- z8.object({
2013
- type: z8.literal("response.mcp_call_output.done"),
2014
- item_id: z8.string(),
2015
- output_index: z8.number(),
2016
- output: z8.string().optional()
1082
+ z6.object({
1083
+ type: z6.literal("response.mcp_call_output.done"),
1084
+ item_id: z6.string(),
1085
+ output_index: z6.number(),
1086
+ output: z6.string().optional()
2017
1087
  }),
2018
- z8.object({
2019
- type: z8.literal("response.incomplete"),
2020
- response: z8.object({
2021
- incomplete_details: z8.object({ reason: z8.string() }).nullish(),
1088
+ z6.object({
1089
+ type: z6.literal("response.incomplete"),
1090
+ response: z6.object({
1091
+ incomplete_details: z6.object({ reason: z6.string() }).nullish(),
2022
1092
  usage: xaiResponsesUsageSchema.nullish(),
2023
- service_tier: z8.string().nullish()
1093
+ service_tier: z6.string().nullish()
2024
1094
  })
2025
1095
  }),
2026
- z8.object({
2027
- type: z8.literal("response.failed"),
2028
- response: z8.object({
2029
- error: z8.object({
2030
- code: z8.string().nullish(),
2031
- message: z8.string()
1096
+ z6.object({
1097
+ type: z6.literal("response.failed"),
1098
+ response: z6.object({
1099
+ error: z6.object({
1100
+ code: z6.string().nullish(),
1101
+ message: z6.string()
2032
1102
  }).nullish(),
2033
- incomplete_details: z8.object({ reason: z8.string() }).nullish(),
1103
+ incomplete_details: z6.object({ reason: z6.string() }).nullish(),
2034
1104
  usage: xaiResponsesUsageSchema.nullish()
2035
1105
  })
2036
1106
  }),
2037
- z8.object({
2038
- type: z8.literal("error"),
2039
- code: z8.string().nullish(),
2040
- message: z8.string(),
2041
- param: z8.string().nullish()
1107
+ z6.object({
1108
+ type: z6.literal("error"),
1109
+ code: z6.string().nullish(),
1110
+ message: z6.string(),
1111
+ param: z6.string().nullish()
2042
1112
  }),
2043
- z8.object({
2044
- type: z8.literal("response.done"),
1113
+ z6.object({
1114
+ type: z6.literal("response.done"),
2045
1115
  response: xaiResponsesResponseSchema
2046
1116
  }),
2047
- z8.object({
2048
- type: z8.literal("response.completed"),
1117
+ z6.object({
1118
+ type: z6.literal("response.completed"),
2049
1119
  response: xaiResponsesResponseSchema
2050
1120
  })
2051
1121
  ]);
2052
1122
 
2053
1123
  // src/responses/xai-responses-language-model-options.ts
2054
- import { z as z9 } from "zod/v4";
2055
- var xaiLanguageModelResponsesOptions = z9.object({
1124
+ import { z as z7 } from "zod/v4";
1125
+ var xaiLanguageModelResponsesOptions = z7.object({
2056
1126
  /**
2057
1127
  * Constrains how hard a reasoning model thinks before responding.
2058
1128
  * Possible values are `none` (disables reasoning entirely; supported by
@@ -2062,32 +1132,32 @@ var xaiLanguageModelResponsesOptions = z9.object({
2062
1132
  *
2063
1133
  * @see https://docs.x.ai/docs/guides/reasoning
2064
1134
  */
2065
- reasoningEffort: z9.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
2066
- reasoningSummary: z9.enum(["auto", "concise", "detailed"]).optional(),
2067
- logprobs: z9.boolean().optional(),
2068
- topLogprobs: z9.number().int().min(0).max(8).optional(),
2069
- serviceTier: z9.enum(["default", "priority"]).optional(),
1135
+ reasoningEffort: z7.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
1136
+ reasoningSummary: z7.enum(["auto", "concise", "detailed"]).optional(),
1137
+ logprobs: z7.boolean().optional(),
1138
+ topLogprobs: z7.number().int().min(0).max(8).optional(),
1139
+ serviceTier: z7.enum(["default", "priority"]).optional(),
2070
1140
  /**
2071
1141
  * Whether to store the input message(s) and model response for later retrieval.
2072
1142
  * Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
2073
1143
  * otherwise the API will return an error.
2074
1144
  * @default true
2075
1145
  */
2076
- store: z9.boolean().optional(),
1146
+ store: z7.boolean().optional(),
2077
1147
  /**
2078
1148
  * The ID of the previous response from the model.
2079
1149
  */
2080
- previousResponseId: z9.string().optional(),
1150
+ previousResponseId: z7.string().optional(),
2081
1151
  /**
2082
1152
  * Specify additional output data to include in the model response.
2083
1153
  * Example values: 'file_search_call.results'.
2084
1154
  */
2085
- include: z9.array(z9.enum(["file_search_call.results"])).nullish()
1155
+ include: z7.array(z7.enum(["file_search_call.results"])).nullish()
2086
1156
  });
2087
1157
 
2088
1158
  // src/responses/xai-responses-prepare-tools.ts
2089
1159
  import {
2090
- UnsupportedFunctionalityError as UnsupportedFunctionalityError4
1160
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
2091
1161
  } from "@ai-sdk/provider";
2092
1162
  import { validateTypes } from "@ai-sdk/provider-utils";
2093
1163
 
@@ -2097,25 +1167,25 @@ import {
2097
1167
  lazySchema as lazySchema2,
2098
1168
  zodSchema as zodSchema2
2099
1169
  } from "@ai-sdk/provider-utils";
2100
- import { z as z10 } from "zod/v4";
1170
+ import { z as z8 } from "zod/v4";
2101
1171
  var fileSearchArgsSchema = lazySchema2(
2102
1172
  () => zodSchema2(
2103
- z10.object({
2104
- vectorStoreIds: z10.array(z10.string()),
2105
- maxNumResults: z10.number().optional()
1173
+ z8.object({
1174
+ vectorStoreIds: z8.array(z8.string()),
1175
+ maxNumResults: z8.number().optional()
2106
1176
  })
2107
1177
  )
2108
1178
  );
2109
1179
  var fileSearchOutputSchema = lazySchema2(
2110
1180
  () => zodSchema2(
2111
- z10.object({
2112
- queries: z10.array(z10.string()),
2113
- results: z10.array(
2114
- z10.object({
2115
- fileId: z10.string(),
2116
- filename: z10.string(),
2117
- score: z10.number().min(0).max(1),
2118
- text: z10.string()
1181
+ z8.object({
1182
+ queries: z8.array(z8.string()),
1183
+ results: z8.array(
1184
+ z8.object({
1185
+ fileId: z8.string(),
1186
+ filename: z8.string(),
1187
+ score: z8.number().min(0).max(1),
1188
+ text: z8.string()
2119
1189
  })
2120
1190
  ).nullable()
2121
1191
  })
@@ -2123,7 +1193,7 @@ var fileSearchOutputSchema = lazySchema2(
2123
1193
  );
2124
1194
  var fileSearchToolFactory = createProviderExecutedToolFactory({
2125
1195
  id: "xai.file_search",
2126
- inputSchema: lazySchema2(() => zodSchema2(z10.object({}))),
1196
+ inputSchema: lazySchema2(() => zodSchema2(z8.object({}))),
2127
1197
  outputSchema: fileSearchOutputSchema
2128
1198
  });
2129
1199
  var fileSearch = (args) => fileSearchToolFactory(args);
@@ -2134,20 +1204,20 @@ import {
2134
1204
  lazySchema as lazySchema3,
2135
1205
  zodSchema as zodSchema3
2136
1206
  } from "@ai-sdk/provider-utils";
2137
- import { z as z11 } from "zod/v4";
1207
+ import { z as z9 } from "zod/v4";
2138
1208
  var imageGenerationArgsSchema = lazySchema3(
2139
1209
  () => zodSchema3(
2140
- z11.object({
2141
- action: z11.enum(["auto", "generate", "edit"]).optional()
1210
+ z9.object({
1211
+ action: z9.enum(["auto", "generate", "edit"]).optional()
2142
1212
  })
2143
1213
  )
2144
1214
  );
2145
- var imageGenerationInputSchema = lazySchema3(() => zodSchema3(z11.object({})));
1215
+ var imageGenerationInputSchema = lazySchema3(() => zodSchema3(z9.object({})));
2146
1216
  var imageGenerationOutputSchema = lazySchema3(
2147
1217
  () => zodSchema3(
2148
- z11.object({
2149
- result: z11.string(),
2150
- prompt: z11.string().optional()
1218
+ z9.object({
1219
+ result: z9.string(),
1220
+ prompt: z9.string().optional()
2151
1221
  })
2152
1222
  )
2153
1223
  );
@@ -2164,31 +1234,31 @@ import {
2164
1234
  lazySchema as lazySchema4,
2165
1235
  zodSchema as zodSchema4
2166
1236
  } from "@ai-sdk/provider-utils";
2167
- import { z as z12 } from "zod/v4";
1237
+ import { z as z10 } from "zod/v4";
2168
1238
  var mcpServerArgsSchema = lazySchema4(
2169
1239
  () => zodSchema4(
2170
- z12.object({
2171
- serverUrl: z12.string().describe("The URL of the MCP server"),
2172
- serverLabel: z12.string().optional().describe("A label for the MCP server"),
2173
- serverDescription: z12.string().optional().describe("Description of the MCP server"),
2174
- allowedTools: z12.array(z12.string()).optional().describe("List of allowed tool names"),
2175
- headers: z12.record(z12.string(), z12.string()).optional().describe("Custom headers to send"),
2176
- authorization: z12.string().optional().describe("Authorization header value")
1240
+ z10.object({
1241
+ serverUrl: z10.string().describe("The URL of the MCP server"),
1242
+ serverLabel: z10.string().optional().describe("A label for the MCP server"),
1243
+ serverDescription: z10.string().optional().describe("Description of the MCP server"),
1244
+ allowedTools: z10.array(z10.string()).optional().describe("List of allowed tool names"),
1245
+ headers: z10.record(z10.string(), z10.string()).optional().describe("Custom headers to send"),
1246
+ authorization: z10.string().optional().describe("Authorization header value")
2177
1247
  })
2178
1248
  )
2179
1249
  );
2180
1250
  var mcpServerOutputSchema = lazySchema4(
2181
1251
  () => zodSchema4(
2182
- z12.object({
2183
- name: z12.string(),
2184
- arguments: z12.string(),
2185
- result: z12.unknown()
1252
+ z10.object({
1253
+ name: z10.string(),
1254
+ arguments: z10.string(),
1255
+ result: z10.unknown()
2186
1256
  })
2187
1257
  )
2188
1258
  );
2189
1259
  var mcpServerToolFactory = createProviderExecutedToolFactory3({
2190
1260
  id: "xai.mcp",
2191
- inputSchema: lazySchema4(() => zodSchema4(z12.object({}))),
1261
+ inputSchema: lazySchema4(() => zodSchema4(z10.object({}))),
2192
1262
  outputSchema: mcpServerOutputSchema
2193
1263
  });
2194
1264
  var mcpServer = (args) => mcpServerToolFactory(args);
@@ -2199,43 +1269,43 @@ import {
2199
1269
  lazySchema as lazySchema5,
2200
1270
  zodSchema as zodSchema5
2201
1271
  } from "@ai-sdk/provider-utils";
2202
- import { z as z13 } from "zod/v4";
1272
+ import { z as z11 } from "zod/v4";
2203
1273
  var webSearchArgsSchema = lazySchema5(
2204
1274
  () => zodSchema5(
2205
- z13.object({
2206
- allowedDomains: z13.array(z13.string()).max(5).optional(),
2207
- excludedDomains: z13.array(z13.string()).max(5).optional(),
2208
- enableImageSearch: z13.boolean().optional(),
2209
- enableImageUnderstanding: z13.boolean().optional()
1275
+ z11.object({
1276
+ allowedDomains: z11.array(z11.string()).max(5).optional(),
1277
+ excludedDomains: z11.array(z11.string()).max(5).optional(),
1278
+ enableImageSearch: z11.boolean().optional(),
1279
+ enableImageUnderstanding: z11.boolean().optional()
2210
1280
  })
2211
1281
  )
2212
1282
  );
2213
1283
  var webSearchOutputSchema = lazySchema5(
2214
1284
  () => zodSchema5(
2215
- z13.object({
2216
- action: z13.discriminatedUnion("type", [
2217
- z13.object({
2218
- type: z13.literal("search"),
2219
- query: z13.string().optional(),
2220
- queries: z13.array(z13.string()).optional()
1285
+ z11.object({
1286
+ action: z11.discriminatedUnion("type", [
1287
+ z11.object({
1288
+ type: z11.literal("search"),
1289
+ query: z11.string().optional(),
1290
+ queries: z11.array(z11.string()).optional()
2221
1291
  }),
2222
- z13.object({
2223
- type: z13.literal("openPage"),
2224
- url: z13.string().nullish()
1292
+ z11.object({
1293
+ type: z11.literal("openPage"),
1294
+ url: z11.string().nullish()
2225
1295
  }),
2226
- z13.object({
2227
- type: z13.literal("findInPage"),
2228
- url: z13.string().nullish(),
2229
- pattern: z13.string().nullish()
1296
+ z11.object({
1297
+ type: z11.literal("findInPage"),
1298
+ url: z11.string().nullish(),
1299
+ pattern: z11.string().nullish()
2230
1300
  })
2231
1301
  ]).optional(),
2232
- sources: z13.array(z13.object({ type: z13.literal("url"), url: z13.string() })).optional()
1302
+ sources: z11.array(z11.object({ type: z11.literal("url"), url: z11.string() })).optional()
2233
1303
  })
2234
1304
  )
2235
1305
  );
2236
1306
  var webSearchToolFactory = createProviderExecutedToolFactory4({
2237
1307
  id: "xai.web_search",
2238
- inputSchema: lazySchema5(() => zodSchema5(z13.object({}))),
1308
+ inputSchema: lazySchema5(() => zodSchema5(z11.object({}))),
2239
1309
  outputSchema: webSearchOutputSchema
2240
1310
  });
2241
1311
  var webSearch = (args = {}) => webSearchToolFactory(args);
@@ -2246,29 +1316,29 @@ import {
2246
1316
  lazySchema as lazySchema6,
2247
1317
  zodSchema as zodSchema6
2248
1318
  } from "@ai-sdk/provider-utils";
2249
- import { z as z14 } from "zod/v4";
1319
+ import { z as z12 } from "zod/v4";
2250
1320
  var xSearchArgsSchema = lazySchema6(
2251
1321
  () => zodSchema6(
2252
- z14.object({
2253
- allowedXHandles: z14.array(z14.string()).max(10).optional(),
2254
- excludedXHandles: z14.array(z14.string()).max(10).optional(),
2255
- fromDate: z14.string().optional(),
2256
- toDate: z14.string().optional(),
2257
- enableImageUnderstanding: z14.boolean().optional(),
2258
- enableVideoUnderstanding: z14.boolean().optional()
1322
+ z12.object({
1323
+ allowedXHandles: z12.array(z12.string()).max(10).optional(),
1324
+ excludedXHandles: z12.array(z12.string()).max(10).optional(),
1325
+ fromDate: z12.string().optional(),
1326
+ toDate: z12.string().optional(),
1327
+ enableImageUnderstanding: z12.boolean().optional(),
1328
+ enableVideoUnderstanding: z12.boolean().optional()
2259
1329
  })
2260
1330
  )
2261
1331
  );
2262
1332
  var xSearchOutputSchema = lazySchema6(
2263
1333
  () => zodSchema6(
2264
- z14.object({
2265
- query: z14.string(),
2266
- posts: z14.array(
2267
- z14.object({
2268
- author: z14.string(),
2269
- text: z14.string(),
2270
- url: z14.string(),
2271
- likes: z14.number()
1334
+ z12.object({
1335
+ query: z12.string(),
1336
+ posts: z12.array(
1337
+ z12.object({
1338
+ author: z12.string(),
1339
+ text: z12.string(),
1340
+ url: z12.string(),
1341
+ likes: z12.number()
2272
1342
  })
2273
1343
  )
2274
1344
  })
@@ -2276,7 +1346,7 @@ var xSearchOutputSchema = lazySchema6(
2276
1346
  );
2277
1347
  var xSearchToolFactory = createProviderExecutedToolFactory5({
2278
1348
  id: "xai.x_search",
2279
- inputSchema: lazySchema6(() => zodSchema6(z14.object({}))),
1349
+ inputSchema: lazySchema6(() => zodSchema6(z12.object({}))),
2280
1350
  outputSchema: xSearchOutputSchema
2281
1351
  });
2282
1352
  var xSearch = (args = {}) => xSearchToolFactory(args);
@@ -2436,7 +1506,7 @@ async function prepareResponsesTools({
2436
1506
  }
2437
1507
  default: {
2438
1508
  const _exhaustiveCheck = type;
2439
- throw new UnsupportedFunctionalityError4({
1509
+ throw new UnsupportedFunctionalityError2({
2440
1510
  functionality: `tool choice type: ${_exhaustiveCheck}`
2441
1511
  });
2442
1512
  }
@@ -2517,13 +1587,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2517
1587
  this.modelId = modelId;
2518
1588
  this.config = config;
2519
1589
  }
2520
- static [WORKFLOW_SERIALIZE3](model) {
2521
- return serializeModelOptions3({
1590
+ static [WORKFLOW_SERIALIZE2](model) {
1591
+ return serializeModelOptions2({
2522
1592
  modelId: model.modelId,
2523
1593
  config: model.config
2524
1594
  });
2525
1595
  }
2526
- static [WORKFLOW_DESERIALIZE3](options) {
1596
+ static [WORKFLOW_DESERIALIZE2](options) {
2527
1597
  return new _XaiResponsesLanguageModel(options.modelId, options.config);
2528
1598
  }
2529
1599
  get provider() {
@@ -2550,7 +1620,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2550
1620
  }) {
2551
1621
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2552
1622
  const warnings = [];
2553
- const options = (_a = await parseProviderOptions5({
1623
+ const options = (_a = await parseProviderOptions3({
2554
1624
  provider: "xai",
2555
1625
  providerOptions,
2556
1626
  schema: xaiLanguageModelResponsesOptions
@@ -2608,7 +1678,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2608
1678
  }
2609
1679
  }
2610
1680
  let resolvedReasoningEffort = options.reasoningEffort;
2611
- if (resolvedReasoningEffort == null && isCustomReasoning2(reasoning)) {
1681
+ if (resolvedReasoningEffort == null && isCustomReasoning(reasoning)) {
2612
1682
  if (!supportsReasoningEffort(modelId)) {
2613
1683
  warnings.push({
2614
1684
  type: "unsupported",
@@ -2618,7 +1688,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2618
1688
  } else if (reasoning === "none") {
2619
1689
  resolvedReasoningEffort = "none";
2620
1690
  } else {
2621
- resolvedReasoningEffort = mapReasoningToProviderEffort2({
1691
+ resolvedReasoningEffort = mapReasoningToProviderEffort({
2622
1692
  reasoning,
2623
1693
  effortMap: {
2624
1694
  minimal: "low",
@@ -2713,12 +1783,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2713
1783
  responseHeaders,
2714
1784
  value: response,
2715
1785
  rawValue: rawResponse
2716
- } = await postJsonToApi3({
1786
+ } = await postJsonToApi2({
2717
1787
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
2718
- headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
1788
+ headers: combineHeaders2((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
2719
1789
  body,
2720
1790
  failedResponseHandler: xaiFailedResponseHandler,
2721
- successfulResponseHandler: createJsonResponseHandler3(
1791
+ successfulResponseHandler: createJsonResponseHandler2(
2722
1792
  xaiResponsesResponseSchema
2723
1793
  ),
2724
1794
  abortSignal: options.abortSignal,
@@ -2931,12 +2001,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2931
2001
  ...args,
2932
2002
  stream: true
2933
2003
  };
2934
- const { responseHeaders, value: response } = await postJsonToApi3({
2004
+ const { responseHeaders, value: response } = await postJsonToApi2({
2935
2005
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
2936
- headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
2006
+ headers: combineHeaders2((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
2937
2007
  body,
2938
2008
  failedResponseHandler: xaiFailedResponseHandler,
2939
- successfulResponseHandler: createEventSourceResponseHandler2(
2009
+ successfulResponseHandler: createEventSourceResponseHandler(
2940
2010
  xaiResponsesChunkSchema
2941
2011
  ),
2942
2012
  abortSignal: options.abortSignal,
@@ -3505,13 +2575,13 @@ var xaiBatchName = "ai-sdk-text-batch";
3505
2575
  var xaiBatchResultsPageSize = 1e3;
3506
2576
  var xaiBatchProviderOptionsSchema = lazySchema7(
3507
2577
  () => zodSchema7(
3508
- z15.object({
2578
+ z13.object({
3509
2579
  /**
3510
2580
  * TTL in seconds for the uploaded batch input file, measured from
3511
2581
  * upload time. xAI accepts integers between 3600 (1 hour) and
3512
2582
  * 2592000 (30 days) inclusive. Without it the file has no expiry.
3513
2583
  */
3514
- inputFileExpiresAfter: z15.number().int().min(3600).max(2592e3).optional()
2584
+ inputFileExpiresAfter: z13.number().int().min(3600).max(2592e3).optional()
3515
2585
  })
3516
2586
  )
3517
2587
  );
@@ -3519,70 +2589,108 @@ function assertSupportedBatchRequests(requests) {
3519
2589
  for (const request of requests) {
3520
2590
  const requestType = request.type;
3521
2591
  if (requestType !== "text" && requestType !== "image") {
3522
- throw new UnsupportedFunctionalityError5({
2592
+ throw new UnsupportedFunctionalityError3({
3523
2593
  functionality: `batch request type: ${requestType}`,
3524
2594
  message: `The xAI Batch API does not support batch requests with type "${requestType}".`
3525
2595
  });
3526
2596
  }
3527
2597
  }
3528
2598
  }
3529
- var xaiBatchImageResponseSchema = z15.object({
3530
- data: z15.array(
3531
- z15.object({
3532
- url: z15.string().nullish(),
3533
- b64_json: z15.string().nullish(),
3534
- revised_prompt: z15.string().nullish(),
3535
- respect_moderation: z15.boolean().nullish()
2599
+ var xaiBatchImageResponseSchema = z13.object({
2600
+ data: z13.array(
2601
+ z13.object({
2602
+ url: z13.string().nullish(),
2603
+ b64_json: z13.string().nullish(),
2604
+ revised_prompt: z13.string().nullish(),
2605
+ respect_moderation: z13.boolean().nullish()
3536
2606
  })
3537
2607
  ),
3538
- usage: z15.object({ cost_in_usd_ticks: z15.number().nullish() }).nullish()
2608
+ usage: z13.object({ cost_in_usd_ticks: z13.number().nullish() }).nullish()
3539
2609
  });
3540
- var xaiBatchResponseZodSchema = () => z15.object({
3541
- batch_id: z15.string(),
3542
- name: z15.string().nullish(),
3543
- create_time: z15.string().nullish(),
3544
- expire_time: z15.string().nullish(),
3545
- cancel_time: z15.string().nullish(),
3546
- cancel_by_xai_message: z15.string().nullish(),
3547
- state: z15.object({
3548
- num_requests: z15.number().nullish(),
3549
- num_pending: z15.number().nullish(),
3550
- num_success: z15.number().nullish(),
3551
- num_error: z15.number().nullish(),
3552
- num_cancelled: z15.number().nullish()
2610
+ var xaiBatchResponseZodSchema = () => z13.object({
2611
+ batch_id: z13.string(),
2612
+ name: z13.string().nullish(),
2613
+ create_time: z13.string().nullish(),
2614
+ expire_time: z13.string().nullish(),
2615
+ cancel_time: z13.string().nullish(),
2616
+ cancel_by_xai_message: z13.string().nullish(),
2617
+ state: z13.object({
2618
+ num_requests: z13.number().nullish(),
2619
+ num_pending: z13.number().nullish(),
2620
+ num_success: z13.number().nullish(),
2621
+ num_error: z13.number().nullish(),
2622
+ num_cancelled: z13.number().nullish()
3553
2623
  }).nullish()
3554
2624
  });
3555
2625
  var xaiBatchResponseSchema = lazySchema7(
3556
2626
  () => zodSchema7(xaiBatchResponseZodSchema())
3557
2627
  );
3558
- var xaiBatchErrorSchema = z15.object({
3559
- code: z15.union([z15.string(), z15.number()]).nullish(),
3560
- message: z15.string().nullish()
2628
+ var xaiBatchErrorSchema = z13.object({
2629
+ code: z13.union([z13.string(), z13.number()]).nullish(),
2630
+ message: z13.string().nullish()
3561
2631
  });
3562
- var xaiBatchResultSchema = z15.object({
3563
- batch_request_id: z15.string(),
3564
- batch_result: z15.object({
3565
- response: z15.object({
3566
- chat_get_completion: z15.unknown().nullish(),
3567
- image_generation: z15.unknown().nullish()
2632
+ var xaiBatchResultSchema = z13.object({
2633
+ batch_request_id: z13.string(),
2634
+ batch_result: z13.object({
2635
+ response: z13.object({
2636
+ chat_get_completion: z13.unknown().nullish(),
2637
+ image_generation: z13.unknown().nullish()
3568
2638
  }).nullish(),
3569
2639
  error: xaiBatchErrorSchema.nullish()
3570
2640
  }).nullish(),
3571
- error_message: z15.string().nullish()
2641
+ error_message: z13.string().nullish()
2642
+ });
2643
+ var xaiBatchTextResponseSchema = z13.object({
2644
+ id: z13.string().nullish(),
2645
+ created: z13.number().nullish(),
2646
+ model: z13.string().nullish(),
2647
+ choices: z13.array(
2648
+ z13.object({
2649
+ message: z13.object({
2650
+ role: z13.enum(["assistant", "tool"]),
2651
+ content: z13.string().nullish(),
2652
+ reasoning_content: z13.string().nullish(),
2653
+ tool_calls: z13.array(
2654
+ z13.object({
2655
+ id: z13.string(),
2656
+ type: z13.literal("function"),
2657
+ function: z13.object({
2658
+ name: z13.string(),
2659
+ arguments: z13.string()
2660
+ })
2661
+ })
2662
+ ).nullish()
2663
+ }),
2664
+ index: z13.number(),
2665
+ finish_reason: z13.string().nullish()
2666
+ })
2667
+ ).nullish(),
2668
+ usage: z13.object({
2669
+ prompt_tokens: z13.number(),
2670
+ completion_tokens: z13.number(),
2671
+ total_tokens: z13.number(),
2672
+ cost_in_usd_ticks: z13.number().nullish(),
2673
+ prompt_tokens_details: z13.object({ cached_tokens: z13.number().nullish() }).nullish(),
2674
+ completion_tokens_details: z13.object({ reasoning_tokens: z13.number().nullish() }).nullish()
2675
+ }).nullish(),
2676
+ citations: z13.array(z13.string().url()).nullish(),
2677
+ service_tier: z13.string().nullish(),
2678
+ code: z13.string().nullish(),
2679
+ error: z13.string().nullish()
3572
2680
  });
3573
2681
  var xaiBatchResultsPageSchema = lazySchema7(
3574
2682
  () => zodSchema7(
3575
- z15.object({
3576
- results: z15.array(xaiBatchResultSchema),
3577
- pagination_token: z15.string().nullish()
2683
+ z13.object({
2684
+ results: z13.array(xaiBatchResultSchema),
2685
+ pagination_token: z13.string().nullish()
3578
2686
  })
3579
2687
  )
3580
2688
  );
3581
2689
  var xaiBatchListResponseSchema = lazySchema7(
3582
2690
  () => zodSchema7(
3583
- z15.object({
3584
- batches: z15.array(xaiBatchResponseZodSchema()),
3585
- pagination_token: z15.string().nullish()
2691
+ z13.object({
2692
+ batches: z13.array(xaiBatchResponseZodSchema()),
2693
+ pagination_token: z13.string().nullish()
3586
2694
  })
3587
2695
  )
3588
2696
  );
@@ -3606,7 +2714,7 @@ var XaiBatch = class {
3606
2714
  }
3607
2715
  }
3608
2716
  ];
3609
- const batchOptions = await parseProviderOptions6({
2717
+ const batchOptions = await parseProviderOptions4({
3610
2718
  provider: "xai",
3611
2719
  providerOptions: options.providerOptions,
3612
2720
  schema: xaiBatchProviderOptionsSchema
@@ -3637,7 +2745,7 @@ var XaiBatch = class {
3637
2745
  );
3638
2746
  }
3639
2747
  formData.append("file", file, filename);
3640
- const headers = combineHeaders4(
2748
+ const headers = combineHeaders3(
3641
2749
  (_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
3642
2750
  options.headers
3643
2751
  );
@@ -3646,13 +2754,13 @@ var XaiBatch = class {
3646
2754
  headers,
3647
2755
  formData,
3648
2756
  failedResponseHandler: xaiFailedResponseHandler,
3649
- successfulResponseHandler: createJsonResponseHandler4(
2757
+ successfulResponseHandler: createJsonResponseHandler3(
3650
2758
  xaiFilesResponseSchema
3651
2759
  ),
3652
2760
  abortSignal: options.abortSignal,
3653
2761
  fetch: this.options.config.fetch
3654
2762
  });
3655
- const { value: batch } = await postJsonToApi4({
2763
+ const { value: batch } = await postJsonToApi3({
3656
2764
  url: this.getUrl("/batches"),
3657
2765
  headers,
3658
2766
  body: {
@@ -3660,7 +2768,7 @@ var XaiBatch = class {
3660
2768
  input_file_id: uploadedFile.id
3661
2769
  },
3662
2770
  failedResponseHandler: xaiFailedResponseHandler,
3663
- successfulResponseHandler: createJsonResponseHandler4(
2771
+ successfulResponseHandler: createJsonResponseHandler3(
3664
2772
  xaiBatchResponseSchema
3665
2773
  ),
3666
2774
  abortSignal: options.abortSignal,
@@ -3687,14 +2795,14 @@ var XaiBatch = class {
3687
2795
  }
3688
2796
  async doCancelBatch(options) {
3689
2797
  var _a, _b;
3690
- await postJsonToApi4({
2798
+ await postJsonToApi3({
3691
2799
  url: this.getUrl(
3692
2800
  `/batches/${encodeURIComponent(options.batchId)}:cancel`
3693
2801
  ),
3694
- headers: combineHeaders4((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
2802
+ headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
3695
2803
  body: {},
3696
2804
  failedResponseHandler: xaiFailedResponseHandler,
3697
- successfulResponseHandler: createJsonResponseHandler4(
2805
+ successfulResponseHandler: createJsonResponseHandler3(
3698
2806
  xaiBatchResponseSchema
3699
2807
  ),
3700
2808
  abortSignal: options.abortSignal,
@@ -3713,9 +2821,9 @@ var XaiBatch = class {
3713
2821
  }
3714
2822
  const { value: page } = await getFromApi2({
3715
2823
  url: url.toString(),
3716
- headers: combineHeaders4((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
2824
+ headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
3717
2825
  failedResponseHandler: xaiFailedResponseHandler,
3718
- successfulResponseHandler: createJsonResponseHandler4(
2826
+ successfulResponseHandler: createJsonResponseHandler3(
3719
2827
  xaiBatchListResponseSchema
3720
2828
  ),
3721
2829
  abortSignal: options.abortSignal,
@@ -3746,9 +2854,9 @@ var XaiBatch = class {
3746
2854
  var _a, _b;
3747
2855
  const { value: batch } = await getFromApi2({
3748
2856
  url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
3749
- headers: combineHeaders4((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
2857
+ headers: combineHeaders3((_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a), options.headers),
3750
2858
  failedResponseHandler: xaiFailedResponseHandler,
3751
- successfulResponseHandler: createJsonResponseHandler4(
2859
+ successfulResponseHandler: createJsonResponseHandler3(
3752
2860
  xaiBatchResponseSchema
3753
2861
  ),
3754
2862
  abortSignal: options.abortSignal,
@@ -3771,12 +2879,12 @@ var XaiBatch = class {
3771
2879
  url: this.getUrl(
3772
2880
  `/batches/${encodeURIComponent(options.batchId)}/results?${query}`
3773
2881
  ),
3774
- headers: combineHeaders4(
2882
+ headers: combineHeaders3(
3775
2883
  (_b = (_a = this.options.config).headers) == null ? void 0 : _b.call(_a),
3776
2884
  options.headers
3777
2885
  ),
3778
2886
  failedResponseHandler: xaiFailedResponseHandler,
3779
- successfulResponseHandler: createJsonResponseHandler4(
2887
+ successfulResponseHandler: createJsonResponseHandler3(
3780
2888
  xaiBatchResultsPageSchema
3781
2889
  ),
3782
2890
  abortSignal: options.abortSignal,
@@ -3805,12 +2913,12 @@ var XaiBatch = class {
3805
2913
  if ((response == null ? void 0 : response.chat_get_completion) != null) {
3806
2914
  const validation = await safeValidateTypes({
3807
2915
  value: response.chat_get_completion,
3808
- schema: xaiChatResponseSchema
2916
+ schema: zodSchema7(xaiBatchTextResponseSchema)
3809
2917
  });
3810
2918
  if (!validation.success) {
3811
2919
  return invalidXaiBatchResult(result.batch_request_id);
3812
2920
  }
3813
- const conversion = convertXaiChatBatchResponse(validation.value);
2921
+ const conversion = convertXaiBatchTextResponse(validation.value);
3814
2922
  return conversion.success ? {
3815
2923
  type: "text",
3816
2924
  id: result.batch_request_id,
@@ -3873,7 +2981,7 @@ var XaiBatch = class {
3873
2981
  }
3874
2982
  if (seed != null) warnings.push({ type: "unsupported", feature: "seed" });
3875
2983
  if (mask != null) warnings.push({ type: "unsupported", feature: "mask" });
3876
- const xaiOptions = await parseProviderOptions6({
2984
+ const xaiOptions = await parseProviderOptions4({
3877
2985
  provider: "xai",
3878
2986
  providerOptions,
3879
2987
  schema: xaiImageModelOptions
@@ -4020,7 +3128,7 @@ function invalidXaiImageBatchResult(id) {
4020
3128
  }
4021
3129
  };
4022
3130
  }
4023
- function convertXaiChatBatchResponse(response) {
3131
+ function convertXaiBatchTextResponse(response) {
4024
3132
  var _a, _b, _c, _d, _e, _f;
4025
3133
  if (response.error != null) {
4026
3134
  return {
@@ -4102,7 +3210,7 @@ function convertXaiChatBatchResponse(response) {
4102
3210
  unified: mapXaiFinishReason(lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason),
4103
3211
  raw: (_d = lastAssistantChoice == null ? void 0 : lastAssistantChoice.finish_reason) != null ? _d : void 0
4104
3212
  },
4105
- usage: response.usage ? convertXaiChatUsage(response.usage) : createNullLanguageModelUsage(),
3213
+ usage: response.usage ? convertXaiBatchTextUsage(response.usage) : createNullLanguageModelUsage(),
4106
3214
  response: getResponseMetadata(response),
4107
3215
  warnings: [],
4108
3216
  ...(((_e = response.usage) == null ? void 0 : _e.cost_in_usd_ticks) != null || response.service_tier != null) && {
@@ -4116,6 +3224,26 @@ function convertXaiChatBatchResponse(response) {
4116
3224
  }
4117
3225
  };
4118
3226
  }
3227
+ function convertXaiBatchTextUsage(usage) {
3228
+ var _a, _b, _c, _d;
3229
+ const cacheReadTokens = (_b = (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0;
3230
+ const reasoningTokens = (_d = (_c = usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0;
3231
+ const promptTokensIncludesCached = cacheReadTokens <= usage.prompt_tokens;
3232
+ return {
3233
+ inputTokens: {
3234
+ total: promptTokensIncludesCached ? usage.prompt_tokens : usage.prompt_tokens + cacheReadTokens,
3235
+ noCache: promptTokensIncludesCached ? usage.prompt_tokens - cacheReadTokens : usage.prompt_tokens,
3236
+ cacheRead: cacheReadTokens,
3237
+ cacheWrite: void 0
3238
+ },
3239
+ outputTokens: {
3240
+ total: usage.completion_tokens + reasoningTokens,
3241
+ text: usage.completion_tokens,
3242
+ reasoning: reasoningTokens
3243
+ },
3244
+ raw: usage
3245
+ };
3246
+ }
4119
3247
 
4120
3248
  // src/realtime/xai-realtime-event-mapper.ts
4121
3249
  function parseXaiRealtimeServerEvent(raw) {
@@ -4488,43 +3616,43 @@ var XaiRealtimeModel = class {
4488
3616
 
4489
3617
  // src/tool/code-execution.ts
4490
3618
  import { createProviderExecutedToolFactory as createProviderExecutedToolFactory6 } from "@ai-sdk/provider-utils";
4491
- import { z as z16 } from "zod/v4";
4492
- var codeExecutionOutputSchema = z16.object({
4493
- output: z16.string().describe("the output of the code execution"),
4494
- error: z16.string().optional().describe("any error that occurred")
3619
+ import { z as z14 } from "zod/v4";
3620
+ var codeExecutionOutputSchema = z14.object({
3621
+ output: z14.string().describe("the output of the code execution"),
3622
+ error: z14.string().optional().describe("any error that occurred")
4495
3623
  });
4496
3624
  var codeExecutionToolFactory = createProviderExecutedToolFactory6({
4497
3625
  id: "xai.code_execution",
4498
- inputSchema: z16.object({}).describe("no input parameters"),
3626
+ inputSchema: z14.object({}).describe("no input parameters"),
4499
3627
  outputSchema: codeExecutionOutputSchema
4500
3628
  });
4501
3629
  var codeExecution = (args = {}) => codeExecutionToolFactory(args);
4502
3630
 
4503
3631
  // src/tool/view-image.ts
4504
3632
  import { createProviderExecutedToolFactory as createProviderExecutedToolFactory7 } from "@ai-sdk/provider-utils";
4505
- import { z as z17 } from "zod/v4";
4506
- var viewImageOutputSchema = z17.object({
4507
- description: z17.string().describe("description of the image"),
4508
- objects: z17.array(z17.string()).optional().describe("objects detected in the image")
3633
+ import { z as z15 } from "zod/v4";
3634
+ var viewImageOutputSchema = z15.object({
3635
+ description: z15.string().describe("description of the image"),
3636
+ objects: z15.array(z15.string()).optional().describe("objects detected in the image")
4509
3637
  });
4510
3638
  var viewImageToolFactory = createProviderExecutedToolFactory7({
4511
3639
  id: "xai.view_image",
4512
- inputSchema: z17.object({}).describe("no input parameters"),
3640
+ inputSchema: z15.object({}).describe("no input parameters"),
4513
3641
  outputSchema: viewImageOutputSchema
4514
3642
  });
4515
3643
  var viewImage = (args = {}) => viewImageToolFactory(args);
4516
3644
 
4517
3645
  // src/tool/view-x-video.ts
4518
3646
  import { createProviderExecutedToolFactory as createProviderExecutedToolFactory8 } from "@ai-sdk/provider-utils";
4519
- import { z as z18 } from "zod/v4";
4520
- var viewXVideoOutputSchema = z18.object({
4521
- transcript: z18.string().optional().describe("transcript of the video"),
4522
- description: z18.string().describe("description of the video content"),
4523
- duration: z18.number().optional().describe("duration in seconds")
3647
+ import { z as z16 } from "zod/v4";
3648
+ var viewXVideoOutputSchema = z16.object({
3649
+ transcript: z16.string().optional().describe("transcript of the video"),
3650
+ description: z16.string().describe("description of the video content"),
3651
+ duration: z16.number().optional().describe("duration in seconds")
4524
3652
  });
4525
3653
  var viewXVideoToolFactory = createProviderExecutedToolFactory8({
4526
3654
  id: "xai.view_x_video",
4527
- inputSchema: z18.object({}).describe("no input parameters"),
3655
+ inputSchema: z16.object({}).describe("no input parameters"),
4528
3656
  outputSchema: viewXVideoOutputSchema
4529
3657
  });
4530
3658
  var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
@@ -4542,20 +3670,20 @@ var xaiTools = {
4542
3670
  };
4543
3671
 
4544
3672
  // src/version.ts
4545
- var VERSION = true ? "4.0.59" : "0.0.0-test";
3673
+ var VERSION = true ? "5.0.1" : "0.0.0-test";
4546
3674
 
4547
3675
  // src/files/xai-files.ts
4548
3676
  import {
4549
3677
  InvalidArgumentError as InvalidArgumentError2
4550
3678
  } from "@ai-sdk/provider";
4551
3679
  import {
4552
- combineHeaders as combineHeaders5,
3680
+ combineHeaders as combineHeaders4,
4553
3681
  convertInlineFileDataToUint8Array,
4554
3682
  createBinaryStreamResponseHandler,
4555
- createJsonResponseHandler as createJsonResponseHandler5,
3683
+ createJsonResponseHandler as createJsonResponseHandler4,
4556
3684
  deleteFromApi,
4557
3685
  getFromApi as getFromApi3,
4558
- parseProviderOptions as parseProviderOptions7,
3686
+ parseProviderOptions as parseProviderOptions5,
4559
3687
  postFormDataToApi as postFormDataToApi2,
4560
3688
  postMultipartStreamToApi
4561
3689
  } from "@ai-sdk/provider-utils";
@@ -4565,18 +3693,18 @@ import {
4565
3693
  lazySchema as lazySchema8,
4566
3694
  zodSchema as zodSchema8
4567
3695
  } from "@ai-sdk/provider-utils";
4568
- import { z as z19 } from "zod/v4";
3696
+ import { z as z17 } from "zod/v4";
4569
3697
  var xaiFilesOptionsSchema = lazySchema8(
4570
3698
  () => zodSchema8(
4571
- z19.looseObject({
4572
- teamId: z19.string().optional(),
4573
- filePath: z19.string().optional(),
3699
+ z17.looseObject({
3700
+ teamId: z17.string().optional(),
3701
+ filePath: z17.string().optional(),
4574
3702
  /**
4575
3703
  * TTL in seconds measured from upload time; xAI accepts integers
4576
3704
  * between 3600 (1 hour) and 2592000 (30 days) inclusive.
4577
3705
  * Omit to keep the file until it is deleted.
4578
3706
  */
4579
- expiresAfter: z19.number().int().min(3600).max(2592e3).optional()
3707
+ expiresAfter: z17.number().int().min(3600).max(2592e3).optional()
4580
3708
  })
4581
3709
  )
4582
3710
  );
@@ -4605,7 +3733,7 @@ var XaiFiles = class {
4605
3733
  return fileId;
4606
3734
  }
4607
3735
  getHeaders(headers) {
4608
- return combineHeaders5(this.config.headers(), headers);
3736
+ return combineHeaders4(this.config.headers(), headers);
4609
3737
  }
4610
3738
  async uploadFile({
4611
3739
  data,
@@ -4618,7 +3746,7 @@ var XaiFiles = class {
4618
3746
  var _a, _b;
4619
3747
  let xaiOptions;
4620
3748
  try {
4621
- xaiOptions = await parseProviderOptions7({
3749
+ xaiOptions = await parseProviderOptions5({
4622
3750
  provider: "xai",
4623
3751
  providerOptions,
4624
3752
  schema: xaiFilesOptionsSchema
@@ -4661,7 +3789,7 @@ var XaiFiles = class {
4661
3789
  headers: requestHeaders,
4662
3790
  parts,
4663
3791
  failedResponseHandler: xaiFailedResponseHandler,
4664
- successfulResponseHandler: createJsonResponseHandler5(
3792
+ successfulResponseHandler: createJsonResponseHandler4(
4665
3793
  xaiFilesResponseSchema
4666
3794
  ),
4667
3795
  abortSignal,
@@ -4689,7 +3817,7 @@ var XaiFiles = class {
4689
3817
  headers: requestHeaders,
4690
3818
  formData,
4691
3819
  failedResponseHandler: xaiFailedResponseHandler,
4692
- successfulResponseHandler: createJsonResponseHandler5(
3820
+ successfulResponseHandler: createJsonResponseHandler4(
4693
3821
  xaiFilesResponseSchema
4694
3822
  ),
4695
3823
  abortSignal,
@@ -4719,7 +3847,7 @@ var XaiFiles = class {
4719
3847
  url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
4720
3848
  headers: this.getHeaders(headers),
4721
3849
  failedResponseHandler: xaiFailedResponseHandler,
4722
- successfulResponseHandler: createJsonResponseHandler5(
3850
+ successfulResponseHandler: createJsonResponseHandler4(
4723
3851
  xaiFilesResponseSchema
4724
3852
  ),
4725
3853
  abortSignal,
@@ -4771,7 +3899,7 @@ var XaiFiles = class {
4771
3899
  url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
4772
3900
  headers: this.getHeaders(headers),
4773
3901
  failedResponseHandler: xaiFailedResponseHandler,
4774
- successfulResponseHandler: createJsonResponseHandler5(
3902
+ successfulResponseHandler: createJsonResponseHandler4(
4775
3903
  xaiFileDeleteResponseSchema
4776
3904
  ),
4777
3905
  abortSignal,
@@ -4798,38 +3926,38 @@ var XaiFiles = class {
4798
3926
  // src/xai-video-model.ts
4799
3927
  import {
4800
3928
  AISDKError,
4801
- APICallError as APICallError2
3929
+ APICallError
4802
3930
  } from "@ai-sdk/provider";
4803
3931
  import {
4804
- combineHeaders as combineHeaders6,
3932
+ combineHeaders as combineHeaders5,
4805
3933
  convertUint8ArrayToBase64,
4806
- createJsonResponseHandler as createJsonResponseHandler6,
4807
- extractResponseHeaders as extractResponseHeaders2,
3934
+ createJsonResponseHandler as createJsonResponseHandler5,
3935
+ extractResponseHeaders,
4808
3936
  getFromApi as getFromApi4,
4809
- getTopLevelMediaType as getTopLevelMediaType3,
4810
- parseProviderOptions as parseProviderOptions8,
4811
- postJsonToApi as postJsonToApi5,
4812
- safeParseJSON as safeParseJSON2
3937
+ getTopLevelMediaType as getTopLevelMediaType2,
3938
+ parseProviderOptions as parseProviderOptions6,
3939
+ postJsonToApi as postJsonToApi4,
3940
+ safeParseJSON
4813
3941
  } from "@ai-sdk/provider-utils";
4814
- import { z as z21 } from "zod/v4";
3942
+ import { z as z19 } from "zod/v4";
4815
3943
 
4816
3944
  // src/xai-video-model-options.ts
4817
3945
  import { lazySchema as lazySchema9, zodSchema as zodSchema9 } from "@ai-sdk/provider-utils";
4818
- import { z as z20 } from "zod/v4";
4819
- var nonEmptyStringSchema = z20.string().min(1);
4820
- var resolutionSchema = z20.enum(["480p", "720p", "1080p"]);
4821
- var modeSchema = z20.enum(["edit-video", "extend-video", "reference-to-video"]);
3946
+ import { z as z18 } from "zod/v4";
3947
+ var nonEmptyStringSchema = z18.string().min(1);
3948
+ var resolutionSchema = z18.enum(["480p", "720p", "1080p"]);
3949
+ var modeSchema = z18.enum(["edit-video", "extend-video", "reference-to-video"]);
4822
3950
  var baseFields = {
4823
- pollIntervalMs: z20.number().positive().nullish(),
4824
- pollTimeoutMs: z20.number().positive().nullish(),
3951
+ pollIntervalMs: z18.number().positive().nullish(),
3952
+ pollTimeoutMs: z18.number().positive().nullish(),
4825
3953
  resolution: resolutionSchema.nullish()
4826
3954
  };
4827
- var runtimeSchema = z20.looseObject({
3955
+ var runtimeSchema = z18.looseObject({
4828
3956
  mode: modeSchema.optional(),
4829
3957
  videoUrl: nonEmptyStringSchema.optional(),
4830
- referenceImageUrls: z20.array(nonEmptyStringSchema).min(1).max(7).optional(),
4831
- referenceVoiceIds: z20.array(nonEmptyStringSchema).max(3).optional(),
4832
- user: z20.string().optional(),
3958
+ referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7).optional(),
3959
+ referenceVoiceIds: z18.array(nonEmptyStringSchema).max(3).optional(),
3960
+ user: z18.string().optional(),
4833
3961
  ...baseFields
4834
3962
  });
4835
3963
  var xaiVideoModelOptionsSchema = lazySchema9(
@@ -4859,8 +3987,8 @@ function resolveStartImage(options) {
4859
3987
  var _a;
4860
3988
  return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
4861
3989
  }
4862
- var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType3(file.mediaType) === "video";
4863
- var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType3(file.mediaType) === "image";
3990
+ var isVideoFile = (file) => file.mediaType != null && getTopLevelMediaType2(file.mediaType) === "video";
3991
+ var isImageReference = (file) => file.mediaType == null || getTopLevelMediaType2(file.mediaType) === "image";
4864
3992
  function fileToXaiUrl(file) {
4865
3993
  if (file.type === "url") {
4866
3994
  return file.url;
@@ -4919,7 +4047,7 @@ var XaiVideoModel = class {
4919
4047
  }
4920
4048
  async buildRequestBody(options) {
4921
4049
  const warnings = [];
4922
- const xaiOptions = await parseProviderOptions8({
4050
+ const xaiOptions = await parseProviderOptions6({
4923
4051
  provider: "xai",
4924
4052
  providerOptions: options.providerOptions,
4925
4053
  schema: xaiVideoModelOptionsSchema
@@ -5127,12 +4255,12 @@ var XaiVideoModel = class {
5127
4255
  } else {
5128
4256
  endpoint = `${baseURL}/videos/generations`;
5129
4257
  }
5130
- const { value: createResponse, responseHeaders } = await postJsonToApi5({
4258
+ const { value: createResponse, responseHeaders } = await postJsonToApi4({
5131
4259
  url: endpoint,
5132
- headers: combineHeaders6(this.config.headers(), options.headers),
4260
+ headers: combineHeaders5(this.config.headers(), options.headers),
5133
4261
  body,
5134
4262
  failedResponseHandler: xaiFailedResponseHandler,
5135
- successfulResponseHandler: createJsonResponseHandler6(
4263
+ successfulResponseHandler: createJsonResponseHandler5(
5136
4264
  xaiCreateVideoResponseSchema
5137
4265
  ),
5138
4266
  abortSignal: options.abortSignal,
@@ -5163,7 +4291,7 @@ var XaiVideoModel = class {
5163
4291
  const { value: statusResponse, responseHeaders } = await getFromApi4({
5164
4292
  url: `${baseURL}/videos/${encodePathSegment2(requestId)}`,
5165
4293
  validateUrl: false,
5166
- headers: combineHeaders6(this.config.headers(), options.headers),
4294
+ headers: combineHeaders5(this.config.headers(), options.headers),
5167
4295
  successfulResponseHandler: xaiVideoStatusResponseHandler,
5168
4296
  failedResponseHandler: xaiFailedResponseHandler,
5169
4297
  abortSignal: options.abortSignal,
@@ -5251,27 +4379,27 @@ var XaiVideoModel = class {
5251
4379
  };
5252
4380
  }
5253
4381
  };
5254
- var xaiCreateVideoResponseSchema = z21.object({
5255
- request_id: z21.string().nullish()
4382
+ var xaiCreateVideoResponseSchema = z19.object({
4383
+ request_id: z19.string().nullish()
5256
4384
  });
5257
- var xaiVideoStatusResponseSchema = z21.object({
5258
- status: z21.string().nullish(),
5259
- video: z21.object({
5260
- url: z21.string(),
5261
- duration: z21.number().nullish(),
5262
- respect_moderation: z21.boolean().nullish()
4385
+ var xaiVideoStatusResponseSchema = z19.object({
4386
+ status: z19.string().nullish(),
4387
+ video: z19.object({
4388
+ url: z19.string(),
4389
+ duration: z19.number().nullish(),
4390
+ respect_moderation: z19.boolean().nullish()
5263
4391
  }).nullish(),
5264
- model: z21.string().nullish(),
5265
- usage: z21.object({
5266
- cost_in_usd_ticks: z21.number().nullish()
4392
+ model: z19.string().nullish(),
4393
+ usage: z19.object({
4394
+ cost_in_usd_ticks: z19.number().nullish()
5267
4395
  }).nullish(),
5268
- progress: z21.number().nullish(),
5269
- error: z21.object({
5270
- code: z21.string().nullish(),
5271
- message: z21.string().nullish()
4396
+ progress: z19.number().nullish(),
4397
+ error: z19.object({
4398
+ code: z19.string().nullish(),
4399
+ message: z19.string().nullish()
5272
4400
  }).nullish()
5273
4401
  });
5274
- var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler6(
4402
+ var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler5(
5275
4403
  xaiVideoStatusResponseSchema
5276
4404
  );
5277
4405
  var MAX_PENDING_BODY_BYTES = 1024 * 1024;
@@ -5293,12 +4421,12 @@ async function readPendingBody({
5293
4421
  if (done) break;
5294
4422
  totalBytes += value.length;
5295
4423
  if (totalBytes > MAX_PENDING_BODY_BYTES) {
5296
- throw new APICallError2({
4424
+ throw new APICallError({
5297
4425
  message: `xAI video status response exceeded ${MAX_PENDING_BODY_BYTES} bytes`,
5298
4426
  url,
5299
4427
  requestBodyValues,
5300
4428
  statusCode: response.status,
5301
- responseHeaders: extractResponseHeaders2(response)
4429
+ responseHeaders: extractResponseHeaders(response)
5302
4430
  });
5303
4431
  }
5304
4432
  chunks.push(value);
@@ -5316,12 +4444,12 @@ async function readPendingBody({
5316
4444
  }
5317
4445
  var xaiVideoStatusResponseHandler = async (options) => {
5318
4446
  if (options.response.status === 202) {
5319
- const responseHeaders = extractResponseHeaders2(options.response);
4447
+ const responseHeaders = extractResponseHeaders(options.response);
5320
4448
  const text = await readPendingBody(options);
5321
4449
  if (text.trim().length === 0) {
5322
4450
  return { responseHeaders, value: { status: "pending" } };
5323
4451
  }
5324
- const parsed = await safeParseJSON2({
4452
+ const parsed = await safeParseJSON({
5325
4453
  text,
5326
4454
  schema: xaiVideoStatusResponseSchema
5327
4455
  });
@@ -5335,69 +4463,69 @@ var xaiVideoStatusResponseHandler = async (options) => {
5335
4463
 
5336
4464
  // src/xai-speech-model.ts
5337
4465
  import {
5338
- combineHeaders as combineHeaders7,
4466
+ combineHeaders as combineHeaders6,
5339
4467
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
5340
4468
  createBinaryResponseHandler as createBinaryResponseHandler3,
5341
- createJsonResponseHandler as createJsonResponseHandler7,
5342
- parseProviderOptions as parseProviderOptions9,
5343
- postJsonToApi as postJsonToApi6,
4469
+ createJsonResponseHandler as createJsonResponseHandler6,
4470
+ parseProviderOptions as parseProviderOptions7,
4471
+ postJsonToApi as postJsonToApi5,
5344
4472
  resolve,
5345
- serializeModelOptions as serializeModelOptions4,
5346
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
5347
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
4473
+ serializeModelOptions as serializeModelOptions3,
4474
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
4475
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
5348
4476
  } from "@ai-sdk/provider-utils";
5349
- import { z as z23 } from "zod/v4";
4477
+ import { z as z21 } from "zod/v4";
5350
4478
 
5351
4479
  // src/xai-speech-model-options.ts
5352
4480
  import {
5353
4481
  lazySchema as lazySchema10,
5354
4482
  zodSchema as zodSchema10
5355
4483
  } from "@ai-sdk/provider-utils";
5356
- import { z as z22 } from "zod/v4";
4484
+ import { z as z20 } from "zod/v4";
5357
4485
  var xaiSpeechModelOptionsSchema = lazySchema10(
5358
4486
  () => zodSchema10(
5359
- z22.object({
4487
+ z20.object({
5360
4488
  /**
5361
4489
  * Sample rate of the generated audio in Hz.
5362
4490
  */
5363
- sampleRate: z22.union([
5364
- z22.literal(8e3),
5365
- z22.literal(16e3),
5366
- z22.literal(22050),
5367
- z22.literal(24e3),
5368
- z22.literal(44100),
5369
- z22.literal(48e3)
4491
+ sampleRate: z20.union([
4492
+ z20.literal(8e3),
4493
+ z20.literal(16e3),
4494
+ z20.literal(22050),
4495
+ z20.literal(24e3),
4496
+ z20.literal(44100),
4497
+ z20.literal(48e3)
5370
4498
  ]).nullish(),
5371
4499
  /**
5372
4500
  * MP3 bit rate in bits per second. Only applies when outputFormat is mp3.
5373
4501
  */
5374
- bitRate: z22.union([
5375
- z22.literal(32e3),
5376
- z22.literal(64e3),
5377
- z22.literal(96e3),
5378
- z22.literal(128e3),
5379
- z22.literal(192e3)
4502
+ bitRate: z20.union([
4503
+ z20.literal(32e3),
4504
+ z20.literal(64e3),
4505
+ z20.literal(96e3),
4506
+ z20.literal(128e3),
4507
+ z20.literal(192e3)
5380
4508
  ]).nullish(),
5381
4509
  /**
5382
4510
  * Reduce time to first audio chunk, trading some quality for latency.
5383
4511
  */
5384
- optimizeStreamingLatency: z22.union([z22.literal(0), z22.literal(1), z22.literal(2)]).nullish(),
4512
+ optimizeStreamingLatency: z20.union([z20.literal(0), z20.literal(1), z20.literal(2)]).nullish(),
5385
4513
  /**
5386
4514
  * Normalize written-form text into spoken-form text before synthesis.
5387
4515
  */
5388
- textNormalization: z22.boolean().nullish(),
4516
+ textNormalization: z20.boolean().nullish(),
5389
4517
  /**
5390
4518
  * Return character-level timing metadata alongside the audio. When
5391
4519
  * enabled, the response carries per-character start/end times and the
5392
4520
  * total duration, exposed via `providerMetadata.xai`.
5393
4521
  */
5394
- withTimestamps: z22.boolean().nullish(),
4522
+ withTimestamps: z20.boolean().nullish(),
5395
4523
  /**
5396
4524
  * Map of phrases to spoken substitutions applied before synthesis.
5397
4525
  * Values may be respellings (`{ 'Acme Mobile': 'Acme Mobull' }`) or IPA
5398
4526
  * phonetics (`{ nginx: '/ˈɛndʒɪn ˈɛks/' }`).
5399
4527
  */
5400
- replace: z22.record(z22.string(), z22.string()).nullish()
4528
+ replace: z20.record(z20.string(), z20.string()).nullish()
5401
4529
  })
5402
4530
  )
5403
4531
  );
@@ -5409,13 +4537,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
5409
4537
  this.config = config;
5410
4538
  this.specificationVersion = "v4";
5411
4539
  }
5412
- static [WORKFLOW_SERIALIZE4](model) {
5413
- return serializeModelOptions4({
4540
+ static [WORKFLOW_SERIALIZE3](model) {
4541
+ return serializeModelOptions3({
5414
4542
  modelId: model.modelId,
5415
4543
  config: model.config
5416
4544
  });
5417
4545
  }
5418
- static [WORKFLOW_DESERIALIZE4](options) {
4546
+ static [WORKFLOW_DESERIALIZE3](options) {
5419
4547
  return new _XaiSpeechModel(options.modelId, options.config);
5420
4548
  }
5421
4549
  get provider() {
@@ -5431,7 +4559,7 @@ var XaiSpeechModel = class _XaiSpeechModel {
5431
4559
  providerOptions
5432
4560
  }) {
5433
4561
  const warnings = [];
5434
- const xaiOptions = await parseProviderOptions9({
4562
+ const xaiOptions = await parseProviderOptions7({
5435
4563
  provider: "xai",
5436
4564
  providerOptions,
5437
4565
  schema: xaiSpeechModelOptionsSchema
@@ -5491,15 +4619,15 @@ var XaiSpeechModel = class _XaiSpeechModel {
5491
4619
  var _a, _b, _c;
5492
4620
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
5493
4621
  const { requestBody, warnings, withTimestamps } = await this.getArgs(options);
5494
- const { value, responseHeaders, rawValue } = await postJsonToApi6({
4622
+ const { value, responseHeaders, rawValue } = await postJsonToApi5({
5495
4623
  url: `${this.config.baseURL}/tts`,
5496
- headers: combineHeaders7(
4624
+ headers: combineHeaders6(
5497
4625
  this.config.headers ? await resolve(this.config.headers) : void 0,
5498
4626
  options.headers
5499
4627
  ),
5500
4628
  body: requestBody,
5501
4629
  failedResponseHandler: xaiFailedResponseHandler,
5502
- successfulResponseHandler: withTimestamps ? createJsonResponseHandler7(xaiSpeechTimestampsResponseSchema) : createBinaryResponseHandler3(),
4630
+ successfulResponseHandler: withTimestamps ? createJsonResponseHandler6(xaiSpeechTimestampsResponseSchema) : createBinaryResponseHandler3(),
5503
4631
  abortSignal: options.abortSignal,
5504
4632
  fetch: this.config.fetch
5505
4633
  });
@@ -5540,13 +4668,13 @@ var XaiSpeechModel = class _XaiSpeechModel {
5540
4668
  };
5541
4669
  }
5542
4670
  };
5543
- var xaiSpeechTimestampsResponseSchema = z23.object({
5544
- audio: z23.string().nullish(),
5545
- content_type: z23.string().nullish(),
5546
- duration: z23.number().nullish(),
5547
- audio_timestamps: z23.object({
5548
- graph_chars: z23.array(z23.string()),
5549
- graph_times: z23.array(z23.tuple([z23.number(), z23.number()]))
4671
+ var xaiSpeechTimestampsResponseSchema = z21.object({
4672
+ audio: z21.string().nullish(),
4673
+ content_type: z21.string().nullish(),
4674
+ duration: z21.number().nullish(),
4675
+ audio_timestamps: z21.object({
4676
+ graph_chars: z21.array(z21.string()),
4677
+ graph_times: z21.array(z21.tuple([z21.number(), z21.number()]))
5550
4678
  }).nullish()
5551
4679
  });
5552
4680
 
@@ -5555,94 +4683,94 @@ import {
5555
4683
  InvalidArgumentError as InvalidArgumentError3
5556
4684
  } from "@ai-sdk/provider";
5557
4685
  import {
5558
- combineHeaders as combineHeaders8,
4686
+ combineHeaders as combineHeaders7,
5559
4687
  convertBase64ToUint8Array as convertBase64ToUint8Array3,
5560
- createJsonResponseHandler as createJsonResponseHandler8,
4688
+ createJsonResponseHandler as createJsonResponseHandler7,
5561
4689
  connectToWebSocket,
5562
4690
  mediaTypeToExtension,
5563
- parseProviderOptions as parseProviderOptions10,
4691
+ parseProviderOptions as parseProviderOptions8,
5564
4692
  postFormDataToApi as postFormDataToApi3,
5565
- safeParseJSON as safeParseJSON3,
5566
- serializeModelOptions as serializeModelOptions5,
4693
+ safeParseJSON as safeParseJSON2,
4694
+ serializeModelOptions as serializeModelOptions4,
5567
4695
  toWebSocketUrl,
5568
4696
  waitForWebSocketBufferDrain,
5569
- WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE5,
5570
- WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE5
4697
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
4698
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
5571
4699
  } from "@ai-sdk/provider-utils";
5572
- import { z as z25 } from "zod/v4";
4700
+ import { z as z23 } from "zod/v4";
5573
4701
 
5574
4702
  // src/xai-transcription-model-options.ts
5575
4703
  import {
5576
4704
  lazySchema as lazySchema11,
5577
4705
  zodSchema as zodSchema11
5578
4706
  } from "@ai-sdk/provider-utils";
5579
- import { z as z24 } from "zod/v4";
4707
+ import { z as z22 } from "zod/v4";
5580
4708
  var xaiTranscriptionModelOptionsSchema = lazySchema11(
5581
4709
  () => zodSchema11(
5582
- z24.object({
4710
+ z22.object({
5583
4711
  /**
5584
4712
  * Audio encoding for raw, headerless input audio.
5585
4713
  */
5586
- audioFormat: z24.enum(["pcm", "mulaw", "alaw"]).nullish(),
4714
+ audioFormat: z22.enum(["pcm", "mulaw", "alaw"]).nullish(),
5587
4715
  /**
5588
4716
  * Sample rate of the input audio in Hz.
5589
4717
  */
5590
- sampleRate: z24.union([
5591
- z24.literal(8e3),
5592
- z24.literal(16e3),
5593
- z24.literal(22050),
5594
- z24.literal(24e3),
5595
- z24.literal(44100),
5596
- z24.literal(48e3)
4718
+ sampleRate: z22.union([
4719
+ z22.literal(8e3),
4720
+ z22.literal(16e3),
4721
+ z22.literal(22050),
4722
+ z22.literal(24e3),
4723
+ z22.literal(44100),
4724
+ z22.literal(48e3)
5597
4725
  ]).nullish(),
5598
4726
  /**
5599
4727
  * Language code used for inverse text normalization.
5600
4728
  */
5601
- language: z24.string().nullish(),
4729
+ language: z22.string().nullish(),
5602
4730
  /**
5603
4731
  * Enable inverse text normalization. Requires `language`.
5604
4732
  */
5605
- format: z24.boolean().nullish(),
4733
+ format: z22.boolean().nullish(),
5606
4734
  /**
5607
4735
  * Enable per-channel transcription for multichannel audio.
5608
4736
  */
5609
- multichannel: z24.boolean().nullish(),
4737
+ multichannel: z22.boolean().nullish(),
5610
4738
  /**
5611
4739
  * Number of interleaved audio channels.
5612
4740
  */
5613
- channels: z24.number().int().min(2).max(8).nullish(),
4741
+ channels: z22.number().int().min(2).max(8).nullish(),
5614
4742
  /**
5615
4743
  * Enable speaker diarization.
5616
4744
  */
5617
- diarize: z24.boolean().nullish(),
4745
+ diarize: z22.boolean().nullish(),
5618
4746
  /**
5619
4747
  * Terms to bias transcription toward.
5620
4748
  */
5621
- keyterm: z24.union([z24.string(), z24.array(z24.string())]).nullish(),
4749
+ keyterm: z22.union([z22.string(), z22.array(z22.string())]).nullish(),
5622
4750
  /**
5623
4751
  * Include filler words such as "uh" and "um" in the transcript.
5624
4752
  */
5625
- fillerWords: z24.boolean().nullish(),
4753
+ fillerWords: z22.boolean().nullish(),
5626
4754
  /**
5627
4755
  * Options for streaming speech-to-text over WebSocket.
5628
4756
  */
5629
- streaming: z24.object({
4757
+ streaming: z22.object({
5630
4758
  /**
5631
4759
  * Emit interim transcript results while speech is being processed.
5632
4760
  */
5633
- interimResults: z24.boolean().optional(),
4761
+ interimResults: z22.boolean().optional(),
5634
4762
  /**
5635
4763
  * Silence duration in milliseconds before an utterance-final event.
5636
4764
  */
5637
- endpointing: z24.number().int().min(0).max(5e3).optional(),
4765
+ endpointing: z22.number().int().min(0).max(5e3).optional(),
5638
4766
  /**
5639
4767
  * End-of-turn detection threshold. When set, enables Smart Turn.
5640
4768
  */
5641
- smartTurn: z24.number().min(0).max(1).optional(),
4769
+ smartTurn: z22.number().min(0).max(1).optional(),
5642
4770
  /**
5643
4771
  * Maximum silence duration in milliseconds before forcing speech_final.
5644
4772
  */
5645
- smartTurnTimeout: z24.number().int().min(1).max(5e3).optional()
4773
+ smartTurnTimeout: z22.number().int().min(1).max(5e3).optional()
5646
4774
  }).optional()
5647
4775
  })
5648
4776
  )
@@ -5655,13 +4783,13 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
5655
4783
  this.config = config;
5656
4784
  this.specificationVersion = "v4";
5657
4785
  }
5658
- static [WORKFLOW_SERIALIZE5](model) {
5659
- return serializeModelOptions5({
4786
+ static [WORKFLOW_SERIALIZE4](model) {
4787
+ return serializeModelOptions4({
5660
4788
  modelId: model.modelId,
5661
4789
  config: model.config
5662
4790
  });
5663
4791
  }
5664
- static [WORKFLOW_DESERIALIZE5](options) {
4792
+ static [WORKFLOW_DESERIALIZE4](options) {
5665
4793
  return new _XaiTranscriptionModel(options.modelId, options.config);
5666
4794
  }
5667
4795
  get provider() {
@@ -5673,7 +4801,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
5673
4801
  providerOptions
5674
4802
  }) {
5675
4803
  const warnings = [];
5676
- const xaiOptions = await parseProviderOptions10({
4804
+ const xaiOptions = await parseProviderOptions8({
5677
4805
  provider: "xai",
5678
4806
  providerOptions,
5679
4807
  schema: xaiTranscriptionModelOptionsSchema
@@ -5719,10 +4847,10 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
5719
4847
  rawValue: rawResponse
5720
4848
  } = await postFormDataToApi3({
5721
4849
  url: `${(_d = this.config.baseURL) != null ? _d : "https://api.x.ai/v1"}/stt`,
5722
- headers: combineHeaders8((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers),
4850
+ headers: combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers),
5723
4851
  formData,
5724
4852
  failedResponseHandler: xaiFailedResponseHandler,
5725
- successfulResponseHandler: createJsonResponseHandler8(
4853
+ successfulResponseHandler: createJsonResponseHandler7(
5726
4854
  xaiTranscriptionResponseSchema
5727
4855
  ),
5728
4856
  abortSignal: options.abortSignal,
@@ -5750,7 +4878,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
5750
4878
  var _a, _b, _c, _d, _e, _f, _g;
5751
4879
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
5752
4880
  const warnings = [];
5753
- const xaiOptions = await parseProviderOptions10({
4881
+ const xaiOptions = await parseProviderOptions8({
5754
4882
  provider: "xai",
5755
4883
  providerOptions: options.providerOptions,
5756
4884
  schema: xaiTranscriptionModelOptionsSchema
@@ -5779,7 +4907,7 @@ var XaiTranscriptionModel = class _XaiTranscriptionModel {
5779
4907
  inputAudioFormat: options.inputAudioFormat,
5780
4908
  providerOptions: xaiOptions
5781
4909
  });
5782
- const headers = combineHeaders8((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers);
4910
+ const headers = combineHeaders7((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), options.headers);
5783
4911
  return {
5784
4912
  request: { body: url.toString() },
5785
4913
  response: {
@@ -5880,7 +5008,7 @@ function createXaiStreamingTranscriptionStream({
5880
5008
  onProcessingError: finishWithError,
5881
5009
  onMessageText: async (text) => {
5882
5010
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5883
- const parsed = await safeParseJSON3({ text });
5011
+ const parsed = await safeParseJSON2({ text });
5884
5012
  if (!parsed.success) return;
5885
5013
  const raw = parsed.value;
5886
5014
  if (includeRawChunks) {
@@ -6041,15 +5169,15 @@ function timingFromXaiEvent(event) {
6041
5169
  ...event.start != null && event.duration != null ? { endSecond: event.start + event.duration } : {}
6042
5170
  };
6043
5171
  }
6044
- var xaiTranscriptionResponseSchema = z25.object({
6045
- text: z25.string(),
6046
- language: z25.string().nullish(),
6047
- duration: z25.number().nullish(),
6048
- words: z25.array(
6049
- z25.object({
6050
- text: z25.string(),
6051
- start: z25.number(),
6052
- end: z25.number()
5172
+ var xaiTranscriptionResponseSchema = z23.object({
5173
+ text: z23.string(),
5174
+ language: z23.string().nullish(),
5175
+ duration: z23.number().nullish(),
5176
+ words: z23.array(
5177
+ z23.object({
5178
+ text: z23.string(),
5179
+ start: z23.number(),
5180
+ end: z23.number()
6053
5181
  })
6054
5182
  ).nullish()
6055
5183
  });
@@ -6071,15 +5199,6 @@ function createXai(options = {}) {
6071
5199
  },
6072
5200
  `ai-sdk/xai/${VERSION}`
6073
5201
  );
6074
- const createChatLanguageModel = (modelId) => {
6075
- return new XaiChatLanguageModel(modelId, {
6076
- provider: "xai.chat",
6077
- baseURL,
6078
- headers: getHeaders,
6079
- generateId,
6080
- fetch: options.fetch
6081
- });
6082
- };
6083
5202
  const createResponsesLanguageModel = (modelId) => {
6084
5203
  return new XaiResponsesLanguageModel(modelId, {
6085
5204
  provider: "xai.responses",
@@ -6166,7 +5285,6 @@ function createXai(options = {}) {
6166
5285
  const provider = (modelId) => createResponsesLanguageModel(modelId);
6167
5286
  provider.specificationVersion = "v4";
6168
5287
  provider.languageModel = createResponsesLanguageModel;
6169
- provider.chat = createChatLanguageModel;
6170
5288
  provider.responses = createResponsesLanguageModel;
6171
5289
  provider.embeddingModel = (modelId) => {
6172
5290
  throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });