@ai-sdk/xai 4.0.37 → 4.0.38
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.ts +8 -0
- package/dist/index.js +52 -21
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +35 -0
- package/package.json +5 -5
- package/src/responses/xai-responses-api.ts +2 -0
- package/src/responses/xai-responses-language-model-options.ts +1 -0
- package/src/responses/xai-responses-language-model.ts +17 -4
- package/src/xai-chat-language-model-options.ts +2 -0
- package/src/xai-chat-language-model.ts +19 -0
package/CHANGELOG.md
CHANGED
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<{
|
|
@@ -92,6 +96,10 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
|
92
96
|
}>>;
|
|
93
97
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
94
98
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
100
|
+
default: "default";
|
|
101
|
+
priority: "priority";
|
|
102
|
+
}>>;
|
|
95
103
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
96
104
|
previousResponseId: z.ZodOptional<z.ZodString>;
|
|
97
105
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
package/dist/index.js
CHANGED
|
@@ -315,6 +315,7 @@ var xaiLanguageModelChatOptions = z2.object({
|
|
|
315
315
|
reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
316
316
|
logprobs: z2.boolean().optional(),
|
|
317
317
|
topLogprobs: z2.number().int().min(0).max(8).optional(),
|
|
318
|
+
serviceTier: z2.enum(["default", "priority"]).optional(),
|
|
318
319
|
/**
|
|
319
320
|
* Whether to enable parallel function calling during tool use.
|
|
320
321
|
* When true, the model can call multiple functions in parallel.
|
|
@@ -575,6 +576,8 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
|
575
576
|
top_p: topP,
|
|
576
577
|
seed,
|
|
577
578
|
reasoning_effort: reasoningEffort,
|
|
579
|
+
// scheduling priority
|
|
580
|
+
service_tier: options.serviceTier,
|
|
578
581
|
// parallel function calling
|
|
579
582
|
parallel_function_calling: options.parallel_function_calling,
|
|
580
583
|
// response format
|
|
@@ -709,6 +712,11 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
|
709
712
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
710
713
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
711
714
|
},
|
|
715
|
+
...response.service_tier != null && {
|
|
716
|
+
providerMetadata: {
|
|
717
|
+
xai: { serviceTier: response.service_tier }
|
|
718
|
+
}
|
|
719
|
+
},
|
|
712
720
|
request: { body },
|
|
713
721
|
response: {
|
|
714
722
|
...getResponseMetadata(response),
|
|
@@ -777,6 +785,7 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
|
777
785
|
raw: void 0
|
|
778
786
|
};
|
|
779
787
|
let usage = void 0;
|
|
788
|
+
let serviceTier = void 0;
|
|
780
789
|
let isFirstChunk = true;
|
|
781
790
|
const contentBlocks = {};
|
|
782
791
|
const lastReasoningDeltas = {};
|
|
@@ -817,6 +826,9 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
|
817
826
|
if (value.usage != null) {
|
|
818
827
|
usage = convertXaiChatUsage(value.usage);
|
|
819
828
|
}
|
|
829
|
+
if (value.service_tier != null) {
|
|
830
|
+
serviceTier = value.service_tier;
|
|
831
|
+
}
|
|
820
832
|
const choice = value.choices[0];
|
|
821
833
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
822
834
|
finishReason = {
|
|
@@ -931,6 +943,9 @@ var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
|
931
943
|
cacheWrite: 0
|
|
932
944
|
},
|
|
933
945
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
946
|
+
},
|
|
947
|
+
...serviceTier != null && {
|
|
948
|
+
providerMetadata: { xai: { serviceTier } }
|
|
934
949
|
}
|
|
935
950
|
});
|
|
936
951
|
}
|
|
@@ -986,6 +1001,7 @@ var xaiChatResponseSchema = z4.object({
|
|
|
986
1001
|
object: z4.literal("chat.completion").nullish(),
|
|
987
1002
|
usage: xaiUsageSchema.nullish(),
|
|
988
1003
|
citations: z4.array(z4.string().url()).nullish(),
|
|
1004
|
+
service_tier: z4.string().nullish(),
|
|
989
1005
|
code: z4.string().nullish(),
|
|
990
1006
|
error: z4.string().nullish()
|
|
991
1007
|
});
|
|
@@ -1015,7 +1031,8 @@ var xaiChatChunkSchema = z4.object({
|
|
|
1015
1031
|
})
|
|
1016
1032
|
),
|
|
1017
1033
|
usage: xaiUsageSchema.nullish(),
|
|
1018
|
-
citations: z4.array(z4.string().url()).nullish()
|
|
1034
|
+
citations: z4.array(z4.string().url()).nullish(),
|
|
1035
|
+
service_tier: z4.string().nullish()
|
|
1019
1036
|
});
|
|
1020
1037
|
var xaiStreamErrorSchema = z4.object({
|
|
1021
1038
|
code: z4.string(),
|
|
@@ -1647,7 +1664,8 @@ var xaiResponsesResponseSchema = z7.object({
|
|
|
1647
1664
|
object: z7.literal("response"),
|
|
1648
1665
|
output: z7.array(outputItemSchema),
|
|
1649
1666
|
usage: xaiResponsesUsageSchema.nullish(),
|
|
1650
|
-
status: z7.string()
|
|
1667
|
+
status: z7.string(),
|
|
1668
|
+
service_tier: z7.string().nullish()
|
|
1651
1669
|
});
|
|
1652
1670
|
var xaiResponsesChunkSchema = z7.union([
|
|
1653
1671
|
z7.object({
|
|
@@ -1930,7 +1948,8 @@ var xaiResponsesChunkSchema = z7.union([
|
|
|
1930
1948
|
type: z7.literal("response.incomplete"),
|
|
1931
1949
|
response: z7.object({
|
|
1932
1950
|
incomplete_details: z7.object({ reason: z7.string() }).nullish(),
|
|
1933
|
-
usage: xaiResponsesUsageSchema.nullish()
|
|
1951
|
+
usage: xaiResponsesUsageSchema.nullish(),
|
|
1952
|
+
service_tier: z7.string().nullish()
|
|
1934
1953
|
})
|
|
1935
1954
|
}),
|
|
1936
1955
|
z7.object({
|
|
@@ -1976,6 +1995,7 @@ var xaiLanguageModelResponsesOptions = z8.object({
|
|
|
1976
1995
|
reasoningSummary: z8.enum(["auto", "concise", "detailed"]).optional(),
|
|
1977
1996
|
logprobs: z8.boolean().optional(),
|
|
1978
1997
|
topLogprobs: z8.number().int().min(0).max(8).optional(),
|
|
1998
|
+
serviceTier: z8.enum(["default", "priority"]).optional(),
|
|
1979
1999
|
/**
|
|
1980
2000
|
* Whether to store the input message(s) and model response for later retrieval.
|
|
1981
2001
|
* Must be set to `false` for teams with Zero Data Retention (ZDR) enabled,
|
|
@@ -2507,6 +2527,9 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2507
2527
|
},
|
|
2508
2528
|
...options.previousResponseId != null && {
|
|
2509
2529
|
previous_response_id: options.previousResponseId
|
|
2530
|
+
},
|
|
2531
|
+
...options.serviceTier != null && {
|
|
2532
|
+
service_tier: options.serviceTier
|
|
2510
2533
|
}
|
|
2511
2534
|
};
|
|
2512
2535
|
if (xaiTools2 && xaiTools2.length > 0) {
|
|
@@ -2527,7 +2550,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2527
2550
|
};
|
|
2528
2551
|
}
|
|
2529
2552
|
async doGenerate(options) {
|
|
2530
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2553
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
2531
2554
|
const {
|
|
2532
2555
|
args: body,
|
|
2533
2556
|
warnings,
|
|
@@ -2715,10 +2738,15 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2715
2738
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2716
2739
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
2717
2740
|
},
|
|
2718
|
-
...((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null && {
|
|
2741
|
+
...(((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null || response.service_tier != null) && {
|
|
2719
2742
|
providerMetadata: {
|
|
2720
2743
|
xai: {
|
|
2721
|
-
|
|
2744
|
+
...((_r = response.usage) == null ? void 0 : _r.cost_in_usd_ticks) != null && {
|
|
2745
|
+
costInUsdTicks: response.usage.cost_in_usd_ticks
|
|
2746
|
+
},
|
|
2747
|
+
...response.service_tier != null && {
|
|
2748
|
+
serviceTier: response.service_tier
|
|
2749
|
+
}
|
|
2722
2750
|
}
|
|
2723
2751
|
}
|
|
2724
2752
|
},
|
|
@@ -2765,6 +2793,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2765
2793
|
let hasFunctionCall = false;
|
|
2766
2794
|
let usage = void 0;
|
|
2767
2795
|
let costInUsdTicks = void 0;
|
|
2796
|
+
let serviceTier = void 0;
|
|
2768
2797
|
let isFirstChunk = true;
|
|
2769
2798
|
const contentBlocks = {};
|
|
2770
2799
|
const seenToolCalls = /* @__PURE__ */ new Set();
|
|
@@ -2778,7 +2807,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2778
2807
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2779
2808
|
},
|
|
2780
2809
|
transform(chunk, controller) {
|
|
2781
|
-
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2810
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2782
2811
|
if (options.includeRawChunks) {
|
|
2783
2812
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2784
2813
|
}
|
|
@@ -2909,8 +2938,9 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2909
2938
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2910
2939
|
costInUsdTicks = (_c2 = response2.usage.cost_in_usd_ticks) != null ? _c2 : void 0;
|
|
2911
2940
|
}
|
|
2941
|
+
serviceTier = (_d = response2.service_tier) != null ? _d : void 0;
|
|
2912
2942
|
if (event.type === "response.incomplete") {
|
|
2913
|
-
const reason = "incomplete_details" in response2 ? (
|
|
2943
|
+
const reason = "incomplete_details" in response2 ? (_e = response2.incomplete_details) == null ? void 0 : _e.reason : void 0;
|
|
2914
2944
|
finishReason = {
|
|
2915
2945
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2916
2946
|
raw: reason != null ? reason : "incomplete"
|
|
@@ -2924,7 +2954,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2924
2954
|
return;
|
|
2925
2955
|
}
|
|
2926
2956
|
if (event.type === "response.failed") {
|
|
2927
|
-
const reason = (
|
|
2957
|
+
const reason = (_f = event.response.incomplete_details) == null ? void 0 : _f.reason;
|
|
2928
2958
|
finishReason = {
|
|
2929
2959
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2930
2960
|
raw: reason != null ? reason : "error"
|
|
@@ -3048,13 +3078,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3048
3078
|
toolCallId: part.id,
|
|
3049
3079
|
toolName,
|
|
3050
3080
|
result: {
|
|
3051
|
-
queries: (
|
|
3052
|
-
results: (
|
|
3081
|
+
queries: (_g = part.queries) != null ? _g : [],
|
|
3082
|
+
results: (_i = (_h = part.results) == null ? void 0 : _h.map((result) => ({
|
|
3053
3083
|
fileId: result.file_id,
|
|
3054
3084
|
filename: result.filename,
|
|
3055
3085
|
score: result.score,
|
|
3056
3086
|
text: result.text
|
|
3057
|
-
}))) != null ?
|
|
3087
|
+
}))) != null ? _i : null
|
|
3058
3088
|
}
|
|
3059
3089
|
});
|
|
3060
3090
|
}
|
|
@@ -3121,17 +3151,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3121
3151
|
"x_semantic_search",
|
|
3122
3152
|
"x_thread_fetch"
|
|
3123
3153
|
];
|
|
3124
|
-
let toolName = (
|
|
3125
|
-
if (webSearchSubTools.includes((
|
|
3154
|
+
let toolName = (_j = part.name) != null ? _j : "";
|
|
3155
|
+
if (webSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "web_search_call") {
|
|
3126
3156
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
3127
|
-
} else if (xSearchSubTools.includes((
|
|
3157
|
+
} else if (xSearchSubTools.includes((_l = part.name) != null ? _l : "") || part.type === "x_search_call") {
|
|
3128
3158
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
3129
3159
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
3130
3160
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
3131
3161
|
} else if (part.type === "mcp_call") {
|
|
3132
|
-
toolName = (
|
|
3162
|
+
toolName = (_m = mcpToolName != null ? mcpToolName : part.name) != null ? _m : "mcp";
|
|
3133
3163
|
}
|
|
3134
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
3164
|
+
const toolInput = part.type === "custom_tool_call" ? (_n = part.input) != null ? _n : "" : part.type === "mcp_call" ? (_o = part.arguments) != null ? _o : "" : (_p = part.arguments) != null ? _p : "";
|
|
3135
3165
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
3136
3166
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
3137
3167
|
seenToolCalls.add(part.id);
|
|
@@ -3192,7 +3222,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3192
3222
|
sourceType: "url",
|
|
3193
3223
|
id: self.config.generateId(),
|
|
3194
3224
|
url: annotation.url,
|
|
3195
|
-
title: (
|
|
3225
|
+
title: (_q = annotation.title) != null ? _q : annotation.url
|
|
3196
3226
|
});
|
|
3197
3227
|
}
|
|
3198
3228
|
}
|
|
@@ -3247,10 +3277,11 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3247
3277
|
},
|
|
3248
3278
|
outputTokens: { total: 0, text: 0, reasoning: 0 }
|
|
3249
3279
|
},
|
|
3250
|
-
...costInUsdTicks != null && {
|
|
3280
|
+
...(costInUsdTicks != null || serviceTier != null) && {
|
|
3251
3281
|
providerMetadata: {
|
|
3252
3282
|
xai: {
|
|
3253
|
-
costInUsdTicks
|
|
3283
|
+
...costInUsdTicks != null && { costInUsdTicks },
|
|
3284
|
+
...serviceTier != null && { serviceTier }
|
|
3254
3285
|
}
|
|
3255
3286
|
}
|
|
3256
3287
|
}
|
|
@@ -3689,7 +3720,7 @@ var xaiTools = {
|
|
|
3689
3720
|
};
|
|
3690
3721
|
|
|
3691
3722
|
// src/version.ts
|
|
3692
|
-
var VERSION = true ? "4.0.
|
|
3723
|
+
var VERSION = true ? "4.0.38" : "0.0.0-test";
|
|
3693
3724
|
|
|
3694
3725
|
// src/files/xai-files.ts
|
|
3695
3726
|
import {
|