@slack/radar-mcp 1.11.0 → 1.13.0
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/README.md +12 -2
- package/dist/mcp/api-paths.js +2 -0
- package/dist/mcp/flags-tools.d.ts +71 -0
- package/dist/mcp/flags-tools.js +158 -0
- package/dist/mcp/index.js +103 -5
- package/dist/mcp/prefs-tools.d.ts +15 -0
- package/dist/mcp/prefs-tools.js +204 -0
- package/dist/mcp/session-enable.d.ts +2 -1
- package/dist/mcp/session-enable.js +29 -2
- package/dist/mcp/snapshot.js +6 -1
- package/dist/mcp/sources-gate.d.ts +23 -0
- package/dist/mcp/sources-gate.js +63 -0
- package/dist/mcp/tools.js +102 -2
- package/dist/shared/android.d.ts +33 -1
- package/dist/shared/android.js +203 -6
- package/dist/shared/constants.d.ts +8 -0
- package/dist/shared/constants.js +13 -1
- package/dist/shared/db.d.ts +21 -3
- package/dist/shared/db.js +89 -23
- package/dist/shared/feature-flags.d.ts +6 -0
- package/dist/shared/feature-flags.js +17 -0
- package/dist/shared/prefs.d.ts +78 -0
- package/dist/shared/prefs.js +416 -0
- package/dist/shared/transport.d.ts +68 -0
- package/dist/web/log-session.d.ts +13 -0
- package/dist/web/log-session.js +16 -0
- package/dist/web/public/index.html +129 -3
- package/dist/web/public/next/app.js +82 -4
- package/dist/web/public/next/feed.js +270 -14
- package/dist/web/public/next/filter.js +200 -0
- package/dist/web/public/next/flags.js +179 -0
- package/dist/web/public/next/prefs.js +399 -0
- package/dist/web/public/next/registry.js +16 -6
- package/dist/web/public/next/store.js +250 -11
- package/dist/web/server.js +267 -7
- package/dist/web/spec.d.ts +7 -7
- package/dist/web/spec.js +15 -9
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { STREAM_KINDS, EAGER_CAPTURE_KINDS } from "./registry.js";
|
|
1
|
+
import { STREAM_KINDS, EAGER_CAPTURE_KINDS, isStateSource } from "./registry.js";
|
|
2
2
|
// Logcat-scale retention. At the live firehose (~400+ events/sec on the unified Live tab) a
|
|
3
3
|
// small ring recycles in seconds, so a rare signal (a once-per-5s heartbeat) gets evicted
|
|
4
4
|
// before you can filter for it. Android Studio / Flipper keep the whole session and filter
|
|
@@ -32,7 +32,25 @@ export const MODES = [
|
|
|
32
32
|
{ key: "trace", label: "Traces", spec: { title: "Traces", summary: "Performance trace spans, click to see timing details and tags.", source: "trace", viz: ["rate", "graph", "feed", "inspector"], series: [{ metric: "ratePerSec", label: "spans/s", unit: "/s" }, { metric: "avg", field: "duration_ms", label: "avg ms", unit: "ms" }] } },
|
|
33
33
|
{ key: "log", label: "Logs", spec: { title: "Device Logs", summary: "Live Slack app logcat, color-coded by level. Scroll the full session buffer, select a range, copy raw lines.", source: "log", viz: ["feed", "inspector"], match: { package: "com.Slack.internal.debug" } } },
|
|
34
34
|
{ key: "db", label: "Database", spec: { title: "Device DB", summary: "Browse the on-device SQLite databases (read-only snapshot).", source: "db" } },
|
|
35
|
+
{ key: "prefs", label: "Preferences", spec: { title: "Device Preferences", summary: "Browse the on-device SharedPreferences (including feature-flag overrides), read-only.", source: "prefs" } },
|
|
36
|
+
{ key: "flags", label: "Feature Flags", spec: { title: "Feature Flags", summary: "Every feature flag the Slack app knows about, with its current effective value and whether it is locally overridden. Live-updates as flags change on the device. Filter by name.", source: "flags" } },
|
|
35
37
|
];
|
|
38
|
+
// Dashboard mode key -> the ping `sources` name that must be present for the tab to work. Only
|
|
39
|
+
// sources the device ships as plugins are gateable; the rest (network/rtm/clog/db/prefs/...)
|
|
40
|
+
// always show, and each joins this map when its device-side migration lands. Lives here next to
|
|
41
|
+
// MODES (the thing it keys off) so the two cannot drift apart in separate files.
|
|
42
|
+
export const MODE_SOURCE = {
|
|
43
|
+
trace: "traces",
|
|
44
|
+
flags: "feature_flags",
|
|
45
|
+
};
|
|
46
|
+
// True when the device serves this mode's source. Old builds declare nothing
|
|
47
|
+
// (sources null) and keep every tab.
|
|
48
|
+
export function modeServed(key, sources) {
|
|
49
|
+
if (!sources)
|
|
50
|
+
return true;
|
|
51
|
+
const required = MODE_SOURCE[key];
|
|
52
|
+
return !required || sources.includes(required);
|
|
53
|
+
}
|
|
36
54
|
// A preset is identified by what it DOES, not how it is labelled. canonicalSpecKey reduces a
|
|
37
55
|
// spec to its behavioral identity so a spec that is semantically a preset still matches it
|
|
38
56
|
// despite cosmetic drift:
|
|
@@ -73,7 +91,26 @@ class Store {
|
|
|
73
91
|
spec = { blank: true, viz: [] };
|
|
74
92
|
conn = { state: "waiting", msg: "connecting…" };
|
|
75
93
|
profileLabel = "detecting…";
|
|
94
|
+
serverVersion = "";
|
|
76
95
|
profiles = [];
|
|
96
|
+
// Attached devices + the currently pinned one, for the header device picker. Mirrors how
|
|
97
|
+
// profiles/profileLabel are stored: plain fields the header reads via useStoreValue, refreshed
|
|
98
|
+
// off the same poll loop and emitted on a named event.
|
|
99
|
+
devices = [];
|
|
100
|
+
selectedDevice = null;
|
|
101
|
+
// True when the last /_control/devices poll reported adb_error: `adb devices` itself failed
|
|
102
|
+
// (adb not on PATH, server down), which is distinct from "zero devices attached". The header
|
|
103
|
+
// chip renders this differently so the user knows to check adb, not plug in a phone.
|
|
104
|
+
devicesError = false;
|
|
105
|
+
// Last device-select failure text (an /enable 409 or error), or null when the pick succeeded.
|
|
106
|
+
// Distinct from devicesError (adb itself failed) and from conn: a device-select failure used to
|
|
107
|
+
// ride conn via setConn("waiting", …), but any healthy pollHealth flips conn back to connected
|
|
108
|
+
// within 2s and the message vanished before the user read it. This field is owned by
|
|
109
|
+
// selectDevice, survives the health poll, and clears only on a successful pick.
|
|
110
|
+
deviceError = null;
|
|
111
|
+
// Capture-source names the device declares on ping (seam builds). null = old build with no
|
|
112
|
+
// discovery, in which case every tab shows (today's behavior). Emitted as "sources" on change.
|
|
113
|
+
deviceSources = null;
|
|
77
114
|
cache = [];
|
|
78
115
|
cacheKeys = new Set();
|
|
79
116
|
seen = {};
|
|
@@ -86,6 +123,11 @@ class Store {
|
|
|
86
123
|
liveMatches = 0;
|
|
87
124
|
graph = null;
|
|
88
125
|
feedVersion = 0;
|
|
126
|
+
// Bumped on every observed serial change (first pin included), emitted as "db-resync". The DB
|
|
127
|
+
// tab keys its remount off this so it drops stale picked-db/table/results and re-fetches /dbs
|
|
128
|
+
// when the bound device changes — including the null->serial FIRST pin, where the tab loaded
|
|
129
|
+
// unpinned and its /dbs failed with an ambiguous run-as before any device was pinned.
|
|
130
|
+
dbSerialVersion = 0;
|
|
89
131
|
customActive = false;
|
|
90
132
|
lastCustomSpec = null;
|
|
91
133
|
detailCache = new Map();
|
|
@@ -107,6 +149,11 @@ class Store {
|
|
|
107
149
|
// connected but the dead EventSource is never re-opened and the device ring is never pulled,
|
|
108
150
|
// so the tab shows nothing until a manual refresh.
|
|
109
151
|
_dropped = false;
|
|
152
|
+
// The device_serial last seen from /health. Lets pollHealth detect a device SWITCH under a
|
|
153
|
+
// live dashboard (a re-enable that repinned ANDROID_SERIAL to different hardware) so it can
|
|
154
|
+
// drop the old device's cached feed once, on the switch edge. null = not yet observed; the
|
|
155
|
+
// first non-null serial just records it and does NOT clear (nothing stale to drop yet).
|
|
156
|
+
_lastSerial = null;
|
|
110
157
|
_rafPending = false;
|
|
111
158
|
_intervals = [];
|
|
112
159
|
// ---- shared detail cache (bounded FIFO) ----
|
|
@@ -188,7 +235,13 @@ class Store {
|
|
|
188
235
|
this.spec = { blank: true, viz: [] };
|
|
189
236
|
this.conn = { state: "waiting", msg: "connecting…" };
|
|
190
237
|
this.profileLabel = "detecting…";
|
|
238
|
+
this.serverVersion = "";
|
|
191
239
|
this.profiles = [];
|
|
240
|
+
this.devices = [];
|
|
241
|
+
this.selectedDevice = null;
|
|
242
|
+
this.devicesError = false;
|
|
243
|
+
this.deviceError = null;
|
|
244
|
+
this.deviceSources = null;
|
|
192
245
|
this.cache = [];
|
|
193
246
|
this.cacheKeys = new Set();
|
|
194
247
|
this.seen = {};
|
|
@@ -199,6 +252,7 @@ class Store {
|
|
|
199
252
|
this.liveMatches = 0;
|
|
200
253
|
this.graph = null;
|
|
201
254
|
this.feedVersion = 0;
|
|
255
|
+
this.dbSerialVersion = 0;
|
|
202
256
|
this.customActive = false;
|
|
203
257
|
this.lastCustomSpec = null;
|
|
204
258
|
this.detailCache = new Map();
|
|
@@ -212,8 +266,43 @@ class Store {
|
|
|
212
266
|
this._lastBoundLabel = null;
|
|
213
267
|
this._backfillToken = 0;
|
|
214
268
|
this._dropped = false;
|
|
269
|
+
this._lastSerial = null;
|
|
215
270
|
this._rafPending = false;
|
|
216
271
|
}
|
|
272
|
+
// Build the graph aggregate structure for the current spec: one zero-filled series per
|
|
273
|
+
// spec.series entry, or null when the spec has no graph. Shared by applySpec (fresh spec) and
|
|
274
|
+
// clearDeviceCaches (device switch) so the two paths cannot drift.
|
|
275
|
+
buildGraph() {
|
|
276
|
+
if (this.spec.blank || isStateSource(this.spec.source) || !Array.isArray(this.spec.viz) || !this.spec.viz.includes("graph") || !Array.isArray(this.spec.series)) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
return { N: GRAPH_N, series: this.spec.series.map((s) => ({ def: s, buckets: new Array(GRAPH_N).fill(0), counts: new Array(GRAPH_N).fill(0) })) };
|
|
280
|
+
}
|
|
281
|
+
// Drop every device-scoped cache when the dashboard switches to different hardware. The old
|
|
282
|
+
// device's records, dedup keys, learned field values, and detail bodies belong to the wrong
|
|
283
|
+
// phone. The live aggregates (counter, rate, graph) reset too: backfill re-ACCUMULATES into
|
|
284
|
+
// them rather than rebuilding them, so leaving them would layer the new device's counts on
|
|
285
|
+
// top of the old device's totals. The graph is REBUILT zero-filled (not nulled): nothing else
|
|
286
|
+
// reconstructs it after a switch, so nulling it would blank the Network/Trace charts until the
|
|
287
|
+
// next tab change. Timers and spec are left running.
|
|
288
|
+
clearDeviceCaches() {
|
|
289
|
+
this.cache = [];
|
|
290
|
+
this.cacheKeys = new Set();
|
|
291
|
+
this.seen = {};
|
|
292
|
+
this.detailCache = new Map();
|
|
293
|
+
this._capSeen = new Set();
|
|
294
|
+
this._capQueue = [];
|
|
295
|
+
this.total = 0;
|
|
296
|
+
this.liveMatches = 0;
|
|
297
|
+
this.times = [];
|
|
298
|
+
this.perSec = new Array(PERSEC_N).fill(0);
|
|
299
|
+
this.graph = this.buildGraph();
|
|
300
|
+
// The old device's declared sources do not describe the new one; null until its next poll.
|
|
301
|
+
this.updateSources(null);
|
|
302
|
+
// Best-effort latency win: age the fresh-frame stamp so the next pollHealth really fetches.
|
|
303
|
+
// Backfill frames can re-freshen it within ms; pollProfile's 5s read is the backstop.
|
|
304
|
+
this._lastEventTs = 0;
|
|
305
|
+
}
|
|
217
306
|
// ---- start everything ----
|
|
218
307
|
start() {
|
|
219
308
|
this.bootDefault();
|
|
@@ -237,6 +326,14 @@ class Store {
|
|
|
237
326
|
this.closeStream();
|
|
238
327
|
}
|
|
239
328
|
setConn(state, msg) {
|
|
329
|
+
// Unpinned multi-device is never "connected": frames can ride a stale forward from a prior
|
|
330
|
+
// pin and flip the dot green while the per-device surfaces (DB run-as) are broken by the
|
|
331
|
+
// ambiguity. Override any connected claim to a waiting "pick one" until a device is pinned.
|
|
332
|
+
// Centralized here so every caller (pollHealth, onFrame) is covered by the one derived getter.
|
|
333
|
+
if (state === "connected" && this.needsDevicePick) {
|
|
334
|
+
state = "waiting";
|
|
335
|
+
msg = "multiple devices attached, pick one";
|
|
336
|
+
}
|
|
240
337
|
if (this.conn.state === state && this.conn.msg === (msg || ""))
|
|
241
338
|
return;
|
|
242
339
|
this.conn = { state, msg: msg || "" };
|
|
@@ -244,7 +341,17 @@ class Store {
|
|
|
244
341
|
}
|
|
245
342
|
async pollSpec() {
|
|
246
343
|
try {
|
|
247
|
-
const
|
|
344
|
+
const res = await fetch("/spec");
|
|
345
|
+
// The server already stamps its version on /spec (the adopt-path check);
|
|
346
|
+
// reuse it here so the header can show which Radar version is serving.
|
|
347
|
+
// A missing header clears the badge rather than pinning a stale value
|
|
348
|
+
// (an older server rebound to the port would not send it).
|
|
349
|
+
const ver = res.headers.get("X-Radar-Version") ?? "";
|
|
350
|
+
if (ver !== this.serverVersion) {
|
|
351
|
+
this.serverVersion = ver;
|
|
352
|
+
this.emit("version", ver);
|
|
353
|
+
}
|
|
354
|
+
const spec = await res.json();
|
|
248
355
|
const key = JSON.stringify(spec);
|
|
249
356
|
if (key === this._specKey)
|
|
250
357
|
return;
|
|
@@ -298,15 +405,13 @@ class Store {
|
|
|
298
405
|
this.liveMatches = 0;
|
|
299
406
|
this.times = [];
|
|
300
407
|
this.perSec = new Array(PERSEC_N).fill(0);
|
|
301
|
-
this.graph = null;
|
|
302
408
|
this._capQueue.length = 0;
|
|
303
|
-
|
|
304
|
-
this.graph = { N: GRAPH_N, series: this.spec.series.map((s) => ({ def: s, buckets: new Array(GRAPH_N).fill(0), counts: new Array(GRAPH_N).fill(0) })) };
|
|
305
|
-
}
|
|
409
|
+
this.graph = this.buildGraph();
|
|
306
410
|
this.emit("spec", this.spec);
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
|
|
411
|
+
// State browsers (db/prefs/flags) + blank: fully quiet the streaming engine so it does not
|
|
412
|
+
// compete with point-in-time operations (each state tab runs its own fetch/stream). Close the
|
|
413
|
+
// SSE stream AND stop the per-second tick. The 100k cache is left intact.
|
|
414
|
+
if (this.spec.blank || isStateSource(this.spec.source)) {
|
|
310
415
|
this.closeStream();
|
|
311
416
|
if (this._tick) {
|
|
312
417
|
clearInterval(this._tick);
|
|
@@ -584,6 +689,17 @@ class Store {
|
|
|
584
689
|
get matchedRetained() {
|
|
585
690
|
return this.viewFrames().length;
|
|
586
691
|
}
|
|
692
|
+
// 2+ READY devices attached but none pinned yet: a real, renderable state, not "connected".
|
|
693
|
+
// The header shows a "pick a device…" dropdown and the conn dot says so, instead of riding a
|
|
694
|
+
// stale forward and claiming live while the per-device surfaces (DB run-as) are broken by
|
|
695
|
+
// ambiguity. Ready-state only, matching the picker's option list and the server's ambiguity
|
|
696
|
+
// rule: an offline or unauthorized entry cannot be picked, so it must not put the dot in a
|
|
697
|
+
// pick-one state the dropdown cannot resolve. A pinned session (selectedDevice set) is never
|
|
698
|
+
// in this state, even with 2 devices attached.
|
|
699
|
+
get needsDevicePick() {
|
|
700
|
+
return (this.devices.filter((d) => d.state === "device").length >= 2 &&
|
|
701
|
+
this.selectedDevice === null);
|
|
702
|
+
}
|
|
587
703
|
matches(ev) {
|
|
588
704
|
const m = this.spec.match;
|
|
589
705
|
if (!m)
|
|
@@ -606,7 +722,47 @@ class Store {
|
|
|
606
722
|
const op = h.op || ">";
|
|
607
723
|
return op === ">" ? v > h.value : op === ">=" ? v >= h.value : op === "<" ? v < h.value : op === "<=" ? v <= h.value : v === h.value;
|
|
608
724
|
}
|
|
725
|
+
// Device-SWITCH edge detection, shared by pollHealth (quiet case) and fetchDevices (busy
|
|
726
|
+
// observer case). A changed non-null serial means a re-enable repinned to different hardware:
|
|
727
|
+
// drop the old device's cached feed + resync the stream ONCE. Skip the first observation
|
|
728
|
+
// (_lastSerial null): there is nothing stale to clear yet, just record the baseline. A null
|
|
729
|
+
// serial (not reported this poll) is ignored, never resets the baseline.
|
|
730
|
+
checkSerialEdge(serial) {
|
|
731
|
+
if (serial == null || serial === this._lastSerial)
|
|
732
|
+
return;
|
|
733
|
+
// Feed clear + stream resync only on a REAL switch (serial -> other serial): a null->serial
|
|
734
|
+
// FIRST pin has no stale feed to drop, it just records the baseline.
|
|
735
|
+
if (this._lastSerial !== null) {
|
|
736
|
+
this.clearDeviceCaches();
|
|
737
|
+
this.resyncStream();
|
|
738
|
+
}
|
|
739
|
+
this._lastSerial = serial;
|
|
740
|
+
// The DB tab, unlike the feed, DOES carry stale state across a first pin: it loaded unpinned
|
|
741
|
+
// and its /dbs failed with an ambiguous run-as. So the db-resync fires on ANY serial change,
|
|
742
|
+
// including null->serial, so the tab drops that failed state and re-fetches once pinned.
|
|
743
|
+
this.bumpDbSerial();
|
|
744
|
+
}
|
|
745
|
+
// Signal the DB tab to drop its picked-db/table/results and reload /dbs. The DB module cannot
|
|
746
|
+
// import the store (it is a point-in-time view with no SSE engine), so app.ts subscribes and
|
|
747
|
+
// remounts DbBrowser off this counter. Fires on every bound-device change, first pin included.
|
|
748
|
+
bumpDbSerial() {
|
|
749
|
+
this.dbSerialVersion++;
|
|
750
|
+
this.emit("db-resync", this.dbSerialVersion);
|
|
751
|
+
}
|
|
609
752
|
// ---- health + profile ----
|
|
753
|
+
// Track the device's declared capture sources (seam builds). Emits "sources" only on a real
|
|
754
|
+
// change so the modebar does not re-render every 2s poll.
|
|
755
|
+
updateSources(raw) {
|
|
756
|
+
const names = raw
|
|
757
|
+
? raw.map((s) => (typeof s?.name === "string" ? s.name : "")).filter(Boolean)
|
|
758
|
+
: null;
|
|
759
|
+
const key = names ? names.slice().sort().join(",") : null;
|
|
760
|
+
const prev = this.deviceSources ? this.deviceSources.slice().sort().join(",") : null;
|
|
761
|
+
if (key === prev)
|
|
762
|
+
return;
|
|
763
|
+
this.deviceSources = names;
|
|
764
|
+
this.emit("sources", names);
|
|
765
|
+
}
|
|
610
766
|
async pollHealth() {
|
|
611
767
|
if (Date.now() - this._lastEventTs < 6000) {
|
|
612
768
|
this._healthMisses = 0;
|
|
@@ -616,7 +772,16 @@ class Store {
|
|
|
616
772
|
}
|
|
617
773
|
try {
|
|
618
774
|
const h = await (await fetch("/health")).json();
|
|
775
|
+
// Detect a device SWITCH under the live dashboard off /health's pinned serial. This edge
|
|
776
|
+
// only covers the QUIET case: the fresh-frame early return above skips this fetch while the
|
|
777
|
+
// stream is busy, so a switch made from another tab (whose stream stays busy here) is caught
|
|
778
|
+
// instead by fetchDevices, which polls /_control/devices every 5s regardless of stream
|
|
779
|
+
// activity. Between the two, both busy and quiet observer tabs converge within 5s.
|
|
780
|
+
this.checkSerialEdge(h.device_serial ?? null);
|
|
619
781
|
if (h.device) {
|
|
782
|
+
// Only a healthy reply updates the source list: a device:false blip must not flip
|
|
783
|
+
// tabs off and back on recovery. The last list stands until the serial edge clears it.
|
|
784
|
+
this.updateSources(Array.isArray(h.sources) ? h.sources : null);
|
|
620
785
|
this._healthMisses = 0;
|
|
621
786
|
this.recovered();
|
|
622
787
|
this.setConn("connected", "");
|
|
@@ -644,12 +809,18 @@ class Store {
|
|
|
644
809
|
this.resyncStream();
|
|
645
810
|
}
|
|
646
811
|
async pollProfile() {
|
|
812
|
+
this.fetchDevices();
|
|
647
813
|
try {
|
|
648
814
|
const [profilesR, healthR] = await Promise.all([
|
|
649
815
|
fetch("/_control/profiles").then((r) => r.json()).catch(() => null),
|
|
650
816
|
fetch("/health").then((r) => r.json()).catch(() => null),
|
|
651
817
|
]);
|
|
652
818
|
const uid = healthR && healthR.boundUserId;
|
|
819
|
+
// pollHealth's fresh-frame fast path can skip its /health fetch indefinitely on a chatty
|
|
820
|
+
// stream; this 5s poll already fetched /health, so read the sources off it too.
|
|
821
|
+
if (healthR && healthR.device) {
|
|
822
|
+
this.updateSources(Array.isArray(healthR.sources) ? healthR.sources : null);
|
|
823
|
+
}
|
|
653
824
|
this.profiles = (profilesR && profilesR.profiles) || [];
|
|
654
825
|
if (uid == null) {
|
|
655
826
|
this.profileLabel = this._lastBoundLabel ? "last seen " + this._lastBoundLabel + " — reconnecting…" : "waiting for device…";
|
|
@@ -667,6 +838,66 @@ class Store {
|
|
|
667
838
|
/* leave the last label */
|
|
668
839
|
}
|
|
669
840
|
}
|
|
841
|
+
// Pull the attached-device list + the pinned device for the header picker. Fired off the
|
|
842
|
+
// profile poll loop (same cadence as profiles) and again whenever an /enable 409 lands, so the
|
|
843
|
+
// dropdown reflects what is actually attached when the user is asked to disambiguate.
|
|
844
|
+
async fetchDevices() {
|
|
845
|
+
try {
|
|
846
|
+
const r = await (await fetch("/_control/devices")).json();
|
|
847
|
+
this.devices = r?.devices || [];
|
|
848
|
+
this.selectedDevice = r?.selected || null;
|
|
849
|
+
this.devicesError = !!r?.adb_error;
|
|
850
|
+
// Observer-tab switch coverage: a busy stream keeps pollHealth on its fresh-frame fast path,
|
|
851
|
+
// so its serial edge never fires. This poll gets the pinned serial regardless of stream
|
|
852
|
+
// activity, so drive the same switch detection off it (no extra request).
|
|
853
|
+
this.checkSerialEdge(this.selectedDevice?.serial ?? null);
|
|
854
|
+
this.emit("devices", this.devices);
|
|
855
|
+
}
|
|
856
|
+
catch {
|
|
857
|
+
/* transient; next poll retries */
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
// Pin a specific device for the session. POSTs the same /enable the reconnect button uses,
|
|
861
|
+
// with the chosen serial; on success it runs the same post-enable refresh as reconnect() so
|
|
862
|
+
// the UI does not wait for the next poll. On a REAL switch (target serial differs from the one
|
|
863
|
+
// last seen) it clears the old device's caches and resyncs HERE, deterministically, rather than
|
|
864
|
+
// leaning on pollHealth's serial edge: that edge is starved by the <6s fresh-frame fast path
|
|
865
|
+
// while the new stream is already delivering frames, so it may never fire. Same-serial reselect
|
|
866
|
+
// skips the clear (nothing stale). A 409/error is surfaced on deviceError (the device chip shows
|
|
867
|
+
// it) rather than via conn, which a healthy health poll would overwrite within 2s; the device
|
|
868
|
+
// list is refreshed so the dropdown is current and the user can pick a valid device.
|
|
869
|
+
async selectDevice(serial) {
|
|
870
|
+
try {
|
|
871
|
+
const r = await fetch("/enable?device_serial=" + encodeURIComponent(serial), { method: "POST" });
|
|
872
|
+
if (!r.ok && r.status === 409) {
|
|
873
|
+
const body = await r.json().catch(() => null);
|
|
874
|
+
// Surface the failure on the device chip itself, not via conn: a healthy pollHealth flips
|
|
875
|
+
// conn back to connected within 2s and would erase a setConn("waiting", …) message before
|
|
876
|
+
// the user reads it. deviceError is owned here and survives the health poll.
|
|
877
|
+
this.deviceError = (body && body.error) ? String(body.error) : "device select failed";
|
|
878
|
+
this.emit("devices", this.devices);
|
|
879
|
+
this.fetchDevices();
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
// A successful pick clears any prior select failure.
|
|
883
|
+
this.deviceError = null;
|
|
884
|
+
this.emit("devices", this.devices);
|
|
885
|
+
if (serial !== this._lastSerial) {
|
|
886
|
+
this.clearDeviceCaches();
|
|
887
|
+
this._lastSerial = serial;
|
|
888
|
+
// Resync the DB tab too: a first pick (null->serial) leaves it holding the failed
|
|
889
|
+
// ambiguous /dbs; a real switch leaves it on the old device's databases.
|
|
890
|
+
this.bumpDbSerial();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
catch {
|
|
894
|
+
/* ignore; the refresh below re-syncs state */
|
|
895
|
+
}
|
|
896
|
+
this.pollHealth();
|
|
897
|
+
this.pollProfile();
|
|
898
|
+
this.pollSpec();
|
|
899
|
+
this.resyncStream();
|
|
900
|
+
}
|
|
670
901
|
// Re-open the SSE stream and backfill the device ring for the ACTIVE streaming source, so the
|
|
671
902
|
// current tab repopulates from what the device already holds (not just new live events).
|
|
672
903
|
// Needed because the EventSource does not survive a device drop and pollSpec only re-applies
|
|
@@ -682,14 +913,22 @@ class Store {
|
|
|
682
913
|
resyncStream() {
|
|
683
914
|
this._dropped = false;
|
|
684
915
|
const src = this.spec.source;
|
|
685
|
-
if (this.spec.blank || !src || src
|
|
916
|
+
if (this.spec.blank || !src || isStateSource(src))
|
|
686
917
|
return;
|
|
687
918
|
this.openStream();
|
|
688
919
|
this.backfill();
|
|
689
920
|
}
|
|
690
921
|
async reconnect() {
|
|
691
922
|
try {
|
|
692
|
-
await fetch("/enable", { method: "POST" });
|
|
923
|
+
const r = await fetch("/enable", { method: "POST" });
|
|
924
|
+
// 409 = ambiguous device (multiple attached, none picked). Surface the server's
|
|
925
|
+
// reason through the existing connection-status line so the user sees why enable
|
|
926
|
+
// did not connect, instead of a silent stall on "reconnecting…".
|
|
927
|
+
if (!r.ok && r.status === 409) {
|
|
928
|
+
const body = await r.json().catch(() => null);
|
|
929
|
+
if (body && body.error)
|
|
930
|
+
this.setConn("waiting", String(body.error));
|
|
931
|
+
}
|
|
693
932
|
}
|
|
694
933
|
catch {
|
|
695
934
|
/* ignore */
|