@ai-sdk/gateway 4.0.0-beta.39 → 4.0.0-beta.40

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/dist/index.mjs CHANGED
@@ -1357,68 +1357,160 @@ var gatewayVideoEventSchema = z10.discriminatedUnion("type", [
1357
1357
  })
1358
1358
  ]);
1359
1359
 
1360
- // src/tool/parallel-search.ts
1360
+ // src/gateway-reranking-model.ts
1361
1361
  import {
1362
- createProviderToolFactoryWithOutputSchema,
1362
+ combineHeaders as combineHeaders5,
1363
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler8,
1364
+ createJsonResponseHandler as createJsonResponseHandler7,
1363
1365
  lazySchema as lazySchema8,
1366
+ postJsonToApi as postJsonToApi5,
1367
+ resolve as resolve8,
1364
1368
  zodSchema as zodSchema8
1365
1369
  } from "@ai-sdk/provider-utils";
1366
- import { z as z11 } from "zod";
1367
- var parallelSearchInputSchema = lazySchema8(
1370
+ import { z as z11 } from "zod/v4";
1371
+ var GatewayRerankingModel = class {
1372
+ constructor(modelId, config) {
1373
+ this.modelId = modelId;
1374
+ this.config = config;
1375
+ this.specificationVersion = "v4";
1376
+ }
1377
+ get provider() {
1378
+ return this.config.provider;
1379
+ }
1380
+ async doRerank({
1381
+ documents,
1382
+ query,
1383
+ topN,
1384
+ headers,
1385
+ abortSignal,
1386
+ providerOptions
1387
+ }) {
1388
+ const resolvedHeaders = await resolve8(this.config.headers());
1389
+ try {
1390
+ const {
1391
+ responseHeaders,
1392
+ value: responseBody,
1393
+ rawValue
1394
+ } = await postJsonToApi5({
1395
+ url: this.getUrl(),
1396
+ headers: combineHeaders5(
1397
+ resolvedHeaders,
1398
+ headers != null ? headers : {},
1399
+ this.getModelConfigHeaders(),
1400
+ await resolve8(this.config.o11yHeaders)
1401
+ ),
1402
+ body: {
1403
+ documents,
1404
+ query,
1405
+ ...topN != null ? { topN } : {},
1406
+ ...providerOptions ? { providerOptions } : {}
1407
+ },
1408
+ successfulResponseHandler: createJsonResponseHandler7(
1409
+ gatewayRerankingResponseSchema
1410
+ ),
1411
+ failedResponseHandler: createJsonErrorResponseHandler8({
1412
+ errorSchema: z11.any(),
1413
+ errorToMessage: (data) => data
1414
+ }),
1415
+ ...abortSignal && { abortSignal },
1416
+ fetch: this.config.fetch
1417
+ });
1418
+ return {
1419
+ ranking: responseBody.ranking,
1420
+ providerMetadata: responseBody.providerMetadata,
1421
+ response: { headers: responseHeaders, body: rawValue },
1422
+ warnings: []
1423
+ };
1424
+ } catch (error) {
1425
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
1426
+ }
1427
+ }
1428
+ getUrl() {
1429
+ return `${this.config.baseURL}/reranking-model`;
1430
+ }
1431
+ getModelConfigHeaders() {
1432
+ return {
1433
+ "ai-reranking-model-specification-version": "4",
1434
+ "ai-model-id": this.modelId
1435
+ };
1436
+ }
1437
+ };
1438
+ var gatewayRerankingResponseSchema = lazySchema8(
1368
1439
  () => zodSchema8(
1369
1440
  z11.object({
1370
- objective: z11.string().describe(
1441
+ ranking: z11.array(
1442
+ z11.object({
1443
+ index: z11.number(),
1444
+ relevanceScore: z11.number()
1445
+ })
1446
+ ),
1447
+ providerMetadata: z11.record(z11.string(), z11.record(z11.string(), z11.unknown())).optional()
1448
+ })
1449
+ )
1450
+ );
1451
+
1452
+ // src/tool/parallel-search.ts
1453
+ import {
1454
+ createProviderToolFactoryWithOutputSchema,
1455
+ lazySchema as lazySchema9,
1456
+ zodSchema as zodSchema9
1457
+ } from "@ai-sdk/provider-utils";
1458
+ import { z as z12 } from "zod";
1459
+ var parallelSearchInputSchema = lazySchema9(
1460
+ () => zodSchema9(
1461
+ z12.object({
1462
+ objective: z12.string().describe(
1371
1463
  "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
1372
1464
  ),
1373
- search_queries: z11.array(z11.string()).optional().describe(
1465
+ search_queries: z12.array(z12.string()).optional().describe(
1374
1466
  "Optional search queries to supplement the objective. Maximum 200 characters per query."
1375
1467
  ),
1376
- mode: z11.enum(["one-shot", "agentic"]).optional().describe(
1468
+ mode: z12.enum(["one-shot", "agentic"]).optional().describe(
1377
1469
  'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
1378
1470
  ),
1379
- max_results: z11.number().optional().describe(
1471
+ max_results: z12.number().optional().describe(
1380
1472
  "Maximum number of results to return (1-20). Defaults to 10 if not specified."
1381
1473
  ),
1382
- source_policy: z11.object({
1383
- include_domains: z11.array(z11.string()).optional().describe("List of domains to include in search results."),
1384
- exclude_domains: z11.array(z11.string()).optional().describe("List of domains to exclude from search results."),
1385
- after_date: z11.string().optional().describe(
1474
+ source_policy: z12.object({
1475
+ include_domains: z12.array(z12.string()).optional().describe("List of domains to include in search results."),
1476
+ exclude_domains: z12.array(z12.string()).optional().describe("List of domains to exclude from search results."),
1477
+ after_date: z12.string().optional().describe(
1386
1478
  "Only include results published after this date (ISO 8601 format)."
1387
1479
  )
1388
1480
  }).optional().describe(
1389
1481
  "Source policy for controlling which domains to include/exclude and freshness."
1390
1482
  ),
1391
- excerpts: z11.object({
1392
- max_chars_per_result: z11.number().optional().describe("Maximum characters per result."),
1393
- max_chars_total: z11.number().optional().describe("Maximum total characters across all results.")
1483
+ excerpts: z12.object({
1484
+ max_chars_per_result: z12.number().optional().describe("Maximum characters per result."),
1485
+ max_chars_total: z12.number().optional().describe("Maximum total characters across all results.")
1394
1486
  }).optional().describe("Excerpt configuration for controlling result length."),
1395
- fetch_policy: z11.object({
1396
- max_age_seconds: z11.number().optional().describe(
1487
+ fetch_policy: z12.object({
1488
+ max_age_seconds: z12.number().optional().describe(
1397
1489
  "Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
1398
1490
  )
1399
1491
  }).optional().describe("Fetch policy for controlling content freshness.")
1400
1492
  })
1401
1493
  )
1402
1494
  );
1403
- var parallelSearchOutputSchema = lazySchema8(
1404
- () => zodSchema8(
1405
- z11.union([
1495
+ var parallelSearchOutputSchema = lazySchema9(
1496
+ () => zodSchema9(
1497
+ z12.union([
1406
1498
  // Success response
1407
- z11.object({
1408
- searchId: z11.string(),
1409
- results: z11.array(
1410
- z11.object({
1411
- url: z11.string(),
1412
- title: z11.string(),
1413
- excerpt: z11.string(),
1414
- publishDate: z11.string().nullable().optional(),
1415
- relevanceScore: z11.number().optional()
1499
+ z12.object({
1500
+ searchId: z12.string(),
1501
+ results: z12.array(
1502
+ z12.object({
1503
+ url: z12.string(),
1504
+ title: z12.string(),
1505
+ excerpt: z12.string(),
1506
+ publishDate: z12.string().nullable().optional(),
1507
+ relevanceScore: z12.number().optional()
1416
1508
  })
1417
1509
  )
1418
1510
  }),
1419
1511
  // Error response
1420
- z11.object({
1421
- error: z11.enum([
1512
+ z12.object({
1513
+ error: z12.enum([
1422
1514
  "api_error",
1423
1515
  "rate_limit",
1424
1516
  "timeout",
@@ -1426,8 +1518,8 @@ var parallelSearchOutputSchema = lazySchema8(
1426
1518
  "configuration_error",
1427
1519
  "unknown"
1428
1520
  ]),
1429
- statusCode: z11.number().optional(),
1430
- message: z11.string()
1521
+ statusCode: z12.number().optional(),
1522
+ message: z12.string()
1431
1523
  })
1432
1524
  ])
1433
1525
  )
@@ -1442,79 +1534,79 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
1442
1534
  // src/tool/perplexity-search.ts
1443
1535
  import {
1444
1536
  createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema2,
1445
- lazySchema as lazySchema9,
1446
- zodSchema as zodSchema9
1537
+ lazySchema as lazySchema10,
1538
+ zodSchema as zodSchema10
1447
1539
  } from "@ai-sdk/provider-utils";
1448
- import { z as z12 } from "zod";
1449
- var perplexitySearchInputSchema = lazySchema9(
1450
- () => zodSchema9(
1451
- z12.object({
1452
- query: z12.union([z12.string(), z12.array(z12.string())]).describe(
1540
+ import { z as z13 } from "zod";
1541
+ var perplexitySearchInputSchema = lazySchema10(
1542
+ () => zodSchema10(
1543
+ z13.object({
1544
+ query: z13.union([z13.string(), z13.array(z13.string())]).describe(
1453
1545
  "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
1454
1546
  ),
1455
- max_results: z12.number().optional().describe(
1547
+ max_results: z13.number().optional().describe(
1456
1548
  "Maximum number of search results to return (1-20, default: 10)"
1457
1549
  ),
1458
- max_tokens_per_page: z12.number().optional().describe(
1550
+ max_tokens_per_page: z13.number().optional().describe(
1459
1551
  "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
1460
1552
  ),
1461
- max_tokens: z12.number().optional().describe(
1553
+ max_tokens: z13.number().optional().describe(
1462
1554
  "Maximum total tokens across all search results (default: 25000, max: 1000000)"
1463
1555
  ),
1464
- country: z12.string().optional().describe(
1556
+ country: z13.string().optional().describe(
1465
1557
  "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
1466
1558
  ),
1467
- search_domain_filter: z12.array(z12.string()).optional().describe(
1559
+ search_domain_filter: z13.array(z13.string()).optional().describe(
1468
1560
  "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
1469
1561
  ),
1470
- search_language_filter: z12.array(z12.string()).optional().describe(
1562
+ search_language_filter: z13.array(z13.string()).optional().describe(
1471
1563
  "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
1472
1564
  ),
1473
- search_after_date: z12.string().optional().describe(
1565
+ search_after_date: z13.string().optional().describe(
1474
1566
  "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1475
1567
  ),
1476
- search_before_date: z12.string().optional().describe(
1568
+ search_before_date: z13.string().optional().describe(
1477
1569
  "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1478
1570
  ),
1479
- last_updated_after_filter: z12.string().optional().describe(
1571
+ last_updated_after_filter: z13.string().optional().describe(
1480
1572
  "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1481
1573
  ),
1482
- last_updated_before_filter: z12.string().optional().describe(
1574
+ last_updated_before_filter: z13.string().optional().describe(
1483
1575
  "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1484
1576
  ),
1485
- search_recency_filter: z12.enum(["day", "week", "month", "year"]).optional().describe(
1577
+ search_recency_filter: z13.enum(["day", "week", "month", "year"]).optional().describe(
1486
1578
  "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
1487
1579
  )
1488
1580
  })
1489
1581
  )
1490
1582
  );
1491
- var perplexitySearchOutputSchema = lazySchema9(
1492
- () => zodSchema9(
1493
- z12.union([
1583
+ var perplexitySearchOutputSchema = lazySchema10(
1584
+ () => zodSchema10(
1585
+ z13.union([
1494
1586
  // Success response
1495
- z12.object({
1496
- results: z12.array(
1497
- z12.object({
1498
- title: z12.string(),
1499
- url: z12.string(),
1500
- snippet: z12.string(),
1501
- date: z12.string().optional(),
1502
- lastUpdated: z12.string().optional()
1587
+ z13.object({
1588
+ results: z13.array(
1589
+ z13.object({
1590
+ title: z13.string(),
1591
+ url: z13.string(),
1592
+ snippet: z13.string(),
1593
+ date: z13.string().optional(),
1594
+ lastUpdated: z13.string().optional()
1503
1595
  })
1504
1596
  ),
1505
- id: z12.string()
1597
+ id: z13.string()
1506
1598
  }),
1507
1599
  // Error response
1508
- z12.object({
1509
- error: z12.enum([
1600
+ z13.object({
1601
+ error: z13.enum([
1510
1602
  "api_error",
1511
1603
  "rate_limit",
1512
1604
  "timeout",
1513
1605
  "invalid_input",
1514
1606
  "unknown"
1515
1607
  ]),
1516
- statusCode: z12.number().optional(),
1517
- message: z12.string()
1608
+ statusCode: z13.number().optional(),
1609
+ message: z13.string()
1518
1610
  })
1519
1611
  ])
1520
1612
  )
@@ -1559,7 +1651,7 @@ async function getVercelRequestId() {
1559
1651
  import { withUserAgentSuffix } from "@ai-sdk/provider-utils";
1560
1652
 
1561
1653
  // src/version.ts
1562
- var VERSION = true ? "4.0.0-beta.39" : "0.0.0-test";
1654
+ var VERSION = true ? "4.0.0-beta.40" : "0.0.0-test";
1563
1655
 
1564
1656
  // src/gateway-provider.ts
1565
1657
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -1728,6 +1820,17 @@ function createGatewayProvider(options = {}) {
1728
1820
  o11yHeaders: createO11yHeaders()
1729
1821
  });
1730
1822
  };
1823
+ const createRerankingModel = (modelId) => {
1824
+ return new GatewayRerankingModel(modelId, {
1825
+ provider: "gateway",
1826
+ baseURL,
1827
+ headers: getHeaders,
1828
+ fetch: options.fetch,
1829
+ o11yHeaders: createO11yHeaders()
1830
+ });
1831
+ };
1832
+ provider.rerankingModel = createRerankingModel;
1833
+ provider.reranking = createRerankingModel;
1731
1834
  provider.chat = provider.languageModel;
1732
1835
  provider.embedding = provider.embeddingModel;
1733
1836
  provider.image = provider.imageModel;