bunnyquery 1.4.3 → 1.4.5
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/bunnyquery.js +44 -10
- package/dist/engine.cjs +43 -9
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.mjs +43 -9
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/session.ts +76 -15
package/bunnyquery.js
CHANGED
|
@@ -1090,11 +1090,17 @@ ${options.inlineContentPlaceholder}
|
|
|
1090
1090
|
}
|
|
1091
1091
|
dispatchAgentRequest(params) {
|
|
1092
1092
|
var self = this;
|
|
1093
|
+
var dispatchItemId;
|
|
1093
1094
|
var sendAndPoll = function() {
|
|
1094
1095
|
return Promise.resolve(
|
|
1095
1096
|
self._callProviderFor(params.aiPlatform, params.text, params.boundedMessages, params.systemPrompt, params.aiModel, params.userId, params.extractContent)
|
|
1096
1097
|
).then(function(initial) {
|
|
1097
1098
|
if (initial && initial.poll && (initial.status === "pending" || initial.status === "running")) {
|
|
1099
|
+
if (initial.id) {
|
|
1100
|
+
if (dispatchItemId && dispatchItemId !== initial.id) self.historyItemPolls.delete(dispatchItemId);
|
|
1101
|
+
dispatchItemId = initial.id;
|
|
1102
|
+
self.historyItemPolls.set(initial.id, true);
|
|
1103
|
+
}
|
|
1098
1104
|
return initial.poll({ latency: POLL_INTERVAL });
|
|
1099
1105
|
}
|
|
1100
1106
|
return initial;
|
|
@@ -1116,13 +1122,39 @@ ${options.inlineContentPlaceholder}
|
|
|
1116
1122
|
}).catch(function(err) {
|
|
1117
1123
|
return { content: getErrorMessage(err), isError: true };
|
|
1118
1124
|
}).then(function(result) {
|
|
1119
|
-
var existing = self.aiChatHistoryCache[params.key] || { messages: [], endOfList: false, startKeyHistory: [] };
|
|
1120
|
-
self.aiChatHistoryCache[params.key] = {
|
|
1121
|
-
messages: existing.messages.concat([{ role: "assistant", content: result.content, isError: result.isError }]),
|
|
1122
|
-
endOfList: existing.endOfList,
|
|
1123
|
-
startKeyHistory: existing.startKeyHistory
|
|
1124
|
-
};
|
|
1125
1125
|
delete self.pendingAgentRequests[params.key];
|
|
1126
|
+
if (dispatchItemId) self.historyItemPolls.delete(dispatchItemId);
|
|
1127
|
+
var existing = self.aiChatHistoryCache[params.key] || { messages: [], endOfList: false, startKeyHistory: [] };
|
|
1128
|
+
var reply = { role: "assistant", content: result.content, isError: result.isError };
|
|
1129
|
+
var onThisVisibleChat = self.host.isViewMounted() && self.getHistoryCacheKey() === params.key;
|
|
1130
|
+
if (onThisVisibleChat) {
|
|
1131
|
+
self.aiChatHistoryCache[params.key] = {
|
|
1132
|
+
messages: existing.messages.concat([reply]),
|
|
1133
|
+
endOfList: existing.endOfList,
|
|
1134
|
+
startKeyHistory: existing.startKeyHistory
|
|
1135
|
+
};
|
|
1136
|
+
} else {
|
|
1137
|
+
var msgs = existing.messages.slice();
|
|
1138
|
+
var idx = -1;
|
|
1139
|
+
for (var i = msgs.length - 1; i >= 0; i--) {
|
|
1140
|
+
var m = msgs[i];
|
|
1141
|
+
if (m && m.isPending && m.role === "assistant" && !m.isBackgroundTask) {
|
|
1142
|
+
idx = i;
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
if (idx !== -1) {
|
|
1147
|
+
reply._serverItemId = msgs[idx]._serverItemId;
|
|
1148
|
+
msgs[idx] = reply;
|
|
1149
|
+
} else {
|
|
1150
|
+
msgs.push(reply);
|
|
1151
|
+
}
|
|
1152
|
+
self.aiChatHistoryCache[params.key] = {
|
|
1153
|
+
messages: msgs,
|
|
1154
|
+
endOfList: existing.endOfList,
|
|
1155
|
+
startKeyHistory: existing.startKeyHistory
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1126
1158
|
return result;
|
|
1127
1159
|
});
|
|
1128
1160
|
this.pendingAgentRequests[params.key] = run;
|
|
@@ -1175,6 +1207,7 @@ ${options.inlineContentPlaceholder}
|
|
|
1175
1207
|
self.host.notify();
|
|
1176
1208
|
}
|
|
1177
1209
|
if (result && result.poll && (result.status === "pending" || result.status === "running")) {
|
|
1210
|
+
if (serverId) self.historyItemPolls.set(serverId, true);
|
|
1178
1211
|
return result.poll({ latency: POLL_INTERVAL }).then(function(res) {
|
|
1179
1212
|
return self.onQueuedSendResponse(capturedComposed, res, capturedPlatform, serverId);
|
|
1180
1213
|
}).catch(function(err) {
|
|
@@ -1212,7 +1245,6 @@ ${options.inlineContentPlaceholder}
|
|
|
1212
1245
|
serviceId: id.serviceId,
|
|
1213
1246
|
history: historyForLlm
|
|
1214
1247
|
});
|
|
1215
|
-
var requestToken = this.state.gateRefreshToken;
|
|
1216
1248
|
var run = this.dispatchAgentRequest({
|
|
1217
1249
|
key,
|
|
1218
1250
|
serviceId: id.serviceId,
|
|
@@ -1227,7 +1259,7 @@ ${options.inlineContentPlaceholder}
|
|
|
1227
1259
|
});
|
|
1228
1260
|
Promise.resolve(run).catch(function() {
|
|
1229
1261
|
}).then(function() {
|
|
1230
|
-
if (
|
|
1262
|
+
if (!(self.host.isViewMounted() && self.getHistoryCacheKey() === key)) return;
|
|
1231
1263
|
self.state.sending = false;
|
|
1232
1264
|
return Promise.resolve(self.typewriteLatestReply(key)).then(function() {
|
|
1233
1265
|
self.host.scrollToBottom(true);
|
|
@@ -1315,6 +1347,7 @@ ${options.inlineContentPlaceholder}
|
|
|
1315
1347
|
else this.state.messages.push(msg);
|
|
1316
1348
|
}
|
|
1317
1349
|
onQueuedSendResponse(_composed, response, platform, serverId) {
|
|
1350
|
+
if (serverId) this.historyItemPolls.delete(serverId);
|
|
1318
1351
|
var targetIdx = this.resolveQueuedUserBubble(serverId);
|
|
1319
1352
|
if (targetIdx === void 0) {
|
|
1320
1353
|
this.host.notify();
|
|
@@ -1349,6 +1382,7 @@ ${options.inlineContentPlaceholder}
|
|
|
1349
1382
|
this.host.scrollToBottom(true);
|
|
1350
1383
|
}
|
|
1351
1384
|
onQueuedSendError(_composed, err, serverId) {
|
|
1385
|
+
if (serverId) this.historyItemPolls.delete(serverId);
|
|
1352
1386
|
var isNotExists = err && (err.code === "NOT_EXISTS" || err.body && err.body.code === "NOT_EXISTS");
|
|
1353
1387
|
if (isNotExists) {
|
|
1354
1388
|
var userIdx = serverId ? this.state.messages.findIndex(function(m) {
|
|
@@ -1841,7 +1875,7 @@ ${options.inlineContentPlaceholder}
|
|
|
1841
1875
|
if (item.status !== "running" && item.status !== "pending") return;
|
|
1842
1876
|
if (!item.poll || !item.id) return;
|
|
1843
1877
|
if (self.historyItemPolls.has(item.id)) return;
|
|
1844
|
-
if (item.status === "running" && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
|
|
1878
|
+
if ((item.status === "running" || item.status === "pending") && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
|
|
1845
1879
|
self.historyItemPolls.set(item.id, true);
|
|
1846
1880
|
var capturedId = item.id;
|
|
1847
1881
|
var pp = item.poll({
|
|
@@ -2084,7 +2118,7 @@ ${options.inlineContentPlaceholder}
|
|
|
2084
2118
|
(function() {
|
|
2085
2119
|
var MCP_PROD = "https://mcp.broadwayinc.computer";
|
|
2086
2120
|
var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
|
|
2087
|
-
var BQ_VERSION = "1.4.
|
|
2121
|
+
var BQ_VERSION = "1.4.5" ;
|
|
2088
2122
|
var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
|
|
2089
2123
|
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
2090
2124
|
var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
package/dist/engine.cjs
CHANGED
|
@@ -1124,11 +1124,17 @@ var ChatSession = class {
|
|
|
1124
1124
|
}
|
|
1125
1125
|
dispatchAgentRequest(params) {
|
|
1126
1126
|
var self = this;
|
|
1127
|
+
var dispatchItemId;
|
|
1127
1128
|
var sendAndPoll = function() {
|
|
1128
1129
|
return Promise.resolve(
|
|
1129
1130
|
self._callProviderFor(params.aiPlatform, params.text, params.boundedMessages, params.systemPrompt, params.aiModel, params.userId, params.extractContent)
|
|
1130
1131
|
).then(function(initial) {
|
|
1131
1132
|
if (initial && initial.poll && (initial.status === "pending" || initial.status === "running")) {
|
|
1133
|
+
if (initial.id) {
|
|
1134
|
+
if (dispatchItemId && dispatchItemId !== initial.id) self.historyItemPolls.delete(dispatchItemId);
|
|
1135
|
+
dispatchItemId = initial.id;
|
|
1136
|
+
self.historyItemPolls.set(initial.id, true);
|
|
1137
|
+
}
|
|
1132
1138
|
return initial.poll({ latency: POLL_INTERVAL });
|
|
1133
1139
|
}
|
|
1134
1140
|
return initial;
|
|
@@ -1150,13 +1156,39 @@ var ChatSession = class {
|
|
|
1150
1156
|
}).catch(function(err) {
|
|
1151
1157
|
return { content: getErrorMessage(err), isError: true };
|
|
1152
1158
|
}).then(function(result) {
|
|
1153
|
-
var existing = self.aiChatHistoryCache[params.key] || { messages: [], endOfList: false, startKeyHistory: [] };
|
|
1154
|
-
self.aiChatHistoryCache[params.key] = {
|
|
1155
|
-
messages: existing.messages.concat([{ role: "assistant", content: result.content, isError: result.isError }]),
|
|
1156
|
-
endOfList: existing.endOfList,
|
|
1157
|
-
startKeyHistory: existing.startKeyHistory
|
|
1158
|
-
};
|
|
1159
1159
|
delete self.pendingAgentRequests[params.key];
|
|
1160
|
+
if (dispatchItemId) self.historyItemPolls.delete(dispatchItemId);
|
|
1161
|
+
var existing = self.aiChatHistoryCache[params.key] || { messages: [], endOfList: false, startKeyHistory: [] };
|
|
1162
|
+
var reply = { role: "assistant", content: result.content, isError: result.isError };
|
|
1163
|
+
var onThisVisibleChat = self.host.isViewMounted() && self.getHistoryCacheKey() === params.key;
|
|
1164
|
+
if (onThisVisibleChat) {
|
|
1165
|
+
self.aiChatHistoryCache[params.key] = {
|
|
1166
|
+
messages: existing.messages.concat([reply]),
|
|
1167
|
+
endOfList: existing.endOfList,
|
|
1168
|
+
startKeyHistory: existing.startKeyHistory
|
|
1169
|
+
};
|
|
1170
|
+
} else {
|
|
1171
|
+
var msgs = existing.messages.slice();
|
|
1172
|
+
var idx = -1;
|
|
1173
|
+
for (var i = msgs.length - 1; i >= 0; i--) {
|
|
1174
|
+
var m = msgs[i];
|
|
1175
|
+
if (m && m.isPending && m.role === "assistant" && !m.isBackgroundTask) {
|
|
1176
|
+
idx = i;
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if (idx !== -1) {
|
|
1181
|
+
reply._serverItemId = msgs[idx]._serverItemId;
|
|
1182
|
+
msgs[idx] = reply;
|
|
1183
|
+
} else {
|
|
1184
|
+
msgs.push(reply);
|
|
1185
|
+
}
|
|
1186
|
+
self.aiChatHistoryCache[params.key] = {
|
|
1187
|
+
messages: msgs,
|
|
1188
|
+
endOfList: existing.endOfList,
|
|
1189
|
+
startKeyHistory: existing.startKeyHistory
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1160
1192
|
return result;
|
|
1161
1193
|
});
|
|
1162
1194
|
this.pendingAgentRequests[params.key] = run;
|
|
@@ -1209,6 +1241,7 @@ var ChatSession = class {
|
|
|
1209
1241
|
self.host.notify();
|
|
1210
1242
|
}
|
|
1211
1243
|
if (result && result.poll && (result.status === "pending" || result.status === "running")) {
|
|
1244
|
+
if (serverId) self.historyItemPolls.set(serverId, true);
|
|
1212
1245
|
return result.poll({ latency: POLL_INTERVAL }).then(function(res) {
|
|
1213
1246
|
return self.onQueuedSendResponse(capturedComposed, res, capturedPlatform, serverId);
|
|
1214
1247
|
}).catch(function(err) {
|
|
@@ -1246,7 +1279,6 @@ var ChatSession = class {
|
|
|
1246
1279
|
serviceId: id.serviceId,
|
|
1247
1280
|
history: historyForLlm
|
|
1248
1281
|
});
|
|
1249
|
-
var requestToken = this.state.gateRefreshToken;
|
|
1250
1282
|
var run = this.dispatchAgentRequest({
|
|
1251
1283
|
key,
|
|
1252
1284
|
serviceId: id.serviceId,
|
|
@@ -1261,7 +1293,7 @@ var ChatSession = class {
|
|
|
1261
1293
|
});
|
|
1262
1294
|
Promise.resolve(run).catch(function() {
|
|
1263
1295
|
}).then(function() {
|
|
1264
|
-
if (
|
|
1296
|
+
if (!(self.host.isViewMounted() && self.getHistoryCacheKey() === key)) return;
|
|
1265
1297
|
self.state.sending = false;
|
|
1266
1298
|
return Promise.resolve(self.typewriteLatestReply(key)).then(function() {
|
|
1267
1299
|
self.host.scrollToBottom(true);
|
|
@@ -1349,6 +1381,7 @@ var ChatSession = class {
|
|
|
1349
1381
|
else this.state.messages.push(msg);
|
|
1350
1382
|
}
|
|
1351
1383
|
onQueuedSendResponse(_composed, response, platform, serverId) {
|
|
1384
|
+
if (serverId) this.historyItemPolls.delete(serverId);
|
|
1352
1385
|
var targetIdx = this.resolveQueuedUserBubble(serverId);
|
|
1353
1386
|
if (targetIdx === void 0) {
|
|
1354
1387
|
this.host.notify();
|
|
@@ -1383,6 +1416,7 @@ var ChatSession = class {
|
|
|
1383
1416
|
this.host.scrollToBottom(true);
|
|
1384
1417
|
}
|
|
1385
1418
|
onQueuedSendError(_composed, err, serverId) {
|
|
1419
|
+
if (serverId) this.historyItemPolls.delete(serverId);
|
|
1386
1420
|
var isNotExists = err && (err.code === "NOT_EXISTS" || err.body && err.body.code === "NOT_EXISTS");
|
|
1387
1421
|
if (isNotExists) {
|
|
1388
1422
|
var userIdx = serverId ? this.state.messages.findIndex(function(m) {
|
|
@@ -1875,7 +1909,7 @@ var ChatSession = class {
|
|
|
1875
1909
|
if (item.status !== "running" && item.status !== "pending") return;
|
|
1876
1910
|
if (!item.poll || !item.id) return;
|
|
1877
1911
|
if (self.historyItemPolls.has(item.id)) return;
|
|
1878
|
-
if (item.status === "running" && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
|
|
1912
|
+
if ((item.status === "running" || item.status === "pending") && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
|
|
1879
1913
|
self.historyItemPolls.set(item.id, true);
|
|
1880
1914
|
var capturedId = item.id;
|
|
1881
1915
|
var pp = item.poll({
|