@ai-sdk/xai 3.0.119 → 3.0.120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +49 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -16
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +35 -0
- package/package.json +3 -3
- package/src/responses/xai-responses-api.ts +2 -0
- package/src/responses/xai-responses-language-model.ts +14 -0
- package/src/responses/xai-responses-options.ts +1 -0
- package/src/xai-chat-language-model.ts +19 -0
- package/src/xai-chat-options.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -261,6 +261,7 @@ var xaiLanguageModelChatOptions = z2.object({
|
|
|
261
261
|
reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
262
262
|
logprobs: z2.boolean().optional(),
|
|
263
263
|
topLogprobs: z2.number().int().min(0).max(8).optional(),
|
|
264
|
+
serviceTier: z2.enum(["default", "priority"]).optional(),
|
|
264
265
|
/**
|
|
265
266
|
* Whether to enable parallel function calling during tool use.
|
|
266
267
|
* When true, the model can call multiple functions in parallel.
|
|
@@ -487,6 +488,8 @@ var XaiChatLanguageModel = class {
|
|
|
487
488
|
top_p: topP,
|
|
488
489
|
seed,
|
|
489
490
|
reasoning_effort: options.reasoningEffort,
|
|
491
|
+
// scheduling priority
|
|
492
|
+
service_tier: options.serviceTier,
|
|
490
493
|
// parallel function calling
|
|
491
494
|
parallel_function_calling: options.parallel_function_calling,
|
|
492
495
|
// response format
|
|
@@ -621,6 +624,11 @@ var XaiChatLanguageModel = class {
|
|
|
621
624
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
622
625
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
623
626
|
},
|
|
627
|
+
...response.service_tier != null && {
|
|
628
|
+
providerMetadata: {
|
|
629
|
+
xai: { serviceTier: response.service_tier }
|
|
630
|
+
}
|
|
631
|
+
},
|
|
624
632
|
request: { body },
|
|
625
633
|
response: {
|
|
626
634
|
...getResponseMetadata(response),
|
|
@@ -689,6 +697,7 @@ var XaiChatLanguageModel = class {
|
|
|
689
697
|
raw: void 0
|
|
690
698
|
};
|
|
691
699
|
let usage = void 0;
|
|
700
|
+
let serviceTier = void 0;
|
|
692
701
|
let isFirstChunk = true;
|
|
693
702
|
const contentBlocks = {};
|
|
694
703
|
const lastReasoningDeltas = {};
|
|
@@ -729,6 +738,9 @@ var XaiChatLanguageModel = class {
|
|
|
729
738
|
if (value.usage != null) {
|
|
730
739
|
usage = convertXaiChatUsage(value.usage);
|
|
731
740
|
}
|
|
741
|
+
if (value.service_tier != null) {
|
|
742
|
+
serviceTier = value.service_tier;
|
|
743
|
+
}
|
|
732
744
|
const choice = value.choices[0];
|
|
733
745
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
734
746
|
finishReason = {
|
|
@@ -843,6 +855,9 @@ var XaiChatLanguageModel = class {
|
|
|
843
855
|
cacheWrite: 0
|
|
844
856
|
},
|
|
845
857
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
858
|
+
},
|
|
859
|
+
...serviceTier != null && {
|
|
860
|
+
providerMetadata: { xai: { serviceTier } }
|
|
846
861
|
}
|
|
847
862
|
});
|
|
848
863
|
}
|
|
@@ -898,6 +913,7 @@ var xaiChatResponseSchema = z4.object({
|
|
|
898
913
|
object: z4.literal("chat.completion").nullish(),
|
|
899
914
|
usage: xaiUsageSchema.nullish(),
|
|
900
915
|
citations: z4.array(z4.string().url()).nullish(),
|
|
916
|
+
service_tier: z4.string().nullish(),
|
|
901
917
|
code: z4.string().nullish(),
|
|
902
918
|
error: z4.string().nullish()
|
|
903
919
|
});
|
|
@@ -927,7 +943,8 @@ var xaiChatChunkSchema = z4.object({
|
|
|
927
943
|
})
|
|
928
944
|
),
|
|
929
945
|
usage: xaiUsageSchema.nullish(),
|
|
930
|
-
citations: z4.array(z4.string().url()).nullish()
|
|
946
|
+
citations: z4.array(z4.string().url()).nullish(),
|
|
947
|
+
service_tier: z4.string().nullish()
|
|
931
948
|
});
|
|
932
949
|
var xaiStreamErrorSchema = z4.object({
|
|
933
950
|
code: z4.string(),
|
|
@@ -1512,7 +1529,8 @@ var xaiResponsesResponseSchema = z7.object({
|
|
|
1512
1529
|
object: z7.literal("response"),
|
|
1513
1530
|
output: z7.array(outputItemSchema),
|
|
1514
1531
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1515
|
-
status: z7.string()
|
|
1532
|
+
status: z7.string(),
|
|
1533
|
+
service_tier: z7.string().nullish()
|
|
1516
1534
|
});
|
|
1517
1535
|
var xaiResponsesChunkSchema = z7.union([
|
|
1518
1536
|
z7.object({
|
|
@@ -1780,7 +1798,8 @@ var xaiResponsesChunkSchema = z7.union([
|
|
|
1780
1798
|
type: z7.literal("response.incomplete"),
|
|
1781
1799
|
response: z7.object({
|
|
1782
1800
|
incomplete_details: z7.object({ reason: z7.string() }).nullish(),
|
|
1783
|
-
usage: xaiResponsesUsageSchema.nullish()
|
|
1801
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
1802
|
+
service_tier: z7.string().nullish()
|
|
1784
1803
|
})
|
|
1785
1804
|
}),
|
|
1786
1805
|
z7.object({
|
|
@@ -1823,6 +1842,7 @@ var xaiLanguageModelResponsesOptions = z8.object({
|
|
|
1823
1842
|
reasoningEffort: z8.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
1824
1843
|
logprobs: z8.boolean().optional(),
|
|
1825
1844
|
topLogprobs: z8.number().int().min(0).max(8).optional(),
|
|
1845
|
+
serviceTier: z8.enum(["default", "priority"]).optional(),
|
|
1826
1846
|
/**
|
|
1827
1847
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
1828
1848
|
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
@@ -2269,6 +2289,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2269
2289
|
},
|
|
2270
2290
|
...options.previousResponseId != null && {
|
|
2271
2291
|
previous_response_id: options.previousResponseId
|
|
2292
|
+
},
|
|
2293
|
+
...options.serviceTier != null && {
|
|
2294
|
+
service_tier: options.serviceTier
|
|
2272
2295
|
}
|
|
2273
2296
|
};
|
|
2274
2297
|
if (xaiTools2 && xaiTools2.length > 0) {
|
|
@@ -2445,6 +2468,11 @@ var XaiResponsesLanguageModel = class {
|
|
|
2445
2468
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2446
2469
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2447
2470
|
},
|
|
2471
|
+
...response.service_tier != null && {
|
|
2472
|
+
providerMetadata: {
|
|
2473
|
+
xai: { serviceTier: response.service_tier }
|
|
2474
|
+
}
|
|
2475
|
+
},
|
|
2448
2476
|
request: { body },
|
|
2449
2477
|
response: {
|
|
2450
2478
|
...getResponseMetadata(response),
|
|
@@ -2486,6 +2514,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2486
2514
|
};
|
|
2487
2515
|
let hasFunctionCall = false;
|
|
2488
2516
|
let usage = void 0;
|
|
2517
|
+
let serviceTier = void 0;
|
|
2489
2518
|
let isFirstChunk = true;
|
|
2490
2519
|
const contentBlocks = {};
|
|
2491
2520
|
const seenToolCalls = /* @__PURE__ */ new Set();
|
|
@@ -2499,7 +2528,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2499
2528
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2500
2529
|
},
|
|
2501
2530
|
transform(chunk, controller) {
|
|
2502
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2531
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2503
2532
|
if (options.includeRawChunks) {
|
|
2504
2533
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2505
2534
|
}
|
|
@@ -2629,8 +2658,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2629
2658
|
if (response2.usage) {
|
|
2630
2659
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2631
2660
|
}
|
|
2661
|
+
serviceTier = (_c = response2.service_tier) != null ? _c : void 0;
|
|
2632
2662
|
if (event.type === "response.incomplete") {
|
|
2633
|
-
const reason = "incomplete_details" in response2 ? (
|
|
2663
|
+
const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
|
|
2634
2664
|
finishReason = {
|
|
2635
2665
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2636
2666
|
raw: reason != null ? reason : "incomplete"
|
|
@@ -2644,7 +2674,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2644
2674
|
return;
|
|
2645
2675
|
}
|
|
2646
2676
|
if (event.type === "response.failed") {
|
|
2647
|
-
const reason = (
|
|
2677
|
+
const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
|
|
2648
2678
|
finishReason = {
|
|
2649
2679
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2650
2680
|
raw: reason != null ? reason : "error"
|
|
@@ -2740,13 +2770,13 @@ var XaiResponsesLanguageModel = class {
|
|
|
2740
2770
|
toolCallId: part.id,
|
|
2741
2771
|
toolName,
|
|
2742
2772
|
result: {
|
|
2743
|
-
queries: (
|
|
2744
|
-
results: (
|
|
2773
|
+
queries: (_f = part.queries) != null ? _f : [],
|
|
2774
|
+
results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
|
|
2745
2775
|
fileId: result.file_id,
|
|
2746
2776
|
filename: result.filename,
|
|
2747
2777
|
score: result.score,
|
|
2748
2778
|
text: result.text
|
|
2749
|
-
}))) != null ?
|
|
2779
|
+
}))) != null ? _h : null
|
|
2750
2780
|
}
|
|
2751
2781
|
});
|
|
2752
2782
|
}
|
|
@@ -2764,17 +2794,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2764
2794
|
"x_semantic_search",
|
|
2765
2795
|
"x_thread_fetch"
|
|
2766
2796
|
];
|
|
2767
|
-
let toolName = (
|
|
2768
|
-
if (webSearchSubTools.includes((
|
|
2797
|
+
let toolName = (_i = part.name) != null ? _i : "";
|
|
2798
|
+
if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
|
|
2769
2799
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2770
|
-
} else if (xSearchSubTools.includes((
|
|
2800
|
+
} else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
|
|
2771
2801
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2772
2802
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2773
2803
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2774
2804
|
} else if (part.type === "mcp_call") {
|
|
2775
|
-
toolName = (
|
|
2805
|
+
toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
|
|
2776
2806
|
}
|
|
2777
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2807
|
+
const toolInput = part.type === "custom_tool_call" ? (_m = part.input) != null ? _m : "" : part.type === "mcp_call" ? (_n = part.arguments) != null ? _n : "" : (_o = part.arguments) != null ? _o : "";
|
|
2778
2808
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2779
2809
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2780
2810
|
seenToolCalls.add(part.id);
|
|
@@ -2835,7 +2865,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2835
2865
|
sourceType: "url",
|
|
2836
2866
|
id: self.config.generateId(),
|
|
2837
2867
|
url: annotation.url,
|
|
2838
|
-
title: (
|
|
2868
|
+
title: (_p = annotation.title) != null ? _p : annotation.url
|
|
2839
2869
|
});
|
|
2840
2870
|
}
|
|
2841
2871
|
}
|
|
@@ -2889,6 +2919,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2889
2919
|
cacheWrite: 0
|
|
2890
2920
|
},
|
|
2891
2921
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2922
|
+
},
|
|
2923
|
+
...serviceTier != null && {
|
|
2924
|
+
providerMetadata: { xai: { serviceTier } }
|
|
2892
2925
|
}
|
|
2893
2926
|
});
|
|
2894
2927
|
}
|
|
@@ -2955,7 +2988,7 @@ var xaiTools = {
|
|
|
2955
2988
|
};
|
|
2956
2989
|
|
|
2957
2990
|
// src/version.ts
|
|
2958
|
-
var VERSION = true ? "3.0.
|
|
2991
|
+
var VERSION = true ? "3.0.120" : "0.0.0-test";
|
|
2959
2992
|
|
|
2960
2993
|
// src/xai-video-model.ts
|
|
2961
2994
|
import {
|