@ai-sdk/gateway 0.0.0-02dba89b-20251009204516 → 0.0.0-4115c213-20260122152721

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 (37) hide show
  1. package/CHANGELOG.md +886 -167
  2. package/dist/index.d.mts +205 -34
  3. package/dist/index.d.ts +205 -34
  4. package/dist/index.js +459 -180
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +450 -148
  7. package/dist/index.mjs.map +1 -1
  8. package/docs/00-ai-gateway.mdx +625 -0
  9. package/package.json +19 -6
  10. package/src/errors/as-gateway-error.ts +33 -0
  11. package/src/errors/create-gateway-error.ts +132 -0
  12. package/src/errors/extract-api-call-response.ts +15 -0
  13. package/src/errors/gateway-authentication-error.ts +84 -0
  14. package/src/errors/gateway-error.ts +47 -0
  15. package/src/errors/gateway-internal-server-error.ts +33 -0
  16. package/src/errors/gateway-invalid-request-error.ts +33 -0
  17. package/src/errors/gateway-model-not-found-error.ts +47 -0
  18. package/src/errors/gateway-rate-limit-error.ts +33 -0
  19. package/src/errors/gateway-response-error.ts +42 -0
  20. package/src/errors/index.ts +16 -0
  21. package/src/errors/parse-auth-method.ts +23 -0
  22. package/src/gateway-config.ts +7 -0
  23. package/src/gateway-embedding-model-settings.ts +22 -0
  24. package/src/gateway-embedding-model.ts +109 -0
  25. package/src/gateway-fetch-metadata.ts +127 -0
  26. package/src/gateway-image-model-settings.ts +12 -0
  27. package/src/gateway-image-model.ts +145 -0
  28. package/src/gateway-language-model-settings.ts +159 -0
  29. package/src/gateway-language-model.ts +212 -0
  30. package/src/gateway-model-entry.ts +58 -0
  31. package/src/gateway-provider-options.ts +66 -0
  32. package/src/gateway-provider.ts +284 -0
  33. package/src/gateway-tools.ts +15 -0
  34. package/src/index.ts +27 -0
  35. package/src/tool/perplexity-search.ts +294 -0
  36. package/src/vercel-environment.ts +6 -0
  37. package/src/version.ts +6 -0
@@ -0,0 +1,294 @@
1
+ import {
2
+ createProviderToolFactoryWithOutputSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod';
7
+
8
+ export interface PerplexitySearchConfig {
9
+ /**
10
+ * Default maximum number of search results to return (1-20, default: 10).
11
+ */
12
+ maxResults?: number;
13
+
14
+ /**
15
+ * Default maximum tokens to extract per search result page (256-2048, default: 2048).
16
+ */
17
+ maxTokensPerPage?: number;
18
+
19
+ /**
20
+ * Default maximum total tokens across all search results (default: 25000, max: 1000000).
21
+ */
22
+ maxTokens?: number;
23
+
24
+ /**
25
+ * Default two-letter ISO 3166-1 alpha-2 country code for regional search results.
26
+ * Examples: 'US', 'GB', 'FR'
27
+ */
28
+ country?: string;
29
+
30
+ /**
31
+ * Default list of domains to include or exclude from search results (max 20).
32
+ * To include: ['nature.com', 'science.org']
33
+ * To exclude: ['-example.com', '-spam.net']
34
+ */
35
+ searchDomainFilter?: string[];
36
+
37
+ /**
38
+ * Default list of ISO 639-1 language codes to filter results (max 10, lowercase).
39
+ * Examples: ['en', 'fr', 'de']
40
+ */
41
+ searchLanguageFilter?: string[];
42
+
43
+ /**
44
+ * Default recency filter for results.
45
+ * Cannot be combined with searchAfterDate/searchBeforeDate at runtime.
46
+ */
47
+ searchRecencyFilter?: 'day' | 'week' | 'month' | 'year';
48
+ }
49
+
50
+ export interface PerplexitySearchResult {
51
+ /** Title of the search result */
52
+ title: string;
53
+ /** URL of the search result */
54
+ url: string;
55
+ /** Text snippet/preview of the content */
56
+ snippet: string;
57
+ /** Publication date of the content */
58
+ date?: string;
59
+ /** Last updated date of the content */
60
+ lastUpdated?: string;
61
+ }
62
+
63
+ export interface PerplexitySearchResponse {
64
+ /** Array of search results */
65
+ results: PerplexitySearchResult[];
66
+ /** Unique identifier for this search request */
67
+ id: string;
68
+ }
69
+
70
+ export interface PerplexitySearchError {
71
+ /** Error type */
72
+ error: 'api_error' | 'rate_limit' | 'timeout' | 'invalid_input' | 'unknown';
73
+ /** HTTP status code if applicable */
74
+ statusCode?: number;
75
+ /** Human-readable error message */
76
+ message: string;
77
+ }
78
+
79
+ export interface PerplexitySearchInput {
80
+ /**
81
+ * Search query (string) or multiple queries (array of up to 5 strings).
82
+ * Multi-query searches return combined results from all queries.
83
+ */
84
+ query: string | string[];
85
+
86
+ /**
87
+ * Maximum number of search results to return (1-20, default: 10).
88
+ */
89
+ max_results?: number;
90
+
91
+ /**
92
+ * Maximum number of tokens to extract per search result page (256-2048, default: 2048).
93
+ */
94
+ max_tokens_per_page?: number;
95
+
96
+ /**
97
+ * Maximum total tokens across all search results (default: 25000, max: 1000000).
98
+ */
99
+ max_tokens?: number;
100
+
101
+ /**
102
+ * Two-letter ISO 3166-1 alpha-2 country code for regional search results.
103
+ * Examples: 'US', 'GB', 'FR'
104
+ */
105
+ country?: string;
106
+
107
+ /**
108
+ * List of domains to include or exclude from search results (max 20).
109
+ * To include: ['nature.com', 'science.org']
110
+ * To exclude: ['-example.com', '-spam.net']
111
+ */
112
+ search_domain_filter?: string[];
113
+
114
+ /**
115
+ * List of ISO 639-1 language codes to filter results (max 10, lowercase).
116
+ * Examples: ['en', 'fr', 'de']
117
+ */
118
+ search_language_filter?: string[];
119
+
120
+ /**
121
+ * Include only results published after this date.
122
+ * Format: 'MM/DD/YYYY' (e.g., '3/1/2025')
123
+ * Cannot be used with search_recency_filter.
124
+ */
125
+ search_after_date?: string;
126
+
127
+ /**
128
+ * Include only results published before this date.
129
+ * Format: 'MM/DD/YYYY' (e.g., '3/15/2025')
130
+ * Cannot be used with search_recency_filter.
131
+ */
132
+ search_before_date?: string;
133
+
134
+ /**
135
+ * Include only results last updated after this date.
136
+ * Format: 'MM/DD/YYYY' (e.g., '3/1/2025')
137
+ * Cannot be used with search_recency_filter.
138
+ */
139
+ last_updated_after_filter?: string;
140
+
141
+ /**
142
+ * Include only results last updated before this date.
143
+ * Format: 'MM/DD/YYYY' (e.g., '3/15/2025')
144
+ * Cannot be used with search_recency_filter.
145
+ */
146
+ last_updated_before_filter?: string;
147
+
148
+ /**
149
+ * Filter results by relative time period.
150
+ * Cannot be used with search_after_date or search_before_date.
151
+ */
152
+ search_recency_filter?: 'day' | 'week' | 'month' | 'year';
153
+ }
154
+
155
+ export type PerplexitySearchOutput =
156
+ | PerplexitySearchResponse
157
+ | PerplexitySearchError;
158
+
159
+ const perplexitySearchInputSchema = lazySchema(() =>
160
+ zodSchema(
161
+ z.object({
162
+ query: z
163
+ .union([z.string(), z.array(z.string())])
164
+ .describe(
165
+ 'Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries.',
166
+ ),
167
+
168
+ max_results: z
169
+ .number()
170
+ .optional()
171
+ .describe(
172
+ 'Maximum number of search results to return (1-20, default: 10)',
173
+ ),
174
+
175
+ max_tokens_per_page: z
176
+ .number()
177
+ .optional()
178
+ .describe(
179
+ 'Maximum number of tokens to extract per search result page (256-2048, default: 2048)',
180
+ ),
181
+
182
+ max_tokens: z
183
+ .number()
184
+ .optional()
185
+ .describe(
186
+ 'Maximum total tokens across all search results (default: 25000, max: 1000000)',
187
+ ),
188
+
189
+ country: z
190
+ .string()
191
+ .optional()
192
+ .describe(
193
+ "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')",
194
+ ),
195
+
196
+ search_domain_filter: z
197
+ .array(z.string())
198
+ .optional()
199
+ .describe(
200
+ "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']",
201
+ ),
202
+
203
+ search_language_filter: z
204
+ .array(z.string())
205
+ .optional()
206
+ .describe(
207
+ "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']",
208
+ ),
209
+
210
+ search_after_date: z
211
+ .string()
212
+ .optional()
213
+ .describe(
214
+ "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter.",
215
+ ),
216
+
217
+ search_before_date: z
218
+ .string()
219
+ .optional()
220
+ .describe(
221
+ "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter.",
222
+ ),
223
+
224
+ last_updated_after_filter: z
225
+ .string()
226
+ .optional()
227
+ .describe(
228
+ "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter.",
229
+ ),
230
+
231
+ last_updated_before_filter: z
232
+ .string()
233
+ .optional()
234
+ .describe(
235
+ "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter.",
236
+ ),
237
+
238
+ search_recency_filter: z
239
+ .enum(['day', 'week', 'month', 'year'])
240
+ .optional()
241
+ .describe(
242
+ 'Filter results by relative time period. Cannot be used with search_after_date or search_before_date.',
243
+ ),
244
+ }),
245
+ ),
246
+ );
247
+
248
+ const perplexitySearchOutputSchema = lazySchema(() =>
249
+ zodSchema(
250
+ z.union([
251
+ // Success response
252
+ z.object({
253
+ results: z.array(
254
+ z.object({
255
+ title: z.string(),
256
+ url: z.string(),
257
+ snippet: z.string(),
258
+ date: z.string().optional(),
259
+ lastUpdated: z.string().optional(),
260
+ }),
261
+ ),
262
+ id: z.string(),
263
+ }),
264
+ // Error response
265
+ z.object({
266
+ error: z.enum([
267
+ 'api_error',
268
+ 'rate_limit',
269
+ 'timeout',
270
+ 'invalid_input',
271
+ 'unknown',
272
+ ]),
273
+ statusCode: z.number().optional(),
274
+ message: z.string(),
275
+ }),
276
+ ]),
277
+ ),
278
+ );
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
+ });
290
+
291
+ export const perplexitySearch = (
292
+ config: PerplexitySearchConfig = {},
293
+ ): ReturnType<typeof perplexitySearchToolFactory> =>
294
+ perplexitySearchToolFactory(config);
@@ -0,0 +1,6 @@
1
+ import { getContext } from '@vercel/oidc';
2
+ export { getVercelOidcToken } from '@vercel/oidc';
3
+
4
+ export async function getVercelRequestId(): Promise<string | undefined> {
5
+ return getContext().headers?.['x-vercel-id'];
6
+ }
package/src/version.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Version string of this package injected at build time.
2
+ declare const __PACKAGE_VERSION__: string | undefined;
3
+ export const VERSION: string =
4
+ typeof __PACKAGE_VERSION__ !== 'undefined'
5
+ ? __PACKAGE_VERSION__
6
+ : '0.0.0-test';