@ai-sdk/xai 4.0.0-beta.28 → 4.0.0-beta.29

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,11 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.0-beta.29
4
+
5
+ ### Patch Changes
6
+
7
+ - 813851f: fix (provider/xai): add response.incomplete and response.failed streaming event handling
8
+
3
9
  ## 4.0.0-beta.28
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1261,6 +1261,7 @@ function mapXaiResponsesFinishReason(finishReason) {
1261
1261
  case "completed":
1262
1262
  return "stop";
1263
1263
  case "length":
1264
+ case "max_output_tokens":
1264
1265
  return "length";
1265
1266
  case "tool_calls":
1266
1267
  case "function_call":
@@ -1666,6 +1667,24 @@ var xaiResponsesChunkSchema = import_v46.z.union([
1666
1667
  output_index: import_v46.z.number(),
1667
1668
  output: import_v46.z.string().optional()
1668
1669
  }),
1670
+ import_v46.z.object({
1671
+ type: import_v46.z.literal("response.incomplete"),
1672
+ response: import_v46.z.object({
1673
+ incomplete_details: import_v46.z.object({ reason: import_v46.z.string() }).nullish(),
1674
+ usage: xaiResponsesUsageSchema.nullish()
1675
+ })
1676
+ }),
1677
+ import_v46.z.object({
1678
+ type: import_v46.z.literal("response.failed"),
1679
+ response: import_v46.z.object({
1680
+ error: import_v46.z.object({
1681
+ code: import_v46.z.string().nullish(),
1682
+ message: import_v46.z.string()
1683
+ }).nullish(),
1684
+ incomplete_details: import_v46.z.object({ reason: import_v46.z.string() }).nullish(),
1685
+ usage: xaiResponsesUsageSchema.nullish()
1686
+ })
1687
+ }),
1669
1688
  import_v46.z.object({
1670
1689
  type: import_v46.z.literal("response.done"),
1671
1690
  response: xaiResponsesResponseSchema
@@ -2347,7 +2366,7 @@ var XaiResponsesLanguageModel = class {
2347
2366
  controller.enqueue({ type: "stream-start", warnings });
2348
2367
  },
2349
2368
  transform(chunk, controller) {
2350
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2369
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2351
2370
  if (options.includeRawChunks) {
2352
2371
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2353
2372
  }
@@ -2470,12 +2489,18 @@ var XaiResponsesLanguageModel = class {
2470
2489
  }
2471
2490
  return;
2472
2491
  }
2473
- if (event.type === "response.done" || event.type === "response.completed") {
2492
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2474
2493
  const response2 = event.response;
2475
2494
  if (response2.usage) {
2476
2495
  usage = convertXaiResponsesUsage(response2.usage);
2477
2496
  }
2478
- if (response2.status) {
2497
+ if (event.type === "response.incomplete") {
2498
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2499
+ finishReason = {
2500
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2501
+ raw: reason != null ? reason : "incomplete"
2502
+ };
2503
+ } else if ("status" in response2 && response2.status) {
2479
2504
  finishReason = {
2480
2505
  unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
2481
2506
  raw: response2.status
@@ -2483,6 +2508,17 @@ var XaiResponsesLanguageModel = class {
2483
2508
  }
2484
2509
  return;
2485
2510
  }
2511
+ if (event.type === "response.failed") {
2512
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2513
+ finishReason = {
2514
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2515
+ raw: reason != null ? reason : "error"
2516
+ };
2517
+ if (event.response.usage) {
2518
+ usage = convertXaiResponsesUsage(event.response.usage);
2519
+ }
2520
+ return;
2521
+ }
2486
2522
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2487
2523
  return;
2488
2524
  }
@@ -2565,13 +2601,13 @@ var XaiResponsesLanguageModel = class {
2565
2601
  toolCallId: part.id,
2566
2602
  toolName,
2567
2603
  result: {
2568
- queries: (_c = part.queries) != null ? _c : [],
2569
- results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2604
+ queries: (_e = part.queries) != null ? _e : [],
2605
+ results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2570
2606
  fileId: result.file_id,
2571
2607
  filename: result.filename,
2572
2608
  score: result.score,
2573
2609
  text: result.text
2574
- }))) != null ? _e : null
2610
+ }))) != null ? _g : null
2575
2611
  }
2576
2612
  });
2577
2613
  }
@@ -2589,17 +2625,17 @@ var XaiResponsesLanguageModel = class {
2589
2625
  "x_semantic_search",
2590
2626
  "x_thread_fetch"
2591
2627
  ];
2592
- let toolName = (_f = part.name) != null ? _f : "";
2593
- if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2628
+ let toolName = (_h = part.name) != null ? _h : "";
2629
+ if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2594
2630
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2595
- } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2631
+ } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2596
2632
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2597
2633
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2598
2634
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2599
2635
  } else if (part.type === "mcp_call") {
2600
- toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2636
+ toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2601
2637
  }
2602
- 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 : "";
2638
+ 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 : "";
2603
2639
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2604
2640
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2605
2641
  seenToolCalls.add(part.id);
@@ -2652,7 +2688,7 @@ var XaiResponsesLanguageModel = class {
2652
2688
  sourceType: "url",
2653
2689
  id: self.config.generateId(),
2654
2690
  url: annotation.url,
2655
- title: (_m = annotation.title) != null ? _m : annotation.url
2691
+ title: (_o = annotation.title) != null ? _o : annotation.url
2656
2692
  });
2657
2693
  }
2658
2694
  }
@@ -2772,7 +2808,7 @@ var xaiTools = {
2772
2808
  };
2773
2809
 
2774
2810
  // src/version.ts
2775
- var VERSION = true ? "4.0.0-beta.28" : "0.0.0-test";
2811
+ var VERSION = true ? "4.0.0-beta.29" : "0.0.0-test";
2776
2812
 
2777
2813
  // src/files/xai-files.ts
2778
2814
  var import_provider_utils17 = require("@ai-sdk/provider-utils");