@ai-sdk/openai 4.0.18 → 4.0.20
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 +12 -0
- package/dist/index.d.ts +60 -3
- package/dist/index.js +1111 -885
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +67 -2
- package/dist/internal/index.js +1247 -1022
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +62 -0
- package/package.json +1 -1
- package/src/image/openai-image-model-options.ts +8 -7
- package/src/image/openai-image-model.ts +2 -2
- package/src/index.ts +1 -0
- package/src/internal/index.ts +1 -0
- package/src/openai-language-model-capabilities.ts +47 -22
- package/src/openai-tools.ts +7 -0
- package/src/responses/convert-to-openai-responses-input.ts +86 -0
- package/src/responses/openai-responses-api.ts +63 -1
- package/src/responses/openai-responses-language-model.ts +103 -0
- package/src/responses/openai-responses-prepare-tools.ts +20 -2
- package/src/tool/programmatic-tool-calling.ts +57 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type JSONSchema7,
|
|
4
|
+
type JSONObject,
|
|
3
5
|
type LanguageModelV4CallOptions,
|
|
4
6
|
type LanguageModelV4FunctionTool,
|
|
5
7
|
type SharedV4ProviderReference,
|
|
@@ -24,8 +26,10 @@ import type {
|
|
|
24
26
|
OpenAIResponsesTool,
|
|
25
27
|
} from './openai-responses-api';
|
|
26
28
|
|
|
27
|
-
type OpenAIToolOptions = {
|
|
29
|
+
export type OpenAIToolOptions = {
|
|
30
|
+
allowedCallers?: Array<'direct' | 'programmatic'>;
|
|
28
31
|
deferLoading?: boolean;
|
|
32
|
+
outputSchema?: JSONObject;
|
|
29
33
|
namespace?: {
|
|
30
34
|
name: string;
|
|
31
35
|
description: string;
|
|
@@ -63,6 +67,7 @@ export async function prepareResponsesTools({
|
|
|
63
67
|
| { type: 'image_generation' }
|
|
64
68
|
| { type: 'apply_patch' }
|
|
65
69
|
| { type: 'computer' }
|
|
70
|
+
| { type: 'programmatic_tool_calling' }
|
|
66
71
|
| {
|
|
67
72
|
type: 'allowed_tools';
|
|
68
73
|
mode: 'auto' | 'required';
|
|
@@ -312,6 +317,12 @@ export async function prepareResponsesTools({
|
|
|
312
317
|
resolvedCustomProviderToolNames.add(tool.name);
|
|
313
318
|
break;
|
|
314
319
|
}
|
|
320
|
+
case 'openai.programmatic_tool_calling': {
|
|
321
|
+
openaiTools.push({
|
|
322
|
+
type: 'programmatic_tool_calling',
|
|
323
|
+
});
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
315
326
|
case 'openai.tool_search': {
|
|
316
327
|
const args = await validateTypes({
|
|
317
328
|
value: tool.args,
|
|
@@ -382,7 +393,8 @@ export async function prepareResponsesTools({
|
|
|
382
393
|
resolvedToolName === 'web_search' ||
|
|
383
394
|
resolvedToolName === 'mcp' ||
|
|
384
395
|
resolvedToolName === 'apply_patch' ||
|
|
385
|
-
resolvedToolName === 'computer'
|
|
396
|
+
resolvedToolName === 'computer' ||
|
|
397
|
+
resolvedToolName === 'programmatic_tool_calling'
|
|
386
398
|
? { type: resolvedToolName }
|
|
387
399
|
: resolvedCustomProviderToolNames.has(resolvedToolName)
|
|
388
400
|
? { type: 'custom', name: resolvedToolName }
|
|
@@ -415,6 +427,12 @@ function prepareFunctionTool({
|
|
|
415
427
|
parameters: tool.inputSchema,
|
|
416
428
|
...(tool.strict != null ? { strict: tool.strict } : {}),
|
|
417
429
|
...(deferLoading != null ? { defer_loading: deferLoading } : {}),
|
|
430
|
+
...(options?.allowedCallers != null
|
|
431
|
+
? { allowed_callers: options.allowedCallers }
|
|
432
|
+
: {}),
|
|
433
|
+
...(options?.outputSchema != null
|
|
434
|
+
? { output_schema: options.outputSchema as JSONSchema7 }
|
|
435
|
+
: {}),
|
|
418
436
|
};
|
|
419
437
|
}
|
|
420
438
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const programmaticToolCallingInputSchema = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
code: z.string(),
|
|
12
|
+
fingerprint: z.string(),
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const programmaticToolCallingOutputSchema = lazySchema(() =>
|
|
18
|
+
zodSchema(
|
|
19
|
+
z.object({
|
|
20
|
+
result: z.string(),
|
|
21
|
+
status: z.enum(['completed', 'incomplete']),
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const programmaticToolCallingFactory = createProviderExecutedToolFactory<
|
|
27
|
+
{
|
|
28
|
+
/**
|
|
29
|
+
* JavaScript source generated and executed by OpenAI.
|
|
30
|
+
*/
|
|
31
|
+
code: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Opaque replay fingerprint that must be preserved across requests.
|
|
35
|
+
*/
|
|
36
|
+
fingerprint: string;
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
/**
|
|
40
|
+
* The result emitted by the hosted JavaScript program.
|
|
41
|
+
*/
|
|
42
|
+
result: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether the program completed or stopped before producing a final result.
|
|
46
|
+
*/
|
|
47
|
+
status: 'completed' | 'incomplete';
|
|
48
|
+
},
|
|
49
|
+
{}
|
|
50
|
+
>({
|
|
51
|
+
id: 'openai.programmatic_tool_calling',
|
|
52
|
+
inputSchema: programmaticToolCallingInputSchema,
|
|
53
|
+
outputSchema: programmaticToolCallingOutputSchema,
|
|
54
|
+
supportsDeferredResults: true,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const programmaticToolCalling = () => programmaticToolCallingFactory({});
|