@ai-sdk/openai 2.0.10 → 2.0.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 +18 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +108 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -11
- 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 +106 -10
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +106 -10
- 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
|
};
|
|
@@ -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
|
});
|
|
@@ -3056,7 +3150,9 @@ var openaiResponsesProviderOptionsSchema = z13.object({
|
|
|
3056
3150
|
reasoningSummary: z13.string().nullish(),
|
|
3057
3151
|
serviceTier: z13.enum(["auto", "flex", "priority"]).nullish(),
|
|
3058
3152
|
include: z13.array(z13.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish(),
|
|
3059
|
-
textVerbosity: z13.enum(["low", "medium", "high"]).nullish()
|
|
3153
|
+
textVerbosity: z13.enum(["low", "medium", "high"]).nullish(),
|
|
3154
|
+
promptCacheKey: z13.string().nullish(),
|
|
3155
|
+
safetyIdentifier: z13.string().nullish()
|
|
3060
3156
|
});
|
|
3061
3157
|
|
|
3062
3158
|
// src/speech/openai-speech-model.ts
|
|
@@ -3430,7 +3526,8 @@ function createOpenAI(options = {}) {
|
|
|
3430
3526
|
provider: `${providerName}.responses`,
|
|
3431
3527
|
url: ({ path }) => `${baseURL}${path}`,
|
|
3432
3528
|
headers: getHeaders,
|
|
3433
|
-
fetch: options.fetch
|
|
3529
|
+
fetch: options.fetch,
|
|
3530
|
+
fileIdPrefixes: ["file-"]
|
|
3434
3531
|
});
|
|
3435
3532
|
};
|
|
3436
3533
|
const provider = function(modelId) {
|