@ai-sdk/openai 3.0.124 → 3.0.125
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 +7 -0
- package/dist/index.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +73 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -7
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +15 -15
- package/dist/internal/index.d.ts +15 -15
- package/dist/internal/index.js +964 -898
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +956 -889
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +89 -0
- package/src/responses/openai-responses-api.ts +9 -1
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
isNonNullable,
|
|
13
13
|
parseJSON,
|
|
14
14
|
parseProviderOptions,
|
|
15
|
+
safeValidateTypes,
|
|
15
16
|
validateTypes,
|
|
16
17
|
type ToolNameMapping,
|
|
17
18
|
} from '@ai-sdk/provider-utils';
|
|
@@ -30,11 +31,13 @@ import {
|
|
|
30
31
|
toolSearchInputSchema,
|
|
31
32
|
toolSearchOutputSchema,
|
|
32
33
|
} from '../tool/tool-search';
|
|
34
|
+
import { webSearchOutputSchema } from '../tool/web-search';
|
|
33
35
|
import type {
|
|
34
36
|
OpenAIResponsesCustomToolCallOutput,
|
|
35
37
|
OpenAIResponsesFunctionCallOutput,
|
|
36
38
|
OpenAIResponsesInput,
|
|
37
39
|
OpenAIResponsesReasoning,
|
|
40
|
+
OpenAIResponsesWebSearchCall,
|
|
38
41
|
} from './openai-responses-api';
|
|
39
42
|
import {
|
|
40
43
|
getParallelToolCallMetadata,
|
|
@@ -45,6 +48,65 @@ function serializeToolCallArguments(input: unknown): string {
|
|
|
45
48
|
return JSON.stringify(input === undefined ? {} : input);
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
async function convertWebSearchToolResultOutput({
|
|
52
|
+
output,
|
|
53
|
+
id,
|
|
54
|
+
}: {
|
|
55
|
+
output: LanguageModelV3ToolResultOutput;
|
|
56
|
+
id: string;
|
|
57
|
+
}): Promise<OpenAIResponsesWebSearchCall | undefined> {
|
|
58
|
+
if (output.type !== 'json') {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const validation = await safeValidateTypes({
|
|
63
|
+
value: output.value,
|
|
64
|
+
schema: webSearchOutputSchema,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (!validation.success || validation.value.action == null) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const { action, sources } = validation.value;
|
|
72
|
+
|
|
73
|
+
switch (action.type) {
|
|
74
|
+
case 'search':
|
|
75
|
+
return {
|
|
76
|
+
type: 'web_search_call',
|
|
77
|
+
id,
|
|
78
|
+
status: 'completed',
|
|
79
|
+
action: {
|
|
80
|
+
type: 'search',
|
|
81
|
+
...(action.query != null && { query: action.query }),
|
|
82
|
+
...(action.queries != null && { queries: action.queries }),
|
|
83
|
+
...(sources != null && { sources }),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
case 'openPage':
|
|
87
|
+
return {
|
|
88
|
+
type: 'web_search_call',
|
|
89
|
+
id,
|
|
90
|
+
status: 'completed',
|
|
91
|
+
action: {
|
|
92
|
+
type: 'open_page',
|
|
93
|
+
url: action.url,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
case 'findInPage':
|
|
97
|
+
return {
|
|
98
|
+
type: 'web_search_call',
|
|
99
|
+
id,
|
|
100
|
+
status: 'completed',
|
|
101
|
+
action: {
|
|
102
|
+
type: 'find_in_page',
|
|
103
|
+
url: action.url,
|
|
104
|
+
pattern: action.pattern,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
48
110
|
async function convertFunctionToolResultOutput({
|
|
49
111
|
output,
|
|
50
112
|
promptCacheBreakpoint,
|
|
@@ -865,6 +927,33 @@ export async function convertToOpenAIResponsesInput({
|
|
|
865
927
|
part.toolName,
|
|
866
928
|
);
|
|
867
929
|
|
|
930
|
+
if (
|
|
931
|
+
resolvedResultToolName === 'web_search' ||
|
|
932
|
+
resolvedResultToolName === 'web_search_preview'
|
|
933
|
+
) {
|
|
934
|
+
const itemId =
|
|
935
|
+
(
|
|
936
|
+
part.providerOptions?.[providerOptionsName] as
|
|
937
|
+
| { itemId?: string }
|
|
938
|
+
| undefined
|
|
939
|
+
)?.itemId ?? part.toolCallId;
|
|
940
|
+
|
|
941
|
+
if (store) {
|
|
942
|
+
input.push({ type: 'item_reference', id: itemId });
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
const webSearchCall = await convertWebSearchToolResultOutput({
|
|
947
|
+
output: part.output,
|
|
948
|
+
id: itemId,
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
if (webSearchCall != null) {
|
|
952
|
+
input.push(webSearchCall);
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
868
957
|
if (part.toolName === toolSearchToolName) {
|
|
869
958
|
const itemId = (part.providerOptions?.[providerOptionsName]
|
|
870
959
|
?.itemId ??
|
|
@@ -86,6 +86,7 @@ export type OpenAIResponsesInputItem =
|
|
|
86
86
|
| OpenAIResponsesApplyPatchCallOutput
|
|
87
87
|
| OpenAIResponsesToolSearchCall
|
|
88
88
|
| OpenAIResponsesToolSearchOutput
|
|
89
|
+
| OpenAIResponsesWebSearchCall
|
|
89
90
|
| OpenAIResponsesReasoning
|
|
90
91
|
| OpenAIResponsesItemReference
|
|
91
92
|
| OpenAIResponsesConfigurationUpdate;
|
|
@@ -228,6 +229,13 @@ export type OpenAIResponsesFunctionCallOutput = {
|
|
|
228
229
|
>;
|
|
229
230
|
};
|
|
230
231
|
|
|
232
|
+
export type OpenAIResponsesWebSearchCall = {
|
|
233
|
+
type: 'web_search_call';
|
|
234
|
+
id: string;
|
|
235
|
+
status: 'completed';
|
|
236
|
+
action: OpenAIResponsesWebSearchAction;
|
|
237
|
+
};
|
|
238
|
+
|
|
231
239
|
export type OpenAIResponsesCustomToolCall = {
|
|
232
240
|
type: 'custom_tool_call';
|
|
233
241
|
id?: string;
|
|
@@ -612,7 +620,7 @@ const openaiResponsesNestedErrorChunkSchema = z.object({
|
|
|
612
620
|
sequence_number: z.number(),
|
|
613
621
|
error: z.object({
|
|
614
622
|
type: z.string(),
|
|
615
|
-
code: z.string(),
|
|
623
|
+
code: z.string().nullish(),
|
|
616
624
|
message: z.string(),
|
|
617
625
|
param: z.string().nullish(),
|
|
618
626
|
}),
|