@ai-sdk/xai 3.0.80 → 3.0.82

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.82
4
+
5
+ ### Patch Changes
6
+
7
+ - 72ebb54: fix (provider/xai): handle mid-stream error chunks
8
+
9
+ ## 3.0.81
10
+
11
+ ### Patch Changes
12
+
13
+ - c1cc97f: fix (provider/xai): add response.incomplete and response.failed streaming event handling
14
+
3
15
  ## 3.0.80
4
16
 
5
17
  ### Patch Changes
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,30 @@ 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
+ }),
1655
+ import_v46.z.object({
1656
+ type: import_v46.z.literal("error"),
1657
+ code: import_v46.z.string().nullish(),
1658
+ message: import_v46.z.string(),
1659
+ param: import_v46.z.string().nullish()
1660
+ }),
1636
1661
  import_v46.z.object({
1637
1662
  type: import_v46.z.literal("response.done"),
1638
1663
  response: xaiResponsesResponseSchema
@@ -2294,7 +2319,7 @@ var XaiResponsesLanguageModel = class {
2294
2319
  controller.enqueue({ type: "stream-start", warnings });
2295
2320
  },
2296
2321
  transform(chunk, controller) {
2297
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2322
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2298
2323
  if (options.includeRawChunks) {
2299
2324
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2300
2325
  }
@@ -2417,12 +2442,18 @@ var XaiResponsesLanguageModel = class {
2417
2442
  }
2418
2443
  return;
2419
2444
  }
2420
- if (event.type === "response.done" || event.type === "response.completed") {
2445
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2421
2446
  const response2 = event.response;
2422
2447
  if (response2.usage) {
2423
2448
  usage = convertXaiResponsesUsage(response2.usage);
2424
2449
  }
2425
- if (response2.status) {
2450
+ if (event.type === "response.incomplete") {
2451
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2452
+ finishReason = {
2453
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2454
+ raw: reason != null ? reason : "incomplete"
2455
+ };
2456
+ } else if ("status" in response2 && response2.status) {
2426
2457
  finishReason = {
2427
2458
  unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
2428
2459
  raw: response2.status
@@ -2430,6 +2461,21 @@ var XaiResponsesLanguageModel = class {
2430
2461
  }
2431
2462
  return;
2432
2463
  }
2464
+ if (event.type === "response.failed") {
2465
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2466
+ finishReason = {
2467
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2468
+ raw: reason != null ? reason : "error"
2469
+ };
2470
+ if (event.response.usage) {
2471
+ usage = convertXaiResponsesUsage(event.response.usage);
2472
+ }
2473
+ return;
2474
+ }
2475
+ if (event.type === "error") {
2476
+ controller.enqueue({ type: "error", error: event });
2477
+ return;
2478
+ }
2433
2479
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2434
2480
  return;
2435
2481
  }
@@ -2512,13 +2558,13 @@ var XaiResponsesLanguageModel = class {
2512
2558
  toolCallId: part.id,
2513
2559
  toolName,
2514
2560
  result: {
2515
- queries: (_c = part.queries) != null ? _c : [],
2516
- results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2561
+ queries: (_e = part.queries) != null ? _e : [],
2562
+ results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2517
2563
  fileId: result.file_id,
2518
2564
  filename: result.filename,
2519
2565
  score: result.score,
2520
2566
  text: result.text
2521
- }))) != null ? _e : null
2567
+ }))) != null ? _g : null
2522
2568
  }
2523
2569
  });
2524
2570
  }
@@ -2536,17 +2582,17 @@ var XaiResponsesLanguageModel = class {
2536
2582
  "x_semantic_search",
2537
2583
  "x_thread_fetch"
2538
2584
  ];
2539
- let toolName = (_f = part.name) != null ? _f : "";
2540
- if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2585
+ let toolName = (_h = part.name) != null ? _h : "";
2586
+ if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2541
2587
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2542
- } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2588
+ } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2543
2589
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2544
2590
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2545
2591
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2546
2592
  } else if (part.type === "mcp_call") {
2547
- toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2593
+ toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2548
2594
  }
2549
- const toolInput = part.type === "custom_tool_call" ? (_j = part.input) != null ? _j : "" : part.type === "mcp_call" ? (_k = part.arguments) != null ? _k : "" : (_l = part.arguments) != null ? _l : "";
2595
+ 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
2596
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2551
2597
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2552
2598
  seenToolCalls.add(part.id);
@@ -2599,7 +2645,7 @@ var XaiResponsesLanguageModel = class {
2599
2645
  sourceType: "url",
2600
2646
  id: self.config.generateId(),
2601
2647
  url: annotation.url,
2602
- title: (_m = annotation.title) != null ? _m : annotation.url
2648
+ title: (_o = annotation.title) != null ? _o : annotation.url
2603
2649
  });
2604
2650
  }
2605
2651
  }
@@ -2719,7 +2765,7 @@ var xaiTools = {
2719
2765
  };
2720
2766
 
2721
2767
  // src/version.ts
2722
- var VERSION = true ? "3.0.80" : "0.0.0-test";
2768
+ var VERSION = true ? "3.0.82" : "0.0.0-test";
2723
2769
 
2724
2770
  // src/xai-video-model.ts
2725
2771
  var import_provider6 = require("@ai-sdk/provider");