ai 3.1.28 → 3.1.30
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/dist/index.d.mts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.js +36 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/rsc/dist/rsc-server.mjs +7 -1
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -282,7 +282,13 @@ function convertToLanguageModelMessage(message) {
|
|
282
282
|
content: [{ type: "text", text: message.content }]
|
283
283
|
};
|
284
284
|
}
|
285
|
-
return {
|
285
|
+
return {
|
286
|
+
role: "assistant",
|
287
|
+
content: message.content.filter(
|
288
|
+
// remove empty text parts:
|
289
|
+
(part) => part.type !== "text" || part.text !== ""
|
290
|
+
)
|
291
|
+
};
|
286
292
|
}
|
287
293
|
case "tool": {
|
288
294
|
return message;
|
@@ -993,6 +999,7 @@ async function streamObject({
|
|
993
999
|
messages,
|
994
1000
|
maxRetries,
|
995
1001
|
abortSignal,
|
1002
|
+
onFinish,
|
996
1003
|
...settings
|
997
1004
|
}) {
|
998
1005
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
@@ -1108,7 +1115,8 @@ async function streamObject({
|
|
1108
1115
|
stream: result.stream.pipeThrough(new TransformStream(transformer)),
|
1109
1116
|
warnings: result.warnings,
|
1110
1117
|
rawResponse: result.rawResponse,
|
1111
|
-
schema
|
1118
|
+
schema,
|
1119
|
+
onFinish
|
1112
1120
|
});
|
1113
1121
|
}
|
1114
1122
|
var StreamObjectResult = class {
|
@@ -1116,7 +1124,8 @@ var StreamObjectResult = class {
|
|
1116
1124
|
stream,
|
1117
1125
|
warnings,
|
1118
1126
|
rawResponse,
|
1119
|
-
schema
|
1127
|
+
schema,
|
1128
|
+
onFinish
|
1120
1129
|
}) {
|
1121
1130
|
this.warnings = warnings;
|
1122
1131
|
this.rawResponse = rawResponse;
|
@@ -1131,6 +1140,8 @@ var StreamObjectResult = class {
|
|
1131
1140
|
resolveUsage = resolve;
|
1132
1141
|
});
|
1133
1142
|
let usage;
|
1143
|
+
let object;
|
1144
|
+
let error;
|
1134
1145
|
let accumulatedText = "";
|
1135
1146
|
let latestObject = void 0;
|
1136
1147
|
this.originalStream = stream.pipeThrough(
|
@@ -1157,9 +1168,11 @@ var StreamObjectResult = class {
|
|
1157
1168
|
schema
|
1158
1169
|
});
|
1159
1170
|
if (validationResult.success) {
|
1160
|
-
|
1171
|
+
object = validationResult.value;
|
1172
|
+
resolveObject(object);
|
1161
1173
|
} else {
|
1162
|
-
|
1174
|
+
error = validationResult.error;
|
1175
|
+
rejectObject(error);
|
1163
1176
|
}
|
1164
1177
|
break;
|
1165
1178
|
}
|
@@ -1168,6 +1181,24 @@ var StreamObjectResult = class {
|
|
1168
1181
|
break;
|
1169
1182
|
}
|
1170
1183
|
}
|
1184
|
+
},
|
1185
|
+
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
1186
|
+
async flush(controller) {
|
1187
|
+
try {
|
1188
|
+
await (onFinish == null ? void 0 : onFinish({
|
1189
|
+
usage: usage != null ? usage : {
|
1190
|
+
promptTokens: NaN,
|
1191
|
+
completionTokens: NaN,
|
1192
|
+
totalTokens: NaN
|
1193
|
+
},
|
1194
|
+
object,
|
1195
|
+
error,
|
1196
|
+
rawResponse,
|
1197
|
+
warnings
|
1198
|
+
}));
|
1199
|
+
} catch (error2) {
|
1200
|
+
controller.error(error2);
|
1201
|
+
}
|
1171
1202
|
}
|
1172
1203
|
})
|
1173
1204
|
);
|