@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/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,30 @@ 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
+ }),
1658
+ z6.object({
1659
+ type: z6.literal("error"),
1660
+ code: z6.string().nullish(),
1661
+ message: z6.string(),
1662
+ param: z6.string().nullish()
1663
+ }),
1639
1664
  z6.object({
1640
1665
  type: z6.literal("response.done"),
1641
1666
  response: xaiResponsesResponseSchema
@@ -2315,7 +2340,7 @@ var XaiResponsesLanguageModel = class {
2315
2340
  controller.enqueue({ type: "stream-start", warnings });
2316
2341
  },
2317
2342
  transform(chunk, controller) {
2318
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2343
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2319
2344
  if (options.includeRawChunks) {
2320
2345
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2321
2346
  }
@@ -2438,12 +2463,18 @@ var XaiResponsesLanguageModel = class {
2438
2463
  }
2439
2464
  return;
2440
2465
  }
2441
- if (event.type === "response.done" || event.type === "response.completed") {
2466
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2442
2467
  const response2 = event.response;
2443
2468
  if (response2.usage) {
2444
2469
  usage = convertXaiResponsesUsage(response2.usage);
2445
2470
  }
2446
- if (response2.status) {
2471
+ if (event.type === "response.incomplete") {
2472
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2473
+ finishReason = {
2474
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2475
+ raw: reason != null ? reason : "incomplete"
2476
+ };
2477
+ } else if ("status" in response2 && response2.status) {
2447
2478
  finishReason = {
2448
2479
  unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
2449
2480
  raw: response2.status
@@ -2451,6 +2482,21 @@ var XaiResponsesLanguageModel = class {
2451
2482
  }
2452
2483
  return;
2453
2484
  }
2485
+ if (event.type === "response.failed") {
2486
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2487
+ finishReason = {
2488
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2489
+ raw: reason != null ? reason : "error"
2490
+ };
2491
+ if (event.response.usage) {
2492
+ usage = convertXaiResponsesUsage(event.response.usage);
2493
+ }
2494
+ return;
2495
+ }
2496
+ if (event.type === "error") {
2497
+ controller.enqueue({ type: "error", error: event });
2498
+ return;
2499
+ }
2454
2500
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2455
2501
  return;
2456
2502
  }
@@ -2533,13 +2579,13 @@ var XaiResponsesLanguageModel = class {
2533
2579
  toolCallId: part.id,
2534
2580
  toolName,
2535
2581
  result: {
2536
- queries: (_c = part.queries) != null ? _c : [],
2537
- results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2582
+ queries: (_e = part.queries) != null ? _e : [],
2583
+ results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2538
2584
  fileId: result.file_id,
2539
2585
  filename: result.filename,
2540
2586
  score: result.score,
2541
2587
  text: result.text
2542
- }))) != null ? _e : null
2588
+ }))) != null ? _g : null
2543
2589
  }
2544
2590
  });
2545
2591
  }
@@ -2557,17 +2603,17 @@ var XaiResponsesLanguageModel = class {
2557
2603
  "x_semantic_search",
2558
2604
  "x_thread_fetch"
2559
2605
  ];
2560
- let toolName = (_f = part.name) != null ? _f : "";
2561
- if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2606
+ let toolName = (_h = part.name) != null ? _h : "";
2607
+ if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2562
2608
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2563
- } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2609
+ } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2564
2610
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2565
2611
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2566
2612
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2567
2613
  } else if (part.type === "mcp_call") {
2568
- toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2614
+ toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2569
2615
  }
2570
- 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 : "";
2616
+ 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
2617
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2572
2618
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2573
2619
  seenToolCalls.add(part.id);
@@ -2620,7 +2666,7 @@ var XaiResponsesLanguageModel = class {
2620
2666
  sourceType: "url",
2621
2667
  id: self.config.generateId(),
2622
2668
  url: annotation.url,
2623
- title: (_m = annotation.title) != null ? _m : annotation.url
2669
+ title: (_o = annotation.title) != null ? _o : annotation.url
2624
2670
  });
2625
2671
  }
2626
2672
  }
@@ -2740,7 +2786,7 @@ var xaiTools = {
2740
2786
  };
2741
2787
 
2742
2788
  // src/version.ts
2743
- var VERSION = true ? "3.0.80" : "0.0.0-test";
2789
+ var VERSION = true ? "3.0.82" : "0.0.0-test";
2744
2790
 
2745
2791
  // src/xai-video-model.ts
2746
2792
  import {