hmcp-web 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +77 -0
- package/README.md +49 -2
- package/THIRD-PARTY-NOTICES.md +110 -0
- package/bin/hmcp-web.js +20 -0
- package/dist/api.d.ts +22 -0
- package/dist/api.js +1458 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +40 -0
- package/dist/contracts/onboarding.d.ts +233 -0
- package/dist/contracts/onboarding.js +1 -0
- package/dist/http.d.ts +72 -0
- package/dist/http.js +319 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/model/app-servers.d.ts +85 -0
- package/dist/model/app-servers.js +109 -0
- package/dist/model/console-settings.d.ts +37 -0
- package/dist/model/console-settings.js +74 -0
- package/dist/model/doctor.d.ts +68 -0
- package/dist/model/doctor.js +254 -0
- package/dist/model/fs-browse.d.ts +9 -0
- package/dist/model/fs-browse.js +184 -0
- package/dist/model/gateway-config.d.ts +287 -0
- package/dist/model/gateway-config.js +760 -0
- package/dist/model/import-record.d.ts +80 -0
- package/dist/model/import-record.js +179 -0
- package/dist/model/metrics.d.ts +65 -0
- package/dist/model/metrics.js +213 -0
- package/dist/model/oauth-flows.d.ts +60 -0
- package/dist/model/oauth-flows.js +79 -0
- package/dist/model/pipeline.d.ts +58 -0
- package/dist/model/pipeline.js +84 -0
- package/dist/model/probe.d.ts +155 -0
- package/dist/model/probe.js +385 -0
- package/dist/model/process.d.ts +100 -0
- package/dist/model/process.js +278 -0
- package/dist/model/protection.d.ts +378 -0
- package/dist/model/protection.js +470 -0
- package/dist/model/registry-cache.d.ts +59 -0
- package/dist/model/registry-cache.js +238 -0
- package/dist/model/scan.d.ts +48 -0
- package/dist/model/scan.js +59 -0
- package/dist/model/server.d.ts +127 -0
- package/dist/model/server.js +243 -0
- package/dist/model/tools.d.ts +61 -0
- package/dist/model/tools.js +72 -0
- package/dist/routes/catalog.d.ts +8 -0
- package/dist/routes/catalog.js +47 -0
- package/dist/routes/connect-import.d.ts +9 -0
- package/dist/routes/connect-import.js +594 -0
- package/dist/routes/connect.d.ts +50 -0
- package/dist/routes/connect.js +691 -0
- package/dist/routes/github.d.ts +97 -0
- package/dist/routes/github.js +587 -0
- package/dist/routes/guard.d.ts +3 -0
- package/dist/routes/guard.js +166 -0
- package/dist/routes/oauth.d.ts +55 -0
- package/dist/routes/oauth.js +406 -0
- package/dist/routes/policy.d.ts +34 -0
- package/dist/routes/policy.js +513 -0
- package/dist/routes/runtime.d.ts +12 -0
- package/dist/routes/runtime.js +921 -0
- package/dist/routes/servers-add.d.ts +32 -0
- package/dist/routes/servers-add.js +1091 -0
- package/dist/routes/system.d.ts +4 -0
- package/dist/routes/system.js +13 -0
- package/dist/start.d.ts +56 -0
- package/dist/start.js +164 -0
- package/dist-ui/assets/Activity-CZ78RyRO.js +1 -0
- package/dist-ui/assets/Approvals-DPIlNZsv.js +1 -0
- package/dist-ui/assets/AttachApp-DjSeWCbS.js +5 -0
- package/dist-ui/assets/Connections-qcA96lXh.js +2 -0
- package/dist-ui/assets/Gallery-DB_OO7Vw.js +17 -0
- package/dist-ui/assets/PreApprovals-C4cKajcK.js +1 -0
- package/dist-ui/assets/Protection-B8h-5YAb.js +1 -0
- package/dist-ui/assets/Safety-BQqHyYdo.js +1 -0
- package/dist-ui/assets/Settings-Cx50zZSt.js +1 -0
- package/dist-ui/assets/StartPage-CdX-v7ej.js +1 -0
- package/dist-ui/assets/Suggestions-CRo5UOTT.js +1 -0
- package/dist-ui/assets/Tools-xo39lPKB.js +4 -0
- package/dist-ui/assets/index-DttDjRpu.js +16 -0
- package/dist-ui/assets/index-QeJyD5z2.css +2 -0
- package/dist-ui/assets/kit-DRVm92_t.js +4 -0
- package/dist-ui/brand/logo-256.png +0 -0
- package/dist-ui/brand/logo-512.png +0 -0
- package/dist-ui/brand/logo.svg +6 -0
- package/dist-ui/brand/mark.svg +5 -0
- package/dist-ui/fonts/OFL.txt +99 -0
- package/dist-ui/fonts/README.md +21 -0
- package/dist-ui/fonts/jetbrainsmono-latin.woff2 +0 -0
- package/dist-ui/fonts/manrope-latin.woff2 +0 -0
- package/dist-ui/index.html +51 -0
- package/package.json +69 -6
- package/bin/notice.js +0 -7
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { ApprovalStore, NO_TENANT, expandPath, normalizeTenantKey, queryAuditLog, resolveTenant } from "hmcp-core";
|
|
4
|
+
import { loadGatewayConfig } from "hmcp-gateway";
|
|
5
|
+
function mtime(path) {
|
|
6
|
+
try {
|
|
7
|
+
return statSync(path).mtimeMs;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function loadServer(entry) {
|
|
14
|
+
const configPath = expandPath(entry.config_path);
|
|
15
|
+
if (!existsSync(configPath))
|
|
16
|
+
throw new Error(`no gateway config at ${configPath}`);
|
|
17
|
+
// Reuses the gateway's own loader, which already resolves an inline-or-path
|
|
18
|
+
// policy against the config's directory. Reimplementing that would be a
|
|
19
|
+
// second answer to the same question.
|
|
20
|
+
const gateway = loadGatewayConfig(configPath);
|
|
21
|
+
const cwd = dirname(configPath);
|
|
22
|
+
const inline = typeof gateway.config.policy !== "string";
|
|
23
|
+
const policyFile = inline ? null : expandPath(gateway.config.policy, cwd);
|
|
24
|
+
return {
|
|
25
|
+
entry,
|
|
26
|
+
cwd,
|
|
27
|
+
policy: gateway.policy,
|
|
28
|
+
policyPath: configPath,
|
|
29
|
+
policyFile,
|
|
30
|
+
policyWritable: policyWritable(gateway, policyFile),
|
|
31
|
+
policyOverrides: gateway.config.policy_overrides,
|
|
32
|
+
gateway,
|
|
33
|
+
component: entry.component ?? `gateway:${gateway.config.name}`,
|
|
34
|
+
auditPath: expandPath(gateway.policy.audit.path, cwd),
|
|
35
|
+
storePath: expandPath(gateway.policy.approvals.store_path, cwd),
|
|
36
|
+
...resolveTenantSafely(gateway.policy),
|
|
37
|
+
mtimes: { [configPath]: mtime(configPath) }
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Why a classification cannot be written for this server.
|
|
42
|
+
*
|
|
43
|
+
* Both reasons are about the file rather than about the person: an inline
|
|
44
|
+
* policy has nowhere to append to that a reload would pick up, and
|
|
45
|
+
* `policy_writes: false` is a deployment saying policy changes only with a
|
|
46
|
+
* deployment. The core writer refuses in both cases too -- this exists so the
|
|
47
|
+
* console can say which one it is before offering a control.
|
|
48
|
+
*/
|
|
49
|
+
function policyWritable(gateway, policyFile) {
|
|
50
|
+
if (policyFile === null) {
|
|
51
|
+
return {
|
|
52
|
+
ok: false,
|
|
53
|
+
why: "this gateway's policy is written inline in its gateway.yaml, which is deliberately not reloadable — " +
|
|
54
|
+
"the rest of that file configures child processes and transports an edit cannot touch. " +
|
|
55
|
+
"Move the policy into its own file to classify tools from here."
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (!gateway.config.policy_writes) {
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
why: "this gateway has `policy_writes: false`, so its policy only ever changes with a deployment. " +
|
|
62
|
+
"The rule to add is shown below, for a reviewed edit."
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (!gateway.config.policy_reload) {
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
why: "this gateway has `policy_reload: false`, so a rule written here takes effect when it next restarts " +
|
|
69
|
+
"rather than on its next call."
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { ok: true, why: null };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* `resolveTenant`, never `requireTenant`.
|
|
76
|
+
*
|
|
77
|
+
* `requireTenant` throws when the value is missing, which is right at server
|
|
78
|
+
* boot and wrong here: it would make the protection view unavailable for
|
|
79
|
+
* exactly the server whose configuration most needs inspecting. The failure is
|
|
80
|
+
* captured and rendered instead.
|
|
81
|
+
*/
|
|
82
|
+
function resolveTenantSafely(policy) {
|
|
83
|
+
if (!policy.tenant)
|
|
84
|
+
return { tenantValue: undefined, tenantError: null };
|
|
85
|
+
try {
|
|
86
|
+
const value = resolveTenant(policy.tenant);
|
|
87
|
+
if (value === undefined && policy.tenant.required) {
|
|
88
|
+
return {
|
|
89
|
+
tenantValue: undefined,
|
|
90
|
+
tenantError: `tenant scoping is required but no value resolved from ${describeTenantSource(policy)}. ` +
|
|
91
|
+
"This server would refuse to start in this environment."
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return { tenantValue: value, tenantError: null };
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
return { tenantValue: undefined, tenantError: err.message };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function describeTenantSource(policy) {
|
|
101
|
+
const tenant = policy.tenant;
|
|
102
|
+
if (!tenant)
|
|
103
|
+
return "no tenant configuration";
|
|
104
|
+
switch (tenant.source.kind) {
|
|
105
|
+
case "env":
|
|
106
|
+
return `the ${tenant.source.name} environment variable`;
|
|
107
|
+
case "header":
|
|
108
|
+
return `the ${tenant.source.name} request header`;
|
|
109
|
+
case "jwt-claim":
|
|
110
|
+
return `the ${tenant.source.name} claim of the token in ${tenant.source.token_env}`;
|
|
111
|
+
case "jwt-verified":
|
|
112
|
+
return `the verified ${tenant.source.claim} claim of the caller's token, issued by ${tenant.source.issuer}`;
|
|
113
|
+
case "static":
|
|
114
|
+
return "a fixed value in the policy";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* One approval store per server, kept for the process lifetime.
|
|
119
|
+
*
|
|
120
|
+
* Opening and closing per request would thrash the WAL. The store's own
|
|
121
|
+
* constructor already sets `journal_mode = WAL` and `busy_timeout = 5000`,
|
|
122
|
+
* which is what makes sharing the file with a running server safe, so nothing
|
|
123
|
+
* here opens a `DatabaseSync` directly.
|
|
124
|
+
*/
|
|
125
|
+
const stores = new Map();
|
|
126
|
+
export function storeFor(server) {
|
|
127
|
+
const existing = stores.get(server.storePath);
|
|
128
|
+
if (existing)
|
|
129
|
+
return existing;
|
|
130
|
+
const store = new ApprovalStore(server.storePath, server.cwd);
|
|
131
|
+
stores.set(server.storePath, store);
|
|
132
|
+
return store;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Settles the tenant for one request.
|
|
136
|
+
*
|
|
137
|
+
* Three cases, and they differ in whether the console can legitimately know
|
|
138
|
+
* the answer:
|
|
139
|
+
*
|
|
140
|
+
* - **No tenant configured.** The gateway scopes everything to `NO_TENANT`, so
|
|
141
|
+
* that is the only correct key and naming another one is a mistake worth
|
|
142
|
+
* refusing rather than honouring.
|
|
143
|
+
* - **`jwt-verified`.** Resolved per request from the caller's token. One
|
|
144
|
+
* gateway serves every tenant at once and the console's own environment says
|
|
145
|
+
* nothing about any of them, so the request has to name one.
|
|
146
|
+
* - **`static`, `env` or `jwt-claim`.** A property of the deployment, resolved
|
|
147
|
+
* once at startup, and the console reads it from the same place the gateway
|
|
148
|
+
* does. Defaulting is legitimate here — but an explicit value still wins, so
|
|
149
|
+
* an operator whose console environment differs from the gateway's can say
|
|
150
|
+
* so instead of being quietly wrong.
|
|
151
|
+
*/
|
|
152
|
+
export function chooseTenant(server, requested) {
|
|
153
|
+
const config = server.policy.tenant;
|
|
154
|
+
if (!config) {
|
|
155
|
+
if (requested !== null && requested !== NO_TENANT) {
|
|
156
|
+
return {
|
|
157
|
+
ok: false,
|
|
158
|
+
why: `"${server.entry.id}" has no tenant configured, so every row it writes is scoped to the empty ` +
|
|
159
|
+
`tenant. Asking for "${requested}" would read and write rows this gateway never touches.`
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return { ok: true, tenant: NO_TENANT, explicit: false };
|
|
163
|
+
}
|
|
164
|
+
if (requested !== null && requested !== "") {
|
|
165
|
+
try {
|
|
166
|
+
return { ok: true, tenant: normalizeTenantKey(requested), explicit: true };
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
return { ok: false, why: err.message };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (config.source.kind === "jwt-verified") {
|
|
173
|
+
return {
|
|
174
|
+
ok: false,
|
|
175
|
+
why: `"${server.entry.id}" resolves its tenant per request, from the verified "${config.source.claim}" ` +
|
|
176
|
+
`claim of the caller's token, so there is no single tenant for this console to assume. Name one ` +
|
|
177
|
+
`with ?tenant=<id>. Guessing would read an empty queue and write a switch the gateway never reads.`
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (server.tenantValue === undefined) {
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
why: server.tenantError ??
|
|
184
|
+
`"${server.entry.id}" requires a tenant and none resolved from ${describeTenantSource(server.policy)}. ` +
|
|
185
|
+
`Name one with ?tenant=<id>.`
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return { ok: true, tenant: server.tenantValue, explicit: false };
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The scope this gateway's rows live under in that store.
|
|
192
|
+
*
|
|
193
|
+
* The console reads a shared database — one file commonly holds rows for
|
|
194
|
+
* several gateways and several tenants — so every read it makes has to say
|
|
195
|
+
* whose rows it wants.
|
|
196
|
+
*/
|
|
197
|
+
export function scopeFor(server, tenant) {
|
|
198
|
+
return { component: server.component, tenant };
|
|
199
|
+
}
|
|
200
|
+
/** `storeFor` already narrowed to this gateway and one named tenant. */
|
|
201
|
+
export function scopedFor(server, tenant) {
|
|
202
|
+
return storeFor(server).scoped(scopeFor(server, tenant));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Which tenants this gateway has any trace of, so a selector can be offered
|
|
206
|
+
* rather than a free-text box with no hint in it.
|
|
207
|
+
*
|
|
208
|
+
* Two sources, because neither alone is complete. `listScopes` covers tenants
|
|
209
|
+
* with approvals, grants or exposure rows; the audit log covers one that has
|
|
210
|
+
* only ever made calls, which has rows in none of those three. Both are
|
|
211
|
+
* historical — a tenant that has never been seen will not appear, which is why
|
|
212
|
+
* naming one by hand stays possible.
|
|
213
|
+
*/
|
|
214
|
+
export function knownTenants(server, auditSample = 2000) {
|
|
215
|
+
const seen = new Set();
|
|
216
|
+
for (const scope of storeFor(server).listScopes()) {
|
|
217
|
+
if (scope.component === server.component)
|
|
218
|
+
seen.add(scope.tenant);
|
|
219
|
+
}
|
|
220
|
+
if (server.policy.audit.enabled) {
|
|
221
|
+
try {
|
|
222
|
+
for (const record of queryAuditLog(server.auditPath, { limit: auditSample }).records) {
|
|
223
|
+
if (record.component === server.component)
|
|
224
|
+
seen.add(record.tenant ?? NO_TENANT);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
/* a missing or unreadable log costs the hint, never the page */
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return [...seen].sort();
|
|
232
|
+
}
|
|
233
|
+
export function closeStores() {
|
|
234
|
+
for (const store of stores.values()) {
|
|
235
|
+
try {
|
|
236
|
+
store.close();
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
/* best effort on shutdown */
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
stores.clear();
|
|
243
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type ToolSurfaceEntry } from "hmcp-core";
|
|
2
|
+
import { type LoadedServer } from "./server.js";
|
|
3
|
+
/**
|
|
4
|
+
* A gateway's tool surface, as this console can know it.
|
|
5
|
+
*
|
|
6
|
+
* The console never speaks MCP to an upstream. It would have to spawn child
|
|
7
|
+
* processes and open sockets to do it, on a page load, for a surface the
|
|
8
|
+
* gateway has already discovered — so instead the gateway publishes what it is
|
|
9
|
+
* serving and this reads that.
|
|
10
|
+
*
|
|
11
|
+
* The consequence is that the surface has a *provenance*, which a file on disk
|
|
12
|
+
* did not: rows were written by some process at some time, and that process may
|
|
13
|
+
* be gone. Everything a reader needs to judge that is on this object rather
|
|
14
|
+
* than left for each caller to work out, because the failure that matters is
|
|
15
|
+
* silent — presenting a dead gateway's tool list as what is being served now.
|
|
16
|
+
*/
|
|
17
|
+
export interface ToolSurfaceView {
|
|
18
|
+
readonly entries: readonly ToolSurfaceEntry[];
|
|
19
|
+
/** A gateway process is announcing itself and these rows are its. */
|
|
20
|
+
readonly live: boolean;
|
|
21
|
+
/** Rows exist, but no live process claims them. */
|
|
22
|
+
readonly stale: boolean;
|
|
23
|
+
readonly publishedAt: number | null;
|
|
24
|
+
/** True when no gateway has ever published for this component. */
|
|
25
|
+
readonly neverPublished: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const EMPTY_SURFACE: ToolSurfaceView;
|
|
28
|
+
/**
|
|
29
|
+
* Reads the published inventory and narrows it by one tenant's exposure rows.
|
|
30
|
+
*
|
|
31
|
+
* The inventory itself is process-wide — every tenant of one gateway is offered
|
|
32
|
+
* the same upstream tools — so the tenant only ever subtracts here.
|
|
33
|
+
*
|
|
34
|
+
* Rows are trusted only when the live `runtime_state` row names the same pid
|
|
35
|
+
* that wrote them. Two gateways sharing a component — a dev and a staging
|
|
36
|
+
* process on one box, both on the default store path — otherwise overwrite each
|
|
37
|
+
* other, and a blend of two upstream sets is a surface nobody serves.
|
|
38
|
+
*/
|
|
39
|
+
export declare function toolSurfaceFor(server: LoadedServer, tenant: string): ToolSurfaceView;
|
|
40
|
+
/**
|
|
41
|
+
* Whether this console may author a change to the surface right now.
|
|
42
|
+
*
|
|
43
|
+
* A tool name read from a stale inventory is the one input that must not be
|
|
44
|
+
* trusted: writing an exposure row for a tool the running gateway does not
|
|
45
|
+
* serve produces a row that looks exactly like protection and guards nothing.
|
|
46
|
+
* The gateway's own admin API refuses this for the same reason, validating the
|
|
47
|
+
* name against live inventory before it writes.
|
|
48
|
+
*/
|
|
49
|
+
export declare function surfaceWritable(view: ToolSurfaceView, options?: {
|
|
50
|
+
allowStale?: boolean;
|
|
51
|
+
}): {
|
|
52
|
+
ok: true;
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
why: string;
|
|
56
|
+
};
|
|
57
|
+
/** The scope these entries were narrowed to, for a caller that has to say so. */
|
|
58
|
+
export declare function surfaceScope(server: LoadedServer, tenant: string): {
|
|
59
|
+
component: string;
|
|
60
|
+
tenant: string;
|
|
61
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { runtimeStateIsLive, toolSurface } from "hmcp-core";
|
|
2
|
+
import { scopedFor, scopeFor, storeFor } from "./server.js";
|
|
3
|
+
export const EMPTY_SURFACE = {
|
|
4
|
+
entries: [],
|
|
5
|
+
live: false,
|
|
6
|
+
stale: false,
|
|
7
|
+
publishedAt: null,
|
|
8
|
+
neverPublished: true
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Reads the published inventory and narrows it by one tenant's exposure rows.
|
|
12
|
+
*
|
|
13
|
+
* The inventory itself is process-wide — every tenant of one gateway is offered
|
|
14
|
+
* the same upstream tools — so the tenant only ever subtracts here.
|
|
15
|
+
*
|
|
16
|
+
* Rows are trusted only when the live `runtime_state` row names the same pid
|
|
17
|
+
* that wrote them. Two gateways sharing a component — a dev and a staging
|
|
18
|
+
* process on one box, both on the default store path — otherwise overwrite each
|
|
19
|
+
* other, and a blend of two upstream sets is a surface nobody serves.
|
|
20
|
+
*/
|
|
21
|
+
export function toolSurfaceFor(server, tenant) {
|
|
22
|
+
const store = storeFor(server);
|
|
23
|
+
const rows = store.inventory(server.component);
|
|
24
|
+
if (rows.length === 0)
|
|
25
|
+
return EMPTY_SURFACE;
|
|
26
|
+
const announced = store.runtimeState(server.component);
|
|
27
|
+
const live = announced !== undefined && runtimeStateIsLive(announced) && announced.pid === rows[0].pid;
|
|
28
|
+
const entries = toolSurface(rows, scopedFor(server, tenant).listDisabledTools());
|
|
29
|
+
return {
|
|
30
|
+
entries,
|
|
31
|
+
live,
|
|
32
|
+
stale: !live,
|
|
33
|
+
publishedAt: rows[0].discovered_at,
|
|
34
|
+
neverPublished: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether this console may author a change to the surface right now.
|
|
39
|
+
*
|
|
40
|
+
* A tool name read from a stale inventory is the one input that must not be
|
|
41
|
+
* trusted: writing an exposure row for a tool the running gateway does not
|
|
42
|
+
* serve produces a row that looks exactly like protection and guards nothing.
|
|
43
|
+
* The gateway's own admin API refuses this for the same reason, validating the
|
|
44
|
+
* name against live inventory before it writes.
|
|
45
|
+
*/
|
|
46
|
+
export function surfaceWritable(view, options = {}) {
|
|
47
|
+
if (view.neverPublished) {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
why: "no gateway has published a tool surface for this component yet. Start the gateway once so it " +
|
|
51
|
+
"can report what its upstreams offer, then this switch can name a tool that exists."
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/*
|
|
55
|
+
* A rule names a tool in the policy file and holds whether the list is
|
|
56
|
+
* current or not; switching a tool off is a row keyed to a tool that must
|
|
57
|
+
* exist now, so only it insists on a live list.
|
|
58
|
+
*/
|
|
59
|
+
if (!view.live && !options.allowStale) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
why: "no running gateway is announcing itself for this component, so the last published tool list " +
|
|
63
|
+
"cannot be confirmed as current. Switching a tool off against a stale list would write a row " +
|
|
64
|
+
"that looks like protection and guards nothing."
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return { ok: true };
|
|
68
|
+
}
|
|
69
|
+
/** The scope these entries were narrowed to, for a caller that has to say so. */
|
|
70
|
+
export function surfaceScope(server, tenant) {
|
|
71
|
+
return scopeFor(server, tenant);
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiOptions } from "../api.js";
|
|
2
|
+
import { type Route } from "../http.js";
|
|
3
|
+
import { RegistrySearch } from "../model/registry-cache.js";
|
|
4
|
+
export interface CatalogRouteDeps {
|
|
5
|
+
/** The public-list search; a test passes one pointed at a local stub. */
|
|
6
|
+
readonly registry?: RegistrySearch;
|
|
7
|
+
}
|
|
8
|
+
export declare function catalogRoutes(_options: ApiOptions, deps?: CatalogRouteDeps): Route[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalog, public-list search and pasted instructions. Workstream D.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here writes anything or holds a key: a draft carries field
|
|
5
|
+
* definitions, and a pasted key comes back only in `values` for the form the
|
|
6
|
+
* person is filling in (it was theirs a moment ago, in their own clipboard).
|
|
7
|
+
* It is written to the locked-keys file by install, never by these routes.
|
|
8
|
+
*/
|
|
9
|
+
import { catalogEntry, draftFromCatalog, loadCatalog, parseSnippet } from "hmcp-gateway";
|
|
10
|
+
import { badRequest, HttpError, notFound, route } from "../http.js";
|
|
11
|
+
import { registryEnabled } from "../model/console-settings.js";
|
|
12
|
+
import { RegistrySearch } from "../model/registry-cache.js";
|
|
13
|
+
/** The most text a paste may be: a README section, not a whole file. */
|
|
14
|
+
const MAX_PASTE = 64 * 1024;
|
|
15
|
+
let shared;
|
|
16
|
+
export function catalogRoutes(_options, deps = {}) {
|
|
17
|
+
const registry = () => deps.registry ?? (shared ??= new RegistrySearch());
|
|
18
|
+
return [
|
|
19
|
+
route("GET", "/api/v1/catalog", () => ({ entries: loadCatalog() })),
|
|
20
|
+
route("GET", "/api/v1/catalog/:id/draft", (ctx) => {
|
|
21
|
+
const entry = catalogEntry(ctx.params["id"]);
|
|
22
|
+
if (!entry)
|
|
23
|
+
throw notFound(`There is no server called "${ctx.params["id"]}" in the catalog.`);
|
|
24
|
+
const variant = ctx.query.get("variant") ?? undefined;
|
|
25
|
+
if (variant !== undefined && !entry.variants.some((v) => v.id === variant)) {
|
|
26
|
+
throw notFound(`"${entry.name}" has no option called "${variant}".`);
|
|
27
|
+
}
|
|
28
|
+
return { draft: draftFromCatalog(entry, variant) };
|
|
29
|
+
}),
|
|
30
|
+
route("GET", "/api/v1/registry/search", async (ctx) => {
|
|
31
|
+
if (!registryEnabled()) {
|
|
32
|
+
throw new HttpError(404, "registry-off", "Searching the public server list is switched off in Settings.");
|
|
33
|
+
}
|
|
34
|
+
const q = (ctx.query.get("q") ?? "").slice(0, 200);
|
|
35
|
+
const cursor = (ctx.query.get("cursor") ?? "").slice(0, 512) || null;
|
|
36
|
+
return registry().search(q, cursor);
|
|
37
|
+
}),
|
|
38
|
+
route("POST", "/api/v1/paste", (ctx) => {
|
|
39
|
+
const text = ctx.body?.text;
|
|
40
|
+
if (typeof text !== "string")
|
|
41
|
+
throw badRequest("Send the pasted text as { text }.");
|
|
42
|
+
if (text.length > MAX_PASTE)
|
|
43
|
+
throw badRequest("That is too much text. Paste only the part of the README that shows how to set the server up.");
|
|
44
|
+
return parseSnippet(text);
|
|
45
|
+
})
|
|
46
|
+
];
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApiOptions } from "../api.js";
|
|
2
|
+
import { type Route } from "../http.js";
|
|
3
|
+
/**
|
|
4
|
+
* Puts back what a refused import wrote, every step tried even when one
|
|
5
|
+
* before it fails: a gateway.yaml that can't be restored must not also leave
|
|
6
|
+
* the new keys behind. Returns what could not be put back, without keys.
|
|
7
|
+
*/
|
|
8
|
+
export declare function rollBack(steps: readonly (readonly [string, () => void])[], values: readonly string[]): string[];
|
|
9
|
+
export declare function connectImportRoutes(options: ApiOptions): Route[];
|