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.cjs
CHANGED
|
@@ -2838,12 +2838,38 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2838
2838
|
} else if (!grp.finished && grp.driver === "worker" && !liveIndexChecked && !liveIndexKeys[grp.key]) {
|
|
2839
2839
|
grp.resolving = true;
|
|
2840
2840
|
grp.resolvingReason = "status";
|
|
2841
|
+
var openRun = opts && opts.runStubs && (grp.path && opts.runStubs[grp.path] || opts.runStubs[grp.key]);
|
|
2842
|
+
var runNow = opts && opts.liveIndexRunningKeys;
|
|
2843
|
+
if (opts && opts.liveIndexRunningChecked && openRun && openRun.status === "working" && runNow && !runNow[grp.key] && !(grp.path && runNow[grp.path]) && !(grp.name && runNow[grp.name])) {
|
|
2844
|
+
grp.resolving = false;
|
|
2845
|
+
grp.resolvingReason = void 0;
|
|
2846
|
+
grp.queued = true;
|
|
2847
|
+
}
|
|
2841
2848
|
} else {
|
|
2842
2849
|
grp.resolving = false;
|
|
2843
2850
|
}
|
|
2844
2851
|
var runningNow = opts && opts.liveIndexRunningKeys;
|
|
2845
|
-
if (runningNow && !grp.finished && !grp.resolving && grp.status === "active" &&
|
|
2846
|
-
|
|
2852
|
+
if (runningNow && !grp.finished && !grp.resolving && grp.status === "active" && !runningNow[grp.key] && !(grp.path && runningNow[grp.path]) && !(grp.name && runningNow[grp.name])) {
|
|
2853
|
+
var otherRunning = false;
|
|
2854
|
+
if (opts && opts.liveIndexRunningChecked) {
|
|
2855
|
+
for (var rk in runningNow) {
|
|
2856
|
+
if (runningNow[rk] && rk !== grp.key && rk !== grp.path && rk !== grp.name) {
|
|
2857
|
+
otherRunning = true;
|
|
2858
|
+
break;
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
var openRun2 = opts && opts.runStubs && (grp.path && opts.runStubs[grp.path] || opts.runStubs[grp.key]);
|
|
2863
|
+
var waitingOpenRun = !!(opts && opts.liveIndexRunningChecked && openRun2 && openRun2.status === "working");
|
|
2864
|
+
var startedRun = false;
|
|
2865
|
+
for (var mi = 0; mi < grp.members.length; mi++) {
|
|
2866
|
+
var mm = grp.members[mi].msg;
|
|
2867
|
+
if (mm && mm.role === "assistant" && !mm.isPending && !mm.isPendingInProcess && !mm.isPendingQueued) {
|
|
2868
|
+
startedRun = true;
|
|
2869
|
+
break;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
if (!startedRun && (liveIndexKeys[grp.key] || grp.path && liveIndexKeys[grp.path] || otherRunning || waitingOpenRun)) grp.queued = true;
|
|
2847
2873
|
}
|
|
2848
2874
|
}
|
|
2849
2875
|
var superseded = {};
|
|
@@ -2870,6 +2896,7 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2870
2896
|
}
|
|
2871
2897
|
var now = opts && typeof opts.now === "number" ? opts.now : Date.now();
|
|
2872
2898
|
var runningKeys = opts && opts.liveIndexRunningKeys;
|
|
2899
|
+
var runningChecked = !!(opts && opts.liveIndexRunningChecked);
|
|
2873
2900
|
var stubClearedAt = opts && typeof opts.stubClearedAt === "number" && opts.stubClearedAt > 0 ? opts.stubClearedAt : 0;
|
|
2874
2901
|
for (var sp in runStubs) {
|
|
2875
2902
|
var rec = runStubs[sp];
|
|
@@ -2896,6 +2923,7 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2896
2923
|
var st = "active";
|
|
2897
2924
|
var fin = false;
|
|
2898
2925
|
var res = false;
|
|
2926
|
+
var waitingStub = false;
|
|
2899
2927
|
var reason;
|
|
2900
2928
|
if (!live) {
|
|
2901
2929
|
if (rec.status === "done" || doneKeys[sp] || doneKeys[canonIndexKey(sp)] || doneKeys[fname] || doneKeys[canonIndexKey(fname)]) {
|
|
@@ -2913,6 +2941,8 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2913
2941
|
} else if (typeof rec.started === "number" && now - rec.started > RUN_RECORD_WORKING_STALE_MS) {
|
|
2914
2942
|
st = "error";
|
|
2915
2943
|
fin = true;
|
|
2944
|
+
} else if (runningChecked && rec.status === "working") {
|
|
2945
|
+
waitingStub = true;
|
|
2916
2946
|
} else {
|
|
2917
2947
|
res = true;
|
|
2918
2948
|
reason = "status";
|
|
@@ -2946,7 +2976,7 @@ function buildChatDisplayList(messages, opts) {
|
|
|
2946
2976
|
resolving: res,
|
|
2947
2977
|
resolvingReason: reason,
|
|
2948
2978
|
stub: true,
|
|
2949
|
-
queued: live && !!runningKeys && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname] ? true : void 0,
|
|
2979
|
+
queued: waitingStub || live && !!runningKeys && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname] ? true : void 0,
|
|
2950
2980
|
stubError: rec.error || (st === "error" && !rec.error ? "Indexing did not finish." : void 0)
|
|
2951
2981
|
};
|
|
2952
2982
|
stubList.push({ started: typeof rec.started === "number" ? rec.started : Infinity, group: sg });
|
|
@@ -5391,6 +5421,8 @@ var _ChatSession = class _ChatSession {
|
|
|
5391
5421
|
passPaging: {},
|
|
5392
5422
|
liveIndexChecked: false,
|
|
5393
5423
|
liveIndexRunning: {},
|
|
5424
|
+
liveIndexRunningChecked: false,
|
|
5425
|
+
liveIndexSettled: {},
|
|
5394
5426
|
stoppedIndexIds: {}
|
|
5395
5427
|
};
|
|
5396
5428
|
this.bgTaskQueue = [];
|
|
@@ -5418,7 +5450,7 @@ var _ChatSession = class _ChatSession {
|
|
|
5418
5450
|
* every file the server still has indexing work for; `checked` is false until the
|
|
5419
5451
|
* first answer for this chat, and false means "we do not know yet". */
|
|
5420
5452
|
getLiveIndexState() {
|
|
5421
|
-
return { keys: this.state.liveIndexKeys, checked: this.state.liveIndexChecked, running: this.state.liveIndexRunning || {} };
|
|
5453
|
+
return { keys: this.state.liveIndexKeys, checked: this.state.liveIndexChecked, running: this.state.liveIndexRunning || {}, runningChecked: !!this.state.liveIndexRunningChecked, settled: this.state.liveIndexSettled || {} };
|
|
5422
5454
|
}
|
|
5423
5455
|
/** Passes that were on a row when the user stopped it, so the display layer can
|
|
5424
5456
|
* still tell that this run was stopped once the stop has left no other trace.
|
|
@@ -5702,6 +5734,7 @@ var _ChatSession = class _ChatSession {
|
|
|
5702
5734
|
var next = {};
|
|
5703
5735
|
var running = {};
|
|
5704
5736
|
var truncated = false;
|
|
5737
|
+
var runningTruncated = false;
|
|
5705
5738
|
var settledIds = {};
|
|
5706
5739
|
this.state.messages.forEach(function(m) {
|
|
5707
5740
|
if (!m._serverItemId) return;
|
|
@@ -5710,7 +5743,15 @@ var _ChatSession = class _ChatSession {
|
|
|
5710
5743
|
});
|
|
5711
5744
|
for (var li = 0; li < lists.length; li++) {
|
|
5712
5745
|
var list = lists[li] && Array.isArray(lists[li].list) ? lists[li].list : [];
|
|
5713
|
-
if (list.length >= WORKER_PASS_ADOPT_LIMIT
|
|
5746
|
+
if (list.length >= WORKER_PASS_ADOPT_LIMIT || lists[li] && lists[li].endOfList === false) {
|
|
5747
|
+
truncated = true;
|
|
5748
|
+
for (var si = 0; si < list.length; si++) {
|
|
5749
|
+
if (list[si] && list[si].status === "running") {
|
|
5750
|
+
runningTruncated = true;
|
|
5751
|
+
break;
|
|
5752
|
+
}
|
|
5753
|
+
}
|
|
5754
|
+
}
|
|
5714
5755
|
for (var i = 0; i < list.length; i++) {
|
|
5715
5756
|
var item = list[i];
|
|
5716
5757
|
if (!item || item.status !== "pending" && item.status !== "running") continue;
|
|
@@ -5755,7 +5796,19 @@ var _ChatSession = class _ChatSession {
|
|
|
5755
5796
|
}
|
|
5756
5797
|
}
|
|
5757
5798
|
this.state.liveIndexKeys = next;
|
|
5799
|
+
if (this.state.liveIndexRunningChecked !== !runningTruncated) changed = true;
|
|
5800
|
+
var settledNow = this.state.liveIndexSettled || {};
|
|
5801
|
+
var settledNext = {};
|
|
5802
|
+
for (var sk in settledNow) if (settledNow[sk] && !next[sk]) settledNext[sk] = true;
|
|
5803
|
+
if (nowChecked) {
|
|
5804
|
+
for (var wk in was) if (was[wk] && !next[wk]) {
|
|
5805
|
+
if (!settledNext[wk]) changed = true;
|
|
5806
|
+
settledNext[wk] = true;
|
|
5807
|
+
}
|
|
5808
|
+
}
|
|
5809
|
+
this.state.liveIndexSettled = settledNext;
|
|
5758
5810
|
this.state.liveIndexRunning = running;
|
|
5811
|
+
this.state.liveIndexRunningChecked = !runningTruncated;
|
|
5759
5812
|
this.state.liveIndexChecked = nowChecked;
|
|
5760
5813
|
this._liveIndexAt = nowMs();
|
|
5761
5814
|
this._liveIndexKey = this.getHistoryCacheKey();
|
|
@@ -5766,6 +5819,8 @@ var _ChatSession = class _ChatSession {
|
|
|
5766
5819
|
_resetLiveIndexKeys() {
|
|
5767
5820
|
this.state.liveIndexKeys = {};
|
|
5768
5821
|
this.state.liveIndexRunning = {};
|
|
5822
|
+
this.state.liveIndexRunningChecked = false;
|
|
5823
|
+
this.state.liveIndexSettled = {};
|
|
5769
5824
|
this.state.liveIndexChecked = false;
|
|
5770
5825
|
this._liveIndexAt = 0;
|
|
5771
5826
|
this.state.passPaging = {};
|
|
@@ -9134,9 +9189,23 @@ var _ChatSession = class _ChatSession {
|
|
|
9134
9189
|
});
|
|
9135
9190
|
}
|
|
9136
9191
|
/** The page progress to show for a file's row, or null (see _refreshPageProgress). */
|
|
9137
|
-
pageProgressFor(storagePath) {
|
|
9138
|
-
|
|
9139
|
-
|
|
9192
|
+
pageProgressFor(storagePath, fileName) {
|
|
9193
|
+
var map = this.state.indexPageProgress;
|
|
9194
|
+
if (!map) return null;
|
|
9195
|
+
var p = storagePath ? map[storagePath] : void 0;
|
|
9196
|
+
if (!p && fileName) {
|
|
9197
|
+
var hit = null;
|
|
9198
|
+
for (var k in map) {
|
|
9199
|
+
if (k === fileName || k.slice(-(fileName.length + 1)) === "/" + fileName) {
|
|
9200
|
+
if (hit) {
|
|
9201
|
+
hit = null;
|
|
9202
|
+
break;
|
|
9203
|
+
}
|
|
9204
|
+
hit = k;
|
|
9205
|
+
}
|
|
9206
|
+
}
|
|
9207
|
+
if (hit) p = map[hit];
|
|
9208
|
+
}
|
|
9140
9209
|
return p ? { saved: p.saved, total: p.total } : null;
|
|
9141
9210
|
}
|
|
9142
9211
|
_noteLiveLook(svcId, platform, results) {
|
|
@@ -9144,7 +9213,7 @@ var _ChatSession = class _ChatSession {
|
|
|
9144
9213
|
var complete = true;
|
|
9145
9214
|
for (var r = 0; r < results.length; r++) {
|
|
9146
9215
|
var list = results[r] && Array.isArray(results[r].list) ? results[r].list : [];
|
|
9147
|
-
if (list.length >= WORKER_PASS_ADOPT_LIMIT) complete = false;
|
|
9216
|
+
if (list.length >= WORKER_PASS_ADOPT_LIMIT || results[r] && results[r].endOfList === false) complete = false;
|
|
9148
9217
|
for (var i = 0; i < list.length; i++) if (list[i] && typeof list[i].id === "string") ids[list[i].id] = true;
|
|
9149
9218
|
}
|
|
9150
9219
|
this._lastLiveLook = complete ? { svcId, platform, at: Date.now(), ids } : null;
|
|
@@ -10175,6 +10244,7 @@ var _ChatSession = class _ChatSession {
|
|
|
10175
10244
|
uploadSingleAttachment(att, stageId) {
|
|
10176
10245
|
var self = this;
|
|
10177
10246
|
var id = this.host.getIdentity();
|
|
10247
|
+
var isIndexRetry = att.status === "indexError";
|
|
10178
10248
|
att.status = "uploading";
|
|
10179
10249
|
att.progress = null;
|
|
10180
10250
|
att.errorMessage = "";
|
|
@@ -10227,7 +10297,12 @@ var _ChatSession = class _ChatSession {
|
|
|
10227
10297
|
}
|
|
10228
10298
|
});
|
|
10229
10299
|
};
|
|
10230
|
-
|
|
10300
|
+
if (isIndexRetry) {
|
|
10301
|
+
hadExists = true;
|
|
10302
|
+
existedBefore = true;
|
|
10303
|
+
}
|
|
10304
|
+
return (isIndexRetry ? Promise.resolve(null) : findDuplicate(member)).then(function(dup) {
|
|
10305
|
+
if (isIndexRetry) return;
|
|
10231
10306
|
if (dup) {
|
|
10232
10307
|
duplicateOf = dup;
|
|
10233
10308
|
console.log("[chat-engine] skipping an upload the user already has:", member.storagePath, "->", dup);
|
|
@@ -10254,7 +10329,19 @@ var _ChatSession = class _ChatSession {
|
|
|
10254
10329
|
});
|
|
10255
10330
|
}).then(function() {
|
|
10256
10331
|
if (skipped) return;
|
|
10257
|
-
return self.host.getTemporaryUrl(duplicateOf || member.storagePath)
|
|
10332
|
+
return Promise.resolve(self.host.getTemporaryUrl(duplicateOf || member.storagePath)).catch(function(err) {
|
|
10333
|
+
var ecode = err && (err.code || err.body && err.body.code);
|
|
10334
|
+
var emsg = String(err && (err.message || err.body && err.body.message) || err || "");
|
|
10335
|
+
var refused = /no access to this file/i.test(emsg) || ecode === "INVALID_REQUEST" && /access/i.test(emsg);
|
|
10336
|
+
if (duplicateOf || !refused || typeof self.host.ensureFileIndexRecord !== "function") throw err;
|
|
10337
|
+
return Promise.resolve(self.host.ensureFileIndexRecord(member.storagePath, {
|
|
10338
|
+
name: member.file.name,
|
|
10339
|
+
mime: member.file.type || self.host.getMimeType(member.file.name),
|
|
10340
|
+
size: member.file.size
|
|
10341
|
+
})).then(function() {
|
|
10342
|
+
return self.host.getTemporaryUrl(member.storagePath);
|
|
10343
|
+
});
|
|
10344
|
+
});
|
|
10258
10345
|
}).then(function(url) {
|
|
10259
10346
|
if (skipped) return;
|
|
10260
10347
|
if (duplicateOf) {
|
|
@@ -10424,7 +10511,7 @@ var _ChatSession = class _ChatSession {
|
|
|
10424
10511
|
if (!self.state.attachments.some(function(a) {
|
|
10425
10512
|
return a.id === att.id;
|
|
10426
10513
|
})) return;
|
|
10427
|
-
if (att.status === "done"
|
|
10514
|
+
if (att.status === "done") {
|
|
10428
10515
|
if (att.kind === "folder" && att.uploadedUrls) {
|
|
10429
10516
|
att.uploadedUrls.forEach(function(u) {
|
|
10430
10517
|
collected.push({ name: u.path, url: u.url, storagePath: u.storagePath });
|