@ai-sdk/openai 3.0.135 → 3.0.136
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +43 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +42 -9
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +49 -10
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +34 -0
- package/package.json +3 -3
- package/src/chat/convert-to-openai-chat-messages.ts +22 -3
- package/src/responses/convert-to-openai-responses-input.ts +21 -7
- package/src/transcription/openai-transcription-model.ts +2 -0
- package/src/transcription/openai-transcription-options.ts +12 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -362,9 +362,24 @@ function convertOpenAIChatUsage(usage) {
|
|
|
362
362
|
import {
|
|
363
363
|
UnsupportedFunctionalityError
|
|
364
364
|
} from "@ai-sdk/provider";
|
|
365
|
-
import {
|
|
365
|
+
import {
|
|
366
|
+
secureJsonParse,
|
|
367
|
+
stringifyWithBigIntAndCycles,
|
|
368
|
+
convertToBase64
|
|
369
|
+
} from "@ai-sdk/provider-utils";
|
|
366
370
|
function serializeToolCallArguments(input) {
|
|
367
|
-
|
|
371
|
+
if (typeof input === "string") {
|
|
372
|
+
try {
|
|
373
|
+
const parsed = secureJsonParse(input);
|
|
374
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
375
|
+
return "{}";
|
|
376
|
+
}
|
|
377
|
+
return input;
|
|
378
|
+
} catch (e) {
|
|
379
|
+
return "{}";
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return stringifyWithBigIntAndCycles(
|
|
368
383
|
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
369
384
|
);
|
|
370
385
|
}
|
|
@@ -592,7 +607,7 @@ function convertToOpenAIChatMessages({
|
|
|
592
607
|
case "content":
|
|
593
608
|
case "json":
|
|
594
609
|
case "error-json":
|
|
595
|
-
contentValue =
|
|
610
|
+
contentValue = stringifyWithBigIntAndCycles(output.value);
|
|
596
611
|
break;
|
|
597
612
|
}
|
|
598
613
|
messages.push({
|
|
@@ -2483,6 +2498,16 @@ var openAITranscriptionModelOptions = lazySchema11(
|
|
|
2483
2498
|
* The language of the input audio in ISO-639-1 format.
|
|
2484
2499
|
*/
|
|
2485
2500
|
language: z11.string().optional(),
|
|
2501
|
+
/**
|
|
2502
|
+
* Expected languages for REST transcription, e.g. with gpt-transcribe.
|
|
2503
|
+
* Use this instead of language. The API validates model support.
|
|
2504
|
+
*/
|
|
2505
|
+
languages: z11.array(z11.string()).optional(),
|
|
2506
|
+
/**
|
|
2507
|
+
* Vocabulary hints for REST transcription, e.g. names or technical terms.
|
|
2508
|
+
* The API validates model support.
|
|
2509
|
+
*/
|
|
2510
|
+
keywords: z11.array(z11.string()).optional(),
|
|
2486
2511
|
/**
|
|
2487
2512
|
* An optional text to guide the model's style or continue a previous audio segment.
|
|
2488
2513
|
*/
|
|
@@ -2594,6 +2619,8 @@ var OpenAITranscriptionModel = class {
|
|
|
2594
2619
|
const transcriptionModelOptions = {
|
|
2595
2620
|
include: openAIOptions.include,
|
|
2596
2621
|
language: openAIOptions.language,
|
|
2622
|
+
languages: openAIOptions.languages,
|
|
2623
|
+
keywords: openAIOptions.keywords,
|
|
2597
2624
|
prompt: openAIOptions.prompt,
|
|
2598
2625
|
// https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
|
|
2599
2626
|
// prefer verbose_json to get segments for models that support it
|
|
@@ -2853,6 +2880,8 @@ import {
|
|
|
2853
2880
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
2854
2881
|
} from "@ai-sdk/provider";
|
|
2855
2882
|
import {
|
|
2883
|
+
secureJsonParse as secureJsonParse2,
|
|
2884
|
+
stringifyWithBigIntAndCycles as stringifyWithBigIntAndCycles2,
|
|
2856
2885
|
lazySchema as lazySchema19,
|
|
2857
2886
|
zodSchema as zodSchema19,
|
|
2858
2887
|
convertToBase64 as convertToBase642,
|
|
@@ -3527,7 +3556,15 @@ async function expandParallelToolCall({
|
|
|
3527
3556
|
|
|
3528
3557
|
// src/responses/convert-to-openai-responses-input.ts
|
|
3529
3558
|
function serializeToolCallArguments2(input) {
|
|
3530
|
-
|
|
3559
|
+
if (typeof input === "string") {
|
|
3560
|
+
try {
|
|
3561
|
+
secureJsonParse2(input);
|
|
3562
|
+
return input;
|
|
3563
|
+
} catch (e) {
|
|
3564
|
+
return stringifyWithBigIntAndCycles2(input);
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
return stringifyWithBigIntAndCycles2(input === void 0 ? {} : input);
|
|
3531
3568
|
}
|
|
3532
3569
|
async function convertWebSearchToolResultOutput({
|
|
3533
3570
|
output,
|
|
@@ -3605,7 +3642,7 @@ async function convertFunctionToolResultOutput({
|
|
|
3605
3642
|
}
|
|
3606
3643
|
case "json":
|
|
3607
3644
|
case "error-json":
|
|
3608
|
-
return convertScalarOutput(
|
|
3645
|
+
return convertScalarOutput(stringifyWithBigIntAndCycles2(output.value));
|
|
3609
3646
|
case "content":
|
|
3610
3647
|
return output.value.map((item) => {
|
|
3611
3648
|
var _a3, _b, _c, _d, _e, _f, _g;
|
|
@@ -4108,7 +4145,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4108
4145
|
type: "custom_tool_call",
|
|
4109
4146
|
call_id: part.toolCallId,
|
|
4110
4147
|
name: resolvedToolName,
|
|
4111
|
-
input: typeof part.input === "string" ? part.input :
|
|
4148
|
+
input: typeof part.input === "string" ? part.input : stringifyWithBigIntAndCycles2(part.input),
|
|
4112
4149
|
...isAsync != null && { async: isAsync },
|
|
4113
4150
|
id
|
|
4114
4151
|
});
|
|
@@ -4234,7 +4271,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4234
4271
|
} else if (reasoningMessage !== void 0) {
|
|
4235
4272
|
warnings.push({
|
|
4236
4273
|
type: "other",
|
|
4237
|
-
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${
|
|
4274
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
|
|
4238
4275
|
});
|
|
4239
4276
|
}
|
|
4240
4277
|
if (reasoningMessage === void 0) {
|
|
@@ -4270,7 +4307,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4270
4307
|
} else {
|
|
4271
4308
|
warnings.push({
|
|
4272
4309
|
type: "other",
|
|
4273
|
-
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${
|
|
4310
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${stringifyWithBigIntAndCycles2(part)}.`
|
|
4274
4311
|
});
|
|
4275
4312
|
}
|
|
4276
4313
|
}
|
|
@@ -4336,7 +4373,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4336
4373
|
})
|
|
4337
4374
|
);
|
|
4338
4375
|
const serializedToolOutputs = toolOutputs.map(
|
|
4339
|
-
({ output: output2 }) => typeof output2 === "string" ? output2 :
|
|
4376
|
+
({ output: output2 }) => typeof output2 === "string" ? output2 : stringifyWithBigIntAndCycles2(output2)
|
|
4340
4377
|
);
|
|
4341
4378
|
const hasPromptCacheBreakpoint = toolOutputs.some(
|
|
4342
4379
|
({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
|
|
@@ -4452,7 +4489,9 @@ ${text}`,
|
|
|
4452
4489
|
break;
|
|
4453
4490
|
case "json":
|
|
4454
4491
|
case "error-json":
|
|
4455
|
-
outputValue = convertScalarOutput(
|
|
4492
|
+
outputValue = convertScalarOutput(
|
|
4493
|
+
stringifyWithBigIntAndCycles2(output.value)
|
|
4494
|
+
);
|
|
4456
4495
|
break;
|
|
4457
4496
|
case "content":
|
|
4458
4497
|
outputValue = output.value.map((item) => {
|