@ai-sdk/openai 1.3.7 → 1.3.9
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/CHANGELOG.md +19 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +297 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +295 -107
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +67 -2
- package/internal/dist/index.d.ts +67 -2
- package/internal/dist/index.js +286 -110
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +286 -105
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 1.3.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 013faa8: core (ai): change transcription model mimeType to mediaType
|
|
8
|
+
- 013faa8: fix (provider/openai): increase transcription model resilience
|
|
9
|
+
- Updated dependencies [013faa8]
|
|
10
|
+
- @ai-sdk/provider@1.1.2
|
|
11
|
+
- @ai-sdk/provider-utils@2.2.6
|
|
12
|
+
|
|
13
|
+
## 1.3.8
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- c21fa6d: feat: add transcription with experimental_transcribe
|
|
18
|
+
- Updated dependencies [c21fa6d]
|
|
19
|
+
- @ai-sdk/provider-utils@2.2.5
|
|
20
|
+
- @ai-sdk/provider@1.1.1
|
|
21
|
+
|
|
3
22
|
## 1.3.7
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV1, ProviderV1, EmbeddingModelV1, ImageModelV1 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV1, ProviderV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -179,6 +179,8 @@ interface OpenAIImageSettings {
|
|
|
179
179
|
maxImagesPerCall?: number;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-4o-transcribe' | (string & {});
|
|
183
|
+
|
|
182
184
|
type OpenAIResponsesModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
|
|
183
185
|
|
|
184
186
|
declare const WebSearchPreviewParameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
@@ -244,6 +246,10 @@ interface OpenAIProvider extends ProviderV1 {
|
|
|
244
246
|
*/
|
|
245
247
|
imageModel(modelId: OpenAIImageModelId, settings?: OpenAIImageSettings): ImageModelV1;
|
|
246
248
|
/**
|
|
249
|
+
Creates a model for transcription.
|
|
250
|
+
*/
|
|
251
|
+
transcription(modelId: OpenAITranscriptionModelId): TranscriptionModelV1;
|
|
252
|
+
/**
|
|
247
253
|
OpenAI-specific tools.
|
|
248
254
|
*/
|
|
249
255
|
tools: typeof openaiTools;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV1, ProviderV1, EmbeddingModelV1, ImageModelV1 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV1, ProviderV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -179,6 +179,8 @@ interface OpenAIImageSettings {
|
|
|
179
179
|
maxImagesPerCall?: number;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-4o-transcribe' | (string & {});
|
|
183
|
+
|
|
182
184
|
type OpenAIResponsesModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
|
|
183
185
|
|
|
184
186
|
declare const WebSearchPreviewParameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
@@ -244,6 +246,10 @@ interface OpenAIProvider extends ProviderV1 {
|
|
|
244
246
|
*/
|
|
245
247
|
imageModel(modelId: OpenAIImageModelId, settings?: OpenAIImageSettings): ImageModelV1;
|
|
246
248
|
/**
|
|
249
|
+
Creates a model for transcription.
|
|
250
|
+
*/
|
|
251
|
+
transcription(modelId: OpenAITranscriptionModelId): TranscriptionModelV1;
|
|
252
|
+
/**
|
|
247
253
|
OpenAI-specific tools.
|
|
248
254
|
*/
|
|
249
255
|
tools: typeof openaiTools;
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
|
28
28
|
// src/openai-provider.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/openai-chat-language-model.ts
|
|
32
32
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1601,13 +1601,187 @@ var openaiImageResponseSchema = import_zod5.z.object({
|
|
|
1601
1601
|
data: import_zod5.z.array(import_zod5.z.object({ b64_json: import_zod5.z.string() }))
|
|
1602
1602
|
});
|
|
1603
1603
|
|
|
1604
|
-
// src/
|
|
1605
|
-
var
|
|
1604
|
+
// src/openai-transcription-model.ts
|
|
1605
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1606
1606
|
var import_zod6 = require("zod");
|
|
1607
|
+
var OpenAIProviderOptionsSchema = import_zod6.z.object({
|
|
1608
|
+
include: import_zod6.z.array(import_zod6.z.string()).optional().describe(
|
|
1609
|
+
"Additional information to include in the transcription response."
|
|
1610
|
+
),
|
|
1611
|
+
language: import_zod6.z.string().optional().describe("The language of the input audio in ISO-639-1 format."),
|
|
1612
|
+
prompt: import_zod6.z.string().optional().describe(
|
|
1613
|
+
"An optional text to guide the model's style or continue a previous audio segment."
|
|
1614
|
+
),
|
|
1615
|
+
temperature: import_zod6.z.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
1616
|
+
timestampGranularities: import_zod6.z.array(import_zod6.z.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
1617
|
+
"The timestamp granularities to populate for this transcription."
|
|
1618
|
+
)
|
|
1619
|
+
});
|
|
1620
|
+
var languageMap = {
|
|
1621
|
+
afrikaans: "af",
|
|
1622
|
+
arabic: "ar",
|
|
1623
|
+
armenian: "hy",
|
|
1624
|
+
azerbaijani: "az",
|
|
1625
|
+
belarusian: "be",
|
|
1626
|
+
bosnian: "bs",
|
|
1627
|
+
bulgarian: "bg",
|
|
1628
|
+
catalan: "ca",
|
|
1629
|
+
chinese: "zh",
|
|
1630
|
+
croatian: "hr",
|
|
1631
|
+
czech: "cs",
|
|
1632
|
+
danish: "da",
|
|
1633
|
+
dutch: "nl",
|
|
1634
|
+
english: "en",
|
|
1635
|
+
estonian: "et",
|
|
1636
|
+
finnish: "fi",
|
|
1637
|
+
french: "fr",
|
|
1638
|
+
galician: "gl",
|
|
1639
|
+
german: "de",
|
|
1640
|
+
greek: "el",
|
|
1641
|
+
hebrew: "he",
|
|
1642
|
+
hindi: "hi",
|
|
1643
|
+
hungarian: "hu",
|
|
1644
|
+
icelandic: "is",
|
|
1645
|
+
indonesian: "id",
|
|
1646
|
+
italian: "it",
|
|
1647
|
+
japanese: "ja",
|
|
1648
|
+
kannada: "kn",
|
|
1649
|
+
kazakh: "kk",
|
|
1650
|
+
korean: "ko",
|
|
1651
|
+
latvian: "lv",
|
|
1652
|
+
lithuanian: "lt",
|
|
1653
|
+
macedonian: "mk",
|
|
1654
|
+
malay: "ms",
|
|
1655
|
+
marathi: "mr",
|
|
1656
|
+
maori: "mi",
|
|
1657
|
+
nepali: "ne",
|
|
1658
|
+
norwegian: "no",
|
|
1659
|
+
persian: "fa",
|
|
1660
|
+
polish: "pl",
|
|
1661
|
+
portuguese: "pt",
|
|
1662
|
+
romanian: "ro",
|
|
1663
|
+
russian: "ru",
|
|
1664
|
+
serbian: "sr",
|
|
1665
|
+
slovak: "sk",
|
|
1666
|
+
slovenian: "sl",
|
|
1667
|
+
spanish: "es",
|
|
1668
|
+
swahili: "sw",
|
|
1669
|
+
swedish: "sv",
|
|
1670
|
+
tagalog: "tl",
|
|
1671
|
+
tamil: "ta",
|
|
1672
|
+
thai: "th",
|
|
1673
|
+
turkish: "tr",
|
|
1674
|
+
ukrainian: "uk",
|
|
1675
|
+
urdu: "ur",
|
|
1676
|
+
vietnamese: "vi",
|
|
1677
|
+
welsh: "cy"
|
|
1678
|
+
};
|
|
1679
|
+
var OpenAITranscriptionModel = class {
|
|
1680
|
+
constructor(modelId, config) {
|
|
1681
|
+
this.modelId = modelId;
|
|
1682
|
+
this.config = config;
|
|
1683
|
+
this.specificationVersion = "v1";
|
|
1684
|
+
}
|
|
1685
|
+
get provider() {
|
|
1686
|
+
return this.config.provider;
|
|
1687
|
+
}
|
|
1688
|
+
getArgs({
|
|
1689
|
+
audio,
|
|
1690
|
+
mediaType,
|
|
1691
|
+
providerOptions
|
|
1692
|
+
}) {
|
|
1693
|
+
const warnings = [];
|
|
1694
|
+
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1695
|
+
provider: "openai",
|
|
1696
|
+
providerOptions,
|
|
1697
|
+
schema: OpenAIProviderOptionsSchema
|
|
1698
|
+
});
|
|
1699
|
+
const formData = new FormData();
|
|
1700
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
|
|
1701
|
+
formData.append("model", this.modelId);
|
|
1702
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1703
|
+
if (openAIOptions) {
|
|
1704
|
+
const transcriptionModelOptions = {
|
|
1705
|
+
include: openAIOptions.include,
|
|
1706
|
+
language: openAIOptions.language,
|
|
1707
|
+
prompt: openAIOptions.prompt,
|
|
1708
|
+
temperature: openAIOptions.temperature,
|
|
1709
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1710
|
+
};
|
|
1711
|
+
for (const key in transcriptionModelOptions) {
|
|
1712
|
+
const value = transcriptionModelOptions[key];
|
|
1713
|
+
if (value !== void 0) {
|
|
1714
|
+
formData.append(key, value);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
return {
|
|
1719
|
+
formData,
|
|
1720
|
+
warnings
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
async doGenerate(options) {
|
|
1724
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1725
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1726
|
+
const { formData, warnings } = this.getArgs(options);
|
|
1727
|
+
const {
|
|
1728
|
+
value: response,
|
|
1729
|
+
responseHeaders,
|
|
1730
|
+
rawValue: rawResponse
|
|
1731
|
+
} = await (0, import_provider_utils7.postFormDataToApi)({
|
|
1732
|
+
url: this.config.url({
|
|
1733
|
+
path: "/audio/transcriptions",
|
|
1734
|
+
modelId: this.modelId
|
|
1735
|
+
}),
|
|
1736
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
|
|
1737
|
+
formData,
|
|
1738
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1739
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
1740
|
+
openaiTranscriptionResponseSchema
|
|
1741
|
+
),
|
|
1742
|
+
abortSignal: options.abortSignal,
|
|
1743
|
+
fetch: this.config.fetch
|
|
1744
|
+
});
|
|
1745
|
+
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
1746
|
+
return {
|
|
1747
|
+
text: response.text,
|
|
1748
|
+
segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
|
|
1749
|
+
text: word.word,
|
|
1750
|
+
startSecond: word.start,
|
|
1751
|
+
endSecond: word.end
|
|
1752
|
+
}))) != null ? _e : [],
|
|
1753
|
+
language,
|
|
1754
|
+
durationInSeconds: (_f = response.duration) != null ? _f : void 0,
|
|
1755
|
+
warnings,
|
|
1756
|
+
response: {
|
|
1757
|
+
timestamp: currentDate,
|
|
1758
|
+
modelId: this.modelId,
|
|
1759
|
+
headers: responseHeaders,
|
|
1760
|
+
body: rawResponse
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
var openaiTranscriptionResponseSchema = import_zod6.z.object({
|
|
1766
|
+
text: import_zod6.z.string(),
|
|
1767
|
+
language: import_zod6.z.string().nullish(),
|
|
1768
|
+
duration: import_zod6.z.number().nullish(),
|
|
1769
|
+
words: import_zod6.z.array(
|
|
1770
|
+
import_zod6.z.object({
|
|
1771
|
+
word: import_zod6.z.string(),
|
|
1772
|
+
start: import_zod6.z.number(),
|
|
1773
|
+
end: import_zod6.z.number()
|
|
1774
|
+
})
|
|
1775
|
+
).nullish()
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
// src/responses/openai-responses-language-model.ts
|
|
1779
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1780
|
+
var import_zod7 = require("zod");
|
|
1607
1781
|
|
|
1608
1782
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1609
1783
|
var import_provider7 = require("@ai-sdk/provider");
|
|
1610
|
-
var
|
|
1784
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1611
1785
|
function convertToOpenAIResponsesMessages({
|
|
1612
1786
|
prompt,
|
|
1613
1787
|
systemMessageMode
|
|
@@ -1654,7 +1828,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1654
1828
|
case "image": {
|
|
1655
1829
|
return {
|
|
1656
1830
|
type: "input_image",
|
|
1657
|
-
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0,
|
|
1831
|
+
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils8.convertUint8ArrayToBase64)(part.image)}`,
|
|
1658
1832
|
// OpenAI specific extension: image detail
|
|
1659
1833
|
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1660
1834
|
};
|
|
@@ -1890,7 +2064,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1890
2064
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1891
2065
|
});
|
|
1892
2066
|
warnings.push(...messageWarnings);
|
|
1893
|
-
const openaiOptions = (0,
|
|
2067
|
+
const openaiOptions = (0, import_provider_utils9.parseProviderOptions)({
|
|
1894
2068
|
provider: "openai",
|
|
1895
2069
|
providerOptions: providerMetadata,
|
|
1896
2070
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -2010,58 +2184,58 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2010
2184
|
responseHeaders,
|
|
2011
2185
|
value: response,
|
|
2012
2186
|
rawValue: rawResponse
|
|
2013
|
-
} = await (0,
|
|
2187
|
+
} = await (0, import_provider_utils9.postJsonToApi)({
|
|
2014
2188
|
url: this.config.url({
|
|
2015
2189
|
path: "/responses",
|
|
2016
2190
|
modelId: this.modelId
|
|
2017
2191
|
}),
|
|
2018
|
-
headers: (0,
|
|
2192
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
2019
2193
|
body,
|
|
2020
2194
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2021
|
-
successfulResponseHandler: (0,
|
|
2022
|
-
|
|
2023
|
-
id:
|
|
2024
|
-
created_at:
|
|
2025
|
-
model:
|
|
2026
|
-
output:
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
type:
|
|
2030
|
-
role:
|
|
2031
|
-
content:
|
|
2032
|
-
|
|
2033
|
-
type:
|
|
2034
|
-
text:
|
|
2035
|
-
annotations:
|
|
2036
|
-
|
|
2037
|
-
type:
|
|
2038
|
-
start_index:
|
|
2039
|
-
end_index:
|
|
2040
|
-
url:
|
|
2041
|
-
title:
|
|
2195
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
|
|
2196
|
+
import_zod7.z.object({
|
|
2197
|
+
id: import_zod7.z.string(),
|
|
2198
|
+
created_at: import_zod7.z.number(),
|
|
2199
|
+
model: import_zod7.z.string(),
|
|
2200
|
+
output: import_zod7.z.array(
|
|
2201
|
+
import_zod7.z.discriminatedUnion("type", [
|
|
2202
|
+
import_zod7.z.object({
|
|
2203
|
+
type: import_zod7.z.literal("message"),
|
|
2204
|
+
role: import_zod7.z.literal("assistant"),
|
|
2205
|
+
content: import_zod7.z.array(
|
|
2206
|
+
import_zod7.z.object({
|
|
2207
|
+
type: import_zod7.z.literal("output_text"),
|
|
2208
|
+
text: import_zod7.z.string(),
|
|
2209
|
+
annotations: import_zod7.z.array(
|
|
2210
|
+
import_zod7.z.object({
|
|
2211
|
+
type: import_zod7.z.literal("url_citation"),
|
|
2212
|
+
start_index: import_zod7.z.number(),
|
|
2213
|
+
end_index: import_zod7.z.number(),
|
|
2214
|
+
url: import_zod7.z.string(),
|
|
2215
|
+
title: import_zod7.z.string()
|
|
2042
2216
|
})
|
|
2043
2217
|
)
|
|
2044
2218
|
})
|
|
2045
2219
|
)
|
|
2046
2220
|
}),
|
|
2047
|
-
|
|
2048
|
-
type:
|
|
2049
|
-
call_id:
|
|
2050
|
-
name:
|
|
2051
|
-
arguments:
|
|
2221
|
+
import_zod7.z.object({
|
|
2222
|
+
type: import_zod7.z.literal("function_call"),
|
|
2223
|
+
call_id: import_zod7.z.string(),
|
|
2224
|
+
name: import_zod7.z.string(),
|
|
2225
|
+
arguments: import_zod7.z.string()
|
|
2052
2226
|
}),
|
|
2053
|
-
|
|
2054
|
-
type:
|
|
2227
|
+
import_zod7.z.object({
|
|
2228
|
+
type: import_zod7.z.literal("web_search_call")
|
|
2055
2229
|
}),
|
|
2056
|
-
|
|
2057
|
-
type:
|
|
2230
|
+
import_zod7.z.object({
|
|
2231
|
+
type: import_zod7.z.literal("computer_call")
|
|
2058
2232
|
}),
|
|
2059
|
-
|
|
2060
|
-
type:
|
|
2233
|
+
import_zod7.z.object({
|
|
2234
|
+
type: import_zod7.z.literal("reasoning")
|
|
2061
2235
|
})
|
|
2062
2236
|
])
|
|
2063
2237
|
),
|
|
2064
|
-
incomplete_details:
|
|
2238
|
+
incomplete_details: import_zod7.z.object({ reason: import_zod7.z.string() }).nullable(),
|
|
2065
2239
|
usage: usageSchema
|
|
2066
2240
|
})
|
|
2067
2241
|
),
|
|
@@ -2082,7 +2256,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2082
2256
|
var _a2, _b2, _c2;
|
|
2083
2257
|
return {
|
|
2084
2258
|
sourceType: "url",
|
|
2085
|
-
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0,
|
|
2259
|
+
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils9.generateId)(),
|
|
2086
2260
|
url: annotation.url,
|
|
2087
2261
|
title: annotation.title
|
|
2088
2262
|
};
|
|
@@ -2125,18 +2299,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2125
2299
|
}
|
|
2126
2300
|
async doStream(options) {
|
|
2127
2301
|
const { args: body, warnings } = this.getArgs(options);
|
|
2128
|
-
const { responseHeaders, value: response } = await (0,
|
|
2302
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils9.postJsonToApi)({
|
|
2129
2303
|
url: this.config.url({
|
|
2130
2304
|
path: "/responses",
|
|
2131
2305
|
modelId: this.modelId
|
|
2132
2306
|
}),
|
|
2133
|
-
headers: (0,
|
|
2307
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
2134
2308
|
body: {
|
|
2135
2309
|
...body,
|
|
2136
2310
|
stream: true
|
|
2137
2311
|
},
|
|
2138
2312
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2139
|
-
successfulResponseHandler: (0,
|
|
2313
|
+
successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(
|
|
2140
2314
|
openaiResponsesChunkSchema
|
|
2141
2315
|
),
|
|
2142
2316
|
abortSignal: options.abortSignal,
|
|
@@ -2224,7 +2398,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2224
2398
|
type: "source",
|
|
2225
2399
|
source: {
|
|
2226
2400
|
sourceType: "url",
|
|
2227
|
-
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0,
|
|
2401
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils9.generateId)(),
|
|
2228
2402
|
url: value.annotation.url,
|
|
2229
2403
|
title: value.annotation.title
|
|
2230
2404
|
}
|
|
@@ -2259,79 +2433,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2259
2433
|
};
|
|
2260
2434
|
}
|
|
2261
2435
|
};
|
|
2262
|
-
var usageSchema =
|
|
2263
|
-
input_tokens:
|
|
2264
|
-
input_tokens_details:
|
|
2265
|
-
output_tokens:
|
|
2266
|
-
output_tokens_details:
|
|
2436
|
+
var usageSchema = import_zod7.z.object({
|
|
2437
|
+
input_tokens: import_zod7.z.number(),
|
|
2438
|
+
input_tokens_details: import_zod7.z.object({ cached_tokens: import_zod7.z.number().nullish() }).nullish(),
|
|
2439
|
+
output_tokens: import_zod7.z.number(),
|
|
2440
|
+
output_tokens_details: import_zod7.z.object({ reasoning_tokens: import_zod7.z.number().nullish() }).nullish()
|
|
2267
2441
|
});
|
|
2268
|
-
var textDeltaChunkSchema =
|
|
2269
|
-
type:
|
|
2270
|
-
delta:
|
|
2442
|
+
var textDeltaChunkSchema = import_zod7.z.object({
|
|
2443
|
+
type: import_zod7.z.literal("response.output_text.delta"),
|
|
2444
|
+
delta: import_zod7.z.string()
|
|
2271
2445
|
});
|
|
2272
|
-
var responseFinishedChunkSchema =
|
|
2273
|
-
type:
|
|
2274
|
-
response:
|
|
2275
|
-
incomplete_details:
|
|
2446
|
+
var responseFinishedChunkSchema = import_zod7.z.object({
|
|
2447
|
+
type: import_zod7.z.enum(["response.completed", "response.incomplete"]),
|
|
2448
|
+
response: import_zod7.z.object({
|
|
2449
|
+
incomplete_details: import_zod7.z.object({ reason: import_zod7.z.string() }).nullish(),
|
|
2276
2450
|
usage: usageSchema
|
|
2277
2451
|
})
|
|
2278
2452
|
});
|
|
2279
|
-
var responseCreatedChunkSchema =
|
|
2280
|
-
type:
|
|
2281
|
-
response:
|
|
2282
|
-
id:
|
|
2283
|
-
created_at:
|
|
2284
|
-
model:
|
|
2453
|
+
var responseCreatedChunkSchema = import_zod7.z.object({
|
|
2454
|
+
type: import_zod7.z.literal("response.created"),
|
|
2455
|
+
response: import_zod7.z.object({
|
|
2456
|
+
id: import_zod7.z.string(),
|
|
2457
|
+
created_at: import_zod7.z.number(),
|
|
2458
|
+
model: import_zod7.z.string()
|
|
2285
2459
|
})
|
|
2286
2460
|
});
|
|
2287
|
-
var responseOutputItemDoneSchema =
|
|
2288
|
-
type:
|
|
2289
|
-
output_index:
|
|
2290
|
-
item:
|
|
2291
|
-
|
|
2292
|
-
type:
|
|
2461
|
+
var responseOutputItemDoneSchema = import_zod7.z.object({
|
|
2462
|
+
type: import_zod7.z.literal("response.output_item.done"),
|
|
2463
|
+
output_index: import_zod7.z.number(),
|
|
2464
|
+
item: import_zod7.z.discriminatedUnion("type", [
|
|
2465
|
+
import_zod7.z.object({
|
|
2466
|
+
type: import_zod7.z.literal("message")
|
|
2293
2467
|
}),
|
|
2294
|
-
|
|
2295
|
-
type:
|
|
2296
|
-
id:
|
|
2297
|
-
call_id:
|
|
2298
|
-
name:
|
|
2299
|
-
arguments:
|
|
2300
|
-
status:
|
|
2468
|
+
import_zod7.z.object({
|
|
2469
|
+
type: import_zod7.z.literal("function_call"),
|
|
2470
|
+
id: import_zod7.z.string(),
|
|
2471
|
+
call_id: import_zod7.z.string(),
|
|
2472
|
+
name: import_zod7.z.string(),
|
|
2473
|
+
arguments: import_zod7.z.string(),
|
|
2474
|
+
status: import_zod7.z.literal("completed")
|
|
2301
2475
|
})
|
|
2302
2476
|
])
|
|
2303
2477
|
});
|
|
2304
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2305
|
-
type:
|
|
2306
|
-
item_id:
|
|
2307
|
-
output_index:
|
|
2308
|
-
delta:
|
|
2478
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod7.z.object({
|
|
2479
|
+
type: import_zod7.z.literal("response.function_call_arguments.delta"),
|
|
2480
|
+
item_id: import_zod7.z.string(),
|
|
2481
|
+
output_index: import_zod7.z.number(),
|
|
2482
|
+
delta: import_zod7.z.string()
|
|
2309
2483
|
});
|
|
2310
|
-
var responseOutputItemAddedSchema =
|
|
2311
|
-
type:
|
|
2312
|
-
output_index:
|
|
2313
|
-
item:
|
|
2314
|
-
|
|
2315
|
-
type:
|
|
2484
|
+
var responseOutputItemAddedSchema = import_zod7.z.object({
|
|
2485
|
+
type: import_zod7.z.literal("response.output_item.added"),
|
|
2486
|
+
output_index: import_zod7.z.number(),
|
|
2487
|
+
item: import_zod7.z.discriminatedUnion("type", [
|
|
2488
|
+
import_zod7.z.object({
|
|
2489
|
+
type: import_zod7.z.literal("message")
|
|
2316
2490
|
}),
|
|
2317
|
-
|
|
2318
|
-
type:
|
|
2319
|
-
id:
|
|
2320
|
-
call_id:
|
|
2321
|
-
name:
|
|
2322
|
-
arguments:
|
|
2491
|
+
import_zod7.z.object({
|
|
2492
|
+
type: import_zod7.z.literal("function_call"),
|
|
2493
|
+
id: import_zod7.z.string(),
|
|
2494
|
+
call_id: import_zod7.z.string(),
|
|
2495
|
+
name: import_zod7.z.string(),
|
|
2496
|
+
arguments: import_zod7.z.string()
|
|
2323
2497
|
})
|
|
2324
2498
|
])
|
|
2325
2499
|
});
|
|
2326
|
-
var responseAnnotationAddedSchema =
|
|
2327
|
-
type:
|
|
2328
|
-
annotation:
|
|
2329
|
-
type:
|
|
2330
|
-
url:
|
|
2331
|
-
title:
|
|
2500
|
+
var responseAnnotationAddedSchema = import_zod7.z.object({
|
|
2501
|
+
type: import_zod7.z.literal("response.output_text.annotation.added"),
|
|
2502
|
+
annotation: import_zod7.z.object({
|
|
2503
|
+
type: import_zod7.z.literal("url_citation"),
|
|
2504
|
+
url: import_zod7.z.string(),
|
|
2505
|
+
title: import_zod7.z.string()
|
|
2332
2506
|
})
|
|
2333
2507
|
});
|
|
2334
|
-
var openaiResponsesChunkSchema =
|
|
2508
|
+
var openaiResponsesChunkSchema = import_zod7.z.union([
|
|
2335
2509
|
textDeltaChunkSchema,
|
|
2336
2510
|
responseFinishedChunkSchema,
|
|
2337
2511
|
responseCreatedChunkSchema,
|
|
@@ -2339,7 +2513,7 @@ var openaiResponsesChunkSchema = import_zod6.z.union([
|
|
|
2339
2513
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2340
2514
|
responseOutputItemAddedSchema,
|
|
2341
2515
|
responseAnnotationAddedSchema,
|
|
2342
|
-
|
|
2516
|
+
import_zod7.z.object({ type: import_zod7.z.string() }).passthrough()
|
|
2343
2517
|
// fallback for unknown chunks
|
|
2344
2518
|
]);
|
|
2345
2519
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2384,20 +2558,20 @@ function getResponsesModelConfig(modelId) {
|
|
|
2384
2558
|
requiredAutoTruncation: false
|
|
2385
2559
|
};
|
|
2386
2560
|
}
|
|
2387
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2388
|
-
metadata:
|
|
2389
|
-
parallelToolCalls:
|
|
2390
|
-
previousResponseId:
|
|
2391
|
-
store:
|
|
2392
|
-
user:
|
|
2393
|
-
reasoningEffort:
|
|
2394
|
-
strictSchemas:
|
|
2395
|
-
instructions:
|
|
2561
|
+
var openaiResponsesProviderOptionsSchema = import_zod7.z.object({
|
|
2562
|
+
metadata: import_zod7.z.any().nullish(),
|
|
2563
|
+
parallelToolCalls: import_zod7.z.boolean().nullish(),
|
|
2564
|
+
previousResponseId: import_zod7.z.string().nullish(),
|
|
2565
|
+
store: import_zod7.z.boolean().nullish(),
|
|
2566
|
+
user: import_zod7.z.string().nullish(),
|
|
2567
|
+
reasoningEffort: import_zod7.z.string().nullish(),
|
|
2568
|
+
strictSchemas: import_zod7.z.boolean().nullish(),
|
|
2569
|
+
instructions: import_zod7.z.string().nullish()
|
|
2396
2570
|
});
|
|
2397
2571
|
|
|
2398
2572
|
// src/openai-tools.ts
|
|
2399
|
-
var
|
|
2400
|
-
var WebSearchPreviewParameters =
|
|
2573
|
+
var import_zod8 = require("zod");
|
|
2574
|
+
var WebSearchPreviewParameters = import_zod8.z.object({});
|
|
2401
2575
|
function webSearchPreviewTool({
|
|
2402
2576
|
searchContextSize,
|
|
2403
2577
|
userLocation
|
|
@@ -2419,11 +2593,11 @@ var openaiTools = {
|
|
|
2419
2593
|
// src/openai-provider.ts
|
|
2420
2594
|
function createOpenAI(options = {}) {
|
|
2421
2595
|
var _a, _b, _c;
|
|
2422
|
-
const baseURL = (_a = (0,
|
|
2596
|
+
const baseURL = (_a = (0, import_provider_utils10.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
2423
2597
|
const compatibility = (_b = options.compatibility) != null ? _b : "compatible";
|
|
2424
2598
|
const providerName = (_c = options.name) != null ? _c : "openai";
|
|
2425
2599
|
const getHeaders = () => ({
|
|
2426
|
-
Authorization: `Bearer ${(0,
|
|
2600
|
+
Authorization: `Bearer ${(0, import_provider_utils10.loadApiKey)({
|
|
2427
2601
|
apiKey: options.apiKey,
|
|
2428
2602
|
environmentVariableName: "OPENAI_API_KEY",
|
|
2429
2603
|
description: "OpenAI"
|
|
@@ -2458,6 +2632,12 @@ function createOpenAI(options = {}) {
|
|
|
2458
2632
|
headers: getHeaders,
|
|
2459
2633
|
fetch: options.fetch
|
|
2460
2634
|
});
|
|
2635
|
+
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
2636
|
+
provider: `${providerName}.transcription`,
|
|
2637
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
2638
|
+
headers: getHeaders,
|
|
2639
|
+
fetch: options.fetch
|
|
2640
|
+
});
|
|
2461
2641
|
const createLanguageModel = (modelId, settings) => {
|
|
2462
2642
|
if (new.target) {
|
|
2463
2643
|
throw new Error(
|
|
@@ -2492,6 +2672,8 @@ function createOpenAI(options = {}) {
|
|
|
2492
2672
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
2493
2673
|
provider.image = createImageModel;
|
|
2494
2674
|
provider.imageModel = createImageModel;
|
|
2675
|
+
provider.transcription = createTranscriptionModel;
|
|
2676
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
2495
2677
|
provider.tools = openaiTools;
|
|
2496
2678
|
return provider;
|
|
2497
2679
|
}
|