@ai-sdk/xai 3.0.38 → 3.0.40

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.js CHANGED
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(src_exports);
36
36
  // src/xai-provider.ts
37
37
  var import_openai_compatible = require("@ai-sdk/openai-compatible");
38
38
  var import_provider6 = require("@ai-sdk/provider");
39
- var import_provider_utils13 = require("@ai-sdk/provider-utils");
39
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
40
40
 
41
41
  // src/xai-chat-language-model.ts
42
42
  var import_provider3 = require("@ai-sdk/provider");
@@ -865,7 +865,7 @@ var xaiStreamErrorSchema = import_v43.z.object({
865
865
  });
866
866
 
867
867
  // src/responses/xai-responses-language-model.ts
868
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
868
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
869
869
 
870
870
  // src/responses/convert-to-xai-responses-input.ts
871
871
  var import_provider4 = require("@ai-sdk/provider");
@@ -1125,6 +1125,20 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
1125
1125
  type: import_v44.z.literal("view_x_video_call"),
1126
1126
  ...toolCallSchema.shape
1127
1127
  }),
1128
+ import_v44.z.object({
1129
+ type: import_v44.z.literal("file_search_call"),
1130
+ id: import_v44.z.string(),
1131
+ status: import_v44.z.string(),
1132
+ queries: import_v44.z.array(import_v44.z.string()).optional(),
1133
+ results: import_v44.z.array(
1134
+ import_v44.z.object({
1135
+ file_id: import_v44.z.string(),
1136
+ filename: import_v44.z.string(),
1137
+ score: import_v44.z.number(),
1138
+ text: import_v44.z.string()
1139
+ })
1140
+ ).nullish()
1141
+ }),
1128
1142
  import_v44.z.object({
1129
1143
  type: import_v44.z.literal("custom_tool_call"),
1130
1144
  ...toolCallSchema.shape
@@ -1293,6 +1307,21 @@ var xaiResponsesChunkSchema = import_v44.z.union([
1293
1307
  item_id: import_v44.z.string(),
1294
1308
  output_index: import_v44.z.number()
1295
1309
  }),
1310
+ import_v44.z.object({
1311
+ type: import_v44.z.literal("response.file_search_call.in_progress"),
1312
+ item_id: import_v44.z.string(),
1313
+ output_index: import_v44.z.number()
1314
+ }),
1315
+ import_v44.z.object({
1316
+ type: import_v44.z.literal("response.file_search_call.searching"),
1317
+ item_id: import_v44.z.string(),
1318
+ output_index: import_v44.z.number()
1319
+ }),
1320
+ import_v44.z.object({
1321
+ type: import_v44.z.literal("response.file_search_call.completed"),
1322
+ item_id: import_v44.z.string(),
1323
+ output_index: import_v44.z.number()
1324
+ }),
1296
1325
  import_v44.z.object({
1297
1326
  type: import_v44.z.literal("response.custom_tool_call_input.done"),
1298
1327
  item_id: import_v44.z.string(),
@@ -1433,110 +1462,148 @@ var xaiResponsesProviderOptions = import_v45.z.object({
1433
1462
  /**
1434
1463
  * The ID of the previous response from the model.
1435
1464
  */
1436
- previousResponseId: import_v45.z.string().optional()
1465
+ previousResponseId: import_v45.z.string().optional(),
1466
+ /**
1467
+ * Specify additional output data to include in the model response.
1468
+ * Example values: 'file_search_call.results'.
1469
+ */
1470
+ include: import_v45.z.array(import_v45.z.enum(["file_search_call.results"])).nullish()
1437
1471
  });
1438
1472
 
1439
1473
  // src/responses/xai-responses-prepare-tools.ts
1440
1474
  var import_provider5 = require("@ai-sdk/provider");
1441
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1475
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1442
1476
 
1443
- // src/tool/mcp-server.ts
1477
+ // src/tool/file-search.ts
1444
1478
  var import_provider_utils5 = require("@ai-sdk/provider-utils");
1445
1479
  var import_v46 = require("zod/v4");
1446
- var mcpServerArgsSchema = (0, import_provider_utils5.lazySchema)(
1480
+ var fileSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1447
1481
  () => (0, import_provider_utils5.zodSchema)(
1448
1482
  import_v46.z.object({
1449
- serverUrl: import_v46.z.string().describe("The URL of the MCP server"),
1450
- serverLabel: import_v46.z.string().optional().describe("A label for the MCP server"),
1451
- serverDescription: import_v46.z.string().optional().describe("Description of the MCP server"),
1452
- allowedTools: import_v46.z.array(import_v46.z.string()).optional().describe("List of allowed tool names"),
1453
- headers: import_v46.z.record(import_v46.z.string(), import_v46.z.string()).optional().describe("Custom headers to send"),
1454
- authorization: import_v46.z.string().optional().describe("Authorization header value")
1483
+ vectorStoreIds: import_v46.z.array(import_v46.z.string()),
1484
+ maxNumResults: import_v46.z.number().optional()
1455
1485
  })
1456
1486
  )
1457
1487
  );
1458
- var mcpServerOutputSchema = (0, import_provider_utils5.lazySchema)(
1488
+ var fileSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1459
1489
  () => (0, import_provider_utils5.zodSchema)(
1460
1490
  import_v46.z.object({
1461
- name: import_v46.z.string(),
1462
- arguments: import_v46.z.string(),
1463
- result: import_v46.z.unknown()
1491
+ queries: import_v46.z.array(import_v46.z.string()),
1492
+ results: import_v46.z.array(
1493
+ import_v46.z.object({
1494
+ fileId: import_v46.z.string(),
1495
+ filename: import_v46.z.string(),
1496
+ score: import_v46.z.number().min(0).max(1),
1497
+ text: import_v46.z.string()
1498
+ })
1499
+ ).nullable()
1464
1500
  })
1465
1501
  )
1466
1502
  );
1467
- var mcpServerToolFactory = (0, import_provider_utils5.createProviderToolFactoryWithOutputSchema)({
1468
- id: "xai.mcp",
1503
+ var fileSearchToolFactory = (0, import_provider_utils5.createProviderToolFactoryWithOutputSchema)({
1504
+ id: "xai.file_search",
1469
1505
  inputSchema: (0, import_provider_utils5.lazySchema)(() => (0, import_provider_utils5.zodSchema)(import_v46.z.object({}))),
1470
- outputSchema: mcpServerOutputSchema
1506
+ outputSchema: fileSearchOutputSchema
1471
1507
  });
1472
- var mcpServer = (args) => mcpServerToolFactory(args);
1508
+ var fileSearch = (args) => fileSearchToolFactory(args);
1473
1509
 
1474
- // src/tool/web-search.ts
1510
+ // src/tool/mcp-server.ts
1475
1511
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1476
1512
  var import_v47 = require("zod/v4");
1477
- var webSearchArgsSchema = (0, import_provider_utils6.lazySchema)(
1513
+ var mcpServerArgsSchema = (0, import_provider_utils6.lazySchema)(
1478
1514
  () => (0, import_provider_utils6.zodSchema)(
1479
1515
  import_v47.z.object({
1480
- allowedDomains: import_v47.z.array(import_v47.z.string()).max(5).optional(),
1481
- excludedDomains: import_v47.z.array(import_v47.z.string()).max(5).optional(),
1482
- enableImageUnderstanding: import_v47.z.boolean().optional()
1516
+ serverUrl: import_v47.z.string().describe("The URL of the MCP server"),
1517
+ serverLabel: import_v47.z.string().optional().describe("A label for the MCP server"),
1518
+ serverDescription: import_v47.z.string().optional().describe("Description of the MCP server"),
1519
+ allowedTools: import_v47.z.array(import_v47.z.string()).optional().describe("List of allowed tool names"),
1520
+ headers: import_v47.z.record(import_v47.z.string(), import_v47.z.string()).optional().describe("Custom headers to send"),
1521
+ authorization: import_v47.z.string().optional().describe("Authorization header value")
1483
1522
  })
1484
1523
  )
1485
1524
  );
1486
- var webSearchOutputSchema = (0, import_provider_utils6.lazySchema)(
1525
+ var mcpServerOutputSchema = (0, import_provider_utils6.lazySchema)(
1487
1526
  () => (0, import_provider_utils6.zodSchema)(
1488
1527
  import_v47.z.object({
1489
- query: import_v47.z.string(),
1490
- sources: import_v47.z.array(
1491
- import_v47.z.object({
1492
- title: import_v47.z.string(),
1493
- url: import_v47.z.string(),
1494
- snippet: import_v47.z.string()
1495
- })
1496
- )
1528
+ name: import_v47.z.string(),
1529
+ arguments: import_v47.z.string(),
1530
+ result: import_v47.z.unknown()
1497
1531
  })
1498
1532
  )
1499
1533
  );
1500
- var webSearchToolFactory = (0, import_provider_utils6.createProviderToolFactoryWithOutputSchema)({
1501
- id: "xai.web_search",
1534
+ var mcpServerToolFactory = (0, import_provider_utils6.createProviderToolFactoryWithOutputSchema)({
1535
+ id: "xai.mcp",
1502
1536
  inputSchema: (0, import_provider_utils6.lazySchema)(() => (0, import_provider_utils6.zodSchema)(import_v47.z.object({}))),
1503
- outputSchema: webSearchOutputSchema
1537
+ outputSchema: mcpServerOutputSchema
1504
1538
  });
1505
- var webSearch = (args = {}) => webSearchToolFactory(args);
1539
+ var mcpServer = (args) => mcpServerToolFactory(args);
1506
1540
 
1507
- // src/tool/x-search.ts
1541
+ // src/tool/web-search.ts
1508
1542
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
1509
1543
  var import_v48 = require("zod/v4");
1510
- var xSearchArgsSchema = (0, import_provider_utils7.lazySchema)(
1544
+ var webSearchArgsSchema = (0, import_provider_utils7.lazySchema)(
1511
1545
  () => (0, import_provider_utils7.zodSchema)(
1512
1546
  import_v48.z.object({
1513
- allowedXHandles: import_v48.z.array(import_v48.z.string()).max(10).optional(),
1514
- excludedXHandles: import_v48.z.array(import_v48.z.string()).max(10).optional(),
1515
- fromDate: import_v48.z.string().optional(),
1516
- toDate: import_v48.z.string().optional(),
1517
- enableImageUnderstanding: import_v48.z.boolean().optional(),
1518
- enableVideoUnderstanding: import_v48.z.boolean().optional()
1547
+ allowedDomains: import_v48.z.array(import_v48.z.string()).max(5).optional(),
1548
+ excludedDomains: import_v48.z.array(import_v48.z.string()).max(5).optional(),
1549
+ enableImageUnderstanding: import_v48.z.boolean().optional()
1519
1550
  })
1520
1551
  )
1521
1552
  );
1522
- var xSearchOutputSchema = (0, import_provider_utils7.lazySchema)(
1553
+ var webSearchOutputSchema = (0, import_provider_utils7.lazySchema)(
1523
1554
  () => (0, import_provider_utils7.zodSchema)(
1524
1555
  import_v48.z.object({
1525
1556
  query: import_v48.z.string(),
1526
- posts: import_v48.z.array(
1557
+ sources: import_v48.z.array(
1527
1558
  import_v48.z.object({
1528
- author: import_v48.z.string(),
1529
- text: import_v48.z.string(),
1559
+ title: import_v48.z.string(),
1530
1560
  url: import_v48.z.string(),
1531
- likes: import_v48.z.number()
1561
+ snippet: import_v48.z.string()
1532
1562
  })
1533
1563
  )
1534
1564
  })
1535
1565
  )
1536
1566
  );
1537
- var xSearchToolFactory = (0, import_provider_utils7.createProviderToolFactoryWithOutputSchema)({
1538
- id: "xai.x_search",
1567
+ var webSearchToolFactory = (0, import_provider_utils7.createProviderToolFactoryWithOutputSchema)({
1568
+ id: "xai.web_search",
1539
1569
  inputSchema: (0, import_provider_utils7.lazySchema)(() => (0, import_provider_utils7.zodSchema)(import_v48.z.object({}))),
1570
+ outputSchema: webSearchOutputSchema
1571
+ });
1572
+ var webSearch = (args = {}) => webSearchToolFactory(args);
1573
+
1574
+ // src/tool/x-search.ts
1575
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1576
+ var import_v49 = require("zod/v4");
1577
+ var xSearchArgsSchema = (0, import_provider_utils8.lazySchema)(
1578
+ () => (0, import_provider_utils8.zodSchema)(
1579
+ import_v49.z.object({
1580
+ allowedXHandles: import_v49.z.array(import_v49.z.string()).max(10).optional(),
1581
+ excludedXHandles: import_v49.z.array(import_v49.z.string()).max(10).optional(),
1582
+ fromDate: import_v49.z.string().optional(),
1583
+ toDate: import_v49.z.string().optional(),
1584
+ enableImageUnderstanding: import_v49.z.boolean().optional(),
1585
+ enableVideoUnderstanding: import_v49.z.boolean().optional()
1586
+ })
1587
+ )
1588
+ );
1589
+ var xSearchOutputSchema = (0, import_provider_utils8.lazySchema)(
1590
+ () => (0, import_provider_utils8.zodSchema)(
1591
+ import_v49.z.object({
1592
+ query: import_v49.z.string(),
1593
+ posts: import_v49.z.array(
1594
+ import_v49.z.object({
1595
+ author: import_v49.z.string(),
1596
+ text: import_v49.z.string(),
1597
+ url: import_v49.z.string(),
1598
+ likes: import_v49.z.number()
1599
+ })
1600
+ )
1601
+ })
1602
+ )
1603
+ );
1604
+ var xSearchToolFactory = (0, import_provider_utils8.createProviderToolFactoryWithOutputSchema)({
1605
+ id: "xai.x_search",
1606
+ inputSchema: (0, import_provider_utils8.lazySchema)(() => (0, import_provider_utils8.zodSchema)(import_v49.z.object({}))),
1540
1607
  outputSchema: xSearchOutputSchema
1541
1608
  });
1542
1609
  var xSearch = (args = {}) => xSearchToolFactory(args);
@@ -1558,7 +1625,7 @@ async function prepareResponsesTools({
1558
1625
  if (tool.type === "provider") {
1559
1626
  switch (tool.id) {
1560
1627
  case "xai.web_search": {
1561
- const args = await (0, import_provider_utils8.validateTypes)({
1628
+ const args = await (0, import_provider_utils9.validateTypes)({
1562
1629
  value: tool.args,
1563
1630
  schema: webSearchArgsSchema
1564
1631
  });
@@ -1571,7 +1638,7 @@ async function prepareResponsesTools({
1571
1638
  break;
1572
1639
  }
1573
1640
  case "xai.x_search": {
1574
- const args = await (0, import_provider_utils8.validateTypes)({
1641
+ const args = await (0, import_provider_utils9.validateTypes)({
1575
1642
  value: tool.args,
1576
1643
  schema: xSearchArgsSchema
1577
1644
  });
@@ -1605,13 +1672,19 @@ async function prepareResponsesTools({
1605
1672
  break;
1606
1673
  }
1607
1674
  case "xai.file_search": {
1675
+ const args = await (0, import_provider_utils9.validateTypes)({
1676
+ value: tool.args,
1677
+ schema: fileSearchArgsSchema
1678
+ });
1608
1679
  xaiTools2.push({
1609
- type: "file_search"
1680
+ type: "file_search",
1681
+ vector_store_ids: args.vectorStoreIds,
1682
+ max_num_results: args.maxNumResults
1610
1683
  });
1611
1684
  break;
1612
1685
  }
1613
1686
  case "xai.mcp": {
1614
- const args = await (0, import_provider_utils8.validateTypes)({
1687
+ const args = await (0, import_provider_utils9.validateTypes)({
1615
1688
  value: tool.args,
1616
1689
  schema: mcpServerArgsSchema
1617
1690
  });
@@ -1663,56 +1736,11 @@ async function prepareResponsesTools({
1663
1736
  };
1664
1737
  }
1665
1738
  if (selectedTool.type === "provider") {
1666
- switch (selectedTool.id) {
1667
- case "xai.web_search":
1668
- return {
1669
- tools: xaiTools2,
1670
- toolChoice: { type: "web_search" },
1671
- toolWarnings
1672
- };
1673
- case "xai.x_search":
1674
- return {
1675
- tools: xaiTools2,
1676
- toolChoice: { type: "x_search" },
1677
- toolWarnings
1678
- };
1679
- case "xai.code_execution":
1680
- return {
1681
- tools: xaiTools2,
1682
- toolChoice: { type: "code_interpreter" },
1683
- toolWarnings
1684
- };
1685
- case "xai.view_image":
1686
- return {
1687
- tools: xaiTools2,
1688
- toolChoice: { type: "view_image" },
1689
- toolWarnings
1690
- };
1691
- case "xai.view_x_video":
1692
- return {
1693
- tools: xaiTools2,
1694
- toolChoice: { type: "view_x_video" },
1695
- toolWarnings
1696
- };
1697
- case "xai.file_search":
1698
- return {
1699
- tools: xaiTools2,
1700
- toolChoice: { type: "file_search" },
1701
- toolWarnings
1702
- };
1703
- case "xai.mcp":
1704
- return {
1705
- tools: xaiTools2,
1706
- toolChoice: { type: "mcp" },
1707
- toolWarnings
1708
- };
1709
- default:
1710
- toolWarnings.push({
1711
- type: "unsupported",
1712
- feature: `provider-defined tool ${selectedTool.name}`
1713
- });
1714
- return { tools: xaiTools2, toolChoice: void 0, toolWarnings };
1715
- }
1739
+ toolWarnings.push({
1740
+ type: "unsupported",
1741
+ feature: `toolChoice for server-side tool "${selectedTool.name}"`
1742
+ });
1743
+ return { tools: xaiTools2, toolChoice: void 0, toolWarnings };
1716
1744
  }
1717
1745
  return {
1718
1746
  tools: xaiTools2,
@@ -1754,9 +1782,9 @@ var XaiResponsesLanguageModel = class {
1754
1782
  tools,
1755
1783
  toolChoice
1756
1784
  }) {
1757
- var _a, _b, _c, _d, _e, _f;
1785
+ var _a, _b, _c, _d, _e, _f, _g;
1758
1786
  const warnings = [];
1759
- const options = (_a = await (0, import_provider_utils9.parseProviderOptions)({
1787
+ const options = (_a = await (0, import_provider_utils10.parseProviderOptions)({
1760
1788
  provider: "xai",
1761
1789
  providerOptions,
1762
1790
  schema: xaiResponsesProviderOptions
@@ -1776,6 +1804,9 @@ var XaiResponsesLanguageModel = class {
1776
1804
  const mcpToolName = (_e = tools == null ? void 0 : tools.find(
1777
1805
  (tool) => tool.type === "provider" && tool.id === "xai.mcp"
1778
1806
  )) == null ? void 0 : _e.name;
1807
+ const fileSearchToolName = (_f = tools == null ? void 0 : tools.find(
1808
+ (tool) => tool.type === "provider" && tool.id === "xai.file_search"
1809
+ )) == null ? void 0 : _f.name;
1779
1810
  const { input, inputWarnings } = await convertToXaiResponsesInput({
1780
1811
  prompt,
1781
1812
  store: true
@@ -1790,6 +1821,14 @@ var XaiResponsesLanguageModel = class {
1790
1821
  toolChoice
1791
1822
  });
1792
1823
  warnings.push(...toolWarnings);
1824
+ let include = options.include ? [...options.include] : void 0;
1825
+ if (options.store === false) {
1826
+ if (include == null) {
1827
+ include = ["reasoning.encrypted_content"];
1828
+ } else {
1829
+ include = [...include, "reasoning.encrypted_content"];
1830
+ }
1831
+ }
1793
1832
  const baseArgs = {
1794
1833
  model: this.modelId,
1795
1834
  input,
@@ -1802,7 +1841,7 @@ var XaiResponsesLanguageModel = class {
1802
1841
  format: responseFormat.schema != null ? {
1803
1842
  type: "json_schema",
1804
1843
  strict: true,
1805
- name: (_f = responseFormat.name) != null ? _f : "response",
1844
+ name: (_g = responseFormat.name) != null ? _g : "response",
1806
1845
  description: responseFormat.description,
1807
1846
  schema: responseFormat.schema
1808
1847
  } : { type: "json_object" }
@@ -1812,8 +1851,10 @@ var XaiResponsesLanguageModel = class {
1812
1851
  reasoning: { effort: options.reasoningEffort }
1813
1852
  },
1814
1853
  ...options.store === false && {
1815
- store: options.store,
1816
- include: ["reasoning.encrypted_content"]
1854
+ store: options.store
1855
+ },
1856
+ ...include != null && {
1857
+ include
1817
1858
  },
1818
1859
  ...options.previousResponseId != null && {
1819
1860
  previous_response_id: options.previousResponseId
@@ -1831,29 +1872,31 @@ var XaiResponsesLanguageModel = class {
1831
1872
  webSearchToolName,
1832
1873
  xSearchToolName,
1833
1874
  codeExecutionToolName,
1834
- mcpToolName
1875
+ mcpToolName,
1876
+ fileSearchToolName
1835
1877
  };
1836
1878
  }
1837
1879
  async doGenerate(options) {
1838
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1880
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1839
1881
  const {
1840
1882
  args: body,
1841
1883
  warnings,
1842
1884
  webSearchToolName,
1843
1885
  xSearchToolName,
1844
1886
  codeExecutionToolName,
1845
- mcpToolName
1887
+ mcpToolName,
1888
+ fileSearchToolName
1846
1889
  } = await this.getArgs(options);
1847
1890
  const {
1848
1891
  responseHeaders,
1849
1892
  value: response,
1850
1893
  rawValue: rawResponse
1851
- } = await (0, import_provider_utils9.postJsonToApi)({
1894
+ } = await (0, import_provider_utils10.postJsonToApi)({
1852
1895
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
1853
- headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
1896
+ headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
1854
1897
  body,
1855
1898
  failedResponseHandler: xaiFailedResponseHandler,
1856
- successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
1899
+ successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
1857
1900
  xaiResponsesResponseSchema
1858
1901
  ),
1859
1902
  abortSignal: options.abortSignal,
@@ -1872,18 +1915,43 @@ var XaiResponsesLanguageModel = class {
1872
1915
  "x_thread_fetch"
1873
1916
  ];
1874
1917
  for (const part of response.output) {
1918
+ if (part.type === "file_search_call") {
1919
+ const toolName = fileSearchToolName != null ? fileSearchToolName : "file_search";
1920
+ content.push({
1921
+ type: "tool-call",
1922
+ toolCallId: part.id,
1923
+ toolName,
1924
+ input: "",
1925
+ providerExecuted: true
1926
+ });
1927
+ content.push({
1928
+ type: "tool-result",
1929
+ toolCallId: part.id,
1930
+ toolName,
1931
+ result: {
1932
+ queries: (_b = part.queries) != null ? _b : [],
1933
+ results: (_d = (_c = part.results) == null ? void 0 : _c.map((result) => ({
1934
+ fileId: result.file_id,
1935
+ filename: result.filename,
1936
+ score: result.score,
1937
+ text: result.text
1938
+ }))) != null ? _d : null
1939
+ }
1940
+ });
1941
+ continue;
1942
+ }
1875
1943
  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" || part.type === "mcp_call") {
1876
- let toolName = (_b = part.name) != null ? _b : "";
1877
- if (webSearchSubTools.includes((_c = part.name) != null ? _c : "") || part.type === "web_search_call") {
1944
+ let toolName = (_e = part.name) != null ? _e : "";
1945
+ if (webSearchSubTools.includes((_f = part.name) != null ? _f : "") || part.type === "web_search_call") {
1878
1946
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
1879
- } else if (xSearchSubTools.includes((_d = part.name) != null ? _d : "") || part.type === "x_search_call") {
1947
+ } else if (xSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "x_search_call") {
1880
1948
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
1881
1949
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
1882
1950
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
1883
1951
  } else if (part.type === "mcp_call") {
1884
- toolName = (_e = mcpToolName != null ? mcpToolName : part.name) != null ? _e : "mcp";
1952
+ toolName = (_h = mcpToolName != null ? mcpToolName : part.name) != null ? _h : "mcp";
1885
1953
  }
1886
- const toolInput = part.type === "custom_tool_call" ? (_f = part.input) != null ? _f : "" : part.type === "mcp_call" ? (_g = part.arguments) != null ? _g : "" : (_h = part.arguments) != null ? _h : "";
1954
+ const toolInput = part.type === "custom_tool_call" ? (_i = part.input) != null ? _i : "" : part.type === "mcp_call" ? (_j = part.arguments) != null ? _j : "" : (_k = part.arguments) != null ? _k : "";
1887
1955
  content.push({
1888
1956
  type: "tool-call",
1889
1957
  toolCallId: part.id,
@@ -1910,7 +1978,7 @@ var XaiResponsesLanguageModel = class {
1910
1978
  sourceType: "url",
1911
1979
  id: this.config.generateId(),
1912
1980
  url: annotation.url,
1913
- title: (_i = annotation.title) != null ? _i : annotation.url
1981
+ title: (_l = annotation.title) != null ? _l : annotation.url
1914
1982
  });
1915
1983
  }
1916
1984
  }
@@ -1962,7 +2030,7 @@ var XaiResponsesLanguageModel = class {
1962
2030
  content,
1963
2031
  finishReason: {
1964
2032
  unified: mapXaiResponsesFinishReason(response.status),
1965
- raw: (_j = response.status) != null ? _j : void 0
2033
+ raw: (_m = response.status) != null ? _m : void 0
1966
2034
  },
1967
2035
  usage: response.usage ? convertXaiResponsesUsage(response.usage) : {
1968
2036
  inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
@@ -1985,18 +2053,19 @@ var XaiResponsesLanguageModel = class {
1985
2053
  webSearchToolName,
1986
2054
  xSearchToolName,
1987
2055
  codeExecutionToolName,
1988
- mcpToolName
2056
+ mcpToolName,
2057
+ fileSearchToolName
1989
2058
  } = await this.getArgs(options);
1990
2059
  const body = {
1991
2060
  ...args,
1992
2061
  stream: true
1993
2062
  };
1994
- const { responseHeaders, value: response } = await (0, import_provider_utils9.postJsonToApi)({
2063
+ const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
1995
2064
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
1996
- headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2065
+ headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
1997
2066
  body,
1998
2067
  failedResponseHandler: xaiFailedResponseHandler,
1999
- successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(
2068
+ successfulResponseHandler: (0, import_provider_utils10.createEventSourceResponseHandler)(
2000
2069
  xaiResponsesChunkSchema
2001
2070
  ),
2002
2071
  abortSignal: options.abortSignal,
@@ -2019,7 +2088,7 @@ var XaiResponsesLanguageModel = class {
2019
2088
  controller.enqueue({ type: "stream-start", warnings });
2020
2089
  },
2021
2090
  transform(chunk, controller) {
2022
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2091
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2023
2092
  if (options.includeRawChunks) {
2024
2093
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2025
2094
  }
@@ -2040,6 +2109,7 @@ var XaiResponsesLanguageModel = class {
2040
2109
  }
2041
2110
  if (event.type === "response.reasoning_summary_part.added") {
2042
2111
  const blockId = `reasoning-${event.item_id}`;
2112
+ activeReasoning[event.item_id] = {};
2043
2113
  controller.enqueue({
2044
2114
  type: "reasoning-start",
2045
2115
  id: blockId,
@@ -2132,9 +2202,22 @@ var XaiResponsesLanguageModel = class {
2132
2202
  const part = event.item;
2133
2203
  if (part.type === "reasoning") {
2134
2204
  if (event.type === "response.output_item.done") {
2205
+ const blockId = `reasoning-${part.id}`;
2206
+ if (!(part.id in activeReasoning)) {
2207
+ activeReasoning[part.id] = {};
2208
+ controller.enqueue({
2209
+ type: "reasoning-start",
2210
+ id: blockId,
2211
+ providerMetadata: {
2212
+ xai: {
2213
+ ...part.id && { itemId: part.id }
2214
+ }
2215
+ }
2216
+ });
2217
+ }
2135
2218
  controller.enqueue({
2136
2219
  type: "reasoning-end",
2137
- id: `reasoning-${part.id}`,
2220
+ id: blockId,
2138
2221
  providerMetadata: {
2139
2222
  xai: {
2140
2223
  ...part.encrypted_content && {
@@ -2148,6 +2231,50 @@ var XaiResponsesLanguageModel = class {
2148
2231
  }
2149
2232
  return;
2150
2233
  }
2234
+ if (part.type === "file_search_call") {
2235
+ const toolName = fileSearchToolName != null ? fileSearchToolName : "file_search";
2236
+ if (!seenToolCalls.has(part.id)) {
2237
+ seenToolCalls.add(part.id);
2238
+ controller.enqueue({
2239
+ type: "tool-input-start",
2240
+ id: part.id,
2241
+ toolName
2242
+ });
2243
+ controller.enqueue({
2244
+ type: "tool-input-delta",
2245
+ id: part.id,
2246
+ delta: ""
2247
+ });
2248
+ controller.enqueue({
2249
+ type: "tool-input-end",
2250
+ id: part.id
2251
+ });
2252
+ controller.enqueue({
2253
+ type: "tool-call",
2254
+ toolCallId: part.id,
2255
+ toolName,
2256
+ input: "",
2257
+ providerExecuted: true
2258
+ });
2259
+ }
2260
+ if (event.type === "response.output_item.done") {
2261
+ controller.enqueue({
2262
+ type: "tool-result",
2263
+ toolCallId: part.id,
2264
+ toolName,
2265
+ result: {
2266
+ queries: (_c = part.queries) != null ? _c : [],
2267
+ results: (_e = (_d = part.results) == null ? void 0 : _d.map((result) => ({
2268
+ fileId: result.file_id,
2269
+ filename: result.filename,
2270
+ score: result.score,
2271
+ text: result.text
2272
+ }))) != null ? _e : null
2273
+ }
2274
+ });
2275
+ }
2276
+ return;
2277
+ }
2151
2278
  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" || part.type === "mcp_call") {
2152
2279
  const webSearchSubTools = [
2153
2280
  "web_search",
@@ -2160,17 +2287,17 @@ var XaiResponsesLanguageModel = class {
2160
2287
  "x_semantic_search",
2161
2288
  "x_thread_fetch"
2162
2289
  ];
2163
- let toolName = (_c = part.name) != null ? _c : "";
2164
- if (webSearchSubTools.includes((_d = part.name) != null ? _d : "") || part.type === "web_search_call") {
2290
+ let toolName = (_f = part.name) != null ? _f : "";
2291
+ if (webSearchSubTools.includes((_g = part.name) != null ? _g : "") || part.type === "web_search_call") {
2165
2292
  toolName = webSearchToolName != null ? webSearchToolName : "web_search";
2166
- } else if (xSearchSubTools.includes((_e = part.name) != null ? _e : "") || part.type === "x_search_call") {
2293
+ } else if (xSearchSubTools.includes((_h = part.name) != null ? _h : "") || part.type === "x_search_call") {
2167
2294
  toolName = xSearchToolName != null ? xSearchToolName : "x_search";
2168
2295
  } else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
2169
2296
  toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
2170
2297
  } else if (part.type === "mcp_call") {
2171
- toolName = (_f = mcpToolName != null ? mcpToolName : part.name) != null ? _f : "mcp";
2298
+ toolName = (_i = mcpToolName != null ? mcpToolName : part.name) != null ? _i : "mcp";
2172
2299
  }
2173
- const toolInput = part.type === "custom_tool_call" ? (_g = part.input) != null ? _g : "" : part.type === "mcp_call" ? (_h = part.arguments) != null ? _h : "" : (_i = part.arguments) != null ? _i : "";
2300
+ 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 : "";
2174
2301
  const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
2175
2302
  if (shouldEmit && !seenToolCalls.has(part.id)) {
2176
2303
  seenToolCalls.add(part.id);
@@ -2223,7 +2350,7 @@ var XaiResponsesLanguageModel = class {
2223
2350
  sourceType: "url",
2224
2351
  id: self.config.generateId(),
2225
2352
  url: annotation.url,
2226
- title: (_j = annotation.title) != null ? _j : annotation.url
2353
+ title: (_m = annotation.title) != null ? _m : annotation.url
2227
2354
  });
2228
2355
  }
2229
2356
  }
@@ -2276,44 +2403,44 @@ var XaiResponsesLanguageModel = class {
2276
2403
  };
2277
2404
 
2278
2405
  // src/tool/code-execution.ts
2279
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
2280
- var import_v49 = require("zod/v4");
2281
- var codeExecutionOutputSchema = import_v49.z.object({
2282
- output: import_v49.z.string().describe("the output of the code execution"),
2283
- error: import_v49.z.string().optional().describe("any error that occurred")
2406
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
2407
+ var import_v410 = require("zod/v4");
2408
+ var codeExecutionOutputSchema = import_v410.z.object({
2409
+ output: import_v410.z.string().describe("the output of the code execution"),
2410
+ error: import_v410.z.string().optional().describe("any error that occurred")
2284
2411
  });
2285
- var codeExecutionToolFactory = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
2412
+ var codeExecutionToolFactory = (0, import_provider_utils11.createProviderToolFactoryWithOutputSchema)({
2286
2413
  id: "xai.code_execution",
2287
- inputSchema: import_v49.z.object({}).describe("no input parameters"),
2414
+ inputSchema: import_v410.z.object({}).describe("no input parameters"),
2288
2415
  outputSchema: codeExecutionOutputSchema
2289
2416
  });
2290
2417
  var codeExecution = (args = {}) => codeExecutionToolFactory(args);
2291
2418
 
2292
2419
  // src/tool/view-image.ts
2293
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
2294
- var import_v410 = require("zod/v4");
2295
- var viewImageOutputSchema = import_v410.z.object({
2296
- description: import_v410.z.string().describe("description of the image"),
2297
- objects: import_v410.z.array(import_v410.z.string()).optional().describe("objects detected in the image")
2420
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
2421
+ var import_v411 = require("zod/v4");
2422
+ var viewImageOutputSchema = import_v411.z.object({
2423
+ description: import_v411.z.string().describe("description of the image"),
2424
+ objects: import_v411.z.array(import_v411.z.string()).optional().describe("objects detected in the image")
2298
2425
  });
2299
- var viewImageToolFactory = (0, import_provider_utils11.createProviderToolFactoryWithOutputSchema)({
2426
+ var viewImageToolFactory = (0, import_provider_utils12.createProviderToolFactoryWithOutputSchema)({
2300
2427
  id: "xai.view_image",
2301
- inputSchema: import_v410.z.object({}).describe("no input parameters"),
2428
+ inputSchema: import_v411.z.object({}).describe("no input parameters"),
2302
2429
  outputSchema: viewImageOutputSchema
2303
2430
  });
2304
2431
  var viewImage = (args = {}) => viewImageToolFactory(args);
2305
2432
 
2306
2433
  // src/tool/view-x-video.ts
2307
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
2308
- var import_v411 = require("zod/v4");
2309
- var viewXVideoOutputSchema = import_v411.z.object({
2310
- transcript: import_v411.z.string().optional().describe("transcript of the video"),
2311
- description: import_v411.z.string().describe("description of the video content"),
2312
- duration: import_v411.z.number().optional().describe("duration in seconds")
2434
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
2435
+ var import_v412 = require("zod/v4");
2436
+ var viewXVideoOutputSchema = import_v412.z.object({
2437
+ transcript: import_v412.z.string().optional().describe("transcript of the video"),
2438
+ description: import_v412.z.string().describe("description of the video content"),
2439
+ duration: import_v412.z.number().optional().describe("duration in seconds")
2313
2440
  });
2314
- var viewXVideoToolFactory = (0, import_provider_utils12.createProviderToolFactoryWithOutputSchema)({
2441
+ var viewXVideoToolFactory = (0, import_provider_utils13.createProviderToolFactoryWithOutputSchema)({
2315
2442
  id: "xai.view_x_video",
2316
- inputSchema: import_v411.z.object({}).describe("no input parameters"),
2443
+ inputSchema: import_v412.z.object({}).describe("no input parameters"),
2317
2444
  outputSchema: viewXVideoOutputSchema
2318
2445
  });
2319
2446
  var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
@@ -2321,6 +2448,7 @@ var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
2321
2448
  // src/tool/index.ts
2322
2449
  var xaiTools = {
2323
2450
  codeExecution,
2451
+ fileSearch,
2324
2452
  mcpServer,
2325
2453
  viewImage,
2326
2454
  viewXVideo,
@@ -2329,7 +2457,7 @@ var xaiTools = {
2329
2457
  };
2330
2458
 
2331
2459
  // src/version.ts
2332
- var VERSION = true ? "3.0.38" : "0.0.0-test";
2460
+ var VERSION = true ? "3.0.40" : "0.0.0-test";
2333
2461
 
2334
2462
  // src/xai-provider.ts
2335
2463
  var xaiErrorStructure = {
@@ -2338,12 +2466,12 @@ var xaiErrorStructure = {
2338
2466
  };
2339
2467
  function createXai(options = {}) {
2340
2468
  var _a;
2341
- const baseURL = (0, import_provider_utils13.withoutTrailingSlash)(
2469
+ const baseURL = (0, import_provider_utils14.withoutTrailingSlash)(
2342
2470
  (_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
2343
2471
  );
2344
- const getHeaders = () => (0, import_provider_utils13.withUserAgentSuffix)(
2472
+ const getHeaders = () => (0, import_provider_utils14.withUserAgentSuffix)(
2345
2473
  {
2346
- Authorization: `Bearer ${(0, import_provider_utils13.loadApiKey)({
2474
+ Authorization: `Bearer ${(0, import_provider_utils14.loadApiKey)({
2347
2475
  apiKey: options.apiKey,
2348
2476
  environmentVariableName: "XAI_API_KEY",
2349
2477
  description: "xAI API key"
@@ -2357,7 +2485,7 @@ function createXai(options = {}) {
2357
2485
  provider: "xai.chat",
2358
2486
  baseURL,
2359
2487
  headers: getHeaders,
2360
- generateId: import_provider_utils13.generateId,
2488
+ generateId: import_provider_utils14.generateId,
2361
2489
  fetch: options.fetch
2362
2490
  });
2363
2491
  };
@@ -2366,7 +2494,7 @@ function createXai(options = {}) {
2366
2494
  provider: "xai.responses",
2367
2495
  baseURL,
2368
2496
  headers: getHeaders,
2369
- generateId: import_provider_utils13.generateId,
2497
+ generateId: import_provider_utils14.generateId,
2370
2498
  fetch: options.fetch
2371
2499
  });
2372
2500
  };