@ai-sdk/openai 2.0.0-canary.2 → 2.0.0-canary.4

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
@@ -23,7 +23,6 @@ import { z as z2 } from "zod";
23
23
  import {
24
24
  UnsupportedFunctionalityError
25
25
  } from "@ai-sdk/provider";
26
- import { convertUint8ArrayToBase64 } from "@ai-sdk/provider-utils";
27
26
  function convertToOpenAIChatMessages({
28
27
  prompt,
29
28
  useLegacyFunctionCalling = false,
@@ -67,55 +66,65 @@ function convertToOpenAIChatMessages({
67
66
  messages.push({
68
67
  role: "user",
69
68
  content: content.map((part, index) => {
70
- var _a, _b, _c, _d;
69
+ var _a, _b, _c;
71
70
  switch (part.type) {
72
71
  case "text": {
73
72
  return { type: "text", text: part.text };
74
73
  }
75
- case "image": {
76
- return {
77
- type: "image_url",
78
- image_url: {
79
- url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${convertUint8ArrayToBase64(part.image)}`,
80
- // OpenAI specific extension: image detail
81
- detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
82
- }
83
- };
84
- }
85
74
  case "file": {
86
- if (part.data instanceof URL) {
87
- throw new UnsupportedFunctionalityError({
88
- functionality: "'File content parts with URL data' functionality not supported."
89
- });
90
- }
91
- switch (part.mimeType) {
92
- case "audio/wav": {
93
- return {
94
- type: "input_audio",
95
- input_audio: { data: part.data, format: "wav" }
96
- };
97
- }
98
- case "audio/mp3":
99
- case "audio/mpeg": {
100
- return {
101
- type: "input_audio",
102
- input_audio: { data: part.data, format: "mp3" }
103
- };
75
+ if (part.mediaType.startsWith("image/")) {
76
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
77
+ return {
78
+ type: "image_url",
79
+ image_url: {
80
+ url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
81
+ // OpenAI specific extension: image detail
82
+ detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
83
+ }
84
+ };
85
+ } else if (part.mediaType.startsWith("audio/")) {
86
+ if (part.data instanceof URL) {
87
+ throw new UnsupportedFunctionalityError({
88
+ functionality: "audio file parts with URLs"
89
+ });
104
90
  }
105
- case "application/pdf": {
106
- return {
107
- type: "file",
108
- file: {
109
- filename: (_d = part.filename) != null ? _d : `part-${index}.pdf`,
110
- file_data: `data:application/pdf;base64,${part.data}`
111
- }
112
- };
91
+ switch (part.mediaType) {
92
+ case "audio/wav": {
93
+ return {
94
+ type: "input_audio",
95
+ input_audio: { data: part.data, format: "wav" }
96
+ };
97
+ }
98
+ case "audio/mp3":
99
+ case "audio/mpeg": {
100
+ return {
101
+ type: "input_audio",
102
+ input_audio: { data: part.data, format: "mp3" }
103
+ };
104
+ }
105
+ default: {
106
+ throw new UnsupportedFunctionalityError({
107
+ functionality: `audio content parts with media type ${part.mediaType}`
108
+ });
109
+ }
113
110
  }
114
- default: {
111
+ } else if (part.mediaType === "application/pdf") {
112
+ if (part.data instanceof URL) {
115
113
  throw new UnsupportedFunctionalityError({
116
- functionality: `File content part type ${part.mimeType} in user messages`
114
+ functionality: "PDF file parts with URLs"
117
115
  });
118
116
  }
117
+ return {
118
+ type: "file",
119
+ file: {
120
+ filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
121
+ file_data: `data:application/pdf;base64,${part.data}`
122
+ }
123
+ };
124
+ } else {
125
+ throw new UnsupportedFunctionalityError({
126
+ functionality: `file part media type ${part.mediaType}`
127
+ });
119
128
  }
120
129
  }
121
130
  }
@@ -350,7 +359,7 @@ function prepareTools({
350
359
  default: {
351
360
  const _exhaustiveCheck = type;
352
361
  throw new UnsupportedFunctionalityError2({
353
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
362
+ functionality: `tool choice type: ${_exhaustiveCheck}`
354
363
  });
355
364
  }
356
365
  }
@@ -612,9 +621,12 @@ var OpenAIChatLanguageModel = class {
612
621
  completionTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : NaN
613
622
  },
614
623
  rawCall: { rawPrompt, rawSettings },
615
- rawResponse: { headers: responseHeaders, body: rawResponse },
616
624
  request: { body: JSON.stringify(body) },
617
- response: getResponseMetadata(response),
625
+ response: {
626
+ ...getResponseMetadata(response),
627
+ headers: responseHeaders,
628
+ body: rawResponse
629
+ },
618
630
  warnings,
619
631
  logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
620
632
  providerMetadata
@@ -660,7 +672,7 @@ var OpenAIChatLanguageModel = class {
660
672
  return {
661
673
  stream: simulatedStream,
662
674
  rawCall: result.rawCall,
663
- rawResponse: result.rawResponse,
675
+ response: result.response,
664
676
  warnings: result.warnings
665
677
  };
666
678
  }
@@ -870,7 +882,7 @@ var OpenAIChatLanguageModel = class {
870
882
  })
871
883
  ),
872
884
  rawCall: { rawPrompt, rawSettings },
873
- rawResponse: { headers: responseHeaders },
885
+ response: { headers: responseHeaders },
874
886
  request: { body: JSON.stringify(body) },
875
887
  warnings
876
888
  };
@@ -1058,13 +1070,8 @@ function convertToOpenAICompletionPrompt({
1058
1070
  case "text": {
1059
1071
  return part.text;
1060
1072
  }
1061
- case "image": {
1062
- throw new UnsupportedFunctionalityError4({
1063
- functionality: "images"
1064
- });
1065
- }
1066
1073
  }
1067
- }).join("");
1074
+ }).filter(Boolean).join("");
1068
1075
  text += `${user}:
1069
1076
  ${userMessage}
1070
1077
 
@@ -1226,10 +1233,13 @@ var OpenAICompletionLanguageModel = class {
1226
1233
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
1227
1234
  logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
1228
1235
  rawCall: { rawPrompt, rawSettings },
1229
- rawResponse: { headers: responseHeaders, body: rawResponse },
1230
- response: getResponseMetadata(response),
1231
- warnings,
1232
- request: { body: JSON.stringify(args) }
1236
+ request: { body: JSON.stringify(args) },
1237
+ response: {
1238
+ ...getResponseMetadata(response),
1239
+ headers: responseHeaders,
1240
+ body: rawResponse
1241
+ },
1242
+ warnings
1233
1243
  };
1234
1244
  }
1235
1245
  async doStream(options) {
@@ -1319,7 +1329,7 @@ var OpenAICompletionLanguageModel = class {
1319
1329
  })
1320
1330
  ),
1321
1331
  rawCall: { rawPrompt, rawSettings },
1322
- rawResponse: { headers: responseHeaders },
1332
+ response: { headers: responseHeaders },
1323
1333
  warnings,
1324
1334
  request: { body: JSON.stringify(body) }
1325
1335
  };
@@ -1552,22 +1562,201 @@ var openaiTools = {
1552
1562
  webSearchPreview: webSearchPreviewTool
1553
1563
  };
1554
1564
 
1555
- // src/responses/openai-responses-language-model.ts
1565
+ // src/openai-transcription-model.ts
1556
1566
  import {
1557
1567
  combineHeaders as combineHeaders5,
1558
- createEventSourceResponseHandler as createEventSourceResponseHandler3,
1568
+ convertBase64ToUint8Array,
1559
1569
  createJsonResponseHandler as createJsonResponseHandler5,
1560
- generateId as generateId2,
1561
1570
  parseProviderOptions,
1562
- postJsonToApi as postJsonToApi5
1571
+ postFormDataToApi
1563
1572
  } from "@ai-sdk/provider-utils";
1564
1573
  import { z as z7 } from "zod";
1574
+ var OpenAIProviderOptionsSchema = z7.object({
1575
+ include: z7.array(z7.string()).optional().describe(
1576
+ "Additional information to include in the transcription response."
1577
+ ),
1578
+ language: z7.string().optional().describe("The language of the input audio in ISO-639-1 format."),
1579
+ prompt: z7.string().optional().describe(
1580
+ "An optional text to guide the model's style or continue a previous audio segment."
1581
+ ),
1582
+ temperature: z7.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
1583
+ timestampGranularities: z7.array(z7.enum(["word", "segment"])).optional().default(["segment"]).describe(
1584
+ "The timestamp granularities to populate for this transcription."
1585
+ )
1586
+ });
1587
+ var languageMap = {
1588
+ afrikaans: "af",
1589
+ arabic: "ar",
1590
+ armenian: "hy",
1591
+ azerbaijani: "az",
1592
+ belarusian: "be",
1593
+ bosnian: "bs",
1594
+ bulgarian: "bg",
1595
+ catalan: "ca",
1596
+ chinese: "zh",
1597
+ croatian: "hr",
1598
+ czech: "cs",
1599
+ danish: "da",
1600
+ dutch: "nl",
1601
+ english: "en",
1602
+ estonian: "et",
1603
+ finnish: "fi",
1604
+ french: "fr",
1605
+ galician: "gl",
1606
+ german: "de",
1607
+ greek: "el",
1608
+ hebrew: "he",
1609
+ hindi: "hi",
1610
+ hungarian: "hu",
1611
+ icelandic: "is",
1612
+ indonesian: "id",
1613
+ italian: "it",
1614
+ japanese: "ja",
1615
+ kannada: "kn",
1616
+ kazakh: "kk",
1617
+ korean: "ko",
1618
+ latvian: "lv",
1619
+ lithuanian: "lt",
1620
+ macedonian: "mk",
1621
+ malay: "ms",
1622
+ marathi: "mr",
1623
+ maori: "mi",
1624
+ nepali: "ne",
1625
+ norwegian: "no",
1626
+ persian: "fa",
1627
+ polish: "pl",
1628
+ portuguese: "pt",
1629
+ romanian: "ro",
1630
+ russian: "ru",
1631
+ serbian: "sr",
1632
+ slovak: "sk",
1633
+ slovenian: "sl",
1634
+ spanish: "es",
1635
+ swahili: "sw",
1636
+ swedish: "sv",
1637
+ tagalog: "tl",
1638
+ tamil: "ta",
1639
+ thai: "th",
1640
+ turkish: "tr",
1641
+ ukrainian: "uk",
1642
+ urdu: "ur",
1643
+ vietnamese: "vi",
1644
+ welsh: "cy"
1645
+ };
1646
+ var OpenAITranscriptionModel = class {
1647
+ constructor(modelId, config) {
1648
+ this.modelId = modelId;
1649
+ this.config = config;
1650
+ this.specificationVersion = "v1";
1651
+ }
1652
+ get provider() {
1653
+ return this.config.provider;
1654
+ }
1655
+ getArgs({
1656
+ audio,
1657
+ mediaType,
1658
+ providerOptions
1659
+ }) {
1660
+ const warnings = [];
1661
+ const openAIOptions = parseProviderOptions({
1662
+ provider: "openai",
1663
+ providerOptions,
1664
+ schema: OpenAIProviderOptionsSchema
1665
+ });
1666
+ const formData = new FormData();
1667
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
1668
+ formData.append("model", this.modelId);
1669
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
1670
+ if (openAIOptions) {
1671
+ const transcriptionModelOptions = {
1672
+ include: openAIOptions.include,
1673
+ language: openAIOptions.language,
1674
+ prompt: openAIOptions.prompt,
1675
+ temperature: openAIOptions.temperature,
1676
+ timestamp_granularities: openAIOptions.timestampGranularities
1677
+ };
1678
+ for (const key in transcriptionModelOptions) {
1679
+ const value = transcriptionModelOptions[key];
1680
+ if (value !== void 0) {
1681
+ formData.append(key, value);
1682
+ }
1683
+ }
1684
+ }
1685
+ return {
1686
+ formData,
1687
+ warnings
1688
+ };
1689
+ }
1690
+ async doGenerate(options) {
1691
+ var _a, _b, _c, _d, _e, _f;
1692
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1693
+ const { formData, warnings } = this.getArgs(options);
1694
+ const {
1695
+ value: response,
1696
+ responseHeaders,
1697
+ rawValue: rawResponse
1698
+ } = await postFormDataToApi({
1699
+ url: this.config.url({
1700
+ path: "/audio/transcriptions",
1701
+ modelId: this.modelId
1702
+ }),
1703
+ headers: combineHeaders5(this.config.headers(), options.headers),
1704
+ formData,
1705
+ failedResponseHandler: openaiFailedResponseHandler,
1706
+ successfulResponseHandler: createJsonResponseHandler5(
1707
+ openaiTranscriptionResponseSchema
1708
+ ),
1709
+ abortSignal: options.abortSignal,
1710
+ fetch: this.config.fetch
1711
+ });
1712
+ const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1713
+ return {
1714
+ text: response.text,
1715
+ segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1716
+ text: word.word,
1717
+ startSecond: word.start,
1718
+ endSecond: word.end
1719
+ }))) != null ? _e : [],
1720
+ language,
1721
+ durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1722
+ warnings,
1723
+ response: {
1724
+ timestamp: currentDate,
1725
+ modelId: this.modelId,
1726
+ headers: responseHeaders,
1727
+ body: rawResponse
1728
+ }
1729
+ };
1730
+ }
1731
+ };
1732
+ var openaiTranscriptionResponseSchema = z7.object({
1733
+ text: z7.string(),
1734
+ language: z7.string().nullish(),
1735
+ duration: z7.number().nullish(),
1736
+ words: z7.array(
1737
+ z7.object({
1738
+ word: z7.string(),
1739
+ start: z7.number(),
1740
+ end: z7.number()
1741
+ })
1742
+ ).nullish()
1743
+ });
1744
+
1745
+ // src/responses/openai-responses-language-model.ts
1746
+ import {
1747
+ combineHeaders as combineHeaders6,
1748
+ createEventSourceResponseHandler as createEventSourceResponseHandler3,
1749
+ createJsonResponseHandler as createJsonResponseHandler6,
1750
+ generateId as generateId2,
1751
+ parseProviderOptions as parseProviderOptions2,
1752
+ postJsonToApi as postJsonToApi5
1753
+ } from "@ai-sdk/provider-utils";
1754
+ import { z as z8 } from "zod";
1565
1755
 
1566
1756
  // src/responses/convert-to-openai-responses-messages.ts
1567
1757
  import {
1568
1758
  UnsupportedFunctionalityError as UnsupportedFunctionalityError5
1569
1759
  } from "@ai-sdk/provider";
1570
- import { convertUint8ArrayToBase64 as convertUint8ArrayToBase642 } from "@ai-sdk/provider-utils";
1571
1760
  function convertToOpenAIResponsesMessages({
1572
1761
  prompt,
1573
1762
  systemMessageMode
@@ -1606,38 +1795,35 @@ function convertToOpenAIResponsesMessages({
1606
1795
  messages.push({
1607
1796
  role: "user",
1608
1797
  content: content.map((part, index) => {
1609
- var _a, _b, _c, _d;
1798
+ var _a, _b, _c;
1610
1799
  switch (part.type) {
1611
1800
  case "text": {
1612
1801
  return { type: "input_text", text: part.text };
1613
1802
  }
1614
- case "image": {
1615
- return {
1616
- type: "input_image",
1617
- image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${convertUint8ArrayToBase642(part.image)}`,
1618
- // OpenAI specific extension: image detail
1619
- detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
1620
- };
1621
- }
1622
1803
  case "file": {
1623
- if (part.data instanceof URL) {
1624
- throw new UnsupportedFunctionalityError5({
1625
- functionality: "File URLs in user messages"
1626
- });
1627
- }
1628
- switch (part.mimeType) {
1629
- case "application/pdf": {
1630
- return {
1631
- type: "input_file",
1632
- filename: (_d = part.filename) != null ? _d : `part-${index}.pdf`,
1633
- file_data: `data:application/pdf;base64,${part.data}`
1634
- };
1635
- }
1636
- default: {
1804
+ if (part.mediaType.startsWith("image/")) {
1805
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
1806
+ return {
1807
+ type: "input_image",
1808
+ image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
1809
+ // OpenAI specific extension: image detail
1810
+ detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
1811
+ };
1812
+ } else if (part.mediaType === "application/pdf") {
1813
+ if (part.data instanceof URL) {
1637
1814
  throw new UnsupportedFunctionalityError5({
1638
- functionality: "Only PDF files are supported in user messages"
1815
+ functionality: "PDF file parts with URLs"
1639
1816
  });
1640
1817
  }
1818
+ return {
1819
+ type: "input_file",
1820
+ filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
1821
+ file_data: `data:application/pdf;base64,${part.data}`
1822
+ };
1823
+ } else {
1824
+ throw new UnsupportedFunctionalityError5({
1825
+ functionality: `file part media type ${part.mediaType}`
1826
+ });
1641
1827
  }
1642
1828
  }
1643
1829
  }
@@ -1768,7 +1954,7 @@ function prepareResponsesTools({
1768
1954
  default: {
1769
1955
  const _exhaustiveCheck = type;
1770
1956
  throw new UnsupportedFunctionalityError6({
1771
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
1957
+ functionality: `tool choice type: ${_exhaustiveCheck}`
1772
1958
  });
1773
1959
  }
1774
1960
  }
@@ -1829,7 +2015,7 @@ var OpenAIResponsesLanguageModel = class {
1829
2015
  systemMessageMode: modelConfig.systemMessageMode
1830
2016
  });
1831
2017
  warnings.push(...messageWarnings);
1832
- const openaiOptions = parseProviderOptions({
2018
+ const openaiOptions = parseProviderOptions2({
1833
2019
  provider: "openai",
1834
2020
  providerOptions,
1835
2021
  schema: openaiResponsesProviderOptionsSchema
@@ -1915,53 +2101,53 @@ var OpenAIResponsesLanguageModel = class {
1915
2101
  path: "/responses",
1916
2102
  modelId: this.modelId
1917
2103
  }),
1918
- headers: combineHeaders5(this.config.headers(), options.headers),
2104
+ headers: combineHeaders6(this.config.headers(), options.headers),
1919
2105
  body,
1920
2106
  failedResponseHandler: openaiFailedResponseHandler,
1921
- successfulResponseHandler: createJsonResponseHandler5(
1922
- z7.object({
1923
- id: z7.string(),
1924
- created_at: z7.number(),
1925
- model: z7.string(),
1926
- output: z7.array(
1927
- z7.discriminatedUnion("type", [
1928
- z7.object({
1929
- type: z7.literal("message"),
1930
- role: z7.literal("assistant"),
1931
- content: z7.array(
1932
- z7.object({
1933
- type: z7.literal("output_text"),
1934
- text: z7.string(),
1935
- annotations: z7.array(
1936
- z7.object({
1937
- type: z7.literal("url_citation"),
1938
- start_index: z7.number(),
1939
- end_index: z7.number(),
1940
- url: z7.string(),
1941
- title: z7.string()
2107
+ successfulResponseHandler: createJsonResponseHandler6(
2108
+ z8.object({
2109
+ id: z8.string(),
2110
+ created_at: z8.number(),
2111
+ model: z8.string(),
2112
+ output: z8.array(
2113
+ z8.discriminatedUnion("type", [
2114
+ z8.object({
2115
+ type: z8.literal("message"),
2116
+ role: z8.literal("assistant"),
2117
+ content: z8.array(
2118
+ z8.object({
2119
+ type: z8.literal("output_text"),
2120
+ text: z8.string(),
2121
+ annotations: z8.array(
2122
+ z8.object({
2123
+ type: z8.literal("url_citation"),
2124
+ start_index: z8.number(),
2125
+ end_index: z8.number(),
2126
+ url: z8.string(),
2127
+ title: z8.string()
1942
2128
  })
1943
2129
  )
1944
2130
  })
1945
2131
  )
1946
2132
  }),
1947
- z7.object({
1948
- type: z7.literal("function_call"),
1949
- call_id: z7.string(),
1950
- name: z7.string(),
1951
- arguments: z7.string()
2133
+ z8.object({
2134
+ type: z8.literal("function_call"),
2135
+ call_id: z8.string(),
2136
+ name: z8.string(),
2137
+ arguments: z8.string()
1952
2138
  }),
1953
- z7.object({
1954
- type: z7.literal("web_search_call")
2139
+ z8.object({
2140
+ type: z8.literal("web_search_call")
1955
2141
  }),
1956
- z7.object({
1957
- type: z7.literal("computer_call")
2142
+ z8.object({
2143
+ type: z8.literal("computer_call")
1958
2144
  }),
1959
- z7.object({
1960
- type: z7.literal("reasoning")
2145
+ z8.object({
2146
+ type: z8.literal("reasoning")
1961
2147
  })
1962
2148
  ])
1963
2149
  ),
1964
- incomplete_details: z7.object({ reason: z7.string() }).nullable(),
2150
+ incomplete_details: z8.object({ reason: z8.string() }).nullable(),
1965
2151
  usage: usageSchema
1966
2152
  })
1967
2153
  ),
@@ -2001,17 +2187,15 @@ var OpenAIResponsesLanguageModel = class {
2001
2187
  rawPrompt: void 0,
2002
2188
  rawSettings: {}
2003
2189
  },
2004
- rawResponse: {
2005
- headers: responseHeaders,
2006
- body: rawResponse
2007
- },
2008
2190
  request: {
2009
2191
  body: JSON.stringify(body)
2010
2192
  },
2011
2193
  response: {
2012
2194
  id: response.id,
2013
2195
  timestamp: new Date(response.created_at * 1e3),
2014
- modelId: response.model
2196
+ modelId: response.model,
2197
+ headers: responseHeaders,
2198
+ body: rawResponse
2015
2199
  },
2016
2200
  providerMetadata: {
2017
2201
  openai: {
@@ -2030,7 +2214,7 @@ var OpenAIResponsesLanguageModel = class {
2030
2214
  path: "/responses",
2031
2215
  modelId: this.modelId
2032
2216
  }),
2033
- headers: combineHeaders5(this.config.headers(), options.headers),
2217
+ headers: combineHeaders6(this.config.headers(), options.headers),
2034
2218
  body: {
2035
2219
  ...body,
2036
2220
  stream: true
@@ -2153,85 +2337,85 @@ var OpenAIResponsesLanguageModel = class {
2153
2337
  rawPrompt: void 0,
2154
2338
  rawSettings: {}
2155
2339
  },
2156
- rawResponse: { headers: responseHeaders },
2157
2340
  request: { body: JSON.stringify(body) },
2341
+ response: { headers: responseHeaders },
2158
2342
  warnings
2159
2343
  };
2160
2344
  }
2161
2345
  };
2162
- var usageSchema = z7.object({
2163
- input_tokens: z7.number(),
2164
- input_tokens_details: z7.object({ cached_tokens: z7.number().nullish() }).nullish(),
2165
- output_tokens: z7.number(),
2166
- output_tokens_details: z7.object({ reasoning_tokens: z7.number().nullish() }).nullish()
2346
+ var usageSchema = z8.object({
2347
+ input_tokens: z8.number(),
2348
+ input_tokens_details: z8.object({ cached_tokens: z8.number().nullish() }).nullish(),
2349
+ output_tokens: z8.number(),
2350
+ output_tokens_details: z8.object({ reasoning_tokens: z8.number().nullish() }).nullish()
2167
2351
  });
2168
- var textDeltaChunkSchema = z7.object({
2169
- type: z7.literal("response.output_text.delta"),
2170
- delta: z7.string()
2352
+ var textDeltaChunkSchema = z8.object({
2353
+ type: z8.literal("response.output_text.delta"),
2354
+ delta: z8.string()
2171
2355
  });
2172
- var responseFinishedChunkSchema = z7.object({
2173
- type: z7.enum(["response.completed", "response.incomplete"]),
2174
- response: z7.object({
2175
- incomplete_details: z7.object({ reason: z7.string() }).nullish(),
2356
+ var responseFinishedChunkSchema = z8.object({
2357
+ type: z8.enum(["response.completed", "response.incomplete"]),
2358
+ response: z8.object({
2359
+ incomplete_details: z8.object({ reason: z8.string() }).nullish(),
2176
2360
  usage: usageSchema
2177
2361
  })
2178
2362
  });
2179
- var responseCreatedChunkSchema = z7.object({
2180
- type: z7.literal("response.created"),
2181
- response: z7.object({
2182
- id: z7.string(),
2183
- created_at: z7.number(),
2184
- model: z7.string()
2363
+ var responseCreatedChunkSchema = z8.object({
2364
+ type: z8.literal("response.created"),
2365
+ response: z8.object({
2366
+ id: z8.string(),
2367
+ created_at: z8.number(),
2368
+ model: z8.string()
2185
2369
  })
2186
2370
  });
2187
- var responseOutputItemDoneSchema = z7.object({
2188
- type: z7.literal("response.output_item.done"),
2189
- output_index: z7.number(),
2190
- item: z7.discriminatedUnion("type", [
2191
- z7.object({
2192
- type: z7.literal("message")
2371
+ var responseOutputItemDoneSchema = z8.object({
2372
+ type: z8.literal("response.output_item.done"),
2373
+ output_index: z8.number(),
2374
+ item: z8.discriminatedUnion("type", [
2375
+ z8.object({
2376
+ type: z8.literal("message")
2193
2377
  }),
2194
- z7.object({
2195
- type: z7.literal("function_call"),
2196
- id: z7.string(),
2197
- call_id: z7.string(),
2198
- name: z7.string(),
2199
- arguments: z7.string(),
2200
- status: z7.literal("completed")
2378
+ z8.object({
2379
+ type: z8.literal("function_call"),
2380
+ id: z8.string(),
2381
+ call_id: z8.string(),
2382
+ name: z8.string(),
2383
+ arguments: z8.string(),
2384
+ status: z8.literal("completed")
2201
2385
  })
2202
2386
  ])
2203
2387
  });
2204
- var responseFunctionCallArgumentsDeltaSchema = z7.object({
2205
- type: z7.literal("response.function_call_arguments.delta"),
2206
- item_id: z7.string(),
2207
- output_index: z7.number(),
2208
- delta: z7.string()
2388
+ var responseFunctionCallArgumentsDeltaSchema = z8.object({
2389
+ type: z8.literal("response.function_call_arguments.delta"),
2390
+ item_id: z8.string(),
2391
+ output_index: z8.number(),
2392
+ delta: z8.string()
2209
2393
  });
2210
- var responseOutputItemAddedSchema = z7.object({
2211
- type: z7.literal("response.output_item.added"),
2212
- output_index: z7.number(),
2213
- item: z7.discriminatedUnion("type", [
2214
- z7.object({
2215
- type: z7.literal("message")
2394
+ var responseOutputItemAddedSchema = z8.object({
2395
+ type: z8.literal("response.output_item.added"),
2396
+ output_index: z8.number(),
2397
+ item: z8.discriminatedUnion("type", [
2398
+ z8.object({
2399
+ type: z8.literal("message")
2216
2400
  }),
2217
- z7.object({
2218
- type: z7.literal("function_call"),
2219
- id: z7.string(),
2220
- call_id: z7.string(),
2221
- name: z7.string(),
2222
- arguments: z7.string()
2401
+ z8.object({
2402
+ type: z8.literal("function_call"),
2403
+ id: z8.string(),
2404
+ call_id: z8.string(),
2405
+ name: z8.string(),
2406
+ arguments: z8.string()
2223
2407
  })
2224
2408
  ])
2225
2409
  });
2226
- var responseAnnotationAddedSchema = z7.object({
2227
- type: z7.literal("response.output_text.annotation.added"),
2228
- annotation: z7.object({
2229
- type: z7.literal("url_citation"),
2230
- url: z7.string(),
2231
- title: z7.string()
2410
+ var responseAnnotationAddedSchema = z8.object({
2411
+ type: z8.literal("response.output_text.annotation.added"),
2412
+ annotation: z8.object({
2413
+ type: z8.literal("url_citation"),
2414
+ url: z8.string(),
2415
+ title: z8.string()
2232
2416
  })
2233
2417
  });
2234
- var openaiResponsesChunkSchema = z7.union([
2418
+ var openaiResponsesChunkSchema = z8.union([
2235
2419
  textDeltaChunkSchema,
2236
2420
  responseFinishedChunkSchema,
2237
2421
  responseCreatedChunkSchema,
@@ -2239,7 +2423,7 @@ var openaiResponsesChunkSchema = z7.union([
2239
2423
  responseFunctionCallArgumentsDeltaSchema,
2240
2424
  responseOutputItemAddedSchema,
2241
2425
  responseAnnotationAddedSchema,
2242
- z7.object({ type: z7.string() }).passthrough()
2426
+ z8.object({ type: z8.string() }).passthrough()
2243
2427
  // fallback for unknown chunks
2244
2428
  ]);
2245
2429
  function isTextDeltaChunk(chunk) {
@@ -2284,15 +2468,15 @@ function getResponsesModelConfig(modelId) {
2284
2468
  requiredAutoTruncation: false
2285
2469
  };
2286
2470
  }
2287
- var openaiResponsesProviderOptionsSchema = z7.object({
2288
- metadata: z7.any().nullish(),
2289
- parallelToolCalls: z7.boolean().nullish(),
2290
- previousResponseId: z7.string().nullish(),
2291
- store: z7.boolean().nullish(),
2292
- user: z7.string().nullish(),
2293
- reasoningEffort: z7.string().nullish(),
2294
- strictSchemas: z7.boolean().nullish(),
2295
- instructions: z7.string().nullish()
2471
+ var openaiResponsesProviderOptionsSchema = z8.object({
2472
+ metadata: z8.any().nullish(),
2473
+ parallelToolCalls: z8.boolean().nullish(),
2474
+ previousResponseId: z8.string().nullish(),
2475
+ store: z8.boolean().nullish(),
2476
+ user: z8.string().nullish(),
2477
+ reasoningEffort: z8.string().nullish(),
2478
+ strictSchemas: z8.boolean().nullish(),
2479
+ instructions: z8.string().nullish()
2296
2480
  });
2297
2481
 
2298
2482
  // src/openai-provider.ts
@@ -2337,6 +2521,12 @@ function createOpenAI(options = {}) {
2337
2521
  headers: getHeaders,
2338
2522
  fetch: options.fetch
2339
2523
  });
2524
+ const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
2525
+ provider: `${providerName}.transcription`,
2526
+ url: ({ path }) => `${baseURL}${path}`,
2527
+ headers: getHeaders,
2528
+ fetch: options.fetch
2529
+ });
2340
2530
  const createLanguageModel = (modelId, settings) => {
2341
2531
  if (new.target) {
2342
2532
  throw new Error(
@@ -2371,6 +2561,8 @@ function createOpenAI(options = {}) {
2371
2561
  provider.textEmbeddingModel = createEmbeddingModel;
2372
2562
  provider.image = createImageModel;
2373
2563
  provider.imageModel = createImageModel;
2564
+ provider.transcription = createTranscriptionModel;
2565
+ provider.transcriptionModel = createTranscriptionModel;
2374
2566
  provider.tools = openaiTools;
2375
2567
  return provider;
2376
2568
  }