hmcp-web 0.2.1 → 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 +21 -1
- package/dist/model/protection.js +68 -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-CXcU-_ug.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-XjNZ-wo-.js → Settings-DZ4P3Us6.js} +1 -1
- package/dist-ui/assets/StartPage-Bke6mrv5.js +1 -0
- package/dist-ui/assets/{Suggestions-HZyd0jDU.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-Dgo5oK2r.js +0 -1
- package/dist-ui/assets/Approvals-C5_8rBkL.js +0 -1
- package/dist-ui/assets/AttachApp-BRW1mJ7X.js +0 -5
- package/dist-ui/assets/Connections-BHsXRdYI.js +0 -2
- package/dist-ui/assets/Protection-BF5OlzGC.js +0 -1
- package/dist-ui/assets/Safety-DVb8sdbt.js +0 -1
- package/dist-ui/assets/StartPage-D8WBBhDy.js +0 -1
- package/dist-ui/assets/Tools-GMaKxxIG.js +0 -4
- package/dist-ui/assets/index-DbHZ_SUd.js +0 -16
package/dist/routes/connect.d.ts
CHANGED
|
@@ -47,4 +47,15 @@ export declare function projectDirOf(raw: string | null | undefined): string;
|
|
|
47
47
|
export declare function gatewayAudit(configPath: string, actor: string): AuditLog | null;
|
|
48
48
|
/** Appends one record, and turns a failure into a warning: the change itself already happened. */
|
|
49
49
|
export declare function record(log: AuditLog | null, entry: Parameters<AuditLog["appendStrict"]>[0]): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Drops a project scope that is the very file of an all-projects scope: with
|
|
52
|
+
* the project folder at the home folder, "Cursor — this project" and "Cursor —
|
|
53
|
+
* all projects" are both `~/.cursor/mcp.json`, and offering both would act
|
|
54
|
+
* twice on one file. Claude Code's "local" lives inside `~/.claude.json` by
|
|
55
|
+
* design and is not a duplicate.
|
|
56
|
+
*/
|
|
57
|
+
export declare function withoutSameFile<T extends {
|
|
58
|
+
scope: Scope;
|
|
59
|
+
path: string;
|
|
60
|
+
}>(clients: readonly T[]): T[];
|
|
50
61
|
export declare function connectRoutes(options: ApiOptions, deps?: ConnectDeps): Route[];
|
package/dist/routes/connect.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { existsSync,
|
|
1
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
-
import { stringify } from "yaml";
|
|
5
4
|
import { z } from "zod";
|
|
6
|
-
import { AuditLog,
|
|
7
|
-
import { AdoptCommandError, AdoptRefusedError, ClientConfigError, codexHomeNote, UpstreamSchema, adoptApply, adoptPlan, adoptRevert, connectClient, detectClients,
|
|
8
|
-
import { appServersFor } from "../model/app-servers.js";
|
|
5
|
+
import { AuditLog, expandPath, readRegistry } from "hmcp-core";
|
|
6
|
+
import { AdoptCommandError, AdoptRefusedError, ClientConfigError, codexHomeNote, UpstreamSchema, adoptApply, adoptPlan, adoptRevert, connectClient, detectClients, loadGatewayConfig, readBackup, resolveScope } from "hmcp-gateway";
|
|
7
|
+
import { appServersFor, recordedToolbox } from "../model/app-servers.js";
|
|
9
8
|
import { deleteImportRecord, readImportRecord } from "../model/import-record.js";
|
|
9
|
+
import { dropNotesForApp } from "../model/app-connect-note.js";
|
|
10
|
+
import { localLoosens, planNewToolbox, writeNewToolbox } from "../model/new-toolbox.js";
|
|
10
11
|
import { badRequest, conflict, HttpError, route, unprocessable } from "../http.js";
|
|
11
12
|
/**
|
|
12
13
|
* Connecting the AI apps a person already uses: `hmcp-gateway adopt`, from
|
|
@@ -313,6 +314,10 @@ export function gatewayAudit(configPath, actor) {
|
|
|
313
314
|
return null;
|
|
314
315
|
}
|
|
315
316
|
}
|
|
317
|
+
/** A registry row's gateway.yaml as a full path (`~` expanded), or undefined for no row. */
|
|
318
|
+
function configOf(row) {
|
|
319
|
+
return row ? resolve(expandPath(row.config_path)) : undefined;
|
|
320
|
+
}
|
|
316
321
|
/** Appends one record, and turns a failure into a warning: the change itself already happened. */
|
|
317
322
|
export function record(log, entry) {
|
|
318
323
|
if (!log)
|
|
@@ -325,31 +330,6 @@ export function record(log, entry) {
|
|
|
325
330
|
return `the change was made but the activity log record failed: ${err.message}`;
|
|
326
331
|
}
|
|
327
332
|
}
|
|
328
|
-
function uniqueId(base, taken) {
|
|
329
|
-
let candidate = base;
|
|
330
|
-
for (let n = 2; taken.has(candidate); n++)
|
|
331
|
-
candidate = `${base}-${n}`.slice(0, 64);
|
|
332
|
-
return candidate;
|
|
333
|
-
}
|
|
334
|
-
/** Drops the keys `UpstreamSchema` filled with nothing, so the file says only what was chosen. */
|
|
335
|
-
function prune(upstream) {
|
|
336
|
-
const out = {};
|
|
337
|
-
for (const [key, value] of Object.entries(upstream)) {
|
|
338
|
-
if (Array.isArray(value) && value.length === 0)
|
|
339
|
-
continue;
|
|
340
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)
|
|
341
|
-
continue;
|
|
342
|
-
if (key === "credential_passthrough" && value.enabled === false)
|
|
343
|
-
continue;
|
|
344
|
-
out[key] = value;
|
|
345
|
-
}
|
|
346
|
-
return out;
|
|
347
|
-
}
|
|
348
|
-
/** Whether a value in env or headers is written as itself rather than as a locked-key reference. */
|
|
349
|
-
function hasLiteral(upstream) {
|
|
350
|
-
const values = Object.values(upstream.transport === "stdio" ? upstream.env : upstream.headers);
|
|
351
|
-
return values.some((v) => typeof v === "string");
|
|
352
|
-
}
|
|
353
333
|
/** A path with every existing folder on it resolved, so one file is always spelled one way. */
|
|
354
334
|
function realPath(path) {
|
|
355
335
|
try {
|
|
@@ -371,7 +351,7 @@ function realPath(path) {
|
|
|
371
351
|
* twice on one file. Claude Code's "local" lives inside `~/.claude.json` by
|
|
372
352
|
* design and is not a duplicate.
|
|
373
353
|
*/
|
|
374
|
-
function withoutSameFile(clients) {
|
|
354
|
+
export function withoutSameFile(clients) {
|
|
375
355
|
const shared = new Set(clients.filter((c) => !PROJECT_SCOPES.has(c.scope)).map((c) => realPath(c.path)));
|
|
376
356
|
return clients.filter((c) => c.scope === "local" || !PROJECT_SCOPES.has(c.scope) || !shared.has(realPath(c.path)));
|
|
377
357
|
}
|
|
@@ -460,11 +440,9 @@ export function connectRoutes(options, deps = {}) {
|
|
|
460
440
|
}
|
|
461
441
|
// Opened before reverting, because purging deletes the config that names the log.
|
|
462
442
|
const backup = readBackup(resolveScope(body.scope, { cwd }));
|
|
463
|
-
// A connection made with attach generated nothing; its gateway is found by its console row.
|
|
443
|
+
// A connection made with attach generated nothing; its gateway is found by its console row (or, its id gone, the one the app runs).
|
|
464
444
|
const generatedConfig = backup?.generated.find((p) => p.endsWith("gateway.yaml")) ??
|
|
465
|
-
(backup
|
|
466
|
-
? readRegistry(options.registryPath).servers.find((s) => s.id === backup.registry_id)?.config_path
|
|
467
|
-
: undefined);
|
|
445
|
+
(backup ? configOf(recordedToolbox(backup, options.registryPath, { scope: body.scope, cwd, home: homedir() })) : undefined);
|
|
468
446
|
const log = generatedConfig ? gatewayAudit(generatedConfig, ctx.actor) : null;
|
|
469
447
|
const target = resolveScope(body.scope, { cwd });
|
|
470
448
|
const imported = readImportRecord(options.registryPath, target);
|
|
@@ -483,6 +461,8 @@ export function connectRoutes(options, deps = {}) {
|
|
|
483
461
|
* app for its Undo to put back.
|
|
484
462
|
*/
|
|
485
463
|
deleteImportRecord(options.registryPath, target);
|
|
464
|
+
// A one-click note about this connection goes with it, so its Undo can't act on a connection that is gone.
|
|
465
|
+
dropNotesForApp(options.registryPath, target);
|
|
486
466
|
const importedKept = (imported?.items ?? []).filter((i) => i.added).map((i) => i.upstream);
|
|
487
467
|
const warning = record(log, {
|
|
488
468
|
tool: "(connect)",
|
|
@@ -586,90 +566,22 @@ export function connectRoutes(options, deps = {}) {
|
|
|
586
566
|
const twice = names.find((n, i) => names.indexOf(n) !== i);
|
|
587
567
|
if (twice)
|
|
588
568
|
throw unprocessable(`two connected servers are both called "${twice}"`);
|
|
589
|
-
const
|
|
590
|
-
const configPath = join(dir, "gateway.yaml");
|
|
591
|
-
const policyPath = join(dir, "policy.yaml");
|
|
592
|
-
for (const path of [configPath, policyPath]) {
|
|
593
|
-
if (existsSync(path))
|
|
594
|
-
throw conflict(`${path} already exists; choose another name or folder`);
|
|
595
|
-
}
|
|
596
|
-
const reg = readRegistry(options.registryPath);
|
|
597
|
-
const taken = new Set(reg.servers.map((s) => s.id));
|
|
598
|
-
if (body.id && taken.has(body.id))
|
|
599
|
-
throw conflict(`a server with id "${body.id}" is already registered`);
|
|
600
|
-
const id = body.id ?? uniqueId(body.name, taken);
|
|
601
|
-
// A `{ secret }` reference is a name, not a value, so only literals earn the warning.
|
|
602
|
-
const literals = upstreams.some(hasLiteral);
|
|
603
|
-
const hosts = upstreams.flatMap((u) => (u.transport === "http" ? [new URL(u.url).hostname] : []));
|
|
604
|
-
/*
|
|
605
|
-
* A server on this computer or the local network is reachable only with
|
|
606
|
-
* the private-address protections off, for every HTTP server of this
|
|
607
|
-
* gateway. That is a loosening, so it is confirmed like any other.
|
|
608
|
-
*/
|
|
609
|
-
const local = hosts.filter((h) => isLocalTarget(h));
|
|
610
|
-
if (local.length > 0 && !body.acknowledged?.loosens) {
|
|
611
|
-
throw unprocessable(`a server is on this computer or the local network (${[...new Set(local)].join(", ")}), which needs the ` +
|
|
612
|
-
`protection against reaching private addresses switched off for this toolbox`, {
|
|
613
|
-
needs: "loosens",
|
|
614
|
-
loosens: [
|
|
615
|
-
`allow connections to this computer and the local network (${[...new Set(local)].join(", ")})`,
|
|
616
|
-
"allow plain http:// and bare IP addresses"
|
|
617
|
-
]
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
const plan = {
|
|
621
|
-
upstreams: upstreams.map((upstream) => ({ upstream, originalName: upstream.name, warnings: [] })),
|
|
622
|
-
skipped: [],
|
|
623
|
-
gatewayEnv: {},
|
|
624
|
-
egressAllow: [...new Set(hosts)].sort(),
|
|
625
|
-
egressNeedsLocalHttp: local.length > 0,
|
|
626
|
-
secretsOnDisk: literals,
|
|
627
|
-
nameMap: new Map(),
|
|
628
|
-
malformed: []
|
|
629
|
-
};
|
|
630
|
-
const gatewayYaml = [
|
|
631
|
-
"# Created in the hardened-mcp console. policy.yaml beside this file decides",
|
|
632
|
-
"# what each tool may do.",
|
|
633
|
-
...(literals
|
|
634
|
-
? ["#", "# A value set in env or headers below is stored here as written. If it is a", "# credential, do not share or commit this file."]
|
|
635
|
-
: []),
|
|
636
|
-
"",
|
|
637
|
-
stringify({ version: 1, name: body.name, policy: "./policy.yaml", upstreams: upstreams.map(prune), on_injection: "strip", namespace: true }, { lineWidth: 0 })
|
|
638
|
-
].join("\n");
|
|
639
|
-
const policyYaml = emitPolicyYaml(plan, {
|
|
569
|
+
const plan = planNewToolbox({
|
|
640
570
|
name: body.name,
|
|
571
|
+
upstreams,
|
|
641
572
|
posture: body.posture,
|
|
642
|
-
|
|
643
|
-
onUnclassified: body.onUnclassified
|
|
644
|
-
|
|
645
|
-
.
|
|
646
|
-
.
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
writeFileSync(policyPath, policyYaml, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
653
|
-
loadGatewayConfig(configPath);
|
|
654
|
-
}
|
|
655
|
-
catch (err) {
|
|
656
|
-
for (const path of [configPath, policyPath])
|
|
657
|
-
if (existsSync(path))
|
|
658
|
-
unlinkSync(path);
|
|
659
|
-
if (createdDir)
|
|
660
|
-
rmSync(dir, { recursive: true, force: true });
|
|
661
|
-
if (err.code === "EEXIST")
|
|
662
|
-
throw conflict(`${err.message}; nothing was written`);
|
|
663
|
-
throw unprocessable(`the gateway could not be written: ${err.message}`);
|
|
573
|
+
mode: body.mode,
|
|
574
|
+
onUnclassified: body.onUnclassified,
|
|
575
|
+
...(body.outDir ? { dir: plainDirectory(body.outDir, "outDir", false) } : {}),
|
|
576
|
+
...(body.id ? { id: body.id } : {}),
|
|
577
|
+
...(body.label ? { label: body.label } : {})
|
|
578
|
+
}, options.registryPath);
|
|
579
|
+
const { local, literals, id, configPath, policyPath } = plan;
|
|
580
|
+
if (local.length > 0 && !body.acknowledged?.loosens) {
|
|
581
|
+
throw unprocessable(`a server is on this computer or the local network (${local.join(", ")}), which needs the ` +
|
|
582
|
+
`protection against reaching private addresses switched off for this toolbox`, { needs: "loosens", loosens: localLoosens(local) });
|
|
664
583
|
}
|
|
665
|
-
|
|
666
|
-
id,
|
|
667
|
-
kind: "gateway",
|
|
668
|
-
label: body.label ?? body.name,
|
|
669
|
-
config_path: configPath,
|
|
670
|
-
added_at: new Date().toISOString()
|
|
671
|
-
};
|
|
672
|
-
writeRegistry({ ...reg, servers: [...reg.servers, entry] }, options.registryPath);
|
|
584
|
+
writeNewToolbox(plan, options.registryPath);
|
|
673
585
|
const warning = record(gatewayAudit(configPath, ctx.actor), {
|
|
674
586
|
tool: "(connect)",
|
|
675
587
|
effect: null,
|
package/dist/routes/github.js
CHANGED
|
@@ -9,6 +9,7 @@ import { applyPolicyChanges, commitGatewayText, readGatewayFile, sameExcept } fr
|
|
|
9
9
|
import { packRulesFor, runProbe, scratchPolicy, withProbeSlot } from "../model/probe.js";
|
|
10
10
|
import { loadServer, scopedFor, storeFor } from "../model/server.js";
|
|
11
11
|
import { gatewayAudit, projectDirOf, record } from "./connect.js";
|
|
12
|
+
import { toolboxLabel } from "../model/toolbox-label.js";
|
|
12
13
|
/** The same test "Test it" runs: this toolbox's policy with the server's address allowed, the real locked keys. */
|
|
13
14
|
const defaultProbe = (spec, server) => withProbeSlot(() => runProbe(spec, { policy: scratchPolicy(server.policy, spec, false), secrets: new SecretStore(), cwd: server.cwd }));
|
|
14
15
|
const ClaudeCodeBody = z
|
|
@@ -145,7 +146,7 @@ function githubServers(options) {
|
|
|
145
146
|
continue;
|
|
146
147
|
out.push({
|
|
147
148
|
gatewayId: entry.id,
|
|
148
|
-
gatewayLabel: entry.
|
|
149
|
+
gatewayLabel: toolboxLabel(entry, file.config.name),
|
|
149
150
|
configPath,
|
|
150
151
|
upstream: u.name,
|
|
151
152
|
access: githubHostedAccess(u),
|
package/dist/routes/guard.js
CHANGED
|
@@ -4,6 +4,7 @@ import { existsSync, statSync } from "node:fs";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { AuditLog, expandPath, readRegistry } from "hmcp-core";
|
|
6
6
|
import { GuardInstallError, guardStatus, installGuard, loadGatewayConfig, uninstallGuard } from "hmcp-gateway";
|
|
7
|
+
import { dropGuardFromNotes } from "../model/app-connect-note.js";
|
|
7
8
|
import { badRequest, route, unprocessable } from "../http.js";
|
|
8
9
|
/**
|
|
9
10
|
* "Guard every Claude Code tool with hmcp": the guard's hooks in Claude
|
|
@@ -125,6 +126,9 @@ export function guardRoutes(options) {
|
|
|
125
126
|
}
|
|
126
127
|
const before = guardStatus(where);
|
|
127
128
|
const result = uninstallGuard(where);
|
|
129
|
+
// A one-click connect that turned it on must not turn it off again later.
|
|
130
|
+
if (result.removed > 0)
|
|
131
|
+
dropGuardFromNotes(options.registryPath, result.settingsPath);
|
|
128
132
|
const warning = result.removed > 0 && before.configPath
|
|
129
133
|
? note(auditFor(before.configPath, ctx.actor), {
|
|
130
134
|
tool: "(guard)",
|
package/dist/routes/runtime.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFileSync, statSync } from "node:fs";
|
|
|
2
2
|
import { writeAtomically } from "hmcp-core";
|
|
3
3
|
import { parseDocument } from "yaml";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { AuditLog, PIN_ACCEPT_RULE, contractDigest, describeContractChange, expandPath, readRegistry
|
|
5
|
+
import { AuditLog, PIN_ACCEPT_RULE, contractDigest, describeContractChange, expandPath, readRegistry } from "hmcp-core";
|
|
6
6
|
import { UpstreamSchema } from "hmcp-gateway";
|
|
7
7
|
import { HttpError, conflict, notFound, route, unprocessable } from "../http.js";
|
|
8
8
|
import { loadServer, storeFor } from "../model/server.js";
|
|
@@ -60,9 +60,13 @@ function parseBody(schema, body) {
|
|
|
60
60
|
}
|
|
61
61
|
return parsed.data;
|
|
62
62
|
}
|
|
63
|
+
/** The announced row, only while the process that wrote it is still running (see `liveRuntimeState`). */
|
|
63
64
|
function liveRuntime(server) {
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
return storeFor(server).liveRuntimeState(server.component);
|
|
66
|
+
}
|
|
67
|
+
/** Every running process of this server, by the shared judgement (`liveProcesses`). */
|
|
68
|
+
function livePids(server) {
|
|
69
|
+
return new Set(storeFor(server).liveProcesses(server.component).map((p) => p.pid));
|
|
66
70
|
}
|
|
67
71
|
const Acknowledged = z.object({ loosens: z.boolean().optional() }).strict();
|
|
68
72
|
/* -------------------------------------------------------------- tool changes */
|
|
@@ -129,19 +133,20 @@ function acceptChange(server, row, actor) {
|
|
|
129
133
|
return null;
|
|
130
134
|
}
|
|
131
135
|
/**
|
|
132
|
-
* The changes a reviewer may act on: published by
|
|
133
|
-
*
|
|
134
|
-
* the next process to start re-checks every pin and
|
|
136
|
+
* The changes a reviewer may act on: published by a process that is running
|
|
137
|
+
* now, whichever of its processes announced last. A dead gateway's list is
|
|
138
|
+
* shown but not acted on -- the next process to start re-checks every pin and
|
|
139
|
+
* may find something else.
|
|
135
140
|
*/
|
|
136
141
|
function actionableChanges(server) {
|
|
137
|
-
const live =
|
|
138
|
-
if (
|
|
142
|
+
const live = livePids(server);
|
|
143
|
+
if (live.size === 0) {
|
|
139
144
|
throw unprocessable("no running gateway is announcing itself for this server, so there is no current list of changed tools " +
|
|
140
145
|
"to accept. Start the gateway, then review what it reports.");
|
|
141
146
|
}
|
|
142
147
|
return storeFor(server)
|
|
143
148
|
.toolChanges(server.component)
|
|
144
|
-
.filter((row) => row.pid
|
|
149
|
+
.filter((row) => live.has(row.pid));
|
|
145
150
|
}
|
|
146
151
|
/* ------------------------------------------------------------ gateway config */
|
|
147
152
|
/**
|
|
@@ -397,20 +402,14 @@ function joinWarnings(warning, plan) {
|
|
|
397
402
|
* gateway, so when a second AI app (or a second session of one) starts the
|
|
398
403
|
* same toolbox and then exits, the row names a dead process while the first
|
|
399
404
|
* one is still serving. The live-state table has a row per process, each with
|
|
400
|
-
* its own heartbeat, so it still sees the first.
|
|
401
|
-
* to say "running", and to refuse to start
|
|
405
|
+
* its own heartbeat, so it still sees the first. `liveProcesses` reads both,
|
|
406
|
+
* and any process it finds is enough to say "running", and to refuse to start
|
|
407
|
+
* another copy beside it.
|
|
402
408
|
*/
|
|
403
409
|
function externalPids(options, id) {
|
|
404
410
|
try {
|
|
405
411
|
const server = loadServer(entryById(options, id));
|
|
406
|
-
|
|
407
|
-
const live = liveRuntime(server);
|
|
408
|
-
if (live && processes.isForeign(live.pid))
|
|
409
|
-
pids.add(live.pid);
|
|
410
|
-
for (const row of liveRows(storeFor(server), server.component))
|
|
411
|
-
if (processes.isForeign(row.pid))
|
|
412
|
-
pids.add(row.pid);
|
|
413
|
-
return [...pids].sort((a, b) => a - b);
|
|
412
|
+
return [...livePids(server)].filter((pid) => processes.isForeign(pid)).sort((a, b) => a - b);
|
|
414
413
|
}
|
|
415
414
|
catch {
|
|
416
415
|
return [];
|
|
@@ -513,11 +512,11 @@ export function runtimeRoutes(options) {
|
|
|
513
512
|
/* changed tools */
|
|
514
513
|
route("GET", "/api/v1/servers/:id/tool-changes", (ctx) => {
|
|
515
514
|
const server = serverById(options, ctx.params["id"]);
|
|
516
|
-
const live =
|
|
515
|
+
const live = livePids(server);
|
|
517
516
|
const store = storeFor(server);
|
|
518
517
|
const rows = store.toolChanges(server.component);
|
|
519
518
|
return {
|
|
520
|
-
live: live
|
|
519
|
+
live: live.size > 0,
|
|
521
520
|
onToolChange: server.policy.on_tool_change,
|
|
522
521
|
/*
|
|
523
522
|
* Rows from a process that is no longer announcing itself are still
|
|
@@ -525,7 +524,7 @@ export function runtimeRoutes(options) {
|
|
|
525
524
|
* pins that are still waiting. They cannot be accepted until a gateway
|
|
526
525
|
* re-checks them.
|
|
527
526
|
*/
|
|
528
|
-
changed: rows.filter((r) =>
|
|
527
|
+
changed: rows.filter((r) => live.size === 0 || live.has(r.pid)).map(changeDto),
|
|
529
528
|
pins: store.listPins(server.component)
|
|
530
529
|
};
|
|
531
530
|
}),
|
|
@@ -18,6 +18,7 @@ import { type Route } from "../http.js";
|
|
|
18
18
|
*/
|
|
19
19
|
/** The toolbox made for someone who has none yet. */
|
|
20
20
|
export declare const DEFAULT_GATEWAY_ID = "main";
|
|
21
|
+
export declare const DEFAULT_GATEWAY_LABEL = "My toolbox";
|
|
21
22
|
/** Drops the keys `UpstreamSchema` filled with nothing, so the file says only what was chosen. */
|
|
22
23
|
export declare function upstreamYaml(upstream: Upstream): Record<string, unknown>;
|
|
23
24
|
/** Which registered toolboxes use which locked keys. Broken files are skipped. */
|
|
@@ -4,7 +4,7 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { parseDocument, stringify } from "yaml";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
import { AuditLog, SECRET_NAME, SecretStore, expandPath, isSecretRef, parsePolicy, policyDigest, readRegistry,
|
|
7
|
+
import { AuditLog, SECRET_NAME, SecretStore, expandPath, isSecretRef, parsePolicy, policyDigest, readRegistry, writeAtomically, writeRegistry } from "hmcp-core";
|
|
8
8
|
import { UpstreamSchema, catalogCheck, catalogEntry, detectClients, emitPolicyYaml, loadGatewayConfig, materializeDraft } from "hmcp-gateway";
|
|
9
9
|
import { HttpError, conflict, notFound, respond, route, unprocessable } from "../http.js";
|
|
10
10
|
import { loadServer, storeFor } from "../model/server.js";
|
|
@@ -30,7 +30,7 @@ import { consoleOAuthFetch } from "./oauth.js";
|
|
|
30
30
|
*/
|
|
31
31
|
/** The toolbox made for someone who has none yet. */
|
|
32
32
|
export const DEFAULT_GATEWAY_ID = "main";
|
|
33
|
-
const DEFAULT_GATEWAY_LABEL = "My toolbox";
|
|
33
|
+
export const DEFAULT_GATEWAY_LABEL = "My toolbox";
|
|
34
34
|
/* ------------------------------------------------------------------ helpers */
|
|
35
35
|
function entryById(options, id) {
|
|
36
36
|
return readRegistry(options.registryPath).servers.find((s) => s.id === id);
|
|
@@ -333,8 +333,8 @@ function mergeUpstreams(rows) {
|
|
|
333
333
|
function gatewayRunning(options, id, server) {
|
|
334
334
|
if (processes.isActive(id))
|
|
335
335
|
return true;
|
|
336
|
-
|
|
337
|
-
return
|
|
336
|
+
// The shared judgement, so a toolbox that just exited is not "running".
|
|
337
|
+
return storeFor(server).liveProcesses(server.component).length > 0;
|
|
338
338
|
}
|
|
339
339
|
/* ------------------------------------------------------------- request bodies */
|
|
340
340
|
/** The draft is workstream D's shape; checked here only as far as this route relies on it. */
|
|
@@ -871,7 +871,8 @@ export function serversAddRoutes(options) {
|
|
|
871
871
|
heartbeat_at: r.heartbeat_at
|
|
872
872
|
})),
|
|
873
873
|
applied: rows.some((r) => r.config_digest === digest),
|
|
874
|
-
|
|
874
|
+
// The same judgement `status` and the tool list make, so the pages agree.
|
|
875
|
+
running: storeFor(server).liveProcesses(server.component).length > 0
|
|
875
876
|
};
|
|
876
877
|
}),
|
|
877
878
|
route("POST", "/api/v1/servers/:id/upstreams/:name/retry", (ctx) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$ as e,B as t,Ct as n,E as r,Et as i,G as a,H as o,I as s,It as c,M as l,O as u,Ot as d,P as f,Pt as p,R as m,S as h,St as g,U as _,V as v,Z as y,_ as b,bt as x,c as ee,d as S,dt as C,et as w,gt as T,ht as E,k as D,kt as O,lt as k,ot as te,pt as ne,s as re,tt as ie,ut as A,w as ae,wt as oe,x as j,y as M,yt as N,z as P}from"./kit-BHB_ha4i.js";import{At as F,Ct as I,Dt as se,Et as ce,Mt as L,Ot as R,St as z,Tt as le,_t as ue,bt as B,gn as V,gt as de,hn as H,jt as fe,kt as U,pn as pe,s as W,vt as G,wt as K,xt as q,yt as me}from"./index-Cm4wG2zz.js";var J=c(),Y=O();function he({open:e,onClose:n,serverId:i}){let s=M(),[c,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),[ee,S]=(0,J.useState)(!1),C=()=>{h(!0),f(null),p.verify(i).then(u).catch(e=>f(e.message)).finally(()=>h(!1))};(0,J.useEffect)(()=>{e&&(u(null),y(null),x(null),C())},[e,i]);let w=g.trim().toLowerCase(),D=/^[0-9a-f]{16,128}$/.test(w),O=()=>{D&&(S(!0),x(null),p.verify(i,w).then(e=>y({head:w,result:e})).catch(e=>x(e.message)).finally(()=>S(!1)))},k=async e=>{let t=await q(e);s.show(t?`ok`:`bad`,t?`Fingerprint copied`:`The browser did not allow copying`)};return(0,Y.jsx)(j,{open:e,onClose:n,title:`Check log integrity`,description:`Reads every entry in the activity log and checks that each still matches its fingerprint.`,width:600,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`ghost`,icon:`refresh`,onClick:C,loading:m,children:`Check again`}),(0,Y.jsx)(E,{variant:`primary`,onClick:n,children:`Close`})]}),children:(0,Y.jsxs)(`div`,{className:`space-y-5 pb-1 text-[14px]`,children:[d&&(0,Y.jsx)(o,{tone:`danger`,title:`The check could not run`,actions:(0,Y.jsx)(E,{size:`sm`,onClick:C,children:`Try again`}),children:d}),!c&&!d&&(0,Y.jsx)(a,{lines:3,height:18}),c&&(0,Y.jsxs)(Y.Fragment,{children:[c.ok?(0,Y.jsx)(o,{tone:`ok`,role:`status`,title:`All ${P(c.count)} entries are intact`,children:`No entry has been edited, removed or put out of order.`}):(0,Y.jsxs)(o,{tone:`danger`,role:`alert`,title:`${t(c.problems.length,`problem`)} found in ${t(c.count,`entry`,`entries`)}`,children:[(0,Y.jsx)(`ul`,{className:`mt-1 space-y-1`,children:c.problems.slice(0,8).map(e=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsxs)(`span`,{className:`font-semibold`,children:[`Entry `,e.line,`:`]}),` `,ge(e.message),` `,(0,Y.jsxs)(`span`,{className:`mono text-[11.5px] opacity-80`,children:[`(`,e.message,`)`]})]},`${e.line}-${e.message}`))}),c.problems.length>8&&(0,Y.jsxs)(`p`,{className:`mt-1`,children:[`And `,c.problems.length-8,` more.`]})]}),c.head?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`mb-1.5 text-[13px] font-semibold`,children:`Fingerprint of the latest entry`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded-2xl bg-sunken py-2 pr-2 pl-4`,children:[(0,Y.jsx)(`code`,{className:`mono min-w-0 flex-1 text-[12px] break-all`,children:c.head}),(0,Y.jsx)(T,{icon:`copy`,label:`Copy fingerprint`,variant:`soft`,size:36,onClick:()=>k(c.head)})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-[13px] text-soft`,children:`Save this somewhere the toolbox cannot reach, such as a note or a ticket. The check above catches an entry that was edited or removed, but not the newest entries being cut off the end, because what is left still checks out. A fingerprint you saved earlier can prove nothing was cut.`})]}):(0,Y.jsx)(`p`,{className:`text-soft`,children:`The log has no entries yet, so there is no fingerprint to save.`}),(0,Y.jsxs)(`div`,{className:`border-t border-faint pt-5`,children:[(0,Y.jsx)(r,{label:`Compare with a fingerprint you saved earlier`,help:`Paste the fingerprint exactly as you saved it.`,error:g.trim()&&!D?`That does not look like a fingerprint. It is a long run of letters a–f and digits.`:null,children:(0,Y.jsx)(l,{value:g,onChange:_,mono:!0,onEnter:O,placeholder:`e.g. 3f9a…`})}),(0,Y.jsx)(`div`,{className:`mt-3`,children:(0,Y.jsx)(E,{onClick:O,disabled:!D,loading:ee,icon:`search`,children:`Compare fingerprint`})}),b&&(0,Y.jsx)(`p`,{role:`alert`,className:`mt-3 text-[13px] font-medium text-bad`,children:b}),v&&(0,Y.jsx)(`div`,{className:`mt-4`,children:v.result.headPosition===void 0?(0,Y.jsx)(o,{tone:`danger`,role:`alert`,title:`Not found in this log`,children:`The log may have been cut short or replaced, or the fingerprint came from a different toolbox's log. Treat this as something to look into.`}):(0,Y.jsxs)(o,{tone:`ok`,role:`status`,title:`Found at entry ${P(v.result.headPosition+1)} of ${P(v.result.count)}`,children:[`Everything up to that entry is still in the log, so nothing written before you saved the fingerprint was lost.`,` `,v.result.count-v.result.headPosition-1>0?`${t(v.result.count-v.result.headPosition-1,`entry has`,`entries have`)} been added since.`:`No entries have been added since.`]})})]})]})]})})}function ge(e){return/^record altered/.test(e)?`This entry was changed after it was written.`:/^sequence gap/.test(e)?`An entry before this one was removed, or entries were put out of order.`:/^chain break/.test(e)?`This entry doesn't follow on from the one before it: something was removed or put in between.`:/^unparseable JSON/.test(e)?`This entry can't be read; the file was edited or cut short.`:e}function _e({record:t,onClose:r,nav:a,redaction:o}){let c=M(),l=H(),u=V();if(!t)return null;let p=t,g=K(p,l,u),_=p.rule_id===`gateway.unknown-tool`,v=_?null:L(p),x=te[p.outcome]?.tone??`neutral`;return(0,Y.jsx)(h,{open:!0,onClose:r,title:g?g.title:(0,Y.jsxs)(Y.Fragment,{children:[B(p),` `,(0,Y.jsx)(`span`,{className:`mono text-[17px]`,children:p.tool})]}),subtitle:`Entry ${P(p.seq)} · ${s(p.ts)}`,width:620,footer:(0,Y.jsx)(E,{icon:`copy`,onClick:async()=>{let e=await q(`${location.origin}${i(a,{seq:String(p.seq)})}`);c.show(e?`ok`:`bad`,e?`Link to this entry copied`:`The browser did not allow copying`)},children:`Copy link to entry`}),children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[_?(0,Y.jsx)(e,{tone:`warn`,children:`No such tool: your AI app asked for a tool this toolbox doesn't have`}):(0,Y.jsx)(w,{decision:p.decision}),!_&&C(p.outcome)!==k(p.decision)&&(0,Y.jsx)(e,{tone:x,children:R(p)?`You said no`:C(p.outcome)}),p.grant_id&&(0,Y.jsx)(e,{icon:`key`,children:`Released by a pre-approval`})]}),v&&(0,Y.jsxs)(`p`,{className:`flex gap-2 rounded-2xl bg-warn-tint px-4 py-3 text-[14px] text-ink`,children:[(0,Y.jsx)(d,{name:`eye`,size:18,className:`mt-0.5 shrink-0 text-warn`}),(0,Y.jsxs)(`span`,{children:[v,`. `,(0,Y.jsx)(b,{term:`watchOnly`})]})]}),(0,Y.jsxs)(X,{title:`What happened`,children:[(0,Y.jsx)(Z,{label:`Tool`,children:(0,Y.jsx)(`span`,{className:`mono text-[13px] break-all`,children:p.tool})}),(0,Y.jsx)(Z,{label:`What the tool does`,children:p.effect?(0,Y.jsx)(y,{effect:p.effect,withLabel:!0}):(0,Y.jsx)($,{children:A(null)})}),(0,Y.jsxs)(Z,{label:`Decided by`,children:[I(p),` `,(0,Y.jsx)(Q,{children:p.rule_id})]}),(0,Y.jsx)(Z,{label:`Reason`,children:p.reason||(0,Y.jsx)($,{children:`None recorded`})}),(0,Y.jsx)(Z,{label:`Took`,children:p.duration_ms===null?(0,Y.jsx)($,{children:`Not timed`}):m(p.duration_ms)}),p.error&&(0,Y.jsx)(Z,{label:`Error`,children:(0,Y.jsx)(`span`,{className:`text-bad`,children:p.error})})]}),(0,Y.jsxs)(X,{title:`Who asked`,children:[(0,Y.jsx)(Z,{label:`Asked by`,children:(0,Y.jsx)(`span`,{className:`break-all`,children:p.actor})}),G(p.client)&&(0,Y.jsxs)(Z,{label:`App (as it reports itself)`,children:[(0,Y.jsx)(`span`,{className:`block overflow-hidden break-all`,children:G(p.client)}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-[12.5px] text-soft`,children:`The name the app gave when it connected. Any app can give any name, so it is not checked.`})]}),(0,Y.jsx)(Z,{label:`Session`,children:(0,Y.jsx)(Q,{children:p.session})}),(0,Y.jsx)(Z,{label:`Written by`,children:(0,Y.jsx)(Q,{children:p.component})}),p.tenant!==null&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Customer `,(0,Y.jsx)(b,{term:`customer`})]}),children:p.tenant===``?(0,Y.jsx)($,{children:`None`}):p.tenant})]}),p.upstream&&(0,Y.jsxs)(X,{title:`Request to the connected server`,children:[(0,Y.jsx)(Z,{label:`Request`,children:(0,Y.jsxs)(`span`,{className:`mono text-[12.5px] break-all`,children:[p.upstream.method??`?`,` `,p.upstream.host??``,p.upstream.path??``]})}),(0,Y.jsx)(Z,{label:`Answer`,children:p.upstream.status===null?(0,Y.jsx)($,{children:`No status`}):(0,Y.jsx)(`span`,{className:`tnum`,children:p.upstream.status})}),p.upstream.bytes!==null&&(0,Y.jsx)(Z,{label:`Size`,children:f(p.upstream.bytes)})]}),(p.approval_id||p.grant_id)&&(0,Y.jsxs)(X,{title:`Linked`,children:[p.approval_id&&(0,Y.jsx)(Z,{label:`Approval request`,children:(0,Y.jsx)(ye,{href:n(a,`/approvals`,{id:p.approval_id}),children:p.approval_id})}),p.grant_id&&(0,Y.jsx)(Z,{label:(0,Y.jsxs)(Y.Fragment,{children:[`Pre-approval `,(0,Y.jsx)(b,{term:`preApproval`})]}),children:(0,Y.jsx)(ye,{href:n(a,`/pre-approvals`,{id:p.grant_id}),children:p.grant_id})})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[15px] font-semibold`,children:[`Inputs, as recorded `,(0,Y.jsx)(b,{term:`redaction`})]}),p.args_redacted===null?(0,Y.jsx)(`p`,{className:`text-[14px] text-soft`,children:`This toolbox does not record call inputs.`}):(0,Y.jsx)(S,{label:`Inputs as recorded`,maxHeight:260,children:JSON.stringify(p.args_redacted,null,2)}),o&&p.args_redacted!==null&&(0,Y.jsxs)(`details`,{className:`mt-3 rounded-2xl border border-faint px-4 py-3 text-[13px]`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`What the hidden-value markers mean`}),(0,Y.jsx)(`ul`,{className:`mt-2 space-y-1.5`,children:o.markers.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-3`,children:[(0,Y.jsx)(Q,{children:e.marker}),(0,Y.jsxs)(`span`,{className:`text-muted`,children:[ve(e.meaning),`.`]})]},e.marker))}),(0,Y.jsx)(`p`,{className:`mt-2 text-soft`,children:`Inputs are hidden by their name as well as their content, so a harmless value can still be hidden. The original values were never written down, so they cannot be recovered from the log.`})]})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[15px] font-semibold`,children:[`Tamper check `,(0,Y.jsx)(b,{term:`hashChain`})]}),(0,Y.jsxs)(`ol`,{className:`space-y-2 text-[13px]`,children:[(0,Y.jsx)(be,{label:`Fingerprint of the entry before`,value:p.prev_hash}),(0,Y.jsx)(`li`,{"aria-hidden":!0,className:`pl-4 text-soft`,children:(0,Y.jsx)(d,{name:`chevron`,size:16})}),(0,Y.jsx)(be,{label:`Fingerprint of this entry`,value:p.hash,strong:!0})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-[13px] text-soft`,children:`This entry's fingerprint covers its contents and the one before it, so editing or removing any earlier entry breaks every fingerprint after it.`}),(0,Y.jsxs)(`p`,{className:`mt-3 text-[12.5px] text-soft`,children:[`Fingerprint of the inputs: `,(0,Y.jsx)(Q,{children:p.args_hash})]})]})]})})}var ve=e=>e.charAt(0).toUpperCase()+e.slice(1);function X({title:e,children:t}){return(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(`h3`,{className:`mb-2 text-[15px] font-semibold`,children:e}),(0,Y.jsx)(`dl`,{className:`divide-y divide-faint rounded-2xl border border-faint px-4`,children:t})]})}function Z({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`grid gap-1 py-2.5 sm:grid-cols-[160px_1fr] sm:gap-4`,children:[(0,Y.jsx)(`dt`,{className:`flex items-center gap-1.5 text-[13px] text-soft`,children:e}),(0,Y.jsx)(`dd`,{className:`min-w-0 text-[14px]`,children:t})]})}var Q=({children:e})=>(0,Y.jsx)(`code`,{className:`mono text-[12px] break-all text-soft`,children:e}),$=({children:e})=>(0,Y.jsx)(`span`,{className:`text-soft`,children:e});function ye({href:e,children:t}){return(0,Y.jsx)(`a`,{href:e,onClick:g,className:`mono text-[12.5px] break-all text-ok underline underline-offset-2`,children:t})}function be({label:e,value:t,strong:n}){return(0,Y.jsxs)(`li`,{className:n?`rounded-2xl bg-sunken px-4 py-3`:`rounded-2xl border border-faint px-4 py-3`,children:[(0,Y.jsx)(`span`,{className:`block text-[12.5px] text-soft`,children:e}),(0,Y.jsx)(`code`,{className:`mono mt-1 block text-[12px] break-all text-ink`,children:t})]})}function xe(){let{serverId:e,server:n,tenant:a,tenantInfo:s,nav:c}=pe(),[d,f]=(0,J.useState)(()=>se(c)),[m,h]=(0,J.useState)(()=>Date.now()),[g,_]=(0,J.useState)([]),[v,y]=(0,J.useState)(),[b,S]=(0,J.useState)(null),[w,T]=(0,J.useState)(!1),[O,A]=(0,J.useState)(!1),[j=``,M=``,N=``]=x([d.tool,d.actor,d.component].join(`\0`),300).split(`\0`),F={...d,tool:j,actor:M,component:N};(0,J.useEffect)(()=>{oe(i(c,{...le(F),seq:b?String(b.seq):null}))},[JSON.stringify(F),b?.seq]);let I=ue(F,a,m),L=JSON.stringify(I),R=re(()=>p.audit(e,v===void 0?I:{...I,cursor:String(v)}),[e,L,v],v===void 0?5e3:void 0),z=re(()=>p.redaction(),[]),B=v===void 0?R.data?.records??[]:[...g,...R.data?.records??[]],V=R.loading&&!R.data;function H(e){f(t=>({...t,...e})),y(void 0),_([]),e.range!==void 0&&h(Date.now())}let fe=()=>{y(void 0),_([]),h(Date.now()),R.reload()},[U,W]=(0,J.useState)(()=>c.query.get(`seq`));(0,J.useEffect)(()=>{if(!U)return;let t=Number(U);if(W(null),!Number.isInteger(t)||t<0)return;let n={limit:`1`,cursor:String(t+1)};!d.allTenants&&a!==null&&(n.tenant=a),p.audit(e,n).then(e=>{let n=e.records.find(e=>e.seq===t);n&&S(n)}).catch(()=>void 0)},[U]);let G=(0,J.useMemo)(()=>[{value:``,label:`Any decision`},...(z.data?.decisions??Object.keys(ie).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:k(e.value)}))],[z.data]),K=(0,J.useMemo)(()=>[{value:``,label:`Any result`},...(z.data?.outcomes??Object.keys(te).map(e=>({value:e,label:e}))).map(e=>({value:e.value,label:C(e.value)}))],[z.data]),q=s?.configured?s.tenants.filter(e=>e!==``):[];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ee,{title:`Activity`,subtitle:`Every call your AI made through this toolbox, and what happened. Each entry is chained to the one before it, so edits can be detected.`,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`primary`,icon:`shield-check`,onClick:()=>T(!0),children:`Check log integrity`}),(0,Y.jsx)(E,{icon:`download`,onClick:()=>A(!0),disabled:B.length===0,children:`Download log`})]})}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(ne,{title:`Filters`,actions:ce(d)&&(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`x`,onClick:()=>H(de),children:`Clear filters`}),children:[(0,Y.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,Y.jsx)(r,{label:`Result`,children:(0,Y.jsx)(D,{value:d.outcome,onChange:e=>H({outcome:e}),options:K})}),(0,Y.jsx)(r,{label:`Decision`,children:(0,Y.jsx)(D,{value:d.decision,onChange:e=>H({decision:e}),options:G})}),(0,Y.jsx)(r,{label:`Tool`,help:`Use * to match any text, like files.*`,children:(0,Y.jsx)(l,{value:d.tool,onChange:e=>H({tool:e}),mono:!0,placeholder:`Any tool`})}),(0,Y.jsx)(r,{label:`Who asked`,children:(0,Y.jsx)(l,{value:d.actor,onChange:e=>H({actor:e}),placeholder:`Anyone`})}),q.length>0&&(0,Y.jsx)(r,{label:`Customer`,children:(0,Y.jsx)(D,{value:d.allTenants?`*`:a??``,onChange:e=>{e===`*`?H({allTenants:!0}):e===a?H({allTenants:!1}):oe(i(c,{tenant:e,allTenants:null}))},options:[...a===null?[{value:``,label:`Choose a customer`}]:[],...q.map(e=>({value:e,label:e})),{value:`*`,label:`All customers`}]})}),d.component&&(0,Y.jsx)(r,{label:`Written by`,technical:`component`,children:(0,Y.jsx)(l,{value:d.component,onChange:e=>H({component:e}),mono:!0})})]}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-end justify-between gap-4 border-t border-faint pt-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-[13px] font-semibold text-soft`,"aria-hidden":!0,children:`When`}),(0,Y.jsx)(u,{label:`Time range`,value:d.range,onChange:e=>H({range:e}),options:[{value:``,label:`Any time`},{value:`1h`,label:`Last hour`},{value:`24h`,label:`Last 24 hours`},{value:`7d`,label:`Last 7 days`},{value:`custom`,label:`Custom`}]})]}),(0,Y.jsx)(ae,{checked:d.noteworthy,onChange:e=>H({noteworthy:e}),label:`Only problems`,description:`Blocked, failed or still waiting.`})]}),d.range===`custom`&&(0,Y.jsxs)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-2`,children:[(0,Y.jsx)(Ee,{label:`From`,value:d.since,onChange:e=>H({since:e})}),(0,Y.jsx)(Ee,{label:`Until`,value:d.until,onChange:e=>H({until:e}),help:`Leave empty for up to now.`})]})]}),R.data&&R.data.malformed>0&&(0,Y.jsxs)(o,{tone:`warn`,title:`${t(R.data.malformed,`line`)} could not be read`,children:[`Of the `,P(R.data.scanned),` lines read for this list, `,P(R.data.malformed),` were damaged and skipped. Run the integrity check to see where.`]}),(0,Y.jsxs)(ne,{title:V?`Entries`:`${t(B.length,`entry`,`entries`)}${R.data?.nextCursor==null?``:` so far`}`,actions:(0,Y.jsx)(E,{size:`sm`,variant:`ghost`,icon:`refresh`,onClick:fe,loading:R.loading&&!!R.data,children:`Refresh list`}),children:[(0,Y.jsx)(Se,{loading:V,error:R.error,onRetry:R.reload,records:B,filtered:ce(d),onClear:()=>H(de),onOpen:S,mixedCustomers:d.allTenants}),R.data?.nextCursor!=null&&(0,Y.jsx)(`div`,{className:`mt-5 flex flex-wrap items-center gap-3`,children:(0,Y.jsx)(E,{icon:`chevron`,loading:R.loading,onClick:()=>{_(B),y(R.data.nextCursor)},children:`Load older entries`})})]})]}),(0,Y.jsx)(_e,{record:b,onClose:()=>S(null),nav:c,redaction:z.data}),(0,Y.jsx)(he,{open:w,onClose:()=>T(!1),serverId:e}),(0,Y.jsx)(De,{open:O,onClose:()=>A(!1),records:B,stem:`activity-${n.id}-${new Date().toISOString().slice(0,10)}`})]})}function Se({loading:e,error:t,onRetry:n,records:r,filtered:i,onClear:s,onOpen:c,mixedCustomers:l}){return t?(0,Y.jsx)(o,{tone:`danger`,title:`The activity log could not be read`,actions:(0,Y.jsx)(E,{size:`sm`,onClick:n,children:`Try again`}),children:t}):e?(0,Y.jsx)(`div`,{className:`space-y-5`,"aria-busy":!0,children:[0,1,2,3,4].map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`skeleton h-10 w-10 shrink-0 rounded-full`}),(0,Y.jsx)(a,{lines:2})]},e))}):r.length===0?i?(0,Y.jsx)(_,{icon:`filter`,title:`No entries match these filters`,actions:(0,Y.jsx)(E,{onClick:s,children:`Clear filters`}),children:`The whole log was searched. Try a wider time range or fewer filters.`}):(0,Y.jsx)(_,{icon:`activity`,title:`No activity yet`,children:`Calls appear here as soon as an AI app connected to this toolbox uses a tool.`}):(0,Y.jsx)(`ul`,{className:`-mx-2`,children:r.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsx)(Te,{record:e,onOpen:()=>c(e),showCustomer:l})},`${e.seq}-${e.id}`))})}var Ce={ok:`bg-ok-tint text-ok`,warn:`bg-warn-tint text-warn`,bad:`bg-bad-tint text-bad`,neutral:`bg-sunken text-muted`};function we(e,t){if(!t&&(e.actor===`agent`||!e.actor))return me(e.client);if(e.actor===`gateway`)return`The toolbox`;let n=e.args_redacted?.origin;return t&&(n===`console`||e.component===`hmcp-web`||e.rule_id===`approval.decide`||e.tool?.startsWith(`(`))?e.actor&&e.actor!==`console`?`You (${e.actor})`:`You`:e.actor}function Te({record:t,onOpen:n,showCustomer:r}){let i=K(t,H(),V()),a=t.rule_id===`gateway.unknown-tool`,o=a?null:L(t),c=te[t.outcome]?.tone??`neutral`,l=i?`neutral`:a?`warn`:t.outcome===`error`?`bad`:ie[t.decision]?.tone??`neutral`,u=i?.icon??(t.decision===`deny`?`x`:t.decision===`approve`?`clock`:`check`);return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:`flex w-full flex-wrap items-center gap-x-3 gap-y-2 rounded-2xl px-2 py-3 text-left transition-colors hover:bg-faint focus-visible:bg-faint`,children:[(0,Y.jsx)(`span`,{className:N(`grid h-10 w-10 shrink-0 place-items-center rounded-full`,Ce[l]),children:(0,Y.jsx)(d,{name:u,size:18,strokeWidth:2})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1 basis-56`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-[14.5px] font-medium`,children:i?(0,Y.jsxs)(Y.Fragment,{children:[i.title,t.tool&&!t.tool.startsWith(`(`)&&(0,Y.jsx)(`span`,{className:`ml-1.5 text-soft`,title:t.tool,children:W(t.tool).label})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-soft`,children:B(t)}),` `,(0,Y.jsx)(`span`,{title:t.tool,children:W(t.tool).label})]})}),(0,Y.jsxs)(`span`,{className:`mt-0.5 block truncate text-[12.5px] text-soft`,children:[(0,Y.jsx)(`time`,{dateTime:t.ts,title:s(t.ts),children:v(t.ts)}),` · `,we(t,i!==null),r&&t.tenant?` · ${t.tenant}`:``,!i&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,z(t)]})]}),o&&(0,Y.jsxs)(`span`,{className:`mt-1 flex items-center gap-1.5 text-[12.5px] font-medium text-warn`,children:[(0,Y.jsx)(d,{name:`eye`,size:14,strokeWidth:2}),o]})]}),(0,Y.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1.5 max-sm:pl-[52px] sm:shrink-0`,children:[a?(0,Y.jsx)(e,{tone:`warn`,children:`No such tool`}):!i&&(0,Y.jsx)(w,{decision:t.decision}),!a&&(i||C(t.outcome)!==k(t.decision))&&(0,Y.jsx)(e,{tone:c,children:R(t)?`You said no`:C(t.outcome)}),(0,Y.jsx)(d,{name:`chevron-right`,size:18,className:`text-soft max-sm:hidden`})]})]})}function Ee({label:e,value:t,onChange:n,help:i}){return(0,Y.jsx)(r,{label:e,help:i,children:(0,Y.jsx)(`input`,{type:`datetime-local`,value:t,onChange:e=>n(e.target.value),className:`field`})})}function De({open:e,onClose:n,records:r,stem:i}){let[a,o]=(0,J.useState)(`jsonl`);return(0,Y.jsx)(j,{open:e,onClose:n,title:`Download log`,description:`Saves the ${t(r.length,`entry`,`entries`)} listed now, with the filters you set. Load older entries first to include more.`,footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(E,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,Y.jsx)(E,{variant:`primary`,icon:`download`,onClick:()=>{a===`jsonl`?U(`${i}.jsonl`,`application/x-ndjson`,fe(r)):U(`${i}.csv`,`text/csv`,F(r)),n()},children:`Download file`})]}),children:(0,Y.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,Y.jsx)(`legend`,{className:`sr-only`,children:`File format`}),(0,Y.jsx)(Oe,{checked:a===`jsonl`,onSelect:()=>o(`jsonl`),title:`Exact log entries (JSONL)`,children:`One entry per line, exactly as written, fingerprints included. Use this to keep a copy or to check it later.`}),(0,Y.jsx)(Oe,{checked:a===`csv`,onSelect:()=>o(`csv`),title:`Spreadsheet (CSV)`,children:`The main columns, for sorting and counting in a spreadsheet. Fingerprints are left out.`})]})})}function Oe({checked:e,onSelect:t,title:n,children:r}){return(0,Y.jsxs)(`label`,{className:N(`flex cursor-pointer gap-3 rounded-2xl border-[1.5px] px-4 py-3 transition-colors`,e?`border-[var(--primary)] bg-ok-tint/40`:`border-line hover:bg-faint`),children:[(0,Y.jsx)(`input`,{type:`radio`,name:`log-format`,checked:e,onChange:t,className:`mt-1 accent-[var(--primary)]`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`block text-[14px] font-semibold`,children:n}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-[13px] text-soft`,children:r})]})]})}export{xe as ActivityPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$ as e,B as t,Ct as n,D as r,E as i,Et as a,F as o,G as s,H as c,I as l,It as u,J as d,K as f,M as p,Nt as m,Ot as h,Pt as g,T as _,U as v,V as y,Y as ee,Z as b,_ as x,_t as S,c as te,gt as ne,ht as C,j as w,kt as T,mt as E,pt as D,q as O,rt as k,s as A,w as j,wt as M,x as re,y as ie,yt as N}from"./kit-BHB_ha4i.js";import{a as P,c as ae,hn as F,l as I,n as oe,o as L,pn as R,r as se,s as z,t as B,u as ce}from"./index-Cm4wG2zz.js";var V=u(),H=T(),U=/^\[redacted:([^\]]+)\]$/,W=/…\[truncated (\d+) chars\]$/,G=/^\[truncated (\d+) items\]$/;function K(e){if(typeof e!=`string`)return null;let t=U.exec(e);return t?t[1]===`key`||t[1]===`circular`||t[1]===`max-depth`?t[1]:`pattern`:W.test(e)?`chars`:G.test(e)?`items`:null}function q(e,t,n=0){if(n>20)return;let r=K(e);r&&t.add(r),Array.isArray(e)?e.forEach(e=>q(e,t,n+1)):e&&typeof e==`object`&&Object.values(e).forEach(e=>q(e,t,n+1))}var J={key:`[redacted:key]`,pattern:`[redacted:<pattern>]`,circular:`[redacted:circular]`,"max-depth":`[redacted:max-depth]`,chars:`…[truncated N chars]`,items:`[truncated N items]`},Y={key:`Hidden`,pattern:`Hidden`,circular:`Hidden`,"max-depth":`Hidden`,chars:`Cut short`,items:`Cut short`};function X({args:e,error:t,meta:n}){let r=new Set;q(e,r);let i=e=>n?.markers.find(t=>t.marker===J[e])?.meaning,a=e&&typeof e==`object`&&!Array.isArray(e)?Object.entries(e):null;return(0,H.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,H.jsx)(c,{tone:`warn`,title:`Some inputs could not be read back`,children:t}),a===null?e==null?!t&&(0,H.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`The inputs were not recorded.`}):(0,H.jsx)(Z,{value:e,meaning:i}):a.length===0?(0,H.jsx)(`p`,{className:`text-[13.5px] text-soft`,children:`This call sent no inputs.`}):(0,H.jsx)(`dl`,{className:`divide-y divide-faint overflow-hidden rounded-2xl bg-sunken/60`,children:a.map(([e,t])=>(0,H.jsxs)(`div`,{className:`grid gap-1 px-4 py-2.5 sm:grid-cols-[minmax(6rem,10rem)_minmax(0,1fr)] sm:gap-4`,children:[(0,H.jsx)(`dt`,{className:`mono pt-px text-[12.5px] break-all text-soft`,children:e}),(0,H.jsx)(`dd`,{className:`min-w-0`,children:(0,H.jsx)(Z,{value:t,meaning:i})})]},e))}),r.size>0&&(0,H.jsxs)(`div`,{className:`flex gap-2 text-[12.5px] text-soft`,children:[(0,H.jsx)(h,{name:`eye-off`,size:15,className:`mt-0.5 shrink-0`}),(0,H.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-muted`,children:[`Some values are hidden or cut short in the record `,(0,H.jsx)(x,{term:`redaction`})]}),[...r].map(e=>(0,H.jsxs)(`p`,{children:[(0,H.jsx)(`code`,{className:`mono text-[11.5px]`,children:J[e]}),`: `,i(e)??`not shown in full`]},e))]})]})]})}function Z({value:t,meaning:n}){let r=K(t);if(r&&r!==`chars`)return(0,H.jsx)(e,{tone:`neutral`,icon:`eye-off`,title:n(r),children:Y[r]});if(typeof t==`string`){let r=W.exec(t),i=r?t.slice(0,r.index):t;return(0,H.jsxs)(`p`,{className:`scrollbar-thin max-h-40 overflow-y-auto text-[13.5px] break-words whitespace-pre-wrap`,children:[i===``?(0,H.jsx)(`span`,{className:`text-soft`,children:`(empty)`}):i,r&&(0,H.jsxs)(e,{tone:`neutral`,className:`ml-1.5 align-middle`,title:n(`chars`),children:[r[1],` more characters not recorded`]})]})}return typeof t==`number`||typeof t==`boolean`||t===null?(0,H.jsx)(`span`,{className:`mono text-[13px]`,children:String(t)}):(0,H.jsx)(`pre`,{className:`scrollbar-thin mono max-h-48 overflow-auto rounded-xl bg-surface px-3 py-2 text-[12px] leading-relaxed whitespace-pre-wrap break-words`,children:JSON.stringify(t,null,2)})}var Q=e=>e instanceof m&&(e.status===409||e.status===404);function le({approval:e,meta:t,now:n,serverId:a,tenant:s,selecting:u,selected:d,onSelect:f,locked:h,onDecided:v,onRemembered:ee}){let S=ie(),[te,ne]=(0,V.useState)(``),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,A]=(0,V.useState)(t?.rememberDefaults.ttlSeconds??3600),[M,re]=(0,V.useState)(t?.rememberDefaults.maxUses??20),[I,oe]=(0,V.useState)(!1),[R,U]=(0,V.useState)(null),W=z(e.tool),G=F(),K=e.expiresAt-n,q=se(e),J=t?.grantTtlMaxSeconds,Y=h||w!==null;async function Z(t,n={}){T(n.remember?`remember`:n.classify?`classify-${n.classify}`:t),U(null);let r;try{r=await g.decide(a,e.id,t,te.trim(),s,n.classify,n.remember)}catch(e){T(null),Q(e)?(S.show(`warn`,`This call was already answered, or it ran out of time.`),v()):n.remember&&e instanceof m&&e.status===422?U(L(e.message)):S.show(`bad`,L(e.message));return}T(null),t===`denied`?S.show(`ok`,`You said no. ${W.label} will not run, and the AI is told you said no.`):r.remembered?(S.show(`ok`,`Approved. Similar calls won't ask until ${ae(r.remembered.expiresAt)}.`),ee(r.remembered,e.tool)):r.classifyWarning?S.show(`warn`,L(r.classifyWarning)):r.classified&&n.classify?S.show(`ok`,`Approved, and ${W.label} is now labelled "${k[n.classify].label}". Its calls still ask you.`):S.show(`ok`,`Approved. The call can go ahead.`),v()}let le=O!==null&&(J===void 0||O<=J)&&(I||M!==null&&M>=1);return(0,H.jsxs)(`article`,{"aria-labelledby":`apr-${e.id}`,className:N(`card flex min-w-0 flex-col gap-5 p-5 sm:p-6`,d&&`outline-2 outline-offset-2 outline-[var(--primary)]`),children:[(0,H.jsxs)(`header`,{className:`flex items-start gap-3`,children:[u&&(0,H.jsx)(`span`,{className:`pt-2.5`,children:(0,H.jsx)(j,{checked:d,onChange:f,disabled:Y,label:(0,H.jsxs)(`span`,{className:`sr-only`,children:[`Select `,W.label]})})}),(0,H.jsx)(`span`,{className:`grid h-11 w-11 shrink-0 place-items-center rounded-full bg-sunken`,children:(0,H.jsx)(b,{effect:e.effect})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`h3`,{id:`apr-${e.id}`,tabIndex:-1,className:`text-[18px] outline-none focus-visible:outline-2 focus-visible:outline-[var(--focus)] leading-snug font-medium tracking-[-0.015em] break-words`,children:W.label}),(0,H.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-[12.5px] text-soft`,children:[W.server&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{title:W.server,children:G(W.server)}),(0,H.jsx)(`span`,{"aria-hidden":!0,children:`·`})]}),(0,H.jsx)(b,{effect:e.effect,withLabel:!0})]})]})]}),(0,H.jsxs)(`section`,{"aria-label":`What it wants to do`,className:`space-y-2.5`,children:[(0,H.jsx)(`p`,{className:`text-[15px] leading-relaxed [overflow-wrap:anywhere]`,children:B(e)}),(0,H.jsx)(`p`,{className:`text-[14px] text-muted`,children:ce(e)}),e.violations.length>0&&(0,H.jsx)(`ul`,{className:`space-y-1.5 rounded-2xl bg-warn-tint px-4 py-3 text-[13.5px]`,children:e.violations.map(t=>(0,H.jsxs)(`li`,{className:`flex gap-2`,children:[(0,H.jsx)(`span`,{className:`mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-warn`,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`min-w-0 break-words`,children:P(t,e.args)})]},t))}),(0,H.jsx)(`p`,{className:`text-[13px] text-soft`,children:K>0?`If you don't answer by ${o(e.expiresAt)}, it doesn't run. The AI can ask again.`:`This request ran out of time, so it doesn't run. The AI can ask again.`})]}),(0,H.jsxs)(`section`,{"aria-label":`The details it would send`,className:`space-y-2`,children:[(0,H.jsx)(`h4`,{className:`eyebrow`,children:`The details it would send`}),(0,H.jsx)(X,{args:e.args,error:e.argsError,meta:t})]}),(0,H.jsxs)(`details`,{className:`group text-[12.5px] text-soft`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer select-none font-medium text-muted`,children:`Details`}),(0,H.jsxs)(`dl`,{className:`mt-2 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1`,children:[(0,H.jsx)(`dt`,{children:`Tool`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.tool})}),(0,H.jsx)(`dt`,{children:`Asked by`}),(0,H.jsxs)(`dd`,{children:[e.actor,` `,(0,H.jsx)(`span`,{title:l(e.createdAt),children:y(e.createdAt,n)})]}),(0,H.jsx)(`dt`,{children:`Session`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.session})}),e.ruleId&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`dt`,{children:`Rule`}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(`code`,{className:`mono break-all`,children:e.ruleId})})]}),(0,H.jsx)(`dt`,{children:`Request`}),(0,H.jsxs)(`dd`,{children:[(0,H.jsx)(`code`,{className:`mono break-all`,children:e.id}),`, expires `,l(e.expiresAt)]})]})]}),(0,H.jsxs)(`div`,{className:`mt-auto space-y-3 border-t border-faint pt-4`,children:[(0,H.jsx)(i,{label:`Note for the activity log`,optional:!0,children:(0,H.jsx)(p,{value:te,onChange:ne,placeholder:`Why you said yes or no`,disabled:Y})}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(C,{variant:`primary`,icon:`check`,onClick:()=>Z(`granted`),loading:w===`granted`,disabled:Y,children:`Approve`}),(0,H.jsx)(C,{variant:`secondary`,icon:`x`,onClick:()=>Z(`denied`),loading:w===`denied`,disabled:Y,children:`Say no`}),e.rememberAllowed&&!q&&(0,H.jsx)(C,{variant:`ghost`,icon:E?`chevron`:`chevron-right`,"aria-expanded":E,"aria-controls":`remember-${e.id}`,onClick:()=>D(e=>!e),disabled:Y,children:`Approve and don't ask again`})]}),q&&(0,H.jsxs)(`div`,{className:`space-y-2.5 rounded-2xl bg-sunken/70 p-4`,children:[(0,H.jsx)(`p`,{className:`text-[13.5px] font-semibold`,children:`Approve and remember this tool as:`}),(0,H.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`group`,"aria-label":`Approve and say what this tool does`,children:[`read`,`write`,`destructive`].map(e=>(0,H.jsx)(C,{size:`sm`,variant:`secondary`,onClick:()=>Z(`granted`,{classify:e}),loading:w===`classify-${e}`,disabled:Y,title:k[e].explain,children:k[e].label},e))}),(0,H.jsx)(`p`,{className:`text-[12.5px] text-soft`,children:`This approves the call and saves what the tool does in your protection settings. Its calls still ask you; once it is labelled you can set a rule for it on the Tools page.`})]}),E&&e.rememberAllowed&&(0,H.jsxs)(`div`,{id:`remember-${e.id}`,className:`space-y-4 rounded-2xl bg-sunken/70 p-4`,children:[(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[14px] font-semibold`,children:[`Approve and don't ask again `,(0,H.jsx)(x,{term:`preApproval`})]}),(0,H.jsx)(i,{label:`For how long`,children:(0,H.jsx)(_,{value:O,onChange:A,label:`For how long`,max:J})}),(0,H.jsx)(i,{label:`Up to how many calls`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,H.jsx)(r,{value:I?null:M,onChange:re,min:1,step:1,unit:`calls`,disabled:I||Y,className:`w-40`}),(0,H.jsx)(j,{checked:I,onChange:oe,label:`No limit`,disabled:Y})]})}),(0,H.jsx)(`p`,{className:`text-[13px] text-muted`,children:`For the time you choose, your AI can make this same request again without asking. Anything different still asks you, including a list with items changed, repeated or left out. You can take it back any time on the Pre-approvals page.`}),R&&(0,H.jsx)(c,{tone:`danger`,title:`Nothing was approved`,role:`alert`,children:R}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(C,{variant:`primary`,icon:`check`,disabled:!le||Y,loading:w===`remember`,onClick:()=>Z(`granted`,{remember:{ttlSeconds:O,maxUses:I?null:M}}),children:`Approve and remember`}),(0,H.jsx)(C,{variant:`ghost`,onClick:()=>D(!1),disabled:w!==null,children:`Cancel`})]})]})]})]})}var ue={elicit:`On this toolbox your AI app asks you in its own window, so calls usually do not wait here.`,cli:`On this toolbox every call that needs your OK waits here until you answer it.`,both:`Your AI app asks you in its own window when it can. When it cannot, the call waits here.`,deny:`On this toolbox calls that would need your OK are blocked instead, so nothing waits here.`};function de(){let{serverId:e,tenant:r,nav:i,reload:o}=R(),l=ie(),u=I(1e3),f=A(()=>g.pending(e,r),[e,r],2e3),p=A(()=>g.approvals(e,r,{limit:200}),[e,r],15e3),h=A(()=>g.redaction(),[]),_=A(()=>g.protection(e,r),[e,r],3e4),b=i.query.get(`id`),x=b!==null&&(f.data??[]).some(e=>e.id===b),T=i.query.get(`tab`)===`history`||b!==null&&f.data!==null&&!x?`history`:`waiting`,k=e=>M(a(i,{tab:e===`waiting`?null:e})),j=(0,V.useMemo)(()=>[...f.data??[]].filter(e=>e.expiresAt>u).sort((e,t)=>e.createdAt-t.createdAt),[f.data,u]),N=(0,V.useMemo)(()=>(p.data??[]).filter(e=>e.state!==`pending`).sort((e,t)=>(t.decidedAt??t.expiresAt)-(e.decidedAt??e.expiresAt)),[p.data]),[P,F]=(0,V.useState)(!1),[se,B]=(0,V.useState)([]),ce=new Set(j.map(e=>e.id)),U=se.filter(e=>ce.has(e)),[W,G]=(0,V.useState)(null),[K,q]=(0,V.useState)(``),[J,Y]=(0,V.useState)(!1),[X,Z]=(0,V.useState)(null),Q=(0,V.useRef)(!1),de=(0,V.useRef)(null),fe=(0,V.useRef)(null);(0,V.useEffect)(()=>{Q.current&&f.data!==null&&(Q.current=!1,(de.current?.querySelector(`article h3[tabindex]`)??fe.current)?.focus())},[f.data]);let pe=()=>{f.reload(),p.reload(),_.reload(),o()};async function he(n){Y(!0);let i=0,a=0,o=[];for(let t of U)try{await g.decide(e,t,n,K.trim(),r),i++}catch(e){e instanceof m&&(e.status===409||e.status===404)?a++:o.push(L(e.message))}Y(!1),G(null),q(``),B([]),F(!1),pe();let s=[`${n===`granted`?`Approved`:`Denied`} ${t(i,`call`)}.`];a&&s.push(`${t(a,`call`)} had already been answered or ran out of time.`),o.length&&s.push(`${o.length} failed: ${o[0]}`),l.show(o.length?`bad`:a?`warn`:`ok`,s.join(` `))}let $=_.data?.approvals,ge=$?ue[$.mode]:void 0,_e=j.reduce((e,t)=>e===null||t.expiresAt<e?t.expiresAt:e,null),ve=j[0];return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(te,{title:`Waiting for you`,subtitle:`Your AI wanted to do these things. Nothing happens until you decide.`,actions:(0,H.jsx)(C,{variant:P?`primary`:`secondary`,icon:P?`x`:`list`,"aria-pressed":P,disabled:!P&&j.length<2,onClick:()=>{F(e=>!e),B([])},children:P?`Stop selecting`:`Select several`})}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,H.jsx)(E,{tone:`hero`,title:`Waiting now`,loading:f.data===null&&!f.error,value:j.length,sub:ve?`Oldest asked ${y(ve.createdAt,u)}`:`Nothing needs you`}),(0,H.jsxs)(`div`,{className:`contents max-sm:hidden`,children:[(0,H.jsx)(E,{title:`Expires next`,loading:f.data===null&&!f.error,value:_e===null?`None`:oe(_e-u),sub:_e===null?`Nothing is waiting`:`A request nobody answers doesn't run`}),(0,H.jsx)(E,{title:`Pre-approvals in use`,loading:_.data===null&&!_.error,value:$?.activeGrantCount??`–`,sub:`Calls they cover skip this page`,href:n(i,`/pre-approvals`),hrefLabel:`Open pre-approvals`})]})]}),(0,H.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[$&&$.pendingElsewhere>0&&(0,H.jsxs)(c,{tone:`info`,title:`${t($.pendingElsewhere,`call`)} ${$.pendingElsewhere===1?`is`:`are`} waiting for a different customer`,children:[`Choose that customer at the top of the page to answer `,$.pendingElsewhere===1?`it`:`them`,`.`]}),X&&(0,H.jsxs)(c,{tone:`ok`,title:`Pre-approval created`,role:`status`,actions:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(S,{size:`sm`,variant:`secondary`,href:n(i,`/pre-approvals`,{grant:X.grant.id}),children:`Open pre-approval`}),(0,H.jsx)(ne,{icon:`x`,label:`Dismiss message`,size:32,onClick:()=>Z(null)})]}),children:[`Calls like this one to `,z(X.tool).label,` won't ask until `,ae(X.grant.expiresAt),X.grant.maxUses===null?``:`, for up to ${t(X.grant.maxUses,`call`)}`,`.`]})]}),(0,H.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center justify-between gap-3`,children:[(0,H.jsx)(O,{label:`Calls`,value:T,onChange:k,items:[{id:`waiting`,label:`Waiting`,count:j.length},{id:`history`,label:`Decided earlier`,count:N.length}]}),T===`waiting`&&j.length>0&&(0,H.jsx)(`p`,{className:`text-[13px] text-soft`,children:`Oldest first: the call at the top runs out soonest.`})]}),(0,H.jsx)(`div`,{role:`tabpanel`,id:ee(T),"aria-labelledby":d(T),className:`mt-5`,children:T===`waiting`?(0,H.jsxs)(H.Fragment,{children:[P&&j.length>0&&(0,H.jsx)(D,{className:`mb-5`,padded:!1,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-5 py-4`,children:[(0,H.jsxs)(`p`,{className:`min-w-0 flex-1 text-[14px]`,children:[(0,H.jsx)(`span`,{className:`tnum font-semibold`,children:U.length}),` of `,t(j.length,`call`),` selected`]}),(0,H.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>B(U.length===j.length?[]:j.map(e=>e.id)),children:U.length===j.length?`Clear selection`:`Select all`}),(0,H.jsx)(C,{size:`sm`,variant:`primary`,icon:`check`,disabled:U.length===0,onClick:()=>G(`granted`),children:`Approve all`}),(0,H.jsx)(C,{size:`sm`,variant:`secondary`,icon:`x`,disabled:U.length===0,onClick:()=>G(`denied`),children:`Deny all`})]})}),f.error&&(0,H.jsx)(`div`,{className:`mb-5`,children:(0,H.jsx)(c,{tone:`danger`,title:`Could not load the calls waiting for you`,role:`alert`,actions:(0,H.jsx)(C,{size:`sm`,icon:`refresh`,onClick:f.reload,children:`Try again`}),children:L(f.error)})}),f.data===null?!f.error&&(0,H.jsx)(`div`,{className:`grid gap-5 xl:grid-cols-2`,children:[0,1].map(e=>(0,H.jsxs)(D,{children:[(0,H.jsx)(s,{height:22,width:`45%`}),(0,H.jsx)(`div`,{className:`mt-5`,children:(0,H.jsx)(s,{lines:4})})]},e))}):j.length===0?(0,H.jsx)(D,{children:(0,H.jsx)(`div`,{ref:fe,tabIndex:-1,className:`outline-none`,children:(0,H.jsxs)(v,{icon:`inbox`,title:`Nothing is waiting for you.`,actions:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(C,{variant:`secondary`,onClick:()=>k(`history`),children:`Show decided calls`}),(0,H.jsx)(S,{variant:`secondary`,href:n(i,`/pre-approvals`),children:`Manage pre-approvals`})]}),children:[`When your AI tries something that needs your OK, it appears here and this page updates by itself.`,` `,ge]})})}):(0,H.jsx)(`div`,{ref:de,className:`grid items-start gap-5 xl:grid-cols-2`,children:j.map(t=>(0,H.jsx)(`div`,{className:t.id===b?`rounded-[22px] ring-2 ring-[var(--focus)] ring-offset-2 ring-offset-[var(--bg)]`:void 0,children:(0,H.jsx)(le,{approval:t,meta:h.data,now:u,serverId:e,tenant:r,selecting:P,selected:P&&U.includes(t.id),onSelect:e=>B(n=>e?[...new Set([...n,t.id])]:n.filter(e=>e!==t.id)),locked:J,onDecided:()=>{Q.current=!0,pe()},onRemembered:(e,t)=>Z({grant:e,tool:t})})},t.id))})]}):(0,H.jsx)(me,{rows:N,error:p.error,loading:p.data===null,retry:p.reload,now:u,focusId:b})}),(0,H.jsxs)(re,{open:W!==null,onClose:()=>!J&&G(null),dismissable:!J,title:W===`granted`?`Approve ${t(U.length,`call`)}?`:`Deny ${t(U.length,`call`)}?`,description:W===`granted`?`Each call runs with exactly the inputs shown on its card. Nothing else is approved.`:`None of these calls will run. Your AI is told they were denied.`,footer:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(C,{variant:`secondary`,onClick:()=>G(null),disabled:J,children:`Go back`}),(0,H.jsx)(C,{variant:W===`granted`?`primary`:`danger`,loading:J,onClick:()=>W&&he(W),children:W===`granted`?`Approve all`:`Deny all`})]}),children:[(0,H.jsx)(`ul`,{className:`mb-4 max-h-48 space-y-1 overflow-y-auto text-[14px]`,children:j.filter(e=>U.includes(e.id)).map(e=>(0,H.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:z(e.tool).label}),(0,H.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.tool})]},e.id))}),(0,H.jsx)(w,{value:K,onChange:q,rows:2,"aria-label":`Note for the activity log, for every selected call`,placeholder:`Note for the activity log (optional)`})]})]})}function fe(t){return t.decidedBy?.startsWith(`standing-grant:`)?(0,H.jsx)(e,{tone:`ok`,icon:`key`,children:`Let through by a pre-approval`}):t.state===`granted`||t.state===`used`?(0,H.jsx)(e,{tone:`ok`,icon:`check`,children:`Approved`}):t.state===`denied`?(0,H.jsx)(e,{tone:`bad`,icon:`x`,children:`Denied`}):t.state===`expired`?(0,H.jsx)(e,{tone:`neutral`,icon:`clock`,children:`Expired`}):(0,H.jsx)(e,{children:t.state})}function pe(e){return e.decidedBy?e.decidedBy.startsWith(`standing-grant:`)?(0,H.jsxs)(`span`,{children:[`Pre-approval `,(0,H.jsx)(`code`,{className:`mono text-[12px] text-soft`,children:e.decidedBy.slice(15)})]}):e.decidedBy:(0,H.jsx)(`span`,{className:`text-soft`,children:e.state===`expired`?`Nobody answered`:`Not recorded`})}function me({rows:e,error:t,loading:n,retry:r,now:i,focusId:a}){let o=[{key:`call`,header:`Call`,cell:e=>(0,H.jsxs)(`span`,{className:`block min-w-0`,children:[(0,H.jsx)(`span`,{className:`block font-medium`,children:z(e.tool).label}),(0,H.jsx)(`code`,{className:`mono block text-[12px] break-all text-soft`,children:e.tool})]})},{key:`result`,header:`Result`,cell:fe},{key:`who`,header:`Decided by`,cell:pe},{key:`when`,header:`When`,cell:e=>{let t=e.decidedAt??e.expiresAt;return(0,H.jsx)(`span`,{title:l(t),children:y(t,i)})}},{key:`note`,header:`Note`,cell:e=>e.decisionNote?(0,H.jsx)(`span`,{className:`break-words`,children:e.decisionNote}):(0,H.jsx)(`span`,{className:`text-soft`,children:`None`}),hideOnMobile:!1}];return(0,H.jsxs)(D,{children:[t&&(0,H.jsx)(`div`,{className:`mb-4`,children:(0,H.jsx)(c,{tone:`danger`,title:`Could not load decided calls`,actions:(0,H.jsx)(C,{size:`sm`,icon:`refresh`,onClick:r,children:`Try again`}),children:L(t)})}),n?!t&&(0,H.jsx)(s,{lines:5,height:18}):(0,H.jsx)(f,{caption:`Calls decided earlier`,columns:o,rows:e,rowKey:e=>e.id,selectedKey:a,empty:(0,H.jsx)(v,{icon:`clock`,title:`No calls decided yet`,compact:!0,children:`Calls you approve or deny, and calls that run out of time, are listed here.`})})]})}export{de as ApprovalsPage};
|