@ai-sdk/gateway 4.0.0-beta.11 → 4.0.0-beta.111

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +762 -4
  2. package/dist/index.d.ts +449 -42
  3. package/dist/index.js +1554 -397
  4. package/dist/index.js.map +1 -1
  5. package/docs/00-ai-gateway.mdx +534 -61
  6. package/package.json +14 -14
  7. package/src/errors/as-gateway-error.ts +2 -1
  8. package/src/errors/create-gateway-error.ts +17 -3
  9. package/src/errors/gateway-authentication-error.ts +8 -5
  10. package/src/errors/gateway-error.ts +8 -0
  11. package/src/errors/gateway-failed-dependency-error.ts +35 -0
  12. package/src/errors/gateway-forbidden-error.ts +34 -0
  13. package/src/errors/gateway-response-error.ts +1 -1
  14. package/src/errors/index.ts +2 -0
  15. package/src/errors/parse-auth-method.ts +1 -2
  16. package/src/gateway-config.ts +1 -1
  17. package/src/gateway-embedding-model-settings.ts +1 -0
  18. package/src/gateway-embedding-model.ts +62 -15
  19. package/src/gateway-fetch-metadata.ts +51 -38
  20. package/src/gateway-generation-info.ts +149 -0
  21. package/src/gateway-headers.ts +3 -0
  22. package/src/gateway-image-model-settings.ts +8 -1
  23. package/src/gateway-image-model.ts +46 -21
  24. package/src/gateway-language-model-settings.ts +45 -26
  25. package/src/gateway-language-model.ts +72 -42
  26. package/src/gateway-model-entry.ts +15 -3
  27. package/src/gateway-provider-options.ts +50 -78
  28. package/src/gateway-provider.ts +296 -35
  29. package/src/gateway-realtime-auth.ts +126 -0
  30. package/src/gateway-realtime-model-settings.ts +1 -0
  31. package/src/gateway-realtime-model.ts +118 -0
  32. package/src/gateway-reranking-model-settings.ts +7 -0
  33. package/src/gateway-reranking-model.ts +142 -0
  34. package/src/gateway-speech-model-settings.ts +1 -0
  35. package/src/gateway-speech-model.ts +145 -0
  36. package/src/gateway-spend-report.ts +193 -0
  37. package/src/gateway-tools.ts +10 -0
  38. package/src/gateway-transcription-model-settings.ts +1 -0
  39. package/src/gateway-transcription-model.ts +155 -0
  40. package/src/gateway-video-model-settings.ts +4 -0
  41. package/src/gateway-video-model.ts +29 -19
  42. package/src/index.ts +30 -5
  43. package/src/tool/exa-search.ts +352 -0
  44. package/src/tool/parallel-search.ts +10 -11
  45. package/src/tool/perplexity-search.ts +10 -11
  46. package/dist/index.d.mts +0 -602
  47. package/dist/index.mjs +0 -1539
  48. package/dist/index.mjs.map +0 -1
@@ -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);
@@ -1,5 +1,5 @@
1
1
  import {
2
- createProviderToolFactoryWithOutputSchema,
2
+ createProviderExecutedToolFactory,
3
3
  lazySchema,
4
4
  zodSchema,
5
5
  } from '@ai-sdk/provider-utils';
@@ -278,16 +278,15 @@ const parallelSearchOutputSchema = lazySchema(() =>
278
278
  ),
279
279
  );
280
280
 
281
- export const parallelSearchToolFactory =
282
- createProviderToolFactoryWithOutputSchema<
283
- ParallelSearchInput,
284
- ParallelSearchOutput,
285
- ParallelSearchConfig
286
- >({
287
- id: 'gateway.parallel_search',
288
- inputSchema: parallelSearchInputSchema,
289
- outputSchema: parallelSearchOutputSchema,
290
- });
281
+ export const parallelSearchToolFactory = createProviderExecutedToolFactory<
282
+ ParallelSearchInput,
283
+ ParallelSearchOutput,
284
+ ParallelSearchConfig
285
+ >({
286
+ id: 'gateway.parallel_search',
287
+ inputSchema: parallelSearchInputSchema,
288
+ outputSchema: parallelSearchOutputSchema,
289
+ });
291
290
 
292
291
  export const parallelSearch = (
293
292
  config: ParallelSearchConfig = {},
@@ -1,5 +1,5 @@
1
1
  import {
2
- createProviderToolFactoryWithOutputSchema,
2
+ createProviderExecutedToolFactory,
3
3
  lazySchema,
4
4
  zodSchema,
5
5
  } from '@ai-sdk/provider-utils';
@@ -277,16 +277,15 @@ const perplexitySearchOutputSchema = lazySchema(() =>
277
277
  ),
278
278
  );
279
279
 
280
- export const perplexitySearchToolFactory =
281
- createProviderToolFactoryWithOutputSchema<
282
- PerplexitySearchInput,
283
- PerplexitySearchOutput,
284
- PerplexitySearchConfig
285
- >({
286
- id: 'gateway.perplexity_search',
287
- inputSchema: perplexitySearchInputSchema,
288
- outputSchema: perplexitySearchOutputSchema,
289
- });
280
+ export const perplexitySearchToolFactory = createProviderExecutedToolFactory<
281
+ PerplexitySearchInput,
282
+ PerplexitySearchOutput,
283
+ PerplexitySearchConfig
284
+ >({
285
+ id: 'gateway.perplexity_search',
286
+ inputSchema: perplexitySearchInputSchema,
287
+ outputSchema: perplexitySearchOutputSchema,
288
+ });
290
289
 
291
290
  export const perplexitySearch = (
292
291
  config: PerplexitySearchConfig = {},