@ai-sdk/xai 4.0.0-beta.26 → 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/dist/index.mjs CHANGED
@@ -1276,6 +1276,7 @@ function mapXaiResponsesFinishReason(finishReason) {
1276
1276
  case "completed":
1277
1277
  return "stop";
1278
1278
  case "length":
1279
+ case "max_output_tokens":
1279
1280
  return "length";
1280
1281
  case "tool_calls":
1281
1282
  case "function_call":
@@ -1681,6 +1682,24 @@ var xaiResponsesChunkSchema = z6.union([
1681
1682
  output_index: z6.number(),
1682
1683
  output: z6.string().optional()
1683
1684
  }),
1685
+ z6.object({
1686
+ type: z6.literal("response.incomplete"),
1687
+ response: z6.object({
1688
+ incomplete_details: z6.object({ reason: z6.string() }).nullish(),
1689
+ usage: xaiResponsesUsageSchema.nullish()
1690
+ })
1691
+ }),
1692
+ z6.object({
1693
+ type: z6.literal("response.failed"),
1694
+ response: z6.object({
1695
+ error: z6.object({
1696
+ code: z6.string().nullish(),
1697
+ message: z6.string()
1698
+ }).nullish(),
1699
+ incomplete_details: z6.object({ reason: z6.string() }).nullish(),
1700
+ usage: xaiResponsesUsageSchema.nullish()
1701
+ })
1702
+ }),
1684
1703
  z6.object({
1685
1704
  type: z6.literal("response.done"),
1686
1705
  response: xaiResponsesResponseSchema
@@ -2380,7 +2399,7 @@ var XaiResponsesLanguageModel = class {
2380
2399
  controller.enqueue({ type: "stream-start", warnings });
2381
2400
  },
2382
2401
  transform(chunk, controller) {
2383
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2402
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2384
2403
  if (options.includeRawChunks) {
2385
2404
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2386
2405
  }
@@ -2503,12 +2522,18 @@ var XaiResponsesLanguageModel = class {
2503
2522
  }
2504
2523
  return;
2505
2524
  }
2506
- if (event.type === "response.done" || event.type === "response.completed") {
2525
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2507
2526
  const response2 = event.response;
2508
2527
  if (response2.usage) {
2509
2528
  usage = convertXaiResponsesUsage(response2.usage);
2510
2529
  }
2511
- if (response2.status) {
2530
+ if (event.type === "response.incomplete") {
2531
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2532
+ finishReason = {
2533
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2534
+ raw: reason != null ? reason : "incomplete"
2535
+ };
2536
+ } else if ("status" in response2 && response2.status) {
2512
2537
  finishReason = {
2513
2538
  unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
2514
2539
  raw: response2.status
@@ -2516,6 +2541,17 @@ var XaiResponsesLanguageModel = class {
2516
2541
  }
2517
2542
  return;
2518
2543
  }
2544
+ if (event.type === "response.failed") {
2545
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2546
+ finishReason = {
2547
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2548
+ raw: reason != null ? reason : "error"
2549
+ };
2550
+ if (event.response.usage) {
2551
+ usage = convertXaiResponsesUsage(event.response.usage);
2552
+ }
2553
+ return;
2554
+ }
2519
2555
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2520
2556
  return;
2521
2557
  }
@@ -2598,13 +2634,13 @@ var XaiResponsesLanguageModel = class {
2598
2634
  toolCallId: part.id,
2599
2635
  toolName,
2600
2636
  result: {
2601
- queries: (_c = part.queries) != null ? _c : [],
2602
- results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2637
+ queries: (_e = part.queries) != null ? _e : [],
2638
+ results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2603
2639
  fileId: result.file_id,
2604
2640
  filename: result.filename,
2605
2641
  score: result.score,
2606
2642
  text: result.text
2607
- }))) != null ? _e : null
2643
+ }))) != null ? _g : null
2608
2644
  }
2609
2645
  });
2610
2646
  }
@@ -2622,17 +2658,17 @@ var XaiResponsesLanguageModel = class {
2622
2658
  "x_semantic_search",
2623
2659
  "x_thread_fetch"
2624
2660
  ];
2625
- let toolName = (_f = part.name) != null ? _f : "";
2626
- if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2661
+ let toolName = (_h = part.name) != null ? _h : "";
2662
+ if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2627
2663
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2628
- } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2664
+ } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2629
2665
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2630
2666
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2631
2667
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2632
2668
  } else if (part.type === "mcp_call") {
2633
- toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2669
+ toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2634
2670
  }
2635
- 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 : "";
2671
+ 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 : "";
2636
2672
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2637
2673
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2638
2674
  seenToolCalls.add(part.id);
@@ -2685,7 +2721,7 @@ var XaiResponsesLanguageModel = class {
2685
2721
  sourceType: "url",
2686
2722
  id: self.config.generateId(),
2687
2723
  url: annotation.url,
2688
- title: (_m = annotation.title) != null ? _m : annotation.url
2724
+ title: (_o = annotation.title) != null ? _o : annotation.url
2689
2725
  });
2690
2726
  }
2691
2727
  }
@@ -2805,7 +2841,7 @@ var xaiTools = {
2805
2841
  };
2806
2842
 
2807
2843
  // src/version.ts
2808
- var VERSION = true ? "4.0.0-beta.26" : "0.0.0-test";
2844
+ var VERSION = true ? "4.0.0-beta.29" : "0.0.0-test";
2809
2845
 
2810
2846
  // src/files/xai-files.ts
2811
2847
  import {