@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/dist/index.mjs
CHANGED
|
@@ -1232,6 +1232,7 @@ function mapXaiResponsesFinishReason(finishReason) {
|
|
|
1232
1232
|
case "completed":
|
|
1233
1233
|
return "stop";
|
|
1234
1234
|
case "length":
|
|
1235
|
+
case "max_output_tokens":
|
|
1235
1236
|
return "length";
|
|
1236
1237
|
case "tool_calls":
|
|
1237
1238
|
case "function_call":
|
|
@@ -1636,6 +1637,24 @@ var xaiResponsesChunkSchema = z6.union([
|
|
|
1636
1637
|
output_index: z6.number(),
|
|
1637
1638
|
output: z6.string().optional()
|
|
1638
1639
|
}),
|
|
1640
|
+
z6.object({
|
|
1641
|
+
type: z6.literal("response.incomplete"),
|
|
1642
|
+
response: z6.object({
|
|
1643
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1644
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1645
|
+
})
|
|
1646
|
+
}),
|
|
1647
|
+
z6.object({
|
|
1648
|
+
type: z6.literal("response.failed"),
|
|
1649
|
+
response: z6.object({
|
|
1650
|
+
error: z6.object({
|
|
1651
|
+
code: z6.string().nullish(),
|
|
1652
|
+
message: z6.string()
|
|
1653
|
+
}).nullish(),
|
|
1654
|
+
incomplete_details: z6.object({ reason: z6.string() }).nullish(),
|
|
1655
|
+
usage: xaiResponsesUsageSchema.nullish()
|
|
1656
|
+
})
|
|
1657
|
+
}),
|
|
1639
1658
|
z6.object({
|
|
1640
1659
|
type: z6.literal("response.done"),
|
|
1641
1660
|
response: xaiResponsesResponseSchema
|
|
@@ -2315,7 +2334,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2315
2334
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2316
2335
|
},
|
|
2317
2336
|
transform(chunk, controller) {
|
|
2318
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2337
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2319
2338
|
if (options.includeRawChunks) {
|
|
2320
2339
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2321
2340
|
}
|
|
@@ -2438,12 +2457,18 @@ var XaiResponsesLanguageModel = class {
|
|
|
2438
2457
|
}
|
|
2439
2458
|
return;
|
|
2440
2459
|
}
|
|
2441
|
-
if (event.type === "response.done" || event.type === "response.completed") {
|
|
2460
|
+
if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
|
|
2442
2461
|
const response2 = event.response;
|
|
2443
2462
|
if (response2.usage) {
|
|
2444
2463
|
usage = convertXaiResponsesUsage(response2.usage);
|
|
2445
2464
|
}
|
|
2446
|
-
if (
|
|
2465
|
+
if (event.type === "response.incomplete") {
|
|
2466
|
+
const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
|
|
2467
|
+
finishReason = {
|
|
2468
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
|
|
2469
|
+
raw: reason != null ? reason : "incomplete"
|
|
2470
|
+
};
|
|
2471
|
+
} else if ("status" in response2 && response2.status) {
|
|
2447
2472
|
finishReason = {
|
|
2448
2473
|
unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
|
|
2449
2474
|
raw: response2.status
|
|
@@ -2451,6 +2476,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2451
2476
|
}
|
|
2452
2477
|
return;
|
|
2453
2478
|
}
|
|
2479
|
+
if (event.type === "response.failed") {
|
|
2480
|
+
const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
|
|
2481
|
+
finishReason = {
|
|
2482
|
+
unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
|
|
2483
|
+
raw: reason != null ? reason : "error"
|
|
2484
|
+
};
|
|
2485
|
+
if (event.response.usage) {
|
|
2486
|
+
usage = convertXaiResponsesUsage(event.response.usage);
|
|
2487
|
+
}
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2454
2490
|
if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
|
|
2455
2491
|
return;
|
|
2456
2492
|
}
|
|
@@ -2533,13 +2569,13 @@ var XaiResponsesLanguageModel = class {
|
|
|
2533
2569
|
toolCallId: part.id,
|
|
2534
2570
|
toolName,
|
|
2535
2571
|
result: {
|
|
2536
|
-
queries: (
|
|
2537
|
-
results: (
|
|
2572
|
+
queries: (_e = part.queries) != null ? _e : [],
|
|
2573
|
+
results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
|
|
2538
2574
|
fileId: result.file_id,
|
|
2539
2575
|
filename: result.filename,
|
|
2540
2576
|
score: result.score,
|
|
2541
2577
|
text: result.text
|
|
2542
|
-
}))) != null ?
|
|
2578
|
+
}))) != null ? _g : null
|
|
2543
2579
|
}
|
|
2544
2580
|
});
|
|
2545
2581
|
}
|
|
@@ -2557,17 +2593,17 @@ var XaiResponsesLanguageModel = class {
|
|
|
2557
2593
|
"x_semantic_search",
|
|
2558
2594
|
"x_thread_fetch"
|
|
2559
2595
|
];
|
|
2560
|
-
let toolName = (
|
|
2561
|
-
if (webSearchSubTools.includes((
|
|
2596
|
+
let toolName = (_h = part.name) != null ? _h : "";
|
|
2597
|
+
if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
|
|
2562
2598
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
2563
|
-
} else if (xSearchSubTools.includes((
|
|
2599
|
+
} else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
|
|
2564
2600
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2565
2601
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2566
2602
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2567
2603
|
} else if (part.type === "mcp_call") {
|
|
2568
|
-
toolName = (
|
|
2604
|
+
toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
|
|
2569
2605
|
}
|
|
2570
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2606
|
+
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 : "";
|
|
2571
2607
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2572
2608
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2573
2609
|
seenToolCalls.add(part.id);
|
|
@@ -2620,7 +2656,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2620
2656
|
sourceType: "url",
|
|
2621
2657
|
id: self.config.generateId(),
|
|
2622
2658
|
url: annotation.url,
|
|
2623
|
-
title: (
|
|
2659
|
+
title: (_o = annotation.title) != null ? _o : annotation.url
|
|
2624
2660
|
});
|
|
2625
2661
|
}
|
|
2626
2662
|
}
|
|
@@ -2740,7 +2776,7 @@ var xaiTools = {
|
|
|
2740
2776
|
};
|
|
2741
2777
|
|
|
2742
2778
|
// src/version.ts
|
|
2743
|
-
var VERSION = true ? "3.0.
|
|
2779
|
+
var VERSION = true ? "3.0.81" : "0.0.0-test";
|
|
2744
2780
|
|
|
2745
2781
|
// src/xai-video-model.ts
|
|
2746
2782
|
import {
|