@ai-sdk/xai 4.0.0-beta.41 → 4.0.0-beta.43

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,23 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 4.0.0-beta.43
4
+
5
+ ### Patch Changes
6
+
7
+ - a0b0a0c: expose costInUsdTicks in responses provider metadata
8
+ - Updated dependencies [2e98477]
9
+ - Updated dependencies [bfb756d]
10
+ - @ai-sdk/provider-utils@5.0.0-beta.26
11
+ - @ai-sdk/openai-compatible@3.0.0-beta.31
12
+
13
+ ## 4.0.0-beta.42
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [eea8d98]
18
+ - @ai-sdk/provider-utils@5.0.0-beta.25
19
+ - @ai-sdk/openai-compatible@3.0.0-beta.30
20
+
3
21
  ## 4.0.0-beta.41
4
22
 
5
23
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1463,7 +1463,8 @@ var xaiResponsesUsageSchema = z6.object({
1463
1463
  reasoning_tokens: z6.number().optional()
1464
1464
  }).optional(),
1465
1465
  num_sources_used: z6.number().optional(),
1466
- num_server_side_tools_used: z6.number().optional()
1466
+ num_server_side_tools_used: z6.number().optional(),
1467
+ cost_in_usd_ticks: z6.number().nullish()
1467
1468
  });
1468
1469
  var xaiResponsesResponseSchema = z6.object({
1469
1470
  id: z6.string().nullish(),
@@ -2255,7 +2256,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2255
2256
  };
2256
2257
  }
2257
2258
  async doGenerate(options) {
2258
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2259
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2259
2260
  const {
2260
2261
  args: body,
2261
2262
  warnings,
@@ -2412,6 +2413,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2412
2413
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
2413
2414
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2414
2415
  },
2416
+ ...((_q = response.usage) == null ? void 0 : _q.cost_in_usd_ticks) != null && {
2417
+ providerMetadata: {
2418
+ xai: {
2419
+ costInUsdTicks: response.usage.cost_in_usd_ticks
2420
+ }
2421
+ }
2422
+ },
2415
2423
  request: { body },
2416
2424
  response: {
2417
2425
  ...getResponseMetadata(response),
@@ -2453,6 +2461,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2453
2461
  };
2454
2462
  let hasFunctionCall = false;
2455
2463
  let usage = void 0;
2464
+ let costInUsdTicks = void 0;
2456
2465
  let isFirstChunk = true;
2457
2466
  const contentBlocks = {};
2458
2467
  const seenToolCalls = /* @__PURE__ */ new Set();
@@ -2466,7 +2475,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2466
2475
  controller.enqueue({ type: "stream-start", warnings });
2467
2476
  },
2468
2477
  transform(chunk, controller) {
2469
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
2478
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2470
2479
  if (options.includeRawChunks) {
2471
2480
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2472
2481
  }
@@ -2593,9 +2602,10 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2593
2602
  const response2 = event.response;
2594
2603
  if (response2.usage) {
2595
2604
  usage = convertXaiResponsesUsage(response2.usage);
2605
+ costInUsdTicks = (_c2 = response2.usage.cost_in_usd_ticks) != null ? _c2 : void 0;
2596
2606
  }
2597
2607
  if (event.type === "response.incomplete") {
2598
- const reason = "incomplete_details" in response2 ? (_c2 = response2.incomplete_details) == null ? void 0 : _c2.reason : void 0;
2608
+ const reason = "incomplete_details" in response2 ? (_d = response2.incomplete_details) == null ? void 0 : _d.reason : void 0;
2599
2609
  finishReason = {
2600
2610
  unified: reason ? mapXaiResponsesFinishReason(reason) : "other",
2601
2611
  raw: reason != null ? reason : "incomplete"
@@ -2609,7 +2619,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2609
2619
  return;
2610
2620
  }
2611
2621
  if (event.type === "response.failed") {
2612
- const reason = (_d = event.response.incomplete_details) == null ? void 0 : _d.reason;
2622
+ const reason = (_e = event.response.incomplete_details) == null ? void 0 : _e.reason;
2613
2623
  finishReason = {
2614
2624
  unified: reason ? mapXaiResponsesFinishReason(reason) : "error",
2615
2625
  raw: reason != null ? reason : "error"
@@ -2705,13 +2715,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2705
2715
  toolCallId: part.id,
2706
2716
  toolName,
2707
2717
  result: {
2708
- queries: (_e = part.queries) != null ? _e : [],
2709
- results: (_g = (_f = part.results) == null ? void 0 : _f.map((result) => ({
2718
+ queries: (_f = part.queries) != null ? _f : [],
2719
+ results: (_h = (_g = part.results) == null ? void 0 : _g.map((result) => ({
2710
2720
  fileId: result.file_id,
2711
2721
  filename: result.filename,
2712
2722
  score: result.score,
2713
2723
  text: result.text
2714
- }))) != null ? _g : null
2724
+ }))) != null ? _h : null
2715
2725
  }
2716
2726
  });
2717
2727
  }
@@ -2729,17 +2739,17 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2729
2739
  "x_semantic_search",
2730
2740
  "x_thread_fetch"
2731
2741
  ];
2732
- let toolName = (_h = part.name) != null ? _h : "";
2733
- if (webSearchSubTools.includes((_i = part.name) != null ? _i : "") || part.type === "web_search_call") {
2742
+ let toolName = (_i = part.name) != null ? _i : "";
2743
+ if (webSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "web_search_call") {
2734
2744
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2735
- } else if (xSearchSubTools.includes((_j = part.name) != null ? _j : "") || part.type === "x_search_call") {
2745
+ } else if (xSearchSubTools.includes((_k = part.name) != null ? _k : "") || part.type === "x_search_call") {
2736
2746
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2737
2747
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2738
2748
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2739
2749
  } else if (part.type === "mcp_call") {
2740
- toolName = (_k = mcpToolName != null ? mcpToolName : part.name) != null ? _k : "mcp";
2750
+ toolName = (_l = mcpToolName != null ? mcpToolName : part.name) != null ? _l : "mcp";
2741
2751
  }
2742
- 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 : "";
2752
+ const toolInput = part.type === "custom_tool_call" ? (_m = part.input) != null ? _m : "" : part.type === "mcp_call" ? (_n = part.arguments) != null ? _n : "" : (_o = part.arguments) != null ? _o : "";
2743
2753
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2744
2754
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2745
2755
  seenToolCalls.add(part.id);
@@ -2792,7 +2802,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2792
2802
  sourceType: "url",
2793
2803
  id: self.config.generateId(),
2794
2804
  url: annotation.url,
2795
- title: (_o = annotation.title) != null ? _o : annotation.url
2805
+ title: (_p = annotation.title) != null ? _p : annotation.url
2796
2806
  });
2797
2807
  }
2798
2808
  }
@@ -2846,6 +2856,13 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
2846
2856
  cacheWrite: 0
2847
2857
  },
2848
2858
  outputTokens: { total: 0, text: 0, reasoning: 0 }
2859
+ },
2860
+ ...costInUsdTicks != null && {
2861
+ providerMetadata: {
2862
+ xai: {
2863
+ costInUsdTicks
2864
+ }
2865
+ }
2849
2866
  }
2850
2867
  });
2851
2868
  }
@@ -2912,7 +2929,7 @@ var xaiTools = {
2912
2929
  };
2913
2930
 
2914
2931
  // src/version.ts
2915
- var VERSION = true ? "4.0.0-beta.41" : "0.0.0-test";
2932
+ var VERSION = true ? "4.0.0-beta.43" : "0.0.0-test";
2916
2933
 
2917
2934
  // src/files/xai-files.ts
2918
2935
  import {