@ai-sdk/openai 4.0.0-beta.4 → 4.0.0-beta.40
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 +387 -22
- package/README.md +2 -0
- package/dist/index.d.ts +162 -45
- package/dist/index.js +2341 -1572
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +174 -51
- package/dist/internal/index.js +2110 -1593
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +274 -9
- package/package.json +13 -14
- package/src/chat/convert-openai-chat-usage.ts +2 -2
- package/src/chat/convert-to-openai-chat-messages.ts +33 -18
- package/src/chat/map-openai-finish-reason.ts +2 -2
- package/src/chat/openai-chat-language-model.ts +62 -158
- package/src/chat/openai-chat-options.ts +5 -0
- package/src/chat/openai-chat-prepare-tools.ts +6 -6
- package/src/completion/convert-openai-completion-usage.ts +2 -2
- package/src/completion/convert-to-openai-completion-prompt.ts +2 -2
- package/src/completion/map-openai-finish-reason.ts +2 -2
- package/src/completion/openai-completion-language-model.ts +40 -23
- package/src/embedding/openai-embedding-model.ts +23 -6
- package/src/files/openai-files-api.ts +17 -0
- package/src/files/openai-files-options.ts +18 -0
- package/src/files/openai-files.ts +102 -0
- package/src/image/openai-image-model.ts +28 -11
- package/src/image/openai-image-options.ts +3 -0
- package/src/index.ts +2 -0
- package/src/openai-config.ts +6 -6
- package/src/openai-language-model-capabilities.ts +3 -2
- package/src/openai-provider.ts +54 -21
- 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 +194 -39
- package/src/responses/map-openai-responses-finish-reason.ts +2 -2
- package/src/responses/openai-responses-api.ts +136 -2
- package/src/responses/openai-responses-language-model.ts +252 -39
- package/src/responses/openai-responses-options.ts +24 -2
- package/src/responses/openai-responses-prepare-tools.ts +47 -14
- package/src/responses/openai-responses-provider-metadata.ts +10 -0
- package/src/skills/openai-skills-api.ts +31 -0
- package/src/skills/openai-skills.ts +87 -0
- package/src/speech/openai-speech-model.ts +25 -8
- 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 +2 -2
- package/src/tool/image-generation.ts +2 -2
- package/src/tool/local-shell.ts +2 -2
- package/src/tool/mcp.ts +2 -2
- 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 +26 -9
- 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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { JSONObject } from '@ai-sdk/provider';
|
|
2
|
+
import {
|
|
3
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
4
|
+
FlexibleSchema,
|
|
5
|
+
lazySchema,
|
|
6
|
+
zodSchema,
|
|
7
|
+
} from '@ai-sdk/provider-utils';
|
|
8
|
+
import { z } from 'zod/v4';
|
|
9
|
+
|
|
10
|
+
export const toolSearchArgsSchema = lazySchema(() =>
|
|
11
|
+
zodSchema(
|
|
12
|
+
z.object({
|
|
13
|
+
execution: z.enum(['server', 'client']).optional(),
|
|
14
|
+
description: z.string().optional(),
|
|
15
|
+
parameters: z.record(z.string(), z.unknown()).optional(),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const toolSearchInputSchema = lazySchema(() =>
|
|
21
|
+
zodSchema(
|
|
22
|
+
z.object({
|
|
23
|
+
arguments: z.unknown().optional(),
|
|
24
|
+
call_id: z.string().nullish(),
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const toolSearchOutputSchema: FlexibleSchema<{
|
|
30
|
+
tools: Array<JSONObject>;
|
|
31
|
+
}> = lazySchema(() =>
|
|
32
|
+
zodSchema(
|
|
33
|
+
z.object({
|
|
34
|
+
tools: z.array(z.record(z.string(), z.unknown())),
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
) as FlexibleSchema<{ tools: Array<JSONObject> }>;
|
|
38
|
+
|
|
39
|
+
const toolSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema<
|
|
40
|
+
{
|
|
41
|
+
/**
|
|
42
|
+
* The arguments from the tool_search_call.
|
|
43
|
+
* This is preserved for multi-turn conversation reconstruction.
|
|
44
|
+
*/
|
|
45
|
+
arguments?: unknown;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The call ID from the tool_search_call.
|
|
49
|
+
* Present for client-executed tool search; null for hosted.
|
|
50
|
+
*/
|
|
51
|
+
call_id?: string | null;
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
/**
|
|
55
|
+
* The tools that were loaded by the tool search.
|
|
56
|
+
* These are the deferred tools that the model requested to load.
|
|
57
|
+
* Each tool is represented as a JSON object with properties depending on its type.
|
|
58
|
+
*
|
|
59
|
+
* Common properties include:
|
|
60
|
+
* - `type`: The type of the tool (e.g., 'function', 'web_search', etc.)
|
|
61
|
+
* - `name`: The name of the tool (for function tools)
|
|
62
|
+
* - `description`: A description of the tool
|
|
63
|
+
* - `deferLoading`: Whether this tool was deferred (had defer_loading: true)
|
|
64
|
+
* - `parameters`: The JSON Schema for the function parameters (for function tools)
|
|
65
|
+
* - `strict`: Whether to enable strict schema adherence (for function tools)
|
|
66
|
+
*/
|
|
67
|
+
tools: Array<JSONObject>;
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
/**
|
|
71
|
+
* Whether the tool search is executed by the server (hosted) or client.
|
|
72
|
+
* - `'server'` (default): OpenAI performs the search across deferred tools.
|
|
73
|
+
* - `'client'`: The model emits a `tool_search_call` and your `execute`
|
|
74
|
+
* function performs the lookup, returning the tools to load.
|
|
75
|
+
*/
|
|
76
|
+
execution?: 'server' | 'client';
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A description of the tool search capability.
|
|
80
|
+
* Only used for client-executed tool search.
|
|
81
|
+
*/
|
|
82
|
+
description?: string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* JSON Schema for the search arguments your application expects.
|
|
86
|
+
* Only used for client-executed tool search.
|
|
87
|
+
*/
|
|
88
|
+
parameters?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
>({
|
|
91
|
+
id: 'openai.tool_search',
|
|
92
|
+
inputSchema: toolSearchInputSchema,
|
|
93
|
+
outputSchema: toolSearchOutputSchema,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const toolSearch = (
|
|
97
|
+
args: Parameters<typeof toolSearchToolFactory>[0] = {},
|
|
98
|
+
) => toolSearchToolFactory(args);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -50,7 +50,7 @@ const webSearchPreviewOutputSchema = lazySchema(() =>
|
|
|
50
50
|
),
|
|
51
51
|
);
|
|
52
52
|
|
|
53
|
-
export const webSearchPreview =
|
|
53
|
+
export const webSearchPreview = createProviderExecutedToolFactory<
|
|
54
54
|
{
|
|
55
55
|
// Web search preview doesn't take input parameters - it's controlled by the prompt
|
|
56
56
|
},
|
package/src/tool/web-search.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -60,7 +60,7 @@ export const webSearchOutputSchema = lazySchema(() =>
|
|
|
60
60
|
),
|
|
61
61
|
);
|
|
62
62
|
|
|
63
|
-
export const webSearchToolFactory =
|
|
63
|
+
export const webSearchToolFactory = createProviderExecutedToolFactory<
|
|
64
64
|
{
|
|
65
65
|
// Web search doesn't take input parameters - it's controlled by the prompt
|
|
66
66
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
TranscriptionModelV4,
|
|
3
|
+
TranscriptionModelV4CallOptions,
|
|
4
|
+
SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
@@ -10,6 +10,9 @@ import {
|
|
|
10
10
|
mediaTypeToExtension,
|
|
11
11
|
parseProviderOptions,
|
|
12
12
|
postFormDataToApi,
|
|
13
|
+
serializeModelOptions,
|
|
14
|
+
WORKFLOW_DESERIALIZE,
|
|
15
|
+
WORKFLOW_SERIALIZE,
|
|
13
16
|
} from '@ai-sdk/provider-utils';
|
|
14
17
|
import { OpenAIConfig } from '../openai-config';
|
|
15
18
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
@@ -21,7 +24,7 @@ import {
|
|
|
21
24
|
} from './openai-transcription-options';
|
|
22
25
|
|
|
23
26
|
export type OpenAITranscriptionCallOptions = Omit<
|
|
24
|
-
|
|
27
|
+
TranscriptionModelV4CallOptions,
|
|
25
28
|
'providerOptions'
|
|
26
29
|
> & {
|
|
27
30
|
providerOptions?: {
|
|
@@ -96,8 +99,22 @@ const languageMap = {
|
|
|
96
99
|
welsh: 'cy',
|
|
97
100
|
};
|
|
98
101
|
|
|
99
|
-
export class OpenAITranscriptionModel implements
|
|
100
|
-
readonly specificationVersion = '
|
|
102
|
+
export class OpenAITranscriptionModel implements TranscriptionModelV4 {
|
|
103
|
+
readonly specificationVersion = 'v4';
|
|
104
|
+
|
|
105
|
+
static [WORKFLOW_SERIALIZE](model: OpenAITranscriptionModel) {
|
|
106
|
+
return serializeModelOptions({
|
|
107
|
+
modelId: model.modelId,
|
|
108
|
+
config: model.config,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
113
|
+
modelId: OpenAITranscriptionModelId;
|
|
114
|
+
config: OpenAITranscriptionModelConfig;
|
|
115
|
+
}) {
|
|
116
|
+
return new OpenAITranscriptionModel(options.modelId, options.config);
|
|
117
|
+
}
|
|
101
118
|
|
|
102
119
|
get provider(): string {
|
|
103
120
|
return this.config.provider;
|
|
@@ -113,7 +130,7 @@ export class OpenAITranscriptionModel implements TranscriptionModelV3 {
|
|
|
113
130
|
mediaType,
|
|
114
131
|
providerOptions,
|
|
115
132
|
}: OpenAITranscriptionCallOptions) {
|
|
116
|
-
const warnings:
|
|
133
|
+
const warnings: SharedV4Warning[] = [];
|
|
117
134
|
|
|
118
135
|
// Parse provider options
|
|
119
136
|
const openAIOptions = await parseProviderOptions({
|
|
@@ -176,7 +193,7 @@ export class OpenAITranscriptionModel implements TranscriptionModelV3 {
|
|
|
176
193
|
|
|
177
194
|
async doGenerate(
|
|
178
195
|
options: OpenAITranscriptionCallOptions,
|
|
179
|
-
): Promise<Awaited<ReturnType<
|
|
196
|
+
): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
|
|
180
197
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
181
198
|
const { formData, warnings } = await this.getArgs(options);
|
|
182
199
|
|
|
@@ -189,7 +206,7 @@ export class OpenAITranscriptionModel implements TranscriptionModelV3 {
|
|
|
189
206
|
path: '/audio/transcriptions',
|
|
190
207
|
modelId: this.modelId,
|
|
191
208
|
}),
|
|
192
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
209
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
193
210
|
formData,
|
|
194
211
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
195
212
|
successfulResponseHandler: createJsonResponseHandler(
|