@ai-sdk/xai 4.0.47 → 4.0.49
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 +13 -0
- package/dist/index.d.ts +56 -16
- package/dist/index.js +77 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/responses/xai-responses-api.ts +25 -0
- package/src/responses/xai-responses-language-model.ts +50 -1
- package/src/tool/web-search.ts +38 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.49
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [90192f1]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.33
|
|
9
|
+
|
|
10
|
+
## 4.0.48
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 6843788: fix(xai): preserve web_search action (query, sources, open_page) in responses tool results
|
|
15
|
+
|
|
3
16
|
## 4.0.47
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -331,11 +331,21 @@ declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) =
|
|
|
331
331
|
}, {}>;
|
|
332
332
|
|
|
333
333
|
declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
action?: {
|
|
335
|
+
type: "search";
|
|
336
|
+
query?: string;
|
|
337
|
+
queries?: string[];
|
|
338
|
+
} | {
|
|
339
|
+
type: "openPage";
|
|
340
|
+
url?: string | null;
|
|
341
|
+
} | {
|
|
342
|
+
type: "findInPage";
|
|
343
|
+
url?: string | null;
|
|
344
|
+
pattern?: string | null;
|
|
345
|
+
};
|
|
346
|
+
sources?: Array<{
|
|
347
|
+
type: "url";
|
|
337
348
|
url: string;
|
|
338
|
-
snippet: string;
|
|
339
349
|
}>;
|
|
340
350
|
}, {
|
|
341
351
|
allowedDomains?: string[];
|
|
@@ -344,11 +354,21 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolF
|
|
|
344
354
|
enableImageUnderstanding?: boolean;
|
|
345
355
|
}, {}>;
|
|
346
356
|
declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
357
|
+
action?: {
|
|
358
|
+
type: "search";
|
|
359
|
+
query?: string;
|
|
360
|
+
queries?: string[];
|
|
361
|
+
} | {
|
|
362
|
+
type: "openPage";
|
|
363
|
+
url?: string | null;
|
|
364
|
+
} | {
|
|
365
|
+
type: "findInPage";
|
|
366
|
+
url?: string | null;
|
|
367
|
+
pattern?: string | null;
|
|
368
|
+
};
|
|
369
|
+
sources?: Array<{
|
|
370
|
+
type: "url";
|
|
350
371
|
url: string;
|
|
351
|
-
snippet: string;
|
|
352
372
|
}>;
|
|
353
373
|
}, {}>;
|
|
354
374
|
|
|
@@ -448,11 +468,21 @@ declare const xaiTools: {
|
|
|
448
468
|
duration?: number | undefined;
|
|
449
469
|
}, {}>;
|
|
450
470
|
webSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
471
|
+
action?: {
|
|
472
|
+
type: "search";
|
|
473
|
+
query?: string;
|
|
474
|
+
queries?: string[];
|
|
475
|
+
} | {
|
|
476
|
+
type: "openPage";
|
|
477
|
+
url?: string | null;
|
|
478
|
+
} | {
|
|
479
|
+
type: "findInPage";
|
|
480
|
+
url?: string | null;
|
|
481
|
+
pattern?: string | null;
|
|
482
|
+
};
|
|
483
|
+
sources?: Array<{
|
|
484
|
+
type: "url";
|
|
454
485
|
url: string;
|
|
455
|
-
snippet: string;
|
|
456
486
|
}>;
|
|
457
487
|
}, {
|
|
458
488
|
allowedDomains?: string[];
|
|
@@ -460,11 +490,21 @@ declare const xaiTools: {
|
|
|
460
490
|
enableImageSearch?: boolean;
|
|
461
491
|
enableImageUnderstanding?: boolean;
|
|
462
492
|
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
493
|
+
action?: {
|
|
494
|
+
type: "search";
|
|
495
|
+
query?: string;
|
|
496
|
+
queries?: string[];
|
|
497
|
+
} | {
|
|
498
|
+
type: "openPage";
|
|
499
|
+
url?: string | null;
|
|
500
|
+
} | {
|
|
501
|
+
type: "findInPage";
|
|
502
|
+
url?: string | null;
|
|
503
|
+
pattern?: string | null;
|
|
504
|
+
};
|
|
505
|
+
sources?: Array<{
|
|
506
|
+
type: "url";
|
|
466
507
|
url: string;
|
|
467
|
-
snippet: string;
|
|
468
508
|
}>;
|
|
469
509
|
}, {}>;
|
|
470
510
|
xSearch: (args?: Parameters<_ai_sdk_provider_utils.ProviderExecutedToolFactory<{}, {
|
package/dist/index.js
CHANGED
|
@@ -1612,6 +1612,29 @@ var toolCallSchema = z8.object({
|
|
|
1612
1612
|
status: z8.string(),
|
|
1613
1613
|
action: z8.any().optional()
|
|
1614
1614
|
});
|
|
1615
|
+
var webSearchWireSourceSchema = z8.object({
|
|
1616
|
+
type: z8.literal("url"),
|
|
1617
|
+
url: z8.string()
|
|
1618
|
+
});
|
|
1619
|
+
var webSearchWireActionSchema = z8.discriminatedUnion("type", [
|
|
1620
|
+
z8.object({
|
|
1621
|
+
type: z8.literal("search"),
|
|
1622
|
+
query: z8.string().nullish(),
|
|
1623
|
+
queries: z8.array(z8.string()).nullish(),
|
|
1624
|
+
sources: z8.array(z8.unknown()).nullish()
|
|
1625
|
+
}),
|
|
1626
|
+
z8.object({
|
|
1627
|
+
type: z8.literal("open_page"),
|
|
1628
|
+
url: z8.string().nullish(),
|
|
1629
|
+
sources: z8.array(z8.unknown()).nullish()
|
|
1630
|
+
}),
|
|
1631
|
+
z8.object({
|
|
1632
|
+
type: z8.literal("find_in_page"),
|
|
1633
|
+
url: z8.string().nullish(),
|
|
1634
|
+
pattern: z8.string().nullish(),
|
|
1635
|
+
sources: z8.array(z8.unknown()).nullish()
|
|
1636
|
+
})
|
|
1637
|
+
]);
|
|
1615
1638
|
var mcpCallSchema = z8.object({
|
|
1616
1639
|
name: z8.string().optional(),
|
|
1617
1640
|
arguments: z8.string().optional(),
|
|
@@ -2197,14 +2220,23 @@ var webSearchArgsSchema = lazySchema5(
|
|
|
2197
2220
|
var webSearchOutputSchema = lazySchema5(
|
|
2198
2221
|
() => zodSchema5(
|
|
2199
2222
|
z13.object({
|
|
2200
|
-
|
|
2201
|
-
|
|
2223
|
+
action: z13.discriminatedUnion("type", [
|
|
2224
|
+
z13.object({
|
|
2225
|
+
type: z13.literal("search"),
|
|
2226
|
+
query: z13.string().optional(),
|
|
2227
|
+
queries: z13.array(z13.string()).optional()
|
|
2228
|
+
}),
|
|
2202
2229
|
z13.object({
|
|
2203
|
-
|
|
2204
|
-
url: z13.string()
|
|
2205
|
-
|
|
2230
|
+
type: z13.literal("openPage"),
|
|
2231
|
+
url: z13.string().nullish()
|
|
2232
|
+
}),
|
|
2233
|
+
z13.object({
|
|
2234
|
+
type: z13.literal("findInPage"),
|
|
2235
|
+
url: z13.string().nullish(),
|
|
2236
|
+
pattern: z13.string().nullish()
|
|
2206
2237
|
})
|
|
2207
|
-
)
|
|
2238
|
+
]).optional(),
|
|
2239
|
+
sources: z13.array(z13.object({ type: z13.literal("url"), url: z13.string() })).optional()
|
|
2208
2240
|
})
|
|
2209
2241
|
)
|
|
2210
2242
|
);
|
|
@@ -2777,6 +2809,14 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2777
2809
|
input: toolInput,
|
|
2778
2810
|
providerExecuted: true
|
|
2779
2811
|
});
|
|
2812
|
+
if (part.type === "web_search_call") {
|
|
2813
|
+
content.push({
|
|
2814
|
+
type: "tool-result",
|
|
2815
|
+
toolCallId: part.id,
|
|
2816
|
+
toolName,
|
|
2817
|
+
result: mapWebSearchAction(part.action)
|
|
2818
|
+
});
|
|
2819
|
+
}
|
|
2780
2820
|
continue;
|
|
2781
2821
|
}
|
|
2782
2822
|
switch (part.type) {
|
|
@@ -3324,7 +3364,7 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3324
3364
|
type: "tool-result",
|
|
3325
3365
|
toolCallId: part.id,
|
|
3326
3366
|
toolName,
|
|
3327
|
-
result: {}
|
|
3367
|
+
result: part.type === "web_search_call" ? mapWebSearchAction(part.action) : {}
|
|
3328
3368
|
});
|
|
3329
3369
|
}
|
|
3330
3370
|
return;
|
|
@@ -3426,6 +3466,35 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
3426
3466
|
};
|
|
3427
3467
|
}
|
|
3428
3468
|
};
|
|
3469
|
+
function mapWebSearchAction(action) {
|
|
3470
|
+
var _a;
|
|
3471
|
+
const parsed = webSearchWireActionSchema.safeParse(action);
|
|
3472
|
+
if (!parsed.success) return {};
|
|
3473
|
+
const a = parsed.data;
|
|
3474
|
+
const sources = (_a = a.sources) == null ? void 0 : _a.flatMap((s) => {
|
|
3475
|
+
const source = webSearchWireSourceSchema.safeParse(s);
|
|
3476
|
+
return source.success ? [source.data] : [];
|
|
3477
|
+
});
|
|
3478
|
+
const sourcesExtra = sources != null && sources.length > 0 ? { sources } : {};
|
|
3479
|
+
switch (a.type) {
|
|
3480
|
+
case "search":
|
|
3481
|
+
return {
|
|
3482
|
+
action: {
|
|
3483
|
+
type: "search",
|
|
3484
|
+
...a.query != null && { query: a.query },
|
|
3485
|
+
...a.queries != null && { queries: a.queries }
|
|
3486
|
+
},
|
|
3487
|
+
...sourcesExtra
|
|
3488
|
+
};
|
|
3489
|
+
case "open_page":
|
|
3490
|
+
return { action: { type: "openPage", url: a.url }, ...sourcesExtra };
|
|
3491
|
+
case "find_in_page":
|
|
3492
|
+
return {
|
|
3493
|
+
action: { type: "findInPage", url: a.url, pattern: a.pattern },
|
|
3494
|
+
...sourcesExtra
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3429
3498
|
|
|
3430
3499
|
// src/responses/xai-responses-batch.ts
|
|
3431
3500
|
var xaiBatchEndpoint = "/v1/responses";
|
|
@@ -4227,7 +4296,7 @@ var xaiTools = {
|
|
|
4227
4296
|
};
|
|
4228
4297
|
|
|
4229
4298
|
// src/version.ts
|
|
4230
|
-
var VERSION = true ? "4.0.
|
|
4299
|
+
var VERSION = true ? "4.0.49" : "0.0.0-test";
|
|
4231
4300
|
|
|
4232
4301
|
// src/files/xai-files.ts
|
|
4233
4302
|
import {
|