bunnyquery 1.4.3 → 1.4.4

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 CHANGED
@@ -1116,13 +1116,38 @@ ${options.inlineContentPlaceholder}
1116
1116
  }).catch(function(err) {
1117
1117
  return { content: getErrorMessage(err), isError: true };
1118
1118
  }).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
1119
  delete self.pendingAgentRequests[params.key];
1120
+ var existing = self.aiChatHistoryCache[params.key] || { messages: [], endOfList: false, startKeyHistory: [] };
1121
+ var reply = { role: "assistant", content: result.content, isError: result.isError };
1122
+ var onThisVisibleChat = self.host.isViewMounted() && self.getHistoryCacheKey() === params.key;
1123
+ if (onThisVisibleChat) {
1124
+ self.aiChatHistoryCache[params.key] = {
1125
+ messages: existing.messages.concat([reply]),
1126
+ endOfList: existing.endOfList,
1127
+ startKeyHistory: existing.startKeyHistory
1128
+ };
1129
+ } else {
1130
+ var msgs = existing.messages.slice();
1131
+ var idx = -1;
1132
+ for (var i = msgs.length - 1; i >= 0; i--) {
1133
+ var m = msgs[i];
1134
+ if (m && m.isPending && m.role === "assistant" && !m.isBackgroundTask) {
1135
+ idx = i;
1136
+ break;
1137
+ }
1138
+ }
1139
+ if (idx !== -1) {
1140
+ reply._serverItemId = msgs[idx]._serverItemId;
1141
+ msgs[idx] = reply;
1142
+ } else {
1143
+ msgs.push(reply);
1144
+ }
1145
+ self.aiChatHistoryCache[params.key] = {
1146
+ messages: msgs,
1147
+ endOfList: existing.endOfList,
1148
+ startKeyHistory: existing.startKeyHistory
1149
+ };
1150
+ }
1126
1151
  return result;
1127
1152
  });
1128
1153
  this.pendingAgentRequests[params.key] = run;
@@ -1212,7 +1237,6 @@ ${options.inlineContentPlaceholder}
1212
1237
  serviceId: id.serviceId,
1213
1238
  history: historyForLlm
1214
1239
  });
1215
- var requestToken = this.state.gateRefreshToken;
1216
1240
  var run = this.dispatchAgentRequest({
1217
1241
  key,
1218
1242
  serviceId: id.serviceId,
@@ -1227,7 +1251,7 @@ ${options.inlineContentPlaceholder}
1227
1251
  });
1228
1252
  Promise.resolve(run).catch(function() {
1229
1253
  }).then(function() {
1230
- if (requestToken !== self.state.gateRefreshToken || self.getHistoryCacheKey() !== key) return;
1254
+ if (!(self.host.isViewMounted() && self.getHistoryCacheKey() === key)) return;
1231
1255
  self.state.sending = false;
1232
1256
  return Promise.resolve(self.typewriteLatestReply(key)).then(function() {
1233
1257
  self.host.scrollToBottom(true);
@@ -1841,7 +1865,7 @@ ${options.inlineContentPlaceholder}
1841
1865
  if (item.status !== "running" && item.status !== "pending") return;
1842
1866
  if (!item.poll || !item.id) return;
1843
1867
  if (self.historyItemPolls.has(item.id)) return;
1844
- if (item.status === "running" && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
1868
+ if ((item.status === "running" || item.status === "pending") && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
1845
1869
  self.historyItemPolls.set(item.id, true);
1846
1870
  var capturedId = item.id;
1847
1871
  var pp = item.poll({
@@ -2084,7 +2108,7 @@ ${options.inlineContentPlaceholder}
2084
2108
  (function() {
2085
2109
  var MCP_PROD = "https://mcp.broadwayinc.computer";
2086
2110
  var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
2087
- var BQ_VERSION = "1.4.3" ;
2111
+ var BQ_VERSION = "1.4.4" ;
2088
2112
  var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
2089
2113
  var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
2090
2114
  var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
package/dist/engine.cjs CHANGED
@@ -1150,13 +1150,38 @@ var ChatSession = class {
1150
1150
  }).catch(function(err) {
1151
1151
  return { content: getErrorMessage(err), isError: true };
1152
1152
  }).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
1153
  delete self.pendingAgentRequests[params.key];
1154
+ var existing = self.aiChatHistoryCache[params.key] || { messages: [], endOfList: false, startKeyHistory: [] };
1155
+ var reply = { role: "assistant", content: result.content, isError: result.isError };
1156
+ var onThisVisibleChat = self.host.isViewMounted() && self.getHistoryCacheKey() === params.key;
1157
+ if (onThisVisibleChat) {
1158
+ self.aiChatHistoryCache[params.key] = {
1159
+ messages: existing.messages.concat([reply]),
1160
+ endOfList: existing.endOfList,
1161
+ startKeyHistory: existing.startKeyHistory
1162
+ };
1163
+ } else {
1164
+ var msgs = existing.messages.slice();
1165
+ var idx = -1;
1166
+ for (var i = msgs.length - 1; i >= 0; i--) {
1167
+ var m = msgs[i];
1168
+ if (m && m.isPending && m.role === "assistant" && !m.isBackgroundTask) {
1169
+ idx = i;
1170
+ break;
1171
+ }
1172
+ }
1173
+ if (idx !== -1) {
1174
+ reply._serverItemId = msgs[idx]._serverItemId;
1175
+ msgs[idx] = reply;
1176
+ } else {
1177
+ msgs.push(reply);
1178
+ }
1179
+ self.aiChatHistoryCache[params.key] = {
1180
+ messages: msgs,
1181
+ endOfList: existing.endOfList,
1182
+ startKeyHistory: existing.startKeyHistory
1183
+ };
1184
+ }
1160
1185
  return result;
1161
1186
  });
1162
1187
  this.pendingAgentRequests[params.key] = run;
@@ -1246,7 +1271,6 @@ var ChatSession = class {
1246
1271
  serviceId: id.serviceId,
1247
1272
  history: historyForLlm
1248
1273
  });
1249
- var requestToken = this.state.gateRefreshToken;
1250
1274
  var run = this.dispatchAgentRequest({
1251
1275
  key,
1252
1276
  serviceId: id.serviceId,
@@ -1261,7 +1285,7 @@ var ChatSession = class {
1261
1285
  });
1262
1286
  Promise.resolve(run).catch(function() {
1263
1287
  }).then(function() {
1264
- if (requestToken !== self.state.gateRefreshToken || self.getHistoryCacheKey() !== key) return;
1288
+ if (!(self.host.isViewMounted() && self.getHistoryCacheKey() === key)) return;
1265
1289
  self.state.sending = false;
1266
1290
  return Promise.resolve(self.typewriteLatestReply(key)).then(function() {
1267
1291
  self.host.scrollToBottom(true);
@@ -1875,7 +1899,7 @@ var ChatSession = class {
1875
1899
  if (item.status !== "running" && item.status !== "pending") return;
1876
1900
  if (!item.poll || !item.id) return;
1877
1901
  if (self.historyItemPolls.has(item.id)) return;
1878
- if (item.status === "running" && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
1902
+ if ((item.status === "running" || item.status === "pending") && self.pendingAgentRequests[self.getHistoryCacheKey()]) return;
1879
1903
  self.historyItemPolls.set(item.id, true);
1880
1904
  var capturedId = item.id;
1881
1905
  var pp = item.poll({