@ai-sdk/openai 4.0.109 → 4.0.111
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 +35 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +206 -68
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +316 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +195 -67
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +68 -0
- package/package.json +3 -3
- package/src/chat/map-openai-finish-reason.ts +11 -4
- package/src/chat/openai-chat-api.ts +36 -0
- package/src/chat/openai-chat-language-model.ts +120 -20
- package/src/completion/openai-completion-language-model.ts +11 -13
- package/src/image/openai-image-model-options.ts +68 -57
- package/src/internal/index.ts +2 -0
- package/src/openai-batch.ts +8 -0
- package/src/responses/map-openai-responses-finish-reason.ts +7 -1
- package/src/responses/openai-responses-api.ts +71 -48
- package/src/responses/openai-responses-language-model.ts +62 -12
- package/src/speech/openai-speech-model-options.ts +11 -6
- package/src/transcription/openai-transcription-model-options.ts +71 -70
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.111
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6400cf8: Add `resolveProviderOptions` to parse provider options that a model accepts under several `providerOptions` keys, either as aliases (`first`) or merged in order (`merge`), and use it for the existing multi-key lookups in the OpenAI, OpenAI-compatible, Anthropic, Google, and Amazon Bedrock models. Resolution behavior for these models is unchanged.
|
|
8
|
+
- Updated dependencies [6400cf8]
|
|
9
|
+
- Updated dependencies [f608c05]
|
|
10
|
+
- Updated dependencies [cab9c1f]
|
|
11
|
+
- Updated dependencies [c70adf6]
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.76
|
|
13
|
+
- @ai-sdk/provider@4.0.37
|
|
14
|
+
|
|
15
|
+
## 4.0.110
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- c6efa4b: Refactor Azure model ID logic into a model catalog that declares capabilities and provider options, and generate provider capability documentation from it. Export the OpenAI catalog internally for Azure to reuse. Request behavior is unchanged.
|
|
20
|
+
- f6dbf04: fix(openai): surface Chat Completions refusals as text content
|
|
21
|
+
|
|
22
|
+
The Chat Completions model ignored `message.refusal` (non-streaming) and `delta.refusal` (streaming). When the model refused to answer, `content` was `null`, so the AI SDK returned empty text with a `stop` finish reason and silently dropped the refusal. Refusal text is now emitted as text content in both `generateText` and `streamText` results, and it is emitted in addition to content when the API returns both. A refusal with a `stop` finish reason is now reported as a `content-filter` finish reason, matching the Anthropic provider and the Responses API.
|
|
23
|
+
|
|
24
|
+
- 646a7e3: fix(openai,openai-compatible): surface refusal logprobs and openai-compatible refusals
|
|
25
|
+
|
|
26
|
+
`@ai-sdk/openai`: Chat Completions responses that contain a refusal can return `logprobs.refusal` next to `logprobs.content`. The provider previously read only `logprobs.content`, so `providerMetadata.openai.logprobs` was empty or missing for refusals. Refusal logprobs are now included in emission order (content logprobs followed by refusal logprobs) in both `generateText` and `streamText`.
|
|
27
|
+
|
|
28
|
+
Streaming logprobs are now collected across all chunks in `streamText`: previously only the logprobs of the last streamed chunk were reported. This applies to content logprobs as well, so `providerMetadata.openai.logprobs` now contains the logprobs of every streamed token instead of only the last chunk's tokens. Explicitly empty logprobs (`logprobs: { content: [], refusal: null }`) are reported as an empty array, as before.
|
|
29
|
+
|
|
30
|
+
A refusal that arrives in the same streamed chunk as the `finish_reason` is now taken into account: such a response is reported with a `content-filter` finish reason instead of `stop`.
|
|
31
|
+
|
|
32
|
+
`@ai-sdk/openai-compatible`: Chat Completions responses that carry `message.refusal` (non-streaming) or `delta.refusal` (streaming) were ignored, so providers such as OpenAI served through `createOpenAICompatible` lost the refusal text and reported an empty `stop` response. Refusals are now returned as text content after any content text, and a non-empty refusal with a `stop` finish reason is reported as a `content-filter` finish reason. This also applies when the refusal and the finish reason arrive in the same streamed chunk. Non-string refusals (for example `refusal: false` from servers that use booleans) are ignored instead of failing the response.
|
|
33
|
+
|
|
34
|
+
- 6b97088: fix(openai): handle refusal content parts in the Responses API
|
|
35
|
+
|
|
36
|
+
The Responses API returns a `refusal` content part instead of `output_text` when the model declines a request. The response schema rejected these parts, so non-streaming calls failed with an `APICallError` ("Invalid JSON response"), and streamed `response.refusal.delta` / `response.refusal.done` events were dropped, producing empty text. Refusal content parts and stream events are now parsed: the refusal explanation is surfaced as text and the finish reason is mapped to `content-filter`. When the response also contains a client-side function call, the finish reason stays `tool-calls` so the tools are still executed.
|
|
37
|
+
|
|
3
38
|
## 4.0.109
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -297,6 +297,18 @@ declare const openaiResponsesChunkSchema: import("@ai-sdk/provider-utils").LazyS
|
|
|
297
297
|
logprob: number;
|
|
298
298
|
}[];
|
|
299
299
|
}[] | null | undefined;
|
|
300
|
+
} | {
|
|
301
|
+
type: "response.refusal.delta";
|
|
302
|
+
item_id: string;
|
|
303
|
+
delta: string;
|
|
304
|
+
output_index?: number | null | undefined;
|
|
305
|
+
content_index?: number | null | undefined;
|
|
306
|
+
} | {
|
|
307
|
+
type: "response.refusal.done";
|
|
308
|
+
item_id: string;
|
|
309
|
+
refusal: string;
|
|
310
|
+
output_index?: number | null | undefined;
|
|
311
|
+
content_index?: number | null | undefined;
|
|
300
312
|
} | {
|
|
301
313
|
type: "response.completed" | "response.incomplete";
|
|
302
314
|
response: {
|
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","RealtimeModelV4SessionIntent","RealtimeModelV4ServerConnection","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4","RealtimeModelV4SessionIntent","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/openai-model-catalog.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":";;;;KAMK,gBAAgB;KAMT;EACV;;EAEA;EACA;EACA,MAAM;IAAW;IAAiB;;EAClC,UAAU,WAAW;EACrB,QAAQ;EACR,YAAY;EACZ;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;EASA;;;;KCZU;;;KCxBA;cAuEC,iEAA8B;;;;;;;;;;;;;;;;;;;;;;;KAwJ/B,iCAAiC,mBACpC;cAGI,mEAAgC;EAAA;;KASjC,mCAAmC,mBACtC;;;KC7OG;cAKC,uEAAoC;;cAApC;;;;;KAiDD,uCAAuC,mBAC1C;;;KCxDG;cAMC,8DAA2B;;;;KAkB5B,8BAA8B,mBACjC;;;KCrBG;cAmFC,0DAAuB;;;;;;;;;KAIxB,0BAA0B,mBAC7B;
|
|
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","RealtimeModelV4SessionIntent","RealtimeModelV4ServerConnection","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4","RealtimeModelV4SessionIntent","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/openai-model-catalog.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":";;;;KAMK,gBAAgB;KAMT;EACV;;EAEA;EACA;EACA,MAAM;IAAW;IAAiB;;EAClC,UAAU,WAAW;EACrB,QAAQ;EACR,YAAY;EACZ;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;EASA;;;;KCZU;;;KCxBA;cAuEC,iEAA8B;;;;;;;;;;;;;;;;;;;;;;;KAwJ/B,iCAAiC,mBACpC;cAGI,mEAAgC;EAAA;;KASjC,mCAAmC,mBACtC;;;KC7OG;cAKC,uEAAoC;;cAApC;;;;;KAiDD,uCAAuC,mBAC1C;;;KCxDG;cAMC,8DAA2B;;;;KAkB5B,8BAA8B,mBACjC;;;KCrBG;cAmFC,0DAAuB;;;;;;;;;KAIxB,0BAA0B,mBAC7B;cA2CI,oEAAiC;;;;;;;;;;;;;KAIlC,oCAAoC,mBACvC;cA6BI,8DAA2B;;;;;;;;;;;;KAI5B,8BAA8B,mBACjC;;;;;;KC3HG;EAEN;;;;EAIA;;;;EAIA;;EAGA;;;;EAIA;;EAGA;;;;EAIA;;;;EAIA;;;;cCxDO,oDAAiB;;;;EAMZ;;;;;EAMN;;;;;EAOJ;IACE;IACA;IACA;;IAGA;;;;;KCqCE;cAsEC,4EAAyC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoR1C,sCAAsC,mBACzC;cAGI,4EAAyC;EAAA;;KAkB1C,sCAAsC,mBACzC;cAGI,yEAAsC;;;;;;;;;KAmBvC,mCAAmC,mBACtC;;;;;;KCsDG;;;;EAIV;;;;EAKA;;;;EAKA;;;;;KAMU;;;;EAIV;;;;EAKA,SAAS,MACL,gDACA;;cAwWO,6DAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, resolveWith, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, 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, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderOptions, resolveProviderReference, resolveWith, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, 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
|
|
@@ -1396,9 +1396,9 @@ function getResponseMetadata$1({ id, model, created }) {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
//#endregion
|
|
1398
1398
|
//#region src/chat/map-openai-finish-reason.ts
|
|
1399
|
-
function mapOpenAIFinishReason$1(finishReason) {
|
|
1399
|
+
function mapOpenAIFinishReason$1({ finishReason, hasRefusal = false }) {
|
|
1400
1400
|
switch (finishReason) {
|
|
1401
|
-
case "stop": return "stop";
|
|
1401
|
+
case "stop": return hasRefusal ? "content-filter" : "stop";
|
|
1402
1402
|
case "length": return "length";
|
|
1403
1403
|
case "content_filter": return "content-filter";
|
|
1404
1404
|
case "function_call":
|
|
@@ -1416,6 +1416,7 @@ const openaiChatResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
1416
1416
|
message: z.object({
|
|
1417
1417
|
role: z.literal("assistant").nullish(),
|
|
1418
1418
|
content: z.string().nullish(),
|
|
1419
|
+
refusal: z.string().nullish(),
|
|
1419
1420
|
audio: z.object({ transcript: z.string().nullish() }).nullish(),
|
|
1420
1421
|
tool_calls: z.array(z.object({
|
|
1421
1422
|
id: z.string().nullish(),
|
|
@@ -1436,14 +1437,24 @@ const openaiChatResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
1436
1437
|
})).nullish()
|
|
1437
1438
|
}),
|
|
1438
1439
|
index: z.number(),
|
|
1439
|
-
logprobs: z.object({
|
|
1440
|
-
|
|
1441
|
-
logprob: z.number(),
|
|
1442
|
-
top_logprobs: z.array(z.object({
|
|
1440
|
+
logprobs: z.object({
|
|
1441
|
+
content: z.array(z.object({
|
|
1443
1442
|
token: z.string(),
|
|
1444
|
-
logprob: z.number()
|
|
1445
|
-
|
|
1446
|
-
|
|
1443
|
+
logprob: z.number(),
|
|
1444
|
+
top_logprobs: z.array(z.object({
|
|
1445
|
+
token: z.string(),
|
|
1446
|
+
logprob: z.number()
|
|
1447
|
+
}))
|
|
1448
|
+
})).nullish(),
|
|
1449
|
+
refusal: z.array(z.object({
|
|
1450
|
+
token: z.string(),
|
|
1451
|
+
logprob: z.number(),
|
|
1452
|
+
top_logprobs: z.array(z.object({
|
|
1453
|
+
token: z.string(),
|
|
1454
|
+
logprob: z.number()
|
|
1455
|
+
}))
|
|
1456
|
+
})).nullish()
|
|
1457
|
+
}).nullish(),
|
|
1447
1458
|
finish_reason: z.string().nullish()
|
|
1448
1459
|
})),
|
|
1449
1460
|
usage: z.object({
|
|
@@ -1469,6 +1480,7 @@ const openaiChatChunkSchema = lazySchema(() => zodSchema(z.union([z.object({
|
|
|
1469
1480
|
delta: z.object({
|
|
1470
1481
|
role: z.enum(["assistant"]).nullish(),
|
|
1471
1482
|
content: z.string().nullish(),
|
|
1483
|
+
refusal: z.string().nullish(),
|
|
1472
1484
|
tool_calls: z.array(z.object({
|
|
1473
1485
|
index: z.number(),
|
|
1474
1486
|
id: z.string().nullish(),
|
|
@@ -1488,14 +1500,24 @@ const openaiChatChunkSchema = lazySchema(() => zodSchema(z.union([z.object({
|
|
|
1488
1500
|
})
|
|
1489
1501
|
})).nullish()
|
|
1490
1502
|
}).nullish(),
|
|
1491
|
-
logprobs: z.object({
|
|
1492
|
-
|
|
1493
|
-
logprob: z.number(),
|
|
1494
|
-
top_logprobs: z.array(z.object({
|
|
1503
|
+
logprobs: z.object({
|
|
1504
|
+
content: z.array(z.object({
|
|
1495
1505
|
token: z.string(),
|
|
1496
|
-
logprob: z.number()
|
|
1497
|
-
|
|
1498
|
-
|
|
1506
|
+
logprob: z.number(),
|
|
1507
|
+
top_logprobs: z.array(z.object({
|
|
1508
|
+
token: z.string(),
|
|
1509
|
+
logprob: z.number()
|
|
1510
|
+
}))
|
|
1511
|
+
})).nullish(),
|
|
1512
|
+
refusal: z.array(z.object({
|
|
1513
|
+
token: z.string(),
|
|
1514
|
+
logprob: z.number(),
|
|
1515
|
+
top_logprobs: z.array(z.object({
|
|
1516
|
+
token: z.string(),
|
|
1517
|
+
logprob: z.number()
|
|
1518
|
+
}))
|
|
1519
|
+
})).nullish()
|
|
1520
|
+
}).nullish(),
|
|
1499
1521
|
finish_reason: z.string().nullish(),
|
|
1500
1522
|
index: z.number()
|
|
1501
1523
|
})),
|
|
@@ -1725,11 +1747,13 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1725
1747
|
}
|
|
1726
1748
|
async getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions }) {
|
|
1727
1749
|
const warnings = [];
|
|
1728
|
-
const
|
|
1729
|
-
|
|
1750
|
+
const providerOptionsNames = this.config.provider.includes("azure") ? ["openai", "azure"] : ["openai"];
|
|
1751
|
+
const openaiOptions = (await resolveProviderOptions({
|
|
1730
1752
|
providerOptions,
|
|
1753
|
+
namespaces: providerOptionsNames,
|
|
1754
|
+
resolution: "merge",
|
|
1731
1755
|
schema: openaiLanguageModelChatOptions
|
|
1732
|
-
}) ?? {};
|
|
1756
|
+
})).options ?? {};
|
|
1733
1757
|
const { capabilities: { language: modelCapabilities }, requestConfig: { language: modelRequestConfig } } = getOpenAILanguageModelEntry(this.modelId);
|
|
1734
1758
|
const requiresNoReasoningEffort = !modelCapabilities.endpoints.chat.functionToolsWithReasoning && openaiOptions.reasoningEffort == null && (tools?.some((tool) => tool.type === "function") ?? false);
|
|
1735
1759
|
if (requiresNoReasoningEffort && isCustomReasoning(reasoning) && reasoning !== "none") warnings.push({
|
|
@@ -1748,7 +1772,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1748
1772
|
type: "unsupported",
|
|
1749
1773
|
feature: "topK"
|
|
1750
1774
|
});
|
|
1751
|
-
if (providerOptions?.
|
|
1775
|
+
if (providerOptionsNames.some((name) => providerOptions?.[name]?.reasoningSummary != null)) warnings.push({
|
|
1752
1776
|
type: "unsupported",
|
|
1753
1777
|
feature: "reasoningSummary",
|
|
1754
1778
|
details: "reasoningSummary is only supported by the Responses API, not the Chat Completions API"
|
|
@@ -1930,6 +1954,12 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1930
1954
|
type: "text",
|
|
1931
1955
|
text
|
|
1932
1956
|
});
|
|
1957
|
+
const refusal = choice.message.refusal;
|
|
1958
|
+
const hasRefusal = refusal != null && refusal.length > 0;
|
|
1959
|
+
if (hasRefusal) content.push({
|
|
1960
|
+
type: "text",
|
|
1961
|
+
text: refusal
|
|
1962
|
+
});
|
|
1933
1963
|
for (const toolCall of choice.message.tool_calls ?? []) content.push({
|
|
1934
1964
|
type: "tool-call",
|
|
1935
1965
|
toolCallId: toolCall.id || generateId(),
|
|
@@ -1947,11 +1977,16 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
1947
1977
|
const providerMetadata = { openai: {} };
|
|
1948
1978
|
if (completionTokenDetails?.accepted_prediction_tokens != null) providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails?.accepted_prediction_tokens;
|
|
1949
1979
|
if (completionTokenDetails?.rejected_prediction_tokens != null) providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails?.rejected_prediction_tokens;
|
|
1950
|
-
|
|
1980
|
+
const contentLogprobs = choice.logprobs?.content;
|
|
1981
|
+
const refusalLogprobs = choice.logprobs?.refusal;
|
|
1982
|
+
if (contentLogprobs != null || refusalLogprobs != null) providerMetadata.openai.logprobs = [...contentLogprobs ?? [], ...refusalLogprobs ?? []];
|
|
1951
1983
|
return {
|
|
1952
1984
|
content,
|
|
1953
1985
|
finishReason: {
|
|
1954
|
-
unified: mapOpenAIFinishReason$1(
|
|
1986
|
+
unified: mapOpenAIFinishReason$1({
|
|
1987
|
+
finishReason: choice.finish_reason,
|
|
1988
|
+
hasRefusal
|
|
1989
|
+
}),
|
|
1955
1990
|
raw: choice.finish_reason ?? void 0
|
|
1956
1991
|
},
|
|
1957
1992
|
usage: convertOpenAIChatUsage(response.usage),
|
|
@@ -2004,6 +2039,10 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
2004
2039
|
let usage = void 0;
|
|
2005
2040
|
let metadataExtracted = false;
|
|
2006
2041
|
let isActiveText = false;
|
|
2042
|
+
let hasRefusal = false;
|
|
2043
|
+
let rawFinishReason = void 0;
|
|
2044
|
+
let hasLogprobs = false;
|
|
2045
|
+
const streamedLogprobs = [];
|
|
2007
2046
|
const providerMetadata = { openai: {} };
|
|
2008
2047
|
return {
|
|
2009
2048
|
stream: checkedResponse.pipeThrough(new TransformStream({
|
|
@@ -2027,6 +2066,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
2027
2066
|
unified: "error",
|
|
2028
2067
|
raw: void 0
|
|
2029
2068
|
};
|
|
2069
|
+
rawFinishReason = void 0;
|
|
2030
2070
|
controller.enqueue({
|
|
2031
2071
|
type: "error",
|
|
2032
2072
|
error: chunk.error
|
|
@@ -2039,6 +2079,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
2039
2079
|
unified: "error",
|
|
2040
2080
|
raw: void 0
|
|
2041
2081
|
};
|
|
2082
|
+
rawFinishReason = void 0;
|
|
2042
2083
|
controller.enqueue({
|
|
2043
2084
|
type: "error",
|
|
2044
2085
|
error: createOpenAIProviderStreamError(value.error) ?? value.error
|
|
@@ -2061,14 +2102,25 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
2061
2102
|
if (value.usage.completion_tokens_details?.rejected_prediction_tokens != null) providerMetadata.openai.rejectedPredictionTokens = value.usage.completion_tokens_details?.rejected_prediction_tokens;
|
|
2062
2103
|
}
|
|
2063
2104
|
const choice = value.choices[0];
|
|
2064
|
-
if (choice?.finish_reason != null)
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2105
|
+
if (choice?.finish_reason != null) rawFinishReason = choice.finish_reason;
|
|
2106
|
+
if (choice?.logprobs != null) {
|
|
2107
|
+
const contentLogprobs = choice.logprobs.content;
|
|
2108
|
+
const refusalLogprobs = choice.logprobs.refusal;
|
|
2109
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
2110
|
+
hasLogprobs = true;
|
|
2111
|
+
streamedLogprobs.push(...contentLogprobs ?? [], ...refusalLogprobs ?? []);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2069
2114
|
if (choice?.delta == null) return;
|
|
2070
2115
|
const delta = choice.delta;
|
|
2071
|
-
|
|
2116
|
+
const textDeltas = [];
|
|
2117
|
+
if (delta.content != null && delta.content.length > 0) textDeltas.push(delta.content);
|
|
2118
|
+
if (delta.refusal != null && delta.refusal.length > 0) {
|
|
2119
|
+
hasRefusal = true;
|
|
2120
|
+
textDeltas.push(delta.refusal);
|
|
2121
|
+
}
|
|
2122
|
+
if (textDeltas.length === 0 && delta.content === "") textDeltas.push(delta.content);
|
|
2123
|
+
for (const textDelta of textDeltas) {
|
|
2072
2124
|
if (!isActiveText) {
|
|
2073
2125
|
controller.enqueue({
|
|
2074
2126
|
type: "text-start",
|
|
@@ -2079,7 +2131,7 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
2079
2131
|
controller.enqueue({
|
|
2080
2132
|
type: "text-delta",
|
|
2081
2133
|
id: "0",
|
|
2082
|
-
delta:
|
|
2134
|
+
delta: textDelta
|
|
2083
2135
|
});
|
|
2084
2136
|
}
|
|
2085
2137
|
if (delta.tool_calls != null) for (const toolCallDelta of delta.tool_calls) toolCallTracker.processDelta(toolCallDelta);
|
|
@@ -2097,6 +2149,14 @@ var OpenAIChatLanguageModel = class OpenAIChatLanguageModel {
|
|
|
2097
2149
|
id: "0"
|
|
2098
2150
|
});
|
|
2099
2151
|
toolCallTracker.flush();
|
|
2152
|
+
if (rawFinishReason != null) finishReason = {
|
|
2153
|
+
unified: mapOpenAIFinishReason$1({
|
|
2154
|
+
finishReason: rawFinishReason,
|
|
2155
|
+
hasRefusal
|
|
2156
|
+
}),
|
|
2157
|
+
raw: rawFinishReason
|
|
2158
|
+
};
|
|
2159
|
+
if (hasLogprobs) providerMetadata.openai.logprobs = streamedLogprobs;
|
|
2100
2160
|
controller.enqueue({
|
|
2101
2161
|
type: "finish",
|
|
2102
2162
|
finishReason,
|
|
@@ -2117,7 +2177,7 @@ function isOpenAIChatOutputChunk(chunk) {
|
|
|
2117
2177
|
if ("error" in chunk) return false;
|
|
2118
2178
|
return chunk.choices.some((choice) => {
|
|
2119
2179
|
const delta = choice.delta;
|
|
2120
|
-
return delta?.content != null && delta.content.length > 0 || delta?.tool_calls != null && delta.tool_calls.length > 0 || delta?.annotations != null && delta.annotations.length > 0;
|
|
2180
|
+
return delta?.content != null && delta.content.length > 0 || delta?.refusal != null && delta.refusal.length > 0 || delta?.tool_calls != null && delta.tool_calls.length > 0 || delta?.annotations != null && delta.annotations.length > 0;
|
|
2121
2181
|
});
|
|
2122
2182
|
}
|
|
2123
2183
|
//#endregion
|
|
@@ -2303,18 +2363,12 @@ var OpenAICompletionLanguageModel = class OpenAICompletionLanguageModel {
|
|
|
2303
2363
|
}
|
|
2304
2364
|
async getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences: userStopSequences, responseFormat, tools, toolChoice, seed, providerOptions }) {
|
|
2305
2365
|
const warnings = [];
|
|
2306
|
-
const openaiOptions = {
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
...await parseProviderOptions({
|
|
2313
|
-
provider: this.providerOptionsName,
|
|
2314
|
-
providerOptions,
|
|
2315
|
-
schema: openaiLanguageModelCompletionOptions
|
|
2316
|
-
})
|
|
2317
|
-
};
|
|
2366
|
+
const openaiOptions = (await resolveProviderOptions({
|
|
2367
|
+
providerOptions,
|
|
2368
|
+
namespaces: ["openai", this.providerOptionsName],
|
|
2369
|
+
resolution: "merge",
|
|
2370
|
+
schema: openaiLanguageModelCompletionOptions
|
|
2371
|
+
})).options ?? {};
|
|
2318
2372
|
if (topK != null) warnings.push({
|
|
2319
2373
|
type: "unsupported",
|
|
2320
2374
|
feature: "topK"
|
|
@@ -2873,7 +2927,12 @@ const baseImageModelOptionsObject = () => z.object({
|
|
|
2873
2927
|
safetyIdentifier: z.string().max(128).optional()
|
|
2874
2928
|
});
|
|
2875
2929
|
lazySchema(() => zodSchema(baseImageModelOptionsObject()));
|
|
2876
|
-
|
|
2930
|
+
/**
|
|
2931
|
+
* Shape of the OpenAI image generation options. Exported so that routers
|
|
2932
|
+
* that also call the OpenAI image API (e.g. Azure) can accept these options
|
|
2933
|
+
* under their own providerOptions key.
|
|
2934
|
+
*/
|
|
2935
|
+
const openaiImageModelGenerationOptionsShape = () => baseImageModelOptionsObject().extend({
|
|
2877
2936
|
/**
|
|
2878
2937
|
* Style of the generated image. `vivid` produces hyper-real and
|
|
2879
2938
|
* dramatic images; `natural` produces more subdued, less hyper-real
|
|
@@ -2906,8 +2965,13 @@ const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageMo
|
|
|
2906
2965
|
* less restrictive filtering.
|
|
2907
2966
|
*/
|
|
2908
2967
|
moderation: z.enum(["auto", "low"]).optional()
|
|
2909
|
-
})
|
|
2910
|
-
const
|
|
2968
|
+
}).shape;
|
|
2969
|
+
const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(z.object(openaiImageModelGenerationOptionsShape())));
|
|
2970
|
+
/**
|
|
2971
|
+
* Shape of the OpenAI image edit options. Exported so that routers can accept
|
|
2972
|
+
* these options under their own providerOptions key.
|
|
2973
|
+
*/
|
|
2974
|
+
const openaiImageModelEditOptionsShape = () => baseImageModelOptionsObject().extend({
|
|
2911
2975
|
/**
|
|
2912
2976
|
* Fidelity of the output image(s) to the input image(s).
|
|
2913
2977
|
*/
|
|
@@ -2924,7 +2988,8 @@ const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOpt
|
|
|
2924
2988
|
* less restrictive filtering. Supported by GPT Image models.
|
|
2925
2989
|
*/
|
|
2926
2990
|
moderation: z.enum(["auto", "low"]).optional()
|
|
2927
|
-
})
|
|
2991
|
+
}).shape;
|
|
2992
|
+
const openaiImageModelEditOptions = lazySchema(() => zodSchema(z.object(openaiImageModelEditOptionsShape())));
|
|
2928
2993
|
//#endregion
|
|
2929
2994
|
//#region src/image/openai-image-model.ts
|
|
2930
2995
|
var OpenAIImageModel = class OpenAIImageModel {
|
|
@@ -3855,10 +3920,12 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
3855
3920
|
}
|
|
3856
3921
|
//#endregion
|
|
3857
3922
|
//#region src/responses/map-openai-responses-finish-reason.ts
|
|
3858
|
-
function mapOpenAIResponseFinishReason({ finishReason, hasFunctionCall }) {
|
|
3923
|
+
function mapOpenAIResponseFinishReason({ finishReason, hasFunctionCall, hasRefusal = false }) {
|
|
3859
3924
|
switch (finishReason) {
|
|
3860
3925
|
case void 0:
|
|
3861
|
-
case null:
|
|
3926
|
+
case null:
|
|
3927
|
+
if (hasFunctionCall) return "tool-calls";
|
|
3928
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
3862
3929
|
case "max_output_tokens": return "length";
|
|
3863
3930
|
case "content_filter": return "content-filter";
|
|
3864
3931
|
default: return hasFunctionCall ? "tool-calls" : "other";
|
|
@@ -4038,6 +4105,8 @@ const openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
|
4038
4105
|
"response.output_item.done",
|
|
4039
4106
|
"response.output_text.annotation.added",
|
|
4040
4107
|
"response.output_text.delta",
|
|
4108
|
+
"response.refusal.delta",
|
|
4109
|
+
"response.refusal.done",
|
|
4041
4110
|
"response.reasoning_summary_part.added",
|
|
4042
4111
|
"response.reasoning_summary_part.done",
|
|
4043
4112
|
"response.reasoning_summary_text.delta"
|
|
@@ -4091,6 +4160,20 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4091
4160
|
}))
|
|
4092
4161
|
})).nullish()
|
|
4093
4162
|
}),
|
|
4163
|
+
z.object({
|
|
4164
|
+
type: z.literal("response.refusal.delta"),
|
|
4165
|
+
item_id: z.string(),
|
|
4166
|
+
output_index: z.number().nullish(),
|
|
4167
|
+
content_index: z.number().nullish(),
|
|
4168
|
+
delta: z.string()
|
|
4169
|
+
}),
|
|
4170
|
+
z.object({
|
|
4171
|
+
type: z.literal("response.refusal.done"),
|
|
4172
|
+
item_id: z.string(),
|
|
4173
|
+
output_index: z.number().nullish(),
|
|
4174
|
+
content_index: z.number().nullish(),
|
|
4175
|
+
refusal: z.string()
|
|
4176
|
+
}),
|
|
4094
4177
|
z.object({
|
|
4095
4178
|
type: z.enum(["response.completed", "response.incomplete"]),
|
|
4096
4179
|
response: z.object({
|
|
@@ -4648,7 +4731,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
4648
4731
|
role: z.literal("assistant"),
|
|
4649
4732
|
id: z.string(),
|
|
4650
4733
|
phase: z.enum(["commentary", "final_answer"]).nullish(),
|
|
4651
|
-
content: z.array(z.object({
|
|
4734
|
+
content: z.array(z.discriminatedUnion("type", [z.object({
|
|
4652
4735
|
type: z.literal("output_text"),
|
|
4653
4736
|
text: z.string(),
|
|
4654
4737
|
logprobs: z.array(z.object({
|
|
@@ -4687,7 +4770,10 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
4687
4770
|
index: z.number()
|
|
4688
4771
|
})
|
|
4689
4772
|
]))
|
|
4690
|
-
})
|
|
4773
|
+
}), z.object({
|
|
4774
|
+
type: z.literal("refusal"),
|
|
4775
|
+
refusal: z.string()
|
|
4776
|
+
})]))
|
|
4691
4777
|
}),
|
|
4692
4778
|
z.object({
|
|
4693
4779
|
type: z.literal("web_search_call"),
|
|
@@ -6908,14 +6994,10 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6908
6994
|
feature: "stopSequences"
|
|
6909
6995
|
});
|
|
6910
6996
|
const providerOptionsName = config.provider.includes("azure") ? "azure" : "openai";
|
|
6911
|
-
|
|
6912
|
-
provider: providerOptionsName,
|
|
6913
|
-
providerOptions,
|
|
6914
|
-
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6915
|
-
});
|
|
6916
|
-
if (openaiOptions == null && providerOptionsName !== "openai") openaiOptions = await parseProviderOptions({
|
|
6917
|
-
provider: "openai",
|
|
6997
|
+
const { options: openaiOptions } = await resolveProviderOptions({
|
|
6918
6998
|
providerOptions,
|
|
6999
|
+
namespaces: [providerOptionsName, "openai"],
|
|
7000
|
+
resolution: "first",
|
|
6919
7001
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6920
7002
|
});
|
|
6921
7003
|
const resolvedReasoningEffort = resolveOpenAIReasoningEffort({
|
|
@@ -7220,6 +7302,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7220
7302
|
const retrievedFileIds = /* @__PURE__ */ new Set();
|
|
7221
7303
|
let hasFunctionCall = false;
|
|
7222
7304
|
const hostedToolSearchCallIds = [];
|
|
7305
|
+
let hasRefusal = false;
|
|
7223
7306
|
let structuredOutputText;
|
|
7224
7307
|
for (const part of response.output) switch (part.type) {
|
|
7225
7308
|
case "reasoning":
|
|
@@ -7321,8 +7404,20 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7321
7404
|
});
|
|
7322
7405
|
break;
|
|
7323
7406
|
case "message":
|
|
7324
|
-
if (options.responseFormat?.type === "json" && part.phase === "final_answer") structuredOutputText = part.content.map((contentPart) => contentPart.text).join("");
|
|
7407
|
+
if (options.responseFormat?.type === "json" && part.phase === "final_answer") structuredOutputText = part.content.map((contentPart) => contentPart.type === "output_text" ? contentPart.text : contentPart.refusal).join("");
|
|
7325
7408
|
for (const contentPart of part.content) {
|
|
7409
|
+
if (contentPart.type === "refusal") {
|
|
7410
|
+
hasRefusal = true;
|
|
7411
|
+
content.push({
|
|
7412
|
+
type: "text",
|
|
7413
|
+
text: contentPart.refusal,
|
|
7414
|
+
providerMetadata: { [providerOptionsName]: {
|
|
7415
|
+
itemId: part.id,
|
|
7416
|
+
...part.phase != null && { phase: part.phase }
|
|
7417
|
+
} }
|
|
7418
|
+
});
|
|
7419
|
+
continue;
|
|
7420
|
+
}
|
|
7326
7421
|
if (options.providerOptions?.[providerOptionsName]?.logprobs && contentPart.logprobs) logprobs.push(contentPart.logprobs);
|
|
7327
7422
|
const providerMetadata = {
|
|
7328
7423
|
itemId: part.id,
|
|
@@ -7609,7 +7704,8 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7609
7704
|
finishReason: {
|
|
7610
7705
|
unified: mapOpenAIResponseFinishReason({
|
|
7611
7706
|
finishReason: response.incomplete_details?.reason,
|
|
7612
|
-
hasFunctionCall
|
|
7707
|
+
hasFunctionCall,
|
|
7708
|
+
hasRefusal
|
|
7613
7709
|
}),
|
|
7614
7710
|
raw: response.incomplete_details?.reason ?? void 0
|
|
7615
7711
|
},
|
|
@@ -7672,6 +7768,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7672
7768
|
const fallbackAnnotations = [];
|
|
7673
7769
|
let activeMessagePhase;
|
|
7674
7770
|
let hasFunctionCall = false;
|
|
7771
|
+
let hasRefusal = false;
|
|
7675
7772
|
const activeReasoning = {};
|
|
7676
7773
|
const activeOutputItemIds = {};
|
|
7677
7774
|
const resolveOutputItemId = ({ itemId, outputIndex }) => outputIndex == null ? itemId : activeOutputItemIds[outputIndex] ?? itemId;
|
|
@@ -8438,7 +8535,19 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
8438
8535
|
delta: value.delta
|
|
8439
8536
|
});
|
|
8440
8537
|
if (options.providerOptions?.[providerOptionsName]?.logprobs && value.logprobs) logprobs.push(value.logprobs);
|
|
8441
|
-
} else if (value
|
|
8538
|
+
} else if (isRefusalDeltaChunk(value)) {
|
|
8539
|
+
hasRefusal = true;
|
|
8540
|
+
const itemId = resolveOutputItemId({
|
|
8541
|
+
itemId: value.item_id,
|
|
8542
|
+
outputIndex: value.output_index
|
|
8543
|
+
});
|
|
8544
|
+
controller.enqueue({
|
|
8545
|
+
type: "text-delta",
|
|
8546
|
+
id: itemId,
|
|
8547
|
+
delta: value.delta
|
|
8548
|
+
});
|
|
8549
|
+
} else if (isRefusalDoneChunk(value)) hasRefusal = true;
|
|
8550
|
+
else if (value.type === "response.reasoning_summary_part.added") {
|
|
8442
8551
|
const itemId = resolveOutputItemId({
|
|
8443
8552
|
itemId: value.item_id,
|
|
8444
8553
|
outputIndex: value.output_index
|
|
@@ -8496,7 +8605,8 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
8496
8605
|
if (!encounteredStreamError) finishReason = {
|
|
8497
8606
|
unified: mapOpenAIResponseFinishReason({
|
|
8498
8607
|
finishReason: value.response.incomplete_details?.reason,
|
|
8499
|
-
hasFunctionCall
|
|
8608
|
+
hasFunctionCall,
|
|
8609
|
+
hasRefusal
|
|
8500
8610
|
}),
|
|
8501
8611
|
raw: value.response.incomplete_details?.reason ?? void 0
|
|
8502
8612
|
};
|
|
@@ -8586,6 +8696,12 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
8586
8696
|
function isTextDeltaChunk(chunk) {
|
|
8587
8697
|
return chunk.type === "response.output_text.delta";
|
|
8588
8698
|
}
|
|
8699
|
+
function isRefusalDeltaChunk(chunk) {
|
|
8700
|
+
return chunk.type === "response.refusal.delta";
|
|
8701
|
+
}
|
|
8702
|
+
function isRefusalDoneChunk(chunk) {
|
|
8703
|
+
return chunk.type === "response.refusal.done";
|
|
8704
|
+
}
|
|
8589
8705
|
function isOpenAIChatCompletionChunk(value) {
|
|
8590
8706
|
const chunk = asRecord(value);
|
|
8591
8707
|
return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
|
|
@@ -9106,6 +9222,7 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9106
9222
|
const content = [];
|
|
9107
9223
|
const logprobs = [];
|
|
9108
9224
|
let hasFunctionCall = false;
|
|
9225
|
+
let hasRefusal = false;
|
|
9109
9226
|
for (const part of response.output) switch (part.type) {
|
|
9110
9227
|
case "reasoning": {
|
|
9111
9228
|
const summaries = part.summary.length > 0 ? part.summary : [{
|
|
@@ -9124,6 +9241,14 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9124
9241
|
}
|
|
9125
9242
|
case "message":
|
|
9126
9243
|
for (const contentPart of part.content) {
|
|
9244
|
+
if (contentPart.type === "refusal") {
|
|
9245
|
+
hasRefusal = true;
|
|
9246
|
+
content.push({
|
|
9247
|
+
type: "text",
|
|
9248
|
+
text: contentPart.refusal
|
|
9249
|
+
});
|
|
9250
|
+
continue;
|
|
9251
|
+
}
|
|
9127
9252
|
content.push({
|
|
9128
9253
|
type: "text",
|
|
9129
9254
|
text: contentPart.text
|
|
@@ -9242,7 +9367,8 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9242
9367
|
finishReason: {
|
|
9243
9368
|
unified: mapOpenAIResponseFinishReason({
|
|
9244
9369
|
finishReason: response.incomplete_details?.reason,
|
|
9245
|
-
hasFunctionCall
|
|
9370
|
+
hasFunctionCall,
|
|
9371
|
+
hasRefusal
|
|
9246
9372
|
}),
|
|
9247
9373
|
raw: response.incomplete_details?.reason ?? void 0
|
|
9248
9374
|
},
|
|
@@ -10121,10 +10247,16 @@ function createOpenAIRealtimeFactory(config) {
|
|
|
10121
10247
|
}
|
|
10122
10248
|
//#endregion
|
|
10123
10249
|
//#region src/speech/openai-speech-model-options.ts
|
|
10124
|
-
|
|
10250
|
+
/**
|
|
10251
|
+
* Shape of the OpenAI speech model options. Exported so that routers that
|
|
10252
|
+
* also call the OpenAI speech API (e.g. Azure) can accept these options under
|
|
10253
|
+
* their own providerOptions key.
|
|
10254
|
+
*/
|
|
10255
|
+
const openaiSpeechModelOptionsShape = () => ({
|
|
10125
10256
|
instructions: z.string().nullish(),
|
|
10126
10257
|
speed: z.number().min(.25).max(4).nullish()
|
|
10127
|
-
})
|
|
10258
|
+
});
|
|
10259
|
+
const openaiSpeechModelOptionsSchema = lazySchema(() => zodSchema(z.object(openaiSpeechModelOptionsShape())));
|
|
10128
10260
|
//#endregion
|
|
10129
10261
|
//#region src/speech/openai-speech-model.ts
|
|
10130
10262
|
var OpenAISpeechModel = class OpenAISpeechModel {
|
|
@@ -10258,7 +10390,12 @@ const openaiTranscriptionResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
10258
10390
|
})));
|
|
10259
10391
|
//#endregion
|
|
10260
10392
|
//#region src/transcription/openai-transcription-model-options.ts
|
|
10261
|
-
|
|
10393
|
+
/**
|
|
10394
|
+
* Shape of the OpenAI transcription model options. Exported so that routers
|
|
10395
|
+
* that also call the OpenAI transcription API (e.g. Azure) can accept these
|
|
10396
|
+
* options under their own providerOptions key.
|
|
10397
|
+
*/
|
|
10398
|
+
const openAITranscriptionModelOptionsShape = () => ({
|
|
10262
10399
|
/**
|
|
10263
10400
|
* Additional information to include in the transcription response.
|
|
10264
10401
|
*/
|
|
@@ -10327,7 +10464,8 @@ const openAITranscriptionModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
10327
10464
|
*/
|
|
10328
10465
|
include: z.array(z.string()).optional()
|
|
10329
10466
|
}).optional()
|
|
10330
|
-
})
|
|
10467
|
+
});
|
|
10468
|
+
const openAITranscriptionModelOptions = lazySchema(() => zodSchema(z.object(openAITranscriptionModelOptionsShape())));
|
|
10331
10469
|
//#endregion
|
|
10332
10470
|
//#region src/transcription/openai-transcription-model.ts
|
|
10333
10471
|
const languageMap = {
|
|
@@ -11009,7 +11147,7 @@ var OpenAISkills = class {
|
|
|
11009
11147
|
};
|
|
11010
11148
|
//#endregion
|
|
11011
11149
|
//#region src/version.ts
|
|
11012
|
-
const VERSION = "4.0.
|
|
11150
|
+
const VERSION = "4.0.111";
|
|
11013
11151
|
//#endregion
|
|
11014
11152
|
//#region src/openai-provider.ts
|
|
11015
11153
|
/**
|