bunnyquery 1.5.2 → 1.5.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/dist/engine.mjs CHANGED
@@ -1826,22 +1826,22 @@ var ChatSession = class {
1826
1826
  var id = this.host.getIdentity();
1827
1827
  var svcId = id.serviceId, plat = id.platform;
1828
1828
  if (!svcId || plat === "none" || !this.host.isViewMounted()) return;
1829
+ var presentIds = {};
1830
+ var pendingIds = {};
1831
+ this.state.messages.forEach(function(m) {
1832
+ var sid = m._serverItemId;
1833
+ if (sid == null) return;
1834
+ presentIds[sid] = true;
1835
+ if (m.isPending || m.isPendingInProcess || m.isPendingQueued) pendingIds[sid] = true;
1836
+ });
1829
1837
  for (var i = this.bgTaskQueue.length - 1; i >= 0; i--) {
1830
1838
  var e = this.bgTaskQueue[i];
1831
1839
  if (e.serviceId !== svcId || e.platform !== plat) continue;
1832
- var present = this.state.messages.some(function(m) {
1833
- return m._serverItemId === e.id;
1834
- });
1835
- var stillPending = this.state.messages.some(function(m) {
1836
- return m._serverItemId === e.id && (m.isPending || m.isPendingInProcess || m.isPendingQueued);
1837
- });
1838
- if (present && !stillPending) this.bgTaskQueue.splice(i, 1);
1840
+ if (presentIds[e.id] && !pendingIds[e.id]) this.bgTaskQueue.splice(i, 1);
1839
1841
  }
1840
1842
  this.bgTaskQueue.forEach(function(entry) {
1841
1843
  if (entry.serviceId !== svcId || entry.platform !== plat) return;
1842
- if (self.state.messages.some(function(m) {
1843
- return m._serverItemId === entry.id;
1844
- })) return;
1844
+ if (presentIds[entry.id]) return;
1845
1845
  var isRunning = entry.status === "running";
1846
1846
  var userBubble = { role: "user", content: self.host.formatIndexingLabel(entry.filename, entry.mime, entry.size, entry.storagePath, entry.isReindex), isBackgroundTask: true, _serverItemId: entry.id };
1847
1847
  if (isRunning) userBubble.isPendingInProcess = true;
@@ -1850,6 +1850,7 @@ var ChatSession = class {
1850
1850
  if (isRunning) {
1851
1851
  self.state.messages.push({ role: "assistant", content: "", isPending: true, isPendingInProcess: true, isBackgroundTask: true, _serverItemId: entry.id });
1852
1852
  }
1853
+ presentIds[entry.id] = true;
1853
1854
  self.host.notify();
1854
1855
  self.updateHistoryCache();
1855
1856
  self.host.scrollToBottom(false);