@zackbart/connecta 0.7.8 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +67 -144
  3. package/dist/activity.d.ts +1 -1
  4. package/dist/activity.d.ts.map +1 -1
  5. package/dist/activity.js.map +1 -1
  6. package/dist/auth/bearer.d.ts +1 -1
  7. package/dist/auth/bearer.js +4 -4
  8. package/dist/auth/bearer.js.map +1 -1
  9. package/dist/auth/clerk.d.ts +1 -1
  10. package/dist/auth/clerk.js +1 -1
  11. package/dist/call-admission.d.ts +81 -0
  12. package/dist/call-admission.d.ts.map +1 -0
  13. package/dist/call-admission.js +345 -0
  14. package/dist/call-admission.js.map +1 -0
  15. package/dist/catalog-fingerprint.d.ts +20 -0
  16. package/dist/catalog-fingerprint.d.ts.map +1 -0
  17. package/dist/catalog-fingerprint.js +34 -0
  18. package/dist/catalog-fingerprint.js.map +1 -0
  19. package/dist/catalog-limits.d.ts +10 -0
  20. package/dist/catalog-limits.d.ts.map +1 -0
  21. package/dist/catalog-limits.js +10 -0
  22. package/dist/catalog-limits.js.map +1 -0
  23. package/dist/catalog-service.d.ts +138 -0
  24. package/dist/catalog-service.d.ts.map +1 -0
  25. package/dist/catalog-service.js +407 -0
  26. package/dist/catalog-service.js.map +1 -0
  27. package/dist/catalog.js +2 -2
  28. package/dist/catalog.js.map +1 -1
  29. package/dist/concurrency.d.ts +4 -0
  30. package/dist/concurrency.d.ts.map +1 -0
  31. package/dist/concurrency.js +31 -0
  32. package/dist/concurrency.js.map +1 -0
  33. package/dist/connectors/api.d.ts +3 -1
  34. package/dist/connectors/api.d.ts.map +1 -1
  35. package/dist/connectors/api.js +22 -11
  36. package/dist/connectors/api.js.map +1 -1
  37. package/dist/connectors/remote-mcp.d.ts +3 -1
  38. package/dist/connectors/remote-mcp.d.ts.map +1 -1
  39. package/dist/connectors/remote-mcp.js +44 -18
  40. package/dist/connectors/remote-mcp.js.map +1 -1
  41. package/dist/credential-health.d.ts +0 -22
  42. package/dist/credential-health.d.ts.map +1 -1
  43. package/dist/credential-health.js +14 -10
  44. package/dist/credential-health.js.map +1 -1
  45. package/dist/credentials.d.ts +3 -2
  46. package/dist/credentials.d.ts.map +1 -1
  47. package/dist/errors.d.ts +1 -1
  48. package/dist/errors.d.ts.map +1 -1
  49. package/dist/errors.js.map +1 -1
  50. package/dist/execute.d.ts +9 -8
  51. package/dist/execute.d.ts.map +1 -1
  52. package/dist/execute.js +144 -291
  53. package/dist/execute.js.map +1 -1
  54. package/dist/executor-result.d.ts +0 -3
  55. package/dist/executor-result.d.ts.map +1 -1
  56. package/dist/executor-result.js +2 -2
  57. package/dist/executor-result.js.map +1 -1
  58. package/dist/executors/quickjs-child.js +3 -3
  59. package/dist/executors/quickjs-child.js.map +1 -1
  60. package/dist/executors/quickjs-protocol.d.ts +4 -1
  61. package/dist/executors/quickjs-protocol.d.ts.map +1 -1
  62. package/dist/executors/quickjs-runtime.d.ts.map +1 -1
  63. package/dist/executors/quickjs-runtime.js +7 -2
  64. package/dist/executors/quickjs-runtime.js.map +1 -1
  65. package/dist/executors/quickjs.d.ts.map +1 -1
  66. package/dist/executors/quickjs.js +4 -1
  67. package/dist/executors/quickjs.js.map +1 -1
  68. package/dist/favicon.js +2 -2
  69. package/dist/favicon.js.map +1 -1
  70. package/dist/index.d.ts +6 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +45 -17
  73. package/dist/index.js.map +1 -1
  74. package/dist/invocation.d.ts +96 -0
  75. package/dist/invocation.d.ts.map +1 -0
  76. package/dist/invocation.js +369 -0
  77. package/dist/invocation.js.map +1 -0
  78. package/dist/meta-tools.d.ts +11 -86
  79. package/dist/meta-tools.d.ts.map +1 -1
  80. package/dist/meta-tools.js +145 -485
  81. package/dist/meta-tools.js.map +1 -1
  82. package/dist/operator-ui/generated.d.ts +3 -0
  83. package/dist/operator-ui/generated.d.ts.map +1 -0
  84. package/dist/operator-ui/generated.js +5 -0
  85. package/dist/operator-ui/generated.js.map +1 -0
  86. package/dist/operator-ui/model.d.ts +94 -0
  87. package/dist/operator-ui/model.d.ts.map +1 -0
  88. package/dist/operator-ui/model.js +28 -0
  89. package/dist/operator-ui/model.js.map +1 -0
  90. package/dist/registry.d.ts +47 -6
  91. package/dist/registry.d.ts.map +1 -1
  92. package/dist/registry.js +356 -35
  93. package/dist/registry.js.map +1 -1
  94. package/dist/routes/activity.d.ts +3 -0
  95. package/dist/routes/activity.d.ts.map +1 -0
  96. package/dist/routes/activity.js +173 -0
  97. package/dist/routes/activity.js.map +1 -0
  98. package/dist/routes/credentials.d.ts +3 -0
  99. package/dist/routes/credentials.d.ts.map +1 -0
  100. package/dist/routes/credentials.js +181 -0
  101. package/dist/routes/credentials.js.map +1 -0
  102. package/dist/routes/mcp.d.ts +8 -0
  103. package/dist/routes/mcp.d.ts.map +1 -0
  104. package/dist/routes/mcp.js +383 -0
  105. package/dist/routes/mcp.js.map +1 -0
  106. package/dist/routes/oauth.d.ts +4 -0
  107. package/dist/routes/oauth.d.ts.map +1 -0
  108. package/dist/routes/oauth.js +268 -0
  109. package/dist/routes/oauth.js.map +1 -0
  110. package/dist/routes/shared.d.ts +97 -0
  111. package/dist/routes/shared.d.ts.map +1 -0
  112. package/dist/routes/shared.js +199 -0
  113. package/dist/routes/shared.js.map +1 -0
  114. package/dist/routes/ui.d.ts +3 -0
  115. package/dist/routes/ui.d.ts.map +1 -0
  116. package/dist/routes/ui.js +122 -0
  117. package/dist/routes/ui.js.map +1 -0
  118. package/dist/server.d.ts +9 -40
  119. package/dist/server.d.ts.map +1 -1
  120. package/dist/server.js +67 -1292
  121. package/dist/server.js.map +1 -1
  122. package/dist/skills.d.ts +0 -15
  123. package/dist/skills.d.ts.map +1 -1
  124. package/dist/skills.js +6 -5
  125. package/dist/skills.js.map +1 -1
  126. package/dist/storage/file.d.ts.map +1 -1
  127. package/dist/storage/file.js +3 -1
  128. package/dist/storage/file.js.map +1 -1
  129. package/dist/storage/memory.d.ts.map +1 -1
  130. package/dist/storage/memory.js +3 -1
  131. package/dist/storage/memory.js.map +1 -1
  132. package/dist/toolkits.d.ts +0 -22
  133. package/dist/toolkits.d.ts.map +1 -1
  134. package/dist/toolkits.js +2 -2
  135. package/dist/toolkits.js.map +1 -1
  136. package/dist/types.d.ts +64 -2
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/ui.d.ts +3 -93
  139. package/dist/ui.d.ts.map +1 -1
  140. package/dist/ui.js +26 -1389
  141. package/dist/ui.js.map +1 -1
  142. package/dist/version.d.ts +1 -1
  143. package/dist/version.js +1 -1
  144. package/package.json +15 -8
  145. package/src/activity.ts +5 -1
  146. package/src/auth/bearer.ts +4 -4
  147. package/src/auth/clerk.ts +1 -1
  148. package/src/call-admission.ts +522 -0
  149. package/src/catalog-fingerprint.ts +52 -0
  150. package/src/catalog-limits.ts +11 -0
  151. package/src/catalog-service.ts +601 -0
  152. package/src/catalog.ts +2 -2
  153. package/src/concurrency.ts +39 -0
  154. package/src/connectors/api.ts +25 -11
  155. package/src/connectors/remote-mcp.ts +55 -21
  156. package/src/credential-health.ts +13 -10
  157. package/src/credentials.ts +2 -2
  158. package/src/errors.ts +1 -1
  159. package/src/execute.ts +194 -377
  160. package/src/executor-result.ts +2 -2
  161. package/src/executors/quickjs-child.ts +8 -4
  162. package/src/executors/quickjs-protocol.ts +1 -1
  163. package/src/executors/quickjs-runtime.ts +5 -1
  164. package/src/executors/quickjs.ts +11 -8
  165. package/src/favicon.ts +2 -2
  166. package/src/index.ts +54 -17
  167. package/src/invocation.ts +527 -0
  168. package/src/meta-tools.ts +369 -797
  169. package/src/operator-ui/browser.css +413 -0
  170. package/src/operator-ui/browser.ts +1121 -0
  171. package/src/operator-ui/generated.ts +4 -0
  172. package/src/operator-ui/model.ts +127 -0
  173. package/src/registry.ts +489 -44
  174. package/src/routes/activity.ts +220 -0
  175. package/src/routes/credentials.ts +266 -0
  176. package/src/routes/mcp.ts +485 -0
  177. package/src/routes/oauth.ts +328 -0
  178. package/src/routes/shared.ts +330 -0
  179. package/src/routes/ui.ts +153 -0
  180. package/src/server.ts +70 -1702
  181. package/src/skills.ts +6 -5
  182. package/src/storage/file.ts +3 -1
  183. package/src/storage/memory.ts +3 -1
  184. package/src/toolkits.ts +2 -2
  185. package/src/types.ts +70 -2
  186. package/src/ui.ts +52 -1489
  187. package/src/version.ts +1 -1
package/src/ui.ts CHANGED
@@ -8,11 +8,33 @@ import {
8
8
  closeConnectorScope,
9
9
  type DeferredWork,
10
10
  } from "./connector-scope.js";
11
+ import {
12
+ mapSettledWithConcurrency,
13
+ resolveDiscoveryConcurrency,
14
+ } from "./concurrency.js";
15
+ import {
16
+ type CredentialManagementCapability,
17
+ type UiConnector,
18
+ type UiData,
19
+ type UiToolkit,
20
+ type UiTool,
21
+ } from "./operator-ui/model.js";
22
+ import {
23
+ OPERATOR_UI_CSS,
24
+ OPERATOR_UI_SCRIPT,
25
+ } from "./operator-ui/generated.js";
11
26
  import type { Registry } from "./registry.js";
12
27
  import type { Toolkit } from "./toolkits.js";
13
28
  import type { ConnectaBranding, UiAuthConfig } from "./types.js";
14
29
  import { CONNECTA_VERSION } from "./version.js";
15
30
 
31
+ export {
32
+ filterUiConnectors,
33
+ type CredentialManagementCapability,
34
+ type UiConnector,
35
+ type UiData,
36
+ } from "./operator-ui/model.js";
37
+
16
38
  /** Connecta's default monochrome "C" mark. */
17
39
  export const CONNECTA_FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
18
40
  <style>
@@ -35,7 +57,7 @@ interface ResolvedBranding {
35
57
  themeColor: string;
36
58
  }
37
59
 
38
- export const DEFAULT_FAVICON_HREF = "/favicon.svg";
60
+ const DEFAULT_FAVICON_HREF = "/favicon.svg";
39
61
 
40
62
  /**
41
63
  * Branding arrives from operator config, which is untyped at a JS call site, so
@@ -91,6 +113,14 @@ function isSetUrlValue(value: unknown): boolean {
91
113
  : value !== undefined && value !== null;
92
114
  }
93
115
 
116
+ /**
117
+ * A JS string literal safe to inline in a script element. Escaping `/` keeps
118
+ * an operator-supplied `</script>` from terminating the element early.
119
+ */
120
+ function stringForInlineScript(value: string): string {
121
+ return JSON.stringify(value).replace(/\//g, "\\/");
122
+ }
123
+
94
124
  /**
95
125
  * Names of the branding URLs the operator set that failed their gate and were
96
126
  * replaced by a default. Lives beside the gates so the startup warning cannot
@@ -115,15 +145,6 @@ export function droppedBrandingUrls(branding?: ConnectaBranding): string[] {
115
145
  ];
116
146
  }
117
147
 
118
- /**
119
- * A JS string literal safe to inline in a <script> block. JSON.stringify alone
120
- * leaves `/` untouched, so a value containing "</script>" would close the
121
- * element early — operator-supplied branding still goes through here.
122
- */
123
- function escapeScriptString(value: string): string {
124
- return JSON.stringify(value).replace(/\//g, "\\/");
125
- }
126
-
127
148
  /**
128
149
  * True only for absolute `http:`/`https:` URLs. Downstream connectors control
129
150
  * their `authorizationUrl`, so a hostile/misconfigured one could hand back a
@@ -242,92 +263,6 @@ export function droppedUiAuthUrls(uiAuth?: UiAuthConfig): string[] {
242
263
  ];
243
264
  }
244
265
 
245
- export interface UiTool {
246
- name: string;
247
- address: string;
248
- description?: string;
249
- }
250
-
251
- export interface UiConnector {
252
- id: string;
253
- title?: string;
254
- description?: string;
255
- status: "ok" | "auth_required" | "error";
256
- message?: string;
257
- authorizationUrl?: string;
258
- toolCount: number;
259
- tools: UiTool[];
260
- /** This connector exposes operator-managed downstream OAuth lifecycle hooks. */
261
- oauth?: boolean;
262
- /**
263
- * Verdict of the last proactive credential liveness check (issue #24), for the
264
- * connectors that hold a credential connecta stores. Shown beside the live
265
- * status so an operator can tell "checked just now" from "last verified an
266
- * hour ago", and see a dead credential the page's own probe may not reach.
267
- */
268
- credentialCheck?: {
269
- state: "ok" | "auth_required" | "error";
270
- checkedAt: string;
271
- message?: string;
272
- };
273
- credential?: {
274
- label: string;
275
- description?: string;
276
- placeholder?: string;
277
- fields?: Array<{
278
- name: string;
279
- label: string;
280
- description?: string;
281
- placeholder?: string;
282
- inputType: "email" | "password" | "text";
283
- configured: boolean;
284
- lastFour?: string;
285
- updatedAt?: string;
286
- }>;
287
- configured: boolean;
288
- /** A stored value exists and may be deleted even if it cannot be decrypted. */
289
- removable?: boolean;
290
- lastFour?: string;
291
- updatedAt?: string;
292
- testable: boolean;
293
- error?: string;
294
- /**
295
- * Something true and non-blocking about a working credential — today, that
296
- * the vault still holds fields the connector has stopped declaring.
297
- * Distinct from `error`, which means the credential cannot be used.
298
- */
299
- notice?: string;
300
- };
301
- }
302
-
303
- export interface UiData {
304
- serverInfo: { name: string; version: string };
305
- /** Version of the installed @zackbart/connecta package. */
306
- connectaVersion: string;
307
- connectors: UiConnector[];
308
- /** Read-only projection of the validated deployment config. */
309
- toolkits: UiToolkit[];
310
- activityEnabled: boolean;
311
- credentialManagement: CredentialManagementCapability;
312
- /** True only for an eligible, unrestricted Clerk operator. */
313
- oauthManagement: boolean;
314
- }
315
-
316
- export interface UiToolkit {
317
- name: string;
318
- connectors: string[];
319
- includeTools: string[];
320
- excludeTools: string[];
321
- /** Tools currently loaded through healthy connectors and visible in this view. */
322
- toolCount: number;
323
- }
324
-
325
- export type CredentialManagementCapability =
326
- | "available"
327
- | "requires_clerk"
328
- | "vault_not_configured"
329
- | "no_slots";
330
-
331
266
  export type OperatorPage = "connections" | "credentials" | "activity";
332
267
 
333
268
  const OPERATOR_PAGE_LABELS: Readonly<Record<OperatorPage, string>> = {
@@ -361,44 +296,6 @@ export function credentialManagementCapability(input: {
361
296
  return "available";
362
297
  }
363
298
 
364
- export interface FilteredUiConnector {
365
- connector: UiConnector;
366
- tools: UiTool[];
367
- }
368
-
369
- /**
370
- * Filter by connector identity/description or tool name/description. A
371
- * connector-level match stays visible even when it currently exposes no tools
372
- * (for example while authorization is required).
373
- */
374
- export function filterUiConnectors(
375
- connectors: UiConnector[],
376
- query: string,
377
- ): FilteredUiConnector[] {
378
- const q = query.trim().toLowerCase();
379
- const filtered: FilteredUiConnector[] = [];
380
- for (const connector of connectors) {
381
- const connectorText = [
382
- connector.id,
383
- connector.title,
384
- connector.description,
385
- connector.status,
386
- ]
387
- .join(" ")
388
- .toLowerCase();
389
- const connectorMatches = Boolean(q && connectorText.includes(q));
390
- const tools = connector.tools.filter(
391
- (tool) =>
392
- !q ||
393
- connectorMatches ||
394
- `${tool.name} ${tool.description ?? ""}`.toLowerCase().includes(q),
395
- );
396
- if (q && tools.length === 0 && !connectorMatches) continue;
397
- filtered.push({ connector, tools });
398
- }
399
- return filtered;
400
- }
401
-
402
299
  /**
403
300
  * Build the read-only status payload served at `/ui/data`. Broken connectors are
404
301
  * isolated: they surface status "error" with an empty tool list rather than
@@ -416,11 +313,15 @@ export async function buildUiData(
416
313
  toolkits?: ReadonlyMap<string, Toolkit>,
417
314
  defer?: DeferredWork,
418
315
  oauthManagement = false,
316
+ discoveryConcurrency?: number,
419
317
  ): Promise<UiData> {
420
318
  const requestScope = {};
421
319
  const connectorSet = registry.listConnectors();
422
- const settled = await Promise.allSettled(
423
- connectorSet.map(async (c): Promise<UiConnector> => {
320
+ const concurrency = resolveDiscoveryConcurrency(discoveryConcurrency);
321
+ const settled = await mapSettledWithConcurrency(
322
+ connectorSet,
323
+ concurrency,
324
+ async (c): Promise<UiConnector> => {
424
325
  const status = await registry.statusFor(c.id, baseUrl, requestScope);
425
326
  const credentialCheck = await registry.credentialHealthFor(c.id);
426
327
  let tools: UiTool[] = [];
@@ -436,7 +337,9 @@ export async function buildUiData(
436
337
  ).map((t) => ({
437
338
  name: t.name,
438
339
  address: `${c.id}.${t.name}`,
439
- description: t.description,
340
+ ...(t.description !== undefined
341
+ ? { description: t.description }
342
+ : {}),
440
343
  }));
441
344
  } catch {
442
345
  // broken connector: reported via status "error", tools stay empty
@@ -533,7 +436,9 @@ export async function buildUiData(
533
436
  return {
534
437
  id: c.id,
535
438
  ...(c.title ? { title: c.title } : {}),
536
- description: c.description,
439
+ ...(c.description !== undefined
440
+ ? { description: c.description }
441
+ : {}),
537
442
  status: status.state,
538
443
  ...(status.message ? { message: status.message } : {}),
539
444
  ...(isSafeHttpUrl(status.authorizationUrl)
@@ -555,16 +460,17 @@ export async function buildUiData(
555
460
  : {}),
556
461
  ...(credential ? { credential } : {}),
557
462
  };
558
- }),
463
+ },
559
464
  );
560
- await Promise.all(
561
- connectorSet.map((connector) =>
465
+ await mapSettledWithConcurrency(
466
+ connectorSet,
467
+ concurrency,
468
+ (connector) =>
562
469
  closeConnectorScope(
563
470
  connector,
564
471
  registry.contextFor(connector.id, baseUrl, requestScope),
565
472
  defer,
566
473
  ),
567
- ),
568
474
  );
569
475
  const connectors = settled.map((result) => {
570
476
  if (result.status === "rejected") throw result.reason;
@@ -690,420 +596,7 @@ export function renderUiHtml(
690
596
  <link rel="shortcut icon" href="/favicon.ico">
691
597
  <title>${escapeHtmlAttr(title)}</title>
692
598
  ${clerkScript}
693
- <style>
694
- :root {
695
- color-scheme: light;
696
- --ink: #000;
697
- --paper: #fff;
698
- --rule: #ccc;
699
- --muted: #666;
700
- --trace: #f5f5f5;
701
- --shell: 70rem;
702
- --pad: 1rem;
703
- --gap: 1.5rem;
704
- --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
705
- --mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Code", Consolas,
706
- monospace;
707
- }
708
- * { border-radius: 0; box-sizing: border-box; }
709
- html {
710
- background: var(--paper);
711
- color: var(--ink);
712
- font-family: var(--sans);
713
- font-size: 16px;
714
- line-height: 1.5;
715
- -webkit-font-smoothing: antialiased;
716
- text-rendering: optimizeLegibility;
717
- }
718
- body { margin: 0; min-height: 100vh; }
719
- ::selection { background: var(--ink); color: var(--paper); }
720
- :is(h1, h2, h3, p, ul, ol) { margin: 0; padding: 0; }
721
- :is(h1, h2, h3) { font-size: inherit; font-weight: 400; }
722
- :is(ul, ol) { list-style: none; }
723
- a { color: inherit; }
724
- button, input { font: inherit; }
725
- button {
726
- background: none;
727
- border: 0;
728
- color: inherit;
729
- cursor: pointer;
730
- margin: 0;
731
- padding: 0;
732
- text-align: left;
733
- }
734
- button:disabled { cursor: wait; opacity: .5; }
735
- input {
736
- background: var(--paper);
737
- border: 1px solid var(--rule);
738
- color: var(--ink);
739
- min-height: 2rem;
740
- padding: .2rem .5rem;
741
- }
742
- input:focus-visible { outline-offset: -1px; }
743
- :is(a, button, input, summary):focus-visible {
744
- outline: 1px solid var(--ink);
745
- }
746
- :is(a, button, summary):focus-visible { outline-offset: 2px; }
747
- .skip-link {
748
- background: var(--paper);
749
- left: var(--pad);
750
- padding: .5rem;
751
- position: fixed;
752
- top: -4rem;
753
- z-index: 10;
754
- }
755
- .skip-link:focus { top: var(--pad); }
756
-
757
- .shell {
758
- margin: 0 auto;
759
- max-width: var(--shell);
760
- padding-left: var(--pad);
761
- padding-right: var(--pad);
762
- }
763
- .pgrid {
764
- column-gap: var(--gap);
765
- display: grid;
766
- grid-template-columns: repeat(3, minmax(0, 1fr));
767
- row-gap: 1rem;
768
- }
769
- .pcap { grid-column: 1; }
770
- .pbody { grid-column: 2 / -1; min-width: 0; }
771
- .cap, .meta { color: var(--muted); font-size: .9em; }
772
- .mono { font-family: var(--mono); font-size: .78rem; }
773
- .hidden { display: none !important; }
774
- .visually-hidden {
775
- clip: rect(0 0 0 0);
776
- clip-path: inset(50%);
777
- height: 1px;
778
- overflow: hidden;
779
- position: absolute;
780
- white-space: nowrap;
781
- width: 1px;
782
- }
783
-
784
- .masthead {
785
- align-items: start;
786
- padding-bottom: var(--pad);
787
- padding-top: var(--pad);
788
- }
789
- .brand {
790
- font-weight: 500;
791
- grid-column: 1;
792
- text-decoration: none;
793
- }
794
- .mast-nav {
795
- display: flex;
796
- gap: var(--gap);
797
- grid-column: 2 / -1;
798
- justify-content: space-between;
799
- min-width: 0;
800
- }
801
- .mast-actions {
802
- display: flex;
803
- gap: var(--gap);
804
- justify-content: flex-end;
805
- min-width: 0;
806
- }
807
- .page-nav,
808
- .session-actions {
809
- display: flex;
810
- flex-wrap: wrap;
811
- gap: .5rem var(--gap);
812
- }
813
- .mast-actions :is(a, button) {
814
- align-items: center;
815
- display: inline-flex;
816
- min-height: 2rem;
817
- }
818
- .navlink,
819
- .linklike {
820
- text-decoration: underline;
821
- text-decoration-thickness: 1.5px;
822
- text-underline-offset: .22em;
823
- }
824
- .navlink { text-decoration-color: transparent; }
825
- .navlink:hover,
826
- .navlink:focus-visible,
827
- .navlink[aria-current="page"] { text-decoration-color: currentColor; }
828
- .linklike { text-decoration-color: currentColor; }
829
- .linklike:hover,
830
- .linklike:focus-visible { text-decoration-color: transparent; }
831
-
832
- .page { padding-bottom: 5rem; }
833
- .lead { margin-top: 6rem; }
834
- .section,
835
- .section + .section { margin-top: 3rem; }
836
- .lead-copy,
837
- .body-copy { max-width: 34em; }
838
- .lead-copy > * + *,
839
- .body-copy > * + * { margin-top: 1.5rem; }
840
- .row,
841
- .actions {
842
- align-items: center;
843
- display: flex;
844
- flex-wrap: wrap;
845
- gap: var(--gap);
846
- }
847
- .row input { flex: 1; min-width: 12rem; }
848
-
849
- .gate-actions { margin-top: 1.5rem; }
850
- #err { margin-top: 1.5rem; text-decoration: underline; }
851
-
852
- .endpoint { border-bottom: 1px solid var(--rule); border-top: 1px solid var(--rule); }
853
- .endpoint-row {
854
- align-items: baseline;
855
- display: flex;
856
- gap: var(--gap);
857
- min-width: 0;
858
- padding: .75rem 0;
859
- }
860
- .endpoint-row code {
861
- flex: 1;
862
- min-width: 0;
863
- overflow-x: auto;
864
- white-space: nowrap;
865
- }
866
- .endpoint-row button { flex: none; }
867
-
868
- .connector-tools { border-bottom: 1px solid var(--rule); }
869
- .toolbar { margin-bottom: 1.5rem; }
870
- .toolbar input { flex-basis: 18rem; }
871
- #notice { margin-bottom: .75rem; }
872
- #notice:empty { display: none; }
873
- #notice:not(:empty) { text-decoration: underline; }
874
- #oauthNotice { margin-bottom: .75rem; }
875
- #oauthNotice:empty { display: none; }
876
- .error-notice, .msg { text-decoration: underline; }
877
- .card,
878
- .credential-card,
879
- .activity-item {
880
- padding-left: 1.25rem;
881
- position: relative;
882
- }
883
- .card::before,
884
- .credential-card::before,
885
- .activity-item::before {
886
- background: var(--rule);
887
- bottom: 0;
888
- content: "";
889
- left: .25rem;
890
- position: absolute;
891
- top: 0;
892
- width: 1px;
893
- }
894
- .card { border-top: 1px solid var(--rule); padding-bottom: .75rem; padding-top: .75rem; }
895
- .connector-head {
896
- display: grid;
897
- gap: var(--gap);
898
- grid-template-columns: minmax(0, 2fr) minmax(10rem, 1fr);
899
- }
900
- .connector-title {
901
- align-items: baseline;
902
- display: flex;
903
- gap: .5rem;
904
- }
905
- .connector-title .dot,
906
- .activity-stamp .dot {
907
- margin-left: -1.25rem;
908
- }
909
- .activity-stamp {
910
- align-items: baseline;
911
- display: flex;
912
- gap: .75rem;
913
- }
914
- .card h2 { overflow-wrap: anywhere; }
915
- .connector-state { text-align: right; }
916
- .dot {
917
- background: var(--paper);
918
- border: 1px solid var(--ink);
919
- display: inline-block;
920
- flex: none;
921
- height: .5rem;
922
- width: .5rem;
923
- z-index: 1;
924
- }
925
- .dot.ok { background: var(--ink); }
926
- .dot.auth_required {
927
- background: linear-gradient(90deg, var(--ink) 50%, var(--paper) 50%);
928
- }
929
- .connector-description { margin-top: .25rem; max-width: 40rem; }
930
- .connector-message,
931
- .connector-auth { margin-top: .75rem; }
932
- .connector-toolkits {
933
- align-items: baseline;
934
- display: flex;
935
- flex-wrap: wrap;
936
- gap: .25rem .5rem;
937
- margin-top: .5rem;
938
- }
939
- .scope-label {
940
- border: 1px solid var(--rule);
941
- display: inline-block;
942
- font-family: var(--mono);
943
- font-size: .72rem;
944
- padding: .05rem .35rem;
945
- }
946
-
947
- .toolkit-copy { margin-bottom: 1rem; max-width: 42rem; }
948
- .toolkit-ledger { border-bottom: 1px solid var(--rule); }
949
- .toolkit-card {
950
- border-top: 1px solid var(--rule);
951
- padding: .9rem 0 1rem;
952
- }
953
- .toolkit-head {
954
- display: grid;
955
- gap: var(--gap);
956
- grid-template-columns: minmax(0, 2fr) minmax(10rem, 1fr);
957
- }
958
- .toolkit-name {
959
- align-items: baseline;
960
- display: flex;
961
- flex-wrap: wrap;
962
- gap: .5rem;
963
- }
964
- .toolkit-name h3 { overflow-wrap: anywhere; }
965
- .toolkit-state { text-align: right; }
966
- .toolkit-connectors {
967
- display: flex;
968
- flex-wrap: wrap;
969
- gap: .5rem;
970
- margin-top: .75rem;
971
- }
972
- .toolkit-connector {
973
- border-left: 1px solid var(--ink);
974
- display: inline-flex;
975
- flex-wrap: wrap;
976
- gap: .4rem;
977
- padding-left: .5rem;
978
- }
979
- .toolkit-rules { margin-top: .75rem; }
980
- .toolkit-rules > * + * { margin-top: .25rem; }
981
- .toolkit-endpoint { margin-top: .75rem; }
982
-
983
- .credential-ledger { border-bottom: 1px solid var(--rule); }
984
- .credential-card { border-top: 1px solid var(--rule); padding-bottom: .75rem; padding-top: .75rem; }
985
- .credential-head {
986
- align-items: baseline;
987
- display: flex;
988
- flex-wrap: wrap;
989
- gap: .25rem var(--gap);
990
- justify-content: space-between;
991
- }
992
- .credential-copy { margin-top: .25rem; max-width: 40rem; }
993
- .credential-field-summary {
994
- border-top: 1px solid var(--rule);
995
- margin-top: .75rem;
996
- }
997
- .credential-field-summary > div {
998
- border-bottom: 1px solid var(--rule);
999
- display: flex;
1000
- flex-wrap: wrap;
1001
- gap: .25rem var(--gap);
1002
- justify-content: space-between;
1003
- padding: .5rem 0;
1004
- }
1005
- .credential-actions { display: flex; flex-wrap: wrap; gap: var(--gap); margin-top: .75rem; }
1006
- .credential-actions button,
1007
- .credential-form button,
1008
- .activity-controls button,
1009
- .activity-more {
1010
- align-items: center;
1011
- display: inline-flex;
1012
- min-height: 2.75rem;
1013
- }
1014
- .credential-form {
1015
- align-items: center;
1016
- display: flex;
1017
- flex-wrap: wrap;
1018
- gap: .75rem var(--gap);
1019
- margin-top: .75rem;
1020
- }
1021
- .credential-form > input { flex: 1 1 18rem; }
1022
- .credential-fields { display: grid; flex: 1 1 100%; gap: .75rem; }
1023
- .credential-field {
1024
- align-items: center;
1025
- display: grid;
1026
- gap: var(--gap);
1027
- grid-template-columns: minmax(9rem, 12rem) 1fr;
1028
- }
1029
- .credential-field input { min-width: 0; width: 100%; }
1030
- .danger { text-decoration-style: double; }
1031
-
1032
- details { margin-top: .75rem; }
1033
- summary { cursor: pointer; list-style: none; width: max-content; }
1034
- summary::-webkit-details-marker { display: none; }
1035
- .tool-list { border-bottom: 1px solid var(--rule); margin-top: .5rem; }
1036
- .tool {
1037
- border-top: 1px solid var(--rule);
1038
- display: grid;
1039
- gap: .25rem var(--gap);
1040
- grid-template-columns: minmax(12rem, 1fr) minmax(0, 2fr);
1041
- padding: .5rem 0;
1042
- }
1043
- .tool code { font-family: var(--mono); font-size: .78rem; overflow-wrap: anywhere; }
1044
- .tool .td { color: var(--muted); font-size: .9em; }
1045
- .empty { border-top: 1px solid var(--rule); padding: .75rem 0; }
1046
-
1047
- .activity-copy { margin-bottom: 1.5rem; }
1048
- .activity-controls { margin-bottom: 1.5rem; }
1049
- .activity-controls input { flex: 1 1 18rem; }
1050
- #activityNotice { margin-bottom: .75rem; }
1051
- .activity-ledger { border-bottom: 1px solid var(--rule); }
1052
- .activity-item {
1053
- border-top: 1px solid var(--rule);
1054
- display: grid;
1055
- gap: .25rem var(--gap);
1056
- grid-template-columns: minmax(9rem, .85fr) minmax(12rem, 1.4fr) minmax(8rem, .9fr);
1057
- padding-bottom: .75rem;
1058
- padding-top: .75rem;
1059
- }
1060
- .activity-time,
1061
- .activity-actor,
1062
- .activity-detail { color: var(--muted); font-size: .82rem; }
1063
- .activity-actor-id { color: var(--muted); margin-top: .1rem; }
1064
- .activity-address { font-family: var(--mono); font-size: .78rem; overflow-wrap: anywhere; }
1065
- .activity-outcome { font-size: .9em; }
1066
- .activity-item.error .activity-outcome,
1067
- .activity-item.timeout .activity-outcome { text-decoration: underline; }
1068
- .activity-empty { border-top: 1px solid var(--rule); padding: .75rem 0; }
1069
- .activity-more { margin-top: .75rem; }
1070
- .unavailable {
1071
- background: var(--trace);
1072
- border-bottom: 1px solid var(--rule);
1073
- border-top: 1px solid var(--rule);
1074
- padding: .75rem;
1075
- }
1076
-
1077
- @media (prefers-reduced-motion: reduce) {
1078
- html:focus-within { scroll-behavior: auto; }
1079
- }
1080
-
1081
- @media (max-width: 36.99rem) {
1082
- .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1083
- .pcap,
1084
- .pbody { grid-column: 1 / -1; }
1085
- .masthead .brand { grid-column: 1; }
1086
- .mast-nav { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
1087
- .product { display: none; }
1088
- .mast-actions {
1089
- align-items: flex-start;
1090
- flex-direction: column;
1091
- font-size: .875rem;
1092
- gap: .25rem;
1093
- }
1094
- .lead { margin-top: 4rem; }
1095
- .section,
1096
- .section + .section { margin-top: 2.5rem; }
1097
- .connector-head,
1098
- .toolkit-head,
1099
- .tool,
1100
- .activity-item { grid-template-columns: 1fr; }
1101
- .connector-state,
1102
- .toolkit-state { text-align: left; }
1103
- .credential-field { align-items: start; grid-template-columns: 1fr; gap: .25rem; }
1104
- input { min-height: 2.75rem; }
1105
- }
1106
- </style>
599
+ <style>${OPERATOR_UI_CSS}</style>
1107
600
  </head>
1108
601
  <body>
1109
602
  <a class="skip-link" href="#operatorContent">Skip to operator page</a>
@@ -1231,939 +724,9 @@ const AUTH = ${jsonForInlineScript(auth)};
1231
724
  const MCP_URL = ${jsonForInlineScript(mcpUrl)};
1232
725
  const INITIAL_PAGE = ${jsonForInlineScript(page)};
1233
726
  const TITLE_SUFFIX = ${jsonForInlineScript(brand.pageTitle)};
1234
- const filterUiConnectors = ${filterUiConnectors.toString()};
1235
- const KEY = "connecta:token";
1236
- const $ = (id) => document.getElementById(id);
1237
- const PAGE_META = {
1238
- connections: { path: "/", label: "Connections" },
1239
- credentials: { path: "/credentials", label: "Credentials" },
1240
- activity: { path: "/activity", label: "Activity" },
1241
- };
1242
- let DATA = null;
1243
- let ACTIVITY = [];
1244
- let ACTIVITY_CURSOR = null;
1245
- let ACTIVITY_LOADED = false;
1246
- let CURRENT_PAGE = INITIAL_PAGE;
1247
- let SESSION_GENERATION = 0;
1248
- let ACTIVITY_GENERATION = 0;
1249
- let CLERK_SESSION_ID = null;
1250
- $("mcpUrl").textContent = MCP_URL;
1251
-
1252
- function esc(s) {
1253
- return String(s == null ? "" : s).replace(/[&<>"]/g, (c) =>
1254
- ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]));
1255
- }
1256
-
1257
- // Only http/https may become a clickable href — mirrors the server-side gate
1258
- // so a hostile scheme (javascript:, data:) can never be linked. Defense in depth.
1259
- function safeHttp(u) {
1260
- try {
1261
- const p = new URL(u).protocol;
1262
- return p === "http:" || p === "https:" ? u : null;
1263
- } catch (e) { return null; }
1264
- }
1265
-
1266
- function formatDate(value) {
1267
- if (!value) return "";
1268
- const date = new Date(value);
1269
- return Number.isNaN(date.valueOf()) ? "" : date.toLocaleString();
1270
- }
1271
-
1272
- function setNotice(message, isError) {
1273
- $("credentialNotice").textContent = message || "";
1274
- $("credentialNotice").classList.toggle("error-notice", Boolean(isError));
1275
- $("credentialNotice").setAttribute("role", isError ? "alert" : "status");
1276
- }
1277
-
1278
- function setOauthNotice(message, isError) {
1279
- $("oauthNotice").textContent = message || "";
1280
- $("oauthNotice").classList.toggle("error-notice", Boolean(isError));
1281
- $("oauthNotice").setAttribute("role", isError ? "alert" : "status");
1282
- }
1283
-
1284
- async function sessionToken() {
1285
- return AUTH.kind === "clerk"
1286
- ? await Clerk.session?.getToken()
1287
- : localStorage.getItem(KEY);
1288
- }
1289
-
1290
- function clearActivityState() {
1291
- ACTIVITY_GENERATION += 1;
1292
- ACTIVITY = [];
1293
- ACTIVITY_CURSOR = null;
1294
- ACTIVITY_LOADED = false;
1295
- $("activityList").innerHTML = "";
1296
- $("activityList").setAttribute("aria-busy", "false");
1297
- $("activityNotice").textContent = "";
1298
- $("activityNotice").setAttribute("role", "status");
1299
- $("activitySummary").textContent = "Arguments and results are never stored.";
1300
- $("activitySearch").value = "";
1301
- $("refreshActivity").disabled = false;
1302
- $("moreActivity").disabled = false;
1303
- $("moreActivity").classList.add("hidden");
1304
- }
1305
-
1306
- function clearIdentityState() {
1307
- SESSION_GENERATION += 1;
1308
- DATA = null;
1309
- clearActivityState();
1310
- $("list").innerHTML = "";
1311
- setOauthNotice("");
1312
- $("toolkitList").innerHTML = "";
1313
- $("filter").value = "";
1314
- $("credentialList").innerHTML = "";
1315
- $("credentialList").setAttribute("aria-busy", "false");
1316
- $("credentialNotice").textContent = "";
1317
- $("credentialNotice").setAttribute("role", "status");
1318
- $("credentialNotice").classList.remove("error-notice");
1319
- $("credentialUnavailable").textContent = "";
1320
- $("credentialUnavailable").classList.add("hidden");
1321
- $("credentialList").classList.add("hidden");
1322
- $("activityUnavailable").classList.add("hidden");
1323
- $("activityAvailable").classList.add("hidden");
1324
- $("credentialsNav").classList.add("hidden");
1325
- $("activityNav").classList.add("hidden");
1326
- $("serverInfo").textContent = ${escapeScriptString(brand.productName + " operator")};
1327
- }
1328
-
1329
- function showGate(msg) {
1330
- clearIdentityState();
1331
- $("app").classList.add("hidden");
1332
- $("appNav").classList.add("hidden");
1333
- $("gate").classList.remove("hidden");
1334
- $("err").textContent = msg || "";
1335
- if (AUTH.kind === "clerk") {
1336
- const signedIn = Boolean(window.Clerk && Clerk.user);
1337
- $("gateCopy").textContent = signedIn
1338
- ? "Signed in with Clerk, but this account cannot open deployment-wide operator pages."
1339
- : "Sign in with Clerk to open this operator page.";
1340
- $("signin").classList.toggle("hidden", signedIn);
1341
- $("gateSignout").classList.toggle("hidden", !signedIn);
1342
- } else {
1343
- $("gateCopy").textContent = "";
1344
- }
1345
- }
1346
-
1347
- function pageForPath(path) {
1348
- if (path === "/credentials") return "credentials";
1349
- if (path === "/activity") return "activity";
1350
- return "connections";
1351
- }
1352
-
1353
- function credentialUnavailableCopy(capability) {
1354
- if (capability === "no_slots") {
1355
- return "No connectors declare operator-managed credential slots. Connector credentials remain configuration-as-code until a slot is declared.";
1356
- }
1357
- if (capability === "vault_not_configured") {
1358
- return "Credential storage is not configured. Set credentials.encryptionKey before managing connector credentials here.";
1359
- }
1360
- return "Credential management requires an eligible Clerk operator. Bearer-authenticated sessions can inspect connections but cannot manage stored credentials.";
1361
- }
1362
-
1363
- function updateCapabilities() {
1364
- const credentialsAvailable =
1365
- DATA?.credentialManagement === "available";
1366
- $("credentialsNav").classList.toggle("hidden", !credentialsAvailable);
1367
- $("activityNav").classList.toggle("hidden", !DATA?.activityEnabled);
1368
- $("credentialUnavailable").classList.toggle("hidden", credentialsAvailable);
1369
- $("credentialList").classList.toggle("hidden", !credentialsAvailable);
1370
- $("credentialUnavailable").textContent = credentialsAvailable
1371
- ? ""
1372
- : credentialUnavailableCopy(DATA?.credentialManagement);
1373
- $("activityUnavailable").classList.toggle("hidden", Boolean(DATA?.activityEnabled));
1374
- $("activityAvailable").classList.toggle("hidden", !DATA?.activityEnabled);
1375
- }
1376
-
1377
- function activatePage(page, options) {
1378
- const next = PAGE_META[page] ? page : "connections";
1379
- CURRENT_PAGE = next;
1380
- for (const name of Object.keys(PAGE_META)) {
1381
- $(name + "View").classList.toggle("hidden", name !== next);
1382
- const link = $(name + "Nav");
1383
- if (name === next) link.setAttribute("aria-current", "page");
1384
- else link.removeAttribute("aria-current");
1385
- }
1386
- $("gateHeading").textContent = PAGE_META[next].label;
1387
- document.title = PAGE_META[next].label + " — " + TITLE_SUFFIX;
1388
- if (DATA) {
1389
- updateCapabilities();
1390
- if (next === "connections") renderConnections();
1391
- if (next === "credentials") renderCredentials();
1392
- if (next === "activity" && DATA.activityEnabled && !ACTIVITY_LOADED) {
1393
- loadActivity(true);
1394
- }
1395
- }
1396
- if (next !== "credentials") {
1397
- $("credentialList").innerHTML = "";
1398
- setNotice("");
1399
- }
1400
- // Focus what is actually on screen. While gated the page views are hidden, so
1401
- // focusing their heading is a silent no-op that drops focus to <body> and
1402
- // restarts the next Tab from the top of the document — the gate's own h1 is
1403
- // the visible heading, and activatePage has just relabelled it.
1404
- if (options?.focus) $(DATA ? next + "Heading" : "gateHeading").focus();
1405
- }
1406
-
1407
- function navigateTo(page, href) {
1408
- history.pushState({ operatorPage: page }, "", href);
1409
- activatePage(page, { focus: true });
1410
- }
1411
-
1412
- async function load() {
1413
- const generation = SESSION_GENERATION;
1414
- let token;
1415
- try {
1416
- token = await sessionToken();
1417
- } catch (e) {
1418
- if (generation !== SESSION_GENERATION) return;
1419
- return showGate("Could not read the Clerk session: " + e.message);
1420
- }
1421
- if (generation !== SESSION_GENERATION) return;
1422
- if (!token) return showGate("");
1423
- let res;
1424
- try {
1425
- res = await fetch("/ui/data", { headers: { Authorization: "Bearer " + token } });
1426
- } catch (e) {
1427
- if (generation !== SESSION_GENERATION) return;
1428
- return showGate("Network error: " + e.message);
1429
- }
1430
- if (generation !== SESSION_GENERATION) return;
1431
- if (res.status === 401 || res.status === 403) {
1432
- if (AUTH.kind === "clerk") {
1433
- return showGate(
1434
- res.status === 403
1435
- ? "This Clerk account is not allowed to access connecta."
1436
- : "Your Clerk session was not accepted. Sign out and try again."
1437
- );
1438
- }
1439
- localStorage.removeItem(KEY);
1440
- return showGate("Token rejected — enter a valid bearer token.");
1441
- }
1442
- if (!res.ok) return showGate("Error " + res.status);
1443
- let data;
1444
- try {
1445
- data = await res.json();
1446
- } catch (e) {
1447
- if (generation !== SESSION_GENERATION) return;
1448
- return showGate("Operator data could not be read.");
1449
- }
1450
- if (generation !== SESSION_GENERATION) return;
1451
- DATA = data;
1452
- $("gate").classList.add("hidden");
1453
- $("app").classList.remove("hidden");
1454
- $("appNav").classList.remove("hidden");
1455
- const si = DATA.serverInfo || {};
1456
- $("serverInfo").textContent = (si.name || ${escapeScriptString(brand.productName)}) + " v" + (DATA.connectaVersion || "?");
1457
- updateCapabilities();
1458
- activatePage(CURRENT_PAGE);
1459
- }
1460
-
1461
- function actorLabel(actor) {
1462
- if (!actor || !actor.kind) return "unknown";
1463
- return actor.label
1464
- ? actor.kind + " · " + actor.label
1465
- : actor.id ? actor.kind + " · " + actor.id : actor.kind;
1466
- }
1467
-
1468
- function renderActivity() {
1469
- const list = $("activityList");
1470
- list.innerHTML = "";
1471
- const query = $("activitySearch").value.trim().toLowerCase();
1472
- const visible = ACTIVITY.filter((event) => {
1473
- if (!query) return true;
1474
- const actor = event.actor || {};
1475
- return [
1476
- event.address,
1477
- event.connectorId,
1478
- event.toolName,
1479
- event.source,
1480
- event.outcome,
1481
- event.errorCode,
1482
- actor.kind,
1483
- actor.id,
1484
- actor.namespace,
1485
- actor.label,
1486
- ].some((value) => String(value || "").toLowerCase().includes(query));
1487
- });
1488
- const uniqueTools = new Set(ACTIVITY.map((event) => event.address)).size;
1489
- $("activitySummary").textContent = ACTIVITY.length
1490
- ? ACTIVITY.length + " loaded call" + (ACTIVITY.length === 1 ? "" : "s") +
1491
- " · " + uniqueTools + " tool" + (uniqueTools === 1 ? "" : "s") +
1492
- " · no arguments or results stored"
1493
- : "Arguments and results are never stored.";
1494
- if (visible.length === 0) {
1495
- list.innerHTML = '<div class="activity-empty">' +
1496
- (query ? "No loaded activity matches this search." :
1497
- "No connector tool calls recorded yet.") + "</div>";
1498
- }
1499
- for (const event of visible) {
1500
- const item = document.createElement("article");
1501
- const outcomeClass = ["success", "error", "timeout"].includes(event.outcome)
1502
- ? event.outcome
1503
- : "error";
1504
- item.className = "activity-item " + outcomeClass;
1505
- const retryCopy = event.attempts > 1
1506
- ? " · " + esc(event.attempts) + " attempts"
1507
- : "";
1508
- const errorCopy = event.errorCode ? " · " + esc(event.errorCode) : "";
1509
- const actorId = event.actor?.id
1510
- ? (event.actor.namespace
1511
- ? event.actor.namespace + " · " + event.actor.id
1512
- : event.actor.id)
1513
- : "";
1514
- const stableActorId = actorId &&
1515
- (event.actor?.label || event.actor?.namespace)
1516
- ? '<div class="activity-actor-id mono">' + esc(actorId) + "</div>"
1517
- : "";
1518
- item.innerHTML =
1519
- '<div class="activity-stamp"><span class="dot ' +
1520
- (outcomeClass === "success" ? "ok" : "") +
1521
- '" aria-hidden="true"></span><div><time class="activity-time" datetime="' +
1522
- esc(event.occurredAt) + '">' +
1523
- esc(formatDate(event.occurredAt)) +
1524
- '</time><div class="activity-actor">' + esc(actorLabel(event.actor)) +
1525
- "</div>" + stableActorId + "</div></div>" +
1526
- '<div><div class="activity-address">' + esc(event.address) +
1527
- '</div><div class="activity-detail">' + esc(event.source) + retryCopy +
1528
- errorCopy + '</div></div>' +
1529
- '<div><div class="activity-outcome">' + esc(event.outcome) +
1530
- '</div><div class="activity-detail">' + esc(event.durationMs) + ' ms</div></div>';
1531
- list.appendChild(item);
1532
- }
1533
- $("moreActivity").classList.toggle("hidden", !ACTIVITY_CURSOR);
1534
- }
1535
-
1536
- async function loadActivity(reset) {
1537
- if (!DATA?.activityEnabled) return;
1538
- const sessionGeneration = SESSION_GENERATION;
1539
- if (reset) ACTIVITY_GENERATION += 1;
1540
- const activityGeneration = ACTIVITY_GENERATION;
1541
- const isCurrent = () =>
1542
- sessionGeneration === SESSION_GENERATION &&
1543
- activityGeneration === ACTIVITY_GENERATION;
1544
- $("activityNotice").textContent = "Loading activity…";
1545
- $("activityNotice").setAttribute("role", "status");
1546
- $("activityList").setAttribute("aria-busy", "true");
1547
- $("refreshActivity").disabled = true;
1548
- $("moreActivity").disabled = true;
1549
- try {
1550
- const token = await sessionToken();
1551
- if (!isCurrent()) return;
1552
- if (!token) return showGate("Your session has expired.");
1553
- const cursor = reset ? null : ACTIVITY_CURSOR;
1554
- const params = new URLSearchParams({ limit: "50" });
1555
- if (cursor) params.set("cursor", cursor);
1556
- const res = await fetch("/ui/activity?" + params, {
1557
- headers: { Authorization: "Bearer " + token },
1558
- });
1559
- if (!isCurrent()) return;
1560
- let payload = {};
1561
- try { payload = await res.json(); } catch (e) {}
1562
- if (!isCurrent()) return;
1563
- if (res.status === 401) {
1564
- return showGate("Your session was not accepted. Sign in again.");
1565
- }
1566
- if (res.status === 403) {
1567
- clearActivityState();
1568
- $("activityNotice").setAttribute("role", "alert");
1569
- $("activityNotice").textContent =
1570
- "This identity may not read activity history.";
1571
- return;
1572
- }
1573
- if (!res.ok) {
1574
- throw new Error(
1575
- payload.error || "Activity could not be loaded (" + res.status + ")."
1576
- );
1577
- }
1578
- ACTIVITY = reset
1579
- ? (payload.events || [])
1580
- : ACTIVITY.concat(payload.events || []);
1581
- ACTIVITY_CURSOR = payload.nextCursor || null;
1582
- ACTIVITY_LOADED = true;
1583
- $("activityNotice").textContent = "";
1584
- renderActivity();
1585
- } catch (e) {
1586
- if (!isCurrent()) return;
1587
- $("activityNotice").setAttribute("role", "alert");
1588
- $("activityNotice").textContent = e.message || "Activity could not be loaded.";
1589
- } finally {
1590
- if (isCurrent()) {
1591
- $("activityList").setAttribute("aria-busy", "false");
1592
- $("refreshActivity").disabled = false;
1593
- $("moreActivity").disabled = false;
1594
- }
1595
- }
1596
- }
1597
-
1598
- function toolkitMcpUrl(name) {
1599
- const url = new URL(MCP_URL, window.location.href);
1600
- url.searchParams.set("toolkit", name);
1601
- return url.toString();
1602
- }
1603
-
1604
- function renderToolkits() {
1605
- const list = $("toolkitList");
1606
- const toolkits = DATA.toolkits || [];
1607
- list.innerHTML = "";
1608
- if (!toolkits.length) {
1609
- list.innerHTML =
1610
- '<p class="empty">No toolkits are configured. Unscoped clients see the full connector registry.</p>';
1611
- return;
1612
- }
1613
- const connectors = new Map(
1614
- DATA.connectors.map((connector) => [connector.id, connector]),
1615
- );
1616
- for (const toolkit of toolkits) {
1617
- const el = document.createElement("article");
1618
- el.className = "toolkit-card";
1619
- const connectorCount = toolkit.connectors.length;
1620
- const toolCount = toolkit.toolCount || 0;
1621
- let body =
1622
- '<div class="toolkit-head"><div><div class="toolkit-name">' +
1623
- '<h3 class="mono">' + esc(toolkit.name) + "</h3>" +
1624
- '<span class="cap">configured view</span></div>';
1625
- body += '</div><div class="toolkit-state cap">' +
1626
- connectorCount + (connectorCount === 1 ? " connector" : " connectors") +
1627
- " · " + toolCount + (toolCount === 1 ? " loaded tool" : " loaded tools") +
1628
- "</div></div>";
1629
- body += '<ul class="toolkit-connectors" aria-label="Included connectors">';
1630
- for (const id of toolkit.connectors) {
1631
- const connector = connectors.get(id);
1632
- body += '<li class="toolkit-connector"><span>' +
1633
- esc(connector?.title || id) + '</span><code class="mono">' +
1634
- esc(id) + "</code></li>";
1635
- }
1636
- body += "</ul>";
1637
- body += '<div class="toolkit-rules meta">';
1638
- if (toolkit.includeTools.length) {
1639
- body += '<p>Per-connector allowlist: <span class="mono">' +
1640
- toolkit.includeTools.map(esc).join('</span>, <span class="mono">') +
1641
- "</span>. Connectors without an allowlist keep all tools.</p>";
1642
- }
1643
- if (toolkit.excludeTools.length) {
1644
- body += '<p>Hidden: <span class="mono">' +
1645
- toolkit.excludeTools.map(esc).join('</span>, <span class="mono">') +
1646
- "</span></p>";
1647
- }
1648
- if (!toolkit.includeTools.length && !toolkit.excludeTools.length) {
1649
- body += "<p>All tools on the included connectors are visible.</p>";
1650
- }
1651
- body += "</div>";
1652
- const endpoint = toolkitMcpUrl(toolkit.name);
1653
- body += '<div class="endpoint toolkit-endpoint"><div class="endpoint-row">' +
1654
- '<code class="mono">' + esc(endpoint) + "</code>" +
1655
- '<button class="linklike" type="button" data-toolkit-copy="' +
1656
- esc(toolkit.name) + '" aria-label="Copy endpoint for ' +
1657
- esc(toolkit.name) + '">Copy URL</button></div></div>';
1658
- el.innerHTML = body;
1659
- list.appendChild(el);
1660
- }
1661
- }
1662
-
1663
- function renderConnections() {
1664
- const q = $("filter").value.trim().toLowerCase();
1665
- const list = $("list");
1666
- list.innerHTML = "";
1667
- for (const filtered of filterUiConnectors(DATA.connectors, q)) {
1668
- const c = filtered.connector;
1669
- const tools = filtered.tools;
1670
- const el = document.createElement("div");
1671
- el.className = "card";
1672
- const status = c.status === "ok"
1673
- ? "Connected"
1674
- : c.status === "auth_required"
1675
- ? "Authorization needed"
1676
- : "Unavailable";
1677
- let head = '<div class="connector-head"><div><div class="connector-title">' +
1678
- '<span class="dot ' + esc(c.status) + '" aria-hidden="true"></span>' +
1679
- '<h2>' + esc(c.title || c.id) + "</h2></div>";
1680
- if (c.description) {
1681
- head += '<p class="connector-description meta">' + esc(c.description) + "</p>";
1682
- }
1683
- const memberships = (DATA.toolkits || [])
1684
- .filter((toolkit) => toolkit.connectors.includes(c.id))
1685
- .map((toolkit) => toolkit.name);
1686
- if (memberships.length) {
1687
- head += '<div class="connector-toolkits meta"><span>Toolkits</span>' +
1688
- memberships.map((name) =>
1689
- '<span class="scope-label">' + esc(name) + "</span>"
1690
- ).join("") + "</div>";
1691
- }
1692
- head += '</div><div class="connector-state cap">' + esc(status) + " · " +
1693
- c.toolCount + (c.toolCount === 1 ? " tool" : " tools") +
1694
- '<br><span class="mono">' + esc(c.id) + "</span></div></div>";
1695
- if (c.message) {
1696
- head += '<p class="connector-message msg">' + esc(c.message) + "</p>";
1697
- }
1698
- if (c.credentialCheck) {
1699
- const check = c.credentialCheck;
1700
- const verdict = check.state === "ok"
1701
- ? "credential verified"
1702
- : check.state === "auth_required"
1703
- ? "credential needs authorization"
1704
- : "credential check failed";
1705
- head += '<p class="connector-check meta">Credential check: ' +
1706
- esc(verdict) + " · " + esc(formatDate(check.checkedAt)) +
1707
- (check.message && check.message !== c.message
1708
- ? " — " + esc(check.message)
1709
- : "") + "</p>";
1710
- }
1711
- if (c.authorizationUrl) {
1712
- const safe = safeHttp(c.authorizationUrl);
1713
- head += safe
1714
- ? '<p class="connector-auth"><a class="linklike" href="' + esc(safe) +
1715
- '" target="_blank" rel="noopener">Authorize connector →</a></p>'
1716
- : '<p class="connector-auth meta">Authorization URL: ' +
1717
- esc(c.authorizationUrl) + "</p>";
1718
- }
1719
- if (c.oauth && DATA.oauthManagement) {
1720
- const oauthName = c.title || c.id;
1721
- head += '<div class="credential-actions">';
1722
- head += '<button type="button" class="linklike danger" ' +
1723
- 'aria-label="Disconnect OAuth for ' + esc(oauthName) + '" ' +
1724
- 'data-oauth-action="disconnect" data-connector="' + esc(c.id) +
1725
- '">Disconnect OAuth</button>';
1726
- head += '<button type="button" class="linklike" ' +
1727
- 'aria-label="' + (c.status === "ok" ? "Reconnect OAuth for " :
1728
- "Restart authorization for ") + esc(oauthName) + '" ' +
1729
- 'data-oauth-action="reconnect" data-connector="' + esc(c.id) +
1730
- '">' + (c.status === "ok" ? "Reconnect OAuth" : "Restart authorization") +
1731
- "</button></div>";
1732
- }
1733
- if (c.credential) {
1734
- head += '<p class="connector-auth"><a class="linklike" href="/credentials" ' +
1735
- 'data-operator-page="credentials">Manage credential →</a></p>';
1736
- }
1737
- let body = "";
1738
- if (tools.length) {
1739
- body = "<details" + (q ? " open" : "") +
1740
- '><summary class="linklike">Show tools (' + tools.length + ")</summary>" +
1741
- '<div class="tool-list">';
1742
- for (const t of tools) {
1743
- body += '<div class="tool"><code>' + esc(t.address) + "</code>";
1744
- if (t.description) body += '<span class="td">' + esc(t.description) + "</span>";
1745
- body += "</div>";
1746
- }
1747
- body += "</div></details>";
1748
- }
1749
- el.innerHTML = head + body;
1750
- list.appendChild(el);
1751
- }
1752
- if (!list.children.length) {
1753
- list.innerHTML = '<p class="empty">' +
1754
- (q
1755
- ? "No connectors or tools match this filter."
1756
- : "No connectors are declared in this deployment.") +
1757
- "</p>";
1758
- }
1759
- renderToolkits();
1760
- }
1761
-
1762
- async function oauthRequest(connector, method, generation) {
1763
- const token = await sessionToken();
1764
- if (generation !== SESSION_GENERATION) {
1765
- throw new Error("The operator session changed.");
1766
- }
1767
- if (!token) throw new Error("Your Clerk session has expired.");
1768
- const res = await fetch("/ui/oauth/" + encodeURIComponent(connector), {
1769
- method,
1770
- headers: { Authorization: "Bearer " + token },
1771
- });
1772
- if (res.status === 204) return null;
1773
- let payload = {};
1774
- try { payload = await res.json(); } catch (e) {}
1775
- if (!res.ok) throw new Error(payload.error || "Request failed (" + res.status + ").");
1776
- return payload;
1777
- }
1778
-
1779
- $("list").onclick = async (event) => {
1780
- const button = event.target.closest("[data-oauth-action]");
1781
- if (!button) return;
1782
- const connector = button.dataset.connector;
1783
- const action = button.dataset.oauthAction;
1784
- const generation = SESSION_GENERATION;
1785
- const question = action === "disconnect"
1786
- ? "Disconnect OAuth for " + connector +
1787
- "? Stored credentials and any pending authorization will be removed."
1788
- : "Restart OAuth for " + connector +
1789
- "? Stored credentials and any pending authorization will be replaced.";
1790
- if (!window.confirm(question)) return;
1791
-
1792
- setOauthNotice("");
1793
- const buttons = [...document.querySelectorAll(
1794
- '[data-connector="' + CSS.escape(connector) + '"]'
1795
- )];
1796
- buttons.forEach((item) => { item.disabled = true; });
1797
- try {
1798
- const result = await oauthRequest(
1799
- connector,
1800
- action === "disconnect" ? "DELETE" : "POST",
1801
- generation,
1802
- );
1803
- if (generation !== SESSION_GENERATION) return;
1804
- await load();
1805
- if (generation !== SESSION_GENERATION) return;
1806
- setOauthNotice(
1807
- action === "disconnect"
1808
- ? "OAuth disconnected. Restart authorization when you are ready to reconnect."
1809
- : result?.message ||
1810
- "Authorization restarted. Open the authorization link to reconnect.",
1811
- );
1812
- $("oauthNotice").focus();
1813
- } catch (e) {
1814
- if (generation !== SESSION_GENERATION) return;
1815
- // A reset can publish its durable epoch before best-effort physical cleanup
1816
- // reports failure. Refresh so stale tools/health/actions never survive that
1817
- // partial success, while preserving the original error for the operator.
1818
- try {
1819
- await load();
1820
- } catch (refreshError) {
1821
- // The mutation error is the actionable one; load() already owns its gate.
1822
- }
1823
- if (generation !== SESSION_GENERATION) return;
1824
- setOauthNotice(e.message || "OAuth action failed.", true);
1825
- $("oauthNotice").focus();
1826
- } finally {
1827
- if (generation === SESSION_GENERATION) {
1828
- buttons.forEach((item) => { item.disabled = false; });
1829
- }
1830
- }
1831
- };
1832
-
1833
- function renderCredentials() {
1834
- const list = $("credentialList");
1835
- list.innerHTML = "";
1836
- if (DATA.credentialManagement !== "available") return;
1837
- for (const c of DATA.connectors.filter((connector) => connector.credential)) {
1838
- const cred = c.credential;
1839
- const configured = Boolean(cred.configured);
1840
- const removable = configured || Boolean(cred.removable);
1841
- const state = configured
1842
- ? cred.fields?.length
1843
- ? "configured"
1844
- : "configured · ••••" + esc(cred.lastFour || "")
1845
- : "not configured";
1846
- const updated = configured && cred.updatedAt
1847
- ? " · updated " + esc(formatDate(cred.updatedAt))
1848
- : "";
1849
- const el = document.createElement("section");
1850
- el.className = "credential-card";
1851
- el.id = "credential-" + c.id;
1852
- el.setAttribute("aria-labelledby", "credential-title-" + c.id);
1853
- let body = '<div class="credential-head"><div class="connector-title">' +
1854
- '<span class="dot ' + (configured ? "ok" : "auth_required") +
1855
- '" aria-hidden="true"></span><h2 id="credential-title-' + esc(c.id) + '">' +
1856
- esc(c.title || c.id) + '</h2></div><span class="credential-state">' +
1857
- state + updated + "</span></div>";
1858
- body += '<p class="mono">' + esc(c.id) + " · " + esc(cred.label) + "</p>";
1859
- if (cred.description) {
1860
- body += '<p class="credential-copy meta">' + esc(cred.description) + "</p>";
1861
- }
1862
- if (cred.fields?.length) {
1863
- body += '<div class="credential-field-summary">';
1864
- for (const field of cred.fields) {
1865
- const fieldState = field.configured
1866
- ? "configured · ••••" + esc(field.lastFour || "") +
1867
- (field.updatedAt ? " · updated " + esc(formatDate(field.updatedAt)) : "")
1868
- : "not configured";
1869
- body += '<div><span>' + esc(field.label) +
1870
- '</span><span class="meta">' + fieldState + "</span></div>";
1871
- }
1872
- body += "</div>";
1873
- }
1874
- if (c.credentialCheck) {
1875
- const check = c.credentialCheck;
1876
- const verdict = check.state === "ok"
1877
- ? "healthy"
1878
- : check.state === "auth_required"
1879
- ? "needs authorization"
1880
- : "check failed";
1881
- body += '<p class="connector-check meta">Liveness: ' + esc(verdict) +
1882
- " · " + esc(formatDate(check.checkedAt)) +
1883
- (check.message ? " — " + esc(check.message) : "") + "</p>";
1884
- }
1885
- if (cred.error) body += '<div class="msg">' + esc(cred.error) + "</div>";
1886
- // Leftover stored fields are not an error — the credential still works, so
1887
- // this stays muted copy rather than the msg block an actual failure earns.
1888
- if (cred.notice) {
1889
- body += '<p class="credential-copy meta">' + esc(cred.notice) + "</p>";
1890
- }
1891
- body += '<div class="credential-actions">';
1892
- body += '<button class="linklike" type="button" data-credential-action="edit" data-connector="' +
1893
- esc(c.id) + '">' + (removable ? "Replace" : "Add credential") + "</button>";
1894
- if (configured && cred.testable) {
1895
- body += '<button class="linklike" type="button" data-credential-action="test" data-connector="' +
1896
- esc(c.id) + '">Test</button>';
1897
- }
1898
- if (removable) {
1899
- body += '<button type="button" class="linklike danger" data-credential-action="remove" data-connector="' +
1900
- esc(c.id) + '">Remove</button>';
1901
- }
1902
- body += "</div>";
1903
- body += '<div class="credential-form hidden" data-credential-form="' +
1904
- esc(c.id) + '">';
1905
- if (cred.fields && cred.fields.length) {
1906
- body += '<div class="credential-fields">';
1907
- for (let index = 0; index < cred.fields.length; index += 1) {
1908
- const field = cred.fields[index];
1909
- const inputId = "credential-input-" + c.id + "-" + index;
1910
- body += '<div class="credential-field"><label for="' + esc(inputId) + '">' +
1911
- esc(field.label) + '</label><input id="' + esc(inputId) + '" type="' +
1912
- esc(field.inputType || "password") + '" data-credential-field="' +
1913
- esc(field.name) + '" placeholder="' + esc(field.placeholder || field.label) +
1914
- '" autocomplete="' +
1915
- (field.inputType === "password" ? "new-password" : "off") +
1916
- '" autocapitalize="none" spellcheck="false"></div>';
1917
- }
1918
- body += "</div>";
1919
- } else {
1920
- const inputId = "credential-input-" + c.id;
1921
- body += '<label class="visually-hidden" for="' + esc(inputId) + '">' +
1922
- esc(cred.label) + '</label><input id="' + esc(inputId) +
1923
- '" type="password" data-credential-input="' +
1924
- esc(c.id) + '" aria-label="' + esc(cred.label) + '" placeholder="' +
1925
- esc(cred.placeholder || "Paste credential") +
1926
- '" autocomplete="new-password" autocapitalize="none" spellcheck="false">';
1927
- }
1928
- body += '<button class="linklike" type="button" data-credential-action="save" data-connector="' +
1929
- esc(c.id) + '">Save</button><button class="linklike" type="button" data-credential-action="cancel" data-connector="' +
1930
- esc(c.id) + '">Cancel</button></div>';
1931
- el.innerHTML = body;
1932
- list.appendChild(el);
1933
- }
1934
- }
1935
-
1936
- async function credentialRequest(connector, method, action, body, generation) {
1937
- const token = await sessionToken();
1938
- if (generation !== SESSION_GENERATION) {
1939
- throw new Error("The operator session changed.");
1940
- }
1941
- if (!token) throw new Error("Your Clerk session has expired.");
1942
- const suffix = action ? "/" + action : "";
1943
- const res = await fetch(
1944
- "/ui/credentials/" + encodeURIComponent(connector) + suffix,
1945
- {
1946
- method,
1947
- headers: {
1948
- Authorization: "Bearer " + token,
1949
- ...(body ? { "Content-Type": "application/json" } : {}),
1950
- },
1951
- ...(body ? { body: JSON.stringify(body) } : {}),
1952
- },
1953
- );
1954
- if (res.status === 204) return null;
1955
- let payload = {};
1956
- try { payload = await res.json(); } catch (e) {}
1957
- if (!res.ok) throw new Error(payload.error || "Request failed (" + res.status + ").");
1958
- return payload;
1959
- }
1960
-
1961
- function credentialForm(connector) {
1962
- return document.querySelector('[data-credential-form="' +
1963
- CSS.escape(connector) + '"]');
1964
- }
1965
-
1966
- $("credentialList").onclick = async (event) => {
1967
- const button = event.target.closest("[data-credential-action]");
1968
- if (!button) return;
1969
- const connector = button.dataset.connector;
1970
- const action = button.dataset.credentialAction;
1971
- const form = credentialForm(connector);
1972
- const generation = SESSION_GENERATION;
1973
-
1974
- if (action === "edit") {
1975
- form.classList.remove("hidden");
1976
- form.querySelector("input")?.focus();
1977
- return;
1978
- }
1979
- if (action === "cancel") {
1980
- form.querySelectorAll("input").forEach((input) => { input.value = ""; });
1981
- form.classList.add("hidden");
1982
- document.querySelector(
1983
- '[data-credential-action="edit"][data-connector="' +
1984
- CSS.escape(connector) + '"]'
1985
- )?.focus();
1986
- return;
1987
- }
1988
- if (action === "remove" && !window.confirm(
1989
- "Remove this credential? The connector will stop authenticating until a replacement is added."
1990
- )) return;
1991
-
1992
- setNotice("");
1993
- $("credentialList").setAttribute("aria-busy", "true");
1994
- const buttons = [...document.querySelectorAll(
1995
- '[data-connector="' + CSS.escape(connector) + '"]'
1996
- )];
1997
- buttons.forEach((item) => { item.disabled = true; });
1998
- try {
1999
- if (action === "save") {
2000
- const fieldInputs = [...form.querySelectorAll("[data-credential-field]")];
2001
- if (fieldInputs.length) {
2002
- const values = {};
2003
- for (const input of fieldInputs) {
2004
- const value = input.value.trim();
2005
- if (!value) throw new Error("Complete every credential field before saving.");
2006
- values[input.dataset.credentialField] = value;
2007
- }
2008
- await credentialRequest(connector, "PUT", "", { values }, generation);
2009
- } else {
2010
- const input = form.querySelector("[data-credential-input]");
2011
- const value = input.value.trim();
2012
- if (!value) throw new Error("Paste a credential before saving.");
2013
- await credentialRequest(connector, "PUT", "", { value }, generation);
2014
- }
2015
- if (generation !== SESSION_GENERATION) return;
2016
- form.querySelectorAll("input").forEach((input) => { input.value = ""; });
2017
- setNotice("Credential saved.");
2018
- await load();
2019
- if (generation !== SESSION_GENERATION) return;
2020
- $("credentialNotice").focus();
2021
- } else if (action === "remove") {
2022
- await credentialRequest(connector, "DELETE", "", null, generation);
2023
- if (generation !== SESSION_GENERATION) return;
2024
- setNotice("Credential removed.");
2025
- await load();
2026
- if (generation !== SESSION_GENERATION) return;
2027
- $("credentialNotice").focus();
2028
- } else if (action === "test") {
2029
- const result = await credentialRequest(
2030
- connector,
2031
- "POST",
2032
- "test",
2033
- null,
2034
- generation,
2035
- );
2036
- if (generation !== SESSION_GENERATION) return;
2037
- setNotice(
2038
- result.message || (result.ok ? "Credential is valid." : "Credential test failed."),
2039
- !result.ok,
2040
- );
2041
- }
2042
- } catch (e) {
2043
- if (generation !== SESSION_GENERATION) return;
2044
- setNotice(e.message || "Credential action failed.", true);
2045
- } finally {
2046
- if (generation === SESSION_GENERATION) {
2047
- $("credentialList").setAttribute("aria-busy", "false");
2048
- buttons.forEach((item) => { item.disabled = false; });
2049
- }
2050
- }
2051
- };
2052
-
2053
- $("save").onclick = async () => {
2054
- const v = $("token").value.trim();
2055
- if (!v) return;
2056
- clearIdentityState();
2057
- localStorage.setItem(KEY, v);
2058
- $("token").value = "";
2059
- await load();
2060
- if (DATA) $(CURRENT_PAGE + "Heading").focus();
2061
- };
2062
- $("change").onclick = () => {
2063
- localStorage.removeItem(KEY);
2064
- showGate("");
2065
- $("token").focus();
2066
- };
2067
- $("copyMcpUrl").onclick = async () => {
2068
- const button = $("copyMcpUrl");
2069
- try {
2070
- await navigator.clipboard.writeText(MCP_URL);
2071
- button.textContent = "Copied";
2072
- } catch (e) {
2073
- button.textContent = "Copy failed";
2074
- }
2075
- window.setTimeout(() => { button.textContent = "Copy URL"; }, 1600);
2076
- };
2077
- $("toolkitList").onclick = async (event) => {
2078
- const button = event.target.closest("[data-toolkit-copy]");
2079
- if (!button) return;
2080
- try {
2081
- await navigator.clipboard.writeText(
2082
- toolkitMcpUrl(button.dataset.toolkitCopy),
2083
- );
2084
- button.textContent = "Copied";
2085
- } catch (e) {
2086
- button.textContent = "Copy failed";
2087
- }
2088
- window.setTimeout(() => { button.textContent = "Copy URL"; }, 1600);
2089
- };
2090
- $("signin").onclick = () => Clerk.redirectToSignIn({
2091
- signInFallbackRedirectUrl: window.location.href,
2092
- signUpFallbackRedirectUrl: window.location.href,
2093
- });
2094
- function signOut() {
2095
- clearIdentityState();
2096
- return Clerk.signOut({ redirectUrl: window.location.href });
2097
- }
2098
- $("gateSignout").onclick = signOut;
2099
- $("signout").onclick = signOut;
2100
- $("filter").oninput = () => { if (DATA) renderConnections(); };
2101
- $("refreshActivity").onclick = () => loadActivity(true);
2102
- $("moreActivity").onclick = () => loadActivity(false);
2103
- $("activitySearch").oninput = () => renderActivity();
2104
- document.addEventListener("click", (event) => {
2105
- const link = event.target.closest("a[data-operator-page]");
2106
- if (
2107
- !link ||
2108
- event.defaultPrevented ||
2109
- event.button !== 0 ||
2110
- event.metaKey ||
2111
- event.ctrlKey ||
2112
- event.shiftKey ||
2113
- event.altKey
2114
- ) return;
2115
- const target = new URL(link.href, window.location.href);
2116
- if (target.origin !== window.location.origin) return;
2117
- event.preventDefault();
2118
- navigateTo(link.dataset.operatorPage, target.pathname + target.search + target.hash);
2119
- });
2120
- window.addEventListener("popstate", () => {
2121
- activatePage(pageForPath(window.location.pathname), { focus: true });
2122
- });
2123
-
2124
- async function init() {
2125
- if (AUTH.kind === "clerk") {
2126
- $("clerkGate").classList.remove("hidden");
2127
- $("signout").classList.remove("hidden");
2128
- try {
2129
- if (!window.Clerk) {
2130
- return showGate("Clerk could not load. Check your network and try again.");
2131
- }
2132
- await Clerk.load({
2133
- ...(AUTH.signInUrl ? { signInUrl: AUTH.signInUrl } : {}),
2134
- ...(AUTH.signUpUrl ? { signUpUrl: AUTH.signUpUrl } : {}),
2135
- signInFallbackRedirectUrl: window.location.href,
2136
- signUpFallbackRedirectUrl: window.location.href,
2137
- afterSignOutUrl: window.location.href,
2138
- });
2139
- CLERK_SESSION_ID = Clerk.session?.id ?? null;
2140
- Clerk.addListener((resources) => {
2141
- const nextSessionId = resources.session?.id ?? null;
2142
- if (nextSessionId === CLERK_SESSION_ID) return;
2143
- CLERK_SESSION_ID = nextSessionId;
2144
- // Clerk has already updated its public session before notifying
2145
- // listeners. Clear synchronously so stale identity-scoped data cannot
2146
- // be repainted while the replacement identity is being fetched.
2147
- showGate("");
2148
- void load();
2149
- });
2150
- } catch (e) {
2151
- return showGate("Clerk could not initialize: " + e.message);
2152
- }
2153
- } else {
2154
- $("tokenGate").classList.remove("hidden");
2155
- $("change").classList.remove("hidden");
2156
- }
2157
- activatePage(pageForPath(window.location.pathname));
2158
- await load();
2159
- }
2160
-
2161
- if (AUTH.kind === "clerk") {
2162
- window.addEventListener("load", init);
2163
- } else {
2164
- init();
2165
- }
2166
- </script>
727
+ const PRODUCT_NAME = ${stringForInlineScript(brand.productName)};
728
+ const PRODUCT_OPERATOR_LABEL = ${stringForInlineScript(brand.productName + " operator")};
729
+ ${OPERATOR_UI_SCRIPT}</script>
2167
730
  </body>
2168
731
  </html>`;
2169
732
  }