@ai-sdk/xai 2.0.52 → 2.0.54

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,18 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 2.0.54
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [fcb9d27]
8
+ - @ai-sdk/openai-compatible@1.0.31
9
+
10
+ ## 2.0.53
11
+
12
+ ### Patch Changes
13
+
14
+ - c23ae93: feat(provider/xai): add image support to responses api
15
+
3
16
  ## 2.0.52
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -34,8 +34,8 @@ module.exports = __toCommonJS(src_exports);
34
34
 
35
35
  // src/xai-provider.ts
36
36
  var import_openai_compatible = require("@ai-sdk/openai-compatible");
37
- var import_provider5 = require("@ai-sdk/provider");
38
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
37
+ var import_provider6 = require("@ai-sdk/provider");
38
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
39
39
 
40
40
  // src/xai-chat-language-model.ts
41
41
  var import_provider3 = require("@ai-sdk/provider");
@@ -862,7 +862,7 @@ var xaiStreamErrorSchema = import_v43.z.object({
862
862
  });
863
863
 
864
864
  // src/responses/xai-responses-language-model.ts
865
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
865
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
866
866
 
867
867
  // src/responses/xai-responses-api.ts
868
868
  var import_v44 = require("zod/v4");
@@ -1190,6 +1190,8 @@ var xaiResponsesProviderOptions = import_v45.z.object({
1190
1190
  });
1191
1191
 
1192
1192
  // src/responses/convert-to-xai-responses-input.ts
1193
+ var import_provider4 = require("@ai-sdk/provider");
1194
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
1193
1195
  async function convertToXaiResponsesInput({
1194
1196
  prompt
1195
1197
  }) {
@@ -1206,18 +1208,23 @@ async function convertToXaiResponsesInput({
1206
1208
  break;
1207
1209
  }
1208
1210
  case "user": {
1209
- let userContent = "";
1211
+ const contentParts = [];
1210
1212
  for (const block of message.content) {
1211
1213
  switch (block.type) {
1212
1214
  case "text": {
1213
- userContent += block.text;
1215
+ contentParts.push({ type: "input_text", text: block.text });
1214
1216
  break;
1215
1217
  }
1216
1218
  case "file": {
1217
- inputWarnings.push({
1218
- type: "other",
1219
- message: `xAI Responses API does not support ${block.type} in user messages`
1220
- });
1219
+ if (block.mediaType.startsWith("image/")) {
1220
+ const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
1221
+ const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils4.convertToBase64)(block.data)}`;
1222
+ contentParts.push({ type: "input_image", image_url: imageUrl });
1223
+ } else {
1224
+ throw new import_provider4.UnsupportedFunctionalityError({
1225
+ functionality: `file part media type ${block.mediaType}`
1226
+ });
1227
+ }
1221
1228
  break;
1222
1229
  }
1223
1230
  default: {
@@ -1231,7 +1238,7 @@ async function convertToXaiResponsesInput({
1231
1238
  }
1232
1239
  input.push({
1233
1240
  role: "user",
1234
- content: userContent
1241
+ content: contentParts
1235
1242
  });
1236
1243
  break;
1237
1244
  }
@@ -1331,14 +1338,14 @@ async function convertToXaiResponsesInput({
1331
1338
  }
1332
1339
 
1333
1340
  // src/responses/xai-responses-prepare-tools.ts
1334
- var import_provider4 = require("@ai-sdk/provider");
1335
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1341
+ var import_provider5 = require("@ai-sdk/provider");
1342
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1336
1343
 
1337
1344
  // src/tool/web-search.ts
1338
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
1345
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1339
1346
  var import_v46 = require("zod/v4");
1340
- var webSearchArgsSchema = (0, import_provider_utils4.lazySchema)(
1341
- () => (0, import_provider_utils4.zodSchema)(
1347
+ var webSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1348
+ () => (0, import_provider_utils5.zodSchema)(
1342
1349
  import_v46.z.object({
1343
1350
  allowedDomains: import_v46.z.array(import_v46.z.string()).max(5).optional(),
1344
1351
  excludedDomains: import_v46.z.array(import_v46.z.string()).max(5).optional(),
@@ -1346,8 +1353,8 @@ var webSearchArgsSchema = (0, import_provider_utils4.lazySchema)(
1346
1353
  })
1347
1354
  )
1348
1355
  );
1349
- var webSearchOutputSchema = (0, import_provider_utils4.lazySchema)(
1350
- () => (0, import_provider_utils4.zodSchema)(
1356
+ var webSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1357
+ () => (0, import_provider_utils5.zodSchema)(
1351
1358
  import_v46.z.object({
1352
1359
  query: import_v46.z.string(),
1353
1360
  sources: import_v46.z.array(
@@ -1360,19 +1367,19 @@ var webSearchOutputSchema = (0, import_provider_utils4.lazySchema)(
1360
1367
  })
1361
1368
  )
1362
1369
  );
1363
- var webSearchToolFactory = (0, import_provider_utils4.createProviderDefinedToolFactoryWithOutputSchema)({
1370
+ var webSearchToolFactory = (0, import_provider_utils5.createProviderDefinedToolFactoryWithOutputSchema)({
1364
1371
  id: "xai.web_search",
1365
1372
  name: "web_search",
1366
- inputSchema: (0, import_provider_utils4.lazySchema)(() => (0, import_provider_utils4.zodSchema)(import_v46.z.object({}))),
1373
+ inputSchema: (0, import_provider_utils5.lazySchema)(() => (0, import_provider_utils5.zodSchema)(import_v46.z.object({}))),
1367
1374
  outputSchema: webSearchOutputSchema
1368
1375
  });
1369
1376
  var webSearch = (args = {}) => webSearchToolFactory(args);
1370
1377
 
1371
1378
  // src/tool/x-search.ts
1372
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1379
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1373
1380
  var import_v47 = require("zod/v4");
1374
- var xSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1375
- () => (0, import_provider_utils5.zodSchema)(
1381
+ var xSearchArgsSchema = (0, import_provider_utils6.lazySchema)(
1382
+ () => (0, import_provider_utils6.zodSchema)(
1376
1383
  import_v47.z.object({
1377
1384
  allowedXHandles: import_v47.z.array(import_v47.z.string()).max(10).optional(),
1378
1385
  excludedXHandles: import_v47.z.array(import_v47.z.string()).max(10).optional(),
@@ -1383,8 +1390,8 @@ var xSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1383
1390
  })
1384
1391
  )
1385
1392
  );
1386
- var xSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1387
- () => (0, import_provider_utils5.zodSchema)(
1393
+ var xSearchOutputSchema = (0, import_provider_utils6.lazySchema)(
1394
+ () => (0, import_provider_utils6.zodSchema)(
1388
1395
  import_v47.z.object({
1389
1396
  query: import_v47.z.string(),
1390
1397
  posts: import_v47.z.array(
@@ -1398,10 +1405,10 @@ var xSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1398
1405
  })
1399
1406
  )
1400
1407
  );
1401
- var xSearchToolFactory = (0, import_provider_utils5.createProviderDefinedToolFactoryWithOutputSchema)({
1408
+ var xSearchToolFactory = (0, import_provider_utils6.createProviderDefinedToolFactoryWithOutputSchema)({
1402
1409
  id: "xai.x_search",
1403
1410
  name: "x_search",
1404
- inputSchema: (0, import_provider_utils5.lazySchema)(() => (0, import_provider_utils5.zodSchema)(import_v47.z.object({}))),
1411
+ inputSchema: (0, import_provider_utils6.lazySchema)(() => (0, import_provider_utils6.zodSchema)(import_v47.z.object({}))),
1405
1412
  outputSchema: xSearchOutputSchema
1406
1413
  });
1407
1414
  var xSearch = (args = {}) => xSearchToolFactory(args);
@@ -1423,7 +1430,7 @@ async function prepareResponsesTools({
1423
1430
  if (tool.type === "provider-defined") {
1424
1431
  switch (tool.id) {
1425
1432
  case "xai.web_search": {
1426
- const args = await (0, import_provider_utils6.validateTypes)({
1433
+ const args = await (0, import_provider_utils7.validateTypes)({
1427
1434
  value: tool.args,
1428
1435
  schema: webSearchArgsSchema
1429
1436
  });
@@ -1436,7 +1443,7 @@ async function prepareResponsesTools({
1436
1443
  break;
1437
1444
  }
1438
1445
  case "xai.x_search": {
1439
- const args = await (0, import_provider_utils6.validateTypes)({
1446
+ const args = await (0, import_provider_utils7.validateTypes)({
1440
1447
  value: tool.args,
1441
1448
  schema: xSearchArgsSchema
1442
1449
  });
@@ -1571,7 +1578,7 @@ async function prepareResponsesTools({
1571
1578
  }
1572
1579
  default: {
1573
1580
  const _exhaustiveCheck = type;
1574
- throw new import_provider4.UnsupportedFunctionalityError({
1581
+ throw new import_provider5.UnsupportedFunctionalityError({
1575
1582
  functionality: `tool choice type: ${_exhaustiveCheck}`
1576
1583
  });
1577
1584
  }
@@ -1605,7 +1612,7 @@ var XaiResponsesLanguageModel = class {
1605
1612
  }) {
1606
1613
  var _a, _b, _c, _d, _e;
1607
1614
  const warnings = [];
1608
- const options = (_a = await (0, import_provider_utils7.parseProviderOptions)({
1615
+ const options = (_a = await (0, import_provider_utils8.parseProviderOptions)({
1609
1616
  provider: "xai",
1610
1617
  providerOptions,
1611
1618
  schema: xaiResponsesProviderOptions
@@ -1695,12 +1702,12 @@ var XaiResponsesLanguageModel = class {
1695
1702
  responseHeaders,
1696
1703
  value: response,
1697
1704
  rawValue: rawResponse
1698
- } = await (0, import_provider_utils7.postJsonToApi)({
1705
+ } = await (0, import_provider_utils8.postJsonToApi)({
1699
1706
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
1700
- headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1707
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1701
1708
  body,
1702
1709
  failedResponseHandler: xaiFailedResponseHandler,
1703
- successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1710
+ successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
1704
1711
  xaiResponsesResponseSchema
1705
1712
  ),
1706
1713
  abortSignal: options.abortSignal,
@@ -1835,12 +1842,12 @@ var XaiResponsesLanguageModel = class {
1835
1842
  ...args,
1836
1843
  stream: true
1837
1844
  };
1838
- const { responseHeaders, value: response } = await (0, import_provider_utils7.postJsonToApi)({
1845
+ const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
1839
1846
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
1840
- headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1847
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1841
1848
  body,
1842
1849
  failedResponseHandler: xaiFailedResponseHandler,
1843
- successfulResponseHandler: (0, import_provider_utils7.createEventSourceResponseHandler)(
1850
+ successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(
1844
1851
  xaiResponsesChunkSchema
1845
1852
  ),
1846
1853
  abortSignal: options.abortSignal,
@@ -2117,13 +2124,13 @@ var XaiResponsesLanguageModel = class {
2117
2124
  };
2118
2125
 
2119
2126
  // src/tool/code-execution.ts
2120
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
2127
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
2121
2128
  var import_v48 = require("zod/v4");
2122
2129
  var codeExecutionOutputSchema = import_v48.z.object({
2123
2130
  output: import_v48.z.string().describe("the output of the code execution"),
2124
2131
  error: import_v48.z.string().optional().describe("any error that occurred")
2125
2132
  });
2126
- var codeExecutionToolFactory = (0, import_provider_utils8.createProviderDefinedToolFactoryWithOutputSchema)({
2133
+ var codeExecutionToolFactory = (0, import_provider_utils9.createProviderDefinedToolFactoryWithOutputSchema)({
2127
2134
  id: "xai.code_execution",
2128
2135
  name: "code_execution",
2129
2136
  inputSchema: import_v48.z.object({}).describe("no input parameters"),
@@ -2132,13 +2139,13 @@ var codeExecutionToolFactory = (0, import_provider_utils8.createProviderDefinedT
2132
2139
  var codeExecution = (args = {}) => codeExecutionToolFactory(args);
2133
2140
 
2134
2141
  // src/tool/view-image.ts
2135
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2142
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
2136
2143
  var import_v49 = require("zod/v4");
2137
2144
  var viewImageOutputSchema = import_v49.z.object({
2138
2145
  description: import_v49.z.string().describe("description of the image"),
2139
2146
  objects: import_v49.z.array(import_v49.z.string()).optional().describe("objects detected in the image")
2140
2147
  });
2141
- var viewImageToolFactory = (0, import_provider_utils9.createProviderDefinedToolFactoryWithOutputSchema)({
2148
+ var viewImageToolFactory = (0, import_provider_utils10.createProviderDefinedToolFactoryWithOutputSchema)({
2142
2149
  id: "xai.view_image",
2143
2150
  name: "view_image",
2144
2151
  inputSchema: import_v49.z.object({}).describe("no input parameters"),
@@ -2147,14 +2154,14 @@ var viewImageToolFactory = (0, import_provider_utils9.createProviderDefinedToolF
2147
2154
  var viewImage = (args = {}) => viewImageToolFactory(args);
2148
2155
 
2149
2156
  // src/tool/view-x-video.ts
2150
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
2157
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
2151
2158
  var import_v410 = require("zod/v4");
2152
2159
  var viewXVideoOutputSchema = import_v410.z.object({
2153
2160
  transcript: import_v410.z.string().optional().describe("transcript of the video"),
2154
2161
  description: import_v410.z.string().describe("description of the video content"),
2155
2162
  duration: import_v410.z.number().optional().describe("duration in seconds")
2156
2163
  });
2157
- var viewXVideoToolFactory = (0, import_provider_utils10.createProviderDefinedToolFactoryWithOutputSchema)({
2164
+ var viewXVideoToolFactory = (0, import_provider_utils11.createProviderDefinedToolFactoryWithOutputSchema)({
2158
2165
  id: "xai.view_x_video",
2159
2166
  name: "view_x_video",
2160
2167
  inputSchema: import_v410.z.object({}).describe("no input parameters"),
@@ -2172,7 +2179,7 @@ var xaiTools = {
2172
2179
  };
2173
2180
 
2174
2181
  // src/version.ts
2175
- var VERSION = true ? "2.0.52" : "0.0.0-test";
2182
+ var VERSION = true ? "2.0.54" : "0.0.0-test";
2176
2183
 
2177
2184
  // src/xai-provider.ts
2178
2185
  var xaiErrorStructure = {
@@ -2181,12 +2188,12 @@ var xaiErrorStructure = {
2181
2188
  };
2182
2189
  function createXai(options = {}) {
2183
2190
  var _a;
2184
- const baseURL = (0, import_provider_utils11.withoutTrailingSlash)(
2191
+ const baseURL = (0, import_provider_utils12.withoutTrailingSlash)(
2185
2192
  (_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
2186
2193
  );
2187
- const getHeaders = () => (0, import_provider_utils11.withUserAgentSuffix)(
2194
+ const getHeaders = () => (0, import_provider_utils12.withUserAgentSuffix)(
2188
2195
  {
2189
- Authorization: `Bearer ${(0, import_provider_utils11.loadApiKey)({
2196
+ Authorization: `Bearer ${(0, import_provider_utils12.loadApiKey)({
2190
2197
  apiKey: options.apiKey,
2191
2198
  environmentVariableName: "XAI_API_KEY",
2192
2199
  description: "xAI API key"
@@ -2200,7 +2207,7 @@ function createXai(options = {}) {
2200
2207
  provider: "xai.chat",
2201
2208
  baseURL,
2202
2209
  headers: getHeaders,
2203
- generateId: import_provider_utils11.generateId,
2210
+ generateId: import_provider_utils12.generateId,
2204
2211
  fetch: options.fetch
2205
2212
  });
2206
2213
  };
@@ -2209,7 +2216,7 @@ function createXai(options = {}) {
2209
2216
  provider: "xai.responses",
2210
2217
  baseURL,
2211
2218
  headers: getHeaders,
2212
- generateId: import_provider_utils11.generateId,
2219
+ generateId: import_provider_utils12.generateId,
2213
2220
  fetch: options.fetch
2214
2221
  });
2215
2222
  };
@@ -2228,7 +2235,7 @@ function createXai(options = {}) {
2228
2235
  provider.chat = createChatLanguageModel;
2229
2236
  provider.responses = createResponsesLanguageModel;
2230
2237
  provider.textEmbeddingModel = (modelId) => {
2231
- throw new import_provider5.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
2238
+ throw new import_provider6.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
2232
2239
  };
2233
2240
  provider.imageModel = createImageModel;
2234
2241
  provider.image = createImageModel;