@ai-sdk/openai 2.0.10 → 2.0.12
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 +28 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +144 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -20
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +15 -3
- package/dist/internal/index.d.ts +15 -3
- package/dist/internal/index.js +142 -19
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +142 -19
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -322,7 +322,20 @@ var openaiProviderOptions = z2.object({
|
|
|
322
322
|
* Controls the verbosity of the model's responses.
|
|
323
323
|
* Lower values will result in more concise responses, while higher values will result in more verbose responses.
|
|
324
324
|
*/
|
|
325
|
-
textVerbosity: z2.enum(["low", "medium", "high"]).optional()
|
|
325
|
+
textVerbosity: z2.enum(["low", "medium", "high"]).optional(),
|
|
326
|
+
/**
|
|
327
|
+
* A cache key for prompt caching. Allows manual control over prompt caching behavior.
|
|
328
|
+
* Useful for improving cache hit rates and working around automatic caching issues.
|
|
329
|
+
*/
|
|
330
|
+
promptCacheKey: z2.string().optional(),
|
|
331
|
+
/**
|
|
332
|
+
* A stable identifier used to help detect users of your application
|
|
333
|
+
* that may be violating OpenAI's usage policies. The IDs should be a
|
|
334
|
+
* string that uniquely identifies each user. We recommend hashing their
|
|
335
|
+
* username or email address, in order to avoid sending us any identifying
|
|
336
|
+
* information.
|
|
337
|
+
*/
|
|
338
|
+
safetyIdentifier: z2.string().optional()
|
|
326
339
|
});
|
|
327
340
|
|
|
328
341
|
// src/chat/openai-chat-prepare-tools.ts
|
|
@@ -595,6 +608,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
595
608
|
prediction: openaiOptions.prediction,
|
|
596
609
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
597
610
|
service_tier: openaiOptions.serviceTier,
|
|
611
|
+
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
612
|
+
safety_identifier: openaiOptions.safetyIdentifier,
|
|
598
613
|
// messages:
|
|
599
614
|
messages
|
|
600
615
|
};
|
|
@@ -1110,13 +1125,13 @@ var openaiChatChunkSchema = z5.union([
|
|
|
1110
1125
|
openaiErrorDataSchema
|
|
1111
1126
|
]);
|
|
1112
1127
|
function isReasoningModel(modelId) {
|
|
1113
|
-
return modelId.startsWith("o") || modelId.startsWith("gpt-5");
|
|
1128
|
+
return (modelId.startsWith("o") || modelId.startsWith("gpt-5")) && !modelId.startsWith("gpt-5-chat");
|
|
1114
1129
|
}
|
|
1115
1130
|
function supportsFlexProcessing(modelId) {
|
|
1116
|
-
return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5");
|
|
1131
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
1117
1132
|
}
|
|
1118
1133
|
function supportsPriorityProcessing(modelId) {
|
|
1119
|
-
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
1134
|
+
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
1120
1135
|
}
|
|
1121
1136
|
function getSystemMessageMode(modelId) {
|
|
1122
1137
|
var _a, _b;
|
|
@@ -1832,9 +1847,14 @@ import {
|
|
|
1832
1847
|
import { parseProviderOptions as parseProviderOptions4 } from "@ai-sdk/provider-utils";
|
|
1833
1848
|
import { z as z12 } from "zod/v4";
|
|
1834
1849
|
import { convertToBase64 as convertToBase642 } from "@ai-sdk/provider-utils";
|
|
1850
|
+
function isFileId(data, prefixes) {
|
|
1851
|
+
if (!prefixes) return false;
|
|
1852
|
+
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
1853
|
+
}
|
|
1835
1854
|
async function convertToOpenAIResponsesMessages({
|
|
1836
1855
|
prompt,
|
|
1837
|
-
systemMessageMode
|
|
1856
|
+
systemMessageMode,
|
|
1857
|
+
fileIdPrefixes
|
|
1838
1858
|
}) {
|
|
1839
1859
|
var _a, _b, _c, _d, _e, _f;
|
|
1840
1860
|
const messages = [];
|
|
@@ -1881,7 +1901,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1881
1901
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
1882
1902
|
return {
|
|
1883
1903
|
type: "input_image",
|
|
1884
|
-
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && part.data
|
|
1904
|
+
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
1885
1905
|
image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
1886
1906
|
},
|
|
1887
1907
|
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
@@ -1894,7 +1914,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1894
1914
|
}
|
|
1895
1915
|
return {
|
|
1896
1916
|
type: "input_file",
|
|
1897
|
-
...typeof part.data === "string" && part.data
|
|
1917
|
+
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
1898
1918
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
1899
1919
|
file_data: `data:application/pdf;base64,${convertToBase642(part.data)}`
|
|
1900
1920
|
}
|
|
@@ -2183,7 +2203,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2183
2203
|
}
|
|
2184
2204
|
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
2185
2205
|
prompt,
|
|
2186
|
-
systemMessageMode: modelConfig.systemMessageMode
|
|
2206
|
+
systemMessageMode: modelConfig.systemMessageMode,
|
|
2207
|
+
fileIdPrefixes: this.config.fileIdPrefixes
|
|
2187
2208
|
});
|
|
2188
2209
|
warnings.push(...messageWarnings);
|
|
2189
2210
|
const openaiOptions = await parseProviderOptions5({
|
|
@@ -2223,6 +2244,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2223
2244
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2224
2245
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2225
2246
|
include: openaiOptions == null ? void 0 : openaiOptions.include,
|
|
2247
|
+
prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
|
|
2248
|
+
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
2226
2249
|
// model-specific settings:
|
|
2227
2250
|
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2228
2251
|
reasoning: {
|
|
@@ -2372,7 +2395,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2372
2395
|
z13.object({
|
|
2373
2396
|
type: z13.literal("file_search_call"),
|
|
2374
2397
|
id: z13.string(),
|
|
2375
|
-
status: z13.string().optional()
|
|
2398
|
+
status: z13.string().optional(),
|
|
2399
|
+
queries: z13.array(z13.string()).nullish(),
|
|
2400
|
+
results: z13.array(
|
|
2401
|
+
z13.object({
|
|
2402
|
+
attributes: z13.object({
|
|
2403
|
+
file_id: z13.string(),
|
|
2404
|
+
filename: z13.string(),
|
|
2405
|
+
score: z13.number(),
|
|
2406
|
+
text: z13.string()
|
|
2407
|
+
})
|
|
2408
|
+
})
|
|
2409
|
+
).nullish()
|
|
2376
2410
|
}),
|
|
2377
2411
|
z13.object({
|
|
2378
2412
|
type: z13.literal("reasoning"),
|
|
@@ -2514,7 +2548,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2514
2548
|
toolName: "file_search",
|
|
2515
2549
|
result: {
|
|
2516
2550
|
type: "file_search_tool_result",
|
|
2517
|
-
status: part.status || "completed"
|
|
2551
|
+
status: part.status || "completed",
|
|
2552
|
+
...part.queries && { queries: part.queries },
|
|
2553
|
+
...part.results && { results: part.results }
|
|
2518
2554
|
},
|
|
2519
2555
|
providerExecuted: true
|
|
2520
2556
|
});
|
|
@@ -2629,6 +2665,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2629
2665
|
id: value.item.id,
|
|
2630
2666
|
toolName: "computer_use"
|
|
2631
2667
|
});
|
|
2668
|
+
} else if (value.item.type === "file_search_call") {
|
|
2669
|
+
ongoingToolCalls[value.output_index] = {
|
|
2670
|
+
toolName: "file_search",
|
|
2671
|
+
toolCallId: value.item.id
|
|
2672
|
+
};
|
|
2673
|
+
controller.enqueue({
|
|
2674
|
+
type: "tool-input-start",
|
|
2675
|
+
id: value.item.id,
|
|
2676
|
+
toolName: "file_search"
|
|
2677
|
+
});
|
|
2632
2678
|
} else if (value.item.type === "message") {
|
|
2633
2679
|
controller.enqueue({
|
|
2634
2680
|
type: "text-start",
|
|
@@ -2722,6 +2768,32 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2722
2768
|
},
|
|
2723
2769
|
providerExecuted: true
|
|
2724
2770
|
});
|
|
2771
|
+
} else if (value.item.type === "file_search_call") {
|
|
2772
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2773
|
+
hasToolCalls = true;
|
|
2774
|
+
controller.enqueue({
|
|
2775
|
+
type: "tool-input-end",
|
|
2776
|
+
id: value.item.id
|
|
2777
|
+
});
|
|
2778
|
+
controller.enqueue({
|
|
2779
|
+
type: "tool-call",
|
|
2780
|
+
toolCallId: value.item.id,
|
|
2781
|
+
toolName: "file_search",
|
|
2782
|
+
input: "",
|
|
2783
|
+
providerExecuted: true
|
|
2784
|
+
});
|
|
2785
|
+
controller.enqueue({
|
|
2786
|
+
type: "tool-result",
|
|
2787
|
+
toolCallId: value.item.id,
|
|
2788
|
+
toolName: "file_search",
|
|
2789
|
+
result: {
|
|
2790
|
+
type: "file_search_tool_result",
|
|
2791
|
+
status: value.item.status || "completed",
|
|
2792
|
+
...value.item.queries && { queries: value.item.queries },
|
|
2793
|
+
...value.item.results && { results: value.item.results }
|
|
2794
|
+
},
|
|
2795
|
+
providerExecuted: true
|
|
2796
|
+
});
|
|
2725
2797
|
} else if (value.item.type === "message") {
|
|
2726
2798
|
controller.enqueue({
|
|
2727
2799
|
type: "text-end",
|
|
@@ -2900,7 +2972,18 @@ var responseOutputItemAddedSchema = z13.object({
|
|
|
2900
2972
|
z13.object({
|
|
2901
2973
|
type: z13.literal("file_search_call"),
|
|
2902
2974
|
id: z13.string(),
|
|
2903
|
-
status: z13.string()
|
|
2975
|
+
status: z13.string(),
|
|
2976
|
+
queries: z13.array(z13.string()).nullish(),
|
|
2977
|
+
results: z13.array(
|
|
2978
|
+
z13.object({
|
|
2979
|
+
attributes: z13.object({
|
|
2980
|
+
file_id: z13.string(),
|
|
2981
|
+
filename: z13.string(),
|
|
2982
|
+
score: z13.number(),
|
|
2983
|
+
text: z13.string()
|
|
2984
|
+
})
|
|
2985
|
+
})
|
|
2986
|
+
).optional()
|
|
2904
2987
|
})
|
|
2905
2988
|
])
|
|
2906
2989
|
});
|
|
@@ -2938,7 +3021,18 @@ var responseOutputItemDoneSchema = z13.object({
|
|
|
2938
3021
|
z13.object({
|
|
2939
3022
|
type: z13.literal("file_search_call"),
|
|
2940
3023
|
id: z13.string(),
|
|
2941
|
-
status: z13.literal("completed")
|
|
3024
|
+
status: z13.literal("completed"),
|
|
3025
|
+
queries: z13.array(z13.string()).nullish(),
|
|
3026
|
+
results: z13.array(
|
|
3027
|
+
z13.object({
|
|
3028
|
+
attributes: z13.object({
|
|
3029
|
+
file_id: z13.string(),
|
|
3030
|
+
filename: z13.string(),
|
|
3031
|
+
score: z13.number(),
|
|
3032
|
+
text: z13.string()
|
|
3033
|
+
})
|
|
3034
|
+
})
|
|
3035
|
+
).nullish()
|
|
2942
3036
|
})
|
|
2943
3037
|
])
|
|
2944
3038
|
});
|
|
@@ -3018,6 +3112,13 @@ function isErrorChunk(chunk) {
|
|
|
3018
3112
|
return chunk.type === "error";
|
|
3019
3113
|
}
|
|
3020
3114
|
function getResponsesModelConfig(modelId) {
|
|
3115
|
+
if (modelId.startsWith("gpt-5-chat")) {
|
|
3116
|
+
return {
|
|
3117
|
+
isReasoningModel: false,
|
|
3118
|
+
systemMessageMode: "system",
|
|
3119
|
+
requiredAutoTruncation: false
|
|
3120
|
+
};
|
|
3121
|
+
}
|
|
3021
3122
|
if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
3022
3123
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
3023
3124
|
return {
|
|
@@ -3039,10 +3140,10 @@ function getResponsesModelConfig(modelId) {
|
|
|
3039
3140
|
};
|
|
3040
3141
|
}
|
|
3041
3142
|
function supportsFlexProcessing2(modelId) {
|
|
3042
|
-
return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5");
|
|
3143
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
3043
3144
|
}
|
|
3044
3145
|
function supportsPriorityProcessing2(modelId) {
|
|
3045
|
-
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
3146
|
+
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
3046
3147
|
}
|
|
3047
3148
|
var openaiResponsesProviderOptionsSchema = z13.object({
|
|
3048
3149
|
metadata: z13.any().nullish(),
|
|
@@ -3056,7 +3157,9 @@ var openaiResponsesProviderOptionsSchema = z13.object({
|
|
|
3056
3157
|
reasoningSummary: z13.string().nullish(),
|
|
3057
3158
|
serviceTier: z13.enum(["auto", "flex", "priority"]).nullish(),
|
|
3058
3159
|
include: z13.array(z13.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish(),
|
|
3059
|
-
textVerbosity: z13.enum(["low", "medium", "high"]).nullish()
|
|
3160
|
+
textVerbosity: z13.enum(["low", "medium", "high"]).nullish(),
|
|
3161
|
+
promptCacheKey: z13.string().nullish(),
|
|
3162
|
+
safetyIdentifier: z13.string().nullish()
|
|
3060
3163
|
});
|
|
3061
3164
|
|
|
3062
3165
|
// src/speech/openai-speech-model.ts
|
|
@@ -3297,6 +3400,8 @@ var OpenAITranscriptionModel = class {
|
|
|
3297
3400
|
include: openAIOptions.include,
|
|
3298
3401
|
language: openAIOptions.language,
|
|
3299
3402
|
prompt: openAIOptions.prompt,
|
|
3403
|
+
response_format: "verbose_json",
|
|
3404
|
+
// always use verbose_json to get segments
|
|
3300
3405
|
temperature: openAIOptions.temperature,
|
|
3301
3406
|
timestamp_granularities: openAIOptions.timestampGranularities
|
|
3302
3407
|
};
|
|
@@ -3312,7 +3417,7 @@ var OpenAITranscriptionModel = class {
|
|
|
3312
3417
|
};
|
|
3313
3418
|
}
|
|
3314
3419
|
async doGenerate(options) {
|
|
3315
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3420
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3316
3421
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3317
3422
|
const { formData, warnings } = await this.getArgs(options);
|
|
3318
3423
|
const {
|
|
@@ -3336,13 +3441,17 @@ var OpenAITranscriptionModel = class {
|
|
|
3336
3441
|
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
3337
3442
|
return {
|
|
3338
3443
|
text: response.text,
|
|
3339
|
-
segments: (
|
|
3444
|
+
segments: (_g = (_f = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
3445
|
+
text: segment.text,
|
|
3446
|
+
startSecond: segment.start,
|
|
3447
|
+
endSecond: segment.end
|
|
3448
|
+
}))) != null ? _f : (_e = response.words) == null ? void 0 : _e.map((word) => ({
|
|
3340
3449
|
text: word.word,
|
|
3341
3450
|
startSecond: word.start,
|
|
3342
3451
|
endSecond: word.end
|
|
3343
|
-
}))) != null ?
|
|
3452
|
+
}))) != null ? _g : [],
|
|
3344
3453
|
language,
|
|
3345
|
-
durationInSeconds: (
|
|
3454
|
+
durationInSeconds: (_h = response.duration) != null ? _h : void 0,
|
|
3346
3455
|
warnings,
|
|
3347
3456
|
response: {
|
|
3348
3457
|
timestamp: currentDate,
|
|
@@ -3363,6 +3472,20 @@ var openaiTranscriptionResponseSchema = z16.object({
|
|
|
3363
3472
|
start: z16.number(),
|
|
3364
3473
|
end: z16.number()
|
|
3365
3474
|
})
|
|
3475
|
+
).nullish(),
|
|
3476
|
+
segments: z16.array(
|
|
3477
|
+
z16.object({
|
|
3478
|
+
id: z16.number(),
|
|
3479
|
+
seek: z16.number(),
|
|
3480
|
+
start: z16.number(),
|
|
3481
|
+
end: z16.number(),
|
|
3482
|
+
text: z16.string(),
|
|
3483
|
+
tokens: z16.array(z16.number()),
|
|
3484
|
+
temperature: z16.number(),
|
|
3485
|
+
avg_logprob: z16.number(),
|
|
3486
|
+
compression_ratio: z16.number(),
|
|
3487
|
+
no_speech_prob: z16.number()
|
|
3488
|
+
})
|
|
3366
3489
|
).nullish()
|
|
3367
3490
|
});
|
|
3368
3491
|
|
|
@@ -3430,7 +3553,8 @@ function createOpenAI(options = {}) {
|
|
|
3430
3553
|
provider: `${providerName}.responses`,
|
|
3431
3554
|
url: ({ path }) => `${baseURL}${path}`,
|
|
3432
3555
|
headers: getHeaders,
|
|
3433
|
-
fetch: options.fetch
|
|
3556
|
+
fetch: options.fetch,
|
|
3557
|
+
fileIdPrefixes: ["file-"]
|
|
3434
3558
|
});
|
|
3435
3559
|
};
|
|
3436
3560
|
const provider = function(modelId) {
|