@ai-sdk/gateway 4.0.92 → 4.0.95

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.
@@ -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);