@ai-sdk/xai 3.0.79 → 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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.81
4
+
5
+ ### Patch Changes
6
+
7
+ - c1cc97f: fix (provider/xai): add response.incomplete and response.failed streaming event handling
8
+
9
+ ## 3.0.80
10
+
11
+ ### Patch Changes
12
+
13
+ - d42076d: Add AI Gateway hint to provider READMEs
14
+ - Updated dependencies [d42076d]
15
+ - @ai-sdk/openai-compatible@2.0.41
16
+
3
17
  ## 3.0.79
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  The **[xAI Grok provider](https://ai-sdk.dev/providers/ai-sdk-providers/xai)** for the [AI SDK](https://ai-sdk.dev/docs)
4
4
  contains language model support for the xAI chat and completion APIs.
5
5
 
6
+ > **Deploying to Vercel?** With Vercel's AI Gateway you can access xAI (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
7
+
6
8
  ## Setup
7
9
 
8
10
  The xAI Grok provider is available in the `@ai-sdk/xai` module. You can install it with
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,24 @@ 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
+ }),
1636
1655
  import_v46.z.object({
1637
1656
  type: import_v46.z.literal("response.done"),
1638
1657
  response: xaiResponsesResponseSchema
@@ -2294,7 +2313,7 @@ var XaiResponsesLanguageModel = class {
2294
2313
  controller.enqueue({ type: "stream-start", warnings });
2295
2314
  },
2296
2315
  transform(chunk, controller) {
2297
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2316
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2298
2317
  if (options.includeRawChunks) {
2299
2318
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2300
2319
  }
@@ -2417,12 +2436,18 @@ var XaiResponsesLanguageModel = class {
2417
2436
  }
2418
2437
  return;
2419
2438
  }
2420
- if (event.type === "response.done" || event.type === "response.completed") {
2439
+ if (event.type === "response.done" || event.type === "response.completed" || event.type === "response.incomplete") {
2421
2440
  const response2 = event.response;
2422
2441
  if (response2.usage) {
2423
2442
  usage = convertXaiResponsesUsage(response2.usage);
2424
2443
  }
2425
- if (response2.status) {
2444
+ if (event.type === "response.incomplete") {
2445
+ const reason = "incomplete_details" in response2 ? (_c = response2.incomplete_details) == null ? void 0 : _c.reason : void 0;
2446
+ finishReason = {
2447
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2448
+ raw: reason != null ? reason : "incomplete"
2449
+ };
2450
+ } else if ("status" in response2 && response2.status) {
2426
2451
  finishReason = {
2427
2452
  unified: hasFunctionCall ? "tool-calls" : mapXaiResponsesFinishReason(response2.status),
2428
2453
  raw: response2.status
@@ -2430,6 +2455,17 @@ var XaiResponsesLanguageModel = class {
2430
2455
  }
2431
2456
  return;
2432
2457
  }
2458
+ if (event.type === "response.failed") {
2459
+ const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2460
+ finishReason = {
2461
+ unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2462
+ raw: reason != null ? reason : "error"
2463
+ };
2464
+ if (event.response.usage) {
2465
+ usage = convertXaiResponsesUsage(event.response.usage);
2466
+ }
2467
+ return;
2468
+ }
2433
2469
  if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
2434
2470
  return;
2435
2471
  }
@@ -2512,13 +2548,13 @@ var XaiResponsesLanguageModel = class {
2512
2548
  toolCallId: part.id,
2513
2549
  toolName,
2514
2550
  result: {
2515
- queries: (_c = part.queries) != null ? _c : [],
2516
- results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2551
+ queries: (_e = part.queries) != null ? _e : [],
2552
+ results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2517
2553
  fileId: result.file_id,
2518
2554
  filename: result.filename,
2519
2555
  score: result.score,
2520
2556
  text: result.text
2521
- }))) != null ? _e : null
2557
+ }))) != null ? _g : null
2522
2558
  }
2523
2559
  });
2524
2560
  }
@@ -2536,17 +2572,17 @@ var XaiResponsesLanguageModel = class {
2536
2572
  "x_semantic_search",
2537
2573
  "x_thread_fetch"
2538
2574
  ];
2539
- let toolName = (_f = part.name) != null ? _f : "";
2540
- if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2575
+ let toolName = (_h = part.name) != null ? _h : "";
2576
+ if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2541
2577
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2542
- } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2578
+ } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2543
2579
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2544
2580
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2545
2581
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2546
2582
  } else if (part.type === "mcp_call") {
2547
- toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2583
+ toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2548
2584
  }
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 : "";
2585
+ 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
2586
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2551
2587
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2552
2588
  seenToolCalls.add(part.id);
@@ -2599,7 +2635,7 @@ var XaiResponsesLanguageModel = class {
2599
2635
  sourceType: "url",
2600
2636
  id: self.config.generateId(),
2601
2637
  url: annotation.url,
2602
- title: (_m = annotation.title) != null ? _m : annotation.url
2638
+ title: (_o = annotation.title) != null ? _o : annotation.url
2603
2639
  });
2604
2640
  }
2605
2641
  }
@@ -2719,7 +2755,7 @@ var xaiTools = {
2719
2755
  };
2720
2756
 
2721
2757
  // src/version.ts
2722
- var VERSION = true ? "3.0.79" : "0.0.0-test";
2758
+ var VERSION = true ? "3.0.81" : "0.0.0-test";
2723
2759
 
2724
2760
  // src/xai-video-model.ts
2725
2761
  var import_provider6 = require("@ai-sdk/provider");