@ai-sdk/openai 4.0.0-beta.35 → 4.0.0-beta.37
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 +15 -0
- package/dist/index.js +12 -91
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +11 -90
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/chat/openai-chat-language-model.ts +11 -129
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.37
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [eea8d98]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.0-beta.25
|
|
9
|
+
|
|
10
|
+
## 4.0.0-beta.36
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- f807e45: Extract shared `StreamingToolCallTracker` class into `@ai-sdk/provider-utils` to deduplicate streaming tool call handling across OpenAI-compatible providers. Also adds missing `generateId()` fallback for `toolCallId` in Alibaba's `doGenerate` path and ensures all providers finalize unfinished tool calls during stream flush.
|
|
15
|
+
- Updated dependencies [f807e45]
|
|
16
|
+
- @ai-sdk/provider-utils@5.0.0-beta.24
|
|
17
|
+
|
|
3
18
|
## 4.0.0-beta.35
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -8,15 +8,12 @@ import {
|
|
|
8
8
|
|
|
9
9
|
// src/chat/openai-chat-language-model.ts
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "@ai-sdk/provider";
|
|
13
|
-
import {
|
|
11
|
+
StreamingToolCallTracker,
|
|
14
12
|
combineHeaders,
|
|
15
13
|
createEventSourceResponseHandler,
|
|
16
14
|
createJsonResponseHandler,
|
|
17
15
|
generateId,
|
|
18
16
|
isCustomReasoning,
|
|
19
|
-
isParsableJson,
|
|
20
17
|
parseProviderOptions,
|
|
21
18
|
postJsonToApi,
|
|
22
19
|
serializeModelOptions,
|
|
@@ -958,7 +955,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
958
955
|
abortSignal: options.abortSignal,
|
|
959
956
|
fetch: this.config.fetch
|
|
960
957
|
});
|
|
961
|
-
const
|
|
958
|
+
const toolCallTracker = new StreamingToolCallTracker({
|
|
959
|
+
generateId,
|
|
960
|
+
typeValidation: "if-present"
|
|
961
|
+
});
|
|
962
962
|
let finishReason = {
|
|
963
963
|
unified: "other",
|
|
964
964
|
raw: void 0
|
|
@@ -974,7 +974,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
974
974
|
controller.enqueue({ type: "stream-start", warnings });
|
|
975
975
|
},
|
|
976
976
|
transform(chunk, controller) {
|
|
977
|
-
var _a2, _b2, _c, _d, _e
|
|
977
|
+
var _a2, _b2, _c, _d, _e;
|
|
978
978
|
if (options.includeRawChunks) {
|
|
979
979
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
980
980
|
}
|
|
@@ -1035,90 +1035,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1035
1035
|
}
|
|
1036
1036
|
if (delta.tool_calls != null) {
|
|
1037
1037
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
data: toolCallDelta,
|
|
1043
|
-
message: `Expected 'function' type.`
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
if (toolCallDelta.id == null) {
|
|
1047
|
-
throw new InvalidResponseDataError({
|
|
1048
|
-
data: toolCallDelta,
|
|
1049
|
-
message: `Expected 'id' to be a string.`
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
if (((_f = toolCallDelta.function) == null ? void 0 : _f.name) == null) {
|
|
1053
|
-
throw new InvalidResponseDataError({
|
|
1054
|
-
data: toolCallDelta,
|
|
1055
|
-
message: `Expected 'function.name' to be a string.`
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
controller.enqueue({
|
|
1059
|
-
type: "tool-input-start",
|
|
1060
|
-
id: toolCallDelta.id,
|
|
1061
|
-
toolName: toolCallDelta.function.name
|
|
1062
|
-
});
|
|
1063
|
-
toolCalls[index] = {
|
|
1064
|
-
id: toolCallDelta.id,
|
|
1065
|
-
type: "function",
|
|
1066
|
-
function: {
|
|
1067
|
-
name: toolCallDelta.function.name,
|
|
1068
|
-
arguments: (_g = toolCallDelta.function.arguments) != null ? _g : ""
|
|
1069
|
-
},
|
|
1070
|
-
hasFinished: false
|
|
1071
|
-
};
|
|
1072
|
-
const toolCall2 = toolCalls[index];
|
|
1073
|
-
if (((_h = toolCall2.function) == null ? void 0 : _h.name) != null && ((_i = toolCall2.function) == null ? void 0 : _i.arguments) != null) {
|
|
1074
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
1075
|
-
controller.enqueue({
|
|
1076
|
-
type: "tool-input-delta",
|
|
1077
|
-
id: toolCall2.id,
|
|
1078
|
-
delta: toolCall2.function.arguments
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
if (isParsableJson(toolCall2.function.arguments)) {
|
|
1082
|
-
controller.enqueue({
|
|
1083
|
-
type: "tool-input-end",
|
|
1084
|
-
id: toolCall2.id
|
|
1085
|
-
});
|
|
1086
|
-
controller.enqueue({
|
|
1087
|
-
type: "tool-call",
|
|
1088
|
-
toolCallId: (_j = toolCall2.id) != null ? _j : generateId(),
|
|
1089
|
-
toolName: toolCall2.function.name,
|
|
1090
|
-
input: toolCall2.function.arguments
|
|
1091
|
-
});
|
|
1092
|
-
toolCall2.hasFinished = true;
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
continue;
|
|
1096
|
-
}
|
|
1097
|
-
const toolCall = toolCalls[index];
|
|
1098
|
-
if (toolCall.hasFinished) {
|
|
1099
|
-
continue;
|
|
1100
|
-
}
|
|
1101
|
-
if (((_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null) {
|
|
1102
|
-
toolCall.function.arguments += (_m = (_l = toolCallDelta.function) == null ? void 0 : _l.arguments) != null ? _m : "";
|
|
1103
|
-
}
|
|
1104
|
-
controller.enqueue({
|
|
1105
|
-
type: "tool-input-delta",
|
|
1106
|
-
id: toolCall.id,
|
|
1107
|
-
delta: (_n = toolCallDelta.function.arguments) != null ? _n : ""
|
|
1108
|
-
});
|
|
1109
|
-
if (((_o = toolCall.function) == null ? void 0 : _o.name) != null && ((_p = toolCall.function) == null ? void 0 : _p.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1110
|
-
controller.enqueue({
|
|
1111
|
-
type: "tool-input-end",
|
|
1112
|
-
id: toolCall.id
|
|
1113
|
-
});
|
|
1114
|
-
controller.enqueue({
|
|
1115
|
-
type: "tool-call",
|
|
1116
|
-
toolCallId: (_q = toolCall.id) != null ? _q : generateId(),
|
|
1117
|
-
toolName: toolCall.function.name,
|
|
1118
|
-
input: toolCall.function.arguments
|
|
1119
|
-
});
|
|
1120
|
-
toolCall.hasFinished = true;
|
|
1121
|
-
}
|
|
1038
|
+
toolCallTracker.processDelta(
|
|
1039
|
+
toolCallDelta,
|
|
1040
|
+
controller.enqueue.bind(controller)
|
|
1041
|
+
);
|
|
1122
1042
|
}
|
|
1123
1043
|
}
|
|
1124
1044
|
if (delta.annotations != null) {
|
|
@@ -1137,6 +1057,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1137
1057
|
if (isActiveText) {
|
|
1138
1058
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1139
1059
|
}
|
|
1060
|
+
toolCallTracker.flush(controller.enqueue.bind(controller));
|
|
1140
1061
|
controller.enqueue({
|
|
1141
1062
|
type: "finish",
|
|
1142
1063
|
finishReason,
|
|
@@ -7148,7 +7069,7 @@ var OpenAISkills = class {
|
|
|
7148
7069
|
};
|
|
7149
7070
|
|
|
7150
7071
|
// src/version.ts
|
|
7151
|
-
var VERSION = true ? "4.0.0-beta.
|
|
7072
|
+
var VERSION = true ? "4.0.0-beta.37" : "0.0.0-test";
|
|
7152
7073
|
|
|
7153
7074
|
// src/openai-provider.ts
|
|
7154
7075
|
function createOpenAI(options = {}) {
|