bunnyquery 1.19.0 → 1.19.1

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.19.0",
3
+ "version": "1.19.1",
4
4
  "description": "Embeddable BunnyQuery AI chat widget + its framework-agnostic chat engine",
5
5
  "main": "bunnyquery.js",
6
6
  "exports": {
@@ -293,6 +293,12 @@ export interface ChatState {
293
293
  /** The files of liveIndexKeys that have a pass RUNNING, same keys. A live file missing
294
294
  * here only has passes waiting: its row says "Queued". */
295
295
  liveIndexRunning?: { [fileKey: string]: boolean };
296
+ /** The running half of the last look came back whole (see liveIndexRunning), even when
297
+ * the pending half did not: a file with an open run that is not running is waiting. */
298
+ liveIndexRunningChecked?: boolean;
299
+ /** Files a complete look saw leave the queue, kept until they are live again (same keys
300
+ * as liveIndexKeys). The display reads them like done:: markers. */
301
+ liveIndexSettled?: { [fileKey: string]: boolean };
296
302
  /** Server item ids of the indexing passes that existed — on the row, or on the
297
303
  * bg queue — when the user STOPPED that file. Two readers, one fact:
298
304
  * buildChatDisplayList reports the run as stopped when it holds any of them
@@ -249,6 +249,11 @@ export type BuildDisplayListOptions = {
249
249
  * is missing here has only waiting passes and is marked `queued`. Absent: unknown, and
250
250
  * no row is marked. */
251
251
  liveIndexRunningKeys?: { [fileKey: string]: boolean };
252
+ /** The running half of the queue look is complete (liveIndexRunningChecked). With the
253
+ * pending half cut off (liveIndexChecked false), a file whose run:: record is still
254
+ * 'working' and that is not running is waiting: its row says "Queued" instead of
255
+ * "Fetching status" until the queue is small enough to list whole. */
256
+ liveIndexRunningChecked?: boolean;
252
257
  /** Files carrying the durable done:: completion marker (one prefix sweep),
253
258
  * keyed like IndexingGroup.key (storage path; the bare-name fallback keys
254
259
  * of very old prompts simply never match — they keep the queue inference).
@@ -888,6 +893,16 @@ export function buildChatDisplayList(
888
893
  // thing here that is actually known.
889
894
  grp.resolving = true;
890
895
  grp.resolvingReason = 'status';
896
+ // Same reading as a run:: row's: the running half is whole and this file is
897
+ // not in it, while its run record says the run is open, so it is waiting.
898
+ var openRun = opts && opts.runStubs && ((grp.path && opts.runStubs[grp.path]) || opts.runStubs[grp.key]);
899
+ var runNow = opts && opts.liveIndexRunningKeys;
900
+ if (opts && opts.liveIndexRunningChecked && openRun && openRun.status === 'working' && runNow
901
+ && !runNow[grp.key] && !(grp.path && runNow[grp.path]) && !(grp.name && runNow[grp.name])) {
902
+ grp.resolving = false;
903
+ grp.resolvingReason = undefined;
904
+ grp.queued = true;
905
+ }
891
906
  } else {
892
907
  grp.resolving = false;
893
908
  }
@@ -896,9 +911,30 @@ export function buildChatDisplayList(
896
911
  // halves of it: live, and not among the running.
897
912
  var runningNow = opts && opts.liveIndexRunningKeys;
898
913
  if (runningNow && !grp.finished && !grp.resolving && grp.status === 'active'
899
- && (liveIndexKeys[grp.key] || (grp.path && liveIndexKeys[grp.path]))
900
914
  && !runningNow[grp.key] && !(grp.path && runningNow[grp.path]) && !(grp.name && runningNow[grp.name])) {
901
- grp.queued = true;
915
+ // A file sent a moment ago is not in the last look yet, and the engine guesses
916
+ // its first pass is running. One project's files index one at a time, so when
917
+ // the look shows ANOTHER file running, this one is waiting whatever the guess.
918
+ var otherRunning = false;
919
+ if (opts && opts.liveIndexRunningChecked) {
920
+ for (var rk in runningNow) {
921
+ if (runningNow[rk] && rk !== grp.key && rk !== grp.path && rk !== grp.name) { otherRunning = true; break; }
922
+ }
923
+ }
924
+ // And a file whose run is open (its run:: record) that the WHOLE running list does
925
+ // not hold: it is waiting, even when the pending list was cut off before it.
926
+ var openRun2 = opts && opts.runStubs && ((grp.path && opts.runStubs[grp.path]) || opts.runStubs[grp.key]);
927
+ var waitingOpenRun = !!(opts && opts.liveIndexRunningChecked && openRun2 && openRun2.status === 'working');
928
+ // Only before the run has done anything: a file with a FINISHED pass is mid-run.
929
+ // Between two of its own passes it is briefly not running, and the look can still
930
+ // hold the pass that just ended; calling that "Queued" next to its saved pages read
931
+ // as going backwards.
932
+ var startedRun = false;
933
+ for (var mi = 0; mi < grp.members.length; mi++) {
934
+ var mm = grp.members[mi].msg;
935
+ if (mm && mm.role === 'assistant' && !mm.isPending && !mm.isPendingInProcess && !mm.isPendingQueued) { startedRun = true; break; }
936
+ }
937
+ if (!startedRun && (liveIndexKeys[grp.key] || (grp.path && liveIndexKeys[grp.path]) || otherRunning || waitingOpenRun)) grp.queued = true;
902
938
  }
903
939
  }
904
940
 
@@ -951,6 +987,7 @@ export function buildChatDisplayList(
951
987
  }
952
988
  var now = opts && typeof opts.now === 'number' ? opts.now : Date.now();
953
989
  var runningKeys = opts && opts.liveIndexRunningKeys;
990
+ var runningChecked = !!(opts && opts.liveIndexRunningChecked);
954
991
  var stubClearedAt = (opts && typeof opts.stubClearedAt === 'number' && opts.stubClearedAt > 0)
955
992
  ? opts.stubClearedAt : 0;
956
993
  for (var sp in runStubs) {
@@ -1005,6 +1042,7 @@ export function buildChatDisplayList(
1005
1042
  var st: IndexingGroupStatus = 'active';
1006
1043
  var fin = false;
1007
1044
  var res = false;
1045
+ var waitingStub = false;
1008
1046
  var reason: 'history' | 'status' | undefined;
1009
1047
  if (!live) {
1010
1048
  // A done:: marker from the same sweep is as terminal as the record's
@@ -1026,6 +1064,10 @@ export function buildChatDisplayList(
1026
1064
  // Older than any real run and still unconfirmed: a dead claim, not
1027
1065
  // an open question. Same horizon the files page applies.
1028
1066
  st = 'error'; fin = true;
1067
+ } else if (runningChecked && rec.status === 'working') {
1068
+ // The pending half was cut off, the running half was not, and this
1069
+ // file is not running: it is waiting behind the files that are.
1070
+ waitingStub = true;
1029
1071
  } else {
1030
1072
  // Genuinely unanswered — the queue reply is one round trip away
1031
1073
  // and this self-heals the moment it lands.
@@ -1062,8 +1104,8 @@ export function buildChatDisplayList(
1062
1104
  resolving: res,
1063
1105
  resolvingReason: reason,
1064
1106
  stub: true,
1065
- queued: live && !!runningKeys
1066
- && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname] ? true : undefined,
1107
+ queued: waitingStub || (live && !!runningKeys
1108
+ && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname]) ? true : undefined,
1067
1109
  stubError: rec.error || (st === 'error' && !rec.error
1068
1110
  ? 'Indexing did not finish.' : undefined),
1069
1111
  };
@@ -674,6 +674,8 @@ export class ChatSession {
674
674
  passPaging: {},
675
675
  liveIndexChecked: false,
676
676
  liveIndexRunning: {},
677
+ liveIndexRunningChecked: false,
678
+ liveIndexSettled: {},
677
679
  stoppedIndexIds: {},
678
680
  };
679
681
  this.bgTaskQueue = [];
@@ -701,8 +703,8 @@ export class ChatSession {
701
703
  /** What the display layer needs to decide whether a run is finished. `keys` holds
702
704
  * every file the server still has indexing work for; `checked` is false until the
703
705
  * first answer for this chat, and false means "we do not know yet". */
704
- getLiveIndexState(): { keys: { [fileKey: string]: boolean }; checked: boolean; running: { [fileKey: string]: boolean } } {
705
- return { keys: this.state.liveIndexKeys, checked: this.state.liveIndexChecked, running: this.state.liveIndexRunning || {} };
706
+ getLiveIndexState(): { keys: { [fileKey: string]: boolean }; checked: boolean; running: { [fileKey: string]: boolean }; runningChecked: boolean; settled: { [fileKey: string]: boolean } } {
707
+ return { keys: this.state.liveIndexKeys, checked: this.state.liveIndexChecked, running: this.state.liveIndexRunning || {}, runningChecked: !!this.state.liveIndexRunningChecked, settled: this.state.liveIndexSettled || {} };
706
708
  }
707
709
 
708
710
  /** Passes that were on a row when the user stopped it, so the display layer can
@@ -1003,6 +1005,11 @@ export class ChatSession {
1003
1005
  // and omits the 20 about to run. Absence would then read as "finished" for
1004
1006
  // exactly the files that have not been touched yet. Report not-knowing instead.
1005
1007
  var truncated = false;
1008
+ // The RUNNING half on its own. A file indexes in at most a few parallel lanes, so the
1009
+ // running list practically never fills; the pending one fills on any bulk upload. A
1010
+ // complete running half still proves something when the pending half is cut off: a
1011
+ // file whose run is open and which is not running is waiting its turn.
1012
+ var runningTruncated = false;
1006
1013
  // Locally settled already. The adopt path refuses these items for the same
1007
1014
  // reason and says why: the status index is eventually consistent, so the pass
1008
1015
  // that just finished can still come back as running. Counting it as live work
@@ -1016,7 +1023,16 @@ export class ChatSession {
1016
1023
  });
1017
1024
  for (var li = 0; li < lists.length; li++) {
1018
1025
  var list = lists[li] && Array.isArray(lists[li].list) ? lists[li].list : [];
1019
- if (list.length >= WORKER_PASS_ADOPT_LIMIT) truncated = true;
1026
+ // Cut off when it came back full OR the server says more exist: a filtered
1027
+ // listing can return fewer rows than asked for and still not be the end, and
1028
+ // reading that page as whole turned every file past it into "Indexed".
1029
+ if (list.length >= WORKER_PASS_ADOPT_LIMIT || (lists[li] && lists[li].endOfList === false)) {
1030
+ truncated = true;
1031
+ // Which half this is, from its items (the callers pass them in either order).
1032
+ for (var si = 0; si < list.length; si++) {
1033
+ if (list[si] && list[si].status === 'running') { runningTruncated = true; break; }
1034
+ }
1035
+ }
1020
1036
  for (var i = 0; i < list.length; i++) {
1021
1037
  var item = list[i];
1022
1038
  if (!item || (item.status !== 'pending' && item.status !== 'running')) continue;
@@ -1053,7 +1069,19 @@ export class ChatSession {
1053
1069
  if (!changed) for (var r2 in wasRun) if (!running[r2]) { changed = true; break; }
1054
1070
  }
1055
1071
  this.state.liveIndexKeys = next;
1072
+ if (this.state.liveIndexRunningChecked !== !runningTruncated) changed = true;
1073
+ // Files seen to LEAVE the queue: live in the previous look, absent from a complete
1074
+ // one. Kept until the file is live again, so a later look that comes back cut off
1075
+ // (a bulk upload behind it) cannot turn its "Indexed" back into "Indexing".
1076
+ var settledNow = this.state.liveIndexSettled || {};
1077
+ var settledNext: { [k: string]: boolean } = {};
1078
+ for (var sk in settledNow) if (settledNow[sk] && !next[sk]) settledNext[sk] = true;
1079
+ if (nowChecked) {
1080
+ for (var wk in was) if (was[wk] && !next[wk]) { if (!settledNext[wk]) changed = true; settledNext[wk] = true; }
1081
+ }
1082
+ this.state.liveIndexSettled = settledNext;
1056
1083
  this.state.liveIndexRunning = running;
1084
+ this.state.liveIndexRunningChecked = !runningTruncated;
1057
1085
  this.state.liveIndexChecked = nowChecked;
1058
1086
  this._liveIndexAt = nowMs();
1059
1087
  // Claim the snapshot for the CURRENT chat. Both callers verify identity before
@@ -1075,6 +1103,8 @@ export class ChatSession {
1075
1103
  private _resetLiveIndexKeys(): void {
1076
1104
  this.state.liveIndexKeys = {};
1077
1105
  this.state.liveIndexRunning = {};
1106
+ this.state.liveIndexRunningChecked = false;
1107
+ this.state.liveIndexSettled = {};
1078
1108
  this.state.liveIndexChecked = false;
1079
1109
  this._liveIndexAt = 0;
1080
1110
  // Steps loaded into rows belong to that chat too.
@@ -5325,9 +5355,23 @@ export class ChatSession {
5325
5355
  }
5326
5356
 
5327
5357
  /** The page progress to show for a file's row, or null (see _refreshPageProgress). */
5328
- pageProgressFor(storagePath?: string): { saved: number; total: number | null } | null {
5329
- if (!storagePath || !this.state.indexPageProgress) return null;
5330
- var p = this.state.indexPageProgress[storagePath];
5358
+ pageProgressFor(storagePath?: string, fileName?: string): { saved: number; total: number | null } | null {
5359
+ var map = this.state.indexPageProgress;
5360
+ if (!map) return null;
5361
+ var p = storagePath ? map[storagePath] : undefined;
5362
+ // A row put together from passes the queue check just found can lack its storage
5363
+ // path for a moment (the first of them carries it); the file NAME still finds the
5364
+ // progress then, when exactly one file of that name is being followed.
5365
+ if (!p && fileName) {
5366
+ var hit: string | null = null;
5367
+ for (var k in map) {
5368
+ if (k === fileName || k.slice(-(fileName.length + 1)) === '/' + fileName) {
5369
+ if (hit) { hit = null; break; }
5370
+ hit = k;
5371
+ }
5372
+ }
5373
+ if (hit) p = map[hit];
5374
+ }
5331
5375
  return p ? { saved: p.saved, total: p.total } : null;
5332
5376
  }
5333
5377
 
@@ -5336,7 +5380,7 @@ export class ChatSession {
5336
5380
  var complete = true;
5337
5381
  for (var r = 0; r < results.length; r++) {
5338
5382
  var list = results[r] && Array.isArray(results[r].list) ? results[r].list : [];
5339
- if (list.length >= WORKER_PASS_ADOPT_LIMIT) complete = false;
5383
+ if (list.length >= WORKER_PASS_ADOPT_LIMIT || (results[r] && results[r].endOfList === false)) complete = false;
5340
5384
  for (var i = 0; i < list.length; i++) if (list[i] && typeof list[i].id === 'string') ids[list[i].id] = true;
5341
5385
  }
5342
5386
  this._lastLiveLook = complete ? { svcId: svcId, platform: platform, at: Date.now(), ids: ids } : null;
@@ -6744,6 +6788,12 @@ export class ChatSession {
6744
6788
  uploadSingleAttachment(att: any, stageId?: string): Promise<Array<{ name: string; url: string; storagePath: string }>> {
6745
6789
  var self = this;
6746
6790
  var id = this.host.getIdentity();
6791
+ // Read BEFORE the status is reset below: a chip in "indexError" is one whose
6792
+ // bytes are already stored and only whose indexing failed. Its retry (the next
6793
+ // Send) re-indexes the stored copies through the "file is already there,
6794
+ // reindex it" path: no second upload, no "already exists" question about the
6795
+ // user's own file, no duplicate check (agent.vue isIndexRetry).
6796
+ var isIndexRetry = att.status === 'indexError';
6747
6797
  // progress stays null until the first byte-progress event. Every upload
6748
6798
  // opens with a get-signed-url round trip that reports nothing, so a chip
6749
6799
  // initialised to 0 rendered an empty, motionless bar for the whole
@@ -6810,7 +6860,9 @@ export class ChatSession {
6810
6860
  onProgress: onProg, setAbort: function (abort) { att._abort = abort; },
6811
6861
  });
6812
6862
  };
6813
- return findDuplicate(member).then(function (dup) {
6863
+ if (isIndexRetry) { hadExists = true; existedBefore = true; }
6864
+ return (isIndexRetry ? Promise.resolve(null) : findDuplicate(member)).then(function (dup) {
6865
+ if (isIndexRetry) return;
6814
6866
  if (dup) {
6815
6867
  duplicateOf = dup;
6816
6868
  console.log('[chat-engine] skipping an upload the user already has:', member.storagePath, '->', dup);
@@ -6841,7 +6893,22 @@ export class ChatSession {
6841
6893
  // A duplicate takes the STORED copy's url: the same reuse an EXISTS
6842
6894
  // answer gets when the user keeps the file, minus the prompt and
6843
6895
  // minus the re-index.
6844
- return self.host.getTemporaryUrl(duplicateOf || member.storagePath);
6896
+ return Promise.resolve(self.host.getTemporaryUrl(duplicateOf || member.storagePath)).catch(function (err: any) {
6897
+ // A file nobody has indexed yet is readable by the project OWNER only
6898
+ // (the store's access rule), so for any other uploader the link to the
6899
+ // file they just uploaded is refused ("No access to this file.") and the
6900
+ // file could never be indexed. Its file record makes it a file of the
6901
+ // uploader's chosen group, which they can read: create it now (the step
6902
+ // below would have created the same record a moment later, and a second
6903
+ // create is refused harmlessly) and ask again.
6904
+ var ecode = err && (err.code || (err.body && err.body.code));
6905
+ var emsg = String((err && (err.message || (err.body && err.body.message))) || err || '');
6906
+ var refused = /no access to this file/i.test(emsg) || (ecode === 'INVALID_REQUEST' && /access/i.test(emsg));
6907
+ if (duplicateOf || !refused || typeof self.host.ensureFileIndexRecord !== 'function') throw err;
6908
+ return Promise.resolve(self.host.ensureFileIndexRecord(member.storagePath, {
6909
+ name: member.file.name, mime: member.file.type || self.host.getMimeType(member.file.name), size: member.file.size,
6910
+ })).then(function () { return self.host.getTemporaryUrl(member.storagePath); });
6911
+ });
6845
6912
  }).then(function (url: string) {
6846
6913
  if (skipped) return; // guard the indexing branch for a skipped member
6847
6914
  if (duplicateOf) {
@@ -7027,7 +7094,9 @@ export class ChatSession {
7027
7094
  snapshot.forEach(function (att: any) {
7028
7095
  chain = chain.then(function () {
7029
7096
  if (!self.state.attachments.some(function (a: any) { return a.id === att.id; })) return; // removed
7030
- if (att.status === 'done' || att.status === 'indexError') {
7097
+ // "indexError" is NOT collected as-is: its upload worked but its indexing
7098
+ // did not, and uploadSingleAttachment retries just the indexing.
7099
+ if (att.status === 'done') {
7031
7100
  if (att.kind === 'folder' && att.uploadedUrls) {
7032
7101
  att.uploadedUrls.forEach(function (u: any) { collected.push({ name: u.path, url: u.url, storagePath: u.storagePath }); });
7033
7102
  return;
package/src/widget.css CHANGED
@@ -727,6 +727,21 @@
727
727
  pointer-events: none;
728
728
  opacity: 0.92;
729
729
  }
730
+ /* "Preparing files..." between a drop and its chips (agent.vue / main.less
731
+ .bq-drop-preparing). Swallows clicks on purpose, unlike the drag overlay:
732
+ it sits over controls whose files are still being read. */
733
+ .bq-drop-preparing {
734
+ position: absolute;
735
+ inset: 0;
736
+ z-index: 11;
737
+ display: flex;
738
+ align-items: center;
739
+ justify-content: center;
740
+ background: color-mix(in srgb, var(--bq-paper) 85%, transparent);
741
+ pointer-events: auto;
742
+ cursor: progress;
743
+ user-select: none;
744
+ }
730
745
  .bq-drop-overlay-inner {
731
746
  display: flex;
732
747
  flex-direction: column;