@ai-sdk/xai 2.0.90 → 2.0.92

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,19 @@
1
1
  # @ai-sdk/xai
2
2
 
3
+ ## 2.0.92
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [26165ee]
8
+ - @ai-sdk/provider-utils@3.0.36
9
+ - @ai-sdk/openai-compatible@1.0.53
10
+
11
+ ## 2.0.91
12
+
13
+ ### Patch Changes
14
+
15
+ - a2d81eb: fix(xai): preserve web_search action (query, sources, open_page) in responses tool results
16
+
3
17
  ## 2.0.90
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -109,11 +109,21 @@ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) =
109
109
  }>;
110
110
 
111
111
  declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
112
- query: string;
113
- sources: Array<{
114
- title: string;
112
+ action?: {
113
+ type: "search";
114
+ query?: string;
115
+ queries?: string[];
116
+ } | {
117
+ type: "openPage";
118
+ url?: string | null;
119
+ } | {
120
+ type: "findInPage";
121
+ url?: string | null;
122
+ pattern?: string | null;
123
+ };
124
+ sources?: Array<{
125
+ type: "url";
115
126
  url: string;
116
- snippet: string;
117
127
  }>;
118
128
  }, {
119
129
  allowedDomains?: string[];
@@ -121,11 +131,21 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFa
121
131
  enableImageUnderstanding?: boolean;
122
132
  }>;
123
133
  declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
124
- query: string;
125
- sources: Array<{
126
- title: string;
134
+ action?: {
135
+ type: "search";
136
+ query?: string;
137
+ queries?: string[];
138
+ } | {
139
+ type: "openPage";
140
+ url?: string | null;
141
+ } | {
142
+ type: "findInPage";
143
+ url?: string | null;
144
+ pattern?: string | null;
145
+ };
146
+ sources?: Array<{
147
+ type: "url";
127
148
  url: string;
128
- snippet: string;
129
149
  }>;
130
150
  }>;
131
151
 
@@ -180,22 +200,42 @@ declare const xaiTools: {
180
200
  duration?: number | undefined;
181
201
  }>;
182
202
  webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
183
- query: string;
184
- sources: Array<{
185
- title: string;
203
+ action?: {
204
+ type: "search";
205
+ query?: string;
206
+ queries?: string[];
207
+ } | {
208
+ type: "openPage";
209
+ url?: string | null;
210
+ } | {
211
+ type: "findInPage";
212
+ url?: string | null;
213
+ pattern?: string | null;
214
+ };
215
+ sources?: Array<{
216
+ type: "url";
186
217
  url: string;
187
- snippet: string;
188
218
  }>;
189
219
  }, {
190
220
  allowedDomains?: string[];
191
221
  excludedDomains?: string[];
192
222
  enableImageUnderstanding?: boolean;
193
223
  }>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
194
- query: string;
195
- sources: Array<{
196
- title: string;
224
+ action?: {
225
+ type: "search";
226
+ query?: string;
227
+ queries?: string[];
228
+ } | {
229
+ type: "openPage";
230
+ url?: string | null;
231
+ } | {
232
+ type: "findInPage";
233
+ url?: string | null;
234
+ pattern?: string | null;
235
+ };
236
+ sources?: Array<{
237
+ type: "url";
197
238
  url: string;
198
- snippet: string;
199
239
  }>;
200
240
  }>;
201
241
  xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
package/dist/index.d.ts CHANGED
@@ -109,11 +109,21 @@ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) =
109
109
  }>;
110
110
 
111
111
  declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
112
- query: string;
113
- sources: Array<{
114
- title: string;
112
+ action?: {
113
+ type: "search";
114
+ query?: string;
115
+ queries?: string[];
116
+ } | {
117
+ type: "openPage";
118
+ url?: string | null;
119
+ } | {
120
+ type: "findInPage";
121
+ url?: string | null;
122
+ pattern?: string | null;
123
+ };
124
+ sources?: Array<{
125
+ type: "url";
115
126
  url: string;
116
- snippet: string;
117
127
  }>;
118
128
  }, {
119
129
  allowedDomains?: string[];
@@ -121,11 +131,21 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFa
121
131
  enableImageUnderstanding?: boolean;
122
132
  }>;
123
133
  declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
124
- query: string;
125
- sources: Array<{
126
- title: string;
134
+ action?: {
135
+ type: "search";
136
+ query?: string;
137
+ queries?: string[];
138
+ } | {
139
+ type: "openPage";
140
+ url?: string | null;
141
+ } | {
142
+ type: "findInPage";
143
+ url?: string | null;
144
+ pattern?: string | null;
145
+ };
146
+ sources?: Array<{
147
+ type: "url";
127
148
  url: string;
128
- snippet: string;
129
149
  }>;
130
150
  }>;
131
151
 
@@ -180,22 +200,42 @@ declare const xaiTools: {
180
200
  duration?: number | undefined;
181
201
  }>;
182
202
  webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
183
- query: string;
184
- sources: Array<{
185
- title: string;
203
+ action?: {
204
+ type: "search";
205
+ query?: string;
206
+ queries?: string[];
207
+ } | {
208
+ type: "openPage";
209
+ url?: string | null;
210
+ } | {
211
+ type: "findInPage";
212
+ url?: string | null;
213
+ pattern?: string | null;
214
+ };
215
+ sources?: Array<{
216
+ type: "url";
186
217
  url: string;
187
- snippet: string;
188
218
  }>;
189
219
  }, {
190
220
  allowedDomains?: string[];
191
221
  excludedDomains?: string[];
192
222
  enableImageUnderstanding?: boolean;
193
223
  }>>[0]) => _ai_sdk_provider_utils.Tool<Record<string, never>, {
194
- query: string;
195
- sources: Array<{
196
- title: string;
224
+ action?: {
225
+ type: "search";
226
+ query?: string;
227
+ queries?: string[];
228
+ } | {
229
+ type: "openPage";
230
+ url?: string | null;
231
+ } | {
232
+ type: "findInPage";
233
+ url?: string | null;
234
+ pattern?: string | null;
235
+ };
236
+ sources?: Array<{
237
+ type: "url";
197
238
  url: string;
198
- snippet: string;
199
239
  }>;
200
240
  }>;
201
241
  xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<Record<string, never>, {
package/dist/index.js CHANGED
@@ -947,6 +947,29 @@ var toolCallSchema = import_v44.z.object({
947
947
  status: import_v44.z.string(),
948
948
  action: import_v44.z.any().optional()
949
949
  });
950
+ var webSearchWireSourceSchema = import_v44.z.object({
951
+ type: import_v44.z.literal("url"),
952
+ url: import_v44.z.string()
953
+ });
954
+ var webSearchWireActionSchema = import_v44.z.discriminatedUnion("type", [
955
+ import_v44.z.object({
956
+ type: import_v44.z.literal("search"),
957
+ query: import_v44.z.string().nullish(),
958
+ queries: import_v44.z.array(import_v44.z.string()).nullish(),
959
+ sources: import_v44.z.array(import_v44.z.unknown()).nullish()
960
+ }),
961
+ import_v44.z.object({
962
+ type: import_v44.z.literal("open_page"),
963
+ url: import_v44.z.string().nullish(),
964
+ sources: import_v44.z.array(import_v44.z.unknown()).nullish()
965
+ }),
966
+ import_v44.z.object({
967
+ type: import_v44.z.literal("find_in_page"),
968
+ url: import_v44.z.string().nullish(),
969
+ pattern: import_v44.z.string().nullish(),
970
+ sources: import_v44.z.array(import_v44.z.unknown()).nullish()
971
+ })
972
+ ]);
950
973
  var outputItemSchema = import_v44.z.discriminatedUnion("type", [
951
974
  import_v44.z.object({
952
975
  type: import_v44.z.literal("web_search_call"),
@@ -1482,14 +1505,23 @@ var webSearchArgsSchema = (0, import_provider_utils5.lazySchema)(
1482
1505
  var webSearchOutputSchema = (0, import_provider_utils5.lazySchema)(
1483
1506
  () => (0, import_provider_utils5.zodSchema)(
1484
1507
  import_v46.z.object({
1485
- query: import_v46.z.string(),
1486
- sources: import_v46.z.array(
1508
+ action: import_v46.z.discriminatedUnion("type", [
1509
+ import_v46.z.object({
1510
+ type: import_v46.z.literal("search"),
1511
+ query: import_v46.z.string().optional(),
1512
+ queries: import_v46.z.array(import_v46.z.string()).optional()
1513
+ }),
1487
1514
  import_v46.z.object({
1488
- title: import_v46.z.string(),
1489
- url: import_v46.z.string(),
1490
- snippet: import_v46.z.string()
1515
+ type: import_v46.z.literal("openPage"),
1516
+ url: import_v46.z.string().nullish()
1517
+ }),
1518
+ import_v46.z.object({
1519
+ type: import_v46.z.literal("findInPage"),
1520
+ url: import_v46.z.string().nullish(),
1521
+ pattern: import_v46.z.string().nullish()
1491
1522
  })
1492
- )
1523
+ ]).optional(),
1524
+ sources: import_v46.z.array(import_v46.z.object({ type: import_v46.z.literal("url"), url: import_v46.z.string() })).optional()
1493
1525
  })
1494
1526
  )
1495
1527
  );
@@ -1893,6 +1925,14 @@ var XaiResponsesLanguageModel = class {
1893
1925
  input: toolInput,
1894
1926
  providerExecuted: true
1895
1927
  });
1928
+ if (part.type === "web_search_call") {
1929
+ content.push({
1930
+ type: "tool-result",
1931
+ toolCallId: part.id,
1932
+ toolName,
1933
+ result: mapWebSearchAction(part.action)
1934
+ });
1935
+ }
1896
1936
  continue;
1897
1937
  }
1898
1938
  switch (part.type) {
@@ -2271,6 +2311,14 @@ var XaiResponsesLanguageModel = class {
2271
2311
  providerExecuted: true
2272
2312
  });
2273
2313
  }
2314
+ if (event.type === "response.output_item.done") {
2315
+ controller.enqueue({
2316
+ type: "tool-result",
2317
+ toolCallId: part.id,
2318
+ toolName,
2319
+ result: part.type === "web_search_call" ? mapWebSearchAction(part.action) : {}
2320
+ });
2321
+ }
2274
2322
  return;
2275
2323
  }
2276
2324
  if (part.type === "message") {
@@ -2350,6 +2398,35 @@ var XaiResponsesLanguageModel = class {
2350
2398
  };
2351
2399
  }
2352
2400
  };
2401
+ function mapWebSearchAction(action) {
2402
+ var _a;
2403
+ const parsed = webSearchWireActionSchema.safeParse(action);
2404
+ if (!parsed.success) return {};
2405
+ const a = parsed.data;
2406
+ const sources = (_a = a.sources) == null ? void 0 : _a.flatMap((s) => {
2407
+ const source = webSearchWireSourceSchema.safeParse(s);
2408
+ return source.success ? [source.data] : [];
2409
+ });
2410
+ const sourcesExtra = sources != null && sources.length > 0 ? { sources } : {};
2411
+ switch (a.type) {
2412
+ case "search":
2413
+ return {
2414
+ action: {
2415
+ type: "search",
2416
+ ...a.query != null && { query: a.query },
2417
+ ...a.queries != null && { queries: a.queries }
2418
+ },
2419
+ ...sourcesExtra
2420
+ };
2421
+ case "open_page":
2422
+ return { action: { type: "openPage", url: a.url }, ...sourcesExtra };
2423
+ case "find_in_page":
2424
+ return {
2425
+ action: { type: "findInPage", url: a.url, pattern: a.pattern },
2426
+ ...sourcesExtra
2427
+ };
2428
+ }
2429
+ }
2353
2430
 
2354
2431
  // src/tool/code-execution.ts
2355
2432
  var import_provider_utils9 = require("@ai-sdk/provider-utils");
@@ -2407,7 +2484,7 @@ var xaiTools = {
2407
2484
  };
2408
2485
 
2409
2486
  // src/version.ts
2410
- var VERSION = true ? "2.0.90" : "0.0.0-test";
2487
+ var VERSION = true ? "2.0.92" : "0.0.0-test";
2411
2488
 
2412
2489
  // src/xai-provider.ts
2413
2490
  var xaiErrorStructure = {