@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
package/internal/dist/index.mjs
CHANGED
|
@@ -1623,7 +1623,7 @@ import {
|
|
|
1623
1623
|
postFormDataToApi
|
|
1624
1624
|
} from "@ai-sdk/provider-utils";
|
|
1625
1625
|
import { z as z6 } from "zod";
|
|
1626
|
-
var
|
|
1626
|
+
var openAIProviderOptionsSchema = z6.object({
|
|
1627
1627
|
include: z6.array(z6.string()).nullish(),
|
|
1628
1628
|
language: z6.string().nullish(),
|
|
1629
1629
|
prompt: z6.string().nullish(),
|
|
@@ -1708,7 +1708,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1708
1708
|
const openAIOptions = parseProviderOptions({
|
|
1709
1709
|
provider: "openai",
|
|
1710
1710
|
providerOptions,
|
|
1711
|
-
schema:
|
|
1711
|
+
schema: openAIProviderOptionsSchema
|
|
1712
1712
|
});
|
|
1713
1713
|
const formData = new FormData();
|
|
1714
1714
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -1789,16 +1789,120 @@ var openaiTranscriptionResponseSchema = z6.object({
|
|
|
1789
1789
|
).nullish()
|
|
1790
1790
|
});
|
|
1791
1791
|
|
|
1792
|
-
// src/
|
|
1792
|
+
// src/openai-speech-model.ts
|
|
1793
1793
|
import {
|
|
1794
1794
|
combineHeaders as combineHeaders6,
|
|
1795
|
-
|
|
1796
|
-
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1797
|
-
generateId as generateId2,
|
|
1795
|
+
createBinaryResponseHandler,
|
|
1798
1796
|
parseProviderOptions as parseProviderOptions2,
|
|
1799
1797
|
postJsonToApi as postJsonToApi5
|
|
1800
1798
|
} from "@ai-sdk/provider-utils";
|
|
1801
1799
|
import { z as z7 } from "zod";
|
|
1800
|
+
var OpenAIProviderOptionsSchema = z7.object({
|
|
1801
|
+
instructions: z7.string().nullish(),
|
|
1802
|
+
speed: z7.number().min(0.25).max(4).default(1).nullish()
|
|
1803
|
+
});
|
|
1804
|
+
var OpenAISpeechModel = class {
|
|
1805
|
+
constructor(modelId, config) {
|
|
1806
|
+
this.modelId = modelId;
|
|
1807
|
+
this.config = config;
|
|
1808
|
+
this.specificationVersion = "v1";
|
|
1809
|
+
}
|
|
1810
|
+
get provider() {
|
|
1811
|
+
return this.config.provider;
|
|
1812
|
+
}
|
|
1813
|
+
getArgs({
|
|
1814
|
+
text,
|
|
1815
|
+
voice = "alloy",
|
|
1816
|
+
outputFormat = "mp3",
|
|
1817
|
+
speed,
|
|
1818
|
+
instructions,
|
|
1819
|
+
providerOptions
|
|
1820
|
+
}) {
|
|
1821
|
+
const warnings = [];
|
|
1822
|
+
const openAIOptions = parseProviderOptions2({
|
|
1823
|
+
provider: "openai",
|
|
1824
|
+
providerOptions,
|
|
1825
|
+
schema: OpenAIProviderOptionsSchema
|
|
1826
|
+
});
|
|
1827
|
+
const requestBody = {
|
|
1828
|
+
model: this.modelId,
|
|
1829
|
+
input: text,
|
|
1830
|
+
voice,
|
|
1831
|
+
response_format: "mp3",
|
|
1832
|
+
speed,
|
|
1833
|
+
instructions
|
|
1834
|
+
};
|
|
1835
|
+
if (outputFormat) {
|
|
1836
|
+
if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
|
|
1837
|
+
requestBody.response_format = outputFormat;
|
|
1838
|
+
} else {
|
|
1839
|
+
warnings.push({
|
|
1840
|
+
type: "unsupported-setting",
|
|
1841
|
+
setting: "outputFormat",
|
|
1842
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
if (openAIOptions) {
|
|
1847
|
+
const speechModelOptions = {};
|
|
1848
|
+
for (const key in speechModelOptions) {
|
|
1849
|
+
const value = speechModelOptions[key];
|
|
1850
|
+
if (value !== void 0) {
|
|
1851
|
+
requestBody[key] = value;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return {
|
|
1856
|
+
requestBody,
|
|
1857
|
+
warnings
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
async doGenerate(options) {
|
|
1861
|
+
var _a, _b, _c;
|
|
1862
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1863
|
+
const { requestBody, warnings } = this.getArgs(options);
|
|
1864
|
+
const {
|
|
1865
|
+
value: audio,
|
|
1866
|
+
responseHeaders,
|
|
1867
|
+
rawValue: rawResponse
|
|
1868
|
+
} = await postJsonToApi5({
|
|
1869
|
+
url: this.config.url({
|
|
1870
|
+
path: "/audio/speech",
|
|
1871
|
+
modelId: this.modelId
|
|
1872
|
+
}),
|
|
1873
|
+
headers: combineHeaders6(this.config.headers(), options.headers),
|
|
1874
|
+
body: requestBody,
|
|
1875
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1876
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
1877
|
+
abortSignal: options.abortSignal,
|
|
1878
|
+
fetch: this.config.fetch
|
|
1879
|
+
});
|
|
1880
|
+
return {
|
|
1881
|
+
audio,
|
|
1882
|
+
warnings,
|
|
1883
|
+
request: {
|
|
1884
|
+
body: JSON.stringify(requestBody)
|
|
1885
|
+
},
|
|
1886
|
+
response: {
|
|
1887
|
+
timestamp: currentDate,
|
|
1888
|
+
modelId: this.modelId,
|
|
1889
|
+
headers: responseHeaders,
|
|
1890
|
+
body: rawResponse
|
|
1891
|
+
}
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
|
|
1896
|
+
// src/responses/openai-responses-language-model.ts
|
|
1897
|
+
import {
|
|
1898
|
+
combineHeaders as combineHeaders7,
|
|
1899
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
1900
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1901
|
+
generateId as generateId2,
|
|
1902
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1903
|
+
postJsonToApi as postJsonToApi6
|
|
1904
|
+
} from "@ai-sdk/provider-utils";
|
|
1905
|
+
import { z as z8 } from "zod";
|
|
1802
1906
|
|
|
1803
1907
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1804
1908
|
import {
|
|
@@ -2089,7 +2193,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2089
2193
|
systemMessageMode: modelConfig.systemMessageMode
|
|
2090
2194
|
});
|
|
2091
2195
|
warnings.push(...messageWarnings);
|
|
2092
|
-
const openaiOptions =
|
|
2196
|
+
const openaiOptions = parseProviderOptions3({
|
|
2093
2197
|
provider: "openai",
|
|
2094
2198
|
providerOptions: providerMetadata,
|
|
2095
2199
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -2209,58 +2313,58 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2209
2313
|
responseHeaders,
|
|
2210
2314
|
value: response,
|
|
2211
2315
|
rawValue: rawResponse
|
|
2212
|
-
} = await
|
|
2316
|
+
} = await postJsonToApi6({
|
|
2213
2317
|
url: this.config.url({
|
|
2214
2318
|
path: "/responses",
|
|
2215
2319
|
modelId: this.modelId
|
|
2216
2320
|
}),
|
|
2217
|
-
headers:
|
|
2321
|
+
headers: combineHeaders7(this.config.headers(), options.headers),
|
|
2218
2322
|
body,
|
|
2219
2323
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2220
2324
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
2221
|
-
|
|
2222
|
-
id:
|
|
2223
|
-
created_at:
|
|
2224
|
-
model:
|
|
2225
|
-
output:
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
type:
|
|
2229
|
-
role:
|
|
2230
|
-
content:
|
|
2231
|
-
|
|
2232
|
-
type:
|
|
2233
|
-
text:
|
|
2234
|
-
annotations:
|
|
2235
|
-
|
|
2236
|
-
type:
|
|
2237
|
-
start_index:
|
|
2238
|
-
end_index:
|
|
2239
|
-
url:
|
|
2240
|
-
title:
|
|
2325
|
+
z8.object({
|
|
2326
|
+
id: z8.string(),
|
|
2327
|
+
created_at: z8.number(),
|
|
2328
|
+
model: z8.string(),
|
|
2329
|
+
output: z8.array(
|
|
2330
|
+
z8.discriminatedUnion("type", [
|
|
2331
|
+
z8.object({
|
|
2332
|
+
type: z8.literal("message"),
|
|
2333
|
+
role: z8.literal("assistant"),
|
|
2334
|
+
content: z8.array(
|
|
2335
|
+
z8.object({
|
|
2336
|
+
type: z8.literal("output_text"),
|
|
2337
|
+
text: z8.string(),
|
|
2338
|
+
annotations: z8.array(
|
|
2339
|
+
z8.object({
|
|
2340
|
+
type: z8.literal("url_citation"),
|
|
2341
|
+
start_index: z8.number(),
|
|
2342
|
+
end_index: z8.number(),
|
|
2343
|
+
url: z8.string(),
|
|
2344
|
+
title: z8.string()
|
|
2241
2345
|
})
|
|
2242
2346
|
)
|
|
2243
2347
|
})
|
|
2244
2348
|
)
|
|
2245
2349
|
}),
|
|
2246
|
-
|
|
2247
|
-
type:
|
|
2248
|
-
call_id:
|
|
2249
|
-
name:
|
|
2250
|
-
arguments:
|
|
2350
|
+
z8.object({
|
|
2351
|
+
type: z8.literal("function_call"),
|
|
2352
|
+
call_id: z8.string(),
|
|
2353
|
+
name: z8.string(),
|
|
2354
|
+
arguments: z8.string()
|
|
2251
2355
|
}),
|
|
2252
|
-
|
|
2253
|
-
type:
|
|
2356
|
+
z8.object({
|
|
2357
|
+
type: z8.literal("web_search_call")
|
|
2254
2358
|
}),
|
|
2255
|
-
|
|
2256
|
-
type:
|
|
2359
|
+
z8.object({
|
|
2360
|
+
type: z8.literal("computer_call")
|
|
2257
2361
|
}),
|
|
2258
|
-
|
|
2259
|
-
type:
|
|
2362
|
+
z8.object({
|
|
2363
|
+
type: z8.literal("reasoning")
|
|
2260
2364
|
})
|
|
2261
2365
|
])
|
|
2262
2366
|
),
|
|
2263
|
-
incomplete_details:
|
|
2367
|
+
incomplete_details: z8.object({ reason: z8.string() }).nullable(),
|
|
2264
2368
|
usage: usageSchema
|
|
2265
2369
|
})
|
|
2266
2370
|
),
|
|
@@ -2324,12 +2428,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2324
2428
|
}
|
|
2325
2429
|
async doStream(options) {
|
|
2326
2430
|
const { args: body, warnings } = this.getArgs(options);
|
|
2327
|
-
const { responseHeaders, value: response } = await
|
|
2431
|
+
const { responseHeaders, value: response } = await postJsonToApi6({
|
|
2328
2432
|
url: this.config.url({
|
|
2329
2433
|
path: "/responses",
|
|
2330
2434
|
modelId: this.modelId
|
|
2331
2435
|
}),
|
|
2332
|
-
headers:
|
|
2436
|
+
headers: combineHeaders7(this.config.headers(), options.headers),
|
|
2333
2437
|
body: {
|
|
2334
2438
|
...body,
|
|
2335
2439
|
stream: true
|
|
@@ -2458,79 +2562,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2458
2562
|
};
|
|
2459
2563
|
}
|
|
2460
2564
|
};
|
|
2461
|
-
var usageSchema =
|
|
2462
|
-
input_tokens:
|
|
2463
|
-
input_tokens_details:
|
|
2464
|
-
output_tokens:
|
|
2465
|
-
output_tokens_details:
|
|
2565
|
+
var usageSchema = z8.object({
|
|
2566
|
+
input_tokens: z8.number(),
|
|
2567
|
+
input_tokens_details: z8.object({ cached_tokens: z8.number().nullish() }).nullish(),
|
|
2568
|
+
output_tokens: z8.number(),
|
|
2569
|
+
output_tokens_details: z8.object({ reasoning_tokens: z8.number().nullish() }).nullish()
|
|
2466
2570
|
});
|
|
2467
|
-
var textDeltaChunkSchema =
|
|
2468
|
-
type:
|
|
2469
|
-
delta:
|
|
2571
|
+
var textDeltaChunkSchema = z8.object({
|
|
2572
|
+
type: z8.literal("response.output_text.delta"),
|
|
2573
|
+
delta: z8.string()
|
|
2470
2574
|
});
|
|
2471
|
-
var responseFinishedChunkSchema =
|
|
2472
|
-
type:
|
|
2473
|
-
response:
|
|
2474
|
-
incomplete_details:
|
|
2575
|
+
var responseFinishedChunkSchema = z8.object({
|
|
2576
|
+
type: z8.enum(["response.completed", "response.incomplete"]),
|
|
2577
|
+
response: z8.object({
|
|
2578
|
+
incomplete_details: z8.object({ reason: z8.string() }).nullish(),
|
|
2475
2579
|
usage: usageSchema
|
|
2476
2580
|
})
|
|
2477
2581
|
});
|
|
2478
|
-
var responseCreatedChunkSchema =
|
|
2479
|
-
type:
|
|
2480
|
-
response:
|
|
2481
|
-
id:
|
|
2482
|
-
created_at:
|
|
2483
|
-
model:
|
|
2582
|
+
var responseCreatedChunkSchema = z8.object({
|
|
2583
|
+
type: z8.literal("response.created"),
|
|
2584
|
+
response: z8.object({
|
|
2585
|
+
id: z8.string(),
|
|
2586
|
+
created_at: z8.number(),
|
|
2587
|
+
model: z8.string()
|
|
2484
2588
|
})
|
|
2485
2589
|
});
|
|
2486
|
-
var responseOutputItemDoneSchema =
|
|
2487
|
-
type:
|
|
2488
|
-
output_index:
|
|
2489
|
-
item:
|
|
2490
|
-
|
|
2491
|
-
type:
|
|
2590
|
+
var responseOutputItemDoneSchema = z8.object({
|
|
2591
|
+
type: z8.literal("response.output_item.done"),
|
|
2592
|
+
output_index: z8.number(),
|
|
2593
|
+
item: z8.discriminatedUnion("type", [
|
|
2594
|
+
z8.object({
|
|
2595
|
+
type: z8.literal("message")
|
|
2492
2596
|
}),
|
|
2493
|
-
|
|
2494
|
-
type:
|
|
2495
|
-
id:
|
|
2496
|
-
call_id:
|
|
2497
|
-
name:
|
|
2498
|
-
arguments:
|
|
2499
|
-
status:
|
|
2597
|
+
z8.object({
|
|
2598
|
+
type: z8.literal("function_call"),
|
|
2599
|
+
id: z8.string(),
|
|
2600
|
+
call_id: z8.string(),
|
|
2601
|
+
name: z8.string(),
|
|
2602
|
+
arguments: z8.string(),
|
|
2603
|
+
status: z8.literal("completed")
|
|
2500
2604
|
})
|
|
2501
2605
|
])
|
|
2502
2606
|
});
|
|
2503
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2504
|
-
type:
|
|
2505
|
-
item_id:
|
|
2506
|
-
output_index:
|
|
2507
|
-
delta:
|
|
2607
|
+
var responseFunctionCallArgumentsDeltaSchema = z8.object({
|
|
2608
|
+
type: z8.literal("response.function_call_arguments.delta"),
|
|
2609
|
+
item_id: z8.string(),
|
|
2610
|
+
output_index: z8.number(),
|
|
2611
|
+
delta: z8.string()
|
|
2508
2612
|
});
|
|
2509
|
-
var responseOutputItemAddedSchema =
|
|
2510
|
-
type:
|
|
2511
|
-
output_index:
|
|
2512
|
-
item:
|
|
2513
|
-
|
|
2514
|
-
type:
|
|
2613
|
+
var responseOutputItemAddedSchema = z8.object({
|
|
2614
|
+
type: z8.literal("response.output_item.added"),
|
|
2615
|
+
output_index: z8.number(),
|
|
2616
|
+
item: z8.discriminatedUnion("type", [
|
|
2617
|
+
z8.object({
|
|
2618
|
+
type: z8.literal("message")
|
|
2515
2619
|
}),
|
|
2516
|
-
|
|
2517
|
-
type:
|
|
2518
|
-
id:
|
|
2519
|
-
call_id:
|
|
2520
|
-
name:
|
|
2521
|
-
arguments:
|
|
2620
|
+
z8.object({
|
|
2621
|
+
type: z8.literal("function_call"),
|
|
2622
|
+
id: z8.string(),
|
|
2623
|
+
call_id: z8.string(),
|
|
2624
|
+
name: z8.string(),
|
|
2625
|
+
arguments: z8.string()
|
|
2522
2626
|
})
|
|
2523
2627
|
])
|
|
2524
2628
|
});
|
|
2525
|
-
var responseAnnotationAddedSchema =
|
|
2526
|
-
type:
|
|
2527
|
-
annotation:
|
|
2528
|
-
type:
|
|
2529
|
-
url:
|
|
2530
|
-
title:
|
|
2629
|
+
var responseAnnotationAddedSchema = z8.object({
|
|
2630
|
+
type: z8.literal("response.output_text.annotation.added"),
|
|
2631
|
+
annotation: z8.object({
|
|
2632
|
+
type: z8.literal("url_citation"),
|
|
2633
|
+
url: z8.string(),
|
|
2634
|
+
title: z8.string()
|
|
2531
2635
|
})
|
|
2532
2636
|
});
|
|
2533
|
-
var openaiResponsesChunkSchema =
|
|
2637
|
+
var openaiResponsesChunkSchema = z8.union([
|
|
2534
2638
|
textDeltaChunkSchema,
|
|
2535
2639
|
responseFinishedChunkSchema,
|
|
2536
2640
|
responseCreatedChunkSchema,
|
|
@@ -2538,7 +2642,7 @@ var openaiResponsesChunkSchema = z7.union([
|
|
|
2538
2642
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2539
2643
|
responseOutputItemAddedSchema,
|
|
2540
2644
|
responseAnnotationAddedSchema,
|
|
2541
|
-
|
|
2645
|
+
z8.object({ type: z8.string() }).passthrough()
|
|
2542
2646
|
// fallback for unknown chunks
|
|
2543
2647
|
]);
|
|
2544
2648
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2583,15 +2687,15 @@ function getResponsesModelConfig(modelId) {
|
|
|
2583
2687
|
requiredAutoTruncation: false
|
|
2584
2688
|
};
|
|
2585
2689
|
}
|
|
2586
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2587
|
-
metadata:
|
|
2588
|
-
parallelToolCalls:
|
|
2589
|
-
previousResponseId:
|
|
2590
|
-
store:
|
|
2591
|
-
user:
|
|
2592
|
-
reasoningEffort:
|
|
2593
|
-
strictSchemas:
|
|
2594
|
-
instructions:
|
|
2690
|
+
var openaiResponsesProviderOptionsSchema = z8.object({
|
|
2691
|
+
metadata: z8.any().nullish(),
|
|
2692
|
+
parallelToolCalls: z8.boolean().nullish(),
|
|
2693
|
+
previousResponseId: z8.string().nullish(),
|
|
2694
|
+
store: z8.boolean().nullish(),
|
|
2695
|
+
user: z8.string().nullish(),
|
|
2696
|
+
reasoningEffort: z8.string().nullish(),
|
|
2697
|
+
strictSchemas: z8.boolean().nullish(),
|
|
2698
|
+
instructions: z8.string().nullish()
|
|
2595
2699
|
});
|
|
2596
2700
|
export {
|
|
2597
2701
|
OpenAIChatLanguageModel,
|
|
@@ -2599,6 +2703,7 @@ export {
|
|
|
2599
2703
|
OpenAIEmbeddingModel,
|
|
2600
2704
|
OpenAIImageModel,
|
|
2601
2705
|
OpenAIResponsesLanguageModel,
|
|
2706
|
+
OpenAISpeechModel,
|
|
2602
2707
|
OpenAITranscriptionModel,
|
|
2603
2708
|
modelMaxImagesPerCall
|
|
2604
2709
|
};
|