@crvouga/mockingbird-service-bedrock 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(([key, handler]) => {
374
+ for (const key of Object.keys(context.routes)) {
375
+ if (Object.hasOwn(builtin, key))
376
+ throw new Error(`admin route ${key} overrides a shared route`);
377
+ const path = key.slice(key.indexOf(" ") + 1);
378
+ if (isAdminPath(path, "/ns") || isAdminPath(path, "/blobs"))
379
+ throw new Error(`admin route ${key} overlaps an internal transport`);
380
+ }
381
+ const routes = [...Object.entries(builtin), ...Object.entries(context.routes)].map(([key, handler]) => {
343
382
  const space = key.indexOf(" ");
344
383
  return { method: key.slice(0, space), pattern: key.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
  };
@@ -1765,6 +1804,34 @@ dialog:not([open]) {
1765
1804
  function isRecord2(value) {
1766
1805
  return typeof value === "object" && value !== null && !Array.isArray(value);
1767
1806
  }
1807
+ function highlightJsonText(text2) {
1808
+ const escapeToken = (value) => value.replace(/[&<>"']/g, (char) => {
1809
+ switch (char) {
1810
+ case "&":
1811
+ return "&amp;";
1812
+ case "<":
1813
+ return "&lt;";
1814
+ case ">":
1815
+ return "&gt;";
1816
+ case '"':
1817
+ return "&quot;";
1818
+ default:
1819
+ return "&#39;";
1820
+ }
1821
+ });
1822
+ 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;
1823
+ let cursor = 0;
1824
+ let html = "";
1825
+ for (const match of text2.matchAll(token)) {
1826
+ const index = match.index ?? 0;
1827
+ const value = match[0];
1828
+ html += escapeToken(text2.slice(cursor, index));
1829
+ const kind = value.startsWith('"') ? value.trimEnd().endsWith(":") ? "key" : "string" : value === "true" || value === "false" ? "boolean" : value === "null" ? "null" : "number";
1830
+ html += `<span class="json-${kind}">${escapeToken(value)}</span>`;
1831
+ cursor = index + value.length;
1832
+ }
1833
+ return html + escapeToken(text2.slice(cursor));
1834
+ }
1768
1835
  function mountAdminBrand(doc, host, service, catalog) {
1769
1836
  const clip = (value, max) => {
1770
1837
  if (typeof value !== "string")
@@ -2126,14 +2193,16 @@ function bootAdmin(config) {
2126
2193
  const state = {
2127
2194
  namespace: "default",
2128
2195
  key: sessionStorage.getItem("mockingbird-admin-key") || "",
2129
- view: "overview",
2196
+ view: ["overview", "state", "clock", "faults", "journal", "routes"].includes(location.hash.slice(1)) ? location.hash.slice(1) : "overview",
2130
2197
  collection: "",
2131
2198
  shape: null,
2132
2199
  route: null,
2200
+ routes: [],
2133
2201
  editing: null
2134
2202
  };
2135
2203
  const standard = new Set(config.standardRoutes);
2136
2204
  const banner = el("banner", HTMLElement);
2205
+ const bannerMessage = el("banner-message", HTMLElement);
2137
2206
  const keyInput = el("admin-key", HTMLInputElement);
2138
2207
  keyInput.value = state.key;
2139
2208
  const params = new URLSearchParams(location.search);
@@ -2144,18 +2213,21 @@ function bootAdmin(config) {
2144
2213
  sessionStorage.setItem("mockingbird-admin-key", state.key);
2145
2214
  params.delete("key");
2146
2215
  const next = params.toString();
2147
- history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
2216
+ history.replaceState(null, "", location.pathname + (next ? `?${next}` : "") + location.hash);
2148
2217
  }
2149
2218
  const queryNamespace = params.get("namespace");
2150
2219
  if (queryNamespace)
2151
2220
  state.namespace = queryNamespace;
2152
2221
  const showError = (error) => {
2153
- banner.textContent = error instanceof Error ? error.message : String(error);
2222
+ bannerMessage.textContent = error instanceof Error ? error.message : String(error);
2154
2223
  banner.classList.add("show");
2224
+ banner.scrollIntoView({ behavior: "smooth", block: "nearest" });
2155
2225
  };
2156
2226
  const clearError = () => {
2157
2227
  banner.classList.remove("show");
2228
+ bannerMessage.textContent = "";
2158
2229
  };
2230
+ el("banner-dismiss", HTMLButtonElement).addEventListener("click", clearError);
2159
2231
  const api = async (method, path, body) => {
2160
2232
  const headers = { accept: "application/json" };
2161
2233
  if (state.key !== "")
@@ -2199,16 +2271,21 @@ function bootAdmin(config) {
2199
2271
  namespace: () => state.namespace
2200
2272
  };
2201
2273
  const isPanelScript = (value) => typeof value === "function";
2274
+ const themeButton = el("theme", HTMLButtonElement);
2202
2275
  const setTheme = (theme) => {
2203
2276
  if (theme)
2204
2277
  document.documentElement.dataset.theme = theme;
2205
2278
  else
2206
2279
  delete document.documentElement.dataset.theme;
2280
+ const dark = theme ? theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2281
+ 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>';
2282
+ const label = dark ? "Use light theme" : "Use dark theme";
2283
+ themeButton.setAttribute("aria-label", label);
2284
+ themeButton.title = label;
2207
2285
  };
2208
2286
  const storedTheme = localStorage.getItem("mockingbird-admin-theme");
2209
- if (storedTheme)
2210
- setTheme(storedTheme);
2211
- el("theme", HTMLButtonElement).addEventListener("click", () => {
2287
+ setTheme(storedTheme === "dark" || storedTheme === "light" ? storedTheme : null);
2288
+ themeButton.addEventListener("click", () => {
2212
2289
  const current = document.documentElement.dataset.theme;
2213
2290
  const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2214
2291
  const next = dark ? "light" : "dark";
@@ -2227,6 +2304,7 @@ function bootAdmin(config) {
2227
2304
  continue;
2228
2305
  section.hidden = section.id !== `view-${view}`;
2229
2306
  }
2307
+ history.replaceState(null, "", `${location.pathname}${location.search}#${encodeURIComponent(view)}`);
2230
2308
  };
2231
2309
  el("nav", HTMLElement).addEventListener("click", (event) => {
2232
2310
  const target = event.target;
@@ -2241,7 +2319,7 @@ function bootAdmin(config) {
2241
2319
  show(view);
2242
2320
  refresh().catch(showError);
2243
2321
  });
2244
- 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>`;
2322
+ 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>`;
2245
2323
  const table = (columns, rows) => {
2246
2324
  if (rows.length === 0)
2247
2325
  return '<p class="empty">Nothing here yet.</p>';
@@ -2251,16 +2329,22 @@ function bootAdmin(config) {
2251
2329
  const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
2252
2330
  return `<tr${attrs}>${cells}</tr>`;
2253
2331
  }).join("");
2254
- return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
2332
+ return `<div class="table-shell"><table><thead>${head}</thead><tbody>${body}</tbody></table></div>`;
2255
2333
  };
2256
2334
  const preview = (value) => {
2257
2335
  const text2 = JSON.stringify(value) ?? "null";
2258
- return esc(text2.length > 180 ? `${text2.slice(0, 180)}\u2026` : text2);
2336
+ const clipped = text2.length > 180 ? `${text2.slice(0, 180)}\u2026` : text2;
2337
+ return `<code class="json-inline">${highlightJsonText(clipped)}</code>`;
2259
2338
  };
2260
2339
  const when = (epoch) => {
2261
2340
  const date = new Date(epoch);
2262
2341
  return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
2263
2342
  };
2343
+ const journalWhen = (value) => {
2344
+ const numeric = value.trim() === "" ? Number.NaN : Number(value);
2345
+ const epoch = Number.isFinite(numeric) ? numeric : Date.parse(value);
2346
+ return Number.isFinite(epoch) ? when(epoch) : value;
2347
+ };
2264
2348
  const clockCard = (epoch) => {
2265
2349
  const date = new Date(epoch);
2266
2350
  if (Number.isNaN(date.getTime()))
@@ -2380,7 +2464,7 @@ function bootAdmin(config) {
2380
2464
  };
2381
2465
  const renderOverview = async () => {
2382
2466
  const [health, shape, clock, journal] = await Promise.all([
2383
- originGet("/health"),
2467
+ originGet(`${config.adminPrefix}/health`),
2384
2468
  api("GET", "/state"),
2385
2469
  api("GET", "/clock"),
2386
2470
  api("GET", "/requests?limit=8")
@@ -2397,7 +2481,7 @@ function bootAdmin(config) {
2397
2481
  },
2398
2482
  {
2399
2483
  k: "Status",
2400
- v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
2484
+ v: `<span class="badge ok">${esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")}</span>`
2401
2485
  },
2402
2486
  { k: "Namespace", v: esc(state.namespace) },
2403
2487
  { k: "Collections", v: String(decoded.collections.length) },
@@ -2484,26 +2568,46 @@ function bootAdmin(config) {
2484
2568
  const renderJournal = async () => {
2485
2569
  const journal = await api("GET", "/requests?limit=100");
2486
2570
  el("journal", HTMLElement).innerHTML = table([
2487
- { label: "When", cell: (row) => esc(row.at) },
2488
- { label: "Method", cell: (row) => esc(row.method) },
2571
+ { label: "When", cell: (row) => esc(journalWhen(row.at)) },
2572
+ {
2573
+ label: "Method",
2574
+ cell: (row) => `<span class="method">${esc(row.method)}</span>`
2575
+ },
2489
2576
  { label: "Path", cell: (row) => esc(row.path) },
2490
- { label: "Status", cell: (row) => esc(row.status) },
2577
+ {
2578
+ label: "Status",
2579
+ cell: (row) => `<span class="badge ${row.status.startsWith("2") ? "ok" : row.status.startsWith("4") || row.status.startsWith("5") ? "warn" : ""}">${esc(row.status)}</span>`
2580
+ },
2491
2581
  { label: "ms", cell: (row) => esc(row.durationMs) }
2492
2582
  ], decodeJournal(journal));
2493
2583
  };
2494
- const renderRoutes = async () => {
2495
- const data = await api("GET", "/");
2496
- if (!isRecord2(data))
2497
- throw new Error("Route list was not an object");
2498
- const routes = requireList(data.routes, "Routes").map((route) => String(route));
2584
+ const paintRoutes = () => {
2585
+ const query = el("route-search", HTMLInputElement).value.trim().toLocaleLowerCase();
2586
+ const routes = state.routes.filter((route) => route.toLocaleLowerCase().includes(query));
2587
+ el("route-count", HTMLElement).textContent = `${routes.length} of ${state.routes.length}`;
2588
+ if (state.routes.length === 0) {
2589
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No admin routes are available.</p>';
2590
+ return;
2591
+ }
2592
+ if (routes.length === 0) {
2593
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No routes match this filter.</p>';
2594
+ return;
2595
+ }
2499
2596
  el("route-list", HTMLElement).innerHTML = routes.map((route) => {
2500
2597
  const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
2501
2598
  const parts = route.split(" ");
2502
2599
  const method = parts[0] ?? "";
2503
2600
  const path = parts.slice(1).join(" ");
2504
- 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>`;
2601
+ 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>`;
2505
2602
  }).join("");
2506
2603
  };
2604
+ const renderRoutes = async () => {
2605
+ const data = await api("GET", "/");
2606
+ if (!isRecord2(data))
2607
+ throw new Error("Route list was not an object");
2608
+ state.routes = requireList(data.routes, "Routes").map((route) => String(route));
2609
+ paintRoutes();
2610
+ };
2507
2611
  const renderers = {
2508
2612
  overview: renderOverview,
2509
2613
  state: renderState,
@@ -2512,19 +2616,50 @@ function bootAdmin(config) {
2512
2616
  journal: renderJournal,
2513
2617
  routes: renderRoutes
2514
2618
  };
2619
+ let refreshToken = 0;
2515
2620
  async function refresh() {
2621
+ const token = ++refreshToken;
2516
2622
  clearError();
2623
+ const main = el("views", HTMLElement);
2624
+ const sync = el("sync-status", HTMLElement);
2625
+ main.setAttribute("aria-busy", "true");
2626
+ sync.classList.add("busy");
2627
+ sync.textContent = "Updating";
2517
2628
  const render = renderers[state.view];
2518
- if (render)
2519
- await render();
2629
+ try {
2630
+ if (render)
2631
+ await render();
2632
+ if (token === refreshToken)
2633
+ sync.textContent = "Up to date";
2634
+ } finally {
2635
+ if (token === refreshToken) {
2636
+ main.removeAttribute("aria-busy");
2637
+ sync.classList.remove("busy");
2638
+ }
2639
+ }
2520
2640
  }
2521
2641
  const delay = (ms) => new Promise((resolve) => {
2522
2642
  window.setTimeout(resolve, ms);
2523
2643
  });
2524
- const confirmAction = async (button, pending, done, work) => {
2644
+ const confirmAction = async (button, pending, done, work, confirmLabel) => {
2525
2645
  if (button.dataset.pending === "1")
2526
2646
  return;
2527
2647
  const label = button.textContent ?? "";
2648
+ if (confirmLabel !== void 0 && button.dataset.confirming !== "1") {
2649
+ button.dataset.confirming = "1";
2650
+ button.classList.add("confirming");
2651
+ button.textContent = confirmLabel;
2652
+ window.setTimeout(() => {
2653
+ if (button.dataset.confirming !== "1")
2654
+ return;
2655
+ button.textContent = label;
2656
+ button.classList.remove("confirming");
2657
+ delete button.dataset.confirming;
2658
+ }, 3e3);
2659
+ return;
2660
+ }
2661
+ button.classList.remove("confirming");
2662
+ delete button.dataset.confirming;
2528
2663
  const width = button.offsetWidth;
2529
2664
  button.dataset.pending = "1";
2530
2665
  button.classList.add("pressed");
@@ -2545,6 +2680,65 @@ function bootAdmin(config) {
2545
2680
  delete button.dataset.pending;
2546
2681
  }
2547
2682
  };
2683
+ const wireJsonEditor = (textareaId, highlightId, statusId, shellId, allowEmpty) => {
2684
+ const textarea = el(textareaId, HTMLTextAreaElement);
2685
+ const highlight = el(highlightId, HTMLElement);
2686
+ const status = el(statusId, HTMLElement);
2687
+ const shell = el(shellId, HTMLElement);
2688
+ const sync = () => {
2689
+ const text2 = textarea.value;
2690
+ highlight.innerHTML = `${highlightJsonText(text2)}
2691
+ `;
2692
+ let valid = true;
2693
+ let message = "Valid JSON";
2694
+ if (allowEmpty && text2.trim() === "")
2695
+ message = "No body";
2696
+ else {
2697
+ try {
2698
+ readJson2(text2);
2699
+ } catch {
2700
+ valid = false;
2701
+ message = "Invalid JSON";
2702
+ }
2703
+ }
2704
+ shell.classList.toggle("invalid", !valid);
2705
+ status.classList.toggle("invalid", !valid);
2706
+ status.textContent = message;
2707
+ textarea.setAttribute("aria-invalid", valid ? "false" : "true");
2708
+ };
2709
+ const syncScroll = () => {
2710
+ const preview2 = highlight.parentElement;
2711
+ if (!(preview2 instanceof HTMLElement))
2712
+ return;
2713
+ preview2.scrollTop = textarea.scrollTop;
2714
+ preview2.scrollLeft = textarea.scrollLeft;
2715
+ };
2716
+ textarea.addEventListener("input", sync);
2717
+ textarea.addEventListener("scroll", syncScroll);
2718
+ sync();
2719
+ return sync;
2720
+ };
2721
+ const syncRouteEditor = wireJsonEditor("route-body", "route-highlight", "route-json-status", "route-editor", true);
2722
+ const syncRecordEditor = wireJsonEditor("editor-value", "editor-highlight", "editor-json-status", "record-editor", false);
2723
+ for (const button of document.querySelectorAll("[data-format]")) {
2724
+ if (!(button instanceof HTMLButtonElement))
2725
+ continue;
2726
+ button.addEventListener("click", () => {
2727
+ const target = button.dataset.format;
2728
+ if (target === void 0)
2729
+ return;
2730
+ const textarea = document.getElementById(target);
2731
+ if (!(textarea instanceof HTMLTextAreaElement) || textarea.value.trim() === "")
2732
+ return;
2733
+ try {
2734
+ textarea.value = JSON.stringify(readJson2(textarea.value), null, 2) ?? "";
2735
+ textarea.dispatchEvent(new Event("input"));
2736
+ textarea.focus();
2737
+ } catch {
2738
+ showError(new Error("Fix the JSON before formatting it"));
2739
+ }
2740
+ });
2741
+ }
2548
2742
  document.addEventListener("click", (event) => {
2549
2743
  const target = event.target;
2550
2744
  if (!(target instanceof Element))
@@ -2617,6 +2811,7 @@ function bootAdmin(config) {
2617
2811
  } else {
2618
2812
  editorValue.value = "{\n \n}";
2619
2813
  }
2814
+ syncRecordEditor();
2620
2815
  editor.showModal();
2621
2816
  }
2622
2817
  el("new-record", HTMLButtonElement).addEventListener("click", () => {
@@ -2646,10 +2841,10 @@ function bootAdmin(config) {
2646
2841
  const id = state.editing;
2647
2842
  if (!id)
2648
2843
  return;
2649
- api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2844
+ confirmAction(editorDelete, "Deleting...", "Deleted", () => api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2650
2845
  editor.close();
2651
2846
  return renderState();
2652
- }).catch(showError);
2847
+ }), "Confirm delete").catch(showError);
2653
2848
  });
2654
2849
  for (const button of document.querySelectorAll("[data-advance]")) {
2655
2850
  if (!(button instanceof HTMLButtonElement))
@@ -2695,10 +2890,10 @@ function bootAdmin(config) {
2695
2890
  }).then(() => renderFaults()).catch(showError);
2696
2891
  });
2697
2892
  el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
2698
- confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults())).catch(showError);
2893
+ confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults()), "Confirm clear").catch(showError);
2699
2894
  });
2700
2895
  el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
2701
- confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal())).catch(showError);
2896
+ confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal()), "Confirm clear").catch(showError);
2702
2897
  });
2703
2898
  el("route-list", HTMLElement).addEventListener("click", (event) => {
2704
2899
  const target = event.target;
@@ -2712,9 +2907,15 @@ function bootAdmin(config) {
2712
2907
  return;
2713
2908
  state.route = route;
2714
2909
  el("route-title", HTMLElement).textContent = route;
2910
+ el("route-send", HTMLButtonElement).disabled = false;
2715
2911
  const method = route.split(" ")[0] ?? "";
2716
- el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
2912
+ const routeBody = el("route-body", HTMLTextAreaElement);
2913
+ routeBody.disabled = method === "GET" || method === "DELETE";
2914
+ el("route-editor", HTMLElement).hidden = routeBody.disabled;
2915
+ el("route-json-status", HTMLElement).parentElement?.toggleAttribute("hidden", routeBody.disabled);
2916
+ syncRouteEditor();
2717
2917
  });
2918
+ el("route-search", HTMLInputElement).addEventListener("input", paintRoutes);
2718
2919
  el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
2719
2920
  event.preventDefault();
2720
2921
  const send = async () => {
@@ -2736,7 +2937,8 @@ function bootAdmin(config) {
2736
2937
  }
2737
2938
  }
2738
2939
  const data = await api(method, concrete, body);
2739
- el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
2940
+ const text2 = JSON.stringify(data, null, 2) ?? "null";
2941
+ el("route-result", HTMLElement).innerHTML = `<code>${highlightJsonText(text2)}</code>`;
2740
2942
  };
2741
2943
  send().catch(showError);
2742
2944
  });
@@ -2854,11 +3056,13 @@ function bootAdmin(config) {
2854
3056
  views.append(section);
2855
3057
  mountSqlExplorer(body, panelApi);
2856
3058
  }
3059
+ show(document.getElementById(`view-${state.view}`) === null ? "overview" : state.view);
2857
3060
  return refresh();
2858
3061
  }).catch(showError);
2859
3062
  }
2860
3063
  var clientPrelude = [
2861
3064
  isRecord2,
3065
+ highlightJsonText,
2862
3066
  mountAdminBrand,
2863
3067
  startAdminBrand,
2864
3068
  faultPresetList,
@@ -2881,6 +3085,7 @@ ${entry}(${payload});
2881
3085
  var defineMock = (runtime) => runtime;
2882
3086
  var STANDARD_ADMIN_ROUTES = [
2883
3087
  "GET /",
3088
+ "GET /health",
2884
3089
  "POST /reset",
2885
3090
  "GET /namespaces",
2886
3091
  "GET /clock",
@@ -2960,11 +3165,11 @@ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
2960
3165
  }
2961
3166
  });
2962
3167
  var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
2963
- var renderAdminDocument = (service) => {
3168
+ var renderAdminDocument = (service, adminPrefix = ADMIN_PREFIX) => {
2964
3169
  const name = escapeHtml(service);
2965
3170
  const script = adminClientSource({
2966
3171
  standardRoutes: STANDARD_ADMIN_ROUTES,
2967
- adminPrefix: ADMIN_PREFIX,
3172
+ adminPrefix,
2968
3173
  adminKeyHeader: ADMIN_KEY_HEADER,
2969
3174
  brandsUrl: ADMIN_BRANDS_URL,
2970
3175
  service
@@ -2981,75 +3186,99 @@ var renderAdminDocument = (service) => {
2981
3186
  ${CSS_RESET}
2982
3187
  :root {
2983
3188
  color-scheme: light;
2984
- --bg: #fafafa;
3189
+ --bg: #f7f8fb;
2985
3190
  --bg-elev: #ffffff;
2986
- --bg-muted: #f4f4f5;
2987
- --bg-inset: #f4f4f5;
2988
- --line: #dedee3;
2989
- --line-strong: #c4c4cc;
2990
- --ink: #18181b;
2991
- --muted: #62626b;
2992
- --faint: #71717a;
2993
- --accent: #27272a;
3191
+ --bg-muted: #f1f3f7;
3192
+ --bg-inset: #f8f9fc;
3193
+ --line: #e4e7ec;
3194
+ --line-strong: #cfd4dc;
3195
+ --ink: #101828;
3196
+ --muted: #475467;
3197
+ --faint: #667085;
3198
+ --accent: #6941c6;
3199
+ --accent-hover: #5933b4;
2994
3200
  --accent-ink: #ffffff;
2995
- --accent-soft: #f4f4f5;
2996
- --ok: #166534;
2997
- --ok-soft: #f0fdf4;
2998
- --warn: #a16207;
2999
- --warn-soft: #fefce8;
3000
- --err: #a82d32;
3001
- --err-soft: #fef2f2;
3002
- --shadow: none;
3201
+ --accent-soft: #f4f0ff;
3202
+ --ok: #067647;
3203
+ --ok-soft: #ecfdf3;
3204
+ --warn: #b54708;
3205
+ --warn-soft: #fffaeb;
3206
+ --err: #b42318;
3207
+ --err-soft: #fef3f2;
3208
+ --code-key: #6941c6;
3209
+ --code-string: #067647;
3210
+ --code-number: #175cd3;
3211
+ --code-boolean: #c11574;
3212
+ --code-null: #667085;
3213
+ --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
3214
+ --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
3215
+ --shadow-lg: 0 18px 48px rgb(16 24 40 / 0.16), 0 4px 12px rgb(16 24 40 / 0.08);
3003
3216
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
3004
3217
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
3005
- --radius: 10px;
3006
- --header: 56px;
3007
- --nav: 200px;
3218
+ --radius: 12px;
3219
+ --header: 72px;
3220
+ --nav: 224px;
3008
3221
  }
3009
3222
  :root[data-theme="dark"] {
3010
3223
  color-scheme: dark;
3011
- --bg: #111113;
3012
- --bg-elev: #19191c;
3013
- --bg-muted: #242428;
3014
- --bg-inset: #111113;
3015
- --line: #36363c;
3016
- --line-strong: #52525b;
3017
- --ink: #f4f4f5;
3018
- --muted: #a9a9b2;
3019
- --faint: #71717a;
3020
- --accent: #e4e4e7;
3021
- --accent-ink: #18181b;
3022
- --accent-soft: #242428;
3023
- --ok: #86efac;
3024
- --ok-soft: #14241b;
3025
- --warn: #fde68a;
3026
- --warn-soft: #2a2410;
3027
- --err: #ffaaaa;
3028
- --err-soft: #2c1516;
3029
- --shadow: none;
3224
+ --bg: #0c0e14;
3225
+ --bg-elev: #151821;
3226
+ --bg-muted: #20232e;
3227
+ --bg-inset: #11141c;
3228
+ --line: #2b303d;
3229
+ --line-strong: #414858;
3230
+ --ink: #f5f7fa;
3231
+ --muted: #b6bdc9;
3232
+ --faint: #8d96a7;
3233
+ --accent: #9e77ed;
3234
+ --accent-hover: #b692f6;
3235
+ --accent-ink: #ffffff;
3236
+ --accent-soft: #2b2142;
3237
+ --ok: #75e0a7;
3238
+ --ok-soft: #102a20;
3239
+ --warn: #fec84b;
3240
+ --warn-soft: #302611;
3241
+ --err: #fda29b;
3242
+ --err-soft: #321817;
3243
+ --code-key: #c3a6ff;
3244
+ --code-string: #75e0a7;
3245
+ --code-number: #84adff;
3246
+ --code-boolean: #f9a8d4;
3247
+ --code-null: #98a2b3;
3248
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3249
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3250
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3030
3251
  }
3031
3252
  @media (prefers-color-scheme: dark) {
3032
3253
  :root:not([data-theme="light"]) {
3033
3254
  color-scheme: dark;
3034
- --bg: #111113;
3035
- --bg-elev: #19191c;
3036
- --bg-muted: #242428;
3037
- --bg-inset: #111113;
3038
- --line: #36363c;
3039
- --line-strong: #52525b;
3040
- --ink: #f4f4f5;
3041
- --muted: #a9a9b2;
3042
- --faint: #71717a;
3043
- --accent: #e4e4e7;
3044
- --accent-ink: #18181b;
3045
- --accent-soft: #242428;
3046
- --ok: #86efac;
3047
- --ok-soft: #14241b;
3048
- --warn: #fde68a;
3049
- --warn-soft: #2a2410;
3050
- --err: #ffaaaa;
3051
- --err-soft: #2c1516;
3052
- --shadow: none;
3255
+ --bg: #0c0e14;
3256
+ --bg-elev: #151821;
3257
+ --bg-muted: #20232e;
3258
+ --bg-inset: #11141c;
3259
+ --line: #2b303d;
3260
+ --line-strong: #414858;
3261
+ --ink: #f5f7fa;
3262
+ --muted: #b6bdc9;
3263
+ --faint: #8d96a7;
3264
+ --accent: #9e77ed;
3265
+ --accent-hover: #b692f6;
3266
+ --accent-ink: #ffffff;
3267
+ --accent-soft: #2b2142;
3268
+ --ok: #75e0a7;
3269
+ --ok-soft: #102a20;
3270
+ --warn: #fec84b;
3271
+ --warn-soft: #302611;
3272
+ --err: #fda29b;
3273
+ --err-soft: #321817;
3274
+ --code-key: #c3a6ff;
3275
+ --code-string: #75e0a7;
3276
+ --code-number: #84adff;
3277
+ --code-boolean: #f9a8d4;
3278
+ --code-null: #98a2b3;
3279
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3280
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3281
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3053
3282
  }
3054
3283
  }
3055
3284
  /* Fill the viewport, then grow with the content so the background covers the scroll. */
@@ -3067,13 +3296,17 @@ var renderAdminDocument = (service) => {
3067
3296
  padding-right: env(safe-area-inset-right);
3068
3297
  -webkit-text-size-adjust: 100%;
3069
3298
  }
3070
- :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
3299
+ ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
3300
+ :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
3301
+ button, input, select, textarea { transition: border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease; }
3302
+ button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }
3071
3303
  .app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
3072
3304
  header.top {
3073
- position: sticky; top: 0; z-index: 5;
3305
+ position: sticky; top: 0; z-index: 20;
3074
3306
  display: flex; align-items: center; gap: 12px;
3075
- min-height: var(--header); padding: 10px 16px;
3076
- background: var(--bg-elev);
3307
+ min-height: var(--header); padding: 12px 20px;
3308
+ background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
3309
+ backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
3077
3310
  border-bottom: 1px solid var(--line);
3078
3311
  min-width: 0; max-width: 100%;
3079
3312
  }
@@ -3081,12 +3314,21 @@ var renderAdminDocument = (service) => {
3081
3314
  display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
3082
3315
  min-width: 0; max-width: 100%; margin-right: auto;
3083
3316
  }
3084
- .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
3085
- .brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
3317
+ .brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
3318
+ .brand-mark {
3319
+ width: 38px; height: 38px; display: grid; place-items: center; flex: none;
3320
+ border-radius: 11px; color: #fff;
3321
+ background: linear-gradient(145deg, #7f56d9 0%, #53389e 100%);
3322
+ box-shadow: 0 6px 16px rgb(105 65 198 / 0.24), inset 0 1px 0 rgb(255 255 255 / 0.25);
3323
+ }
3324
+ .brand-mark svg { width: 22px; height: 22px; }
3325
+ .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; line-height: 1.25; }
3326
+ .brand-id strong { font-size: 15px; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
3086
3327
  .brand-id span { color: var(--faint); font-size: 12px; }
3087
3328
  .vendor {
3088
3329
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
3089
3330
  min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
3331
+ padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-inset);
3090
3332
  }
3091
3333
  .vendor[hidden] { display: none; }
3092
3334
  /* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
@@ -3098,12 +3340,17 @@ var renderAdminDocument = (service) => {
3098
3340
  .vendor-sep { color: var(--faint); }
3099
3341
  .vendor-link { color: inherit; text-decoration: none; }
3100
3342
  .vendor-link:hover { color: var(--ink); text-decoration: underline; }
3101
- .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
3102
- label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
3343
+ .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
3344
+ .sync-status { align-self: center; display: flex; align-items: center; gap: 6px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3345
+ .sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
3346
+ .sync-status.busy::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
3347
+ label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--faint); }
3103
3348
  label.field input, label.field select, .controls input[type="password"] {
3104
- background-color: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
3105
- padding: 7px 8px; min-height: 36px; line-height: 1.2;
3349
+ background-color: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 9px;
3350
+ padding: 8px 10px; min-height: 38px; line-height: 1.2; box-shadow: var(--shadow-xs);
3106
3351
  }
3352
+ label.field input:hover, label.field select:hover, textarea:hover { border-color: color-mix(in srgb, var(--accent) 38%, var(--line-strong)); }
3353
+ 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; }
3107
3354
  /* A native menu ignores min-height, so Preset rendered about half as tall as
3108
3355
  the text fields in the same form. Paint it like those fields. */
3109
3356
  label.field select {
@@ -3120,12 +3367,20 @@ var renderAdminDocument = (service) => {
3120
3367
  dialog .field > textarea { width: 100%; }
3121
3368
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger, nav.side button { cursor: pointer; }
3122
3369
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
3123
- border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
3124
- background: var(--bg-elev);
3125
- }
3126
- .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
3127
- .btn-quiet { background: transparent; }
3128
- .btn-danger { color: var(--err); }
3370
+ display: inline-flex; align-items: center; justify-content: center; gap: 7px;
3371
+ border-radius: 9px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line-strong);
3372
+ background: var(--bg-elev); color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1;
3373
+ box-shadow: var(--shadow-xs);
3374
+ }
3375
+ .icon-btn { width: 38px; padding: 0; }
3376
+ .icon-btn svg, .btn svg, .btn-primary svg { width: 16px; height: 16px; }
3377
+ .icon-btn:hover, .btn:hover { background: var(--bg-muted); border-color: var(--line-strong); }
3378
+ .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; }
3379
+ .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
3380
+ .btn-quiet { background: transparent; border-color: transparent; box-shadow: none; }
3381
+ .btn-quiet:hover { background: var(--bg-muted); }
3382
+ .btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, var(--line)); }
3383
+ .btn-danger:hover, .btn-danger.confirming { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
3129
3384
  /* Held after mouseup. Clearing an empty journal changes nothing on screen,
3130
3385
  so the press itself has to stay visible. */
3131
3386
  .icon-btn:active, .btn:active, .btn-quiet:active, .btn-danger:active, nav.side button:active,
@@ -3141,93 +3396,159 @@ var renderAdminDocument = (service) => {
3141
3396
  flex: 1 0 auto; min-width: 0;
3142
3397
  }
3143
3398
  nav.side {
3144
- border-right: 1px solid var(--line); padding: 12px;
3399
+ position: sticky; top: var(--header); align-self: start; height: calc(100vh - var(--header));
3400
+ border-right: 1px solid var(--line); padding: 18px 12px;
3145
3401
  display: flex; flex-direction: column; gap: 4px;
3146
- background: var(--bg-elev);
3402
+ background: var(--bg-elev); overflow-y: auto;
3147
3403
  }
3404
+ .nav-label { padding: 0 10px 8px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
3148
3405
  nav.side button {
3406
+ position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
3149
3407
  text-align: left; border: 0; background: transparent; border-radius: 9px;
3150
- padding: 9px 10px; min-height: 40px; color: var(--muted);
3151
- }
3152
- nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
3153
- main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
3154
- .view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
3155
- .lede { margin: 0 0 16px; color: var(--muted); }
3156
- .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
3408
+ padding: 9px 10px; min-height: 42px; color: var(--muted); font-size: 13px; font-weight: 550;
3409
+ }
3410
+ nav.side button:hover { background: var(--bg-muted); color: var(--ink); }
3411
+ nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
3412
+ 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); }
3413
+ .nav-icon { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
3414
+ .nav-icon svg { width: 18px; height: 18px; }
3415
+ main { padding: 32px clamp(20px, 4vw, 48px) 64px; max-width: 1320px; width: 100%; min-width: 0; }
3416
+ main[aria-busy="true"] .view { opacity: 0.62; }
3417
+ .view { animation: view-in 180ms ease-out; }
3418
+ .view[hidden] { display: none; }
3419
+ .view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
3420
+ .view h2 { margin: 0 0 5px; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -0.035em; }
3421
+ .view h3 { margin: 24px 0 10px; font-size: 15px; letter-spacing: -0.01em; }
3422
+ .lede { margin: 0; color: var(--muted); max-width: 72ch; font-size: 14px; }
3423
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 14px; }
3157
3424
  .card {
3158
3425
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
3159
- padding: 14px 16px; box-shadow: var(--shadow);
3426
+ padding: 18px; box-shadow: var(--shadow-sm);
3160
3427
  }
3161
- .card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
3162
- .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
3428
+ .stat-card { position: relative; overflow: hidden; }
3429
+ .stat-card::after { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, var(--accent), transparent 78%); opacity: 0.7; }
3430
+ .card .k { color: var(--faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
3431
+ .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; }
3163
3432
  .card .v .clock-time { font-size: 14px; color: var(--muted); }
3164
- .split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
3433
+ .section-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: hidden; }
3434
+ .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
3435
+ .section-title h3 { margin: 0; }
3436
+ .split { display: grid; grid-template-columns: minmax(0, 250px) minmax(0, 1fr); gap: 18px; align-items: start; }
3437
+ #collections { padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3165
3438
  .collection {
3166
3439
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
3167
- border-radius: 10px; padding: 8px 10px; min-height: 44px;
3440
+ border-radius: 9px; padding: 10px 11px; min-height: 48px; color: var(--ink); cursor: pointer;
3168
3441
  }
3169
- .collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
3442
+ .collection:hover { background: var(--bg-muted); }
3443
+ .collection[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 18%, var(--line)); color: var(--accent); }
3170
3444
  .collection small { display: block; color: var(--faint); }
3171
3445
  .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
3172
- .chip {
3173
- font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
3174
- border-radius: 999px; padding: 4px 8px;
3175
- }
3446
+ .chip { font-family: var(--mono); font-size: 11px; background: var(--bg-muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; }
3176
3447
  .chip i { color: var(--faint); font-style: normal; }
3177
3448
  .sql-layout {
3178
3449
  display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3179
3450
  }
3180
- .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3181
- .sql-tables button { text-align: left; }
3451
+ .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); }
3452
+ .sql-tables button { text-align: left; border: 0; border-radius: 8px; padding: 9px 10px; background: transparent; color: var(--muted); cursor: pointer; }
3453
+ .sql-tables button:hover, .sql-tables button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
3182
3454
  .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
3183
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
3184
- th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
3185
- th { color: var(--faint); font-weight: 600; font-size: 12px; }
3455
+ .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); }
3456
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
3457
+ th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
3458
+ th { color: var(--faint); background: var(--bg-inset); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: 0.045em; }
3459
+ tbody tr:last-child td { border-bottom: 0; }
3186
3460
  tr.clickable { cursor: pointer; }
3187
- tr.clickable:hover { background: var(--bg-muted); }
3461
+ tr.clickable:hover { background: var(--accent-soft); }
3188
3462
  pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
3189
3463
  pre {
3190
3464
  margin: 0; white-space: pre-wrap; word-break: break-word;
3191
- background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
3192
- }
3193
- .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
3465
+ background: var(--bg-inset); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 12px; line-height: 1.65;
3466
+ }
3467
+ .json-key { color: var(--code-key); }
3468
+ .json-string { color: var(--code-string); }
3469
+ .json-number { color: var(--code-number); }
3470
+ .json-boolean { color: var(--code-boolean); }
3471
+ .json-null { color: var(--code-null); font-style: italic; }
3472
+ .json-inline { display: block; max-width: 44rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
3473
+ .json-view { position: relative; max-height: 26rem; overflow: auto; }
3474
+ .json-editor { position: relative; min-height: 190px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg-inset); overflow: hidden; }
3475
+ .json-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
3476
+ .json-editor.invalid { border-color: var(--err); }
3477
+ .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; }
3478
+ .json-editor pre { position: absolute; inset: 0; pointer-events: none; background: transparent; }
3479
+ .json-editor textarea { position: relative; z-index: 1; resize: vertical; background: transparent; color: transparent; caret-color: var(--ink); -webkit-text-fill-color: transparent; }
3480
+ .json-editor textarea::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
3481
+ .editor-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; }
3482
+ .json-status { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 11px; }
3483
+ .json-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
3484
+ .json-status.invalid { color: var(--err); }
3485
+ .format-json { border: 0; padding: 3px 5px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 650; cursor: pointer; }
3486
+ .row-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 14px 0; }
3194
3487
  .banner {
3195
- display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
3196
- background: var(--err-soft); color: var(--err);
3197
- }
3198
- .banner.show { display: block; }
3199
- .empty { color: var(--muted); padding: 24px 8px; }
3488
+ display: none; position: sticky; top: calc(var(--header) + 12px); z-index: 15;
3489
+ align-items: center; gap: 10px; margin: 0 0 16px; padding: 11px 12px 11px 14px;
3490
+ border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line)); border-radius: 10px;
3491
+ background: var(--err-soft); color: var(--err); box-shadow: var(--shadow-sm); font-size: 13px;
3492
+ }
3493
+ .banner.show { display: flex; }
3494
+ .banner span { flex: 1; }
3495
+ .banner button { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: currentColor; cursor: pointer; }
3496
+ .banner button:hover { background: color-mix(in srgb, var(--err) 10%, transparent); }
3497
+ .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); }
3200
3498
  dialog {
3201
- border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
3202
- color: var(--ink); width: min(640px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: none;
3203
- }
3204
- dialog::backdrop { background: rgb(20 19 17 / 0.45); }
3205
- dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
3499
+ border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--bg-elev);
3500
+ color: var(--ink); width: min(720px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: var(--shadow-lg);
3501
+ }
3502
+ dialog[open] { animation: dialog-in 160ms ease-out; }
3503
+ dialog::backdrop { background: rgb(12 14 20 / 0.58); backdrop-filter: blur(3px); }
3504
+ dialog form, .dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
3505
+ .dialog-heading { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
3506
+ .dialog-heading strong { font-size: 18px; letter-spacing: -0.02em; }
3507
+ .dialog-heading span { color: var(--muted); font-size: 12px; }
3206
3508
  textarea {
3207
3509
  width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
3208
3510
  border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
3209
3511
  font-family: var(--mono); font-size: 12px;
3210
3512
  }
3211
- .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
3212
- .badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
3513
+ .dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 4px; }
3514
+ .dialog-actions .btn-danger { margin-right: auto; }
3515
+ .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); }
3213
3516
  .badge.ok { background: var(--ok-soft); color: var(--ok); }
3214
3517
  .badge.warn { background: var(--warn-soft); color: var(--warn); }
3215
3518
  .status-2 { color: var(--ok); }
3216
3519
  .status-4, .status-5, .status-0 { color: var(--err); }
3217
3520
  .stack { display: flex; flex-direction: column; gap: 12px; }
3521
+ .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
3522
+ .form-grid .wide { grid-column: span 2; }
3218
3523
  .route {
3219
- display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
3220
- padding: 8px 0; border-bottom: 1px solid var(--line);
3221
- }
3222
- .method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
3524
+ display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 10px; align-items: center;
3525
+ padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-elev);
3526
+ }
3527
+ .route:first-child { border-radius: var(--radius) var(--radius) 0 0; }
3528
+ .route:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
3529
+ .route-tools { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
3530
+ .route-tools .field { flex: 1; }
3531
+ .route-tools input { width: 100%; }
3532
+ .route-count { padding-bottom: 10px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3533
+ #route-list { max-height: 34rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-xs); }
3534
+ .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; }
3535
+ @keyframes view-in { from { transform: translateY(3px); } to { transform: translateY(0); } }
3536
+ @keyframes dialog-in { from { transform: translateY(8px) scale(0.99); } to { transform: translateY(0) scale(1); } }
3537
+ @keyframes pulse { 50% { opacity: 0.45; } }
3538
+ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
3539
+ @media (forced-colors: active) { .json-editor pre { display: none; } .json-editor textarea { color: CanvasText; -webkit-text-fill-color: CanvasText; } }
3223
3540
  @media (max-width: 800px) {
3541
+ :root { --header: 0px; }
3224
3542
  header.top {
3225
- align-items: stretch; flex-direction: column;
3226
- padding-top: max(10px, env(safe-area-inset-top));
3543
+ position: relative; align-items: stretch; flex-direction: column;
3544
+ padding: max(12px, env(safe-area-inset-top)) 14px 12px;
3227
3545
  }
3228
3546
  input, select, textarea { font-size: 16px; }
3229
3547
  .brand, .vendor, .controls { width: 100%; }
3548
+ .brand { gap: 10px; }
3549
+ .vendor { order: 2; border-radius: 9px; }
3230
3550
  label.field, label.field select, label.field input { flex: 1; min-width: 0; }
3551
+ .sync-status { display: none; }
3231
3552
  /* The layout fills the screen. A single-column grid stretches every auto
3232
3553
  row, so the tab bar grew with the leftover height and the buttons floated
3233
3554
  in the middle of it. The bar stays one row; the page below takes the rest. */
@@ -3237,14 +3558,23 @@ var renderAdminDocument = (service) => {
3237
3558
  align-content: start;
3238
3559
  }
3239
3560
  nav.side {
3240
- align-self: start; height: auto;
3561
+ position: sticky; top: 0; z-index: 12; align-self: start; height: auto;
3241
3562
  flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
3242
3563
  border-right: 0; border-bottom: 1px solid var(--line);
3243
- padding: 8px;
3564
+ padding: 8px; box-shadow: var(--shadow-xs);
3244
3565
  }
3245
- nav.side button { white-space: nowrap; flex: none; }
3566
+ .nav-label { display: none; }
3567
+ nav.side button { width: auto; white-space: nowrap; flex: none; }
3568
+ nav.side button[aria-current="true"]::before { inset: auto 9px -8px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
3246
3569
  .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3247
- main { padding: 14px; }
3570
+ .form-grid { grid-template-columns: minmax(0, 1fr); }
3571
+ .form-grid .wide { grid-column: auto; }
3572
+ main { padding: 22px 14px 48px; }
3573
+ .view-head { margin-bottom: 18px; }
3574
+ .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
3575
+ .card { padding: 14px; }
3576
+ .card .v { font-size: 20px; }
3577
+ .table-shell { border: 0; background: transparent; box-shadow: none; overflow: visible; }
3248
3578
  table, thead, tbody, tr, th, td { display: block; }
3249
3579
  thead { display: none; }
3250
3580
  tr {
@@ -3259,50 +3589,63 @@ var renderAdminDocument = (service) => {
3259
3589
  .route { grid-template-columns: 72px 1fr; }
3260
3590
  .route button { grid-column: 1 / -1; }
3261
3591
  }
3592
+ @media (max-width: 460px) {
3593
+ .controls label.field { min-width: calc(50% - 4px); }
3594
+ .controls .icon-btn, .controls .btn { flex: 1; }
3595
+ .grid { grid-template-columns: minmax(0, 1fr); }
3596
+ .dialog-actions { flex-wrap: wrap; }
3597
+ .dialog-actions button { flex: 1; }
3598
+ .dialog-actions .btn-danger { flex-basis: 100%; margin-right: 0; }
3599
+ }
3262
3600
  </style>
3263
3601
  </head>
3264
3602
  <body>
3265
3603
  <div class="app" data-service="${name}" data-mockingbird-admin>
3266
3604
  <header class="top">
3267
3605
  <div class="brand">
3268
- <div class="brand-id">
3269
- <strong>${name}</strong>
3270
- <span>Admin</span>
3606
+ <div class="brand-lockup">
3607
+ <div class="brand-mark" aria-hidden="true">
3608
+ <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>
3609
+ </div>
3610
+ <div class="brand-id">
3611
+ <strong>${name}</strong>
3612
+ <span>Mock admin</span>
3613
+ </div>
3271
3614
  </div>
3272
3615
  <div class="vendor" id="vendor" hidden></div>
3273
3616
  </div>
3274
3617
  <div class="controls">
3618
+ <span class="sync-status" id="sync-status" role="status" aria-live="polite">Ready</span>
3275
3619
  <label class="field">Namespace
3276
3620
  <select id="namespace" aria-label="Namespace"></select>
3277
3621
  </label>
3278
3622
  <label class="field">Admin key
3279
3623
  <input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
3280
3624
  </label>
3281
- <button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
3282
- <button class="btn" id="refresh" type="button">Refresh</button>
3625
+ <button class="icon-btn" id="theme" type="button" aria-label="Use dark theme" title="Use dark theme"></button>
3626
+ <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>
3283
3627
  </div>
3284
3628
  </header>
3285
3629
  <div class="layout">
3286
3630
  <nav class="side" id="nav" aria-label="Admin sections">
3287
- <button type="button" data-view="overview" aria-current="true">Overview</button>
3288
- <button type="button" data-view="state">State</button>
3289
- <button type="button" data-view="clock">Clock</button>
3290
- <button type="button" data-view="faults">Faults</button>
3291
- <button type="button" data-view="journal">Journal</button>
3292
- <button type="button" data-view="routes">Routes</button>
3631
+ <span class="nav-label">Workspace</span>
3632
+ <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>
3633
+ <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>
3634
+ <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>
3635
+ <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>
3636
+ <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>
3637
+ <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>
3293
3638
  </nav>
3294
3639
  <main id="views">
3295
- <p class="banner" id="banner" role="alert"></p>
3640
+ <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>
3296
3641
  <section class="view" id="view-overview">
3297
- <h2>Overview</h2>
3298
- <p class="lede">Health, clock, and the collections this namespace is holding.</p>
3642
+ <div class="view-head"><div><h2>Overview</h2><p class="lede">Health, clock, and the collections this namespace is holding.</p></div></div>
3299
3643
  <div class="grid" id="overview-cards"></div>
3300
3644
  <h3>Recent requests</h3>
3301
3645
  <div id="overview-requests"></div>
3302
3646
  </section>
3303
3647
  <section class="view" id="view-state" hidden>
3304
- <h2>State</h2>
3305
- <p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
3648
+ <div class="view-head"><div><h2>State</h2><p class="lede">Inspect and edit every collection in this namespace.</p></div></div>
3306
3649
  <div class="split">
3307
3650
  <div id="collections"></div>
3308
3651
  <div>
@@ -3315,8 +3658,7 @@ var renderAdminDocument = (service) => {
3315
3658
  </div>
3316
3659
  </section>
3317
3660
  <section class="view" id="view-clock" hidden>
3318
- <h2>Clock</h2>
3319
- <p class="lede">The clock every timestamp in this mock reads.</p>
3661
+ <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>
3320
3662
  <div class="card" id="clock-readout"></div>
3321
3663
  <div class="row-actions">
3322
3664
  <button class="btn" type="button" data-advance="60000">+1m</button>
@@ -3335,21 +3677,22 @@ var renderAdminDocument = (service) => {
3335
3677
  </form>
3336
3678
  </section>
3337
3679
  <section class="view" id="view-faults" hidden>
3338
- <h2>Faults</h2>
3339
- <p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
3680
+ <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>
3340
3681
  <form id="fault-form" class="card stack">
3341
- <label class="field">Preset
3342
- <select id="fault-preset"><option value="">Custom rule</option></select>
3343
- </label>
3344
- <label class="field">Status
3345
- <input id="fault-status" inputmode="numeric" placeholder="503">
3346
- </label>
3347
- <label class="field">Path prefix
3348
- <input id="fault-path" placeholder="/v1">
3349
- </label>
3350
- <label class="field">Method
3351
- <input id="fault-method" placeholder="GET">
3352
- </label>
3682
+ <div class="form-grid">
3683
+ <label class="field wide">Preset
3684
+ <select id="fault-preset"><option value="">Custom rule</option></select>
3685
+ </label>
3686
+ <label class="field">Status
3687
+ <input id="fault-status" inputmode="numeric" placeholder="503">
3688
+ </label>
3689
+ <label class="field wide">Path prefix
3690
+ <input id="fault-path" placeholder="/v1">
3691
+ </label>
3692
+ <label class="field">Method
3693
+ <input id="fault-method" placeholder="GET">
3694
+ </label>
3695
+ </div>
3353
3696
  <div class="dialog-actions">
3354
3697
  <button class="btn-primary" type="submit">Add fault</button>
3355
3698
  <button class="btn-danger" id="fault-clear" type="button">Clear all</button>
@@ -3358,26 +3701,31 @@ var renderAdminDocument = (service) => {
3358
3701
  <div id="fault-list"></div>
3359
3702
  </section>
3360
3703
  <section class="view" id="view-journal" hidden>
3361
- <h2>Journal</h2>
3362
- <p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
3363
- <div class="row-actions">
3364
- <button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
3365
- </div>
3704
+ <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>
3366
3705
  <div id="journal"></div>
3367
3706
  </section>
3368
3707
  <section class="view" id="view-routes" hidden>
3369
- <h2>Routes</h2>
3370
- <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>
3708
+ <div class="view-head"><div><h2>Routes</h2><p class="lede">Explore shared controls and service-specific admin endpoints.</p></div></div>
3709
+ <div class="route-tools">
3710
+ <label class="field">Filter routes
3711
+ <input id="route-search" type="search" placeholder="Method, path, or extension" autocomplete="off">
3712
+ </label>
3713
+ <span class="route-count" id="route-count"></span>
3714
+ </div>
3371
3715
  <div id="route-list"></div>
3372
- <form id="route-form" class="card stack">
3716
+ <form id="route-form" class="card stack" style="margin-top: 18px">
3373
3717
  <strong id="route-title">Select a route</strong>
3374
3718
  <label class="field">JSON body
3375
- <textarea id="route-body" placeholder="{ }"></textarea>
3719
+ <div class="json-editor" id="route-editor" hidden>
3720
+ <pre aria-hidden="true"><code id="route-highlight"></code></pre>
3721
+ <textarea id="route-body" placeholder="{ }" spellcheck="false" aria-describedby="route-json-status" disabled></textarea>
3722
+ </div>
3723
+ <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>
3376
3724
  </label>
3377
3725
  <div class="dialog-actions">
3378
- <button class="btn-primary" type="submit">Send</button>
3726
+ <button class="btn-primary" id="route-send" type="submit" disabled>Send request</button>
3379
3727
  </div>
3380
- <pre id="route-result">Response will show here.</pre>
3728
+ <pre class="json-view" id="route-result"><code>Response will show here.</code></pre>
3381
3729
  </form>
3382
3730
  </section>
3383
3731
  </main>
@@ -3385,12 +3733,16 @@ var renderAdminDocument = (service) => {
3385
3733
  </div>
3386
3734
  <dialog id="editor">
3387
3735
  <form method="dialog" id="editor-form">
3388
- <strong id="editor-title">Record</strong>
3736
+ <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>
3389
3737
  <label class="field">Id
3390
3738
  <input id="editor-id" required>
3391
3739
  </label>
3392
3740
  <label class="field">JSON value
3393
- <textarea id="editor-value"></textarea>
3741
+ <div class="json-editor" id="record-editor">
3742
+ <pre aria-hidden="true"><code id="editor-highlight"></code></pre>
3743
+ <textarea id="editor-value" spellcheck="false" aria-describedby="editor-json-status"></textarea>
3744
+ </div>
3745
+ <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>
3394
3746
  </label>
3395
3747
  <div class="dialog-actions">
3396
3748
  <button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
@@ -3432,8 +3784,8 @@ var describeExtension = (extension) => {
3432
3784
  ...extension.script !== void 0 ? { script: extension.script } : {}
3433
3785
  };
3434
3786
  };
3435
- var adminUiRoutes = (service, ui) => {
3436
- const shell = () => renderAdminDocument(service);
3787
+ var adminUiRoutes = (service, ui, adminPrefix = ADMIN_PREFIX) => {
3788
+ const shell = () => renderAdminDocument(service, adminPrefix);
3437
3789
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
3438
3790
  return {
3439
3791
  "GET /ui": () => htmlResponse(document3()),
@@ -4124,7 +4476,7 @@ var stateAdminRoutes = (routes) => {
4124
4476
  };
4125
4477
 
4126
4478
  // ../core/dist/version.js
4127
- var PACKAGE_VERSION = true ? "1.8.0" : UNRELEASED_VERSION;
4479
+ var PACKAGE_VERSION = true ? "2.0.0" : UNRELEASED_VERSION;
4128
4480
 
4129
4481
  // ../core/dist/signing.js
4130
4482
  var encoder = new TextEncoder();
@@ -4132,7 +4484,10 @@ var toHex = (bytes) => [...bytes instanceof Uint8Array ? bytes : new Uint8Array(
4132
4484
  var sha = async (algorithm, input) => toHex(await crypto.subtle.digest(algorithm, typeof input === "string" ? encoder.encode(input) : input));
4133
4485
 
4134
4486
  // ../core/dist/webhooks.js
4135
- var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
4487
+ var json4 = (status, body) => new Response(JSON.stringify(body), {
4488
+ status,
4489
+ headers: { "content-type": "application/json; charset=utf-8" }
4490
+ });
4136
4491
  var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
4137
4492
  var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4138
4493
  var parseEndpoint = (value) => {
@@ -4240,7 +4595,6 @@ var AT_HEADER = "x-mockingbird-at";
4240
4595
  var CHECKPOINT_HEADER = "x-mockingbird-checkpoint";
4241
4596
  var DEFAULT_NAMESPACE = "default";
4242
4597
  var NAMESPACE_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
4243
- var PATH_PREFIX = /^\/ns\/([^/]+)(\/.*)?$/;
4244
4598
  var BRANCH_PATTERN2 = /^[A-Za-z0-9_.-]{1,64}$/;
4245
4599
  var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
4246
4600
  var effects = /* @__PURE__ */ new WeakMap();
@@ -4281,6 +4635,22 @@ var operationMatcher = (document3) => {
4281
4635
  return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
4282
4636
  };
4283
4637
  var createRuntime = (options) => {
4638
+ const adminPrefix = resolveAdminPrefix(options.adminPrefix);
4639
+ const internalPaths = Object.entries(options.document?.paths ?? {}).filter(([, item]) => item["x-mockingbird-internal"] === true).map(([path]) => path);
4640
+ for (const path of internalPaths) {
4641
+ if (!path.startsWith(`${ADMIN_PREFIX}/blobs/`))
4642
+ throw new Error(`internal transport ${path} must live under ${ADMIN_PREFIX}/blobs/`);
4643
+ }
4644
+ assertAdminPrefixAvailable(adminPrefix, Object.keys(options.document?.paths ?? {}).filter((path) => !internalPaths.includes(path)));
4645
+ const internalMatch = (path) => {
4646
+ for (const pattern of internalPaths) {
4647
+ const actual = path.split("/");
4648
+ const expected = pattern.split("/");
4649
+ if (actual.length === expected.length && expected.every((part, i) => part.startsWith("{") || part === actual[i]))
4650
+ return pattern;
4651
+ }
4652
+ return void 0;
4653
+ };
4284
4654
  assertAdminUi(options.adminUi);
4285
4655
  const sqlite = bootSqlite(options.sqlite);
4286
4656
  const clock = options.clock ?? createClock();
@@ -4326,6 +4696,7 @@ var createRuntime = (options) => {
4326
4696
  const created = options.create({
4327
4697
  namespace: storageNamespace(key),
4328
4698
  publicNamespace,
4699
+ adminPrefix,
4329
4700
  sqlite,
4330
4701
  clock: namespaceClock(publicNamespace),
4331
4702
  rng: createdContextRng
@@ -4558,10 +4929,10 @@ var createRuntime = (options) => {
4558
4929
  namespaceClock,
4559
4930
  namespaceOf(request) {
4560
4931
  const url = new URL(request.url);
4561
- const prefixed = PATH_PREFIX.exec(url.pathname);
4932
+ const prefixed = matchNamespacePath(url.pathname, adminPrefix);
4562
4933
  const selected = request.headers.get(NAMESPACE_HEADER) ?? (prefixed ? decodeURIComponent(prefixed[1]) : void 0);
4563
4934
  const path = prefixed ? prefixed[2] ?? "/" : url.pathname;
4564
- if (path === "/__admin" || path.startsWith("/__admin/"))
4935
+ if (isAdminPath(path, adminPrefix))
4565
4936
  return url.searchParams.get("namespace") ?? selected ?? DEFAULT_NAMESPACE;
4566
4937
  if (selected !== void 0)
4567
4938
  return selected;
@@ -4627,7 +4998,7 @@ var createRuntime = (options) => {
4627
4998
  state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
4628
4999
  fetch: async (incoming) => {
4629
5000
  let request = incoming;
4630
- const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
5001
+ const prefixed = matchNamespacePath(new URL(request.url).pathname, adminPrefix);
4631
5002
  if (prefixed) {
4632
5003
  const url2 = new URL(request.url);
4633
5004
  url2.pathname = prefixed[2] ?? "/";
@@ -4643,7 +5014,15 @@ var createRuntime = (options) => {
4643
5014
  signal: request.signal
4644
5015
  });
4645
5016
  }
4646
- let namespace = control.namespaceOf(request);
5017
+ const internalUrl = new URL(request.url);
5018
+ const internalPath = isAdminPath(internalUrl.pathname, adminPrefix) ? `${ADMIN_PREFIX}${internalUrl.pathname.slice(adminPrefix.length)}` : "";
5019
+ const internal = internalMatch(internalPath);
5020
+ const obsoleteInternalPath = adminPrefix !== ADMIN_PREFIX && internalMatch(internalUrl.pathname) && !internal;
5021
+ if (internal) {
5022
+ internalUrl.pathname = internalPath;
5023
+ request = new Request(internalUrl, request);
5024
+ }
5025
+ let namespace = internal ? internalUrl.searchParams.get("namespace") ?? control.namespaceOf(request) : control.namespaceOf(request);
4647
5026
  if (!request.headers.has(NAMESPACE_HEADER) && options.credential) {
4648
5027
  const credential = options.credential(request);
4649
5028
  const mapped = credential !== void 0 ? credentials.get(credential) : void 0;
@@ -4663,7 +5042,9 @@ var createRuntime = (options) => {
4663
5042
  return copy;
4664
5043
  }
4665
5044
  };
4666
- const handled = await control.handle(request);
5045
+ if (obsoleteInternalPath)
5046
+ return stamp(adminFail(404, "internal transport is only available under adminPrefix"));
5047
+ const handled = internal ? void 0 : await control.handle(request);
4667
5048
  if (handled)
4668
5049
  return stamp(handled);
4669
5050
  const started = monotonicNow();
@@ -4704,7 +5085,7 @@ var createRuntime = (options) => {
4704
5085
  type: "mockingbird_admin",
4705
5086
  message: `${NAMESPACE_HEADER} must match ${NAMESPACE_PATTERN}`
4706
5087
  }
4707
- }), { status: 400, headers: { "content-type": "application/json" } }));
5088
+ }), { status: 400, headers: { "content-type": "application/json; charset=utf-8" } }));
4708
5089
  }
4709
5090
  if (!BRANCH_PATTERN2.test(selectedBranch)) {
4710
5091
  log(400);
@@ -4821,15 +5202,16 @@ var createRuntime = (options) => {
4821
5202
  ...options.admin?.(runtime) ?? {},
4822
5203
  // Shell routes win a colliding key. Fault presets are one of them: the admin page
4823
5204
  // maps `presets`, and a service route must not replace that list with a record.
4824
- ...options.presets ? presetRoutes(options.presets, runtime) : {},
5205
+ ...options.presets ? presetRoutes(options.presets, runtime, adminPrefix) : {},
4825
5206
  ...stateAdminRoutes({
4826
5207
  open: stateScope,
4827
5208
  afterWrite: (namespace) => {
4828
5209
  checkpoint(namespace, "main");
4829
5210
  }
4830
5211
  }),
4831
- ...adminUiRoutes(options.name, options.adminUi)
5212
+ ...adminUiRoutes(options.name, options.adminUi, adminPrefix)
4832
5213
  },
5214
+ adminPrefix,
4833
5215
  adminKey: options.adminKey
4834
5216
  });
4835
5217
  return defineMock(runtime);
@@ -4843,7 +5225,10 @@ var mutableResponse = (response) => {
4843
5225
  return new Response(response.body, response);
4844
5226
  }
4845
5227
  };
4846
- var adminJson = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
5228
+ var adminJson = (status, body) => new Response(JSON.stringify(body), {
5229
+ status,
5230
+ headers: { "content-type": "application/json; charset=utf-8" }
5231
+ });
4847
5232
  var adminFail = (status, message) => adminJson(status, { error: { type: "mockingbird_admin", message } });
4848
5233
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4849
5234
  var credentialRoutes = (registry) => ({
@@ -4895,7 +5280,7 @@ var credentialRoutes = (registry) => ({
4895
5280
  return adminJson(200, { status: "ok" });
4896
5281
  }
4897
5282
  });
4898
- var presetRoutes = (presets, runtime) => ({
5283
+ var presetRoutes = (presets, runtime, adminPrefix) => ({
4899
5284
  "GET /faults/presets": () => {
4900
5285
  const body = {
4901
5286
  presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
@@ -4905,7 +5290,7 @@ var presetRoutes = (presets, runtime) => ({
4905
5290
  "POST /faults/presets/:name": ({ params, body, namespace }) => {
4906
5291
  const name = params.name;
4907
5292
  if (!presets[name])
4908
- return adminFail(404, `no fault preset ${name}; GET /__admin/faults/presets`);
5293
+ return adminFail(404, `no fault preset ${name}; GET ${adminPrefix}/faults/presets`);
4909
5294
  const overrides = isObject(body) ? body : {};
4910
5295
  return adminJson(201, { preset: name, rules: runtime.applyPreset(name, namespace, overrides) });
4911
5296
  }
@@ -6821,6 +7206,7 @@ var createRuntime2 = (options = {}) => {
6821
7206
  ...options.sqlite ? { sqlite: options.sqlite } : {},
6822
7207
  ...options.clock ? { clock: options.clock } : {},
6823
7208
  ...options.seed !== void 0 ? { seed: options.seed } : {},
7209
+ ...options.adminPrefix !== void 0 ? { adminPrefix: options.adminPrefix } : {},
6824
7210
  ...options.adminKey !== void 0 ? { adminKey: options.adminKey } : {},
6825
7211
  ...options.onLog ? { onLog: options.onLog } : {},
6826
7212
  credential: accessKeyCredential,
@@ -7344,6 +7730,7 @@ var BedrockAPI = class {
7344
7730
 
7345
7731
  export {
7346
7732
  createClock,
7733
+ resolveAdminPrefix,
7347
7734
  parseDuration,
7348
7735
  document2 as document,
7349
7736
  operationIds,
@@ -7376,4 +7763,4 @@ export {
7376
7763
  titanEmbedding,
7377
7764
  BedrockAPI
7378
7765
  };
7379
- //# sourceMappingURL=chunk-BDXV2KJB.js.map
7766
+ //# sourceMappingURL=chunk-LYWMNREM.js.map