@ai-sdk/gateway 3.0.135 → 3.0.136

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
@@ -544,6 +544,8 @@ var KNOWN_MODEL_TYPES = [
544
544
  "image",
545
545
  "language",
546
546
  "reranking",
547
+ "speech",
548
+ "transcription",
547
549
  "video"
548
550
  ];
549
551
 
@@ -1568,43 +1570,276 @@ var gatewayRerankingResponseSchema = lazySchema8(
1568
1570
  )
1569
1571
  );
1570
1572
 
1573
+ // src/gateway-speech-model.ts
1574
+ import {
1575
+ combineHeaders as combineHeaders6,
1576
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler9,
1577
+ createJsonResponseHandler as createJsonResponseHandler8,
1578
+ postJsonToApi as postJsonToApi6,
1579
+ resolve as resolve9
1580
+ } from "@ai-sdk/provider-utils";
1581
+ import { z as z12 } from "zod/v4";
1582
+ var GatewaySpeechModel = class {
1583
+ constructor(modelId, config) {
1584
+ this.modelId = modelId;
1585
+ this.config = config;
1586
+ this.specificationVersion = "v3";
1587
+ }
1588
+ get provider() {
1589
+ return this.config.provider;
1590
+ }
1591
+ async doGenerate({
1592
+ text,
1593
+ voice,
1594
+ outputFormat,
1595
+ instructions,
1596
+ speed,
1597
+ language,
1598
+ providerOptions,
1599
+ headers,
1600
+ abortSignal
1601
+ }) {
1602
+ var _a11;
1603
+ const resolvedHeaders = await resolve9(this.config.headers());
1604
+ try {
1605
+ const {
1606
+ responseHeaders,
1607
+ value: responseBody,
1608
+ rawValue
1609
+ } = await postJsonToApi6({
1610
+ url: this.getUrl(),
1611
+ headers: combineHeaders6(
1612
+ resolvedHeaders,
1613
+ headers != null ? headers : {},
1614
+ this.getModelConfigHeaders(),
1615
+ await resolve9(this.config.o11yHeaders)
1616
+ ),
1617
+ body: {
1618
+ text,
1619
+ ...voice && { voice },
1620
+ ...outputFormat && { outputFormat },
1621
+ ...instructions && { instructions },
1622
+ ...speed != null && { speed },
1623
+ ...language && { language },
1624
+ ...providerOptions && { providerOptions }
1625
+ },
1626
+ successfulResponseHandler: createJsonResponseHandler8(
1627
+ gatewaySpeechResponseSchema
1628
+ ),
1629
+ failedResponseHandler: createJsonErrorResponseHandler9({
1630
+ errorSchema: z12.any(),
1631
+ errorToMessage: (data) => data
1632
+ }),
1633
+ ...abortSignal && { abortSignal },
1634
+ fetch: this.config.fetch
1635
+ });
1636
+ return {
1637
+ audio: responseBody.audio,
1638
+ warnings: (_a11 = responseBody.warnings) != null ? _a11 : [],
1639
+ providerMetadata: responseBody.providerMetadata,
1640
+ response: {
1641
+ timestamp: /* @__PURE__ */ new Date(),
1642
+ modelId: this.modelId,
1643
+ headers: responseHeaders,
1644
+ body: rawValue
1645
+ }
1646
+ };
1647
+ } catch (error) {
1648
+ throw await asGatewayError(
1649
+ error,
1650
+ await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1651
+ );
1652
+ }
1653
+ }
1654
+ getUrl() {
1655
+ return `${this.config.baseURL}/speech-model`;
1656
+ }
1657
+ getModelConfigHeaders() {
1658
+ return {
1659
+ "ai-speech-model-specification-version": "3",
1660
+ "ai-model-id": this.modelId
1661
+ };
1662
+ }
1663
+ };
1664
+ var providerMetadataEntrySchema3 = z12.object({}).catchall(z12.unknown());
1665
+ var gatewaySpeechWarningSchema = z12.discriminatedUnion("type", [
1666
+ z12.object({
1667
+ type: z12.literal("unsupported"),
1668
+ feature: z12.string(),
1669
+ details: z12.string().optional()
1670
+ }),
1671
+ z12.object({
1672
+ type: z12.literal("compatibility"),
1673
+ feature: z12.string(),
1674
+ details: z12.string().optional()
1675
+ }),
1676
+ z12.object({
1677
+ type: z12.literal("other"),
1678
+ message: z12.string()
1679
+ })
1680
+ ]);
1681
+ var gatewaySpeechResponseSchema = z12.object({
1682
+ audio: z12.string(),
1683
+ warnings: z12.array(gatewaySpeechWarningSchema).optional(),
1684
+ providerMetadata: z12.record(z12.string(), providerMetadataEntrySchema3).optional()
1685
+ });
1686
+
1687
+ // src/gateway-transcription-model.ts
1688
+ import {
1689
+ combineHeaders as combineHeaders7,
1690
+ convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
1691
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler10,
1692
+ createJsonResponseHandler as createJsonResponseHandler9,
1693
+ postJsonToApi as postJsonToApi7,
1694
+ resolve as resolve10
1695
+ } from "@ai-sdk/provider-utils";
1696
+ import { z as z13 } from "zod/v4";
1697
+ var GatewayTranscriptionModel = class {
1698
+ constructor(modelId, config) {
1699
+ this.modelId = modelId;
1700
+ this.config = config;
1701
+ this.specificationVersion = "v3";
1702
+ }
1703
+ get provider() {
1704
+ return this.config.provider;
1705
+ }
1706
+ async doGenerate({
1707
+ audio,
1708
+ mediaType,
1709
+ providerOptions,
1710
+ headers,
1711
+ abortSignal
1712
+ }) {
1713
+ var _a11, _b11, _c, _d;
1714
+ const resolvedHeaders = await resolve10(this.config.headers());
1715
+ try {
1716
+ const {
1717
+ responseHeaders,
1718
+ value: responseBody,
1719
+ rawValue
1720
+ } = await postJsonToApi7({
1721
+ url: this.getUrl(),
1722
+ headers: combineHeaders7(
1723
+ resolvedHeaders,
1724
+ headers != null ? headers : {},
1725
+ this.getModelConfigHeaders(),
1726
+ await resolve10(this.config.o11yHeaders)
1727
+ ),
1728
+ body: {
1729
+ audio: audio instanceof Uint8Array ? convertUint8ArrayToBase643(audio) : audio,
1730
+ mediaType,
1731
+ ...providerOptions && { providerOptions }
1732
+ },
1733
+ successfulResponseHandler: createJsonResponseHandler9(
1734
+ gatewayTranscriptionResponseSchema
1735
+ ),
1736
+ failedResponseHandler: createJsonErrorResponseHandler10({
1737
+ errorSchema: z13.any(),
1738
+ errorToMessage: (data) => data
1739
+ }),
1740
+ ...abortSignal && { abortSignal },
1741
+ fetch: this.config.fetch
1742
+ });
1743
+ return {
1744
+ text: responseBody.text,
1745
+ segments: (_a11 = responseBody.segments) != null ? _a11 : [],
1746
+ language: (_b11 = responseBody.language) != null ? _b11 : void 0,
1747
+ durationInSeconds: (_c = responseBody.durationInSeconds) != null ? _c : void 0,
1748
+ warnings: (_d = responseBody.warnings) != null ? _d : [],
1749
+ providerMetadata: responseBody.providerMetadata,
1750
+ response: {
1751
+ timestamp: /* @__PURE__ */ new Date(),
1752
+ modelId: this.modelId,
1753
+ headers: responseHeaders,
1754
+ body: rawValue
1755
+ }
1756
+ };
1757
+ } catch (error) {
1758
+ throw await asGatewayError(
1759
+ error,
1760
+ await parseAuthMethod(resolvedHeaders != null ? resolvedHeaders : {})
1761
+ );
1762
+ }
1763
+ }
1764
+ getUrl() {
1765
+ return `${this.config.baseURL}/transcription-model`;
1766
+ }
1767
+ getModelConfigHeaders() {
1768
+ return {
1769
+ "ai-transcription-model-specification-version": "3",
1770
+ "ai-model-id": this.modelId
1771
+ };
1772
+ }
1773
+ };
1774
+ var providerMetadataEntrySchema4 = z13.object({}).catchall(z13.unknown());
1775
+ var gatewayTranscriptionWarningSchema = z13.discriminatedUnion("type", [
1776
+ z13.object({
1777
+ type: z13.literal("unsupported"),
1778
+ feature: z13.string(),
1779
+ details: z13.string().optional()
1780
+ }),
1781
+ z13.object({
1782
+ type: z13.literal("compatibility"),
1783
+ feature: z13.string(),
1784
+ details: z13.string().optional()
1785
+ }),
1786
+ z13.object({
1787
+ type: z13.literal("other"),
1788
+ message: z13.string()
1789
+ })
1790
+ ]);
1791
+ var gatewayTranscriptionResponseSchema = z13.object({
1792
+ text: z13.string(),
1793
+ segments: z13.array(
1794
+ z13.object({
1795
+ text: z13.string(),
1796
+ startSecond: z13.number(),
1797
+ endSecond: z13.number()
1798
+ })
1799
+ ).optional(),
1800
+ language: z13.string().nullish(),
1801
+ durationInSeconds: z13.number().nullish(),
1802
+ warnings: z13.array(gatewayTranscriptionWarningSchema).optional(),
1803
+ providerMetadata: z13.record(z13.string(), providerMetadataEntrySchema4).optional()
1804
+ });
1805
+
1571
1806
  // src/tool/parallel-search.ts
1572
1807
  import {
1573
1808
  createProviderToolFactoryWithOutputSchema,
1574
1809
  lazySchema as lazySchema9,
1575
1810
  zodSchema as zodSchema9
1576
1811
  } from "@ai-sdk/provider-utils";
1577
- import { z as z12 } from "zod";
1812
+ import { z as z14 } from "zod";
1578
1813
  var parallelSearchInputSchema = lazySchema9(
1579
1814
  () => zodSchema9(
1580
- z12.object({
1581
- objective: z12.string().describe(
1815
+ z14.object({
1816
+ objective: z14.string().describe(
1582
1817
  "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
1583
1818
  ),
1584
- search_queries: z12.array(z12.string()).optional().describe(
1819
+ search_queries: z14.array(z14.string()).optional().describe(
1585
1820
  "Optional search queries to supplement the objective. Maximum 200 characters per query."
1586
1821
  ),
1587
- mode: z12.enum(["one-shot", "agentic"]).optional().describe(
1822
+ mode: z14.enum(["one-shot", "agentic"]).optional().describe(
1588
1823
  'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
1589
1824
  ),
1590
- max_results: z12.number().optional().describe(
1825
+ max_results: z14.number().optional().describe(
1591
1826
  "Maximum number of results to return (1-20). Defaults to 10 if not specified."
1592
1827
  ),
1593
- source_policy: z12.object({
1594
- include_domains: z12.array(z12.string()).optional().describe("List of domains to include in search results."),
1595
- exclude_domains: z12.array(z12.string()).optional().describe("List of domains to exclude from search results."),
1596
- after_date: z12.string().optional().describe(
1828
+ source_policy: z14.object({
1829
+ include_domains: z14.array(z14.string()).optional().describe("List of domains to include in search results."),
1830
+ exclude_domains: z14.array(z14.string()).optional().describe("List of domains to exclude from search results."),
1831
+ after_date: z14.string().optional().describe(
1597
1832
  "Only include results published after this date (ISO 8601 format)."
1598
1833
  )
1599
1834
  }).optional().describe(
1600
1835
  "Source policy for controlling which domains to include/exclude and freshness."
1601
1836
  ),
1602
- excerpts: z12.object({
1603
- max_chars_per_result: z12.number().optional().describe("Maximum characters per result."),
1604
- max_chars_total: z12.number().optional().describe("Maximum total characters across all results.")
1837
+ excerpts: z14.object({
1838
+ max_chars_per_result: z14.number().optional().describe("Maximum characters per result."),
1839
+ max_chars_total: z14.number().optional().describe("Maximum total characters across all results.")
1605
1840
  }).optional().describe("Excerpt configuration for controlling result length."),
1606
- fetch_policy: z12.object({
1607
- max_age_seconds: z12.number().optional().describe(
1841
+ fetch_policy: z14.object({
1842
+ max_age_seconds: z14.number().optional().describe(
1608
1843
  "Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
1609
1844
  )
1610
1845
  }).optional().describe("Fetch policy for controlling content freshness.")
@@ -1613,23 +1848,23 @@ var parallelSearchInputSchema = lazySchema9(
1613
1848
  );
1614
1849
  var parallelSearchOutputSchema = lazySchema9(
1615
1850
  () => zodSchema9(
1616
- z12.union([
1851
+ z14.union([
1617
1852
  // Success response
1618
- z12.object({
1619
- searchId: z12.string(),
1620
- results: z12.array(
1621
- z12.object({
1622
- url: z12.string(),
1623
- title: z12.string(),
1624
- excerpt: z12.string(),
1625
- publishDate: z12.string().nullable().optional(),
1626
- relevanceScore: z12.number().optional()
1853
+ z14.object({
1854
+ searchId: z14.string(),
1855
+ results: z14.array(
1856
+ z14.object({
1857
+ url: z14.string(),
1858
+ title: z14.string(),
1859
+ excerpt: z14.string(),
1860
+ publishDate: z14.string().nullable().optional(),
1861
+ relevanceScore: z14.number().optional()
1627
1862
  })
1628
1863
  )
1629
1864
  }),
1630
1865
  // Error response
1631
- z12.object({
1632
- error: z12.enum([
1866
+ z14.object({
1867
+ error: z14.enum([
1633
1868
  "api_error",
1634
1869
  "rate_limit",
1635
1870
  "timeout",
@@ -1637,8 +1872,8 @@ var parallelSearchOutputSchema = lazySchema9(
1637
1872
  "configuration_error",
1638
1873
  "unknown"
1639
1874
  ]),
1640
- statusCode: z12.number().optional(),
1641
- message: z12.string()
1875
+ statusCode: z14.number().optional(),
1876
+ message: z14.string()
1642
1877
  })
1643
1878
  ])
1644
1879
  )
@@ -1656,44 +1891,44 @@ import {
1656
1891
  lazySchema as lazySchema10,
1657
1892
  zodSchema as zodSchema10
1658
1893
  } from "@ai-sdk/provider-utils";
1659
- import { z as z13 } from "zod";
1894
+ import { z as z15 } from "zod";
1660
1895
  var perplexitySearchInputSchema = lazySchema10(
1661
1896
  () => zodSchema10(
1662
- z13.object({
1663
- query: z13.union([z13.string(), z13.array(z13.string())]).describe(
1897
+ z15.object({
1898
+ query: z15.union([z15.string(), z15.array(z15.string())]).describe(
1664
1899
  "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
1665
1900
  ),
1666
- max_results: z13.number().optional().describe(
1901
+ max_results: z15.number().optional().describe(
1667
1902
  "Maximum number of search results to return (1-20, default: 10)"
1668
1903
  ),
1669
- max_tokens_per_page: z13.number().optional().describe(
1904
+ max_tokens_per_page: z15.number().optional().describe(
1670
1905
  "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
1671
1906
  ),
1672
- max_tokens: z13.number().optional().describe(
1907
+ max_tokens: z15.number().optional().describe(
1673
1908
  "Maximum total tokens across all search results (default: 25000, max: 1000000)"
1674
1909
  ),
1675
- country: z13.string().optional().describe(
1910
+ country: z15.string().optional().describe(
1676
1911
  "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
1677
1912
  ),
1678
- search_domain_filter: z13.array(z13.string()).optional().describe(
1913
+ search_domain_filter: z15.array(z15.string()).optional().describe(
1679
1914
  "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
1680
1915
  ),
1681
- search_language_filter: z13.array(z13.string()).optional().describe(
1916
+ search_language_filter: z15.array(z15.string()).optional().describe(
1682
1917
  "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
1683
1918
  ),
1684
- search_after_date: z13.string().optional().describe(
1919
+ search_after_date: z15.string().optional().describe(
1685
1920
  "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1686
1921
  ),
1687
- search_before_date: z13.string().optional().describe(
1922
+ search_before_date: z15.string().optional().describe(
1688
1923
  "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1689
1924
  ),
1690
- last_updated_after_filter: z13.string().optional().describe(
1925
+ last_updated_after_filter: z15.string().optional().describe(
1691
1926
  "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
1692
1927
  ),
1693
- last_updated_before_filter: z13.string().optional().describe(
1928
+ last_updated_before_filter: z15.string().optional().describe(
1694
1929
  "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
1695
1930
  ),
1696
- search_recency_filter: z13.enum(["day", "week", "month", "year"]).optional().describe(
1931
+ search_recency_filter: z15.enum(["day", "week", "month", "year"]).optional().describe(
1697
1932
  "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
1698
1933
  )
1699
1934
  })
@@ -1701,31 +1936,31 @@ var perplexitySearchInputSchema = lazySchema10(
1701
1936
  );
1702
1937
  var perplexitySearchOutputSchema = lazySchema10(
1703
1938
  () => zodSchema10(
1704
- z13.union([
1939
+ z15.union([
1705
1940
  // Success response
1706
- z13.object({
1707
- results: z13.array(
1708
- z13.object({
1709
- title: z13.string(),
1710
- url: z13.string(),
1711
- snippet: z13.string(),
1712
- date: z13.string().optional(),
1713
- lastUpdated: z13.string().optional()
1941
+ z15.object({
1942
+ results: z15.array(
1943
+ z15.object({
1944
+ title: z15.string(),
1945
+ url: z15.string(),
1946
+ snippet: z15.string(),
1947
+ date: z15.string().optional(),
1948
+ lastUpdated: z15.string().optional()
1714
1949
  })
1715
1950
  ),
1716
- id: z13.string()
1951
+ id: z15.string()
1717
1952
  }),
1718
1953
  // Error response
1719
- z13.object({
1720
- error: z13.enum([
1954
+ z15.object({
1955
+ error: z15.enum([
1721
1956
  "api_error",
1722
1957
  "rate_limit",
1723
1958
  "timeout",
1724
1959
  "invalid_input",
1725
1960
  "unknown"
1726
1961
  ]),
1727
- statusCode: z13.number().optional(),
1728
- message: z13.string()
1962
+ statusCode: z15.number().optional(),
1963
+ message: z15.string()
1729
1964
  })
1730
1965
  ])
1731
1966
  )
@@ -1767,7 +2002,7 @@ async function getVercelRequestId() {
1767
2002
  }
1768
2003
 
1769
2004
  // src/version.ts
1770
- var VERSION = true ? "3.0.135" : "0.0.0-test";
2005
+ var VERSION = true ? "3.0.136" : "0.0.0-test";
1771
2006
 
1772
2007
  // src/gateway-provider.ts
1773
2008
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
@@ -1947,6 +2182,28 @@ function createGatewayProvider(options = {}) {
1947
2182
  };
1948
2183
  provider.rerankingModel = createRerankingModel;
1949
2184
  provider.reranking = createRerankingModel;
2185
+ const createSpeechModel = (modelId) => {
2186
+ return new GatewaySpeechModel(modelId, {
2187
+ provider: "gateway",
2188
+ baseURL,
2189
+ headers: getHeaders,
2190
+ fetch: options.fetch,
2191
+ o11yHeaders: createO11yHeaders()
2192
+ });
2193
+ };
2194
+ provider.speechModel = createSpeechModel;
2195
+ provider.speech = createSpeechModel;
2196
+ const createTranscriptionModel = (modelId) => {
2197
+ return new GatewayTranscriptionModel(modelId, {
2198
+ provider: "gateway",
2199
+ baseURL,
2200
+ headers: getHeaders,
2201
+ fetch: options.fetch,
2202
+ o11yHeaders: createO11yHeaders()
2203
+ });
2204
+ };
2205
+ provider.transcriptionModel = createTranscriptionModel;
2206
+ provider.transcription = createTranscriptionModel;
1950
2207
  provider.chat = provider.languageModel;
1951
2208
  provider.embedding = provider.embeddingModel;
1952
2209
  provider.image = provider.imageModel;