@ai-sdk/openai 0.0.0-2f1ae29d-20260122140908 → 0.0.0-4115c213-20260122152721
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 +17 -2
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +14 -0
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -0
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +9 -5
- package/src/responses/convert-to-openai-responses-input.ts +20 -1
- package/src/chat/__fixtures__/azure-model-router.1.chunks.txt +0 -8
- package/src/chat/__snapshots__/openai-chat-language-model.test.ts.snap +0 -88
- package/src/chat/convert-to-openai-chat-messages.test.ts +0 -516
- package/src/chat/openai-chat-language-model.test.ts +0 -3496
- package/src/chat/openai-chat-prepare-tools.test.ts +0 -322
- package/src/completion/openai-completion-language-model.test.ts +0 -752
- package/src/embedding/__snapshots__/openai-embedding-model.test.ts.snap +0 -43
- package/src/embedding/openai-embedding-model.test.ts +0 -146
- package/src/image/openai-image-model.test.ts +0 -722
- package/src/openai-error.test.ts +0 -34
- package/src/openai-language-model-capabilities.test.ts +0 -93
- package/src/openai-provider.test.ts +0 -98
- package/src/responses/__fixtures__/openai-apply-patch-tool-delete.1.chunks.txt +0 -5
- package/src/responses/__fixtures__/openai-apply-patch-tool.1.chunks.txt +0 -38
- package/src/responses/__fixtures__/openai-apply-patch-tool.1.json +0 -69
- package/src/responses/__fixtures__/openai-code-interpreter-tool.1.chunks.txt +0 -393
- package/src/responses/__fixtures__/openai-code-interpreter-tool.1.json +0 -137
- package/src/responses/__fixtures__/openai-error.1.chunks.txt +0 -4
- package/src/responses/__fixtures__/openai-error.1.json +0 -8
- package/src/responses/__fixtures__/openai-file-search-tool.1.chunks.txt +0 -94
- package/src/responses/__fixtures__/openai-file-search-tool.1.json +0 -89
- package/src/responses/__fixtures__/openai-file-search-tool.2.chunks.txt +0 -93
- package/src/responses/__fixtures__/openai-file-search-tool.2.json +0 -112
- package/src/responses/__fixtures__/openai-image-generation-tool.1.chunks.txt +0 -16
- package/src/responses/__fixtures__/openai-image-generation-tool.1.json +0 -96
- package/src/responses/__fixtures__/openai-local-shell-tool.1.chunks.txt +0 -7
- package/src/responses/__fixtures__/openai-local-shell-tool.1.json +0 -70
- package/src/responses/__fixtures__/openai-mcp-tool-approval.1.chunks.txt +0 -11
- package/src/responses/__fixtures__/openai-mcp-tool-approval.1.json +0 -169
- package/src/responses/__fixtures__/openai-mcp-tool-approval.2.chunks.txt +0 -123
- package/src/responses/__fixtures__/openai-mcp-tool-approval.2.json +0 -176
- package/src/responses/__fixtures__/openai-mcp-tool-approval.3.chunks.txt +0 -11
- package/src/responses/__fixtures__/openai-mcp-tool-approval.3.json +0 -169
- package/src/responses/__fixtures__/openai-mcp-tool-approval.4.chunks.txt +0 -84
- package/src/responses/__fixtures__/openai-mcp-tool-approval.4.json +0 -182
- package/src/responses/__fixtures__/openai-mcp-tool.1.chunks.txt +0 -373
- package/src/responses/__fixtures__/openai-mcp-tool.1.json +0 -159
- package/src/responses/__fixtures__/openai-reasoning-encrypted-content.1.chunks.txt +0 -110
- package/src/responses/__fixtures__/openai-reasoning-encrypted-content.1.json +0 -117
- package/src/responses/__fixtures__/openai-shell-tool.1.chunks.txt +0 -182
- package/src/responses/__fixtures__/openai-shell-tool.1.json +0 -73
- package/src/responses/__fixtures__/openai-web-search-tool.1.chunks.txt +0 -185
- package/src/responses/__fixtures__/openai-web-search-tool.1.json +0 -266
- package/src/responses/__snapshots__/openai-responses-language-model.test.ts.snap +0 -10955
- package/src/responses/convert-to-openai-responses-input.test.ts +0 -2976
- package/src/responses/openai-responses-api.test.ts +0 -89
- package/src/responses/openai-responses-language-model.test.ts +0 -6927
- package/src/responses/openai-responses-prepare-tools.test.ts +0 -924
- package/src/speech/openai-speech-model.test.ts +0 -202
- package/src/tool/local-shell.test-d.ts +0 -20
- package/src/tool/web-search.test-d.ts +0 -13
- package/src/transcription/openai-transcription-model.test.ts +0 -507
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { prepareChatTools } from './openai-chat-prepare-tools';
|
|
3
|
-
|
|
4
|
-
describe('prepareChatTools', () => {
|
|
5
|
-
it('should return undefined tools and toolChoice when tools are null', () => {
|
|
6
|
-
const result = prepareChatTools({
|
|
7
|
-
tools: undefined,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
expect(result).toEqual({
|
|
11
|
-
tools: undefined,
|
|
12
|
-
toolChoice: undefined,
|
|
13
|
-
toolWarnings: [],
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should return undefined tools and toolChoice when tools are empty', () => {
|
|
18
|
-
const result = prepareChatTools({
|
|
19
|
-
tools: [],
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
expect(result).toEqual({
|
|
23
|
-
tools: undefined,
|
|
24
|
-
toolChoice: undefined,
|
|
25
|
-
toolWarnings: [],
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should correctly prepare function tools', () => {
|
|
30
|
-
const result = prepareChatTools({
|
|
31
|
-
tools: [
|
|
32
|
-
{
|
|
33
|
-
type: 'function',
|
|
34
|
-
name: 'testFunction',
|
|
35
|
-
description: 'A test function',
|
|
36
|
-
inputSchema: { type: 'object', properties: {} },
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(result).toMatchInlineSnapshot(`
|
|
42
|
-
{
|
|
43
|
-
"toolChoice": undefined,
|
|
44
|
-
"toolWarnings": [],
|
|
45
|
-
"tools": [
|
|
46
|
-
{
|
|
47
|
-
"function": {
|
|
48
|
-
"description": "A test function",
|
|
49
|
-
"name": "testFunction",
|
|
50
|
-
"parameters": {
|
|
51
|
-
"properties": {},
|
|
52
|
-
"type": "object",
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
"type": "function",
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
}
|
|
59
|
-
`);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should add warnings for unsupported tools', () => {
|
|
63
|
-
const result = prepareChatTools({
|
|
64
|
-
tools: [
|
|
65
|
-
{
|
|
66
|
-
type: 'provider',
|
|
67
|
-
id: 'openai.unsupported_tool',
|
|
68
|
-
name: 'unsupported_tool',
|
|
69
|
-
args: {},
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expect(result.tools).toEqual([]);
|
|
75
|
-
expect(result.toolChoice).toBeUndefined();
|
|
76
|
-
expect(result.toolWarnings).toMatchInlineSnapshot(`
|
|
77
|
-
[
|
|
78
|
-
{
|
|
79
|
-
"feature": "tool type: provider",
|
|
80
|
-
"type": "unsupported",
|
|
81
|
-
},
|
|
82
|
-
]
|
|
83
|
-
`);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should handle tool choice "auto"', () => {
|
|
87
|
-
const result = prepareChatTools({
|
|
88
|
-
tools: [
|
|
89
|
-
{
|
|
90
|
-
type: 'function',
|
|
91
|
-
name: 'testFunction',
|
|
92
|
-
description: 'Test',
|
|
93
|
-
inputSchema: {},
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
toolChoice: { type: 'auto' },
|
|
97
|
-
});
|
|
98
|
-
expect(result.toolChoice).toEqual('auto');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should handle tool choice "required"', () => {
|
|
102
|
-
const result = prepareChatTools({
|
|
103
|
-
tools: [
|
|
104
|
-
{
|
|
105
|
-
type: 'function',
|
|
106
|
-
name: 'testFunction',
|
|
107
|
-
description: 'Test',
|
|
108
|
-
inputSchema: {},
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
toolChoice: { type: 'required' },
|
|
112
|
-
});
|
|
113
|
-
expect(result.toolChoice).toEqual('required');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should handle tool choice "none"', () => {
|
|
117
|
-
const result = prepareChatTools({
|
|
118
|
-
tools: [
|
|
119
|
-
{
|
|
120
|
-
type: 'function',
|
|
121
|
-
name: 'testFunction',
|
|
122
|
-
description: 'Test',
|
|
123
|
-
inputSchema: {},
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
toolChoice: { type: 'none' },
|
|
127
|
-
});
|
|
128
|
-
expect(result.toolChoice).toEqual('none');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should handle tool choice "tool"', () => {
|
|
132
|
-
const result = prepareChatTools({
|
|
133
|
-
tools: [
|
|
134
|
-
{
|
|
135
|
-
type: 'function',
|
|
136
|
-
name: 'testFunction',
|
|
137
|
-
description: 'Test',
|
|
138
|
-
inputSchema: {},
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
toolChoice: { type: 'tool', toolName: 'testFunction' },
|
|
142
|
-
});
|
|
143
|
-
expect(result.toolChoice).toEqual({
|
|
144
|
-
type: 'function',
|
|
145
|
-
function: { name: 'testFunction' },
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should pass through strict mode when strict is true', () => {
|
|
150
|
-
const result = prepareChatTools({
|
|
151
|
-
tools: [
|
|
152
|
-
{
|
|
153
|
-
type: 'function',
|
|
154
|
-
name: 'testFunction',
|
|
155
|
-
description: 'A test function',
|
|
156
|
-
inputSchema: { type: 'object', properties: {} },
|
|
157
|
-
strict: true,
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
expect(result).toMatchInlineSnapshot(`
|
|
163
|
-
{
|
|
164
|
-
"toolChoice": undefined,
|
|
165
|
-
"toolWarnings": [],
|
|
166
|
-
"tools": [
|
|
167
|
-
{
|
|
168
|
-
"function": {
|
|
169
|
-
"description": "A test function",
|
|
170
|
-
"name": "testFunction",
|
|
171
|
-
"parameters": {
|
|
172
|
-
"properties": {},
|
|
173
|
-
"type": "object",
|
|
174
|
-
},
|
|
175
|
-
"strict": true,
|
|
176
|
-
},
|
|
177
|
-
"type": "function",
|
|
178
|
-
},
|
|
179
|
-
],
|
|
180
|
-
}
|
|
181
|
-
`);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should pass through strict mode when strict is false', () => {
|
|
185
|
-
const result = prepareChatTools({
|
|
186
|
-
tools: [
|
|
187
|
-
{
|
|
188
|
-
type: 'function',
|
|
189
|
-
name: 'testFunction',
|
|
190
|
-
description: 'A test function',
|
|
191
|
-
inputSchema: { type: 'object', properties: {} },
|
|
192
|
-
strict: false,
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
expect(result).toMatchInlineSnapshot(`
|
|
198
|
-
{
|
|
199
|
-
"toolChoice": undefined,
|
|
200
|
-
"toolWarnings": [],
|
|
201
|
-
"tools": [
|
|
202
|
-
{
|
|
203
|
-
"function": {
|
|
204
|
-
"description": "A test function",
|
|
205
|
-
"name": "testFunction",
|
|
206
|
-
"parameters": {
|
|
207
|
-
"properties": {},
|
|
208
|
-
"type": "object",
|
|
209
|
-
},
|
|
210
|
-
"strict": false,
|
|
211
|
-
},
|
|
212
|
-
"type": "function",
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
}
|
|
216
|
-
`);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should not include strict mode when strict is undefined', () => {
|
|
220
|
-
const result = prepareChatTools({
|
|
221
|
-
tools: [
|
|
222
|
-
{
|
|
223
|
-
type: 'function',
|
|
224
|
-
name: 'testFunction',
|
|
225
|
-
description: 'A test function',
|
|
226
|
-
inputSchema: { type: 'object', properties: {} },
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
expect(result).toMatchInlineSnapshot(`
|
|
232
|
-
{
|
|
233
|
-
"toolChoice": undefined,
|
|
234
|
-
"toolWarnings": [],
|
|
235
|
-
"tools": [
|
|
236
|
-
{
|
|
237
|
-
"function": {
|
|
238
|
-
"description": "A test function",
|
|
239
|
-
"name": "testFunction",
|
|
240
|
-
"parameters": {
|
|
241
|
-
"properties": {},
|
|
242
|
-
"type": "object",
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
"type": "function",
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
}
|
|
249
|
-
`);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should pass through strict mode for multiple tools with different strict settings', () => {
|
|
253
|
-
const result = prepareChatTools({
|
|
254
|
-
tools: [
|
|
255
|
-
{
|
|
256
|
-
type: 'function',
|
|
257
|
-
name: 'strictTool',
|
|
258
|
-
description: 'A strict tool',
|
|
259
|
-
inputSchema: { type: 'object', properties: {} },
|
|
260
|
-
strict: true,
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
type: 'function',
|
|
264
|
-
name: 'nonStrictTool',
|
|
265
|
-
description: 'A non-strict tool',
|
|
266
|
-
inputSchema: { type: 'object', properties: {} },
|
|
267
|
-
strict: false,
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
type: 'function',
|
|
271
|
-
name: 'defaultTool',
|
|
272
|
-
description: 'A tool without strict setting',
|
|
273
|
-
inputSchema: { type: 'object', properties: {} },
|
|
274
|
-
},
|
|
275
|
-
],
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
expect(result).toMatchInlineSnapshot(`
|
|
279
|
-
{
|
|
280
|
-
"toolChoice": undefined,
|
|
281
|
-
"toolWarnings": [],
|
|
282
|
-
"tools": [
|
|
283
|
-
{
|
|
284
|
-
"function": {
|
|
285
|
-
"description": "A strict tool",
|
|
286
|
-
"name": "strictTool",
|
|
287
|
-
"parameters": {
|
|
288
|
-
"properties": {},
|
|
289
|
-
"type": "object",
|
|
290
|
-
},
|
|
291
|
-
"strict": true,
|
|
292
|
-
},
|
|
293
|
-
"type": "function",
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
"function": {
|
|
297
|
-
"description": "A non-strict tool",
|
|
298
|
-
"name": "nonStrictTool",
|
|
299
|
-
"parameters": {
|
|
300
|
-
"properties": {},
|
|
301
|
-
"type": "object",
|
|
302
|
-
},
|
|
303
|
-
"strict": false,
|
|
304
|
-
},
|
|
305
|
-
"type": "function",
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
"function": {
|
|
309
|
-
"description": "A tool without strict setting",
|
|
310
|
-
"name": "defaultTool",
|
|
311
|
-
"parameters": {
|
|
312
|
-
"properties": {},
|
|
313
|
-
"type": "object",
|
|
314
|
-
},
|
|
315
|
-
},
|
|
316
|
-
"type": "function",
|
|
317
|
-
},
|
|
318
|
-
],
|
|
319
|
-
}
|
|
320
|
-
`);
|
|
321
|
-
});
|
|
322
|
-
});
|