@crvouga/mockingbird-service-aha 1.8.0 → 2.0.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.
@@ -110,13 +110,31 @@ var Collection = class {
110
110
  };
111
111
 
112
112
  // ../core/dist/control.js
113
- var HEALTH_PATH = "/health";
114
113
  var ADMIN_PREFIX = "/__admin";
114
+ var resolveAdminPrefix = (prefix = ADMIN_PREFIX) => {
115
+ if (!/^\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/.test(prefix)) {
116
+ throw new Error("adminPrefix must be an absolute non-root path of literal segments, without a trailing slash");
117
+ }
118
+ return prefix;
119
+ };
120
+ var isAdminPath = (path, prefix) => path === prefix || path.startsWith(`${prefix}/`);
121
+ var matchNamespacePath = (path, prefix) => /^\/ns\/([^/]+)(\/.*)?$/.exec(isAdminPath(path, prefix) ? path.slice(prefix.length) : "");
122
+ var assertAdminPrefixAvailable = (prefix, paths) => {
123
+ const reserved = prefix.split("/").slice(1);
124
+ for (const path of paths) {
125
+ const segments = path.split("/").slice(1);
126
+ if (segments.length < reserved.length || /^\{[^}]+\}$/.test(segments[0] ?? ""))
127
+ continue;
128
+ if (reserved.every((part, i) => segments[i] === part || /^\{[^}]+\}$/.test(segments[i] ?? ""))) {
129
+ throw new Error(`vendor route ${path} collides with adminPrefix ${prefix}; choose a different adminPrefix`);
130
+ }
131
+ }
132
+ };
115
133
  var ADMIN_KEY_HEADER = "x-mockingbird-admin-key";
116
134
  var NAMESPACE_HEADER = "x-mockingbird-namespace";
117
135
  var json = (status, body) => new Response(JSON.stringify(body), {
118
136
  status,
119
- headers: { "content-type": "application/json" }
137
+ headers: { "content-type": "application/json; charset=utf-8" }
120
138
  });
121
139
  var adminError = (status, message) => json(status, { error: { type: "mockingbird_admin", message } });
122
140
  var UNITS = {
@@ -168,11 +186,25 @@ var readJson = async (request) => {
168
186
  };
169
187
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
170
188
  var createControlPlane = (context) => {
189
+ const adminPrefix = resolveAdminPrefix(context.adminPrefix);
171
190
  const snapshots = /* @__PURE__ */ new Map();
172
191
  let snapshotCounter = 0;
173
192
  const headerNamespace = (request) => request.headers.get(NAMESPACE_HEADER) ?? context.defaultNamespace;
174
193
  const adminNamespace = (request, url) => url.searchParams.get("namespace") ?? headerNamespace(request);
194
+ const health = () => {
195
+ return json(200, {
196
+ ...context.describe(),
197
+ status: "ok",
198
+ service: context.name,
199
+ uptimeMs: context.wallNow() - context.startedAt,
200
+ clock: context.clock.state(),
201
+ namespaces: context.namespaces().length,
202
+ adminPrefix,
203
+ adminUi: `${adminPrefix}/ui`
204
+ });
205
+ };
175
206
  const builtin = {
207
+ "GET /health": health,
176
208
  "GET /": () => json(200, {
177
209
  service: context.name,
178
210
  routes: [...Object.keys(builtin), ...Object.keys(context.routes)].sort()
@@ -339,7 +371,14 @@ var createControlPlane = (context) => {
339
371
  return json(200, { status: "ok" });
340
372
  }
341
373
  };
342
- const routes = [...Object.entries(context.routes), ...Object.entries(builtin)].map(([key2, handler]) => {
374
+ for (const key2 of Object.keys(context.routes)) {
375
+ if (Object.hasOwn(builtin, key2))
376
+ throw new Error(`admin route ${key2} overrides a shared route`);
377
+ const path = key2.slice(key2.indexOf(" ") + 1);
378
+ if (isAdminPath(path, "/ns") || isAdminPath(path, "/blobs"))
379
+ throw new Error(`admin route ${key2} overlaps an internal transport`);
380
+ }
381
+ const routes = [...Object.entries(builtin), ...Object.entries(context.routes)].map(([key2, handler]) => {
343
382
  const space = key2.indexOf(" ");
344
383
  return { method: key2.slice(0, space), pattern: key2.slice(space + 1), handler };
345
384
  });
@@ -347,21 +386,13 @@ var createControlPlane = (context) => {
347
386
  namespaceOf: headerNamespace,
348
387
  async handle(request) {
349
388
  const url = new URL(request.url);
350
- if (url.pathname === HEALTH_PATH && request.method === "GET") {
351
- return json(200, {
352
- status: "ok",
353
- service: context.name,
354
- uptimeMs: context.wallNow() - context.startedAt,
355
- clock: context.clock.state(),
356
- namespaces: context.namespaces().length,
357
- adminUi: `${ADMIN_PREFIX}/ui`,
358
- ...context.describe()
359
- });
389
+ if (url.pathname === `${adminPrefix}/health` && request.method === "GET") {
390
+ return health();
360
391
  }
361
- if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
392
+ if (!isAdminPath(url.pathname, adminPrefix)) {
362
393
  return void 0;
363
394
  }
364
- const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
395
+ const path = url.pathname.slice(adminPrefix.length) || "/";
365
396
  const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
366
397
  if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
367
398
  return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
@@ -369,7 +400,12 @@ var createControlPlane = (context) => {
369
400
  for (const route of routes) {
370
401
  if (route.method !== request.method)
371
402
  continue;
372
- const params = matchRoute(route.pattern, path);
403
+ let params;
404
+ try {
405
+ params = matchRoute(route.pattern, path);
406
+ } catch {
407
+ return adminError(400, "invalid path encoding");
408
+ }
373
409
  if (!params)
374
410
  continue;
375
411
  let body;
@@ -378,15 +414,18 @@ var createControlPlane = (context) => {
378
414
  } catch {
379
415
  return adminError(400, "request body is not valid JSON");
380
416
  }
417
+ const namespace = adminNamespace(request, url);
418
+ if (!/^[A-Za-z0-9_.-]{1,64}$/.test(namespace))
419
+ return adminError(400, "invalid namespace");
381
420
  return route.handler({
382
421
  request,
383
422
  url,
384
423
  params,
385
- namespace: adminNamespace(request, url),
424
+ namespace,
386
425
  body
387
426
  });
388
427
  }
389
- return adminError(404, `no admin route ${request.method} ${path}; GET ${ADMIN_PREFIX} lists them`);
428
+ return adminError(404, `no admin route ${request.method} ${path}; GET ${adminPrefix} lists them`);
390
429
  }
391
430
  };
392
431
  };
@@ -1817,6 +1856,34 @@ dialog:not([open]) {
1817
1856
  function isRecord2(value) {
1818
1857
  return typeof value === "object" && value !== null && !Array.isArray(value);
1819
1858
  }
1859
+ function highlightJsonText(text) {
1860
+ const escapeToken = (value) => value.replace(/[&<>"']/g, (char) => {
1861
+ switch (char) {
1862
+ case "&":
1863
+ return "&amp;";
1864
+ case "<":
1865
+ return "&lt;";
1866
+ case ">":
1867
+ return "&gt;";
1868
+ case '"':
1869
+ return "&quot;";
1870
+ default:
1871
+ return "&#39;";
1872
+ }
1873
+ });
1874
+ const token = /("(?:\\u[\da-fA-F]{4}|\\[^u]|[^\\"])*"\s*:|"(?:\\u[\da-fA-F]{4}|\\[^u]|[^\\"])*"|\b(?:true|false)\b|\bnull\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g;
1875
+ let cursor = 0;
1876
+ let html = "";
1877
+ for (const match of text.matchAll(token)) {
1878
+ const index = match.index ?? 0;
1879
+ const value = match[0];
1880
+ html += escapeToken(text.slice(cursor, index));
1881
+ const kind = value.startsWith('"') ? value.trimEnd().endsWith(":") ? "key" : "string" : value === "true" || value === "false" ? "boolean" : value === "null" ? "null" : "number";
1882
+ html += `<span class="json-${kind}">${escapeToken(value)}</span>`;
1883
+ cursor = index + value.length;
1884
+ }
1885
+ return html + escapeToken(text.slice(cursor));
1886
+ }
1820
1887
  function mountAdminBrand(doc, host, service, catalog) {
1821
1888
  const clip = (value, max) => {
1822
1889
  if (typeof value !== "string")
@@ -2178,14 +2245,16 @@ function bootAdmin(config) {
2178
2245
  const state = {
2179
2246
  namespace: "default",
2180
2247
  key: sessionStorage.getItem("mockingbird-admin-key") || "",
2181
- view: "overview",
2248
+ view: ["overview", "state", "clock", "faults", "journal", "routes"].includes(location.hash.slice(1)) ? location.hash.slice(1) : "overview",
2182
2249
  collection: "",
2183
2250
  shape: null,
2184
2251
  route: null,
2252
+ routes: [],
2185
2253
  editing: null
2186
2254
  };
2187
2255
  const standard = new Set(config.standardRoutes);
2188
2256
  const banner = el("banner", HTMLElement);
2257
+ const bannerMessage = el("banner-message", HTMLElement);
2189
2258
  const keyInput = el("admin-key", HTMLInputElement);
2190
2259
  keyInput.value = state.key;
2191
2260
  const params = new URLSearchParams(location.search);
@@ -2196,18 +2265,21 @@ function bootAdmin(config) {
2196
2265
  sessionStorage.setItem("mockingbird-admin-key", state.key);
2197
2266
  params.delete("key");
2198
2267
  const next = params.toString();
2199
- history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
2268
+ history.replaceState(null, "", location.pathname + (next ? `?${next}` : "") + location.hash);
2200
2269
  }
2201
2270
  const queryNamespace = params.get("namespace");
2202
2271
  if (queryNamespace)
2203
2272
  state.namespace = queryNamespace;
2204
2273
  const showError = (error2) => {
2205
- banner.textContent = error2 instanceof Error ? error2.message : String(error2);
2274
+ bannerMessage.textContent = error2 instanceof Error ? error2.message : String(error2);
2206
2275
  banner.classList.add("show");
2276
+ banner.scrollIntoView({ behavior: "smooth", block: "nearest" });
2207
2277
  };
2208
2278
  const clearError = () => {
2209
2279
  banner.classList.remove("show");
2280
+ bannerMessage.textContent = "";
2210
2281
  };
2282
+ el("banner-dismiss", HTMLButtonElement).addEventListener("click", clearError);
2211
2283
  const api = async (method, path, body) => {
2212
2284
  const headers = { accept: "application/json" };
2213
2285
  if (state.key !== "")
@@ -2251,16 +2323,21 @@ function bootAdmin(config) {
2251
2323
  namespace: () => state.namespace
2252
2324
  };
2253
2325
  const isPanelScript = (value) => typeof value === "function";
2326
+ const themeButton = el("theme", HTMLButtonElement);
2254
2327
  const setTheme = (theme) => {
2255
2328
  if (theme)
2256
2329
  document.documentElement.dataset.theme = theme;
2257
2330
  else
2258
2331
  delete document.documentElement.dataset.theme;
2332
+ const dark = theme ? theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2333
+ themeButton.innerHTML = dark ? '<svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><circle cx="10" cy="10" r="3.2" stroke="currentColor" stroke-width="1.5"/><path d="M10 2v1.5M10 16.5V18M18 10h-1.5M3.5 10H2M15.7 4.3l-1 1M5.3 14.7l-1 1M15.7 15.7l-1-1M5.3 5.3l-1-1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>' : '<svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M16.8 12.2A7 7 0 0 1 7.8 3.2a7 7 0 1 0 9 9Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>';
2334
+ const label = dark ? "Use light theme" : "Use dark theme";
2335
+ themeButton.setAttribute("aria-label", label);
2336
+ themeButton.title = label;
2259
2337
  };
2260
2338
  const storedTheme = localStorage.getItem("mockingbird-admin-theme");
2261
- if (storedTheme)
2262
- setTheme(storedTheme);
2263
- el("theme", HTMLButtonElement).addEventListener("click", () => {
2339
+ setTheme(storedTheme === "dark" || storedTheme === "light" ? storedTheme : null);
2340
+ themeButton.addEventListener("click", () => {
2264
2341
  const current = document.documentElement.dataset.theme;
2265
2342
  const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2266
2343
  const next = dark ? "light" : "dark";
@@ -2279,6 +2356,7 @@ function bootAdmin(config) {
2279
2356
  continue;
2280
2357
  section.hidden = section.id !== `view-${view}`;
2281
2358
  }
2359
+ history.replaceState(null, "", `${location.pathname}${location.search}#${encodeURIComponent(view)}`);
2282
2360
  };
2283
2361
  el("nav", HTMLElement).addEventListener("click", (event) => {
2284
2362
  const target = event.target;
@@ -2293,7 +2371,7 @@ function bootAdmin(config) {
2293
2371
  show(view);
2294
2372
  refresh().catch(showError);
2295
2373
  });
2296
- const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
2374
+ const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card stat-card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
2297
2375
  const table = (columns, rows) => {
2298
2376
  if (rows.length === 0)
2299
2377
  return '<p class="empty">Nothing here yet.</p>';
@@ -2303,16 +2381,22 @@ function bootAdmin(config) {
2303
2381
  const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
2304
2382
  return `<tr${attrs}>${cells}</tr>`;
2305
2383
  }).join("");
2306
- return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
2384
+ return `<div class="table-shell"><table><thead>${head}</thead><tbody>${body}</tbody></table></div>`;
2307
2385
  };
2308
2386
  const preview = (value) => {
2309
2387
  const text = JSON.stringify(value) ?? "null";
2310
- return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
2388
+ const clipped = text.length > 180 ? `${text.slice(0, 180)}\u2026` : text;
2389
+ return `<code class="json-inline">${highlightJsonText(clipped)}</code>`;
2311
2390
  };
2312
2391
  const when = (epoch) => {
2313
2392
  const date = new Date(epoch);
2314
2393
  return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
2315
2394
  };
2395
+ const journalWhen = (value) => {
2396
+ const numeric = value.trim() === "" ? Number.NaN : Number(value);
2397
+ const epoch = Number.isFinite(numeric) ? numeric : Date.parse(value);
2398
+ return Number.isFinite(epoch) ? when(epoch) : value;
2399
+ };
2316
2400
  const clockCard = (epoch) => {
2317
2401
  const date = new Date(epoch);
2318
2402
  if (Number.isNaN(date.getTime()))
@@ -2432,7 +2516,7 @@ function bootAdmin(config) {
2432
2516
  };
2433
2517
  const renderOverview = async () => {
2434
2518
  const [health, shape, clock, journal] = await Promise.all([
2435
- originGet("/health"),
2519
+ originGet(`${config.adminPrefix}/health`),
2436
2520
  api("GET", "/state"),
2437
2521
  api("GET", "/clock"),
2438
2522
  api("GET", "/requests?limit=8")
@@ -2449,7 +2533,7 @@ function bootAdmin(config) {
2449
2533
  },
2450
2534
  {
2451
2535
  k: "Status",
2452
- v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
2536
+ v: `<span class="badge ok">${esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")}</span>`
2453
2537
  },
2454
2538
  { k: "Namespace", v: esc(state.namespace) },
2455
2539
  { k: "Collections", v: String(decoded.collections.length) },
@@ -2536,26 +2620,46 @@ function bootAdmin(config) {
2536
2620
  const renderJournal = async () => {
2537
2621
  const journal = await api("GET", "/requests?limit=100");
2538
2622
  el("journal", HTMLElement).innerHTML = table([
2539
- { label: "When", cell: (row) => esc(row.at) },
2540
- { label: "Method", cell: (row) => esc(row.method) },
2623
+ { label: "When", cell: (row) => esc(journalWhen(row.at)) },
2624
+ {
2625
+ label: "Method",
2626
+ cell: (row) => `<span class="method">${esc(row.method)}</span>`
2627
+ },
2541
2628
  { label: "Path", cell: (row) => esc(row.path) },
2542
- { label: "Status", cell: (row) => esc(row.status) },
2629
+ {
2630
+ label: "Status",
2631
+ cell: (row) => `<span class="badge ${row.status.startsWith("2") ? "ok" : row.status.startsWith("4") || row.status.startsWith("5") ? "warn" : ""}">${esc(row.status)}</span>`
2632
+ },
2543
2633
  { label: "ms", cell: (row) => esc(row.durationMs) }
2544
2634
  ], decodeJournal(journal));
2545
2635
  };
2546
- const renderRoutes = async () => {
2547
- const data = await api("GET", "/");
2548
- if (!isRecord2(data))
2549
- throw new Error("Route list was not an object");
2550
- const routes = requireList(data.routes, "Routes").map((route) => String(route));
2636
+ const paintRoutes = () => {
2637
+ const query = el("route-search", HTMLInputElement).value.trim().toLocaleLowerCase();
2638
+ const routes = state.routes.filter((route) => route.toLocaleLowerCase().includes(query));
2639
+ el("route-count", HTMLElement).textContent = `${routes.length} of ${state.routes.length}`;
2640
+ if (state.routes.length === 0) {
2641
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No admin routes are available.</p>';
2642
+ return;
2643
+ }
2644
+ if (routes.length === 0) {
2645
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No routes match this filter.</p>';
2646
+ return;
2647
+ }
2551
2648
  el("route-list", HTMLElement).innerHTML = routes.map((route) => {
2552
2649
  const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
2553
2650
  const parts = route.split(" ");
2554
2651
  const method = parts[0] ?? "";
2555
2652
  const path = parts.slice(1).join(" ");
2556
- return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}">Use</button></div>`;
2653
+ return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}" aria-label="Use ${esc(route)}">Use</button></div>`;
2557
2654
  }).join("");
2558
2655
  };
2656
+ const renderRoutes = async () => {
2657
+ const data = await api("GET", "/");
2658
+ if (!isRecord2(data))
2659
+ throw new Error("Route list was not an object");
2660
+ state.routes = requireList(data.routes, "Routes").map((route) => String(route));
2661
+ paintRoutes();
2662
+ };
2559
2663
  const renderers = {
2560
2664
  overview: renderOverview,
2561
2665
  state: renderState,
@@ -2564,19 +2668,50 @@ function bootAdmin(config) {
2564
2668
  journal: renderJournal,
2565
2669
  routes: renderRoutes
2566
2670
  };
2671
+ let refreshToken = 0;
2567
2672
  async function refresh() {
2673
+ const token = ++refreshToken;
2568
2674
  clearError();
2675
+ const main = el("views", HTMLElement);
2676
+ const sync = el("sync-status", HTMLElement);
2677
+ main.setAttribute("aria-busy", "true");
2678
+ sync.classList.add("busy");
2679
+ sync.textContent = "Updating";
2569
2680
  const render = renderers[state.view];
2570
- if (render)
2571
- await render();
2681
+ try {
2682
+ if (render)
2683
+ await render();
2684
+ if (token === refreshToken)
2685
+ sync.textContent = "Up to date";
2686
+ } finally {
2687
+ if (token === refreshToken) {
2688
+ main.removeAttribute("aria-busy");
2689
+ sync.classList.remove("busy");
2690
+ }
2691
+ }
2572
2692
  }
2573
2693
  const delay = (ms) => new Promise((resolve) => {
2574
2694
  window.setTimeout(resolve, ms);
2575
2695
  });
2576
- const confirmAction = async (button, pending, done, work) => {
2696
+ const confirmAction = async (button, pending, done, work, confirmLabel) => {
2577
2697
  if (button.dataset.pending === "1")
2578
2698
  return;
2579
2699
  const label = button.textContent ?? "";
2700
+ if (confirmLabel !== void 0 && button.dataset.confirming !== "1") {
2701
+ button.dataset.confirming = "1";
2702
+ button.classList.add("confirming");
2703
+ button.textContent = confirmLabel;
2704
+ window.setTimeout(() => {
2705
+ if (button.dataset.confirming !== "1")
2706
+ return;
2707
+ button.textContent = label;
2708
+ button.classList.remove("confirming");
2709
+ delete button.dataset.confirming;
2710
+ }, 3e3);
2711
+ return;
2712
+ }
2713
+ button.classList.remove("confirming");
2714
+ delete button.dataset.confirming;
2580
2715
  const width = button.offsetWidth;
2581
2716
  button.dataset.pending = "1";
2582
2717
  button.classList.add("pressed");
@@ -2597,6 +2732,65 @@ function bootAdmin(config) {
2597
2732
  delete button.dataset.pending;
2598
2733
  }
2599
2734
  };
2735
+ const wireJsonEditor = (textareaId, highlightId, statusId, shellId, allowEmpty) => {
2736
+ const textarea = el(textareaId, HTMLTextAreaElement);
2737
+ const highlight = el(highlightId, HTMLElement);
2738
+ const status = el(statusId, HTMLElement);
2739
+ const shell = el(shellId, HTMLElement);
2740
+ const sync = () => {
2741
+ const text = textarea.value;
2742
+ highlight.innerHTML = `${highlightJsonText(text)}
2743
+ `;
2744
+ let valid = true;
2745
+ let message = "Valid JSON";
2746
+ if (allowEmpty && text.trim() === "")
2747
+ message = "No body";
2748
+ else {
2749
+ try {
2750
+ readJson2(text);
2751
+ } catch {
2752
+ valid = false;
2753
+ message = "Invalid JSON";
2754
+ }
2755
+ }
2756
+ shell.classList.toggle("invalid", !valid);
2757
+ status.classList.toggle("invalid", !valid);
2758
+ status.textContent = message;
2759
+ textarea.setAttribute("aria-invalid", valid ? "false" : "true");
2760
+ };
2761
+ const syncScroll = () => {
2762
+ const preview2 = highlight.parentElement;
2763
+ if (!(preview2 instanceof HTMLElement))
2764
+ return;
2765
+ preview2.scrollTop = textarea.scrollTop;
2766
+ preview2.scrollLeft = textarea.scrollLeft;
2767
+ };
2768
+ textarea.addEventListener("input", sync);
2769
+ textarea.addEventListener("scroll", syncScroll);
2770
+ sync();
2771
+ return sync;
2772
+ };
2773
+ const syncRouteEditor = wireJsonEditor("route-body", "route-highlight", "route-json-status", "route-editor", true);
2774
+ const syncRecordEditor = wireJsonEditor("editor-value", "editor-highlight", "editor-json-status", "record-editor", false);
2775
+ for (const button of document.querySelectorAll("[data-format]")) {
2776
+ if (!(button instanceof HTMLButtonElement))
2777
+ continue;
2778
+ button.addEventListener("click", () => {
2779
+ const target = button.dataset.format;
2780
+ if (target === void 0)
2781
+ return;
2782
+ const textarea = document.getElementById(target);
2783
+ if (!(textarea instanceof HTMLTextAreaElement) || textarea.value.trim() === "")
2784
+ return;
2785
+ try {
2786
+ textarea.value = JSON.stringify(readJson2(textarea.value), null, 2) ?? "";
2787
+ textarea.dispatchEvent(new Event("input"));
2788
+ textarea.focus();
2789
+ } catch {
2790
+ showError(new Error("Fix the JSON before formatting it"));
2791
+ }
2792
+ });
2793
+ }
2600
2794
  document.addEventListener("click", (event) => {
2601
2795
  const target = event.target;
2602
2796
  if (!(target instanceof Element))
@@ -2669,6 +2863,7 @@ function bootAdmin(config) {
2669
2863
  } else {
2670
2864
  editorValue.value = "{\n \n}";
2671
2865
  }
2866
+ syncRecordEditor();
2672
2867
  editor.showModal();
2673
2868
  }
2674
2869
  el("new-record", HTMLButtonElement).addEventListener("click", () => {
@@ -2698,10 +2893,10 @@ function bootAdmin(config) {
2698
2893
  const id = state.editing;
2699
2894
  if (!id)
2700
2895
  return;
2701
- api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2896
+ confirmAction(editorDelete, "Deleting...", "Deleted", () => api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2702
2897
  editor.close();
2703
2898
  return renderState();
2704
- }).catch(showError);
2899
+ }), "Confirm delete").catch(showError);
2705
2900
  });
2706
2901
  for (const button of document.querySelectorAll("[data-advance]")) {
2707
2902
  if (!(button instanceof HTMLButtonElement))
@@ -2747,10 +2942,10 @@ function bootAdmin(config) {
2747
2942
  }).then(() => renderFaults()).catch(showError);
2748
2943
  });
2749
2944
  el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
2750
- confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults())).catch(showError);
2945
+ confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults()), "Confirm clear").catch(showError);
2751
2946
  });
2752
2947
  el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
2753
- confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal())).catch(showError);
2948
+ confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal()), "Confirm clear").catch(showError);
2754
2949
  });
2755
2950
  el("route-list", HTMLElement).addEventListener("click", (event) => {
2756
2951
  const target = event.target;
@@ -2764,9 +2959,15 @@ function bootAdmin(config) {
2764
2959
  return;
2765
2960
  state.route = route;
2766
2961
  el("route-title", HTMLElement).textContent = route;
2962
+ el("route-send", HTMLButtonElement).disabled = false;
2767
2963
  const method = route.split(" ")[0] ?? "";
2768
- el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
2964
+ const routeBody = el("route-body", HTMLTextAreaElement);
2965
+ routeBody.disabled = method === "GET" || method === "DELETE";
2966
+ el("route-editor", HTMLElement).hidden = routeBody.disabled;
2967
+ el("route-json-status", HTMLElement).parentElement?.toggleAttribute("hidden", routeBody.disabled);
2968
+ syncRouteEditor();
2769
2969
  });
2970
+ el("route-search", HTMLInputElement).addEventListener("input", paintRoutes);
2770
2971
  el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
2771
2972
  event.preventDefault();
2772
2973
  const send = async () => {
@@ -2788,7 +2989,8 @@ function bootAdmin(config) {
2788
2989
  }
2789
2990
  }
2790
2991
  const data = await api(method, concrete, body);
2791
- el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
2992
+ const text = JSON.stringify(data, null, 2) ?? "null";
2993
+ el("route-result", HTMLElement).innerHTML = `<code>${highlightJsonText(text)}</code>`;
2792
2994
  };
2793
2995
  send().catch(showError);
2794
2996
  });
@@ -2906,11 +3108,13 @@ function bootAdmin(config) {
2906
3108
  views.append(section);
2907
3109
  mountSqlExplorer(body, panelApi);
2908
3110
  }
3111
+ show(document.getElementById(`view-${state.view}`) === null ? "overview" : state.view);
2909
3112
  return refresh();
2910
3113
  }).catch(showError);
2911
3114
  }
2912
3115
  var clientPrelude = [
2913
3116
  isRecord2,
3117
+ highlightJsonText,
2914
3118
  mountAdminBrand,
2915
3119
  startAdminBrand,
2916
3120
  faultPresetList,
@@ -2933,6 +3137,7 @@ ${entry}(${payload});
2933
3137
  var defineMock = (runtime) => runtime;
2934
3138
  var STANDARD_ADMIN_ROUTES = [
2935
3139
  "GET /",
3140
+ "GET /health",
2936
3141
  "POST /reset",
2937
3142
  "GET /namespaces",
2938
3143
  "GET /clock",
@@ -3012,11 +3217,11 @@ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
3012
3217
  }
3013
3218
  });
3014
3219
  var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
3015
- var renderAdminDocument = (service) => {
3220
+ var renderAdminDocument = (service, adminPrefix = ADMIN_PREFIX) => {
3016
3221
  const name = escapeHtml(service);
3017
3222
  const script = adminClientSource({
3018
3223
  standardRoutes: STANDARD_ADMIN_ROUTES,
3019
- adminPrefix: ADMIN_PREFIX,
3224
+ adminPrefix,
3020
3225
  adminKeyHeader: ADMIN_KEY_HEADER,
3021
3226
  brandsUrl: ADMIN_BRANDS_URL,
3022
3227
  service
@@ -3033,75 +3238,99 @@ var renderAdminDocument = (service) => {
3033
3238
  ${CSS_RESET}
3034
3239
  :root {
3035
3240
  color-scheme: light;
3036
- --bg: #fafafa;
3241
+ --bg: #f7f8fb;
3037
3242
  --bg-elev: #ffffff;
3038
- --bg-muted: #f4f4f5;
3039
- --bg-inset: #f4f4f5;
3040
- --line: #dedee3;
3041
- --line-strong: #c4c4cc;
3042
- --ink: #18181b;
3043
- --muted: #62626b;
3044
- --faint: #71717a;
3045
- --accent: #27272a;
3243
+ --bg-muted: #f1f3f7;
3244
+ --bg-inset: #f8f9fc;
3245
+ --line: #e4e7ec;
3246
+ --line-strong: #cfd4dc;
3247
+ --ink: #101828;
3248
+ --muted: #475467;
3249
+ --faint: #667085;
3250
+ --accent: #6941c6;
3251
+ --accent-hover: #5933b4;
3046
3252
  --accent-ink: #ffffff;
3047
- --accent-soft: #f4f4f5;
3048
- --ok: #166534;
3049
- --ok-soft: #f0fdf4;
3050
- --warn: #a16207;
3051
- --warn-soft: #fefce8;
3052
- --err: #a82d32;
3053
- --err-soft: #fef2f2;
3054
- --shadow: none;
3253
+ --accent-soft: #f4f0ff;
3254
+ --ok: #067647;
3255
+ --ok-soft: #ecfdf3;
3256
+ --warn: #b54708;
3257
+ --warn-soft: #fffaeb;
3258
+ --err: #b42318;
3259
+ --err-soft: #fef3f2;
3260
+ --code-key: #6941c6;
3261
+ --code-string: #067647;
3262
+ --code-number: #175cd3;
3263
+ --code-boolean: #c11574;
3264
+ --code-null: #667085;
3265
+ --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
3266
+ --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
3267
+ --shadow-lg: 0 18px 48px rgb(16 24 40 / 0.16), 0 4px 12px rgb(16 24 40 / 0.08);
3055
3268
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
3056
3269
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
3057
- --radius: 10px;
3058
- --header: 56px;
3059
- --nav: 200px;
3270
+ --radius: 12px;
3271
+ --header: 72px;
3272
+ --nav: 224px;
3060
3273
  }
3061
3274
  :root[data-theme="dark"] {
3062
3275
  color-scheme: dark;
3063
- --bg: #111113;
3064
- --bg-elev: #19191c;
3065
- --bg-muted: #242428;
3066
- --bg-inset: #111113;
3067
- --line: #36363c;
3068
- --line-strong: #52525b;
3069
- --ink: #f4f4f5;
3070
- --muted: #a9a9b2;
3071
- --faint: #71717a;
3072
- --accent: #e4e4e7;
3073
- --accent-ink: #18181b;
3074
- --accent-soft: #242428;
3075
- --ok: #86efac;
3076
- --ok-soft: #14241b;
3077
- --warn: #fde68a;
3078
- --warn-soft: #2a2410;
3079
- --err: #ffaaaa;
3080
- --err-soft: #2c1516;
3081
- --shadow: none;
3276
+ --bg: #0c0e14;
3277
+ --bg-elev: #151821;
3278
+ --bg-muted: #20232e;
3279
+ --bg-inset: #11141c;
3280
+ --line: #2b303d;
3281
+ --line-strong: #414858;
3282
+ --ink: #f5f7fa;
3283
+ --muted: #b6bdc9;
3284
+ --faint: #8d96a7;
3285
+ --accent: #9e77ed;
3286
+ --accent-hover: #b692f6;
3287
+ --accent-ink: #ffffff;
3288
+ --accent-soft: #2b2142;
3289
+ --ok: #75e0a7;
3290
+ --ok-soft: #102a20;
3291
+ --warn: #fec84b;
3292
+ --warn-soft: #302611;
3293
+ --err: #fda29b;
3294
+ --err-soft: #321817;
3295
+ --code-key: #c3a6ff;
3296
+ --code-string: #75e0a7;
3297
+ --code-number: #84adff;
3298
+ --code-boolean: #f9a8d4;
3299
+ --code-null: #98a2b3;
3300
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3301
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3302
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3082
3303
  }
3083
3304
  @media (prefers-color-scheme: dark) {
3084
3305
  :root:not([data-theme="light"]) {
3085
3306
  color-scheme: dark;
3086
- --bg: #111113;
3087
- --bg-elev: #19191c;
3088
- --bg-muted: #242428;
3089
- --bg-inset: #111113;
3090
- --line: #36363c;
3091
- --line-strong: #52525b;
3092
- --ink: #f4f4f5;
3093
- --muted: #a9a9b2;
3094
- --faint: #71717a;
3095
- --accent: #e4e4e7;
3096
- --accent-ink: #18181b;
3097
- --accent-soft: #242428;
3098
- --ok: #86efac;
3099
- --ok-soft: #14241b;
3100
- --warn: #fde68a;
3101
- --warn-soft: #2a2410;
3102
- --err: #ffaaaa;
3103
- --err-soft: #2c1516;
3104
- --shadow: none;
3307
+ --bg: #0c0e14;
3308
+ --bg-elev: #151821;
3309
+ --bg-muted: #20232e;
3310
+ --bg-inset: #11141c;
3311
+ --line: #2b303d;
3312
+ --line-strong: #414858;
3313
+ --ink: #f5f7fa;
3314
+ --muted: #b6bdc9;
3315
+ --faint: #8d96a7;
3316
+ --accent: #9e77ed;
3317
+ --accent-hover: #b692f6;
3318
+ --accent-ink: #ffffff;
3319
+ --accent-soft: #2b2142;
3320
+ --ok: #75e0a7;
3321
+ --ok-soft: #102a20;
3322
+ --warn: #fec84b;
3323
+ --warn-soft: #302611;
3324
+ --err: #fda29b;
3325
+ --err-soft: #321817;
3326
+ --code-key: #c3a6ff;
3327
+ --code-string: #75e0a7;
3328
+ --code-number: #84adff;
3329
+ --code-boolean: #f9a8d4;
3330
+ --code-null: #98a2b3;
3331
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3332
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3333
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3105
3334
  }
3106
3335
  }
3107
3336
  /* Fill the viewport, then grow with the content so the background covers the scroll. */
@@ -3119,13 +3348,17 @@ var renderAdminDocument = (service) => {
3119
3348
  padding-right: env(safe-area-inset-right);
3120
3349
  -webkit-text-size-adjust: 100%;
3121
3350
  }
3122
- :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
3351
+ ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
3352
+ :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
3353
+ button, input, select, textarea { transition: border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease; }
3354
+ button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }
3123
3355
  .app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
3124
3356
  header.top {
3125
- position: sticky; top: 0; z-index: 5;
3357
+ position: sticky; top: 0; z-index: 20;
3126
3358
  display: flex; align-items: center; gap: 12px;
3127
- min-height: var(--header); padding: 10px 16px;
3128
- background: var(--bg-elev);
3359
+ min-height: var(--header); padding: 12px 20px;
3360
+ background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
3361
+ backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
3129
3362
  border-bottom: 1px solid var(--line);
3130
3363
  min-width: 0; max-width: 100%;
3131
3364
  }
@@ -3133,12 +3366,21 @@ var renderAdminDocument = (service) => {
3133
3366
  display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
3134
3367
  min-width: 0; max-width: 100%; margin-right: auto;
3135
3368
  }
3136
- .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
3137
- .brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
3369
+ .brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
3370
+ .brand-mark {
3371
+ width: 38px; height: 38px; display: grid; place-items: center; flex: none;
3372
+ border-radius: 11px; color: #fff;
3373
+ background: linear-gradient(145deg, #7f56d9 0%, #53389e 100%);
3374
+ box-shadow: 0 6px 16px rgb(105 65 198 / 0.24), inset 0 1px 0 rgb(255 255 255 / 0.25);
3375
+ }
3376
+ .brand-mark svg { width: 22px; height: 22px; }
3377
+ .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; line-height: 1.25; }
3378
+ .brand-id strong { font-size: 15px; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
3138
3379
  .brand-id span { color: var(--faint); font-size: 12px; }
3139
3380
  .vendor {
3140
3381
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
3141
3382
  min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
3383
+ padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-inset);
3142
3384
  }
3143
3385
  .vendor[hidden] { display: none; }
3144
3386
  /* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
@@ -3150,12 +3392,17 @@ var renderAdminDocument = (service) => {
3150
3392
  .vendor-sep { color: var(--faint); }
3151
3393
  .vendor-link { color: inherit; text-decoration: none; }
3152
3394
  .vendor-link:hover { color: var(--ink); text-decoration: underline; }
3153
- .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
3154
- label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
3395
+ .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
3396
+ .sync-status { align-self: center; display: flex; align-items: center; gap: 6px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3397
+ .sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
3398
+ .sync-status.busy::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
3399
+ label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--faint); }
3155
3400
  label.field input, label.field select, .controls input[type="password"] {
3156
- background-color: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
3157
- padding: 7px 8px; min-height: 36px; line-height: 1.2;
3401
+ background-color: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 9px;
3402
+ padding: 8px 10px; min-height: 38px; line-height: 1.2; box-shadow: var(--shadow-xs);
3158
3403
  }
3404
+ label.field input:hover, label.field select:hover, textarea:hover { border-color: color-mix(in srgb, var(--accent) 38%, var(--line-strong)); }
3405
+ label.field input:focus, label.field select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); outline: none; }
3159
3406
  /* A native menu ignores min-height, so Preset rendered about half as tall as
3160
3407
  the text fields in the same form. Paint it like those fields. */
3161
3408
  label.field select {
@@ -3172,12 +3419,20 @@ var renderAdminDocument = (service) => {
3172
3419
  dialog .field > textarea { width: 100%; }
3173
3420
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger, nav.side button { cursor: pointer; }
3174
3421
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
3175
- border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
3176
- background: var(--bg-elev);
3177
- }
3178
- .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
3179
- .btn-quiet { background: transparent; }
3180
- .btn-danger { color: var(--err); }
3422
+ display: inline-flex; align-items: center; justify-content: center; gap: 7px;
3423
+ border-radius: 9px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line-strong);
3424
+ background: var(--bg-elev); color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1;
3425
+ box-shadow: var(--shadow-xs);
3426
+ }
3427
+ .icon-btn { width: 38px; padding: 0; }
3428
+ .icon-btn svg, .btn svg, .btn-primary svg { width: 16px; height: 16px; }
3429
+ .icon-btn:hover, .btn:hover { background: var(--bg-muted); border-color: var(--line-strong); }
3430
+ .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 1px 2px rgb(16 24 40 / 0.08), 0 0 0 1px rgb(255 255 255 / 0.08) inset; }
3431
+ .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
3432
+ .btn-quiet { background: transparent; border-color: transparent; box-shadow: none; }
3433
+ .btn-quiet:hover { background: var(--bg-muted); }
3434
+ .btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, var(--line)); }
3435
+ .btn-danger:hover, .btn-danger.confirming { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
3181
3436
  /* Held after mouseup. Clearing an empty journal changes nothing on screen,
3182
3437
  so the press itself has to stay visible. */
3183
3438
  .icon-btn:active, .btn:active, .btn-quiet:active, .btn-danger:active, nav.side button:active,
@@ -3193,93 +3448,159 @@ var renderAdminDocument = (service) => {
3193
3448
  flex: 1 0 auto; min-width: 0;
3194
3449
  }
3195
3450
  nav.side {
3196
- border-right: 1px solid var(--line); padding: 12px;
3451
+ position: sticky; top: var(--header); align-self: start; height: calc(100vh - var(--header));
3452
+ border-right: 1px solid var(--line); padding: 18px 12px;
3197
3453
  display: flex; flex-direction: column; gap: 4px;
3198
- background: var(--bg-elev);
3454
+ background: var(--bg-elev); overflow-y: auto;
3199
3455
  }
3456
+ .nav-label { padding: 0 10px 8px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
3200
3457
  nav.side button {
3458
+ position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
3201
3459
  text-align: left; border: 0; background: transparent; border-radius: 9px;
3202
- padding: 9px 10px; min-height: 40px; color: var(--muted);
3203
- }
3204
- nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
3205
- main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
3206
- .view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
3207
- .lede { margin: 0 0 16px; color: var(--muted); }
3208
- .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
3460
+ padding: 9px 10px; min-height: 42px; color: var(--muted); font-size: 13px; font-weight: 550;
3461
+ }
3462
+ nav.side button:hover { background: var(--bg-muted); color: var(--ink); }
3463
+ nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
3464
+ nav.side button[aria-current="true"]::before { content: ""; position: absolute; left: -12px; width: 3px; height: 22px; border-radius: 0 4px 4px 0; background: var(--accent); }
3465
+ .nav-icon { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
3466
+ .nav-icon svg { width: 18px; height: 18px; }
3467
+ main { padding: 32px clamp(20px, 4vw, 48px) 64px; max-width: 1320px; width: 100%; min-width: 0; }
3468
+ main[aria-busy="true"] .view { opacity: 0.62; }
3469
+ .view { animation: view-in 180ms ease-out; }
3470
+ .view[hidden] { display: none; }
3471
+ .view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
3472
+ .view h2 { margin: 0 0 5px; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -0.035em; }
3473
+ .view h3 { margin: 24px 0 10px; font-size: 15px; letter-spacing: -0.01em; }
3474
+ .lede { margin: 0; color: var(--muted); max-width: 72ch; font-size: 14px; }
3475
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 14px; }
3209
3476
  .card {
3210
3477
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
3211
- padding: 14px 16px; box-shadow: var(--shadow);
3478
+ padding: 18px; box-shadow: var(--shadow-sm);
3212
3479
  }
3213
- .card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
3214
- .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
3480
+ .stat-card { position: relative; overflow: hidden; }
3481
+ .stat-card::after { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, var(--accent), transparent 78%); opacity: 0.7; }
3482
+ .card .k { color: var(--faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
3483
+ .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 24px; font-weight: 650; margin-top: 7px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; letter-spacing: -0.025em; }
3215
3484
  .card .v .clock-time { font-size: 14px; color: var(--muted); }
3216
- .split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
3485
+ .section-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: hidden; }
3486
+ .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
3487
+ .section-title h3 { margin: 0; }
3488
+ .split { display: grid; grid-template-columns: minmax(0, 250px) minmax(0, 1fr); gap: 18px; align-items: start; }
3489
+ #collections { padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3217
3490
  .collection {
3218
3491
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
3219
- border-radius: 10px; padding: 8px 10px; min-height: 44px;
3492
+ border-radius: 9px; padding: 10px 11px; min-height: 48px; color: var(--ink); cursor: pointer;
3220
3493
  }
3221
- .collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
3494
+ .collection:hover { background: var(--bg-muted); }
3495
+ .collection[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 18%, var(--line)); color: var(--accent); }
3222
3496
  .collection small { display: block; color: var(--faint); }
3223
3497
  .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
3224
- .chip {
3225
- font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
3226
- border-radius: 999px; padding: 4px 8px;
3227
- }
3498
+ .chip { font-family: var(--mono); font-size: 11px; background: var(--bg-muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; }
3228
3499
  .chip i { color: var(--faint); font-style: normal; }
3229
3500
  .sql-layout {
3230
3501
  display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3231
3502
  }
3232
- .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3233
- .sql-tables button { text-align: left; }
3503
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
3504
+ .sql-tables button { text-align: left; border: 0; border-radius: 8px; padding: 9px 10px; background: transparent; color: var(--muted); cursor: pointer; }
3505
+ .sql-tables button:hover, .sql-tables button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
3234
3506
  .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
3235
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
3236
- th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
3237
- th { color: var(--faint); font-weight: 600; font-size: 12px; }
3507
+ .table-shell { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3508
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
3509
+ th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
3510
+ th { color: var(--faint); background: var(--bg-inset); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: 0.045em; }
3511
+ tbody tr:last-child td { border-bottom: 0; }
3238
3512
  tr.clickable { cursor: pointer; }
3239
- tr.clickable:hover { background: var(--bg-muted); }
3513
+ tr.clickable:hover { background: var(--accent-soft); }
3240
3514
  pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
3241
3515
  pre {
3242
3516
  margin: 0; white-space: pre-wrap; word-break: break-word;
3243
- background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
3244
- }
3245
- .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
3517
+ background: var(--bg-inset); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 12px; line-height: 1.65;
3518
+ }
3519
+ .json-key { color: var(--code-key); }
3520
+ .json-string { color: var(--code-string); }
3521
+ .json-number { color: var(--code-number); }
3522
+ .json-boolean { color: var(--code-boolean); }
3523
+ .json-null { color: var(--code-null); font-style: italic; }
3524
+ .json-inline { display: block; max-width: 44rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
3525
+ .json-view { position: relative; max-height: 26rem; overflow: auto; }
3526
+ .json-editor { position: relative; min-height: 190px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg-inset); overflow: hidden; }
3527
+ .json-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
3528
+ .json-editor.invalid { border-color: var(--err); }
3529
+ .json-editor pre, .json-editor textarea { margin: 0; padding: 12px; border: 0; border-radius: 0; min-height: 190px; width: 100%; font: 12px/1.65 var(--mono); tab-size: 2; white-space: pre; overflow: auto; }
3530
+ .json-editor pre { position: absolute; inset: 0; pointer-events: none; background: transparent; }
3531
+ .json-editor textarea { position: relative; z-index: 1; resize: vertical; background: transparent; color: transparent; caret-color: var(--ink); -webkit-text-fill-color: transparent; }
3532
+ .json-editor textarea::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
3533
+ .editor-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; }
3534
+ .json-status { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 11px; }
3535
+ .json-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
3536
+ .json-status.invalid { color: var(--err); }
3537
+ .format-json { border: 0; padding: 3px 5px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 650; cursor: pointer; }
3538
+ .row-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 14px 0; }
3246
3539
  .banner {
3247
- display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
3248
- background: var(--err-soft); color: var(--err);
3249
- }
3250
- .banner.show { display: block; }
3251
- .empty { color: var(--muted); padding: 24px 8px; }
3540
+ display: none; position: sticky; top: calc(var(--header) + 12px); z-index: 15;
3541
+ align-items: center; gap: 10px; margin: 0 0 16px; padding: 11px 12px 11px 14px;
3542
+ border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line)); border-radius: 10px;
3543
+ background: var(--err-soft); color: var(--err); box-shadow: var(--shadow-sm); font-size: 13px;
3544
+ }
3545
+ .banner.show { display: flex; }
3546
+ .banner span { flex: 1; }
3547
+ .banner button { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: currentColor; cursor: pointer; }
3548
+ .banner button:hover { background: color-mix(in srgb, var(--err) 10%, transparent); }
3549
+ .empty { color: var(--muted); padding: 34px 18px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: color-mix(in srgb, var(--bg-elev) 55%, transparent); }
3252
3550
  dialog {
3253
- border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
3254
- color: var(--ink); width: min(640px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: none;
3255
- }
3256
- dialog::backdrop { background: rgb(20 19 17 / 0.45); }
3257
- dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
3551
+ border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--bg-elev);
3552
+ color: var(--ink); width: min(720px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: var(--shadow-lg);
3553
+ }
3554
+ dialog[open] { animation: dialog-in 160ms ease-out; }
3555
+ dialog::backdrop { background: rgb(12 14 20 / 0.58); backdrop-filter: blur(3px); }
3556
+ dialog form, .dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
3557
+ .dialog-heading { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
3558
+ .dialog-heading strong { font-size: 18px; letter-spacing: -0.02em; }
3559
+ .dialog-heading span { color: var(--muted); font-size: 12px; }
3258
3560
  textarea {
3259
3561
  width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
3260
3562
  border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
3261
3563
  font-family: var(--mono); font-size: 12px;
3262
3564
  }
3263
- .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
3264
- .badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
3565
+ .dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 4px; }
3566
+ .dialog-actions .btn-danger { margin-right: auto; }
3567
+ .badge { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; letter-spacing: 0.03em; border: 1px solid var(--line); border-radius: 999px; padding: 3px 7px; background: var(--bg-muted); color: var(--muted); }
3265
3568
  .badge.ok { background: var(--ok-soft); color: var(--ok); }
3266
3569
  .badge.warn { background: var(--warn-soft); color: var(--warn); }
3267
3570
  .status-2 { color: var(--ok); }
3268
3571
  .status-4, .status-5, .status-0 { color: var(--err); }
3269
3572
  .stack { display: flex; flex-direction: column; gap: 12px; }
3573
+ .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
3574
+ .form-grid .wide { grid-column: span 2; }
3270
3575
  .route {
3271
- display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
3272
- padding: 8px 0; border-bottom: 1px solid var(--line);
3273
- }
3274
- .method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
3576
+ display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 10px; align-items: center;
3577
+ padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-elev);
3578
+ }
3579
+ .route:first-child { border-radius: var(--radius) var(--radius) 0 0; }
3580
+ .route:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
3581
+ .route-tools { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
3582
+ .route-tools .field { flex: 1; }
3583
+ .route-tools input { width: 100%; }
3584
+ .route-count { padding-bottom: 10px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3585
+ #route-list { max-height: 34rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-xs); }
3586
+ .method { width: fit-content; font-family: var(--mono); font-size: 11px; font-weight: 750; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 4px 6px; }
3587
+ @keyframes view-in { from { transform: translateY(3px); } to { transform: translateY(0); } }
3588
+ @keyframes dialog-in { from { transform: translateY(8px) scale(0.99); } to { transform: translateY(0) scale(1); } }
3589
+ @keyframes pulse { 50% { opacity: 0.45; } }
3590
+ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
3591
+ @media (forced-colors: active) { .json-editor pre { display: none; } .json-editor textarea { color: CanvasText; -webkit-text-fill-color: CanvasText; } }
3275
3592
  @media (max-width: 800px) {
3593
+ :root { --header: 0px; }
3276
3594
  header.top {
3277
- align-items: stretch; flex-direction: column;
3278
- padding-top: max(10px, env(safe-area-inset-top));
3595
+ position: relative; align-items: stretch; flex-direction: column;
3596
+ padding: max(12px, env(safe-area-inset-top)) 14px 12px;
3279
3597
  }
3280
3598
  input, select, textarea { font-size: 16px; }
3281
3599
  .brand, .vendor, .controls { width: 100%; }
3600
+ .brand { gap: 10px; }
3601
+ .vendor { order: 2; border-radius: 9px; }
3282
3602
  label.field, label.field select, label.field input { flex: 1; min-width: 0; }
3603
+ .sync-status { display: none; }
3283
3604
  /* The layout fills the screen. A single-column grid stretches every auto
3284
3605
  row, so the tab bar grew with the leftover height and the buttons floated
3285
3606
  in the middle of it. The bar stays one row; the page below takes the rest. */
@@ -3289,14 +3610,23 @@ var renderAdminDocument = (service) => {
3289
3610
  align-content: start;
3290
3611
  }
3291
3612
  nav.side {
3292
- align-self: start; height: auto;
3613
+ position: sticky; top: 0; z-index: 12; align-self: start; height: auto;
3293
3614
  flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
3294
3615
  border-right: 0; border-bottom: 1px solid var(--line);
3295
- padding: 8px;
3616
+ padding: 8px; box-shadow: var(--shadow-xs);
3296
3617
  }
3297
- nav.side button { white-space: nowrap; flex: none; }
3618
+ .nav-label { display: none; }
3619
+ nav.side button { width: auto; white-space: nowrap; flex: none; }
3620
+ nav.side button[aria-current="true"]::before { inset: auto 9px -8px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
3298
3621
  .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3299
- main { padding: 14px; }
3622
+ .form-grid { grid-template-columns: minmax(0, 1fr); }
3623
+ .form-grid .wide { grid-column: auto; }
3624
+ main { padding: 22px 14px 48px; }
3625
+ .view-head { margin-bottom: 18px; }
3626
+ .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
3627
+ .card { padding: 14px; }
3628
+ .card .v { font-size: 20px; }
3629
+ .table-shell { border: 0; background: transparent; box-shadow: none; overflow: visible; }
3300
3630
  table, thead, tbody, tr, th, td { display: block; }
3301
3631
  thead { display: none; }
3302
3632
  tr {
@@ -3311,50 +3641,63 @@ var renderAdminDocument = (service) => {
3311
3641
  .route { grid-template-columns: 72px 1fr; }
3312
3642
  .route button { grid-column: 1 / -1; }
3313
3643
  }
3644
+ @media (max-width: 460px) {
3645
+ .controls label.field { min-width: calc(50% - 4px); }
3646
+ .controls .icon-btn, .controls .btn { flex: 1; }
3647
+ .grid { grid-template-columns: minmax(0, 1fr); }
3648
+ .dialog-actions { flex-wrap: wrap; }
3649
+ .dialog-actions button { flex: 1; }
3650
+ .dialog-actions .btn-danger { flex-basis: 100%; margin-right: 0; }
3651
+ }
3314
3652
  </style>
3315
3653
  </head>
3316
3654
  <body>
3317
3655
  <div class="app" data-service="${name}" data-mockingbird-admin>
3318
3656
  <header class="top">
3319
3657
  <div class="brand">
3320
- <div class="brand-id">
3321
- <strong>${name}</strong>
3322
- <span>Admin</span>
3658
+ <div class="brand-lockup">
3659
+ <div class="brand-mark" aria-hidden="true">
3660
+ <svg viewBox="0 0 24 24" fill="none"><path d="M5 17.5V7l7 5 7-5v10.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/><path d="M8 15.5 12 18l4-2.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
3661
+ </div>
3662
+ <div class="brand-id">
3663
+ <strong>${name}</strong>
3664
+ <span>Mock admin</span>
3665
+ </div>
3323
3666
  </div>
3324
3667
  <div class="vendor" id="vendor" hidden></div>
3325
3668
  </div>
3326
3669
  <div class="controls">
3670
+ <span class="sync-status" id="sync-status" role="status" aria-live="polite">Ready</span>
3327
3671
  <label class="field">Namespace
3328
3672
  <select id="namespace" aria-label="Namespace"></select>
3329
3673
  </label>
3330
3674
  <label class="field">Admin key
3331
3675
  <input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
3332
3676
  </label>
3333
- <button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
3334
- <button class="btn" id="refresh" type="button">Refresh</button>
3677
+ <button class="icon-btn" id="theme" type="button" aria-label="Use dark theme" title="Use dark theme"></button>
3678
+ <button class="btn" id="refresh" type="button"><svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M15.8 7.2A6.2 6.2 0 1 0 16 12" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M12.8 7.2h3v-3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>Refresh</button>
3335
3679
  </div>
3336
3680
  </header>
3337
3681
  <div class="layout">
3338
3682
  <nav class="side" id="nav" aria-label="Admin sections">
3339
- <button type="button" data-view="overview" aria-current="true">Overview</button>
3340
- <button type="button" data-view="state">State</button>
3341
- <button type="button" data-view="clock">Clock</button>
3342
- <button type="button" data-view="faults">Faults</button>
3343
- <button type="button" data-view="journal">Journal</button>
3344
- <button type="button" data-view="routes">Routes</button>
3683
+ <span class="nav-label">Workspace</span>
3684
+ <button type="button" data-view="overview" aria-current="true"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><rect x="2.5" y="2.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="2.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="2.5" y="11.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="11.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/></svg></span>Overview</button>
3685
+ <button type="button" data-view="state"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><ellipse cx="10" cy="5" rx="6.5" ry="2.5" stroke="currentColor" stroke-width="1.5"/><path d="M3.5 5v5c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5V5M3.5 10v5c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5v-5" stroke="currentColor" stroke-width="1.5"/></svg></span>State</button>
3686
+ <button type="button" data-view="clock"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><circle cx="10" cy="10" r="7.5" stroke="currentColor" stroke-width="1.5"/><path d="M10 5.8v4.6l3 1.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>Clock</button>
3687
+ <button type="button" data-view="faults"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="m11.2 2.8-6.5 9h5.1l-1 5.4 6.5-9h-5.1l1-5.4Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></span>Faults</button>
3688
+ <button type="button" data-view="journal"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="M5 3.5h10a1.5 1.5 0 0 1 1.5 1.5v12l-2.2-1.4-2.2 1.4-2.1-1.4L7.8 17l-2.2-1.4L3.5 17V5A1.5 1.5 0 0 1 5 3.5Z" stroke="currentColor" stroke-width="1.5"/><path d="M6.7 7h6.6M6.7 10h6.6M6.7 13h3.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>Journal</button>
3689
+ <button type="button" data-view="routes"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="M6.5 4.5h7a2 2 0 0 1 2 2v7M13 11l2.5 2.5L18 11M13.5 15.5h-7a2 2 0 0 1-2-2v-7M7 9 4.5 6.5 2 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span>Routes</button>
3345
3690
  </nav>
3346
3691
  <main id="views">
3347
- <p class="banner" id="banner" role="alert"></p>
3692
+ <div class="banner" id="banner" role="alert"><span id="banner-message"></span><button id="banner-dismiss" type="button" aria-label="Dismiss error">\xD7</button></div>
3348
3693
  <section class="view" id="view-overview">
3349
- <h2>Overview</h2>
3350
- <p class="lede">Health, clock, and the collections this namespace is holding.</p>
3694
+ <div class="view-head"><div><h2>Overview</h2><p class="lede">Health, clock, and the collections this namespace is holding.</p></div></div>
3351
3695
  <div class="grid" id="overview-cards"></div>
3352
3696
  <h3>Recent requests</h3>
3353
3697
  <div id="overview-requests"></div>
3354
3698
  </section>
3355
3699
  <section class="view" id="view-state" hidden>
3356
- <h2>State</h2>
3357
- <p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
3700
+ <div class="view-head"><div><h2>State</h2><p class="lede">Inspect and edit every collection in this namespace.</p></div></div>
3358
3701
  <div class="split">
3359
3702
  <div id="collections"></div>
3360
3703
  <div>
@@ -3367,8 +3710,7 @@ var renderAdminDocument = (service) => {
3367
3710
  </div>
3368
3711
  </section>
3369
3712
  <section class="view" id="view-clock" hidden>
3370
- <h2>Clock</h2>
3371
- <p class="lede">The clock every timestamp in this mock reads.</p>
3713
+ <div class="view-head"><div><h2>Clock</h2><p class="lede">Control the source of time used by every timestamp in this mock.</p></div></div>
3372
3714
  <div class="card" id="clock-readout"></div>
3373
3715
  <div class="row-actions">
3374
3716
  <button class="btn" type="button" data-advance="60000">+1m</button>
@@ -3387,21 +3729,22 @@ var renderAdminDocument = (service) => {
3387
3729
  </form>
3388
3730
  </section>
3389
3731
  <section class="view" id="view-faults" hidden>
3390
- <h2>Faults</h2>
3391
- <p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
3732
+ <div class="view-head"><div><h2>Faults</h2><p class="lede">Test unhappy paths with a response, delay, or named preset scoped to this namespace.</p></div></div>
3392
3733
  <form id="fault-form" class="card stack">
3393
- <label class="field">Preset
3394
- <select id="fault-preset"><option value="">Custom rule</option></select>
3395
- </label>
3396
- <label class="field">Status
3397
- <input id="fault-status" inputmode="numeric" placeholder="503">
3398
- </label>
3399
- <label class="field">Path prefix
3400
- <input id="fault-path" placeholder="/v1">
3401
- </label>
3402
- <label class="field">Method
3403
- <input id="fault-method" placeholder="GET">
3404
- </label>
3734
+ <div class="form-grid">
3735
+ <label class="field wide">Preset
3736
+ <select id="fault-preset"><option value="">Custom rule</option></select>
3737
+ </label>
3738
+ <label class="field">Status
3739
+ <input id="fault-status" inputmode="numeric" placeholder="503">
3740
+ </label>
3741
+ <label class="field wide">Path prefix
3742
+ <input id="fault-path" placeholder="/v1">
3743
+ </label>
3744
+ <label class="field">Method
3745
+ <input id="fault-method" placeholder="GET">
3746
+ </label>
3747
+ </div>
3405
3748
  <div class="dialog-actions">
3406
3749
  <button class="btn-primary" type="submit">Add fault</button>
3407
3750
  <button class="btn-danger" id="fault-clear" type="button">Clear all</button>
@@ -3410,26 +3753,31 @@ var renderAdminDocument = (service) => {
3410
3753
  <div id="fault-list"></div>
3411
3754
  </section>
3412
3755
  <section class="view" id="view-journal" hidden>
3413
- <h2>Journal</h2>
3414
- <p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
3415
- <div class="row-actions">
3416
- <button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
3417
- </div>
3756
+ <div class="view-head"><div><h2>Journal</h2><p class="lede">Requests this namespace has seen. Bodies are never stored.</p></div><button class="btn-danger" id="journal-clear" type="button">Clear journal</button></div>
3418
3757
  <div id="journal"></div>
3419
3758
  </section>
3420
3759
  <section class="view" id="view-routes" hidden>
3421
- <h2>Routes</h2>
3422
- <p class="lede">Shared controls, plus any routes this mock adds. Extra routes are how a bespoke workflow shows up beside the default UI.</p>
3760
+ <div class="view-head"><div><h2>Routes</h2><p class="lede">Explore shared controls and service-specific admin endpoints.</p></div></div>
3761
+ <div class="route-tools">
3762
+ <label class="field">Filter routes
3763
+ <input id="route-search" type="search" placeholder="Method, path, or extension" autocomplete="off">
3764
+ </label>
3765
+ <span class="route-count" id="route-count"></span>
3766
+ </div>
3423
3767
  <div id="route-list"></div>
3424
- <form id="route-form" class="card stack">
3768
+ <form id="route-form" class="card stack" style="margin-top: 18px">
3425
3769
  <strong id="route-title">Select a route</strong>
3426
3770
  <label class="field">JSON body
3427
- <textarea id="route-body" placeholder="{ }"></textarea>
3771
+ <div class="json-editor" id="route-editor" hidden>
3772
+ <pre aria-hidden="true"><code id="route-highlight"></code></pre>
3773
+ <textarea id="route-body" placeholder="{ }" spellcheck="false" aria-describedby="route-json-status" disabled></textarea>
3774
+ </div>
3775
+ <span class="editor-meta" hidden><span class="json-status" id="route-json-status">Valid JSON</span><button class="format-json" type="button" data-format="route-body">Format JSON</button></span>
3428
3776
  </label>
3429
3777
  <div class="dialog-actions">
3430
- <button class="btn-primary" type="submit">Send</button>
3778
+ <button class="btn-primary" id="route-send" type="submit" disabled>Send request</button>
3431
3779
  </div>
3432
- <pre id="route-result">Response will show here.</pre>
3780
+ <pre class="json-view" id="route-result"><code>Response will show here.</code></pre>
3433
3781
  </form>
3434
3782
  </section>
3435
3783
  </main>
@@ -3437,12 +3785,16 @@ var renderAdminDocument = (service) => {
3437
3785
  </div>
3438
3786
  <dialog id="editor">
3439
3787
  <form method="dialog" id="editor-form">
3440
- <strong id="editor-title">Record</strong>
3788
+ <div class="dialog-heading"><div><strong id="editor-title">Record</strong><br><span>Edit the ID and JSON value stored in this collection.</span></div></div>
3441
3789
  <label class="field">Id
3442
3790
  <input id="editor-id" required>
3443
3791
  </label>
3444
3792
  <label class="field">JSON value
3445
- <textarea id="editor-value"></textarea>
3793
+ <div class="json-editor" id="record-editor">
3794
+ <pre aria-hidden="true"><code id="editor-highlight"></code></pre>
3795
+ <textarea id="editor-value" spellcheck="false" aria-describedby="editor-json-status"></textarea>
3796
+ </div>
3797
+ <span class="editor-meta"><span class="json-status" id="editor-json-status">Valid JSON</span><button class="format-json" type="button" data-format="editor-value">Format JSON</button></span>
3446
3798
  </label>
3447
3799
  <div class="dialog-actions">
3448
3800
  <button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
@@ -3484,8 +3836,8 @@ var describeExtension = (extension) => {
3484
3836
  ...extension.script !== void 0 ? { script: extension.script } : {}
3485
3837
  };
3486
3838
  };
3487
- var adminUiRoutes = (service, ui) => {
3488
- const shell = () => renderAdminDocument(service);
3839
+ var adminUiRoutes = (service, ui, adminPrefix = ADMIN_PREFIX) => {
3840
+ const shell = () => renderAdminDocument(service, adminPrefix);
3489
3841
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
3490
3842
  return {
3491
3843
  "GET /ui": () => htmlResponse(document3()),
@@ -4186,7 +4538,7 @@ var stateAdminRoutes = (routes) => {
4186
4538
  };
4187
4539
 
4188
4540
  // ../core/dist/version.js
4189
- var PACKAGE_VERSION = true ? "1.8.0" : UNRELEASED_VERSION;
4541
+ var PACKAGE_VERSION = true ? "2.0.0" : UNRELEASED_VERSION;
4190
4542
 
4191
4543
  // ../core/dist/signing.js
4192
4544
  var encoder = new TextEncoder();
@@ -4567,7 +4919,10 @@ var createWebhookHub = (options) => {
4567
4919
  };
4568
4920
  return hub;
4569
4921
  };
4570
- var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
4922
+ var json4 = (status, body) => new Response(JSON.stringify(body), {
4923
+ status,
4924
+ headers: { "content-type": "application/json; charset=utf-8" }
4925
+ });
4571
4926
  var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
4572
4927
  var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4573
4928
  var parseEndpoint = (value) => {
@@ -4675,7 +5030,6 @@ var AT_HEADER = "x-mockingbird-at";
4675
5030
  var CHECKPOINT_HEADER = "x-mockingbird-checkpoint";
4676
5031
  var DEFAULT_NAMESPACE = "default";
4677
5032
  var NAMESPACE_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
4678
- var PATH_PREFIX = /^\/ns\/([^/]+)(\/.*)?$/;
4679
5033
  var BRANCH_PATTERN2 = /^[A-Za-z0-9_.-]{1,64}$/;
4680
5034
  var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
4681
5035
  var effects = /* @__PURE__ */ new WeakMap();
@@ -4716,6 +5070,22 @@ var operationMatcher = (document3) => {
4716
5070
  return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
4717
5071
  };
4718
5072
  var createRuntime = (options) => {
5073
+ const adminPrefix = resolveAdminPrefix(options.adminPrefix);
5074
+ const internalPaths = Object.entries(options.document?.paths ?? {}).filter(([, item]) => item["x-mockingbird-internal"] === true).map(([path]) => path);
5075
+ for (const path of internalPaths) {
5076
+ if (!path.startsWith(`${ADMIN_PREFIX}/blobs/`))
5077
+ throw new Error(`internal transport ${path} must live under ${ADMIN_PREFIX}/blobs/`);
5078
+ }
5079
+ assertAdminPrefixAvailable(adminPrefix, Object.keys(options.document?.paths ?? {}).filter((path) => !internalPaths.includes(path)));
5080
+ const internalMatch = (path) => {
5081
+ for (const pattern of internalPaths) {
5082
+ const actual = path.split("/");
5083
+ const expected = pattern.split("/");
5084
+ if (actual.length === expected.length && expected.every((part, i) => part.startsWith("{") || part === actual[i]))
5085
+ return pattern;
5086
+ }
5087
+ return void 0;
5088
+ };
4719
5089
  assertAdminUi(options.adminUi);
4720
5090
  const sqlite = bootSqlite(options.sqlite);
4721
5091
  const clock = options.clock ?? createClock();
@@ -4761,6 +5131,7 @@ var createRuntime = (options) => {
4761
5131
  const created = options.create({
4762
5132
  namespace: storageNamespace(key2),
4763
5133
  publicNamespace,
5134
+ adminPrefix,
4764
5135
  sqlite,
4765
5136
  clock: namespaceClock(publicNamespace),
4766
5137
  rng: createdContextRng
@@ -4993,10 +5364,10 @@ var createRuntime = (options) => {
4993
5364
  namespaceClock,
4994
5365
  namespaceOf(request) {
4995
5366
  const url = new URL(request.url);
4996
- const prefixed = PATH_PREFIX.exec(url.pathname);
5367
+ const prefixed = matchNamespacePath(url.pathname, adminPrefix);
4997
5368
  const selected = request.headers.get(NAMESPACE_HEADER) ?? (prefixed ? decodeURIComponent(prefixed[1]) : void 0);
4998
5369
  const path = prefixed ? prefixed[2] ?? "/" : url.pathname;
4999
- if (path === "/__admin" || path.startsWith("/__admin/"))
5370
+ if (isAdminPath(path, adminPrefix))
5000
5371
  return url.searchParams.get("namespace") ?? selected ?? DEFAULT_NAMESPACE;
5001
5372
  if (selected !== void 0)
5002
5373
  return selected;
@@ -5062,7 +5433,7 @@ var createRuntime = (options) => {
5062
5433
  state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
5063
5434
  fetch: async (incoming) => {
5064
5435
  let request = incoming;
5065
- const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
5436
+ const prefixed = matchNamespacePath(new URL(request.url).pathname, adminPrefix);
5066
5437
  if (prefixed) {
5067
5438
  const url2 = new URL(request.url);
5068
5439
  url2.pathname = prefixed[2] ?? "/";
@@ -5078,7 +5449,15 @@ var createRuntime = (options) => {
5078
5449
  signal: request.signal
5079
5450
  });
5080
5451
  }
5081
- let namespace = control.namespaceOf(request);
5452
+ const internalUrl = new URL(request.url);
5453
+ const internalPath = isAdminPath(internalUrl.pathname, adminPrefix) ? `${ADMIN_PREFIX}${internalUrl.pathname.slice(adminPrefix.length)}` : "";
5454
+ const internal = internalMatch(internalPath);
5455
+ const obsoleteInternalPath = adminPrefix !== ADMIN_PREFIX && internalMatch(internalUrl.pathname) && !internal;
5456
+ if (internal) {
5457
+ internalUrl.pathname = internalPath;
5458
+ request = new Request(internalUrl, request);
5459
+ }
5460
+ let namespace = internal ? internalUrl.searchParams.get("namespace") ?? control.namespaceOf(request) : control.namespaceOf(request);
5082
5461
  if (!request.headers.has(NAMESPACE_HEADER) && options.credential) {
5083
5462
  const credential = options.credential(request);
5084
5463
  const mapped = credential !== void 0 ? credentials.get(credential) : void 0;
@@ -5098,7 +5477,9 @@ var createRuntime = (options) => {
5098
5477
  return copy;
5099
5478
  }
5100
5479
  };
5101
- const handled = await control.handle(request);
5480
+ if (obsoleteInternalPath)
5481
+ return stamp(adminFail(404, "internal transport is only available under adminPrefix"));
5482
+ const handled = internal ? void 0 : await control.handle(request);
5102
5483
  if (handled)
5103
5484
  return stamp(handled);
5104
5485
  const started = monotonicNow();
@@ -5139,7 +5520,7 @@ var createRuntime = (options) => {
5139
5520
  type: "mockingbird_admin",
5140
5521
  message: `${NAMESPACE_HEADER} must match ${NAMESPACE_PATTERN}`
5141
5522
  }
5142
- }), { status: 400, headers: { "content-type": "application/json" } }));
5523
+ }), { status: 400, headers: { "content-type": "application/json; charset=utf-8" } }));
5143
5524
  }
5144
5525
  if (!BRANCH_PATTERN2.test(selectedBranch)) {
5145
5526
  log(400);
@@ -5256,15 +5637,16 @@ var createRuntime = (options) => {
5256
5637
  ...options.admin?.(runtime) ?? {},
5257
5638
  // Shell routes win a colliding key. Fault presets are one of them: the admin page
5258
5639
  // maps `presets`, and a service route must not replace that list with a record.
5259
- ...options.presets ? presetRoutes(options.presets, runtime) : {},
5640
+ ...options.presets ? presetRoutes(options.presets, runtime, adminPrefix) : {},
5260
5641
  ...stateAdminRoutes({
5261
5642
  open: stateScope,
5262
5643
  afterWrite: (namespace) => {
5263
5644
  checkpoint(namespace, "main");
5264
5645
  }
5265
5646
  }),
5266
- ...adminUiRoutes(options.name, options.adminUi)
5647
+ ...adminUiRoutes(options.name, options.adminUi, adminPrefix)
5267
5648
  },
5649
+ adminPrefix,
5268
5650
  adminKey: options.adminKey
5269
5651
  });
5270
5652
  return defineMock(runtime);
@@ -5278,7 +5660,10 @@ var mutableResponse = (response) => {
5278
5660
  return new Response(response.body, response);
5279
5661
  }
5280
5662
  };
5281
- var adminJson = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
5663
+ var adminJson = (status, body) => new Response(JSON.stringify(body), {
5664
+ status,
5665
+ headers: { "content-type": "application/json; charset=utf-8" }
5666
+ });
5282
5667
  var adminFail = (status, message) => adminJson(status, { error: { type: "mockingbird_admin", message } });
5283
5668
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5284
5669
  var credentialRoutes = (registry) => ({
@@ -5330,7 +5715,7 @@ var credentialRoutes = (registry) => ({
5330
5715
  return adminJson(200, { status: "ok" });
5331
5716
  }
5332
5717
  });
5333
- var presetRoutes = (presets, runtime) => ({
5718
+ var presetRoutes = (presets, runtime, adminPrefix) => ({
5334
5719
  "GET /faults/presets": () => {
5335
5720
  const body = {
5336
5721
  presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
@@ -5340,7 +5725,7 @@ var presetRoutes = (presets, runtime) => ({
5340
5725
  "POST /faults/presets/:name": ({ params, body, namespace }) => {
5341
5726
  const name = params.name;
5342
5727
  if (!presets[name])
5343
- return adminFail(404, `no fault preset ${name}; GET /__admin/faults/presets`);
5728
+ return adminFail(404, `no fault preset ${name}; GET ${adminPrefix}/faults/presets`);
5344
5729
  const overrides = isObject(body) ? body : {};
5345
5730
  return adminJson(201, { preset: name, rules: runtime.applyPreset(name, namespace, overrides) });
5346
5731
  }
@@ -5642,6 +6027,7 @@ var createRuntime2 = (options = {}) => {
5642
6027
  ...options.sqlite ? { sqlite: options.sqlite } : {},
5643
6028
  ...options.clock ? { clock: options.clock } : {},
5644
6029
  ...options.seed !== void 0 ? { seed: options.seed } : {},
6030
+ ...options.adminPrefix !== void 0 ? { adminPrefix: options.adminPrefix } : {},
5645
6031
  ...options.adminKey !== void 0 ? { adminKey: options.adminKey } : {},
5646
6032
  ...options.onLog ? { onLog: options.onLog } : {},
5647
6033
  credential: apiKeyCredential,
@@ -6015,6 +6401,7 @@ var AhaAPI = class {
6015
6401
 
6016
6402
  export {
6017
6403
  createClock,
6404
+ resolveAdminPrefix,
6018
6405
  parseDuration,
6019
6406
  document2 as document,
6020
6407
  operationIds,
@@ -6032,4 +6419,4 @@ export {
6032
6419
  apiKeyCredential,
6033
6420
  AhaAPI
6034
6421
  };
6035
- //# sourceMappingURL=chunk-ZXTUCFOK.js.map
6422
+ //# sourceMappingURL=chunk-OPYCBZYR.js.map