@slack/radar-mcp 1.20.0 → 1.21.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 (41) hide show
  1. package/README.md +11 -6
  2. package/dist/mcp/api-paths.d.ts +11 -0
  3. package/dist/mcp/api-paths.js +67 -16
  4. package/dist/mcp/index.js +24 -7
  5. package/dist/mcp/network-detail.d.ts +5 -0
  6. package/dist/mcp/network-detail.js +86 -0
  7. package/dist/mcp/radar-response.d.ts +7 -0
  8. package/dist/mcp/radar-response.js +15 -0
  9. package/dist/mcp/session-backfill.d.ts +9 -3
  10. package/dist/mcp/session-backfill.js +77 -17
  11. package/dist/mcp/session-detail.js +54 -2
  12. package/dist/mcp/session-query.js +53 -11
  13. package/dist/mcp/sources-gate.js +4 -0
  14. package/dist/mcp/switchboard-tools.d.ts +9 -0
  15. package/dist/mcp/switchboard-tools.js +40 -0
  16. package/dist/mcp/tools.js +62 -16
  17. package/dist/shared/constants.d.ts +10 -0
  18. package/dist/shared/constants.js +10 -0
  19. package/dist/shared/event-spool.js +3 -2
  20. package/dist/shared/form-body.d.ts +18 -0
  21. package/dist/shared/form-body.js +251 -0
  22. package/dist/shared/stream.d.ts +1 -1
  23. package/dist/shared/switchboard.d.ts +9 -0
  24. package/dist/shared/switchboard.js +54 -0
  25. package/dist/shared/wire.d.ts +32 -0
  26. package/dist/web/public/index.html +172 -10
  27. package/dist/web/public/next/app.js +16 -10
  28. package/dist/web/public/next/db.js +4 -1
  29. package/dist/web/public/next/feed.js +515 -57
  30. package/dist/web/public/next/filters.js +158 -40
  31. package/dist/web/public/next/form-body.js +252 -0
  32. package/dist/web/public/next/inspector.js +103 -12
  33. package/dist/web/public/next/registry.js +21 -2
  34. package/dist/web/public/next/store.js +503 -51
  35. package/dist/web/public/next/voice-model.js +532 -0
  36. package/dist/web/public/next/voice.js +397 -0
  37. package/dist/web/server.d.ts +7 -0
  38. package/dist/web/server.js +154 -16
  39. package/dist/web/spec.d.ts +10 -6
  40. package/dist/web/spec.js +61 -6
  41. package/package.json +3 -3
@@ -5,8 +5,9 @@
5
5
  import { html } from "./html.js";
6
6
  import { useState, useEffect } from "preact/hooks";
7
7
  import { esc } from "./esc.js";
8
- import { shortUrl, store } from "./store.js";
8
+ import { fmtNum, shortUrl, store } from "./store.js";
9
9
  import { hasDetailEndpoint, SOURCES } from "./registry.js";
10
+ import { decodeFormBody, formBodyLooksTruncated, formContentType, jsonTextLooksCut } from "./form-body.js";
10
11
  function shq(s) {
11
12
  return "'" + String(s).replace(/'/g, "'\\''") + "'";
12
13
  }
@@ -73,11 +74,57 @@ function Section({ title, sub, children, open }) {
73
74
  </div>
74
75
  `;
75
76
  }
77
+ function JsonPre({ value }) {
78
+ return html `<pre class="json" dangerouslySetInnerHTML=${{ __html: highlightJson(value, 0) }}></pre>`;
79
+ }
80
+ // A decoded form body: one row per field, a JSON-valued field in its own collapsible subtree
81
+ // through the same highlighter the JSON body uses, everything else as its decoded text.
82
+ function FormFields({ form, truncated }) {
83
+ return html `
84
+ ${truncated ? html `<div class="trunc">${formTruncationNote(form)}</div>` : null}
85
+ <div class="formnote">form body, decoded; Copy cURL carries the raw bytes</div>
86
+ <div class="kv formkv">
87
+ ${form.fields.map((f) => hasEntries(f.json)
88
+ ? html `<div class="kv-k formkey">${f.key}</div><div class="kv-v"><${Section} title="json" sub=${Array.isArray(f.json) ? plural(f.json.length, "item") : plural(Object.keys(f.json).length, "key")}><${JsonPre} value=${f.json} /><//></div>`
89
+ : formValue(f))}
90
+ </div>
91
+ `;
92
+ }
93
+ function formValue(f) {
94
+ const text = f.json !== undefined ? JSON.stringify(f.json) : f.value;
95
+ // A lone space would render as a blank cell, indistinguishable from a missing value, and the
96
+ // two are different facts about the request.
97
+ const shown = text.length === 0 ? "(empty)" : text.trim() === "" ? "(whitespace only)" : null;
98
+ if (shown !== null)
99
+ return html `<div class="kv-k formkey">${f.key}</div><div class="kv-v formval empty">${shown}</div>`;
100
+ // JSON the decoder left unparsed shows as the string it is, with the reason, so the flat text
101
+ // is not mistaken for a value the request sent flat.
102
+ if (f.unparsedReason)
103
+ return html `<div class="kv-k formkey">${f.key}</div><div class="kv-v formval"><div class="formunparsed">${f.unparsedReason}</div>${text}</div>`;
104
+ return html `<div class="kv-k formkey">${f.key}</div><div class="kv-v formval">${text}</div>`;
105
+ }
106
+ // Name the field the device cap cut. When the cut landed inside a field name that name is gone,
107
+ // so the note points at the last field that survived instead.
108
+ function formTruncationNote(form) {
109
+ const last = form.fields[form.fields.length - 1]?.key;
110
+ if (form.truncated)
111
+ return `⚠ truncated by the device cap; complete through ${last}, the rest is missing`;
112
+ return `⚠ truncated by the device cap; ${last} is partial`;
113
+ }
114
+ function plural(n, noun) {
115
+ return n === 1 ? `1 ${noun}` : `${n} ${noun}s`;
116
+ }
117
+ // An empty {} or [] reads better inline than as a collapsible with nothing in it.
118
+ function hasEntries(v) {
119
+ return typeof v === "object" && v !== null && (Array.isArray(v) ? v.length : Object.keys(v).length) > 0;
120
+ }
76
121
  function Body({ parsed }) {
77
122
  const v = parsed.value;
78
123
  if (v && typeof v === "object") {
79
- return html `<pre class="json" dangerouslySetInnerHTML=${{ __html: highlightJson(v, 0) }}></pre>`;
124
+ return html `<${JsonPre} value=${v} />`;
80
125
  }
126
+ if (parsed.form)
127
+ return html `<${FormFields} form=${parsed.form} truncated=${parsed.truncated} />`;
81
128
  return html `
82
129
  ${parsed.truncated ? html `<div class="trunc">⚠ truncated by the device cap</div>` : null}
83
130
  <pre class="json rawbody">${String(v)}</pre>
@@ -89,20 +136,47 @@ function KV({ map }) {
89
136
  return null;
90
137
  return html `<div class="kv">${keys.map((k) => html `<div class="kv-k">${k}</div><div class="kv-v">${String(map[k])}</div>`)}</div>`;
91
138
  }
92
- // Parse a body. A string that does not parse AND looks cut off (starts like JSON, ends
93
- // mid-token) is flagged truncated -- the on-device interceptor caps bodies (installed build at
94
- // 8KB), so large JSON arrives clipped. We show it as readable text with a banner.
139
+ // Parse a body. A string that does not parse AND looks cut off (starts like JSON, ends inside an
140
+ // open bracket or string) is flagged truncated -- the on-device interceptor caps bodies at 1 MB
141
+ // (NetworkRadarPlugin's MAX_BODY_SIZE), so a very large JSON body arrives clipped. We show it as
142
+ // readable text with a banner. The same rule sets request_body_truncated on the MCP side.
95
143
  export function parseBody(v) {
144
+ return parse(v, false);
145
+ }
146
+ // The request body is the only place a form-encoded string (Slack API POSTs) belongs; it keeps
147
+ // its raw value and carries the decoded fields alongside. A response body, clog payload or trace
148
+ // tags that happen to look like `a=1&b=2` render as the text they are. `contentType` is the
149
+ // record's request_content_type and `deviceCut` its request_body_truncated, when the build emits
150
+ // them: the type settles the form question and the flag settles the banner (shape cannot see a
151
+ // body clipped inside a plain value); an older build without them falls back to the shape rules.
152
+ export function parseRequestBody(v, contentType, deviceCut) {
153
+ const parsed = parse(v, true, contentType);
154
+ if (typeof deviceCut !== "boolean" || typeof v !== "string")
155
+ return parsed;
156
+ // A cut the device reports on a body that parsed as whole JSON is still a cut: show the text.
157
+ if (deviceCut && parsed.value !== v && !parsed.form)
158
+ return { value: v, truncated: true, bytes: v.length };
159
+ return { ...parsed, truncated: deviceCut };
160
+ }
161
+ function parse(v, decodeForm, contentType) {
96
162
  if (typeof v !== "string")
97
163
  return { value: v, truncated: false };
98
164
  const s = v.trim();
165
+ // A declared form body is a form before it is anything else: a body `true` or `123` under a
166
+ // form Content-Type is a field named true, the same answer the MCP gives.
167
+ if (decodeForm && formContentType(contentType) === true) {
168
+ const form = decodeFormBody(v, contentType);
169
+ if (form)
170
+ return { value: v, truncated: formBodyLooksTruncated(form), form };
171
+ }
99
172
  try {
100
173
  return { value: JSON.parse(s), truncated: false };
101
174
  }
102
175
  catch {
103
- const looksJson = s.startsWith("{") || s.startsWith("[");
104
- const looksCut = looksJson && !(s.endsWith("}") || s.endsWith("]"));
105
- return { value: v, truncated: looksCut, bytes: v.length };
176
+ const form = decodeForm ? decodeFormBody(v, contentType) : null;
177
+ if (form)
178
+ return { value: v, truncated: formBodyLooksTruncated(form), form };
179
+ return { value: v, truncated: jsonTextLooksCut(s, contentType), bytes: v.length };
106
180
  }
107
181
  }
108
182
  export function statusClass(code) {
@@ -129,7 +203,7 @@ export function Inspector({ ev, onClose }) {
129
203
  if (ev.id == null || !hasDetailEndpoint(kind))
130
204
  return;
131
205
  // read-through the store's shared cache (eager-capture + prior click-fetches land there).
132
- const cached = store.getDetail(kind, ev.id);
206
+ const cached = store.getDetail(kind, ev);
133
207
  if (cached) {
134
208
  setDetail({ ...ev, ...cached, _type: kind });
135
209
  return;
@@ -148,7 +222,7 @@ export function Inspector({ ev, onClose }) {
148
222
  return;
149
223
  }
150
224
  const merged = { ...ev, ...d, _type: kind };
151
- store.cacheDetail(kind, ev.id, merged);
225
+ store.cacheDetail(kind, ev, merged);
152
226
  setDetail(merged);
153
227
  })
154
228
  .catch(() => { })
@@ -159,7 +233,7 @@ export function Inspector({ ev, onClose }) {
159
233
  }, [ev]);
160
234
  const kind = ev._type || "";
161
235
  const isNet = kind === "network" || detail.url != null || detail.method != null;
162
- const title = ev.trace_name || ev.event_name || ev.event_type || shortUrl(ev.url) || kind || "detail";
236
+ const title = kind === "switchboard" ? `switchboard ${ev.kind || ""}`.trim() : ev.trace_name || ev.event_name || ev.event_type || shortUrl(ev.url) || kind || "detail";
163
237
  const copy = (which, e) => {
164
238
  let text = "";
165
239
  if (which === "json")
@@ -215,7 +289,19 @@ export function Inspector({ ev, onClose }) {
215
289
  if (ev.package)
216
290
  badges.push(html `<span class="ibadge">${ev.package}</span>`);
217
291
  }
218
- const reqBody = parseBody(detail.request_body ?? detail.requestBody);
292
+ else if (kind === "switchboard") {
293
+ // The session, (for frames) the direction and (for phases) the duration up top, next to the
294
+ // time badge every kind gets; the kind is already in the title. Every other field of the record
295
+ // lands in "other fields" below. The duration badge exists because duration_ms is omitted from that dump for the
296
+ // network and trace rows, and a phase record's one number must not vanish with it.
297
+ if (ev.session_id != null)
298
+ badges.push(html `<span class="ibadge">session ${String(ev.session_id)}</span>`);
299
+ if (ev.direction)
300
+ badges.push(html `<span class=${"ibadge dir-" + ev.direction}>${ev.direction}</span>`);
301
+ if (ev.duration_ms != null)
302
+ badges.push(html `<span class="ibadge">${fmtNum(Number(ev.duration_ms))} ms</span>`);
303
+ }
304
+ const reqBody = parseRequestBody(detail.request_body ?? detail.requestBody, detail.request_content_type, detail.request_body_truncated);
219
305
  const resBody = parseBody(detail.response_body ?? detail.responseBody);
220
306
  const reqHeaders = (detail.request_headers || detail.requestHeaders);
221
307
  const resHeaders = (detail.response_headers || detail.responseHeaders);
@@ -234,6 +320,11 @@ export function Inspector({ ev, onClose }) {
234
320
  ]);
235
321
  if (traceTags)
236
322
  omit.add("tags"); // rendered in its own section below
323
+ // The kind is in the title with the record's repeated `type`, the session is a badge, so a
324
+ // switchboard dump carries only the fields the header does not already show.
325
+ if (kind === "switchboard")
326
+ for (const k of ["kind", "session_id", "type"])
327
+ omit.add(k);
237
328
  const rest = {};
238
329
  for (const k of Object.keys(detail))
239
330
  if (!omit.has(k))
@@ -2,6 +2,14 @@
2
2
  // edits across many hardcoded conditionals (the vanilla index.html debt). The app reads these
3
3
  // to drive the modebar, the Filters source select + field lists, the feed sort options, the
4
4
  // per-source detail fetch, and which widget components to mount.
5
+ // The caps on `exclude`. Mirrors the server's caps in src/web/spec.ts, which the browser build
6
+ // cannot import; the toolbar, the Filters panel and the view memory all read these.
7
+ export const EXCLUDE_MAX_TERMS = 20;
8
+ export const EXCLUDE_MAX_TERM_LENGTH = 200;
9
+ // Logcat-scale retention window for the store's cache ring. Lives here, not in store.ts, so
10
+ // voice-model.ts (which must stay DOM-free and store-free to run its tests with no runtime) can
11
+ // read it without importing the store itself.
12
+ export const CACHE_TTL_MS = 60 * 60 * 1000;
5
13
  // Match-fields the Filters panel offers per source. `all` is derived as the union below, so a
6
14
  // new source's fields show up in the unified view with no extra edit.
7
15
  export const MATCH_FIELDS = {
@@ -13,13 +21,16 @@ export const MATCH_FIELDS = {
13
21
  // controls with one word and different meanings. A spec that already carries match.level still
14
22
  // works and still shows as a row (the row select keeps an unknown field), it is just not offered.
15
23
  log: ["tag", "message", "pid", "package"],
24
+ // The voice transport's records: `kind` picks the record shape, the rest are that shape's key
25
+ // fields (frame: direction/frame_type, state: state_kind, phase: phase, session/player: event).
26
+ switchboard: ["kind", "session_id", "direction", "frame_type", "state_kind", "phase", "event"],
16
27
  };
17
28
  // `all` = the union of every streaming source's fields (deduped, order-stable). Derived, not
18
29
  // hand-maintained, so adding a source's fields above surfaces them in the unified Live tab too.
19
30
  MATCH_FIELDS.all = (() => {
20
31
  const seen = new Set();
21
32
  const out = [];
22
- for (const src of ["network", "rtm", "clog", "trace", "log"]) {
33
+ for (const src of ["network", "rtm", "clog", "trace", "log", "switchboard"]) {
23
34
  for (const f of MATCH_FIELDS[src])
24
35
  if (!seen.has(f)) {
25
36
  seen.add(f);
@@ -50,6 +61,10 @@ export const SOURCES = {
50
61
  clog: { label: "Clogs", kind: "stream", origin: "device", hasDetailEndpoint: true, eagerCapture: true, ringSize: 1000, detailNoun: "the full payload" },
51
62
  trace: { label: "Traces", kind: "stream", origin: "device", hasDetailEndpoint: true, ringSize: 2000, detailNoun: "the span timing and tag detail" },
52
63
  log: { label: "Logs", kind: "stream", origin: "host", hasDetailEndpoint: false },
64
+ // The Slackbot voice transport's event stream. Device-produced (so a frame is proof the device
65
+ // is answering), but there is no per-record /detail: the device keys its endpoints by session,
66
+ // and every field a record has already rides on the stream row.
67
+ switchboard: { label: "Switchboard", kind: "stream", origin: "device", hasDetailEndpoint: false },
53
68
  all: { label: "Live", kind: "stream", origin: "alias" },
54
69
  db: { label: "Database", kind: "state", origin: "device" },
55
70
  prefs: { label: "Preferences", kind: "state", origin: "device" },
@@ -94,8 +109,12 @@ export function hasDetailEndpoint(kind) {
94
109
  // see widgets.ts). A new widget = one key here + one component.
95
110
  export const WIDGETS = ["counter", "rate", "sparkline", "graph"];
96
111
  // Source order for the modebar / global tab-switch (matches the MODES preset order).
97
- export const SOURCE_ORDER = ["all", "network", "rtm", "clog", "trace", "log", "db", "prefs", "flags"];
112
+ export const SOURCE_ORDER = ["all", "network", "rtm", "clog", "trace", "log", "switchboard", "db", "prefs", "flags"];
98
113
  // The source options the Filters panel offers: every streaming source (state sources like db/prefs
99
114
  // are their own containers, not feed filters). Derived from SOURCES so adding a streaming source
100
115
  // surfaces it in Filters with no edit there. Ordered by SOURCE_ORDER (the modebar order) for a stable, familiar list.
101
116
  export const FILTER_SOURCES = SOURCE_ORDER.filter((s) => SOURCES[s]?.kind === "stream");
117
+ // The five switchboard record kinds, in the order the toolbar's kind chips show them. Each chip
118
+ // writes the exclude term `kind:<name>`; a spec listing that term shows the chip off. These are
119
+ // the kinds switchboardFields (store.ts) knows fields for; a test holds the two lists together.
120
+ export const SWITCHBOARD_KINDS = ["session", "state", "frame", "phase", "player"];