ai 3.1.23 → 3.1.24
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 +45 -5
- package/dist/index.d.ts +45 -5
- package/dist/index.js +51 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/react/dist/index.d.mts +24 -0
- package/react/dist/index.d.ts +24 -0
- package/rsc/dist/index.d.ts +6 -1
- package/rsc/dist/rsc-server.d.mts +6 -1
- package/rsc/dist/rsc-shared.d.mts +6 -1
- package/solid/dist/index.d.mts +24 -0
- package/solid/dist/index.d.ts +24 -0
- package/svelte/dist/index.d.mts +24 -0
- package/svelte/dist/index.d.ts +24 -0
- package/vue/dist/index.d.mts +24 -0
- package/vue/dist/index.d.ts +24 -0
package/dist/index.mjs
CHANGED
@@ -1115,57 +1115,72 @@ var StreamObjectResult = class {
|
|
1115
1115
|
warnings,
|
1116
1116
|
rawResponse
|
1117
1117
|
}) {
|
1118
|
-
this.originalStream = stream;
|
1119
1118
|
this.warnings = warnings;
|
1120
1119
|
this.rawResponse = rawResponse;
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
let latestObject = void 0;
|
1125
|
-
return createAsyncIterableStream(this.originalStream, {
|
1126
|
-
transform(chunk, controller) {
|
1127
|
-
if (typeof chunk === "string") {
|
1128
|
-
accumulatedText += chunk;
|
1129
|
-
const currentObject = parsePartialJson(
|
1130
|
-
accumulatedText
|
1131
|
-
);
|
1132
|
-
if (!isDeepEqualData(latestObject, currentObject)) {
|
1133
|
-
latestObject = currentObject;
|
1134
|
-
controller.enqueue(currentObject);
|
1135
|
-
}
|
1136
|
-
} else if (chunk.type === "error") {
|
1137
|
-
throw chunk.error;
|
1138
|
-
}
|
1139
|
-
}
|
1120
|
+
let resolveUsage;
|
1121
|
+
this.usage = new Promise((resolve) => {
|
1122
|
+
resolveUsage = resolve;
|
1140
1123
|
});
|
1141
|
-
|
1142
|
-
get fullStream() {
|
1124
|
+
let usage;
|
1143
1125
|
let accumulatedText = "";
|
1144
1126
|
let latestObject = void 0;
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
latestObject
|
1154
|
-
|
1127
|
+
this.originalStream = stream.pipeThrough(
|
1128
|
+
new TransformStream({
|
1129
|
+
async transform(chunk, controller) {
|
1130
|
+
if (typeof chunk === "string") {
|
1131
|
+
accumulatedText += chunk;
|
1132
|
+
const currentObject = parsePartialJson(
|
1133
|
+
accumulatedText
|
1134
|
+
);
|
1135
|
+
if (!isDeepEqualData(latestObject, currentObject)) {
|
1136
|
+
latestObject = currentObject;
|
1137
|
+
controller.enqueue({ type: "object", object: currentObject });
|
1138
|
+
}
|
1139
|
+
return;
|
1155
1140
|
}
|
1156
|
-
} else {
|
1157
1141
|
switch (chunk.type) {
|
1158
|
-
case "finish":
|
1142
|
+
case "finish": {
|
1143
|
+
usage = calculateTokenUsage(chunk.usage);
|
1159
1144
|
controller.enqueue({
|
1160
1145
|
...chunk,
|
1161
|
-
usage
|
1146
|
+
usage
|
1162
1147
|
});
|
1148
|
+
resolveUsage(usage);
|
1163
1149
|
break;
|
1164
|
-
|
1150
|
+
}
|
1151
|
+
default: {
|
1165
1152
|
controller.enqueue(chunk);
|
1166
1153
|
break;
|
1154
|
+
}
|
1167
1155
|
}
|
1168
1156
|
}
|
1157
|
+
})
|
1158
|
+
);
|
1159
|
+
}
|
1160
|
+
get partialObjectStream() {
|
1161
|
+
return createAsyncIterableStream(this.originalStream, {
|
1162
|
+
transform(chunk, controller) {
|
1163
|
+
switch (chunk.type) {
|
1164
|
+
case "object":
|
1165
|
+
controller.enqueue(chunk.object);
|
1166
|
+
break;
|
1167
|
+
case "finish":
|
1168
|
+
break;
|
1169
|
+
case "error":
|
1170
|
+
controller.error(chunk.error);
|
1171
|
+
break;
|
1172
|
+
default: {
|
1173
|
+
const _exhaustiveCheck = chunk;
|
1174
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
1175
|
+
}
|
1176
|
+
}
|
1177
|
+
}
|
1178
|
+
});
|
1179
|
+
}
|
1180
|
+
get fullStream() {
|
1181
|
+
return createAsyncIterableStream(this.originalStream, {
|
1182
|
+
transform(chunk, controller) {
|
1183
|
+
controller.enqueue(chunk);
|
1169
1184
|
}
|
1170
1185
|
});
|
1171
1186
|
}
|