@ai-sdk/openai 4.0.0-beta.7 → 4.0.0-beta.74
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 +636 -24
- package/README.md +2 -0
- package/dist/index.d.ts +240 -44
- package/dist/index.js +3345 -1683
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +390 -36
- package/dist/internal/index.js +2707 -1706
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +413 -39
- package/package.json +16 -17
- package/src/chat/convert-openai-chat-usage.ts +1 -1
- package/src/chat/convert-to-openai-chat-messages.ts +96 -68
- package/src/chat/map-openai-finish-reason.ts +1 -1
- package/src/chat/openai-chat-api.ts +6 -2
- package/src/chat/{openai-chat-options.ts → openai-chat-language-model-options.ts} +11 -1
- package/src/chat/openai-chat-language-model.ts +82 -148
- package/src/chat/openai-chat-prepare-tools.ts +3 -3
- package/src/completion/convert-openai-completion-usage.ts +1 -1
- package/src/completion/convert-to-openai-completion-prompt.ts +1 -2
- package/src/completion/map-openai-finish-reason.ts +1 -1
- package/src/completion/openai-completion-api.ts +5 -2
- package/src/completion/{openai-completion-options.ts → openai-completion-language-model-options.ts} +5 -1
- package/src/completion/openai-completion-language-model.ts +53 -17
- package/src/embedding/{openai-embedding-options.ts → openai-embedding-model-options.ts} +5 -1
- package/src/embedding/openai-embedding-model.ts +22 -5
- 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-options.ts +123 -0
- package/src/image/openai-image-model.ts +62 -83
- package/src/index.ts +15 -6
- package/src/internal/index.ts +7 -6
- package/src/openai-config.ts +7 -7
- package/src/openai-language-model-capabilities.ts +5 -4
- package/src/openai-provider.ts +80 -9
- package/src/openai-stream-error.ts +181 -0
- package/src/openai-tools.ts +12 -1
- package/src/realtime/index.ts +2 -0
- package/src/realtime/openai-realtime-event-mapper.ts +436 -0
- package/src/realtime/openai-realtime-model-options.ts +3 -0
- package/src/realtime/openai-realtime-model.ts +111 -0
- package/src/responses/convert-openai-responses-usage.ts +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +345 -90
- package/src/responses/map-openai-responses-finish-reason.ts +1 -1
- package/src/responses/openai-responses-api.ts +186 -17
- package/src/responses/{openai-responses-options.ts → openai-responses-language-model-options.ts} +55 -1
- package/src/responses/openai-responses-language-model.ts +330 -52
- package/src/responses/openai-responses-prepare-tools.ts +129 -18
- 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-options.ts → openai-speech-model-options.ts} +5 -1
- package/src/speech/openai-speech-model.ts +23 -7
- 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 +10 -2
- package/src/transcription/{openai-transcription-options.ts → openai-transcription-model-options.ts} +5 -1
- package/src/transcription/openai-transcription-model.ts +35 -13
- package/dist/index.d.mts +0 -1107
- package/dist/index.mjs +0 -6509
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -1137
- package/dist/internal/index.mjs +0 -6322
- package/dist/internal/index.mjs.map +0 -1
- package/src/image/openai-image-options.ts +0 -31
|
@@ -1,27 +1,50 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV4CallOptions,
|
|
3
|
-
SharedV4Warning,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV4CallOptions,
|
|
4
|
+
type LanguageModelV4FunctionTool,
|
|
5
|
+
type SharedV4ProviderReference,
|
|
6
|
+
type SharedV4Warning,
|
|
5
7
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
resolveProviderReference,
|
|
10
|
+
validateTypes,
|
|
11
|
+
type ToolNameMapping,
|
|
12
|
+
} from '@ai-sdk/provider-utils';
|
|
7
13
|
import { codeInterpreterArgsSchema } from '../tool/code-interpreter';
|
|
8
14
|
import { fileSearchArgsSchema } from '../tool/file-search';
|
|
9
15
|
import { imageGenerationArgsSchema } from '../tool/image-generation';
|
|
10
16
|
import { customArgsSchema } from '../tool/custom';
|
|
11
17
|
import { mcpArgsSchema } from '../tool/mcp';
|
|
12
18
|
import { shellArgsSchema } from '../tool/shell';
|
|
19
|
+
import { toolSearchArgsSchema } from '../tool/tool-search';
|
|
13
20
|
import { webSearchArgsSchema } from '../tool/web-search';
|
|
14
21
|
import { webSearchPreviewArgsSchema } from '../tool/web-search-preview';
|
|
15
|
-
import {
|
|
22
|
+
import type {
|
|
23
|
+
OpenAIResponsesFunctionTool,
|
|
24
|
+
OpenAIResponsesTool,
|
|
25
|
+
} from './openai-responses-api';
|
|
26
|
+
|
|
27
|
+
type OpenAIToolOptions = {
|
|
28
|
+
deferLoading?: boolean;
|
|
29
|
+
namespace?: {
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
16
34
|
|
|
17
35
|
export async function prepareResponsesTools({
|
|
18
36
|
tools,
|
|
19
37
|
toolChoice,
|
|
38
|
+
allowedTools,
|
|
20
39
|
toolNameMapping,
|
|
21
40
|
customProviderToolNames,
|
|
22
41
|
}: {
|
|
23
42
|
tools: LanguageModelV4CallOptions['tools'];
|
|
24
43
|
toolChoice: LanguageModelV4CallOptions['toolChoice'] | undefined;
|
|
44
|
+
allowedTools?: {
|
|
45
|
+
toolNames: string[];
|
|
46
|
+
mode?: 'auto' | 'required';
|
|
47
|
+
};
|
|
25
48
|
toolNameMapping?: ToolNameMapping;
|
|
26
49
|
customProviderToolNames?: Set<string>;
|
|
27
50
|
}): Promise<{
|
|
@@ -38,7 +61,12 @@ export async function prepareResponsesTools({
|
|
|
38
61
|
| { type: 'code_interpreter' }
|
|
39
62
|
| { type: 'mcp' }
|
|
40
63
|
| { type: 'image_generation' }
|
|
41
|
-
| { type: 'apply_patch' }
|
|
64
|
+
| { type: 'apply_patch' }
|
|
65
|
+
| {
|
|
66
|
+
type: 'allowed_tools';
|
|
67
|
+
mode: 'auto' | 'required';
|
|
68
|
+
tools: Array<{ type: 'function'; name: string }>;
|
|
69
|
+
};
|
|
42
70
|
toolWarnings: SharedV4Warning[];
|
|
43
71
|
}> {
|
|
44
72
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
@@ -51,20 +79,49 @@ export async function prepareResponsesTools({
|
|
|
51
79
|
}
|
|
52
80
|
|
|
53
81
|
const openaiTools: Array<OpenAIResponsesTool> = [];
|
|
82
|
+
const namespaceTools = new Map<
|
|
83
|
+
string,
|
|
84
|
+
Extract<OpenAIResponsesTool, { type: 'namespace' }>
|
|
85
|
+
>();
|
|
54
86
|
const resolvedCustomProviderToolNames =
|
|
55
87
|
customProviderToolNames ?? new Set<string>();
|
|
56
88
|
|
|
57
89
|
for (const tool of tools) {
|
|
58
90
|
switch (tool.type) {
|
|
59
|
-
case 'function':
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
case 'function': {
|
|
92
|
+
const openaiOptions = tool.providerOptions?.openai as
|
|
93
|
+
| OpenAIToolOptions
|
|
94
|
+
| undefined;
|
|
95
|
+
const openaiFunctionTool = prepareFunctionTool({
|
|
96
|
+
tool,
|
|
97
|
+
options: openaiOptions,
|
|
66
98
|
});
|
|
99
|
+
const namespace = openaiOptions?.namespace;
|
|
100
|
+
|
|
101
|
+
if (namespace == null) {
|
|
102
|
+
openaiTools.push(openaiFunctionTool);
|
|
103
|
+
} else {
|
|
104
|
+
let namespaceTool = namespaceTools.get(namespace.name);
|
|
105
|
+
|
|
106
|
+
if (namespaceTool == null) {
|
|
107
|
+
namespaceTool = {
|
|
108
|
+
type: 'namespace',
|
|
109
|
+
name: namespace.name,
|
|
110
|
+
description: namespace.description,
|
|
111
|
+
tools: [],
|
|
112
|
+
};
|
|
113
|
+
namespaceTools.set(namespace.name, namespaceTool);
|
|
114
|
+
openaiTools.push(namespaceTool);
|
|
115
|
+
} else if (namespaceTool.description !== namespace.description) {
|
|
116
|
+
throw new UnsupportedFunctionalityError({
|
|
117
|
+
functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
namespaceTool.tools.push(openaiFunctionTool);
|
|
122
|
+
}
|
|
67
123
|
break;
|
|
124
|
+
}
|
|
68
125
|
case 'provider': {
|
|
69
126
|
switch (tool.id) {
|
|
70
127
|
case 'openai.file_search': {
|
|
@@ -241,11 +298,28 @@ export async function prepareResponsesTools({
|
|
|
241
298
|
|
|
242
299
|
openaiTools.push({
|
|
243
300
|
type: 'custom',
|
|
244
|
-
name:
|
|
301
|
+
name: tool.name,
|
|
245
302
|
description: args.description,
|
|
246
303
|
format: args.format,
|
|
247
304
|
});
|
|
248
|
-
resolvedCustomProviderToolNames.add(
|
|
305
|
+
resolvedCustomProviderToolNames.add(tool.name);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case 'openai.tool_search': {
|
|
309
|
+
const args = await validateTypes({
|
|
310
|
+
value: tool.args,
|
|
311
|
+
schema: toolSearchArgsSchema,
|
|
312
|
+
});
|
|
313
|
+
openaiTools.push({
|
|
314
|
+
type: 'tool_search',
|
|
315
|
+
...(args.execution != null ? { execution: args.execution } : {}),
|
|
316
|
+
...(args.description != null
|
|
317
|
+
? { description: args.description }
|
|
318
|
+
: {}),
|
|
319
|
+
...(args.parameters != null
|
|
320
|
+
? { parameters: args.parameters }
|
|
321
|
+
: {}),
|
|
322
|
+
});
|
|
249
323
|
break;
|
|
250
324
|
}
|
|
251
325
|
}
|
|
@@ -260,6 +334,21 @@ export async function prepareResponsesTools({
|
|
|
260
334
|
}
|
|
261
335
|
}
|
|
262
336
|
|
|
337
|
+
if (allowedTools != null) {
|
|
338
|
+
return {
|
|
339
|
+
tools: openaiTools,
|
|
340
|
+
toolChoice: {
|
|
341
|
+
type: 'allowed_tools',
|
|
342
|
+
mode: allowedTools.mode ?? 'auto',
|
|
343
|
+
tools: allowedTools.toolNames.map(name => ({
|
|
344
|
+
type: 'function',
|
|
345
|
+
name: toolNameMapping?.toProviderToolName(name) ?? name,
|
|
346
|
+
})),
|
|
347
|
+
},
|
|
348
|
+
toolWarnings,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
263
352
|
if (toolChoice == null) {
|
|
264
353
|
return { tools: openaiTools, toolChoice: undefined, toolWarnings };
|
|
265
354
|
}
|
|
@@ -302,6 +391,25 @@ export async function prepareResponsesTools({
|
|
|
302
391
|
}
|
|
303
392
|
}
|
|
304
393
|
|
|
394
|
+
function prepareFunctionTool({
|
|
395
|
+
tool,
|
|
396
|
+
options,
|
|
397
|
+
}: {
|
|
398
|
+
tool: LanguageModelV4FunctionTool;
|
|
399
|
+
options: OpenAIToolOptions | undefined;
|
|
400
|
+
}): OpenAIResponsesFunctionTool {
|
|
401
|
+
const deferLoading = options?.deferLoading;
|
|
402
|
+
|
|
403
|
+
return {
|
|
404
|
+
type: 'function',
|
|
405
|
+
name: tool.name,
|
|
406
|
+
description: tool.description,
|
|
407
|
+
parameters: tool.inputSchema,
|
|
408
|
+
...(tool.strict != null ? { strict: tool.strict } : {}),
|
|
409
|
+
...(deferLoading != null ? { defer_loading: deferLoading } : {}),
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
305
413
|
function mapShellEnvironment(environment: {
|
|
306
414
|
type?: string;
|
|
307
415
|
[key: string]: unknown;
|
|
@@ -335,7 +443,7 @@ function mapShellEnvironment(environment: {
|
|
|
335
443
|
};
|
|
336
444
|
skills?: Array<{
|
|
337
445
|
type: string;
|
|
338
|
-
|
|
446
|
+
providerReference?: SharedV4ProviderReference;
|
|
339
447
|
version?: string;
|
|
340
448
|
name?: string;
|
|
341
449
|
description?: string;
|
|
@@ -379,7 +487,7 @@ function mapShellSkills(
|
|
|
379
487
|
skills:
|
|
380
488
|
| Array<{
|
|
381
489
|
type: string;
|
|
382
|
-
|
|
490
|
+
providerReference?: SharedV4ProviderReference;
|
|
383
491
|
version?: string;
|
|
384
492
|
name?: string;
|
|
385
493
|
description?: string;
|
|
@@ -391,8 +499,11 @@ function mapShellSkills(
|
|
|
391
499
|
skill.type === 'skillReference'
|
|
392
500
|
? {
|
|
393
501
|
type: 'skill_reference' as const,
|
|
394
|
-
skill_id:
|
|
395
|
-
|
|
502
|
+
skill_id: resolveProviderReference({
|
|
503
|
+
reference: skill.providerReference ?? {},
|
|
504
|
+
provider: 'openai',
|
|
505
|
+
}),
|
|
506
|
+
version: skill.version ?? 'latest',
|
|
396
507
|
}
|
|
397
508
|
: {
|
|
398
509
|
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,18 +1,20 @@
|
|
|
1
|
-
import { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
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,
|
|
14
|
-
} from './openai-speech-options';
|
|
15
|
-
|
|
16
|
+
type OpenAISpeechModelId,
|
|
17
|
+
} from './openai-speech-model-options';
|
|
16
18
|
interface OpenAISpeechModelConfig extends OpenAIConfig {
|
|
17
19
|
_internal?: {
|
|
18
20
|
currentDate?: () => Date;
|
|
@@ -22,6 +24,20 @@ interface OpenAISpeechModelConfig extends OpenAIConfig {
|
|
|
22
24
|
export class OpenAISpeechModel implements SpeechModelV4 {
|
|
23
25
|
readonly specificationVersion = 'v4';
|
|
24
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
|
+
}
|
|
40
|
+
|
|
25
41
|
get provider(): string {
|
|
26
42
|
return this.config.provider;
|
|
27
43
|
}
|
|
@@ -112,7 +128,7 @@ export class OpenAISpeechModel implements SpeechModelV4 {
|
|
|
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
|
/**
|