@ai-sdk/xai 4.0.0-beta.35 → 4.0.0-beta.36
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 +18 -0
- package/dist/index.js +69 -33
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/responses/xai-responses-language-model.ts +20 -3
- package/src/xai-chat-language-model.ts +20 -3
- package/src/xai-image-model.ts +19 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.36
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b3976a2: Add workflow serialization support to all provider models.
|
|
8
|
+
|
|
9
|
+
**`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
|
|
10
|
+
|
|
11
|
+
**All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
|
|
12
|
+
|
|
13
|
+
All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [b3976a2]
|
|
16
|
+
- Updated dependencies [ff5eba1]
|
|
17
|
+
- @ai-sdk/provider-utils@5.0.0-beta.20
|
|
18
|
+
- @ai-sdk/openai-compatible@3.0.0-beta.25
|
|
19
|
+
- @ai-sdk/provider@4.0.0-beta.12
|
|
20
|
+
|
|
3
21
|
## 4.0.0-beta.35
|
|
4
22
|
|
|
5
23
|
### Major Changes
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,10 @@ import {
|
|
|
22
22
|
mapReasoningToProviderEffort,
|
|
23
23
|
parseProviderOptions,
|
|
24
24
|
postJsonToApi,
|
|
25
|
-
safeParseJSON
|
|
25
|
+
safeParseJSON,
|
|
26
|
+
serializeModelOptions,
|
|
27
|
+
WORKFLOW_SERIALIZE,
|
|
28
|
+
WORKFLOW_DESERIALIZE
|
|
26
29
|
} from "@ai-sdk/provider-utils";
|
|
27
30
|
import { z as z3 } from "zod/v4";
|
|
28
31
|
|
|
@@ -371,7 +374,7 @@ function prepareTools({
|
|
|
371
374
|
}
|
|
372
375
|
|
|
373
376
|
// src/xai-chat-language-model.ts
|
|
374
|
-
var XaiChatLanguageModel = class {
|
|
377
|
+
var XaiChatLanguageModel = class _XaiChatLanguageModel {
|
|
375
378
|
constructor(modelId, config) {
|
|
376
379
|
this.specificationVersion = "v4";
|
|
377
380
|
this.supportedUrls = {
|
|
@@ -380,6 +383,15 @@ var XaiChatLanguageModel = class {
|
|
|
380
383
|
this.modelId = modelId;
|
|
381
384
|
this.config = config;
|
|
382
385
|
}
|
|
386
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
387
|
+
return serializeModelOptions({
|
|
388
|
+
modelId: model.modelId,
|
|
389
|
+
config: model.config
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
393
|
+
return new _XaiChatLanguageModel(options.modelId, options.config);
|
|
394
|
+
}
|
|
383
395
|
get provider() {
|
|
384
396
|
return this.config.provider;
|
|
385
397
|
}
|
|
@@ -507,7 +519,7 @@ var XaiChatLanguageModel = class {
|
|
|
507
519
|
};
|
|
508
520
|
}
|
|
509
521
|
async doGenerate(options) {
|
|
510
|
-
var _a, _b;
|
|
522
|
+
var _a, _b, _c, _d;
|
|
511
523
|
const { args: body, warnings } = await this.getArgs(options);
|
|
512
524
|
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
513
525
|
const {
|
|
@@ -516,7 +528,7 @@ var XaiChatLanguageModel = class {
|
|
|
516
528
|
rawValue: rawResponse
|
|
517
529
|
} = await postJsonToApi({
|
|
518
530
|
url,
|
|
519
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
531
|
+
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
520
532
|
body,
|
|
521
533
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
522
534
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -578,7 +590,7 @@ var XaiChatLanguageModel = class {
|
|
|
578
590
|
content,
|
|
579
591
|
finishReason: {
|
|
580
592
|
unified: mapXaiFinishReason(choice.finish_reason),
|
|
581
|
-
raw: (
|
|
593
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
582
594
|
},
|
|
583
595
|
usage: response.usage ? convertXaiChatUsage(response.usage) : {
|
|
584
596
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -594,7 +606,7 @@ var XaiChatLanguageModel = class {
|
|
|
594
606
|
};
|
|
595
607
|
}
|
|
596
608
|
async doStream(options) {
|
|
597
|
-
var _a;
|
|
609
|
+
var _a, _b, _c;
|
|
598
610
|
const { args, warnings } = await this.getArgs(options);
|
|
599
611
|
const body = {
|
|
600
612
|
...args,
|
|
@@ -606,7 +618,7 @@ var XaiChatLanguageModel = class {
|
|
|
606
618
|
const url = `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/chat/completions`;
|
|
607
619
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
608
620
|
url,
|
|
609
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
621
|
+
headers: combineHeaders((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
610
622
|
body,
|
|
611
623
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
612
624
|
successfulResponseHandler: async ({ response: response2 }) => {
|
|
@@ -906,7 +918,10 @@ import {
|
|
|
906
918
|
createStatusCodeErrorResponseHandler,
|
|
907
919
|
getFromApi,
|
|
908
920
|
parseProviderOptions as parseProviderOptions2,
|
|
909
|
-
postJsonToApi as postJsonToApi2
|
|
921
|
+
postJsonToApi as postJsonToApi2,
|
|
922
|
+
serializeModelOptions as serializeModelOptions2,
|
|
923
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
924
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
910
925
|
} from "@ai-sdk/provider-utils";
|
|
911
926
|
import { z as z5 } from "zod/v4";
|
|
912
927
|
|
|
@@ -922,7 +937,7 @@ var xaiImageModelOptions = z4.object({
|
|
|
922
937
|
});
|
|
923
938
|
|
|
924
939
|
// src/xai-image-model.ts
|
|
925
|
-
var XaiImageModel = class {
|
|
940
|
+
var XaiImageModel = class _XaiImageModel {
|
|
926
941
|
constructor(modelId, config) {
|
|
927
942
|
this.modelId = modelId;
|
|
928
943
|
this.config = config;
|
|
@@ -932,6 +947,15 @@ var XaiImageModel = class {
|
|
|
932
947
|
get provider() {
|
|
933
948
|
return this.config.provider;
|
|
934
949
|
}
|
|
950
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
951
|
+
return serializeModelOptions2({
|
|
952
|
+
modelId: model.modelId,
|
|
953
|
+
config: model.config
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
957
|
+
return new _XaiImageModel(options.modelId, options.config);
|
|
958
|
+
}
|
|
935
959
|
async doGenerate({
|
|
936
960
|
prompt,
|
|
937
961
|
n,
|
|
@@ -944,7 +968,7 @@ var XaiImageModel = class {
|
|
|
944
968
|
files,
|
|
945
969
|
mask
|
|
946
970
|
}) {
|
|
947
|
-
var _a, _b, _c, _d, _e;
|
|
971
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
948
972
|
const warnings = [];
|
|
949
973
|
if (size != null) {
|
|
950
974
|
warnings.push({
|
|
@@ -1009,7 +1033,7 @@ var XaiImageModel = class {
|
|
|
1009
1033
|
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
1010
1034
|
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
1011
1035
|
url: `${baseURL}${endpoint}`,
|
|
1012
|
-
headers: combineHeaders2(this.config.headers(), headers),
|
|
1036
|
+
headers: combineHeaders2((_f = (_e = this.config).headers) == null ? void 0 : _f.call(_e), headers),
|
|
1013
1037
|
body,
|
|
1014
1038
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1015
1039
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
@@ -1037,7 +1061,7 @@ var XaiImageModel = class {
|
|
|
1037
1061
|
images: response.data.map((item) => ({
|
|
1038
1062
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {}
|
|
1039
1063
|
})),
|
|
1040
|
-
...((
|
|
1064
|
+
...((_g = response.usage) == null ? void 0 : _g.cost_in_usd_ticks) != null ? { costInUsdTicks: response.usage.cost_in_usd_ticks } : {}
|
|
1041
1065
|
}
|
|
1042
1066
|
}
|
|
1043
1067
|
};
|
|
@@ -1074,7 +1098,10 @@ import {
|
|
|
1074
1098
|
isCustomReasoning as isCustomReasoning2,
|
|
1075
1099
|
mapReasoningToProviderEffort as mapReasoningToProviderEffort2,
|
|
1076
1100
|
parseProviderOptions as parseProviderOptions3,
|
|
1077
|
-
postJsonToApi as postJsonToApi3
|
|
1101
|
+
postJsonToApi as postJsonToApi3,
|
|
1102
|
+
serializeModelOptions as serializeModelOptions3,
|
|
1103
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
|
|
1104
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3
|
|
1078
1105
|
} from "@ai-sdk/provider-utils";
|
|
1079
1106
|
|
|
1080
1107
|
// src/responses/convert-to-xai-responses-input.ts
|
|
@@ -2050,7 +2077,7 @@ async function prepareResponsesTools({
|
|
|
2050
2077
|
}
|
|
2051
2078
|
|
|
2052
2079
|
// src/responses/xai-responses-language-model.ts
|
|
2053
|
-
var XaiResponsesLanguageModel = class {
|
|
2080
|
+
var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
2054
2081
|
constructor(modelId, config) {
|
|
2055
2082
|
this.specificationVersion = "v4";
|
|
2056
2083
|
this.supportedUrls = {
|
|
@@ -2059,6 +2086,15 @@ var XaiResponsesLanguageModel = class {
|
|
|
2059
2086
|
this.modelId = modelId;
|
|
2060
2087
|
this.config = config;
|
|
2061
2088
|
}
|
|
2089
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
2090
|
+
return serializeModelOptions3({
|
|
2091
|
+
modelId: model.modelId,
|
|
2092
|
+
config: model.config
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
2096
|
+
return new _XaiResponsesLanguageModel(options.modelId, options.config);
|
|
2097
|
+
}
|
|
2062
2098
|
get provider() {
|
|
2063
2099
|
return this.config.provider;
|
|
2064
2100
|
}
|
|
@@ -2190,7 +2226,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2190
2226
|
};
|
|
2191
2227
|
}
|
|
2192
2228
|
async doGenerate(options) {
|
|
2193
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2229
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2194
2230
|
const {
|
|
2195
2231
|
args: body,
|
|
2196
2232
|
warnings,
|
|
@@ -2206,7 +2242,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2206
2242
|
rawValue: rawResponse
|
|
2207
2243
|
} = await postJsonToApi3({
|
|
2208
2244
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2209
|
-
headers: combineHeaders3(this.config.headers(), options.headers),
|
|
2245
|
+
headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2210
2246
|
body,
|
|
2211
2247
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2212
2248
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
@@ -2243,29 +2279,29 @@ var XaiResponsesLanguageModel = class {
|
|
|
2243
2279
|
toolCallId: part.id,
|
|
2244
2280
|
toolName,
|
|
2245
2281
|
result: {
|
|
2246
|
-
queries: (
|
|
2247
|
-
results: (
|
|
2282
|
+
queries: (_d = part.queries) != null ? _d : [],
|
|
2283
|
+
results: (_f = (_e = part.results) == null ? void 0 : _e.map((result) => ({
|
|
2248
2284
|
fileId: result.file_id,
|
|
2249
2285
|
filename: result.filename,
|
|
2250
2286
|
score: result.score,
|
|
2251
2287
|
text: result.text
|
|
2252
|
-
}))) != null ?
|
|
2288
|
+
}))) != null ? _f : null
|
|
2253
2289
|
}
|
|
2254
2290
|
});
|
|
2255
2291
|
continue;
|
|
2256
2292
|
}
|
|
2257
2293
|
if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call" || part.type === "mcp_call") {
|
|
2258
|
-
let toolName = (
|
|
2259
|
-
if (webSearchSubTools.includes((
|
|
2294
|
+
let toolName = (_g = part.name) != null ? _g : "";
|
|
2295
|
+
if (webSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "web_search_call") {
|
|
2260
2296
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2261
|
-
} else if (xSearchSubTools.includes((
|
|
2297
|
+
} else if (xSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "x_search_call") {
|
|
2262
2298
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2263
2299
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2264
2300
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2265
2301
|
} else if (part.type === "mcp_call") {
|
|
2266
|
-
toolName = (
|
|
2302
|
+
toolName = (_j = mcpToolName != null ? mcpToolName : part.name) != null ? _j : "mcp";
|
|
2267
2303
|
}
|
|
2268
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2304
|
+
const toolInput = part.type === "custom_tool_call" ? (_k = part.input) != null ? _k : "" : part.type === "mcp_call" ? (_l = part.arguments) != null ? _l : "" : (_m = part.arguments) != null ? _m : "";
|
|
2269
2305
|
content.push({
|
|
2270
2306
|
type: "tool-call",
|
|
2271
2307
|
toolCallId: part.id,
|
|
@@ -2292,7 +2328,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2292
2328
|
sourceType: "url",
|
|
2293
2329
|
id: this.config.generateId(),
|
|
2294
2330
|
url: annotation.url,
|
|
2295
|
-
title: (
|
|
2331
|
+
title: (_n = annotation.title) != null ? _n : annotation.url
|
|
2296
2332
|
});
|
|
2297
2333
|
}
|
|
2298
2334
|
}
|
|
@@ -2311,7 +2347,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2311
2347
|
break;
|
|
2312
2348
|
}
|
|
2313
2349
|
case "reasoning": {
|
|
2314
|
-
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((
|
|
2350
|
+
const texts = part.summary.length > 0 ? part.summary.map((s) => s.text) : ((_o = part.content) != null ? _o : []).map((c) => c.text);
|
|
2315
2351
|
const reasoningText = texts.filter((text) => text && text.length > 0).join("");
|
|
2316
2352
|
if (reasoningText) {
|
|
2317
2353
|
if (part.encrypted_content || part.id) {
|
|
@@ -2345,7 +2381,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2345
2381
|
content,
|
|
2346
2382
|
finishReason: {
|
|
2347
2383
|
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response.status),
|
|
2348
|
-
raw: (
|
|
2384
|
+
raw: (_p = response.status) != null ? _p : void 0
|
|
2349
2385
|
},
|
|
2350
2386
|
usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
|
|
2351
2387
|
inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -2361,7 +2397,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2361
2397
|
};
|
|
2362
2398
|
}
|
|
2363
2399
|
async doStream(options) {
|
|
2364
|
-
var _a;
|
|
2400
|
+
var _a, _b, _c;
|
|
2365
2401
|
const {
|
|
2366
2402
|
args,
|
|
2367
2403
|
warnings,
|
|
@@ -2377,7 +2413,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2377
2413
|
};
|
|
2378
2414
|
const { responseHeaders, value: response } = await postJsonToApi3({
|
|
2379
2415
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
2380
|
-
headers: combineHeaders3(this.config.headers(), options.headers),
|
|
2416
|
+
headers: combineHeaders3((_c = (_b = this.config).headers) == null ? void 0 : _c.call(_b), options.headers),
|
|
2381
2417
|
body,
|
|
2382
2418
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
2383
2419
|
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
@@ -2405,7 +2441,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2405
2441
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2406
2442
|
},
|
|
2407
2443
|
transform(chunk, controller) {
|
|
2408
|
-
var _a2,
|
|
2444
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2409
2445
|
if (options.includeRawChunks) {
|
|
2410
2446
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2411
2447
|
}
|
|
@@ -2523,7 +2559,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2523
2559
|
sourceType: "url",
|
|
2524
2560
|
id: self.config.generateId(),
|
|
2525
2561
|
url: annotation.url,
|
|
2526
|
-
title: (
|
|
2562
|
+
title: (_b2 = annotation.title) != null ? _b2 : annotation.url
|
|
2527
2563
|
});
|
|
2528
2564
|
}
|
|
2529
2565
|
return;
|
|
@@ -2534,7 +2570,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2534
2570
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2535
2571
|
}
|
|
2536
2572
|
if (event.type === "response.incomplete") {
|
|
2537
|
-
const reason = "incomplete_details" in response2 ? (
|
|
2573
|
+
const reason = "incomplete_details" in response2 ? (_c2 = response2.incomplete_details) == null ? void 0 : _c2.reason : void 0;
|
|
2538
2574
|
finishReason = {
|
|
2539
2575
|
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2540
2576
|
raw: reason != null ? reason : "incomplete"
|
|
@@ -2851,7 +2887,7 @@ var xaiTools = {
|
|
|
2851
2887
|
};
|
|
2852
2888
|
|
|
2853
2889
|
// src/version.ts
|
|
2854
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2890
|
+
var VERSION = true ? "4.0.0-beta.36" : "0.0.0-test";
|
|
2855
2891
|
|
|
2856
2892
|
// src/files/xai-files.ts
|
|
2857
2893
|
import {
|