@ai-sdk/xai 3.0.4 → 3.0.6

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.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 77012ef: fix(xai): correct token counting for reasoning models to prevent negative text_output_tokens
8
+
9
+ ## 3.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - e7f0a6f: fix(xai): add missing stream response schema and provider tool name parsing
14
+
3
15
  ## 3.0.4
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -166,8 +166,8 @@ function convertXaiChatUsage(usage) {
166
166
  cacheWrite: void 0
167
167
  },
168
168
  outputTokens: {
169
- total: usage.completion_tokens + reasoningTokens,
170
- text: usage.completion_tokens,
169
+ total: usage.completion_tokens,
170
+ text: usage.completion_tokens - reasoningTokens,
171
171
  reasoning: reasoningTokens
172
172
  },
173
173
  raw: usage
@@ -1221,11 +1221,29 @@ var xaiResponsesChunkSchema = import_v44.z.union([
1221
1221
  item_id: import_v44.z.string(),
1222
1222
  output_index: import_v44.z.number()
1223
1223
  }),
1224
+ import_v44.z.object({
1225
+ type: import_v44.z.literal("response.code_interpreter_call.interpreting"),
1226
+ item_id: import_v44.z.string(),
1227
+ output_index: import_v44.z.number()
1228
+ }),
1224
1229
  import_v44.z.object({
1225
1230
  type: import_v44.z.literal("response.code_interpreter_call.completed"),
1226
1231
  item_id: import_v44.z.string(),
1227
1232
  output_index: import_v44.z.number()
1228
1233
  }),
1234
+ // Code interpreter code streaming events
1235
+ import_v44.z.object({
1236
+ type: import_v44.z.literal("response.code_interpreter_call_code.delta"),
1237
+ item_id: import_v44.z.string(),
1238
+ output_index: import_v44.z.number(),
1239
+ delta: import_v44.z.string()
1240
+ }),
1241
+ import_v44.z.object({
1242
+ type: import_v44.z.literal("response.code_interpreter_call_code.done"),
1243
+ item_id: import_v44.z.string(),
1244
+ output_index: import_v44.z.number(),
1245
+ code: import_v44.z.string()
1246
+ }),
1229
1247
  import_v44.z.object({
1230
1248
  type: import_v44.z.literal("response.done"),
1231
1249
  response: xaiResponsesResponseSchema
@@ -1637,11 +1655,11 @@ var XaiResponsesLanguageModel = class {
1637
1655
  for (const part of response.output) {
1638
1656
  if (part.type === "web_search_call" || part.type === "x_search_call" || part.type === "code_interpreter_call" || part.type === "code_execution_call" || part.type === "view_image_call" || part.type === "view_x_video_call" || part.type === "custom_tool_call") {
1639
1657
  let toolName = (_b = part.name) != null ? _b : "";
1640
- if (webSearchSubTools.includes((_c = part.name) != null ? _c : "")) {
1658
+ if (webSearchSubTools.includes((_c = part.name) != null ? _c : "") || part.type === "web_search_call") {
1641
1659
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1642
- } else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "")) {
1660
+ } else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "") || part.type === "x_search_call") {
1643
1661
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1644
- } else if (part.name === "code_execution") {
1662
+ } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
1645
1663
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1646
1664
  }
1647
1665
  const toolInput = part.type === "custom_tool_call" ? (_e = part.input) != null ? _e : "" : (_f = part.arguments) != null ? _f : "";
@@ -1866,11 +1884,11 @@ var XaiResponsesLanguageModel = class {
1866
1884
  "x_thread_fetch"
1867
1885
  ];
1868
1886
  let toolName = (_c = part.name) != null ? _c : "";
1869
- if (webSearchSubTools.includes((_d = part.name) != null ? _d : "")) {
1887
+ if (webSearchSubTools.includes((_d = part.name) != null ? _d : "") || part.type === "web_search_call") {
1870
1888
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1871
- } else if (xSearchSubTools.includes((_e = part.name) != null ? _e : "")) {
1889
+ } else if (xSearchSubTools.includes((_e = part.name) != null ? _e : "") || part.type === "x_search_call") {
1872
1890
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1873
- } else if (part.name === "code_execution") {
1891
+ } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
1874
1892
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1875
1893
  }
1876
1894
  const toolInput = part.type === "custom_tool_call" ? (_f = part.input) != null ? _f : "" : (_g = part.arguments) != null ? _g : "";
@@ -2028,7 +2046,7 @@ var xaiTools = {
2028
2046
  };
2029
2047
 
2030
2048
  // src/version.ts
2031
- var VERSION = true ? "3.0.4" : "0.0.0-test";
2049
+ var VERSION = true ? "3.0.6" : "0.0.0-test";
2032
2050
 
2033
2051
  // src/xai-provider.ts
2034
2052
  var xaiErrorStructure = {