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/bunnyquery.css +15 -0
- package/bunnyquery.js +177 -25
- package/dist/engine.cjs +99 -12
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.mts +18 -1
- package/dist/engine.d.ts +18 -1
- package/dist/engine.mjs +99 -12
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/host.ts +6 -0
- package/src/engine/indexing_groups.ts +46 -4
- package/src/engine/session.ts +79 -10
- package/src/widget.css +15 -0
package/dist/engine.d.mts
CHANGED
|
@@ -2966,6 +2966,14 @@ interface ChatState {
|
|
|
2966
2966
|
liveIndexRunning?: {
|
|
2967
2967
|
[fileKey: string]: boolean;
|
|
2968
2968
|
};
|
|
2969
|
+
/** The running half of the last look came back whole (see liveIndexRunning), even when
|
|
2970
|
+
* the pending half did not: a file with an open run that is not running is waiting. */
|
|
2971
|
+
liveIndexRunningChecked?: boolean;
|
|
2972
|
+
/** Files a complete look saw leave the queue, kept until they are live again (same keys
|
|
2973
|
+
* as liveIndexKeys). The display reads them like done:: markers. */
|
|
2974
|
+
liveIndexSettled?: {
|
|
2975
|
+
[fileKey: string]: boolean;
|
|
2976
|
+
};
|
|
2969
2977
|
/** Server item ids of the indexing passes that existed — on the row, or on the
|
|
2970
2978
|
* bg queue — when the user STOPPED that file. Two readers, one fact:
|
|
2971
2979
|
* buildChatDisplayList reports the run as stopped when it holds any of them
|
|
@@ -3846,6 +3854,11 @@ type BuildDisplayListOptions = {
|
|
|
3846
3854
|
liveIndexRunningKeys?: {
|
|
3847
3855
|
[fileKey: string]: boolean;
|
|
3848
3856
|
};
|
|
3857
|
+
/** The running half of the queue look is complete (liveIndexRunningChecked). With the
|
|
3858
|
+
* pending half cut off (liveIndexChecked false), a file whose run:: record is still
|
|
3859
|
+
* 'working' and that is not running is waiting: its row says "Queued" instead of
|
|
3860
|
+
* "Fetching status" until the queue is small enough to list whole. */
|
|
3861
|
+
liveIndexRunningChecked?: boolean;
|
|
3849
3862
|
/** Files carrying the durable done:: completion marker (one prefix sweep),
|
|
3850
3863
|
* keyed like IndexingGroup.key (storage path; the bare-name fallback keys
|
|
3851
3864
|
* of very old prompts simply never match — they keep the queue inference).
|
|
@@ -4198,6 +4211,10 @@ declare class ChatSession {
|
|
|
4198
4211
|
running: {
|
|
4199
4212
|
[fileKey: string]: boolean;
|
|
4200
4213
|
};
|
|
4214
|
+
runningChecked: boolean;
|
|
4215
|
+
settled: {
|
|
4216
|
+
[fileKey: string]: boolean;
|
|
4217
|
+
};
|
|
4201
4218
|
};
|
|
4202
4219
|
/** Passes that were on a row when the user stopped it, so the display layer can
|
|
4203
4220
|
* still tell that this run was stopped once the stop has left no other trace.
|
|
@@ -5276,7 +5293,7 @@ declare class ChatSession {
|
|
|
5276
5293
|
*/
|
|
5277
5294
|
private _refreshPageProgress;
|
|
5278
5295
|
/** The page progress to show for a file's row, or null (see _refreshPageProgress). */
|
|
5279
|
-
pageProgressFor(storagePath?: string): {
|
|
5296
|
+
pageProgressFor(storagePath?: string, fileName?: string): {
|
|
5280
5297
|
saved: number;
|
|
5281
5298
|
total: number | null;
|
|
5282
5299
|
} | null;
|
package/dist/engine.d.ts
CHANGED
|
@@ -2966,6 +2966,14 @@ interface ChatState {
|
|
|
2966
2966
|
liveIndexRunning?: {
|
|
2967
2967
|
[fileKey: string]: boolean;
|
|
2968
2968
|
};
|
|
2969
|
+
/** The running half of the last look came back whole (see liveIndexRunning), even when
|
|
2970
|
+
* the pending half did not: a file with an open run that is not running is waiting. */
|
|
2971
|
+
liveIndexRunningChecked?: boolean;
|
|
2972
|
+
/** Files a complete look saw leave the queue, kept until they are live again (same keys
|
|
2973
|
+
* as liveIndexKeys). The display reads them like done:: markers. */
|
|
2974
|
+
liveIndexSettled?: {
|
|
2975
|
+
[fileKey: string]: boolean;
|
|
2976
|
+
};
|
|
2969
2977
|
/** Server item ids of the indexing passes that existed — on the row, or on the
|
|
2970
2978
|
* bg queue — when the user STOPPED that file. Two readers, one fact:
|
|
2971
2979
|
* buildChatDisplayList reports the run as stopped when it holds any of them
|
|
@@ -3846,6 +3854,11 @@ type BuildDisplayListOptions = {
|
|
|
3846
3854
|
liveIndexRunningKeys?: {
|
|
3847
3855
|
[fileKey: string]: boolean;
|
|
3848
3856
|
};
|
|
3857
|
+
/** The running half of the queue look is complete (liveIndexRunningChecked). With the
|
|
3858
|
+
* pending half cut off (liveIndexChecked false), a file whose run:: record is still
|
|
3859
|
+
* 'working' and that is not running is waiting: its row says "Queued" instead of
|
|
3860
|
+
* "Fetching status" until the queue is small enough to list whole. */
|
|
3861
|
+
liveIndexRunningChecked?: boolean;
|
|
3849
3862
|
/** Files carrying the durable done:: completion marker (one prefix sweep),
|
|
3850
3863
|
* keyed like IndexingGroup.key (storage path; the bare-name fallback keys
|
|
3851
3864
|
* of very old prompts simply never match — they keep the queue inference).
|
|
@@ -4198,6 +4211,10 @@ declare class ChatSession {
|
|
|
4198
4211
|
running: {
|
|
4199
4212
|
[fileKey: string]: boolean;
|
|
4200
4213
|
};
|
|
4214
|
+
runningChecked: boolean;
|
|
4215
|
+
settled: {
|
|
4216
|
+
[fileKey: string]: boolean;
|
|
4217
|
+
};
|
|
4201
4218
|
};
|
|
4202
4219
|
/** Passes that were on a row when the user stopped it, so the display layer can
|
|
4203
4220
|
* still tell that this run was stopped once the stop has left no other trace.
|
|
@@ -5276,7 +5293,7 @@ declare class ChatSession {
|
|
|
5276
5293
|
*/
|
|
5277
5294
|
private _refreshPageProgress;
|
|
5278
5295
|
/** The page progress to show for a file's row, or null (see _refreshPageProgress). */
|
|
5279
|
-
pageProgressFor(storagePath?: string): {
|
|
5296
|
+
pageProgressFor(storagePath?: string, fileName?: string): {
|
|
5280
5297
|
saved: number;
|
|
5281
5298
|
total: number | null;
|
|
5282
5299
|
} | null;
|
package/dist/engine.mjs
CHANGED
|
@@ -2836,12 +2836,38 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2836
2836
|
} else if (!grp.finished && grp.driver === "worker" && !liveIndexChecked && !liveIndexKeys[grp.key]) {
|
|
2837
2837
|
grp.resolving = true;
|
|
2838
2838
|
grp.resolvingReason = "status";
|
|
2839
|
+
var openRun = opts && opts.runStubs && (grp.path && opts.runStubs[grp.path] || opts.runStubs[grp.key]);
|
|
2840
|
+
var runNow = opts && opts.liveIndexRunningKeys;
|
|
2841
|
+
if (opts && opts.liveIndexRunningChecked && openRun && openRun.status === "working" && runNow && !runNow[grp.key] && !(grp.path && runNow[grp.path]) && !(grp.name && runNow[grp.name])) {
|
|
2842
|
+
grp.resolving = false;
|
|
2843
|
+
grp.resolvingReason = void 0;
|
|
2844
|
+
grp.queued = true;
|
|
2845
|
+
}
|
|
2839
2846
|
} else {
|
|
2840
2847
|
grp.resolving = false;
|
|
2841
2848
|
}
|
|
2842
2849
|
var runningNow = opts && opts.liveIndexRunningKeys;
|
|
2843
|
-
if (runningNow && !grp.finished && !grp.resolving && grp.status === "active" &&
|
|
2844
|
-
|
|
2850
|
+
if (runningNow && !grp.finished && !grp.resolving && grp.status === "active" && !runningNow[grp.key] && !(grp.path && runningNow[grp.path]) && !(grp.name && runningNow[grp.name])) {
|
|
2851
|
+
var otherRunning = false;
|
|
2852
|
+
if (opts && opts.liveIndexRunningChecked) {
|
|
2853
|
+
for (var rk in runningNow) {
|
|
2854
|
+
if (runningNow[rk] && rk !== grp.key && rk !== grp.path && rk !== grp.name) {
|
|
2855
|
+
otherRunning = true;
|
|
2856
|
+
break;
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
var openRun2 = opts && opts.runStubs && (grp.path && opts.runStubs[grp.path] || opts.runStubs[grp.key]);
|
|
2861
|
+
var waitingOpenRun = !!(opts && opts.liveIndexRunningChecked && openRun2 && openRun2.status === "working");
|
|
2862
|
+
var startedRun = false;
|
|
2863
|
+
for (var mi = 0; mi < grp.members.length; mi++) {
|
|
2864
|
+
var mm = grp.members[mi].msg;
|
|
2865
|
+
if (mm && mm.role === "assistant" && !mm.isPending && !mm.isPendingInProcess && !mm.isPendingQueued) {
|
|
2866
|
+
startedRun = true;
|
|
2867
|
+
break;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
if (!startedRun && (liveIndexKeys[grp.key] || grp.path && liveIndexKeys[grp.path] || otherRunning || waitingOpenRun)) grp.queued = true;
|
|
2845
2871
|
}
|
|
2846
2872
|
}
|
|
2847
2873
|
var superseded = {};
|
|
@@ -2868,6 +2894,7 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2868
2894
|
}
|
|
2869
2895
|
var now = opts && typeof opts.now === "number" ? opts.now : Date.now();
|
|
2870
2896
|
var runningKeys = opts && opts.liveIndexRunningKeys;
|
|
2897
|
+
var runningChecked = !!(opts && opts.liveIndexRunningChecked);
|
|
2871
2898
|
var stubClearedAt = opts && typeof opts.stubClearedAt === "number" && opts.stubClearedAt > 0 ? opts.stubClearedAt : 0;
|
|
2872
2899
|
for (var sp in runStubs) {
|
|
2873
2900
|
var rec = runStubs[sp];
|
|
@@ -2894,6 +2921,7 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2894
2921
|
var st = "active";
|
|
2895
2922
|
var fin = false;
|
|
2896
2923
|
var res = false;
|
|
2924
|
+
var waitingStub = false;
|
|
2897
2925
|
var reason;
|
|
2898
2926
|
if (!live) {
|
|
2899
2927
|
if (rec.status === "done" || doneKeys[sp] || doneKeys[canonIndexKey(sp)] || doneKeys[fname] || doneKeys[canonIndexKey(fname)]) {
|
|
@@ -2911,6 +2939,8 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2911
2939
|
} else if (typeof rec.started === "number" && now - rec.started > RUN_RECORD_WORKING_STALE_MS) {
|
|
2912
2940
|
st = "error";
|
|
2913
2941
|
fin = true;
|
|
2942
|
+
} else if (runningChecked && rec.status === "working") {
|
|
2943
|
+
waitingStub = true;
|
|
2914
2944
|
} else {
|
|
2915
2945
|
res = true;
|
|
2916
2946
|
reason = "status";
|
|
@@ -2944,7 +2974,7 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2944
2974
|
resolving: res,
|
|
2945
2975
|
resolvingReason: reason,
|
|
2946
2976
|
stub: true,
|
|
2947
|
-
queued: live && !!runningKeys && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname] ? true : void 0,
|
|
2977
|
+
queued: waitingStub || live && !!runningKeys && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname] ? true : void 0,
|
|
2948
2978
|
stubError: rec.error || (st === "error" && !rec.error ? "Indexing did not finish." : void 0)
|
|
2949
2979
|
};
|
|
2950
2980
|
stubList.push({ started: typeof rec.started === "number" ? rec.started : Infinity, group: sg });
|
|
@@ -5389,6 +5419,8 @@ var _ChatSession = class _ChatSession {
|
|
|
5389
5419
|
passPaging: {},
|
|
5390
5420
|
liveIndexChecked: false,
|
|
5391
5421
|
liveIndexRunning: {},
|
|
5422
|
+
liveIndexRunningChecked: false,
|
|
5423
|
+
liveIndexSettled: {},
|
|
5392
5424
|
stoppedIndexIds: {}
|
|
5393
5425
|
};
|
|
5394
5426
|
this.bgTaskQueue = [];
|
|
@@ -5416,7 +5448,7 @@ var _ChatSession = class _ChatSession {
|
|
|
5416
5448
|
* every file the server still has indexing work for; `checked` is false until the
|
|
5417
5449
|
* first answer for this chat, and false means "we do not know yet". */
|
|
5418
5450
|
getLiveIndexState() {
|
|
5419
|
-
return { keys: this.state.liveIndexKeys, checked: this.state.liveIndexChecked, running: this.state.liveIndexRunning || {} };
|
|
5451
|
+
return { keys: this.state.liveIndexKeys, checked: this.state.liveIndexChecked, running: this.state.liveIndexRunning || {}, runningChecked: !!this.state.liveIndexRunningChecked, settled: this.state.liveIndexSettled || {} };
|
|
5420
5452
|
}
|
|
5421
5453
|
/** Passes that were on a row when the user stopped it, so the display layer can
|
|
5422
5454
|
* still tell that this run was stopped once the stop has left no other trace.
|
|
@@ -5700,6 +5732,7 @@ var _ChatSession = class _ChatSession {
|
|
|
5700
5732
|
var next = {};
|
|
5701
5733
|
var running = {};
|
|
5702
5734
|
var truncated = false;
|
|
5735
|
+
var runningTruncated = false;
|
|
5703
5736
|
var settledIds = {};
|
|
5704
5737
|
this.state.messages.forEach(function(m) {
|
|
5705
5738
|
if (!m._serverItemId) return;
|
|
@@ -5708,7 +5741,15 @@ var _ChatSession = class _ChatSession {
|
|
|
5708
5741
|
});
|
|
5709
5742
|
for (var li = 0; li < lists.length; li++) {
|
|
5710
5743
|
var list = lists[li] && Array.isArray(lists[li].list) ? lists[li].list : [];
|
|
5711
|
-
if (list.length >= WORKER_PASS_ADOPT_LIMIT
|
|
5744
|
+
if (list.length >= WORKER_PASS_ADOPT_LIMIT || lists[li] && lists[li].endOfList === false) {
|
|
5745
|
+
truncated = true;
|
|
5746
|
+
for (var si = 0; si < list.length; si++) {
|
|
5747
|
+
if (list[si] && list[si].status === "running") {
|
|
5748
|
+
runningTruncated = true;
|
|
5749
|
+
break;
|
|
5750
|
+
}
|
|
5751
|
+
}
|
|
5752
|
+
}
|
|
5712
5753
|
for (var i = 0; i < list.length; i++) {
|
|
5713
5754
|
var item = list[i];
|
|
5714
5755
|
if (!item || item.status !== "pending" && item.status !== "running") continue;
|
|
@@ -5753,7 +5794,19 @@ var _ChatSession = class _ChatSession {
|
|
|
5753
5794
|
}
|
|
5754
5795
|
}
|
|
5755
5796
|
this.state.liveIndexKeys = next;
|
|
5797
|
+
if (this.state.liveIndexRunningChecked !== !runningTruncated) changed = true;
|
|
5798
|
+
var settledNow = this.state.liveIndexSettled || {};
|
|
5799
|
+
var settledNext = {};
|
|
5800
|
+
for (var sk in settledNow) if (settledNow[sk] && !next[sk]) settledNext[sk] = true;
|
|
5801
|
+
if (nowChecked) {
|
|
5802
|
+
for (var wk in was) if (was[wk] && !next[wk]) {
|
|
5803
|
+
if (!settledNext[wk]) changed = true;
|
|
5804
|
+
settledNext[wk] = true;
|
|
5805
|
+
}
|
|
5806
|
+
}
|
|
5807
|
+
this.state.liveIndexSettled = settledNext;
|
|
5756
5808
|
this.state.liveIndexRunning = running;
|
|
5809
|
+
this.state.liveIndexRunningChecked = !runningTruncated;
|
|
5757
5810
|
this.state.liveIndexChecked = nowChecked;
|
|
5758
5811
|
this._liveIndexAt = nowMs();
|
|
5759
5812
|
this._liveIndexKey = this.getHistoryCacheKey();
|
|
@@ -5764,6 +5817,8 @@ var _ChatSession = class _ChatSession {
|
|
|
5764
5817
|
_resetLiveIndexKeys() {
|
|
5765
5818
|
this.state.liveIndexKeys = {};
|
|
5766
5819
|
this.state.liveIndexRunning = {};
|
|
5820
|
+
this.state.liveIndexRunningChecked = false;
|
|
5821
|
+
this.state.liveIndexSettled = {};
|
|
5767
5822
|
this.state.liveIndexChecked = false;
|
|
5768
5823
|
this._liveIndexAt = 0;
|
|
5769
5824
|
this.state.passPaging = {};
|
|
@@ -9132,9 +9187,23 @@ var _ChatSession = class _ChatSession {
|
|
|
9132
9187
|
});
|
|
9133
9188
|
}
|
|
9134
9189
|
/** The page progress to show for a file's row, or null (see _refreshPageProgress). */
|
|
9135
|
-
pageProgressFor(storagePath) {
|
|
9136
|
-
|
|
9137
|
-
|
|
9190
|
+
pageProgressFor(storagePath, fileName) {
|
|
9191
|
+
var map = this.state.indexPageProgress;
|
|
9192
|
+
if (!map) return null;
|
|
9193
|
+
var p = storagePath ? map[storagePath] : void 0;
|
|
9194
|
+
if (!p && fileName) {
|
|
9195
|
+
var hit = null;
|
|
9196
|
+
for (var k in map) {
|
|
9197
|
+
if (k === fileName || k.slice(-(fileName.length + 1)) === "/" + fileName) {
|
|
9198
|
+
if (hit) {
|
|
9199
|
+
hit = null;
|
|
9200
|
+
break;
|
|
9201
|
+
}
|
|
9202
|
+
hit = k;
|
|
9203
|
+
}
|
|
9204
|
+
}
|
|
9205
|
+
if (hit) p = map[hit];
|
|
9206
|
+
}
|
|
9138
9207
|
return p ? { saved: p.saved, total: p.total } : null;
|
|
9139
9208
|
}
|
|
9140
9209
|
_noteLiveLook(svcId, platform, results) {
|
|
@@ -9142,7 +9211,7 @@ var _ChatSession = class _ChatSession {
|
|
|
9142
9211
|
var complete = true;
|
|
9143
9212
|
for (var r = 0; r < results.length; r++) {
|
|
9144
9213
|
var list = results[r] && Array.isArray(results[r].list) ? results[r].list : [];
|
|
9145
|
-
if (list.length >= WORKER_PASS_ADOPT_LIMIT) complete = false;
|
|
9214
|
+
if (list.length >= WORKER_PASS_ADOPT_LIMIT || results[r] && results[r].endOfList === false) complete = false;
|
|
9146
9215
|
for (var i = 0; i < list.length; i++) if (list[i] && typeof list[i].id === "string") ids[list[i].id] = true;
|
|
9147
9216
|
}
|
|
9148
9217
|
this._lastLiveLook = complete ? { svcId, platform, at: Date.now(), ids } : null;
|
|
@@ -10173,6 +10242,7 @@ var _ChatSession = class _ChatSession {
|
|
|
10173
10242
|
uploadSingleAttachment(att, stageId) {
|
|
10174
10243
|
var self = this;
|
|
10175
10244
|
var id = this.host.getIdentity();
|
|
10245
|
+
var isIndexRetry = att.status === "indexError";
|
|
10176
10246
|
att.status = "uploading";
|
|
10177
10247
|
att.progress = null;
|
|
10178
10248
|
att.errorMessage = "";
|
|
@@ -10225,7 +10295,12 @@ var _ChatSession = class _ChatSession {
|
|
|
10225
10295
|
}
|
|
10226
10296
|
});
|
|
10227
10297
|
};
|
|
10228
|
-
|
|
10298
|
+
if (isIndexRetry) {
|
|
10299
|
+
hadExists = true;
|
|
10300
|
+
existedBefore = true;
|
|
10301
|
+
}
|
|
10302
|
+
return (isIndexRetry ? Promise.resolve(null) : findDuplicate(member)).then(function(dup) {
|
|
10303
|
+
if (isIndexRetry) return;
|
|
10229
10304
|
if (dup) {
|
|
10230
10305
|
duplicateOf = dup;
|
|
10231
10306
|
console.log("[chat-engine] skipping an upload the user already has:", member.storagePath, "->", dup);
|
|
@@ -10252,7 +10327,19 @@ var _ChatSession = class _ChatSession {
|
|
|
10252
10327
|
});
|
|
10253
10328
|
}).then(function() {
|
|
10254
10329
|
if (skipped) return;
|
|
10255
|
-
return self.host.getTemporaryUrl(duplicateOf || member.storagePath)
|
|
10330
|
+
return Promise.resolve(self.host.getTemporaryUrl(duplicateOf || member.storagePath)).catch(function(err) {
|
|
10331
|
+
var ecode = err && (err.code || err.body && err.body.code);
|
|
10332
|
+
var emsg = String(err && (err.message || err.body && err.body.message) || err || "");
|
|
10333
|
+
var refused = /no access to this file/i.test(emsg) || ecode === "INVALID_REQUEST" && /access/i.test(emsg);
|
|
10334
|
+
if (duplicateOf || !refused || typeof self.host.ensureFileIndexRecord !== "function") throw err;
|
|
10335
|
+
return Promise.resolve(self.host.ensureFileIndexRecord(member.storagePath, {
|
|
10336
|
+
name: member.file.name,
|
|
10337
|
+
mime: member.file.type || self.host.getMimeType(member.file.name),
|
|
10338
|
+
size: member.file.size
|
|
10339
|
+
})).then(function() {
|
|
10340
|
+
return self.host.getTemporaryUrl(member.storagePath);
|
|
10341
|
+
});
|
|
10342
|
+
});
|
|
10256
10343
|
}).then(function(url) {
|
|
10257
10344
|
if (skipped) return;
|
|
10258
10345
|
if (duplicateOf) {
|
|
@@ -10422,7 +10509,7 @@ var _ChatSession = class _ChatSession {
|
|
|
10422
10509
|
if (!self.state.attachments.some(function(a) {
|
|
10423
10510
|
return a.id === att.id;
|
|
10424
10511
|
})) return;
|
|
10425
|
-
if (att.status === "done"
|
|
10512
|
+
if (att.status === "done") {
|
|
10426
10513
|
if (att.kind === "folder" && att.uploadedUrls) {
|
|
10427
10514
|
att.uploadedUrls.forEach(function(u) {
|
|
10428
10515
|
collected.push({ name: u.path, url: u.url, storagePath: u.storagePath });
|