@ai-sdk/openai 2.0.133 → 2.0.135
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 +14 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +86 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -13
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +580 -507
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +578 -504
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2349,6 +2349,7 @@ import {
|
|
|
2349
2349
|
import {
|
|
2350
2350
|
convertToBase64 as convertToBase642,
|
|
2351
2351
|
parseProviderOptions as parseProviderOptions5,
|
|
2352
|
+
safeValidateTypes,
|
|
2352
2353
|
validateTypes
|
|
2353
2354
|
} from "@ai-sdk/provider-utils";
|
|
2354
2355
|
import { z as z17 } from "zod/v4";
|
|
@@ -2559,6 +2560,56 @@ var openaiResponsesSystemMessageOptionsSchema = lazyValidator9(
|
|
|
2559
2560
|
);
|
|
2560
2561
|
|
|
2561
2562
|
// src/responses/convert-to-openai-responses-input.ts
|
|
2563
|
+
async function convertWebSearchToolResultOutput({
|
|
2564
|
+
output,
|
|
2565
|
+
id
|
|
2566
|
+
}) {
|
|
2567
|
+
if (output.type !== "json") {
|
|
2568
|
+
return void 0;
|
|
2569
|
+
}
|
|
2570
|
+
const validation = await safeValidateTypes({
|
|
2571
|
+
value: output.value,
|
|
2572
|
+
schema: webSearchOutputSchema
|
|
2573
|
+
});
|
|
2574
|
+
if (!validation.success || validation.value.action == null) {
|
|
2575
|
+
return void 0;
|
|
2576
|
+
}
|
|
2577
|
+
const { action, sources } = validation.value;
|
|
2578
|
+
switch (action.type) {
|
|
2579
|
+
case "search":
|
|
2580
|
+
return {
|
|
2581
|
+
type: "web_search_call",
|
|
2582
|
+
id,
|
|
2583
|
+
status: "completed",
|
|
2584
|
+
action: {
|
|
2585
|
+
type: "search",
|
|
2586
|
+
...action.query != null && { query: action.query },
|
|
2587
|
+
...sources != null && { sources }
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
case "openPage":
|
|
2591
|
+
return {
|
|
2592
|
+
type: "web_search_call",
|
|
2593
|
+
id,
|
|
2594
|
+
status: "completed",
|
|
2595
|
+
action: {
|
|
2596
|
+
type: "open_page",
|
|
2597
|
+
url: action.url
|
|
2598
|
+
}
|
|
2599
|
+
};
|
|
2600
|
+
case "findInPage":
|
|
2601
|
+
return {
|
|
2602
|
+
type: "web_search_call",
|
|
2603
|
+
id,
|
|
2604
|
+
status: "completed",
|
|
2605
|
+
action: {
|
|
2606
|
+
type: "find_in_page",
|
|
2607
|
+
url: action.url,
|
|
2608
|
+
pattern: action.pattern
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2562
2613
|
function getPromptCacheBreakpoint2(providerOptions) {
|
|
2563
2614
|
var _a2;
|
|
2564
2615
|
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
@@ -2574,10 +2625,12 @@ async function convertToOpenAIResponsesInput({
|
|
|
2574
2625
|
explicitMessageItemType = false,
|
|
2575
2626
|
fileIdPrefixes,
|
|
2576
2627
|
store,
|
|
2628
|
+
isReasoningModel = false,
|
|
2577
2629
|
configurationUpdateUnsupportedReason,
|
|
2578
|
-
hasLocalShellTool = false
|
|
2630
|
+
hasLocalShellTool = false,
|
|
2631
|
+
webSearchToolName
|
|
2579
2632
|
}) {
|
|
2580
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
2633
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2581
2634
|
let input = [];
|
|
2582
2635
|
const warnings = [];
|
|
2583
2636
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -2726,12 +2779,14 @@ async function convertToOpenAIResponsesInput({
|
|
|
2726
2779
|
case "assistant": {
|
|
2727
2780
|
const reasoningMessages = {};
|
|
2728
2781
|
const toolCallParts = {};
|
|
2782
|
+
let hasPrecedingReasoning = false;
|
|
2729
2783
|
for (const part of content) {
|
|
2730
2784
|
switch (part.type) {
|
|
2731
2785
|
case "text": {
|
|
2732
2786
|
const id = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.itemId;
|
|
2733
2787
|
const phase = (_d = (_c = part.providerOptions) == null ? void 0 : _c.openai) == null ? void 0 : _d.phase;
|
|
2734
|
-
|
|
2788
|
+
const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
|
|
2789
|
+
if (store && canUseItemId) {
|
|
2735
2790
|
input.push({ type: "item_reference", id });
|
|
2736
2791
|
break;
|
|
2737
2792
|
}
|
|
@@ -2739,7 +2794,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2739
2794
|
...explicitMessageItemType && { type: "message" },
|
|
2740
2795
|
role: "assistant",
|
|
2741
2796
|
content: [{ type: "output_text", text: part.text }],
|
|
2742
|
-
id,
|
|
2797
|
+
id: canUseItemId ? id : void 0,
|
|
2743
2798
|
...phase != null && { phase }
|
|
2744
2799
|
});
|
|
2745
2800
|
break;
|
|
@@ -2751,7 +2806,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
2751
2806
|
}
|
|
2752
2807
|
const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
|
|
2753
2808
|
const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
|
|
2754
|
-
|
|
2809
|
+
const canUseItemId = id != null && (!isReasoningModel || hasPrecedingReasoning);
|
|
2810
|
+
if (store && canUseItemId) {
|
|
2755
2811
|
input.push({ type: "item_reference", id });
|
|
2756
2812
|
break;
|
|
2757
2813
|
}
|
|
@@ -2781,12 +2837,27 @@ async function convertToOpenAIResponsesInput({
|
|
|
2781
2837
|
name: part.toolName,
|
|
2782
2838
|
arguments: JSON.stringify(part.input),
|
|
2783
2839
|
...isAsync != null && { async: isAsync },
|
|
2784
|
-
id
|
|
2840
|
+
id: canUseItemId ? id : void 0
|
|
2785
2841
|
});
|
|
2786
2842
|
break;
|
|
2787
2843
|
}
|
|
2788
2844
|
// assistant tool result parts are from provider-executed tools:
|
|
2789
2845
|
case "tool-result": {
|
|
2846
|
+
if (part.toolName === "web_search" || part.toolName === "web_search_preview" || part.toolName === webSearchToolName) {
|
|
2847
|
+
const itemId = (_k = (_j = (_i = part.providerOptions) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.itemId) != null ? _k : part.toolCallId;
|
|
2848
|
+
if (store) {
|
|
2849
|
+
input.push({ type: "item_reference", id: itemId });
|
|
2850
|
+
break;
|
|
2851
|
+
}
|
|
2852
|
+
const webSearchCall = await convertWebSearchToolResultOutput({
|
|
2853
|
+
output: part.output,
|
|
2854
|
+
id: itemId
|
|
2855
|
+
});
|
|
2856
|
+
if (webSearchCall != null) {
|
|
2857
|
+
input.push(webSearchCall);
|
|
2858
|
+
break;
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2790
2861
|
if (store) {
|
|
2791
2862
|
input.push({ type: "item_reference", id: part.toolCallId });
|
|
2792
2863
|
} else {
|
|
@@ -2798,6 +2869,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2798
2869
|
break;
|
|
2799
2870
|
}
|
|
2800
2871
|
case "reasoning": {
|
|
2872
|
+
hasPrecedingReasoning = true;
|
|
2801
2873
|
const providerOptions2 = await parseProviderOptions5({
|
|
2802
2874
|
provider: "openai",
|
|
2803
2875
|
providerOptions: part.providerOptions,
|
|
@@ -3722,6 +3794,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3722
3794
|
modelCapabilities,
|
|
3723
3795
|
options: openaiOptions
|
|
3724
3796
|
});
|
|
3797
|
+
const webSearchToolName = (_a2 = tools == null ? void 0 : tools.find(
|
|
3798
|
+
(tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
3799
|
+
)) == null ? void 0 : _a2.name;
|
|
3725
3800
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
3726
3801
|
prompt,
|
|
3727
3802
|
configurationUpdateUnsupportedReason,
|
|
@@ -3729,8 +3804,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3729
3804
|
systemMessageMode: modelCapabilities.systemMessageMode,
|
|
3730
3805
|
explicitMessageItemType: this.config.explicitMessageItemType,
|
|
3731
3806
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
3732
|
-
store: (
|
|
3733
|
-
|
|
3807
|
+
store: (_b = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _b : true,
|
|
3808
|
+
isReasoningModel: modelCapabilities.isReasoningModel,
|
|
3809
|
+
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
3810
|
+
webSearchToolName
|
|
3734
3811
|
});
|
|
3735
3812
|
warnings.push(...inputWarnings);
|
|
3736
3813
|
let resolvedReasoningEffort = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort;
|
|
@@ -3767,7 +3844,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3767
3844
|
});
|
|
3768
3845
|
}
|
|
3769
3846
|
}
|
|
3770
|
-
const strictJsonSchema = (
|
|
3847
|
+
const strictJsonSchema = (_c = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _c : false;
|
|
3771
3848
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
3772
3849
|
function addInclude(key) {
|
|
3773
3850
|
if (include == null) {
|
|
@@ -3785,9 +3862,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3785
3862
|
if (topLogprobs) {
|
|
3786
3863
|
addInclude("message.output_text.logprobs");
|
|
3787
3864
|
}
|
|
3788
|
-
const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
|
|
3789
|
-
(tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
3790
|
-
)) == null ? void 0 : _c.name;
|
|
3791
3865
|
if (webSearchToolName) {
|
|
3792
3866
|
addInclude("web_search_call.action.sources");
|
|
3793
3867
|
}
|
|
@@ -5236,7 +5310,7 @@ var OpenAITranscriptionModel = class {
|
|
|
5236
5310
|
};
|
|
5237
5311
|
|
|
5238
5312
|
// src/version.ts
|
|
5239
|
-
var VERSION = true ? "2.0.
|
|
5313
|
+
var VERSION = true ? "2.0.135" : "0.0.0-test";
|
|
5240
5314
|
|
|
5241
5315
|
// src/openai-provider.ts
|
|
5242
5316
|
function createOpenAI(options = {}) {
|