@ai-sdk/xai 3.0.17 → 3.0.18

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,11 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 9ed771c: feat(provider/xai): add image support to responses api
8
+
3
9
  ## 3.0.17
4
10
 
5
11
  ### 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");
@@ -864,9 +864,11 @@ var xaiStreamErrorSchema = import_v43.z.object({
864
864
  });
865
865
 
866
866
  // src/responses/xai-responses-language-model.ts
867
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
867
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
868
868
 
869
869
  // src/responses/convert-to-xai-responses-input.ts
870
+ var import_provider4 = require("@ai-sdk/provider");
871
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
870
872
  async function convertToXaiResponsesInput({
871
873
  prompt
872
874
  }) {
@@ -883,18 +885,23 @@ async function convertToXaiResponsesInput({
883
885
  break;
884
886
  }
885
887
  case "user": {
886
- let userContent = "";
888
+ const contentParts = [];
887
889
  for (const block of message.content) {
888
890
  switch (block.type) {
889
891
  case "text": {
890
- userContent += block.text;
892
+ contentParts.push({ type: "input_text", text: block.text });
891
893
  break;
892
894
  }
893
895
  case "file": {
894
- inputWarnings.push({
895
- type: "other",
896
- message: `xAI Responses API does not support ${block.type} in user messages`
897
- });
896
+ if (block.mediaType.startsWith("image/")) {
897
+ const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
898
+ const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils4.convertToBase64)(block.data)}`;
899
+ contentParts.push({ type: "input_image", image_url: imageUrl });
900
+ } else {
901
+ throw new import_provider4.UnsupportedFunctionalityError({
902
+ functionality: `file part media type ${block.mediaType}`
903
+ });
904
+ }
898
905
  break;
899
906
  }
900
907
  default: {
@@ -908,7 +915,7 @@ async function convertToXaiResponsesInput({
908
915
  }
909
916
  input.push({
910
917
  role: "user",
911
- content: userContent
918
+ content: contentParts
912
919
  });
913
920
  break;
914
921
  }
@@ -1360,14 +1367,14 @@ var xaiResponsesProviderOptions = import_v45.z.object({
1360
1367
  });
1361
1368
 
1362
1369
  // src/responses/xai-responses-prepare-tools.ts
1363
- var import_provider4 = require("@ai-sdk/provider");
1364
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1370
+ var import_provider5 = require("@ai-sdk/provider");
1371
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1365
1372
 
1366
1373
  // src/tool/web-search.ts
1367
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
1374
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1368
1375
  var import_v46 = require("zod/v4");
1369
- var webSearchArgsSchema = (0, import_provider_utils4.lazySchema)(
1370
- () => (0, import_provider_utils4.zodSchema)(
1376
+ var webSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1377
+ () => (0, import_provider_utils5.zodSchema)(
1371
1378
  import_v46.z.object({
1372
1379
  allowedDomains: import_v46.z.array(import_v46.z.string()).max(5).optional(),
1373
1380
  excludedDomains: import_v46.z.array(import_v46.z.string()).max(5).optional(),
@@ -1375,8 +1382,8 @@ var webSearchArgsSchema = (0, import_provider_utils4.lazySchema)(
1375
1382
  })
1376
1383
  )
1377
1384
  );
1378
- var webSearchOutputSchema = (0, import_provider_utils4.lazySchema)(
1379
- () => (0, import_provider_utils4.zodSchema)(
1385
+ var webSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1386
+ () => (0, import_provider_utils5.zodSchema)(
1380
1387
  import_v46.z.object({
1381
1388
  query: import_v46.z.string(),
1382
1389
  sources: import_v46.z.array(
@@ -1389,18 +1396,18 @@ var webSearchOutputSchema = (0, import_provider_utils4.lazySchema)(
1389
1396
  })
1390
1397
  )
1391
1398
  );
1392
- var webSearchToolFactory = (0, import_provider_utils4.createProviderToolFactoryWithOutputSchema)({
1399
+ var webSearchToolFactory = (0, import_provider_utils5.createProviderToolFactoryWithOutputSchema)({
1393
1400
  id: "xai.web_search",
1394
- inputSchema: (0, import_provider_utils4.lazySchema)(() => (0, import_provider_utils4.zodSchema)(import_v46.z.object({}))),
1401
+ inputSchema: (0, import_provider_utils5.lazySchema)(() => (0, import_provider_utils5.zodSchema)(import_v46.z.object({}))),
1395
1402
  outputSchema: webSearchOutputSchema
1396
1403
  });
1397
1404
  var webSearch = (args = {}) => webSearchToolFactory(args);
1398
1405
 
1399
1406
  // src/tool/x-search.ts
1400
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1407
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1401
1408
  var import_v47 = require("zod/v4");
1402
- var xSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1403
- () => (0, import_provider_utils5.zodSchema)(
1409
+ var xSearchArgsSchema = (0, import_provider_utils6.lazySchema)(
1410
+ () => (0, import_provider_utils6.zodSchema)(
1404
1411
  import_v47.z.object({
1405
1412
  allowedXHandles: import_v47.z.array(import_v47.z.string()).max(10).optional(),
1406
1413
  excludedXHandles: import_v47.z.array(import_v47.z.string()).max(10).optional(),
@@ -1411,8 +1418,8 @@ var xSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1411
1418
  })
1412
1419
  )
1413
1420
  );
1414
- var xSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1415
- () => (0, import_provider_utils5.zodSchema)(
1421
+ var xSearchOutputSchema = (0, import_provider_utils6.lazySchema)(
1422
+ () => (0, import_provider_utils6.zodSchema)(
1416
1423
  import_v47.z.object({
1417
1424
  query: import_v47.z.string(),
1418
1425
  posts: import_v47.z.array(
@@ -1426,9 +1433,9 @@ var xSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1426
1433
  })
1427
1434
  )
1428
1435
  );
1429
- var xSearchToolFactory = (0, import_provider_utils5.createProviderToolFactoryWithOutputSchema)({
1436
+ var xSearchToolFactory = (0, import_provider_utils6.createProviderToolFactoryWithOutputSchema)({
1430
1437
  id: "xai.x_search",
1431
- inputSchema: (0, import_provider_utils5.lazySchema)(() => (0, import_provider_utils5.zodSchema)(import_v47.z.object({}))),
1438
+ inputSchema: (0, import_provider_utils6.lazySchema)(() => (0, import_provider_utils6.zodSchema)(import_v47.z.object({}))),
1432
1439
  outputSchema: xSearchOutputSchema
1433
1440
  });
1434
1441
  var xSearch = (args = {}) => xSearchToolFactory(args);
@@ -1450,7 +1457,7 @@ async function prepareResponsesTools({
1450
1457
  if (tool.type === "provider") {
1451
1458
  switch (tool.id) {
1452
1459
  case "xai.web_search": {
1453
- const args = await (0, import_provider_utils6.validateTypes)({
1460
+ const args = await (0, import_provider_utils7.validateTypes)({
1454
1461
  value: tool.args,
1455
1462
  schema: webSearchArgsSchema
1456
1463
  });
@@ -1463,7 +1470,7 @@ async function prepareResponsesTools({
1463
1470
  break;
1464
1471
  }
1465
1472
  case "xai.x_search": {
1466
- const args = await (0, import_provider_utils6.validateTypes)({
1473
+ const args = await (0, import_provider_utils7.validateTypes)({
1467
1474
  value: tool.args,
1468
1475
  schema: xSearchArgsSchema
1469
1476
  });
@@ -1604,7 +1611,7 @@ async function prepareResponsesTools({
1604
1611
  }
1605
1612
  default: {
1606
1613
  const _exhaustiveCheck = type;
1607
- throw new import_provider4.UnsupportedFunctionalityError({
1614
+ throw new import_provider5.UnsupportedFunctionalityError({
1608
1615
  functionality: `tool choice type: ${_exhaustiveCheck}`
1609
1616
  });
1610
1617
  }
@@ -1638,7 +1645,7 @@ var XaiResponsesLanguageModel = class {
1638
1645
  }) {
1639
1646
  var _a, _b, _c, _d, _e;
1640
1647
  const warnings = [];
1641
- const options = (_a = await (0, import_provider_utils7.parseProviderOptions)({
1648
+ const options = (_a = await (0, import_provider_utils8.parseProviderOptions)({
1642
1649
  provider: "xai",
1643
1650
  providerOptions,
1644
1651
  schema: xaiResponsesProviderOptions
@@ -1725,12 +1732,12 @@ var XaiResponsesLanguageModel = class {
1725
1732
  responseHeaders,
1726
1733
  value: response,
1727
1734
  rawValue: rawResponse
1728
- } = await (0, import_provider_utils7.postJsonToApi)({
1735
+ } = await (0, import_provider_utils8.postJsonToApi)({
1729
1736
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
1730
- headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1737
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1731
1738
  body,
1732
1739
  failedResponseHandler: xaiFailedResponseHandler,
1733
- successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1740
+ successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
1734
1741
  xaiResponsesResponseSchema
1735
1742
  ),
1736
1743
  abortSignal: options.abortSignal,
@@ -1862,12 +1869,12 @@ var XaiResponsesLanguageModel = class {
1862
1869
  ...args,
1863
1870
  stream: true
1864
1871
  };
1865
- const { responseHeaders, value: response } = await (0, import_provider_utils7.postJsonToApi)({
1872
+ const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
1866
1873
  url: `${(_a = this.config.baseURL) != null ? _a : "https://api.x.ai/v1"}/responses`,
1867
- headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1874
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1868
1875
  body,
1869
1876
  failedResponseHandler: xaiFailedResponseHandler,
1870
- successfulResponseHandler: (0, import_provider_utils7.createEventSourceResponseHandler)(
1877
+ successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(
1871
1878
  xaiResponsesChunkSchema
1872
1879
  ),
1873
1880
  abortSignal: options.abortSignal,
@@ -2142,13 +2149,13 @@ var XaiResponsesLanguageModel = class {
2142
2149
  };
2143
2150
 
2144
2151
  // src/tool/code-execution.ts
2145
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
2152
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
2146
2153
  var import_v48 = require("zod/v4");
2147
2154
  var codeExecutionOutputSchema = import_v48.z.object({
2148
2155
  output: import_v48.z.string().describe("the output of the code execution"),
2149
2156
  error: import_v48.z.string().optional().describe("any error that occurred")
2150
2157
  });
2151
- var codeExecutionToolFactory = (0, import_provider_utils8.createProviderToolFactoryWithOutputSchema)({
2158
+ var codeExecutionToolFactory = (0, import_provider_utils9.createProviderToolFactoryWithOutputSchema)({
2152
2159
  id: "xai.code_execution",
2153
2160
  inputSchema: import_v48.z.object({}).describe("no input parameters"),
2154
2161
  outputSchema: codeExecutionOutputSchema
@@ -2156,13 +2163,13 @@ var codeExecutionToolFactory = (0, import_provider_utils8.createProviderToolFact
2156
2163
  var codeExecution = (args = {}) => codeExecutionToolFactory(args);
2157
2164
 
2158
2165
  // src/tool/view-image.ts
2159
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2166
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
2160
2167
  var import_v49 = require("zod/v4");
2161
2168
  var viewImageOutputSchema = import_v49.z.object({
2162
2169
  description: import_v49.z.string().describe("description of the image"),
2163
2170
  objects: import_v49.z.array(import_v49.z.string()).optional().describe("objects detected in the image")
2164
2171
  });
2165
- var viewImageToolFactory = (0, import_provider_utils9.createProviderToolFactoryWithOutputSchema)({
2172
+ var viewImageToolFactory = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
2166
2173
  id: "xai.view_image",
2167
2174
  inputSchema: import_v49.z.object({}).describe("no input parameters"),
2168
2175
  outputSchema: viewImageOutputSchema
@@ -2170,14 +2177,14 @@ var viewImageToolFactory = (0, import_provider_utils9.createProviderToolFactoryW
2170
2177
  var viewImage = (args = {}) => viewImageToolFactory(args);
2171
2178
 
2172
2179
  // src/tool/view-x-video.ts
2173
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
2180
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
2174
2181
  var import_v410 = require("zod/v4");
2175
2182
  var viewXVideoOutputSchema = import_v410.z.object({
2176
2183
  transcript: import_v410.z.string().optional().describe("transcript of the video"),
2177
2184
  description: import_v410.z.string().describe("description of the video content"),
2178
2185
  duration: import_v410.z.number().optional().describe("duration in seconds")
2179
2186
  });
2180
- var viewXVideoToolFactory = (0, import_provider_utils10.createProviderToolFactoryWithOutputSchema)({
2187
+ var viewXVideoToolFactory = (0, import_provider_utils11.createProviderToolFactoryWithOutputSchema)({
2181
2188
  id: "xai.view_x_video",
2182
2189
  inputSchema: import_v410.z.object({}).describe("no input parameters"),
2183
2190
  outputSchema: viewXVideoOutputSchema
@@ -2194,7 +2201,7 @@ var xaiTools = {
2194
2201
  };
2195
2202
 
2196
2203
  // src/version.ts
2197
- var VERSION = true ? "3.0.17" : "0.0.0-test";
2204
+ var VERSION = true ? "3.0.18" : "0.0.0-test";
2198
2205
 
2199
2206
  // src/xai-provider.ts
2200
2207
  var xaiErrorStructure = {
@@ -2203,12 +2210,12 @@ var xaiErrorStructure = {
2203
2210
  };
2204
2211
  function createXai(options = {}) {
2205
2212
  var _a;
2206
- const baseURL = (0, import_provider_utils11.withoutTrailingSlash)(
2213
+ const baseURL = (0, import_provider_utils12.withoutTrailingSlash)(
2207
2214
  (_a = options.baseURL) != null ? _a : "https://api.x.ai/v1"
2208
2215
  );
2209
- const getHeaders = () => (0, import_provider_utils11.withUserAgentSuffix)(
2216
+ const getHeaders = () => (0, import_provider_utils12.withUserAgentSuffix)(
2210
2217
  {
2211
- Authorization: `Bearer ${(0, import_provider_utils11.loadApiKey)({
2218
+ Authorization: `Bearer ${(0, import_provider_utils12.loadApiKey)({
2212
2219
  apiKey: options.apiKey,
2213
2220
  environmentVariableName: "XAI_API_KEY",
2214
2221
  description: "xAI API key"
@@ -2222,7 +2229,7 @@ function createXai(options = {}) {
2222
2229
  provider: "xai.chat",
2223
2230
  baseURL,
2224
2231
  headers: getHeaders,
2225
- generateId: import_provider_utils11.generateId,
2232
+ generateId: import_provider_utils12.generateId,
2226
2233
  fetch: options.fetch
2227
2234
  });
2228
2235
  };
@@ -2231,7 +2238,7 @@ function createXai(options = {}) {
2231
2238
  provider: "xai.responses",
2232
2239
  baseURL,
2233
2240
  headers: getHeaders,
2234
- generateId: import_provider_utils11.generateId,
2241
+ generateId: import_provider_utils12.generateId,
2235
2242
  fetch: options.fetch
2236
2243
  });
2237
2244
  };
@@ -2250,7 +2257,7 @@ function createXai(options = {}) {
2250
2257
  provider.chat = createChatLanguageModel;
2251
2258
  provider.responses = createResponsesLanguageModel;
2252
2259
  provider.embeddingModel = (modelId) => {
2253
- throw new import_provider5.NoSuchModelError({ modelId, modelType: "embeddingModel" });
2260
+ throw new import_provider6.NoSuchModelError({ modelId, modelType: "embeddingModel" });
2254
2261
  };
2255
2262
  provider.textEmbeddingModel = provider.embeddingModel;
2256
2263
  provider.imageModel = createImageModel;