bunnyquery 1.10.7 → 1.10.10

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.d.mts CHANGED
@@ -2082,6 +2082,9 @@ type BgTaskEntry = {
2082
2082
  status: 'running' | 'pending';
2083
2083
  poll: ((opts: {
2084
2084
  latency: number;
2085
+ onResponse?: (res: any, meta?: {
2086
+ executed?: number;
2087
+ }) => void;
2085
2088
  }) => Promise<any>) | undefined;
2086
2089
  /** How many CONTINUE passes have already run for this file (resume-across-passes). */
2087
2090
  resumePass?: number;
@@ -4309,7 +4312,22 @@ declare class ChatSession {
4309
4312
  private _isOwnPlaceholderOf;
4310
4313
  _clearPendingUserBubble(itemId: string): void;
4311
4314
  resumePendingRequest(token: number): Promise<void>;
4312
- handleHistoryItemResolution(itemId: string, response: any, platform: string): void;
4315
+ /** Record how long a background indexing pass took, on the bubble that just
4316
+ * settled, so the duration shows immediately instead of waiting for whatever
4317
+ * next refetches history.
4318
+ *
4319
+ * `_tsStart` is otherwise written only by the history mapper, which reads the
4320
+ * row's `executed`; a live settle never sees the row at all (the poll resolves
4321
+ * with the destination's body). This is the same value by the other route.
4322
+ *
4323
+ * `_ts` is stamped too when the branch that built the bubble left it without
4324
+ * one: it is the END of the pass, and the pass ended now. A later history load
4325
+ * replaces both with the server's own numbers.
4326
+ *
4327
+ * Indexing passes only: an ordinary turn has no duration to show, and
4328
+ * `_tsStart`'s presence is what both views read to decide. */
4329
+ private _stampPassDuration;
4330
+ handleHistoryItemResolution(itemId: string, response: any, platform: string, executedAt?: number): void;
4313
4331
  /** The file an already-rendered background pass is about, off its request
4314
4332
  * bubble. Null for an ordinary turn, which is most of them. */
4315
4333
  private _indexRefOfItem;
package/dist/engine.d.ts CHANGED
@@ -2082,6 +2082,9 @@ type BgTaskEntry = {
2082
2082
  status: 'running' | 'pending';
2083
2083
  poll: ((opts: {
2084
2084
  latency: number;
2085
+ onResponse?: (res: any, meta?: {
2086
+ executed?: number;
2087
+ }) => void;
2085
2088
  }) => Promise<any>) | undefined;
2086
2089
  /** How many CONTINUE passes have already run for this file (resume-across-passes). */
2087
2090
  resumePass?: number;
@@ -4309,7 +4312,22 @@ declare class ChatSession {
4309
4312
  private _isOwnPlaceholderOf;
4310
4313
  _clearPendingUserBubble(itemId: string): void;
4311
4314
  resumePendingRequest(token: number): Promise<void>;
4312
- handleHistoryItemResolution(itemId: string, response: any, platform: string): void;
4315
+ /** Record how long a background indexing pass took, on the bubble that just
4316
+ * settled, so the duration shows immediately instead of waiting for whatever
4317
+ * next refetches history.
4318
+ *
4319
+ * `_tsStart` is otherwise written only by the history mapper, which reads the
4320
+ * row's `executed`; a live settle never sees the row at all (the poll resolves
4321
+ * with the destination's body). This is the same value by the other route.
4322
+ *
4323
+ * `_ts` is stamped too when the branch that built the bubble left it without
4324
+ * one: it is the END of the pass, and the pass ended now. A later history load
4325
+ * replaces both with the server's own numbers.
4326
+ *
4327
+ * Indexing passes only: an ordinary turn has no duration to show, and
4328
+ * `_tsStart`'s presence is what both views read to decide. */
4329
+ private _stampPassDuration;
4330
+ handleHistoryItemResolution(itemId: string, response: any, platform: string, executedAt?: number): void;
4313
4331
  /** The file an already-rendered background pass is about, off its request
4314
4332
  * bubble. Null for an ordinary turn, which is most of them. */
4315
4333
  private _indexRefOfItem;
package/dist/engine.mjs CHANGED
@@ -3244,6 +3244,7 @@ function mapHistoryListToMessages(list, platform, opts) {
3244
3244
  if (item._isBgTask) em.isBackgroundTask = true;
3245
3245
  if (serverItemId !== void 0) em._serverItemId = serverItemId;
3246
3246
  if (replyTs !== void 0) em._ts = replyTs;
3247
+ if (indexFile && isFinite(executedTs) && executedTs > 0) em._tsStart = executedTs;
3247
3248
  mapped.push(em);
3248
3249
  } else if (isStreamPending) {
3249
3250
  var sp = { role: "assistant", content: "", _streamPending: true };
@@ -6547,9 +6548,39 @@ var ChatSession = class {
6547
6548
  });
6548
6549
  }
6549
6550
  // --- background-task resolution + drain -------------------------------
6550
- handleHistoryItemResolution(itemId, response, platform) {
6551
+ /** Record how long a background indexing pass took, on the bubble that just
6552
+ * settled, so the duration shows immediately instead of waiting for whatever
6553
+ * next refetches history.
6554
+ *
6555
+ * `_tsStart` is otherwise written only by the history mapper, which reads the
6556
+ * row's `executed`; a live settle never sees the row at all (the poll resolves
6557
+ * with the destination's body). This is the same value by the other route.
6558
+ *
6559
+ * `_ts` is stamped too when the branch that built the bubble left it without
6560
+ * one: it is the END of the pass, and the pass ended now. A later history load
6561
+ * replaces both with the server's own numbers.
6562
+ *
6563
+ * Indexing passes only: an ordinary turn has no duration to show, and
6564
+ * `_tsStart`'s presence is what both views read to decide. */
6565
+ _stampPassDuration(itemId, executedAt) {
6566
+ if (!itemId) return;
6567
+ if (!this._indexRefOfItem(itemId)) return;
6568
+ var hasStart = typeof executedAt === "number" && executedAt > 0;
6569
+ for (var i = this.state.messages.length - 1; i >= 0; i--) {
6570
+ var m = this.state.messages[i];
6571
+ if (!m || m.role !== "assistant" || m._serverItemId !== itemId) continue;
6572
+ if (m.isPending) continue;
6573
+ if (typeof m._ts !== "number") m._ts = Date.now();
6574
+ if (hasStart) m._tsStart = executedAt;
6575
+ this.host.notify();
6576
+ this.updateHistoryCache();
6577
+ break;
6578
+ }
6579
+ }
6580
+ handleHistoryItemResolution(itemId, response, platform, executedAt) {
6551
6581
  var indexRef = this._indexRefOfItem(itemId);
6552
6582
  this.applyHistoryItemResolution(itemId, response, platform);
6583
+ this._stampPassDuration(itemId, executedAt);
6553
6584
  this.promoteNextBgQueuedToRunning();
6554
6585
  this.drainBgTaskQueue();
6555
6586
  if (indexRef) this._followWorkerIndexingChain(indexRef.name, indexRef.mime);
@@ -6996,14 +7027,20 @@ var ChatSession = class {
6996
7027
  var capturedId = entry2.id, capturedPlat = plat;
6997
7028
  var capturedEntry = entry2;
6998
7029
  var wasStopped = false;
6999
- var bp = entry2.poll({ latency: POLL_INTERVAL });
7030
+ var executedAt;
7031
+ var bp = entry2.poll({
7032
+ latency: POLL_INTERVAL,
7033
+ onResponse: function(_res, meta) {
7034
+ if (meta && typeof meta.executed === "number" && meta.executed > 0) executedAt = meta.executed;
7035
+ }
7036
+ });
7000
7037
  self._trackPoll(entry2.id, "bg", bp);
7001
7038
  bp.then(function(response) {
7002
7039
  if (isPollStopped(response)) {
7003
7040
  wasStopped = true;
7004
7041
  return;
7005
7042
  }
7006
- self.handleHistoryItemResolution(capturedId, response, capturedPlat);
7043
+ self.handleHistoryItemResolution(capturedId, response, capturedPlat, executedAt);
7007
7044
  self.maybeResumeIndexing(capturedEntry, response, capturedPlat);
7008
7045
  }).catch(function(err) {
7009
7046
  self.historyItemPolls.delete(capturedId);
@@ -7572,9 +7609,14 @@ var ChatSession = class {
7572
7609
  var capturedId = item.id;
7573
7610
  var isBg = !!(item._isBgTask || item._isOnBgQueue);
7574
7611
  var pollOpts = {
7575
- onResponse: function(response) {
7612
+ // `meta.executed` rides on the poll's running ticks, so a pass this
7613
+ // path re-attached to (a reload or a remount while its chain was
7614
+ // still going) shows its duration at settle exactly as one polled
7615
+ // from the drain does. Without it, only passes started in this page
7616
+ // life would be stamped.
7617
+ onResponse: function(response, meta) {
7576
7618
  if (isPollStopped(response)) return;
7577
- self.handleHistoryItemResolution(capturedId, response, platform);
7619
+ self.handleHistoryItemResolution(capturedId, response, platform, meta && meta.executed);
7578
7620
  },
7579
7621
  onError: function(err) {
7580
7622
  self.historyItemPolls.delete(capturedId);