@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,202 +0,0 @@
|
|
|
1
|
-
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
|
|
2
|
-
import { createOpenAI } from '../openai-provider';
|
|
3
|
-
import { OpenAISpeechModel } from './openai-speech-model';
|
|
4
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
vi.mock('../version', () => ({
|
|
7
|
-
VERSION: '0.0.0-test',
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
const provider = createOpenAI({ apiKey: 'test-api-key' });
|
|
11
|
-
const model = provider.speech('tts-1');
|
|
12
|
-
|
|
13
|
-
const server = createTestServer({
|
|
14
|
-
'https://api.openai.com/v1/audio/speech': {},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('doGenerate', () => {
|
|
18
|
-
function prepareAudioResponse({
|
|
19
|
-
headers,
|
|
20
|
-
format = 'mp3',
|
|
21
|
-
}: {
|
|
22
|
-
headers?: Record<string, string>;
|
|
23
|
-
format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
|
|
24
|
-
} = {}) {
|
|
25
|
-
const audioBuffer = new Uint8Array(100); // Mock audio data
|
|
26
|
-
server.urls['https://api.openai.com/v1/audio/speech'].response = {
|
|
27
|
-
type: 'binary',
|
|
28
|
-
headers: {
|
|
29
|
-
'content-type': `audio/${format}`,
|
|
30
|
-
...headers,
|
|
31
|
-
},
|
|
32
|
-
body: Buffer.from(audioBuffer),
|
|
33
|
-
};
|
|
34
|
-
return audioBuffer;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
it('should pass the model and text', async () => {
|
|
38
|
-
prepareAudioResponse();
|
|
39
|
-
|
|
40
|
-
await model.doGenerate({
|
|
41
|
-
text: 'Hello from the AI SDK!',
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(await server.calls[0].requestBodyJson).toMatchObject({
|
|
45
|
-
model: 'tts-1',
|
|
46
|
-
input: 'Hello from the AI SDK!',
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should pass headers', async () => {
|
|
51
|
-
prepareAudioResponse();
|
|
52
|
-
|
|
53
|
-
const provider = createOpenAI({
|
|
54
|
-
apiKey: 'test-api-key',
|
|
55
|
-
organization: 'test-organization',
|
|
56
|
-
project: 'test-project',
|
|
57
|
-
headers: {
|
|
58
|
-
'Custom-Provider-Header': 'provider-header-value',
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
await provider.speech('tts-1').doGenerate({
|
|
63
|
-
text: 'Hello from the AI SDK!',
|
|
64
|
-
headers: {
|
|
65
|
-
'Custom-Request-Header': 'request-header-value',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(server.calls[0].requestHeaders).toMatchObject({
|
|
70
|
-
authorization: 'Bearer test-api-key',
|
|
71
|
-
'content-type': 'application/json',
|
|
72
|
-
'custom-provider-header': 'provider-header-value',
|
|
73
|
-
'custom-request-header': 'request-header-value',
|
|
74
|
-
'openai-organization': 'test-organization',
|
|
75
|
-
'openai-project': 'test-project',
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(server.calls[0].requestUserAgent).toContain(
|
|
79
|
-
`ai-sdk/openai/0.0.0-test`,
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should pass options', async () => {
|
|
84
|
-
prepareAudioResponse();
|
|
85
|
-
|
|
86
|
-
await model.doGenerate({
|
|
87
|
-
text: 'Hello from the AI SDK!',
|
|
88
|
-
voice: 'nova',
|
|
89
|
-
outputFormat: 'opus',
|
|
90
|
-
speed: 1.5,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(await server.calls[0].requestBodyJson).toMatchObject({
|
|
94
|
-
model: 'tts-1',
|
|
95
|
-
input: 'Hello from the AI SDK!',
|
|
96
|
-
voice: 'nova',
|
|
97
|
-
speed: 1.5,
|
|
98
|
-
response_format: 'opus',
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should return audio data with correct content type', async () => {
|
|
103
|
-
const audio = new Uint8Array(100); // Mock audio data
|
|
104
|
-
prepareAudioResponse({
|
|
105
|
-
format: 'opus',
|
|
106
|
-
headers: {
|
|
107
|
-
'x-request-id': 'test-request-id',
|
|
108
|
-
'x-ratelimit-remaining': '123',
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const result = await model.doGenerate({
|
|
113
|
-
text: 'Hello from the AI SDK!',
|
|
114
|
-
outputFormat: 'opus',
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
expect(result.audio).toStrictEqual(audio);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should include response data with timestamp, modelId and headers', async () => {
|
|
121
|
-
prepareAudioResponse({
|
|
122
|
-
headers: {
|
|
123
|
-
'x-request-id': 'test-request-id',
|
|
124
|
-
'x-ratelimit-remaining': '123',
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const testDate = new Date(0);
|
|
129
|
-
const customModel = new OpenAISpeechModel('tts-1', {
|
|
130
|
-
provider: 'test-provider',
|
|
131
|
-
url: () => 'https://api.openai.com/v1/audio/speech',
|
|
132
|
-
headers: () => ({}),
|
|
133
|
-
_internal: {
|
|
134
|
-
currentDate: () => testDate,
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const result = await customModel.doGenerate({
|
|
139
|
-
text: 'Hello from the AI SDK!',
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(result.response).toMatchObject({
|
|
143
|
-
timestamp: testDate,
|
|
144
|
-
modelId: 'tts-1',
|
|
145
|
-
headers: {
|
|
146
|
-
'content-type': 'audio/mp3',
|
|
147
|
-
'x-request-id': 'test-request-id',
|
|
148
|
-
'x-ratelimit-remaining': '123',
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should use real date when no custom date provider is specified', async () => {
|
|
154
|
-
prepareAudioResponse();
|
|
155
|
-
|
|
156
|
-
const testDate = new Date(0);
|
|
157
|
-
const customModel = new OpenAISpeechModel('tts-1', {
|
|
158
|
-
provider: 'test-provider',
|
|
159
|
-
url: () => 'https://api.openai.com/v1/audio/speech',
|
|
160
|
-
headers: () => ({}),
|
|
161
|
-
_internal: {
|
|
162
|
-
currentDate: () => testDate,
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const result = await customModel.doGenerate({
|
|
167
|
-
text: 'Hello from the AI SDK!',
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
expect(result.response.timestamp.getTime()).toEqual(testDate.getTime());
|
|
171
|
-
expect(result.response.modelId).toBe('tts-1');
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should handle different audio formats', async () => {
|
|
175
|
-
const formats = ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] as const;
|
|
176
|
-
|
|
177
|
-
for (const format of formats) {
|
|
178
|
-
const audio = prepareAudioResponse({ format });
|
|
179
|
-
|
|
180
|
-
const result = await model.doGenerate({
|
|
181
|
-
text: 'Hello from the AI SDK!',
|
|
182
|
-
providerOptions: {
|
|
183
|
-
openai: {
|
|
184
|
-
response_format: format,
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
expect(result.audio).toStrictEqual(audio);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should include warnings if any are generated', async () => {
|
|
194
|
-
prepareAudioResponse();
|
|
195
|
-
|
|
196
|
-
const result = await model.doGenerate({
|
|
197
|
-
text: 'Hello from the AI SDK!',
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
expect(result.warnings).toEqual([]);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { InferSchema, Tool } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { describe, expectTypeOf, it } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
localShell,
|
|
5
|
-
localShellInputSchema,
|
|
6
|
-
localShellOutputSchema,
|
|
7
|
-
} from './local-shell';
|
|
8
|
-
|
|
9
|
-
describe('local-shell tool type', () => {
|
|
10
|
-
it('should have Tool type', () => {
|
|
11
|
-
const localShellTool = localShell({});
|
|
12
|
-
|
|
13
|
-
expectTypeOf(localShellTool).toEqualTypeOf<
|
|
14
|
-
Tool<
|
|
15
|
-
InferSchema<typeof localShellInputSchema>,
|
|
16
|
-
InferSchema<typeof localShellOutputSchema>
|
|
17
|
-
>
|
|
18
|
-
>();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { InferSchema, Tool } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { describe, expectTypeOf, it } from 'vitest';
|
|
3
|
-
import { webSearch, webSearchOutputSchema } from './web-search';
|
|
4
|
-
|
|
5
|
-
describe('web-search tool type', () => {
|
|
6
|
-
it('should have Tool type', () => {
|
|
7
|
-
const webSearchTool = webSearch();
|
|
8
|
-
|
|
9
|
-
expectTypeOf(webSearchTool).toEqualTypeOf<
|
|
10
|
-
Tool<{}, InferSchema<typeof webSearchOutputSchema>>
|
|
11
|
-
>();
|
|
12
|
-
});
|
|
13
|
-
});
|