@ai-sdk/openai 4.0.14 → 4.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 +6 -0
- package/dist/index.d.ts +285 -24
- package/dist/index.js +1496 -1152
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +184 -8
- package/dist/internal/index.js +1438 -1104
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +89 -0
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/openai-tools.ts +11 -0
- package/src/responses/convert-to-openai-responses-input.ts +83 -1
- package/src/responses/openai-responses-api.ts +96 -19
- package/src/responses/openai-responses-language-model.ts +162 -31
- package/src/responses/openai-responses-prepare-tools.ts +9 -1
- package/src/tool/computer.ts +147 -0
|
@@ -62,6 +62,7 @@ export async function prepareResponsesTools({
|
|
|
62
62
|
| { type: 'mcp' }
|
|
63
63
|
| { type: 'image_generation' }
|
|
64
64
|
| { type: 'apply_patch' }
|
|
65
|
+
| { type: 'computer' }
|
|
65
66
|
| {
|
|
66
67
|
type: 'allowed_tools';
|
|
67
68
|
mode: 'auto' | 'required';
|
|
@@ -171,6 +172,12 @@ export async function prepareResponsesTools({
|
|
|
171
172
|
});
|
|
172
173
|
break;
|
|
173
174
|
}
|
|
175
|
+
case 'openai.computer': {
|
|
176
|
+
openaiTools.push({
|
|
177
|
+
type: 'computer',
|
|
178
|
+
});
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
174
181
|
case 'openai.web_search_preview': {
|
|
175
182
|
const args = await validateTypes({
|
|
176
183
|
value: tool.args,
|
|
@@ -374,7 +381,8 @@ export async function prepareResponsesTools({
|
|
|
374
381
|
resolvedToolName === 'web_search_preview' ||
|
|
375
382
|
resolvedToolName === 'web_search' ||
|
|
376
383
|
resolvedToolName === 'mcp' ||
|
|
377
|
-
resolvedToolName === 'apply_patch'
|
|
384
|
+
resolvedToolName === 'apply_patch' ||
|
|
385
|
+
resolvedToolName === 'computer'
|
|
378
386
|
? { type: resolvedToolName }
|
|
379
387
|
: resolvedCustomProviderToolNames.has(resolvedToolName)
|
|
380
388
|
? { type: 'custom', name: resolvedToolName }
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
const safetyCheckSchema = z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
code: z.string().optional(),
|
|
11
|
+
message: z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const computerActionSchema = z.discriminatedUnion('type', [
|
|
15
|
+
z.object({
|
|
16
|
+
type: z.literal('click'),
|
|
17
|
+
button: z.enum(['left', 'right', 'wheel', 'back', 'forward']),
|
|
18
|
+
x: z.number(),
|
|
19
|
+
y: z.number(),
|
|
20
|
+
keys: z.array(z.string()).optional(),
|
|
21
|
+
}),
|
|
22
|
+
z.object({
|
|
23
|
+
type: z.literal('double_click'),
|
|
24
|
+
x: z.number(),
|
|
25
|
+
y: z.number(),
|
|
26
|
+
keys: z.array(z.string()).optional(),
|
|
27
|
+
}),
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.literal('drag'),
|
|
30
|
+
path: z.array(z.object({ x: z.number(), y: z.number() })),
|
|
31
|
+
keys: z.array(z.string()).optional(),
|
|
32
|
+
}),
|
|
33
|
+
z.object({
|
|
34
|
+
type: z.literal('keypress'),
|
|
35
|
+
keys: z.array(z.string()),
|
|
36
|
+
}),
|
|
37
|
+
z.object({
|
|
38
|
+
type: z.literal('move'),
|
|
39
|
+
x: z.number(),
|
|
40
|
+
y: z.number(),
|
|
41
|
+
keys: z.array(z.string()).optional(),
|
|
42
|
+
}),
|
|
43
|
+
z.object({
|
|
44
|
+
type: z.literal('screenshot'),
|
|
45
|
+
}),
|
|
46
|
+
z.object({
|
|
47
|
+
type: z.literal('scroll'),
|
|
48
|
+
x: z.number(),
|
|
49
|
+
y: z.number(),
|
|
50
|
+
scrollX: z.number(),
|
|
51
|
+
scrollY: z.number(),
|
|
52
|
+
keys: z.array(z.string()).optional(),
|
|
53
|
+
}),
|
|
54
|
+
z.object({
|
|
55
|
+
type: z.literal('type'),
|
|
56
|
+
text: z.string(),
|
|
57
|
+
}),
|
|
58
|
+
z.object({
|
|
59
|
+
type: z.literal('wait'),
|
|
60
|
+
}),
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
export const computerInputSchema = lazySchema(() =>
|
|
64
|
+
zodSchema(
|
|
65
|
+
z.object({
|
|
66
|
+
actions: z.array(computerActionSchema),
|
|
67
|
+
pendingSafetyChecks: z.array(safetyCheckSchema),
|
|
68
|
+
status: z.enum(['in_progress', 'completed', 'incomplete']),
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export const computerOutputSchema = lazySchema(() =>
|
|
74
|
+
zodSchema(
|
|
75
|
+
z.object({
|
|
76
|
+
output: z.union([
|
|
77
|
+
z.object({
|
|
78
|
+
type: z.literal('computer_screenshot'),
|
|
79
|
+
imageUrl: z.string(),
|
|
80
|
+
fileId: z.string().optional(),
|
|
81
|
+
detail: z.enum(['auto', 'low', 'high', 'original']).optional(),
|
|
82
|
+
}),
|
|
83
|
+
z.object({
|
|
84
|
+
type: z.literal('computer_screenshot'),
|
|
85
|
+
fileId: z.string(),
|
|
86
|
+
imageUrl: z.string().optional(),
|
|
87
|
+
detail: z.enum(['auto', 'low', 'high', 'original']).optional(),
|
|
88
|
+
}),
|
|
89
|
+
]),
|
|
90
|
+
acknowledgedSafetyChecks: z.array(safetyCheckSchema).optional(),
|
|
91
|
+
}),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export type OpenAIComputerAction = z.infer<typeof computerActionSchema>;
|
|
96
|
+
export type OpenAIComputerSafetyCheck = z.infer<typeof safetyCheckSchema>;
|
|
97
|
+
|
|
98
|
+
const computerToolFactory = createProviderDefinedToolFactoryWithOutputSchema<
|
|
99
|
+
{
|
|
100
|
+
/**
|
|
101
|
+
* Ordered UI actions to execute.
|
|
102
|
+
*/
|
|
103
|
+
actions: OpenAIComputerAction[];
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Safety checks that must be acknowledged before continuing.
|
|
107
|
+
*/
|
|
108
|
+
pendingSafetyChecks: OpenAIComputerSafetyCheck[];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Status of the computer call.
|
|
112
|
+
*/
|
|
113
|
+
status: 'in_progress' | 'completed' | 'incomplete';
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
/**
|
|
117
|
+
* The screenshot captured after executing all actions.
|
|
118
|
+
*/
|
|
119
|
+
output:
|
|
120
|
+
| {
|
|
121
|
+
type: 'computer_screenshot';
|
|
122
|
+
imageUrl: string;
|
|
123
|
+
fileId?: string;
|
|
124
|
+
detail?: 'auto' | 'low' | 'high' | 'original';
|
|
125
|
+
}
|
|
126
|
+
| {
|
|
127
|
+
type: 'computer_screenshot';
|
|
128
|
+
fileId: string;
|
|
129
|
+
imageUrl?: string;
|
|
130
|
+
detail?: 'auto' | 'low' | 'high' | 'original';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Safety checks that the application has reviewed and acknowledged.
|
|
135
|
+
*/
|
|
136
|
+
acknowledgedSafetyChecks?: OpenAIComputerSafetyCheck[];
|
|
137
|
+
},
|
|
138
|
+
{}
|
|
139
|
+
>({
|
|
140
|
+
id: 'openai.computer',
|
|
141
|
+
inputSchema: computerInputSchema,
|
|
142
|
+
outputSchema: computerOutputSchema,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export const computer = (
|
|
146
|
+
options: Parameters<typeof computerToolFactory>[0] = {},
|
|
147
|
+
) => computerToolFactory(options);
|