@ai-sdk/xai 3.0.30 → 3.0.32
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 +12 -0
- package/dist/index.d.mts +43 -9
- package/dist/index.d.ts +43 -9
- package/dist/index.js +214 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +200 -71
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +747 -0
- package/package.json +8 -4
- package/src/index.ts +1 -0
- package/src/responses/xai-responses-api.ts +79 -1
- package/src/responses/xai-responses-language-model.ts +30 -4
- package/src/responses/xai-responses-prepare-tools.test.ts +123 -0
- package/src/responses/xai-responses-prepare-tools.ts +12 -0
- package/src/tool/index.ts +3 -1
- package/src/tool/mcp-server.ts +66 -0
- package/src/tool/web-search.ts +1 -1
- package/src/tool/x-search.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(src_exports, {
|
|
|
23
23
|
VERSION: () => VERSION,
|
|
24
24
|
codeExecution: () => codeExecution,
|
|
25
25
|
createXai: () => createXai,
|
|
26
|
+
mcpServer: () => mcpServer,
|
|
26
27
|
viewImage: () => viewImage,
|
|
27
28
|
viewXVideo: () => viewXVideo,
|
|
28
29
|
webSearch: () => webSearch,
|
|
@@ -35,7 +36,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
35
36
|
// src/xai-provider.ts
|
|
36
37
|
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
37
38
|
var import_provider6 = require("@ai-sdk/provider");
|
|
38
|
-
var
|
|
39
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
39
40
|
|
|
40
41
|
// src/xai-chat-language-model.ts
|
|
41
42
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -864,7 +865,7 @@ var xaiStreamErrorSchema = import_v43.z.object({
|
|
|
864
865
|
});
|
|
865
866
|
|
|
866
867
|
// src/responses/xai-responses-language-model.ts
|
|
867
|
-
var
|
|
868
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
868
869
|
|
|
869
870
|
// src/responses/convert-to-xai-responses-input.ts
|
|
870
871
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -1090,6 +1091,15 @@ var toolCallSchema = import_v44.z.object({
|
|
|
1090
1091
|
status: import_v44.z.string(),
|
|
1091
1092
|
action: import_v44.z.any().optional()
|
|
1092
1093
|
});
|
|
1094
|
+
var mcpCallSchema = import_v44.z.object({
|
|
1095
|
+
name: import_v44.z.string().optional(),
|
|
1096
|
+
arguments: import_v44.z.string().optional(),
|
|
1097
|
+
output: import_v44.z.string().optional(),
|
|
1098
|
+
error: import_v44.z.string().optional(),
|
|
1099
|
+
id: import_v44.z.string(),
|
|
1100
|
+
status: import_v44.z.string(),
|
|
1101
|
+
server_label: import_v44.z.string().optional()
|
|
1102
|
+
});
|
|
1093
1103
|
var outputItemSchema = import_v44.z.discriminatedUnion("type", [
|
|
1094
1104
|
import_v44.z.object({
|
|
1095
1105
|
type: import_v44.z.literal("web_search_call"),
|
|
@@ -1119,6 +1129,10 @@ var outputItemSchema = import_v44.z.discriminatedUnion("type", [
|
|
|
1119
1129
|
type: import_v44.z.literal("custom_tool_call"),
|
|
1120
1130
|
...toolCallSchema.shape
|
|
1121
1131
|
}),
|
|
1132
|
+
import_v44.z.object({
|
|
1133
|
+
type: import_v44.z.literal("mcp_call"),
|
|
1134
|
+
...mcpCallSchema.shape
|
|
1135
|
+
}),
|
|
1122
1136
|
import_v44.z.object({
|
|
1123
1137
|
type: import_v44.z.literal("message"),
|
|
1124
1138
|
role: import_v44.z.string(),
|
|
@@ -1337,6 +1351,62 @@ var xaiResponsesChunkSchema = import_v44.z.union([
|
|
|
1337
1351
|
output_index: import_v44.z.number(),
|
|
1338
1352
|
code: import_v44.z.string()
|
|
1339
1353
|
}),
|
|
1354
|
+
import_v44.z.object({
|
|
1355
|
+
type: import_v44.z.literal("response.custom_tool_call_input.delta"),
|
|
1356
|
+
item_id: import_v44.z.string(),
|
|
1357
|
+
output_index: import_v44.z.number(),
|
|
1358
|
+
delta: import_v44.z.string()
|
|
1359
|
+
}),
|
|
1360
|
+
import_v44.z.object({
|
|
1361
|
+
type: import_v44.z.literal("response.custom_tool_call_input.done"),
|
|
1362
|
+
item_id: import_v44.z.string(),
|
|
1363
|
+
output_index: import_v44.z.number(),
|
|
1364
|
+
input: import_v44.z.string()
|
|
1365
|
+
}),
|
|
1366
|
+
import_v44.z.object({
|
|
1367
|
+
type: import_v44.z.literal("response.mcp_call.in_progress"),
|
|
1368
|
+
item_id: import_v44.z.string(),
|
|
1369
|
+
output_index: import_v44.z.number()
|
|
1370
|
+
}),
|
|
1371
|
+
import_v44.z.object({
|
|
1372
|
+
type: import_v44.z.literal("response.mcp_call.executing"),
|
|
1373
|
+
item_id: import_v44.z.string(),
|
|
1374
|
+
output_index: import_v44.z.number()
|
|
1375
|
+
}),
|
|
1376
|
+
import_v44.z.object({
|
|
1377
|
+
type: import_v44.z.literal("response.mcp_call.completed"),
|
|
1378
|
+
item_id: import_v44.z.string(),
|
|
1379
|
+
output_index: import_v44.z.number()
|
|
1380
|
+
}),
|
|
1381
|
+
import_v44.z.object({
|
|
1382
|
+
type: import_v44.z.literal("response.mcp_call.failed"),
|
|
1383
|
+
item_id: import_v44.z.string(),
|
|
1384
|
+
output_index: import_v44.z.number()
|
|
1385
|
+
}),
|
|
1386
|
+
import_v44.z.object({
|
|
1387
|
+
type: import_v44.z.literal("response.mcp_call_arguments.delta"),
|
|
1388
|
+
item_id: import_v44.z.string(),
|
|
1389
|
+
output_index: import_v44.z.number(),
|
|
1390
|
+
delta: import_v44.z.string()
|
|
1391
|
+
}),
|
|
1392
|
+
import_v44.z.object({
|
|
1393
|
+
type: import_v44.z.literal("response.mcp_call_arguments.done"),
|
|
1394
|
+
item_id: import_v44.z.string(),
|
|
1395
|
+
output_index: import_v44.z.number(),
|
|
1396
|
+
arguments: import_v44.z.string().optional()
|
|
1397
|
+
}),
|
|
1398
|
+
import_v44.z.object({
|
|
1399
|
+
type: import_v44.z.literal("response.mcp_call_output.delta"),
|
|
1400
|
+
item_id: import_v44.z.string(),
|
|
1401
|
+
output_index: import_v44.z.number(),
|
|
1402
|
+
delta: import_v44.z.string()
|
|
1403
|
+
}),
|
|
1404
|
+
import_v44.z.object({
|
|
1405
|
+
type: import_v44.z.literal("response.mcp_call_output.done"),
|
|
1406
|
+
item_id: import_v44.z.string(),
|
|
1407
|
+
output_index: import_v44.z.number(),
|
|
1408
|
+
output: import_v44.z.string().optional()
|
|
1409
|
+
}),
|
|
1340
1410
|
import_v44.z.object({
|
|
1341
1411
|
type: import_v44.z.literal("response.done"),
|
|
1342
1412
|
response: xaiResponsesResponseSchema
|
|
@@ -1368,74 +1438,105 @@ var xaiResponsesProviderOptions = import_v45.z.object({
|
|
|
1368
1438
|
|
|
1369
1439
|
// src/responses/xai-responses-prepare-tools.ts
|
|
1370
1440
|
var import_provider5 = require("@ai-sdk/provider");
|
|
1371
|
-
var
|
|
1441
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1372
1442
|
|
|
1373
|
-
// src/tool/
|
|
1443
|
+
// src/tool/mcp-server.ts
|
|
1374
1444
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1375
1445
|
var import_v46 = require("zod/v4");
|
|
1376
|
-
var
|
|
1446
|
+
var mcpServerArgsSchema = (0, import_provider_utils5.lazySchema)(
|
|
1377
1447
|
() => (0, import_provider_utils5.zodSchema)(
|
|
1378
1448
|
import_v46.z.object({
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
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")
|
|
1382
1455
|
})
|
|
1383
1456
|
)
|
|
1384
1457
|
);
|
|
1385
|
-
var
|
|
1458
|
+
var mcpServerOutputSchema = (0, import_provider_utils5.lazySchema)(
|
|
1386
1459
|
() => (0, import_provider_utils5.zodSchema)(
|
|
1387
1460
|
import_v46.z.object({
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
title: import_v46.z.string(),
|
|
1392
|
-
url: import_v46.z.string(),
|
|
1393
|
-
snippet: import_v46.z.string()
|
|
1394
|
-
})
|
|
1395
|
-
)
|
|
1461
|
+
name: import_v46.z.string(),
|
|
1462
|
+
arguments: import_v46.z.string(),
|
|
1463
|
+
result: import_v46.z.unknown()
|
|
1396
1464
|
})
|
|
1397
1465
|
)
|
|
1398
1466
|
);
|
|
1399
|
-
var
|
|
1400
|
-
id: "xai.
|
|
1467
|
+
var mcpServerToolFactory = (0, import_provider_utils5.createProviderToolFactoryWithOutputSchema)({
|
|
1468
|
+
id: "xai.mcp",
|
|
1401
1469
|
inputSchema: (0, import_provider_utils5.lazySchema)(() => (0, import_provider_utils5.zodSchema)(import_v46.z.object({}))),
|
|
1402
|
-
outputSchema:
|
|
1470
|
+
outputSchema: mcpServerOutputSchema
|
|
1403
1471
|
});
|
|
1404
|
-
var
|
|
1472
|
+
var mcpServer = (args) => mcpServerToolFactory(args);
|
|
1405
1473
|
|
|
1406
|
-
// src/tool/
|
|
1474
|
+
// src/tool/web-search.ts
|
|
1407
1475
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1408
1476
|
var import_v47 = require("zod/v4");
|
|
1409
|
-
var
|
|
1477
|
+
var webSearchArgsSchema = (0, import_provider_utils6.lazySchema)(
|
|
1410
1478
|
() => (0, import_provider_utils6.zodSchema)(
|
|
1411
1479
|
import_v47.z.object({
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
toDate: import_v47.z.string().optional(),
|
|
1416
|
-
enableImageUnderstanding: import_v47.z.boolean().optional(),
|
|
1417
|
-
enableVideoUnderstanding: import_v47.z.boolean().optional()
|
|
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()
|
|
1418
1483
|
})
|
|
1419
1484
|
)
|
|
1420
1485
|
);
|
|
1421
|
-
var
|
|
1486
|
+
var webSearchOutputSchema = (0, import_provider_utils6.lazySchema)(
|
|
1422
1487
|
() => (0, import_provider_utils6.zodSchema)(
|
|
1423
1488
|
import_v47.z.object({
|
|
1424
1489
|
query: import_v47.z.string(),
|
|
1425
|
-
|
|
1490
|
+
sources: import_v47.z.array(
|
|
1426
1491
|
import_v47.z.object({
|
|
1427
|
-
|
|
1428
|
-
text: import_v47.z.string(),
|
|
1492
|
+
title: import_v47.z.string(),
|
|
1429
1493
|
url: import_v47.z.string(),
|
|
1430
|
-
|
|
1494
|
+
snippet: import_v47.z.string()
|
|
1431
1495
|
})
|
|
1432
1496
|
)
|
|
1433
1497
|
})
|
|
1434
1498
|
)
|
|
1435
1499
|
);
|
|
1436
|
-
var
|
|
1437
|
-
id: "xai.
|
|
1500
|
+
var webSearchToolFactory = (0, import_provider_utils6.createProviderToolFactoryWithOutputSchema)({
|
|
1501
|
+
id: "xai.web_search",
|
|
1438
1502
|
inputSchema: (0, import_provider_utils6.lazySchema)(() => (0, import_provider_utils6.zodSchema)(import_v47.z.object({}))),
|
|
1503
|
+
outputSchema: webSearchOutputSchema
|
|
1504
|
+
});
|
|
1505
|
+
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
1506
|
+
|
|
1507
|
+
// src/tool/x-search.ts
|
|
1508
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1509
|
+
var import_v48 = require("zod/v4");
|
|
1510
|
+
var xSearchArgsSchema = (0, import_provider_utils7.lazySchema)(
|
|
1511
|
+
() => (0, import_provider_utils7.zodSchema)(
|
|
1512
|
+
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()
|
|
1519
|
+
})
|
|
1520
|
+
)
|
|
1521
|
+
);
|
|
1522
|
+
var xSearchOutputSchema = (0, import_provider_utils7.lazySchema)(
|
|
1523
|
+
() => (0, import_provider_utils7.zodSchema)(
|
|
1524
|
+
import_v48.z.object({
|
|
1525
|
+
query: import_v48.z.string(),
|
|
1526
|
+
posts: import_v48.z.array(
|
|
1527
|
+
import_v48.z.object({
|
|
1528
|
+
author: import_v48.z.string(),
|
|
1529
|
+
text: import_v48.z.string(),
|
|
1530
|
+
url: import_v48.z.string(),
|
|
1531
|
+
likes: import_v48.z.number()
|
|
1532
|
+
})
|
|
1533
|
+
)
|
|
1534
|
+
})
|
|
1535
|
+
)
|
|
1536
|
+
);
|
|
1537
|
+
var xSearchToolFactory = (0, import_provider_utils7.createProviderToolFactoryWithOutputSchema)({
|
|
1538
|
+
id: "xai.x_search",
|
|
1539
|
+
inputSchema: (0, import_provider_utils7.lazySchema)(() => (0, import_provider_utils7.zodSchema)(import_v48.z.object({}))),
|
|
1439
1540
|
outputSchema: xSearchOutputSchema
|
|
1440
1541
|
});
|
|
1441
1542
|
var xSearch = (args = {}) => xSearchToolFactory(args);
|
|
@@ -1457,7 +1558,7 @@ async function prepareResponsesTools({
|
|
|
1457
1558
|
if (tool.type === "provider") {
|
|
1458
1559
|
switch (tool.id) {
|
|
1459
1560
|
case "xai.web_search": {
|
|
1460
|
-
const args = await (0,
|
|
1561
|
+
const args = await (0, import_provider_utils8.validateTypes)({
|
|
1461
1562
|
value: tool.args,
|
|
1462
1563
|
schema: webSearchArgsSchema
|
|
1463
1564
|
});
|
|
@@ -1470,7 +1571,7 @@ async function prepareResponsesTools({
|
|
|
1470
1571
|
break;
|
|
1471
1572
|
}
|
|
1472
1573
|
case "xai.x_search": {
|
|
1473
|
-
const args = await (0,
|
|
1574
|
+
const args = await (0, import_provider_utils8.validateTypes)({
|
|
1474
1575
|
value: tool.args,
|
|
1475
1576
|
schema: xSearchArgsSchema
|
|
1476
1577
|
});
|
|
@@ -1510,8 +1611,18 @@ async function prepareResponsesTools({
|
|
|
1510
1611
|
break;
|
|
1511
1612
|
}
|
|
1512
1613
|
case "xai.mcp": {
|
|
1614
|
+
const args = await (0, import_provider_utils8.validateTypes)({
|
|
1615
|
+
value: tool.args,
|
|
1616
|
+
schema: mcpServerArgsSchema
|
|
1617
|
+
});
|
|
1513
1618
|
xaiTools2.push({
|
|
1514
|
-
type: "mcp"
|
|
1619
|
+
type: "mcp",
|
|
1620
|
+
server_url: args.serverUrl,
|
|
1621
|
+
server_label: args.serverLabel,
|
|
1622
|
+
server_description: args.serverDescription,
|
|
1623
|
+
allowed_tools: args.allowedTools,
|
|
1624
|
+
headers: args.headers,
|
|
1625
|
+
authorization: args.authorization
|
|
1515
1626
|
});
|
|
1516
1627
|
break;
|
|
1517
1628
|
}
|
|
@@ -1643,9 +1754,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
1643
1754
|
tools,
|
|
1644
1755
|
toolChoice
|
|
1645
1756
|
}) {
|
|
1646
|
-
var _a, _b, _c, _d, _e;
|
|
1757
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1647
1758
|
const warnings = [];
|
|
1648
|
-
const options = (_a = await (0,
|
|
1759
|
+
const options = (_a = await (0, import_provider_utils9.parseProviderOptions)({
|
|
1649
1760
|
provider: "xai",
|
|
1650
1761
|
providerOptions,
|
|
1651
1762
|
schema: xaiResponsesProviderOptions
|
|
@@ -1662,6 +1773,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
1662
1773
|
const codeExecutionToolName = (_d = tools == null ? void 0 : tools.find(
|
|
1663
1774
|
(tool) => tool.type === "provider" && tool.id === "xai.code_execution"
|
|
1664
1775
|
)) == null ? void 0 : _d.name;
|
|
1776
|
+
const mcpToolName = (_e = tools == null ? void 0 : tools.find(
|
|
1777
|
+
(tool) => tool.type === "provider" && tool.id === "xai.mcp"
|
|
1778
|
+
)) == null ? void 0 : _e.name;
|
|
1665
1779
|
const { input, inputWarnings } = await convertToXaiResponsesInput({
|
|
1666
1780
|
prompt,
|
|
1667
1781
|
store: true
|
|
@@ -1688,7 +1802,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1688
1802
|
format: responseFormat.schema != null ? {
|
|
1689
1803
|
type: "json_schema",
|
|
1690
1804
|
strict: true,
|
|
1691
|
-
name: (
|
|
1805
|
+
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
1692
1806
|
description: responseFormat.description,
|
|
1693
1807
|
schema: responseFormat.schema
|
|
1694
1808
|
} : { type: "json_object" }
|
|
@@ -1716,28 +1830,30 @@ var XaiResponsesLanguageModel = class {
|
|
|
1716
1830
|
warnings,
|
|
1717
1831
|
webSearchToolName,
|
|
1718
1832
|
xSearchToolName,
|
|
1719
|
-
codeExecutionToolName
|
|
1833
|
+
codeExecutionToolName,
|
|
1834
|
+
mcpToolName
|
|
1720
1835
|
};
|
|
1721
1836
|
}
|
|
1722
1837
|
async doGenerate(options) {
|
|
1723
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1838
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1724
1839
|
const {
|
|
1725
1840
|
args: body,
|
|
1726
1841
|
warnings,
|
|
1727
1842
|
webSearchToolName,
|
|
1728
1843
|
xSearchToolName,
|
|
1729
|
-
codeExecutionToolName
|
|
1844
|
+
codeExecutionToolName,
|
|
1845
|
+
mcpToolName
|
|
1730
1846
|
} = await this.getArgs(options);
|
|
1731
1847
|
const {
|
|
1732
1848
|
responseHeaders,
|
|
1733
1849
|
value: response,
|
|
1734
1850
|
rawValue: rawResponse
|
|
1735
|
-
} = await (0,
|
|
1851
|
+
} = await (0, import_provider_utils9.postJsonToApi)({
|
|
1736
1852
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
1737
|
-
headers: (0,
|
|
1853
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
1738
1854
|
body,
|
|
1739
1855
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1740
|
-
successfulResponseHandler: (0,
|
|
1856
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
|
|
1741
1857
|
xaiResponsesResponseSchema
|
|
1742
1858
|
),
|
|
1743
1859
|
abortSignal: options.abortSignal,
|
|
@@ -1756,7 +1872,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1756
1872
|
"x_thread_fetch"
|
|
1757
1873
|
];
|
|
1758
1874
|
for (const part of response.output) {
|
|
1759
|
-
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") {
|
|
1875
|
+
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") {
|
|
1760
1876
|
let toolName = (_b = part.name) != null ? _b : "";
|
|
1761
1877
|
if (webSearchSubTools.includes((_c = part.name) != null ? _c : "") || part.type === "web_search_call") {
|
|
1762
1878
|
toolName = webSearchToolName != null ? webSearchToolName : "web_search";
|
|
@@ -1764,8 +1880,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
1764
1880
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
1765
1881
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
1766
1882
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
1883
|
+
} else if (part.type === "mcp_call") {
|
|
1884
|
+
toolName = (_e = mcpToolName != null ? mcpToolName : part.name) != null ? _e : "mcp";
|
|
1767
1885
|
}
|
|
1768
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
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 : "";
|
|
1769
1887
|
content.push({
|
|
1770
1888
|
type: "tool-call",
|
|
1771
1889
|
toolCallId: part.id,
|
|
@@ -1792,7 +1910,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1792
1910
|
sourceType: "url",
|
|
1793
1911
|
id: this.config.generateId(),
|
|
1794
1912
|
url: annotation.url,
|
|
1795
|
-
title: (
|
|
1913
|
+
title: (_i = annotation.title) != null ? _i : annotation.url
|
|
1796
1914
|
});
|
|
1797
1915
|
}
|
|
1798
1916
|
}
|
|
@@ -1844,7 +1962,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1844
1962
|
content,
|
|
1845
1963
|
finishReason: {
|
|
1846
1964
|
unified: mapXaiResponsesFinishReason(response.status),
|
|
1847
|
-
raw: (
|
|
1965
|
+
raw: (_j = response.status) != null ? _j : void 0
|
|
1848
1966
|
},
|
|
1849
1967
|
usage: convertXaiResponsesUsage(response.usage),
|
|
1850
1968
|
request: { body },
|
|
@@ -1863,18 +1981,19 @@ var XaiResponsesLanguageModel = class {
|
|
|
1863
1981
|
warnings,
|
|
1864
1982
|
webSearchToolName,
|
|
1865
1983
|
xSearchToolName,
|
|
1866
|
-
codeExecutionToolName
|
|
1984
|
+
codeExecutionToolName,
|
|
1985
|
+
mcpToolName
|
|
1867
1986
|
} = await this.getArgs(options);
|
|
1868
1987
|
const body = {
|
|
1869
1988
|
...args,
|
|
1870
1989
|
stream: true
|
|
1871
1990
|
};
|
|
1872
|
-
const { responseHeaders, value: response } = await (0,
|
|
1991
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils9.postJsonToApi)({
|
|
1873
1992
|
url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
|
|
1874
|
-
headers: (0,
|
|
1993
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
1875
1994
|
body,
|
|
1876
1995
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
1877
|
-
successfulResponseHandler: (0,
|
|
1996
|
+
successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(
|
|
1878
1997
|
xaiResponsesChunkSchema
|
|
1879
1998
|
),
|
|
1880
1999
|
abortSignal: options.abortSignal,
|
|
@@ -1897,7 +2016,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
1897
2016
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1898
2017
|
},
|
|
1899
2018
|
transform(chunk, controller) {
|
|
1900
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
2019
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1901
2020
|
if (options.includeRawChunks) {
|
|
1902
2021
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1903
2022
|
}
|
|
@@ -2003,6 +2122,9 @@ var XaiResponsesLanguageModel = class {
|
|
|
2003
2122
|
}
|
|
2004
2123
|
return;
|
|
2005
2124
|
}
|
|
2125
|
+
if (event.type === "response.custom_tool_call_input.delta" || event.type === "response.custom_tool_call_input.done") {
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2006
2128
|
if (event.type === "response.output_item.added" || event.type === "response.output_item.done") {
|
|
2007
2129
|
const part = event.item;
|
|
2008
2130
|
if (part.type === "reasoning") {
|
|
@@ -2023,7 +2145,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2023
2145
|
}
|
|
2024
2146
|
return;
|
|
2025
2147
|
}
|
|
2026
|
-
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") {
|
|
2148
|
+
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") {
|
|
2027
2149
|
const webSearchSubTools = [
|
|
2028
2150
|
"web_search",
|
|
2029
2151
|
"web_search_with_snippets",
|
|
@@ -2042,8 +2164,10 @@ var XaiResponsesLanguageModel = class {
|
|
|
2042
2164
|
toolName = xSearchToolName != null ? xSearchToolName : "x_search";
|
|
2043
2165
|
} else if (part.name === "code_execution" || part.type === "code_interpreter_call" || part.type === "code_execution_call") {
|
|
2044
2166
|
toolName = codeExecutionToolName != null ? codeExecutionToolName : "code_execution";
|
|
2167
|
+
} else if (part.type === "mcp_call") {
|
|
2168
|
+
toolName = (_f = mcpToolName != null ? mcpToolName : part.name) != null ? _f : "mcp";
|
|
2045
2169
|
}
|
|
2046
|
-
const toolInput = part.type === "custom_tool_call" ? (
|
|
2170
|
+
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 : "";
|
|
2047
2171
|
const shouldEmit = part.type === "custom_tool_call" ? event.type === "response.output_item.done" : !seenToolCalls.has(part.id);
|
|
2048
2172
|
if (shouldEmit && !seenToolCalls.has(part.id)) {
|
|
2049
2173
|
seenToolCalls.add(part.id);
|
|
@@ -2096,7 +2220,7 @@ var XaiResponsesLanguageModel = class {
|
|
|
2096
2220
|
sourceType: "url",
|
|
2097
2221
|
id: self.config.generateId(),
|
|
2098
2222
|
url: annotation.url,
|
|
2099
|
-
title: (
|
|
2223
|
+
title: (_j = annotation.title) != null ? _j : annotation.url
|
|
2100
2224
|
});
|
|
2101
2225
|
}
|
|
2102
2226
|
}
|
|
@@ -2149,44 +2273,44 @@ var XaiResponsesLanguageModel = class {
|
|
|
2149
2273
|
};
|
|
2150
2274
|
|
|
2151
2275
|
// src/tool/code-execution.ts
|
|
2152
|
-
var
|
|
2153
|
-
var
|
|
2154
|
-
var codeExecutionOutputSchema =
|
|
2155
|
-
output:
|
|
2156
|
-
error:
|
|
2276
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
2277
|
+
var import_v49 = require("zod/v4");
|
|
2278
|
+
var codeExecutionOutputSchema = import_v49.z.object({
|
|
2279
|
+
output: import_v49.z.string().describe("the output of the code execution"),
|
|
2280
|
+
error: import_v49.z.string().optional().describe("any error that occurred")
|
|
2157
2281
|
});
|
|
2158
|
-
var codeExecutionToolFactory = (0,
|
|
2282
|
+
var codeExecutionToolFactory = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
|
|
2159
2283
|
id: "xai.code_execution",
|
|
2160
|
-
inputSchema:
|
|
2284
|
+
inputSchema: import_v49.z.object({}).describe("no input parameters"),
|
|
2161
2285
|
outputSchema: codeExecutionOutputSchema
|
|
2162
2286
|
});
|
|
2163
2287
|
var codeExecution = (args = {}) => codeExecutionToolFactory(args);
|
|
2164
2288
|
|
|
2165
2289
|
// src/tool/view-image.ts
|
|
2166
|
-
var
|
|
2167
|
-
var
|
|
2168
|
-
var viewImageOutputSchema =
|
|
2169
|
-
description:
|
|
2170
|
-
objects:
|
|
2290
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
2291
|
+
var import_v410 = require("zod/v4");
|
|
2292
|
+
var viewImageOutputSchema = import_v410.z.object({
|
|
2293
|
+
description: import_v410.z.string().describe("description of the image"),
|
|
2294
|
+
objects: import_v410.z.array(import_v410.z.string()).optional().describe("objects detected in the image")
|
|
2171
2295
|
});
|
|
2172
|
-
var viewImageToolFactory = (0,
|
|
2296
|
+
var viewImageToolFactory = (0, import_provider_utils11.createProviderToolFactoryWithOutputSchema)({
|
|
2173
2297
|
id: "xai.view_image",
|
|
2174
|
-
inputSchema:
|
|
2298
|
+
inputSchema: import_v410.z.object({}).describe("no input parameters"),
|
|
2175
2299
|
outputSchema: viewImageOutputSchema
|
|
2176
2300
|
});
|
|
2177
2301
|
var viewImage = (args = {}) => viewImageToolFactory(args);
|
|
2178
2302
|
|
|
2179
2303
|
// src/tool/view-x-video.ts
|
|
2180
|
-
var
|
|
2181
|
-
var
|
|
2182
|
-
var viewXVideoOutputSchema =
|
|
2183
|
-
transcript:
|
|
2184
|
-
description:
|
|
2185
|
-
duration:
|
|
2304
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
2305
|
+
var import_v411 = require("zod/v4");
|
|
2306
|
+
var viewXVideoOutputSchema = import_v411.z.object({
|
|
2307
|
+
transcript: import_v411.z.string().optional().describe("transcript of the video"),
|
|
2308
|
+
description: import_v411.z.string().describe("description of the video content"),
|
|
2309
|
+
duration: import_v411.z.number().optional().describe("duration in seconds")
|
|
2186
2310
|
});
|
|
2187
|
-
var viewXVideoToolFactory = (0,
|
|
2311
|
+
var viewXVideoToolFactory = (0, import_provider_utils12.createProviderToolFactoryWithOutputSchema)({
|
|
2188
2312
|
id: "xai.view_x_video",
|
|
2189
|
-
inputSchema:
|
|
2313
|
+
inputSchema: import_v411.z.object({}).describe("no input parameters"),
|
|
2190
2314
|
outputSchema: viewXVideoOutputSchema
|
|
2191
2315
|
});
|
|
2192
2316
|
var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
@@ -2194,6 +2318,7 @@ var viewXVideo = (args = {}) => viewXVideoToolFactory(args);
|
|
|
2194
2318
|
// src/tool/index.ts
|
|
2195
2319
|
var xaiTools = {
|
|
2196
2320
|
codeExecution,
|
|
2321
|
+
mcpServer,
|
|
2197
2322
|
viewImage,
|
|
2198
2323
|
viewXVideo,
|
|
2199
2324
|
webSearch,
|
|
@@ -2201,7 +2326,7 @@ var xaiTools = {
|
|
|
2201
2326
|
};
|
|
2202
2327
|
|
|
2203
2328
|
// src/version.ts
|
|
2204
|
-
var VERSION = true ? "3.0.
|
|
2329
|
+
var VERSION = true ? "3.0.32" : "0.0.0-test";
|
|
2205
2330
|
|
|
2206
2331
|
// src/xai-provider.ts
|
|
2207
2332
|
var xaiErrorStructure = {
|
|
@@ -2210,12 +2335,12 @@ var xaiErrorStructure = {
|
|
|
2210
2335
|
};
|
|
2211
2336
|
function createXai(options = {}) {
|
|
2212
2337
|
var _a;
|
|
2213
|
-
const baseURL = (0,
|
|
2338
|
+
const baseURL = (0, import_provider_utils13.withoutTrailingSlash)(
|
|
2214
2339
|
(_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
|
|
2215
2340
|
);
|
|
2216
|
-
const getHeaders = () => (0,
|
|
2341
|
+
const getHeaders = () => (0, import_provider_utils13.withUserAgentSuffix)(
|
|
2217
2342
|
{
|
|
2218
|
-
Authorization: `Bearer ${(0,
|
|
2343
|
+
Authorization: `Bearer ${(0, import_provider_utils13.loadApiKey)({
|
|
2219
2344
|
apiKey: options.apiKey,
|
|
2220
2345
|
environmentVariableName: "XAI_API_KEY",
|
|
2221
2346
|
description: "xAI API key"
|
|
@@ -2229,7 +2354,7 @@ function createXai(options = {}) {
|
|
|
2229
2354
|
provider: "xai.chat",
|
|
2230
2355
|
baseURL,
|
|
2231
2356
|
headers: getHeaders,
|
|
2232
|
-
generateId:
|
|
2357
|
+
generateId: import_provider_utils13.generateId,
|
|
2233
2358
|
fetch: options.fetch
|
|
2234
2359
|
});
|
|
2235
2360
|
};
|
|
@@ -2238,7 +2363,7 @@ function createXai(options = {}) {
|
|
|
2238
2363
|
provider: "xai.responses",
|
|
2239
2364
|
baseURL,
|
|
2240
2365
|
headers: getHeaders,
|
|
2241
|
-
generateId:
|
|
2366
|
+
generateId: import_provider_utils13.generateId,
|
|
2242
2367
|
fetch: options.fetch
|
|
2243
2368
|
});
|
|
2244
2369
|
};
|
|
@@ -2271,6 +2396,7 @@ var xai = createXai();
|
|
|
2271
2396
|
VERSION,
|
|
2272
2397
|
codeExecution,
|
|
2273
2398
|
createXai,
|
|
2399
|
+
mcpServer,
|
|
2274
2400
|
viewImage,
|
|
2275
2401
|
viewXVideo,
|
|
2276
2402
|
webSearch,
|