Add L0 index and anchor UI updates

This commit is contained in:
2026-02-06 11:22:02 +08:00
parent c36efe6805
commit 44ca06f9b9
23 changed files with 1749 additions and 3898 deletions

View File

@@ -32,6 +32,7 @@ class StreamingGeneration {
this.activeCount = 0;
this._toggleBusy = false;
this._toggleQueue = Promise.resolve();
this.MAX_SESSIONS = 100;
}
init() {
@@ -44,16 +45,22 @@ class StreamingGeneration {
_getSlotId(id) {
if (!id) return 1;
const m = String(id).match(/^xb(\d+)$/i);
if (m && +m[1] >= 1 && +m[1] <= 10) return `xb${m[1]}`;
const n = parseInt(id, 10);
return (!isNaN(n) && n >= 1 && n <= 10) ? n : 1;
const s = String(id).trim();
const m = s.match(/^xb(\d+)$/i);
if (m) {
const n = +m[1];
if (n >= 1 && n <= 100) return `xb${n}`;
}
const n = parseInt(s, 10);
if (!isNaN(n) && n >= 1 && n <= 100) return n;
if (s.length > 0 && s.length <= 50) return s;
return 1;
}
_ensureSession(id, prompt) {
const slotId = this._getSlotId(id);
if (!this.sessions.has(slotId)) {
if (this.sessions.size >= 10) this._cleanupOldestSessions();
if (this.sessions.size >= this.MAX_SESSIONS) this._cleanupOldestSessions();
this.sessions.set(slotId, {
id: slotId, text: '', isStreaming: false, prompt: prompt || '',
updatedAt: Date.now(), abortController: null
@@ -64,8 +71,9 @@ class StreamingGeneration {
}
_cleanupOldestSessions() {
const keepCount = Math.max(10, this.MAX_SESSIONS - 10);
const sorted = [...this.sessions.entries()].sort((a, b) => a[1].updatedAt - b[1].updatedAt);
sorted.slice(0, Math.max(0, sorted.length - 9)).forEach(([sid, s]) => {
sorted.slice(0, Math.max(0, sorted.length - keepCount)).forEach(([sid, s]) => {
try { s.abortController?.abort(); } catch {}
this.sessions.delete(sid);
});