@zackbart/connecta 0.7.9 → 0.8.1

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 (199) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +47 -148
  3. package/dist/activity.d.ts +0 -8
  4. package/dist/activity.d.ts.map +1 -1
  5. package/dist/activity.js +0 -1
  6. package/dist/activity.js.map +1 -1
  7. package/dist/auth/bearer.d.ts +1 -7
  8. package/dist/auth/bearer.d.ts.map +1 -1
  9. package/dist/auth/bearer.js +3 -24
  10. package/dist/auth/bearer.js.map +1 -1
  11. package/dist/auth/clerk.d.ts +2 -11
  12. package/dist/auth/clerk.d.ts.map +1 -1
  13. package/dist/auth/clerk.js +31 -46
  14. package/dist/auth/clerk.js.map +1 -1
  15. package/dist/call-admission.d.ts.map +1 -1
  16. package/dist/call-admission.js +9 -4
  17. package/dist/call-admission.js.map +1 -1
  18. package/dist/catalog-fingerprint.d.ts +20 -0
  19. package/dist/catalog-fingerprint.d.ts.map +1 -0
  20. package/dist/catalog-fingerprint.js +34 -0
  21. package/dist/catalog-fingerprint.js.map +1 -0
  22. package/dist/catalog-limits.d.ts +10 -0
  23. package/dist/catalog-limits.d.ts.map +1 -0
  24. package/dist/catalog-limits.js +10 -0
  25. package/dist/catalog-limits.js.map +1 -0
  26. package/dist/catalog-service.d.ts +137 -0
  27. package/dist/catalog-service.d.ts.map +1 -0
  28. package/dist/catalog-service.js +401 -0
  29. package/dist/catalog-service.js.map +1 -0
  30. package/dist/catalog.d.ts +6 -0
  31. package/dist/catalog.d.ts.map +1 -1
  32. package/dist/catalog.js +53 -2
  33. package/dist/catalog.js.map +1 -1
  34. package/dist/concurrency.d.ts +4 -0
  35. package/dist/concurrency.d.ts.map +1 -0
  36. package/dist/concurrency.js +31 -0
  37. package/dist/concurrency.js.map +1 -0
  38. package/dist/connectors/api.d.ts.map +1 -1
  39. package/dist/connectors/api.js +22 -12
  40. package/dist/connectors/api.js.map +1 -1
  41. package/dist/connectors/remote-mcp.d.ts.map +1 -1
  42. package/dist/connectors/remote-mcp.js +53 -41
  43. package/dist/connectors/remote-mcp.js.map +1 -1
  44. package/dist/credentials.d.ts +3 -2
  45. package/dist/credentials.d.ts.map +1 -1
  46. package/dist/errors.d.ts +19 -1
  47. package/dist/errors.d.ts.map +1 -1
  48. package/dist/errors.js.map +1 -1
  49. package/dist/execute.d.ts +10 -16
  50. package/dist/execute.d.ts.map +1 -1
  51. package/dist/execute.js +143 -330
  52. package/dist/execute.js.map +1 -1
  53. package/dist/executor-result.d.ts +0 -3
  54. package/dist/executor-result.d.ts.map +1 -1
  55. package/dist/executor-result.js +3 -3
  56. package/dist/executor-result.js.map +1 -1
  57. package/dist/executors/quickjs-child.js +3 -3
  58. package/dist/executors/quickjs-child.js.map +1 -1
  59. package/dist/executors/quickjs-protocol.d.ts +4 -1
  60. package/dist/executors/quickjs-protocol.d.ts.map +1 -1
  61. package/dist/executors/quickjs-runtime.d.ts.map +1 -1
  62. package/dist/executors/quickjs-runtime.js +7 -2
  63. package/dist/executors/quickjs-runtime.js.map +1 -1
  64. package/dist/executors/quickjs.d.ts.map +1 -1
  65. package/dist/executors/quickjs.js +4 -1
  66. package/dist/executors/quickjs.js.map +1 -1
  67. package/dist/favicon.js +2 -2
  68. package/dist/favicon.js.map +1 -1
  69. package/dist/index.d.ts +8 -82
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +58 -104
  72. package/dist/index.js.map +1 -1
  73. package/dist/invocation.d.ts +101 -0
  74. package/dist/invocation.d.ts.map +1 -0
  75. package/dist/invocation.js +405 -0
  76. package/dist/invocation.js.map +1 -0
  77. package/dist/meta-tools.d.ts +9 -95
  78. package/dist/meta-tools.d.ts.map +1 -1
  79. package/dist/meta-tools.js +235 -725
  80. package/dist/meta-tools.js.map +1 -1
  81. package/dist/operator-ui/generated.d.ts +3 -0
  82. package/dist/operator-ui/generated.d.ts.map +1 -0
  83. package/dist/operator-ui/generated.js +5 -0
  84. package/dist/operator-ui/generated.js.map +1 -0
  85. package/dist/operator-ui/model.d.ts +73 -0
  86. package/dist/operator-ui/model.d.ts.map +1 -0
  87. package/dist/operator-ui/model.js +28 -0
  88. package/dist/operator-ui/model.js.map +1 -0
  89. package/dist/registry.d.ts +33 -184
  90. package/dist/registry.d.ts.map +1 -1
  91. package/dist/registry.js +345 -330
  92. package/dist/registry.js.map +1 -1
  93. package/dist/retired-toolkits.d.ts +3 -0
  94. package/dist/retired-toolkits.d.ts.map +1 -0
  95. package/dist/retired-toolkits.js +9 -0
  96. package/dist/retired-toolkits.js.map +1 -0
  97. package/dist/routes/activity.d.ts +3 -0
  98. package/dist/routes/activity.d.ts.map +1 -0
  99. package/dist/routes/activity.js +170 -0
  100. package/dist/routes/activity.js.map +1 -0
  101. package/dist/routes/credentials.d.ts +3 -0
  102. package/dist/routes/credentials.d.ts.map +1 -0
  103. package/dist/routes/credentials.js +170 -0
  104. package/dist/routes/credentials.js.map +1 -0
  105. package/dist/routes/mcp.d.ts +8 -0
  106. package/dist/routes/mcp.d.ts.map +1 -0
  107. package/dist/routes/mcp.js +270 -0
  108. package/dist/routes/mcp.js.map +1 -0
  109. package/dist/routes/oauth.d.ts +4 -0
  110. package/dist/routes/oauth.d.ts.map +1 -0
  111. package/dist/routes/oauth.js +263 -0
  112. package/dist/routes/oauth.js.map +1 -0
  113. package/dist/routes/shared.d.ts +76 -0
  114. package/dist/routes/shared.d.ts.map +1 -0
  115. package/dist/routes/shared.js +140 -0
  116. package/dist/routes/shared.js.map +1 -0
  117. package/dist/routes/ui.d.ts +3 -0
  118. package/dist/routes/ui.d.ts.map +1 -0
  119. package/dist/routes/ui.js +116 -0
  120. package/dist/routes/ui.js.map +1 -0
  121. package/dist/server.d.ts +9 -40
  122. package/dist/server.d.ts.map +1 -1
  123. package/dist/server.js +62 -1322
  124. package/dist/server.js.map +1 -1
  125. package/dist/skills.d.ts +3 -21
  126. package/dist/skills.d.ts.map +1 -1
  127. package/dist/skills.js +15 -43
  128. package/dist/skills.js.map +1 -1
  129. package/dist/storage/file.d.ts.map +1 -1
  130. package/dist/storage/file.js +3 -1
  131. package/dist/storage/file.js.map +1 -1
  132. package/dist/storage/memory.d.ts.map +1 -1
  133. package/dist/storage/memory.js +3 -1
  134. package/dist/storage/memory.js.map +1 -1
  135. package/dist/timeout.d.ts.map +1 -1
  136. package/dist/timeout.js +2 -4
  137. package/dist/timeout.js.map +1 -1
  138. package/dist/types.d.ts +9 -59
  139. package/dist/types.d.ts.map +1 -1
  140. package/dist/ui.d.ts +3 -94
  141. package/dist/ui.d.ts.map +1 -1
  142. package/dist/ui.js +30 -1427
  143. package/dist/ui.js.map +1 -1
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/package.json +15 -8
  147. package/src/activity.ts +0 -9
  148. package/src/auth/bearer.ts +4 -33
  149. package/src/auth/clerk.ts +35 -48
  150. package/src/call-admission.ts +8 -6
  151. package/src/catalog-fingerprint.ts +52 -0
  152. package/src/catalog-limits.ts +11 -0
  153. package/src/catalog-service.ts +601 -0
  154. package/src/catalog.ts +57 -2
  155. package/src/concurrency.ts +39 -0
  156. package/src/connectors/api.ts +22 -12
  157. package/src/connectors/remote-mcp.ts +63 -45
  158. package/src/credentials.ts +2 -2
  159. package/src/errors.ts +21 -1
  160. package/src/execute.ts +193 -423
  161. package/src/executor-result.ts +3 -3
  162. package/src/executors/quickjs-child.ts +8 -4
  163. package/src/executors/quickjs-protocol.ts +1 -1
  164. package/src/executors/quickjs-runtime.ts +5 -1
  165. package/src/executors/quickjs.ts +11 -8
  166. package/src/favicon.ts +2 -2
  167. package/src/index.ts +70 -222
  168. package/src/invocation.ts +580 -0
  169. package/src/meta-tools.ts +393 -985
  170. package/src/operator-ui/browser.css +360 -0
  171. package/src/operator-ui/browser.ts +987 -0
  172. package/src/operator-ui/generated.ts +4 -0
  173. package/src/operator-ui/model.ts +105 -0
  174. package/src/registry.ts +459 -439
  175. package/src/retired-toolkits.ts +14 -0
  176. package/src/routes/activity.ts +215 -0
  177. package/src/routes/credentials.ts +254 -0
  178. package/src/routes/mcp.ts +339 -0
  179. package/src/routes/oauth.ts +322 -0
  180. package/src/routes/shared.ts +240 -0
  181. package/src/routes/ui.ts +143 -0
  182. package/src/server.ts +64 -1731
  183. package/src/skills.ts +15 -43
  184. package/src/storage/file.ts +3 -1
  185. package/src/storage/memory.ts +3 -1
  186. package/src/timeout.ts +2 -4
  187. package/src/types.ts +8 -60
  188. package/src/ui.ts +60 -1538
  189. package/src/version.ts +1 -1
  190. package/dist/credential-health.d.ts +0 -227
  191. package/dist/credential-health.d.ts.map +0 -1
  192. package/dist/credential-health.js +0 -606
  193. package/dist/credential-health.js.map +0 -1
  194. package/dist/toolkits.d.ts +0 -146
  195. package/dist/toolkits.d.ts.map +0 -1
  196. package/dist/toolkits.js +0 -322
  197. package/dist/toolkits.js.map +0 -1
  198. package/src/credential-health.ts +0 -832
  199. package/src/toolkits.ts +0 -461
package/dist/ui.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { credentialTestRule, describeUndeclaredCredentialFields, storedCredentialShape, } from "./credentials.js";
2
2
  import { closeConnectorScope, } from "./connector-scope.js";
3
+ import { mapSettledWithConcurrency, resolveDiscoveryConcurrency, } from "./concurrency.js";
4
+ import { OPERATOR_UI_CSS, OPERATOR_UI_SCRIPT, } from "./operator-ui/generated.js";
3
5
  import { CONNECTA_VERSION } from "./version.js";
6
+ export { filterUiConnectors, } from "./operator-ui/model.js";
4
7
  /** Connecta's default monochrome "C" mark. */
5
8
  export const CONNECTA_FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
6
9
  <style>
@@ -9,7 +12,7 @@ export const CONNECTA_FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" vie
9
12
  </style>
10
13
  <path class="fg" d="M27 9.4A13 13 0 1 0 27 22.6l-4.4-2.5a8 8 0 1 1 0-8.2z"/>
11
14
  </svg>`;
12
- export const DEFAULT_FAVICON_HREF = "/favicon.svg";
15
+ const DEFAULT_FAVICON_HREF = "/favicon.svg";
13
16
  /**
14
17
  * Branding arrives from operator config, which is untyped at a JS call site, so
15
18
  * every field is treated as `unknown`: a non-string is read as unset rather than
@@ -56,6 +59,13 @@ function isSetUrlValue(value) {
56
59
  ? trimmedString(value) !== undefined
57
60
  : value !== undefined && value !== null;
58
61
  }
62
+ /**
63
+ * A JS string literal safe to inline in a script element. Escaping `/` keeps
64
+ * an operator-supplied `</script>` from terminating the element early.
65
+ */
66
+ function stringForInlineScript(value) {
67
+ return JSON.stringify(value).replace(/\//g, "\\/");
68
+ }
59
69
  /**
60
70
  * Names of the branding URLs the operator set that failed their gate and were
61
71
  * replaced by a default. Lives beside the gates so the startup warning cannot
@@ -80,14 +90,6 @@ export function droppedBrandingUrls(branding) {
80
90
  : []),
81
91
  ];
82
92
  }
83
- /**
84
- * A JS string literal safe to inline in a <script> block. JSON.stringify alone
85
- * leaves `/` untouched, so a value containing "</script>" would close the
86
- * element early — operator-supplied branding still goes through here.
87
- */
88
- function escapeScriptString(value) {
89
- return JSON.stringify(value).replace(/\//g, "\\/");
90
- }
91
93
  /**
92
94
  * True only for absolute `http:`/`https:` URLs. Downstream connectors control
93
95
  * their `authorizationUrl`, so a hostile/misconfigured one could hand back a
@@ -235,33 +237,6 @@ export function credentialManagementCapability(input) {
235
237
  return "vault_not_configured";
236
238
  return "available";
237
239
  }
238
- /**
239
- * Filter by connector identity/description or tool name/description. A
240
- * connector-level match stays visible even when it currently exposes no tools
241
- * (for example while authorization is required).
242
- */
243
- export function filterUiConnectors(connectors, query) {
244
- const q = query.trim().toLowerCase();
245
- const filtered = [];
246
- for (const connector of connectors) {
247
- const connectorText = [
248
- connector.id,
249
- connector.title,
250
- connector.description,
251
- connector.status,
252
- ]
253
- .join(" ")
254
- .toLowerCase();
255
- const connectorMatches = Boolean(q && connectorText.includes(q));
256
- const tools = connector.tools.filter((tool) => !q ||
257
- connectorMatches ||
258
- `${tool.name} ${tool.description ?? ""}`.toLowerCase().includes(q));
259
- if (q && tools.length === 0 && !connectorMatches)
260
- continue;
261
- filtered.push({ connector, tools });
262
- }
263
- return filtered;
264
- }
265
240
  /**
266
241
  * Build the read-only status payload served at `/ui/data`. Broken connectors are
267
242
  * isolated: they surface status "error" with an empty tool list rather than
@@ -269,12 +244,15 @@ export function filterUiConnectors(connectors, query) {
269
244
  */
270
245
  export async function buildUiData(registry, baseUrl, serverInfo, credentialVault, activityEnabled = false, credentialManagement = credentialVault
271
246
  ? "available"
272
- : "requires_clerk", toolkits, defer, oauthManagement = false) {
247
+ : "requires_clerk", defer, oauthManagement = false, discoveryConcurrency) {
273
248
  const requestScope = {};
274
249
  const connectorSet = registry.listConnectors();
275
- const settled = await Promise.allSettled(connectorSet.map(async (c) => {
276
- const status = await registry.statusFor(c.id, baseUrl, requestScope);
277
- const credentialCheck = await registry.credentialHealthFor(c.id);
250
+ const concurrency = resolveDiscoveryConcurrency(discoveryConcurrency);
251
+ const settled = await mapSettledWithConcurrency(connectorSet, concurrency, async (c) => {
252
+ const drift = await registry.credentialDriftFor(c.id);
253
+ const status = drift
254
+ ? { state: "auth_required", message: drift }
255
+ : await registry.statusFor(c.id, baseUrl, requestScope);
278
256
  let tools = [];
279
257
  // `status()` on an unauthenticated remote connector starts OAuth and
280
258
  // stores its state + PKCE verifier. Probing listTools immediately
@@ -286,7 +264,9 @@ export async function buildUiData(registry, baseUrl, serverInfo, credentialVault
286
264
  tools = (await registry.getTools(c.id, baseUrl, requestScope)).map((t) => ({
287
265
  name: t.name,
288
266
  address: `${c.id}.${t.name}`,
289
- description: t.description,
267
+ ...(t.description !== undefined
268
+ ? { description: t.description }
269
+ : {}),
290
270
  }));
291
271
  }
292
272
  catch {
@@ -376,7 +356,9 @@ export async function buildUiData(registry, baseUrl, serverInfo, credentialVault
376
356
  return {
377
357
  id: c.id,
378
358
  ...(c.title ? { title: c.title } : {}),
379
- description: c.description,
359
+ ...(c.description !== undefined
360
+ ? { description: c.description }
361
+ : {}),
380
362
  status: status.state,
381
363
  ...(status.message ? { message: status.message } : {}),
382
364
  ...(isSafeHttpUrl(status.authorizationUrl)
@@ -385,41 +367,19 @@ export async function buildUiData(registry, baseUrl, serverInfo, credentialVault
385
367
  toolCount: tools.length,
386
368
  tools,
387
369
  ...(c.disconnectAuth && c.startAuth ? { oauth: true } : {}),
388
- ...(credentialCheck
389
- ? {
390
- credentialCheck: {
391
- state: credentialCheck.state,
392
- checkedAt: credentialCheck.checkedAt,
393
- ...(credentialCheck.message
394
- ? { message: credentialCheck.message }
395
- : {}),
396
- },
397
- }
398
- : {}),
399
370
  ...(credential ? { credential } : {}),
400
371
  };
401
- }));
402
- await Promise.all(connectorSet.map((connector) => closeConnectorScope(connector, registry.contextFor(connector.id, baseUrl, requestScope), defer)));
372
+ });
373
+ await mapSettledWithConcurrency(connectorSet, concurrency, (connector) => closeConnectorScope(connector, registry.contextFor(connector.id, baseUrl, requestScope), defer));
403
374
  const connectors = settled.map((result) => {
404
375
  if (result.status === "rejected")
405
376
  throw result.reason;
406
377
  return result.value;
407
378
  });
408
- const toolkitData = [...(toolkits?.values() ?? [])].map((toolkit) => ({
409
- name: toolkit.name,
410
- connectors: [...toolkit.connectors],
411
- includeTools: [...toolkit.includeTools],
412
- excludeTools: [...toolkit.excludeTools],
413
- toolCount: connectors.reduce((count, connector) => count +
414
- (toolkit.hasConnector(connector.id)
415
- ? connector.tools.filter((tool) => toolkit.hasTool(connector.id, tool.name)).length
416
- : 0), 0),
417
- }));
418
379
  return {
419
380
  serverInfo,
420
381
  connectaVersion: CONNECTA_VERSION,
421
382
  connectors,
422
- toolkits: toolkitData,
423
383
  activityEnabled,
424
384
  credentialManagement,
425
385
  oauthManagement,
@@ -505,421 +465,7 @@ export function renderUiHtml(uiAuth, mcpUrl = "/mcp", branding, nonce, page = "c
505
465
  <link rel="shortcut icon" href="/favicon.ico">
506
466
  <title>${escapeHtmlAttr(title)}</title>
507
467
  ${clerkScript}
508
- <style>
509
- :root {
510
- color-scheme: light;
511
- --ink: #000;
512
- --paper: #fff;
513
- --rule: #ccc;
514
- --muted: #666;
515
- --trace: #f5f5f5;
516
- --shell: 70rem;
517
- --pad: 1rem;
518
- --gap: 1.5rem;
519
- --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
520
- --mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Code", Consolas,
521
- monospace;
522
- }
523
- * { border-radius: 0; box-sizing: border-box; }
524
- html {
525
- background: var(--paper);
526
- color: var(--ink);
527
- font-family: var(--sans);
528
- font-size: 16px;
529
- line-height: 1.5;
530
- -webkit-font-smoothing: antialiased;
531
- text-rendering: optimizeLegibility;
532
- }
533
- body { margin: 0; min-height: 100vh; }
534
- ::selection { background: var(--ink); color: var(--paper); }
535
- :is(h1, h2, h3, p, ul, ol) { margin: 0; padding: 0; }
536
- :is(h1, h2, h3) { font-size: inherit; font-weight: 400; }
537
- :is(ul, ol) { list-style: none; }
538
- a { color: inherit; }
539
- button, input { font: inherit; }
540
- button {
541
- background: none;
542
- border: 0;
543
- color: inherit;
544
- cursor: pointer;
545
- margin: 0;
546
- padding: 0;
547
- text-align: left;
548
- }
549
- button:disabled { cursor: wait; opacity: .5; }
550
- input {
551
- background: var(--paper);
552
- border: 1px solid var(--rule);
553
- color: var(--ink);
554
- min-height: 2rem;
555
- padding: .2rem .5rem;
556
- }
557
- input:focus-visible { outline-offset: -1px; }
558
- :is(a, button, input, summary):focus-visible {
559
- outline: 1px solid var(--ink);
560
- }
561
- :is(a, button, summary):focus-visible { outline-offset: 2px; }
562
- .skip-link {
563
- background: var(--paper);
564
- left: var(--pad);
565
- padding: .5rem;
566
- position: fixed;
567
- top: -4rem;
568
- z-index: 10;
569
- }
570
- .skip-link:focus { top: var(--pad); }
571
-
572
- .shell {
573
- margin: 0 auto;
574
- max-width: var(--shell);
575
- padding-left: var(--pad);
576
- padding-right: var(--pad);
577
- }
578
- .pgrid {
579
- column-gap: var(--gap);
580
- display: grid;
581
- grid-template-columns: repeat(3, minmax(0, 1fr));
582
- row-gap: 1rem;
583
- }
584
- .pcap { grid-column: 1; }
585
- .pbody { grid-column: 2 / -1; min-width: 0; }
586
- .cap, .meta { color: var(--muted); font-size: .9em; }
587
- .mono { font-family: var(--mono); font-size: .78rem; }
588
- .hidden { display: none !important; }
589
- .visually-hidden {
590
- clip: rect(0 0 0 0);
591
- clip-path: inset(50%);
592
- height: 1px;
593
- overflow: hidden;
594
- position: absolute;
595
- white-space: nowrap;
596
- width: 1px;
597
- }
598
-
599
- .masthead {
600
- align-items: start;
601
- padding-bottom: var(--pad);
602
- padding-top: var(--pad);
603
- }
604
- .brand {
605
- font-weight: 500;
606
- grid-column: 1;
607
- text-decoration: none;
608
- }
609
- .mast-nav {
610
- display: flex;
611
- gap: var(--gap);
612
- grid-column: 2 / -1;
613
- justify-content: space-between;
614
- min-width: 0;
615
- }
616
- .mast-actions {
617
- display: flex;
618
- gap: var(--gap);
619
- justify-content: flex-end;
620
- min-width: 0;
621
- }
622
- .page-nav,
623
- .session-actions {
624
- display: flex;
625
- flex-wrap: wrap;
626
- gap: .5rem var(--gap);
627
- }
628
- .mast-actions :is(a, button) {
629
- align-items: center;
630
- display: inline-flex;
631
- min-height: 2rem;
632
- }
633
- .navlink,
634
- .linklike {
635
- text-decoration: underline;
636
- text-decoration-thickness: 1.5px;
637
- text-underline-offset: .22em;
638
- }
639
- .navlink { text-decoration-color: transparent; }
640
- .navlink:hover,
641
- .navlink:focus-visible,
642
- .navlink[aria-current="page"] { text-decoration-color: currentColor; }
643
- .linklike { text-decoration-color: currentColor; }
644
- .linklike:hover,
645
- .linklike:focus-visible { text-decoration-color: transparent; }
646
-
647
- .page { padding-bottom: 5rem; }
648
- .lead { margin-top: 6rem; }
649
- .section,
650
- .section + .section { margin-top: 3rem; }
651
- .lead-copy,
652
- .body-copy { max-width: 34em; }
653
- .lead-copy > * + *,
654
- .body-copy > * + * { margin-top: 1.5rem; }
655
- .row,
656
- .actions {
657
- align-items: center;
658
- display: flex;
659
- flex-wrap: wrap;
660
- gap: var(--gap);
661
- }
662
- .row input { flex: 1; min-width: 12rem; }
663
-
664
- .gate-actions { margin-top: 1.5rem; }
665
- #err { margin-top: 1.5rem; text-decoration: underline; }
666
-
667
- .endpoint { border-bottom: 1px solid var(--rule); border-top: 1px solid var(--rule); }
668
- .endpoint-row {
669
- align-items: baseline;
670
- display: flex;
671
- gap: var(--gap);
672
- min-width: 0;
673
- padding: .75rem 0;
674
- }
675
- .endpoint-row code {
676
- flex: 1;
677
- min-width: 0;
678
- overflow-x: auto;
679
- white-space: nowrap;
680
- }
681
- .endpoint-row button { flex: none; }
682
-
683
- .connector-tools { border-bottom: 1px solid var(--rule); }
684
- .toolbar { margin-bottom: 1.5rem; }
685
- .toolbar input { flex-basis: 18rem; }
686
- #notice { margin-bottom: .75rem; }
687
- #notice:empty { display: none; }
688
- #notice:not(:empty) { text-decoration: underline; }
689
- #oauthNotice { margin-bottom: .75rem; }
690
- #oauthNotice:empty { display: none; }
691
- .error-notice, .msg { text-decoration: underline; }
692
- .card,
693
- .credential-card,
694
- .activity-item {
695
- padding-left: 1.25rem;
696
- position: relative;
697
- }
698
- .card::before,
699
- .credential-card::before,
700
- .activity-item::before {
701
- background: var(--rule);
702
- bottom: 0;
703
- content: "";
704
- left: .25rem;
705
- position: absolute;
706
- top: 0;
707
- width: 1px;
708
- }
709
- .card { border-top: 1px solid var(--rule); padding-bottom: .75rem; padding-top: .75rem; }
710
- .connector-head {
711
- display: grid;
712
- gap: var(--gap);
713
- grid-template-columns: minmax(0, 2fr) minmax(10rem, 1fr);
714
- }
715
- .connector-title {
716
- align-items: baseline;
717
- display: flex;
718
- gap: .5rem;
719
- }
720
- .connector-title .dot,
721
- .activity-stamp .dot {
722
- margin-left: -1.25rem;
723
- }
724
- .activity-stamp {
725
- align-items: baseline;
726
- display: flex;
727
- gap: .75rem;
728
- }
729
- .card h2 { overflow-wrap: anywhere; }
730
- .connector-state { text-align: right; }
731
- .dot {
732
- background: var(--paper);
733
- border: 1px solid var(--ink);
734
- display: inline-block;
735
- flex: none;
736
- height: .5rem;
737
- width: .5rem;
738
- z-index: 1;
739
- }
740
- .dot.ok { background: var(--ink); }
741
- .dot.auth_required {
742
- background: linear-gradient(90deg, var(--ink) 50%, var(--paper) 50%);
743
- }
744
- .connector-description { margin-top: .25rem; max-width: 40rem; }
745
- .connector-message,
746
- .connector-auth { margin-top: .75rem; }
747
- .connector-toolkits {
748
- align-items: baseline;
749
- display: flex;
750
- flex-wrap: wrap;
751
- gap: .25rem .5rem;
752
- margin-top: .5rem;
753
- }
754
- .scope-label {
755
- border: 1px solid var(--rule);
756
- display: inline-block;
757
- font-family: var(--mono);
758
- font-size: .72rem;
759
- padding: .05rem .35rem;
760
- }
761
-
762
- .toolkit-copy { margin-bottom: 1rem; max-width: 42rem; }
763
- .toolkit-ledger { border-bottom: 1px solid var(--rule); }
764
- .toolkit-card {
765
- border-top: 1px solid var(--rule);
766
- padding: .9rem 0 1rem;
767
- }
768
- .toolkit-head {
769
- display: grid;
770
- gap: var(--gap);
771
- grid-template-columns: minmax(0, 2fr) minmax(10rem, 1fr);
772
- }
773
- .toolkit-name {
774
- align-items: baseline;
775
- display: flex;
776
- flex-wrap: wrap;
777
- gap: .5rem;
778
- }
779
- .toolkit-name h3 { overflow-wrap: anywhere; }
780
- .toolkit-state { text-align: right; }
781
- .toolkit-connectors {
782
- display: flex;
783
- flex-wrap: wrap;
784
- gap: .5rem;
785
- margin-top: .75rem;
786
- }
787
- .toolkit-connector {
788
- border-left: 1px solid var(--ink);
789
- display: inline-flex;
790
- flex-wrap: wrap;
791
- gap: .4rem;
792
- padding-left: .5rem;
793
- }
794
- .toolkit-rules { margin-top: .75rem; }
795
- .toolkit-rules > * + * { margin-top: .25rem; }
796
- .toolkit-endpoint { margin-top: .75rem; }
797
-
798
- .credential-ledger { border-bottom: 1px solid var(--rule); }
799
- .credential-card { border-top: 1px solid var(--rule); padding-bottom: .75rem; padding-top: .75rem; }
800
- .credential-head {
801
- align-items: baseline;
802
- display: flex;
803
- flex-wrap: wrap;
804
- gap: .25rem var(--gap);
805
- justify-content: space-between;
806
- }
807
- .credential-copy { margin-top: .25rem; max-width: 40rem; }
808
- .credential-field-summary {
809
- border-top: 1px solid var(--rule);
810
- margin-top: .75rem;
811
- }
812
- .credential-field-summary > div {
813
- border-bottom: 1px solid var(--rule);
814
- display: flex;
815
- flex-wrap: wrap;
816
- gap: .25rem var(--gap);
817
- justify-content: space-between;
818
- padding: .5rem 0;
819
- }
820
- .credential-actions { display: flex; flex-wrap: wrap; gap: var(--gap); margin-top: .75rem; }
821
- .credential-actions button,
822
- .credential-form button,
823
- .activity-controls button,
824
- .activity-more {
825
- align-items: center;
826
- display: inline-flex;
827
- min-height: 2.75rem;
828
- }
829
- .credential-form {
830
- align-items: center;
831
- display: flex;
832
- flex-wrap: wrap;
833
- gap: .75rem var(--gap);
834
- margin-top: .75rem;
835
- }
836
- .credential-form > input { flex: 1 1 18rem; }
837
- .credential-fields { display: grid; flex: 1 1 100%; gap: .75rem; }
838
- .credential-field {
839
- align-items: center;
840
- display: grid;
841
- gap: var(--gap);
842
- grid-template-columns: minmax(9rem, 12rem) 1fr;
843
- }
844
- .credential-field input { min-width: 0; width: 100%; }
845
- .danger { text-decoration-style: double; }
846
-
847
- details { margin-top: .75rem; }
848
- summary { cursor: pointer; list-style: none; width: max-content; }
849
- summary::-webkit-details-marker { display: none; }
850
- .tool-list { border-bottom: 1px solid var(--rule); margin-top: .5rem; }
851
- .tool {
852
- border-top: 1px solid var(--rule);
853
- display: grid;
854
- gap: .25rem var(--gap);
855
- grid-template-columns: minmax(12rem, 1fr) minmax(0, 2fr);
856
- padding: .5rem 0;
857
- }
858
- .tool code { font-family: var(--mono); font-size: .78rem; overflow-wrap: anywhere; }
859
- .tool .td { color: var(--muted); font-size: .9em; }
860
- .empty { border-top: 1px solid var(--rule); padding: .75rem 0; }
861
-
862
- .activity-copy { margin-bottom: 1.5rem; }
863
- .activity-controls { margin-bottom: 1.5rem; }
864
- .activity-controls input { flex: 1 1 18rem; }
865
- #activityNotice { margin-bottom: .75rem; }
866
- .activity-ledger { border-bottom: 1px solid var(--rule); }
867
- .activity-item {
868
- border-top: 1px solid var(--rule);
869
- display: grid;
870
- gap: .25rem var(--gap);
871
- grid-template-columns: minmax(9rem, .85fr) minmax(12rem, 1.4fr) minmax(8rem, .9fr);
872
- padding-bottom: .75rem;
873
- padding-top: .75rem;
874
- }
875
- .activity-time,
876
- .activity-actor,
877
- .activity-detail { color: var(--muted); font-size: .82rem; }
878
- .activity-actor-id { color: var(--muted); margin-top: .1rem; }
879
- .activity-address { font-family: var(--mono); font-size: .78rem; overflow-wrap: anywhere; }
880
- .activity-outcome { font-size: .9em; }
881
- .activity-item.error .activity-outcome,
882
- .activity-item.timeout .activity-outcome,
883
- .activity-item.cancelled .activity-outcome { text-decoration: underline; }
884
- .activity-empty { border-top: 1px solid var(--rule); padding: .75rem 0; }
885
- .activity-more { margin-top: .75rem; }
886
- .unavailable {
887
- background: var(--trace);
888
- border-bottom: 1px solid var(--rule);
889
- border-top: 1px solid var(--rule);
890
- padding: .75rem;
891
- }
892
-
893
- @media (prefers-reduced-motion: reduce) {
894
- html:focus-within { scroll-behavior: auto; }
895
- }
896
-
897
- @media (max-width: 36.99rem) {
898
- .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
899
- .pcap,
900
- .pbody { grid-column: 1 / -1; }
901
- .masthead .brand { grid-column: 1; }
902
- .mast-nav { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
903
- .product { display: none; }
904
- .mast-actions {
905
- align-items: flex-start;
906
- flex-direction: column;
907
- font-size: .875rem;
908
- gap: .25rem;
909
- }
910
- .lead { margin-top: 4rem; }
911
- .section,
912
- .section + .section { margin-top: 2.5rem; }
913
- .connector-head,
914
- .toolkit-head,
915
- .tool,
916
- .activity-item { grid-template-columns: 1fr; }
917
- .connector-state,
918
- .toolkit-state { text-align: left; }
919
- .credential-field { align-items: start; grid-template-columns: 1fr; gap: .25rem; }
920
- input { min-height: 2.75rem; }
921
- }
922
- </style>
468
+ <style>${OPERATOR_UI_CSS}</style>
923
469
  </head>
924
470
  <body>
925
471
  <a class="skip-link" href="#operatorContent">Skip to operator page</a>
@@ -991,16 +537,6 @@ ${clerkScript}
991
537
  <div id="list" class="connector-tools" aria-busy="false"></div>
992
538
  </div>
993
539
  </section>
994
- <section class="section pgrid" aria-labelledby="toolkitLedgerHeading">
995
- <h2 class="pcap" id="toolkitLedgerHeading">Toolkits</h2>
996
- <div class="pbody">
997
- <p class="toolkit-copy meta">
998
- Read-only views from deployment config. Change the config and redeploy
999
- to update them.
1000
- </p>
1001
- <div id="toolkitList" class="toolkit-ledger"></div>
1002
- </div>
1003
- </section>
1004
540
  </section>
1005
541
 
1006
542
  <section id="credentialsView"${page === "credentials" ? "" : ' class="hidden"'}>
@@ -1047,942 +583,9 @@ const AUTH = ${jsonForInlineScript(auth)};
1047
583
  const MCP_URL = ${jsonForInlineScript(mcpUrl)};
1048
584
  const INITIAL_PAGE = ${jsonForInlineScript(page)};
1049
585
  const TITLE_SUFFIX = ${jsonForInlineScript(brand.pageTitle)};
1050
- const filterUiConnectors = ${filterUiConnectors.toString()};
1051
- const KEY = "connecta:token";
1052
- const $ = (id) => document.getElementById(id);
1053
- const PAGE_META = {
1054
- connections: { path: "/", label: "Connections" },
1055
- credentials: { path: "/credentials", label: "Credentials" },
1056
- activity: { path: "/activity", label: "Activity" },
1057
- };
1058
- let DATA = null;
1059
- let ACTIVITY = [];
1060
- let ACTIVITY_CURSOR = null;
1061
- let ACTIVITY_LOADED = false;
1062
- let CURRENT_PAGE = INITIAL_PAGE;
1063
- let SESSION_GENERATION = 0;
1064
- let ACTIVITY_GENERATION = 0;
1065
- let CLERK_SESSION_ID = null;
1066
- $("mcpUrl").textContent = MCP_URL;
1067
-
1068
- function esc(s) {
1069
- return String(s == null ? "" : s).replace(/[&<>"]/g, (c) =>
1070
- ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]));
1071
- }
1072
-
1073
- // Only http/https may become a clickable href — mirrors the server-side gate
1074
- // so a hostile scheme (javascript:, data:) can never be linked. Defense in depth.
1075
- function safeHttp(u) {
1076
- try {
1077
- const p = new URL(u).protocol;
1078
- return p === "http:" || p === "https:" ? u : null;
1079
- } catch (e) { return null; }
1080
- }
1081
-
1082
- function formatDate(value) {
1083
- if (!value) return "";
1084
- const date = new Date(value);
1085
- return Number.isNaN(date.valueOf()) ? "" : date.toLocaleString();
1086
- }
1087
-
1088
- function setNotice(message, isError) {
1089
- $("credentialNotice").textContent = message || "";
1090
- $("credentialNotice").classList.toggle("error-notice", Boolean(isError));
1091
- $("credentialNotice").setAttribute("role", isError ? "alert" : "status");
1092
- }
1093
-
1094
- function setOauthNotice(message, isError) {
1095
- $("oauthNotice").textContent = message || "";
1096
- $("oauthNotice").classList.toggle("error-notice", Boolean(isError));
1097
- $("oauthNotice").setAttribute("role", isError ? "alert" : "status");
1098
- }
1099
-
1100
- async function sessionToken() {
1101
- return AUTH.kind === "clerk"
1102
- ? await Clerk.session?.getToken()
1103
- : localStorage.getItem(KEY);
1104
- }
1105
-
1106
- function clearActivityState() {
1107
- ACTIVITY_GENERATION += 1;
1108
- ACTIVITY = [];
1109
- ACTIVITY_CURSOR = null;
1110
- ACTIVITY_LOADED = false;
1111
- $("activityList").innerHTML = "";
1112
- $("activityList").setAttribute("aria-busy", "false");
1113
- $("activityNotice").textContent = "";
1114
- $("activityNotice").setAttribute("role", "status");
1115
- $("activitySummary").textContent = "Arguments and results are never stored.";
1116
- $("activitySearch").value = "";
1117
- $("refreshActivity").disabled = false;
1118
- $("moreActivity").disabled = false;
1119
- $("moreActivity").classList.add("hidden");
1120
- }
1121
-
1122
- function clearIdentityState() {
1123
- SESSION_GENERATION += 1;
1124
- DATA = null;
1125
- clearActivityState();
1126
- $("list").innerHTML = "";
1127
- setOauthNotice("");
1128
- $("toolkitList").innerHTML = "";
1129
- $("filter").value = "";
1130
- $("credentialList").innerHTML = "";
1131
- $("credentialList").setAttribute("aria-busy", "false");
1132
- $("credentialNotice").textContent = "";
1133
- $("credentialNotice").setAttribute("role", "status");
1134
- $("credentialNotice").classList.remove("error-notice");
1135
- $("credentialUnavailable").textContent = "";
1136
- $("credentialUnavailable").classList.add("hidden");
1137
- $("credentialList").classList.add("hidden");
1138
- $("activityUnavailable").classList.add("hidden");
1139
- $("activityAvailable").classList.add("hidden");
1140
- $("credentialsNav").classList.add("hidden");
1141
- $("activityNav").classList.add("hidden");
1142
- $("serverInfo").textContent = ${escapeScriptString(brand.productName + " operator")};
1143
- }
1144
-
1145
- function showGate(msg) {
1146
- clearIdentityState();
1147
- $("app").classList.add("hidden");
1148
- $("appNav").classList.add("hidden");
1149
- $("gate").classList.remove("hidden");
1150
- $("err").textContent = msg || "";
1151
- if (AUTH.kind === "clerk") {
1152
- const signedIn = Boolean(window.Clerk && Clerk.user);
1153
- $("gateCopy").textContent = signedIn
1154
- ? "Signed in with Clerk, but this account cannot open deployment-wide operator pages."
1155
- : "Sign in with Clerk to open this operator page.";
1156
- $("signin").classList.toggle("hidden", signedIn);
1157
- $("gateSignout").classList.toggle("hidden", !signedIn);
1158
- } else {
1159
- $("gateCopy").textContent = "";
1160
- }
1161
- }
1162
-
1163
- function pageForPath(path) {
1164
- if (path === "/credentials") return "credentials";
1165
- if (path === "/activity") return "activity";
1166
- return "connections";
1167
- }
1168
-
1169
- function credentialUnavailableCopy(capability) {
1170
- if (capability === "no_slots") {
1171
- return "No connectors declare operator-managed credential slots. Connector credentials remain configuration-as-code until a slot is declared.";
1172
- }
1173
- if (capability === "vault_not_configured") {
1174
- return "Credential storage is not configured. Set credentials.encryptionKey before managing connector credentials here.";
1175
- }
1176
- return "Credential management requires an eligible Clerk operator. Bearer-authenticated sessions can inspect connections but cannot manage stored credentials.";
1177
- }
1178
-
1179
- function updateCapabilities() {
1180
- const credentialsAvailable =
1181
- DATA?.credentialManagement === "available";
1182
- $("credentialsNav").classList.toggle("hidden", !credentialsAvailable);
1183
- $("activityNav").classList.toggle("hidden", !DATA?.activityEnabled);
1184
- $("credentialUnavailable").classList.toggle("hidden", credentialsAvailable);
1185
- $("credentialList").classList.toggle("hidden", !credentialsAvailable);
1186
- $("credentialUnavailable").textContent = credentialsAvailable
1187
- ? ""
1188
- : credentialUnavailableCopy(DATA?.credentialManagement);
1189
- $("activityUnavailable").classList.toggle("hidden", Boolean(DATA?.activityEnabled));
1190
- $("activityAvailable").classList.toggle("hidden", !DATA?.activityEnabled);
1191
- }
1192
-
1193
- function activatePage(page, options) {
1194
- const next = PAGE_META[page] ? page : "connections";
1195
- CURRENT_PAGE = next;
1196
- for (const name of Object.keys(PAGE_META)) {
1197
- $(name + "View").classList.toggle("hidden", name !== next);
1198
- const link = $(name + "Nav");
1199
- if (name === next) link.setAttribute("aria-current", "page");
1200
- else link.removeAttribute("aria-current");
1201
- }
1202
- $("gateHeading").textContent = PAGE_META[next].label;
1203
- document.title = PAGE_META[next].label + " — " + TITLE_SUFFIX;
1204
- if (DATA) {
1205
- updateCapabilities();
1206
- if (next === "connections") renderConnections();
1207
- if (next === "credentials") renderCredentials();
1208
- if (next === "activity" && DATA.activityEnabled && !ACTIVITY_LOADED) {
1209
- loadActivity(true);
1210
- }
1211
- }
1212
- if (next !== "credentials") {
1213
- $("credentialList").innerHTML = "";
1214
- setNotice("");
1215
- }
1216
- // Focus what is actually on screen. While gated the page views are hidden, so
1217
- // focusing their heading is a silent no-op that drops focus to <body> and
1218
- // restarts the next Tab from the top of the document — the gate's own h1 is
1219
- // the visible heading, and activatePage has just relabelled it.
1220
- if (options?.focus) $(DATA ? next + "Heading" : "gateHeading").focus();
1221
- }
1222
-
1223
- function navigateTo(page, href) {
1224
- history.pushState({ operatorPage: page }, "", href);
1225
- activatePage(page, { focus: true });
1226
- }
1227
-
1228
- async function load() {
1229
- const generation = SESSION_GENERATION;
1230
- let token;
1231
- try {
1232
- token = await sessionToken();
1233
- } catch (e) {
1234
- if (generation !== SESSION_GENERATION) return;
1235
- return showGate("Could not read the Clerk session: " + e.message);
1236
- }
1237
- if (generation !== SESSION_GENERATION) return;
1238
- if (!token) return showGate("");
1239
- let res;
1240
- try {
1241
- res = await fetch("/ui/data", { headers: { Authorization: "Bearer " + token } });
1242
- } catch (e) {
1243
- if (generation !== SESSION_GENERATION) return;
1244
- return showGate("Network error: " + e.message);
1245
- }
1246
- if (generation !== SESSION_GENERATION) return;
1247
- if (res.status === 401 || res.status === 403) {
1248
- if (AUTH.kind === "clerk") {
1249
- return showGate(
1250
- res.status === 403
1251
- ? "This Clerk account is not allowed to access connecta."
1252
- : "Your Clerk session was not accepted. Sign out and try again."
1253
- );
1254
- }
1255
- localStorage.removeItem(KEY);
1256
- return showGate("Token rejected — enter a valid bearer token.");
1257
- }
1258
- if (!res.ok) return showGate("Error " + res.status);
1259
- let data;
1260
- try {
1261
- data = await res.json();
1262
- } catch (e) {
1263
- if (generation !== SESSION_GENERATION) return;
1264
- return showGate("Operator data could not be read.");
1265
- }
1266
- if (generation !== SESSION_GENERATION) return;
1267
- DATA = data;
1268
- $("gate").classList.add("hidden");
1269
- $("app").classList.remove("hidden");
1270
- $("appNav").classList.remove("hidden");
1271
- const si = DATA.serverInfo || {};
1272
- $("serverInfo").textContent = (si.name || ${escapeScriptString(brand.productName)}) + " v" + (DATA.connectaVersion || "?");
1273
- updateCapabilities();
1274
- activatePage(CURRENT_PAGE);
1275
- }
1276
-
1277
- function actorLabel(actor) {
1278
- if (!actor || !actor.kind) return "unknown";
1279
- return actor.label
1280
- ? actor.kind + " · " + actor.label
1281
- : actor.id ? actor.kind + " · " + actor.id : actor.kind;
1282
- }
1283
-
1284
- function renderActivity() {
1285
- const list = $("activityList");
1286
- list.innerHTML = "";
1287
- const query = $("activitySearch").value.trim().toLowerCase();
1288
- const visible = ACTIVITY.filter((event) => {
1289
- if (!query) return true;
1290
- const actor = event.actor || {};
1291
- return [
1292
- event.address,
1293
- event.connectorId,
1294
- event.toolName,
1295
- event.source,
1296
- event.outcome,
1297
- event.errorCode,
1298
- actor.kind,
1299
- actor.id,
1300
- actor.namespace,
1301
- actor.label,
1302
- ].some((value) => String(value || "").toLowerCase().includes(query));
1303
- });
1304
- const uniqueTools = new Set(ACTIVITY.map((event) => event.address)).size;
1305
- $("activitySummary").textContent = ACTIVITY.length
1306
- ? ACTIVITY.length + " loaded call" + (ACTIVITY.length === 1 ? "" : "s") +
1307
- " · " + uniqueTools + " tool" + (uniqueTools === 1 ? "" : "s") +
1308
- " · no arguments or results stored"
1309
- : "Arguments and results are never stored.";
1310
- if (visible.length === 0) {
1311
- list.innerHTML = '<div class="activity-empty">' +
1312
- (query ? "No loaded activity matches this search." :
1313
- "No connector tool calls recorded yet.") + "</div>";
1314
- }
1315
- for (const event of visible) {
1316
- const item = document.createElement("article");
1317
- const outcomeClass = [
1318
- "success",
1319
- "error",
1320
- "timeout",
1321
- "cancelled",
1322
- ].includes(event.outcome) ? event.outcome : "error";
1323
- item.className = "activity-item " + outcomeClass;
1324
- const retryCopy = event.attempts > 1
1325
- ? " · " + esc(event.attempts) + " attempts"
1326
- : "";
1327
- const errorCopy = event.errorCode ? " · " + esc(event.errorCode) : "";
1328
- const actorId = event.actor?.id
1329
- ? (event.actor.namespace
1330
- ? event.actor.namespace + " · " + event.actor.id
1331
- : event.actor.id)
1332
- : "";
1333
- const stableActorId = actorId &&
1334
- (event.actor?.label || event.actor?.namespace)
1335
- ? '<div class="activity-actor-id mono">' + esc(actorId) + "</div>"
1336
- : "";
1337
- item.innerHTML =
1338
- '<div class="activity-stamp"><span class="dot ' +
1339
- (outcomeClass === "success" ? "ok" : "") +
1340
- '" aria-hidden="true"></span><div><time class="activity-time" datetime="' +
1341
- esc(event.occurredAt) + '">' +
1342
- esc(formatDate(event.occurredAt)) +
1343
- '</time><div class="activity-actor">' + esc(actorLabel(event.actor)) +
1344
- "</div>" + stableActorId + "</div></div>" +
1345
- '<div><div class="activity-address">' + esc(event.address) +
1346
- '</div><div class="activity-detail">' + esc(event.source) + retryCopy +
1347
- errorCopy + '</div></div>' +
1348
- '<div><div class="activity-outcome">' + esc(event.outcome) +
1349
- '</div><div class="activity-detail">' + esc(event.durationMs) + ' ms</div></div>';
1350
- list.appendChild(item);
1351
- }
1352
- $("moreActivity").classList.toggle("hidden", !ACTIVITY_CURSOR);
1353
- }
1354
-
1355
- async function loadActivity(reset) {
1356
- if (!DATA?.activityEnabled) return;
1357
- const sessionGeneration = SESSION_GENERATION;
1358
- if (reset) ACTIVITY_GENERATION += 1;
1359
- const activityGeneration = ACTIVITY_GENERATION;
1360
- const isCurrent = () =>
1361
- sessionGeneration === SESSION_GENERATION &&
1362
- activityGeneration === ACTIVITY_GENERATION;
1363
- $("activityNotice").textContent = "Loading activity…";
1364
- $("activityNotice").setAttribute("role", "status");
1365
- $("activityList").setAttribute("aria-busy", "true");
1366
- $("refreshActivity").disabled = true;
1367
- $("moreActivity").disabled = true;
1368
- try {
1369
- const token = await sessionToken();
1370
- if (!isCurrent()) return;
1371
- if (!token) return showGate("Your session has expired.");
1372
- const cursor = reset ? null : ACTIVITY_CURSOR;
1373
- const params = new URLSearchParams({ limit: "50" });
1374
- if (cursor) params.set("cursor", cursor);
1375
- const res = await fetch("/ui/activity?" + params, {
1376
- headers: { Authorization: "Bearer " + token },
1377
- });
1378
- if (!isCurrent()) return;
1379
- let payload = {};
1380
- try { payload = await res.json(); } catch (e) {}
1381
- if (!isCurrent()) return;
1382
- if (res.status === 401) {
1383
- return showGate("Your session was not accepted. Sign in again.");
1384
- }
1385
- if (res.status === 403) {
1386
- clearActivityState();
1387
- $("activityNotice").setAttribute("role", "alert");
1388
- $("activityNotice").textContent =
1389
- "This identity may not read activity history.";
1390
- return;
1391
- }
1392
- if (!res.ok) {
1393
- throw new Error(
1394
- payload.error || "Activity could not be loaded (" + res.status + ")."
1395
- );
1396
- }
1397
- ACTIVITY = reset
1398
- ? (payload.events || [])
1399
- : ACTIVITY.concat(payload.events || []);
1400
- ACTIVITY_CURSOR = payload.nextCursor || null;
1401
- ACTIVITY_LOADED = true;
1402
- $("activityNotice").textContent = "";
1403
- renderActivity();
1404
- } catch (e) {
1405
- if (!isCurrent()) return;
1406
- $("activityNotice").setAttribute("role", "alert");
1407
- $("activityNotice").textContent = e.message || "Activity could not be loaded.";
1408
- } finally {
1409
- if (isCurrent()) {
1410
- $("activityList").setAttribute("aria-busy", "false");
1411
- $("refreshActivity").disabled = false;
1412
- $("moreActivity").disabled = false;
1413
- }
1414
- }
1415
- }
1416
-
1417
- function toolkitMcpUrl(name) {
1418
- const url = new URL(MCP_URL, window.location.href);
1419
- url.searchParams.set("toolkit", name);
1420
- return url.toString();
1421
- }
1422
-
1423
- function renderToolkits() {
1424
- const list = $("toolkitList");
1425
- const toolkits = DATA.toolkits || [];
1426
- list.innerHTML = "";
1427
- if (!toolkits.length) {
1428
- list.innerHTML =
1429
- '<p class="empty">No toolkits are configured. Unscoped clients see the full connector registry.</p>';
1430
- return;
1431
- }
1432
- const connectors = new Map(
1433
- DATA.connectors.map((connector) => [connector.id, connector]),
1434
- );
1435
- for (const toolkit of toolkits) {
1436
- const el = document.createElement("article");
1437
- el.className = "toolkit-card";
1438
- const connectorCount = toolkit.connectors.length;
1439
- const toolCount = toolkit.toolCount || 0;
1440
- let body =
1441
- '<div class="toolkit-head"><div><div class="toolkit-name">' +
1442
- '<h3 class="mono">' + esc(toolkit.name) + "</h3>" +
1443
- '<span class="cap">configured view</span></div>';
1444
- body += '</div><div class="toolkit-state cap">' +
1445
- connectorCount + (connectorCount === 1 ? " connector" : " connectors") +
1446
- " · " + toolCount + (toolCount === 1 ? " loaded tool" : " loaded tools") +
1447
- "</div></div>";
1448
- body += '<ul class="toolkit-connectors" aria-label="Included connectors">';
1449
- for (const id of toolkit.connectors) {
1450
- const connector = connectors.get(id);
1451
- body += '<li class="toolkit-connector"><span>' +
1452
- esc(connector?.title || id) + '</span><code class="mono">' +
1453
- esc(id) + "</code></li>";
1454
- }
1455
- body += "</ul>";
1456
- body += '<div class="toolkit-rules meta">';
1457
- if (toolkit.includeTools.length) {
1458
- body += '<p>Per-connector allowlist: <span class="mono">' +
1459
- toolkit.includeTools.map(esc).join('</span>, <span class="mono">') +
1460
- "</span>. Connectors without an allowlist keep all tools.</p>";
1461
- }
1462
- if (toolkit.excludeTools.length) {
1463
- body += '<p>Hidden: <span class="mono">' +
1464
- toolkit.excludeTools.map(esc).join('</span>, <span class="mono">') +
1465
- "</span></p>";
1466
- }
1467
- if (!toolkit.includeTools.length && !toolkit.excludeTools.length) {
1468
- body += "<p>All tools on the included connectors are visible.</p>";
1469
- }
1470
- body += "</div>";
1471
- const endpoint = toolkitMcpUrl(toolkit.name);
1472
- body += '<div class="endpoint toolkit-endpoint"><div class="endpoint-row">' +
1473
- '<code class="mono">' + esc(endpoint) + "</code>" +
1474
- '<button class="linklike" type="button" data-toolkit-copy="' +
1475
- esc(toolkit.name) + '" aria-label="Copy endpoint for ' +
1476
- esc(toolkit.name) + '">Copy URL</button></div></div>';
1477
- el.innerHTML = body;
1478
- list.appendChild(el);
1479
- }
1480
- }
1481
-
1482
- function renderConnections() {
1483
- const q = $("filter").value.trim().toLowerCase();
1484
- const list = $("list");
1485
- list.innerHTML = "";
1486
- for (const filtered of filterUiConnectors(DATA.connectors, q)) {
1487
- const c = filtered.connector;
1488
- const tools = filtered.tools;
1489
- const el = document.createElement("div");
1490
- el.className = "card";
1491
- const status = c.status === "ok"
1492
- ? "Connected"
1493
- : c.status === "auth_required"
1494
- ? "Authorization needed"
1495
- : "Unavailable";
1496
- let head = '<div class="connector-head"><div><div class="connector-title">' +
1497
- '<span class="dot ' + esc(c.status) + '" aria-hidden="true"></span>' +
1498
- '<h2>' + esc(c.title || c.id) + "</h2></div>";
1499
- if (c.description) {
1500
- head += '<p class="connector-description meta">' + esc(c.description) + "</p>";
1501
- }
1502
- const memberships = (DATA.toolkits || [])
1503
- .filter((toolkit) => toolkit.connectors.includes(c.id))
1504
- .map((toolkit) => toolkit.name);
1505
- if (memberships.length) {
1506
- head += '<div class="connector-toolkits meta"><span>Toolkits</span>' +
1507
- memberships.map((name) =>
1508
- '<span class="scope-label">' + esc(name) + "</span>"
1509
- ).join("") + "</div>";
1510
- }
1511
- head += '</div><div class="connector-state cap">' + esc(status) + " · " +
1512
- c.toolCount + (c.toolCount === 1 ? " tool" : " tools") +
1513
- '<br><span class="mono">' + esc(c.id) + "</span></div></div>";
1514
- if (c.message) {
1515
- head += '<p class="connector-message msg">' + esc(c.message) + "</p>";
1516
- }
1517
- if (c.credentialCheck) {
1518
- const check = c.credentialCheck;
1519
- const verdict = check.state === "ok"
1520
- ? "credential verified"
1521
- : check.state === "auth_required"
1522
- ? "credential needs authorization"
1523
- : "credential check failed";
1524
- head += '<p class="connector-check meta">Credential check: ' +
1525
- esc(verdict) + " · " + esc(formatDate(check.checkedAt)) +
1526
- (check.message && check.message !== c.message
1527
- ? " — " + esc(check.message)
1528
- : "") + "</p>";
1529
- }
1530
- if (c.authorizationUrl) {
1531
- const safe = safeHttp(c.authorizationUrl);
1532
- head += safe
1533
- ? '<p class="connector-auth"><a class="linklike" href="' + esc(safe) +
1534
- '" target="_blank" rel="noopener">Authorize connector →</a></p>'
1535
- : '<p class="connector-auth meta">Authorization URL: ' +
1536
- esc(c.authorizationUrl) + "</p>";
1537
- }
1538
- if (c.oauth && DATA.oauthManagement) {
1539
- const oauthName = c.title || c.id;
1540
- head += '<div class="credential-actions">';
1541
- head += '<button type="button" class="linklike danger" ' +
1542
- 'aria-label="Disconnect OAuth for ' + esc(oauthName) + '" ' +
1543
- 'data-oauth-action="disconnect" data-connector="' + esc(c.id) +
1544
- '">Disconnect OAuth</button>';
1545
- head += '<button type="button" class="linklike" ' +
1546
- 'aria-label="' + (c.status === "ok" ? "Reconnect OAuth for " :
1547
- "Restart authorization for ") + esc(oauthName) + '" ' +
1548
- 'data-oauth-action="reconnect" data-connector="' + esc(c.id) +
1549
- '">' + (c.status === "ok" ? "Reconnect OAuth" : "Restart authorization") +
1550
- "</button></div>";
1551
- }
1552
- if (c.credential) {
1553
- head += '<p class="connector-auth"><a class="linklike" href="/credentials" ' +
1554
- 'data-operator-page="credentials">Manage credential →</a></p>';
1555
- }
1556
- let body = "";
1557
- if (tools.length) {
1558
- body = "<details" + (q ? " open" : "") +
1559
- '><summary class="linklike">Show tools (' + tools.length + ")</summary>" +
1560
- '<div class="tool-list">';
1561
- for (const t of tools) {
1562
- body += '<div class="tool"><code>' + esc(t.address) + "</code>";
1563
- if (t.description) body += '<span class="td">' + esc(t.description) + "</span>";
1564
- body += "</div>";
1565
- }
1566
- body += "</div></details>";
1567
- }
1568
- el.innerHTML = head + body;
1569
- list.appendChild(el);
1570
- }
1571
- if (!list.children.length) {
1572
- list.innerHTML = '<p class="empty">' +
1573
- (q
1574
- ? "No connectors or tools match this filter."
1575
- : "No connectors are declared in this deployment.") +
1576
- "</p>";
1577
- }
1578
- renderToolkits();
1579
- }
1580
-
1581
- async function oauthRequest(connector, method, generation) {
1582
- const token = await sessionToken();
1583
- if (generation !== SESSION_GENERATION) {
1584
- throw new Error("The operator session changed.");
1585
- }
1586
- if (!token) throw new Error("Your Clerk session has expired.");
1587
- const res = await fetch("/ui/oauth/" + encodeURIComponent(connector), {
1588
- method,
1589
- headers: { Authorization: "Bearer " + token },
1590
- });
1591
- if (res.status === 204) return null;
1592
- let payload = {};
1593
- try { payload = await res.json(); } catch (e) {}
1594
- if (!res.ok) throw new Error(payload.error || "Request failed (" + res.status + ").");
1595
- return payload;
1596
- }
1597
-
1598
- $("list").onclick = async (event) => {
1599
- const button = event.target.closest("[data-oauth-action]");
1600
- if (!button) return;
1601
- const connector = button.dataset.connector;
1602
- const action = button.dataset.oauthAction;
1603
- const generation = SESSION_GENERATION;
1604
- const question = action === "disconnect"
1605
- ? "Disconnect OAuth for " + connector +
1606
- "? Stored credentials and any pending authorization will be removed."
1607
- : "Restart OAuth for " + connector +
1608
- "? Stored credentials and any pending authorization will be replaced.";
1609
- if (!window.confirm(question)) return;
1610
-
1611
- setOauthNotice("");
1612
- const buttons = [...document.querySelectorAll(
1613
- '[data-connector="' + CSS.escape(connector) + '"]'
1614
- )];
1615
- buttons.forEach((item) => { item.disabled = true; });
1616
- try {
1617
- const result = await oauthRequest(
1618
- connector,
1619
- action === "disconnect" ? "DELETE" : "POST",
1620
- generation,
1621
- );
1622
- if (generation !== SESSION_GENERATION) return;
1623
- await load();
1624
- if (generation !== SESSION_GENERATION) return;
1625
- setOauthNotice(
1626
- action === "disconnect"
1627
- ? "OAuth disconnected. Restart authorization when you are ready to reconnect."
1628
- : result?.message ||
1629
- "Authorization restarted. Open the authorization link to reconnect.",
1630
- );
1631
- $("oauthNotice").focus();
1632
- } catch (e) {
1633
- if (generation !== SESSION_GENERATION) return;
1634
- // A reset can publish its durable epoch before best-effort physical cleanup
1635
- // reports failure. Refresh so stale tools/health/actions never survive that
1636
- // partial success, while preserving the original error for the operator.
1637
- try {
1638
- await load();
1639
- } catch (refreshError) {
1640
- // The mutation error is the actionable one; load() already owns its gate.
1641
- }
1642
- if (generation !== SESSION_GENERATION) return;
1643
- setOauthNotice(e.message || "OAuth action failed.", true);
1644
- $("oauthNotice").focus();
1645
- } finally {
1646
- if (generation === SESSION_GENERATION) {
1647
- buttons.forEach((item) => { item.disabled = false; });
1648
- }
1649
- }
1650
- };
1651
-
1652
- function renderCredentials() {
1653
- const list = $("credentialList");
1654
- list.innerHTML = "";
1655
- if (DATA.credentialManagement !== "available") return;
1656
- for (const c of DATA.connectors.filter((connector) => connector.credential)) {
1657
- const cred = c.credential;
1658
- const configured = Boolean(cred.configured);
1659
- const removable = configured || Boolean(cred.removable);
1660
- const state = configured
1661
- ? cred.fields?.length
1662
- ? "configured"
1663
- : "configured · ••••" + esc(cred.lastFour || "")
1664
- : "not configured";
1665
- const updated = configured && cred.updatedAt
1666
- ? " · updated " + esc(formatDate(cred.updatedAt))
1667
- : "";
1668
- const el = document.createElement("section");
1669
- el.className = "credential-card";
1670
- el.id = "credential-" + c.id;
1671
- el.setAttribute("aria-labelledby", "credential-title-" + c.id);
1672
- let body = '<div class="credential-head"><div class="connector-title">' +
1673
- '<span class="dot ' + (configured ? "ok" : "auth_required") +
1674
- '" aria-hidden="true"></span><h2 id="credential-title-' + esc(c.id) + '">' +
1675
- esc(c.title || c.id) + '</h2></div><span class="credential-state">' +
1676
- state + updated + "</span></div>";
1677
- body += '<p class="mono">' + esc(c.id) + " · " + esc(cred.label) + "</p>";
1678
- if (cred.description) {
1679
- body += '<p class="credential-copy meta">' + esc(cred.description) + "</p>";
1680
- }
1681
- if (cred.fields?.length) {
1682
- body += '<div class="credential-field-summary">';
1683
- for (const field of cred.fields) {
1684
- const fieldState = field.configured
1685
- ? "configured · ••••" + esc(field.lastFour || "") +
1686
- (field.updatedAt ? " · updated " + esc(formatDate(field.updatedAt)) : "")
1687
- : "not configured";
1688
- body += '<div><span>' + esc(field.label) +
1689
- '</span><span class="meta">' + fieldState + "</span></div>";
1690
- }
1691
- body += "</div>";
1692
- }
1693
- if (c.credentialCheck) {
1694
- const check = c.credentialCheck;
1695
- const verdict = check.state === "ok"
1696
- ? "healthy"
1697
- : check.state === "auth_required"
1698
- ? "needs authorization"
1699
- : "check failed";
1700
- body += '<p class="connector-check meta">Liveness: ' + esc(verdict) +
1701
- " · " + esc(formatDate(check.checkedAt)) +
1702
- (check.message ? " — " + esc(check.message) : "") + "</p>";
1703
- }
1704
- if (cred.error) body += '<div class="msg">' + esc(cred.error) + "</div>";
1705
- // Leftover stored fields are not an error — the credential still works, so
1706
- // this stays muted copy rather than the msg block an actual failure earns.
1707
- if (cred.notice) {
1708
- body += '<p class="credential-copy meta">' + esc(cred.notice) + "</p>";
1709
- }
1710
- body += '<div class="credential-actions">';
1711
- body += '<button class="linklike" type="button" data-credential-action="edit" data-connector="' +
1712
- esc(c.id) + '">' + (removable ? "Replace" : "Add credential") + "</button>";
1713
- if (configured && cred.testable) {
1714
- body += '<button class="linklike" type="button" data-credential-action="test" data-connector="' +
1715
- esc(c.id) + '">Test</button>';
1716
- }
1717
- if (removable) {
1718
- body += '<button type="button" class="linklike danger" data-credential-action="remove" data-connector="' +
1719
- esc(c.id) + '">Remove</button>';
1720
- }
1721
- body += "</div>";
1722
- body += '<div class="credential-form hidden" data-credential-form="' +
1723
- esc(c.id) + '">';
1724
- if (cred.fields && cred.fields.length) {
1725
- body += '<div class="credential-fields">';
1726
- for (let index = 0; index < cred.fields.length; index += 1) {
1727
- const field = cred.fields[index];
1728
- const inputId = "credential-input-" + c.id + "-" + index;
1729
- body += '<div class="credential-field"><label for="' + esc(inputId) + '">' +
1730
- esc(field.label) + '</label><input id="' + esc(inputId) + '" type="' +
1731
- esc(field.inputType || "password") + '" data-credential-field="' +
1732
- esc(field.name) + '" placeholder="' + esc(field.placeholder || field.label) +
1733
- '" autocomplete="' +
1734
- (field.inputType === "password" ? "new-password" : "off") +
1735
- '" autocapitalize="none" spellcheck="false"></div>';
1736
- }
1737
- body += "</div>";
1738
- } else {
1739
- const inputId = "credential-input-" + c.id;
1740
- body += '<label class="visually-hidden" for="' + esc(inputId) + '">' +
1741
- esc(cred.label) + '</label><input id="' + esc(inputId) +
1742
- '" type="password" data-credential-input="' +
1743
- esc(c.id) + '" aria-label="' + esc(cred.label) + '" placeholder="' +
1744
- esc(cred.placeholder || "Paste credential") +
1745
- '" autocomplete="new-password" autocapitalize="none" spellcheck="false">';
1746
- }
1747
- body += '<button class="linklike" type="button" data-credential-action="save" data-connector="' +
1748
- esc(c.id) + '">Save</button><button class="linklike" type="button" data-credential-action="cancel" data-connector="' +
1749
- esc(c.id) + '">Cancel</button></div>';
1750
- el.innerHTML = body;
1751
- list.appendChild(el);
1752
- }
1753
- }
1754
-
1755
- async function credentialRequest(connector, method, action, body, generation) {
1756
- const token = await sessionToken();
1757
- if (generation !== SESSION_GENERATION) {
1758
- throw new Error("The operator session changed.");
1759
- }
1760
- if (!token) throw new Error("Your Clerk session has expired.");
1761
- const suffix = action ? "/" + action : "";
1762
- const res = await fetch(
1763
- "/ui/credentials/" + encodeURIComponent(connector) + suffix,
1764
- {
1765
- method,
1766
- headers: {
1767
- Authorization: "Bearer " + token,
1768
- ...(body ? { "Content-Type": "application/json" } : {}),
1769
- },
1770
- ...(body ? { body: JSON.stringify(body) } : {}),
1771
- },
1772
- );
1773
- if (res.status === 204) return null;
1774
- let payload = {};
1775
- try { payload = await res.json(); } catch (e) {}
1776
- if (!res.ok) throw new Error(payload.error || "Request failed (" + res.status + ").");
1777
- return payload;
1778
- }
1779
-
1780
- function credentialForm(connector) {
1781
- return document.querySelector('[data-credential-form="' +
1782
- CSS.escape(connector) + '"]');
1783
- }
1784
-
1785
- $("credentialList").onclick = async (event) => {
1786
- const button = event.target.closest("[data-credential-action]");
1787
- if (!button) return;
1788
- const connector = button.dataset.connector;
1789
- const action = button.dataset.credentialAction;
1790
- const form = credentialForm(connector);
1791
- const generation = SESSION_GENERATION;
1792
-
1793
- if (action === "edit") {
1794
- form.classList.remove("hidden");
1795
- form.querySelector("input")?.focus();
1796
- return;
1797
- }
1798
- if (action === "cancel") {
1799
- form.querySelectorAll("input").forEach((input) => { input.value = ""; });
1800
- form.classList.add("hidden");
1801
- document.querySelector(
1802
- '[data-credential-action="edit"][data-connector="' +
1803
- CSS.escape(connector) + '"]'
1804
- )?.focus();
1805
- return;
1806
- }
1807
- if (action === "remove" && !window.confirm(
1808
- "Remove this credential? The connector will stop authenticating until a replacement is added."
1809
- )) return;
1810
-
1811
- setNotice("");
1812
- $("credentialList").setAttribute("aria-busy", "true");
1813
- const buttons = [...document.querySelectorAll(
1814
- '[data-connector="' + CSS.escape(connector) + '"]'
1815
- )];
1816
- buttons.forEach((item) => { item.disabled = true; });
1817
- try {
1818
- if (action === "save") {
1819
- const fieldInputs = [...form.querySelectorAll("[data-credential-field]")];
1820
- if (fieldInputs.length) {
1821
- const values = {};
1822
- for (const input of fieldInputs) {
1823
- const value = input.value.trim();
1824
- if (!value) throw new Error("Complete every credential field before saving.");
1825
- values[input.dataset.credentialField] = value;
1826
- }
1827
- await credentialRequest(connector, "PUT", "", { values }, generation);
1828
- } else {
1829
- const input = form.querySelector("[data-credential-input]");
1830
- const value = input.value.trim();
1831
- if (!value) throw new Error("Paste a credential before saving.");
1832
- await credentialRequest(connector, "PUT", "", { value }, generation);
1833
- }
1834
- if (generation !== SESSION_GENERATION) return;
1835
- form.querySelectorAll("input").forEach((input) => { input.value = ""; });
1836
- setNotice("Credential saved.");
1837
- await load();
1838
- if (generation !== SESSION_GENERATION) return;
1839
- $("credentialNotice").focus();
1840
- } else if (action === "remove") {
1841
- await credentialRequest(connector, "DELETE", "", null, generation);
1842
- if (generation !== SESSION_GENERATION) return;
1843
- setNotice("Credential removed.");
1844
- await load();
1845
- if (generation !== SESSION_GENERATION) return;
1846
- $("credentialNotice").focus();
1847
- } else if (action === "test") {
1848
- const result = await credentialRequest(
1849
- connector,
1850
- "POST",
1851
- "test",
1852
- null,
1853
- generation,
1854
- );
1855
- if (generation !== SESSION_GENERATION) return;
1856
- setNotice(
1857
- result.message || (result.ok ? "Credential is valid." : "Credential test failed."),
1858
- !result.ok,
1859
- );
1860
- }
1861
- } catch (e) {
1862
- if (generation !== SESSION_GENERATION) return;
1863
- setNotice(e.message || "Credential action failed.", true);
1864
- } finally {
1865
- if (generation === SESSION_GENERATION) {
1866
- $("credentialList").setAttribute("aria-busy", "false");
1867
- buttons.forEach((item) => { item.disabled = false; });
1868
- }
1869
- }
1870
- };
1871
-
1872
- $("save").onclick = async () => {
1873
- const v = $("token").value.trim();
1874
- if (!v) return;
1875
- clearIdentityState();
1876
- localStorage.setItem(KEY, v);
1877
- $("token").value = "";
1878
- await load();
1879
- if (DATA) $(CURRENT_PAGE + "Heading").focus();
1880
- };
1881
- $("change").onclick = () => {
1882
- localStorage.removeItem(KEY);
1883
- showGate("");
1884
- $("token").focus();
1885
- };
1886
- $("copyMcpUrl").onclick = async () => {
1887
- const button = $("copyMcpUrl");
1888
- try {
1889
- await navigator.clipboard.writeText(MCP_URL);
1890
- button.textContent = "Copied";
1891
- } catch (e) {
1892
- button.textContent = "Copy failed";
1893
- }
1894
- window.setTimeout(() => { button.textContent = "Copy URL"; }, 1600);
1895
- };
1896
- $("toolkitList").onclick = async (event) => {
1897
- const button = event.target.closest("[data-toolkit-copy]");
1898
- if (!button) return;
1899
- try {
1900
- await navigator.clipboard.writeText(
1901
- toolkitMcpUrl(button.dataset.toolkitCopy),
1902
- );
1903
- button.textContent = "Copied";
1904
- } catch (e) {
1905
- button.textContent = "Copy failed";
1906
- }
1907
- window.setTimeout(() => { button.textContent = "Copy URL"; }, 1600);
1908
- };
1909
- $("signin").onclick = () => Clerk.redirectToSignIn({
1910
- signInFallbackRedirectUrl: window.location.href,
1911
- signUpFallbackRedirectUrl: window.location.href,
1912
- });
1913
- function signOut() {
1914
- clearIdentityState();
1915
- return Clerk.signOut({ redirectUrl: window.location.href });
1916
- }
1917
- $("gateSignout").onclick = signOut;
1918
- $("signout").onclick = signOut;
1919
- $("filter").oninput = () => { if (DATA) renderConnections(); };
1920
- $("refreshActivity").onclick = () => loadActivity(true);
1921
- $("moreActivity").onclick = () => loadActivity(false);
1922
- $("activitySearch").oninput = () => renderActivity();
1923
- document.addEventListener("click", (event) => {
1924
- const link = event.target.closest("a[data-operator-page]");
1925
- if (
1926
- !link ||
1927
- event.defaultPrevented ||
1928
- event.button !== 0 ||
1929
- event.metaKey ||
1930
- event.ctrlKey ||
1931
- event.shiftKey ||
1932
- event.altKey
1933
- ) return;
1934
- const target = new URL(link.href, window.location.href);
1935
- if (target.origin !== window.location.origin) return;
1936
- event.preventDefault();
1937
- navigateTo(link.dataset.operatorPage, target.pathname + target.search + target.hash);
1938
- });
1939
- window.addEventListener("popstate", () => {
1940
- activatePage(pageForPath(window.location.pathname), { focus: true });
1941
- });
1942
-
1943
- async function init() {
1944
- if (AUTH.kind === "clerk") {
1945
- $("clerkGate").classList.remove("hidden");
1946
- $("signout").classList.remove("hidden");
1947
- try {
1948
- if (!window.Clerk) {
1949
- return showGate("Clerk could not load. Check your network and try again.");
1950
- }
1951
- await Clerk.load({
1952
- ...(AUTH.signInUrl ? { signInUrl: AUTH.signInUrl } : {}),
1953
- ...(AUTH.signUpUrl ? { signUpUrl: AUTH.signUpUrl } : {}),
1954
- signInFallbackRedirectUrl: window.location.href,
1955
- signUpFallbackRedirectUrl: window.location.href,
1956
- afterSignOutUrl: window.location.href,
1957
- });
1958
- CLERK_SESSION_ID = Clerk.session?.id ?? null;
1959
- Clerk.addListener((resources) => {
1960
- const nextSessionId = resources.session?.id ?? null;
1961
- if (nextSessionId === CLERK_SESSION_ID) return;
1962
- CLERK_SESSION_ID = nextSessionId;
1963
- // Clerk has already updated its public session before notifying
1964
- // listeners. Clear synchronously so stale identity-scoped data cannot
1965
- // be repainted while the replacement identity is being fetched.
1966
- showGate("");
1967
- void load();
1968
- });
1969
- } catch (e) {
1970
- return showGate("Clerk could not initialize: " + e.message);
1971
- }
1972
- } else {
1973
- $("tokenGate").classList.remove("hidden");
1974
- $("change").classList.remove("hidden");
1975
- }
1976
- activatePage(pageForPath(window.location.pathname));
1977
- await load();
1978
- }
1979
-
1980
- if (AUTH.kind === "clerk") {
1981
- window.addEventListener("load", init);
1982
- } else {
1983
- init();
1984
- }
1985
- </script>
586
+ const PRODUCT_NAME = ${stringForInlineScript(brand.productName)};
587
+ const PRODUCT_OPERATOR_LABEL = ${stringForInlineScript(brand.productName + " operator")};
588
+ ${OPERATOR_UI_SCRIPT}</script>
1986
589
  </body>
1987
590
  </html>`;
1988
591
  }