@ai-sdk/openai 1.3.10 → 1.3.11
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 +9 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +112 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -2
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +34 -6
- package/internal/dist/index.d.ts +34 -6
- package/internal/dist/index.js +213 -112
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +213 -108
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1CallOptions, TranscriptionModelV1 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1CallOptions, TranscriptionModelV1, SpeechModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -270,7 +270,7 @@ type OpenAITranscriptionModelOptions = {
|
|
|
270
270
|
timestamp_granularities?: Array<'word' | 'segment'>;
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
-
declare const
|
|
273
|
+
declare const openAIProviderOptionsSchema: z.ZodObject<{
|
|
274
274
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
275
275
|
language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
276
276
|
prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -291,7 +291,7 @@ declare const OpenAIProviderOptionsSchema: z.ZodObject<{
|
|
|
291
291
|
}>;
|
|
292
292
|
type OpenAITranscriptionCallOptions = Omit<TranscriptionModelV1CallOptions, 'providerOptions'> & {
|
|
293
293
|
providerOptions?: {
|
|
294
|
-
openai?: z.infer<typeof
|
|
294
|
+
openai?: z.infer<typeof openAIProviderOptionsSchema>;
|
|
295
295
|
};
|
|
296
296
|
};
|
|
297
297
|
interface OpenAITranscriptionModelConfig extends OpenAIConfig {
|
|
@@ -309,6 +309,34 @@ declare class OpenAITranscriptionModel implements TranscriptionModelV1 {
|
|
|
309
309
|
doGenerate(options: OpenAITranscriptionCallOptions): Promise<Awaited<ReturnType<TranscriptionModelV1['doGenerate']>>>;
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
type OpenAISpeechModelId = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | (string & {});
|
|
313
|
+
|
|
314
|
+
declare const OpenAIProviderOptionsSchema: z.ZodObject<{
|
|
315
|
+
instructions: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
316
|
+
speed: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodNumber>>>;
|
|
317
|
+
}, "strip", z.ZodTypeAny, {
|
|
318
|
+
instructions?: string | null | undefined;
|
|
319
|
+
speed?: number | null | undefined;
|
|
320
|
+
}, {
|
|
321
|
+
instructions?: string | null | undefined;
|
|
322
|
+
speed?: number | null | undefined;
|
|
323
|
+
}>;
|
|
324
|
+
type OpenAISpeechCallOptions = z.infer<typeof OpenAIProviderOptionsSchema>;
|
|
325
|
+
interface OpenAISpeechModelConfig extends OpenAIConfig {
|
|
326
|
+
_internal?: {
|
|
327
|
+
currentDate?: () => Date;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
declare class OpenAISpeechModel implements SpeechModelV1 {
|
|
331
|
+
readonly modelId: OpenAISpeechModelId;
|
|
332
|
+
private readonly config;
|
|
333
|
+
readonly specificationVersion = "v1";
|
|
334
|
+
get provider(): string;
|
|
335
|
+
constructor(modelId: OpenAISpeechModelId, config: OpenAISpeechModelConfig);
|
|
336
|
+
private getArgs;
|
|
337
|
+
doGenerate(options: Parameters<SpeechModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV1['doGenerate']>>>;
|
|
338
|
+
}
|
|
339
|
+
|
|
312
340
|
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 & {});
|
|
313
341
|
|
|
314
342
|
declare class OpenAIResponsesLanguageModel implements LanguageModelV1 {
|
|
@@ -336,20 +364,20 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
|
|
|
336
364
|
store?: boolean | null | undefined;
|
|
337
365
|
metadata?: any;
|
|
338
366
|
reasoningEffort?: string | null | undefined;
|
|
367
|
+
instructions?: string | null | undefined;
|
|
339
368
|
parallelToolCalls?: boolean | null | undefined;
|
|
340
369
|
previousResponseId?: string | null | undefined;
|
|
341
370
|
strictSchemas?: boolean | null | undefined;
|
|
342
|
-
instructions?: string | null | undefined;
|
|
343
371
|
}, {
|
|
344
372
|
user?: string | null | undefined;
|
|
345
373
|
store?: boolean | null | undefined;
|
|
346
374
|
metadata?: any;
|
|
347
375
|
reasoningEffort?: string | null | undefined;
|
|
376
|
+
instructions?: string | null | undefined;
|
|
348
377
|
parallelToolCalls?: boolean | null | undefined;
|
|
349
378
|
previousResponseId?: string | null | undefined;
|
|
350
379
|
strictSchemas?: boolean | null | undefined;
|
|
351
|
-
instructions?: string | null | undefined;
|
|
352
380
|
}>;
|
|
353
381
|
type OpenAIResponsesProviderOptions = z.infer<typeof openaiResponsesProviderOptionsSchema>;
|
|
354
382
|
|
|
355
|
-
export { OpenAIChatLanguageModel, type OpenAIChatModelId, type OpenAIChatSettings, OpenAICompletionLanguageModel, type OpenAICompletionModelId, type OpenAICompletionSettings, OpenAIEmbeddingModel, type OpenAIEmbeddingModelId, type OpenAIEmbeddingSettings, OpenAIImageModel, type OpenAIImageModelId, type OpenAIImageSettings, OpenAIResponsesLanguageModel, type OpenAIResponsesProviderOptions, type OpenAITranscriptionCallOptions, OpenAITranscriptionModel, type OpenAITranscriptionModelId, type OpenAITranscriptionModelOptions, modelMaxImagesPerCall };
|
|
383
|
+
export { OpenAIChatLanguageModel, type OpenAIChatModelId, type OpenAIChatSettings, OpenAICompletionLanguageModel, type OpenAICompletionModelId, type OpenAICompletionSettings, OpenAIEmbeddingModel, type OpenAIEmbeddingModelId, type OpenAIEmbeddingSettings, OpenAIImageModel, type OpenAIImageModelId, type OpenAIImageSettings, OpenAIResponsesLanguageModel, type OpenAIResponsesProviderOptions, type OpenAISpeechCallOptions, OpenAISpeechModel, type OpenAISpeechModelId, type OpenAITranscriptionCallOptions, OpenAITranscriptionModel, type OpenAITranscriptionModelId, type OpenAITranscriptionModelOptions, modelMaxImagesPerCall };
|
package/internal/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1CallOptions, TranscriptionModelV1 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1CallOptions, TranscriptionModelV1, SpeechModelV1 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -270,7 +270,7 @@ type OpenAITranscriptionModelOptions = {
|
|
|
270
270
|
timestamp_granularities?: Array<'word' | 'segment'>;
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
-
declare const
|
|
273
|
+
declare const openAIProviderOptionsSchema: z.ZodObject<{
|
|
274
274
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
275
275
|
language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
276
276
|
prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -291,7 +291,7 @@ declare const OpenAIProviderOptionsSchema: z.ZodObject<{
|
|
|
291
291
|
}>;
|
|
292
292
|
type OpenAITranscriptionCallOptions = Omit<TranscriptionModelV1CallOptions, 'providerOptions'> & {
|
|
293
293
|
providerOptions?: {
|
|
294
|
-
openai?: z.infer<typeof
|
|
294
|
+
openai?: z.infer<typeof openAIProviderOptionsSchema>;
|
|
295
295
|
};
|
|
296
296
|
};
|
|
297
297
|
interface OpenAITranscriptionModelConfig extends OpenAIConfig {
|
|
@@ -309,6 +309,34 @@ declare class OpenAITranscriptionModel implements TranscriptionModelV1 {
|
|
|
309
309
|
doGenerate(options: OpenAITranscriptionCallOptions): Promise<Awaited<ReturnType<TranscriptionModelV1['doGenerate']>>>;
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
type OpenAISpeechModelId = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | (string & {});
|
|
313
|
+
|
|
314
|
+
declare const OpenAIProviderOptionsSchema: z.ZodObject<{
|
|
315
|
+
instructions: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
316
|
+
speed: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodNumber>>>;
|
|
317
|
+
}, "strip", z.ZodTypeAny, {
|
|
318
|
+
instructions?: string | null | undefined;
|
|
319
|
+
speed?: number | null | undefined;
|
|
320
|
+
}, {
|
|
321
|
+
instructions?: string | null | undefined;
|
|
322
|
+
speed?: number | null | undefined;
|
|
323
|
+
}>;
|
|
324
|
+
type OpenAISpeechCallOptions = z.infer<typeof OpenAIProviderOptionsSchema>;
|
|
325
|
+
interface OpenAISpeechModelConfig extends OpenAIConfig {
|
|
326
|
+
_internal?: {
|
|
327
|
+
currentDate?: () => Date;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
declare class OpenAISpeechModel implements SpeechModelV1 {
|
|
331
|
+
readonly modelId: OpenAISpeechModelId;
|
|
332
|
+
private readonly config;
|
|
333
|
+
readonly specificationVersion = "v1";
|
|
334
|
+
get provider(): string;
|
|
335
|
+
constructor(modelId: OpenAISpeechModelId, config: OpenAISpeechModelConfig);
|
|
336
|
+
private getArgs;
|
|
337
|
+
doGenerate(options: Parameters<SpeechModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV1['doGenerate']>>>;
|
|
338
|
+
}
|
|
339
|
+
|
|
312
340
|
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 & {});
|
|
313
341
|
|
|
314
342
|
declare class OpenAIResponsesLanguageModel implements LanguageModelV1 {
|
|
@@ -336,20 +364,20 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
|
|
|
336
364
|
store?: boolean | null | undefined;
|
|
337
365
|
metadata?: any;
|
|
338
366
|
reasoningEffort?: string | null | undefined;
|
|
367
|
+
instructions?: string | null | undefined;
|
|
339
368
|
parallelToolCalls?: boolean | null | undefined;
|
|
340
369
|
previousResponseId?: string | null | undefined;
|
|
341
370
|
strictSchemas?: boolean | null | undefined;
|
|
342
|
-
instructions?: string | null | undefined;
|
|
343
371
|
}, {
|
|
344
372
|
user?: string | null | undefined;
|
|
345
373
|
store?: boolean | null | undefined;
|
|
346
374
|
metadata?: any;
|
|
347
375
|
reasoningEffort?: string | null | undefined;
|
|
376
|
+
instructions?: string | null | undefined;
|
|
348
377
|
parallelToolCalls?: boolean | null | undefined;
|
|
349
378
|
previousResponseId?: string | null | undefined;
|
|
350
379
|
strictSchemas?: boolean | null | undefined;
|
|
351
|
-
instructions?: string | null | undefined;
|
|
352
380
|
}>;
|
|
353
381
|
type OpenAIResponsesProviderOptions = z.infer<typeof openaiResponsesProviderOptionsSchema>;
|
|
354
382
|
|
|
355
|
-
export { OpenAIChatLanguageModel, type OpenAIChatModelId, type OpenAIChatSettings, OpenAICompletionLanguageModel, type OpenAICompletionModelId, type OpenAICompletionSettings, OpenAIEmbeddingModel, type OpenAIEmbeddingModelId, type OpenAIEmbeddingSettings, OpenAIImageModel, type OpenAIImageModelId, type OpenAIImageSettings, OpenAIResponsesLanguageModel, type OpenAIResponsesProviderOptions, type OpenAITranscriptionCallOptions, OpenAITranscriptionModel, type OpenAITranscriptionModelId, type OpenAITranscriptionModelOptions, modelMaxImagesPerCall };
|
|
383
|
+
export { OpenAIChatLanguageModel, type OpenAIChatModelId, type OpenAIChatSettings, OpenAICompletionLanguageModel, type OpenAICompletionModelId, type OpenAICompletionSettings, OpenAIEmbeddingModel, type OpenAIEmbeddingModelId, type OpenAIEmbeddingSettings, OpenAIImageModel, type OpenAIImageModelId, type OpenAIImageSettings, OpenAIResponsesLanguageModel, type OpenAIResponsesProviderOptions, type OpenAISpeechCallOptions, OpenAISpeechModel, type OpenAISpeechModelId, type OpenAITranscriptionCallOptions, OpenAITranscriptionModel, type OpenAITranscriptionModelId, type OpenAITranscriptionModelOptions, modelMaxImagesPerCall };
|
package/internal/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(internal_exports, {
|
|
|
25
25
|
OpenAIEmbeddingModel: () => OpenAIEmbeddingModel,
|
|
26
26
|
OpenAIImageModel: () => OpenAIImageModel,
|
|
27
27
|
OpenAIResponsesLanguageModel: () => OpenAIResponsesLanguageModel,
|
|
28
|
+
OpenAISpeechModel: () => OpenAISpeechModel,
|
|
28
29
|
OpenAITranscriptionModel: () => OpenAITranscriptionModel,
|
|
29
30
|
modelMaxImagesPerCall: () => modelMaxImagesPerCall
|
|
30
31
|
});
|
|
@@ -1615,7 +1616,7 @@ var openaiImageResponseSchema = import_zod5.z.object({
|
|
|
1615
1616
|
// src/openai-transcription-model.ts
|
|
1616
1617
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1617
1618
|
var import_zod6 = require("zod");
|
|
1618
|
-
var
|
|
1619
|
+
var openAIProviderOptionsSchema = import_zod6.z.object({
|
|
1619
1620
|
include: import_zod6.z.array(import_zod6.z.string()).nullish(),
|
|
1620
1621
|
language: import_zod6.z.string().nullish(),
|
|
1621
1622
|
prompt: import_zod6.z.string().nullish(),
|
|
@@ -1700,7 +1701,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1700
1701
|
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1701
1702
|
provider: "openai",
|
|
1702
1703
|
providerOptions,
|
|
1703
|
-
schema:
|
|
1704
|
+
schema: openAIProviderOptionsSchema
|
|
1704
1705
|
});
|
|
1705
1706
|
const formData = new FormData();
|
|
1706
1707
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
|
|
@@ -1781,13 +1782,112 @@ var openaiTranscriptionResponseSchema = import_zod6.z.object({
|
|
|
1781
1782
|
).nullish()
|
|
1782
1783
|
});
|
|
1783
1784
|
|
|
1784
|
-
// src/
|
|
1785
|
-
var
|
|
1785
|
+
// src/openai-speech-model.ts
|
|
1786
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1786
1787
|
var import_zod7 = require("zod");
|
|
1788
|
+
var OpenAIProviderOptionsSchema = import_zod7.z.object({
|
|
1789
|
+
instructions: import_zod7.z.string().nullish(),
|
|
1790
|
+
speed: import_zod7.z.number().min(0.25).max(4).default(1).nullish()
|
|
1791
|
+
});
|
|
1792
|
+
var OpenAISpeechModel = class {
|
|
1793
|
+
constructor(modelId, config) {
|
|
1794
|
+
this.modelId = modelId;
|
|
1795
|
+
this.config = config;
|
|
1796
|
+
this.specificationVersion = "v1";
|
|
1797
|
+
}
|
|
1798
|
+
get provider() {
|
|
1799
|
+
return this.config.provider;
|
|
1800
|
+
}
|
|
1801
|
+
getArgs({
|
|
1802
|
+
text,
|
|
1803
|
+
voice = "alloy",
|
|
1804
|
+
outputFormat = "mp3",
|
|
1805
|
+
speed,
|
|
1806
|
+
instructions,
|
|
1807
|
+
providerOptions
|
|
1808
|
+
}) {
|
|
1809
|
+
const warnings = [];
|
|
1810
|
+
const openAIOptions = (0, import_provider_utils8.parseProviderOptions)({
|
|
1811
|
+
provider: "openai",
|
|
1812
|
+
providerOptions,
|
|
1813
|
+
schema: OpenAIProviderOptionsSchema
|
|
1814
|
+
});
|
|
1815
|
+
const requestBody = {
|
|
1816
|
+
model: this.modelId,
|
|
1817
|
+
input: text,
|
|
1818
|
+
voice,
|
|
1819
|
+
response_format: "mp3",
|
|
1820
|
+
speed,
|
|
1821
|
+
instructions
|
|
1822
|
+
};
|
|
1823
|
+
if (outputFormat) {
|
|
1824
|
+
if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
|
|
1825
|
+
requestBody.response_format = outputFormat;
|
|
1826
|
+
} else {
|
|
1827
|
+
warnings.push({
|
|
1828
|
+
type: "unsupported-setting",
|
|
1829
|
+
setting: "outputFormat",
|
|
1830
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
if (openAIOptions) {
|
|
1835
|
+
const speechModelOptions = {};
|
|
1836
|
+
for (const key in speechModelOptions) {
|
|
1837
|
+
const value = speechModelOptions[key];
|
|
1838
|
+
if (value !== void 0) {
|
|
1839
|
+
requestBody[key] = value;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
return {
|
|
1844
|
+
requestBody,
|
|
1845
|
+
warnings
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
async doGenerate(options) {
|
|
1849
|
+
var _a, _b, _c;
|
|
1850
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1851
|
+
const { requestBody, warnings } = this.getArgs(options);
|
|
1852
|
+
const {
|
|
1853
|
+
value: audio,
|
|
1854
|
+
responseHeaders,
|
|
1855
|
+
rawValue: rawResponse
|
|
1856
|
+
} = await (0, import_provider_utils8.postJsonToApi)({
|
|
1857
|
+
url: this.config.url({
|
|
1858
|
+
path: "/audio/speech",
|
|
1859
|
+
modelId: this.modelId
|
|
1860
|
+
}),
|
|
1861
|
+
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
|
|
1862
|
+
body: requestBody,
|
|
1863
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1864
|
+
successfulResponseHandler: (0, import_provider_utils8.createBinaryResponseHandler)(),
|
|
1865
|
+
abortSignal: options.abortSignal,
|
|
1866
|
+
fetch: this.config.fetch
|
|
1867
|
+
});
|
|
1868
|
+
return {
|
|
1869
|
+
audio,
|
|
1870
|
+
warnings,
|
|
1871
|
+
request: {
|
|
1872
|
+
body: JSON.stringify(requestBody)
|
|
1873
|
+
},
|
|
1874
|
+
response: {
|
|
1875
|
+
timestamp: currentDate,
|
|
1876
|
+
modelId: this.modelId,
|
|
1877
|
+
headers: responseHeaders,
|
|
1878
|
+
body: rawResponse
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1884
|
+
// src/responses/openai-responses-language-model.ts
|
|
1885
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1886
|
+
var import_zod8 = require("zod");
|
|
1787
1887
|
|
|
1788
1888
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1789
1889
|
var import_provider7 = require("@ai-sdk/provider");
|
|
1790
|
-
var
|
|
1890
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1791
1891
|
function convertToOpenAIResponsesMessages({
|
|
1792
1892
|
prompt,
|
|
1793
1893
|
systemMessageMode
|
|
@@ -1834,7 +1934,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1834
1934
|
case "image": {
|
|
1835
1935
|
return {
|
|
1836
1936
|
type: "input_image",
|
|
1837
|
-
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0,
|
|
1937
|
+
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils9.convertUint8ArrayToBase64)(part.image)}`,
|
|
1838
1938
|
// OpenAI specific extension: image detail
|
|
1839
1939
|
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1840
1940
|
};
|
|
@@ -2070,7 +2170,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2070
2170
|
systemMessageMode: modelConfig.systemMessageMode
|
|
2071
2171
|
});
|
|
2072
2172
|
warnings.push(...messageWarnings);
|
|
2073
|
-
const openaiOptions = (0,
|
|
2173
|
+
const openaiOptions = (0, import_provider_utils10.parseProviderOptions)({
|
|
2074
2174
|
provider: "openai",
|
|
2075
2175
|
providerOptions: providerMetadata,
|
|
2076
2176
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -2190,58 +2290,58 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2190
2290
|
responseHeaders,
|
|
2191
2291
|
value: response,
|
|
2192
2292
|
rawValue: rawResponse
|
|
2193
|
-
} = await (0,
|
|
2293
|
+
} = await (0, import_provider_utils10.postJsonToApi)({
|
|
2194
2294
|
url: this.config.url({
|
|
2195
2295
|
path: "/responses",
|
|
2196
2296
|
modelId: this.modelId
|
|
2197
2297
|
}),
|
|
2198
|
-
headers: (0,
|
|
2298
|
+
headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
|
|
2199
2299
|
body,
|
|
2200
2300
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2201
|
-
successfulResponseHandler: (0,
|
|
2202
|
-
|
|
2203
|
-
id:
|
|
2204
|
-
created_at:
|
|
2205
|
-
model:
|
|
2206
|
-
output:
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
type:
|
|
2210
|
-
role:
|
|
2211
|
-
content:
|
|
2212
|
-
|
|
2213
|
-
type:
|
|
2214
|
-
text:
|
|
2215
|
-
annotations:
|
|
2216
|
-
|
|
2217
|
-
type:
|
|
2218
|
-
start_index:
|
|
2219
|
-
end_index:
|
|
2220
|
-
url:
|
|
2221
|
-
title:
|
|
2301
|
+
successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
|
|
2302
|
+
import_zod8.z.object({
|
|
2303
|
+
id: import_zod8.z.string(),
|
|
2304
|
+
created_at: import_zod8.z.number(),
|
|
2305
|
+
model: import_zod8.z.string(),
|
|
2306
|
+
output: import_zod8.z.array(
|
|
2307
|
+
import_zod8.z.discriminatedUnion("type", [
|
|
2308
|
+
import_zod8.z.object({
|
|
2309
|
+
type: import_zod8.z.literal("message"),
|
|
2310
|
+
role: import_zod8.z.literal("assistant"),
|
|
2311
|
+
content: import_zod8.z.array(
|
|
2312
|
+
import_zod8.z.object({
|
|
2313
|
+
type: import_zod8.z.literal("output_text"),
|
|
2314
|
+
text: import_zod8.z.string(),
|
|
2315
|
+
annotations: import_zod8.z.array(
|
|
2316
|
+
import_zod8.z.object({
|
|
2317
|
+
type: import_zod8.z.literal("url_citation"),
|
|
2318
|
+
start_index: import_zod8.z.number(),
|
|
2319
|
+
end_index: import_zod8.z.number(),
|
|
2320
|
+
url: import_zod8.z.string(),
|
|
2321
|
+
title: import_zod8.z.string()
|
|
2222
2322
|
})
|
|
2223
2323
|
)
|
|
2224
2324
|
})
|
|
2225
2325
|
)
|
|
2226
2326
|
}),
|
|
2227
|
-
|
|
2228
|
-
type:
|
|
2229
|
-
call_id:
|
|
2230
|
-
name:
|
|
2231
|
-
arguments:
|
|
2327
|
+
import_zod8.z.object({
|
|
2328
|
+
type: import_zod8.z.literal("function_call"),
|
|
2329
|
+
call_id: import_zod8.z.string(),
|
|
2330
|
+
name: import_zod8.z.string(),
|
|
2331
|
+
arguments: import_zod8.z.string()
|
|
2232
2332
|
}),
|
|
2233
|
-
|
|
2234
|
-
type:
|
|
2333
|
+
import_zod8.z.object({
|
|
2334
|
+
type: import_zod8.z.literal("web_search_call")
|
|
2235
2335
|
}),
|
|
2236
|
-
|
|
2237
|
-
type:
|
|
2336
|
+
import_zod8.z.object({
|
|
2337
|
+
type: import_zod8.z.literal("computer_call")
|
|
2238
2338
|
}),
|
|
2239
|
-
|
|
2240
|
-
type:
|
|
2339
|
+
import_zod8.z.object({
|
|
2340
|
+
type: import_zod8.z.literal("reasoning")
|
|
2241
2341
|
})
|
|
2242
2342
|
])
|
|
2243
2343
|
),
|
|
2244
|
-
incomplete_details:
|
|
2344
|
+
incomplete_details: import_zod8.z.object({ reason: import_zod8.z.string() }).nullable(),
|
|
2245
2345
|
usage: usageSchema
|
|
2246
2346
|
})
|
|
2247
2347
|
),
|
|
@@ -2262,7 +2362,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2262
2362
|
var _a2, _b2, _c2;
|
|
2263
2363
|
return {
|
|
2264
2364
|
sourceType: "url",
|
|
2265
|
-
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0,
|
|
2365
|
+
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils10.generateId)(),
|
|
2266
2366
|
url: annotation.url,
|
|
2267
2367
|
title: annotation.title
|
|
2268
2368
|
};
|
|
@@ -2305,18 +2405,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2305
2405
|
}
|
|
2306
2406
|
async doStream(options) {
|
|
2307
2407
|
const { args: body, warnings } = this.getArgs(options);
|
|
2308
|
-
const { responseHeaders, value: response } = await (0,
|
|
2408
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
|
|
2309
2409
|
url: this.config.url({
|
|
2310
2410
|
path: "/responses",
|
|
2311
2411
|
modelId: this.modelId
|
|
2312
2412
|
}),
|
|
2313
|
-
headers: (0,
|
|
2413
|
+
headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
|
|
2314
2414
|
body: {
|
|
2315
2415
|
...body,
|
|
2316
2416
|
stream: true
|
|
2317
2417
|
},
|
|
2318
2418
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2319
|
-
successfulResponseHandler: (0,
|
|
2419
|
+
successfulResponseHandler: (0, import_provider_utils10.createEventSourceResponseHandler)(
|
|
2320
2420
|
openaiResponsesChunkSchema
|
|
2321
2421
|
),
|
|
2322
2422
|
abortSignal: options.abortSignal,
|
|
@@ -2404,7 +2504,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2404
2504
|
type: "source",
|
|
2405
2505
|
source: {
|
|
2406
2506
|
sourceType: "url",
|
|
2407
|
-
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0,
|
|
2507
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
|
|
2408
2508
|
url: value.annotation.url,
|
|
2409
2509
|
title: value.annotation.title
|
|
2410
2510
|
}
|
|
@@ -2439,79 +2539,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2439
2539
|
};
|
|
2440
2540
|
}
|
|
2441
2541
|
};
|
|
2442
|
-
var usageSchema =
|
|
2443
|
-
input_tokens:
|
|
2444
|
-
input_tokens_details:
|
|
2445
|
-
output_tokens:
|
|
2446
|
-
output_tokens_details:
|
|
2542
|
+
var usageSchema = import_zod8.z.object({
|
|
2543
|
+
input_tokens: import_zod8.z.number(),
|
|
2544
|
+
input_tokens_details: import_zod8.z.object({ cached_tokens: import_zod8.z.number().nullish() }).nullish(),
|
|
2545
|
+
output_tokens: import_zod8.z.number(),
|
|
2546
|
+
output_tokens_details: import_zod8.z.object({ reasoning_tokens: import_zod8.z.number().nullish() }).nullish()
|
|
2447
2547
|
});
|
|
2448
|
-
var textDeltaChunkSchema =
|
|
2449
|
-
type:
|
|
2450
|
-
delta:
|
|
2548
|
+
var textDeltaChunkSchema = import_zod8.z.object({
|
|
2549
|
+
type: import_zod8.z.literal("response.output_text.delta"),
|
|
2550
|
+
delta: import_zod8.z.string()
|
|
2451
2551
|
});
|
|
2452
|
-
var responseFinishedChunkSchema =
|
|
2453
|
-
type:
|
|
2454
|
-
response:
|
|
2455
|
-
incomplete_details:
|
|
2552
|
+
var responseFinishedChunkSchema = import_zod8.z.object({
|
|
2553
|
+
type: import_zod8.z.enum(["response.completed", "response.incomplete"]),
|
|
2554
|
+
response: import_zod8.z.object({
|
|
2555
|
+
incomplete_details: import_zod8.z.object({ reason: import_zod8.z.string() }).nullish(),
|
|
2456
2556
|
usage: usageSchema
|
|
2457
2557
|
})
|
|
2458
2558
|
});
|
|
2459
|
-
var responseCreatedChunkSchema =
|
|
2460
|
-
type:
|
|
2461
|
-
response:
|
|
2462
|
-
id:
|
|
2463
|
-
created_at:
|
|
2464
|
-
model:
|
|
2559
|
+
var responseCreatedChunkSchema = import_zod8.z.object({
|
|
2560
|
+
type: import_zod8.z.literal("response.created"),
|
|
2561
|
+
response: import_zod8.z.object({
|
|
2562
|
+
id: import_zod8.z.string(),
|
|
2563
|
+
created_at: import_zod8.z.number(),
|
|
2564
|
+
model: import_zod8.z.string()
|
|
2465
2565
|
})
|
|
2466
2566
|
});
|
|
2467
|
-
var responseOutputItemDoneSchema =
|
|
2468
|
-
type:
|
|
2469
|
-
output_index:
|
|
2470
|
-
item:
|
|
2471
|
-
|
|
2472
|
-
type:
|
|
2567
|
+
var responseOutputItemDoneSchema = import_zod8.z.object({
|
|
2568
|
+
type: import_zod8.z.literal("response.output_item.done"),
|
|
2569
|
+
output_index: import_zod8.z.number(),
|
|
2570
|
+
item: import_zod8.z.discriminatedUnion("type", [
|
|
2571
|
+
import_zod8.z.object({
|
|
2572
|
+
type: import_zod8.z.literal("message")
|
|
2473
2573
|
}),
|
|
2474
|
-
|
|
2475
|
-
type:
|
|
2476
|
-
id:
|
|
2477
|
-
call_id:
|
|
2478
|
-
name:
|
|
2479
|
-
arguments:
|
|
2480
|
-
status:
|
|
2574
|
+
import_zod8.z.object({
|
|
2575
|
+
type: import_zod8.z.literal("function_call"),
|
|
2576
|
+
id: import_zod8.z.string(),
|
|
2577
|
+
call_id: import_zod8.z.string(),
|
|
2578
|
+
name: import_zod8.z.string(),
|
|
2579
|
+
arguments: import_zod8.z.string(),
|
|
2580
|
+
status: import_zod8.z.literal("completed")
|
|
2481
2581
|
})
|
|
2482
2582
|
])
|
|
2483
2583
|
});
|
|
2484
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2485
|
-
type:
|
|
2486
|
-
item_id:
|
|
2487
|
-
output_index:
|
|
2488
|
-
delta:
|
|
2584
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod8.z.object({
|
|
2585
|
+
type: import_zod8.z.literal("response.function_call_arguments.delta"),
|
|
2586
|
+
item_id: import_zod8.z.string(),
|
|
2587
|
+
output_index: import_zod8.z.number(),
|
|
2588
|
+
delta: import_zod8.z.string()
|
|
2489
2589
|
});
|
|
2490
|
-
var responseOutputItemAddedSchema =
|
|
2491
|
-
type:
|
|
2492
|
-
output_index:
|
|
2493
|
-
item:
|
|
2494
|
-
|
|
2495
|
-
type:
|
|
2590
|
+
var responseOutputItemAddedSchema = import_zod8.z.object({
|
|
2591
|
+
type: import_zod8.z.literal("response.output_item.added"),
|
|
2592
|
+
output_index: import_zod8.z.number(),
|
|
2593
|
+
item: import_zod8.z.discriminatedUnion("type", [
|
|
2594
|
+
import_zod8.z.object({
|
|
2595
|
+
type: import_zod8.z.literal("message")
|
|
2496
2596
|
}),
|
|
2497
|
-
|
|
2498
|
-
type:
|
|
2499
|
-
id:
|
|
2500
|
-
call_id:
|
|
2501
|
-
name:
|
|
2502
|
-
arguments:
|
|
2597
|
+
import_zod8.z.object({
|
|
2598
|
+
type: import_zod8.z.literal("function_call"),
|
|
2599
|
+
id: import_zod8.z.string(),
|
|
2600
|
+
call_id: import_zod8.z.string(),
|
|
2601
|
+
name: import_zod8.z.string(),
|
|
2602
|
+
arguments: import_zod8.z.string()
|
|
2503
2603
|
})
|
|
2504
2604
|
])
|
|
2505
2605
|
});
|
|
2506
|
-
var responseAnnotationAddedSchema =
|
|
2507
|
-
type:
|
|
2508
|
-
annotation:
|
|
2509
|
-
type:
|
|
2510
|
-
url:
|
|
2511
|
-
title:
|
|
2606
|
+
var responseAnnotationAddedSchema = import_zod8.z.object({
|
|
2607
|
+
type: import_zod8.z.literal("response.output_text.annotation.added"),
|
|
2608
|
+
annotation: import_zod8.z.object({
|
|
2609
|
+
type: import_zod8.z.literal("url_citation"),
|
|
2610
|
+
url: import_zod8.z.string(),
|
|
2611
|
+
title: import_zod8.z.string()
|
|
2512
2612
|
})
|
|
2513
2613
|
});
|
|
2514
|
-
var openaiResponsesChunkSchema =
|
|
2614
|
+
var openaiResponsesChunkSchema = import_zod8.z.union([
|
|
2515
2615
|
textDeltaChunkSchema,
|
|
2516
2616
|
responseFinishedChunkSchema,
|
|
2517
2617
|
responseCreatedChunkSchema,
|
|
@@ -2519,7 +2619,7 @@ var openaiResponsesChunkSchema = import_zod7.z.union([
|
|
|
2519
2619
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2520
2620
|
responseOutputItemAddedSchema,
|
|
2521
2621
|
responseAnnotationAddedSchema,
|
|
2522
|
-
|
|
2622
|
+
import_zod8.z.object({ type: import_zod8.z.string() }).passthrough()
|
|
2523
2623
|
// fallback for unknown chunks
|
|
2524
2624
|
]);
|
|
2525
2625
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2564,15 +2664,15 @@ function getResponsesModelConfig(modelId) {
|
|
|
2564
2664
|
requiredAutoTruncation: false
|
|
2565
2665
|
};
|
|
2566
2666
|
}
|
|
2567
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2568
|
-
metadata:
|
|
2569
|
-
parallelToolCalls:
|
|
2570
|
-
previousResponseId:
|
|
2571
|
-
store:
|
|
2572
|
-
user:
|
|
2573
|
-
reasoningEffort:
|
|
2574
|
-
strictSchemas:
|
|
2575
|
-
instructions:
|
|
2667
|
+
var openaiResponsesProviderOptionsSchema = import_zod8.z.object({
|
|
2668
|
+
metadata: import_zod8.z.any().nullish(),
|
|
2669
|
+
parallelToolCalls: import_zod8.z.boolean().nullish(),
|
|
2670
|
+
previousResponseId: import_zod8.z.string().nullish(),
|
|
2671
|
+
store: import_zod8.z.boolean().nullish(),
|
|
2672
|
+
user: import_zod8.z.string().nullish(),
|
|
2673
|
+
reasoningEffort: import_zod8.z.string().nullish(),
|
|
2674
|
+
strictSchemas: import_zod8.z.boolean().nullish(),
|
|
2675
|
+
instructions: import_zod8.z.string().nullish()
|
|
2576
2676
|
});
|
|
2577
2677
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2578
2678
|
0 && (module.exports = {
|
|
@@ -2581,6 +2681,7 @@ var openaiResponsesProviderOptionsSchema = import_zod7.z.object({
|
|
|
2581
2681
|
OpenAIEmbeddingModel,
|
|
2582
2682
|
OpenAIImageModel,
|
|
2583
2683
|
OpenAIResponsesLanguageModel,
|
|
2684
|
+
OpenAISpeechModel,
|
|
2584
2685
|
OpenAITranscriptionModel,
|
|
2585
2686
|
modelMaxImagesPerCall
|
|
2586
2687
|
});
|