bunnyquery 1.15.1 → 1.15.2

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
@@ -4357,6 +4357,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
4357
4357
  this._liveIndexKey = "";
4358
4358
  this._liveIndexAt = 0;
4359
4359
  this._indexClaims = {};
4360
+ this._bgQueueByFile = null;
4361
+ this._bgQueueStamp = { arr: null, length: 0, first: void 0, last: void 0 };
4362
+ this._bgQueueIndexRebuilds = 0;
4360
4363
  }
4361
4364
  /** What the display layer needs to decide whether a run is finished. `keys` holds
4362
4365
  * every file the server still has indexing work for; `checked` is false until the
@@ -4393,13 +4396,10 @@ Index the REMAINING windows - one record per row/item, looking at any page image
4393
4396
  */
4394
4397
  hasLiveIndexRun(storagePath) {
4395
4398
  if (!storagePath) return false;
4396
- var claimed = this._indexClaims[this._indexClaimKey(storagePath)];
4399
+ var scoped = this._indexClaimKey(storagePath);
4400
+ var claimed = this._indexClaims[scoped];
4397
4401
  if (claimed && nowMs() - claimed < INDEX_DISPATCH_CLAIM_MS) return true;
4398
- var id = this.host.getIdentity();
4399
- for (var i = 0; i < this.bgTaskQueue.length; i++) {
4400
- var e = this.bgTaskQueue[i];
4401
- if (e && e.storagePath === storagePath && e.projectId === id.projectId && e.platform === id.platform) return true;
4402
- }
4402
+ if (this._bgQueueIndex()[scoped] > 0) return true;
4403
4403
  return this.state.messages.some(function(m) {
4404
4404
  if (!m.isBackgroundTask || m.role !== "user" || m.isCancelled) return false;
4405
4405
  if (!(m.isPendingQueued || m.isPendingInProcess || m.isSendingToServer)) return false;
@@ -4412,6 +4412,47 @@ Index the REMAINING windows - one record per row/item, looking at any page image
4412
4412
  var id = this.host.getIdentity();
4413
4413
  return indexScopeKey(id.projectId, id.platform) + "|" + storagePath;
4414
4414
  }
4415
+ /**
4416
+ * bgTaskQueue as a map: scoped path (indexScopeKey(projectId, platform) +
4417
+ * '|' + storagePath, the key the claims and the stops use) -> entries.
4418
+ *
4419
+ * The array stays the source of truth because the engine does not own every
4420
+ * write to it: both hosts hand in their own array (the dashboard a Vue
4421
+ * reactive one it pushes to from the Files page and splices from its
4422
+ * fallback poller), and tests push to it directly. So the map is DERIVED, and
4423
+ * rebuilt when a cheap stamp says the array changed: its identity, its length,
4424
+ * its first and its last entry.
4425
+ *
4426
+ * Why that stamp is exact for this array: every write to bgTaskQueue is either
4427
+ * a push of a NEW entry object or a splice that removes one (nothing inserts
4428
+ * in the middle, replaces in place or re-pushes a removed entry). Under those
4429
+ * two operations, same length plus same last entry means the same contents:
4430
+ * a push changes the last entry unless that same push is removed again, and a
4431
+ * removal changes the length unless a push restores it, which changes the
4432
+ * last entry. The first entry is in the stamp as margin. A rebuild is one
4433
+ * pass over the array, paid once per change instead of once per claim.
4434
+ */
4435
+ _bgQueueIndex() {
4436
+ var q = this.bgTaskQueue;
4437
+ var n = q ? q.length : 0;
4438
+ var first = n ? q[0] : void 0;
4439
+ var last = n ? q[n - 1] : void 0;
4440
+ var st = this._bgQueueStamp;
4441
+ if (this._bgQueueByFile && st.arr === q && st.length === n && st.first === first && st.last === last) {
4442
+ return this._bgQueueByFile;
4443
+ }
4444
+ var idx = {};
4445
+ for (var i = 0; i < n; i++) {
4446
+ var e = q[i];
4447
+ if (!e || !e.storagePath) continue;
4448
+ var k = indexScopeKey(e.projectId, e.platform) + "|" + e.storagePath;
4449
+ idx[k] = (idx[k] || 0) + 1;
4450
+ }
4451
+ this._bgQueueByFile = idx;
4452
+ this._bgQueueStamp = { arr: q, length: n, first, last };
4453
+ this._bgQueueIndexRebuilds++;
4454
+ return idx;
4455
+ }
4415
4456
  /**
4416
4457
  * Take this file's indexing slot, or report that someone already has it.
4417
4458
  *
@@ -9119,7 +9160,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
9119
9160
  (function() {
9120
9161
  var MCP_PROD = "https://mcp.broadwayinc.computer";
9121
9162
  var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
9122
- var BQ_VERSION = "1.15.1" ;
9163
+ var BQ_VERSION = "1.15.2" ;
9123
9164
  var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
9124
9165
  var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
9125
9166
  var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
package/dist/engine.cjs CHANGED
@@ -4538,6 +4538,9 @@ var ChatSession = class {
4538
4538
  this._liveIndexKey = "";
4539
4539
  this._liveIndexAt = 0;
4540
4540
  this._indexClaims = {};
4541
+ this._bgQueueByFile = null;
4542
+ this._bgQueueStamp = { arr: null, length: 0, first: void 0, last: void 0 };
4543
+ this._bgQueueIndexRebuilds = 0;
4541
4544
  }
4542
4545
  /** What the display layer needs to decide whether a run is finished. `keys` holds
4543
4546
  * every file the server still has indexing work for; `checked` is false until the
@@ -4574,13 +4577,10 @@ var ChatSession = class {
4574
4577
  */
4575
4578
  hasLiveIndexRun(storagePath) {
4576
4579
  if (!storagePath) return false;
4577
- var claimed = this._indexClaims[this._indexClaimKey(storagePath)];
4580
+ var scoped = this._indexClaimKey(storagePath);
4581
+ var claimed = this._indexClaims[scoped];
4578
4582
  if (claimed && nowMs() - claimed < INDEX_DISPATCH_CLAIM_MS) return true;
4579
- var id = this.host.getIdentity();
4580
- for (var i = 0; i < this.bgTaskQueue.length; i++) {
4581
- var e = this.bgTaskQueue[i];
4582
- if (e && e.storagePath === storagePath && e.projectId === id.projectId && e.platform === id.platform) return true;
4583
- }
4583
+ if (this._bgQueueIndex()[scoped] > 0) return true;
4584
4584
  return this.state.messages.some(function(m) {
4585
4585
  if (!m.isBackgroundTask || m.role !== "user" || m.isCancelled) return false;
4586
4586
  if (!(m.isPendingQueued || m.isPendingInProcess || m.isSendingToServer)) return false;
@@ -4593,6 +4593,47 @@ var ChatSession = class {
4593
4593
  var id = this.host.getIdentity();
4594
4594
  return indexScopeKey(id.projectId, id.platform) + "|" + storagePath;
4595
4595
  }
4596
+ /**
4597
+ * bgTaskQueue as a map: scoped path (indexScopeKey(projectId, platform) +
4598
+ * '|' + storagePath, the key the claims and the stops use) -> entries.
4599
+ *
4600
+ * The array stays the source of truth because the engine does not own every
4601
+ * write to it: both hosts hand in their own array (the dashboard a Vue
4602
+ * reactive one it pushes to from the Files page and splices from its
4603
+ * fallback poller), and tests push to it directly. So the map is DERIVED, and
4604
+ * rebuilt when a cheap stamp says the array changed: its identity, its length,
4605
+ * its first and its last entry.
4606
+ *
4607
+ * Why that stamp is exact for this array: every write to bgTaskQueue is either
4608
+ * a push of a NEW entry object or a splice that removes one (nothing inserts
4609
+ * in the middle, replaces in place or re-pushes a removed entry). Under those
4610
+ * two operations, same length plus same last entry means the same contents:
4611
+ * a push changes the last entry unless that same push is removed again, and a
4612
+ * removal changes the length unless a push restores it, which changes the
4613
+ * last entry. The first entry is in the stamp as margin. A rebuild is one
4614
+ * pass over the array, paid once per change instead of once per claim.
4615
+ */
4616
+ _bgQueueIndex() {
4617
+ var q = this.bgTaskQueue;
4618
+ var n = q ? q.length : 0;
4619
+ var first = n ? q[0] : void 0;
4620
+ var last = n ? q[n - 1] : void 0;
4621
+ var st = this._bgQueueStamp;
4622
+ if (this._bgQueueByFile && st.arr === q && st.length === n && st.first === first && st.last === last) {
4623
+ return this._bgQueueByFile;
4624
+ }
4625
+ var idx = {};
4626
+ for (var i = 0; i < n; i++) {
4627
+ var e = q[i];
4628
+ if (!e || !e.storagePath) continue;
4629
+ var k = indexScopeKey(e.projectId, e.platform) + "|" + e.storagePath;
4630
+ idx[k] = (idx[k] || 0) + 1;
4631
+ }
4632
+ this._bgQueueByFile = idx;
4633
+ this._bgQueueStamp = { arr: q, length: n, first, last };
4634
+ this._bgQueueIndexRebuilds++;
4635
+ return idx;
4636
+ }
4596
4637
  /**
4597
4638
  * Take this file's indexing slot, or report that someone already has it.
4598
4639
  *