@ai-sdk/openai 4.0.103 → 4.0.105
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 +39 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +181 -75
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +14 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +148 -66
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +20 -10
- package/package.json +2 -2
- package/src/chat/openai-chat-language-model-options.ts +1 -0
- package/src/chat/openai-chat-language-model.ts +30 -15
- package/src/normalize-openai-json-schema.ts +2 -1
- package/src/openai-batch.ts +2 -4
- package/src/openai-decision-model-options.ts +1 -0
- package/src/openai-decision-model.ts +46 -5
- package/src/openai-language-model-capabilities.ts +105 -7
- package/src/responses/openai-responses-language-model-options.ts +2 -0
- package/src/responses/openai-responses-language-model.ts +34 -32
- package/src/transcription/openai-transcription-model-options.ts +5 -6
- package/src/transcription/openai-transcription-model.ts +89 -48
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.105
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 47b1d8b: feat(openai): send native JSON input and prompt cache keys to Decisions
|
|
8
|
+
- d07b475: fix(openai): map top-level `reasoning` to efforts supported by GPT-5.x models instead of sending unsupported values that OpenAI rejects with a 400. `max` is now only sent on the Responses API, and GPT-5.6 on Chat Completions sends `reasoning_effort: 'none'` when function tools are used, since it rejects function tools with reasoning. A warning is emitted when a reasoning level was requested.
|
|
9
|
+
- 61a315e: fix: map the top-level `reasoning` option consistently across providers
|
|
10
|
+
|
|
11
|
+
Providers now resolve reasoning the same way:
|
|
12
|
+
|
|
13
|
+
1. A provider-specific reasoning setting in `providerOptions` is sent unchanged. OpenAI no longer drops `providerOptions.openai.reasoningEffort` values that are not in its list for the model, and Fireworks no longer rewrites `providerOptions.fireworks.reasoningEffort`. Fireworks also sends top-level `reasoning` values directly instead of rounding them to `'high'` at most, except for model families known to reject `'none'` (GPT-OSS, GLM-5.3, Muse Spark) or `'minimal'` (Nemotron, Inkling).
|
|
14
|
+
2. Otherwise, `reasoning` maps to the closest level the model supports, rounding down, and rounds up only when there is no lower level. For example, `'xhigh'` now maps to `'high'` instead of `'max'` on Anthropic and Bedrock models without `xhigh` effort, and `'medium'` maps to `'low'` instead of `'high'` on DeepSeek, Kimi K3, and Mistral GLM-5.3 models.
|
|
15
|
+
3. `'none'` on a model that cannot disable reasoning maps to the model's lowest level with a compatibility warning, instead of being dropped or sending a request the API rejects. This affects GPT-6 models without `'none'`, xAI grok-4.5 and later, Groq GPT-OSS, Kimi K3, Perplexity, QuiverAI, Bedrock OpenAI `gpt-oss` models, and Gemini 2.5 Pro (minimum thinking budget). Gemini 3 and Anthropic and Bedrock `between_tools` mappings now emit the compatibility warning too.
|
|
16
|
+
|
|
17
|
+
`mapReasoningToProviderEffort` now accepts any `reasoning` value, returns an optional `providerOptionsEffort` unchanged, and rounds levels that are missing from the effort map to the closest supported level. `mapReasoningToProviderBudget` maps `'none'` to the minimum reasoning budget, always returns a budget, and uses the default percentage for levels missing from `budgetPercentages`. `OpenAICompatibleChatConfig` adds an optional `mapReasoning` function for mapping the top-level `reasoning` option.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [61a315e]
|
|
20
|
+
- @ai-sdk/provider-utils@5.0.71
|
|
21
|
+
|
|
22
|
+
## 4.0.104
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 01d7a03: feat(openai): add GPT-6.1 Terra model support
|
|
27
|
+
- 599a97f: fix(openai): read transcription duration from `usage` for duration-billed `json` responses
|
|
28
|
+
|
|
29
|
+
`durationInSeconds` now falls back to `usage.seconds` when `usage.type` is `duration` and the response has no top-level `duration` (e.g. `gpt-transcribe` with the default `json` response format).
|
|
30
|
+
|
|
31
|
+
- 8375141: Support streaming transcription with `gpt-live-transcribe` and `gpt-transcribe`. For these models the `language` provider option is sent as a single-entry `languages` list. `gpt-transcribe` warns about and omits `streaming.delay`, which it does not support. `gpt-live-transcribe` rejects non-streaming transcription, since it has no REST endpoint.
|
|
32
|
+
- 7eac057: fix(openai): strip `propertyNames` schemas that omit `type: 'string'` (e.g. Zod 3 records with constrained keys) instead of throwing an unsupported functionality error
|
|
33
|
+
- 436374e: fix(openai): report unfinished web searches as tool errors
|
|
34
|
+
- 9026c7d: fix(openai): only send transcription response format and timestamp defaults when needed
|
|
35
|
+
|
|
36
|
+
Transcription requests no longer send `response_format=verbose_json` or `timestamp_granularities[]=segment` unless the caller sets them or the model needs them. Previously, any `providerOptions.openai` value (such as a `prompt`) caused `verbose_json` to be sent for models like `gpt-transcribe`, which rejected the request.
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [57086ff]
|
|
39
|
+
- Updated dependencies [95348b3]
|
|
40
|
+
- @ai-sdk/provider-utils@5.0.70
|
|
41
|
+
|
|
3
42
|
## 4.0.103
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ type OpenAIConfig = {
|
|
|
45
45
|
type OpenAIDecisionModelId = 'gpt-6-luna' | (string & {});
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region src/chat/openai-chat-language-model-options.d.ts
|
|
48
|
-
type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-6.1-sol' | 'gpt-6-luna' | 'gpt-6-sol' | (string & {});
|
|
48
|
+
type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-6.1-sol' | 'gpt-6.1-terra' | 'gpt-6-luna' | 'gpt-6-sol' | (string & {});
|
|
49
49
|
declare const openaiLanguageModelChatOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
50
50
|
logitBias?: Record<number, number> | undefined;
|
|
51
51
|
logprobs?: number | boolean | undefined;
|
|
@@ -177,7 +177,7 @@ declare const customToolFactory: import("@ai-sdk/provider-utils").ProviderDefine
|
|
|
177
177
|
}, {}>;
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/responses/openai-responses-language-model-options.d.ts
|
|
180
|
-
type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.1-codex-mini' | 'gpt-5.1-codex' | 'gpt-5.1-codex-max' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.2-codex' | 'gpt-5.3-chat-latest' | 'gpt-5.3-codex' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-6.1-sol' | 'gpt-6-luna' | 'gpt-6-sol' | 'gpt-5-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5-codex' | 'gpt-5-mini-2025-08-07' | 'gpt-5-mini' | 'gpt-5-nano-2025-08-07' | 'gpt-5-nano' | 'gpt-5-pro-2025-10-06' | 'gpt-5-pro' | 'gpt-5' | 'o1-2024-12-17' | 'o1' | 'o3-2025-04-16' | 'o3-mini-2025-01-31' | 'o3-mini' | 'o3' | 'o4-mini' | 'o4-mini-2025-04-16' | (string & {});
|
|
180
|
+
type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.1-codex-mini' | 'gpt-5.1-codex' | 'gpt-5.1-codex-max' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.2-codex' | 'gpt-5.3-chat-latest' | 'gpt-5.3-codex' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-6.1-sol' | 'gpt-6.1-terra' | 'gpt-6-luna' | 'gpt-6-sol' | 'gpt-5-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5-codex' | 'gpt-5-mini-2025-08-07' | 'gpt-5-mini' | 'gpt-5-nano-2025-08-07' | 'gpt-5-nano' | 'gpt-5-pro-2025-10-06' | 'gpt-5-pro' | 'gpt-5' | 'o1-2024-12-17' | 'o1' | 'o3-2025-04-16' | 'o3-mini-2025-01-31' | 'o3-mini' | 'o3' | 'o4-mini' | 'o4-mini-2025-04-16' | (string & {});
|
|
181
181
|
declare const openaiLanguageModelResponsesOptionsSchema: import("@ai-sdk/provider-utils").LazySchema<{
|
|
182
182
|
conversation?: string | null | undefined;
|
|
183
183
|
include?: ("reasoning.encrypted_content" | "file_search_call.results" | "web_search_call.results" | "message.output_text.logprobs")[] | null | undefined;
|
|
@@ -1636,7 +1636,7 @@ declare const openaiSpeechModelOptionsSchema: import("@ai-sdk/provider-utils").L
|
|
|
1636
1636
|
type OpenAISpeechModelOptions = InferSchema<typeof openaiSpeechModelOptionsSchema>;
|
|
1637
1637
|
//#endregion
|
|
1638
1638
|
//#region src/transcription/openai-transcription-model-options.d.ts
|
|
1639
|
-
type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-4o-mini-transcribe-2025-03-20' | 'gpt-4o-mini-transcribe-2025-12-15' | 'gpt-4o-transcribe' | 'gpt-4o-transcribe-diarize' | 'gpt-realtime-whisper' | (string & {});
|
|
1639
|
+
type OpenAITranscriptionModelId = 'whisper-1' | 'gpt-4o-mini-transcribe' | 'gpt-4o-mini-transcribe-2025-03-20' | 'gpt-4o-mini-transcribe-2025-12-15' | 'gpt-4o-transcribe' | 'gpt-4o-transcribe-diarize' | 'gpt-live-transcribe' | 'gpt-realtime-whisper' | 'gpt-transcribe' | (string & {});
|
|
1640
1640
|
declare const openAITranscriptionModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
1641
1641
|
include?: string[] | undefined;
|
|
1642
1642
|
language?: string | undefined;
|
|
@@ -1986,6 +1986,7 @@ export declare const VERSION: string;
|
|
|
1986
1986
|
//#region src/openai-decision-model-options.d.ts
|
|
1987
1987
|
declare const openaiDecisionModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
1988
1988
|
safetyIdentifier?: string | undefined;
|
|
1989
|
+
promptCacheKey?: string | undefined;
|
|
1989
1990
|
}>;
|
|
1990
1991
|
type OpenAIDecisionModelOptions = InferSchema<typeof openaiDecisionModelOptions>;
|
|
1991
1992
|
//#endregion
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__tool_apply_patch0.ApplyPatchOperation","_$__tool_custom0.customToolFactory","_$_0.OpenAIComputerAction","_$_0.OpenAIComputerSafetyCheck","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolComparisonFilter","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolCompoundFilter","_$__tool_web_search0.webSearchToolFactory","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4","RealtimeModelV4SessionConfig","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4","RealtimeFactoryV4","DecisionModelV4","SpeechTranslationModelV4","BatchV4","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/openai-config.ts","../src/openai-decision-model.ts","../src/chat/openai-chat-language-model-options.ts","../src/completion/openai-completion-language-model-options.ts","../src/embedding/openai-embedding-model-options.ts","../src/image/openai-image-model-options.ts","../src/tool/apply-patch.ts","../src/tool/custom.ts","../src/responses/openai-responses-language-model-options.ts","../src/responses/openai-responses-api.ts","../src/tool/web-search.ts","../src/openai-tools.ts","../src/live/openai-realtime-model-live-options.ts","../src/realtime/openai-realtime-model.ts","../src/live/openai-realtime-model-live.ts","../src/realtime/openai-realtime-factory.ts","../src/speech/openai-speech-model-options.ts","../src/transcription/openai-transcription-model-options.ts","../src/speech-translation/openai-speech-translation-model-options.ts","../src/openai-provider.ts","../src/responses/openai-responses-prepare-tools.ts","../src/speech-translation/openai-speech-translation-model.ts","../src/files/openai-files-options.ts","../src/tool/computer.ts","../src/responses/openai-responses-provider-metadata.ts","../src/version.ts","../src/openai-decision-model-options.ts"],"mappings":";;;;KAKK,gBAAgB;KAMT;EACV;;EAEA;EACA;EACA,MAAM;IAAW;IAAiB;;EAClC,gBAAgB;EAChB,QAAQ;EACR,YAAY;EACZ;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;EASA;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__tool_apply_patch0.ApplyPatchOperation","_$__tool_custom0.customToolFactory","_$_0.OpenAIComputerAction","_$_0.OpenAIComputerSafetyCheck","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolComparisonFilter","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolCompoundFilter","_$__tool_web_search0.webSearchToolFactory","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4","RealtimeModelV4SessionConfig","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4","RealtimeFactoryV4","DecisionModelV4","SpeechTranslationModelV4","BatchV4","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/openai-config.ts","../src/openai-decision-model.ts","../src/chat/openai-chat-language-model-options.ts","../src/completion/openai-completion-language-model-options.ts","../src/embedding/openai-embedding-model-options.ts","../src/image/openai-image-model-options.ts","../src/tool/apply-patch.ts","../src/tool/custom.ts","../src/responses/openai-responses-language-model-options.ts","../src/responses/openai-responses-api.ts","../src/tool/web-search.ts","../src/openai-tools.ts","../src/live/openai-realtime-model-live-options.ts","../src/realtime/openai-realtime-model.ts","../src/live/openai-realtime-model-live.ts","../src/realtime/openai-realtime-factory.ts","../src/speech/openai-speech-model-options.ts","../src/transcription/openai-transcription-model-options.ts","../src/speech-translation/openai-speech-translation-model-options.ts","../src/openai-provider.ts","../src/responses/openai-responses-prepare-tools.ts","../src/speech-translation/openai-speech-translation-model.ts","../src/files/openai-files-options.ts","../src/tool/computer.ts","../src/responses/openai-responses-provider-metadata.ts","../src/version.ts","../src/openai-decision-model-options.ts"],"mappings":";;;;KAKK,gBAAgB;KAMT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cAIX,wCAAwCE;WAsBxC,SAAS;mBACD;WAtBV;UAED,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B,SAAS;IACT,QAAQ;MACT;MAIG;EAKO,YAAA,SAAS,gCACD,QAAQ;EAGrB,SACJ,SAASD,qDACR,QAAQ,QAAQ,WAAWC;;;;cC5DnB,2DAAwB;;;;KAczB,qBAAqB,mBAAmB;;;cCd9C,yBAAiB,EAAA;;;;GAKnB,EAAA,KAAA;cAEE,4BAAoB,EAAA,uBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDtB,EAAA,KAAA;KAkCQ,uBAAuB,EAAE,MACnC,kBAAkB;KAER,4BAA4B,EAAE,MACxC,kBAAkB;;;KC9Ff,uBAAuB,mBAAmB;KAE1C,gDAAgD,QACnD;EACE;;KAGQ;EACV;EACA,WAAW,MAAM;EACjB;EACA;;KAGU;EACV;EACA;;KAGU;EACV,QAAQ;;KAGE;EACV,QAAQ;;KAGE;EACV;EACA;EACA;EACA;IACM;;IAEA;IACA;;;KAII;EACV,QAAQ;;KAGE;EACV;EACA;EACA;;KAGU;EACV,QAAQ;;KAGE;EACV;EACA;EACA,cAAc,MAAM;;KAGV;EACV,QAAQ;;KAGE;EAEN;EACA;;EAGA;EACA;EACA;;EAGA;EACA;EACA;;EAGA;EACA;EACA;;KAGM;EACV,QAAQ;;;;qBCzFG;;;cCKA,6DAA0B;;;;KAU3B,6BAA6B,mBAChC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, deleteFromApi, detectMediaType, downloadBlob, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isFullMediaType, isNonNullable, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mediaTypeToExtension, normalizeBatchRequestCounts, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateBaseURL, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
1
|
+
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, deleteFromApi, detectMediaType, downloadBlob, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isFullMediaType, isNonNullable, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateBaseURL, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { APICallError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError, isJSONObject } from "@ai-sdk/provider";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
//#region src/openai-config.ts
|
|
@@ -29,9 +29,11 @@ const openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
29
29
|
});
|
|
30
30
|
//#endregion
|
|
31
31
|
//#region src/openai-decision-model-options.ts
|
|
32
|
-
const openaiDecisionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
33
|
-
/** An opaque end-user identifier for safety monitoring, up to 128 characters. */
|
|
34
|
-
safetyIdentifier: z.string().max(128).optional()
|
|
32
|
+
const openaiDecisionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
33
|
+
/** An opaque end-user identifier for safety monitoring, up to 128 characters. */
|
|
34
|
+
safetyIdentifier: z.string().max(128).optional(),
|
|
35
|
+
promptCacheKey: z.string().optional()
|
|
36
|
+
})));
|
|
35
37
|
//#endregion
|
|
36
38
|
//#region src/openai-decision-model.ts
|
|
37
39
|
const probability = () => z.number().min(0).max(1);
|
|
@@ -121,6 +123,7 @@ var DecisionOpenAIModel = class DecisionOpenAIModel {
|
|
|
121
123
|
body: {
|
|
122
124
|
model: this.modelId,
|
|
123
125
|
safety_identifier: openaiOptions?.safetyIdentifier,
|
|
126
|
+
prompt_cache_key: openaiOptions?.promptCacheKey,
|
|
124
127
|
input: [{
|
|
125
128
|
role: "user",
|
|
126
129
|
content: state.map((part) => {
|
|
@@ -128,7 +131,10 @@ var DecisionOpenAIModel = class DecisionOpenAIModel {
|
|
|
128
131
|
type: "input_text",
|
|
129
132
|
text: part.text
|
|
130
133
|
};
|
|
131
|
-
if (part.type === "json") return {
|
|
134
|
+
if (part.type === "json") return isInputJsonData(part.value) ? {
|
|
135
|
+
type: "input_json",
|
|
136
|
+
data: part.value
|
|
137
|
+
} : {
|
|
132
138
|
type: "input_text",
|
|
133
139
|
text: JSON.stringify(part.value)
|
|
134
140
|
};
|
|
@@ -240,7 +246,7 @@ var DecisionOpenAIModel = class DecisionOpenAIModel {
|
|
|
240
246
|
type: "unsupported",
|
|
241
247
|
feature: "reasoning"
|
|
242
248
|
}] : [],
|
|
243
|
-
...Object.keys(providerOptions?.openai ?? {}).filter((option) => option
|
|
249
|
+
...Object.keys(providerOptions?.openai ?? {}).filter((option) => !SUPPORTED_PROVIDER_OPTIONS.has(option)).map((option) => ({
|
|
244
250
|
type: "unsupported",
|
|
245
251
|
feature: `providerOptions.openai.${option}`
|
|
246
252
|
}))
|
|
@@ -257,28 +263,60 @@ var DecisionOpenAIModel = class DecisionOpenAIModel {
|
|
|
257
263
|
};
|
|
258
264
|
}
|
|
259
265
|
};
|
|
266
|
+
const SUPPORTED_PROVIDER_OPTIONS = /* @__PURE__ */ new Set(["safetyIdentifier", "promptCacheKey"]);
|
|
260
267
|
function toText(input) {
|
|
261
268
|
return typeof input === "string" ? input : JSON.stringify(input);
|
|
262
269
|
}
|
|
270
|
+
const INPUT_JSON_MAX_DEPTH = 32;
|
|
271
|
+
const INPUT_JSON_MAX_VALUES = 1e4;
|
|
272
|
+
const INPUT_JSON_MAX_BYTES = 262144;
|
|
273
|
+
function isInputJsonData(value) {
|
|
274
|
+
return (Array.isArray(value) ? value.length > 0 && value.every(isJSONObject$1) : isJSONObject$1(value)) && fitsInputJsonLimits(value);
|
|
275
|
+
}
|
|
276
|
+
function fitsInputJsonLimits(value) {
|
|
277
|
+
let count = 0;
|
|
278
|
+
const visit = (node, depth) => {
|
|
279
|
+
count += 1;
|
|
280
|
+
if (count > INPUT_JSON_MAX_VALUES) return false;
|
|
281
|
+
if (node === null || typeof node !== "object") return true;
|
|
282
|
+
if (depth > INPUT_JSON_MAX_DEPTH) return false;
|
|
283
|
+
return (Array.isArray(node) ? node : Object.values(node)).every((child) => visit(child, depth + 1));
|
|
284
|
+
};
|
|
285
|
+
return visit(value, 1) && new TextEncoder().encode(JSON.stringify(value)).length <= INPUT_JSON_MAX_BYTES;
|
|
286
|
+
}
|
|
287
|
+
function isJSONObject$1(value) {
|
|
288
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
289
|
+
}
|
|
263
290
|
//#endregion
|
|
264
291
|
//#region src/openai-language-model-capabilities.ts
|
|
292
|
+
const ALL_OPENAI_REASONING_EFFORTS = [
|
|
293
|
+
"none",
|
|
294
|
+
"minimal",
|
|
295
|
+
"low",
|
|
296
|
+
"medium",
|
|
297
|
+
"high",
|
|
298
|
+
"xhigh",
|
|
299
|
+
"max"
|
|
300
|
+
];
|
|
265
301
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
266
302
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
267
303
|
const gptVersion = getGptVersion(modelId);
|
|
268
304
|
const isGptChatModel = gptVersion?.minor == null && (gptVersion?.variant?.startsWith("chat") ?? false);
|
|
269
305
|
const isGptNanoModel = gptVersion?.variant?.startsWith("nano") ?? false;
|
|
270
306
|
const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
|
|
271
|
-
const
|
|
307
|
+
const isStandardGpt5Model = gptVersion?.major === 5 && (gptVersion.variant == null || /^(?:(?:mini|nano|sol|luna|terra)(?:-\d{4}-\d{2}-\d{2})?|\d{4}-\d{2}-\d{2})$/.test(gptVersion.variant));
|
|
308
|
+
const isGpt6OrLaterModelWithNoneEffort = modelId === "gpt-6-sol" || modelId === "gpt-6-luna" || modelId === "gpt-6.1-terra";
|
|
272
309
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
273
310
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
274
311
|
const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
275
|
-
const supportsNonReasoningParameters =
|
|
312
|
+
const supportsNonReasoningParameters = isGpt6OrLaterModelWithNoneEffort || !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && (gptVersion.minor ?? 0) >= 1);
|
|
313
|
+
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
276
314
|
return {
|
|
277
315
|
supportsFlexProcessing,
|
|
278
316
|
supportsPriorityProcessing,
|
|
279
317
|
supportsConfigurationUpdate: isGpt6OrLaterModel,
|
|
280
318
|
supportsAsyncToolCalling: isGpt6OrLaterModel,
|
|
281
|
-
supportedReasoningEfforts:
|
|
319
|
+
supportedReasoningEfforts: isGpt6OrLaterModelWithNoneEffort ? [
|
|
282
320
|
"none",
|
|
283
321
|
"low",
|
|
284
322
|
"medium",
|
|
@@ -291,12 +329,42 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
291
329
|
"high",
|
|
292
330
|
"xhigh",
|
|
293
331
|
"max"
|
|
294
|
-
] : void 0,
|
|
332
|
+
] : isStandardGpt5Model ? getGpt5ReasoningEfforts(gptVersion.minor ?? 0) : void 0,
|
|
333
|
+
supportsChatFunctionToolsWithReasoning: !(gptVersion?.major === 5 && (gptVersion.minor ?? 0) >= 6),
|
|
295
334
|
isReasoningModel,
|
|
296
|
-
systemMessageMode
|
|
335
|
+
systemMessageMode,
|
|
297
336
|
supportsNonReasoningParameters
|
|
298
337
|
};
|
|
299
338
|
}
|
|
339
|
+
function getGpt5ReasoningEfforts(minor) {
|
|
340
|
+
if (minor === 0) return [
|
|
341
|
+
"minimal",
|
|
342
|
+
"low",
|
|
343
|
+
"medium",
|
|
344
|
+
"high"
|
|
345
|
+
];
|
|
346
|
+
if (minor === 1) return [
|
|
347
|
+
"none",
|
|
348
|
+
"low",
|
|
349
|
+
"medium",
|
|
350
|
+
"high"
|
|
351
|
+
];
|
|
352
|
+
if (minor < 6) return [
|
|
353
|
+
"none",
|
|
354
|
+
"low",
|
|
355
|
+
"medium",
|
|
356
|
+
"high",
|
|
357
|
+
"xhigh"
|
|
358
|
+
];
|
|
359
|
+
return [
|
|
360
|
+
"none",
|
|
361
|
+
"low",
|
|
362
|
+
"medium",
|
|
363
|
+
"high",
|
|
364
|
+
"xhigh",
|
|
365
|
+
"max"
|
|
366
|
+
];
|
|
367
|
+
}
|
|
300
368
|
function getOSeriesVersion(modelId) {
|
|
301
369
|
const match = /^o(\d+)(?:-|$)/.exec(modelId);
|
|
302
370
|
return match == null ? void 0 : Number(match[1]);
|
|
@@ -310,6 +378,21 @@ function getGptVersion(modelId) {
|
|
|
310
378
|
variant: match[3]
|
|
311
379
|
};
|
|
312
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Resolves the reasoning effort to send to OpenAI.
|
|
383
|
+
*
|
|
384
|
+
* A reasoning effort from provider options is sent unchanged. Otherwise the
|
|
385
|
+
* top-level reasoning value is mapped to the closest effort that the model
|
|
386
|
+
* family supports, or sent directly when the supported efforts are not known.
|
|
387
|
+
*/
|
|
388
|
+
function resolveOpenAIReasoningEffort({ providerReasoningEffort, reasoning, supportedReasoningEfforts, warnings }) {
|
|
389
|
+
return mapReasoningToProviderEffort({
|
|
390
|
+
reasoning,
|
|
391
|
+
providerOptionsEffort: providerReasoningEffort,
|
|
392
|
+
effortMap: Object.fromEntries((supportedReasoningEfforts ?? ALL_OPENAI_REASONING_EFFORTS).map((effort) => [effort, effort])),
|
|
393
|
+
warnings
|
|
394
|
+
});
|
|
395
|
+
}
|
|
313
396
|
//#endregion
|
|
314
397
|
//#region src/openai-stream-error.ts
|
|
315
398
|
/**
|
|
@@ -1004,7 +1087,7 @@ function normalizeOpenAIJsonSchema(schema) {
|
|
|
1004
1087
|
function normalizeSchema(schema, isRoot = false) {
|
|
1005
1088
|
const propertyNames = schema.propertyNames;
|
|
1006
1089
|
if (propertyNames != null) {
|
|
1007
|
-
if (typeof propertyNames === "boolean" || propertyNames.type !== "string") throw new UnsupportedFunctionalityError({ functionality: "JSON Schema propertyNames that does not use a string schema" });
|
|
1090
|
+
if (typeof propertyNames === "boolean" || propertyNames.type != null && propertyNames.type !== "string") throw new UnsupportedFunctionalityError({ functionality: "JSON Schema propertyNames that does not use a string schema" });
|
|
1008
1091
|
removedPropertyNames = true;
|
|
1009
1092
|
}
|
|
1010
1093
|
const normalizedSchema = { ...schema };
|
|
@@ -1182,15 +1265,18 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1182
1265
|
schema: openaiLanguageModelChatOptions
|
|
1183
1266
|
}) ?? {};
|
|
1184
1267
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
1185
|
-
|
|
1186
|
-
if (
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1268
|
+
const requiresNoReasoningEffort = !modelCapabilities.supportsChatFunctionToolsWithReasoning && openaiOptions.reasoningEffort == null && (tools?.some((tool) => tool.type === "function") ?? false);
|
|
1269
|
+
if (requiresNoReasoningEffort && isCustomReasoning(reasoning) && reasoning !== "none") warnings.push({
|
|
1270
|
+
type: "compatibility",
|
|
1271
|
+
feature: "reasoning",
|
|
1272
|
+
details: `${this.modelId} does not support function tools with reasoning in the Chat Completions API. reasoning effort set to "none". Use the Responses API to combine reasoning with function tools.`
|
|
1273
|
+
});
|
|
1274
|
+
const resolvedReasoningEffort = requiresNoReasoningEffort ? "none" : resolveOpenAIReasoningEffort({
|
|
1275
|
+
providerReasoningEffort: openaiOptions.reasoningEffort,
|
|
1276
|
+
reasoning,
|
|
1277
|
+
supportedReasoningEfforts: modelCapabilities.supportedReasoningEfforts?.filter((effort) => effort !== "max"),
|
|
1278
|
+
warnings
|
|
1279
|
+
});
|
|
1194
1280
|
const isReasoningModel = openaiOptions.forceReasoning ?? modelCapabilities.isReasoningModel;
|
|
1195
1281
|
if (topK != null) warnings.push({
|
|
1196
1282
|
type: "unsupported",
|
|
@@ -1245,7 +1331,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1245
1331
|
safety_identifier: openaiOptions.safetyIdentifier,
|
|
1246
1332
|
messages
|
|
1247
1333
|
};
|
|
1248
|
-
if (modelCapabilities.
|
|
1334
|
+
if (modelCapabilities.supportsConfigurationUpdate && baseArgs.prompt_cache_retention != null) {
|
|
1249
1335
|
baseArgs.prompt_cache_retention = void 0;
|
|
1250
1336
|
warnings.push({
|
|
1251
1337
|
type: "unsupported",
|
|
@@ -6281,15 +6367,12 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6281
6367
|
providerOptions,
|
|
6282
6368
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6283
6369
|
});
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
});
|
|
6291
|
-
resolvedReasoningEffort = void 0;
|
|
6292
|
-
}
|
|
6370
|
+
const resolvedReasoningEffort = resolveOpenAIReasoningEffort({
|
|
6371
|
+
providerReasoningEffort: openaiOptions?.reasoningEffort,
|
|
6372
|
+
reasoning,
|
|
6373
|
+
supportedReasoningEfforts: modelCapabilities.supportedReasoningEfforts,
|
|
6374
|
+
warnings
|
|
6375
|
+
});
|
|
6293
6376
|
const resolvedReasoningSummary = openaiOptions?.reasoningSummary !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
6294
6377
|
const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.isReasoningModel;
|
|
6295
6378
|
if (openaiOptions?.conversation && openaiOptions?.previousResponseId) warnings.push({
|
|
@@ -6352,7 +6435,8 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6352
6435
|
outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
|
|
6353
6436
|
});
|
|
6354
6437
|
warnings.push(...inputWarnings);
|
|
6355
|
-
const
|
|
6438
|
+
const supportedReasoningEfforts = modelCapabilities.supportedReasoningEfforts;
|
|
6439
|
+
const getUpdateEffortUnsupportedReason = (effort) => effort != null && supportedReasoningEfforts?.includes(effort) === false ? `${modelId} only supports the following reasoning efforts: ${supportedReasoningEfforts.join(", ")}` : void 0;
|
|
6356
6440
|
for (const item of input) if (item.type === "configuration_update") {
|
|
6357
6441
|
const unsupportedReason = getUpdateEffortUnsupportedReason(item.reasoning.effort);
|
|
6358
6442
|
if (unsupportedReason != null) throw new UnsupportedFunctionalityError({
|
|
@@ -6468,7 +6552,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6468
6552
|
details: "topP is not supported for reasoning models"
|
|
6469
6553
|
});
|
|
6470
6554
|
}
|
|
6471
|
-
if (modelCapabilities.
|
|
6555
|
+
if (modelCapabilities.supportsConfigurationUpdate && (baseArgs.top_logprobs != null || baseArgs.include?.includes("message.output_text.logprobs"))) {
|
|
6472
6556
|
baseArgs.top_logprobs = void 0;
|
|
6473
6557
|
const filteredInclude = baseArgs.include?.filter((value) => value !== "message.output_text.logprobs");
|
|
6474
6558
|
baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
|
|
@@ -6791,10 +6875,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6791
6875
|
type: "tool-result",
|
|
6792
6876
|
toolCallId: part.id,
|
|
6793
6877
|
toolName: toolNameMapping.toCustomToolName(webSearchToolName ?? "web_search"),
|
|
6794
|
-
...part
|
|
6795
|
-
isError: true,
|
|
6796
|
-
result: { status: part.status }
|
|
6797
|
-
} : { result: mapWebSearchOutput(part.action) }
|
|
6878
|
+
...mapWebSearchResult(part)
|
|
6798
6879
|
});
|
|
6799
6880
|
if (part.action?.type === "search") {
|
|
6800
6881
|
for (const source of part.action.sources ?? []) if (source.type === "url") content.push({
|
|
@@ -7405,10 +7486,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7405
7486
|
type: "tool-result",
|
|
7406
7487
|
toolCallId: value.item.id,
|
|
7407
7488
|
toolName: toolNameMapping.toCustomToolName(webSearchToolName ?? "web_search"),
|
|
7408
|
-
...value.item
|
|
7409
|
-
isError: true,
|
|
7410
|
-
result: { status: value.item.status }
|
|
7411
|
-
} : { result: mapWebSearchOutput(value.item.action) }
|
|
7489
|
+
...mapWebSearchResult(value.item)
|
|
7412
7490
|
});
|
|
7413
7491
|
if (value.item.action?.type === "search") {
|
|
7414
7492
|
for (const source of value.item.action.sources ?? []) if (source.type === "url") {
|
|
@@ -8024,6 +8102,12 @@ function isResponseInProgressChunk(chunk) {
|
|
|
8024
8102
|
function isResponseOutputChunk(chunk) {
|
|
8025
8103
|
return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
8026
8104
|
}
|
|
8105
|
+
function mapWebSearchResult({ action, status }) {
|
|
8106
|
+
return status === "completed" ? { result: mapWebSearchOutput(action) } : {
|
|
8107
|
+
isError: true,
|
|
8108
|
+
result: { status }
|
|
8109
|
+
};
|
|
8110
|
+
}
|
|
8027
8111
|
function mapWebSearchOutput(action) {
|
|
8028
8112
|
if (action == null) return {};
|
|
8029
8113
|
switch (action.type) {
|
|
@@ -8536,10 +8620,7 @@ async function convertOpenAIBatchResult(body) {
|
|
|
8536
8620
|
type: "tool-result",
|
|
8537
8621
|
toolCallId: part.id,
|
|
8538
8622
|
toolName: "web_search",
|
|
8539
|
-
...part
|
|
8540
|
-
isError: true,
|
|
8541
|
-
result: { status: part.status }
|
|
8542
|
-
} : { result: mapWebSearchOutput(part.action) },
|
|
8623
|
+
...mapWebSearchResult(part),
|
|
8543
8624
|
dynamic: true
|
|
8544
8625
|
});
|
|
8545
8626
|
break;
|
|
@@ -9545,9 +9626,9 @@ const openAITranscriptionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
9545
9626
|
temperature: z.number().min(0).max(1).default(0).optional(),
|
|
9546
9627
|
/**
|
|
9547
9628
|
* The timestamp granularities to populate for this transcription.
|
|
9548
|
-
*
|
|
9629
|
+
* Defaults to ['segment'] when the response format is verbose_json.
|
|
9549
9630
|
*/
|
|
9550
|
-
timestampGranularities: z.array(z.enum(["word", "segment"])).
|
|
9631
|
+
timestampGranularities: z.array(z.enum(["word", "segment"])).optional(),
|
|
9551
9632
|
/**
|
|
9552
9633
|
* The format of the transcription response.
|
|
9553
9634
|
*/
|
|
@@ -9566,7 +9647,7 @@ const openAITranscriptionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
9566
9647
|
silenceDurationMs: z.number().int().min(0).optional()
|
|
9567
9648
|
})]).optional(),
|
|
9568
9649
|
/**
|
|
9569
|
-
* Options for streaming transcription models such as `gpt-
|
|
9650
|
+
* Options for streaming transcription models such as `gpt-live-transcribe`.
|
|
9570
9651
|
*/
|
|
9571
9652
|
streaming: z.object({
|
|
9572
9653
|
/**
|
|
@@ -9588,12 +9669,32 @@ const openAITranscriptionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
9588
9669
|
//#endregion
|
|
9589
9670
|
//#region src/transcription/openai-transcription-model.ts
|
|
9590
9671
|
/**
|
|
9591
|
-
*
|
|
9592
|
-
*
|
|
9593
|
-
|
|
9672
|
+
* Whether `modelId` is `base` or one of its dated snapshots
|
|
9673
|
+
* (e.g. `gpt-realtime-whisper-2026-01-01`).
|
|
9674
|
+
*/
|
|
9675
|
+
function isModelOrSnapshot(modelId, base) {
|
|
9676
|
+
return modelId === base || modelId.startsWith(`${base}-`);
|
|
9677
|
+
}
|
|
9678
|
+
/**
|
|
9679
|
+
* Model IDs that stream over the realtime transcription WebSocket and do not
|
|
9680
|
+
* support the REST transcription endpoint.
|
|
9594
9681
|
*/
|
|
9595
9682
|
function isRealtimeTranscriptionModelId(modelId) {
|
|
9596
|
-
return modelId
|
|
9683
|
+
return isModelOrSnapshot(modelId, "gpt-realtime-whisper") || isModelOrSnapshot(modelId, "gpt-live-transcribe");
|
|
9684
|
+
}
|
|
9685
|
+
/**
|
|
9686
|
+
* Model IDs that support streaming transcription. `gpt-transcribe` also
|
|
9687
|
+
* supports the REST transcription endpoint.
|
|
9688
|
+
*/
|
|
9689
|
+
function supportsStreamingTranscription(modelId) {
|
|
9690
|
+
return isRealtimeTranscriptionModelId(modelId) || isModelOrSnapshot(modelId, "gpt-transcribe");
|
|
9691
|
+
}
|
|
9692
|
+
/**
|
|
9693
|
+
* Models whose realtime transcription session takes a `languages` list
|
|
9694
|
+
* instead of the singular `language` field.
|
|
9695
|
+
*/
|
|
9696
|
+
function usesLanguagesList(modelId) {
|
|
9697
|
+
return isModelOrSnapshot(modelId, "gpt-live-transcribe") || isModelOrSnapshot(modelId, "gpt-transcribe");
|
|
9597
9698
|
}
|
|
9598
9699
|
const languageMap = {
|
|
9599
9700
|
afrikaans: "af",
|
|
@@ -9687,24 +9788,22 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
9687
9788
|
formData.append("model", this.modelId);
|
|
9688
9789
|
const fileExtension = mediaTypeToExtension(mediaType);
|
|
9689
9790
|
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
9690
|
-
if (this.modelId === "whisper-1") formData.append("response_format", "verbose_json");
|
|
9691
9791
|
const isDiarizationModel = this.modelId === "gpt-4o-transcribe-diarize";
|
|
9792
|
+
const responseFormat = openAIOptions?.responseFormat ?? (isDiarizationModel ? "diarized_json" : this.modelId === "whisper-1" ? "verbose_json" : void 0);
|
|
9793
|
+
const timestampGranularities = openAIOptions?.timestampGranularities ?? (responseFormat === "verbose_json" ? ["segment"] : void 0);
|
|
9692
9794
|
const chunkingStrategy = openAIOptions?.chunkingStrategy ?? (isDiarizationModel ? "auto" : void 0);
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
};
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
else formData.append(key, String(value));
|
|
9706
|
-
}
|
|
9707
|
-
} else if (isDiarizationModel) formData.append("response_format", "diarized_json");
|
|
9795
|
+
const transcriptionModelOptions = {
|
|
9796
|
+
response_format: responseFormat,
|
|
9797
|
+
include: openAIOptions?.include,
|
|
9798
|
+
language: openAIOptions?.language,
|
|
9799
|
+
prompt: openAIOptions?.prompt,
|
|
9800
|
+
temperature: openAIOptions?.temperature,
|
|
9801
|
+
timestamp_granularities: timestampGranularities
|
|
9802
|
+
};
|
|
9803
|
+
for (const [key, value] of Object.entries(transcriptionModelOptions)) if (value != null) {
|
|
9804
|
+
if (Array.isArray(value)) for (const item of value) formData.append(`${key}[]`, String(item));
|
|
9805
|
+
else formData.append(key, String(value));
|
|
9806
|
+
}
|
|
9708
9807
|
if (chunkingStrategy != null) formData.append("chunking_strategy", typeof chunkingStrategy === "string" ? chunkingStrategy : JSON.stringify({
|
|
9709
9808
|
type: chunkingStrategy.type,
|
|
9710
9809
|
...chunkingStrategy.threshold != null && { threshold: chunkingStrategy.threshold },
|
|
@@ -9751,7 +9850,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
9751
9850
|
endSecond: word.end
|
|
9752
9851
|
})) ?? [],
|
|
9753
9852
|
language,
|
|
9754
|
-
durationInSeconds: response.duration ?? void 0,
|
|
9853
|
+
durationInSeconds: response.duration ?? (response.usage?.type === "duration" && typeof response.usage.seconds === "number" ? response.usage.seconds : void 0),
|
|
9755
9854
|
warnings,
|
|
9756
9855
|
...response.usage != null && { usage: response.usage },
|
|
9757
9856
|
response: {
|
|
@@ -9767,7 +9866,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
9767
9866
|
};
|
|
9768
9867
|
}
|
|
9769
9868
|
async doStream(options) {
|
|
9770
|
-
if (!
|
|
9869
|
+
if (!supportsStreamingTranscription(this.modelId)) throw new UnsupportedFunctionalityError({ functionality: `streaming transcription with ${this.modelId}` });
|
|
9771
9870
|
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
9772
9871
|
const openAIOptions = await parseProviderOptions({
|
|
9773
9872
|
provider: "openai",
|
|
@@ -9786,11 +9885,18 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
9786
9885
|
feature: `providerOptions.openai.${option}`,
|
|
9787
9886
|
details: `OpenAI streaming transcription does not support ${option}.`
|
|
9788
9887
|
});
|
|
9888
|
+
const supportsDelay = !isModelOrSnapshot(this.modelId, "gpt-transcribe");
|
|
9889
|
+
if (!supportsDelay && openAIOptions?.streaming?.delay != null) warnings.push({
|
|
9890
|
+
type: "unsupported",
|
|
9891
|
+
feature: "providerOptions.openai.streaming.delay",
|
|
9892
|
+
details: `OpenAI streaming transcription with ${this.modelId} does not support delay.`
|
|
9893
|
+
});
|
|
9789
9894
|
const headers = combineHeaders(this.config.headers?.(), options.headers);
|
|
9790
9895
|
const sessionUpdate = buildOpenAIRealtimeTranscriptionSession({
|
|
9791
9896
|
modelId: this.modelId,
|
|
9792
9897
|
inputAudioFormat: options.inputAudioFormat,
|
|
9793
|
-
providerOptions: openAIOptions
|
|
9898
|
+
providerOptions: openAIOptions,
|
|
9899
|
+
supportsDelay
|
|
9794
9900
|
});
|
|
9795
9901
|
return {
|
|
9796
9902
|
request: { body: sessionUpdate },
|
|
@@ -9925,7 +10031,7 @@ function createOpenAIRealtimeTranscriptionStream({ webSocket, url, headers, sess
|
|
|
9925
10031
|
}
|
|
9926
10032
|
});
|
|
9927
10033
|
}
|
|
9928
|
-
function buildOpenAIRealtimeTranscriptionSession({ modelId, inputAudioFormat, providerOptions }) {
|
|
10034
|
+
function buildOpenAIRealtimeTranscriptionSession({ modelId, inputAudioFormat, providerOptions, supportsDelay }) {
|
|
9929
10035
|
return {
|
|
9930
10036
|
type: "session.update",
|
|
9931
10037
|
session: {
|
|
@@ -9937,8 +10043,8 @@ function buildOpenAIRealtimeTranscriptionSession({ modelId, inputAudioFormat, pr
|
|
|
9937
10043
|
},
|
|
9938
10044
|
transcription: {
|
|
9939
10045
|
model: modelId,
|
|
9940
|
-
...providerOptions?.language != null ? { language: providerOptions.language } : {},
|
|
9941
|
-
...providerOptions?.streaming?.delay != null ? { delay: providerOptions.streaming.delay } : {}
|
|
10046
|
+
...providerOptions?.language != null ? usesLanguagesList(modelId) ? { languages: [providerOptions.language] } : { language: providerOptions.language } : {},
|
|
10047
|
+
...supportsDelay && providerOptions?.streaming?.delay != null ? { delay: providerOptions.streaming.delay } : {}
|
|
9942
10048
|
},
|
|
9943
10049
|
turn_detection: null
|
|
9944
10050
|
} },
|
|
@@ -10252,7 +10358,7 @@ var OpenAISkills = class {
|
|
|
10252
10358
|
};
|
|
10253
10359
|
//#endregion
|
|
10254
10360
|
//#region src/version.ts
|
|
10255
|
-
const VERSION = "4.0.
|
|
10361
|
+
const VERSION = "4.0.105";
|
|
10256
10362
|
//#endregion
|
|
10257
10363
|
//#region src/openai-provider.ts
|
|
10258
10364
|
/**
|