@ai-sdk/xai 3.0.128 → 3.0.130

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,20 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 3.0.130
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6d44462]
8
+ - Updated dependencies [cc23556]
9
+ - @ai-sdk/openai-compatible@2.0.74
10
+ - @ai-sdk/provider-utils@4.0.50
11
+
12
+ ## 3.0.129
13
+
14
+ ### Patch Changes
15
+
16
+ - 0331d34: fix(xai): preserve web_search action (query, sources, open_page) in responses tool results
17
+
3
18
  ## 3.0.128
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -261,11 +261,21 @@ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) =
261
261
  }>;
262
262
 
263
263
  declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
264
- query: string;
265
- sources: Array<{
266
- title: string;
264
+ action?: {
265
+ type: "search";
266
+ query?: string;
267
+ queries?: string[];
268
+ } | {
269
+ type: "openPage";
270
+ url?: string | null;
271
+ } | {
272
+ type: "findInPage";
273
+ url?: string | null;
274
+ pattern?: string | null;
275
+ };
276
+ sources?: Array<{
277
+ type: "url";
267
278
  url: string;
268
- snippet: string;
269
279
  }>;
270
280
  }, {
271
281
  allowedDomains?: string[];
@@ -274,11 +284,21 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWi
274
284
  enableImageUnderstanding?: boolean;
275
285
  }>;
276
286
  declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
277
- query: string;
278
- sources: Array<{
279
- title: string;
287
+ action?: {
288
+ type: "search";
289
+ query?: string;
290
+ queries?: string[];
291
+ } | {
292
+ type: "openPage";
293
+ url?: string | null;
294
+ } | {
295
+ type: "findInPage";
296
+ url?: string | null;
297
+ pattern?: string | null;
298
+ };
299
+ sources?: Array<{
300
+ type: "url";
280
301
  url: string;
281
- snippet: string;
282
302
  }>;
283
303
  }>;
284
304
 
@@ -369,11 +389,21 @@ declare const xaiTools: {
369
389
  duration?: number | undefined;
370
390
  }>;
371
391
  webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
372
- query: string;
373
- sources: Array<{
374
- title: string;
392
+ action?: {
393
+ type: "search";
394
+ query?: string;
395
+ queries?: string[];
396
+ } | {
397
+ type: "openPage";
398
+ url?: string | null;
399
+ } | {
400
+ type: "findInPage";
401
+ url?: string | null;
402
+ pattern?: string | null;
403
+ };
404
+ sources?: Array<{
405
+ type: "url";
375
406
  url: string;
376
- snippet: string;
377
407
  }>;
378
408
  }, {
379
409
  allowedDomains?: string[];
@@ -381,11 +411,21 @@ declare const xaiTools: {
381
411
  enableImageSearch?: boolean;
382
412
  enableImageUnderstanding?: boolean;
383
413
  }>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
384
- query: string;
385
- sources: Array<{
386
- title: string;
414
+ action?: {
415
+ type: "search";
416
+ query?: string;
417
+ queries?: string[];
418
+ } | {
419
+ type: "openPage";
420
+ url?: string | null;
421
+ } | {
422
+ type: "findInPage";
423
+ url?: string | null;
424
+ pattern?: string | null;
425
+ };
426
+ sources?: Array<{
427
+ type: "url";
387
428
  url: string;
388
- snippet: string;
389
429
  }>;
390
430
  }>;
391
431
  xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
package/dist/index.d.ts CHANGED
@@ -261,11 +261,21 @@ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) =
261
261
  }>;
262
262
 
263
263
  declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
264
- query: string;
265
- sources: Array<{
266
- title: string;
264
+ action?: {
265
+ type: "search";
266
+ query?: string;
267
+ queries?: string[];
268
+ } | {
269
+ type: "openPage";
270
+ url?: string | null;
271
+ } | {
272
+ type: "findInPage";
273
+ url?: string | null;
274
+ pattern?: string | null;
275
+ };
276
+ sources?: Array<{
277
+ type: "url";
267
278
  url: string;
268
- snippet: string;
269
279
  }>;
270
280
  }, {
271
281
  allowedDomains?: string[];
@@ -274,11 +284,21 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderToolFactoryWi
274
284
  enableImageUnderstanding?: boolean;
275
285
  }>;
276
286
  declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, {
277
- query: string;
278
- sources: Array<{
279
- title: string;
287
+ action?: {
288
+ type: "search";
289
+ query?: string;
290
+ queries?: string[];
291
+ } | {
292
+ type: "openPage";
293
+ url?: string | null;
294
+ } | {
295
+ type: "findInPage";
296
+ url?: string | null;
297
+ pattern?: string | null;
298
+ };
299
+ sources?: Array<{
300
+ type: "url";
280
301
  url: string;
281
- snippet: string;
282
302
  }>;
283
303
  }>;
284
304
 
@@ -369,11 +389,21 @@ declare const xaiTools: {
369
389
  duration?: number | undefined;
370
390
  }>;
371
391
  webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
372
- query: string;
373
- sources: Array<{
374
- title: string;
392
+ action?: {
393
+ type: "search";
394
+ query?: string;
395
+ queries?: string[];
396
+ } | {
397
+ type: "openPage";
398
+ url?: string | null;
399
+ } | {
400
+ type: "findInPage";
401
+ url?: string | null;
402
+ pattern?: string | null;
403
+ };
404
+ sources?: Array<{
405
+ type: "url";
375
406
  url: string;
376
- snippet: string;
377
407
  }>;
378
408
  }, {
379
409
  allowedDomains?: string[];
@@ -381,11 +411,21 @@ declare const xaiTools: {
381
411
  enableImageSearch?: boolean;
382
412
  enableImageUnderstanding?: boolean;
383
413
  }>>[0]) => _ai_sdk_provider_utils.Tool<{}, {
384
- query: string;
385
- sources: Array<{
386
- title: string;
414
+ action?: {
415
+ type: "search";
416
+ query?: string;
417
+ queries?: string[];
418
+ } | {
419
+ type: "openPage";
420
+ url?: string | null;
421
+ } | {
422
+ type: "findInPage";
423
+ url?: string | null;
424
+ pattern?: string | null;
425
+ };
426
+ sources?: Array<{
427
+ type: "url";
387
428
  url: string;
388
- snippet: string;
389
429
  }>;
390
430
  }>;
391
431
  xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{}, {
package/dist/index.js CHANGED
@@ -1434,6 +1434,29 @@ var toolCallSchema = import_v47.z.object({
1434
1434
  status: import_v47.z.string(),
1435
1435
  action: import_v47.z.any().optional()
1436
1436
  });
1437
+ var webSearchWireSourceSchema = import_v47.z.object({
1438
+ type: import_v47.z.literal("url"),
1439
+ url: import_v47.z.string()
1440
+ });
1441
+ var webSearchWireActionSchema = import_v47.z.discriminatedUnion("type", [
1442
+ import_v47.z.object({
1443
+ type: import_v47.z.literal("search"),
1444
+ query: import_v47.z.string().nullish(),
1445
+ queries: import_v47.z.array(import_v47.z.string()).nullish(),
1446
+ sources: import_v47.z.array(import_v47.z.unknown()).nullish()
1447
+ }),
1448
+ import_v47.z.object({
1449
+ type: import_v47.z.literal("open_page"),
1450
+ url: import_v47.z.string().nullish(),
1451
+ sources: import_v47.z.array(import_v47.z.unknown()).nullish()
1452
+ }),
1453
+ import_v47.z.object({
1454
+ type: import_v47.z.literal("find_in_page"),
1455
+ url: import_v47.z.string().nullish(),
1456
+ pattern: import_v47.z.string().nullish(),
1457
+ sources: import_v47.z.array(import_v47.z.unknown()).nullish()
1458
+ })
1459
+ ]);
1437
1460
  var mcpCallSchema = import_v47.z.object({
1438
1461
  name: import_v47.z.string().optional(),
1439
1462
  arguments: import_v47.z.string().optional(),
@@ -1949,14 +1972,23 @@ var webSearchArgsSchema = (0, import_provider_utils8.lazySchema)(
1949
1972
  var webSearchOutputSchema = (0, import_provider_utils8.lazySchema)(
1950
1973
  () => (0, import_provider_utils8.zodSchema)(
1951
1974
  import_v411.z.object({
1952
- query: import_v411.z.string(),
1953
- sources: import_v411.z.array(
1975
+ action: import_v411.z.discriminatedUnion("type", [
1976
+ import_v411.z.object({
1977
+ type: import_v411.z.literal("search"),
1978
+ query: import_v411.z.string().optional(),
1979
+ queries: import_v411.z.array(import_v411.z.string()).optional()
1980
+ }),
1954
1981
  import_v411.z.object({
1955
- title: import_v411.z.string(),
1956
- url: import_v411.z.string(),
1957
- snippet: import_v411.z.string()
1982
+ type: import_v411.z.literal("openPage"),
1983
+ url: import_v411.z.string().nullish()
1984
+ }),
1985
+ import_v411.z.object({
1986
+ type: import_v411.z.literal("findInPage"),
1987
+ url: import_v411.z.string().nullish(),
1988
+ pattern: import_v411.z.string().nullish()
1958
1989
  })
1959
- )
1990
+ ]).optional(),
1991
+ sources: import_v411.z.array(import_v411.z.object({ type: import_v411.z.literal("url"), url: import_v411.z.string() })).optional()
1960
1992
  })
1961
1993
  )
1962
1994
  );
@@ -2380,6 +2412,14 @@ var XaiResponsesLanguageModel = class {
2380
2412
  input: toolInput,
2381
2413
  providerExecuted: true
2382
2414
  });
2415
+ if (part.type === "web_search_call") {
2416
+ content.push({
2417
+ type: "tool-result",
2418
+ toolCallId: part.id,
2419
+ toolName,
2420
+ result: mapWebSearchAction(part.action)
2421
+ });
2422
+ }
2383
2423
  continue;
2384
2424
  }
2385
2425
  switch (part.type) {
@@ -2821,7 +2861,7 @@ var XaiResponsesLanguageModel = class {
2821
2861
  type: "tool-result",
2822
2862
  toolCallId: part.id,
2823
2863
  toolName,
2824
- result: {}
2864
+ result: part.type === "web_search_call" ? mapWebSearchAction(part.action) : {}
2825
2865
  });
2826
2866
  }
2827
2867
  return;
@@ -2918,6 +2958,35 @@ var XaiResponsesLanguageModel = class {
2918
2958
  };
2919
2959
  }
2920
2960
  };
2961
+ function mapWebSearchAction(action) {
2962
+ var _a;
2963
+ const parsed = webSearchWireActionSchema.safeParse(action);
2964
+ if (!parsed.success) return {};
2965
+ const a = parsed.data;
2966
+ const sources = (_a = a.sources) == null ? void 0 : _a.flatMap((s) => {
2967
+ const source = webSearchWireSourceSchema.safeParse(s);
2968
+ return source.success ? [source.data] : [];
2969
+ });
2970
+ const sourcesExtra = sources != null && sources.length > 0 ? { sources } : {};
2971
+ switch (a.type) {
2972
+ case "search":
2973
+ return {
2974
+ action: {
2975
+ type: "search",
2976
+ ...a.query != null && { query: a.query },
2977
+ ...a.queries != null && { queries: a.queries }
2978
+ },
2979
+ ...sourcesExtra
2980
+ };
2981
+ case "open_page":
2982
+ return { action: { type: "openPage", url: a.url }, ...sourcesExtra };
2983
+ case "find_in_page":
2984
+ return {
2985
+ action: { type: "findInPage", url: a.url, pattern: a.pattern },
2986
+ ...sourcesExtra
2987
+ };
2988
+ }
2989
+ }
2921
2990
 
2922
2991
  // src/tool/code-execution.ts
2923
2992
  var import_provider_utils12 = require("@ai-sdk/provider-utils");
@@ -2974,7 +3043,7 @@ var xaiTools = {
2974
3043
  };
2975
3044
 
2976
3045
  // src/version.ts
2977
- var VERSION = true ? "3.0.128" : "0.0.0-test";
3046
+ var VERSION = true ? "3.0.130" : "0.0.0-test";
2978
3047
 
2979
3048
  // src/xai-video-model.ts
2980
3049
  var import_provider6 = require("@ai-sdk/provider");