shadok-ai 0.19.43 → 0.19.45
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 +1 -1
- package/public/index.html +98 -11
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -4760,6 +4760,91 @@
|
|
|
4760
4760
|
}
|
|
4761
4761
|
});
|
|
4762
4762
|
}
|
|
4763
|
+
// ── Poll guard (invariant 69) ─────────────────────────────────
|
|
4764
|
+
// A periodic poll must be UNABLE to accumulate. A bare `fetch` in a timer has
|
|
4765
|
+
// no deadline and no memory of the previous tick. Against an endpoint that
|
|
4766
|
+
// accepts a request and never answers, that fails in one of two ways. A fixed
|
|
4767
|
+
// interval (the usage poll) adds a request that never settles on every tick —
|
|
4768
|
+
// each one holding one of the half-dozen connections a browser opens to a
|
|
4769
|
+
// host, so a handful is enough to freeze the page's other requests to it. A
|
|
4770
|
+
// self-rescheduling loop (the channel reconciliation) awaits for ever and
|
|
4771
|
+
// simply STOPS: the agent list quietly ceases to update, with nothing on
|
|
4772
|
+
// screen to say so.
|
|
4773
|
+
//
|
|
4774
|
+
// Two halves, and each is needed. The deadline frees the socket; without the
|
|
4775
|
+
// in-flight guard there is still one stuck request per tick until it fires.
|
|
4776
|
+
// The guard alone would hold one socket for ever and freeze that poll.
|
|
4777
|
+
//
|
|
4778
|
+
// A tick that finds its endpoint in flight sends NOTHING and joins the pending
|
|
4779
|
+
// answer, which is why the result is a snapshot ({ok, status, json()}) and not
|
|
4780
|
+
// the Response: a body can be read once, a snapshot by every caller. The body
|
|
4781
|
+
// is read INSIDE the deadline — headers that arrive and a body that stalls is
|
|
4782
|
+
// the same hang one step later.
|
|
4783
|
+
//
|
|
4784
|
+
// GET only, by signature: there is no `init`. Coalescing a write would drop
|
|
4785
|
+
// one, and a deliberate, legitimately long request (an upload, a paste, a
|
|
4786
|
+
// transcription, a sign-in step) must never inherit a polling deadline — those
|
|
4787
|
+
// keep calling `fetch` directly.
|
|
4788
|
+
//
|
|
4789
|
+
// Kept inline rather than in an ESM module: a module reaches this script
|
|
4790
|
+
// through the deferred bridge (invariant 10), and the stub covering the gap
|
|
4791
|
+
// would have to be either a bare fetch — the bug, back exactly when the page
|
|
4792
|
+
// is already degraded — or a copy of this logic. The factory takes its
|
|
4793
|
+
// environment as an argument so test/poll-guard.test.ts can lift the text
|
|
4794
|
+
// between the two markers out of this file and run THIS code on fake timers.
|
|
4795
|
+
// poll-guard:start
|
|
4796
|
+
const POLL_TIMEOUT_MS = 15000;
|
|
4797
|
+
function makePollFetch(env) {
|
|
4798
|
+
const inFlight = new Map();
|
|
4799
|
+
return function pollFetch(url, opts) {
|
|
4800
|
+
const key = (opts && opts.key) || url;
|
|
4801
|
+
const pending = inFlight.get(key);
|
|
4802
|
+
if (pending) return pending;
|
|
4803
|
+
const timeoutMs = (opts && opts.timeoutMs) || env.timeoutMs;
|
|
4804
|
+
const ctl = new env.AbortController();
|
|
4805
|
+
let timer;
|
|
4806
|
+
// Raced as well as aborted: the slot must come back at the deadline even
|
|
4807
|
+
// if something underneath ignores the signal.
|
|
4808
|
+
const deadline = new Promise((_, reject) => {
|
|
4809
|
+
timer = env.setTimeout(() => {
|
|
4810
|
+
const err = new Error("poll timed out after " + timeoutMs + "ms: " + url);
|
|
4811
|
+
err.name = "TimeoutError";
|
|
4812
|
+
reject(err);
|
|
4813
|
+
ctl.abort();
|
|
4814
|
+
}, timeoutMs);
|
|
4815
|
+
});
|
|
4816
|
+
// Started one microtask late so the slot is registered BEFORE anything can
|
|
4817
|
+
// settle: a fetch that throws synchronously would otherwise run `finally`
|
|
4818
|
+
// first and leave a dead promise in the map — that endpoint silenced for
|
|
4819
|
+
// the life of the page.
|
|
4820
|
+
const run = Promise.resolve()
|
|
4821
|
+
.then(() => Promise.race([
|
|
4822
|
+
(async () => {
|
|
4823
|
+
const res = await env.fetch(url, { signal: ctl.signal });
|
|
4824
|
+
const text = await res.text();
|
|
4825
|
+
return { ok: res.ok, status: res.status, json: async () => JSON.parse(text) };
|
|
4826
|
+
})(),
|
|
4827
|
+
deadline,
|
|
4828
|
+
]))
|
|
4829
|
+
.finally(() => {
|
|
4830
|
+
env.clearTimeout(timer);
|
|
4831
|
+
if (inFlight.get(key) === run) inFlight.delete(key);
|
|
4832
|
+
});
|
|
4833
|
+
inFlight.set(key, run);
|
|
4834
|
+
return run;
|
|
4835
|
+
};
|
|
4836
|
+
}
|
|
4837
|
+
// poll-guard:end
|
|
4838
|
+
// `fetch` is looked up at call time, so the 401 → login wrapper installed in
|
|
4839
|
+
// the first inline script stays on the path.
|
|
4840
|
+
const pollFetch = makePollFetch({
|
|
4841
|
+
fetch: (url, init) => fetch(url, init),
|
|
4842
|
+
AbortController,
|
|
4843
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
|
4844
|
+
clearTimeout: (id) => clearTimeout(id),
|
|
4845
|
+
timeoutMs: POLL_TIMEOUT_MS,
|
|
4846
|
+
});
|
|
4847
|
+
|
|
4763
4848
|
// ── Bouchons du pont ESM (invariant 10) ─────────────────────────────────
|
|
4764
4849
|
// Le bloc module ci-dessus est DIFFÉRÉ : il s'exécute après le parsing,
|
|
4765
4850
|
// alors que ce script-ci tourne PENDANT et câble déjà les boutons.
|
|
@@ -7490,9 +7575,9 @@
|
|
|
7490
7575
|
let chans, srvGroups, srvFolders;
|
|
7491
7576
|
try {
|
|
7492
7577
|
[chans, srvGroups, srvFolders] = await Promise.all([
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7578
|
+
pollFetch("/channels").then((r) => r.json()),
|
|
7579
|
+
pollFetch("/groups").then((r) => r.json()).catch(() => null),
|
|
7580
|
+
pollFetch("/agent-folders").then((r) => r.json()).catch(() => null),
|
|
7496
7581
|
]);
|
|
7497
7582
|
} catch { return; }
|
|
7498
7583
|
adoptFolders(srvFolders);
|
|
@@ -7645,7 +7730,7 @@
|
|
|
7645
7730
|
let firstAgentStep = null;
|
|
7646
7731
|
async function syncFirstAgent() {
|
|
7647
7732
|
let st;
|
|
7648
|
-
try { st = await (await
|
|
7733
|
+
try { st = await (await pollFetch("/first-agent")).json(); } catch { return; }
|
|
7649
7734
|
const now = !!(st && st.pending);
|
|
7650
7735
|
// The lead's spawn reports the same real steps as a tab (src/first-agent.ts),
|
|
7651
7736
|
// plus "Saying hello" while its greeting is under way.
|
|
@@ -9880,7 +9965,7 @@
|
|
|
9880
9965
|
const listEl = $("liveList");
|
|
9881
9966
|
let live = [];
|
|
9882
9967
|
try {
|
|
9883
|
-
live = await (await
|
|
9968
|
+
live = await (await pollFetch("/live")).json();
|
|
9884
9969
|
} catch { live = []; }
|
|
9885
9970
|
if (!Array.isArray(live) || live.length === 0) { field.hidden = true; return; }
|
|
9886
9971
|
field.hidden = false;
|
|
@@ -10379,7 +10464,7 @@
|
|
|
10379
10464
|
}
|
|
10380
10465
|
}
|
|
10381
10466
|
async function refreshAuthRows() {
|
|
10382
|
-
try { lastAuth = await (await
|
|
10467
|
+
try { lastAuth = await (await pollFetch("/auth")).json(); }
|
|
10383
10468
|
catch { lastAuth = null; }
|
|
10384
10469
|
if (!verMenu.hidden) renderAuthRows();
|
|
10385
10470
|
updateExpiryBanner(); // the banner must track the clock even menu-closed
|
|
@@ -11542,7 +11627,7 @@
|
|
|
11542
11627
|
if (restoring || swapped) return;
|
|
11543
11628
|
let list;
|
|
11544
11629
|
try {
|
|
11545
|
-
const r = await
|
|
11630
|
+
const r = await pollFetch("/rooms");
|
|
11546
11631
|
if (!r.ok) return;
|
|
11547
11632
|
list = await r.json();
|
|
11548
11633
|
} catch { return; }
|
|
@@ -13281,7 +13366,7 @@
|
|
|
13281
13366
|
}
|
|
13282
13367
|
}
|
|
13283
13368
|
async function refreshAccountBanner() {
|
|
13284
|
-
const r = await
|
|
13369
|
+
const r = await pollFetch("/connected-accounts").catch(() => null);
|
|
13285
13370
|
const j = r && r.ok ? await r.json().catch(() => null) : null;
|
|
13286
13371
|
// A failed fetch keeps what is shown: an unreachable server is not a reconnect.
|
|
13287
13372
|
if (j && Array.isArray(j.accounts)) caBannerAccounts = j.accounts;
|
|
@@ -16015,7 +16100,7 @@
|
|
|
16015
16100
|
|
|
16016
16101
|
// ── Security panel ──────────────────────────────────────
|
|
16017
16102
|
async function securityInbox() {
|
|
16018
|
-
try { const r = await
|
|
16103
|
+
try { const r = await pollFetch("/2fa/inbox"); return r.ok ? await r.json() : null; } catch { return null; }
|
|
16019
16104
|
}
|
|
16020
16105
|
async function refreshSecurityBadge() {
|
|
16021
16106
|
if ($("securityBtn").hidden) return;
|
|
@@ -16125,7 +16210,7 @@
|
|
|
16125
16210
|
|
|
16126
16211
|
// ── Agent reports panel ─────────────────────────────────
|
|
16127
16212
|
async function reportsInbox() {
|
|
16128
|
-
try { const r = await
|
|
16213
|
+
try { const r = await pollFetch("/reports"); return r.ok ? await r.json() : null; } catch { return null; }
|
|
16129
16214
|
}
|
|
16130
16215
|
async function refreshReportsBadge() {
|
|
16131
16216
|
if ($("reportsBtn").hidden) return;
|
|
@@ -17488,12 +17573,14 @@
|
|
|
17488
17573
|
|
|
17489
17574
|
async function refreshUsage() {
|
|
17490
17575
|
try {
|
|
17491
|
-
const u = await (await
|
|
17576
|
+
const u = await (await pollFetch("/usage")).json();
|
|
17492
17577
|
paintGauge($("quota5h"), u.fiveHour);
|
|
17493
17578
|
paintGauge($("quota7d"), u.sevenDay);
|
|
17494
17579
|
paceBlocked = !!u.blocked;
|
|
17495
17580
|
paceReason = u.reason || null;
|
|
17496
17581
|
} catch {
|
|
17582
|
+
// A poll that timed out lands here too (pollFetch rejects on abort) — the
|
|
17583
|
+
// same branch on purpose, never a path around it.
|
|
17497
17584
|
// Leave the gauges on their last values, but not the verdict: a stuck
|
|
17498
17585
|
// `true` would make the client demand confirmation forever where the
|
|
17499
17586
|
// server would let the send through. The server re-checks and is the
|