@ai-sdk/gateway 4.0.121 → 4.0.123

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.
@@ -5,21 +5,37 @@ import {
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from '../zod';
7
7
 
8
+ const parallelSearchModes = [
9
+ 'turbo',
10
+ 'fast',
11
+ 'basic',
12
+ 'advanced',
13
+ 'one-shot',
14
+ 'agentic',
15
+ ] as const;
16
+
17
+ /**
18
+ * Search mode. `turbo` and `fast` trade excerpt depth for latency (`turbo` is
19
+ * English and Japanese only), `basic` is balanced, `advanced` is the most thorough.
20
+ * Deprecated: `one-shot` (runs as `basic`) and `agentic` (runs as `advanced`).
21
+ */
22
+ export type ParallelSearchMode = (typeof parallelSearchModes)[number];
23
+
8
24
  export interface ParallelSearchSourcePolicy {
9
25
  /**
10
- * List of domains to include in search results.
11
- * Example: ['wikipedia.org', 'nature.com']
26
+ * Domains or domain/path prefixes to restrict results to. When set,
27
+ * `excludeDomains` is ignored. Example: ['wikipedia.org', 'docs.python.org/3']
12
28
  */
13
29
  includeDomains?: string[];
14
30
 
15
31
  /**
16
- * List of domains to exclude from search results.
17
- * Example: ['reddit.com', 'twitter.com']
32
+ * Domains or domain/path prefixes to exclude from results.
33
+ * Example: ['reddit.com']
18
34
  */
19
35
  excludeDomains?: string[];
20
36
 
21
37
  /**
22
- * Only include results published after this date (ISO 8601 format).
38
+ * Only include results published on or after this date (YYYY-MM-DD).
23
39
  * Example: '2024-01-01'
24
40
  */
25
41
  afterDate?: string;
@@ -33,25 +49,36 @@ export interface ParallelSearchExcerpts {
33
49
 
34
50
  /**
35
51
  * Maximum total characters across all results.
52
+ * @deprecated Use the top-level `maxCharsTotal` option instead.
36
53
  */
37
54
  maxCharsTotal?: number;
38
55
  }
39
56
 
40
57
  export interface ParallelSearchFetchPolicy {
41
58
  /**
42
- * Maximum age in seconds for cached content.
43
- * Set to 0 to always fetch fresh content.
59
+ * Maximum age in seconds of cached content before a live fetch is attempted.
60
+ * Minimum 600; lower values are raised to 600.
44
61
  */
45
62
  maxAgeSeconds?: number;
63
+
64
+ /**
65
+ * Timeout in seconds for a live fetch when content is not cached.
66
+ * The gateway caps it to stay within its own tool timeout.
67
+ */
68
+ timeoutSeconds?: number;
69
+
70
+ /**
71
+ * Return an error instead of falling back to older cached content when a
72
+ * live fetch fails or times out. Defaults to false.
73
+ */
74
+ disableCacheFallback?: boolean;
46
75
  }
47
76
 
48
77
  export interface ParallelSearchConfig {
49
78
  /**
50
- * Mode preset for different use cases:
51
- * - "one-shot": Comprehensive results with longer excerpts for single-response answers (default)
52
- * - "agentic": Concise, token-efficient results for multi-step agentic workflows
79
+ * Search mode. Defaults to `basic`.
53
80
  */
54
- mode?: 'one-shot' | 'agentic';
81
+ mode?: ParallelSearchMode;
55
82
 
56
83
  /**
57
84
  * Default maximum number of results to return (1-20).
@@ -69,41 +96,75 @@ export interface ParallelSearchConfig {
69
96
  */
70
97
  excerpts?: ParallelSearchExcerpts;
71
98
 
99
+ /**
100
+ * Maximum total characters across all result excerpts.
101
+ */
102
+ maxCharsTotal?: number;
103
+
72
104
  /**
73
105
  * Default fetch policy for controlling content freshness.
74
106
  */
75
107
  fetchPolicy?: ParallelSearchFetchPolicy;
108
+
109
+ /**
110
+ * ISO 3166-1 alpha-2 country code to localize results, e.g. 'us'.
111
+ * Invalid codes are ignored with a warning.
112
+ */
113
+ location?: string;
76
114
  }
77
115
 
78
116
  export interface ParallelSearchResult {
79
117
  /** URL of the search result */
80
118
  url: string;
81
- /** Title of the search result */
82
- title: string;
83
- /** Extracted text excerpt/content from the page */
84
- excerpt: string;
85
- /** Publication date of the content (may be null) */
86
- publishDate?: string | null;
87
- /** Relevance score for the result */
88
- relevanceScore?: number;
119
+ /** Title of the page, if available */
120
+ title?: string | null;
121
+ /** Publication date of the page (YYYY-MM-DD), if available */
122
+ publish_date?: string | null;
123
+ /** Relevant excerpts from the page, formatted as markdown */
124
+ excerpts: string[];
125
+ }
126
+
127
+ export interface ParallelSearchWarning {
128
+ /** Warning type, e.g. 'input_validation_warning'. New types may be added. */
129
+ type: string;
130
+ /** Human-readable message */
131
+ message: string;
132
+ /** Optional detail supporting the warning */
133
+ detail?: Record<string, unknown> | null;
134
+ }
135
+
136
+ export interface ParallelSearchUsage {
137
+ /** Usage item name, e.g. 'sku_search' */
138
+ name: string;
139
+ /** Count for the usage item */
140
+ count?: number;
89
141
  }
90
142
 
91
143
  export interface ParallelSearchResponse {
92
144
  /** Unique identifier for this search request */
93
- searchId: string;
94
- /** Array of search results */
145
+ search_id: string;
146
+ /** Search results, ordered by decreasing relevance */
95
147
  results: ParallelSearchResult[];
148
+ /** Non-fatal issues with the request, such as an ignored `location` */
149
+ warnings?: ParallelSearchWarning[] | null;
150
+ /** Usage reported by Parallel for this search */
151
+ usage?: ParallelSearchUsage[] | null;
152
+ /** Session identifier shared by the searches made during one request */
153
+ session_id?: string;
96
154
  }
97
155
 
98
156
  export interface ParallelSearchError {
99
157
  /** Error type */
100
158
  error:
101
159
  | 'api_error'
160
+ | 'configuration_error'
161
+ | 'execution_error'
162
+ | 'gateway_rate_limit'
163
+ | 'invalid_input'
102
164
  | 'rate_limit'
103
165
  | 'timeout'
104
- | 'invalid_input'
105
- | 'configuration_error'
106
- | 'unknown';
166
+ | 'unknown'
167
+ | 'unknown_tool';
107
168
  /** HTTP status code if applicable */
108
169
  statusCode?: number;
109
170
  /** Human-readable error message */
@@ -119,17 +180,14 @@ export interface ParallelSearchInput {
119
180
  objective: string;
120
181
 
121
182
  /**
122
- * Optional search queries to supplement the objective.
123
- * Maximum 200 characters per query.
183
+ * 2-3 concise keyword queries, 3-6 words each (max 5, 200 characters each).
124
184
  */
125
185
  search_queries?: string[];
126
186
 
127
187
  /**
128
- * Mode preset for different use cases:
129
- * - "one-shot": Comprehensive results with longer excerpts
130
- * - "agentic": Concise, token-efficient results for multi-step workflows
188
+ * Search mode. Defaults to `basic`.
131
189
  */
132
- mode?: 'one-shot' | 'agentic';
190
+ mode?: ParallelSearchMode;
133
191
 
134
192
  /**
135
193
  * Maximum number of results to return (1-20).
@@ -151,15 +209,28 @@ export interface ParallelSearchInput {
151
209
  */
152
210
  excerpts?: {
153
211
  max_chars_per_result?: number;
212
+ /** @deprecated Use the top-level `max_chars_total` instead. */
154
213
  max_chars_total?: number;
155
214
  };
156
215
 
216
+ /**
217
+ * Maximum total characters across all result excerpts.
218
+ */
219
+ max_chars_total?: number;
220
+
157
221
  /**
158
222
  * Fetch policy for controlling content freshness.
159
223
  */
160
224
  fetch_policy?: {
161
225
  max_age_seconds?: number;
226
+ timeout_seconds?: number;
227
+ disable_cache_fallback?: boolean;
162
228
  };
229
+
230
+ /**
231
+ * ISO 3166-1 alpha-2 country code to localize results.
232
+ */
233
+ location?: string;
163
234
  }
164
235
 
165
236
  export type ParallelSearchOutput = ParallelSearchResponse | ParallelSearchError;
@@ -177,14 +248,14 @@ const parallelSearchInputSchema = lazySchema(() =>
177
248
  .array(z.string())
178
249
  .optional()
179
250
  .describe(
180
- 'Optional search queries to supplement the objective. Maximum 200 characters per query.',
251
+ 'Provide 2-3 concise keyword queries, 3-6 words each (max 5, 200 chars each). Strongly recommended; the search runs on these queries.',
181
252
  ),
182
253
 
183
254
  mode: z
184
- .enum(['one-shot', 'agentic'])
255
+ .enum(parallelSearchModes)
185
256
  .optional()
186
257
  .describe(
187
- 'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.',
258
+ 'Search mode: "turbo" and "fast" return quickly with shorter excerpts, "basic" is balanced (default), "advanced" is the most thorough. "turbo" supports English and Japanese only. "one-shot" and "agentic" are deprecated aliases of "basic" and "advanced".',
188
259
  ),
189
260
 
190
261
  max_results: z
@@ -200,19 +271,19 @@ const parallelSearchInputSchema = lazySchema(() =>
200
271
  .array(z.string())
201
272
  .optional()
202
273
  .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).',
274
+ "Domains or domain/path prefixes to restrict results to, without scheme or port. Example: ['wikipedia.org', 'docs.python.org/3'].",
204
275
  ),
205
276
  exclude_domains: z
206
277
  .array(z.string())
207
278
  .optional()
208
279
  .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).',
280
+ "Domains or domain/path prefixes to exclude, without scheme or port. Example: ['reddit.com'].",
210
281
  ),
211
282
  after_date: z
212
283
  .string()
213
284
  .optional()
214
285
  .describe(
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.',
286
+ 'Only include results published on or after this date. Use an ISO 8601 calendar date formatted YYYY-MM-DD (e.g. 2025-01-01); do not include a time.',
216
287
  ),
217
288
  })
218
289
  .optional()
@@ -229,22 +300,46 @@ const parallelSearchInputSchema = lazySchema(() =>
229
300
  max_chars_total: z
230
301
  .number()
231
302
  .optional()
232
- .describe('Maximum total characters across all results.'),
303
+ .describe('Deprecated: use the top-level max_chars_total.'),
233
304
  })
234
305
  .optional()
235
306
  .describe('Excerpt configuration for controlling result length.'),
236
307
 
308
+ max_chars_total: z
309
+ .number()
310
+ .optional()
311
+ .describe('Maximum total characters across all result excerpts.'),
312
+
237
313
  fetch_policy: z
238
314
  .object({
239
315
  max_age_seconds: z
240
316
  .number()
241
317
  .optional()
242
318
  .describe(
243
- 'Maximum age in seconds for cached content. Set to 0 to always fetch fresh content.',
319
+ 'Maximum age of cached content in seconds before a live fetch, minimum 600.',
320
+ ),
321
+ timeout_seconds: z
322
+ .number()
323
+ .optional()
324
+ .describe(
325
+ 'Timeout in seconds for a live fetch when content is not cached. Capped by the gateway tool timeout.',
326
+ ),
327
+ disable_cache_fallback: z
328
+ .boolean()
329
+ .optional()
330
+ .describe(
331
+ 'Return an error instead of older cached content when a live fetch fails.',
244
332
  ),
245
333
  })
246
334
  .optional()
247
335
  .describe('Fetch policy for controlling content freshness.'),
336
+
337
+ location: z
338
+ .string()
339
+ .optional()
340
+ .describe(
341
+ 'ISO 3166-1 alpha-2 country code to localize results, e.g. "us".',
342
+ ),
248
343
  }),
249
344
  ),
250
345
  );
@@ -252,28 +347,45 @@ const parallelSearchInputSchema = lazySchema(() =>
252
347
  const parallelSearchOutputSchema = lazySchema(() =>
253
348
  zodSchema(
254
349
  z.union([
255
- // Success response
350
+ // Success response (Parallel's response, passed through by the gateway)
256
351
  z.object({
257
- searchId: z.string(),
352
+ search_id: z.string(),
258
353
  results: z.array(
259
354
  z.object({
260
355
  url: z.string(),
261
- title: z.string(),
262
- excerpt: z.string(),
263
- publishDate: z.string().nullable().optional(),
264
- relevanceScore: z.number().optional(),
356
+ title: z.string().nullable().optional(),
357
+ publish_date: z.string().nullable().optional(),
358
+ excerpts: z.array(z.string()),
265
359
  }),
266
360
  ),
361
+ warnings: z
362
+ .array(
363
+ z.object({
364
+ type: z.string(),
365
+ message: z.string(),
366
+ detail: z.record(z.string(), z.unknown()).nullable().optional(),
367
+ }),
368
+ )
369
+ .nullable()
370
+ .optional(),
371
+ usage: z
372
+ .array(z.object({ name: z.string(), count: z.number().optional() }))
373
+ .nullable()
374
+ .optional(),
375
+ session_id: z.string().optional(),
267
376
  }),
268
377
  // Error response
269
378
  z.object({
270
379
  error: z.enum([
271
380
  'api_error',
381
+ 'configuration_error',
382
+ 'execution_error',
383
+ 'gateway_rate_limit',
384
+ 'invalid_input',
272
385
  'rate_limit',
273
386
  'timeout',
274
- 'invalid_input',
275
- 'configuration_error',
276
387
  'unknown',
388
+ 'unknown_tool',
277
389
  ]),
278
390
  statusCode: z.number().optional(),
279
391
  message: z.string(),