@ai-sdk/openai 3.0.61 → 3.0.62
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 +6 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +46 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -13
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +45 -12
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +45 -12
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/responses/openai-responses-language-model.ts +1 -0
- package/src/responses/openai-responses-options.ts +17 -0
- package/src/responses/openai-responses-prepare-tools.ts +26 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.62",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/provider
|
|
40
|
-
"@ai-sdk/provider": "
|
|
39
|
+
"@ai-sdk/provider": "3.0.10",
|
|
40
|
+
"@ai-sdk/provider-utils": "4.0.26"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
|
@@ -316,6 +316,23 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
|
316
316
|
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
317
317
|
*/
|
|
318
318
|
forceReasoning: z.boolean().optional(),
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Restrict the callable tools to a subset while keeping the full tools
|
|
322
|
+
* list intact, so prompt caching is preserved across requests with
|
|
323
|
+
* different allowlists.
|
|
324
|
+
*
|
|
325
|
+
* When set, this overrides the request-level `toolChoice` and emits
|
|
326
|
+
* `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
|
|
327
|
+
*
|
|
328
|
+
* @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
|
|
329
|
+
*/
|
|
330
|
+
allowedTools: z
|
|
331
|
+
.object({
|
|
332
|
+
toolNames: z.array(z.string()).min(1),
|
|
333
|
+
mode: z.enum(['auto', 'required']).optional(),
|
|
334
|
+
})
|
|
335
|
+
.optional(),
|
|
319
336
|
}),
|
|
320
337
|
),
|
|
321
338
|
);
|
|
@@ -18,11 +18,16 @@ import type { OpenAIResponsesTool } from './openai-responses-api';
|
|
|
18
18
|
export async function prepareResponsesTools({
|
|
19
19
|
tools,
|
|
20
20
|
toolChoice,
|
|
21
|
+
allowedTools,
|
|
21
22
|
toolNameMapping,
|
|
22
23
|
customProviderToolNames,
|
|
23
24
|
}: {
|
|
24
25
|
tools: LanguageModelV3CallOptions['tools'];
|
|
25
26
|
toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
|
|
27
|
+
allowedTools?: {
|
|
28
|
+
toolNames: string[];
|
|
29
|
+
mode?: 'auto' | 'required';
|
|
30
|
+
};
|
|
26
31
|
toolNameMapping?: ToolNameMapping;
|
|
27
32
|
customProviderToolNames?: Set<string>;
|
|
28
33
|
}): Promise<{
|
|
@@ -39,7 +44,12 @@ export async function prepareResponsesTools({
|
|
|
39
44
|
| { type: 'code_interpreter' }
|
|
40
45
|
| { type: 'mcp' }
|
|
41
46
|
| { type: 'image_generation' }
|
|
42
|
-
| { type: 'apply_patch' }
|
|
47
|
+
| { type: 'apply_patch' }
|
|
48
|
+
| {
|
|
49
|
+
type: 'allowed_tools';
|
|
50
|
+
mode: 'auto' | 'required';
|
|
51
|
+
tools: Array<{ type: 'function'; name: string }>;
|
|
52
|
+
};
|
|
43
53
|
toolWarnings: SharedV3Warning[];
|
|
44
54
|
}> {
|
|
45
55
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
@@ -285,6 +295,21 @@ export async function prepareResponsesTools({
|
|
|
285
295
|
}
|
|
286
296
|
}
|
|
287
297
|
|
|
298
|
+
if (allowedTools != null) {
|
|
299
|
+
return {
|
|
300
|
+
tools: openaiTools,
|
|
301
|
+
toolChoice: {
|
|
302
|
+
type: 'allowed_tools',
|
|
303
|
+
mode: allowedTools.mode ?? 'auto',
|
|
304
|
+
tools: allowedTools.toolNames.map(name => ({
|
|
305
|
+
type: 'function',
|
|
306
|
+
name: toolNameMapping?.toProviderToolName(name) ?? name,
|
|
307
|
+
})),
|
|
308
|
+
},
|
|
309
|
+
toolWarnings,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
288
313
|
if (toolChoice == null) {
|
|
289
314
|
return { tools: openaiTools, toolChoice: undefined, toolWarnings };
|
|
290
315
|
}
|