@ai-sdk/openai 3.0.54 → 3.0.57
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 +22 -0
- package/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +1204 -1122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1176 -1063
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +28 -1
- package/dist/internal/index.d.ts +28 -1
- package/dist/internal/index.js +1203 -1115
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1177 -1061
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +12 -3
- package/package.json +4 -4
- package/src/chat/convert-openai-chat-usage.ts +1 -1
- package/src/chat/convert-to-openai-chat-messages.ts +3 -3
- package/src/chat/map-openai-finish-reason.ts +1 -1
- package/src/chat/openai-chat-api.ts +6 -2
- package/src/chat/openai-chat-language-model.ts +14 -14
- package/src/chat/openai-chat-options.ts +5 -1
- 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 -1
- package/src/completion/map-openai-finish-reason.ts +1 -1
- package/src/completion/openai-completion-api.ts +5 -1
- package/src/completion/openai-completion-language-model.ts +6 -6
- package/src/completion/openai-completion-options.ts +5 -1
- package/src/embedding/openai-embedding-model.ts +3 -3
- package/src/embedding/openai-embedding-options.ts +5 -1
- package/src/image/openai-image-model-options.ts +123 -0
- package/src/image/openai-image-model.ts +43 -80
- package/src/index.ts +5 -0
- package/src/internal/index.ts +1 -1
- package/src/openai-config.ts +1 -1
- package/src/openai-provider.ts +9 -9
- package/src/responses/convert-openai-responses-usage.ts +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +5 -5
- package/src/responses/map-openai-responses-finish-reason.ts +1 -1
- package/src/responses/openai-responses-api.ts +6 -2
- package/src/responses/openai-responses-language-model.ts +35 -35
- package/src/responses/openai-responses-options.ts +5 -1
- package/src/responses/openai-responses-prepare-tools.ts +4 -4
- package/src/responses/openai-responses-provider-metadata.ts +2 -2
- package/src/speech/openai-speech-model.ts +4 -4
- package/src/speech/openai-speech-options.ts +5 -1
- package/src/tool/file-search.ts +1 -1
- package/src/tool/mcp.ts +1 -1
- package/src/tool/tool-search.ts +2 -2
- package/src/transcription/openai-transcription-model.ts +4 -4
- package/src/transcription/openai-transcription-options.ts +5 -1
- package/src/image/openai-image-options.ts +0 -34
package/src/openai-provider.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
EmbeddingModelV3,
|
|
3
3
|
ImageModelV3,
|
|
4
4
|
LanguageModelV3,
|
|
@@ -7,27 +7,27 @@ import {
|
|
|
7
7
|
TranscriptionModelV3,
|
|
8
8
|
} from '@ai-sdk/provider';
|
|
9
9
|
import {
|
|
10
|
-
FetchFunction,
|
|
11
10
|
loadApiKey,
|
|
12
11
|
loadOptionalSetting,
|
|
13
12
|
withoutTrailingSlash,
|
|
14
13
|
withUserAgentSuffix,
|
|
14
|
+
type FetchFunction,
|
|
15
15
|
} from '@ai-sdk/provider-utils';
|
|
16
16
|
import { OpenAIChatLanguageModel } from './chat/openai-chat-language-model';
|
|
17
|
-
import { OpenAIChatModelId } from './chat/openai-chat-options';
|
|
17
|
+
import type { OpenAIChatModelId } from './chat/openai-chat-options';
|
|
18
18
|
import { OpenAICompletionLanguageModel } from './completion/openai-completion-language-model';
|
|
19
|
-
import { OpenAICompletionModelId } from './completion/openai-completion-options';
|
|
19
|
+
import type { OpenAICompletionModelId } from './completion/openai-completion-options';
|
|
20
20
|
import { OpenAIEmbeddingModel } from './embedding/openai-embedding-model';
|
|
21
|
-
import { OpenAIEmbeddingModelId } from './embedding/openai-embedding-options';
|
|
21
|
+
import type { OpenAIEmbeddingModelId } from './embedding/openai-embedding-options';
|
|
22
22
|
import { OpenAIImageModel } from './image/openai-image-model';
|
|
23
|
-
import { OpenAIImageModelId } from './image/openai-image-options';
|
|
23
|
+
import type { OpenAIImageModelId } from './image/openai-image-model-options';
|
|
24
24
|
import { openaiTools } from './openai-tools';
|
|
25
25
|
import { OpenAIResponsesLanguageModel } from './responses/openai-responses-language-model';
|
|
26
|
-
import { OpenAIResponsesModelId } from './responses/openai-responses-options';
|
|
26
|
+
import type { OpenAIResponsesModelId } from './responses/openai-responses-options';
|
|
27
27
|
import { OpenAISpeechModel } from './speech/openai-speech-model';
|
|
28
|
-
import { OpenAISpeechModelId } from './speech/openai-speech-options';
|
|
28
|
+
import type { OpenAISpeechModelId } from './speech/openai-speech-options';
|
|
29
29
|
import { OpenAITranscriptionModel } from './transcription/openai-transcription-model';
|
|
30
|
-
import { OpenAITranscriptionModelId } from './transcription/openai-transcription-options';
|
|
30
|
+
import type { OpenAITranscriptionModelId } from './transcription/openai-transcription-options';
|
|
31
31
|
import { VERSION } from './version';
|
|
32
32
|
|
|
33
33
|
export interface OpenAIProvider extends ProviderV3 {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV3Prompt,
|
|
3
|
-
LanguageModelV3ToolApprovalResponsePart,
|
|
4
|
-
SharedV3Warning,
|
|
5
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV3Prompt,
|
|
4
|
+
type LanguageModelV3ToolApprovalResponsePart,
|
|
5
|
+
type SharedV3Warning,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import {
|
|
8
8
|
convertToBase64,
|
|
9
9
|
isNonNullable,
|
|
10
10
|
parseJSON,
|
|
11
11
|
parseProviderOptions,
|
|
12
|
-
ToolNameMapping,
|
|
13
12
|
validateTypes,
|
|
13
|
+
type ToolNameMapping,
|
|
14
14
|
} from '@ai-sdk/provider-utils';
|
|
15
15
|
import { z } from 'zod/v4';
|
|
16
16
|
import {
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
toolSearchInputSchema,
|
|
27
27
|
toolSearchOutputSchema,
|
|
28
28
|
} from '../tool/tool-search';
|
|
29
|
-
import {
|
|
29
|
+
import type {
|
|
30
30
|
OpenAIResponsesCustomToolCallOutput,
|
|
31
31
|
OpenAIResponsesFunctionCallOutput,
|
|
32
32
|
OpenAIResponsesInput,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { JSONObject, JSONSchema7, JSONValue } from '@ai-sdk/provider';
|
|
2
|
-
import {
|
|
1
|
+
import type { JSONObject, JSONSchema7, JSONValue } from '@ai-sdk/provider';
|
|
2
|
+
import {
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
type InferSchema,
|
|
6
|
+
} from '@ai-sdk/provider-utils';
|
|
3
7
|
import { z } from 'zod/v4';
|
|
4
8
|
|
|
5
9
|
const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APICallError,
|
|
3
|
-
JSONValue,
|
|
4
|
-
LanguageModelV3,
|
|
5
|
-
LanguageModelV3Prompt,
|
|
6
|
-
LanguageModelV3CallOptions,
|
|
7
|
-
LanguageModelV3Content,
|
|
8
|
-
LanguageModelV3FinishReason,
|
|
9
|
-
LanguageModelV3GenerateResult,
|
|
10
|
-
LanguageModelV3ProviderTool,
|
|
11
|
-
LanguageModelV3StreamPart,
|
|
12
|
-
LanguageModelV3StreamResult,
|
|
13
|
-
LanguageModelV3ToolApprovalRequest,
|
|
14
|
-
SharedV3ProviderMetadata,
|
|
15
|
-
SharedV3Warning,
|
|
3
|
+
type JSONValue,
|
|
4
|
+
type LanguageModelV3,
|
|
5
|
+
type LanguageModelV3Prompt,
|
|
6
|
+
type LanguageModelV3CallOptions,
|
|
7
|
+
type LanguageModelV3Content,
|
|
8
|
+
type LanguageModelV3FinishReason,
|
|
9
|
+
type LanguageModelV3GenerateResult,
|
|
10
|
+
type LanguageModelV3ProviderTool,
|
|
11
|
+
type LanguageModelV3StreamPart,
|
|
12
|
+
type LanguageModelV3StreamResult,
|
|
13
|
+
type LanguageModelV3ToolApprovalRequest,
|
|
14
|
+
type SharedV3ProviderMetadata,
|
|
15
|
+
type SharedV3Warning,
|
|
16
16
|
} from '@ai-sdk/provider';
|
|
17
17
|
import {
|
|
18
18
|
combineHeaders,
|
|
@@ -20,53 +20,53 @@ import {
|
|
|
20
20
|
createJsonResponseHandler,
|
|
21
21
|
createToolNameMapping,
|
|
22
22
|
generateId,
|
|
23
|
-
InferSchema,
|
|
24
23
|
parseProviderOptions,
|
|
25
|
-
ParseResult,
|
|
26
24
|
postJsonToApi,
|
|
25
|
+
type InferSchema,
|
|
26
|
+
type ParseResult,
|
|
27
27
|
} from '@ai-sdk/provider-utils';
|
|
28
|
-
import { OpenAIConfig } from '../openai-config';
|
|
28
|
+
import type { OpenAIConfig } from '../openai-config';
|
|
29
29
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
30
30
|
import { getOpenAILanguageModelCapabilities } from '../openai-language-model-capabilities';
|
|
31
|
-
import { applyPatchInputSchema } from '../tool/apply-patch';
|
|
32
|
-
import {
|
|
31
|
+
import type { applyPatchInputSchema } from '../tool/apply-patch';
|
|
32
|
+
import type {
|
|
33
33
|
codeInterpreterInputSchema,
|
|
34
34
|
codeInterpreterOutputSchema,
|
|
35
35
|
} from '../tool/code-interpreter';
|
|
36
|
-
import { fileSearchOutputSchema } from '../tool/file-search';
|
|
37
|
-
import { imageGenerationOutputSchema } from '../tool/image-generation';
|
|
38
|
-
import { localShellInputSchema } from '../tool/local-shell';
|
|
39
|
-
import { mcpOutputSchema } from '../tool/mcp';
|
|
40
|
-
import { shellInputSchema, shellOutputSchema } from '../tool/shell';
|
|
41
|
-
import {
|
|
36
|
+
import type { fileSearchOutputSchema } from '../tool/file-search';
|
|
37
|
+
import type { imageGenerationOutputSchema } from '../tool/image-generation';
|
|
38
|
+
import type { localShellInputSchema } from '../tool/local-shell';
|
|
39
|
+
import type { mcpOutputSchema } from '../tool/mcp';
|
|
40
|
+
import type { shellInputSchema, shellOutputSchema } from '../tool/shell';
|
|
41
|
+
import type {
|
|
42
42
|
toolSearchInputSchema,
|
|
43
43
|
toolSearchOutputSchema,
|
|
44
44
|
} from '../tool/tool-search';
|
|
45
|
-
import { webSearchOutputSchema } from '../tool/web-search';
|
|
45
|
+
import type { webSearchOutputSchema } from '../tool/web-search';
|
|
46
46
|
import {
|
|
47
47
|
convertOpenAIResponsesUsage,
|
|
48
|
-
OpenAIResponsesUsage,
|
|
48
|
+
type OpenAIResponsesUsage,
|
|
49
49
|
} from './convert-openai-responses-usage';
|
|
50
50
|
import { convertToOpenAIResponsesInput } from './convert-to-openai-responses-input';
|
|
51
51
|
import { mapOpenAIResponseFinishReason } from './map-openai-responses-finish-reason';
|
|
52
52
|
import {
|
|
53
|
-
OpenAIResponsesChunk,
|
|
54
53
|
openaiResponsesChunkSchema,
|
|
55
|
-
OpenAIResponsesIncludeOptions,
|
|
56
|
-
OpenAIResponsesIncludeValue,
|
|
57
|
-
OpenAIResponsesLogprobs,
|
|
58
54
|
openaiResponsesResponseSchema,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
type OpenAIResponsesChunk,
|
|
56
|
+
type OpenAIResponsesIncludeOptions,
|
|
57
|
+
type OpenAIResponsesIncludeValue,
|
|
58
|
+
type OpenAIResponsesLogprobs,
|
|
59
|
+
type OpenAIResponsesWebSearchAction,
|
|
60
|
+
type OpenAIResponsesApplyPatchOperationDiffDeltaChunk,
|
|
61
|
+
type OpenAIResponsesApplyPatchOperationDiffDoneChunk,
|
|
62
62
|
} from './openai-responses-api';
|
|
63
63
|
import {
|
|
64
|
-
OpenAIResponsesModelId,
|
|
65
64
|
openaiLanguageModelResponsesOptionsSchema,
|
|
66
65
|
TOP_LOGPROBS_MAX,
|
|
66
|
+
type OpenAIResponsesModelId,
|
|
67
67
|
} from './openai-responses-options';
|
|
68
68
|
import { prepareResponsesTools } from './openai-responses-prepare-tools';
|
|
69
|
-
import {
|
|
69
|
+
import type {
|
|
70
70
|
ResponsesProviderMetadata,
|
|
71
71
|
ResponsesReasoningProviderMetadata,
|
|
72
72
|
ResponsesSourceDocumentProviderMetadata,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV3CallOptions,
|
|
3
|
-
SharedV3Warning,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV3CallOptions,
|
|
4
|
+
type SharedV3Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
6
|
+
import { validateTypes, type ToolNameMapping } from '@ai-sdk/provider-utils';
|
|
7
7
|
import { codeInterpreterArgsSchema } from '../tool/code-interpreter';
|
|
8
8
|
import { fileSearchArgsSchema } from '../tool/file-search';
|
|
9
9
|
import { imageGenerationArgsSchema } from '../tool/image-generation';
|
|
@@ -13,7 +13,7 @@ import { shellArgsSchema } from '../tool/shell';
|
|
|
13
13
|
import { toolSearchArgsSchema } from '../tool/tool-search';
|
|
14
14
|
import { webSearchArgsSchema } from '../tool/web-search';
|
|
15
15
|
import { webSearchPreviewArgsSchema } from '../tool/web-search-preview';
|
|
16
|
-
import { OpenAIResponsesTool } from './openai-responses-api';
|
|
16
|
+
import type { OpenAIResponsesTool } from './openai-responses-api';
|
|
17
17
|
|
|
18
18
|
export async function prepareResponsesTools({
|
|
19
19
|
tools,
|
|
@@ -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
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';
|
|
1
|
+
import type { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
combineHeaders,
|
|
4
4
|
createBinaryResponseHandler,
|
|
5
5
|
parseProviderOptions,
|
|
6
6
|
postJsonToApi,
|
|
7
7
|
} from '@ai-sdk/provider-utils';
|
|
8
|
-
import { OpenAIConfig } from '../openai-config';
|
|
8
|
+
import type { OpenAIConfig } from '../openai-config';
|
|
9
9
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
10
|
-
import { OpenAISpeechAPITypes } from './openai-speech-api';
|
|
10
|
+
import type { OpenAISpeechAPITypes } from './openai-speech-api';
|
|
11
11
|
import {
|
|
12
12
|
openaiSpeechModelOptionsSchema,
|
|
13
|
-
OpenAISpeechModelId,
|
|
13
|
+
type OpenAISpeechModelId,
|
|
14
14
|
} from './openai-speech-options';
|
|
15
15
|
|
|
16
16
|
interface OpenAISpeechModelConfig extends OpenAIConfig {
|
package/src/tool/file-search.ts
CHANGED
package/src/tool/mcp.ts
CHANGED
package/src/tool/tool-search.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { JSONObject } from '@ai-sdk/provider';
|
|
1
|
+
import type { JSONObject } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
createProviderToolFactoryWithOutputSchema,
|
|
4
|
-
FlexibleSchema,
|
|
5
4
|
lazySchema,
|
|
6
5
|
zodSchema,
|
|
6
|
+
type FlexibleSchema,
|
|
7
7
|
} from '@ai-sdk/provider-utils';
|
|
8
8
|
import { z } from 'zod/v4';
|
|
9
9
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
TranscriptionModelV3,
|
|
3
3
|
TranscriptionModelV3CallOptions,
|
|
4
4
|
SharedV3Warning,
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
parseProviderOptions,
|
|
12
12
|
postFormDataToApi,
|
|
13
13
|
} from '@ai-sdk/provider-utils';
|
|
14
|
-
import { OpenAIConfig } from '../openai-config';
|
|
14
|
+
import type { OpenAIConfig } from '../openai-config';
|
|
15
15
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
16
16
|
import { openaiTranscriptionResponseSchema } from './openai-transcription-api';
|
|
17
17
|
import {
|
|
18
|
-
OpenAITranscriptionModelId,
|
|
19
18
|
openAITranscriptionModelOptions,
|
|
20
|
-
|
|
19
|
+
type OpenAITranscriptionModelId,
|
|
20
|
+
type OpenAITranscriptionModelOptions,
|
|
21
21
|
} from './openai-transcription-options';
|
|
22
22
|
|
|
23
23
|
export type OpenAITranscriptionCallOptions = Omit<
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type OpenAIImageModelId =
|
|
2
|
-
| 'dall-e-3'
|
|
3
|
-
| 'dall-e-2'
|
|
4
|
-
| 'gpt-image-1'
|
|
5
|
-
| 'gpt-image-1-mini'
|
|
6
|
-
| 'gpt-image-1.5'
|
|
7
|
-
| 'gpt-image-2'
|
|
8
|
-
| 'chatgpt-image-latest'
|
|
9
|
-
| (string & {});
|
|
10
|
-
|
|
11
|
-
// https://platform.openai.com/docs/guides/images
|
|
12
|
-
export const modelMaxImagesPerCall: Record<OpenAIImageModelId, number> = {
|
|
13
|
-
'dall-e-3': 1,
|
|
14
|
-
'dall-e-2': 10,
|
|
15
|
-
'gpt-image-1': 10,
|
|
16
|
-
'gpt-image-1-mini': 10,
|
|
17
|
-
'gpt-image-1.5': 10,
|
|
18
|
-
'gpt-image-2': 10,
|
|
19
|
-
'chatgpt-image-latest': 10,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const defaultResponseFormatPrefixes = [
|
|
23
|
-
'chatgpt-image-',
|
|
24
|
-
'gpt-image-1-mini',
|
|
25
|
-
'gpt-image-1.5',
|
|
26
|
-
'gpt-image-1',
|
|
27
|
-
'gpt-image-2',
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
export function hasDefaultResponseFormat(modelId: string): boolean {
|
|
31
|
-
return defaultResponseFormatPrefixes.some(prefix =>
|
|
32
|
-
modelId.startsWith(prefix),
|
|
33
|
-
);
|
|
34
|
-
}
|