@ai-sdk/openai 4.0.0-beta.22 → 4.0.0-beta.25
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 +25 -0
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +112 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +20 -14
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +24 -15
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/openai-provider.ts +16 -1
- package/src/responses/openai-responses-prepare-tools.ts +13 -5
- package/src/skills/openai-skills-api.ts +31 -0
- package/src/skills/openai-skills.ts +87 -0
- package/src/tool/shell.ts +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.25",
|
|
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": "4.0.0-beta.
|
|
40
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
39
|
+
"@ai-sdk/provider": "4.0.0-beta.8",
|
|
40
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.14"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
package/src/openai-provider.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
LanguageModelV4,
|
|
6
6
|
ProviderV4,
|
|
7
7
|
SpeechModelV4,
|
|
8
|
+
SkillsV4,
|
|
8
9
|
TranscriptionModelV4,
|
|
9
10
|
} from '@ai-sdk/provider';
|
|
10
11
|
import {
|
|
@@ -30,6 +31,7 @@ import { OpenAISpeechModel } from './speech/openai-speech-model';
|
|
|
30
31
|
import { OpenAISpeechModelId } from './speech/openai-speech-options';
|
|
31
32
|
import { OpenAITranscriptionModel } from './transcription/openai-transcription-model';
|
|
32
33
|
import { OpenAITranscriptionModelId } from './transcription/openai-transcription-options';
|
|
34
|
+
import { OpenAISkills } from './skills/openai-skills';
|
|
33
35
|
import { VERSION } from './version';
|
|
34
36
|
|
|
35
37
|
export interface OpenAIProvider extends ProviderV4 {
|
|
@@ -100,6 +102,11 @@ export interface OpenAIProvider extends ProviderV4 {
|
|
|
100
102
|
*/
|
|
101
103
|
files(): FilesV4;
|
|
102
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Returns a SkillsV4 interface for uploading skills to OpenAI.
|
|
107
|
+
*/
|
|
108
|
+
skills(): SkillsV4;
|
|
109
|
+
|
|
103
110
|
/**
|
|
104
111
|
* OpenAI-specific tools.
|
|
105
112
|
*/
|
|
@@ -231,6 +238,14 @@ export function createOpenAI(
|
|
|
231
238
|
fetch: options.fetch,
|
|
232
239
|
});
|
|
233
240
|
|
|
241
|
+
const createSkills = () =>
|
|
242
|
+
new OpenAISkills({
|
|
243
|
+
provider: `${providerName}.skills`,
|
|
244
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
245
|
+
headers: getHeaders,
|
|
246
|
+
fetch: options.fetch,
|
|
247
|
+
});
|
|
248
|
+
|
|
234
249
|
const createLanguageModel = (modelId: OpenAIResponsesModelId) => {
|
|
235
250
|
if (new.target) {
|
|
236
251
|
throw new Error(
|
|
@@ -274,8 +289,8 @@ export function createOpenAI(
|
|
|
274
289
|
|
|
275
290
|
provider.speech = createSpeechModel;
|
|
276
291
|
provider.speechModel = createSpeechModel;
|
|
277
|
-
|
|
278
292
|
provider.files = createFiles;
|
|
293
|
+
provider.skills = createSkills;
|
|
279
294
|
|
|
280
295
|
provider.tools = openaiTools;
|
|
281
296
|
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LanguageModelV4CallOptions,
|
|
3
|
+
SharedV4ProviderReference,
|
|
3
4
|
SharedV4Warning,
|
|
4
5
|
UnsupportedFunctionalityError,
|
|
5
6
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
resolveProviderReference,
|
|
9
|
+
ToolNameMapping,
|
|
10
|
+
validateTypes,
|
|
11
|
+
} from '@ai-sdk/provider-utils';
|
|
7
12
|
import { codeInterpreterArgsSchema } from '../tool/code-interpreter';
|
|
8
13
|
import { fileSearchArgsSchema } from '../tool/file-search';
|
|
9
14
|
import { imageGenerationArgsSchema } from '../tool/image-generation';
|
|
@@ -360,7 +365,7 @@ function mapShellEnvironment(environment: {
|
|
|
360
365
|
};
|
|
361
366
|
skills?: Array<{
|
|
362
367
|
type: string;
|
|
363
|
-
|
|
368
|
+
providerReference?: SharedV4ProviderReference;
|
|
364
369
|
version?: string;
|
|
365
370
|
name?: string;
|
|
366
371
|
description?: string;
|
|
@@ -404,7 +409,7 @@ function mapShellSkills(
|
|
|
404
409
|
skills:
|
|
405
410
|
| Array<{
|
|
406
411
|
type: string;
|
|
407
|
-
|
|
412
|
+
providerReference?: SharedV4ProviderReference;
|
|
408
413
|
version?: string;
|
|
409
414
|
name?: string;
|
|
410
415
|
description?: string;
|
|
@@ -416,8 +421,11 @@ function mapShellSkills(
|
|
|
416
421
|
skill.type === 'skillReference'
|
|
417
422
|
? {
|
|
418
423
|
type: 'skill_reference' as const,
|
|
419
|
-
skill_id:
|
|
420
|
-
|
|
424
|
+
skill_id: resolveProviderReference({
|
|
425
|
+
reference: skill.providerReference ?? {},
|
|
426
|
+
provider: 'openai',
|
|
427
|
+
}),
|
|
428
|
+
version: skill.version ?? 'latest',
|
|
421
429
|
}
|
|
422
430
|
: {
|
|
423
431
|
type: 'inline' as const,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
export const openaiSkillResponseSchema = lazySchema(() =>
|
|
5
|
+
zodSchema(
|
|
6
|
+
z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
name: z.string().nullish(),
|
|
9
|
+
description: z.string().nullish(),
|
|
10
|
+
default_version: z.string().nullish(),
|
|
11
|
+
latest_version: z.string().nullish(),
|
|
12
|
+
created_at: z.number(),
|
|
13
|
+
updated_at: z.number().nullish(),
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export type OpenAISkillResponse = ReturnType<
|
|
19
|
+
typeof openaiSkillResponseSchema
|
|
20
|
+
>['_type'];
|
|
21
|
+
|
|
22
|
+
export const openaiSkillVersionResponseSchema = lazySchema(() =>
|
|
23
|
+
zodSchema(
|
|
24
|
+
z.object({
|
|
25
|
+
id: z.string(),
|
|
26
|
+
version: z.string().nullish(),
|
|
27
|
+
name: z.string().nullish(),
|
|
28
|
+
description: z.string().nullish(),
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SkillsV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
|
+
import {
|
|
3
|
+
combineHeaders,
|
|
4
|
+
convertBase64ToUint8Array,
|
|
5
|
+
createJsonResponseHandler,
|
|
6
|
+
FetchFunction,
|
|
7
|
+
postFormDataToApi,
|
|
8
|
+
} from '@ai-sdk/provider-utils';
|
|
9
|
+
import { openaiFailedResponseHandler } from '../openai-error';
|
|
10
|
+
import { openaiSkillResponseSchema } from './openai-skills-api';
|
|
11
|
+
|
|
12
|
+
interface OpenAISkillsConfig {
|
|
13
|
+
provider: string;
|
|
14
|
+
url: (options: { path: string }) => string;
|
|
15
|
+
headers: () => Record<string, string | undefined>;
|
|
16
|
+
fetch?: FetchFunction;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class OpenAISkills implements SkillsV4 {
|
|
20
|
+
readonly specificationVersion = 'v4';
|
|
21
|
+
|
|
22
|
+
get provider(): string {
|
|
23
|
+
return this.config.provider;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
constructor(private readonly config: OpenAISkillsConfig) {}
|
|
27
|
+
|
|
28
|
+
async upload(
|
|
29
|
+
params: Parameters<SkillsV4['upload']>[0],
|
|
30
|
+
): Promise<Awaited<ReturnType<SkillsV4['upload']>>> {
|
|
31
|
+
const warnings: SharedV4Warning[] = [];
|
|
32
|
+
|
|
33
|
+
if (params.displayTitle != null) {
|
|
34
|
+
warnings.push({
|
|
35
|
+
type: 'unsupported',
|
|
36
|
+
feature: 'displayTitle',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const formData = new FormData();
|
|
41
|
+
|
|
42
|
+
for (const file of params.files) {
|
|
43
|
+
const content =
|
|
44
|
+
typeof file.content === 'string'
|
|
45
|
+
? convertBase64ToUint8Array(file.content)
|
|
46
|
+
: file.content;
|
|
47
|
+
|
|
48
|
+
formData.append('files[]', new Blob([content]), file.path);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { value: response } = await postFormDataToApi({
|
|
52
|
+
url: this.config.url({ path: '/skills' }),
|
|
53
|
+
headers: combineHeaders(this.config.headers()),
|
|
54
|
+
formData,
|
|
55
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
56
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
57
|
+
openaiSkillResponseSchema,
|
|
58
|
+
),
|
|
59
|
+
fetch: this.config.fetch,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
providerReference: { openai: response.id },
|
|
64
|
+
...(response.name != null ? { name: response.name } : {}),
|
|
65
|
+
...(response.description != null
|
|
66
|
+
? { description: response.description }
|
|
67
|
+
: {}),
|
|
68
|
+
...(response.latest_version != null
|
|
69
|
+
? { latestVersion: response.latest_version }
|
|
70
|
+
: {}),
|
|
71
|
+
providerMetadata: {
|
|
72
|
+
openai: {
|
|
73
|
+
...(response.default_version != null
|
|
74
|
+
? { defaultVersion: response.default_version }
|
|
75
|
+
: {}),
|
|
76
|
+
...(response.created_at != null
|
|
77
|
+
? { createdAt: response.created_at }
|
|
78
|
+
: {}),
|
|
79
|
+
...(response.updated_at != null
|
|
80
|
+
? { updatedAt: response.updated_at }
|
|
81
|
+
: {}),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
warnings,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/tool/shell.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import type { SharedV4ProviderReference } from '@ai-sdk/provider';
|
|
6
7
|
import { z } from 'zod/v4';
|
|
7
8
|
|
|
8
9
|
export const shellInputSchema = lazySchema(() =>
|
|
@@ -39,7 +40,7 @@ const shellSkillsSchema = z
|
|
|
39
40
|
z.discriminatedUnion('type', [
|
|
40
41
|
z.object({
|
|
41
42
|
type: z.literal('skillReference'),
|
|
42
|
-
|
|
43
|
+
providerReference: z.record(z.string(), z.string()),
|
|
43
44
|
version: z.string().optional(),
|
|
44
45
|
}),
|
|
45
46
|
z.object({
|
|
@@ -125,7 +126,11 @@ type ShellArgs = {
|
|
|
125
126
|
}>;
|
|
126
127
|
};
|
|
127
128
|
skills?: Array<
|
|
128
|
-
| {
|
|
129
|
+
| {
|
|
130
|
+
type: 'skillReference';
|
|
131
|
+
providerReference: SharedV4ProviderReference;
|
|
132
|
+
version?: string;
|
|
133
|
+
}
|
|
129
134
|
| {
|
|
130
135
|
type: 'inline';
|
|
131
136
|
name: string;
|