@ai-sdk/openai 4.0.0-beta.4 → 4.0.0-beta.41
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 +399 -22
- package/README.md +2 -0
- package/dist/index.d.ts +166 -49
- package/dist/index.js +2454 -1627
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +176 -53
- package/dist/internal/index.js +2220 -1648
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +292 -22
- package/package.json +13 -14
- package/src/chat/convert-openai-chat-usage.ts +2 -2
- package/src/chat/convert-to-openai-chat-messages.ts +99 -71
- package/src/chat/map-openai-finish-reason.ts +2 -2
- package/src/chat/openai-chat-api.ts +6 -2
- package/src/chat/openai-chat-language-model.ts +68 -164
- package/src/chat/openai-chat-options.ts +10 -1
- package/src/chat/openai-chat-prepare-tools.ts +7 -7
- package/src/completion/convert-openai-completion-usage.ts +2 -2
- package/src/completion/convert-to-openai-completion-prompt.ts +2 -3
- package/src/completion/map-openai-finish-reason.ts +2 -2
- package/src/completion/openai-completion-api.ts +5 -2
- package/src/completion/openai-completion-language-model.ts +46 -30
- package/src/completion/openai-completion-options.ts +5 -1
- package/src/embedding/openai-embedding-model.ts +25 -8
- package/src/embedding/openai-embedding-options.ts +5 -1
- package/src/files/openai-files-api.ts +17 -0
- package/src/files/openai-files-options.ts +22 -0
- package/src/files/openai-files.ts +100 -0
- package/src/image/openai-image-model.ts +31 -15
- package/src/image/openai-image-options.ts +3 -0
- package/src/index.ts +2 -0
- package/src/openai-config.ts +7 -7
- package/src/openai-language-model-capabilities.ts +3 -2
- package/src/openai-provider.ts +63 -30
- package/src/openai-tools.ts +12 -1
- package/src/responses/convert-openai-responses-usage.ts +2 -2
- package/src/responses/convert-to-openai-responses-input.ts +244 -77
- package/src/responses/map-openai-responses-finish-reason.ts +2 -2
- package/src/responses/openai-responses-api.ts +141 -3
- package/src/responses/openai-responses-language-model.ts +274 -61
- package/src/responses/openai-responses-options.ts +29 -3
- package/src/responses/openai-responses-prepare-tools.ts +48 -15
- package/src/responses/openai-responses-provider-metadata.ts +12 -2
- package/src/skills/openai-skills-api.ts +31 -0
- package/src/skills/openai-skills.ts +83 -0
- package/src/speech/openai-speech-model.ts +28 -12
- package/src/speech/openai-speech-options.ts +5 -1
- package/src/tool/apply-patch.ts +33 -32
- package/src/tool/code-interpreter.ts +40 -41
- package/src/tool/custom.ts +2 -8
- package/src/tool/file-search.ts +3 -3
- package/src/tool/image-generation.ts +2 -2
- package/src/tool/local-shell.ts +2 -2
- package/src/tool/mcp.ts +3 -3
- package/src/tool/shell.ts +9 -4
- package/src/tool/tool-search.ts +98 -0
- package/src/tool/web-search-preview.ts +2 -2
- package/src/tool/web-search.ts +2 -2
- package/src/transcription/openai-transcription-model.ts +30 -14
- package/src/transcription/openai-transcription-options.ts +5 -1
- package/dist/index.d.mts +0 -1107
- package/dist/index.mjs +0 -6508
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -1137
- package/dist/internal/index.mjs +0 -6321
- package/dist/internal/index.mjs.map +0 -1
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV3CallOptions,
|
|
3
|
-
SharedV3Warning,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV4CallOptions,
|
|
4
|
+
type SharedV4ProviderReference,
|
|
5
|
+
type SharedV4Warning,
|
|
5
6
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
resolveProviderReference,
|
|
9
|
+
validateTypes,
|
|
10
|
+
type ToolNameMapping,
|
|
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';
|
|
10
15
|
import { customArgsSchema } from '../tool/custom';
|
|
11
16
|
import { mcpArgsSchema } from '../tool/mcp';
|
|
12
17
|
import { shellArgsSchema } from '../tool/shell';
|
|
18
|
+
import { toolSearchArgsSchema } from '../tool/tool-search';
|
|
13
19
|
import { webSearchArgsSchema } from '../tool/web-search';
|
|
14
20
|
import { webSearchPreviewArgsSchema } from '../tool/web-search-preview';
|
|
15
|
-
import { OpenAIResponsesTool } from './openai-responses-api';
|
|
21
|
+
import type { OpenAIResponsesTool } from './openai-responses-api';
|
|
16
22
|
|
|
17
23
|
export async function prepareResponsesTools({
|
|
18
24
|
tools,
|
|
@@ -20,8 +26,8 @@ export async function prepareResponsesTools({
|
|
|
20
26
|
toolNameMapping,
|
|
21
27
|
customProviderToolNames,
|
|
22
28
|
}: {
|
|
23
|
-
tools:
|
|
24
|
-
toolChoice:
|
|
29
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
30
|
+
toolChoice: LanguageModelV4CallOptions['toolChoice'] | undefined;
|
|
25
31
|
toolNameMapping?: ToolNameMapping;
|
|
26
32
|
customProviderToolNames?: Set<string>;
|
|
27
33
|
}): Promise<{
|
|
@@ -39,12 +45,12 @@ export async function prepareResponsesTools({
|
|
|
39
45
|
| { type: 'mcp' }
|
|
40
46
|
| { type: 'image_generation' }
|
|
41
47
|
| { type: 'apply_patch' };
|
|
42
|
-
toolWarnings:
|
|
48
|
+
toolWarnings: SharedV4Warning[];
|
|
43
49
|
}> {
|
|
44
50
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
45
51
|
tools = tools?.length ? tools : undefined;
|
|
46
52
|
|
|
47
|
-
const toolWarnings:
|
|
53
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
48
54
|
|
|
49
55
|
if (tools == null) {
|
|
50
56
|
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
@@ -56,15 +62,22 @@ export async function prepareResponsesTools({
|
|
|
56
62
|
|
|
57
63
|
for (const tool of tools) {
|
|
58
64
|
switch (tool.type) {
|
|
59
|
-
case 'function':
|
|
65
|
+
case 'function': {
|
|
66
|
+
const openaiOptions = tool.providerOptions?.openai as
|
|
67
|
+
| { deferLoading?: boolean }
|
|
68
|
+
| undefined;
|
|
69
|
+
const deferLoading = openaiOptions?.deferLoading;
|
|
70
|
+
|
|
60
71
|
openaiTools.push({
|
|
61
72
|
type: 'function',
|
|
62
73
|
name: tool.name,
|
|
63
74
|
description: tool.description,
|
|
64
75
|
parameters: tool.inputSchema,
|
|
65
76
|
...(tool.strict != null ? { strict: tool.strict } : {}),
|
|
77
|
+
...(deferLoading != null ? { defer_loading: deferLoading } : {}),
|
|
66
78
|
});
|
|
67
79
|
break;
|
|
80
|
+
}
|
|
68
81
|
case 'provider': {
|
|
69
82
|
switch (tool.id) {
|
|
70
83
|
case 'openai.file_search': {
|
|
@@ -241,11 +254,28 @@ export async function prepareResponsesTools({
|
|
|
241
254
|
|
|
242
255
|
openaiTools.push({
|
|
243
256
|
type: 'custom',
|
|
244
|
-
name:
|
|
257
|
+
name: tool.name,
|
|
245
258
|
description: args.description,
|
|
246
259
|
format: args.format,
|
|
247
260
|
});
|
|
248
|
-
resolvedCustomProviderToolNames.add(
|
|
261
|
+
resolvedCustomProviderToolNames.add(tool.name);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case 'openai.tool_search': {
|
|
265
|
+
const args = await validateTypes({
|
|
266
|
+
value: tool.args,
|
|
267
|
+
schema: toolSearchArgsSchema,
|
|
268
|
+
});
|
|
269
|
+
openaiTools.push({
|
|
270
|
+
type: 'tool_search',
|
|
271
|
+
...(args.execution != null ? { execution: args.execution } : {}),
|
|
272
|
+
...(args.description != null
|
|
273
|
+
? { description: args.description }
|
|
274
|
+
: {}),
|
|
275
|
+
...(args.parameters != null
|
|
276
|
+
? { parameters: args.parameters }
|
|
277
|
+
: {}),
|
|
278
|
+
});
|
|
249
279
|
break;
|
|
250
280
|
}
|
|
251
281
|
}
|
|
@@ -335,7 +365,7 @@ function mapShellEnvironment(environment: {
|
|
|
335
365
|
};
|
|
336
366
|
skills?: Array<{
|
|
337
367
|
type: string;
|
|
338
|
-
|
|
368
|
+
providerReference?: SharedV4ProviderReference;
|
|
339
369
|
version?: string;
|
|
340
370
|
name?: string;
|
|
341
371
|
description?: string;
|
|
@@ -379,7 +409,7 @@ function mapShellSkills(
|
|
|
379
409
|
skills:
|
|
380
410
|
| Array<{
|
|
381
411
|
type: string;
|
|
382
|
-
|
|
412
|
+
providerReference?: SharedV4ProviderReference;
|
|
383
413
|
version?: string;
|
|
384
414
|
name?: string;
|
|
385
415
|
description?: string;
|
|
@@ -391,8 +421,11 @@ function mapShellSkills(
|
|
|
391
421
|
skill.type === 'skillReference'
|
|
392
422
|
? {
|
|
393
423
|
type: 'skill_reference' as const,
|
|
394
|
-
skill_id:
|
|
395
|
-
|
|
424
|
+
skill_id: resolveProviderReference({
|
|
425
|
+
reference: skill.providerReference ?? {},
|
|
426
|
+
provider: 'openai',
|
|
427
|
+
}),
|
|
428
|
+
version: skill.version ?? 'latest',
|
|
396
429
|
}
|
|
397
430
|
: {
|
|
398
431
|
type: 'inline' as const,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
openaiResponsesChunkSchema,
|
|
3
3
|
OpenAIResponsesLogprobs,
|
|
4
4
|
} from './openai-responses-api';
|
|
5
|
-
import { InferSchema } from '@ai-sdk/provider-utils';
|
|
5
|
+
import type { InferSchema } from '@ai-sdk/provider-utils';
|
|
6
6
|
|
|
7
7
|
type OpenaiResponsesChunk = InferSchema<typeof openaiResponsesChunkSchema>;
|
|
8
8
|
|
|
@@ -30,6 +30,16 @@ export type OpenaiResponsesProviderMetadata = {
|
|
|
30
30
|
openai: ResponsesProviderMetadata;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
export type ResponsesCompactionProviderMetadata = {
|
|
34
|
+
type: 'compaction';
|
|
35
|
+
itemId: string;
|
|
36
|
+
encryptedContent?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type OpenaiResponsesCompactionProviderMetadata = {
|
|
40
|
+
openai: ResponsesCompactionProviderMetadata;
|
|
41
|
+
};
|
|
42
|
+
|
|
33
43
|
export type ResponsesTextProviderMetadata = {
|
|
34
44
|
itemId: string;
|
|
35
45
|
phase?: 'commentary' | 'final_answer' | null;
|
|
@@ -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,83 @@
|
|
|
1
|
+
import type { SkillsV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
|
+
import {
|
|
3
|
+
combineHeaders,
|
|
4
|
+
convertInlineFileDataToUint8Array,
|
|
5
|
+
createJsonResponseHandler,
|
|
6
|
+
postFormDataToApi,
|
|
7
|
+
type FetchFunction,
|
|
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 uploadSkill(
|
|
29
|
+
params: Parameters<SkillsV4['uploadSkill']>[0],
|
|
30
|
+
): Promise<Awaited<ReturnType<SkillsV4['uploadSkill']>>> {
|
|
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 = convertInlineFileDataToUint8Array(file.data);
|
|
44
|
+
formData.append('files[]', new Blob([content]), file.path);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { value: response } = await postFormDataToApi({
|
|
48
|
+
url: this.config.url({ path: '/skills' }),
|
|
49
|
+
headers: combineHeaders(this.config.headers()),
|
|
50
|
+
formData,
|
|
51
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
52
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
53
|
+
openaiSkillResponseSchema,
|
|
54
|
+
),
|
|
55
|
+
fetch: this.config.fetch,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
providerReference: { openai: response.id },
|
|
60
|
+
...(response.name != null ? { name: response.name } : {}),
|
|
61
|
+
...(response.description != null
|
|
62
|
+
? { description: response.description }
|
|
63
|
+
: {}),
|
|
64
|
+
...(response.latest_version != null
|
|
65
|
+
? { latestVersion: response.latest_version }
|
|
66
|
+
: {}),
|
|
67
|
+
providerMetadata: {
|
|
68
|
+
openai: {
|
|
69
|
+
...(response.default_version != null
|
|
70
|
+
? { defaultVersion: response.default_version }
|
|
71
|
+
: {}),
|
|
72
|
+
...(response.created_at != null
|
|
73
|
+
? { createdAt: response.created_at }
|
|
74
|
+
: {}),
|
|
75
|
+
...(response.updated_at != null
|
|
76
|
+
? { updatedAt: response.updated_at }
|
|
77
|
+
: {}),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
warnings,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,26 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
combineHeaders,
|
|
4
4
|
createBinaryResponseHandler,
|
|
5
5
|
parseProviderOptions,
|
|
6
6
|
postJsonToApi,
|
|
7
|
+
serializeModelOptions,
|
|
8
|
+
WORKFLOW_DESERIALIZE,
|
|
9
|
+
WORKFLOW_SERIALIZE,
|
|
7
10
|
} from '@ai-sdk/provider-utils';
|
|
8
|
-
import { OpenAIConfig } from '../openai-config';
|
|
11
|
+
import type { OpenAIConfig } from '../openai-config';
|
|
9
12
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
10
|
-
import { OpenAISpeechAPITypes } from './openai-speech-api';
|
|
13
|
+
import type { OpenAISpeechAPITypes } from './openai-speech-api';
|
|
11
14
|
import {
|
|
12
15
|
openaiSpeechModelOptionsSchema,
|
|
13
|
-
OpenAISpeechModelId,
|
|
16
|
+
type OpenAISpeechModelId,
|
|
14
17
|
} from './openai-speech-options';
|
|
15
|
-
|
|
16
18
|
interface OpenAISpeechModelConfig extends OpenAIConfig {
|
|
17
19
|
_internal?: {
|
|
18
20
|
currentDate?: () => Date;
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
export class OpenAISpeechModel implements
|
|
23
|
-
readonly specificationVersion = '
|
|
24
|
+
export class OpenAISpeechModel implements SpeechModelV4 {
|
|
25
|
+
readonly specificationVersion = 'v4';
|
|
26
|
+
|
|
27
|
+
static [WORKFLOW_SERIALIZE](model: OpenAISpeechModel) {
|
|
28
|
+
return serializeModelOptions({
|
|
29
|
+
modelId: model.modelId,
|
|
30
|
+
config: model.config,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
35
|
+
modelId: OpenAISpeechModelId;
|
|
36
|
+
config: OpenAISpeechModelConfig;
|
|
37
|
+
}) {
|
|
38
|
+
return new OpenAISpeechModel(options.modelId, options.config);
|
|
39
|
+
}
|
|
24
40
|
|
|
25
41
|
get provider(): string {
|
|
26
42
|
return this.config.provider;
|
|
@@ -39,8 +55,8 @@ export class OpenAISpeechModel implements SpeechModelV3 {
|
|
|
39
55
|
instructions,
|
|
40
56
|
language,
|
|
41
57
|
providerOptions,
|
|
42
|
-
}: Parameters<
|
|
43
|
-
const warnings:
|
|
58
|
+
}: Parameters<SpeechModelV4['doGenerate']>[0]) {
|
|
59
|
+
const warnings: SharedV4Warning[] = [];
|
|
44
60
|
|
|
45
61
|
// Parse provider options
|
|
46
62
|
const openAIOptions = await parseProviderOptions({
|
|
@@ -98,8 +114,8 @@ export class OpenAISpeechModel implements SpeechModelV3 {
|
|
|
98
114
|
}
|
|
99
115
|
|
|
100
116
|
async doGenerate(
|
|
101
|
-
options: Parameters<
|
|
102
|
-
): Promise<Awaited<ReturnType<
|
|
117
|
+
options: Parameters<SpeechModelV4['doGenerate']>[0],
|
|
118
|
+
): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {
|
|
103
119
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
104
120
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
105
121
|
|
|
@@ -112,7 +128,7 @@ export class OpenAISpeechModel implements SpeechModelV3 {
|
|
|
112
128
|
path: '/audio/speech',
|
|
113
129
|
modelId: this.modelId,
|
|
114
130
|
}),
|
|
115
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
131
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
116
132
|
body: requestBody,
|
|
117
133
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
118
134
|
successfulResponseHandler: createBinaryResponseHandler(),
|
package/src/tool/apply-patch.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -98,39 +98,40 @@ export type ApplyPatchOperation =
|
|
|
98
98
|
* - Returns the status of applying those patches (completed or failed)
|
|
99
99
|
*
|
|
100
100
|
*/
|
|
101
|
-
export const applyPatchToolFactory =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
export const applyPatchToolFactory =
|
|
102
|
+
createProviderDefinedToolFactoryWithOutputSchema<
|
|
103
|
+
{
|
|
104
|
+
/**
|
|
105
|
+
* The unique ID of the apply patch tool call generated by the model.
|
|
106
|
+
*/
|
|
107
|
+
callId: string;
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
/**
|
|
110
|
+
* The specific create, delete, or update instruction for the apply_patch tool call.
|
|
111
|
+
*/
|
|
112
|
+
operation: ApplyPatchOperation;
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
/**
|
|
116
|
+
* The status of the apply patch tool call output.
|
|
117
|
+
* - 'completed': The patch was applied successfully.
|
|
118
|
+
* - 'failed': The patch failed to apply.
|
|
119
|
+
*/
|
|
120
|
+
status: 'completed' | 'failed';
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
>({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
122
|
+
/**
|
|
123
|
+
* Optional human-readable log text from the apply patch tool
|
|
124
|
+
* (e.g., patch results or errors).
|
|
125
|
+
*/
|
|
126
|
+
output?: string;
|
|
127
|
+
},
|
|
128
|
+
// No configuration options for apply_patch
|
|
129
|
+
{}
|
|
130
|
+
>({
|
|
131
|
+
id: 'openai.apply_patch',
|
|
132
|
+
inputSchema: applyPatchInputSchema,
|
|
133
|
+
outputSchema: applyPatchOutputSchema,
|
|
134
|
+
});
|
|
134
135
|
|
|
135
136
|
/**
|
|
136
137
|
* The apply_patch tool lets GPT-5.1 create, update, and delete files in your
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -53,49 +53,48 @@ type CodeInterpreterArgs = {
|
|
|
53
53
|
container?: string | { fileIds?: string[] };
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export const codeInterpreterToolFactory =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
code?: string | null;
|
|
56
|
+
export const codeInterpreterToolFactory = createProviderExecutedToolFactory<
|
|
57
|
+
{
|
|
58
|
+
/**
|
|
59
|
+
* The code to run, or null if not available.
|
|
60
|
+
*/
|
|
61
|
+
code?: string | null;
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The ID of the container used to run the code.
|
|
65
|
+
*/
|
|
66
|
+
containerId: string;
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
/**
|
|
70
|
+
* The outputs generated by the code interpreter, such as logs or images.
|
|
71
|
+
* Can be null if no outputs are available.
|
|
72
|
+
*/
|
|
73
|
+
outputs?: Array<
|
|
74
|
+
| {
|
|
75
|
+
type: 'logs';
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The logs output from the code interpreter.
|
|
79
|
+
*/
|
|
80
|
+
logs: string;
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
type: 'image';
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
/**
|
|
86
|
+
* The URL of the image output from the code interpreter.
|
|
87
|
+
*/
|
|
88
|
+
url: string;
|
|
89
|
+
}
|
|
90
|
+
> | null;
|
|
91
|
+
},
|
|
92
|
+
CodeInterpreterArgs
|
|
93
|
+
>({
|
|
94
|
+
id: 'openai.code_interpreter',
|
|
95
|
+
inputSchema: codeInterpreterInputSchema,
|
|
96
|
+
outputSchema: codeInterpreterOutputSchema,
|
|
97
|
+
});
|
|
99
98
|
|
|
100
99
|
export const codeInterpreter = (
|
|
101
100
|
args: CodeInterpreterArgs = {}, // default
|
package/src/tool/custom.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -8,7 +8,6 @@ import { z } from 'zod/v4';
|
|
|
8
8
|
export const customArgsSchema = lazySchema(() =>
|
|
9
9
|
zodSchema(
|
|
10
10
|
z.object({
|
|
11
|
-
name: z.string(),
|
|
12
11
|
description: z.string().optional(),
|
|
13
12
|
format: z
|
|
14
13
|
.union([
|
|
@@ -28,14 +27,9 @@ export const customArgsSchema = lazySchema(() =>
|
|
|
28
27
|
|
|
29
28
|
const customInputSchema = lazySchema(() => zodSchema(z.string()));
|
|
30
29
|
|
|
31
|
-
export const customToolFactory =
|
|
30
|
+
export const customToolFactory = createProviderDefinedToolFactory<
|
|
32
31
|
string,
|
|
33
32
|
{
|
|
34
|
-
/**
|
|
35
|
-
* The name of the custom tool, used to identify it in the API.
|
|
36
|
-
*/
|
|
37
|
-
name: string;
|
|
38
|
-
|
|
39
33
|
/**
|
|
40
34
|
* An optional description of what the tool does.
|
|
41
35
|
*/
|
package/src/tool/file-search.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
6
|
import { z } from 'zod/v4';
|
|
7
|
-
import {
|
|
7
|
+
import type {
|
|
8
8
|
OpenAIResponsesFileSearchToolComparisonFilter,
|
|
9
9
|
OpenAIResponsesFileSearchToolCompoundFilter,
|
|
10
10
|
} from '../responses/openai-responses-api';
|
|
@@ -59,7 +59,7 @@ export const fileSearchOutputSchema = lazySchema(() =>
|
|
|
59
59
|
),
|
|
60
60
|
);
|
|
61
61
|
|
|
62
|
-
export const fileSearch =
|
|
62
|
+
export const fileSearch = createProviderExecutedToolFactory<
|
|
63
63
|
{},
|
|
64
64
|
{
|
|
65
65
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -104,7 +104,7 @@ type ImageGenerationArgs = {
|
|
|
104
104
|
size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024';
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
const imageGenerationToolFactory =
|
|
107
|
+
const imageGenerationToolFactory = createProviderExecutedToolFactory<
|
|
108
108
|
{},
|
|
109
109
|
{
|
|
110
110
|
/**
|
package/src/tool/local-shell.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -24,7 +24,7 @@ export const localShellOutputSchema = lazySchema(() =>
|
|
|
24
24
|
zodSchema(z.object({ output: z.string() })),
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
export const localShell =
|
|
27
|
+
export const localShell = createProviderDefinedToolFactoryWithOutputSchema<
|
|
28
28
|
{
|
|
29
29
|
/**
|
|
30
30
|
* Execute a shell command on the server.
|
package/src/tool/mcp.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
|
-
import { JSONValue } from '@ai-sdk/provider';
|
|
6
|
+
import type { JSONValue } from '@ai-sdk/provider';
|
|
7
7
|
import { z } from 'zod/v4';
|
|
8
8
|
|
|
9
9
|
const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
|
|
@@ -105,7 +105,7 @@ type McpArgs = {
|
|
|
105
105
|
serverUrl?: string;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
export const mcpToolFactory =
|
|
108
|
+
export const mcpToolFactory = createProviderExecutedToolFactory<
|
|
109
109
|
{},
|
|
110
110
|
{
|
|
111
111
|
type: 'call';
|