@slack/radar-mcp 1.19.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 (44) hide show
  1. package/README.md +48 -8
  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 +69 -18
  17. package/dist/shared/constants.d.ts +14 -3
  18. package/dist/shared/constants.js +14 -3
  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/install-app.d.ts +64 -1
  27. package/dist/web/install-app.js +174 -24
  28. package/dist/web/macapp/RadarApp.swift +1287 -71
  29. package/dist/web/public/index.html +216 -11
  30. package/dist/web/public/next/app.js +22 -12
  31. package/dist/web/public/next/db.js +180 -18
  32. package/dist/web/public/next/feed.js +571 -53
  33. package/dist/web/public/next/filters.js +160 -34
  34. package/dist/web/public/next/form-body.js +252 -0
  35. package/dist/web/public/next/inspector.js +103 -12
  36. package/dist/web/public/next/registry.js +33 -3
  37. package/dist/web/public/next/store.js +577 -53
  38. package/dist/web/public/next/voice-model.js +532 -0
  39. package/dist/web/public/next/voice.js +397 -0
  40. package/dist/web/server.d.ts +110 -6
  41. package/dist/web/server.js +436 -40
  42. package/dist/web/spec.d.ts +13 -6
  43. package/dist/web/spec.js +89 -6
  44. package/package.json +3 -3
@@ -9,7 +9,7 @@
9
9
  // point-in-time, not a live feed; pulling the store would start the SSE engine + timers on a
10
10
  // tab that has no use for them. It carries its own keyboard nav since there is no Feed here.
11
11
  import { html } from "./html.js";
12
- import { useState, useEffect, useCallback, useRef } from "preact/hooks";
12
+ import { useState, useEffect, useCallback, useMemo, useRef } from "preact/hooks";
13
13
  import { useLatestRef, useGlobalKeydown } from "./hooks.js";
14
14
  // --- query history ---
15
15
  // The queries you ran by hand in this tab, newest-first, per database AND per profile (the same
@@ -144,6 +144,88 @@ function copyText(text, e) {
144
144
  btn.textContent = "copied ✓";
145
145
  setTimeout(() => (btn.textContent = prev), 1200);
146
146
  }
147
+ // The words SQLite refuses as a bare table name in a FROM clause. Deliberately NOT its full
148
+ // keyword list: most SQLite keywords are still legal identifiers, and measuring the difference
149
+ // matters here because every unnecessary quote brings back the swallowing described below. Each
150
+ // of the 147 documented keywords was created as a table and selected from bare; these 58 failed
151
+ // and the other 89 (`key`, `row`, `end`, `filter`, `view`, `match` and the rest) parsed fine.
152
+ // If a later SQLite reserves another word, that name gets a syntax error the moment it is
153
+ // clicked, which is visible and immediate rather than a wrong answer.
154
+ const SQLITE_RESERVED = new Set(("ADD ALL ALTER AND AS AUTOINCREMENT BETWEEN CASE CHECK COLLATE COMMIT CONSTRAINT CREATE " +
155
+ "DEFAULT DEFERRABLE DELETE DISTINCT DROP ELSE ESCAPE EXCEPT EXISTS FOREIGN FROM GROUP " +
156
+ "HAVING IN INDEX INSERT INTERSECT INTO IS ISNULL JOIN LIMIT NOT NOTHING NOTNULL NULL ON " +
157
+ "OR ORDER PRIMARY REFERENCES RETURNING SELECT SET TABLE THEN TO TRANSACTION UNION UNIQUE " +
158
+ "UPDATE USING VALUES WHEN WHERE").split(" "));
159
+ // A bare table name: the identifier shape SQLite accepts without quotes. Any byte at or above 0x80
160
+ // counts as a name character, so a non-ASCII table name needs no quotes either. `$` counts too, but
161
+ // only after the first character: measured, `a$b` and `a$` select bare while `$b` is a syntax error.
162
+ const BARE_NAME = /^[A-Za-z_\u0080-\uFFFF][A-Za-z0-9_$\u0080-\uFFFF]*$/;
163
+ // How a table name is written into the generated SELECT. A plain word goes in bare, because
164
+ // quotes around it swallow whatever is typed beside them: `SELECT * FROM "items" LIMIT 100`
165
+ // edited into `... FROM "items WHERE id='1'" LIMIT 100` asks for a table named
166
+ // `items WHERE id='1'`, and sqlite answers "no such table", which reads as though the table
167
+ // vanished rather than as a clause in the wrong place. A name that cannot stand bare keeps its
168
+ // quotes, with any embedded quote doubled, which is SQL's own escape. Quotes are the fallback
169
+ // because a quoted identifier is always legal, and the set above is kept tight so the fallback
170
+ // stays rare.
171
+ export function tableRef(name) {
172
+ return BARE_NAME.test(name) && !SQLITE_RESERVED.has(name.toUpperCase())
173
+ ? name
174
+ : '"' + name.replace(/"/g, '""') + '"';
175
+ }
176
+ // A cell with nothing in it. SQLite columns are dynamically typed, so one column holds numbers,
177
+ // text and NULL at once. `undefined` is here for a caller passing rows that do not all carry the
178
+ // same columns; /dbquery cannot produce that, because sqlite3 -json emits every key on every row.
179
+ //
180
+ // Whitespace-only text counts as blank, for two reasons. The grid renders cells into `<td>`, where
181
+ // HTML collapses whitespace, so such a cell IS an empty cell to the reader the sort is for. And it
182
+ // keeps whitespace away from `numericValue`, where `Number("")` is 0, which would rank a
183
+ // blank-looking cell as zero ahead of every real number ascending.
184
+ function isBlank(v) {
185
+ return v === null || v === undefined || (typeof v === "string" && v.trim() === "");
186
+ }
187
+ // One collator for the whole module. Building one per comparison costs 222ms to sort a 10000-row
188
+ // text column against 15ms for a cached one, measured, and a sort runs on the UI thread.
189
+ const COLLATOR = new Intl.Collator(undefined, { numeric: true });
190
+ // A cell's numeric value, when it has one. Not just typeof number: SQLite columns are dynamically
191
+ // typed and a column of numbers stored as TEXT is ordinary, so `"1.09"` has to rank as 1.09. Text
192
+ // collation gets those wrong even with numeric:true, because it reads digit runs rather than values:
193
+ // measured, it puts `1.09` after `1.5` and `-3` before `-5`. A value only counts as numeric when the
194
+ // WHOLE string is a finite number, so `item9` still takes the text path and stays ahead of `item10`.
195
+ function numericValue(v) {
196
+ if (typeof v === "number")
197
+ return Number.isFinite(v) ? v : null;
198
+ if (typeof v !== "string")
199
+ return null;
200
+ const n = Number(v.trim());
201
+ return Number.isFinite(n) ? n : null;
202
+ }
203
+ // A copy of `rows` ordered by `col`.
204
+ //
205
+ // Three bands, in this order: values that are numbers, then everything else, then blanks. The
206
+ // direction reorders values WITHIN a band and never reshuffles the bands, so blanks stay at the
207
+ // bottom and numbers stay ahead of text whichever way the column points. Blanks sink because "no
208
+ // value" is not a value to rank, and because a descending sort whose first screen is empty cells
209
+ // hides the rows the sort was for. Text compares with numeric collation, which keeps `item9` ahead of
210
+ // `item10`. Array.prototype.sort is stable, so rows that tie keep the order the query returned them
211
+ // in, which is what the third click goes back to.
212
+ export function sortRows(rows, col, dir) {
213
+ return rows.slice().sort((x, y) => {
214
+ const xv = x[col];
215
+ const yv = y[col];
216
+ const xb = isBlank(xv);
217
+ const yb = isBlank(yv);
218
+ if (xb || yb)
219
+ return xb && yb ? 0 : xb ? 1 : -1;
220
+ const xn = numericValue(xv);
221
+ const yn = numericValue(yv);
222
+ if (xn !== null && yn !== null)
223
+ return dir * (xn < yn ? -1 : xn > yn ? 1 : 0);
224
+ if ((xn === null) !== (yn === null))
225
+ return xn !== null ? -1 : 1;
226
+ return dir * COLLATOR.compare(String(xv), String(yv));
227
+ });
228
+ }
147
229
  export function DbBrowser({ spec }) {
148
230
  const [user, setUser] = useState(null);
149
231
  const [dbs, setDbs] = useState(null); // null = loading
@@ -152,9 +234,13 @@ export function DbBrowser({ spec }) {
152
234
  const [sql, setSql] = useState("");
153
235
  const [out, setOut] = useState({ msg: "pick a database, then a table" });
154
236
  const [meta, setMeta] = useState("");
155
- // The result row whose full detail is open in the dock. Cleared whenever a new query runs,
156
- // since a stale row index would point into the old result set.
237
+ // The result row whose full detail is open in the dock. Held as the row itself rather than its
238
+ // position, because sorting moves the position while the open row stays the same row. Cleared
239
+ // whenever a new query runs, since a row from the old result set has nothing to point at.
157
240
  const [selectedRow, setSelectedRow] = useState(null);
241
+ // How the grid is ordered. Cleared when a new result ARRIVES rather than when a query is sent, so
242
+ // an earlier answer landing late cannot inherit an ordering chosen for a different result.
243
+ const [sort, setSort] = useState(null);
158
244
  // What the right-hand dock is showing, if anything. Row detail and query history share one
159
245
  // dock (tabbed) so the results grid never has to give up width to two panels at once.
160
246
  const [dock, setDock] = useState(() => (readDockPref() ? "history" : null));
@@ -251,6 +337,7 @@ export function DbBrowser({ spec }) {
251
337
  setOut({ error: r.error });
252
338
  return; // a rejected query is not worth remembering
253
339
  }
340
+ setSort(null); // see the state declaration for why this is here and not before the request
254
341
  // Recorded on any answer the server accepted, 0 rows included -- an empty result is a
255
342
  // legitimate query you may well want to run again.
256
343
  if (record)
@@ -271,8 +358,39 @@ export function DbBrowser({ spec }) {
271
358
  setOut({ error: "network error running query" });
272
359
  }
273
360
  }, [db, sql, user, userQS]);
361
+ // Clicking a column header walks it: ascending, then descending, then back to the order the query
362
+ // returned. Clicking a different header starts that column ascending. Nothing here touches the
363
+ // query or the device: it is grid state over the rows already on screen, which is why it is instant
364
+ // and why the grid says what it covered.
365
+ const cycleSort = useCallback((col) => {
366
+ setSort((s) => (!s || s.col !== col ? { col, dir: 1 } : s.dir === 1 ? { col, dir: -1 } : null));
367
+ }, []);
368
+ // The rows as the grid shows them. Memoized on the rows and the sort so scrolling, opening a row,
369
+ // or typing in the SQL box does not re-sort a big result on every render.
370
+ const shown = useMemo(() => (out.rows && out.rows.length && sort ? sortRows(out.rows, sort.col, sort.dir) : out.rows), [out.rows, sort]);
371
+ // Column set comes from the rows AS THEY ARRIVED, never from the sorted copy, so which row landed
372
+ // first cannot change which columns the grid has. /dbquery cannot actually send rows with
373
+ // different keys, since sqlite3 -json emits every key on every row, but Grid takes the rows it is
374
+ // given and this makes the header set independent of their order either way.
375
+ const cols = useMemo(() => (out.rows && out.rows.length ? Object.keys(out.rows[0]) : []), [out.rows]);
376
+ // The scope, said in rendered text beside the row count rather than in a tooltip, because a sorted
377
+ // column normally implies the whole result and this one covers the rows on screen. Said every time
378
+ // a sort is in effect rather than only when something looks unusual.
379
+ //
380
+ // It states coverage and stops there. Naming what was left out would be a claim about the query,
381
+ // and nothing here can tell whether anything WAS left out: `LIMIT 100` that hands back 14 rows
382
+ // truncated nothing, so "not the whole result" is false exactly as often as it is useful. The
383
+ // reason a reader needs, that `LIMIT` with no ORDER BY returns a storage-order prefix and so the
384
+ // top row after sorting by time can be the newest of an OLD hundred, is in the header tooltip,
385
+ // where it is advice about the next click rather than an assertion about this result.
386
+ //
387
+ // Only rendered when there are rows, so it cannot sit beside a stale count while a query is in
388
+ // flight or after one has failed.
389
+ const sortScope = sort && out.rows && out.rows.length
390
+ ? html `<span class="dbsortnote"> · sorted these ${out.rows.length} rows</span>`
391
+ : null;
274
392
  const pickTable = useCallback((t) => {
275
- const q = 'SELECT * FROM "' + t + '" LIMIT 100';
393
+ const q = "SELECT * FROM " + tableRef(t) + " LIMIT 100";
276
394
  setSql(q);
277
395
  run(q, false); // generated, not typed: keep it out of the history
278
396
  }, [run]);
@@ -325,6 +443,17 @@ export function DbBrowser({ spec }) {
325
443
  if (el && el.scrollIntoView)
326
444
  el.scrollIntoView({ block: "nearest" });
327
445
  }, [pane, dbIdx, tblIdx, histIdx]);
446
+ // The results pane scrolls and its header is sticky, so a sort is one click away however deep you
447
+ // are. Reordering under a scrolled viewport leaves you in the middle of the new order looking at an
448
+ // arbitrary slice, with the rows the sort was for off-screen above. Go back to the top, which is
449
+ // where the answer now is. Keyed on the rows as well as the sort, because a new result is the other
450
+ // way the content under the viewport changes completely, and it should not matter which of the two
451
+ // put different rows there.
452
+ const outRef = useRef(null);
453
+ useEffect(() => {
454
+ if (outRef.current)
455
+ outRef.current.scrollTop = 0;
456
+ }, [sort, out.rows]);
328
457
  // Keyboard navigation. The latest lists/indices/handlers live in a ref so the single window
329
458
  // listener (attached once by useGlobalKeydown) never goes stale. Mirrors the PoC's
330
459
  // stale-closure-ref pattern, now via the shared Foundation hooks.
@@ -496,23 +625,28 @@ export function DbBrowser({ spec }) {
496
625
  </button>`
497
626
  : null}
498
627
  </div>
499
- <div class="dbmeta">${meta}</div>
628
+ <div class="dbmeta">${meta}${sortScope}</div>
500
629
  <div class=${"dbsplit" + (dock ? " open" : "")}>
501
- <div class="dbout">
630
+ <div class="dbout" ref=${outRef}>
502
631
  ${out.msg
503
632
  ? html `<div class="msg">${out.msg}</div>`
504
633
  : out.error
505
634
  ? html `<div class="msg err">${out.error}</div>`
506
- : !out.rows || !out.rows.length
635
+ : !shown || !shown.length
507
636
  ? html `<div class="msg">0 rows</div>`
508
637
  : html `<${Grid}
509
- rows=${out.rows}
510
- selectedIndex=${dock === "row" && selectedRow ? selectedRow.index : -1}
511
- onSelect=${(row, index) => {
638
+ rows=${shown}
639
+ cols=${cols}
640
+ sort=${sort}
641
+ onSort=${cycleSort}
642
+ selectedRow=${dock === "row" ? selectedRow : null}
643
+ onSelect=${(row) => {
512
644
  // Clicking the open row again closes it; the dock then falls back to
513
- // history if that is where you had it.
514
- const same = dock === "row" && selectedRow && selectedRow.index === index;
515
- setSelectedRow(same ? null : { row, index });
645
+ // history if that is where you had it. Compared by row, not by position,
646
+ // so a sort between the two clicks cannot make them look like different
647
+ // rows (or make two different rows look like the same one).
648
+ const same = dock === "row" && selectedRow === row;
649
+ setSelectedRow(same ? null : row);
516
650
  setDock(same ? (readDockPref() ? "history" : null) : "row");
517
651
  }}
518
652
  />`}
@@ -534,7 +668,7 @@ export function DbBrowser({ spec }) {
534
668
  <span class="x" title="close" onClick=${closeDock}>✕</span>
535
669
  </div>
536
670
  ${dock === "row" && selectedRow
537
- ? html `<${RowInspector} row=${selectedRow.row} />`
671
+ ? html `<${RowInspector} row=${selectedRow} />`
538
672
  : html `<${HistoryPanel}
539
673
  entries=${history}
540
674
  focusIdx=${pane === "hist" ? histIdx : -1}
@@ -552,17 +686,45 @@ export function DbBrowser({ spec }) {
552
686
  </div>
553
687
  `;
554
688
  }
555
- function Grid({ rows, selectedIndex, onSelect, }) {
556
- const cols = Object.keys(rows[0]);
689
+ function Grid({ rows, cols, selectedRow, onSelect, sort, onSort, }) {
690
+ // What the next click does, and what it will cover, at the control rather than only on the meta
691
+ // line. The remedy is here too: nothing else tells a reader that the wider question is theirs to
692
+ // ask, and it is knowable without inspecting anything.
693
+ //
694
+ // No aria-describedby pointing at the scope note. It was tried and measured worse: a description
695
+ // SUPERSEDES the title in the accessible name computation, so the action copy disappeared from the
696
+ // accessibility tree exactly where it stops being guessable, and pointing every header at one
697
+ // result-wide note described eleven unsorted columns as sorted. The note is rendered text either
698
+ // way, so a reader meets it; it is just not wired to the control.
699
+ const hint = (dir) => dir === null
700
+ ? "sort ascending, these rows only. Add ORDER BY to the query to sort everything"
701
+ : dir === 1
702
+ ? "sort descending, these rows only. Add ORDER BY to the query to sort everything"
703
+ : "clear the sort";
557
704
  return html `
558
705
  <table>
559
706
  <thead>
560
707
  <tr>
561
- ${cols.map((c) => html `<th>${c}</th>`)}
708
+ ${cols.map((c) => {
709
+ // One read of the sort per header, which every other attribute derives from: null means
710
+ // this column is not the sorted one.
711
+ const dir = sort !== null && sort.col === c ? sort.dir : null;
712
+ return html `<th
713
+ class=${"dbsortable" + (dir === null ? "" : " sorted")}
714
+ title=${hint(dir)}
715
+ aria-sort=${dir === null ? "none" : dir === 1 ? "ascending" : "descending"}
716
+ onClick=${() => onSort(c)}
717
+ >
718
+ ${c}<span class="dbsortdir" aria-hidden="true">${dir === null ? "↕" : dir === 1 ? "▲" : "▼"}</span>
719
+ </th>`;
720
+ })}
562
721
  </tr>
563
722
  </thead>
564
723
  <tbody>
565
- ${rows.map((row, i) => html `<tr class=${i === selectedIndex ? "rowsel" : ""} onClick=${() => onSelect(row, i)}>
724
+ ${rows.map(
725
+ // Keyed by the row object, which sortRows leaves untouched because it copies the array and
726
+ // not the rows, so a sort moves the existing rows instead of rewriting every cell in place.
727
+ (row) => html `<tr key=${row} class=${row === selectedRow ? "rowsel" : ""} onClick=${() => onSelect(row)}>
566
728
  ${cols.map((c) => html `<td title=${String(row[c] ?? "")}>${String(row[c] ?? "")}</td>`)}
567
729
  </tr>`)}
568
730
  </tbody>