@ai-sdk/gateway 4.0.0-canary.99 → 4.0.1
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 +303 -0
- package/dist/index.d.ts +278 -27
- package/dist/index.js +600 -122
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +179 -0
- package/package.json +5 -5
- package/src/errors/create-gateway-error.ts +16 -0
- package/src/errors/gateway-failed-dependency-error.ts +35 -0
- package/src/errors/gateway-forbidden-error.ts +34 -0
- package/src/errors/index.ts +2 -0
- package/src/gateway-embedding-model.ts +24 -1
- package/src/gateway-image-model.ts +5 -0
- package/src/gateway-language-model-settings.ts +5 -4
- package/src/gateway-language-model.ts +25 -19
- package/src/gateway-provider-options.ts +50 -116
- package/src/gateway-provider.ts +113 -0
- package/src/gateway-realtime-auth.ts +126 -0
- package/src/gateway-realtime-model-settings.ts +6 -0
- package/src/gateway-realtime-model.ts +118 -0
- package/src/gateway-reranking-model.ts +24 -1
- package/src/gateway-speech-model-settings.ts +5 -1
- package/src/gateway-speech-model.ts +5 -0
- package/src/gateway-tools.ts +10 -0
- package/src/gateway-transcription-model-settings.ts +6 -1
- package/src/gateway-transcription-model.ts +5 -0
- package/src/gateway-video-model-settings.ts +1 -2
- package/src/gateway-video-model.ts +7 -0
- package/src/index.ts +11 -0
- package/src/tool/exa-search.ts +352 -0
- package/src/tool/parallel-search.ts +7 -3
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
export type ExaSearchType = 'auto' | 'fast' | 'instant';
|
|
9
|
+
|
|
10
|
+
export type ExaSearchCategory =
|
|
11
|
+
| 'company'
|
|
12
|
+
| 'people'
|
|
13
|
+
| 'research paper'
|
|
14
|
+
| 'news'
|
|
15
|
+
| 'personal site'
|
|
16
|
+
| 'financial report';
|
|
17
|
+
|
|
18
|
+
export type ExaTextSection =
|
|
19
|
+
| 'header'
|
|
20
|
+
| 'navigation'
|
|
21
|
+
| 'banner'
|
|
22
|
+
| 'body'
|
|
23
|
+
| 'sidebar'
|
|
24
|
+
| 'footer'
|
|
25
|
+
| 'metadata';
|
|
26
|
+
|
|
27
|
+
export interface ExaSearchTextConfig {
|
|
28
|
+
maxCharacters?: number;
|
|
29
|
+
includeHtmlTags?: boolean;
|
|
30
|
+
verbosity?: 'compact' | 'standard' | 'full';
|
|
31
|
+
includeSections?: ExaTextSection[];
|
|
32
|
+
excludeSections?: ExaTextSection[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ExaSearchHighlightsConfig {
|
|
36
|
+
query?: string;
|
|
37
|
+
maxCharacters?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ExaSearchExtrasConfig {
|
|
41
|
+
links?: number;
|
|
42
|
+
imageLinks?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ExaSearchContentsConfig {
|
|
46
|
+
text?: boolean | ExaSearchTextConfig;
|
|
47
|
+
highlights?: boolean | ExaSearchHighlightsConfig;
|
|
48
|
+
maxAgeHours?: number;
|
|
49
|
+
livecrawlTimeout?: number;
|
|
50
|
+
subpages?: number;
|
|
51
|
+
subpageTarget?: string | string[];
|
|
52
|
+
extras?: ExaSearchExtrasConfig;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ExaSearchConfig {
|
|
56
|
+
/**
|
|
57
|
+
* Default search method. Exa defaults to auto when omitted.
|
|
58
|
+
*/
|
|
59
|
+
type?: ExaSearchType;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Default maximum number of results to return (1-100, default: 10).
|
|
63
|
+
*/
|
|
64
|
+
numResults?: number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Default category filter for result types.
|
|
68
|
+
*/
|
|
69
|
+
category?: ExaSearchCategory;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Default two-letter ISO country code for location-aware search.
|
|
73
|
+
*/
|
|
74
|
+
userLocation?: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Default domains to include or exclude.
|
|
78
|
+
*/
|
|
79
|
+
includeDomains?: string[];
|
|
80
|
+
excludeDomains?: string[];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Default published date filters in ISO 8601 format.
|
|
84
|
+
*/
|
|
85
|
+
startPublishedDate?: string;
|
|
86
|
+
endPublishedDate?: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Default content extraction controls.
|
|
90
|
+
*/
|
|
91
|
+
contents?: ExaSearchContentsConfig;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface ExaSearchResult {
|
|
95
|
+
title: string;
|
|
96
|
+
url: string;
|
|
97
|
+
id: string;
|
|
98
|
+
publishedDate?: string | null;
|
|
99
|
+
author?: string | null;
|
|
100
|
+
image?: string | null;
|
|
101
|
+
favicon?: string | null;
|
|
102
|
+
text?: string;
|
|
103
|
+
highlights?: string[];
|
|
104
|
+
highlightScores?: number[];
|
|
105
|
+
summary?: string;
|
|
106
|
+
subpages?: ExaSearchResult[];
|
|
107
|
+
extras?: {
|
|
108
|
+
links?: string[];
|
|
109
|
+
imageLinks?: string[];
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ExaSearchResponse {
|
|
114
|
+
requestId: string;
|
|
115
|
+
searchType?: string;
|
|
116
|
+
resolvedSearchType?: string;
|
|
117
|
+
results: ExaSearchResult[];
|
|
118
|
+
costDollars?: {
|
|
119
|
+
total?: number;
|
|
120
|
+
search?: Record<string, number>;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface ExaSearchError {
|
|
125
|
+
error:
|
|
126
|
+
| 'api_error'
|
|
127
|
+
| 'rate_limit'
|
|
128
|
+
| 'timeout'
|
|
129
|
+
| 'invalid_input'
|
|
130
|
+
| 'configuration_error'
|
|
131
|
+
| 'execution_error'
|
|
132
|
+
| 'unknown';
|
|
133
|
+
statusCode?: number;
|
|
134
|
+
message: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface ExaSearchInput {
|
|
138
|
+
query: string;
|
|
139
|
+
type?: ExaSearchType;
|
|
140
|
+
num_results?: number;
|
|
141
|
+
category?: ExaSearchCategory;
|
|
142
|
+
user_location?: string;
|
|
143
|
+
include_domains?: string[];
|
|
144
|
+
exclude_domains?: string[];
|
|
145
|
+
start_published_date?: string;
|
|
146
|
+
end_published_date?: string;
|
|
147
|
+
contents?: {
|
|
148
|
+
text?:
|
|
149
|
+
| boolean
|
|
150
|
+
| {
|
|
151
|
+
max_characters?: number;
|
|
152
|
+
include_html_tags?: boolean;
|
|
153
|
+
verbosity?: 'compact' | 'standard' | 'full';
|
|
154
|
+
include_sections?: ExaTextSection[];
|
|
155
|
+
exclude_sections?: ExaTextSection[];
|
|
156
|
+
};
|
|
157
|
+
highlights?:
|
|
158
|
+
| boolean
|
|
159
|
+
| {
|
|
160
|
+
query?: string;
|
|
161
|
+
max_characters?: number;
|
|
162
|
+
};
|
|
163
|
+
max_age_hours?: number;
|
|
164
|
+
livecrawl_timeout?: number;
|
|
165
|
+
subpages?: number;
|
|
166
|
+
subpage_target?: string | string[];
|
|
167
|
+
extras?: {
|
|
168
|
+
links?: number;
|
|
169
|
+
image_links?: number;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export type ExaSearchOutput = ExaSearchResponse | ExaSearchError;
|
|
175
|
+
|
|
176
|
+
const exaSearchInputSchema = lazySchema(() =>
|
|
177
|
+
zodSchema(
|
|
178
|
+
z.object({
|
|
179
|
+
query: z
|
|
180
|
+
.string()
|
|
181
|
+
.describe('Natural-language web search query. This is required.'),
|
|
182
|
+
type: z
|
|
183
|
+
.enum(['auto', 'fast', 'instant'])
|
|
184
|
+
.optional()
|
|
185
|
+
.describe(
|
|
186
|
+
'Search method. Use auto for the default balance of speed and quality.',
|
|
187
|
+
),
|
|
188
|
+
num_results: z
|
|
189
|
+
.number()
|
|
190
|
+
.optional()
|
|
191
|
+
.describe('Maximum number of results to return (1-100, default: 10).'),
|
|
192
|
+
category: z
|
|
193
|
+
.enum([
|
|
194
|
+
'company',
|
|
195
|
+
'people',
|
|
196
|
+
'research paper',
|
|
197
|
+
'news',
|
|
198
|
+
'personal site',
|
|
199
|
+
'financial report',
|
|
200
|
+
])
|
|
201
|
+
.optional()
|
|
202
|
+
.describe('Optional content category to focus results.'),
|
|
203
|
+
user_location: z
|
|
204
|
+
.string()
|
|
205
|
+
.optional()
|
|
206
|
+
.describe("Two-letter ISO country code such as 'US'."),
|
|
207
|
+
include_domains: z
|
|
208
|
+
.array(z.string())
|
|
209
|
+
.optional()
|
|
210
|
+
.describe('Only return results from these domains.'),
|
|
211
|
+
exclude_domains: z
|
|
212
|
+
.array(z.string())
|
|
213
|
+
.optional()
|
|
214
|
+
.describe('Exclude results from these domains.'),
|
|
215
|
+
start_published_date: z
|
|
216
|
+
.string()
|
|
217
|
+
.optional()
|
|
218
|
+
.describe('Only return links published after this ISO 8601 date.'),
|
|
219
|
+
end_published_date: z
|
|
220
|
+
.string()
|
|
221
|
+
.optional()
|
|
222
|
+
.describe('Only return links published before this ISO 8601 date.'),
|
|
223
|
+
contents: z
|
|
224
|
+
.object({
|
|
225
|
+
text: z
|
|
226
|
+
.union([
|
|
227
|
+
z.boolean(),
|
|
228
|
+
z.object({
|
|
229
|
+
max_characters: z.number().optional(),
|
|
230
|
+
include_html_tags: z.boolean().optional(),
|
|
231
|
+
verbosity: z.enum(['compact', 'standard', 'full']).optional(),
|
|
232
|
+
include_sections: z
|
|
233
|
+
.array(
|
|
234
|
+
z.enum([
|
|
235
|
+
'header',
|
|
236
|
+
'navigation',
|
|
237
|
+
'banner',
|
|
238
|
+
'body',
|
|
239
|
+
'sidebar',
|
|
240
|
+
'footer',
|
|
241
|
+
'metadata',
|
|
242
|
+
]),
|
|
243
|
+
)
|
|
244
|
+
.optional(),
|
|
245
|
+
exclude_sections: z
|
|
246
|
+
.array(
|
|
247
|
+
z.enum([
|
|
248
|
+
'header',
|
|
249
|
+
'navigation',
|
|
250
|
+
'banner',
|
|
251
|
+
'body',
|
|
252
|
+
'sidebar',
|
|
253
|
+
'footer',
|
|
254
|
+
'metadata',
|
|
255
|
+
]),
|
|
256
|
+
)
|
|
257
|
+
.optional(),
|
|
258
|
+
}),
|
|
259
|
+
])
|
|
260
|
+
.optional(),
|
|
261
|
+
highlights: z
|
|
262
|
+
.union([
|
|
263
|
+
z.boolean(),
|
|
264
|
+
z.object({
|
|
265
|
+
query: z.string().optional(),
|
|
266
|
+
max_characters: z.number().optional(),
|
|
267
|
+
}),
|
|
268
|
+
])
|
|
269
|
+
.optional(),
|
|
270
|
+
max_age_hours: z.number().optional(),
|
|
271
|
+
livecrawl_timeout: z.number().optional(),
|
|
272
|
+
subpages: z.number().optional(),
|
|
273
|
+
subpage_target: z.union([z.string(), z.array(z.string())]).optional(),
|
|
274
|
+
extras: z
|
|
275
|
+
.object({
|
|
276
|
+
links: z.number().optional(),
|
|
277
|
+
image_links: z.number().optional(),
|
|
278
|
+
})
|
|
279
|
+
.optional(),
|
|
280
|
+
})
|
|
281
|
+
.optional()
|
|
282
|
+
.describe('Controls extracted page content and freshness.'),
|
|
283
|
+
}),
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const exaSearchOutputSchema = lazySchema(() =>
|
|
288
|
+
zodSchema(
|
|
289
|
+
z.union([
|
|
290
|
+
z.object({
|
|
291
|
+
requestId: z.string(),
|
|
292
|
+
searchType: z.string().optional(),
|
|
293
|
+
resolvedSearchType: z.string().optional(),
|
|
294
|
+
results: z.array(
|
|
295
|
+
z.object({
|
|
296
|
+
title: z.string(),
|
|
297
|
+
url: z.string(),
|
|
298
|
+
id: z.string(),
|
|
299
|
+
publishedDate: z.string().nullable().optional(),
|
|
300
|
+
author: z.string().nullable().optional(),
|
|
301
|
+
image: z.string().nullable().optional(),
|
|
302
|
+
favicon: z.string().nullable().optional(),
|
|
303
|
+
text: z.string().optional(),
|
|
304
|
+
highlights: z.array(z.string()).optional(),
|
|
305
|
+
highlightScores: z.array(z.number()).optional(),
|
|
306
|
+
summary: z.string().optional(),
|
|
307
|
+
subpages: z.array(z.any()).optional(),
|
|
308
|
+
extras: z
|
|
309
|
+
.object({
|
|
310
|
+
links: z.array(z.string()).optional(),
|
|
311
|
+
imageLinks: z.array(z.string()).optional(),
|
|
312
|
+
})
|
|
313
|
+
.optional(),
|
|
314
|
+
}),
|
|
315
|
+
),
|
|
316
|
+
costDollars: z
|
|
317
|
+
.object({
|
|
318
|
+
total: z.number().optional(),
|
|
319
|
+
search: z.record(z.number()).optional(),
|
|
320
|
+
})
|
|
321
|
+
.optional(),
|
|
322
|
+
}),
|
|
323
|
+
z.object({
|
|
324
|
+
error: z.enum([
|
|
325
|
+
'api_error',
|
|
326
|
+
'rate_limit',
|
|
327
|
+
'timeout',
|
|
328
|
+
'invalid_input',
|
|
329
|
+
'configuration_error',
|
|
330
|
+
'execution_error',
|
|
331
|
+
'unknown',
|
|
332
|
+
]),
|
|
333
|
+
statusCode: z.number().optional(),
|
|
334
|
+
message: z.string(),
|
|
335
|
+
}),
|
|
336
|
+
]),
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
export const exaSearchToolFactory = createProviderExecutedToolFactory<
|
|
341
|
+
ExaSearchInput,
|
|
342
|
+
ExaSearchOutput,
|
|
343
|
+
ExaSearchConfig
|
|
344
|
+
>({
|
|
345
|
+
id: 'gateway.exa_search',
|
|
346
|
+
inputSchema: exaSearchInputSchema,
|
|
347
|
+
outputSchema: exaSearchOutputSchema,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
export const exaSearch = (
|
|
351
|
+
config: ExaSearchConfig = {},
|
|
352
|
+
): ReturnType<typeof exaSearchToolFactory> => exaSearchToolFactory(config);
|
|
@@ -199,16 +199,20 @@ const parallelSearchInputSchema = lazySchema(() =>
|
|
|
199
199
|
include_domains: z
|
|
200
200
|
.array(z.string())
|
|
201
201
|
.optional()
|
|
202
|
-
.describe(
|
|
202
|
+
.describe(
|
|
203
|
+
'Limit results to these domains. Use plain domain names only — e.g. example.com or sub.example.gov, or a bare extension like .edu. Do not include a scheme, path, or port (e.g. not https://example.com/page).',
|
|
204
|
+
),
|
|
203
205
|
exclude_domains: z
|
|
204
206
|
.array(z.string())
|
|
205
207
|
.optional()
|
|
206
|
-
.describe(
|
|
208
|
+
.describe(
|
|
209
|
+
'Exclude results from these domains. Use plain domain names only — e.g. example.com or sub.example.gov, or a bare extension like .edu. Do not include a scheme, path, or port (e.g. not https://example.com/page).',
|
|
210
|
+
),
|
|
207
211
|
after_date: z
|
|
208
212
|
.string()
|
|
209
213
|
.optional()
|
|
210
214
|
.describe(
|
|
211
|
-
'Only include results published after this date
|
|
215
|
+
'Only include results published after this date. Use an ISO 8601 calendar date formatted YYYY-MM-DD (e.g. 2025-01-01); do not include a time.',
|
|
212
216
|
),
|
|
213
217
|
})
|
|
214
218
|
.optional()
|