@ai-sdk/openai 3.0.0-beta.50 → 3.0.0-beta.52
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 +12 -0
- package/dist/index.js +119 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -60
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +118 -59
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +118 -59
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -71,6 +71,15 @@ var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
|
71
71
|
errorToMessage: (data) => data.error.message
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
+
// src/openai-is-reasoning-model.ts
|
|
75
|
+
function isReasoningModel(modelId) {
|
|
76
|
+
if (modelId.startsWith("gpt-3")) return false;
|
|
77
|
+
if (modelId.startsWith("gpt-4")) return false;
|
|
78
|
+
if (modelId.startsWith("chatgpt-4o")) return false;
|
|
79
|
+
if (modelId.startsWith("gpt-5-chat")) return false;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
// src/chat/convert-to-openai-chat-messages.ts
|
|
75
84
|
var import_provider = require("@ai-sdk/provider");
|
|
76
85
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
@@ -1072,9 +1081,6 @@ var OpenAIChatLanguageModel = class {
|
|
|
1072
1081
|
};
|
|
1073
1082
|
}
|
|
1074
1083
|
};
|
|
1075
|
-
function isReasoningModel(modelId) {
|
|
1076
|
-
return (modelId.startsWith("o") || modelId.startsWith("gpt-5")) && !modelId.startsWith("gpt-5-chat");
|
|
1077
|
-
}
|
|
1078
1084
|
function supportsFlexProcessing(modelId) {
|
|
1079
1085
|
return modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
1080
1086
|
}
|
|
@@ -1082,32 +1088,8 @@ function supportsPriorityProcessing(modelId) {
|
|
|
1082
1088
|
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
1083
1089
|
}
|
|
1084
1090
|
function getSystemMessageMode(modelId) {
|
|
1085
|
-
|
|
1086
|
-
if (!isReasoningModel(modelId)) {
|
|
1087
|
-
return "system";
|
|
1088
|
-
}
|
|
1089
|
-
return (_b = (_a = reasoningModels[modelId]) == null ? void 0 : _a.systemMessageMode) != null ? _b : "developer";
|
|
1091
|
+
return isReasoningModel(modelId) ? "developer" : "system";
|
|
1090
1092
|
}
|
|
1091
|
-
var reasoningModels = {
|
|
1092
|
-
o3: {
|
|
1093
|
-
systemMessageMode: "developer"
|
|
1094
|
-
},
|
|
1095
|
-
"o3-2025-04-16": {
|
|
1096
|
-
systemMessageMode: "developer"
|
|
1097
|
-
},
|
|
1098
|
-
"o3-mini": {
|
|
1099
|
-
systemMessageMode: "developer"
|
|
1100
|
-
},
|
|
1101
|
-
"o3-mini-2025-01-31": {
|
|
1102
|
-
systemMessageMode: "developer"
|
|
1103
|
-
},
|
|
1104
|
-
"o4-mini": {
|
|
1105
|
-
systemMessageMode: "developer"
|
|
1106
|
-
},
|
|
1107
|
-
"o4-mini-2025-04-16": {
|
|
1108
|
-
systemMessageMode: "developer"
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
1093
|
|
|
1112
1094
|
// src/completion/openai-completion-language-model.ts
|
|
1113
1095
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
@@ -2702,6 +2684,20 @@ var openaiResponsesChunkSchema = (0, import_provider_utils21.lazySchema)(
|
|
|
2702
2684
|
start_index: import_v414.z.number().nullish(),
|
|
2703
2685
|
end_index: import_v414.z.number().nullish(),
|
|
2704
2686
|
quote: import_v414.z.string().nullish()
|
|
2687
|
+
}),
|
|
2688
|
+
import_v414.z.object({
|
|
2689
|
+
type: import_v414.z.literal("container_file_citation"),
|
|
2690
|
+
container_id: import_v414.z.string(),
|
|
2691
|
+
file_id: import_v414.z.string(),
|
|
2692
|
+
filename: import_v414.z.string().nullish(),
|
|
2693
|
+
start_index: import_v414.z.number().nullish(),
|
|
2694
|
+
end_index: import_v414.z.number().nullish(),
|
|
2695
|
+
index: import_v414.z.number().nullish()
|
|
2696
|
+
}),
|
|
2697
|
+
import_v414.z.object({
|
|
2698
|
+
type: import_v414.z.literal("file_path"),
|
|
2699
|
+
file_id: import_v414.z.string(),
|
|
2700
|
+
index: import_v414.z.number().nullish()
|
|
2705
2701
|
})
|
|
2706
2702
|
])
|
|
2707
2703
|
}),
|
|
@@ -2787,7 +2783,18 @@ var openaiResponsesResponseSchema = (0, import_provider_utils21.lazySchema)(
|
|
|
2787
2783
|
quote: import_v414.z.string().nullish()
|
|
2788
2784
|
}),
|
|
2789
2785
|
import_v414.z.object({
|
|
2790
|
-
type: import_v414.z.literal("container_file_citation")
|
|
2786
|
+
type: import_v414.z.literal("container_file_citation"),
|
|
2787
|
+
container_id: import_v414.z.string(),
|
|
2788
|
+
file_id: import_v414.z.string(),
|
|
2789
|
+
filename: import_v414.z.string().nullish(),
|
|
2790
|
+
start_index: import_v414.z.number().nullish(),
|
|
2791
|
+
end_index: import_v414.z.number().nullish(),
|
|
2792
|
+
index: import_v414.z.number().nullish()
|
|
2793
|
+
}),
|
|
2794
|
+
import_v414.z.object({
|
|
2795
|
+
type: import_v414.z.literal("file_path"),
|
|
2796
|
+
file_id: import_v414.z.string(),
|
|
2797
|
+
index: import_v414.z.number().nullish()
|
|
2791
2798
|
})
|
|
2792
2799
|
])
|
|
2793
2800
|
)
|
|
@@ -3603,7 +3610,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3603
3610
|
};
|
|
3604
3611
|
}
|
|
3605
3612
|
async doGenerate(options) {
|
|
3606
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
3613
|
+
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;
|
|
3607
3614
|
const {
|
|
3608
3615
|
args: body,
|
|
3609
3616
|
warnings,
|
|
@@ -3701,13 +3708,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3701
3708
|
if (((_c = (_b = options.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
|
|
3702
3709
|
logprobs.push(contentPart.logprobs);
|
|
3703
3710
|
}
|
|
3711
|
+
const providerMetadata2 = {
|
|
3712
|
+
itemId: part.id,
|
|
3713
|
+
...contentPart.annotations.length > 0 && {
|
|
3714
|
+
annotations: contentPart.annotations
|
|
3715
|
+
}
|
|
3716
|
+
};
|
|
3704
3717
|
content.push({
|
|
3705
3718
|
type: "text",
|
|
3706
3719
|
text: contentPart.text,
|
|
3707
3720
|
providerMetadata: {
|
|
3708
|
-
openai:
|
|
3709
|
-
itemId: part.id
|
|
3710
|
-
}
|
|
3721
|
+
openai: providerMetadata2
|
|
3711
3722
|
}
|
|
3712
3723
|
});
|
|
3713
3724
|
for (const annotation of contentPart.annotations) {
|
|
@@ -3735,6 +3746,37 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3735
3746
|
}
|
|
3736
3747
|
} : {}
|
|
3737
3748
|
});
|
|
3749
|
+
} else if (annotation.type === "container_file_citation") {
|
|
3750
|
+
content.push({
|
|
3751
|
+
type: "source",
|
|
3752
|
+
sourceType: "document",
|
|
3753
|
+
id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils29.generateId)(),
|
|
3754
|
+
mediaType: "text/plain",
|
|
3755
|
+
title: (_q = (_p = annotation.filename) != null ? _p : annotation.file_id) != null ? _q : "Document",
|
|
3756
|
+
filename: (_r = annotation.filename) != null ? _r : annotation.file_id,
|
|
3757
|
+
providerMetadata: {
|
|
3758
|
+
openai: {
|
|
3759
|
+
fileId: annotation.file_id,
|
|
3760
|
+
containerId: annotation.container_id,
|
|
3761
|
+
...annotation.index != null ? { index: annotation.index } : {}
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
});
|
|
3765
|
+
} else if (annotation.type === "file_path") {
|
|
3766
|
+
content.push({
|
|
3767
|
+
type: "source",
|
|
3768
|
+
sourceType: "document",
|
|
3769
|
+
id: (_u = (_t = (_s = this.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils29.generateId)(),
|
|
3770
|
+
mediaType: "application/octet-stream",
|
|
3771
|
+
title: annotation.file_id,
|
|
3772
|
+
filename: annotation.file_id,
|
|
3773
|
+
providerMetadata: {
|
|
3774
|
+
openai: {
|
|
3775
|
+
fileId: annotation.file_id,
|
|
3776
|
+
...annotation.index != null ? { index: annotation.index } : {}
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
});
|
|
3738
3780
|
}
|
|
3739
3781
|
}
|
|
3740
3782
|
}
|
|
@@ -3804,13 +3846,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3804
3846
|
toolName: "file_search",
|
|
3805
3847
|
result: {
|
|
3806
3848
|
queries: part.queries,
|
|
3807
|
-
results: (
|
|
3849
|
+
results: (_w = (_v = part.results) == null ? void 0 : _v.map((result) => ({
|
|
3808
3850
|
attributes: result.attributes,
|
|
3809
3851
|
fileId: result.file_id,
|
|
3810
3852
|
filename: result.filename,
|
|
3811
3853
|
score: result.score,
|
|
3812
3854
|
text: result.text
|
|
3813
|
-
}))) != null ?
|
|
3855
|
+
}))) != null ? _w : null
|
|
3814
3856
|
}
|
|
3815
3857
|
});
|
|
3816
3858
|
break;
|
|
@@ -3850,15 +3892,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3850
3892
|
return {
|
|
3851
3893
|
content,
|
|
3852
3894
|
finishReason: mapOpenAIResponseFinishReason({
|
|
3853
|
-
finishReason: (
|
|
3895
|
+
finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
|
|
3854
3896
|
hasFunctionCall
|
|
3855
3897
|
}),
|
|
3856
3898
|
usage: {
|
|
3857
3899
|
inputTokens: response.usage.input_tokens,
|
|
3858
3900
|
outputTokens: response.usage.output_tokens,
|
|
3859
3901
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
3860
|
-
reasoningTokens: (
|
|
3861
|
-
cachedInputTokens: (
|
|
3902
|
+
reasoningTokens: (_z = (_y = response.usage.output_tokens_details) == null ? void 0 : _y.reasoning_tokens) != null ? _z : void 0,
|
|
3903
|
+
cachedInputTokens: (_B = (_A = response.usage.input_tokens_details) == null ? void 0 : _A.cached_tokens) != null ? _B : void 0
|
|
3862
3904
|
},
|
|
3863
3905
|
request: { body },
|
|
3864
3906
|
response: {
|
|
@@ -3916,7 +3958,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3916
3958
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3917
3959
|
},
|
|
3918
3960
|
transform(chunk, controller) {
|
|
3919
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
3961
|
+
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;
|
|
3920
3962
|
if (options.includeRawChunks) {
|
|
3921
3963
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3922
3964
|
}
|
|
@@ -4321,6 +4363,37 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4321
4363
|
}
|
|
4322
4364
|
} : {}
|
|
4323
4365
|
});
|
|
4366
|
+
} else if (value.annotation.type === "container_file_citation") {
|
|
4367
|
+
controller.enqueue({
|
|
4368
|
+
type: "source",
|
|
4369
|
+
sourceType: "document",
|
|
4370
|
+
id: (_y = (_x = (_w = self.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : (0, import_provider_utils29.generateId)(),
|
|
4371
|
+
mediaType: "text/plain",
|
|
4372
|
+
title: (_A = (_z = value.annotation.filename) != null ? _z : value.annotation.file_id) != null ? _A : "Document",
|
|
4373
|
+
filename: (_B = value.annotation.filename) != null ? _B : value.annotation.file_id,
|
|
4374
|
+
providerMetadata: {
|
|
4375
|
+
openai: {
|
|
4376
|
+
fileId: value.annotation.file_id,
|
|
4377
|
+
containerId: value.annotation.container_id,
|
|
4378
|
+
...value.annotation.index != null ? { index: value.annotation.index } : {}
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
});
|
|
4382
|
+
} else if (value.annotation.type === "file_path") {
|
|
4383
|
+
controller.enqueue({
|
|
4384
|
+
type: "source",
|
|
4385
|
+
sourceType: "document",
|
|
4386
|
+
id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : (0, import_provider_utils29.generateId)(),
|
|
4387
|
+
mediaType: "application/octet-stream",
|
|
4388
|
+
title: value.annotation.file_id,
|
|
4389
|
+
filename: value.annotation.file_id,
|
|
4390
|
+
providerMetadata: {
|
|
4391
|
+
openai: {
|
|
4392
|
+
fileId: value.annotation.file_id,
|
|
4393
|
+
...value.annotation.index != null ? { index: value.annotation.index } : {}
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
});
|
|
4324
4397
|
}
|
|
4325
4398
|
} else if (isErrorChunk(value)) {
|
|
4326
4399
|
controller.enqueue({ type: "error", error: value });
|
|
@@ -4388,27 +4461,13 @@ function isErrorChunk(chunk) {
|
|
|
4388
4461
|
function getResponsesModelConfig(modelId) {
|
|
4389
4462
|
const supportsFlexProcessing2 = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
4390
4463
|
const supportsPriorityProcessing2 = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
4391
|
-
const
|
|
4392
|
-
|
|
4393
|
-
supportsFlexProcessing: supportsFlexProcessing2,
|
|
4394
|
-
supportsPriorityProcessing: supportsPriorityProcessing2
|
|
4395
|
-
};
|
|
4396
|
-
if (modelId.startsWith("gpt-5-chat")) {
|
|
4397
|
-
return {
|
|
4398
|
-
...defaults,
|
|
4399
|
-
isReasoningModel: false
|
|
4400
|
-
};
|
|
4401
|
-
}
|
|
4402
|
-
if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
4403
|
-
return {
|
|
4404
|
-
...defaults,
|
|
4405
|
-
isReasoningModel: true,
|
|
4406
|
-
systemMessageMode: "developer"
|
|
4407
|
-
};
|
|
4408
|
-
}
|
|
4464
|
+
const isReasoningModel2 = isReasoningModel(modelId);
|
|
4465
|
+
const systemMessageMode = isReasoningModel2 ? "developer" : "system";
|
|
4409
4466
|
return {
|
|
4410
|
-
|
|
4411
|
-
|
|
4467
|
+
systemMessageMode,
|
|
4468
|
+
supportsFlexProcessing: supportsFlexProcessing2,
|
|
4469
|
+
supportsPriorityProcessing: supportsPriorityProcessing2,
|
|
4470
|
+
isReasoningModel: isReasoningModel2
|
|
4412
4471
|
};
|
|
4413
4472
|
}
|
|
4414
4473
|
function mapWebSearchOutput(action) {
|