@zackbart/connecta 0.15.1 → 0.16.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.
- package/AGENTS.md +40 -20
- package/CHANGELOG.md +653 -0
- package/README.md +25 -5
- package/bin/connecta.mjs +44 -3
- package/dist/access-tokens.d.ts +0 -1
- package/dist/access-tokens.js +0 -1
- package/dist/activity.d.ts +50 -2
- package/dist/activity.js +34 -1
- package/dist/apps-shell.d.ts +0 -1
- package/dist/apps-shell.js +0 -1
- package/dist/auth/bearer.d.ts +0 -1
- package/dist/auth/bearer.js +0 -1
- package/dist/auth/clerk.d.ts +0 -1
- package/dist/auth/clerk.js +45 -9
- package/dist/auth/downstream-oauth.d.ts +0 -1
- package/dist/auth/downstream-oauth.js +0 -1
- package/dist/call-admission.d.ts +0 -1
- package/dist/call-admission.js +0 -1
- package/dist/catalog-drift.d.ts +99 -0
- package/dist/catalog-drift.js +251 -0
- package/dist/catalog-fingerprint.d.ts +0 -1
- package/dist/catalog-fingerprint.js +0 -1
- package/dist/catalog-limits.d.ts +0 -1
- package/dist/catalog-limits.js +0 -1
- package/dist/catalog-service.d.ts +0 -1
- package/dist/catalog-service.js +41 -5
- package/dist/catalog.d.ts +11 -1
- package/dist/catalog.js +20 -1
- package/dist/concurrency.d.ts +0 -1
- package/dist/concurrency.js +0 -1
- package/dist/connector-scope.d.ts +0 -1
- package/dist/connector-scope.js +0 -1
- package/dist/connectors/api.d.ts +29 -21
- package/dist/connectors/api.js +45 -19
- package/dist/connectors/guarded-fetch.d.ts +106 -0
- package/dist/connectors/guarded-fetch.js +289 -0
- package/dist/connectors/remote-mcp.d.ts +0 -1
- package/dist/connectors/remote-mcp.js +0 -1
- package/dist/credentials.d.ts +0 -1
- package/dist/credentials.js +0 -1
- package/dist/errors.d.ts +30 -3
- package/dist/errors.js +1 -1
- package/dist/execute.d.ts +0 -1
- package/dist/execute.js +0 -1
- package/dist/executor-admission.d.ts +11 -1
- package/dist/executor-admission.js +28 -1
- package/dist/executor-result.d.ts +0 -1
- package/dist/executor-result.js +0 -1
- package/dist/executors/quickjs-child.d.ts +0 -1
- package/dist/executors/quickjs-child.js +0 -1
- package/dist/executors/quickjs-protocol.d.ts +0 -1
- package/dist/executors/quickjs-protocol.js +0 -1
- package/dist/executors/quickjs-runtime.d.ts +0 -1
- package/dist/executors/quickjs-runtime.js +0 -1
- package/dist/executors/quickjs.d.ts +0 -1
- package/dist/executors/quickjs.js +2 -1
- package/dist/favicon.d.ts +0 -1
- package/dist/favicon.js +0 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +24 -7
- package/dist/invocation.d.ts +0 -1
- package/dist/invocation.js +0 -1
- package/dist/json-schema.d.ts +0 -1
- package/dist/json-schema.js +0 -1
- package/dist/mcp-result.d.ts +0 -1
- package/dist/mcp-result.js +0 -1
- package/dist/meta-tools.d.ts +0 -1
- package/dist/meta-tools.js +0 -1
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -1
- package/dist/operator-ui/generated.d.ts +2 -3
- package/dist/operator-ui/generated.js +3 -4
- package/dist/operator-ui/model.d.ts +10 -1
- package/dist/operator-ui/model.js +0 -1
- package/dist/operator-ui/view.d.ts +167 -0
- package/dist/operator-ui/view.js +270 -0
- package/dist/providers/cloudflare.d.ts +0 -1
- package/dist/providers/cloudflare.js +261 -299
- package/dist/providers/linear.d.ts +26 -5
- package/dist/providers/linear.js +32 -61
- package/dist/providers/mixpanel.d.ts +35 -4
- package/dist/providers/mixpanel.js +53 -79
- package/dist/providers/notion.d.ts +0 -1
- package/dist/providers/notion.js +87 -42
- package/dist/providers/stripe.d.ts +13 -1
- package/dist/providers/stripe.js +31 -60
- package/dist/registry.d.ts +34 -2
- package/dist/registry.js +85 -5
- package/dist/retired-toolkits.d.ts +0 -1
- package/dist/retired-toolkits.js +0 -1
- package/dist/routes/access-tokens.d.ts +0 -1
- package/dist/routes/access-tokens.js +0 -1
- package/dist/routes/activity.d.ts +0 -1
- package/dist/routes/activity.js +0 -1
- package/dist/routes/credentials.d.ts +0 -1
- package/dist/routes/credentials.js +0 -1
- package/dist/routes/mcp.d.ts +0 -1
- package/dist/routes/mcp.js +0 -1
- package/dist/routes/oauth.d.ts +0 -1
- package/dist/routes/oauth.js +0 -1
- package/dist/routes/shared.d.ts +2 -1
- package/dist/routes/shared.js +0 -1
- package/dist/routes/ui.d.ts +0 -1
- package/dist/routes/ui.js +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +11 -1
- package/dist/skills.d.ts +0 -1
- package/dist/skills.js +0 -1
- package/dist/storage/file.d.ts +0 -1
- package/dist/storage/file.js +0 -1
- package/dist/storage/memory.d.ts +0 -1
- package/dist/storage/memory.js +0 -1
- package/dist/timeout.d.ts +0 -1
- package/dist/timeout.js +0 -1
- package/dist/tool-safety.d.ts +0 -1
- package/dist/tool-safety.js +0 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.js +0 -1
- package/dist/ui.d.ts +0 -1
- package/dist/ui.js +13 -137
- package/dist/validate.d.ts +13 -15
- package/dist/validate.js +24 -11
- package/dist/version.d.ts +1 -2
- package/dist/version.js +1 -2
- package/documentation/architecture.md +186 -5
- package/documentation/auth.md +11 -0
- package/documentation/call-admission.md +142 -6
- package/documentation/cloudflare.md +92 -10
- package/documentation/code-first-exploration.md +2 -2
- package/documentation/code-mode.md +14 -14
- package/documentation/connector-guides.md +172 -5
- package/documentation/connectors.md +89 -0
- package/documentation/linear.md +20 -2
- package/documentation/mcp-ui-design.md +2 -2
- package/documentation/meta-tools.md +7 -1
- package/documentation/mixpanel.md +42 -9
- package/documentation/notion.md +23 -2
- package/documentation/operations.md +325 -5
- package/documentation/operator-ui.md +120 -5
- package/documentation/provider-audit.md +160 -0
- package/documentation/provider-conventions.md +667 -0
- package/documentation/request-admission.md +167 -5
- package/documentation/rich-output-design.md +1 -2
- package/documentation/stripe.md +15 -0
- package/documentation/upgrading.md +454 -0
- package/ethos.md +14 -9
- package/examples/worker/README.md +102 -12
- package/examples/worker/src/index.ts +46 -1
- package/examples/worker/wrangler.jsonc +14 -1
- package/package.json +10 -6
- package/templates/node/.dockerignore +10 -0
- package/templates/node/.env.example +40 -3
- package/templates/node/AGENTS.md +16 -1
- package/templates/node/Dockerfile +49 -0
- package/templates/node/README.md +117 -2
- package/templates/node/docker-compose.yml +39 -0
- package/templates/node/package.json +1 -1
- package/templates/node/src/file-activity.ts +182 -0
- package/templates/node/src/index.ts +80 -4
- package/assets/connecta-clay-hero.png +0 -0
- package/dist/access-tokens.d.ts.map +0 -1
- package/dist/access-tokens.js.map +0 -1
- package/dist/activity.d.ts.map +0 -1
- package/dist/activity.js.map +0 -1
- package/dist/apps-shell.d.ts.map +0 -1
- package/dist/apps-shell.js.map +0 -1
- package/dist/auth/bearer.d.ts.map +0 -1
- package/dist/auth/bearer.js.map +0 -1
- package/dist/auth/clerk.d.ts.map +0 -1
- package/dist/auth/clerk.js.map +0 -1
- package/dist/auth/downstream-oauth.d.ts.map +0 -1
- package/dist/auth/downstream-oauth.js.map +0 -1
- package/dist/call-admission.d.ts.map +0 -1
- package/dist/call-admission.js.map +0 -1
- package/dist/catalog-fingerprint.d.ts.map +0 -1
- package/dist/catalog-fingerprint.js.map +0 -1
- package/dist/catalog-limits.d.ts.map +0 -1
- package/dist/catalog-limits.js.map +0 -1
- package/dist/catalog-service.d.ts.map +0 -1
- package/dist/catalog-service.js.map +0 -1
- package/dist/catalog.d.ts.map +0 -1
- package/dist/catalog.js.map +0 -1
- package/dist/concurrency.d.ts.map +0 -1
- package/dist/concurrency.js.map +0 -1
- package/dist/connector-scope.d.ts.map +0 -1
- package/dist/connector-scope.js.map +0 -1
- package/dist/connectors/api.d.ts.map +0 -1
- package/dist/connectors/api.js.map +0 -1
- package/dist/connectors/remote-mcp.d.ts.map +0 -1
- package/dist/connectors/remote-mcp.js.map +0 -1
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/execute.d.ts.map +0 -1
- package/dist/execute.js.map +0 -1
- package/dist/executor-admission.d.ts.map +0 -1
- package/dist/executor-admission.js.map +0 -1
- package/dist/executor-result.d.ts.map +0 -1
- package/dist/executor-result.js.map +0 -1
- package/dist/executors/quickjs-child.d.ts.map +0 -1
- package/dist/executors/quickjs-child.js.map +0 -1
- package/dist/executors/quickjs-protocol.d.ts.map +0 -1
- package/dist/executors/quickjs-protocol.js.map +0 -1
- package/dist/executors/quickjs-runtime.d.ts.map +0 -1
- package/dist/executors/quickjs-runtime.js.map +0 -1
- package/dist/executors/quickjs.d.ts.map +0 -1
- package/dist/executors/quickjs.js.map +0 -1
- package/dist/favicon.d.ts.map +0 -1
- package/dist/favicon.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/invocation.d.ts.map +0 -1
- package/dist/invocation.js.map +0 -1
- package/dist/json-schema.d.ts.map +0 -1
- package/dist/json-schema.js.map +0 -1
- package/dist/mcp-result.d.ts.map +0 -1
- package/dist/mcp-result.js.map +0 -1
- package/dist/meta-tools.d.ts.map +0 -1
- package/dist/meta-tools.js.map +0 -1
- package/dist/node.d.ts.map +0 -1
- package/dist/node.js.map +0 -1
- package/dist/operator-ui/generated.d.ts.map +0 -1
- package/dist/operator-ui/generated.js.map +0 -1
- package/dist/operator-ui/model.d.ts.map +0 -1
- package/dist/operator-ui/model.js.map +0 -1
- package/dist/providers/cloudflare.d.ts.map +0 -1
- package/dist/providers/cloudflare.js.map +0 -1
- package/dist/providers/linear.d.ts.map +0 -1
- package/dist/providers/linear.js.map +0 -1
- package/dist/providers/mixpanel.d.ts.map +0 -1
- package/dist/providers/mixpanel.js.map +0 -1
- package/dist/providers/notion.d.ts.map +0 -1
- package/dist/providers/notion.js.map +0 -1
- package/dist/providers/stripe.d.ts.map +0 -1
- package/dist/providers/stripe.js.map +0 -1
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/retired-toolkits.d.ts.map +0 -1
- package/dist/retired-toolkits.js.map +0 -1
- package/dist/routes/access-tokens.d.ts.map +0 -1
- package/dist/routes/access-tokens.js.map +0 -1
- package/dist/routes/activity.d.ts.map +0 -1
- package/dist/routes/activity.js.map +0 -1
- package/dist/routes/credentials.d.ts.map +0 -1
- package/dist/routes/credentials.js.map +0 -1
- package/dist/routes/mcp.d.ts.map +0 -1
- package/dist/routes/mcp.js.map +0 -1
- package/dist/routes/oauth.d.ts.map +0 -1
- package/dist/routes/oauth.js.map +0 -1
- package/dist/routes/shared.d.ts.map +0 -1
- package/dist/routes/shared.js.map +0 -1
- package/dist/routes/ui.d.ts.map +0 -1
- package/dist/routes/ui.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/skills.d.ts.map +0 -1
- package/dist/skills.js.map +0 -1
- package/dist/storage/file.d.ts.map +0 -1
- package/dist/storage/file.js.map +0 -1
- package/dist/storage/memory.d.ts.map +0 -1
- package/dist/storage/memory.js.map +0 -1
- package/dist/timeout.d.ts.map +0 -1
- package/dist/timeout.js.map +0 -1
- package/dist/tool-safety.d.ts.map +0 -1
- package/dist/tool-safety.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js.map +0 -1
- package/dist/validate.d.ts.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
- package/examples/node/README.md +0 -52
- package/examples/node/src/index.ts +0 -71
- package/src/access-tokens.ts +0 -289
- package/src/activity.ts +0 -234
- package/src/apps-shell.ts +0 -370
- package/src/auth/bearer.ts +0 -61
- package/src/auth/clerk.ts +0 -553
- package/src/auth/downstream-oauth.ts +0 -575
- package/src/call-admission.ts +0 -521
- package/src/catalog-fingerprint.ts +0 -52
- package/src/catalog-limits.ts +0 -11
- package/src/catalog-service.ts +0 -1153
- package/src/catalog.ts +0 -790
- package/src/concurrency.ts +0 -39
- package/src/connector-scope.ts +0 -66
- package/src/connectors/api.ts +0 -159
- package/src/connectors/remote-mcp.ts +0 -1090
- package/src/credentials.ts +0 -428
- package/src/errors.ts +0 -364
- package/src/execute.ts +0 -1406
- package/src/executor-admission.ts +0 -328
- package/src/executor-result.ts +0 -107
- package/src/executors/quickjs-child.ts +0 -172
- package/src/executors/quickjs-protocol.ts +0 -99
- package/src/executors/quickjs-runtime.ts +0 -470
- package/src/executors/quickjs.ts +0 -776
- package/src/favicon.ts +0 -53
- package/src/index.ts +0 -666
- package/src/invocation.ts +0 -655
- package/src/json-schema.ts +0 -11
- package/src/mcp-result.ts +0 -43
- package/src/meta-tools.ts +0 -1607
- package/src/node.ts +0 -206
- package/src/operator-ui/browser.css +0 -423
- package/src/operator-ui/browser.ts +0 -1281
- package/src/operator-ui/generated.ts +0 -4
- package/src/operator-ui/model.ts +0 -111
- package/src/providers/cloudflare.ts +0 -3999
- package/src/providers/linear.ts +0 -302
- package/src/providers/mixpanel.ts +0 -229
- package/src/providers/notion.ts +0 -1879
- package/src/providers/stripe.ts +0 -307
- package/src/registry.ts +0 -1085
- package/src/retired-toolkits.ts +0 -14
- package/src/routes/access-tokens.ts +0 -115
- package/src/routes/activity.ts +0 -215
- package/src/routes/credentials.ts +0 -254
- package/src/routes/mcp.ts +0 -429
- package/src/routes/oauth.ts +0 -322
- package/src/routes/shared.ts +0 -247
- package/src/routes/ui.ts +0 -152
- package/src/server.ts +0 -195
- package/src/skills.ts +0 -271
- package/src/storage/file.ts +0 -123
- package/src/storage/memory.ts +0 -44
- package/src/timeout.ts +0 -84
- package/src/tool-safety.ts +0 -15
- package/src/types.ts +0 -523
- package/src/ui.ts +0 -744
- package/src/validate.ts +0 -387
- package/src/version.ts +0 -7
|
@@ -1,1281 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AccessTokenManagementCapability,
|
|
3
|
-
filterUiConnectors,
|
|
4
|
-
type CredentialManagementCapability,
|
|
5
|
-
type UiData,
|
|
6
|
-
} from "./model.js";
|
|
7
|
-
|
|
8
|
-
type OperatorPage = "connections" | "credentials" | "tokens" | "activity";
|
|
9
|
-
|
|
10
|
-
interface BrowserAuth {
|
|
11
|
-
kind: string;
|
|
12
|
-
publishableKey?: string;
|
|
13
|
-
frontendApiUrl?: string;
|
|
14
|
-
signInUrl?: string;
|
|
15
|
-
signUpUrl?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface BrowserClerkSession {
|
|
19
|
-
id?: string;
|
|
20
|
-
getToken(): Promise<string | null>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface BrowserClerk {
|
|
24
|
-
user?: unknown;
|
|
25
|
-
session?: BrowserClerkSession | null;
|
|
26
|
-
load(options: {
|
|
27
|
-
signInUrl?: string;
|
|
28
|
-
signUpUrl?: string;
|
|
29
|
-
signInFallbackRedirectUrl: string;
|
|
30
|
-
signUpFallbackRedirectUrl: string;
|
|
31
|
-
afterSignOutUrl: string;
|
|
32
|
-
}): Promise<void>;
|
|
33
|
-
addListener(
|
|
34
|
-
listener: (resources: { session?: BrowserClerkSession | null }) => void,
|
|
35
|
-
): void;
|
|
36
|
-
redirectToSignIn(options: {
|
|
37
|
-
signInFallbackRedirectUrl: string;
|
|
38
|
-
signUpFallbackRedirectUrl: string;
|
|
39
|
-
}): void;
|
|
40
|
-
signOut(options: { redirectUrl: string }): Promise<unknown>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface UiActivityActor {
|
|
44
|
-
kind?: string;
|
|
45
|
-
id?: string;
|
|
46
|
-
namespace?: string;
|
|
47
|
-
label?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface UiActivityEvent {
|
|
51
|
-
occurredAt: string;
|
|
52
|
-
actor?: UiActivityActor;
|
|
53
|
-
connectorId: string;
|
|
54
|
-
toolName: string;
|
|
55
|
-
address: string;
|
|
56
|
-
source: string;
|
|
57
|
-
outcome: string;
|
|
58
|
-
durationMs: number;
|
|
59
|
-
attempts: number;
|
|
60
|
-
errorCode?: string;
|
|
61
|
-
friction?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
interface UiActivityResponse {
|
|
65
|
-
events?: UiActivityEvent[];
|
|
66
|
-
nextCursor?: string;
|
|
67
|
-
error?: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface UiActionResponse {
|
|
71
|
-
ok?: boolean;
|
|
72
|
-
message?: string;
|
|
73
|
-
error?: string;
|
|
74
|
-
token?: string;
|
|
75
|
-
accessToken?: UiAccessToken;
|
|
76
|
-
accessTokens?: UiAccessToken[];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
interface UiAccessToken {
|
|
80
|
-
id: string;
|
|
81
|
-
name: string;
|
|
82
|
-
tokenPrefix: string;
|
|
83
|
-
createdAt: string;
|
|
84
|
-
revokedAt?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface OperatorElement extends HTMLElement {
|
|
88
|
-
disabled: boolean;
|
|
89
|
-
value: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
declare const AUTH: BrowserAuth;
|
|
93
|
-
declare const MCP_URL: string;
|
|
94
|
-
declare const INITIAL_PAGE: OperatorPage;
|
|
95
|
-
declare const TITLE_SUFFIX: string;
|
|
96
|
-
declare const PRODUCT_NAME: string;
|
|
97
|
-
declare const PRODUCT_OPERATOR_LABEL: string;
|
|
98
|
-
declare const Clerk: BrowserClerk;
|
|
99
|
-
|
|
100
|
-
declare global {
|
|
101
|
-
interface Window {
|
|
102
|
-
Clerk?: BrowserClerk;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const KEY = "connecta:token";
|
|
107
|
-
const $ = (id: string): OperatorElement => {
|
|
108
|
-
const element = document.getElementById(id);
|
|
109
|
-
if (!element) throw new Error(`Missing operator UI element #${id}`);
|
|
110
|
-
return element as OperatorElement;
|
|
111
|
-
};
|
|
112
|
-
const PAGE_META = {
|
|
113
|
-
connections: { path: "/", label: "Connections" },
|
|
114
|
-
credentials: { path: "/credentials", label: "Credentials" },
|
|
115
|
-
tokens: { path: "/tokens", label: "Access tokens" },
|
|
116
|
-
activity: { path: "/activity", label: "Activity" },
|
|
117
|
-
} satisfies Record<OperatorPage, { path: string; label: string }>;
|
|
118
|
-
let DATA: UiData | null = null;
|
|
119
|
-
let ACTIVITY: UiActivityEvent[] = [];
|
|
120
|
-
let ACTIVITY_CURSOR: string | null = null;
|
|
121
|
-
let ACTIVITY_LOADED = false;
|
|
122
|
-
let ACCESS_TOKENS: UiAccessToken[] = [];
|
|
123
|
-
let ACCESS_TOKENS_LOADED = false;
|
|
124
|
-
let CURRENT_PAGE: OperatorPage = INITIAL_PAGE;
|
|
125
|
-
let SESSION_GENERATION = 0;
|
|
126
|
-
let ACTIVITY_GENERATION = 0;
|
|
127
|
-
let CLERK_SESSION_ID: string | null = null;
|
|
128
|
-
$("mcpUrl").textContent = MCP_URL;
|
|
129
|
-
|
|
130
|
-
function errorMessage(error: unknown, fallback: string): string {
|
|
131
|
-
return error instanceof Error && error.message ? error.message : fallback;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function closestElement<T extends Element>(
|
|
135
|
-
target: EventTarget | null,
|
|
136
|
-
selector: string,
|
|
137
|
-
): T | null {
|
|
138
|
-
const candidate = target as { closest?: (value: string) => Element | null } | null;
|
|
139
|
-
return typeof candidate?.closest === "function"
|
|
140
|
-
? candidate.closest(selector) as T | null
|
|
141
|
-
: null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function esc(s: unknown): string {
|
|
145
|
-
return String(s == null ? "" : s).replace(/[&<>"]/g, (c) =>
|
|
146
|
-
({ "&": "&", "<": "<", ">": ">", '"': """ })[c] ?? c);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Only http/https may become a clickable href — mirrors the server-side gate
|
|
150
|
-
// so a hostile scheme (javascript:, data:) can never be linked. Defense in depth.
|
|
151
|
-
function safeHttp(u: string): string | null {
|
|
152
|
-
try {
|
|
153
|
-
const p = new URL(u).protocol;
|
|
154
|
-
return p === "http:" || p === "https:" ? u : null;
|
|
155
|
-
} catch { return null; }
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function formatDate(value?: string): string {
|
|
159
|
-
if (!value) return "";
|
|
160
|
-
const date = new Date(value);
|
|
161
|
-
return Number.isNaN(date.valueOf()) ? "" : date.toLocaleString();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function setNotice(message: string, isError = false): void {
|
|
165
|
-
$("credentialNotice").textContent = message || "";
|
|
166
|
-
$("credentialNotice").classList.toggle("error-notice", Boolean(isError));
|
|
167
|
-
$("credentialNotice").setAttribute("role", isError ? "alert" : "status");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function setOauthNotice(message: string, isError = false): void {
|
|
171
|
-
$("oauthNotice").textContent = message || "";
|
|
172
|
-
$("oauthNotice").classList.toggle("error-notice", Boolean(isError));
|
|
173
|
-
$("oauthNotice").setAttribute("role", isError ? "alert" : "status");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async function sessionToken(): Promise<string | null | undefined> {
|
|
177
|
-
return AUTH.kind === "clerk"
|
|
178
|
-
? await Clerk.session?.getToken()
|
|
179
|
-
: localStorage.getItem(KEY);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function clearActivityState(): void {
|
|
183
|
-
ACTIVITY_GENERATION += 1;
|
|
184
|
-
ACTIVITY = [];
|
|
185
|
-
ACTIVITY_CURSOR = null;
|
|
186
|
-
ACTIVITY_LOADED = false;
|
|
187
|
-
$("activityList").innerHTML = "";
|
|
188
|
-
$("activityList").setAttribute("aria-busy", "false");
|
|
189
|
-
$("activityNotice").textContent = "";
|
|
190
|
-
$("activityNotice").setAttribute("role", "status");
|
|
191
|
-
$("activitySummary").textContent = "Arguments and results are never stored.";
|
|
192
|
-
$("activitySearch").value = "";
|
|
193
|
-
$("refreshActivity").disabled = false;
|
|
194
|
-
$("moreActivity").disabled = false;
|
|
195
|
-
$("moreActivity").classList.add("hidden");
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function clearIdentityState(): void {
|
|
199
|
-
SESSION_GENERATION += 1;
|
|
200
|
-
DATA = null;
|
|
201
|
-
clearActivityState();
|
|
202
|
-
$("list").innerHTML = "";
|
|
203
|
-
setOauthNotice("");
|
|
204
|
-
$("filter").value = "";
|
|
205
|
-
$("credentialList").innerHTML = "";
|
|
206
|
-
$("credentialList").setAttribute("aria-busy", "false");
|
|
207
|
-
$("credentialNotice").textContent = "";
|
|
208
|
-
$("credentialNotice").setAttribute("role", "status");
|
|
209
|
-
$("credentialNotice").classList.remove("error-notice");
|
|
210
|
-
$("credentialUnavailable").textContent = "";
|
|
211
|
-
$("credentialUnavailable").classList.add("hidden");
|
|
212
|
-
$("credentialList").classList.add("hidden");
|
|
213
|
-
ACCESS_TOKENS = [];
|
|
214
|
-
ACCESS_TOKENS_LOADED = false;
|
|
215
|
-
$("tokenList").innerHTML = "";
|
|
216
|
-
$("tokenList").setAttribute("aria-busy", "false");
|
|
217
|
-
$("tokenNotice").textContent = "";
|
|
218
|
-
clearCreatedAccessToken();
|
|
219
|
-
$("tokenName").value = "";
|
|
220
|
-
$("tokenUnavailable").textContent = "";
|
|
221
|
-
$("tokenUnavailable").classList.add("hidden");
|
|
222
|
-
$("tokenAvailable").classList.add("hidden");
|
|
223
|
-
$("activityUnavailable").classList.add("hidden");
|
|
224
|
-
$("activityAvailable").classList.add("hidden");
|
|
225
|
-
$("credentialsNav").classList.add("hidden");
|
|
226
|
-
$("tokensNav").classList.add("hidden");
|
|
227
|
-
$("activityNav").classList.add("hidden");
|
|
228
|
-
$("serverInfo").textContent = PRODUCT_OPERATOR_LABEL;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function showGate(msg: string): void {
|
|
232
|
-
clearIdentityState();
|
|
233
|
-
$("app").classList.add("hidden");
|
|
234
|
-
$("appNav").classList.add("hidden");
|
|
235
|
-
$("gate").classList.remove("hidden");
|
|
236
|
-
$("err").textContent = msg || "";
|
|
237
|
-
if (AUTH.kind === "clerk") {
|
|
238
|
-
const signedIn = Boolean(window.Clerk && Clerk.user);
|
|
239
|
-
$("gateCopy").textContent = signedIn
|
|
240
|
-
? "Signed in with Clerk, but this account cannot open deployment-wide operator pages."
|
|
241
|
-
: "Sign in with Clerk to open this operator page.";
|
|
242
|
-
$("signin").classList.toggle("hidden", signedIn);
|
|
243
|
-
$("gateSignout").classList.toggle("hidden", !signedIn);
|
|
244
|
-
} else {
|
|
245
|
-
$("gateCopy").textContent = "";
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function pageForPath(path: string): OperatorPage {
|
|
250
|
-
if (path === "/credentials") return "credentials";
|
|
251
|
-
if (path === "/tokens") return "tokens";
|
|
252
|
-
if (path === "/activity") return "activity";
|
|
253
|
-
return "connections";
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function credentialUnavailableCopy(
|
|
257
|
-
capability?: CredentialManagementCapability,
|
|
258
|
-
): string {
|
|
259
|
-
if (capability === "no_slots") {
|
|
260
|
-
return "No connectors declare operator-managed credential slots. Connector credentials remain configuration-as-code until a slot is declared.";
|
|
261
|
-
}
|
|
262
|
-
if (capability === "vault_not_configured") {
|
|
263
|
-
return "Credential storage is not configured. Set credentials.encryptionKey before managing connector credentials here.";
|
|
264
|
-
}
|
|
265
|
-
return "Credential management requires an eligible Clerk operator. Bearer-authenticated sessions can inspect connections but cannot manage stored credentials.";
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function accessTokenUnavailableCopy(
|
|
269
|
-
capability?: AccessTokenManagementCapability,
|
|
270
|
-
): string {
|
|
271
|
-
if (capability === "not_configured") {
|
|
272
|
-
return "Access tokens are not configured for this deployment. Add accessTokens to the deployment configuration to enable them.";
|
|
273
|
-
}
|
|
274
|
-
return "Access token management requires an eligible Clerk operator. A Bearer token can connect to MCP, but it cannot create or revoke other tokens.";
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function setTokenNotice(message: string, error = false): void {
|
|
278
|
-
$("tokenNotice").textContent = message;
|
|
279
|
-
$("tokenNotice").setAttribute("role", error ? "alert" : "status");
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function clearCreatedAccessToken(): void {
|
|
283
|
-
$("createdToken").textContent = "";
|
|
284
|
-
$("tokenReveal").classList.add("hidden");
|
|
285
|
-
$("tokenCreateForm").classList.remove("hidden");
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function updateCapabilities(): void {
|
|
289
|
-
const credentialsAvailable =
|
|
290
|
-
DATA?.credentialManagement === "available";
|
|
291
|
-
$("credentialsNav").classList.toggle("hidden", !credentialsAvailable);
|
|
292
|
-
const tokensAvailable = DATA?.accessTokenManagement === "available";
|
|
293
|
-
$("tokensNav").classList.toggle("hidden", !tokensAvailable);
|
|
294
|
-
$("activityNav").classList.toggle("hidden", !DATA?.activityEnabled);
|
|
295
|
-
$("credentialUnavailable").classList.toggle("hidden", credentialsAvailable);
|
|
296
|
-
$("credentialList").classList.toggle("hidden", !credentialsAvailable);
|
|
297
|
-
$("credentialUnavailable").textContent = credentialsAvailable
|
|
298
|
-
? ""
|
|
299
|
-
: credentialUnavailableCopy(DATA?.credentialManagement);
|
|
300
|
-
$("tokenUnavailable").classList.toggle("hidden", Boolean(tokensAvailable));
|
|
301
|
-
$("tokenAvailable").classList.toggle("hidden", !tokensAvailable);
|
|
302
|
-
$("tokenUnavailable").textContent = tokensAvailable
|
|
303
|
-
? ""
|
|
304
|
-
: accessTokenUnavailableCopy(DATA?.accessTokenManagement);
|
|
305
|
-
$("activityUnavailable").classList.toggle("hidden", Boolean(DATA?.activityEnabled));
|
|
306
|
-
$("activityAvailable").classList.toggle("hidden", !DATA?.activityEnabled);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function activatePage(
|
|
310
|
-
page: OperatorPage,
|
|
311
|
-
options?: { focus?: boolean },
|
|
312
|
-
): void {
|
|
313
|
-
const next = PAGE_META[page] ? page : "connections";
|
|
314
|
-
CURRENT_PAGE = next;
|
|
315
|
-
for (const name of Object.keys(PAGE_META)) {
|
|
316
|
-
$(name + "View").classList.toggle("hidden", name !== next);
|
|
317
|
-
const link = $(name + "Nav");
|
|
318
|
-
if (name === next) link.setAttribute("aria-current", "page");
|
|
319
|
-
else link.removeAttribute("aria-current");
|
|
320
|
-
}
|
|
321
|
-
$("gateHeading").textContent = PAGE_META[next].label;
|
|
322
|
-
document.title = PAGE_META[next].label + " — " + TITLE_SUFFIX;
|
|
323
|
-
if (DATA) {
|
|
324
|
-
updateCapabilities();
|
|
325
|
-
if (next === "connections") renderConnections();
|
|
326
|
-
if (next === "credentials") renderCredentials();
|
|
327
|
-
if (
|
|
328
|
-
next === "tokens" &&
|
|
329
|
-
DATA.accessTokenManagement === "available" &&
|
|
330
|
-
!ACCESS_TOKENS_LOADED
|
|
331
|
-
) {
|
|
332
|
-
void loadAccessTokens();
|
|
333
|
-
}
|
|
334
|
-
if (next === "activity" && DATA.activityEnabled && !ACTIVITY_LOADED) {
|
|
335
|
-
loadActivity(true);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if (next !== "credentials") {
|
|
339
|
-
$("credentialList").innerHTML = "";
|
|
340
|
-
setNotice("");
|
|
341
|
-
}
|
|
342
|
-
if (next !== "tokens") clearCreatedAccessToken();
|
|
343
|
-
// Focus what is actually on screen. While gated the page views are hidden, so
|
|
344
|
-
// focusing their heading is a silent no-op that drops focus to <body> and
|
|
345
|
-
// restarts the next Tab from the top of the document — the gate's own h1 is
|
|
346
|
-
// the visible heading, and activatePage has just relabelled it.
|
|
347
|
-
if (options?.focus) $(DATA ? next + "Heading" : "gateHeading").focus();
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function navigateTo(page: OperatorPage, href: string): void {
|
|
351
|
-
history.pushState({ operatorPage: page }, "", href);
|
|
352
|
-
activatePage(page, { focus: true });
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
async function load(): Promise<void> {
|
|
356
|
-
const generation = SESSION_GENERATION;
|
|
357
|
-
let token;
|
|
358
|
-
try {
|
|
359
|
-
token = await sessionToken();
|
|
360
|
-
} catch (error) {
|
|
361
|
-
if (generation !== SESSION_GENERATION) return;
|
|
362
|
-
return showGate(
|
|
363
|
-
"Could not read the Clerk session: " +
|
|
364
|
-
errorMessage(error, "unknown error"),
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
if (generation !== SESSION_GENERATION) return;
|
|
368
|
-
if (!token) return showGate("");
|
|
369
|
-
let res;
|
|
370
|
-
try {
|
|
371
|
-
res = await fetch("/ui/data", { headers: { Authorization: "Bearer " + token } });
|
|
372
|
-
} catch (error) {
|
|
373
|
-
if (generation !== SESSION_GENERATION) return;
|
|
374
|
-
return showGate("Network error: " + errorMessage(error, "unknown error"));
|
|
375
|
-
}
|
|
376
|
-
if (generation !== SESSION_GENERATION) return;
|
|
377
|
-
if (res.status === 401 || res.status === 403) {
|
|
378
|
-
if (AUTH.kind === "clerk") {
|
|
379
|
-
return showGate(
|
|
380
|
-
res.status === 403
|
|
381
|
-
? "This Clerk account is not allowed to access connecta."
|
|
382
|
-
: "Your Clerk session was not accepted. Sign out and try again."
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
localStorage.removeItem(KEY);
|
|
386
|
-
return showGate("Token rejected — enter a valid bearer token.");
|
|
387
|
-
}
|
|
388
|
-
if (!res.ok) return showGate("Error " + res.status);
|
|
389
|
-
let data: UiData;
|
|
390
|
-
try {
|
|
391
|
-
data = await res.json() as UiData;
|
|
392
|
-
} catch {
|
|
393
|
-
if (generation !== SESSION_GENERATION) return;
|
|
394
|
-
return showGate("Operator data could not be read.");
|
|
395
|
-
}
|
|
396
|
-
if (generation !== SESSION_GENERATION) return;
|
|
397
|
-
DATA = data;
|
|
398
|
-
$("gate").classList.add("hidden");
|
|
399
|
-
$("app").classList.remove("hidden");
|
|
400
|
-
$("appNav").classList.remove("hidden");
|
|
401
|
-
const si = data.serverInfo || {};
|
|
402
|
-
$("serverInfo").textContent =
|
|
403
|
-
(si.name || PRODUCT_NAME) + " v" + (data.connectaVersion || "?");
|
|
404
|
-
updateCapabilities();
|
|
405
|
-
activatePage(CURRENT_PAGE);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
function actorLabel(actor?: UiActivityActor): string {
|
|
409
|
-
if (!actor || !actor.kind) return "unknown";
|
|
410
|
-
return actor.label
|
|
411
|
-
? actor.kind + " · " + actor.label
|
|
412
|
-
: actor.id ? actor.kind + " · " + actor.id : actor.kind;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
function renderActivity(): void {
|
|
416
|
-
const list = $("activityList");
|
|
417
|
-
list.innerHTML = "";
|
|
418
|
-
const query = $("activitySearch").value.trim().toLowerCase();
|
|
419
|
-
const visible = ACTIVITY.filter((event) => {
|
|
420
|
-
if (!query) return true;
|
|
421
|
-
const actor = event.actor || {};
|
|
422
|
-
return [
|
|
423
|
-
event.address,
|
|
424
|
-
event.connectorId,
|
|
425
|
-
event.toolName,
|
|
426
|
-
event.source,
|
|
427
|
-
event.outcome,
|
|
428
|
-
event.errorCode,
|
|
429
|
-
event.friction,
|
|
430
|
-
actor.kind,
|
|
431
|
-
actor.id,
|
|
432
|
-
actor.namespace,
|
|
433
|
-
actor.label,
|
|
434
|
-
].some((value) => String(value || "").toLowerCase().includes(query));
|
|
435
|
-
});
|
|
436
|
-
const uniqueTools = new Set(ACTIVITY.map((event) => event.address)).size;
|
|
437
|
-
$("activitySummary").textContent = ACTIVITY.length
|
|
438
|
-
? ACTIVITY.length + " loaded call" + (ACTIVITY.length === 1 ? "" : "s") +
|
|
439
|
-
" · " + uniqueTools + " tool" + (uniqueTools === 1 ? "" : "s") +
|
|
440
|
-
" · no arguments or results stored"
|
|
441
|
-
: "Arguments and results are never stored.";
|
|
442
|
-
if (visible.length === 0) {
|
|
443
|
-
list.innerHTML = '<div class="activity-empty">' +
|
|
444
|
-
(query ? "No loaded activity matches this search." :
|
|
445
|
-
"No connector tool calls recorded yet.") + "</div>";
|
|
446
|
-
}
|
|
447
|
-
for (const event of visible) {
|
|
448
|
-
const item = document.createElement("article");
|
|
449
|
-
const outcomeClass = [
|
|
450
|
-
"success",
|
|
451
|
-
"error",
|
|
452
|
-
"timeout",
|
|
453
|
-
"cancelled",
|
|
454
|
-
].includes(event.outcome) ? event.outcome : "error";
|
|
455
|
-
item.className = "activity-item " + outcomeClass;
|
|
456
|
-
const retryCopy = event.attempts > 1
|
|
457
|
-
? " · " + esc(event.attempts) + " attempts"
|
|
458
|
-
: "";
|
|
459
|
-
const frictionCopy = event.friction ? " · " + esc(event.friction) : "";
|
|
460
|
-
// The friction class and the code coincide for auth_required and
|
|
461
|
-
// result_too_large. Printing "· auth_required · auth_required" says nothing
|
|
462
|
-
// twice, so the coarse class stands in for both when they agree.
|
|
463
|
-
const errorCopy = event.errorCode && event.errorCode !== event.friction
|
|
464
|
-
? " · " + esc(event.errorCode)
|
|
465
|
-
: "";
|
|
466
|
-
const actorId = event.actor?.id
|
|
467
|
-
? (event.actor.namespace
|
|
468
|
-
? event.actor.namespace + " · " + event.actor.id
|
|
469
|
-
: event.actor.id)
|
|
470
|
-
: "";
|
|
471
|
-
const stableActorId = actorId &&
|
|
472
|
-
(event.actor?.label || event.actor?.namespace)
|
|
473
|
-
? '<div class="activity-actor-id mono">' + esc(actorId) + "</div>"
|
|
474
|
-
: "";
|
|
475
|
-
item.innerHTML =
|
|
476
|
-
'<div class="activity-stamp"><span class="dot ' +
|
|
477
|
-
(outcomeClass === "success" ? "ok" : "") +
|
|
478
|
-
'" aria-hidden="true"></span><div><time class="activity-time" datetime="' +
|
|
479
|
-
esc(event.occurredAt) + '">' +
|
|
480
|
-
esc(formatDate(event.occurredAt)) +
|
|
481
|
-
'</time><div class="activity-actor">' + esc(actorLabel(event.actor)) +
|
|
482
|
-
"</div>" + stableActorId + "</div></div>" +
|
|
483
|
-
'<div><div class="activity-address">' + esc(event.address) +
|
|
484
|
-
'</div><div class="activity-detail">' + esc(event.source) + retryCopy +
|
|
485
|
-
frictionCopy + errorCopy + '</div></div>' +
|
|
486
|
-
'<div><div class="activity-outcome">' + esc(event.outcome) +
|
|
487
|
-
'</div><div class="activity-detail">' + esc(event.durationMs) + ' ms</div></div>';
|
|
488
|
-
list.appendChild(item);
|
|
489
|
-
}
|
|
490
|
-
$("moreActivity").classList.toggle("hidden", !ACTIVITY_CURSOR);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
async function loadActivity(reset: boolean): Promise<void> {
|
|
494
|
-
if (!DATA?.activityEnabled) return;
|
|
495
|
-
const sessionGeneration = SESSION_GENERATION;
|
|
496
|
-
if (reset) ACTIVITY_GENERATION += 1;
|
|
497
|
-
const activityGeneration = ACTIVITY_GENERATION;
|
|
498
|
-
const isCurrent = () =>
|
|
499
|
-
sessionGeneration === SESSION_GENERATION &&
|
|
500
|
-
activityGeneration === ACTIVITY_GENERATION;
|
|
501
|
-
$("activityNotice").textContent = "Loading activity…";
|
|
502
|
-
$("activityNotice").setAttribute("role", "status");
|
|
503
|
-
$("activityList").setAttribute("aria-busy", "true");
|
|
504
|
-
$("refreshActivity").disabled = true;
|
|
505
|
-
$("moreActivity").disabled = true;
|
|
506
|
-
try {
|
|
507
|
-
const token = await sessionToken();
|
|
508
|
-
if (!isCurrent()) return;
|
|
509
|
-
if (!token) return showGate("Your session has expired.");
|
|
510
|
-
const cursor = reset ? null : ACTIVITY_CURSOR;
|
|
511
|
-
const params = new URLSearchParams({ limit: "50" });
|
|
512
|
-
if (cursor) params.set("cursor", cursor);
|
|
513
|
-
const res = await fetch("/ui/activity?" + params, {
|
|
514
|
-
headers: { Authorization: "Bearer " + token },
|
|
515
|
-
});
|
|
516
|
-
if (!isCurrent()) return;
|
|
517
|
-
let payload: UiActivityResponse = {};
|
|
518
|
-
try {
|
|
519
|
-
payload = await res.json() as UiActivityResponse;
|
|
520
|
-
} catch {
|
|
521
|
-
// The status code below still owns the operator-facing error.
|
|
522
|
-
}
|
|
523
|
-
if (!isCurrent()) return;
|
|
524
|
-
if (res.status === 401) {
|
|
525
|
-
return showGate("Your session was not accepted. Sign in again.");
|
|
526
|
-
}
|
|
527
|
-
if (res.status === 403) {
|
|
528
|
-
clearActivityState();
|
|
529
|
-
$("activityNotice").setAttribute("role", "alert");
|
|
530
|
-
$("activityNotice").textContent =
|
|
531
|
-
"This identity may not read activity history.";
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
if (!res.ok) {
|
|
535
|
-
throw new Error(
|
|
536
|
-
payload.error || "Activity could not be loaded (" + res.status + ")."
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
ACTIVITY = reset
|
|
540
|
-
? (payload.events || [])
|
|
541
|
-
: ACTIVITY.concat(payload.events || []);
|
|
542
|
-
ACTIVITY_CURSOR = payload.nextCursor || null;
|
|
543
|
-
ACTIVITY_LOADED = true;
|
|
544
|
-
$("activityNotice").textContent = "";
|
|
545
|
-
renderActivity();
|
|
546
|
-
} catch (error) {
|
|
547
|
-
if (!isCurrent()) return;
|
|
548
|
-
$("activityNotice").setAttribute("role", "alert");
|
|
549
|
-
$("activityNotice").textContent = errorMessage(
|
|
550
|
-
error,
|
|
551
|
-
"Activity could not be loaded.",
|
|
552
|
-
);
|
|
553
|
-
} finally {
|
|
554
|
-
if (isCurrent()) {
|
|
555
|
-
$("activityList").setAttribute("aria-busy", "false");
|
|
556
|
-
$("refreshActivity").disabled = false;
|
|
557
|
-
$("moreActivity").disabled = false;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
function renderConnections(): void {
|
|
563
|
-
const data = DATA;
|
|
564
|
-
if (!data) return;
|
|
565
|
-
const q = $("filter").value.trim().toLowerCase();
|
|
566
|
-
const list = $("list");
|
|
567
|
-
list.innerHTML = "";
|
|
568
|
-
for (const filtered of filterUiConnectors(data.connectors, q)) {
|
|
569
|
-
const c = filtered.connector;
|
|
570
|
-
const tools = filtered.tools;
|
|
571
|
-
const el = document.createElement("div");
|
|
572
|
-
el.className = "card";
|
|
573
|
-
const status = c.status === "ok"
|
|
574
|
-
? "Connected"
|
|
575
|
-
: c.status === "auth_required"
|
|
576
|
-
? "Authorization needed"
|
|
577
|
-
: "Unavailable";
|
|
578
|
-
let head = '<div class="connector-head"><div><div class="connector-title">' +
|
|
579
|
-
'<span class="dot ' + esc(c.status) + '" aria-hidden="true"></span>' +
|
|
580
|
-
'<h2>' + esc(c.title || c.id) + "</h2></div>";
|
|
581
|
-
if (c.description) {
|
|
582
|
-
head += '<p class="connector-description meta">' + esc(c.description) + "</p>";
|
|
583
|
-
}
|
|
584
|
-
head += '</div><div class="connector-state cap">' + esc(status) + " · " +
|
|
585
|
-
c.toolCount + (c.toolCount === 1 ? " tool" : " tools") +
|
|
586
|
-
'<br><span class="mono">' + esc(c.id) + "</span></div></div>";
|
|
587
|
-
if (c.message) {
|
|
588
|
-
head += '<p class="connector-message msg">' + esc(c.message) + "</p>";
|
|
589
|
-
}
|
|
590
|
-
if (c.authorizationUrl) {
|
|
591
|
-
const safe = safeHttp(c.authorizationUrl);
|
|
592
|
-
head += safe
|
|
593
|
-
? '<p class="connector-auth"><a class="linklike" href="' + esc(safe) +
|
|
594
|
-
'" target="_blank" rel="noopener">Authorize connector →</a></p>'
|
|
595
|
-
: '<p class="connector-auth meta">Authorization URL: ' +
|
|
596
|
-
esc(c.authorizationUrl) + "</p>";
|
|
597
|
-
}
|
|
598
|
-
if (c.oauth && data.oauthManagement) {
|
|
599
|
-
const oauthName = c.title || c.id;
|
|
600
|
-
head += '<div class="credential-actions">';
|
|
601
|
-
head += '<button type="button" class="linklike danger" ' +
|
|
602
|
-
'aria-label="Disconnect OAuth for ' + esc(oauthName) + '" ' +
|
|
603
|
-
'data-oauth-action="disconnect" data-connector="' + esc(c.id) +
|
|
604
|
-
'">Disconnect OAuth</button>';
|
|
605
|
-
head += '<button type="button" class="linklike" ' +
|
|
606
|
-
'aria-label="' + (c.status === "ok" ? "Reconnect OAuth for " :
|
|
607
|
-
"Restart authorization for ") + esc(oauthName) + '" ' +
|
|
608
|
-
'data-oauth-action="reconnect" data-connector="' + esc(c.id) +
|
|
609
|
-
'">' + (c.status === "ok" ? "Reconnect OAuth" : "Restart authorization") +
|
|
610
|
-
"</button></div>";
|
|
611
|
-
}
|
|
612
|
-
if (c.credential) {
|
|
613
|
-
head += '<p class="connector-auth"><a class="linklike" href="/credentials" ' +
|
|
614
|
-
'data-operator-page="credentials">Manage credential →</a></p>';
|
|
615
|
-
}
|
|
616
|
-
let body = "";
|
|
617
|
-
if (tools.length) {
|
|
618
|
-
body = "<details" + (q ? " open" : "") +
|
|
619
|
-
'><summary class="linklike">Show tools (' + tools.length + ")</summary>" +
|
|
620
|
-
'<div class="tool-list">';
|
|
621
|
-
for (const t of tools) {
|
|
622
|
-
body += '<div class="tool"><code>' + esc(t.address) + "</code>";
|
|
623
|
-
if (t.description) body += '<span class="td">' + esc(t.description) + "</span>";
|
|
624
|
-
body += "</div>";
|
|
625
|
-
}
|
|
626
|
-
body += "</div></details>";
|
|
627
|
-
}
|
|
628
|
-
el.innerHTML = head + body;
|
|
629
|
-
list.appendChild(el);
|
|
630
|
-
}
|
|
631
|
-
if (!list.children.length) {
|
|
632
|
-
list.innerHTML = '<p class="empty">' +
|
|
633
|
-
(q
|
|
634
|
-
? "No connectors or tools match this filter."
|
|
635
|
-
: "No connectors are declared in this deployment.") +
|
|
636
|
-
"</p>";
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
async function operatorRequest(
|
|
641
|
-
path: string,
|
|
642
|
-
method: "DELETE" | "GET" | "POST" | "PUT",
|
|
643
|
-
generation: number,
|
|
644
|
-
body?: object,
|
|
645
|
-
): Promise<UiActionResponse | null> {
|
|
646
|
-
const token = await sessionToken();
|
|
647
|
-
if (generation !== SESSION_GENERATION) {
|
|
648
|
-
throw new Error("The operator session changed.");
|
|
649
|
-
}
|
|
650
|
-
if (!token) throw new Error("Your Clerk session has expired.");
|
|
651
|
-
const res = await fetch(path, {
|
|
652
|
-
method,
|
|
653
|
-
headers: {
|
|
654
|
-
Authorization: "Bearer " + token,
|
|
655
|
-
...(body ? { "Content-Type": "application/json" } : {}),
|
|
656
|
-
},
|
|
657
|
-
...(body ? { body: JSON.stringify(body) } : {}),
|
|
658
|
-
});
|
|
659
|
-
if (res.status === 204) return null;
|
|
660
|
-
let payload: UiActionResponse = {};
|
|
661
|
-
try {
|
|
662
|
-
payload = await res.json() as UiActionResponse;
|
|
663
|
-
} catch {
|
|
664
|
-
// The status code below still owns the operator-facing error.
|
|
665
|
-
}
|
|
666
|
-
if (!res.ok) throw new Error(payload.error || "Request failed (" + res.status + ").");
|
|
667
|
-
return payload;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function renderAccessTokens(): void {
|
|
671
|
-
const list = $("tokenList");
|
|
672
|
-
list.innerHTML = "";
|
|
673
|
-
if (!ACCESS_TOKENS.length) {
|
|
674
|
-
list.innerHTML =
|
|
675
|
-
'<p class="empty">No access tokens yet. Name the first MCP client above.</p>';
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
for (const token of ACCESS_TOKENS) {
|
|
679
|
-
const revoked = Boolean(token.revokedAt);
|
|
680
|
-
const item = document.createElement("section");
|
|
681
|
-
item.className = "token-card" + (revoked ? " revoked" : "");
|
|
682
|
-
item.setAttribute("aria-labelledby", "access-token-" + token.id);
|
|
683
|
-
item.innerHTML =
|
|
684
|
-
'<div class="token-card-head"><div><h2 id="access-token-' +
|
|
685
|
-
esc(token.id) + '">' + esc(token.name) +
|
|
686
|
-
'</h2><p class="mono">' + esc(token.tokenPrefix) +
|
|
687
|
-
'…</p></div><div class="cap">' +
|
|
688
|
-
(revoked
|
|
689
|
-
? "Revoked " + esc(formatDate(token.revokedAt!))
|
|
690
|
-
: "Created " + esc(formatDate(token.createdAt))) +
|
|
691
|
-
"</div></div>" +
|
|
692
|
-
'<div class="credential-actions">' +
|
|
693
|
-
'<button class="linklike" type="button" data-token-action="rename" data-token-id="' +
|
|
694
|
-
esc(token.id) + '">Rename</button>' +
|
|
695
|
-
(revoked
|
|
696
|
-
? ""
|
|
697
|
-
: '<button class="linklike danger" type="button" data-token-action="revoke" data-token-id="' +
|
|
698
|
-
esc(token.id) + '">Revoke</button>') +
|
|
699
|
-
"</div>" +
|
|
700
|
-
'<form class="credential-form hidden" data-token-form="' +
|
|
701
|
-
esc(token.id) + '"><label class="visually-hidden" for="token-name-' +
|
|
702
|
-
esc(token.id) + '">Token name</label><input id="token-name-' +
|
|
703
|
-
esc(token.id) + '" type="text" maxlength="80" value="' +
|
|
704
|
-
esc(token.name) + '" autocomplete="off">' +
|
|
705
|
-
'<button class="linklike" type="submit" data-token-action="save-name" data-token-id="' +
|
|
706
|
-
esc(token.id) + '">Save name</button>' +
|
|
707
|
-
'<button class="linklike" type="button" data-token-action="cancel-name" data-token-id="' +
|
|
708
|
-
esc(token.id) + '">Cancel</button></form>';
|
|
709
|
-
list.appendChild(item);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
async function loadAccessTokens(): Promise<void> {
|
|
714
|
-
const generation = SESSION_GENERATION;
|
|
715
|
-
$("tokenList").setAttribute("aria-busy", "true");
|
|
716
|
-
setTokenNotice("Loading access tokens…");
|
|
717
|
-
try {
|
|
718
|
-
const payload = await operatorRequest(
|
|
719
|
-
"/ui/access-tokens",
|
|
720
|
-
"GET",
|
|
721
|
-
generation,
|
|
722
|
-
);
|
|
723
|
-
if (generation !== SESSION_GENERATION) return;
|
|
724
|
-
ACCESS_TOKENS = payload?.accessTokens || [];
|
|
725
|
-
ACCESS_TOKENS_LOADED = true;
|
|
726
|
-
setTokenNotice("");
|
|
727
|
-
renderAccessTokens();
|
|
728
|
-
} catch (error) {
|
|
729
|
-
if (generation !== SESSION_GENERATION) return;
|
|
730
|
-
setTokenNotice(errorMessage(
|
|
731
|
-
error,
|
|
732
|
-
"Access tokens could not be loaded.",
|
|
733
|
-
), true);
|
|
734
|
-
} finally {
|
|
735
|
-
if (generation === SESSION_GENERATION) {
|
|
736
|
-
$("tokenList").setAttribute("aria-busy", "false");
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
$("tokenCreateForm").onsubmit = async (event) => {
|
|
742
|
-
event.preventDefault();
|
|
743
|
-
const name = $("tokenName").value.trim();
|
|
744
|
-
if (!name) {
|
|
745
|
-
setTokenNotice("Name the MCP client before creating a token.", true);
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
const generation = SESSION_GENERATION;
|
|
749
|
-
$("createToken").disabled = true;
|
|
750
|
-
setTokenNotice("");
|
|
751
|
-
try {
|
|
752
|
-
const payload = await operatorRequest(
|
|
753
|
-
"/ui/access-tokens",
|
|
754
|
-
"POST",
|
|
755
|
-
generation,
|
|
756
|
-
{ name },
|
|
757
|
-
);
|
|
758
|
-
if (generation !== SESSION_GENERATION) return;
|
|
759
|
-
if (!payload?.token || !payload.accessToken) {
|
|
760
|
-
throw new Error("The created token was not returned.");
|
|
761
|
-
}
|
|
762
|
-
ACCESS_TOKENS = [
|
|
763
|
-
payload.accessToken,
|
|
764
|
-
...ACCESS_TOKENS.filter((token) => token.id !== payload.accessToken!.id),
|
|
765
|
-
];
|
|
766
|
-
ACCESS_TOKENS_LOADED = true;
|
|
767
|
-
$("tokenName").value = "";
|
|
768
|
-
$("createdToken").textContent = payload.token;
|
|
769
|
-
$("tokenCreateForm").classList.add("hidden");
|
|
770
|
-
$("tokenReveal").classList.remove("hidden");
|
|
771
|
-
setTokenNotice("Access token created.");
|
|
772
|
-
renderAccessTokens();
|
|
773
|
-
$("tokenRevealHeading").focus();
|
|
774
|
-
} catch (error) {
|
|
775
|
-
if (generation !== SESSION_GENERATION) return;
|
|
776
|
-
setTokenNotice(errorMessage(
|
|
777
|
-
error,
|
|
778
|
-
"Access token could not be created.",
|
|
779
|
-
), true);
|
|
780
|
-
$("tokenNotice").focus();
|
|
781
|
-
} finally {
|
|
782
|
-
if (generation === SESSION_GENERATION) $("createToken").disabled = false;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
$("copyCreatedToken").onclick = async () => {
|
|
787
|
-
const button = $("copyCreatedToken");
|
|
788
|
-
const token = $("createdToken").textContent || "";
|
|
789
|
-
try {
|
|
790
|
-
await navigator.clipboard.writeText(token);
|
|
791
|
-
button.textContent = "Copied";
|
|
792
|
-
} catch {
|
|
793
|
-
button.textContent = "Copy failed";
|
|
794
|
-
}
|
|
795
|
-
window.setTimeout(() => { button.textContent = "Copy token"; }, 1600);
|
|
796
|
-
};
|
|
797
|
-
|
|
798
|
-
$("dismissCreatedToken").onclick = () => {
|
|
799
|
-
clearCreatedAccessToken();
|
|
800
|
-
$("tokenName").focus();
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
$("tokenList").onclick = async (event) => {
|
|
804
|
-
const button = closestElement<HTMLButtonElement>(
|
|
805
|
-
event.target,
|
|
806
|
-
"[data-token-action]",
|
|
807
|
-
);
|
|
808
|
-
if (!button) return;
|
|
809
|
-
const id = button.dataset.tokenId;
|
|
810
|
-
const action = button.dataset.tokenAction;
|
|
811
|
-
if (!id || !action) return;
|
|
812
|
-
const form = document.querySelector<HTMLFormElement>(
|
|
813
|
-
'[data-token-form="' + CSS.escape(id) + '"]',
|
|
814
|
-
);
|
|
815
|
-
if (!form) return;
|
|
816
|
-
if (action === "rename") {
|
|
817
|
-
form.classList.remove("hidden");
|
|
818
|
-
form.querySelector("input")?.focus();
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
if (action === "cancel-name") {
|
|
822
|
-
const current = ACCESS_TOKENS.find((token) => token.id === id);
|
|
823
|
-
const input = form.querySelector<HTMLInputElement>("input");
|
|
824
|
-
if (input && current) input.value = current.name;
|
|
825
|
-
form.classList.add("hidden");
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
if (action !== "revoke") return;
|
|
829
|
-
const named = ACCESS_TOKENS.find((token) => token.id === id);
|
|
830
|
-
if (!window.confirm(
|
|
831
|
-
"Revoke " + (named?.name || "this access token") +
|
|
832
|
-
"? Its MCP client will immediately lose access."
|
|
833
|
-
)) return;
|
|
834
|
-
const generation = SESSION_GENERATION;
|
|
835
|
-
try {
|
|
836
|
-
const payload = await operatorRequest(
|
|
837
|
-
"/ui/access-tokens/" + encodeURIComponent(id),
|
|
838
|
-
"DELETE",
|
|
839
|
-
generation,
|
|
840
|
-
);
|
|
841
|
-
if (generation !== SESSION_GENERATION) return;
|
|
842
|
-
if (payload?.accessToken) {
|
|
843
|
-
ACCESS_TOKENS = ACCESS_TOKENS.map((token) =>
|
|
844
|
-
token.id === id ? payload.accessToken! : token);
|
|
845
|
-
}
|
|
846
|
-
setTokenNotice("Access token revoked.");
|
|
847
|
-
renderAccessTokens();
|
|
848
|
-
$("tokenNotice").focus();
|
|
849
|
-
} catch (error) {
|
|
850
|
-
if (generation !== SESSION_GENERATION) return;
|
|
851
|
-
setTokenNotice(errorMessage(
|
|
852
|
-
error,
|
|
853
|
-
"Access token could not be revoked.",
|
|
854
|
-
), true);
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
$("tokenList").onsubmit = async (event) => {
|
|
859
|
-
event.preventDefault();
|
|
860
|
-
const form = closestElement<HTMLFormElement>(event.target, "[data-token-form]");
|
|
861
|
-
if (!form) return;
|
|
862
|
-
const id = form.dataset.tokenForm;
|
|
863
|
-
const name = form.querySelector<HTMLInputElement>("input")?.value.trim();
|
|
864
|
-
if (!id || !name) return;
|
|
865
|
-
const generation = SESSION_GENERATION;
|
|
866
|
-
try {
|
|
867
|
-
const payload = await operatorRequest(
|
|
868
|
-
"/ui/access-tokens/" + encodeURIComponent(id),
|
|
869
|
-
"PUT",
|
|
870
|
-
generation,
|
|
871
|
-
{ name },
|
|
872
|
-
);
|
|
873
|
-
if (generation !== SESSION_GENERATION) return;
|
|
874
|
-
if (payload?.accessToken) {
|
|
875
|
-
ACCESS_TOKENS = ACCESS_TOKENS.map((token) =>
|
|
876
|
-
token.id === id ? payload.accessToken! : token);
|
|
877
|
-
}
|
|
878
|
-
setTokenNotice("Access token renamed.");
|
|
879
|
-
renderAccessTokens();
|
|
880
|
-
$("tokenNotice").focus();
|
|
881
|
-
} catch (error) {
|
|
882
|
-
if (generation !== SESSION_GENERATION) return;
|
|
883
|
-
setTokenNotice(errorMessage(
|
|
884
|
-
error,
|
|
885
|
-
"Access token could not be renamed.",
|
|
886
|
-
), true);
|
|
887
|
-
}
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
$("list").onclick = async (event) => {
|
|
891
|
-
const button = closestElement<HTMLButtonElement>(
|
|
892
|
-
event.target,
|
|
893
|
-
"[data-oauth-action]",
|
|
894
|
-
);
|
|
895
|
-
if (!button) return;
|
|
896
|
-
const connector = button.dataset.connector;
|
|
897
|
-
const action = button.dataset.oauthAction;
|
|
898
|
-
if (!connector || (action !== "disconnect" && action !== "reconnect")) return;
|
|
899
|
-
const generation = SESSION_GENERATION;
|
|
900
|
-
const question = action === "disconnect"
|
|
901
|
-
? "Disconnect OAuth for " + connector +
|
|
902
|
-
"? Stored credentials and any pending authorization will be removed."
|
|
903
|
-
: "Restart OAuth for " + connector +
|
|
904
|
-
"? Stored credentials and any pending authorization will be replaced.";
|
|
905
|
-
if (!window.confirm(question)) return;
|
|
906
|
-
|
|
907
|
-
setOauthNotice("");
|
|
908
|
-
const buttons = [...document.querySelectorAll<HTMLButtonElement>(
|
|
909
|
-
'[data-connector="' + CSS.escape(connector) + '"]'
|
|
910
|
-
)];
|
|
911
|
-
buttons.forEach((item) => { item.disabled = true; });
|
|
912
|
-
try {
|
|
913
|
-
const result = await operatorRequest(
|
|
914
|
-
"/ui/oauth/" + encodeURIComponent(connector),
|
|
915
|
-
action === "disconnect" ? "DELETE" : "POST",
|
|
916
|
-
generation,
|
|
917
|
-
);
|
|
918
|
-
if (generation !== SESSION_GENERATION) return;
|
|
919
|
-
await load();
|
|
920
|
-
if (generation !== SESSION_GENERATION) return;
|
|
921
|
-
setOauthNotice(
|
|
922
|
-
action === "disconnect"
|
|
923
|
-
? "OAuth disconnected. Restart authorization when you are ready to reconnect."
|
|
924
|
-
: result?.message ||
|
|
925
|
-
"Authorization restarted. Open the authorization link to reconnect.",
|
|
926
|
-
);
|
|
927
|
-
$("oauthNotice").focus();
|
|
928
|
-
} catch (error) {
|
|
929
|
-
if (generation !== SESSION_GENERATION) return;
|
|
930
|
-
// A reset can publish its durable epoch before best-effort physical cleanup
|
|
931
|
-
// reports failure. Refresh so stale tools/health/actions never survive that
|
|
932
|
-
// partial success, while preserving the original error for the operator.
|
|
933
|
-
try {
|
|
934
|
-
await load();
|
|
935
|
-
} catch {
|
|
936
|
-
// The mutation error is the actionable one; load() already owns its gate.
|
|
937
|
-
}
|
|
938
|
-
if (generation !== SESSION_GENERATION) return;
|
|
939
|
-
setOauthNotice(errorMessage(error, "OAuth action failed."), true);
|
|
940
|
-
$("oauthNotice").focus();
|
|
941
|
-
} finally {
|
|
942
|
-
if (generation === SESSION_GENERATION) {
|
|
943
|
-
buttons.forEach((item) => { item.disabled = false; });
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
|
-
|
|
948
|
-
function renderCredentials(): void {
|
|
949
|
-
const data = DATA;
|
|
950
|
-
if (!data) return;
|
|
951
|
-
const list = $("credentialList");
|
|
952
|
-
list.innerHTML = "";
|
|
953
|
-
if (data.credentialManagement !== "available") return;
|
|
954
|
-
for (const c of data.connectors) {
|
|
955
|
-
const cred = c.credential;
|
|
956
|
-
if (!cred) continue;
|
|
957
|
-
const configured = Boolean(cred.configured);
|
|
958
|
-
const removable = configured || Boolean(cred.removable);
|
|
959
|
-
const state = configured
|
|
960
|
-
? cred.fields?.length
|
|
961
|
-
? "configured"
|
|
962
|
-
: "configured · ••••" + esc(cred.lastFour || "")
|
|
963
|
-
: "not configured";
|
|
964
|
-
const updated = configured && cred.updatedAt
|
|
965
|
-
? " · updated " + esc(formatDate(cred.updatedAt))
|
|
966
|
-
: "";
|
|
967
|
-
const el = document.createElement("section");
|
|
968
|
-
el.className = "credential-card";
|
|
969
|
-
el.id = "credential-" + c.id;
|
|
970
|
-
el.setAttribute("aria-labelledby", "credential-title-" + c.id);
|
|
971
|
-
let body = '<div class="credential-head"><div class="connector-title">' +
|
|
972
|
-
'<span class="dot ' + (configured ? "ok" : "auth_required") +
|
|
973
|
-
'" aria-hidden="true"></span><h2 id="credential-title-' + esc(c.id) + '">' +
|
|
974
|
-
esc(c.title || c.id) + '</h2></div><span class="credential-state">' +
|
|
975
|
-
state + updated + "</span></div>";
|
|
976
|
-
body += '<p class="mono">' + esc(c.id) + " · " + esc(cred.label) + "</p>";
|
|
977
|
-
if (cred.description) {
|
|
978
|
-
body += '<p class="credential-copy meta">' + esc(cred.description) + "</p>";
|
|
979
|
-
}
|
|
980
|
-
if (cred.fields?.length) {
|
|
981
|
-
body += '<div class="credential-field-summary">';
|
|
982
|
-
for (const field of cred.fields) {
|
|
983
|
-
const fieldState = field.configured
|
|
984
|
-
? "configured · ••••" + esc(field.lastFour || "") +
|
|
985
|
-
(field.updatedAt ? " · updated " + esc(formatDate(field.updatedAt)) : "")
|
|
986
|
-
: "not configured";
|
|
987
|
-
body += '<div><span>' + esc(field.label) +
|
|
988
|
-
'</span><span class="meta">' + fieldState + "</span></div>";
|
|
989
|
-
}
|
|
990
|
-
body += "</div>";
|
|
991
|
-
}
|
|
992
|
-
if (cred.error) body += '<div class="msg">' + esc(cred.error) + "</div>";
|
|
993
|
-
// Leftover stored fields are not an error — the credential still works, so
|
|
994
|
-
// this stays muted copy rather than the msg block an actual failure earns.
|
|
995
|
-
if (cred.notice) {
|
|
996
|
-
body += '<p class="credential-copy meta">' + esc(cred.notice) + "</p>";
|
|
997
|
-
}
|
|
998
|
-
body += '<div class="credential-actions">';
|
|
999
|
-
body += '<button class="linklike" type="button" data-credential-action="edit" data-connector="' +
|
|
1000
|
-
esc(c.id) + '">' + (removable ? "Replace" : "Add credential") + "</button>";
|
|
1001
|
-
if (configured && cred.testable) {
|
|
1002
|
-
body += '<button class="linklike" type="button" data-credential-action="test" data-connector="' +
|
|
1003
|
-
esc(c.id) + '">Test</button>';
|
|
1004
|
-
}
|
|
1005
|
-
if (removable) {
|
|
1006
|
-
body += '<button type="button" class="linklike danger" data-credential-action="remove" data-connector="' +
|
|
1007
|
-
esc(c.id) + '">Remove</button>';
|
|
1008
|
-
}
|
|
1009
|
-
body += "</div>";
|
|
1010
|
-
body += '<div class="credential-form hidden" data-credential-form="' +
|
|
1011
|
-
esc(c.id) + '">';
|
|
1012
|
-
if (cred.fields && cred.fields.length) {
|
|
1013
|
-
body += '<div class="credential-fields">';
|
|
1014
|
-
for (const [index, field] of cred.fields.entries()) {
|
|
1015
|
-
const inputId = "credential-input-" + c.id + "-" + index;
|
|
1016
|
-
body += '<div class="credential-field"><label for="' + esc(inputId) + '">' +
|
|
1017
|
-
esc(field.label) + '</label><input id="' + esc(inputId) + '" type="' +
|
|
1018
|
-
esc(field.inputType || "password") + '" data-credential-field="' +
|
|
1019
|
-
esc(field.name) + '" placeholder="' + esc(field.placeholder || field.label) +
|
|
1020
|
-
'" autocomplete="' +
|
|
1021
|
-
(field.inputType === "password" ? "new-password" : "off") +
|
|
1022
|
-
'" autocapitalize="none" spellcheck="false"></div>';
|
|
1023
|
-
}
|
|
1024
|
-
body += "</div>";
|
|
1025
|
-
} else {
|
|
1026
|
-
const inputId = "credential-input-" + c.id;
|
|
1027
|
-
body += '<label class="visually-hidden" for="' + esc(inputId) + '">' +
|
|
1028
|
-
esc(cred.label) + '</label><input id="' + esc(inputId) +
|
|
1029
|
-
'" type="password" data-credential-input="' +
|
|
1030
|
-
esc(c.id) + '" aria-label="' + esc(cred.label) + '" placeholder="' +
|
|
1031
|
-
esc(cred.placeholder || "Paste credential") +
|
|
1032
|
-
'" autocomplete="new-password" autocapitalize="none" spellcheck="false">';
|
|
1033
|
-
}
|
|
1034
|
-
body += '<button class="linklike" type="button" data-credential-action="save" data-connector="' +
|
|
1035
|
-
esc(c.id) + '">Save</button><button class="linklike" type="button" data-credential-action="cancel" data-connector="' +
|
|
1036
|
-
esc(c.id) + '">Cancel</button></div>';
|
|
1037
|
-
el.innerHTML = body;
|
|
1038
|
-
list.appendChild(el);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
async function credentialRequest(
|
|
1043
|
-
connector: string,
|
|
1044
|
-
method: "DELETE" | "POST" | "PUT",
|
|
1045
|
-
action: "" | "test",
|
|
1046
|
-
body: { value: string } | { values: Record<string, string> } | null,
|
|
1047
|
-
generation: number,
|
|
1048
|
-
): Promise<UiActionResponse | null> {
|
|
1049
|
-
const suffix = action ? "/" + action : "";
|
|
1050
|
-
return operatorRequest(
|
|
1051
|
-
"/ui/credentials/" + encodeURIComponent(connector) + suffix,
|
|
1052
|
-
method,
|
|
1053
|
-
generation,
|
|
1054
|
-
body ?? undefined,
|
|
1055
|
-
);
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
function credentialForm(connector: string): HTMLElement {
|
|
1059
|
-
const form = document.querySelector<HTMLElement>(
|
|
1060
|
-
'[data-credential-form="' + CSS.escape(connector) + '"]',
|
|
1061
|
-
);
|
|
1062
|
-
if (!form) throw new Error("Credential form is unavailable.");
|
|
1063
|
-
return form;
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
$("credentialList").onclick = async (event) => {
|
|
1067
|
-
const button = closestElement<HTMLButtonElement>(
|
|
1068
|
-
event.target,
|
|
1069
|
-
"[data-credential-action]",
|
|
1070
|
-
);
|
|
1071
|
-
if (!button) return;
|
|
1072
|
-
const connector = button.dataset.connector;
|
|
1073
|
-
const action = button.dataset.credentialAction;
|
|
1074
|
-
if (!connector || !action) return;
|
|
1075
|
-
const form = credentialForm(connector);
|
|
1076
|
-
const generation = SESSION_GENERATION;
|
|
1077
|
-
|
|
1078
|
-
if (action === "edit") {
|
|
1079
|
-
form.classList.remove("hidden");
|
|
1080
|
-
form.querySelector("input")?.focus();
|
|
1081
|
-
return;
|
|
1082
|
-
}
|
|
1083
|
-
if (action === "cancel") {
|
|
1084
|
-
form.querySelectorAll("input").forEach((input) => { input.value = ""; });
|
|
1085
|
-
form.classList.add("hidden");
|
|
1086
|
-
document.querySelector<HTMLButtonElement>(
|
|
1087
|
-
'[data-credential-action="edit"][data-connector="' +
|
|
1088
|
-
CSS.escape(connector) + '"]'
|
|
1089
|
-
)?.focus();
|
|
1090
|
-
return;
|
|
1091
|
-
}
|
|
1092
|
-
if (action === "remove" && !window.confirm(
|
|
1093
|
-
"Remove this credential? The connector will stop authenticating until a replacement is added."
|
|
1094
|
-
)) return;
|
|
1095
|
-
|
|
1096
|
-
setNotice("");
|
|
1097
|
-
$("credentialList").setAttribute("aria-busy", "true");
|
|
1098
|
-
const buttons = [...document.querySelectorAll<HTMLButtonElement>(
|
|
1099
|
-
'[data-connector="' + CSS.escape(connector) + '"]'
|
|
1100
|
-
)];
|
|
1101
|
-
buttons.forEach((item) => { item.disabled = true; });
|
|
1102
|
-
try {
|
|
1103
|
-
if (action === "save") {
|
|
1104
|
-
const fieldInputs = [
|
|
1105
|
-
...form.querySelectorAll<HTMLInputElement>("[data-credential-field]"),
|
|
1106
|
-
];
|
|
1107
|
-
if (fieldInputs.length) {
|
|
1108
|
-
const values: Record<string, string> = {};
|
|
1109
|
-
for (const input of fieldInputs) {
|
|
1110
|
-
const value = input.value.trim();
|
|
1111
|
-
if (!value) throw new Error("Complete every credential field before saving.");
|
|
1112
|
-
const field = input.dataset.credentialField;
|
|
1113
|
-
if (!field) throw new Error("Credential field is unnamed.");
|
|
1114
|
-
values[field] = value;
|
|
1115
|
-
}
|
|
1116
|
-
await credentialRequest(connector, "PUT", "", { values }, generation);
|
|
1117
|
-
} else {
|
|
1118
|
-
const input = form.querySelector<HTMLInputElement>(
|
|
1119
|
-
"[data-credential-input]",
|
|
1120
|
-
);
|
|
1121
|
-
if (!input) throw new Error("Credential input is unavailable.");
|
|
1122
|
-
const value = input.value.trim();
|
|
1123
|
-
if (!value) throw new Error("Paste a credential before saving.");
|
|
1124
|
-
await credentialRequest(connector, "PUT", "", { value }, generation);
|
|
1125
|
-
}
|
|
1126
|
-
if (generation !== SESSION_GENERATION) return;
|
|
1127
|
-
form.querySelectorAll<HTMLInputElement>("input")
|
|
1128
|
-
.forEach((input) => { input.value = ""; });
|
|
1129
|
-
setNotice("Credential saved.");
|
|
1130
|
-
await load();
|
|
1131
|
-
if (generation !== SESSION_GENERATION) return;
|
|
1132
|
-
$("credentialNotice").focus();
|
|
1133
|
-
} else if (action === "remove") {
|
|
1134
|
-
await credentialRequest(connector, "DELETE", "", null, generation);
|
|
1135
|
-
if (generation !== SESSION_GENERATION) return;
|
|
1136
|
-
setNotice("Credential removed.");
|
|
1137
|
-
await load();
|
|
1138
|
-
if (generation !== SESSION_GENERATION) return;
|
|
1139
|
-
$("credentialNotice").focus();
|
|
1140
|
-
} else if (action === "test") {
|
|
1141
|
-
const result = await credentialRequest(
|
|
1142
|
-
connector,
|
|
1143
|
-
"POST",
|
|
1144
|
-
"test",
|
|
1145
|
-
null,
|
|
1146
|
-
generation,
|
|
1147
|
-
);
|
|
1148
|
-
if (generation !== SESSION_GENERATION) return;
|
|
1149
|
-
setNotice(
|
|
1150
|
-
result?.message ||
|
|
1151
|
-
(result?.ok ? "Credential is valid." : "Credential test failed."),
|
|
1152
|
-
!result?.ok,
|
|
1153
|
-
);
|
|
1154
|
-
}
|
|
1155
|
-
} catch (error) {
|
|
1156
|
-
if (generation !== SESSION_GENERATION) return;
|
|
1157
|
-
setNotice(errorMessage(error, "Credential action failed."), true);
|
|
1158
|
-
} finally {
|
|
1159
|
-
if (generation === SESSION_GENERATION) {
|
|
1160
|
-
$("credentialList").setAttribute("aria-busy", "false");
|
|
1161
|
-
buttons.forEach((item) => { item.disabled = false; });
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
};
|
|
1165
|
-
|
|
1166
|
-
$("save").onclick = async () => {
|
|
1167
|
-
const v = $("token").value.trim();
|
|
1168
|
-
if (!v) return;
|
|
1169
|
-
clearIdentityState();
|
|
1170
|
-
localStorage.setItem(KEY, v);
|
|
1171
|
-
$("token").value = "";
|
|
1172
|
-
await load();
|
|
1173
|
-
if (DATA) $(CURRENT_PAGE + "Heading").focus();
|
|
1174
|
-
};
|
|
1175
|
-
$("change").onclick = () => {
|
|
1176
|
-
localStorage.removeItem(KEY);
|
|
1177
|
-
showGate("");
|
|
1178
|
-
$("token").focus();
|
|
1179
|
-
};
|
|
1180
|
-
$("copyMcpUrl").onclick = async () => {
|
|
1181
|
-
const button = $("copyMcpUrl");
|
|
1182
|
-
try {
|
|
1183
|
-
await navigator.clipboard.writeText(MCP_URL);
|
|
1184
|
-
button.textContent = "Copied";
|
|
1185
|
-
} catch {
|
|
1186
|
-
button.textContent = "Copy failed";
|
|
1187
|
-
}
|
|
1188
|
-
window.setTimeout(() => { button.textContent = "Copy URL"; }, 1600);
|
|
1189
|
-
};
|
|
1190
|
-
$("signin").onclick = () => Clerk.redirectToSignIn({
|
|
1191
|
-
signInFallbackRedirectUrl: window.location.href,
|
|
1192
|
-
signUpFallbackRedirectUrl: window.location.href,
|
|
1193
|
-
});
|
|
1194
|
-
function signOut(): Promise<unknown> {
|
|
1195
|
-
clearIdentityState();
|
|
1196
|
-
return Clerk.signOut({ redirectUrl: window.location.href });
|
|
1197
|
-
}
|
|
1198
|
-
$("gateSignout").onclick = signOut;
|
|
1199
|
-
$("signout").onclick = signOut;
|
|
1200
|
-
$("filter").oninput = () => { if (DATA) renderConnections(); };
|
|
1201
|
-
$("refreshActivity").onclick = () => loadActivity(true);
|
|
1202
|
-
$("moreActivity").onclick = () => loadActivity(false);
|
|
1203
|
-
$("activitySearch").oninput = () => renderActivity();
|
|
1204
|
-
document.addEventListener("click", (event) => {
|
|
1205
|
-
const link = closestElement<HTMLAnchorElement>(
|
|
1206
|
-
event.target,
|
|
1207
|
-
"a[data-operator-page]",
|
|
1208
|
-
);
|
|
1209
|
-
if (
|
|
1210
|
-
!link ||
|
|
1211
|
-
event.defaultPrevented ||
|
|
1212
|
-
event.button !== 0 ||
|
|
1213
|
-
event.metaKey ||
|
|
1214
|
-
event.ctrlKey ||
|
|
1215
|
-
event.shiftKey ||
|
|
1216
|
-
event.altKey
|
|
1217
|
-
) return;
|
|
1218
|
-
const target = new URL(link.href, window.location.href);
|
|
1219
|
-
if (target.origin !== window.location.origin) return;
|
|
1220
|
-
const page = link.dataset.operatorPage;
|
|
1221
|
-
if (
|
|
1222
|
-
page !== "connections" &&
|
|
1223
|
-
page !== "credentials" &&
|
|
1224
|
-
page !== "tokens" &&
|
|
1225
|
-
page !== "activity"
|
|
1226
|
-
) return;
|
|
1227
|
-
event.preventDefault();
|
|
1228
|
-
navigateTo(page, target.pathname + target.search + target.hash);
|
|
1229
|
-
});
|
|
1230
|
-
window.addEventListener("popstate", () => {
|
|
1231
|
-
activatePage(pageForPath(window.location.pathname), { focus: true });
|
|
1232
|
-
});
|
|
1233
|
-
// A document restored from the back-forward cache must not restore a
|
|
1234
|
-
// one-time secret that was visible when the operator left the page.
|
|
1235
|
-
window.addEventListener("pagehide", clearCreatedAccessToken);
|
|
1236
|
-
|
|
1237
|
-
async function init(): Promise<void> {
|
|
1238
|
-
if (AUTH.kind === "clerk") {
|
|
1239
|
-
$("clerkGate").classList.remove("hidden");
|
|
1240
|
-
$("signout").classList.remove("hidden");
|
|
1241
|
-
try {
|
|
1242
|
-
if (!window.Clerk) {
|
|
1243
|
-
return showGate("Clerk could not load. Check your network and try again.");
|
|
1244
|
-
}
|
|
1245
|
-
await Clerk.load({
|
|
1246
|
-
...(AUTH.signInUrl ? { signInUrl: AUTH.signInUrl } : {}),
|
|
1247
|
-
...(AUTH.signUpUrl ? { signUpUrl: AUTH.signUpUrl } : {}),
|
|
1248
|
-
signInFallbackRedirectUrl: window.location.href,
|
|
1249
|
-
signUpFallbackRedirectUrl: window.location.href,
|
|
1250
|
-
afterSignOutUrl: window.location.href,
|
|
1251
|
-
});
|
|
1252
|
-
CLERK_SESSION_ID = Clerk.session?.id ?? null;
|
|
1253
|
-
Clerk.addListener((resources) => {
|
|
1254
|
-
const nextSessionId = resources.session?.id ?? null;
|
|
1255
|
-
if (nextSessionId === CLERK_SESSION_ID) return;
|
|
1256
|
-
CLERK_SESSION_ID = nextSessionId;
|
|
1257
|
-
// Clerk has already updated its public session before notifying
|
|
1258
|
-
// listeners. Clear synchronously so stale identity-scoped data cannot
|
|
1259
|
-
// be repainted while the replacement identity is being fetched.
|
|
1260
|
-
showGate("");
|
|
1261
|
-
void load();
|
|
1262
|
-
});
|
|
1263
|
-
} catch (error) {
|
|
1264
|
-
return showGate(
|
|
1265
|
-
"Clerk could not initialize: " +
|
|
1266
|
-
errorMessage(error, "unknown error"),
|
|
1267
|
-
);
|
|
1268
|
-
}
|
|
1269
|
-
} else {
|
|
1270
|
-
$("tokenGate").classList.remove("hidden");
|
|
1271
|
-
$("change").classList.remove("hidden");
|
|
1272
|
-
}
|
|
1273
|
-
activatePage(pageForPath(window.location.pathname));
|
|
1274
|
-
await load();
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
if (AUTH.kind === "clerk") {
|
|
1278
|
-
window.addEventListener("load", init);
|
|
1279
|
-
} else {
|
|
1280
|
-
init();
|
|
1281
|
-
}
|