@ai-sdk/openai 4.0.0-beta.12 → 4.0.0-beta.15
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 +23 -0
- package/dist/index.d.mts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +66 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -28
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +24 -2
- package/dist/internal/index.d.ts +24 -2
- package/dist/internal/index.js +65 -27
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +67 -27
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +2 -0
- package/package.json +3 -3
- package/src/chat/openai-chat-language-model.ts +10 -2
- package/src/chat/openai-chat-options.ts +4 -0
- package/src/openai-language-model-capabilities.ts +2 -2
- package/src/responses/openai-responses-api.ts +25 -0
- package/src/responses/openai-responses-language-model.ts +29 -4
- package/src/responses/openai-responses-options.ts +8 -0
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
createEventSourceResponseHandler,
|
|
16
16
|
createJsonResponseHandler,
|
|
17
17
|
generateId,
|
|
18
|
+
isCustomReasoning,
|
|
18
19
|
isParsableJson,
|
|
19
20
|
parseProviderOptions,
|
|
20
21
|
postJsonToApi
|
|
@@ -42,7 +43,7 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
42
43
|
// src/openai-language-model-capabilities.ts
|
|
43
44
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
44
45
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
45
|
-
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5
|
|
46
|
+
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") && !modelId.startsWith("gpt-5.4-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
46
47
|
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
47
48
|
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4");
|
|
48
49
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
@@ -662,9 +663,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
662
663
|
seed,
|
|
663
664
|
tools,
|
|
664
665
|
toolChoice,
|
|
666
|
+
reasoning,
|
|
665
667
|
providerOptions
|
|
666
668
|
}) {
|
|
667
|
-
var _a, _b, _c, _d, _e;
|
|
669
|
+
var _a, _b, _c, _d, _e, _f;
|
|
668
670
|
const warnings = [];
|
|
669
671
|
const openaiOptions = (_a = await parseProviderOptions({
|
|
670
672
|
provider: "openai",
|
|
@@ -672,18 +674,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
672
674
|
schema: openaiLanguageModelChatOptions
|
|
673
675
|
})) != null ? _a : {};
|
|
674
676
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
675
|
-
const
|
|
677
|
+
const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
|
|
678
|
+
const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
|
|
676
679
|
if (topK != null) {
|
|
677
680
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
678
681
|
}
|
|
679
682
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
680
683
|
{
|
|
681
684
|
prompt,
|
|
682
|
-
systemMessageMode: (
|
|
685
|
+
systemMessageMode: (_d = openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
|
|
683
686
|
}
|
|
684
687
|
);
|
|
685
688
|
warnings.push(...messageWarnings);
|
|
686
|
-
const strictJsonSchema = (
|
|
689
|
+
const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
687
690
|
const baseArgs = {
|
|
688
691
|
// model id:
|
|
689
692
|
model: this.modelId,
|
|
@@ -704,7 +707,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
704
707
|
json_schema: {
|
|
705
708
|
schema: responseFormat.schema,
|
|
706
709
|
strict: strictJsonSchema,
|
|
707
|
-
name: (
|
|
710
|
+
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
708
711
|
description: responseFormat.description
|
|
709
712
|
}
|
|
710
713
|
} : { type: "json_object" } : void 0,
|
|
@@ -717,7 +720,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
717
720
|
store: openaiOptions.store,
|
|
718
721
|
metadata: openaiOptions.metadata,
|
|
719
722
|
prediction: openaiOptions.prediction,
|
|
720
|
-
reasoning_effort:
|
|
723
|
+
reasoning_effort: resolvedReasoningEffort,
|
|
721
724
|
service_tier: openaiOptions.serviceTier,
|
|
722
725
|
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
723
726
|
prompt_cache_retention: openaiOptions.promptCacheRetention,
|
|
@@ -726,7 +729,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
726
729
|
messages
|
|
727
730
|
};
|
|
728
731
|
if (isReasoningModel) {
|
|
729
|
-
if (
|
|
732
|
+
if (resolvedReasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
|
|
730
733
|
if (baseArgs.temperature != null) {
|
|
731
734
|
baseArgs.temperature = void 0;
|
|
732
735
|
warnings.push({
|
|
@@ -2661,6 +2664,7 @@ import {
|
|
|
2661
2664
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
2662
2665
|
createToolNameMapping,
|
|
2663
2666
|
generateId as generateId2,
|
|
2667
|
+
isCustomReasoning as isCustomReasoning2,
|
|
2664
2668
|
parseProviderOptions as parseProviderOptions5,
|
|
2665
2669
|
postJsonToApi as postJsonToApi5
|
|
2666
2670
|
} from "@ai-sdk/provider-utils";
|
|
@@ -3396,6 +3400,23 @@ var openaiResponsesChunkSchema = lazySchema19(
|
|
|
3396
3400
|
service_tier: z21.string().nullish()
|
|
3397
3401
|
})
|
|
3398
3402
|
}),
|
|
3403
|
+
z21.object({
|
|
3404
|
+
type: z21.literal("response.failed"),
|
|
3405
|
+
response: z21.object({
|
|
3406
|
+
error: z21.object({
|
|
3407
|
+
code: z21.string().nullish(),
|
|
3408
|
+
message: z21.string()
|
|
3409
|
+
}).nullish(),
|
|
3410
|
+
incomplete_details: z21.object({ reason: z21.string() }).nullish(),
|
|
3411
|
+
usage: z21.object({
|
|
3412
|
+
input_tokens: z21.number(),
|
|
3413
|
+
input_tokens_details: z21.object({ cached_tokens: z21.number().nullish() }).nullish(),
|
|
3414
|
+
output_tokens: z21.number(),
|
|
3415
|
+
output_tokens_details: z21.object({ reasoning_tokens: z21.number().nullish() }).nullish()
|
|
3416
|
+
}).nullish(),
|
|
3417
|
+
service_tier: z21.string().nullish()
|
|
3418
|
+
})
|
|
3419
|
+
}),
|
|
3399
3420
|
z21.object({
|
|
3400
3421
|
type: z21.literal("response.created"),
|
|
3401
3422
|
response: z21.object({
|
|
@@ -4228,6 +4249,10 @@ var openaiResponsesReasoningModelIds = [
|
|
|
4228
4249
|
"gpt-5.3-codex",
|
|
4229
4250
|
"gpt-5.4",
|
|
4230
4251
|
"gpt-5.4-2026-03-05",
|
|
4252
|
+
"gpt-5.4-mini",
|
|
4253
|
+
"gpt-5.4-mini-2026-03-17",
|
|
4254
|
+
"gpt-5.4-nano",
|
|
4255
|
+
"gpt-5.4-nano-2026-03-17",
|
|
4231
4256
|
"gpt-5.4-pro",
|
|
4232
4257
|
"gpt-5.4-pro-2026-03-05"
|
|
4233
4258
|
];
|
|
@@ -4733,12 +4758,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4733
4758
|
frequencyPenalty,
|
|
4734
4759
|
seed,
|
|
4735
4760
|
prompt,
|
|
4761
|
+
reasoning,
|
|
4736
4762
|
providerOptions,
|
|
4737
4763
|
tools,
|
|
4738
4764
|
toolChoice,
|
|
4739
4765
|
responseFormat
|
|
4740
4766
|
}) {
|
|
4741
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4767
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4742
4768
|
const warnings = [];
|
|
4743
4769
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
4744
4770
|
if (topK != null) {
|
|
@@ -4769,7 +4795,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4769
4795
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
4770
4796
|
});
|
|
4771
4797
|
}
|
|
4772
|
-
const
|
|
4798
|
+
const resolvedReasoningEffort = (_a = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a : isCustomReasoning2(reasoning) ? reasoning : void 0;
|
|
4799
|
+
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
4773
4800
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
4774
4801
|
warnings.push({
|
|
4775
4802
|
type: "unsupported",
|
|
@@ -4806,10 +4833,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4806
4833
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
4807
4834
|
prompt,
|
|
4808
4835
|
toolNameMapping,
|
|
4809
|
-
systemMessageMode: (
|
|
4836
|
+
systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
|
|
4810
4837
|
providerOptionsName,
|
|
4811
4838
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
4812
|
-
store: (
|
|
4839
|
+
store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
|
|
4813
4840
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
4814
4841
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
4815
4842
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
@@ -4817,7 +4844,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4817
4844
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
4818
4845
|
});
|
|
4819
4846
|
warnings.push(...inputWarnings);
|
|
4820
|
-
const strictJsonSchema = (
|
|
4847
|
+
const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
4821
4848
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
4822
4849
|
function addInclude(key) {
|
|
4823
4850
|
if (include == null) {
|
|
@@ -4833,9 +4860,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4833
4860
|
if (topLogprobs) {
|
|
4834
4861
|
addInclude("message.output_text.logprobs");
|
|
4835
4862
|
}
|
|
4836
|
-
const webSearchToolName = (
|
|
4863
|
+
const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
|
|
4837
4864
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
4838
|
-
)) == null ? void 0 :
|
|
4865
|
+
)) == null ? void 0 : _f.name;
|
|
4839
4866
|
if (webSearchToolName) {
|
|
4840
4867
|
addInclude("web_search_call.action.sources");
|
|
4841
4868
|
}
|
|
@@ -4858,7 +4885,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4858
4885
|
format: responseFormat.schema != null ? {
|
|
4859
4886
|
type: "json_schema",
|
|
4860
4887
|
strict: strictJsonSchema,
|
|
4861
|
-
name: (
|
|
4888
|
+
name: (_g = responseFormat.name) != null ? _g : "response",
|
|
4862
4889
|
description: responseFormat.description,
|
|
4863
4890
|
schema: responseFormat.schema
|
|
4864
4891
|
} : { type: "json_object" }
|
|
@@ -4892,10 +4919,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4892
4919
|
}))
|
|
4893
4920
|
},
|
|
4894
4921
|
// model-specific settings:
|
|
4895
|
-
...isReasoningModel && (
|
|
4922
|
+
...isReasoningModel && (resolvedReasoningEffort != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
4896
4923
|
reasoning: {
|
|
4897
|
-
...
|
|
4898
|
-
effort:
|
|
4924
|
+
...resolvedReasoningEffort != null && {
|
|
4925
|
+
effort: resolvedReasoningEffort
|
|
4899
4926
|
},
|
|
4900
4927
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
|
|
4901
4928
|
summary: openaiOptions.reasoningSummary
|
|
@@ -4904,7 +4931,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4904
4931
|
}
|
|
4905
4932
|
};
|
|
4906
4933
|
if (isReasoningModel) {
|
|
4907
|
-
if (!(
|
|
4934
|
+
if (!(resolvedReasoningEffort === "none" && modelCapabilities.supportsNonReasoningParameters)) {
|
|
4908
4935
|
if (baseArgs.temperature != null) {
|
|
4909
4936
|
baseArgs.temperature = void 0;
|
|
4910
4937
|
warnings.push({
|
|
@@ -4954,9 +4981,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4954
4981
|
});
|
|
4955
4982
|
delete baseArgs.service_tier;
|
|
4956
4983
|
}
|
|
4957
|
-
const shellToolEnvType = (
|
|
4984
|
+
const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
|
|
4958
4985
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
4959
|
-
)) == null ? void 0 :
|
|
4986
|
+
)) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
|
|
4960
4987
|
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
4961
4988
|
return {
|
|
4962
4989
|
webSearchToolName,
|
|
@@ -5512,7 +5539,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5512
5539
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5513
5540
|
},
|
|
5514
5541
|
transform(chunk, controller) {
|
|
5515
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
|
|
5542
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
|
|
5516
5543
|
if (options.includeRawChunks) {
|
|
5517
5544
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5518
5545
|
}
|
|
@@ -6249,13 +6276,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6249
6276
|
if (typeof value.response.service_tier === "string") {
|
|
6250
6277
|
serviceTier = value.response.service_tier;
|
|
6251
6278
|
}
|
|
6279
|
+
} else if (isResponseFailedChunk(value)) {
|
|
6280
|
+
const incompleteReason = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason;
|
|
6281
|
+
finishReason = {
|
|
6282
|
+
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
6283
|
+
finishReason: incompleteReason,
|
|
6284
|
+
hasFunctionCall
|
|
6285
|
+
}) : "error",
|
|
6286
|
+
raw: incompleteReason != null ? incompleteReason : "error"
|
|
6287
|
+
};
|
|
6288
|
+
usage = (_z = value.response.usage) != null ? _z : void 0;
|
|
6252
6289
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
6253
6290
|
ongoingAnnotations.push(value.annotation);
|
|
6254
6291
|
if (value.annotation.type === "url_citation") {
|
|
6255
6292
|
controller.enqueue({
|
|
6256
6293
|
type: "source",
|
|
6257
6294
|
sourceType: "url",
|
|
6258
|
-
id: (
|
|
6295
|
+
id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId2(),
|
|
6259
6296
|
url: value.annotation.url,
|
|
6260
6297
|
title: value.annotation.title
|
|
6261
6298
|
});
|
|
@@ -6263,7 +6300,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6263
6300
|
controller.enqueue({
|
|
6264
6301
|
type: "source",
|
|
6265
6302
|
sourceType: "document",
|
|
6266
|
-
id: (
|
|
6303
|
+
id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId2(),
|
|
6267
6304
|
mediaType: "text/plain",
|
|
6268
6305
|
title: value.annotation.filename,
|
|
6269
6306
|
filename: value.annotation.filename,
|
|
@@ -6279,7 +6316,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6279
6316
|
controller.enqueue({
|
|
6280
6317
|
type: "source",
|
|
6281
6318
|
sourceType: "document",
|
|
6282
|
-
id: (
|
|
6319
|
+
id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
|
|
6283
6320
|
mediaType: "text/plain",
|
|
6284
6321
|
title: value.annotation.filename,
|
|
6285
6322
|
filename: value.annotation.filename,
|
|
@@ -6295,7 +6332,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6295
6332
|
controller.enqueue({
|
|
6296
6333
|
type: "source",
|
|
6297
6334
|
sourceType: "document",
|
|
6298
|
-
id: (
|
|
6335
|
+
id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
|
|
6299
6336
|
mediaType: "application/octet-stream",
|
|
6300
6337
|
title: value.annotation.file_id,
|
|
6301
6338
|
filename: value.annotation.file_id,
|
|
@@ -6343,6 +6380,9 @@ function isResponseOutputItemDoneChunk(chunk) {
|
|
|
6343
6380
|
function isResponseFinishedChunk(chunk) {
|
|
6344
6381
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
6345
6382
|
}
|
|
6383
|
+
function isResponseFailedChunk(chunk) {
|
|
6384
|
+
return chunk.type === "response.failed";
|
|
6385
|
+
}
|
|
6346
6386
|
function isResponseCreatedChunk(chunk) {
|
|
6347
6387
|
return chunk.type === "response.created";
|
|
6348
6388
|
}
|
|
@@ -6769,7 +6809,7 @@ var OpenAITranscriptionModel = class {
|
|
|
6769
6809
|
};
|
|
6770
6810
|
|
|
6771
6811
|
// src/version.ts
|
|
6772
|
-
var VERSION = true ? "4.0.0-beta.
|
|
6812
|
+
var VERSION = true ? "4.0.0-beta.15" : "0.0.0-test";
|
|
6773
6813
|
|
|
6774
6814
|
// src/openai-provider.ts
|
|
6775
6815
|
function createOpenAI(options = {}) {
|