hmcp-web 0.2.2 → 0.2.3
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/dist/api.d.ts +6 -0
- package/dist/api.js +36 -8
- package/dist/model/app-connect-note.d.ts +114 -0
- package/dist/model/app-connect-note.js +199 -0
- package/dist/model/app-servers.d.ts +24 -1
- package/dist/model/app-servers.js +54 -6
- package/dist/model/apps.d.ts +24 -0
- package/dist/model/apps.js +18 -0
- package/dist/model/bring-in.d.ts +185 -0
- package/dist/model/bring-in.js +755 -0
- package/dist/model/console-settings.d.ts +2 -2
- package/dist/model/import-record.d.ts +4 -0
- package/dist/model/import-record.js +22 -1
- package/dist/model/new-toolbox.d.ts +84 -0
- package/dist/model/new-toolbox.js +209 -0
- package/dist/model/protection.d.ts +4 -1
- package/dist/model/protection.js +12 -9
- package/dist/model/provisional-tools.d.ts +56 -0
- package/dist/model/provisional-tools.js +145 -0
- package/dist/model/server-names.d.ts +25 -0
- package/dist/model/server-names.js +158 -0
- package/dist/model/toolbox-label.d.ts +22 -0
- package/dist/model/toolbox-label.js +42 -0
- package/dist/model/tools.d.ts +20 -5
- package/dist/model/tools.js +22 -11
- package/dist/routes/connect-app.d.ts +54 -0
- package/dist/routes/connect-app.js +1018 -0
- package/dist/routes/connect-import.d.ts +21 -6
- package/dist/routes/connect-import.js +162 -546
- package/dist/routes/connect.d.ts +11 -0
- package/dist/routes/connect.js +28 -116
- package/dist/routes/github.js +2 -1
- package/dist/routes/guard.js +4 -0
- package/dist/routes/runtime.js +21 -22
- package/dist/routes/servers-add.d.ts +1 -0
- package/dist/routes/servers-add.js +6 -5
- package/dist-ui/assets/Activity-BSf4lBm-.js +1 -0
- package/dist-ui/assets/Approvals-CDz3zYpl.js +1 -0
- package/dist-ui/assets/AttachApp-COr1547c.js +5 -0
- package/dist-ui/assets/Connections-ClW5R6ea.js +2 -0
- package/dist-ui/assets/{Gallery-DB_OO7Vw.js → Gallery-0iiv1H9e.js} +3 -3
- package/dist-ui/assets/{PreApprovals-C-2ZGYfc.js → PreApprovals-DYDKgSpr.js} +1 -1
- package/dist-ui/assets/Protection-DMtABpM7.js +1 -0
- package/dist-ui/assets/Safety-BLTF2fqV.js +1 -0
- package/dist-ui/assets/{Settings-CSyTOe8X.js → Settings-DZ4P3Us6.js} +1 -1
- package/dist-ui/assets/StartPage-Bke6mrv5.js +1 -0
- package/dist-ui/assets/{Suggestions-CaQ_ifWR.js → Suggestions-kAWUILyw.js} +1 -1
- package/dist-ui/assets/Tools-BdXSeKeL.js +4 -0
- package/dist-ui/assets/connect-app-words-CT8Fytzv.js +1 -0
- package/dist-ui/assets/index-Cm4wG2zz.js +16 -0
- package/dist-ui/assets/{kit-DRVm92_t.js → kit-BHB_ha4i.js} +1 -1
- package/dist-ui/assets/server-name-D9u6r07i.js +1 -0
- package/dist-ui/index.html +3 -2
- package/package.json +4 -4
- package/dist-ui/assets/Activity-CoVSFaRd.js +0 -1
- package/dist-ui/assets/Approvals-BSEDgiNu.js +0 -1
- package/dist-ui/assets/AttachApp-Cpm6DOaX.js +0 -5
- package/dist-ui/assets/Connections-D5Xd9vH8.js +0 -2
- package/dist-ui/assets/Protection-B4Ltb5iP.js +0 -1
- package/dist-ui/assets/Safety-CSQhoL9D.js +0 -1
- package/dist-ui/assets/StartPage-JBVzYXce.js +0 -1
- package/dist-ui/assets/Tools-CDl6irG1.js +0 -4
- package/dist-ui/assets/index-CTvq_isK.js +0 -16
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CatalogEntry, type Upstream } from "hmcp-gateway";
|
|
2
|
+
/** The catalog's name for this server, or null when it isn't one the catalog knows. */
|
|
3
|
+
export declare function catalogNameFor(upstream: Upstream, catalog: readonly CatalogEntry[]): string | null;
|
|
4
|
+
/**
|
|
5
|
+
* The name Claude Desktop shows for the extension this server was brought in
|
|
6
|
+
* from, or null when it isn't one.
|
|
7
|
+
*
|
|
8
|
+
* Bringing an extension in names its server after the manifest's short name
|
|
9
|
+
* (`dev_mode_mcp_server_dxt`) and starts it in the extension's own folder,
|
|
10
|
+
* `Claude Extensions/<id>/` in Claude Desktop's folder. A server started in
|
|
11
|
+
* exactly such a folder is that extension, so the manifest's `display_name`
|
|
12
|
+
* there is its name. Only the server's folder is looked at to find it --
|
|
13
|
+
* never its settings, arguments or keys -- and only the display name is read
|
|
14
|
+
* back, with control and formatting characters taken out and capped. A
|
|
15
|
+
* manifest that isn't a plain file, or is too large, is not read. Nothing is
|
|
16
|
+
* stored, so a toolbox filled before this is named the same way.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extensionNameFor(upstream: Upstream, extensionsDir: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* `{ id: name }` for the servers the catalog recognises, and for those
|
|
21
|
+
* brought in from a Claude Desktop extension; the others are left out. Never
|
|
22
|
+
* throws: a catalog that cannot be read means no catalog names, not a server
|
|
23
|
+
* list that fails to load.
|
|
24
|
+
*/
|
|
25
|
+
export declare function serverDisplayNames(upstreams: readonly Upstream[], catalog?: readonly CatalogEntry[], extensionsDir?: string | null): Record<string, string>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { desktopFolder, loadCatalog, MAX_EXTENSION_MANIFEST_BYTES, safeName } from "hmcp-gateway";
|
|
4
|
+
/*
|
|
5
|
+
* The name a person knows a connected server by, when it is one of ours.
|
|
6
|
+
*
|
|
7
|
+
* A server's id (`github`, `brave_search`, `fs_local`) is what the settings
|
|
8
|
+
* file and the tool names use. The console shows a person "GitHub" instead,
|
|
9
|
+
* and it can only say that truthfully for a server it recognises: the catalog
|
|
10
|
+
* is the one list of names we wrote ourselves. A server gets a catalog name
|
|
11
|
+
* only when what it runs matches one of that entry's options: the same
|
|
12
|
+
* package or container image, or the same web address. An id alone is never
|
|
13
|
+
* enough, or a server of anyone's making called `github` would be shown as
|
|
14
|
+
* GitHub's own. Anything else gets no name here (the console then makes the
|
|
15
|
+
* id readable on its own; see ui/src/lib/server-name.ts).
|
|
16
|
+
*
|
|
17
|
+
* Among the entries whose launch fits:
|
|
18
|
+
* 1. The one the id names. Adding a server from the catalog names it after
|
|
19
|
+
* the entry, with `_2`, `_3` for a second and third copy ("GitHub 2").
|
|
20
|
+
* 2. Otherwise, for a server brought in from an AI app's own settings under a
|
|
21
|
+
* name of its own, the only entry that fits. Two or more fitting means no
|
|
22
|
+
* name, so a guess never gives a server someone else's name.
|
|
23
|
+
*
|
|
24
|
+
* A server brought in from a Claude Desktop extension that the catalog does
|
|
25
|
+
* not know is named as Claude names the extension ("Figma"), from the
|
|
26
|
+
* extension's own manifest: see `extensionNameFor`.
|
|
27
|
+
*
|
|
28
|
+
* Read-only: nothing here changes what runs or what any rule matches.
|
|
29
|
+
*/
|
|
30
|
+
/** Lower-case, no query or fragment, no trailing slash: two spellings of one address compare equal. */
|
|
31
|
+
function normalUrl(url) {
|
|
32
|
+
return url.replace(/[?#].*$/, "").replace(/\/+$/, "").toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
/** A package or image name without its version: "@scope/pkg@1.2" → "@scope/pkg", "ghcr.io/x/y:latest" → "ghcr.io/x/y". */
|
|
35
|
+
function bare(arg) {
|
|
36
|
+
let s = arg;
|
|
37
|
+
const at = s.lastIndexOf("@");
|
|
38
|
+
if (at > 0)
|
|
39
|
+
s = s.slice(0, at);
|
|
40
|
+
const colon = s.lastIndexOf(":");
|
|
41
|
+
if (s.includes("/") && colon > s.lastIndexOf("/"))
|
|
42
|
+
s = s.slice(0, colon);
|
|
43
|
+
return s.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
/** The arguments that say which program this is (a package or an image), not how it is run. */
|
|
46
|
+
function distinctive(args) {
|
|
47
|
+
return args.filter((a) => !a.includes("{{") && !a.startsWith("-") && /[@/]|mcp/i.test(a)).map(bare);
|
|
48
|
+
}
|
|
49
|
+
function launchMatches(launch, upstream) {
|
|
50
|
+
if (launch.transport === "http") {
|
|
51
|
+
if (upstream.transport !== "http")
|
|
52
|
+
return false;
|
|
53
|
+
const cut = launch.url.indexOf("{{");
|
|
54
|
+
const have = normalUrl(upstream.url);
|
|
55
|
+
if (cut < 0)
|
|
56
|
+
return have === normalUrl(launch.url);
|
|
57
|
+
const prefix = normalUrl(launch.url.slice(0, cut));
|
|
58
|
+
// A template needs a fixed host and path before its first field to say anything.
|
|
59
|
+
return /^https?:\/\/[^/]+\/./.test(prefix) && have.startsWith(prefix);
|
|
60
|
+
}
|
|
61
|
+
if (upstream.transport !== "stdio")
|
|
62
|
+
return false;
|
|
63
|
+
const want = distinctive(launch.args ?? []);
|
|
64
|
+
if (want.length === 0)
|
|
65
|
+
return false;
|
|
66
|
+
const have = new Set(upstream.args.map(bare));
|
|
67
|
+
return want.every((w) => have.has(w));
|
|
68
|
+
}
|
|
69
|
+
/** The catalog's name for this server, or null when it isn't one the catalog knows. */
|
|
70
|
+
export function catalogNameFor(upstream, catalog) {
|
|
71
|
+
// What it runs always has to match: a server of one's own called `github` is not GitHub's.
|
|
72
|
+
const fits = catalog.filter((e) => e.variants.some((v) => launchMatches(v.launch, upstream)));
|
|
73
|
+
const exact = fits.find((e) => safeName(e.id) === upstream.name);
|
|
74
|
+
if (exact)
|
|
75
|
+
return exact.name;
|
|
76
|
+
const numbered = /^(.+)_(\d+)$/.exec(upstream.name);
|
|
77
|
+
const copy = numbered ? fits.find((e) => safeName(e.id) === numbered[1]) : undefined;
|
|
78
|
+
if (copy)
|
|
79
|
+
return `${copy.name} ${numbered[2]}`;
|
|
80
|
+
return fits.length === 1 ? fits[0].name : null;
|
|
81
|
+
}
|
|
82
|
+
/** Claude's id for an extension, which names its folder: plain characters only. */
|
|
83
|
+
const EXTENSION_ID = /^[A-Za-z0-9._-]+$/;
|
|
84
|
+
/** The longest extension name shown, in characters; a manifest is another program's file. */
|
|
85
|
+
const MAX_EXTENSION_NAME = 80;
|
|
86
|
+
/**
|
|
87
|
+
* The name Claude Desktop shows for the extension this server was brought in
|
|
88
|
+
* from, or null when it isn't one.
|
|
89
|
+
*
|
|
90
|
+
* Bringing an extension in names its server after the manifest's short name
|
|
91
|
+
* (`dev_mode_mcp_server_dxt`) and starts it in the extension's own folder,
|
|
92
|
+
* `Claude Extensions/<id>/` in Claude Desktop's folder. A server started in
|
|
93
|
+
* exactly such a folder is that extension, so the manifest's `display_name`
|
|
94
|
+
* there is its name. Only the server's folder is looked at to find it --
|
|
95
|
+
* never its settings, arguments or keys -- and only the display name is read
|
|
96
|
+
* back, with control and formatting characters taken out and capped. A
|
|
97
|
+
* manifest that isn't a plain file, or is too large, is not read. Nothing is
|
|
98
|
+
* stored, so a toolbox filled before this is named the same way.
|
|
99
|
+
*/
|
|
100
|
+
export function extensionNameFor(upstream, extensionsDir) {
|
|
101
|
+
if (upstream.transport !== "stdio" || upstream.cwd === undefined)
|
|
102
|
+
return null;
|
|
103
|
+
const dir = resolve(upstream.cwd);
|
|
104
|
+
if (dirname(dir) !== resolve(extensionsDir) || !EXTENSION_ID.test(basename(dir)))
|
|
105
|
+
return null;
|
|
106
|
+
let manifest;
|
|
107
|
+
try {
|
|
108
|
+
const path = join(dir, "manifest.json");
|
|
109
|
+
const stat = statSync(path);
|
|
110
|
+
if (!stat.isFile() || stat.size > MAX_EXTENSION_MANIFEST_BYTES)
|
|
111
|
+
return null;
|
|
112
|
+
manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const raw = typeof manifest === "object" && manifest !== null ? manifest.display_name : undefined;
|
|
118
|
+
if (typeof raw !== "string")
|
|
119
|
+
return null;
|
|
120
|
+
// Control and invisible formatting characters (line breaks, direction overrides) become spaces.
|
|
121
|
+
const flat = raw.replace(/[\p{Cc}\p{Cf}]+/gu, " ").replace(/\s+/g, " ").trim();
|
|
122
|
+
if (!flat)
|
|
123
|
+
return null;
|
|
124
|
+
// Cut by character, not by UTF-16 unit, so an emoji is never split in half.
|
|
125
|
+
const chars = Array.from(flat);
|
|
126
|
+
return chars.length > MAX_EXTENSION_NAME ? `${chars.slice(0, MAX_EXTENSION_NAME - 1).join("")}\u2026` : flat;
|
|
127
|
+
}
|
|
128
|
+
/** Where Claude Desktop keeps its extensions, or null when that can't be worked out. A path only: nothing is read. */
|
|
129
|
+
function defaultExtensionsDir() {
|
|
130
|
+
try {
|
|
131
|
+
return join(desktopFolder(), "Claude Extensions");
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* `{ id: name }` for the servers the catalog recognises, and for those
|
|
139
|
+
* brought in from a Claude Desktop extension; the others are left out. Never
|
|
140
|
+
* throws: a catalog that cannot be read means no catalog names, not a server
|
|
141
|
+
* list that fails to load.
|
|
142
|
+
*/
|
|
143
|
+
export function serverDisplayNames(upstreams, catalog, extensionsDir = defaultExtensionsDir()) {
|
|
144
|
+
let entries;
|
|
145
|
+
try {
|
|
146
|
+
entries = catalog ?? loadCatalog();
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
entries = [];
|
|
150
|
+
}
|
|
151
|
+
const out = {};
|
|
152
|
+
for (const u of upstreams) {
|
|
153
|
+
const name = catalogNameFor(u, entries) ?? (extensionsDir !== null ? extensionNameFor(u, extensionsDir) : null);
|
|
154
|
+
if (name)
|
|
155
|
+
out[u.name] = name;
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type RegistryEntry } from "hmcp-core";
|
|
2
|
+
/**
|
|
3
|
+
* The name a person reads for a toolbox when nobody typed one.
|
|
4
|
+
*
|
|
5
|
+
* A toolbox added from a settings file with the label left empty used to be
|
|
6
|
+
* titled with the file's full path, so a card read
|
|
7
|
+
* "/Users/…/gateways/main/gateway.yaml settings". The toolbox already has a
|
|
8
|
+
* name of its own, and its folder is usually named after it, so the title is
|
|
9
|
+
* taken from those and the path stays a detail.
|
|
10
|
+
*/
|
|
11
|
+
/** "work-tools" -> "Work tools", "main" -> "Main". */
|
|
12
|
+
export declare function nameInWords(name: string): string;
|
|
13
|
+
/** From the config's `name:` when it has one, else from the folder holding gateway.yaml. */
|
|
14
|
+
export declare function defaultToolboxLabel(configPath: string, configName?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The label to show for a registry entry.
|
|
17
|
+
*
|
|
18
|
+
* Entries saved before this fix hold their path as their label. They are
|
|
19
|
+
* shown under the derived name instead, without rewriting servers.json: the
|
|
20
|
+
* file stays exactly as it was, and a label someone typed is never replaced.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toolboxLabel(entry: RegistryEntry, configName?: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { basename, dirname } from "node:path";
|
|
2
|
+
import { expandPath } from "hmcp-core";
|
|
3
|
+
/**
|
|
4
|
+
* The name a person reads for a toolbox when nobody typed one.
|
|
5
|
+
*
|
|
6
|
+
* A toolbox added from a settings file with the label left empty used to be
|
|
7
|
+
* titled with the file's full path, so a card read
|
|
8
|
+
* "/Users/…/gateways/main/gateway.yaml settings". The toolbox already has a
|
|
9
|
+
* name of its own, and its folder is usually named after it, so the title is
|
|
10
|
+
* taken from those and the path stays a detail.
|
|
11
|
+
*/
|
|
12
|
+
/** "work-tools" -> "Work tools", "main" -> "Main". */
|
|
13
|
+
export function nameInWords(name) {
|
|
14
|
+
const t = name.replace(/[_-]+/g, " ").replace(/\s+/g, " ").trim();
|
|
15
|
+
return t ? t[0].toUpperCase() + t.slice(1) : "";
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* `hmcp-gateway` is what the gateway config schema fills in when `name:` is
|
|
19
|
+
* left out, so it says nothing about this toolbox; the folder says more.
|
|
20
|
+
*/
|
|
21
|
+
const SCHEMA_DEFAULT_NAME = "hmcp-gateway";
|
|
22
|
+
/** From the config's `name:` when it has one, else from the folder holding gateway.yaml. */
|
|
23
|
+
export function defaultToolboxLabel(configPath, configName) {
|
|
24
|
+
const own = configName && configName !== SCHEMA_DEFAULT_NAME ? nameInWords(configName) : "";
|
|
25
|
+
if (own)
|
|
26
|
+
return own;
|
|
27
|
+
// A leading dot is dropped so a folder like ".work" does not read as ". work".
|
|
28
|
+
return nameInWords(basename(dirname(expandPath(configPath))).replace(/^\.+/, "")) || "Toolbox";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The label to show for a registry entry.
|
|
32
|
+
*
|
|
33
|
+
* Entries saved before this fix hold their path as their label. They are
|
|
34
|
+
* shown under the derived name instead, without rewriting servers.json: the
|
|
35
|
+
* file stays exactly as it was, and a label someone typed is never replaced.
|
|
36
|
+
*/
|
|
37
|
+
export function toolboxLabel(entry, configName) {
|
|
38
|
+
const label = entry.label.trim();
|
|
39
|
+
if (label && label !== entry.config_path.trim())
|
|
40
|
+
return entry.label;
|
|
41
|
+
return defaultToolboxLabel(entry.config_path, configName);
|
|
42
|
+
}
|
package/dist/model/tools.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ToolSurfaceEntry } from "hmcp-core";
|
|
2
2
|
import { type LoadedServer } from "./server.js";
|
|
3
|
+
import { type ProvisionalTool } from "./provisional-tools.js";
|
|
3
4
|
/**
|
|
4
5
|
* A gateway's tool surface, as this console can know it.
|
|
5
6
|
*
|
|
@@ -23,6 +24,14 @@ export interface ToolSurfaceView {
|
|
|
23
24
|
readonly publishedAt: number | null;
|
|
24
25
|
/** True when no gateway has ever published for this component. */
|
|
25
26
|
readonly neverPublished: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* What the toolbox's servers offered when they were tested on the way in,
|
|
29
|
+
* shown read-only until the toolbox runs. Never part of `entries`, so no
|
|
30
|
+
* switch or rule can name a tool from it; empty once the toolbox is live,
|
|
31
|
+
* for any server changed since it was tested, and for a test older than
|
|
32
|
+
* the last list the toolbox published.
|
|
33
|
+
*/
|
|
34
|
+
readonly provisional: readonly ProvisionalTool[];
|
|
26
35
|
}
|
|
27
36
|
export declare const EMPTY_SURFACE: ToolSurfaceView;
|
|
28
37
|
/**
|
|
@@ -31,12 +40,18 @@ export declare const EMPTY_SURFACE: ToolSurfaceView;
|
|
|
31
40
|
* The inventory itself is process-wide — every tenant of one gateway is offered
|
|
32
41
|
* the same upstream tools — so the tenant only ever subtracts here.
|
|
33
42
|
*
|
|
34
|
-
* Rows are trusted only when the
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
43
|
+
* Rows are trusted only when the process that wrote them is still running.
|
|
44
|
+
* Two gateways sharing a component — a dev and a staging process on one box,
|
|
45
|
+
* both on the default store path — otherwise overwrite each other, and a blend
|
|
46
|
+
* of two upstream sets is a surface nobody serves.
|
|
47
|
+
*
|
|
48
|
+
* Any running process of the component will do, not only the one that wrote
|
|
49
|
+
* `runtime_state` last. An AI app that starts every server twice runs one
|
|
50
|
+
* toolbox as two processes, and when one reloads its policy it becomes the
|
|
51
|
+
* last writer while the other's list stays the one published: checking only
|
|
52
|
+
* the last writer showed a toolbox in use as one that had never run.
|
|
38
53
|
*/
|
|
39
|
-
export declare function toolSurfaceFor(server: LoadedServer, tenant: string): ToolSurfaceView;
|
|
54
|
+
export declare function toolSurfaceFor(server: LoadedServer, tenant: string, registryPath?: string): ToolSurfaceView;
|
|
40
55
|
/**
|
|
41
56
|
* Whether this console may author a change to the surface right now.
|
|
42
57
|
*
|
package/dist/model/tools.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toolSurface } from "hmcp-core";
|
|
2
2
|
import { scopedFor, scopeFor, storeFor } from "./server.js";
|
|
3
|
+
import { provisionalFor } from "./provisional-tools.js";
|
|
3
4
|
export const EMPTY_SURFACE = {
|
|
4
5
|
entries: [],
|
|
5
6
|
live: false,
|
|
6
7
|
stale: false,
|
|
7
8
|
publishedAt: null,
|
|
8
|
-
neverPublished: true
|
|
9
|
+
neverPublished: true,
|
|
10
|
+
provisional: []
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* Reads the published inventory and narrows it by one tenant's exposure rows.
|
|
@@ -13,25 +15,34 @@ export const EMPTY_SURFACE = {
|
|
|
13
15
|
* The inventory itself is process-wide — every tenant of one gateway is offered
|
|
14
16
|
* the same upstream tools — so the tenant only ever subtracts here.
|
|
15
17
|
*
|
|
16
|
-
* Rows are trusted only when the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Rows are trusted only when the process that wrote them is still running.
|
|
19
|
+
* Two gateways sharing a component — a dev and a staging process on one box,
|
|
20
|
+
* both on the default store path — otherwise overwrite each other, and a blend
|
|
21
|
+
* of two upstream sets is a surface nobody serves.
|
|
22
|
+
*
|
|
23
|
+
* Any running process of the component will do, not only the one that wrote
|
|
24
|
+
* `runtime_state` last. An AI app that starts every server twice runs one
|
|
25
|
+
* toolbox as two processes, and when one reloads its policy it becomes the
|
|
26
|
+
* last writer while the other's list stays the one published: checking only
|
|
27
|
+
* the last writer showed a toolbox in use as one that had never run.
|
|
20
28
|
*/
|
|
21
|
-
export function toolSurfaceFor(server, tenant) {
|
|
29
|
+
export function toolSurfaceFor(server, tenant, registryPath) {
|
|
22
30
|
const store = storeFor(server);
|
|
23
31
|
const rows = store.inventory(server.component);
|
|
32
|
+
// Read only where the caller names the console's list (the provisional lists live beside it).
|
|
33
|
+
const provisional = (live, publishedAt) => live || registryPath === undefined ? [] : provisionalFor(registryPath, server, publishedAt);
|
|
24
34
|
if (rows.length === 0)
|
|
25
|
-
return EMPTY_SURFACE;
|
|
26
|
-
const
|
|
27
|
-
const live =
|
|
35
|
+
return { ...EMPTY_SURFACE, provisional: provisional(false, null) };
|
|
36
|
+
const publisher = rows[0].pid;
|
|
37
|
+
const live = store.liveProcesses(server.component).some((p) => p.pid === publisher);
|
|
28
38
|
const entries = toolSurface(rows, scopedFor(server, tenant).listDisabledTools());
|
|
29
39
|
return {
|
|
30
40
|
entries,
|
|
31
41
|
live,
|
|
32
42
|
stale: !live,
|
|
33
43
|
publishedAt: rows[0].discovered_at,
|
|
34
|
-
neverPublished: false
|
|
44
|
+
neverPublished: false,
|
|
45
|
+
provisional: provisional(live, rows[0].discovered_at)
|
|
35
46
|
};
|
|
36
47
|
}
|
|
37
48
|
/**
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Upstream } from "hmcp-gateway";
|
|
2
|
+
import type { ApiOptions } from "../api.js";
|
|
3
|
+
import { type Route } from "../http.js";
|
|
4
|
+
import { type AppChoice } from "../model/apps.js";
|
|
5
|
+
import { type ConnectDeps } from "./connect.js";
|
|
6
|
+
/**
|
|
7
|
+
* "Connect your AI app" in one click: no project folder, no server set up by
|
|
8
|
+
* hand. The app's own servers are read, tested, and moved behind a toolbox,
|
|
9
|
+
* and the app is connected to that toolbox. Its Undo puts it all back.
|
|
10
|
+
*
|
|
11
|
+
* All the moving is `bringIn`'s (model/bring-in.ts), with its rules intact:
|
|
12
|
+
* every server is tested first, only the ones that connected move, and a
|
|
13
|
+
* refusal part-way puts every write back. This adds:
|
|
14
|
+
*
|
|
15
|
+
* - Nothing that loosens protection is done on the click alone. A server
|
|
16
|
+
* that would need an OK stays in the app, listed in `left` as "needs-ok".
|
|
17
|
+
* The one exception: the allow-list entry for a server's own HTTPS address
|
|
18
|
+
* on a plain DNS name, which the app already reaches. Those addresses are
|
|
19
|
+
* listed in the reply (`allowedHosts`) and written in the activity log.
|
|
20
|
+
* - An app's servers never go into a toolbox the person didn't choose. One
|
|
21
|
+
* is used without asking only when the app is already connected to it, or
|
|
22
|
+
* when a one-click connect made it and every server in it is this app's
|
|
23
|
+
* own or one this app already has. Any other toolbox must be named in the
|
|
24
|
+
* request, as the page showed it. With no toolbox at all, one is made.
|
|
25
|
+
* - A toolbox that already lets servers reach the local network accepts no
|
|
26
|
+
* new address on a click: a public-looking name may lead somewhere private.
|
|
27
|
+
* - A note of what this did (model/app-connect-note.ts), so Undo takes back
|
|
28
|
+
* exactly that and nothing a person did by hand.
|
|
29
|
+
* - What each server offered when tested (model/provisional-tools.ts), so its
|
|
30
|
+
* tools can be shown before the app has started the toolbox.
|
|
31
|
+
*
|
|
32
|
+
* Names only go back to the browser, as with Bring in servers.
|
|
33
|
+
*/
|
|
34
|
+
export interface ConnectAppDeps extends ConnectDeps {
|
|
35
|
+
/** Whether the app looks open right now: advice only, never a reason to refuse. Null when it can't be told. */
|
|
36
|
+
readonly running?: (app: AppChoice) => Promise<boolean | null>;
|
|
37
|
+
}
|
|
38
|
+
/** Where the older "Undo connection" button is, named the same way on the page and here. */
|
|
39
|
+
export declare const OLDER_UNDO = "\"Undo connection\" under Advanced in Connect your AI app";
|
|
40
|
+
/** `pgrep -x`: advice only, so any failure is "can't tell". */
|
|
41
|
+
export declare function pgrepRunning(app: AppChoice): Promise<boolean | null>;
|
|
42
|
+
/**
|
|
43
|
+
* The allow-list entry (`host` or `host:port`) for a server reached over
|
|
44
|
+
* HTTPS at a plain public DNS name, or null for anything else: another
|
|
45
|
+
* protocol, a wildcard or odd host (`*.example.com`, also when written
|
|
46
|
+
* `%2a`), a bare IPv4 or IPv6 address, localhost, a `.local` name, or one the
|
|
47
|
+
* app's settings place on the local network.
|
|
48
|
+
*/
|
|
49
|
+
export declare function plainHttpsEntry(upstream: Upstream, needsLocalHttp?: boolean): string | null;
|
|
50
|
+
/** The one loosening a click may carry: that entry on the allow-list, and the POST its protocol needs. */
|
|
51
|
+
export declare function ownHttpsAddress(line: string, upstream: Upstream, server?: {
|
|
52
|
+
readonly needsLocalHttp: boolean;
|
|
53
|
+
}): boolean;
|
|
54
|
+
export declare function connectAppRoutes(options: ApiOptions, deps?: ConnectAppDeps): Route[];
|