@ai-sdk/xai 3.0.80 → 3.0.81
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.js +49 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/responses/map-xai-responses-finish-reason.ts +1 -0
- package/src/responses/xai-responses-api.ts +20 -0
- package/src/responses/xai-responses-language-model.ts +28 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1229,6 +1229,7 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1229
1229
|
case "completed":
|
|
1230
1230
|
return "stop";
|
|
1231
1231
|
case "length":
|
|
1232
|
+
case "max_output_tokens":
|
|
1232
1233
|
return "length";
|
|
1233
1234
|
case "tool_calls":
|
|
1234
1235
|
case "function_call":
|
|
@@ -1633,6 +1634,24 @@ var xaiResponsesChunkSchema = import_v46.z.union([
|
|
|
1633
1634
|
output_index: import_v46.z.number(),
|
|
1634
1635
|
output: import_v46.z.string().optional()
|
|
1635
1636
|
}),
|
|
1637
|
+
import_v46.z.object({
|
|
1638
|
+
type: import_v46.z.literal("response.incomplete"),
|
|
1639
|
+
response: import_v46.z.object({
|
|
1640
|
+
incomplete_details: import_v46.z.object({ reason: import_v46.z.string() }).nullish(),
|
|
1641
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1642
|
+
})
|
|
1643
|
+
}),
|
|
1644
|
+
import_v46.z.object({
|
|
1645
|
+
type: import_v46.z.literal("response.failed"),
|
|
1646
|
+
response: import_v46.z.object({
|
|
1647
|
+
error: import_v46.z.object({
|
|
1648
|
+
code: import_v46.z.string().nullish(),
|
|
1649
|
+
message: import_v46.z.string()
|
|
1650
|
+
}).nullish(),
|
|
1651
|
+
incomplete_details: import_v46.z.object({ reason: import_v46.z.string() }).nullish(),
|
|
1652
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1653
|
+
})
|
|
1654
|
+
}),
|
|
1636
1655
|
import_v46.z.object({
|
|
1637
1656
|
type: import_v46.z.literal("response.done"),
|
|
1638
1657
|
response: xaiResponsesResponseSchema
|
|
@@ -2294,7 +2313,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2294
2313
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2295
2314
|
},
|
|
2296
2315
|
transform(chunk, controller) {
|
|
2297
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2316
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2298
2317
|
if (options.includeRawChunks) {
|
|
2299
2318
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2300
2319
|
}
|
|
@@ -2417,12 +2436,18 @@ var XaiResponsesLanguageModel = class {
|
|
|
2417
2436
|
}
|
|
2418
2437
|
return;
|
|
2419
2438
|
}
|
|
2420
|
-
if (event.type === "response.done" || event.type === "response.completed") {
|
|
2439
|
+
if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
|
|
2421
2440
|
const response2 = event.response;
|
|
2422
2441
|
if (response2.usage) {
|
|
2423
2442
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2424
2443
|
}
|
|
2425
|
-
if (
|
|
2444
|
+
if (event.type === "response.incomplete") {
|
|
2445
|
+
const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
|
|
2446
|
+
finishReason = {
|
|
2447
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2448
|
+
raw: reason != null ? reason : "incomplete"
|
|
2449
|
+
};
|
|
2450
|
+
} else if ("status" in response2 && response2.status) {
|
|
2426
2451
|
finishReason = {
|
|
2427
2452
|
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
|
|
2428
2453
|
raw: response2.status
|
|
@@ -2430,6 +2455,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2430
2455
|
}
|
|
2431
2456
|
return;
|
|
2432
2457
|
}
|
|
2458
|
+
if (event.type === "response.failed") {
|
|
2459
|
+
const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
|
|
2460
|
+
finishReason = {
|
|
2461
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2462
|
+
raw: reason != null ? reason : "error"
|
|
2463
|
+
};
|
|
2464
|
+
if (event.response.usage) {
|
|
2465
|
+
usage = convertXaiResponsesUsage(event.response.usage);
|
|
2466
|
+
}
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2433
2469
|
if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
|
|
2434
2470
|
return;
|
|
2435
2471
|
}
|
|
@@ -2512,13 +2548,13 @@ var XaiResponsesLanguageModel = class {
|
|
|
2512
2548
|
toolCallId: part.id,
|
|
2513
2549
|
toolName,
|
|
2514
2550
|
result: {
|
|
2515
|
-
queries: (
|
|
2516
|
-
results: (
|
|
2551
|
+
queries: (_e = part.queries) != null ? _e : [],
|
|
2552
|
+
results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
|
|
2517
2553
|
fileId: result.file_id,
|
|
2518
2554
|
filename: result.filename,
|
|
2519
2555
|
score: result.score,
|
|
2520
2556
|
text: result.text
|
|
2521
|
-
}))) != null ?
|
|
2557
|
+
}))) != null ? _g : null
|
|
2522
2558
|
}
|
|
2523
2559
|
});
|
|
2524
2560
|
}
|
|
@@ -2536,17 +2572,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2536
2572
|
"x_semantic_search",
|
|
2537
2573
|
"x_thread_fetch"
|
|
2538
2574
|
];
|
|
2539
|
-
let toolName = (
|
|
2540
|
-
if (webSearchSubTools.includes((
|
|
2575
|
+
let toolName = (_h = part.name) != null ? _h : "";
|
|
2576
|
+
if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
|
|
2541
2577
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2542
|
-
} else if (xSearchSubTools.includes((
|
|
2578
|
+
} else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
|
|
2543
2579
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2544
2580
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2545
2581
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2546
2582
|
} else if (part.type === "mcp_call") {
|
|
2547
|
-
toolName = (
|
|
2583
|
+
toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
|
|
2548
2584
|
}
|
|
2549
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2585
|
+
const toolInput = part.type === "custom_tool_call" ? (_l = part.input) != null ? _l : "" : part.type === "mcp_call" ? (_m = part.arguments) != null ? _m : "" : (_n = part.arguments) != null ? _n : "";
|
|
2550
2586
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2551
2587
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2552
2588
|
seenToolCalls.add(part.id);
|
|
@@ -2599,7 +2635,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2599
2635
|
sourceType: "url",
|
|
2600
2636
|
id: self.config.generateId(),
|
|
2601
2637
|
url: annotation.url,
|
|
2602
|
-
title: (
|
|
2638
|
+
title: (_o = annotation.title) != null ? _o : annotation.url
|
|
2603
2639
|
});
|
|
2604
2640
|
}
|
|
2605
2641
|
}
|
|
@@ -2719,7 +2755,7 @@ var xaiTools = {
|
|
|
2719
2755
|
};
|
|
2720
2756
|
|
|
2721
2757
|
// src/version.ts
|
|
2722
|
-
var VERSION = true ? "3.0.
|
|
2758
|
+
var VERSION = true ? "3.0.81" : "0.0.0-test";
|
|
2723
2759
|
|
|
2724
2760
|
// src/xai-video-model.ts
|
|
2725
2761
|
var import_provider6 = require("@ai-sdk/provider");
|