@ai-sdk/openai 2.0.130 → 2.0.131
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 +8 -0
- package/dist/index.js +9 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -88
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +8 -86
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +9 -87
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -1066,7 +1066,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1066
1066
|
abortSignal: options.abortSignal,
|
|
1067
1067
|
fetch: this.config.fetch
|
|
1068
1068
|
});
|
|
1069
|
-
|
|
1069
|
+
let toolCallTracker;
|
|
1070
1070
|
let finishReason = "unknown";
|
|
1071
1071
|
const usage = {
|
|
1072
1072
|
inputTokens: void 0,
|
|
@@ -1080,10 +1080,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
1080
1080
|
stream: response.pipeThrough(
|
|
1081
1081
|
new TransformStream({
|
|
1082
1082
|
start(controller) {
|
|
1083
|
+
toolCallTracker = new import_provider_utils5.StreamingToolCallTracker(controller, {
|
|
1084
|
+
generateId: import_provider_utils5.generateId,
|
|
1085
|
+
typeValidation: "if-present"
|
|
1086
|
+
});
|
|
1083
1087
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1084
1088
|
},
|
|
1085
1089
|
transform(chunk, controller) {
|
|
1086
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
1090
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1087
1091
|
if (options.includeRawChunks) {
|
|
1088
1092
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1089
1093
|
}
|
|
@@ -1150,90 +1154,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1150
1154
|
}
|
|
1151
1155
|
if (delta.tool_calls != null) {
|
|
1152
1156
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1153
|
-
|
|
1154
|
-
if (toolCalls[index] == null) {
|
|
1155
|
-
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
1156
|
-
throw new import_provider3.InvalidResponseDataError({
|
|
1157
|
-
data: toolCallDelta,
|
|
1158
|
-
message: `Expected 'function' type.`
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
if (toolCallDelta.id == null) {
|
|
1162
|
-
throw new import_provider3.InvalidResponseDataError({
|
|
1163
|
-
data: toolCallDelta,
|
|
1164
|
-
message: `Expected 'id' to be a string.`
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
if (((_n = toolCallDelta.function) == null ? void 0 : _n.name) == null) {
|
|
1168
|
-
throw new import_provider3.InvalidResponseDataError({
|
|
1169
|
-
data: toolCallDelta,
|
|
1170
|
-
message: `Expected 'function.name' to be a string.`
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
controller.enqueue({
|
|
1174
|
-
type: "tool-input-start",
|
|
1175
|
-
id: toolCallDelta.id,
|
|
1176
|
-
toolName: toolCallDelta.function.name
|
|
1177
|
-
});
|
|
1178
|
-
toolCalls[index] = {
|
|
1179
|
-
id: toolCallDelta.id,
|
|
1180
|
-
type: "function",
|
|
1181
|
-
function: {
|
|
1182
|
-
name: toolCallDelta.function.name,
|
|
1183
|
-
arguments: (_o = toolCallDelta.function.arguments) != null ? _o : ""
|
|
1184
|
-
},
|
|
1185
|
-
hasFinished: false
|
|
1186
|
-
};
|
|
1187
|
-
const toolCall2 = toolCalls[index];
|
|
1188
|
-
if (((_p = toolCall2.function) == null ? void 0 : _p.name) != null && ((_q = toolCall2.function) == null ? void 0 : _q.arguments) != null) {
|
|
1189
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
1190
|
-
controller.enqueue({
|
|
1191
|
-
type: "tool-input-delta",
|
|
1192
|
-
id: toolCall2.id,
|
|
1193
|
-
delta: toolCall2.function.arguments
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
if ((0, import_provider_utils5.isParsableJson)(toolCall2.function.arguments)) {
|
|
1197
|
-
controller.enqueue({
|
|
1198
|
-
type: "tool-input-end",
|
|
1199
|
-
id: toolCall2.id
|
|
1200
|
-
});
|
|
1201
|
-
controller.enqueue({
|
|
1202
|
-
type: "tool-call",
|
|
1203
|
-
toolCallId: (_r = toolCall2.id) != null ? _r : (0, import_provider_utils5.generateId)(),
|
|
1204
|
-
toolName: toolCall2.function.name,
|
|
1205
|
-
input: toolCall2.function.arguments
|
|
1206
|
-
});
|
|
1207
|
-
toolCall2.hasFinished = true;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
continue;
|
|
1211
|
-
}
|
|
1212
|
-
const toolCall = toolCalls[index];
|
|
1213
|
-
if (toolCall.hasFinished) {
|
|
1214
|
-
continue;
|
|
1215
|
-
}
|
|
1216
|
-
if (((_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null) {
|
|
1217
|
-
toolCall.function.arguments += (_u = (_t = toolCallDelta.function) == null ? void 0 : _t.arguments) != null ? _u : "";
|
|
1218
|
-
}
|
|
1219
|
-
controller.enqueue({
|
|
1220
|
-
type: "tool-input-delta",
|
|
1221
|
-
id: toolCall.id,
|
|
1222
|
-
delta: (_v = toolCallDelta.function.arguments) != null ? _v : ""
|
|
1223
|
-
});
|
|
1224
|
-
if (((_w = toolCall.function) == null ? void 0 : _w.name) != null && ((_x = toolCall.function) == null ? void 0 : _x.arguments) != null && (0, import_provider_utils5.isParsableJson)(toolCall.function.arguments)) {
|
|
1225
|
-
controller.enqueue({
|
|
1226
|
-
type: "tool-input-end",
|
|
1227
|
-
id: toolCall.id
|
|
1228
|
-
});
|
|
1229
|
-
controller.enqueue({
|
|
1230
|
-
type: "tool-call",
|
|
1231
|
-
toolCallId: (_y = toolCall.id) != null ? _y : (0, import_provider_utils5.generateId)(),
|
|
1232
|
-
toolName: toolCall.function.name,
|
|
1233
|
-
input: toolCall.function.arguments
|
|
1234
|
-
});
|
|
1235
|
-
toolCall.hasFinished = true;
|
|
1236
|
-
}
|
|
1157
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
1237
1158
|
}
|
|
1238
1159
|
}
|
|
1239
1160
|
if (delta.annotations != null) {
|
|
@@ -1252,6 +1173,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1252
1173
|
if (isActiveText) {
|
|
1253
1174
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1254
1175
|
}
|
|
1176
|
+
toolCallTracker.flush();
|
|
1255
1177
|
controller.enqueue({
|
|
1256
1178
|
type: "finish",
|
|
1257
1179
|
finishReason,
|