@ai-sdk/openai 4.0.70 → 4.0.72
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 +17 -0
- package/dist/index.js +65 -14
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +64 -13
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/image/openai-image-model.ts +4 -3
- package/src/normalize-openai-json-schema.ts +79 -10
- package/src/speech/openai-speech-model-options.ts +1 -1
- package/src/speech/openai-speech-model.ts +4 -1
package/dist/internal/index.js
CHANGED
|
@@ -919,16 +919,26 @@ import {
|
|
|
919
919
|
} from "@ai-sdk/provider";
|
|
920
920
|
function normalizeOpenAIJsonSchema(schema) {
|
|
921
921
|
let removedPropertyNames = false;
|
|
922
|
+
let removedLookaroundPattern = false;
|
|
922
923
|
const normalizedSchema = normalizeSchema(schema);
|
|
924
|
+
const warnings = [];
|
|
925
|
+
if (removedPropertyNames) {
|
|
926
|
+
warnings.push({
|
|
927
|
+
type: "compatibility",
|
|
928
|
+
feature: "JSON Schema propertyNames",
|
|
929
|
+
details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
if (removedLookaroundPattern) {
|
|
933
|
+
warnings.push({
|
|
934
|
+
type: "compatibility",
|
|
935
|
+
feature: "JSON Schema pattern with regex lookaround",
|
|
936
|
+
details: "OpenAI does not support regex lookaround in JSON Schema patterns. The pattern was removed before sending the schema, so OpenAI will not enforce that constraint."
|
|
937
|
+
});
|
|
938
|
+
}
|
|
923
939
|
return {
|
|
924
940
|
schema: normalizedSchema,
|
|
925
|
-
warnings
|
|
926
|
-
{
|
|
927
|
-
type: "compatibility",
|
|
928
|
-
feature: "JSON Schema propertyNames",
|
|
929
|
-
details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
|
|
930
|
-
}
|
|
931
|
-
] : []
|
|
941
|
+
warnings
|
|
932
942
|
};
|
|
933
943
|
function normalizeSchema(schema2) {
|
|
934
944
|
const propertyNames = schema2.propertyNames;
|
|
@@ -942,6 +952,10 @@ function normalizeOpenAIJsonSchema(schema) {
|
|
|
942
952
|
}
|
|
943
953
|
const normalizedSchema2 = { ...schema2 };
|
|
944
954
|
delete normalizedSchema2.propertyNames;
|
|
955
|
+
if (normalizedSchema2.pattern != null && containsRegexLookaround(normalizedSchema2.pattern)) {
|
|
956
|
+
delete normalizedSchema2.pattern;
|
|
957
|
+
removedLookaroundPattern = true;
|
|
958
|
+
}
|
|
945
959
|
if (normalizedSchema2.properties != null) {
|
|
946
960
|
normalizedSchema2.properties = normalizeSchemaRecord(
|
|
947
961
|
normalizedSchema2.properties
|
|
@@ -1020,6 +1034,39 @@ function normalizeOpenAIJsonSchema(schema) {
|
|
|
1020
1034
|
return typeof definition === "boolean" ? definition : normalizeSchema(definition);
|
|
1021
1035
|
}
|
|
1022
1036
|
}
|
|
1037
|
+
function containsRegexLookaround(pattern) {
|
|
1038
|
+
let escaped = false;
|
|
1039
|
+
let inCharacterClass = false;
|
|
1040
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1041
|
+
const character = pattern[index];
|
|
1042
|
+
if (escaped) {
|
|
1043
|
+
escaped = false;
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
if (character === "\\") {
|
|
1047
|
+
escaped = true;
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
if (character === "[") {
|
|
1051
|
+
inCharacterClass = true;
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (character === "]") {
|
|
1055
|
+
inCharacterClass = false;
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
if (!inCharacterClass && character === "(" && pattern[index + 1] === "?") {
|
|
1059
|
+
const lookaroundPrefix = pattern[index + 2];
|
|
1060
|
+
if (lookaroundPrefix === "=" || lookaroundPrefix === "!") {
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
if (lookaroundPrefix === "<" && (pattern[index + 3] === "=" || pattern[index + 3] === "!")) {
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1023
1070
|
|
|
1024
1071
|
// src/chat/openai-chat-prepare-tools.ts
|
|
1025
1072
|
function prepareChatTools({
|
|
@@ -2392,10 +2439,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2392
2439
|
})
|
|
2393
2440
|
],
|
|
2394
2441
|
{ type: file.mediaType }
|
|
2395
|
-
) : downloadBlob(file.url)
|
|
2442
|
+
) : downloadBlob(file.url, { abortSignal })
|
|
2396
2443
|
)
|
|
2397
2444
|
),
|
|
2398
|
-
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
2445
|
+
mask: mask != null ? await fileToBlob(mask, abortSignal) : void 0,
|
|
2399
2446
|
n,
|
|
2400
2447
|
size,
|
|
2401
2448
|
quality: openaiOptions2.quality,
|
|
@@ -2532,10 +2579,10 @@ function distributeTokenDetails(details, index, total) {
|
|
|
2532
2579
|
}
|
|
2533
2580
|
return result;
|
|
2534
2581
|
}
|
|
2535
|
-
async function fileToBlob(file) {
|
|
2582
|
+
async function fileToBlob(file, abortSignal) {
|
|
2536
2583
|
if (!file) return void 0;
|
|
2537
2584
|
if (file.type === "url") {
|
|
2538
|
-
return downloadBlob(file.url);
|
|
2585
|
+
return downloadBlob(file.url, { abortSignal });
|
|
2539
2586
|
}
|
|
2540
2587
|
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
|
|
2541
2588
|
return new Blob([data], { type: file.mediaType });
|
|
@@ -3160,7 +3207,7 @@ var openaiSpeechModelOptionsSchema = lazySchema11(
|
|
|
3160
3207
|
() => zodSchema11(
|
|
3161
3208
|
z12.object({
|
|
3162
3209
|
instructions: z12.string().nullish(),
|
|
3163
|
-
speed: z12.number().min(0.25).max(4).
|
|
3210
|
+
speed: z12.number().min(0.25).max(4).nullish()
|
|
3164
3211
|
})
|
|
3165
3212
|
)
|
|
3166
3213
|
);
|
|
@@ -3193,6 +3240,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
3193
3240
|
language,
|
|
3194
3241
|
providerOptions
|
|
3195
3242
|
}) {
|
|
3243
|
+
var _a2, _b;
|
|
3196
3244
|
const warnings = [];
|
|
3197
3245
|
const openAIOptions = await parseProviderOptions6({
|
|
3198
3246
|
provider: "openai",
|
|
@@ -3219,7 +3267,10 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
3219
3267
|
}
|
|
3220
3268
|
}
|
|
3221
3269
|
if (openAIOptions) {
|
|
3222
|
-
const speechModelOptions = {
|
|
3270
|
+
const speechModelOptions = {
|
|
3271
|
+
speed: (_a2 = openAIOptions.speed) != null ? _a2 : void 0,
|
|
3272
|
+
instructions: (_b = openAIOptions.instructions) != null ? _b : void 0
|
|
3273
|
+
};
|
|
3223
3274
|
for (const key in speechModelOptions) {
|
|
3224
3275
|
const value = speechModelOptions[key];
|
|
3225
3276
|
if (value !== void 0) {
|