@slack/radar-mcp 1.24.0 → 1.26.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.
Files changed (51) hide show
  1. package/README.md +41 -4
  2. package/dist/mcp/dispatch.d.ts +1 -0
  3. package/dist/mcp/dispatch.js +4 -2
  4. package/dist/mcp/flags-tools.d.ts +1 -0
  5. package/dist/mcp/flags-tools.js +3 -9
  6. package/dist/mcp/index.js +16 -40
  7. package/dist/mcp/json-rows.d.ts +6 -0
  8. package/dist/mcp/json-rows.js +10 -0
  9. package/dist/mcp/radar-response.d.ts +2 -2
  10. package/dist/mcp/radar-response.js +2 -2
  11. package/dist/mcp/redact.d.ts +14 -0
  12. package/dist/mcp/redact.js +71 -0
  13. package/dist/mcp/session-enable.d.ts +1 -0
  14. package/dist/mcp/session-enable.js +8 -6
  15. package/dist/mcp/snapshot-cli.d.ts +52 -0
  16. package/dist/mcp/snapshot-cli.js +316 -0
  17. package/dist/mcp/snapshot-summary.d.ts +1 -0
  18. package/dist/mcp/snapshot-summary.js +254 -0
  19. package/dist/mcp/snapshot.d.ts +32 -3
  20. package/dist/mcp/snapshot.js +347 -102
  21. package/dist/mcp/tools.js +11 -7
  22. package/dist/shared/android.d.ts +25 -0
  23. package/dist/shared/android.js +97 -0
  24. package/dist/shared/feature-flags.d.ts +20 -0
  25. package/dist/shared/feature-flags.js +35 -4
  26. package/dist/shared/radar-token.d.ts +5 -5
  27. package/dist/shared/radar-token.js +24 -10
  28. package/dist/shared/switchboard-note.d.ts +19 -0
  29. package/dist/shared/switchboard-note.js +76 -0
  30. package/dist/shared/switchboard-report.js +43 -4
  31. package/dist/shared/switchboard.d.ts +1 -1
  32. package/dist/shared/switchboard.js +14 -2
  33. package/dist/shared/transport.d.ts +18 -0
  34. package/dist/shared/wire.d.ts +2 -0
  35. package/dist/web/install-app-cli.d.ts +2 -0
  36. package/dist/web/install-app-cli.js +60 -0
  37. package/dist/web/install-app.d.ts +16 -7
  38. package/dist/web/install-app.js +92 -39
  39. package/dist/web/macapp/RadarApp.swift +12 -11
  40. package/dist/web/public/index.html +5 -2
  41. package/dist/web/public/next/feature-flags.js +50 -0
  42. package/dist/web/public/next/feed.js +15 -4
  43. package/dist/web/public/next/flags.js +17 -3
  44. package/dist/web/public/next/registry.js +4 -4
  45. package/dist/web/public/next/store.js +90 -4
  46. package/dist/web/public/next/switchboard-note.js +76 -0
  47. package/dist/web/public/next/voice-model.js +209 -15
  48. package/dist/web/public/next/voice.js +73 -10
  49. package/dist/web/spec.d.ts +1 -1
  50. package/dist/web/spec.js +1 -1
  51. package/package.json +1 -1
@@ -0,0 +1,50 @@
1
+ // GENERATED by scripts/mirror-shared.mjs from src/shared/feature-flags.ts. Do not edit; edit the source.
2
+ // Shared feature-flag response handling for the callers that read the device's
3
+ // /api/feature_flags route: the MCP tools (flags-tools.ts), the web server (web/server.ts) and the
4
+ // dashboard's Flags tab, which gets a mirrored copy of this file (scripts/mirror-shared.mjs). So it
5
+ // must stay import-free. The "Not Found" rewrite and the restart sentence live here once instead
6
+ // of drifting between copies.
7
+ /**
8
+ * Rewrite the device's raw "Not Found" into an actionable message. The route 404s as valid
9
+ * JSON ({"error":"Not Found"}) on builds that predate the feature-flag Radar plugin, which is
10
+ * correct but useless to a caller with no way to know this route is plugin-gated.
11
+ * A 401 is not read here; both callers decide it from the HTTP status before this runs.
12
+ */
13
+ export function friendlyFeatureFlagError(error) {
14
+ if (typeof error !== "string")
15
+ return "Unknown device error.";
16
+ if (error === "Not Found") {
17
+ return "This debug build does not serve feature flags yet (update to a build with the feature-flag Radar plugin).";
18
+ }
19
+ return error;
20
+ }
21
+ /**
22
+ * The sentence (`note`) and the short tab text (`label`) for a flag whose latest value differs from
23
+ * what the app runs. An experiment's label names the group itself, since a group has no ON/OFF to
24
+ * flip. A flag the app read once keeps that value until restart, so the latest value (`enabled` on a toggle,
25
+ * `group_name` on an experiment; fetched or override) can differ from the session value
26
+ * (`session_enabled`, `session_group_name`). Only two real values of
27
+ * the right type that differ earn a note: an absent or mistyped session value is "not known", and
28
+ * saying nothing there is the honest answer. An experiment's "" is a read that found no group, and
29
+ * its note is hedged because read-once code may still use the session group, not that it must.
30
+ */
31
+ export function flagRestartNote(row) {
32
+ const source = row.is_overridden === true ? "override" : "fetched";
33
+ const { group_name: group, session_group_name: sessionGroup } = row;
34
+ if (typeof group === "string" && typeof sessionGroup === "string") {
35
+ if (group === sessionGroup)
36
+ return undefined;
37
+ const used = sessionGroup || "no group";
38
+ return {
39
+ note: `read-once code may still use ${used} until restart, ${source} ${group || "no group"}`,
40
+ label: `read-once may use ${used}`,
41
+ };
42
+ }
43
+ const { enabled, session_enabled: session } = row;
44
+ if (typeof enabled !== "boolean" || typeof session !== "boolean" || enabled === session)
45
+ return undefined;
46
+ return {
47
+ note: `app uses ${session} until restart, ${source} ${enabled}`,
48
+ label: `runs ${session ? "ON" : "OFF"} until restart`,
49
+ };
50
+ }
@@ -10,7 +10,7 @@ import { gappedFieldHint } from "./filters.js";
10
10
  import { STREAM_KINDS, LOG_LEVEL_ORDER, levelRank, EXCLUDE_MAX_TERMS, EXCLUDE_MAX_TERM_LENGTH, SWITCHBOARD_KINDS } from "./registry.js";
11
11
  import { parseFilter, tokenize, isCompleteTerm, isQuote } from "./filter.js";
12
12
  import { inSessionCut, sameSessionCut } from "./voice-model.js";
13
- import { savedTurnLabel, switchboardClockLabel } from "./switchboard-note.js";
13
+ import { cardLabel, connectionEndedNormally, reconnectTryLabel, savedTurnLabel, switchboardClockLabel } from "./switchboard-note.js";
14
14
  const ROW_H = 24;
15
15
  const OVERSCAN = 10;
16
16
  // How long the empty line's counts may stay behind the cache after an eviction before the next
@@ -166,6 +166,9 @@ export function switchboardArrow(direction) {
166
166
  // A state change whose destination reads as a failure. Cosmetic only (the kind badge turns red):
167
167
  // switchboard rows carry no logcat level, so this is where a failed transition stands out.
168
168
  export function switchboardFailed(ev) {
169
+ // A normal server ending is a Failed state too, but not a fault, so it keeps the plain badge.
170
+ if (connectionEndedNormally(ev))
171
+ return false;
169
172
  return ev.kind === "state" && /fail|error/i.test(String(ev.to ?? ""));
170
173
  }
171
174
  // dBFS reads better than a raw 0..1 peak: 0.05 and 0.5 both look "quiet" on a linear scale, but
@@ -187,7 +190,7 @@ export function switchboardSummary(ev) {
187
190
  const num = (v) => (typeof v === "number" ? v : undefined);
188
191
  const text = (v) => (v == null ? "" : String(v));
189
192
  switch (ev.kind) {
190
- case "session": return text(ev.event);
193
+ case "session": return `${text(ev.event)}${ev.mic_encoding ? ` ${text(ev.mic_encoding)}` : ""}`;
191
194
  // The state kind and the transition are set apart so a word both carry ("speaking speaking →
192
195
  // quiet") does not read as a stutter.
193
196
  case "state": return `${text(ev.state_kind)} · ${text(ev.from)} → ${text(ev.to)}${ev.cause ? ` (${text(ev.cause)})` : ""}`.trim();
@@ -202,8 +205,8 @@ export function switchboardSummary(ev) {
202
205
  return `${text(ev.phase)}${d != null ? ` ${fmtNum(d)} ms` : ""}`;
203
206
  }
204
207
  case "player": {
205
- const g = num(ev.gap_ms), q = num(ev.bytes_queued);
206
- return `${text(ev.event)}${g != null ? ` gap ${fmtNum(g)} ms` : ""}${q != null ? ` queued ${fmtNum(q)} B` : ""}`;
208
+ const g = num(ev.gap_ms), q = num(ev.bytes_queued), d = num(ev.dropped_chunks);
209
+ return `${text(ev.event)}${g != null ? ` gap ${fmtNum(g)} ms` : ""}${q != null ? ` queued ${fmtNum(q)} B` : ""}${d != null ? ` dropped ${fmtNum(d)} mic chunk${d === 1 ? "" : "s"}` : ""}`;
207
210
  }
208
211
  // Shows size, reach, and peak loudness, not averaged rms, since averaging would wash out
209
212
  // the one loud spike a debugger is usually looking for.
@@ -239,6 +242,14 @@ export function switchboardSummary(ev) {
239
242
  }
240
243
  // An unknown outcome shows as its device token, quoted unless plain (see savedTurnLabel).
241
244
  case "saved_turn": return savedTurnLabel(ev.outcome, ev.has_thread);
245
+ // Unknown kinds and events show as sent (see cardLabel); the id follows so one card's moves line up.
246
+ case "card": return [cardLabel(ev.card_kind, ev.event, ev.by), typeof ev.card_id === "string" ? ev.card_id : ""].filter(Boolean).join(" ");
247
+ // The export line's words: "drop try 2 ready", "drop gave_up after 2 tries".
248
+ case "reconnect_try": {
249
+ const trigger = typeof ev.trigger === "string" ? ev.trigger : "?";
250
+ const outcome = typeof ev.outcome === "string" ? ev.outcome : "?";
251
+ return reconnectTryLabel(trigger, outcome, num(ev.try));
252
+ }
242
253
  default: return "";
243
254
  }
244
255
  }
@@ -18,8 +18,13 @@
18
18
  // timestamp when the device recorded this row, so one row is distinguishable from an older
19
19
  // one. Named to match every other source's wire shape.
20
20
  // type "toggle" | "experiment"
21
- // enabled toggles only: the EFFECTIVE boolean the app uses right now (override if set,
22
- // else the server value).
21
+ // enabled toggles only: the latest boolean (override if set, else the server value),
22
+ // which the app may not run until restart.
23
+ // session_group_name experiments only: the group the app's first read returned (or a read returns
24
+ // now, if unread); read-once code may still use it until restart; "" is no group. Absent on older builds: not known, nothing shown.
25
+ // session_enabled toggles only: the flag's own value the app runs this session. Absent on older
26
+ // builds and experiments; absent or non-boolean means not known, so nothing is
27
+ // shown.
23
28
  // group_name experiments only: the EFFECTIVE group/variant string (e.g. "treatment_a";
24
29
  // "" / "control" is the baseline arm).
25
30
  // is_overridden true when a local debug override is active
@@ -34,6 +39,7 @@
34
39
  import { html } from "./html.js";
35
40
  import { useState, useEffect, useCallback, useRef } from "preact/hooks";
36
41
  import { normalizeStreamType } from "./registry.js";
42
+ import { flagRestartNote } from "./feature-flags.js";
37
43
  // A row is unique per (scope, org_id, type, key), not by key alone: the device lists each key once
38
44
  // per scope AND once per signed-in org, and a toggle and an experiment could share a name. Leaving
39
45
  // org out collapsed two workspaces onto one row, so whichever wrote last won. `scope` is a
@@ -90,6 +96,14 @@ function flagValue(f) {
90
96
  // what it means here. Says only what dim means: plenty of undimmed values are single-row groups,
91
97
  // so undimmed does not imply a disagreement.
92
98
  const DIM_TITLE = "every row of this flag in this scope shows this same value";
99
+ // Shown next to the pill when the app still runs an older value than the latest one. The visible
100
+ // text says what the app runs; the title is the shared sentence.
101
+ function restartMark(x) {
102
+ const r = flagRestartNote(x);
103
+ if (r === undefined)
104
+ return null;
105
+ return html `<span class="flagrestart" title=${r.note}>${r.label}</span>`;
106
+ }
93
107
  // Render a flag value. Booleans (toggles) show ON/OFF; a variant group-name string shows as a
94
108
  // text pill ("" / "control" read as the off/baseline arm). `dim` mutes a value that every row of
95
109
  // the flag agrees on, so a disagreement is the only full-weight value in a multi-row group.
@@ -430,7 +444,7 @@ function Table({ rows, flashed, dimmed, }) {
430
444
  <td class="scope">${x.scope || "—"}</td>
431
445
  <td class="org" title=${orgTitle(x)}>${x.org_id || "—"}</td>
432
446
  <td class="ftype"><span class=${"ftbadge " + t.cls}>${t.label}</span></td>
433
- <td class="val">${valuePill(flagValue(x), dimmed.has(dimGroup(x)))}</td>
447
+ <td class="val">${valuePill(flagValue(x), dimmed.has(dimGroup(x)))}${restartMark(x)}</td>
434
448
  <td class="origin"><span class=${"orbadge " + o.cls}>${o.label}</span></td>
435
449
  </tr>`;
436
450
  })}
@@ -23,8 +23,8 @@ export const MATCH_FIELDS = {
23
23
  log: ["tag", "message", "pid", "package", "subsystem", "process"],
24
24
  // The voice transport's records: `kind` picks the record shape, the rest are that shape's key
25
25
  // fields (frame: direction/frame_type, state: state_kind, phase: phase, session/player: event,
26
- // turn: clock, saved_turn: outcome).
27
- switchboard: ["kind", "session_id", "direction", "frame_type", "state_kind", "phase", "event", "clock", "outcome"],
26
+ // turn: clock, saved_turn: outcome, reconnect_try: trigger, card: card_kind and card_id).
27
+ switchboard: ["kind", "session_id", "direction", "frame_type", "state_kind", "phase", "event", "clock", "outcome", "trigger", "card_kind", "card_id"],
28
28
  };
29
29
  // `all` = the union of every streaming source's fields (deduped, order-stable). Derived, not
30
30
  // hand-maintained, so adding a source's fields above surfaces them in the unified Live tab too.
@@ -127,7 +127,7 @@ export const SOURCE_ORDER = ["all", "network", "rtm", "clog", "trace", "log", "s
127
127
  // are their own containers, not feed filters). Derived from SOURCES so adding a streaming source
128
128
  // surfaces it in Filters with no edit there. Ordered by SOURCE_ORDER (the modebar order) for a stable, familiar list.
129
129
  export const FILTER_SOURCES = SOURCE_ORDER.filter((s) => SOURCES[s]?.kind === "stream");
130
- // The eight switchboard record kinds, in the order the toolbar's kind chips show them. Each chip
130
+ // The ten switchboard record kinds, in the order the toolbar's kind chips show them. Each chip
131
131
  // writes the exclude term `kind:<name>`; a spec listing that term shows the chip off. These are
132
132
  // the kinds switchboardFields (store.ts) knows fields for; a test holds the two lists together.
133
- export const SWITCHBOARD_KINDS = ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn"];
133
+ export const SWITCHBOARD_KINDS = ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn", "card", "reconnect_try"];
@@ -1,6 +1,6 @@
1
1
  import { STREAM_KINDS, DEVICE_STREAM_KINDS, EAGER_CAPTURE_KINDS, isStateSource, levelRank, FIELD_VALUES, EXCLUDE_MAX_TERMS, EXCLUDE_MAX_TERM_LENGTH, SWITCHBOARD_KINDS, CACHE_TTL_MS, normalizeStreamType } from "./registry.js";
2
2
  import { byRecordTime, cutFromVotes, inSessionCut, outranks, runRows, sameSessionCut, sessionVote } from "./voice-model.js";
3
- import { savedTurnLabel } from "./switchboard-note.js";
3
+ import { SERVER_SESSION_ID_CAP, cardLabel, savedTurnLabel } from "./switchboard-note.js";
4
4
  export const UNAUTHORIZED_HEAD = "device refused this session (HTTP 401)";
5
5
  // Logcat-scale retention. At the live firehose (~400+ events/sec on the unified Live tab) a
6
6
  // small ring recycles in seconds, so a rare signal (a once-per-5s heartbeat) gets evicted
@@ -109,7 +109,7 @@ function writeViewMemory(mem) {
109
109
  const POLL_PROFILE_MS = 5000;
110
110
  const GRAPH_N = 60;
111
111
  const PERSEC_N = 30;
112
- const SUGGEST_FIELDS = ["event_type", "event_name", "tag", "status_code", "channel", "url", "package", "trace_name", "span_name", "kind", "frame_type", "state_kind", "phase", "event", "clock", "outcome"];
112
+ const SUGGEST_FIELDS = ["event_type", "event_name", "tag", "status_code", "channel", "url", "package", "trace_name", "span_name", "kind", "frame_type", "state_kind", "phase", "event", "clock", "outcome", "trigger", "card_kind"];
113
113
  const PACKAGE_CAP = 1000; // package values learned off the stream; bounded (was Infinity in the PoC, B4)
114
114
  // ---- pre-built dashboards: one tab each. Presets carry only generic placeholders; real
115
115
  // endpoints/channels/event-names are learned LIVE from the device stream. The one baked value
@@ -625,6 +625,19 @@ export class Store {
625
625
  // under the id. undefined means not learned yet; null means the summary reported the key but it
626
626
  // was itself null (see voice-model.ts's serverSessionId).
627
627
  _switchboardSummaryServerId = new Map();
628
+ // Every ready id of the call, oldest first, from every path (the refill page, and live and
629
+ // replayed ready records). Absent on an older build.
630
+ _switchboardSummaryServerIds = new Map();
631
+ // The newest mic codec label from every path (live, replayed and the refill page), so the panel
632
+ // keeps it after the config record ages out of the cache. Absent on a build older than wire
633
+ // revision 5 that sent no config record.
634
+ _switchboardSummaryMicEncoding = new Map();
635
+ // The record id that label is good through: the refill's page, or a newer live config record.
636
+ // Kept so an older replayed config or a late refill cannot put back a codec a reconnect replaced.
637
+ _switchboardSummaryMicEncodingThrough = new Map();
638
+ // The highest record id the id list covers: the refill's page, moved forward on each append. A
639
+ // replayed (non-live) ready at or below it is already in the list or aged out of it.
640
+ _switchboardSummaryServerIdsThrough = new Map();
628
641
  // saved_turn_counts per session id, off the same refill envelope and dropped with it on a new run,
629
642
  // with the newest record id that envelope carried: the counts are a snapshot through that id, and
630
643
  // the panel adds the saved_turn rows newer than it. Absent until a refill lands one; an older
@@ -840,6 +853,10 @@ export class Store {
840
853
  this._backfillToken = 0;
841
854
  this._switchboardRuns = new Map();
842
855
  this._switchboardSummaryServerId = new Map();
856
+ this._switchboardSummaryServerIds = new Map();
857
+ this._switchboardSummaryMicEncoding = new Map();
858
+ this._switchboardSummaryMicEncodingThrough = new Map();
859
+ this._switchboardSummaryServerIdsThrough = new Map();
843
860
  this._switchboardSummarySavedTurnCounts = new Map();
844
861
  this._sbBestBegin = null;
845
862
  this._sbBestAny = null;
@@ -926,6 +943,10 @@ export class Store {
926
943
  // claim the new device's sessions of the same id.
927
944
  this._switchboardRuns = new Map();
928
945
  this._switchboardSummaryServerId = new Map();
946
+ this._switchboardSummaryServerIds = new Map();
947
+ this._switchboardSummaryMicEncoding = new Map();
948
+ this._switchboardSummaryMicEncodingThrough = new Map();
949
+ this._switchboardSummaryServerIdsThrough = new Map();
929
950
  this._switchboardSummarySavedTurnCounts = new Map();
930
951
  // The old device's declared sources do not describe the new one; null until its next poll.
931
952
  this.updateSources(null);
@@ -1447,6 +1468,27 @@ export class Store {
1447
1468
  // id's current run counts: one from an older process under the same id names another call.
1448
1469
  if (ev.kind === "session" && ev.event === "ready" && Object.hasOwn(ev, "server_session_id") && inSwitchboardRun(ev, run)) {
1449
1470
  this._switchboardSummaryServerId.set(ev.session_id, ev.server_session_id ?? null);
1471
+ // A reconnect's new id joins the list the refill learned, so a long call keeps the older
1472
+ // ids after their ready rows age out. The device keeps its newest 8, and so does this.
1473
+ const ids = this._switchboardSummaryServerIds.get(ev.session_id);
1474
+ // A replayed ready (refill page, backfill) at or below what the list covers is old news and
1475
+ // would land out of order; a newer one, like a stream-recovery backfill's, still appends.
1476
+ const through = this._switchboardSummaryServerIdsThrough.get(ev.session_id) ?? -Infinity;
1477
+ const replayedOld = !live && typeof ev.id === "number" && ev.id <= through;
1478
+ if (ids && !replayedOld && typeof ev.server_session_id === "string" && !ids.includes(ev.server_session_id)) {
1479
+ this._switchboardSummaryServerIds.set(ev.session_id, [...ids, ev.server_session_id].slice(-SERVER_SESSION_ID_CAP));
1480
+ if (typeof ev.id === "number" && ev.id > through)
1481
+ this._switchboardSummaryServerIdsThrough.set(ev.session_id, ev.id);
1482
+ }
1483
+ }
1484
+ // Same for the mic codec: hold the newest config's label, so the panel keeps it (and a
1485
+ // reconnect's switch) after the config row ages out. An older replayed config never wins.
1486
+ if (ev.kind === "session" && ev.event === "config" && typeof ev.mic_encoding === "string" && typeof ev.id === "number" && inSwitchboardRun(ev, run)) {
1487
+ const through = this._switchboardSummaryMicEncodingThrough.get(ev.session_id) ?? -Infinity;
1488
+ if (ev.id > through) {
1489
+ this._switchboardSummaryMicEncoding.set(ev.session_id, ev.mic_encoding);
1490
+ this._switchboardSummaryMicEncodingThrough.set(ev.session_id, ev.id);
1491
+ }
1450
1492
  }
1451
1493
  if (ev.kind === "saved_turn" && typeof ev.outcome === "string" && typeof ev.id === "number" && inSwitchboardRun(ev, run)) {
1452
1494
  run.savedTurns.set(ev.id, ev.outcome);
@@ -1488,6 +1530,10 @@ export class Store {
1488
1530
  }
1489
1531
  if (reused) {
1490
1532
  this._switchboardSummaryServerId.delete(sid);
1533
+ this._switchboardSummaryServerIds.delete(sid);
1534
+ this._switchboardSummaryMicEncoding.delete(sid);
1535
+ this._switchboardSummaryMicEncodingThrough.delete(sid);
1536
+ this._switchboardSummaryServerIdsThrough.delete(sid);
1491
1537
  this._switchboardSummarySavedTurnCounts.delete(sid);
1492
1538
  }
1493
1539
  if (!run || reused) {
@@ -1703,6 +1749,32 @@ export class Store {
1703
1749
  if (this._switchboardRuns.get(sessionId) === run && Object.hasOwn(detail ?? {}, "server_session_id")) {
1704
1750
  this._switchboardSummaryServerId.set(sessionId, detail.server_session_id ?? null);
1705
1751
  }
1752
+ if (this._switchboardRuns.get(sessionId) === run && Array.isArray(detail?.server_session_ids)) {
1753
+ this._switchboardSummaryServerIds.set(sessionId, detail.server_session_ids.filter((x) => typeof x === "string"));
1754
+ // The device read the list and the page together, so the list covers the page's highest id,
1755
+ // or the highest id held when the fetch went out if that is higher.
1756
+ let idsThrough = heldThroughId;
1757
+ for (const e of detail?.events || []) {
1758
+ const id = e?.id;
1759
+ if (typeof id === "number" && id > idsThrough)
1760
+ idsThrough = id;
1761
+ }
1762
+ this._switchboardSummaryServerIdsThrough.set(sessionId, idsThrough);
1763
+ }
1764
+ if (this._switchboardRuns.get(sessionId) === run && typeof detail?.mic_encoding === "string") {
1765
+ // Good through the page's highest id, like the id list. A live config newer than that,
1766
+ // seen while the fetch was out, keeps its label.
1767
+ let micThrough = heldThroughId;
1768
+ for (const e of detail?.events || []) {
1769
+ const id = e?.id;
1770
+ if (typeof id === "number" && id > micThrough)
1771
+ micThrough = id;
1772
+ }
1773
+ if (micThrough >= (this._switchboardSummaryMicEncodingThrough.get(sessionId) ?? -Infinity)) {
1774
+ this._switchboardSummaryMicEncoding.set(sessionId, detail.mic_encoding);
1775
+ this._switchboardSummaryMicEncodingThrough.set(sessionId, micThrough);
1776
+ }
1777
+ }
1706
1778
  // The device reads the summary and the page together, so the counts stop at the page's
1707
1779
  // highest id, or at the highest id held when the fetch went out if that is higher (an empty
1708
1780
  // page). With neither, every row the stream brings is newer.
@@ -1737,6 +1809,16 @@ export class Store {
1737
1809
  switchboardSummaryServerId(sessionId) {
1738
1810
  return this._switchboardSummaryServerId.get(sessionId);
1739
1811
  }
1812
+ // Every server_session_id the refill reported for sessionId, oldest first; undefined on an older
1813
+ // build or before the refill lands.
1814
+ switchboardSummaryServerIds(sessionId) {
1815
+ return this._switchboardSummaryServerIds.get(sessionId);
1816
+ }
1817
+ // The newest mic codec label held for sessionId, from the live stream, a replay or the refill;
1818
+ // undefined before any of them brings one.
1819
+ switchboardSummaryMicEncoding(sessionId) {
1820
+ return this._switchboardSummaryMicEncoding.get(sessionId);
1821
+ }
1740
1822
  // The saved_turn outcomes seen for sessionId's current run, by record id; undefined before any
1741
1823
  // record of the id.
1742
1824
  switchboardSavedTurnOutcomes(sessionId) {
@@ -2919,11 +3001,11 @@ export function switchboardFields(ev) {
2919
3001
  const num = (v) => (typeof v === "number" ? v : undefined);
2920
3002
  switch (kind) {
2921
3003
  // Searchable here like any other switchboard field, not just shown on the summary pill.
2922
- case "session": return [kind, ev.event, ev.server_session_id];
3004
+ case "session": return [kind, ev.event, ev.server_session_id, typeof ev.mic_encoding === "string" ? ev.mic_encoding : undefined];
2923
3005
  case "state": return [kind, ev.state_kind, ev.from, ev.to, ev.cause];
2924
3006
  case "frame": return [kind, ev.direction, ev.frame_type, num(ev.bytes)];
2925
3007
  case "phase": return [kind, ev.phase, num(ev.duration_ms)];
2926
- case "player": return [kind, ev.event, num(ev.gap_ms), num(ev.bytes_queued)];
3008
+ case "player": return [kind, ev.event, num(ev.gap_ms), num(ev.bytes_queued), num(ev.dropped_chunks)];
2927
3009
  case "levels": return [kind, num(ev.sample_count)];
2928
3010
  // The raw clock token, not the row's words, the same way a frame keeps "unknown".
2929
3011
  case "turn": return [kind, ev.clock, num(ev.response_ms)];
@@ -2934,6 +3016,10 @@ export function switchboardFields(ev) {
2934
3016
  const label = savedTurnLabel(ev.outcome, ev.has_thread);
2935
3017
  return [kind, ev.outcome, label && label !== ev.outcome ? label : undefined];
2936
3018
  }
3019
+ // The ids and labels, so a search for an approval id finds its moves.
3020
+ case "card": return [kind, ev.card_kind, ev.event, ev.by, ev.card_id, cardLabel(ev.card_kind, ev.event, ev.by)];
3021
+ // The labels and the try number, so a search for either label finds the row.
3022
+ case "reconnect_try": return [kind, ev.trigger, ev.outcome, num(ev.try)];
2937
3023
  default: return [kind];
2938
3024
  }
2939
3025
  }
@@ -8,6 +8,16 @@ export function capitalizeSwitchboardNote(note) {
8
8
  // A peak at or above this is clipping. Shared here so the report and the dashboard sparkline use
9
9
  // the same threshold.
10
10
  export const CLIP_PEAK = 0.99;
11
+ // What the mic codec costs on the uplink, for the strip and the report header. The sizes are
12
+ // 24 kHz x 2 bytes x 0.2 s for pcm16, and the provider's own note for adts. An unknown label is
13
+ // the device's to add, so it has no note and prints as sent.
14
+ const MIC_ENCODING_NOTES = {
15
+ pcm16: "raw 24 kHz PCM, about 9.6 KB per 200 ms uplink audio frame",
16
+ adts: "AAC in ADTS frames, uplink audio frames about a tenth of pcm16",
17
+ };
18
+ export function micEncodingNote(label) {
19
+ return Object.hasOwn(MIC_ENCODING_NOTES, label) ? MIC_ENCODING_NOTES[label] : null;
20
+ }
11
21
  // A turn record's `clock` in words. Shared here so the feed row and the report read the same.
12
22
  // An unknown value is the device's to add, so it shows as sent rather than throwing.
13
23
  const TURN_CLOCK_LABELS = {
@@ -18,6 +28,27 @@ const TURN_CLOCK_LABELS = {
18
28
  export function switchboardClockLabel(clock) {
19
29
  return Object.hasOwn(TURN_CLOCK_LABELS, clock) ? TURN_CLOCK_LABELS[clock] : clock;
20
30
  }
31
+ // The most server session ids the device lists in a summary (server_session_ids). The host trims
32
+ // its own lists to the same count, so a summary built here matches one the device sent.
33
+ export const SERVER_SESSION_ID_CAP = 8;
34
+ // The panel's words for a reconnect's trigger and outcome. An unknown token is the device's to add,
35
+ // so it shows as sent rather than throwing; hasOwn keeps a name like "constructor" from finding an
36
+ // Object.prototype member.
37
+ const RECONNECT_TRIGGER_WORDS = { restart: "server restart", drop: "dropped connection", settings: "settings change" };
38
+ const RECONNECT_OUTCOME_WORDS = { ready: "back", retry: "failed, trying again", refused: "refused, call ended" };
39
+ export function reconnectTriggerWord(trigger) {
40
+ return Object.hasOwn(RECONNECT_TRIGGER_WORDS, trigger) ? RECONNECT_TRIGGER_WORDS[trigger] : trigger;
41
+ }
42
+ export function reconnectOutcomeWord(outcome) {
43
+ return Object.hasOwn(RECONNECT_OUTCOME_WORDS, outcome) ? RECONNECT_OUTCOME_WORDS[outcome] : outcome;
44
+ }
45
+ // A reconnect_try record in the export line's words ("drop try 2 ready", "drop gave_up after 2
46
+ // tries"), shared by the feed row and the report. A missing try number reads "?".
47
+ export function reconnectTryLabel(trigger, outcome, n) {
48
+ if (outcome === "gave_up")
49
+ return `${trigger} gave_up after ${n ?? "?"} ${n === 1 ? "try" : "tries"}`;
50
+ return `${trigger} try ${n ?? "?"} ${outcome}`;
51
+ }
21
52
  // The saved_turn outcomes, the one list the feed row, the panel and the report read. `applied`
22
53
  // (a subtitle line still held the frame's item) and `no_line` (no line held it any more, a normal
23
54
  // late save, still kept) keep the turn; the drop reasons lose it. The words are the row's and the
@@ -34,6 +65,40 @@ export const SAVED_TURN_DROP_OUTCOMES = Object.keys(SAVED_TURN_DROPS);
34
65
  export const SAVED_TURN_KEPT_OUTCOMES = Object.keys(SAVED_TURN_KEPT);
35
66
  // The four a revision 3 build always counts, in the order the panel and the report list them.
36
67
  export const SAVED_TURN_OUTCOMES = [...Object.keys(SAVED_TURN_KEPT), ...SAVED_TURN_DROP_OUTCOMES];
68
+ // A card record in words, shared by the feed row, the voice panel and the report. A kind or event
69
+ // the device adds later shows as sent, and a missing field reads "?", so nothing throws.
70
+ const CARD_KIND_WORDS = { tool_approval: "tool approval", auth_prompt: "connect prompt" };
71
+ // An event in this set takes the card down; "shown" and "carried" put it up.
72
+ const CARD_CLOSING_EVENTS = ["answered", "refused", "declined", "closed", "replaced", "expired", "cleared"];
73
+ const CARD_OPENING_EVENTS = ["shown", "carried"];
74
+ export function cardKindWord(kind) {
75
+ if (typeof kind !== "string" || !kind)
76
+ return "?";
77
+ return Object.hasOwn(CARD_KIND_WORDS, kind) ? CARD_KIND_WORDS[kind] : kind;
78
+ }
79
+ export function cardLabel(kind, event, by) {
80
+ const eventWord = typeof event === "string" && event ? event : "?";
81
+ return `${cardKindWord(kind)} ${eventWord}${typeof by === "string" && by ? ` by ${by}` : ""}`;
82
+ }
83
+ // The cards still up after these records, in the order they came up. Shown or carried puts a card
84
+ // up (a re-sent one keeps its place), the closing events take it down, and an event it does not
85
+ // know changes nothing, so a newer device build cannot make a card look gone.
86
+ export function openCards(records) {
87
+ const open = new Map();
88
+ for (const r of records) {
89
+ if (r.kind !== "card" || typeof r.card_kind !== "string" || typeof r.card_id !== "string" || typeof r.event !== "string")
90
+ continue;
91
+ const key = `${r.card_kind}\u0000${r.card_id}`;
92
+ if (CARD_OPENING_EVENTS.includes(r.event)) {
93
+ if (!open.has(key))
94
+ open.set(key, { kind: r.card_kind, id: r.card_id });
95
+ }
96
+ else if (CARD_CLOSING_EVENTS.includes(r.event)) {
97
+ open.delete(key);
98
+ }
99
+ }
100
+ return [...open.values()];
101
+ }
37
102
  // Code points a free-form device string could use to fake a line break, a report boundary, or a
38
103
  // hidden direction override: controls, bidi marks, zero-width characters, U+2028/2029 (a newline
39
104
  // to a browser), and the BOM. Here rather than in the report so the panel strips the same set.
@@ -91,3 +156,14 @@ export function savedTurnCountEntries(counts) {
91
156
  out.push({ outcome: k, count: read(k) });
92
157
  return out;
93
158
  }
159
+ // The server endings that are a normal end, not a fault. Matches the device's `endsNormally`. An
160
+ // older device build sends plain "Server" for these too, and that stays an error since nothing
161
+ // says which ending it was.
162
+ const NORMAL_SERVER_ENDINGS = ["Server:live_session_limit", "Server:session_limit", "Server:live_idle_timeout", "Server:live_call_ended"];
163
+ export function serverEndedNormally(cause) {
164
+ return typeof cause === "string" && NORMAL_SERVER_ENDINGS.includes(cause);
165
+ }
166
+ // A connection state record that moved to Failed on a normal server ending.
167
+ export function connectionEndedNormally(r) {
168
+ return r.kind === "state" && r.state_kind === "connection" && r.to === "Failed" && serverEndedNormally(r.cause);
169
+ }