@ai-sdk/gateway 4.0.92 → 4.0.94
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 +17 -0
- package/dist/index.d.ts +129 -8
- package/dist/index.js +257 -209
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +129 -2
- package/package.json +3 -3
- package/src/gateway-provider-options.ts +8 -6
- package/src/gateway-tools.ts +18 -0
- package/src/tool/browserbase-fetch.ts +157 -0
- package/src/tool/browserbase-search.ts +137 -0
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -985,6 +985,132 @@ token-efficient content controls. Deep synthesis modes and generated summaries
|
|
|
985
985
|
are intentionally not exposed yet because they have separate pricing from
|
|
986
986
|
standard Search.
|
|
987
987
|
|
|
988
|
+
#### Browserbase Search
|
|
989
|
+
|
|
990
|
+
The Browserbase Search tool enables models to search the web using [Browserbase's Search API](https://docs.browserbase.com/reference/api/web-search). It is executed by AI Gateway and returns fast, structured search results without opening a browser session.
|
|
991
|
+
|
|
992
|
+
```ts
|
|
993
|
+
import { gateway, generateText } from 'ai';
|
|
994
|
+
|
|
995
|
+
const result = await generateText({
|
|
996
|
+
model: 'openai/gpt-5.6-luna',
|
|
997
|
+
prompt:
|
|
998
|
+
'Find official guidance on traveling with power banks on U.S. flights. Return the most relevant page titles and URLs.',
|
|
999
|
+
tools: {
|
|
1000
|
+
browserbase_search: gateway.tools.browserbaseSearch(),
|
|
1001
|
+
},
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
console.log(result.text);
|
|
1005
|
+
console.log('Tool calls:', JSON.stringify(result.toolCalls, null, 2));
|
|
1006
|
+
console.log('Tool results:', JSON.stringify(result.toolResults, null, 2));
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
You can configure the maximum number of results returned by each search:
|
|
1010
|
+
|
|
1011
|
+
```ts
|
|
1012
|
+
import { gateway, generateText } from 'ai';
|
|
1013
|
+
|
|
1014
|
+
const result = await generateText({
|
|
1015
|
+
model: 'openai/gpt-5.6-luna',
|
|
1016
|
+
prompt:
|
|
1017
|
+
'Find three recent reviews comparing e-readers for outdoor reading. Return their titles and URLs.',
|
|
1018
|
+
tools: {
|
|
1019
|
+
browserbase_search: gateway.tools.browserbaseSearch({
|
|
1020
|
+
numResults: 3,
|
|
1021
|
+
}),
|
|
1022
|
+
},
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
console.log(result.text);
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
The Browserbase Search tool supports this optional configuration option:
|
|
1029
|
+
|
|
1030
|
+
- **numResults** _number_
|
|
1031
|
+
|
|
1032
|
+
Maximum number of search results to return (1-25, default: 10).
|
|
1033
|
+
|
|
1034
|
+
The tool works with both `generateText` and `streamText`.
|
|
1035
|
+
|
|
1036
|
+
#### Browserbase Fetch
|
|
1037
|
+
|
|
1038
|
+
The Browserbase Fetch tool enables models to retrieve page content using [Browserbase's Fetch API](https://docs.browserbase.com/platform/fetch/overview). It is a lightweight option for pages that do not require JavaScript execution or browser interaction, and it supports raw, Markdown, and schema-driven JSON output.
|
|
1039
|
+
|
|
1040
|
+
```ts
|
|
1041
|
+
import { gateway, generateText } from 'ai';
|
|
1042
|
+
|
|
1043
|
+
const result = await generateText({
|
|
1044
|
+
model: 'openai/gpt-5.6-luna',
|
|
1045
|
+
prompt:
|
|
1046
|
+
'Fetch https://www.nps.gov/yose/planyourvisit/halfdome.htm and summarize the permit requirements and main safety warnings.',
|
|
1047
|
+
tools: {
|
|
1048
|
+
browserbase_fetch: gateway.tools.browserbaseFetch(),
|
|
1049
|
+
},
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
console.log(result.text);
|
|
1053
|
+
console.log('Tool calls:', JSON.stringify(result.toolCalls, null, 2));
|
|
1054
|
+
console.log('Tool results:', JSON.stringify(result.toolResults, null, 2));
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
You can configure the output format and request behavior. For example, use JSON extraction to return content matching a JSON Schema:
|
|
1058
|
+
|
|
1059
|
+
```ts
|
|
1060
|
+
import { gateway, generateText } from 'ai';
|
|
1061
|
+
|
|
1062
|
+
const result = await generateText({
|
|
1063
|
+
model: 'openai/gpt-5.6-luna',
|
|
1064
|
+
prompt:
|
|
1065
|
+
'Fetch https://www.nps.gov/yose/planyourvisit/halfdome.htm and extract its page title, whether a permit is required, and three safety tips.',
|
|
1066
|
+
tools: {
|
|
1067
|
+
browserbase_fetch: gateway.tools.browserbaseFetch({
|
|
1068
|
+
allowRedirects: true,
|
|
1069
|
+
format: 'json',
|
|
1070
|
+
schema: {
|
|
1071
|
+
type: 'object',
|
|
1072
|
+
properties: {
|
|
1073
|
+
pageTitle: { type: 'string' },
|
|
1074
|
+
permitRequired: { type: 'boolean' },
|
|
1075
|
+
safetyTips: {
|
|
1076
|
+
type: 'array',
|
|
1077
|
+
items: { type: 'string' },
|
|
1078
|
+
maxItems: 3,
|
|
1079
|
+
},
|
|
1080
|
+
},
|
|
1081
|
+
required: ['pageTitle', 'permitRequired', 'safetyTips'],
|
|
1082
|
+
},
|
|
1083
|
+
}),
|
|
1084
|
+
},
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
console.log(result.text);
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
The Browserbase Fetch tool supports these optional configuration options:
|
|
1091
|
+
|
|
1092
|
+
- **format** _'raw' | 'markdown' | 'json'_
|
|
1093
|
+
|
|
1094
|
+
Output format for the fetched content. `raw` returns the upstream response body unchanged and is the default. `markdown` converts the page to Markdown. `json` performs structured extraction and requires `schema`.
|
|
1095
|
+
|
|
1096
|
+
- **schema** _object_
|
|
1097
|
+
|
|
1098
|
+
JSON Schema describing the desired structured content. Only used when `format` is `json`.
|
|
1099
|
+
|
|
1100
|
+
- **allowRedirects** _boolean_
|
|
1101
|
+
|
|
1102
|
+
Follow HTTP redirects. Defaults to `false`.
|
|
1103
|
+
|
|
1104
|
+
- **proxies** _boolean_
|
|
1105
|
+
|
|
1106
|
+
Route the request through Browserbase's proxy network. Defaults to `false`.
|
|
1107
|
+
|
|
1108
|
+
- **allowInsecureSsl** _boolean_
|
|
1109
|
+
|
|
1110
|
+
Bypass TLS certificate verification. Defaults to `false`; only enable it for trusted hosts.
|
|
1111
|
+
|
|
1112
|
+
The Fetch API does not execute JavaScript. Use a browser session for interactive or JavaScript-rendered pages. The tool works with both `generateText` and `streamText`.
|
|
1113
|
+
|
|
988
1114
|
#### Tako Search
|
|
989
1115
|
|
|
990
1116
|
The Tako Search tool enables models to search the web and Tako's curated knowledge graph in a single call using [Tako's Search API](https://docs.tako.com/documentation/integrating-tako/search/overview). This tool is executed by the AI Gateway and returns token-efficient web excerpts, plus knowledge-graph results that carry structured data, premium source attribution, and an embed-ready visualization.
|
|
@@ -1390,13 +1516,14 @@ The following gateway provider options are available:
|
|
|
1390
1516
|
|
|
1391
1517
|
The unique identifier for the entity against which quota is tracked. Used for quota management and enforcement purposes.
|
|
1392
1518
|
|
|
1393
|
-
- **has** _Array<'implicit-caching' | 'reasoning' | 'tool-use' | 'vision' | `quantization:${string}` | `!quantization:${string}`>_
|
|
1519
|
+
- **has** _Array<'implicit-caching' | 'reasoning' | 'structured-output' | 'tool-use' | 'vision' | `quantization:${string}` | `!quantization:${string}`>_
|
|
1394
1520
|
|
|
1395
1521
|
Restricts routing to provider models that have all of the specified capabilities. Applies to both BYOK and system credentials, since the capability is a property of the model rather than the credential. If no provider model for the requested model satisfies the capabilities, the request fails. Unsupported values are rejected.
|
|
1396
1522
|
|
|
1397
1523
|
Supported capabilities:
|
|
1398
1524
|
- `'implicit-caching'` — models that perform automatic (implicit) prompt caching.
|
|
1399
1525
|
- `'reasoning'` — models that support reasoning.
|
|
1526
|
+
- `'structured-output'` — models that support schema-constrained output.
|
|
1400
1527
|
- `'tool-use'` — models that support tool calling.
|
|
1401
1528
|
- `'vision'` — models that accept image input.
|
|
1402
1529
|
|
|
@@ -1540,7 +1667,7 @@ const { text } = await generateText({
|
|
|
1540
1667
|
|
|
1541
1668
|
#### Filtering by Model Capability
|
|
1542
1669
|
|
|
1543
|
-
Set `has` to restrict routing to provider models that have the specified capabilities. This applies to both BYOK and system credentials, since the capability is a property of the model rather than the credential. `'implicit-caching'` limits routing to models that perform automatic prompt caching, `'vision'` limits routing to models that accept image input, `'reasoning'` limits routing to models that support reasoning, and `'tool-use'` limits routing to models that support tool calling. Weight-format conditions (`'quantization:fp8'` to require, `'!quantization:fp8'` to exclude) limit routing by the serving provider's recorded weight format. If no provider model for the requested model satisfies the capabilities, the request fails.
|
|
1670
|
+
Set `has` to restrict routing to provider models that have the specified capabilities. This applies to both BYOK and system credentials, since the capability is a property of the model rather than the credential. `'implicit-caching'` limits routing to models that perform automatic prompt caching, `'vision'` limits routing to models that accept image input, `'reasoning'` limits routing to models that support reasoning, `'structured-output'` limits routing to models that support schema-constrained output, and `'tool-use'` limits routing to models that support tool calling. Weight-format conditions (`'quantization:fp8'` to require, `'!quantization:fp8'` to exclude) limit routing by the serving provider's recorded weight format. If no provider model for the requested model satisfies the capabilities, the request fails.
|
|
1544
1671
|
|
|
1545
1672
|
```ts
|
|
1546
1673
|
import type { GatewayProviderOptions } from '@ai-sdk/gateway';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gateway",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.94",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ai-sdk/provider": "4.0.18",
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.49",
|
|
35
35
|
"@vercel/oidc": "3.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@ai-sdk/test-server": "2.0.
|
|
38
|
+
"@ai-sdk/test-server": "2.0.2",
|
|
39
39
|
"@types/node": "22.19.19",
|
|
40
40
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
41
41
|
"tsup": "^8.5.1",
|
|
@@ -19,16 +19,18 @@ export type GatewayProviderOptions = {
|
|
|
19
19
|
* Restrict routing to provider models that satisfy every given entry.
|
|
20
20
|
*
|
|
21
21
|
* Entries are capability tags (`'implicit-caching'`, `'reasoning'`,
|
|
22
|
-
* `'tool-use'`, `'vision'`
|
|
23
|
-
*
|
|
24
|
-
* `'
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* `'tool-use'`, `'vision'` (image input), `'structured-output'`
|
|
23
|
+
* (schema-constrained output)) or weight-format conditions:
|
|
24
|
+
* `'quantization:fp8'` requires the serving provider to report that weight
|
|
25
|
+
* format, `'!quantization:fp8'` excludes it (providers with no recorded
|
|
26
|
+
* format still pass an exclusion). Format values are an open space but must
|
|
27
|
+
* match `[a-zA-Z0-9._-]{1,32}` and compare case-insensitively. Unknown
|
|
28
|
+
* capability names are rejected by the Gateway with a 400.
|
|
28
29
|
*/
|
|
29
30
|
has?: Array<
|
|
30
31
|
| 'implicit-caching'
|
|
31
32
|
| 'reasoning'
|
|
33
|
+
| 'structured-output'
|
|
32
34
|
| 'tool-use'
|
|
33
35
|
| 'vision'
|
|
34
36
|
| `quantization:${string}`
|
package/src/gateway-tools.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { browserbaseFetch } from './tool/browserbase-fetch';
|
|
2
|
+
import { browserbaseSearch } from './tool/browserbase-search';
|
|
1
3
|
import { exaSearch } from './tool/exa-search';
|
|
2
4
|
import { parallelSearch } from './tool/parallel-search';
|
|
3
5
|
import { perplexitySearch } from './tool/perplexity-search';
|
|
@@ -7,6 +9,22 @@ import { takoSearch } from './tool/tako-search';
|
|
|
7
9
|
* Gateway-specific provider-defined tools.
|
|
8
10
|
*/
|
|
9
11
|
export const gatewayTools = {
|
|
12
|
+
/**
|
|
13
|
+
* Fetch page content using Browserbase's lightweight Fetch API.
|
|
14
|
+
*
|
|
15
|
+
* Supports raw, Markdown, and schema-driven JSON output as well as redirects,
|
|
16
|
+
* proxy routing, and TLS controls.
|
|
17
|
+
*/
|
|
18
|
+
browserbaseFetch,
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Search the web using Browserbase's Search API for fast, structured results.
|
|
22
|
+
*
|
|
23
|
+
* Returns titles, URLs, and available publication metadata without requiring
|
|
24
|
+
* a browser session.
|
|
25
|
+
*/
|
|
26
|
+
browserbaseSearch,
|
|
27
|
+
|
|
10
28
|
/**
|
|
11
29
|
* Search the web using Exa for current information and token-efficient
|
|
12
30
|
* excerpts optimized for agent workflows.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from '../zod';
|
|
7
|
+
|
|
8
|
+
export type BrowserbaseFetchFormat = 'raw' | 'json' | 'markdown';
|
|
9
|
+
|
|
10
|
+
export interface BrowserbaseFetchConfig {
|
|
11
|
+
/** Whether to follow HTTP redirects (default: false). */
|
|
12
|
+
allowRedirects?: boolean;
|
|
13
|
+
/** Whether to bypass TLS certificate verification (default: false). */
|
|
14
|
+
allowInsecureSsl?: boolean;
|
|
15
|
+
/** Whether to route the request through Browserbase proxies (default: false). */
|
|
16
|
+
proxies?: boolean;
|
|
17
|
+
/** Output format for the response content (default: raw). */
|
|
18
|
+
format?: BrowserbaseFetchFormat;
|
|
19
|
+
/**
|
|
20
|
+
* JSON Schema describing the desired response content. Only used when format
|
|
21
|
+
* is json.
|
|
22
|
+
*/
|
|
23
|
+
schema?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface BrowserbaseFetchInput {
|
|
27
|
+
/** URL of the page to fetch. */
|
|
28
|
+
url: string;
|
|
29
|
+
/** Whether to follow HTTP redirects. */
|
|
30
|
+
allow_redirects?: boolean;
|
|
31
|
+
/** Whether to bypass TLS certificate verification. */
|
|
32
|
+
allow_insecure_ssl?: boolean;
|
|
33
|
+
/** Whether to route the request through Browserbase proxies. */
|
|
34
|
+
proxies?: boolean;
|
|
35
|
+
/** Output format for the response content. */
|
|
36
|
+
format?: BrowserbaseFetchFormat;
|
|
37
|
+
/**
|
|
38
|
+
* JSON Schema describing the desired response content. Only used when format
|
|
39
|
+
* is json.
|
|
40
|
+
*/
|
|
41
|
+
schema?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface BrowserbaseFetchResponse {
|
|
45
|
+
/** Unique identifier for the fetch request. */
|
|
46
|
+
id: string;
|
|
47
|
+
/**
|
|
48
|
+
* Response body. Raw and markdown responses return strings; JSON extraction
|
|
49
|
+
* returns an object matching the requested schema.
|
|
50
|
+
*/
|
|
51
|
+
content: string | Record<string, unknown>;
|
|
52
|
+
/** MIME type of the response. */
|
|
53
|
+
contentType: string;
|
|
54
|
+
/** Character encoding of the response. */
|
|
55
|
+
encoding: string;
|
|
56
|
+
/** Response headers from the fetched page. */
|
|
57
|
+
headers: Record<string, string>;
|
|
58
|
+
/** HTTP status code returned by the fetched page. */
|
|
59
|
+
statusCode: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface BrowserbaseFetchError {
|
|
63
|
+
error:
|
|
64
|
+
| 'api_error'
|
|
65
|
+
| 'configuration_error'
|
|
66
|
+
| 'execution_error'
|
|
67
|
+
| 'invalid_input'
|
|
68
|
+
| 'rate_limit'
|
|
69
|
+
| 'timeout'
|
|
70
|
+
| 'unknown';
|
|
71
|
+
statusCode?: number;
|
|
72
|
+
message: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type BrowserbaseFetchOutput =
|
|
76
|
+
| BrowserbaseFetchError
|
|
77
|
+
| BrowserbaseFetchResponse;
|
|
78
|
+
|
|
79
|
+
const jsonObjectSchema = z.record(z.string(), z.unknown());
|
|
80
|
+
|
|
81
|
+
const browserbaseFetchInputSchema = lazySchema(() =>
|
|
82
|
+
zodSchema(
|
|
83
|
+
z.object({
|
|
84
|
+
url: z.string().url().describe('URL of the page to fetch.'),
|
|
85
|
+
allow_redirects: z
|
|
86
|
+
.boolean()
|
|
87
|
+
.optional()
|
|
88
|
+
.describe('Whether to follow HTTP redirects (default: false).'),
|
|
89
|
+
allow_insecure_ssl: z
|
|
90
|
+
.boolean()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe(
|
|
93
|
+
'Whether to bypass TLS certificate verification (default: false). Only use for trusted hosts.',
|
|
94
|
+
),
|
|
95
|
+
proxies: z
|
|
96
|
+
.boolean()
|
|
97
|
+
.optional()
|
|
98
|
+
.describe(
|
|
99
|
+
'Whether to route the request through Browserbase proxies (default: false).',
|
|
100
|
+
),
|
|
101
|
+
format: z
|
|
102
|
+
.enum(['raw', 'json', 'markdown'])
|
|
103
|
+
.optional()
|
|
104
|
+
.describe(
|
|
105
|
+
'Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema.',
|
|
106
|
+
),
|
|
107
|
+
schema: jsonObjectSchema
|
|
108
|
+
.optional()
|
|
109
|
+
.describe(
|
|
110
|
+
'JSON Schema for structured extraction. Only use with format set to json.',
|
|
111
|
+
),
|
|
112
|
+
}),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const browserbaseFetchOutputSchema = lazySchema(() =>
|
|
117
|
+
zodSchema(
|
|
118
|
+
z.union([
|
|
119
|
+
z.object({
|
|
120
|
+
id: z.string(),
|
|
121
|
+
content: z.union([z.string(), jsonObjectSchema]),
|
|
122
|
+
contentType: z.string(),
|
|
123
|
+
encoding: z.string(),
|
|
124
|
+
headers: z.record(z.string(), z.string()),
|
|
125
|
+
statusCode: z.number(),
|
|
126
|
+
}),
|
|
127
|
+
z.object({
|
|
128
|
+
error: z.enum([
|
|
129
|
+
'api_error',
|
|
130
|
+
'configuration_error',
|
|
131
|
+
'execution_error',
|
|
132
|
+
'invalid_input',
|
|
133
|
+
'rate_limit',
|
|
134
|
+
'timeout',
|
|
135
|
+
'unknown',
|
|
136
|
+
]),
|
|
137
|
+
statusCode: z.number().optional(),
|
|
138
|
+
message: z.string(),
|
|
139
|
+
}),
|
|
140
|
+
]),
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
export const browserbaseFetchToolFactory = createProviderExecutedToolFactory<
|
|
145
|
+
BrowserbaseFetchInput,
|
|
146
|
+
BrowserbaseFetchOutput,
|
|
147
|
+
BrowserbaseFetchConfig
|
|
148
|
+
>({
|
|
149
|
+
id: 'gateway.browserbase_fetch',
|
|
150
|
+
inputSchema: browserbaseFetchInputSchema,
|
|
151
|
+
outputSchema: browserbaseFetchOutputSchema,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const browserbaseFetch = (
|
|
155
|
+
config: BrowserbaseFetchConfig = {},
|
|
156
|
+
): ReturnType<typeof browserbaseFetchToolFactory> =>
|
|
157
|
+
browserbaseFetchToolFactory(config);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from '../zod';
|
|
7
|
+
|
|
8
|
+
export interface BrowserbaseSearchConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Default maximum number of results to return (1-25, default: 10).
|
|
11
|
+
*/
|
|
12
|
+
numResults?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BrowserbaseSearchInput {
|
|
16
|
+
/**
|
|
17
|
+
* Web search query (1-200 characters).
|
|
18
|
+
*/
|
|
19
|
+
query: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of results to return (1-25, default: 10).
|
|
23
|
+
*/
|
|
24
|
+
num_results?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BrowserbaseSearchResult {
|
|
28
|
+
/** Unique identifier for the result. */
|
|
29
|
+
id: string;
|
|
30
|
+
/** Title of the search result. */
|
|
31
|
+
title: string;
|
|
32
|
+
/** URL of the search result. */
|
|
33
|
+
url: string;
|
|
34
|
+
/** Author of the content, when available. */
|
|
35
|
+
author?: string;
|
|
36
|
+
/** Favicon URL, when available. */
|
|
37
|
+
favicon?: string;
|
|
38
|
+
/** Image URL, when available. */
|
|
39
|
+
image?: string;
|
|
40
|
+
/** Publication date in ISO 8601 format, when available. */
|
|
41
|
+
publishedDate?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface BrowserbaseSearchResponse {
|
|
45
|
+
/** The search query that was executed. */
|
|
46
|
+
query: string;
|
|
47
|
+
/** Unique identifier for the request. */
|
|
48
|
+
requestId: string;
|
|
49
|
+
/** Search results. */
|
|
50
|
+
results: BrowserbaseSearchResult[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface BrowserbaseSearchError {
|
|
54
|
+
error:
|
|
55
|
+
| 'api_error'
|
|
56
|
+
| 'configuration_error'
|
|
57
|
+
| 'execution_error'
|
|
58
|
+
| 'invalid_input'
|
|
59
|
+
| 'rate_limit'
|
|
60
|
+
| 'timeout'
|
|
61
|
+
| 'unknown';
|
|
62
|
+
statusCode?: number;
|
|
63
|
+
message: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type BrowserbaseSearchOutput =
|
|
67
|
+
| BrowserbaseSearchError
|
|
68
|
+
| BrowserbaseSearchResponse;
|
|
69
|
+
|
|
70
|
+
const browserbaseSearchInputSchema = lazySchema(() =>
|
|
71
|
+
zodSchema(
|
|
72
|
+
z.object({
|
|
73
|
+
query: z
|
|
74
|
+
.string()
|
|
75
|
+
.min(1)
|
|
76
|
+
.max(200)
|
|
77
|
+
.describe('Web search query. Must be between 1 and 200 characters.'),
|
|
78
|
+
num_results: z
|
|
79
|
+
.number()
|
|
80
|
+
.int()
|
|
81
|
+
.min(1)
|
|
82
|
+
.max(25)
|
|
83
|
+
.optional()
|
|
84
|
+
.describe('Maximum number of results to return (1-25, default: 10).'),
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const browserbaseSearchOutputSchema = lazySchema(() =>
|
|
90
|
+
zodSchema(
|
|
91
|
+
z.union([
|
|
92
|
+
z.object({
|
|
93
|
+
query: z.string(),
|
|
94
|
+
requestId: z.string(),
|
|
95
|
+
results: z.array(
|
|
96
|
+
z.object({
|
|
97
|
+
id: z.string(),
|
|
98
|
+
title: z.string(),
|
|
99
|
+
url: z.string(),
|
|
100
|
+
author: z.string().optional(),
|
|
101
|
+
favicon: z.string().optional(),
|
|
102
|
+
image: z.string().optional(),
|
|
103
|
+
publishedDate: z.string().optional(),
|
|
104
|
+
}),
|
|
105
|
+
),
|
|
106
|
+
}),
|
|
107
|
+
z.object({
|
|
108
|
+
error: z.enum([
|
|
109
|
+
'api_error',
|
|
110
|
+
'configuration_error',
|
|
111
|
+
'execution_error',
|
|
112
|
+
'invalid_input',
|
|
113
|
+
'rate_limit',
|
|
114
|
+
'timeout',
|
|
115
|
+
'unknown',
|
|
116
|
+
]),
|
|
117
|
+
statusCode: z.number().optional(),
|
|
118
|
+
message: z.string(),
|
|
119
|
+
}),
|
|
120
|
+
]),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
export const browserbaseSearchToolFactory = createProviderExecutedToolFactory<
|
|
125
|
+
BrowserbaseSearchInput,
|
|
126
|
+
BrowserbaseSearchOutput,
|
|
127
|
+
BrowserbaseSearchConfig
|
|
128
|
+
>({
|
|
129
|
+
id: 'gateway.browserbase_search',
|
|
130
|
+
inputSchema: browserbaseSearchInputSchema,
|
|
131
|
+
outputSchema: browserbaseSearchOutputSchema,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export const browserbaseSearch = (
|
|
135
|
+
config: BrowserbaseSearchConfig = {},
|
|
136
|
+
): ReturnType<typeof browserbaseSearchToolFactory> =>
|
|
137
|
+
browserbaseSearchToolFactory(config);
|