bunnyquery 1.21.3 → 1.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunnyquery",
3
- "version": "1.21.3",
3
+ "version": "1.21.4",
4
4
  "description": "Embeddable BunnyQuery AI chat widget + its framework-agnostic chat engine",
5
5
  "main": "bunnyquery.js",
6
6
  "exports": {
@@ -67,6 +67,7 @@ import type { ChatMessage, IndexingFileRef } from './host';
67
67
  import { isPagedReadFile, isImageVisionFile } from './office';
68
68
  import { windowedIndexingEnabled } from './config';
69
69
  import { MAX_INDEXING_RESUME_PASSES } from './requests';
70
+ import { messageTimeMs } from './time';
70
71
 
71
72
  export type IndexingGroupStatus = 'active' | 'done' | 'error' | 'cancelled';
72
73
 
@@ -542,8 +543,12 @@ export function buildChatDisplayList(
542
543
  // label-only behaviour stands, so the re-index case is unchanged.
543
544
  var openId = openRunOfKey[key];
544
545
  var notLater = false;
545
- if (openId && typeof msg._ts === 'number' && typeof newestTsOfRun[openId] === 'number') {
546
- notLater = (msg._ts as number) <= newestTsOfRun[openId];
546
+ // A message's time is its _ts, else its request id's (messageTimeMs): a live
547
+ // worker pass adopted from the queue has no _ts, and without a time on both
548
+ // sides an OLDER first pass loaded after it split the run in two (2026-11-25).
549
+ var msgTime = messageTimeMs(msg);
550
+ if (openId && msgTime > 0 && typeof newestTsOfRun[openId] === 'number') {
551
+ notLater = msgTime <= newestTsOfRun[openId];
547
552
  }
548
553
  if (!ref.continued && !alreadySeen && !notLater && openRunOfKey[key]) delete openRunOfKey[key];
549
554
  runId = openRunOfKey[key];
@@ -567,9 +572,10 @@ export function buildChatDisplayList(
567
572
  // or a response whose request is not loaded) stays an ordinary message
568
573
  // rather than being folded into whichever group happens to be nearest.
569
574
  if (!runId) continue;
570
- if (typeof msg._ts === 'number') {
575
+ var memberTime = messageTimeMs(msg);
576
+ if (memberTime > 0) {
571
577
  var prevTs = newestTsOfRun[runId];
572
- if (typeof prevTs !== 'number' || (msg._ts as number) > prevTs) newestTsOfRun[runId] = msg._ts as number;
578
+ if (typeof prevTs !== 'number' || memberTime > prevTs) newestTsOfRun[runId] = memberTime;
573
579
  }
574
580
 
575
581
  var g = groups[runId];
@@ -59,7 +59,7 @@ import { retrievalNoteOfAnswer, answerUsedNoDataTool } from './citations';
59
59
  import { createInlineLinkRegex, sanitizeAttachmentLinksForHistory } from './links';
60
60
  import { markImagePreviewStale } from './image_preview';
61
61
  import { chatCacheKey, indexScopeKey, mapHistoryListToMessages, extractLastUserTextFromRequest, listedRequestText, isIndexingRequestText, parseIndexingRequestText, probeBgQueue, BG_PROBE_TTL_MS, fetchLiveIndexingKeys, getSplitChatHistory, shouldRescueInFlightMessage, adoptLocalAnswerIntoPage, adoptLiveTextIntoRunningRow } from './history';
62
- import { wallClockNow } from './time';
62
+ import { wallClockNow, requestIdTimeMs, messageTimeMs } from './time';
63
63
  import { parseAttachmentContent } from './attachment_parsers';
64
64
  import type { ChatHost, ChatState, ChatMessage, ChatIdentity, PinnedDispatchContext, IndexQueueSnapshot } from './host';
65
65
  import type { IndexingGroup } from './indexing_groups';
@@ -839,25 +839,8 @@ type LiveStreamState = {
839
839
  transport: { socket: number; poll: number };
840
840
  };
841
841
 
842
- /**
843
- * Creation time (ms epoch) of a request id "stamp:entropy", whose stamp is a time_ns written
844
- * as 8 bytes of base32hex without padding (the worker's and the producer's _generate_req_id).
845
- * 0 when it is not one.
846
- */
847
- export function requestIdTimeMs(rid: string): number {
848
- if (typeof rid !== 'string') return 0;
849
- var stamp = rid.split(':')[0] || '';
850
- if (stamp.length !== 13) return 0;
851
- var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
852
- var v = 0;
853
- for (var i = 0; i < stamp.length; i++) {
854
- var d = alphabet.indexOf(stamp.charAt(i).toUpperCase());
855
- if (d < 0) return 0;
856
- v = v * 32 + d;
857
- }
858
- // 13 digits are 65 bits for 64 of data: the last bit is padding.
859
- return Math.floor(v / 2 / 1e6);
860
- }
842
+ // requestIdTimeMs lives in time.ts (2026-11-25: indexing_groups.ts needs it too); re-exported here.
843
+ export { requestIdTimeMs };
861
844
 
862
845
  /** The visible message the "Wrong answer?" button sends. The chat prompt's WRONG ANSWER rule reacts to it. */
863
846
  export var WRONG_ANSWER_MESSAGE = 'This answer seems wrong. Please check it again against the documents.';
@@ -7602,15 +7585,18 @@ export class ChatSession {
7602
7585
  });
7603
7586
  }
7604
7587
 
7605
- /** Insert bubbles before the first message that is newer than them (by `_ts`); messages
7606
- * without a time are skipped over, and the end of the list takes them otherwise. */
7588
+ /** Insert bubbles before the first message that is newer than them; messages whose time
7589
+ * is unknown are skipped over, and the end of the list takes them otherwise. A message's
7590
+ * time is its `_ts`, else (2026-11-25) the time in its request id: a live worker pass
7591
+ * adopted from the queue carries no `_ts`, and a file's older passes loaded by opening its
7592
+ * row (loadRunPasses) used to land AFTER it, which split one run into two rows. */
7607
7593
  private _insertByTime(bubbles: ChatMessage[]): void {
7608
- var at = bubbles[0] && bubbles[0]._ts;
7594
+ var at = messageTimeMs(bubbles[0]);
7609
7595
  var idx = this.state.messages.length;
7610
- if (typeof at === 'number') {
7596
+ if (at > 0) {
7611
7597
  for (var i = 0; i < this.state.messages.length; i++) {
7612
- var t = this.state.messages[i] && this.state.messages[i]._ts;
7613
- if (typeof t === 'number' && t > at) { idx = i; break; }
7598
+ var t = messageTimeMs(this.state.messages[i]);
7599
+ if (t > 0 && t > at) { idx = i; break; }
7614
7600
  }
7615
7601
  }
7616
7602
  Array.prototype.splice.apply(this.state.messages, ([idx, 0] as any[]).concat(bubbles));
@@ -61,3 +61,39 @@ export function formatDuration(ms?: number): string {
61
61
  out.push(s + 's');
62
62
  return out.join(' ');
63
63
  }
64
+
65
+ /**
66
+ * Creation time (ms epoch) of a request id "stamp:entropy", whose stamp is a time_ns written
67
+ * as 8 bytes of base32hex without padding (the worker's and the producer's _generate_req_id).
68
+ * 0 when it is not one.
69
+ */
70
+ export function requestIdTimeMs(rid: string): number {
71
+ if (typeof rid !== 'string') return 0;
72
+ var stamp = rid.split(':')[0] || '';
73
+ if (stamp.length !== 13) return 0;
74
+ var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
75
+ var v = 0;
76
+ for (var i = 0; i < stamp.length; i++) {
77
+ var d = alphabet.indexOf(stamp.charAt(i).toUpperCase());
78
+ if (d < 0) return 0;
79
+ v = v * 32 + d;
80
+ }
81
+ // 13 digits are 65 bits for 64 of data: the last bit is padding.
82
+ return Math.floor(v / 2 / 1e6);
83
+ }
84
+
85
+ /**
86
+ * A chat message's time in epoch ms, for ORDERING and grouping (never for display): the time
87
+ * in its request id (`_serverItemId`, "stamp:entropy", the server's clock) when it has one,
88
+ * else its `_ts`, else 0 (unknown). Request-id first so every comparison uses one clock: a
89
+ * live-settled reply's `_ts` is the browser's Date.now(), and mixing the two let a browser
90
+ * running ahead of the server fold a re-index into the previous run. A request and its reply
91
+ * share one id, so nothing is ever ordered between them. A live background pass adopted from
92
+ * the queue has no `_ts` at all until it settles.
93
+ */
94
+ export function messageTimeMs(m: { _ts?: number; _serverItemId?: string } | null | undefined): number {
95
+ if (!m) return 0;
96
+ var r = typeof m._serverItemId === 'string' ? requestIdTimeMs(m._serverItemId) : 0;
97
+ if (r > 0) return r;
98
+ return typeof m._ts === 'number' && m._ts > 0 ? m._ts : 0;
99
+ }