@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.
- package/README.md +48 -8
- package/dist/mcp/api-paths.d.ts +11 -0
- package/dist/mcp/api-paths.js +67 -16
- package/dist/mcp/index.js +24 -7
- package/dist/mcp/network-detail.d.ts +5 -0
- package/dist/mcp/network-detail.js +86 -0
- package/dist/mcp/radar-response.d.ts +7 -0
- package/dist/mcp/radar-response.js +15 -0
- package/dist/mcp/session-backfill.d.ts +9 -3
- package/dist/mcp/session-backfill.js +77 -17
- package/dist/mcp/session-detail.js +54 -2
- package/dist/mcp/session-query.js +53 -11
- package/dist/mcp/sources-gate.js +4 -0
- package/dist/mcp/switchboard-tools.d.ts +9 -0
- package/dist/mcp/switchboard-tools.js +40 -0
- package/dist/mcp/tools.js +69 -18
- package/dist/shared/constants.d.ts +14 -3
- package/dist/shared/constants.js +14 -3
- package/dist/shared/event-spool.js +3 -2
- package/dist/shared/form-body.d.ts +18 -0
- package/dist/shared/form-body.js +251 -0
- package/dist/shared/stream.d.ts +1 -1
- package/dist/shared/switchboard.d.ts +9 -0
- package/dist/shared/switchboard.js +54 -0
- package/dist/shared/wire.d.ts +32 -0
- package/dist/web/install-app.d.ts +64 -1
- package/dist/web/install-app.js +174 -24
- package/dist/web/macapp/RadarApp.swift +1287 -71
- package/dist/web/public/index.html +216 -11
- package/dist/web/public/next/app.js +22 -12
- package/dist/web/public/next/db.js +180 -18
- package/dist/web/public/next/feed.js +571 -53
- package/dist/web/public/next/filters.js +160 -34
- package/dist/web/public/next/form-body.js +252 -0
- package/dist/web/public/next/inspector.js +103 -12
- package/dist/web/public/next/registry.js +33 -3
- package/dist/web/public/next/store.js +577 -53
- package/dist/web/public/next/voice-model.js +532 -0
- package/dist/web/public/next/voice.js +397 -0
- package/dist/web/server.d.ts +110 -6
- package/dist/web/server.js +436 -40
- package/dist/web/spec.d.ts +13 -6
- package/dist/web/spec.js +89 -6
- package/package.json +3 -3
package/dist/shared/constants.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createRequire } from "module";
|
|
2
2
|
/**
|
|
3
3
|
* Package version, read once from package.json at load — NOT a hardcoded copy, so it cannot
|
|
4
|
-
* drift from the published version. Surfaced as the `X-Radar-Version` header on
|
|
5
|
-
* second launcher can tell whether the dashboard
|
|
6
|
-
* Radar version than itself (the adopt path notices a
|
|
4
|
+
* drift from the published version. Surfaced as the `X-Radar-Version` header on every dashboard
|
|
5
|
+
* response past the Host gate (docs/wire-contract.md §7) so a second launcher can tell whether the dashboard
|
|
6
|
+
* already holding the port is a different Radar version than itself (the adopt path notices a
|
|
7
|
+
* mismatch; it still adopts, never kills), and a machine consumer can detect version skew.
|
|
7
8
|
* Falls back to "unknown" if package.json cannot be read (should not happen in a real install).
|
|
8
9
|
*/
|
|
9
10
|
export const RADAR_VERSION = (() => {
|
|
@@ -101,3 +102,13 @@ export const MAX_RADAR_RESPONSE_BYTES = 1024 * 1024;
|
|
|
101
102
|
* any future second caller of this cap shares it rather than risking drift.
|
|
102
103
|
*/
|
|
103
104
|
export const MAX_PREFS_RESPONSE_BYTES = 64 * 1024;
|
|
105
|
+
/**
|
|
106
|
+
* Past this many UTF-8 bytes get_network_call_detail (and a query_session id read) skip the decoded
|
|
107
|
+
* copy of a form-encoded request body and say so in request_body_decoded_omitted; the raw bytes
|
|
108
|
+
* still ride in request_body. The decoded pretty print runs about three times the raw, so the copy
|
|
109
|
+
* would otherwise pile onto an already large payload in the model context. Both the raw body and
|
|
110
|
+
* the decoded pretty print are measured against this one number. The label is the prose form
|
|
111
|
+
* every note and tool description in the server uses, so the number is spelled once there.
|
|
112
|
+
*/
|
|
113
|
+
export const MAX_FORM_DECODE_BYTES = 64 * 1024;
|
|
114
|
+
export const FORM_DECODE_LIMIT_LABEL = `${MAX_FORM_DECODE_BYTES / 1024} KB`;
|
|
@@ -2,8 +2,9 @@ import fs from "fs";
|
|
|
2
2
|
import os from "os";
|
|
3
3
|
import path from "path";
|
|
4
4
|
/**
|
|
5
|
-
* Appends every streamed SSE frame (network, rtm, clog,
|
|
6
|
-
*
|
|
5
|
+
* Appends every streamed SSE frame (network, rtm, clog, trace, switchboard; log
|
|
6
|
+
* lines are a host-side dashboard merge and never reach it) to a per-session
|
|
7
|
+
* file so the full session record survives buffer eviction. The
|
|
7
8
|
* device rings and the host push ring both drop the oldest entry once full, so
|
|
8
9
|
* a long session loses its early events; the spool keeps the whole session. It
|
|
9
10
|
* does not replace the rings. The device ring stays the source of truth: it
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface FormField {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
json?: unknown;
|
|
5
|
+
unparsedReason?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FormBody {
|
|
8
|
+
fields: FormField[];
|
|
9
|
+
truncated: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function formContentType(contentType: unknown): boolean | undefined;
|
|
12
|
+
export declare function isFormBody(text: string, contentType?: unknown): boolean;
|
|
13
|
+
export declare function looksLikeFormBody(text: string): boolean;
|
|
14
|
+
export declare function decodeFormBody(text: string, contentType?: unknown): FormBody | null;
|
|
15
|
+
export declare function formBodyLooksTruncated(body: FormBody): boolean;
|
|
16
|
+
export declare function formTextLooksTruncated(text: string): boolean;
|
|
17
|
+
export declare function jsonTextLooksCut(text: string, contentType?: unknown): boolean;
|
|
18
|
+
export declare function formBodyToObject(body: FormBody): Record<string, unknown>;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// Decode an application/x-www-form-urlencoded request body into its fields. A record that carries
|
|
2
|
+
// `request_content_type` (the request's Content-Type, read off the OkHttp body by the device
|
|
3
|
+
// interceptor) is a form or not by that field alone. A record without it predates the field, so a
|
|
4
|
+
// form body is recognised by shape: `key=value&key=value` with nothing that would make it JSON or
|
|
5
|
+
// prose. Slack API POSTs routinely tuck JSON inside a field (blocks, types, client_context), so
|
|
6
|
+
// every decoded value that looks like JSON is parsed too. Pure, never throws.
|
|
7
|
+
//
|
|
8
|
+
// The browser build cannot import from src/shared, so scripts/mirror-shared.mjs copies this file
|
|
9
|
+
// to src/web/public/next/form-body.ts at build time (gitignored). This is the one to edit.
|
|
10
|
+
// Every pair is `name=value` with no whitespace; a trailing empty value (`draft_id=`) is fine.
|
|
11
|
+
const FORM_SHAPE = /^[^=&\s]+=[^&\s]*(&[^=&\s]+=[^&\s]*)*$/;
|
|
12
|
+
// A lone pair needs a field-like key: a base64 blob such as `QUJDRA==` otherwise passes the
|
|
13
|
+
// shape as key `QUJDRA` with value `=`. Real field names start with a letter or underscore and
|
|
14
|
+
// stay short; the padding pattern catches the blobs that happen to start with a letter too.
|
|
15
|
+
const KEY_START = /^[A-Za-z_]/;
|
|
16
|
+
const MAX_LONE_KEY = 64;
|
|
17
|
+
const BASE64_BLOB = /^[A-Za-z0-9+/]+=*$/;
|
|
18
|
+
// A lower-case snake_case key is a field name, never base64 padding (`token=`, `_x=1`).
|
|
19
|
+
const PLAIN_FIELD_NAME = /^[a-z_][a-z0-9_]*$/;
|
|
20
|
+
// Bracket nesting past this is not a payload the tool needs to read, and the dashboard's JSON
|
|
21
|
+
// highlighter recurses one frame per level, so a hostile depth stays a string, marked as left
|
|
22
|
+
// unparsed so the reader knows it was a choice. Real bodies sit far under it: the fixture's `blocks` nest 6
|
|
23
|
+
// deep, and rich_text lists carry their indent as a field rather than by nesting.
|
|
24
|
+
const MAX_JSON_DEPTH = 32;
|
|
25
|
+
const DEPTH_UNPARSED = `JSON nested past ${MAX_JSON_DEPTH} levels; left unparsed`;
|
|
26
|
+
// The declared media type, with or without parameters. Anchored on the type itself so a
|
|
27
|
+
// multipart boundary or a suffix that happens to contain the words does not read as a form.
|
|
28
|
+
const FORM_MEDIA_TYPE = /^\s*application\/x-www-form-urlencoded\s*(;|$)/i;
|
|
29
|
+
// application/json, the +json structured-syntax family (application/vnd.api+json) and the
|
|
30
|
+
// unregistered but seen text/json, with or without parameters.
|
|
31
|
+
const JSON_MEDIA_TYPE = /^\s*(application|text)\/([\w.+-]*\+)?json\s*(;|$)/i;
|
|
32
|
+
// The first two characters of a JSON object or array with something (or nothing) inside. A
|
|
33
|
+
// value like `[WIP] fix` or `{fire}` opens with a bracket too, but not like a JSON token.
|
|
34
|
+
const JSON_OPENER = /^(\{"|\{\}|\[\{|\["|\[\[|\[-?\d|\[(true|false|null)|\[\])/;
|
|
35
|
+
// Split off a tail the device cap left without an `=`: the body was cut inside a field name or
|
|
36
|
+
// right after an `&`. Only applies when a complete pair precedes it, so a bare word stays intact.
|
|
37
|
+
function splitCutTail(body) {
|
|
38
|
+
const amp = body.lastIndexOf("&");
|
|
39
|
+
if (amp > 0 && /^[^=&\s]*$/.test(body.slice(amp + 1))) {
|
|
40
|
+
return { body: body.slice(0, amp), truncated: true };
|
|
41
|
+
}
|
|
42
|
+
return { body, truncated: false };
|
|
43
|
+
}
|
|
44
|
+
// The record's own answer when it has one: `request_content_type` settles the form question
|
|
45
|
+
// without the shape rules. undefined means the record carries no verdict (a build that predates
|
|
46
|
+
// the field), so the caller falls back to shape.
|
|
47
|
+
export function formContentType(contentType) {
|
|
48
|
+
if (typeof contentType !== "string" || contentType.trim() === "")
|
|
49
|
+
return undefined;
|
|
50
|
+
return FORM_MEDIA_TYPE.test(contentType);
|
|
51
|
+
}
|
|
52
|
+
// The record's own answer to "is this JSON?", by the same rule: undefined without a verdict.
|
|
53
|
+
function jsonContentType(contentType) {
|
|
54
|
+
if (typeof contentType !== "string" || contentType.trim() === "")
|
|
55
|
+
return undefined;
|
|
56
|
+
return JSON_MEDIA_TYPE.test(contentType);
|
|
57
|
+
}
|
|
58
|
+
// Is this request body a form? The declared Content-Type wins when the record has one; the shape
|
|
59
|
+
// rules stand in when it does not. One shape rule holds either way: a body that opens like a JSON
|
|
60
|
+
// token (`{"`, `[{`, `[1`; not `[WIP]` or `{fire}`) is not a form, whatever the header says,
|
|
61
|
+
// because URLSearchParams would swallow the whole text as a single key and hide a cut. Both the
|
|
62
|
+
// decode and the caller that skips it for an oversized body go through here, so the two paths
|
|
63
|
+
// cannot disagree about what is a form.
|
|
64
|
+
export function isFormBody(text, contentType) {
|
|
65
|
+
if (typeof text !== "string")
|
|
66
|
+
return false;
|
|
67
|
+
const declared = formContentType(contentType);
|
|
68
|
+
if (declared === undefined)
|
|
69
|
+
return looksLikeFormBody(text);
|
|
70
|
+
const trimmed = text.trim();
|
|
71
|
+
return declared && trimmed.length > 0 && !opensLikeJsonToken(trimmed);
|
|
72
|
+
}
|
|
73
|
+
// The whole-body opener: JSON_OPENER after collapsing whitespace behind the bracket, so a
|
|
74
|
+
// pretty-printed body qualifies and bracketed prose does not.
|
|
75
|
+
function opensLikeJsonToken(trimmed) {
|
|
76
|
+
return JSON_OPENER.test(trimmed.replace(/^([[{])\s+/, "$1"));
|
|
77
|
+
}
|
|
78
|
+
// The whole shape verdict without the decode: the pair pattern plus the lone-pair rules, for a
|
|
79
|
+
// record with no Content-Type of its own.
|
|
80
|
+
export function looksLikeFormBody(text) {
|
|
81
|
+
if (typeof text !== "string")
|
|
82
|
+
return false;
|
|
83
|
+
// Surrounding whitespace (a captured trailing newline) is not part of the body shape.
|
|
84
|
+
const trimmed = text.trim();
|
|
85
|
+
if (trimmed.length === 0 || trimmed[0] === "{" || trimmed[0] === "[")
|
|
86
|
+
return false;
|
|
87
|
+
const { body } = splitCutTail(trimmed);
|
|
88
|
+
if (!FORM_SHAPE.test(body))
|
|
89
|
+
return false;
|
|
90
|
+
if (!body.includes("&")) {
|
|
91
|
+
const key = body.slice(0, body.indexOf("="));
|
|
92
|
+
if (key.length > MAX_LONE_KEY || !KEY_START.test(key))
|
|
93
|
+
return false;
|
|
94
|
+
if (!PLAIN_FIELD_NAME.test(key) && BASE64_BLOB.test(body))
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
export function decodeFormBody(text, contentType) {
|
|
100
|
+
if (!isFormBody(text, contentType))
|
|
101
|
+
return null;
|
|
102
|
+
const { body, truncated } = splitCutTail(text.trim());
|
|
103
|
+
let params;
|
|
104
|
+
try {
|
|
105
|
+
params = new URLSearchParams(body);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const fields = [];
|
|
111
|
+
params.forEach((value, key) => {
|
|
112
|
+
const field = { key, value };
|
|
113
|
+
if (opensLikeJson(value) && scanJson(value).depth > MAX_JSON_DEPTH) {
|
|
114
|
+
field.unparsedReason = DEPTH_UNPARSED;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const json = parseJsonValue(value);
|
|
118
|
+
if (json !== undefined)
|
|
119
|
+
field.json = json;
|
|
120
|
+
}
|
|
121
|
+
fields.push(field);
|
|
122
|
+
});
|
|
123
|
+
return fields.length ? { fields, truncated } : null;
|
|
124
|
+
}
|
|
125
|
+
function opensLikeJson(value) {
|
|
126
|
+
const c = value[0];
|
|
127
|
+
return c === "{" || c === "[";
|
|
128
|
+
}
|
|
129
|
+
function parseJsonValue(value) {
|
|
130
|
+
if (!opensLikeJson(value))
|
|
131
|
+
return undefined;
|
|
132
|
+
if (scanJson(value).depth > MAX_JSON_DEPTH)
|
|
133
|
+
return undefined;
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(value);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// One linear pass over a JSON-looking value: the deepest `{` / `[` nesting, skipping bracket
|
|
142
|
+
// characters inside strings, and whether the text is still open when it ends (a bracket never
|
|
143
|
+
// closed, or a string never terminated). Open at the end is what a cut looks like; a value that
|
|
144
|
+
// merely ends in a letter (`[1] fix typo`) is balanced and is not.
|
|
145
|
+
function scanJson(value) {
|
|
146
|
+
let depth = 0;
|
|
147
|
+
let deepest = 0;
|
|
148
|
+
let inString = false;
|
|
149
|
+
for (let i = 0; i < value.length; i++) {
|
|
150
|
+
const ch = value[i];
|
|
151
|
+
if (inString) {
|
|
152
|
+
if (ch === "\\")
|
|
153
|
+
i++;
|
|
154
|
+
else if (ch === '"')
|
|
155
|
+
inString = false;
|
|
156
|
+
}
|
|
157
|
+
else if (ch === '"') {
|
|
158
|
+
inString = true;
|
|
159
|
+
}
|
|
160
|
+
else if (ch === "{" || ch === "[") {
|
|
161
|
+
depth++;
|
|
162
|
+
if (depth > deepest)
|
|
163
|
+
deepest = depth;
|
|
164
|
+
}
|
|
165
|
+
else if (ch === "}" || ch === "]") {
|
|
166
|
+
depth--;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return { depth: deepest, open: depth > 0 || inString };
|
|
170
|
+
}
|
|
171
|
+
// The device caps a captured body, so a long form body can end mid-field. Either the tail was
|
|
172
|
+
// cut inside a field name (dropped at decode time), or the last value opens like a JSON token,
|
|
173
|
+
// did not parse, and is still open where the text ends: it was clipped inside its JSON.
|
|
174
|
+
export function formBodyLooksTruncated(body) {
|
|
175
|
+
if (body.truncated)
|
|
176
|
+
return true;
|
|
177
|
+
const last = body.fields[body.fields.length - 1];
|
|
178
|
+
if (!last || last.json !== undefined)
|
|
179
|
+
return false;
|
|
180
|
+
return valueLooksCut(last.value);
|
|
181
|
+
}
|
|
182
|
+
// The same verdict from the raw text, reading only the last pair, for a body too large to decode.
|
|
183
|
+
export function formTextLooksTruncated(text) {
|
|
184
|
+
if (typeof text !== "string")
|
|
185
|
+
return false;
|
|
186
|
+
const { body, truncated } = splitCutTail(text.trim());
|
|
187
|
+
if (truncated)
|
|
188
|
+
return true;
|
|
189
|
+
const last = body.slice(body.lastIndexOf("&") + 1);
|
|
190
|
+
if (!last.includes("="))
|
|
191
|
+
return false;
|
|
192
|
+
// Read the value off the parsed pair rather than by raw key: a `+` or percent escape in the
|
|
193
|
+
// name would make a raw-key lookup miss.
|
|
194
|
+
const value = [...new URLSearchParams(last).values()][0] ?? "";
|
|
195
|
+
return valueLooksCut(value);
|
|
196
|
+
}
|
|
197
|
+
// Bracket balance decides, not the last character: `[1] fix typo` closes its bracket and is a
|
|
198
|
+
// plain value; `[{"a":1}` closes the inner brace and is still a cut.
|
|
199
|
+
function valueLooksCut(value) {
|
|
200
|
+
return JSON_OPENER.test(value) && scanJson(value).open && parseJsonValue(value) === undefined;
|
|
201
|
+
}
|
|
202
|
+
// The same cut verdict for a whole JSON request body (not a form): it opens like a JSON token,
|
|
203
|
+
// does not parse, and the text ends inside an open bracket or string. `{"a":1}trailing` fails to
|
|
204
|
+
// parse but is balanced, so it is malformed rather than cut and stays unflagged; `[draft` opens
|
|
205
|
+
// with a bracket but not like JSON, so a plain-text body is not flagged either. Whitespace after
|
|
206
|
+
// the opening bracket is collapsed first so a pretty-printed body still qualifies. A record that
|
|
207
|
+
// declares a type that is neither JSON nor form (text/plain, multipart) is text whatever it opens
|
|
208
|
+
// with, so it is never flagged. A declared form body is read by shape here like a record with no
|
|
209
|
+
// declared type: the only form-typed body that can be a cut is one that opens like a JSON token,
|
|
210
|
+
// which isFormBody already refused as a mislabel.
|
|
211
|
+
export function jsonTextLooksCut(text, contentType) {
|
|
212
|
+
if (typeof text !== "string")
|
|
213
|
+
return false;
|
|
214
|
+
if (jsonContentType(contentType) === false && formContentType(contentType) !== true)
|
|
215
|
+
return false;
|
|
216
|
+
const s = text.trim();
|
|
217
|
+
if (!opensLikeJsonToken(s) || !scanJson(s).open)
|
|
218
|
+
return false;
|
|
219
|
+
try {
|
|
220
|
+
JSON.parse(s);
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Collapse the field list into a plain object: the parsed JSON where a value parsed, else the
|
|
228
|
+
// decoded string. A key that repeats becomes an array in wire order.
|
|
229
|
+
export function formBodyToObject(body) {
|
|
230
|
+
// Built without a prototype so a field named toString, constructor or __proto__ is just a key.
|
|
231
|
+
const out = Object.create(null);
|
|
232
|
+
// Keys seen more than once. Needed because a first value can itself be a JSON array
|
|
233
|
+
// (`attachments=[]`), which must not be mistaken for an accumulator on a repeat.
|
|
234
|
+
const repeated = new Set();
|
|
235
|
+
for (const f of body.fields) {
|
|
236
|
+
const v = f.json !== undefined ? f.json : f.value;
|
|
237
|
+
if (!Object.hasOwn(out, f.key)) {
|
|
238
|
+
out[f.key] = v;
|
|
239
|
+
}
|
|
240
|
+
else if (repeated.has(f.key)) {
|
|
241
|
+
out[f.key].push(v);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
out[f.key] = [out[f.key], v];
|
|
245
|
+
repeated.add(f.key);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Hand back an ordinary object; fromEntries defines own properties, so a `__proto__` key
|
|
249
|
+
// stays a key instead of swapping the prototype the way assignment would.
|
|
250
|
+
return Object.fromEntries(Object.entries(out));
|
|
251
|
+
}
|
package/dist/shared/stream.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface RadarEvent {
|
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}
|
|
8
8
|
export interface ParsedSSE {
|
|
9
|
-
type: "network" | "rtm" | "clog" | "log" | "trace" | `${string}_detail`;
|
|
9
|
+
type: "network" | "rtm" | "clog" | "log" | "trace" | "switchboard" | `${string}_detail`;
|
|
10
10
|
event: RadarEvent;
|
|
11
11
|
}
|
|
12
12
|
export declare const localNetworkBuffer: RadarEvent[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const SWITCHBOARD_KIND = "switchboard";
|
|
2
|
+
export declare const SWITCHBOARD_BACKFILL_SESSIONS = 3;
|
|
3
|
+
export declare const SWITCHBOARD_BACKFILL_DEADLINE_MS: number;
|
|
4
|
+
export declare function switchboardListPath(): string;
|
|
5
|
+
export declare const SWITCHBOARD_KINDS: readonly ["session", "state", "frame", "phase", "player"];
|
|
6
|
+
export type SwitchboardKind = (typeof SWITCHBOARD_KINDS)[number];
|
|
7
|
+
export declare function switchboardSessionPath(sessionId: number, limit: number, kind?: SwitchboardKind): string;
|
|
8
|
+
export declare function newestSwitchboardSessionIds(list: unknown): number[];
|
|
9
|
+
export declare function switchboardPageEvents(session: unknown): Record<string, unknown>[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// The switchboard replay's device-side shape, shared by the dashboard's /backfill route and the
|
|
2
|
+
// MCP's spool backfill so the two pick the same sessions and build the same paths. Pure: no I/O.
|
|
3
|
+
//
|
|
4
|
+
// The device keeps switchboard two levels deep: `GET /api/switchboard` lists session summaries
|
|
5
|
+
// (`{sessions: [...]}`, newest first), `GET /api/switchboard/<session_id>?limit=N` is one session's
|
|
6
|
+
// summary plus `events`, the newest N records oldest first (the device pages at 50 when the query
|
|
7
|
+
// is absent, so the limit is forwarded per session or a talkative session replays as its last few
|
|
8
|
+
// seconds).
|
|
9
|
+
export const SWITCHBOARD_KIND = "switchboard";
|
|
10
|
+
// Sessions replayed per backfill. Bounds the round trips (one list plus one fetch per session).
|
|
11
|
+
export const SWITCHBOARD_BACKFILL_SESSIONS = 3;
|
|
12
|
+
// The replay is two waves (list, then the sessions), so on its own it could hold a caller for two
|
|
13
|
+
// device timeouts. Both the dashboard's /backfill and the MCP's spool backfill race it against this
|
|
14
|
+
// deadline and answer with the sessions that had landed. The default matches the ring kinds' device
|
|
15
|
+
// timeout; the env var is there so a suite holding a fake device socket does not wait it out.
|
|
16
|
+
export const SWITCHBOARD_BACKFILL_DEADLINE_MS = Number(process.env.SLACK_RADAR_SWITCHBOARD_BACKFILL_DEADLINE_MS) || 4000;
|
|
17
|
+
export function switchboardListPath() {
|
|
18
|
+
return `/api/${SWITCHBOARD_KIND}`;
|
|
19
|
+
}
|
|
20
|
+
// The record kinds the plugin emits, the closed set a `kind` query may name. Shared so the path
|
|
21
|
+
// builder below takes the type and never sees raw input.
|
|
22
|
+
export const SWITCHBOARD_KINDS = ["session", "state", "frame", "phase", "player"];
|
|
23
|
+
export function switchboardSessionPath(sessionId, limit, kind) {
|
|
24
|
+
return `/api/${SWITCHBOARD_KIND}/${sessionId}?limit=${limit}${kind ? `&kind=${kind}` : ""}`;
|
|
25
|
+
}
|
|
26
|
+
// The session ids to replay from a list response: newest first by the session's own start time,
|
|
27
|
+
// the id breaking a tie (minted in order), then the first SWITCHBOARD_BACKFILL_SESSIONS. The
|
|
28
|
+
// list's order is the device's to choose, so the pick does not lean on it, and the id alone is
|
|
29
|
+
// not the key: the counter restarts with the app process, so a restarted id 1 can be the newest
|
|
30
|
+
// session. A session id goes into a path, so only a non-negative safe integer counts as one (7.5,
|
|
31
|
+
// -1 and 1e21 are not ids the device minted). Anything else yields [].
|
|
32
|
+
export function newestSwitchboardSessionIds(list) {
|
|
33
|
+
const sessions = Array.isArray(list?.sessions)
|
|
34
|
+
? list.sessions
|
|
35
|
+
: [];
|
|
36
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : null);
|
|
37
|
+
const id = (v) => (typeof v === "number" && Number.isSafeInteger(v) && v >= 0 ? v : null);
|
|
38
|
+
return sessions
|
|
39
|
+
.map((s) => {
|
|
40
|
+
const row = (s !== null && typeof s === "object" ? s : {});
|
|
41
|
+
return { id: id(row.session_id), began: num(row.began_at) ?? 0 };
|
|
42
|
+
})
|
|
43
|
+
.filter((s) => s.id !== null)
|
|
44
|
+
.sort((a, b) => b.began - a.began || b.id - a.id)
|
|
45
|
+
.map((s) => s.id)
|
|
46
|
+
.slice(0, SWITCHBOARD_BACKFILL_SESSIONS);
|
|
47
|
+
}
|
|
48
|
+
// The `events` page of a session response, only its object rows. Anything else yields [].
|
|
49
|
+
export function switchboardPageEvents(session) {
|
|
50
|
+
const events = session?.events;
|
|
51
|
+
if (!Array.isArray(events))
|
|
52
|
+
return [];
|
|
53
|
+
return events.filter((e) => e !== null && typeof e === "object");
|
|
54
|
+
}
|
package/dist/shared/wire.d.ts
CHANGED
|
@@ -22,3 +22,35 @@ export type EnableRefusal = "self_arm_blocked" | "device_changed";
|
|
|
22
22
|
* from the earlier reason. A frame with NO reason says nothing about the diagnosis.
|
|
23
23
|
*/
|
|
24
24
|
export type StatusReason = "no_session" | "undiagnosed";
|
|
25
|
+
/**
|
|
26
|
+
* The Switchboard plugin's session summary, as `GET /api/switchboard` lists it (`{sessions:
|
|
27
|
+
* [...]}`, newest first) and as the envelope of `GET /api/switchboard/<session_id>`, which adds
|
|
28
|
+
* `events: [...]` (the page of records, newest `limit` oldest first). Every record carries an `id`
|
|
29
|
+
* the plugin mints: strictly increasing across sessions, never repeated within a process, reset
|
|
30
|
+
* with it. `total_captured` is the records the plugin still holds for the session; `events` is
|
|
31
|
+
* only ever the page, the count is `total_captured`. `levels` is the newest audio level tick, null
|
|
32
|
+
* before the first one.
|
|
33
|
+
*/
|
|
34
|
+
export interface SwitchboardLevels {
|
|
35
|
+
timestamp: number;
|
|
36
|
+
mic_rms: number;
|
|
37
|
+
mic_peak: number;
|
|
38
|
+
playback_rms: number;
|
|
39
|
+
playback_peak: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SwitchboardSessionSummary {
|
|
42
|
+
session_id: number;
|
|
43
|
+
team_id: string | null;
|
|
44
|
+
began_at: number;
|
|
45
|
+
ended_at: number | null;
|
|
46
|
+
last_state?: Record<string, unknown> | null;
|
|
47
|
+
frames: {
|
|
48
|
+
incoming: number;
|
|
49
|
+
outgoing: number;
|
|
50
|
+
};
|
|
51
|
+
total_captured: number;
|
|
52
|
+
levels: SwitchboardLevels | null;
|
|
53
|
+
}
|
|
54
|
+
export interface SwitchboardSessionDetail extends SwitchboardSessionSummary {
|
|
55
|
+
events: Record<string, unknown>[];
|
|
56
|
+
}
|
|
@@ -1,9 +1,45 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Where a stable, version-free name for a node interpreter could live. Homebrew keeps one at
|
|
4
|
+
* `<prefix>/bin/node` (`/opt/homebrew` on Apple silicon, `/usr/local` on Intel) pointing into the
|
|
5
|
+
* versioned Cellar directory, plus a `<prefix>/opt/...` name per keg-only formula. HOMEBREW_PREFIX
|
|
6
|
+
* covers a custom prefix when the install runs from a brew-aware shell.
|
|
7
|
+
*
|
|
8
|
+
* Only used to find a stable NAME for the interpreter that is already running this install, never to
|
|
9
|
+
* pick a different one: stableNodePath substitutes a candidate only when realpath proves it is the
|
|
10
|
+
* same binary. Order therefore does not decide anything here.
|
|
11
|
+
*/
|
|
12
|
+
export declare function stableNodeCandidates(env?: NodeJS.ProcessEnv): string[];
|
|
13
|
+
/**
|
|
14
|
+
* A stable path for the node running this install, for baking into the app.
|
|
15
|
+
*
|
|
16
|
+
* WHY NOT process.execPath DIRECTLY. execPath reports the interpreter with symlinks resolved, so a
|
|
17
|
+
* Homebrew node comes back as `/opt/homebrew/Cellar/node/26.8.1/bin/node`. The next `brew upgrade
|
|
18
|
+
* node` deletes that directory, and an app holding it can no longer start the dashboard -- nor
|
|
19
|
+
* repair itself, because the self-heal check runs under the same dead interpreter -- so the window
|
|
20
|
+
* shows its failure page on every launch until someone re-runs install-app by hand.
|
|
21
|
+
* `/opt/homebrew/bin/node` names the same binary today and the upgraded one after that.
|
|
22
|
+
*
|
|
23
|
+
* The trade this makes: `brew unlink node`, or pinning to a keg-only formula later, invalidates the
|
|
24
|
+
* symlink in a case where the versioned Cellar path would still have worked. Worth it, since an
|
|
25
|
+
* upgrade is far more common than an unlink and the failure page now names the exact repair either
|
|
26
|
+
* way, but it is a new way to end up on that page.
|
|
27
|
+
*
|
|
28
|
+
* Substitutes ONLY when a candidate resolves to the exact same executable, so this never bakes in a
|
|
29
|
+
* different node than the one that ran the install: an nvm or system interpreter keeps its own path
|
|
30
|
+
* because no candidate points at it. When nothing matches, the answer is execPath, unchanged.
|
|
31
|
+
*
|
|
32
|
+
* Exported for testing.
|
|
33
|
+
*/
|
|
34
|
+
export declare function stableNodePath(execPath?: string, candidates?: string[]): string;
|
|
2
35
|
/**
|
|
3
36
|
* Resolve npx's absolute path, same reasoning as the baked-in node path: a Finder-launched dock
|
|
4
37
|
* app gets a minimal PATH with no shell config, so a bare `npx` would not resolve. npm ships npx
|
|
5
38
|
* alongside node in most installs, so check there first; `which` covers the rest. Returns null
|
|
6
39
|
* (never throws) so a machine with no npx just does not get the self-heal capability.
|
|
40
|
+
*
|
|
41
|
+
* Looks alongside the STABLE node path rather than execPath for the same upgrade reason: the npx next
|
|
42
|
+
* to a Cellar interpreter disappears with it.
|
|
7
43
|
*/
|
|
8
44
|
export declare function resolveNpxPath(): string | null;
|
|
9
45
|
/**
|
|
@@ -26,7 +62,33 @@ export declare function launcherScript(nodeBin: string, webBin: string, port: nu
|
|
|
26
62
|
* Exported like launcherScript, for the same reason: a test can assert on the generated text
|
|
27
63
|
* without touching ~/Applications.
|
|
28
64
|
*/
|
|
29
|
-
export declare function swiftInstallConfig(radarUrl: string, node: string, webBin: string,
|
|
65
|
+
export declare function swiftInstallConfig(radarUrl: string, node: string, webBin: string, mcpBin: string): string;
|
|
66
|
+
/** The values install-app bakes into the app, resolved once so the substitution stays pure. */
|
|
67
|
+
export interface InstallConfigValues {
|
|
68
|
+
node: string;
|
|
69
|
+
webBin: string;
|
|
70
|
+
mcpBin: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Everything the app needs to know about THIS machine.
|
|
74
|
+
*
|
|
75
|
+
* Takes the same overrides stableNodePath() does, for one reason: without them, a test can only assert
|
|
76
|
+
* against whatever the host happens to be, and on a machine with no version-free name for its node
|
|
77
|
+
* (a Linux CI box) the two sides of that assertion converge and the check passes against code that
|
|
78
|
+
* bakes execPath. With them, a synthetic Homebrew layout proves the wiring anywhere.
|
|
79
|
+
*/
|
|
80
|
+
export declare function installConfigValues(execPath?: string, candidates?: string[]): InstallConfigValues;
|
|
81
|
+
/**
|
|
82
|
+
* RadarApp.swift with its install-config block replaced by this machine's real values. Returns null
|
|
83
|
+
* when the markers no longer match, which must never compile: an app built from the file's own
|
|
84
|
+
* defaults would point at nothing useful.
|
|
85
|
+
*
|
|
86
|
+
* Separate from buildSwiftApp so the values that reach the app can be asserted without a Swift
|
|
87
|
+
* toolchain, which is the only way a Linux CI box can see this wiring at all. Takes those values
|
|
88
|
+
* rather than resolving them, so it stays a pure text substitution: a caller (or a test) can hand it
|
|
89
|
+
* a synthetic machine layout, and nothing here executes an interpreter.
|
|
90
|
+
*/
|
|
91
|
+
export declare function patchedSwiftSource(source: string, values: InstallConfigValues): string | null;
|
|
30
92
|
/**
|
|
31
93
|
* Create (or replace) the launcher app. Returns its path.
|
|
32
94
|
*
|
|
@@ -39,6 +101,7 @@ export declare function swiftInstallConfig(radarUrl: string, node: string, webBi
|
|
|
39
101
|
export declare function installMacApp(): {
|
|
40
102
|
app: string;
|
|
41
103
|
native: boolean;
|
|
104
|
+
node: string;
|
|
42
105
|
};
|
|
43
106
|
/** Entry point for the `install-app` subcommand. Prints what to do next, then reveals the app. */
|
|
44
107
|
export declare function runInstallApp(): void;
|