@crvouga/mockingbird-service-livekit 1.3.0 → 1.5.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.
@@ -38,30 +38,30 @@ var createClock = (source = Date.now) => {
38
38
  var Collection = class {
39
39
  sqlite;
40
40
  namespace;
41
- name;
42
- constructor(sqlite, namespace, name) {
41
+ collectionName;
42
+ constructor(sqlite, namespace, collectionName) {
43
43
  this.sqlite = sqlite;
44
44
  this.namespace = namespace;
45
- this.name = name;
45
+ this.collectionName = collectionName;
46
46
  }
47
47
  bumpCollectionSeq() {
48
- const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.name);
48
+ const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.collectionName);
49
49
  const next = (row?.value ?? 0) + 1;
50
50
  this.sqlite.prepare(`INSERT INTO mockingbird_sequences (namespace, name, kind, value) VALUES (?, ?, 'collection', ?)
51
- ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.name, next);
51
+ ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.collectionName, next);
52
52
  return next;
53
53
  }
54
54
  nextSequence() {
55
55
  return this.sqlite.transaction(() => this.bumpCollectionSeq());
56
56
  }
57
57
  get(id) {
58
- const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.name, id);
58
+ const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
59
59
  if (!row)
60
60
  return void 0;
61
61
  return JSON.parse(row.value).value;
62
62
  }
63
63
  has(id) {
64
- const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.name, id);
64
+ const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
65
65
  return row !== void 0;
66
66
  }
67
67
  /** Insert a new record, assigning it the next sequence number. */
@@ -71,32 +71,32 @@ var Collection = class {
71
71
  const stored = { seq, value };
72
72
  this.sqlite.prepare(`INSERT INTO mockingbird_records (namespace, collection, id, seq, value)
73
73
  VALUES (?, ?, ?, ?, ?)
74
- ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.name, id, seq, JSON.stringify(stored));
74
+ ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.collectionName, id, seq, JSON.stringify(stored));
75
75
  return stored;
76
76
  });
77
77
  }
78
78
  /** Replace an existing record's value, keeping its position. */
79
79
  update(id, value) {
80
80
  return this.sqlite.transaction(() => {
81
- const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.name, id);
81
+ const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
82
82
  if (!row)
83
83
  return void 0;
84
84
  const stored = { seq: row.seq, value };
85
- this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.name, id);
85
+ this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.collectionName, id);
86
86
  return stored;
87
87
  });
88
88
  }
89
89
  delete(id) {
90
- const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.name, id);
90
+ const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.collectionName, id);
91
91
  return result.changes > 0;
92
92
  }
93
93
  /** How many records the collection holds, without reading them. */
94
94
  count() {
95
- const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.name);
95
+ const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.collectionName);
96
96
  return Number(row?.n ?? 0);
97
97
  }
98
98
  list(options = {}) {
99
- const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.name);
99
+ const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.collectionName);
100
100
  const out = [];
101
101
  for (const row of rows) {
102
102
  const stored = JSON.parse(row.value);
@@ -353,16 +353,18 @@ var createControlPlane = (context) => {
353
353
  uptimeMs: context.wallNow() - context.startedAt,
354
354
  clock: context.clock.state(),
355
355
  namespaces: context.namespaces().length,
356
+ adminUi: `${ADMIN_PREFIX}/ui`,
356
357
  ...context.describe()
357
358
  });
358
359
  }
359
360
  if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
360
361
  return void 0;
361
362
  }
362
- if (context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
363
+ const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
364
+ const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
365
+ if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
363
366
  return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
364
367
  }
365
- const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
366
368
  for (const route of routes) {
367
369
  if (route.method !== request.method)
368
370
  continue;
@@ -531,10 +533,10 @@ var OpenAPIReferenceError = class extends Error {
531
533
  };
532
534
  var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
533
535
  var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
534
- var resolveRef = (document2, ref) => {
536
+ var resolveRef = (document3, ref) => {
535
537
  if (!ref.startsWith("#/"))
536
538
  throw new OpenAPIReferenceError(ref);
537
- let cursor = document2;
539
+ let cursor = document3;
538
540
  for (const raw of ref.slice(2).split("/")) {
539
541
  const segment = unescapePointer(raw);
540
542
  if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
@@ -546,14 +548,14 @@ var resolveRef = (document2, ref) => {
546
548
  throw new OpenAPIReferenceError(ref);
547
549
  return cursor;
548
550
  };
549
- var deref = (document2, value) => {
551
+ var deref = (document3, value) => {
550
552
  let current = value;
551
553
  const seen = /* @__PURE__ */ new Set();
552
554
  while (isReference(current)) {
553
555
  if (seen.has(current.$ref))
554
556
  throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
555
557
  seen.add(current.$ref);
556
- current = resolveRef(document2, current.$ref);
558
+ current = resolveRef(document3, current.$ref);
557
559
  }
558
560
  return current;
559
561
  };
@@ -571,36 +573,36 @@ var HTTP_METHODS = [
571
573
  ];
572
574
 
573
575
  // ../../openapi/core/dist/document.js
574
- var mergeParameters = (document2, item, own) => {
576
+ var mergeParameters = (document3, item, own) => {
575
577
  const merged = /* @__PURE__ */ new Map();
576
578
  for (const raw of item.parameters ?? []) {
577
- const parameter = deref(document2, raw);
579
+ const parameter = deref(document3, raw);
578
580
  merged.set(`${parameter.in}:${parameter.name}`, parameter);
579
581
  }
580
582
  for (const raw of own ?? []) {
581
- const parameter = deref(document2, raw);
583
+ const parameter = deref(document3, raw);
582
584
  merged.set(`${parameter.in}:${parameter.name}`, parameter);
583
585
  }
584
586
  return [...merged.values()];
585
587
  };
586
- var listOperations = (document2) => {
588
+ var listOperations = (document3) => {
587
589
  const operations = [];
588
- for (const [path, item] of Object.entries(document2.paths)) {
590
+ for (const [path, item] of Object.entries(document3.paths)) {
589
591
  for (const method of HTTP_METHODS) {
590
592
  const operation = item[method];
591
593
  if (operation?.operationId === void 0)
592
594
  continue;
593
595
  const responses = {};
594
596
  for (const [status, response] of Object.entries(operation.responses)) {
595
- responses[status] = deref(document2, response);
597
+ responses[status] = deref(document3, response);
596
598
  }
597
599
  operations.push({
598
600
  operationId: operation.operationId,
599
601
  method,
600
602
  path,
601
603
  operation,
602
- parameters: mergeParameters(document2, item, operation.parameters),
603
- requestBody: operation.requestBody === void 0 ? void 0 : deref(document2, operation.requestBody),
604
+ parameters: mergeParameters(document3, item, operation.parameters),
605
+ requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
604
606
  responses
605
607
  });
606
608
  }
@@ -961,6 +963,1737 @@ var clearNamespace = (sqlite, namespace) => {
961
963
  });
962
964
  };
963
965
 
966
+ // ../../ui/dist/reset.js
967
+ var CSS_RESET = `*,
968
+ *::before,
969
+ *::after {
970
+ box-sizing: border-box;
971
+ margin: 0;
972
+ padding: 0;
973
+ }
974
+
975
+ * {
976
+ scrollbar-width: thin;
977
+ scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
978
+ }
979
+
980
+ *::-webkit-scrollbar {
981
+ width: 12px;
982
+ height: 12px;
983
+ }
984
+
985
+ *::-webkit-scrollbar-track,
986
+ *::-webkit-scrollbar-corner {
987
+ background: Canvas;
988
+ }
989
+
990
+ *::-webkit-scrollbar-thumb {
991
+ background: color-mix(in srgb, CanvasText 35%, Canvas);
992
+ border: 3px solid Canvas;
993
+ border-radius: 999px;
994
+ }
995
+
996
+ html {
997
+ hanging-punctuation: first allow-end last;
998
+ -webkit-text-size-adjust: none;
999
+ text-size-adjust: none;
1000
+ tab-size: 4;
1001
+ font-family:
1002
+ ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
1003
+ "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
1004
+ font-size: 16px;
1005
+ line-height: 1.5;
1006
+ -webkit-font-smoothing: antialiased;
1007
+ -moz-osx-font-smoothing: grayscale;
1008
+ text-rendering: optimizeLegibility;
1009
+ -webkit-tap-highlight-color: transparent;
1010
+ scroll-behavior: smooth;
1011
+ background: Canvas;
1012
+ color: CanvasText;
1013
+ }
1014
+
1015
+ body {
1016
+ min-height: 100svh;
1017
+ line-height: 1.5;
1018
+ background: Canvas;
1019
+ color: CanvasText;
1020
+ }
1021
+
1022
+ h1 {
1023
+ font-size: 2em;
1024
+ }
1025
+
1026
+ h2 {
1027
+ font-size: 1.5em;
1028
+ }
1029
+
1030
+ h3 {
1031
+ font-size: 1.17em;
1032
+ }
1033
+
1034
+ h4 {
1035
+ font-size: 1em;
1036
+ }
1037
+
1038
+ h5 {
1039
+ font-size: 0.83em;
1040
+ }
1041
+
1042
+ h6 {
1043
+ font-size: 0.67em;
1044
+ }
1045
+
1046
+ h1,
1047
+ h2,
1048
+ h3,
1049
+ h4,
1050
+ h5,
1051
+ h6 {
1052
+ font-weight: 700;
1053
+ line-height: 1.2;
1054
+ text-wrap: balance;
1055
+ overflow-wrap: break-word;
1056
+ }
1057
+
1058
+ p,
1059
+ li,
1060
+ figcaption,
1061
+ dd,
1062
+ dt,
1063
+ blockquote {
1064
+ overflow-wrap: break-word;
1065
+ }
1066
+
1067
+ p,
1068
+ li,
1069
+ figcaption,
1070
+ blockquote {
1071
+ text-wrap: pretty;
1072
+ }
1073
+
1074
+ ul,
1075
+ ol,
1076
+ menu {
1077
+ list-style: none;
1078
+ }
1079
+
1080
+ a {
1081
+ color: inherit;
1082
+ text-decoration: underline;
1083
+ text-decoration-thickness: 1px;
1084
+ text-underline-offset: 0.15em;
1085
+ text-decoration-skip-ink: auto;
1086
+ }
1087
+
1088
+ b,
1089
+ strong {
1090
+ font-weight: 700;
1091
+ }
1092
+
1093
+ small {
1094
+ font-size: 0.875em;
1095
+ }
1096
+
1097
+ code,
1098
+ kbd,
1099
+ samp,
1100
+ pre {
1101
+ font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
1102
+ font-size: 1em;
1103
+ }
1104
+
1105
+ sub,
1106
+ sup {
1107
+ font-size: 75%;
1108
+ line-height: 0;
1109
+ position: relative;
1110
+ vertical-align: baseline;
1111
+ }
1112
+
1113
+ sub {
1114
+ bottom: -0.25em;
1115
+ }
1116
+
1117
+ sup {
1118
+ top: -0.5em;
1119
+ }
1120
+
1121
+ abbr[title] {
1122
+ text-decoration: underline dotted;
1123
+ text-underline-offset: 0.15em;
1124
+ }
1125
+
1126
+ mark {
1127
+ background: Mark;
1128
+ color: MarkText;
1129
+ }
1130
+
1131
+ hr {
1132
+ height: 0;
1133
+ border: 0;
1134
+ border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
1135
+ color: inherit;
1136
+ }
1137
+
1138
+ img,
1139
+ picture,
1140
+ video,
1141
+ canvas {
1142
+ display: block;
1143
+ max-width: 100%;
1144
+ }
1145
+
1146
+ img,
1147
+ video {
1148
+ height: auto;
1149
+ }
1150
+
1151
+ svg {
1152
+ overflow: hidden;
1153
+ }
1154
+
1155
+ iframe {
1156
+ border: 0;
1157
+ max-width: 100%;
1158
+ }
1159
+
1160
+ table {
1161
+ border-collapse: collapse;
1162
+ border-spacing: 0;
1163
+ }
1164
+
1165
+ fieldset {
1166
+ border: 0;
1167
+ min-inline-size: 0;
1168
+ }
1169
+
1170
+ legend {
1171
+ padding: 0;
1172
+ }
1173
+
1174
+ button,
1175
+ input,
1176
+ select,
1177
+ textarea,
1178
+ optgroup {
1179
+ font: inherit;
1180
+ letter-spacing: inherit;
1181
+ color: inherit;
1182
+ margin: 0;
1183
+ vertical-align: middle;
1184
+ }
1185
+
1186
+ button,
1187
+ input[type="button"],
1188
+ input[type="submit"],
1189
+ input[type="reset"] {
1190
+ appearance: none;
1191
+ background: none;
1192
+ border: 0;
1193
+ padding: 0;
1194
+ cursor: pointer;
1195
+ text-align: center;
1196
+ }
1197
+
1198
+ input,
1199
+ textarea,
1200
+ select {
1201
+ background-color: Canvas;
1202
+ border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
1203
+ border-radius: 0;
1204
+ padding: 0.5em 0.65em;
1205
+ }
1206
+
1207
+ input[type="checkbox"],
1208
+ input[type="radio"],
1209
+ input[type="range"],
1210
+ input[type="file"],
1211
+ input[type="color"],
1212
+ input[type="button"],
1213
+ input[type="submit"],
1214
+ input[type="reset"],
1215
+ input[type="image"],
1216
+ input[type="hidden"] {
1217
+ background: none;
1218
+ border: 0;
1219
+ padding: 0;
1220
+ border-radius: 0;
1221
+ }
1222
+
1223
+ input[type="checkbox"],
1224
+ input[type="radio"] {
1225
+ accent-color: CanvasText;
1226
+ }
1227
+
1228
+ input[type="search"] {
1229
+ appearance: none;
1230
+ background-color: Canvas;
1231
+ border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
1232
+ }
1233
+
1234
+ input[type="search"]::-webkit-search-decoration,
1235
+ input[type="search"]::-webkit-search-cancel-button,
1236
+ input[type="search"]::-webkit-search-results-button,
1237
+ input[type="search"]::-webkit-search-results-decoration {
1238
+ -webkit-appearance: none;
1239
+ display: none;
1240
+ }
1241
+
1242
+ input[type="number"] {
1243
+ appearance: textfield;
1244
+ background-color: Canvas;
1245
+ border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
1246
+ }
1247
+
1248
+ input[type="number"]::-webkit-inner-spin-button,
1249
+ input[type="number"]::-webkit-outer-spin-button {
1250
+ -webkit-appearance: none;
1251
+ margin: 0;
1252
+ }
1253
+
1254
+ textarea {
1255
+ resize: vertical;
1256
+ }
1257
+
1258
+ ::placeholder {
1259
+ opacity: 1;
1260
+ color: color-mix(in srgb, CanvasText 45%, transparent);
1261
+ }
1262
+
1263
+ :focus-visible {
1264
+ outline: 2px solid CanvasText;
1265
+ outline-offset: 2px;
1266
+ }
1267
+
1268
+ :focus:not(:focus-visible) {
1269
+ outline: none;
1270
+ }
1271
+
1272
+ :disabled,
1273
+ [disabled] {
1274
+ cursor: default;
1275
+ opacity: 0.6;
1276
+ }
1277
+
1278
+ label,
1279
+ summary,
1280
+ select,
1281
+ [role="button"] {
1282
+ cursor: pointer;
1283
+ }
1284
+
1285
+ summary {
1286
+ display: list-item;
1287
+ }
1288
+
1289
+ details {
1290
+ display: block;
1291
+ }
1292
+
1293
+ dialog {
1294
+ margin: auto;
1295
+ padding: 1rem;
1296
+ border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
1297
+ background: Canvas;
1298
+ color: CanvasText;
1299
+ max-width: calc(100vw - 2rem);
1300
+ max-height: calc(100svh - 2rem);
1301
+ }
1302
+
1303
+ dialog:not([open]) {
1304
+ display: none;
1305
+ }
1306
+
1307
+ ::backdrop {
1308
+ background: color-mix(in srgb, CanvasText 40%, transparent);
1309
+ }
1310
+
1311
+ [hidden] {
1312
+ display: none !important;
1313
+ }
1314
+
1315
+ ::selection {
1316
+ background: Highlight;
1317
+ color: HighlightText;
1318
+ }
1319
+
1320
+ @media (prefers-reduced-motion: reduce) {
1321
+ *,
1322
+ *::before,
1323
+ *::after {
1324
+ animation-duration: 0.01ms !important;
1325
+ animation-iteration-count: 1 !important;
1326
+ transition-duration: 0.01ms !important;
1327
+ scroll-behavior: auto !important;
1328
+ }
1329
+ }
1330
+
1331
+ @media (pointer: coarse) {
1332
+ input,
1333
+ select,
1334
+ textarea {
1335
+ font-size: max(16px, 1em);
1336
+ }
1337
+ }`;
1338
+
1339
+ // ../core/dist/admin-client.js
1340
+ function isRecord2(value) {
1341
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1342
+ }
1343
+ function mountAdminBrand(doc, host, service, catalog) {
1344
+ const clip = (value, max) => {
1345
+ if (typeof value !== "string")
1346
+ return null;
1347
+ const trimmed = value.trim();
1348
+ if (trimmed === "")
1349
+ return null;
1350
+ return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
1351
+ };
1352
+ const httpUrl = (value) => {
1353
+ if (typeof value !== "string" || value.length > 2e3)
1354
+ return null;
1355
+ try {
1356
+ const url = new URL(value);
1357
+ if (url.protocol !== "https:" && url.protocol !== "http:")
1358
+ return null;
1359
+ return url.href;
1360
+ } catch {
1361
+ return null;
1362
+ }
1363
+ };
1364
+ const hexColor = (value) => {
1365
+ if (typeof value !== "string")
1366
+ return null;
1367
+ const raw = value.trim();
1368
+ return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
1369
+ };
1370
+ const hostname = (value) => {
1371
+ try {
1372
+ return new URL(value).hostname.replace(/^www\./, "");
1373
+ } catch {
1374
+ return value;
1375
+ }
1376
+ };
1377
+ host.replaceChildren();
1378
+ host.hidden = true;
1379
+ if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
1380
+ return;
1381
+ const row = catalog[service];
1382
+ if (!isRecord2(row))
1383
+ return;
1384
+ const vendor = clip(row.vendor, 80);
1385
+ const website = httpUrl(row.website);
1386
+ const guide = httpUrl(row.guide);
1387
+ const docs = httpUrl(row.docs);
1388
+ const logo = httpUrl(row.logo);
1389
+ const color = hexColor(row.color);
1390
+ const description = clip(row.description, 280);
1391
+ if (vendor === null || website === null && guide === null && docs === null)
1392
+ return;
1393
+ const add = (node) => {
1394
+ host.append(node);
1395
+ return node;
1396
+ };
1397
+ if (logo !== null) {
1398
+ const img = doc.createElement("img");
1399
+ img.alt = "";
1400
+ img.src = logo;
1401
+ img.width = 16;
1402
+ img.height = 16;
1403
+ img.decoding = "async";
1404
+ img.referrerPolicy = "no-referrer";
1405
+ if (color !== null)
1406
+ img.style.borderColor = color;
1407
+ add(img);
1408
+ }
1409
+ const name = doc.createElement("span");
1410
+ name.className = "vendor-name";
1411
+ name.textContent = vendor;
1412
+ if (description !== null)
1413
+ name.title = description;
1414
+ add(name);
1415
+ const sep = () => {
1416
+ const node = doc.createElement("span");
1417
+ node.className = "vendor-sep";
1418
+ node.setAttribute("aria-hidden", "true");
1419
+ node.textContent = "\xB7";
1420
+ return node;
1421
+ };
1422
+ const link = (href, label, title) => {
1423
+ const node = doc.createElement("a");
1424
+ node.className = "vendor-link";
1425
+ node.href = href;
1426
+ node.target = "_blank";
1427
+ node.rel = "noopener noreferrer";
1428
+ node.referrerPolicy = "no-referrer";
1429
+ node.textContent = label;
1430
+ node.title = title;
1431
+ return node;
1432
+ };
1433
+ if (website !== null) {
1434
+ add(sep());
1435
+ add(link(website, hostname(website), `${vendor} website`));
1436
+ }
1437
+ if (guide !== null) {
1438
+ add(sep());
1439
+ add(link(guide, "Docs", `Docs for ${vendor}`));
1440
+ }
1441
+ if (docs !== null) {
1442
+ add(sep());
1443
+ add(link(docs, "API", `${vendor} API reference`));
1444
+ }
1445
+ host.removeAttribute("hidden");
1446
+ host.hidden = false;
1447
+ }
1448
+ function startAdminBrand(env) {
1449
+ const requested = env.params.get("brands");
1450
+ let brandsUrl = env.brandsUrl;
1451
+ if (requested) {
1452
+ try {
1453
+ const url = new URL(requested, env.location.href);
1454
+ const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
1455
+ if ((url.protocol === "https:" || url.protocol === "http:") && local)
1456
+ brandsUrl = url.href;
1457
+ } catch {
1458
+ brandsUrl = env.brandsUrl;
1459
+ }
1460
+ }
1461
+ const vendorHost = env.$("vendor");
1462
+ const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
1463
+ const brandService = brandRoot?.getAttribute("data-service") || "";
1464
+ if (vendorHost === null)
1465
+ return;
1466
+ env.fetch(brandsUrl, {
1467
+ headers: { accept: "application/json" },
1468
+ signal: AbortSignal.timeout(5e3)
1469
+ }).then(async (response) => {
1470
+ if (!response.ok)
1471
+ return null;
1472
+ const catalog = await response.json();
1473
+ return catalog;
1474
+ }).then((catalog) => {
1475
+ mountAdminBrand(env.document, vendorHost, brandService, catalog);
1476
+ }).catch(() => {
1477
+ });
1478
+ }
1479
+ function faultPresetList(value) {
1480
+ if (!isRecord2(value))
1481
+ throw new Error("Fault presets response was not an object");
1482
+ if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
1483
+ return { presets: [] };
1484
+ }
1485
+ if (!Array.isArray(value.presets))
1486
+ throw new Error("Fault presets response was not a list");
1487
+ return {
1488
+ presets: value.presets.flatMap((item) => {
1489
+ if (!isRecord2(item) || typeof item.name !== "string")
1490
+ return [];
1491
+ return [{ name: item.name }];
1492
+ })
1493
+ };
1494
+ }
1495
+ function bootAdmin(config) {
1496
+ const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1497
+ const sources = ["declared", "inferred", "mixed"];
1498
+ const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
1499
+ const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
1500
+ const readJson2 = (text) => {
1501
+ const value = JSON.parse(text);
1502
+ return value;
1503
+ };
1504
+ const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
1505
+ switch (char) {
1506
+ case "&":
1507
+ return "&amp;";
1508
+ case "<":
1509
+ return "&lt;";
1510
+ case ">":
1511
+ return "&gt;";
1512
+ case '"':
1513
+ return "&quot;";
1514
+ default:
1515
+ return "&#39;";
1516
+ }
1517
+ });
1518
+ const el = (id, kind) => {
1519
+ const node = document.getElementById(id);
1520
+ if (!(node instanceof kind))
1521
+ throw new Error(`admin shell is missing #${id}`);
1522
+ return node;
1523
+ };
1524
+ const errorMessage = (data, fallback) => {
1525
+ if (!isRecord2(data))
1526
+ return fallback;
1527
+ const error2 = data.error;
1528
+ if (!isRecord2(error2) || typeof error2.message !== "string" || error2.message === "") {
1529
+ return fallback;
1530
+ }
1531
+ return error2.message;
1532
+ };
1533
+ const requireList = (value, label) => {
1534
+ if (value === void 0 || value === null)
1535
+ return [];
1536
+ if (!Array.isArray(value))
1537
+ throw new Error(`${label} was not a list`);
1538
+ return value;
1539
+ };
1540
+ const state = {
1541
+ namespace: "default",
1542
+ key: sessionStorage.getItem("mockingbird-admin-key") || "",
1543
+ view: "overview",
1544
+ collection: "",
1545
+ shape: null,
1546
+ route: null,
1547
+ editing: null
1548
+ };
1549
+ const standard = new Set(config.standardRoutes);
1550
+ const banner = el("banner", HTMLElement);
1551
+ const keyInput = el("admin-key", HTMLInputElement);
1552
+ keyInput.value = state.key;
1553
+ const params = new URLSearchParams(location.search);
1554
+ const queryKey = params.get("key");
1555
+ if (queryKey) {
1556
+ state.key = queryKey;
1557
+ keyInput.value = state.key;
1558
+ sessionStorage.setItem("mockingbird-admin-key", state.key);
1559
+ params.delete("key");
1560
+ const next = params.toString();
1561
+ history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
1562
+ }
1563
+ const queryNamespace = params.get("namespace");
1564
+ if (queryNamespace)
1565
+ state.namespace = queryNamespace;
1566
+ const showError = (error2) => {
1567
+ banner.textContent = error2 instanceof Error ? error2.message : String(error2);
1568
+ banner.classList.add("show");
1569
+ };
1570
+ const clearError = () => {
1571
+ banner.classList.remove("show");
1572
+ };
1573
+ const api = async (method, path, body) => {
1574
+ const headers = { accept: "application/json" };
1575
+ if (state.key !== "")
1576
+ headers[config.adminKeyHeader] = state.key;
1577
+ if (state.namespace !== "")
1578
+ headers["x-mockingbird-namespace"] = state.namespace;
1579
+ if (body !== void 0)
1580
+ headers["content-type"] = "application/json";
1581
+ const init = { method, headers };
1582
+ if (body !== void 0)
1583
+ init.body = JSON.stringify(body);
1584
+ const response = await fetch(config.adminPrefix + path, init);
1585
+ const text = await response.text();
1586
+ let data = null;
1587
+ if (text !== "") {
1588
+ try {
1589
+ data = readJson2(text);
1590
+ } catch {
1591
+ data = { raw: text };
1592
+ }
1593
+ }
1594
+ if (response.status === 401) {
1595
+ keyInput.focus();
1596
+ throw new Error(errorMessage(data, "Admin key required"));
1597
+ }
1598
+ if (!response.ok) {
1599
+ throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
1600
+ }
1601
+ return data;
1602
+ };
1603
+ const originGet = async (path) => {
1604
+ const response = await fetch(path, { headers: { accept: "application/json" } });
1605
+ if (!response.ok)
1606
+ throw new Error(`${response.status} ${path}`);
1607
+ const value = await response.json();
1608
+ return value;
1609
+ };
1610
+ const panelApi = {
1611
+ get: (path) => api("GET", path),
1612
+ send: (method, path, body) => api(method, path, body),
1613
+ namespace: () => state.namespace
1614
+ };
1615
+ const isPanelScript = (value) => typeof value === "function";
1616
+ const setTheme = (theme) => {
1617
+ if (theme)
1618
+ document.documentElement.dataset.theme = theme;
1619
+ else
1620
+ delete document.documentElement.dataset.theme;
1621
+ };
1622
+ const storedTheme = localStorage.getItem("mockingbird-admin-theme");
1623
+ if (storedTheme)
1624
+ setTheme(storedTheme);
1625
+ el("theme", HTMLButtonElement).addEventListener("click", () => {
1626
+ const current = document.documentElement.dataset.theme;
1627
+ const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
1628
+ const next = dark ? "light" : "dark";
1629
+ localStorage.setItem("mockingbird-admin-theme", next);
1630
+ setTheme(next);
1631
+ });
1632
+ const show = (view) => {
1633
+ state.view = view;
1634
+ for (const button of document.querySelectorAll("#nav button")) {
1635
+ if (!(button instanceof HTMLButtonElement))
1636
+ continue;
1637
+ button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
1638
+ }
1639
+ for (const section of document.querySelectorAll("main .view")) {
1640
+ if (!(section instanceof HTMLElement))
1641
+ continue;
1642
+ section.hidden = section.id !== `view-${view}`;
1643
+ }
1644
+ };
1645
+ el("nav", HTMLElement).addEventListener("click", (event) => {
1646
+ const target = event.target;
1647
+ if (!(target instanceof Element))
1648
+ return;
1649
+ const button = target.closest("button[data-view]");
1650
+ if (!(button instanceof HTMLButtonElement))
1651
+ return;
1652
+ const view = button.dataset.view;
1653
+ if (view === void 0)
1654
+ return;
1655
+ show(view);
1656
+ refresh().catch(showError);
1657
+ });
1658
+ 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>`;
1659
+ const table = (columns, rows) => {
1660
+ if (rows.length === 0)
1661
+ return '<p class="empty">Nothing here yet.</p>';
1662
+ const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
1663
+ const body = rows.map((row) => {
1664
+ const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
1665
+ const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
1666
+ return `<tr${attrs}>${cells}</tr>`;
1667
+ }).join("");
1668
+ return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
1669
+ };
1670
+ const preview = (value) => {
1671
+ const text = JSON.stringify(value) ?? "null";
1672
+ return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
1673
+ };
1674
+ const when = (epoch) => {
1675
+ const date = new Date(epoch);
1676
+ return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
1677
+ };
1678
+ const clockCard = (epoch) => {
1679
+ const date = new Date(epoch);
1680
+ if (Number.isNaN(date.getTime()))
1681
+ return esc(String(epoch));
1682
+ const iso = date.toISOString();
1683
+ return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
1684
+ };
1685
+ const decodeClock = (value) => {
1686
+ if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
1687
+ throw new Error("Clock response was not a clock");
1688
+ }
1689
+ return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
1690
+ };
1691
+ const decodeField = (value) => {
1692
+ if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
1693
+ return void 0;
1694
+ }
1695
+ const field = {
1696
+ name: value.name,
1697
+ kind: value.kind,
1698
+ optional: value.optional === true
1699
+ };
1700
+ if (typeof value.description === "string")
1701
+ field.description = value.description;
1702
+ if (Array.isArray(value.fields)) {
1703
+ field.fields = value.fields.flatMap((item) => {
1704
+ const child = decodeField(item);
1705
+ return child === void 0 ? [] : [child];
1706
+ });
1707
+ }
1708
+ return field;
1709
+ };
1710
+ const decodeCollection = (value) => {
1711
+ if (!isRecord2(value) || typeof value.name !== "string")
1712
+ return void 0;
1713
+ const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
1714
+ const field = decodeField(item);
1715
+ return field === void 0 ? [] : [field];
1716
+ }) : [];
1717
+ const collection = {
1718
+ name: value.name,
1719
+ label: typeof value.label === "string" ? value.label : value.name,
1720
+ count: typeof value.count === "number" ? value.count : 0,
1721
+ source: isSource(value.source) ? value.source : "inferred",
1722
+ fields
1723
+ };
1724
+ if (typeof value.description === "string")
1725
+ collection.description = value.description;
1726
+ return collection;
1727
+ };
1728
+ const decodeState = (value) => {
1729
+ if (!isRecord2(value) || !Array.isArray(value.collections)) {
1730
+ throw new Error("State response has no collection list");
1731
+ }
1732
+ return {
1733
+ namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
1734
+ storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
1735
+ collections: value.collections.flatMap((item) => {
1736
+ const collection = decodeCollection(item);
1737
+ return collection === void 0 ? [] : [collection];
1738
+ })
1739
+ };
1740
+ };
1741
+ const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
1742
+ if (!isRecord2(item) || typeof item.id !== "string")
1743
+ return [];
1744
+ return [
1745
+ {
1746
+ id: item.id,
1747
+ seq: typeof item.seq === "number" ? item.seq : 0,
1748
+ value: item.value,
1749
+ attrs: ` class="clickable" data-id="${esc(item.id)}"`
1750
+ }
1751
+ ];
1752
+ });
1753
+ const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
1754
+ const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
1755
+ if (!isRecord2(item))
1756
+ return [];
1757
+ return [
1758
+ {
1759
+ at: textOf(item.at),
1760
+ method: textOf(item.method),
1761
+ path: textOf(item.path),
1762
+ status: textOf(item.status),
1763
+ durationMs: textOf(item.durationMs),
1764
+ operationId: textOf(item.operationId)
1765
+ }
1766
+ ];
1767
+ });
1768
+ const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
1769
+ if (!isRecord2(item))
1770
+ return [];
1771
+ return [
1772
+ {
1773
+ id: textOf(item.id),
1774
+ method: typeof item.method === "string" ? item.method : void 0,
1775
+ pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
1776
+ operationId: typeof item.operationId === "string" ? item.operationId : void 0,
1777
+ status: typeof item.status === "number" ? item.status : void 0,
1778
+ effect: typeof item.effect === "string" ? item.effect : void 0,
1779
+ drop: typeof item.drop === "boolean" ? item.drop : void 0,
1780
+ latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
1781
+ }
1782
+ ];
1783
+ });
1784
+ const loadNamespaces = async () => {
1785
+ const data = await api("GET", "/namespaces");
1786
+ const select = el("namespace", HTMLSelectElement);
1787
+ const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
1788
+ const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
1789
+ const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
1790
+ if (!names.includes(state.namespace))
1791
+ names.unshift(state.namespace);
1792
+ select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
1793
+ select.value = state.namespace;
1794
+ };
1795
+ const renderOverview = async () => {
1796
+ const [health, shape, clock, journal] = await Promise.all([
1797
+ originGet("/health"),
1798
+ api("GET", "/state"),
1799
+ api("GET", "/clock"),
1800
+ api("GET", "/requests?limit=8")
1801
+ ]);
1802
+ if (!isRecord2(health))
1803
+ throw new Error("Health response was not an object");
1804
+ const decoded = decodeState(shape);
1805
+ state.shape = decoded;
1806
+ const time = decodeClock(clock);
1807
+ el("overview-cards", HTMLElement).innerHTML = cards([
1808
+ {
1809
+ k: "Service",
1810
+ v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
1811
+ },
1812
+ {
1813
+ k: "Status",
1814
+ v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
1815
+ },
1816
+ { k: "Namespace", v: esc(state.namespace) },
1817
+ { k: "Collections", v: String(decoded.collections.length) },
1818
+ {
1819
+ k: "Records",
1820
+ v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
1821
+ },
1822
+ { k: "Clock", v: clockCard(time.now) }
1823
+ ]);
1824
+ el("overview-requests", HTMLElement).innerHTML = table([
1825
+ { label: "Method", cell: (row) => esc(row.method) },
1826
+ { label: "Path", cell: (row) => esc(row.path) },
1827
+ {
1828
+ label: "Status",
1829
+ cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
1830
+ },
1831
+ { label: "Operation", cell: (row) => esc(row.operationId) }
1832
+ ], decodeJournal(journal));
1833
+ };
1834
+ const schemaChips = (collection) => {
1835
+ if (collection.fields.length === 0) {
1836
+ return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
1837
+ }
1838
+ return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
1839
+ };
1840
+ const renderState = async () => {
1841
+ const shape = decodeState(await api("GET", "/state"));
1842
+ state.shape = shape;
1843
+ const host = el("collections", HTMLElement);
1844
+ if (shape.collections.length === 0) {
1845
+ host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
1846
+ el("schema", HTMLElement).innerHTML = "";
1847
+ el("records", HTMLElement).innerHTML = "";
1848
+ return;
1849
+ }
1850
+ if (!shape.collections.some((item) => item.name === state.collection)) {
1851
+ const first = shape.collections[0];
1852
+ if (first === void 0)
1853
+ return;
1854
+ state.collection = first.name;
1855
+ }
1856
+ host.innerHTML = shape.collections.map((item) => `<button type="button" class="collection" data-collection="${esc(item.name)}" aria-current="${item.name === state.collection ? "true" : "false"}"><strong>${esc(item.label)}</strong><small>${esc(item.count)} \xB7 ${esc(item.source)}</small></button>`).join("");
1857
+ const selected = shape.collections.find((item) => item.name === state.collection);
1858
+ if (selected === void 0)
1859
+ return;
1860
+ const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
1861
+ el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
1862
+ const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
1863
+ el("records", HTMLElement).innerHTML = table([
1864
+ { label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
1865
+ { label: "Seq", cell: (row) => esc(row.seq) },
1866
+ { label: "Value", cell: (row) => preview(row.value) }
1867
+ ], decodeRecords(page));
1868
+ };
1869
+ const renderClock = async () => {
1870
+ const clock = decodeClock(await api("GET", "/clock"));
1871
+ el("clock-readout", HTMLElement).innerHTML = `<div class="k">Now</div><div class="v">${esc(when(clock.now))}</div><p>${esc(clock.now)} ms \xB7 offset ${esc(clock.offsetMs)} ms ${clock.frozen ? "<span class='badge warn'>frozen</span>" : "<span class='badge ok'>live</span>"}</p>`;
1872
+ const freeze = el("freeze", HTMLButtonElement);
1873
+ freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
1874
+ freeze.dataset.frozen = clock.frozen ? "1" : "0";
1875
+ };
1876
+ const renderFaults = async () => {
1877
+ const [faults, presets] = await Promise.all([
1878
+ api("GET", "/faults"),
1879
+ api("GET", "/faults/presets").catch(() => ({ presets: [] }))
1880
+ ]);
1881
+ const select = el("fault-preset", HTMLSelectElement);
1882
+ const current = select.value;
1883
+ const list = faultPresetList(presets).presets;
1884
+ select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
1885
+ select.value = current;
1886
+ el("fault-list", HTMLElement).innerHTML = table([
1887
+ { label: "Id", cell: (row) => esc(row.id) },
1888
+ {
1889
+ label: "Match",
1890
+ cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
1891
+ },
1892
+ {
1893
+ label: "Effect",
1894
+ cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
1895
+ }
1896
+ ], decodeFaults(faults));
1897
+ };
1898
+ const renderJournal = async () => {
1899
+ const journal = await api("GET", "/requests?limit=100");
1900
+ el("journal", HTMLElement).innerHTML = table([
1901
+ { label: "When", cell: (row) => esc(row.at) },
1902
+ { label: "Method", cell: (row) => esc(row.method) },
1903
+ { label: "Path", cell: (row) => esc(row.path) },
1904
+ { label: "Status", cell: (row) => esc(row.status) },
1905
+ { label: "ms", cell: (row) => esc(row.durationMs) }
1906
+ ], decodeJournal(journal));
1907
+ };
1908
+ const renderRoutes = async () => {
1909
+ const data = await api("GET", "/");
1910
+ if (!isRecord2(data))
1911
+ throw new Error("Route list was not an object");
1912
+ const routes = requireList(data.routes, "Routes").map((route) => String(route));
1913
+ el("route-list", HTMLElement).innerHTML = routes.map((route) => {
1914
+ const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
1915
+ const parts = route.split(" ");
1916
+ const method = parts[0] ?? "";
1917
+ const path = parts.slice(1).join(" ");
1918
+ 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>`;
1919
+ }).join("");
1920
+ };
1921
+ const renderers = {
1922
+ overview: renderOverview,
1923
+ state: renderState,
1924
+ clock: renderClock,
1925
+ faults: renderFaults,
1926
+ journal: renderJournal,
1927
+ routes: renderRoutes
1928
+ };
1929
+ async function refresh() {
1930
+ clearError();
1931
+ const render = renderers[state.view];
1932
+ if (render)
1933
+ await render();
1934
+ }
1935
+ el("namespace", HTMLSelectElement).addEventListener("change", () => {
1936
+ state.namespace = el("namespace", HTMLSelectElement).value;
1937
+ refresh().catch(showError);
1938
+ });
1939
+ keyInput.addEventListener("change", () => {
1940
+ state.key = keyInput.value.trim();
1941
+ sessionStorage.setItem("mockingbird-admin-key", state.key);
1942
+ refresh().catch(showError);
1943
+ });
1944
+ el("refresh", HTMLButtonElement).addEventListener("click", () => {
1945
+ refresh().catch(showError);
1946
+ });
1947
+ el("collections", HTMLElement).addEventListener("click", (event) => {
1948
+ const target = event.target;
1949
+ if (!(target instanceof Element))
1950
+ return;
1951
+ const button = target.closest("[data-collection]");
1952
+ if (!(button instanceof HTMLElement))
1953
+ return;
1954
+ const collection = button.dataset.collection;
1955
+ if (collection === void 0)
1956
+ return;
1957
+ state.collection = collection;
1958
+ renderState().catch(showError);
1959
+ });
1960
+ el("records", HTMLElement).addEventListener("click", (event) => {
1961
+ const target = event.target;
1962
+ if (!(target instanceof Element))
1963
+ return;
1964
+ const row = target.closest("[data-id]");
1965
+ if (!(row instanceof HTMLElement))
1966
+ return;
1967
+ const id = row.dataset.id;
1968
+ if (id === void 0)
1969
+ return;
1970
+ openEditor(id).catch(showError);
1971
+ });
1972
+ const editor = el("editor", HTMLDialogElement);
1973
+ const editorId = el("editor-id", HTMLInputElement);
1974
+ const editorValue = el("editor-value", HTMLTextAreaElement);
1975
+ const editorDelete = el("editor-delete", HTMLButtonElement);
1976
+ async function openEditor(id) {
1977
+ state.editing = id;
1978
+ el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
1979
+ editorId.value = id ?? "";
1980
+ editorId.readOnly = id !== null;
1981
+ editorDelete.hidden = id === null;
1982
+ if (id) {
1983
+ const record2 = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
1984
+ if (!isRecord2(record2))
1985
+ throw new Error("Record response was not an object");
1986
+ editorValue.value = JSON.stringify(record2.value, null, 2) ?? "";
1987
+ } else {
1988
+ editorValue.value = "{\n \n}";
1989
+ }
1990
+ editor.showModal();
1991
+ }
1992
+ el("new-record", HTMLButtonElement).addEventListener("click", () => {
1993
+ openEditor(null).catch(showError);
1994
+ });
1995
+ el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
1996
+ const submitter = event.submitter;
1997
+ if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
1998
+ return;
1999
+ event.preventDefault();
2000
+ let value;
2001
+ try {
2002
+ value = readJson2(editorValue.value);
2003
+ } catch {
2004
+ showError(new Error("Value is not JSON"));
2005
+ return;
2006
+ }
2007
+ const id = editorId.value.trim();
2008
+ const path = `/state/${encodeURIComponent(state.collection)}`;
2009
+ const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
2010
+ request.then(() => {
2011
+ editor.close();
2012
+ return renderState();
2013
+ }).catch(showError);
2014
+ });
2015
+ editorDelete.addEventListener("click", () => {
2016
+ const id = state.editing;
2017
+ if (!id)
2018
+ return;
2019
+ api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2020
+ editor.close();
2021
+ return renderState();
2022
+ }).catch(showError);
2023
+ });
2024
+ for (const button of document.querySelectorAll("[data-advance]")) {
2025
+ if (!(button instanceof HTMLButtonElement))
2026
+ continue;
2027
+ button.addEventListener("click", () => {
2028
+ const raw = button.dataset.advance;
2029
+ if (raw === void 0)
2030
+ return;
2031
+ api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
2032
+ });
2033
+ }
2034
+ el("freeze", HTMLButtonElement).addEventListener("click", () => {
2035
+ const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
2036
+ api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
2037
+ });
2038
+ el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
2039
+ api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
2040
+ });
2041
+ el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
2042
+ event.preventDefault();
2043
+ const raw = el("clock-instant", HTMLInputElement).value.trim();
2044
+ const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
2045
+ api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
2046
+ });
2047
+ el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
2048
+ event.preventDefault();
2049
+ const preset = el("fault-preset", HTMLSelectElement).value;
2050
+ if (preset !== "") {
2051
+ api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
2052
+ return;
2053
+ }
2054
+ const status = Number(el("fault-status", HTMLInputElement).value);
2055
+ if (!Number.isFinite(status)) {
2056
+ showError(new Error("Status must be a number, or choose a preset"));
2057
+ return;
2058
+ }
2059
+ const path = el("fault-path", HTMLInputElement).value;
2060
+ const method = el("fault-method", HTMLInputElement).value;
2061
+ api("POST", "/faults", {
2062
+ status,
2063
+ ...path !== "" ? { pathPrefix: path } : {},
2064
+ ...method !== "" ? { method } : {}
2065
+ }).then(() => renderFaults()).catch(showError);
2066
+ });
2067
+ el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
2068
+ api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
2069
+ });
2070
+ el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
2071
+ api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
2072
+ });
2073
+ el("route-list", HTMLElement).addEventListener("click", (event) => {
2074
+ const target = event.target;
2075
+ if (!(target instanceof Element))
2076
+ return;
2077
+ const button = target.closest("[data-route]");
2078
+ if (!(button instanceof HTMLElement))
2079
+ return;
2080
+ const route = button.dataset.route;
2081
+ if (route === void 0)
2082
+ return;
2083
+ state.route = route;
2084
+ el("route-title", HTMLElement).textContent = route;
2085
+ const method = route.split(" ")[0] ?? "";
2086
+ el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
2087
+ });
2088
+ el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
2089
+ event.preventDefault();
2090
+ const send = async () => {
2091
+ if (state.route === null)
2092
+ throw new Error("Choose a route first");
2093
+ const parts = state.route.split(" ");
2094
+ const method = parts[0];
2095
+ const path = parts.slice(1).join(" ");
2096
+ if (method === void 0)
2097
+ throw new Error("Choose a route first");
2098
+ const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
2099
+ let body;
2100
+ const routeBody = el("route-body", HTMLTextAreaElement);
2101
+ if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
2102
+ try {
2103
+ body = readJson2(routeBody.value);
2104
+ } catch {
2105
+ throw new Error("Body is not JSON");
2106
+ }
2107
+ }
2108
+ const data = await api(method, concrete, body);
2109
+ el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
2110
+ };
2111
+ send().catch(showError);
2112
+ });
2113
+ const decodePanel = (value) => {
2114
+ if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
2115
+ return void 0;
2116
+ }
2117
+ const panel = {
2118
+ id: value.id,
2119
+ title: value.title,
2120
+ description: typeof value.description === "string" ? value.description : "",
2121
+ html: typeof value.html === "string" ? value.html : ""
2122
+ };
2123
+ if (typeof value.script === "string")
2124
+ panel.script = value.script;
2125
+ return panel;
2126
+ };
2127
+ const mountPanels = (panels) => {
2128
+ const nav = el("nav", HTMLElement);
2129
+ const views = el("views", HTMLElement);
2130
+ for (const panel of panels) {
2131
+ const button = document.createElement("button");
2132
+ button.type = "button";
2133
+ button.dataset.view = panel.id;
2134
+ button.textContent = panel.title;
2135
+ nav.append(button);
2136
+ const section = document.createElement("section");
2137
+ section.className = "view";
2138
+ section.id = `view-${panel.id}`;
2139
+ section.hidden = true;
2140
+ const title = document.createElement("h2");
2141
+ title.textContent = panel.title;
2142
+ const lede = document.createElement("p");
2143
+ lede.className = "lede";
2144
+ lede.textContent = panel.description;
2145
+ const body = document.createElement("div");
2146
+ body.className = "panel-body";
2147
+ body.id = `panel-${panel.id}`;
2148
+ body.innerHTML = panel.html;
2149
+ section.append(title, lede, body);
2150
+ views.append(section);
2151
+ if (panel.script === void 0)
2152
+ continue;
2153
+ try {
2154
+ const compiled = new Function("root", "api", panel.script);
2155
+ if (!isPanelScript(compiled))
2156
+ throw new Error("panel script did not compile");
2157
+ compiled(body, panelApi);
2158
+ } catch (error2) {
2159
+ const note = document.createElement("p");
2160
+ note.className = "banner show";
2161
+ note.textContent = error2 instanceof Error ? error2.message : String(error2);
2162
+ body.append(note);
2163
+ }
2164
+ }
2165
+ };
2166
+ startAdminBrand({
2167
+ document,
2168
+ $: (id) => document.getElementById(id),
2169
+ params,
2170
+ location: { href: location.href, origin: location.origin },
2171
+ fetch,
2172
+ brandsUrl: config.brandsUrl
2173
+ });
2174
+ loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
2175
+ const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
2176
+ const decoded = decodePanel(panel);
2177
+ return decoded === void 0 ? [] : [decoded];
2178
+ });
2179
+ mountPanels(panels);
2180
+ return refresh();
2181
+ }).catch(showError);
2182
+ }
2183
+ var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2184
+ var adminClientSource = (config) => {
2185
+ const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2186
+ return `<script>
2187
+ ${clientPrelude}
2188
+ bootAdmin(${payload});
2189
+ </script>`;
2190
+ };
2191
+
2192
+ // ../core/dist/surface.js
2193
+ var defineMock = (runtime) => runtime;
2194
+ var STANDARD_ADMIN_ROUTES = [
2195
+ "GET /",
2196
+ "POST /reset",
2197
+ "GET /namespaces",
2198
+ "GET /clock",
2199
+ "POST /clock",
2200
+ "GET /faults",
2201
+ "POST /faults",
2202
+ "DELETE /faults",
2203
+ "POST /snapshots",
2204
+ "POST /snapshots/:id/restore",
2205
+ "DELETE /snapshots/:id",
2206
+ "GET /timeline",
2207
+ "POST /checkpoints",
2208
+ "POST /branches/:name",
2209
+ "POST /branches/:name/checkout",
2210
+ "GET /requests",
2211
+ "DELETE /requests",
2212
+ "GET /metrics",
2213
+ "DELETE /metrics",
2214
+ "GET /credentials",
2215
+ "PUT /credentials",
2216
+ "DELETE /credentials",
2217
+ "GET /state",
2218
+ "GET /state/:collection",
2219
+ "GET /state/:collection/:id",
2220
+ "POST /state/:collection",
2221
+ "PUT /state/:collection/:id",
2222
+ "PATCH /state/:collection/:id",
2223
+ "DELETE /state/:collection/:id",
2224
+ "GET /ui",
2225
+ "GET /ui/",
2226
+ "GET /ui/manifest"
2227
+ ];
2228
+ var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2229
+ var assertAdminUi = (ui) => {
2230
+ if (!ui?.panels)
2231
+ return;
2232
+ const seen = /* @__PURE__ */ new Set();
2233
+ for (const panel of ui.panels) {
2234
+ if (!PANEL_ID.test(panel.id)) {
2235
+ throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2236
+ }
2237
+ if (seen.has(panel.id))
2238
+ throw new RangeError(`duplicate admin panel id ${panel.id}`);
2239
+ seen.add(panel.id);
2240
+ if (panel.title.trim() === "")
2241
+ throw new RangeError(`admin panel ${panel.id} needs a title`);
2242
+ }
2243
+ };
2244
+
2245
+ // ../core/dist/admin-ui.js
2246
+ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
2247
+ switch (char) {
2248
+ case "&":
2249
+ return "&amp;";
2250
+ case "<":
2251
+ return "&lt;";
2252
+ case ">":
2253
+ return "&gt;";
2254
+ case '"':
2255
+ return "&quot;";
2256
+ default:
2257
+ return "&#39;";
2258
+ }
2259
+ });
2260
+ var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
2261
+ var renderAdminDocument = (service) => {
2262
+ const name = escapeHtml(service);
2263
+ const script = adminClientSource({
2264
+ standardRoutes: STANDARD_ADMIN_ROUTES,
2265
+ adminPrefix: ADMIN_PREFIX,
2266
+ adminKeyHeader: ADMIN_KEY_HEADER,
2267
+ brandsUrl: ADMIN_BRANDS_URL,
2268
+ service
2269
+ });
2270
+ return `<!DOCTYPE html>
2271
+ <html lang="en">
2272
+ <head>
2273
+ <meta charset="utf-8">
2274
+ <meta name="viewport" content="width=device-width, initial-scale=1">
2275
+ <meta name="color-scheme" content="light dark">
2276
+ <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='2' fill='%2327272a'/%3E%3C/svg%3E">
2277
+ <title>${name} admin</title>
2278
+ <style>
2279
+ ${CSS_RESET}
2280
+ :root {
2281
+ color-scheme: light;
2282
+ --bg: #fafafa;
2283
+ --bg-elev: #ffffff;
2284
+ --bg-muted: #f4f4f5;
2285
+ --bg-inset: #f4f4f5;
2286
+ --line: #dedee3;
2287
+ --line-strong: #c4c4cc;
2288
+ --ink: #18181b;
2289
+ --muted: #62626b;
2290
+ --faint: #71717a;
2291
+ --accent: #27272a;
2292
+ --accent-ink: #ffffff;
2293
+ --accent-soft: #f4f4f5;
2294
+ --ok: #166534;
2295
+ --ok-soft: #f0fdf4;
2296
+ --warn: #a16207;
2297
+ --warn-soft: #fefce8;
2298
+ --err: #a82d32;
2299
+ --err-soft: #fef2f2;
2300
+ --shadow: none;
2301
+ --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
2302
+ --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
2303
+ --radius: 10px;
2304
+ --header: 56px;
2305
+ --nav: 200px;
2306
+ }
2307
+ :root[data-theme="dark"] {
2308
+ color-scheme: dark;
2309
+ --bg: #111113;
2310
+ --bg-elev: #19191c;
2311
+ --bg-muted: #242428;
2312
+ --bg-inset: #111113;
2313
+ --line: #36363c;
2314
+ --line-strong: #52525b;
2315
+ --ink: #f4f4f5;
2316
+ --muted: #a9a9b2;
2317
+ --faint: #71717a;
2318
+ --accent: #e4e4e7;
2319
+ --accent-ink: #18181b;
2320
+ --accent-soft: #242428;
2321
+ --ok: #86efac;
2322
+ --ok-soft: #14241b;
2323
+ --warn: #fde68a;
2324
+ --warn-soft: #2a2410;
2325
+ --err: #ffaaaa;
2326
+ --err-soft: #2c1516;
2327
+ --shadow: none;
2328
+ }
2329
+ @media (prefers-color-scheme: dark) {
2330
+ :root:not([data-theme="light"]) {
2331
+ color-scheme: dark;
2332
+ --bg: #111113;
2333
+ --bg-elev: #19191c;
2334
+ --bg-muted: #242428;
2335
+ --bg-inset: #111113;
2336
+ --line: #36363c;
2337
+ --line-strong: #52525b;
2338
+ --ink: #f4f4f5;
2339
+ --muted: #a9a9b2;
2340
+ --faint: #71717a;
2341
+ --accent: #e4e4e7;
2342
+ --accent-ink: #18181b;
2343
+ --accent-soft: #242428;
2344
+ --ok: #86efac;
2345
+ --ok-soft: #14241b;
2346
+ --warn: #fde68a;
2347
+ --warn-soft: #2a2410;
2348
+ --err: #ffaaaa;
2349
+ --err-soft: #2c1516;
2350
+ --shadow: none;
2351
+ }
2352
+ }
2353
+ /* Fill the viewport, then grow with the content so the background covers the scroll. */
2354
+ html { height: 100%; }
2355
+ body {
2356
+ margin: 0;
2357
+ min-height: 100%;
2358
+ display: flex;
2359
+ flex-direction: column;
2360
+ font-family: var(--sans);
2361
+ background: var(--bg);
2362
+ color: var(--ink);
2363
+ line-height: 1.45;
2364
+ padding-left: env(safe-area-inset-left);
2365
+ padding-right: env(safe-area-inset-right);
2366
+ -webkit-text-size-adjust: 100%;
2367
+ }
2368
+ :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
2369
+ .app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
2370
+ header.top {
2371
+ position: sticky; top: 0; z-index: 5;
2372
+ display: flex; align-items: center; gap: 12px;
2373
+ min-height: var(--header); padding: 10px 16px;
2374
+ background: var(--bg-elev);
2375
+ border-bottom: 1px solid var(--line);
2376
+ min-width: 0; max-width: 100%;
2377
+ }
2378
+ .brand {
2379
+ display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
2380
+ min-width: 0; max-width: 100%; margin-right: auto;
2381
+ }
2382
+ .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
2383
+ .brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
2384
+ .brand-id span { color: var(--faint); font-size: 12px; }
2385
+ .vendor {
2386
+ display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
2387
+ min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
2388
+ }
2389
+ .vendor[hidden] { display: none; }
2390
+ /* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
2391
+ .vendor img {
2392
+ width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
2393
+ border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
2394
+ }
2395
+ .vendor-name { color: var(--ink); font-weight: 600; }
2396
+ .vendor-sep { color: var(--faint); }
2397
+ .vendor-link { color: inherit; text-decoration: none; }
2398
+ .vendor-link:hover { color: var(--ink); text-decoration: underline; }
2399
+ .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
2400
+ label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
2401
+ label.field input, label.field select, .controls input[type="password"] {
2402
+ background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
2403
+ padding: 7px 8px; min-height: 36px;
2404
+ }
2405
+ .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
2406
+ border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
2407
+ background: var(--bg-elev);
2408
+ }
2409
+ .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
2410
+ .btn-quiet { background: transparent; }
2411
+ .btn-danger { color: var(--err); }
2412
+ /* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
2413
+ record or the full nav row would widen the page past the viewport. */
2414
+ .layout {
2415
+ display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
2416
+ flex: 1 0 auto; min-width: 0;
2417
+ }
2418
+ nav.side {
2419
+ border-right: 1px solid var(--line); padding: 12px;
2420
+ display: flex; flex-direction: column; gap: 4px;
2421
+ background: var(--bg-elev);
2422
+ }
2423
+ nav.side button {
2424
+ text-align: left; border: 0; background: transparent; border-radius: 9px;
2425
+ padding: 9px 10px; min-height: 40px; color: var(--muted);
2426
+ }
2427
+ nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
2428
+ main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
2429
+ .view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
2430
+ .lede { margin: 0 0 16px; color: var(--muted); }
2431
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
2432
+ .card {
2433
+ background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
2434
+ padding: 14px 16px; box-shadow: var(--shadow);
2435
+ }
2436
+ .card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
2437
+ .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
2438
+ .card .v .clock-time { font-size: 14px; color: var(--muted); }
2439
+ .split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
2440
+ .collection {
2441
+ width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
2442
+ border-radius: 10px; padding: 8px 10px; min-height: 44px;
2443
+ }
2444
+ .collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
2445
+ .collection small { display: block; color: var(--faint); }
2446
+ .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
2447
+ .chip {
2448
+ font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
2449
+ border-radius: 999px; padding: 4px 8px;
2450
+ }
2451
+ .chip i { color: var(--faint); font-style: normal; }
2452
+ table { width: 100%; border-collapse: collapse; font-size: 14px; }
2453
+ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2454
+ th { color: var(--faint); font-weight: 600; font-size: 12px; }
2455
+ tr.clickable { cursor: pointer; }
2456
+ tr.clickable:hover { background: var(--bg-muted); }
2457
+ pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
2458
+ pre {
2459
+ margin: 0; white-space: pre-wrap; word-break: break-word;
2460
+ background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
2461
+ }
2462
+ .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
2463
+ .banner {
2464
+ display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
2465
+ background: var(--err-soft); color: var(--err);
2466
+ }
2467
+ .banner.show { display: block; }
2468
+ .empty { color: var(--muted); padding: 24px 8px; }
2469
+ dialog {
2470
+ border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
2471
+ color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
2472
+ }
2473
+ dialog::backdrop { background: rgb(20 19 17 / 0.45); }
2474
+ dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
2475
+ textarea {
2476
+ width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
2477
+ border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
2478
+ font-family: var(--mono); font-size: 12px;
2479
+ }
2480
+ .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
2481
+ .badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
2482
+ .badge.ok { background: var(--ok-soft); color: var(--ok); }
2483
+ .badge.warn { background: var(--warn-soft); color: var(--warn); }
2484
+ .status-2 { color: var(--ok); }
2485
+ .status-4, .status-5, .status-0 { color: var(--err); }
2486
+ .stack { display: flex; flex-direction: column; gap: 12px; }
2487
+ .route {
2488
+ display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
2489
+ padding: 8px 0; border-bottom: 1px solid var(--line);
2490
+ }
2491
+ .method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
2492
+ @media (max-width: 800px) {
2493
+ header.top {
2494
+ align-items: stretch; flex-direction: column;
2495
+ padding-top: max(10px, env(safe-area-inset-top));
2496
+ }
2497
+ input, select, textarea { font-size: 16px; }
2498
+ .brand, .vendor, .controls { width: 100%; }
2499
+ label.field, label.field select, label.field input { flex: 1; min-width: 0; }
2500
+ .layout { grid-template-columns: minmax(0, 1fr); }
2501
+ nav.side {
2502
+ flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
2503
+ border-right: 0; border-bottom: 1px solid var(--line);
2504
+ padding: 8px;
2505
+ }
2506
+ nav.side button { white-space: nowrap; flex: none; }
2507
+ .split { grid-template-columns: minmax(0, 1fr); }
2508
+ main { padding: 14px; }
2509
+ table, thead, tbody, tr, th, td { display: block; }
2510
+ thead { display: none; }
2511
+ tr {
2512
+ border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
2513
+ background: var(--bg-elev); min-width: 0;
2514
+ }
2515
+ td {
2516
+ border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
2517
+ min-width: 0; overflow-wrap: anywhere;
2518
+ }
2519
+ td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
2520
+ .route { grid-template-columns: 72px 1fr; }
2521
+ .route button { grid-column: 1 / -1; }
2522
+ }
2523
+ </style>
2524
+ </head>
2525
+ <body>
2526
+ <div class="app" data-service="${name}" data-mockingbird-admin>
2527
+ <header class="top">
2528
+ <div class="brand">
2529
+ <div class="brand-id">
2530
+ <strong>${name}</strong>
2531
+ <span>Admin</span>
2532
+ </div>
2533
+ <div class="vendor" id="vendor" hidden></div>
2534
+ </div>
2535
+ <div class="controls">
2536
+ <label class="field">Namespace
2537
+ <select id="namespace" aria-label="Namespace"></select>
2538
+ </label>
2539
+ <label class="field">Admin key
2540
+ <input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
2541
+ </label>
2542
+ <button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
2543
+ <button class="btn" id="refresh" type="button">Refresh</button>
2544
+ </div>
2545
+ </header>
2546
+ <div class="layout">
2547
+ <nav class="side" id="nav" aria-label="Admin sections">
2548
+ <button type="button" data-view="overview" aria-current="true">Overview</button>
2549
+ <button type="button" data-view="state">State</button>
2550
+ <button type="button" data-view="clock">Clock</button>
2551
+ <button type="button" data-view="faults">Faults</button>
2552
+ <button type="button" data-view="journal">Journal</button>
2553
+ <button type="button" data-view="routes">Routes</button>
2554
+ </nav>
2555
+ <main id="views">
2556
+ <p class="banner" id="banner" role="alert"></p>
2557
+ <section class="view" id="view-overview">
2558
+ <h2>Overview</h2>
2559
+ <p class="lede">Health, clock, and the collections this namespace is holding.</p>
2560
+ <div class="grid" id="overview-cards"></div>
2561
+ <h3>Recent requests</h3>
2562
+ <div id="overview-requests"></div>
2563
+ </section>
2564
+ <section class="view" id="view-state" hidden>
2565
+ <h2>State</h2>
2566
+ <p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
2567
+ <div class="split">
2568
+ <div id="collections"></div>
2569
+ <div>
2570
+ <div id="schema"></div>
2571
+ <div class="row-actions">
2572
+ <button class="btn-primary" id="new-record" type="button">New record</button>
2573
+ </div>
2574
+ <div id="records"></div>
2575
+ </div>
2576
+ </div>
2577
+ </section>
2578
+ <section class="view" id="view-clock" hidden>
2579
+ <h2>Clock</h2>
2580
+ <p class="lede">The clock every timestamp in this mock reads.</p>
2581
+ <div class="card" id="clock-readout"></div>
2582
+ <div class="row-actions">
2583
+ <button class="btn" type="button" data-advance="60000">+1m</button>
2584
+ <button class="btn" type="button" data-advance="900000">+15m</button>
2585
+ <button class="btn" type="button" data-advance="3600000">+1h</button>
2586
+ <button class="btn" type="button" data-advance="86400000">+1d</button>
2587
+ <button class="btn" type="button" data-advance="-3600000">\u22121h</button>
2588
+ <button class="btn" id="freeze" type="button">Freeze</button>
2589
+ <button class="btn-quiet" id="clock-reset" type="button">Reset</button>
2590
+ </div>
2591
+ <form id="clock-set" class="row-actions">
2592
+ <label class="field">Set instant
2593
+ <input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
2594
+ </label>
2595
+ <button class="btn-primary" type="submit">Set</button>
2596
+ </form>
2597
+ </section>
2598
+ <section class="view" id="view-faults" hidden>
2599
+ <h2>Faults</h2>
2600
+ <p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
2601
+ <form id="fault-form" class="card stack">
2602
+ <label class="field">Preset
2603
+ <select id="fault-preset"><option value="">Custom rule</option></select>
2604
+ </label>
2605
+ <label class="field">Status
2606
+ <input id="fault-status" inputmode="numeric" placeholder="503">
2607
+ </label>
2608
+ <label class="field">Path prefix
2609
+ <input id="fault-path" placeholder="/v1">
2610
+ </label>
2611
+ <label class="field">Method
2612
+ <input id="fault-method" placeholder="GET">
2613
+ </label>
2614
+ <div class="dialog-actions">
2615
+ <button class="btn-primary" type="submit">Add fault</button>
2616
+ <button class="btn-danger" id="fault-clear" type="button">Clear all</button>
2617
+ </div>
2618
+ </form>
2619
+ <div id="fault-list"></div>
2620
+ </section>
2621
+ <section class="view" id="view-journal" hidden>
2622
+ <h2>Journal</h2>
2623
+ <p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
2624
+ <div class="row-actions">
2625
+ <button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
2626
+ </div>
2627
+ <div id="journal"></div>
2628
+ </section>
2629
+ <section class="view" id="view-routes" hidden>
2630
+ <h2>Routes</h2>
2631
+ <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>
2632
+ <div id="route-list"></div>
2633
+ <form id="route-form" class="card stack">
2634
+ <strong id="route-title">Select a route</strong>
2635
+ <label class="field">JSON body
2636
+ <textarea id="route-body" placeholder="{ }"></textarea>
2637
+ </label>
2638
+ <div class="dialog-actions">
2639
+ <button class="btn-primary" type="submit">Send</button>
2640
+ </div>
2641
+ <pre id="route-result">Response will show here.</pre>
2642
+ </form>
2643
+ </section>
2644
+ </main>
2645
+ </div>
2646
+ </div>
2647
+ <dialog id="editor">
2648
+ <form method="dialog" id="editor-form">
2649
+ <strong id="editor-title">Record</strong>
2650
+ <label class="field">Id
2651
+ <input id="editor-id" required>
2652
+ </label>
2653
+ <label class="field">JSON value
2654
+ <textarea id="editor-value"></textarea>
2655
+ </label>
2656
+ <div class="dialog-actions">
2657
+ <button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
2658
+ <button class="btn-quiet" type="submit" value="cancel">Cancel</button>
2659
+ <button class="btn-primary" type="submit" value="save">Save</button>
2660
+ </div>
2661
+ </form>
2662
+ </dialog>
2663
+ ${script}
2664
+ </body>
2665
+ </html>`;
2666
+ };
2667
+ var htmlResponse = (body) => new Response(body, {
2668
+ status: 200,
2669
+ headers: {
2670
+ "content-type": "text/html; charset=utf-8",
2671
+ "cache-control": "no-store"
2672
+ }
2673
+ });
2674
+ var json2 = (body) => new Response(JSON.stringify(body), {
2675
+ status: 200,
2676
+ headers: { "content-type": "application/json; charset=utf-8" }
2677
+ });
2678
+ var adminUiRoutes = (service, ui) => {
2679
+ const shell = () => renderAdminDocument(service);
2680
+ const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
2681
+ return {
2682
+ "GET /ui": () => htmlResponse(document3()),
2683
+ "GET /ui/": () => htmlResponse(document3()),
2684
+ "GET /ui/manifest": () => json2({
2685
+ service,
2686
+ panels: (ui?.panels ?? []).map((panel) => ({
2687
+ id: panel.id,
2688
+ title: panel.title,
2689
+ ...panel.description !== void 0 ? { description: panel.description } : {},
2690
+ html: panel.html,
2691
+ ...panel.script !== void 0 ? { script: panel.script } : {}
2692
+ }))
2693
+ })
2694
+ };
2695
+ };
2696
+
964
2697
  // ../../../node_modules/.bun/hono@4.11.9/node_modules/hono/dist/request/constants.js
965
2698
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
966
2699
 
@@ -1428,8 +3161,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
1428
3161
  });
1429
3162
  };
1430
3163
 
3164
+ // ../core/dist/state-view.js
3165
+ var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
3166
+ var RECORD_ID = /^[^\s/]{1,256}$/;
3167
+ var SAMPLE = 25;
3168
+ var WALK_LIMIT = 1e4;
3169
+ var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
3170
+ var fail = (status, message) => ({ ok: false, status, message });
3171
+ var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3172
+ var kindOf = (value) => {
3173
+ if (value === null)
3174
+ return "null";
3175
+ if (Array.isArray(value))
3176
+ return "array";
3177
+ switch (typeof value) {
3178
+ case "string":
3179
+ return "string";
3180
+ case "number":
3181
+ return Number.isFinite(value) ? "number" : "unknown";
3182
+ case "boolean":
3183
+ return "boolean";
3184
+ case "object":
3185
+ return "object";
3186
+ default:
3187
+ return "unknown";
3188
+ }
3189
+ };
3190
+ var humanize = (name) => {
3191
+ const words = name.replace(/[@:_-]+/g, " ").trim();
3192
+ if (words === "")
3193
+ return name;
3194
+ return words.charAt(0).toUpperCase() + words.slice(1);
3195
+ };
3196
+ var jsonValue = (value) => {
3197
+ if (value === void 0)
3198
+ return fail(400, "value is required");
3199
+ try {
3200
+ return { ok: true, value: JSON.parse(JSON.stringify(value)) };
3201
+ } catch {
3202
+ return fail(400, "value must be JSON");
3203
+ }
3204
+ };
3205
+ var ctorName = (value) => {
3206
+ const ctor = value.constructor;
3207
+ return typeof ctor?.name === "string" ? ctor.name : "";
3208
+ };
3209
+ var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
3210
+ var discoverCollections = (root) => {
3211
+ const found = [];
3212
+ const seen = /* @__PURE__ */ new Set();
3213
+ const visit = (value, depth) => {
3214
+ if (found.length + seen.size > WALK_LIMIT)
3215
+ return;
3216
+ if (value === null || typeof value !== "object")
3217
+ return;
3218
+ if (seen.has(value))
3219
+ return;
3220
+ seen.add(value);
3221
+ if (value instanceof Collection) {
3222
+ found.push(value);
3223
+ return;
3224
+ }
3225
+ if (value instanceof Map) {
3226
+ for (const child of value.values())
3227
+ visit(child, depth + 1);
3228
+ return;
3229
+ }
3230
+ if (value instanceof Set) {
3231
+ for (const child of value.values())
3232
+ visit(child, depth + 1);
3233
+ return;
3234
+ }
3235
+ if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
3236
+ return;
3237
+ if (Array.isArray(value)) {
3238
+ const cap = Math.min(value.length, 32);
3239
+ for (let i = 0; i < cap; i++)
3240
+ visit(value[i], depth + 1);
3241
+ return;
3242
+ }
3243
+ let children;
3244
+ try {
3245
+ children = Object.values(value);
3246
+ } catch {
3247
+ return;
3248
+ }
3249
+ for (const child of children)
3250
+ visit(child, depth + 1);
3251
+ };
3252
+ visit(root, 0);
3253
+ return found;
3254
+ };
3255
+ var storedNames = (sqlite, namespace) => {
3256
+ const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
3257
+ const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
3258
+ return [...records, ...sequences].map((row) => row.name);
3259
+ };
3260
+ var blankAccum = (name) => ({
3261
+ name,
3262
+ kinds: /* @__PURE__ */ new Set(),
3263
+ present: 0,
3264
+ nested: /* @__PURE__ */ new Map()
3265
+ });
3266
+ var absorb = (accum, value) => {
3267
+ const kind = kindOf(value);
3268
+ accum.kinds.add(kind);
3269
+ accum.present++;
3270
+ if (!isRecord3(value))
3271
+ return;
3272
+ for (const [key, child] of Object.entries(value)) {
3273
+ const nested = accum.nested.get(key) ?? blankAccum(key);
3274
+ absorb(nested, child);
3275
+ accum.nested.set(key, nested);
3276
+ }
3277
+ };
3278
+ var finishField = (accum, samples) => {
3279
+ const kinds = [...accum.kinds];
3280
+ const kind = kinds.length === 1 ? kinds[0] : "unknown";
3281
+ const field = {
3282
+ name: accum.name,
3283
+ kind,
3284
+ optional: accum.present < samples || kinds.includes("null")
3285
+ };
3286
+ if (accum.nested.size > 0) {
3287
+ field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
3288
+ }
3289
+ return field;
3290
+ };
3291
+ var inferFields = (records) => {
3292
+ if (records.length === 0)
3293
+ return [];
3294
+ const sample = records.slice(0, SAMPLE);
3295
+ const objects = sample.filter((record2) => isRecord3(record2.value));
3296
+ if (objects.length === 0) {
3297
+ const kinds = new Set(sample.map((record2) => kindOf(record2.value)));
3298
+ const list = [...kinds];
3299
+ return [
3300
+ {
3301
+ name: "(value)",
3302
+ kind: list.length === 1 ? list[0] : "unknown",
3303
+ optional: false
3304
+ }
3305
+ ];
3306
+ }
3307
+ const root = /* @__PURE__ */ new Map();
3308
+ for (const record2 of objects) {
3309
+ for (const [key, value] of Object.entries(record2.value)) {
3310
+ const accum = root.get(key) ?? blankAccum(key);
3311
+ absorb(accum, value);
3312
+ root.set(key, accum);
3313
+ }
3314
+ }
3315
+ return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
3316
+ };
3317
+ var mergeFields = (declared, inferred) => {
3318
+ const byName = /* @__PURE__ */ new Map();
3319
+ for (const field of inferred)
3320
+ byName.set(field.name, field);
3321
+ const ordered = [];
3322
+ const seen = /* @__PURE__ */ new Set();
3323
+ for (const field of declared ?? []) {
3324
+ const found = byName.get(field.name);
3325
+ seen.add(field.name);
3326
+ if (!found) {
3327
+ ordered.push({ ...field, optional: field.optional });
3328
+ continue;
3329
+ }
3330
+ ordered.push({
3331
+ ...found,
3332
+ kind: field.kind === "unknown" ? found.kind : field.kind,
3333
+ optional: field.optional || found.optional,
3334
+ ...field.description !== void 0 ? { description: field.description } : {},
3335
+ ...field.meta !== void 0 ? { meta: field.meta } : {},
3336
+ ...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
3337
+ });
3338
+ }
3339
+ for (const field of inferred) {
3340
+ if (!seen.has(field.name))
3341
+ ordered.push(field);
3342
+ }
3343
+ return ordered;
3344
+ };
3345
+ var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
3346
+ var readRecord = (collection, id) => {
3347
+ const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
3348
+ const row = rows.find((entry) => entry.id === id);
3349
+ return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
3350
+ };
3351
+ var inspectState = (scope) => {
3352
+ const declared = /* @__PURE__ */ new Map();
3353
+ for (const declaration of scope.declarations ?? []) {
3354
+ if (COLLECTION_NAME.test(declaration.name))
3355
+ declared.set(declaration.name, declaration);
3356
+ }
3357
+ const names = new Set(declared.keys());
3358
+ for (const name of storedNames(scope.sqlite, scope.storageNamespace))
3359
+ names.add(name);
3360
+ for (const collection of discoverCollections(scope.root)) {
3361
+ if (collection.namespace === scope.storageNamespace)
3362
+ names.add(collection.collectionName);
3363
+ }
3364
+ const collections = [];
3365
+ for (const name of names) {
3366
+ if (!COLLECTION_NAME.test(name))
3367
+ continue;
3368
+ const declaration = declared.get(name);
3369
+ const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
3370
+ const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
3371
+ const inferred = inferFields(records);
3372
+ const fields = mergeFields(declaration?.fields, inferred);
3373
+ const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
3374
+ collections.push({
3375
+ name,
3376
+ label: declaration?.label ?? humanize(name),
3377
+ ...declaration?.description !== void 0 ? { description: declaration.description } : {},
3378
+ count: collection.count(),
3379
+ source,
3380
+ fields,
3381
+ ...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
3382
+ });
3383
+ }
3384
+ const order = /* @__PURE__ */ new Map();
3385
+ for (const [index, item] of (scope.declarations ?? []).entries())
3386
+ order.set(item.name, index);
3387
+ collections.sort((a, b) => {
3388
+ const left = order.get(a.name);
3389
+ const right = order.get(b.name);
3390
+ if (left !== void 0 && right !== void 0)
3391
+ return left - right;
3392
+ if (left !== void 0)
3393
+ return -1;
3394
+ if (right !== void 0)
3395
+ return 1;
3396
+ return a.name.localeCompare(b.name);
3397
+ });
3398
+ return {
3399
+ namespace: scope.namespace,
3400
+ storageNamespace: scope.storageNamespace,
3401
+ collections
3402
+ };
3403
+ };
3404
+ var pageOf = (sqlite, storageNamespace, name, query) => {
3405
+ if (!COLLECTION_NAME.test(name))
3406
+ return fail(400, "collection name is not allowed");
3407
+ const limit = query.limit ?? 50;
3408
+ if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
3409
+ return fail(400, "limit must be an integer from 1 to 200");
3410
+ }
3411
+ const order = query.order ?? "newest";
3412
+ if (order !== "newest" && order !== "oldest")
3413
+ return fail(400, 'order must be "newest" or "oldest"');
3414
+ const collection = collectionOf(sqlite, storageNamespace, name);
3415
+ const rows = collection.list({ order }).filter((row) => {
3416
+ if (query.after === void 0)
3417
+ return true;
3418
+ return order === "newest" ? row.seq < query.after : row.seq > query.after;
3419
+ });
3420
+ const slice = rows.slice(0, limit);
3421
+ const last = slice.at(-1);
3422
+ return {
3423
+ ok: true,
3424
+ value: {
3425
+ collection: name,
3426
+ count: collection.count(),
3427
+ records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
3428
+ next: rows.length > limit && last ? last.seq : null
3429
+ }
3430
+ };
3431
+ };
3432
+ var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
3433
+ var readStateRecord = (scope, name, id) => {
3434
+ if (!COLLECTION_NAME.test(name))
3435
+ return fail(400, "collection name is not allowed");
3436
+ if (!RECORD_ID.test(id))
3437
+ return fail(400, "record id is not allowed");
3438
+ const record2 = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
3439
+ return record2 ? { ok: true, value: record2 } : fail(404, `no record ${id} in ${name}`);
3440
+ };
3441
+ var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
3442
+ var createStateRecord = (scope, name, input) => {
3443
+ if (!COLLECTION_NAME.test(name))
3444
+ return fail(400, "collection name is not allowed");
3445
+ const parsed = jsonValue(input.value);
3446
+ if (!parsed.ok)
3447
+ return parsed;
3448
+ const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
3449
+ const id = input.id ?? `${name}_${collection.nextSequence()}`;
3450
+ const checked = requireId(id);
3451
+ if (!checked.ok)
3452
+ return checked;
3453
+ if (collection.has(checked.value))
3454
+ return fail(409, `record ${checked.value} already exists`);
3455
+ const stored = collection.insert(checked.value, parsed.value);
3456
+ return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
3457
+ };
3458
+ var replaceStateRecord = (scope, name, id, value) => {
3459
+ if (!COLLECTION_NAME.test(name))
3460
+ return fail(400, "collection name is not allowed");
3461
+ const checked = requireId(id);
3462
+ if (!checked.ok)
3463
+ return checked;
3464
+ const parsed = jsonValue(value);
3465
+ if (!parsed.ok)
3466
+ return parsed;
3467
+ const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
3468
+ if (!collection.has(checked.value))
3469
+ return fail(404, `no record ${checked.value} in ${name}`);
3470
+ const stored = collection.update(checked.value, parsed.value);
3471
+ if (!stored)
3472
+ return fail(404, `no record ${checked.value} in ${name}`);
3473
+ return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
3474
+ };
3475
+ var patchStateRecord = (scope, name, id, value) => {
3476
+ const current = readStateRecord(scope, name, id);
3477
+ if (!current.ok)
3478
+ return current;
3479
+ const parsed = jsonValue(value);
3480
+ if (!parsed.ok)
3481
+ return parsed;
3482
+ const next = isRecord3(current.value.value) && isRecord3(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
3483
+ return replaceStateRecord(scope, name, id, next);
3484
+ };
3485
+ var deleteStateRecord = (scope, name, id) => {
3486
+ if (!COLLECTION_NAME.test(name))
3487
+ return fail(400, "collection name is not allowed");
3488
+ const checked = requireId(id);
3489
+ if (!checked.ok)
3490
+ return checked;
3491
+ const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
3492
+ return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
3493
+ };
3494
+ var json3 = (status, body) => new Response(JSON.stringify(body), {
3495
+ status,
3496
+ headers: { "content-type": "application/json; charset=utf-8" }
3497
+ });
3498
+ var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
3499
+ var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
3500
+ var integerParam = (value) => {
3501
+ if (value === null)
3502
+ return void 0;
3503
+ if (!/^-?\d+$/.test(value))
3504
+ return "bad";
3505
+ return Number(value);
3506
+ };
3507
+ var stateAdminRoutes = (routes) => {
3508
+ const open = (namespace) => {
3509
+ try {
3510
+ return { ok: true, value: routes.open(namespace) };
3511
+ } catch (error2) {
3512
+ return fail(400, error2 instanceof Error ? error2.message : String(error2));
3513
+ }
3514
+ };
3515
+ const wrote = (namespace) => {
3516
+ routes.afterWrite?.(namespace);
3517
+ };
3518
+ return {
3519
+ "GET /state": ({ namespace }) => {
3520
+ const scope = open(namespace);
3521
+ return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
3522
+ },
3523
+ "GET /state/:collection": ({ namespace, params, url }) => {
3524
+ const scope = open(namespace);
3525
+ if (!scope.ok)
3526
+ return fromResult(scope, 200);
3527
+ const limit = integerParam(url.searchParams.get("limit"));
3528
+ const after = integerParam(url.searchParams.get("after"));
3529
+ if (limit === "bad")
3530
+ return adminError2(400, "limit: expected an integer");
3531
+ if (after === "bad")
3532
+ return adminError2(400, "after: expected a sequence number");
3533
+ const order = url.searchParams.get("order");
3534
+ return fromResult(readStatePage(scope.value, params.collection ?? "", {
3535
+ ...limit !== void 0 ? { limit } : {},
3536
+ ...after !== void 0 ? { after } : {},
3537
+ ...order === "newest" || order === "oldest" ? { order } : {}
3538
+ }), 200);
3539
+ },
3540
+ "GET /state/:collection/:id": ({ namespace, params }) => {
3541
+ const scope = open(namespace);
3542
+ if (!scope.ok)
3543
+ return fromResult(scope, 200);
3544
+ return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
3545
+ },
3546
+ "POST /state/:collection": ({ namespace, params, body }) => {
3547
+ const scope = open(namespace);
3548
+ if (!scope.ok)
3549
+ return fromResult(scope, 201);
3550
+ if (!isRecord3(body) || !("value" in body)) {
3551
+ return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
3552
+ }
3553
+ const id = body.id;
3554
+ if (id !== void 0 && typeof id !== "string")
3555
+ return adminError2(400, "id must be a string");
3556
+ const created = createStateRecord(scope.value, params.collection ?? "", {
3557
+ ...typeof id === "string" ? { id } : {},
3558
+ value: body.value
3559
+ });
3560
+ if (created.ok)
3561
+ wrote(namespace);
3562
+ return fromResult(created, 201);
3563
+ },
3564
+ "PUT /state/:collection/:id": ({ namespace, params, body }) => {
3565
+ const scope = open(namespace);
3566
+ if (!scope.ok)
3567
+ return fromResult(scope, 200);
3568
+ if (!isRecord3(body) || !("value" in body))
3569
+ return adminError2(400, 'expected {"value": <json>}');
3570
+ const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
3571
+ if (replaced.ok)
3572
+ wrote(namespace);
3573
+ return fromResult(replaced, 200);
3574
+ },
3575
+ "PATCH /state/:collection/:id": ({ namespace, params, body }) => {
3576
+ const scope = open(namespace);
3577
+ if (!scope.ok)
3578
+ return fromResult(scope, 200);
3579
+ if (!isRecord3(body) || !("value" in body))
3580
+ return adminError2(400, 'expected {"value": <json>}');
3581
+ const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
3582
+ if (patched.ok)
3583
+ wrote(namespace);
3584
+ return fromResult(patched, 200);
3585
+ },
3586
+ "DELETE /state/:collection/:id": ({ namespace, params }) => {
3587
+ const scope = open(namespace);
3588
+ if (!scope.ok)
3589
+ return fromResult(scope, 200);
3590
+ const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
3591
+ if (removed.ok)
3592
+ wrote(namespace);
3593
+ return fromResult(removed, 200);
3594
+ }
3595
+ };
3596
+ };
3597
+
1431
3598
  // ../core/dist/version.js
1432
- var PACKAGE_VERSION = true ? "1.3.0" : UNRELEASED_VERSION;
3599
+ var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
1433
3600
 
1434
3601
  // ../core/dist/signing.js
1435
3602
  var encoder = new TextEncoder();
@@ -1764,11 +3931,11 @@ var createWebhookHub = (options) => {
1764
3931
  };
1765
3932
  return hub;
1766
3933
  };
1767
- var json2 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
1768
- var adminError2 = (status, message) => json2(status, { error: { type: "mockingbird_admin", message } });
1769
- var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3934
+ var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
3935
+ var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
3936
+ var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1770
3937
  var parseEndpoint = (value) => {
1771
- if (!isRecord2(value) || typeof value.url !== "string")
3938
+ if (!isRecord4(value) || typeof value.url !== "string")
1772
3939
  return "each endpoint needs a url";
1773
3940
  try {
1774
3941
  new URL(value.url);
@@ -1785,18 +3952,18 @@ var parseEndpoint = (value) => {
1785
3952
  const events = value.events ?? value.enabledEvents;
1786
3953
  if (Array.isArray(events))
1787
3954
  endpoint.events = events.map(String);
1788
- if (isRecord2(value.tags)) {
3955
+ if (isRecord4(value.tags)) {
1789
3956
  endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
1790
3957
  }
1791
3958
  if (typeof value.account === "string")
1792
3959
  endpoint.tags = { ...endpoint.tags, account: value.account };
1793
- if (isRecord2(value.headers)) {
3960
+ if (isRecord4(value.headers)) {
1794
3961
  endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
1795
3962
  }
1796
3963
  return endpoint;
1797
3964
  };
1798
3965
  var webhookAdminRoutes = (hub) => ({
1799
- "GET /webhooks": ({ url, namespace }) => json2(200, {
3966
+ "GET /webhooks": ({ url, namespace }) => json4(200, {
1800
3967
  deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
1801
3968
  const type = url.searchParams.get("type");
1802
3969
  return type === null || d.type === type;
@@ -1804,51 +3971,51 @@ var webhookAdminRoutes = (hub) => ({
1804
3971
  }),
1805
3972
  "GET /webhooks/events": ({ url, namespace }) => {
1806
3973
  const type = url.searchParams.get("type");
1807
- return json2(200, {
3974
+ return json4(200, {
1808
3975
  events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
1809
3976
  });
1810
3977
  },
1811
3978
  "POST /webhooks/:id/replay": async ({ params }) => {
1812
3979
  const replayed = await hub.replay(params.id);
1813
- return replayed ? json2(200, replayed) : adminError2(404, `no delivery ${params.id}`);
3980
+ return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
1814
3981
  },
1815
3982
  "POST /webhooks/flush": async () => {
1816
3983
  await hub.flush();
1817
- return json2(200, { status: "ok" });
3984
+ return json4(200, { status: "ok" });
1818
3985
  },
1819
3986
  "POST /webhooks/faults": ({ body, namespace }) => {
1820
- if (!isRecord2(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
1821
- return adminError2(400, "mode must be duplicate, reorder or drop");
3987
+ if (!isRecord4(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
3988
+ return adminError3(400, "mode must be duplicate, reorder or drop");
1822
3989
  }
1823
3990
  const fault = { mode: body.mode };
1824
3991
  if (typeof body.count === "number")
1825
3992
  fault.count = body.count;
1826
3993
  hub.fault(namespace, fault);
1827
- return json2(201, { namespace, ...fault });
3994
+ return json4(201, { namespace, ...fault });
1828
3995
  },
1829
- "GET /webhook-endpoints": ({ namespace }) => json2(200, {
3996
+ "GET /webhook-endpoints": ({ namespace }) => json4(200, {
1830
3997
  endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
1831
3998
  ...rest,
1832
3999
  secret: secret ? "(set)" : null
1833
4000
  }))
1834
4001
  }),
1835
4002
  "PUT /webhook-endpoints": ({ body, namespace }) => {
1836
- const list = Array.isArray(body) ? body : isRecord2(body) ? body.endpoints : void 0;
4003
+ const list = Array.isArray(body) ? body : isRecord4(body) ? body.endpoints : void 0;
1837
4004
  if (!Array.isArray(list))
1838
- return adminError2(400, "expected [{url, secret?, events?}]");
4005
+ return adminError3(400, "expected [{url, secret?, events?}]");
1839
4006
  const parsed = [];
1840
4007
  for (const each of list) {
1841
4008
  const endpoint = parseEndpoint(each);
1842
4009
  if (typeof endpoint === "string")
1843
- return adminError2(400, endpoint);
4010
+ return adminError3(400, endpoint);
1844
4011
  parsed.push(endpoint);
1845
4012
  }
1846
4013
  const set = hub.setEndpoints(namespace, parsed);
1847
- return json2(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
4014
+ return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
1848
4015
  },
1849
4016
  "DELETE /webhook-endpoints": ({ namespace }) => {
1850
4017
  hub.setEndpoints(namespace, []);
1851
- return json2(200, { status: "ok" });
4018
+ return json4(200, { status: "ok" });
1852
4019
  }
1853
4020
  });
1854
4021
  var parsePayload = (message) => {
@@ -1901,8 +4068,8 @@ var DroppedConnectionError = class extends TypeError {
1901
4068
  this.name = "TypeError";
1902
4069
  }
1903
4070
  };
1904
- var operationMatcher = (document2) => {
1905
- const matchers = listOperations(document2).map((operation) => ({
4071
+ var operationMatcher = (document3) => {
4072
+ const matchers = listOperations(document3).map((operation) => ({
1906
4073
  operationId: operation.operationId,
1907
4074
  method: operation.method.toUpperCase(),
1908
4075
  pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
@@ -1911,6 +4078,7 @@ var operationMatcher = (document2) => {
1911
4078
  return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
1912
4079
  };
1913
4080
  var createRuntime = (options) => {
4081
+ assertAdminUi(options.adminUi);
1914
4082
  const sqlite = bootSqlite(options.sqlite);
1915
4083
  const clock = options.clock ?? createClock();
1916
4084
  const rng = createRng(options.seed ?? 0);
@@ -1996,10 +4164,10 @@ var createRuntime = (options) => {
1996
4164
  const ensureBranch = (namespace, branch2, at) => {
1997
4165
  if (!BRANCH_PATTERN2.test(branch2))
1998
4166
  throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
1999
- const history = timeline(namespace);
4167
+ const history2 = timeline(namespace);
2000
4168
  if (branch2 === "main") {
2001
4169
  if (at !== void 0) {
2002
- const point = history.checkout("main", at);
4170
+ const point = history2.checkout("main", at);
2003
4171
  restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
2004
4172
  captured.set(namespace, point.value.snapshot);
2005
4173
  rng.setState(point.value.rngState);
@@ -2012,10 +4180,10 @@ var createRuntime = (options) => {
2012
4180
  return namespace;
2013
4181
  }
2014
4182
  const storage = physicalBranch(namespace, branch2);
2015
- if (!history.hasBranch(branch2)) {
4183
+ if (!history2.hasBranch(branch2)) {
2016
4184
  if (at === void 0)
2017
- history.commit(capture(namespace));
2018
- const point = history.fork(branch2, at === void 0 ? {} : { from: at });
4185
+ history2.commit(capture(namespace));
4186
+ const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
2019
4187
  const branchRng = createRng(options.seed ?? 0);
2020
4188
  if (point)
2021
4189
  branchRng.setState(point.value.rngState);
@@ -2024,8 +4192,8 @@ var createRuntime = (options) => {
2024
4192
  restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
2025
4193
  if (point)
2026
4194
  captured.set(storage, point.value.snapshot);
2027
- } else if (at !== void 0 && history.head(branch2)?.id !== at) {
2028
- const point = history.checkout(branch2, at);
4195
+ } else if (at !== void 0 && history2.head(branch2)?.id !== at) {
4196
+ const point = history2.checkout(branch2, at);
2029
4197
  if (!instances.has(storage)) {
2030
4198
  const branchRng = createRng(options.seed ?? 0);
2031
4199
  branchRng.setState(point.value.rngState);
@@ -2036,7 +4204,7 @@ var createRuntime = (options) => {
2036
4204
  captured.set(storage, point.value.snapshot);
2037
4205
  } else {
2038
4206
  if (!instances.has(storage)) {
2039
- const point = history.head(branch2);
4207
+ const point = history2.head(branch2);
2040
4208
  const branchRng = createRng(options.seed ?? 0);
2041
4209
  if (point)
2042
4210
  branchRng.setState(point.value.rngState);
@@ -2060,8 +4228,8 @@ var createRuntime = (options) => {
2060
4228
  const checkout = (checkpointId, checkoutOptions = {}) => {
2061
4229
  const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
2062
4230
  const branchName = checkoutOptions.branch ?? "main";
2063
- const history = timeline(namespace);
2064
- const point = history.checkout(branchName, checkpointId);
4231
+ const history2 = timeline(namespace);
4232
+ const point = history2.checkout(branchName, checkpointId);
2065
4233
  const storage = ensureBranch(namespace, branchName);
2066
4234
  restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
2067
4235
  captured.set(storage, point.value.snapshot);
@@ -2111,12 +4279,25 @@ var createRuntime = (options) => {
2111
4279
  instance(name);
2112
4280
  restoreNamespace(sqlite, storageNamespace(name), from);
2113
4281
  captured.set(name, from);
2114
- const history = timelines.get(name);
2115
- if (history)
2116
- history.commit(capture(name), { branch: "main" });
4282
+ const history2 = timelines.get(name);
4283
+ if (history2)
4284
+ history2.commit(capture(name), { branch: "main" });
2117
4285
  else
2118
4286
  timeline(name);
2119
4287
  };
4288
+ const declarationsFor = (namespace) => {
4289
+ const declared = options.state;
4290
+ if (!declared)
4291
+ return [];
4292
+ return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
4293
+ };
4294
+ const stateScope = (namespace) => ({
4295
+ sqlite,
4296
+ namespace,
4297
+ storageNamespace: storageNamespace(namespace),
4298
+ root: instance(namespace),
4299
+ declarations: declarationsFor(namespace)
4300
+ });
2120
4301
  const runtime = {
2121
4302
  name: options.name,
2122
4303
  sqlite,
@@ -2155,6 +4336,7 @@ var createRuntime = (options) => {
2155
4336
  branch,
2156
4337
  checkout,
2157
4338
  timeline,
4339
+ state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
2158
4340
  fetch: async (incoming) => {
2159
4341
  let request = incoming;
2160
4342
  const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
@@ -2328,10 +4510,10 @@ var createRuntime = (options) => {
2328
4510
  },
2329
4511
  release: (name, checkpointId) => timeline(name).release(checkpointId),
2330
4512
  inspect: (name) => {
2331
- const history = timeline(name);
4513
+ const history2 = timeline(name);
2332
4514
  return {
2333
- branches: history.branches(),
2334
- checkpoints: history.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
4515
+ branches: history2.branches(),
4516
+ checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
2335
4517
  id,
2336
4518
  branch: branchName,
2337
4519
  parent,
@@ -2346,13 +4528,22 @@ var createRuntime = (options) => {
2346
4528
  } : {},
2347
4529
  routes: {
2348
4530
  ...credentialRoutes(credentials),
2349
- ...options.presets ? presetRoutes(options.presets, runtime) : {},
2350
4531
  ...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
2351
- ...options.admin?.(runtime) ?? {}
4532
+ ...options.admin?.(runtime) ?? {},
4533
+ // Shell routes win a colliding key. Fault presets are one of them: the admin page
4534
+ // maps `presets`, and a service route must not replace that list with a record.
4535
+ ...options.presets ? presetRoutes(options.presets, runtime) : {},
4536
+ ...stateAdminRoutes({
4537
+ open: stateScope,
4538
+ afterWrite: (namespace) => {
4539
+ checkpoint(namespace, "main");
4540
+ }
4541
+ }),
4542
+ ...adminUiRoutes(options.name, options.adminUi)
2352
4543
  },
2353
4544
  adminKey: options.adminKey
2354
4545
  });
2355
- return runtime;
4546
+ return defineMock(runtime);
2356
4547
  };
2357
4548
  var mutableResponse = (response) => {
2358
4549
  try {
@@ -2416,9 +4607,12 @@ var credentialRoutes = (registry) => ({
2416
4607
  }
2417
4608
  });
2418
4609
  var presetRoutes = (presets, runtime) => ({
2419
- "GET /faults/presets": () => adminJson(200, {
2420
- presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
2421
- }),
4610
+ "GET /faults/presets": () => {
4611
+ const body = {
4612
+ presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
4613
+ };
4614
+ return adminJson(200, body);
4615
+ },
2422
4616
  "POST /faults/presets/:name": ({ params, body, namespace }) => {
2423
4617
  const name = params.name;
2424
4618
  if (!presets[name])
@@ -2476,7 +4670,7 @@ var verifyJwt = async (token, secrets, now) => {
2476
4670
  var bodySha256 = async (body) => bytesToBase64(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder2.encode(body))));
2477
4671
 
2478
4672
  // src/generated/openapi.ts
2479
- var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"LiveKit Server API (Mockingbird subset)","version":"2.19.1","description":"Twirp JSON room, participant, egress, and SIP contract."},"servers":[{"url":"https://example.livekit.cloud"}],"paths":{"/twirp/livekit.RoomService/{method}":{"post":{"operationId":"RoomService","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"method","in":"path","required":true,"schema":{"type":"string"}},{"name":"Authorization","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Protobuf JSON response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"400":{"description":"Twirp error","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}}}}},"/twirp/livekit.Egress/{method}":{"post":{"operationId":"EgressService","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"method","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Protobuf JSON response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}}}}},"/twirp/livekit.SIP/{method}":{"post":{"operationId":"SipService","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"method","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Protobuf JSON response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}}}}}}}`);
4673
+ var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"LiveKit Server API (Mockingbird subset)","version":"2.19.1","description":"Twirp JSON room, participant, egress, and SIP contract."},"servers":[{"url":"https://example.livekit.cloud"}],"paths":{"/twirp/livekit.RoomService/{method}":{"post":{"operationId":"RoomService","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"method","in":"path","required":true,"schema":{"type":"string"}},{"name":"Authorization","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Protobuf JSON response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"400":{"description":"Twirp error","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}}}}},"/twirp/livekit.Egress/{method}":{"post":{"operationId":"EgressService","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"method","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Protobuf JSON response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}}}}},"/twirp/livekit.SIP/{method}":{"post":{"operationId":"SipService","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"method","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Protobuf JSON response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true}}}}}}}}}`);
2480
4674
  var operationIds = ["RoomService", "EgressService", "SipService"];
2481
4675
  var supportedOperationIds = ["RoomService", "EgressService", "SipService"];
2482
4676
 
@@ -2594,7 +4788,7 @@ var createRuntime2 = (options = {}) => {
2594
4788
  });
2595
4789
  const runtime = createRuntime({
2596
4790
  name: LIVEKIT_NAMESPACE,
2597
- document,
4791
+ document: document2,
2598
4792
  presets: LIVEKIT_PRESETS,
2599
4793
  ...options.sqlite ? { sqlite: options.sqlite } : {},
2600
4794
  ...options.clock ? { clock: options.clock } : {},
@@ -2973,7 +5167,7 @@ var LiveKitAPI = class {
2973
5167
  };
2974
5168
 
2975
5169
  export {
2976
- document,
5170
+ document2 as document,
2977
5171
  operationIds,
2978
5172
  supportedOperationIds,
2979
5173
  LIVEKIT_PRESETS,
@@ -2981,4 +5175,4 @@ export {
2981
5175
  LIVEKIT_NAMESPACE,
2982
5176
  LiveKitAPI
2983
5177
  };
2984
- //# sourceMappingURL=chunk-TV3OEFVK.js.map
5178
+ //# sourceMappingURL=chunk-PGZZE4OX.js.map