@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/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -14,6 +14,10 @@ declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
|
14
14
|
}>>;
|
|
15
15
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
16
16
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
18
|
+
default: "default";
|
|
19
|
+
priority: "priority";
|
|
20
|
+
}>>;
|
|
17
21
|
parallel_function_calling: z.ZodOptional<z.ZodBoolean>;
|
|
18
22
|
searchParameters: z.ZodOptional<z.ZodObject<{
|
|
19
23
|
mode: z.ZodEnum<{
|
|
@@ -87,6 +91,10 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
|
87
91
|
}>>;
|
|
88
92
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
89
93
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
95
|
+
default: "default";
|
|
96
|
+
priority: "priority";
|
|
97
|
+
}>>;
|
|
90
98
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
91
99
|
previousResponseId: z.ZodOptional<z.ZodString>;
|
|
92
100
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
|
14
14
|
}>>;
|
|
15
15
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
16
16
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
18
|
+
default: "default";
|
|
19
|
+
priority: "priority";
|
|
20
|
+
}>>;
|
|
17
21
|
parallel_function_calling: z.ZodOptional<z.ZodBoolean>;
|
|
18
22
|
searchParameters: z.ZodOptional<z.ZodObject<{
|
|
19
23
|
mode: z.ZodEnum<{
|
|
@@ -87,6 +91,10 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
|
87
91
|
}>>;
|
|
88
92
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
89
93
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
95
|
+
default: "default";
|
|
96
|
+
priority: "priority";
|
|
97
|
+
}>>;
|
|
90
98
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
91
99
|
previousResponseId: z.ZodOptional<z.ZodString>;
|
|
92
100
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
package/dist/index.js
CHANGED
|
@@ -277,6 +277,7 @@ var xaiLanguageModelChatOptions = import_v42.z.object({
|
|
|
277
277
|
reasoningEffort: import_v42.z.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
278
278
|
logprobs: import_v42.z.boolean().optional(),
|
|
279
279
|
topLogprobs: import_v42.z.number().int().min(0).max(8).optional(),
|
|
280
|
+
serviceTier: import_v42.z.enum(["default", "priority"]).optional(),
|
|
280
281
|
/**
|
|
281
282
|
* Whether to enable parallel function calling during tool use.
|
|
282
283
|
* When true, the model can call multiple functions in parallel.
|
|
@@ -501,6 +502,8 @@ var XaiChatLanguageModel = class {
|
|
|
501
502
|
top_p: topP,
|
|
502
503
|
seed,
|
|
503
504
|
reasoning_effort: options.reasoningEffort,
|
|
505
|
+
// scheduling priority
|
|
506
|
+
service_tier: options.serviceTier,
|
|
504
507
|
// parallel function calling
|
|
505
508
|
parallel_function_calling: options.parallel_function_calling,
|
|
506
509
|
// response format
|
|
@@ -635,6 +638,11 @@ var XaiChatLanguageModel = class {
|
|
|
635
638
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
636
639
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
637
640
|
},
|
|
641
|
+
...response.service_tier != null && {
|
|
642
|
+
providerMetadata: {
|
|
643
|
+
xai: { serviceTier: response.service_tier }
|
|
644
|
+
}
|
|
645
|
+
},
|
|
638
646
|
request: { body },
|
|
639
647
|
response: {
|
|
640
648
|
...getResponseMetadata(response),
|
|
@@ -703,6 +711,7 @@ var XaiChatLanguageModel = class {
|
|
|
703
711
|
raw: void 0
|
|
704
712
|
};
|
|
705
713
|
let usage = void 0;
|
|
714
|
+
let serviceTier = void 0;
|
|
706
715
|
let isFirstChunk = true;
|
|
707
716
|
const contentBlocks = {};
|
|
708
717
|
const lastReasoningDeltas = {};
|
|
@@ -743,6 +752,9 @@ var XaiChatLanguageModel = class {
|
|
|
743
752
|
if (value.usage != null) {
|
|
744
753
|
usage = convertXaiChatUsage(value.usage);
|
|
745
754
|
}
|
|
755
|
+
if (value.service_tier != null) {
|
|
756
|
+
serviceTier = value.service_tier;
|
|
757
|
+
}
|
|
746
758
|
const choice = value.choices[0];
|
|
747
759
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
748
760
|
finishReason = {
|
|
@@ -857,6 +869,9 @@ var XaiChatLanguageModel = class {
|
|
|
857
869
|
cacheWrite: 0
|
|
858
870
|
},
|
|
859
871
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
872
|
+
},
|
|
873
|
+
...serviceTier != null && {
|
|
874
|
+
providerMetadata: { xai: { serviceTier } }
|
|
860
875
|
}
|
|
861
876
|
});
|
|
862
877
|
}
|
|
@@ -912,6 +927,7 @@ var xaiChatResponseSchema = import_v44.z.object({
|
|
|
912
927
|
object: import_v44.z.literal("chat.completion").nullish(),
|
|
913
928
|
usage: xaiUsageSchema.nullish(),
|
|
914
929
|
citations: import_v44.z.array(import_v44.z.string().url()).nullish(),
|
|
930
|
+
service_tier: import_v44.z.string().nullish(),
|
|
915
931
|
code: import_v44.z.string().nullish(),
|
|
916
932
|
error: import_v44.z.string().nullish()
|
|
917
933
|
});
|
|
@@ -941,7 +957,8 @@ var xaiChatChunkSchema = import_v44.z.object({
|
|
|
941
957
|
})
|
|
942
958
|
),
|
|
943
959
|
usage: xaiUsageSchema.nullish(),
|
|
944
|
-
citations: import_v44.z.array(import_v44.z.string().url()).nullish()
|
|
960
|
+
citations: import_v44.z.array(import_v44.z.string().url()).nullish(),
|
|
961
|
+
service_tier: import_v44.z.string().nullish()
|
|
945
962
|
});
|
|
946
963
|
var xaiStreamErrorSchema = import_v44.z.object({
|
|
947
964
|
code: import_v44.z.string(),
|
|
@@ -1509,7 +1526,8 @@ var xaiResponsesResponseSchema = import_v47.z.object({
|
|
|
1509
1526
|
object: import_v47.z.literal("response"),
|
|
1510
1527
|
output: import_v47.z.array(outputItemSchema),
|
|
1511
1528
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1512
|
-
status: import_v47.z.string()
|
|
1529
|
+
status: import_v47.z.string(),
|
|
1530
|
+
service_tier: import_v47.z.string().nullish()
|
|
1513
1531
|
});
|
|
1514
1532
|
var xaiResponsesChunkSchema = import_v47.z.union([
|
|
1515
1533
|
import_v47.z.object({
|
|
@@ -1777,7 +1795,8 @@ var xaiResponsesChunkSchema = import_v47.z.union([
|
|
|
1777
1795
|
type: import_v47.z.literal("response.incomplete"),
|
|
1778
1796
|
response: import_v47.z.object({
|
|
1779
1797
|
incomplete_details: import_v47.z.object({ reason: import_v47.z.string() }).nullish(),
|
|
1780
|
-
usage: xaiResponsesUsageSchema.nullish()
|
|
1798
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
1799
|
+
service_tier: import_v47.z.string().nullish()
|
|
1781
1800
|
})
|
|
1782
1801
|
}),
|
|
1783
1802
|
import_v47.z.object({
|
|
@@ -1820,6 +1839,7 @@ var xaiLanguageModelResponsesOptions = import_v48.z.object({
|
|
|
1820
1839
|
reasoningEffort: import_v48.z.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
1821
1840
|
logprobs: import_v48.z.boolean().optional(),
|
|
1822
1841
|
topLogprobs: import_v48.z.number().int().min(0).max(8).optional(),
|
|
1842
|
+
serviceTier: import_v48.z.enum(["default", "priority"]).optional(),
|
|
1823
1843
|
/**
|
|
1824
1844
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
1825
1845
|
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
@@ -2248,6 +2268,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2248
2268
|
},
|
|
2249
2269
|
...options.previousResponseId != null && {
|
|
2250
2270
|
previous_response_id: options.previousResponseId
|
|
2271
|
+
},
|
|
2272
|
+
...options.serviceTier != null && {
|
|
2273
|
+
service_tier: options.serviceTier
|
|
2251
2274
|
}
|
|
2252
2275
|
};
|
|
2253
2276
|
if (xaiTools2 && xaiTools2.length > 0) {
|
|
@@ -2424,6 +2447,11 @@ var XaiResponsesLanguageModel = class {
|
|
|
2424
2447
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2425
2448
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2426
2449
|
},
|
|
2450
|
+
...response.service_tier != null && {
|
|
2451
|
+
providerMetadata: {
|
|
2452
|
+
xai: { serviceTier: response.service_tier }
|
|
2453
|
+
}
|
|
2454
|
+
},
|
|
2427
2455
|
request: { body },
|
|
2428
2456
|
response: {
|
|
2429
2457
|
...getResponseMetadata(response),
|
|
@@ -2465,6 +2493,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2465
2493
|
};
|
|
2466
2494
|
let hasFunctionCall = false;
|
|
2467
2495
|
let usage = void 0;
|
|
2496
|
+
let serviceTier = void 0;
|
|
2468
2497
|
let isFirstChunk = true;
|
|
2469
2498
|
const contentBlocks = {};
|
|
2470
2499
|
const seenToolCalls = /* @__PURE__ */ new Set();
|
|
@@ -2478,7 +2507,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2478
2507
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2479
2508
|
},
|
|
2480
2509
|
transform(chunk, controller) {
|
|
2481
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2510
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2482
2511
|
if (options.includeRawChunks) {
|
|
2483
2512
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2484
2513
|
}
|
|
@@ -2608,8 +2637,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2608
2637
|
if (response2.usage) {
|
|
2609
2638
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2610
2639
|
}
|
|
2640
|
+
serviceTier = (_c = response2.service_tier) != null ? _c : void 0;
|
|
2611
2641
|
if (event.type === "response.incomplete") {
|
|
2612
|
-
const reason = "incomplete_details" in response2 ? (
|
|
2642
|
+
const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
|
|
2613
2643
|
finishReason = {
|
|
2614
2644
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2615
2645
|
raw: reason != null ? reason : "incomplete"
|
|
@@ -2623,7 +2653,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2623
2653
|
return;
|
|
2624
2654
|
}
|
|
2625
2655
|
if (event.type === "response.failed") {
|
|
2626
|
-
const reason = (
|
|
2656
|
+
const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
|
|
2627
2657
|
finishReason = {
|
|
2628
2658
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2629
2659
|
raw: reason != null ? reason : "error"
|
|
@@ -2719,13 +2749,13 @@ var XaiResponsesLanguageModel = class {
|
|
|
2719
2749
|
toolCallId: part.id,
|
|
2720
2750
|
toolName,
|
|
2721
2751
|
result: {
|
|
2722
|
-
queries: (
|
|
2723
|
-
results: (
|
|
2752
|
+
queries: (_f = part.queries) != null ? _f : [],
|
|
2753
|
+
results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
|
|
2724
2754
|
fileId: result.file_id,
|
|
2725
2755
|
filename: result.filename,
|
|
2726
2756
|
score: result.score,
|
|
2727
2757
|
text: result.text
|
|
2728
|
-
}))) != null ?
|
|
2758
|
+
}))) != null ? _h : null
|
|
2729
2759
|
}
|
|
2730
2760
|
});
|
|
2731
2761
|
}
|
|
@@ -2743,17 +2773,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2743
2773
|
"x_semantic_search",
|
|
2744
2774
|
"x_thread_fetch"
|
|
2745
2775
|
];
|
|
2746
|
-
let toolName = (
|
|
2747
|
-
if (webSearchSubTools.includes((
|
|
2776
|
+
let toolName = (_i = part.name) != null ? _i : "";
|
|
2777
|
+
if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
|
|
2748
2778
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2749
|
-
} else if (xSearchSubTools.includes((
|
|
2779
|
+
} else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
|
|
2750
2780
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2751
2781
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2752
2782
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2753
2783
|
} else if (part.type === "mcp_call") {
|
|
2754
|
-
toolName = (
|
|
2784
|
+
toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
|
|
2755
2785
|
}
|
|
2756
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2786
|
+
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 : "";
|
|
2757
2787
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2758
2788
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2759
2789
|
seenToolCalls.add(part.id);
|
|
@@ -2814,7 +2844,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2814
2844
|
sourceType: "url",
|
|
2815
2845
|
id: self.config.generateId(),
|
|
2816
2846
|
url: annotation.url,
|
|
2817
|
-
title: (
|
|
2847
|
+
title: (_p = annotation.title) != null ? _p : annotation.url
|
|
2818
2848
|
});
|
|
2819
2849
|
}
|
|
2820
2850
|
}
|
|
@@ -2868,6 +2898,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2868
2898
|
cacheWrite: 0
|
|
2869
2899
|
},
|
|
2870
2900
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2901
|
+
},
|
|
2902
|
+
...serviceTier != null && {
|
|
2903
|
+
providerMetadata: { xai: { serviceTier } }
|
|
2871
2904
|
}
|
|
2872
2905
|
});
|
|
2873
2906
|
}
|
|
@@ -2934,7 +2967,7 @@ var xaiTools = {
|
|
|
2934
2967
|
};
|
|
2935
2968
|
|
|
2936
2969
|
// src/version.ts
|
|
2937
|
-
var VERSION = true ? "3.0.
|
|
2970
|
+
var VERSION = true ? "3.0.120" : "0.0.0-test";
|
|
2938
2971
|
|
|
2939
2972
|
// src/xai-video-model.ts
|
|
2940
2973
|
var import_provider6 = require("@ai-sdk/provider");
|