@ai-sdk/openai 2.0.13 → 2.0.15
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 +15 -0
- package/dist/index.js +118 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -62
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +118 -62
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +118 -62
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 2.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a4bef93: feat(provider/openai): expose web search queries in responses api
|
|
8
|
+
- 6ed34cb: refactor(openai): consolidate model config into `getResponsesModelConfig()`
|
|
9
|
+
|
|
10
|
+
https://github.com/vercel/ai/pull/8038
|
|
11
|
+
|
|
12
|
+
## 2.0.14
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 7f47105: fix(provider/openai): support file_citation annotations in responses api
|
|
17
|
+
|
|
3
18
|
## 2.0.13
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -2287,7 +2287,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2287
2287
|
});
|
|
2288
2288
|
}
|
|
2289
2289
|
}
|
|
2290
|
-
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !
|
|
2290
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelConfig.supportsFlexProcessing) {
|
|
2291
2291
|
warnings.push({
|
|
2292
2292
|
type: "unsupported-setting",
|
|
2293
2293
|
setting: "serviceTier",
|
|
@@ -2295,7 +2295,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2295
2295
|
});
|
|
2296
2296
|
delete baseArgs.service_tier;
|
|
2297
2297
|
}
|
|
2298
|
-
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !
|
|
2298
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !modelConfig.supportsPriorityProcessing) {
|
|
2299
2299
|
warnings.push({
|
|
2300
2300
|
type: "unsupported-setting",
|
|
2301
2301
|
setting: "serviceTier",
|
|
@@ -2322,7 +2322,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2322
2322
|
};
|
|
2323
2323
|
}
|
|
2324
2324
|
async doGenerate(options) {
|
|
2325
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2325
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2326
2326
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2327
2327
|
const url = this.config.url({
|
|
2328
2328
|
path: "/responses",
|
|
@@ -2358,13 +2358,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2358
2358
|
text: import_v413.z.string(),
|
|
2359
2359
|
logprobs: LOGPROBS_SCHEMA.nullish(),
|
|
2360
2360
|
annotations: import_v413.z.array(
|
|
2361
|
-
import_v413.z.
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2361
|
+
import_v413.z.discriminatedUnion("type", [
|
|
2362
|
+
import_v413.z.object({
|
|
2363
|
+
type: import_v413.z.literal("url_citation"),
|
|
2364
|
+
start_index: import_v413.z.number(),
|
|
2365
|
+
end_index: import_v413.z.number(),
|
|
2366
|
+
url: import_v413.z.string(),
|
|
2367
|
+
title: import_v413.z.string()
|
|
2368
|
+
}),
|
|
2369
|
+
import_v413.z.object({
|
|
2370
|
+
type: import_v413.z.literal("file_citation"),
|
|
2371
|
+
start_index: import_v413.z.number(),
|
|
2372
|
+
end_index: import_v413.z.number(),
|
|
2373
|
+
file_id: import_v413.z.string(),
|
|
2374
|
+
quote: import_v413.z.string()
|
|
2375
|
+
})
|
|
2376
|
+
])
|
|
2368
2377
|
)
|
|
2369
2378
|
})
|
|
2370
2379
|
)
|
|
@@ -2379,7 +2388,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2379
2388
|
import_v413.z.object({
|
|
2380
2389
|
type: import_v413.z.literal("web_search_call"),
|
|
2381
2390
|
id: import_v413.z.string(),
|
|
2382
|
-
status: import_v413.z.string().optional()
|
|
2391
|
+
status: import_v413.z.string().optional(),
|
|
2392
|
+
action: import_v413.z.object({
|
|
2393
|
+
type: import_v413.z.literal("search"),
|
|
2394
|
+
query: import_v413.z.string().optional()
|
|
2395
|
+
}).nullish()
|
|
2383
2396
|
}),
|
|
2384
2397
|
import_v413.z.object({
|
|
2385
2398
|
type: import_v413.z.literal("computer_call"),
|
|
@@ -2470,13 +2483,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2470
2483
|
}
|
|
2471
2484
|
});
|
|
2472
2485
|
for (const annotation of contentPart.annotations) {
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2486
|
+
if (annotation.type === "url_citation") {
|
|
2487
|
+
content.push({
|
|
2488
|
+
type: "source",
|
|
2489
|
+
sourceType: "url",
|
|
2490
|
+
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils12.generateId)(),
|
|
2491
|
+
url: annotation.url,
|
|
2492
|
+
title: annotation.title
|
|
2493
|
+
});
|
|
2494
|
+
} else if (annotation.type === "file_citation") {
|
|
2495
|
+
content.push({
|
|
2496
|
+
type: "source",
|
|
2497
|
+
sourceType: "document",
|
|
2498
|
+
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils12.generateId)(),
|
|
2499
|
+
mediaType: "text/plain",
|
|
2500
|
+
title: annotation.quote,
|
|
2501
|
+
filename: annotation.file_id
|
|
2502
|
+
});
|
|
2503
|
+
}
|
|
2480
2504
|
}
|
|
2481
2505
|
}
|
|
2482
2506
|
break;
|
|
@@ -2500,14 +2524,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2500
2524
|
type: "tool-call",
|
|
2501
2525
|
toolCallId: part.id,
|
|
2502
2526
|
toolName: "web_search_preview",
|
|
2503
|
-
input: "",
|
|
2527
|
+
input: (_k = (_j = part.action) == null ? void 0 : _j.query) != null ? _k : "",
|
|
2504
2528
|
providerExecuted: true
|
|
2505
2529
|
});
|
|
2506
2530
|
content.push({
|
|
2507
2531
|
type: "tool-result",
|
|
2508
2532
|
toolCallId: part.id,
|
|
2509
2533
|
toolName: "web_search_preview",
|
|
2510
|
-
result: {
|
|
2534
|
+
result: {
|
|
2535
|
+
status: part.status || "completed",
|
|
2536
|
+
...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
|
|
2537
|
+
},
|
|
2511
2538
|
providerExecuted: true
|
|
2512
2539
|
});
|
|
2513
2540
|
break;
|
|
@@ -2565,15 +2592,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2565
2592
|
return {
|
|
2566
2593
|
content,
|
|
2567
2594
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2568
|
-
finishReason: (
|
|
2595
|
+
finishReason: (_m = response.incomplete_details) == null ? void 0 : _m.reason,
|
|
2569
2596
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2570
2597
|
}),
|
|
2571
2598
|
usage: {
|
|
2572
2599
|
inputTokens: response.usage.input_tokens,
|
|
2573
2600
|
outputTokens: response.usage.output_tokens,
|
|
2574
2601
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2575
|
-
reasoningTokens: (
|
|
2576
|
-
cachedInputTokens: (
|
|
2602
|
+
reasoningTokens: (_o = (_n = response.usage.output_tokens_details) == null ? void 0 : _n.reasoning_tokens) != null ? _o : void 0,
|
|
2603
|
+
cachedInputTokens: (_q = (_p = response.usage.input_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : void 0
|
|
2577
2604
|
},
|
|
2578
2605
|
request: { body },
|
|
2579
2606
|
response: {
|
|
@@ -2625,7 +2652,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2625
2652
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2626
2653
|
},
|
|
2627
2654
|
transform(chunk, controller) {
|
|
2628
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2655
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2629
2656
|
if (options.includeRawChunks) {
|
|
2630
2657
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2631
2658
|
}
|
|
@@ -2732,7 +2759,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2732
2759
|
type: "tool-call",
|
|
2733
2760
|
toolCallId: value.item.id,
|
|
2734
2761
|
toolName: "web_search_preview",
|
|
2735
|
-
input: "",
|
|
2762
|
+
input: (_c = (_b = value.item.action) == null ? void 0 : _b.query) != null ? _c : "",
|
|
2736
2763
|
providerExecuted: true
|
|
2737
2764
|
});
|
|
2738
2765
|
controller.enqueue({
|
|
@@ -2741,7 +2768,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2741
2768
|
toolName: "web_search_preview",
|
|
2742
2769
|
result: {
|
|
2743
2770
|
type: "web_search_tool_result",
|
|
2744
|
-
status: value.item.status || "completed"
|
|
2771
|
+
status: value.item.status || "completed",
|
|
2772
|
+
...((_d = value.item.action) == null ? void 0 : _d.query) && {
|
|
2773
|
+
query: value.item.action.query
|
|
2774
|
+
}
|
|
2745
2775
|
},
|
|
2746
2776
|
providerExecuted: true
|
|
2747
2777
|
});
|
|
@@ -2809,7 +2839,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2809
2839
|
providerMetadata: {
|
|
2810
2840
|
openai: {
|
|
2811
2841
|
itemId: value.item.id,
|
|
2812
|
-
reasoningEncryptedContent: (
|
|
2842
|
+
reasoningEncryptedContent: (_e = value.item.encrypted_content) != null ? _e : null
|
|
2813
2843
|
}
|
|
2814
2844
|
}
|
|
2815
2845
|
});
|
|
@@ -2844,7 +2874,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2844
2874
|
}
|
|
2845
2875
|
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2846
2876
|
if (value.summary_index > 0) {
|
|
2847
|
-
(
|
|
2877
|
+
(_f = activeReasoning[value.item_id]) == null ? void 0 : _f.summaryParts.push(
|
|
2848
2878
|
value.summary_index
|
|
2849
2879
|
);
|
|
2850
2880
|
controller.enqueue({
|
|
@@ -2853,7 +2883,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2853
2883
|
providerMetadata: {
|
|
2854
2884
|
openai: {
|
|
2855
2885
|
itemId: value.item_id,
|
|
2856
|
-
reasoningEncryptedContent: (
|
|
2886
|
+
reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
|
|
2857
2887
|
}
|
|
2858
2888
|
}
|
|
2859
2889
|
});
|
|
@@ -2871,22 +2901,33 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2871
2901
|
});
|
|
2872
2902
|
} else if (isResponseFinishedChunk(value)) {
|
|
2873
2903
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2874
|
-
finishReason: (
|
|
2904
|
+
finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
|
|
2875
2905
|
hasToolCalls
|
|
2876
2906
|
});
|
|
2877
2907
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2878
2908
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2879
2909
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2880
|
-
usage.reasoningTokens = (
|
|
2881
|
-
usage.cachedInputTokens = (
|
|
2910
|
+
usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
|
|
2911
|
+
usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
|
|
2882
2912
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2913
|
+
if (value.annotation.type === "url_citation") {
|
|
2914
|
+
controller.enqueue({
|
|
2915
|
+
type: "source",
|
|
2916
|
+
sourceType: "url",
|
|
2917
|
+
id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils12.generateId)(),
|
|
2918
|
+
url: value.annotation.url,
|
|
2919
|
+
title: value.annotation.title
|
|
2920
|
+
});
|
|
2921
|
+
} else if (value.annotation.type === "file_citation") {
|
|
2922
|
+
controller.enqueue({
|
|
2923
|
+
type: "source",
|
|
2924
|
+
sourceType: "document",
|
|
2925
|
+
id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : (0, import_provider_utils12.generateId)(),
|
|
2926
|
+
mediaType: "text/plain",
|
|
2927
|
+
title: value.annotation.quote,
|
|
2928
|
+
filename: value.annotation.file_id
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2890
2931
|
} else if (isErrorChunk(value)) {
|
|
2891
2932
|
controller.enqueue({ type: "error", error: value });
|
|
2892
2933
|
}
|
|
@@ -2971,7 +3012,11 @@ var responseOutputItemAddedSchema = import_v413.z.object({
|
|
|
2971
3012
|
import_v413.z.object({
|
|
2972
3013
|
type: import_v413.z.literal("web_search_call"),
|
|
2973
3014
|
id: import_v413.z.string(),
|
|
2974
|
-
status: import_v413.z.string()
|
|
3015
|
+
status: import_v413.z.string(),
|
|
3016
|
+
action: import_v413.z.object({
|
|
3017
|
+
type: import_v413.z.literal("search"),
|
|
3018
|
+
query: import_v413.z.string().optional()
|
|
3019
|
+
}).nullish()
|
|
2975
3020
|
}),
|
|
2976
3021
|
import_v413.z.object({
|
|
2977
3022
|
type: import_v413.z.literal("computer_call"),
|
|
@@ -3020,7 +3065,11 @@ var responseOutputItemDoneSchema = import_v413.z.object({
|
|
|
3020
3065
|
import_v413.z.object({
|
|
3021
3066
|
type: import_v413.z.literal("web_search_call"),
|
|
3022
3067
|
id: import_v413.z.string(),
|
|
3023
|
-
status: import_v413.z.literal("completed")
|
|
3068
|
+
status: import_v413.z.literal("completed"),
|
|
3069
|
+
action: import_v413.z.object({
|
|
3070
|
+
type: import_v413.z.literal("search"),
|
|
3071
|
+
query: import_v413.z.string().optional()
|
|
3072
|
+
}).nullish()
|
|
3024
3073
|
}),
|
|
3025
3074
|
import_v413.z.object({
|
|
3026
3075
|
type: import_v413.z.literal("computer_call"),
|
|
@@ -3053,11 +3102,18 @@ var responseFunctionCallArgumentsDeltaSchema = import_v413.z.object({
|
|
|
3053
3102
|
});
|
|
3054
3103
|
var responseAnnotationAddedSchema = import_v413.z.object({
|
|
3055
3104
|
type: import_v413.z.literal("response.output_text.annotation.added"),
|
|
3056
|
-
annotation: import_v413.z.
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3105
|
+
annotation: import_v413.z.discriminatedUnion("type", [
|
|
3106
|
+
import_v413.z.object({
|
|
3107
|
+
type: import_v413.z.literal("url_citation"),
|
|
3108
|
+
url: import_v413.z.string(),
|
|
3109
|
+
title: import_v413.z.string()
|
|
3110
|
+
}),
|
|
3111
|
+
import_v413.z.object({
|
|
3112
|
+
type: import_v413.z.literal("file_citation"),
|
|
3113
|
+
file_id: import_v413.z.string(),
|
|
3114
|
+
quote: import_v413.z.string()
|
|
3115
|
+
})
|
|
3116
|
+
])
|
|
3061
3117
|
});
|
|
3062
3118
|
var responseReasoningSummaryPartAddedSchema = import_v413.z.object({
|
|
3063
3119
|
type: import_v413.z.literal("response.reasoning_summary_part.added"),
|
|
@@ -3121,39 +3177,39 @@ function isErrorChunk(chunk) {
|
|
|
3121
3177
|
return chunk.type === "error";
|
|
3122
3178
|
}
|
|
3123
3179
|
function getResponsesModelConfig(modelId) {
|
|
3180
|
+
const supportsFlexProcessing2 = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
3181
|
+
const supportsPriorityProcessing2 = 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");
|
|
3182
|
+
const defaults = {
|
|
3183
|
+
requiredAutoTruncation: false,
|
|
3184
|
+
systemMessageMode: "system",
|
|
3185
|
+
supportsFlexProcessing: supportsFlexProcessing2,
|
|
3186
|
+
supportsPriorityProcessing: supportsPriorityProcessing2
|
|
3187
|
+
};
|
|
3124
3188
|
if (modelId.startsWith("gpt-5-chat")) {
|
|
3125
3189
|
return {
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
requiredAutoTruncation: false
|
|
3190
|
+
...defaults,
|
|
3191
|
+
isReasoningModel: false
|
|
3129
3192
|
};
|
|
3130
3193
|
}
|
|
3131
3194
|
if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
3132
3195
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
3133
3196
|
return {
|
|
3197
|
+
...defaults,
|
|
3134
3198
|
isReasoningModel: true,
|
|
3135
|
-
systemMessageMode: "remove"
|
|
3136
|
-
requiredAutoTruncation: false
|
|
3199
|
+
systemMessageMode: "remove"
|
|
3137
3200
|
};
|
|
3138
3201
|
}
|
|
3139
3202
|
return {
|
|
3203
|
+
...defaults,
|
|
3140
3204
|
isReasoningModel: true,
|
|
3141
|
-
systemMessageMode: "developer"
|
|
3142
|
-
requiredAutoTruncation: false
|
|
3205
|
+
systemMessageMode: "developer"
|
|
3143
3206
|
};
|
|
3144
3207
|
}
|
|
3145
3208
|
return {
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
requiredAutoTruncation: false
|
|
3209
|
+
...defaults,
|
|
3210
|
+
isReasoningModel: false
|
|
3149
3211
|
};
|
|
3150
3212
|
}
|
|
3151
|
-
function supportsFlexProcessing2(modelId) {
|
|
3152
|
-
return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
3153
|
-
}
|
|
3154
|
-
function supportsPriorityProcessing2(modelId) {
|
|
3155
|
-
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");
|
|
3156
|
-
}
|
|
3157
3213
|
var openaiResponsesProviderOptionsSchema = import_v413.z.object({
|
|
3158
3214
|
metadata: import_v413.z.any().nullish(),
|
|
3159
3215
|
parallelToolCalls: import_v413.z.boolean().nullish(),
|