@agent-deck/backend 1.11.9 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/audit/store.d.ts +43 -0
- package/dist/audit/store.d.ts.map +1 -0
- package/dist/audit/store.js +128 -0
- package/dist/audit/store.js.map +1 -0
- package/dist/auth/client-grants.d.ts +2 -2
- package/dist/auth/client-grants.d.ts.map +1 -1
- package/dist/auth/client-grants.js +0 -1
- package/dist/auth/client-grants.js.map +1 -1
- package/dist/auth/hosted-mode.d.ts +16 -0
- package/dist/auth/hosted-mode.d.ts.map +1 -0
- package/dist/auth/hosted-mode.js +136 -0
- package/dist/auth/hosted-mode.js.map +1 -0
- package/dist/auth/owner-auth.d.ts +24 -0
- package/dist/auth/owner-auth.d.ts.map +1 -0
- package/dist/auth/owner-auth.js +68 -0
- package/dist/auth/owner-auth.js.map +1 -0
- package/dist/auth/request-limiter.d.ts +17 -0
- package/dist/auth/request-limiter.d.ts.map +1 -0
- package/dist/auth/request-limiter.js +47 -0
- package/dist/auth/request-limiter.js.map +1 -0
- package/dist/cli-runtime.d.ts +2 -2
- package/dist/container-entrypoint.d.ts +2 -0
- package/dist/container-entrypoint.d.ts.map +1 -0
- package/dist/container-entrypoint.js +52 -0
- package/dist/container-entrypoint.js.map +1 -0
- package/dist/export-import/export-bundle.d.ts +2 -2
- package/dist/export-import/export-bundle.d.ts.map +1 -1
- package/dist/export-import/export-bundle.js +4 -2
- package/dist/export-import/export-bundle.js.map +1 -1
- package/dist/export-import/import-bundle.d.ts.map +1 -1
- package/dist/export-import/import-bundle.js +15 -3
- package/dist/export-import/import-bundle.js.map +1 -1
- package/dist/index.js +18 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/destination-guard.d.ts +32 -0
- package/dist/lib/destination-guard.d.ts.map +1 -0
- package/dist/lib/destination-guard.js +238 -0
- package/dist/lib/destination-guard.js.map +1 -0
- package/dist/lib/fatal.d.ts +4 -4
- package/dist/lib/fatal.d.ts.map +1 -1
- package/dist/lib/fatal.js +36 -16
- package/dist/lib/fatal.js.map +1 -1
- package/dist/lib/graceful-shutdown.d.ts +26 -0
- package/dist/lib/graceful-shutdown.d.ts.map +1 -0
- package/dist/lib/graceful-shutdown.js +92 -0
- package/dist/lib/graceful-shutdown.js.map +1 -0
- package/dist/lib/mcp-oauth-discovery.d.ts.map +1 -1
- package/dist/lib/mcp-oauth-discovery.js +9 -4
- package/dist/lib/mcp-oauth-discovery.js.map +1 -1
- package/dist/lib/structured-console.d.ts +3 -0
- package/dist/lib/structured-console.d.ts.map +1 -0
- package/dist/lib/structured-console.js +29 -0
- package/dist/lib/structured-console.js.map +1 -0
- package/dist/mcp-index.js +2 -14
- package/dist/mcp-index.js.map +1 -1
- package/dist/mcp-server.d.ts +164 -3
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +496 -42
- package/dist/mcp-server.js.map +1 -1
- package/dist/mcp-tools/elicitation.d.ts +13 -4
- package/dist/mcp-tools/elicitation.d.ts.map +1 -1
- package/dist/mcp-tools/elicitation.js +34 -14
- package/dist/mcp-tools/elicitation.js.map +1 -1
- package/dist/mcp-tools/register.d.ts.map +1 -1
- package/dist/mcp-tools/register.js +59 -5
- package/dist/mcp-tools/register.js.map +1 -1
- package/dist/models/database.d.ts.map +1 -1
- package/dist/models/database.js +18 -5
- package/dist/models/database.js.map +1 -1
- package/dist/routes/agent-grants.d.ts.map +1 -1
- package/dist/routes/agent-grants.js +19 -3
- package/dist/routes/agent-grants.js.map +1 -1
- package/dist/routes/audit.d.ts +5 -0
- package/dist/routes/audit.d.ts.map +1 -0
- package/dist/routes/audit.js +33 -0
- package/dist/routes/audit.js.map +1 -0
- package/dist/routes/decks.d.ts.map +1 -1
- package/dist/routes/decks.js +27 -0
- package/dist/routes/decks.js.map +1 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +5 -4
- package/dist/routes/mcp.js.map +1 -1
- package/dist/routes/trusted-session.d.ts +2 -0
- package/dist/routes/trusted-session.d.ts.map +1 -1
- package/dist/routes/trusted-session.js +132 -0
- package/dist/routes/trusted-session.js.map +1 -1
- package/dist/server/cors-origins.d.ts.map +1 -1
- package/dist/server/cors-origins.js +19 -0
- package/dist/server/cors-origins.js.map +1 -1
- package/dist/server/degraded.d.ts +15 -0
- package/dist/server/degraded.d.ts.map +1 -0
- package/dist/server/degraded.js +55 -0
- package/dist/server/degraded.js.map +1 -0
- package/dist/server/graceful-shutdown.fixture.d.ts +2 -0
- package/dist/server/graceful-shutdown.fixture.d.ts.map +1 -0
- package/dist/server/graceful-shutdown.fixture.js +52 -0
- package/dist/server/graceful-shutdown.fixture.js.map +1 -0
- package/dist/server/health.d.ts +21 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +65 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +49 -2
- package/dist/server/index.js.map +1 -1
- package/dist/services/icon-resolver.d.ts.map +1 -1
- package/dist/services/icon-resolver.js +2 -1
- package/dist/services/icon-resolver.js.map +1 -1
- package/dist/services/mcp-client-manager.d.ts.map +1 -1
- package/dist/services/mcp-client-manager.js +3 -0
- package/dist/services/mcp-client-manager.js.map +1 -1
- package/dist/services/mcp-discovery-service.d.ts.map +1 -1
- package/dist/services/mcp-discovery-service.js +2 -1
- package/dist/services/mcp-discovery-service.js.map +1 -1
- package/dist/services/oauth-manager.d.ts.map +1 -1
- package/dist/services/oauth-manager.js +12 -7
- package/dist/services/oauth-manager.js.map +1 -1
- package/dist/services/service-manager.d.ts.map +1 -1
- package/dist/services/service-manager.js +15 -4
- package/dist/services/service-manager.js.map +1 -1
- package/dist/store/atomic-write.d.ts.map +1 -1
- package/dist/store/atomic-write.js +44 -3
- package/dist/store/atomic-write.js.map +1 -1
- package/dist/store/deck-codec.d.ts +9 -0
- package/dist/store/deck-codec.d.ts.map +1 -1
- package/dist/store/deck-codec.js +64 -1
- package/dist/store/deck-codec.js.map +1 -1
- package/dist/store/deck-file.d.ts +3 -3
- package/dist/store/deck-file.d.ts.map +1 -1
- package/dist/store/deck-file.js +4 -3
- package/dist/store/deck-file.js.map +1 -1
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/migrate-v1-to-v2.d.ts +22 -0
- package/dist/store/migrate-v1-to-v2.d.ts.map +1 -0
- package/dist/store/migrate-v1-to-v2.js +167 -0
- package/dist/store/migrate-v1-to-v2.js.map +1 -0
- package/dist/store/migrate.js +2 -2
- package/dist/store/migrate.js.map +1 -1
- package/dist/store/reindex.d.ts.map +1 -1
- package/dist/store/reindex.js +16 -6
- package/dist/store/reindex.js.map +1 -1
- package/dist/store/startup.d.ts.map +1 -1
- package/dist/store/startup.js +13 -0
- package/dist/store/startup.js.map +1 -1
- package/dist/store/writer.d.ts.map +1 -1
- package/dist/store/writer.js +7 -3
- package/dist/store/writer.js.map +1 -1
- package/dist/trusted-session/route-policy-registry.d.ts.map +1 -1
- package/dist/trusted-session/route-policy-registry.js +9 -1
- package/dist/trusted-session/route-policy-registry.js.map +1 -1
- package/dist/trusted-session/store.d.ts +10 -2
- package/dist/trusted-session/store.d.ts.map +1 -1
- package/dist/trusted-session/store.js +41 -13
- package/dist/trusted-session/store.js.map +1 -1
- package/dist/vault/secret-store.d.ts +8 -0
- package/dist/vault/secret-store.d.ts.map +1 -1
- package/dist/vault/secret-store.js +17 -1
- package/dist/vault/secret-store.js.map +1 -1
- package/package.json +2 -2
- package/static-ui/assets/index-DMqzTrRe.css +1 -0
- package/static-ui/assets/index-ynIby2JK.js +251 -0
- package/static-ui/index.html +2 -2
- package/static-ui/assets/index-CQf3Vouc.css +0 -1
- package/static-ui/assets/index-sENM6Awe.js +0 -235
package/dist/lib/fatal.js
CHANGED
|
@@ -72,10 +72,10 @@ function formatFatalLines(label, phase, error) {
|
|
|
72
72
|
return lines;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* Synchronous write
|
|
76
|
-
* `fd` is a seam for tests; production
|
|
75
|
+
* Synchronous write — process.exit() must not be able to drop it.
|
|
76
|
+
* `fd` is a seam for tests; production writes to stdout.
|
|
77
77
|
*/
|
|
78
|
-
function writeLogSync(text, fd =
|
|
78
|
+
function writeLogSync(text, fd = 1, maxRetries = 1000) {
|
|
79
79
|
const buffer = Buffer.from(text.endsWith('\n') ? text : `${text}\n`, 'utf8');
|
|
80
80
|
let offset = 0;
|
|
81
81
|
let retries = 0;
|
|
@@ -84,7 +84,7 @@ function writeLogSync(text, fd = 2, maxRetries = 1000) {
|
|
|
84
84
|
offset += node_fs_1.default.writeSync(fd, buffer, offset, buffer.length - offset);
|
|
85
85
|
}
|
|
86
86
|
catch (error) {
|
|
87
|
-
// A non-blocking
|
|
87
|
+
// A non-blocking output stream (a TTY, or a pipe whose reader stalled) answers
|
|
88
88
|
// EAGAIN. Retry, but bounded: spinning forever would hang the exit path
|
|
89
89
|
// this diagnostic exists to keep alive.
|
|
90
90
|
if (error.code === 'EAGAIN' && retries < maxRetries) {
|
|
@@ -96,25 +96,45 @@ function writeLogSync(text, fd = 2, maxRetries = 1000) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
function writeStructuredLogSync(level, event, fields, fd) {
|
|
100
|
+
writeLogSync(JSON.stringify({ level, time: new Date().toISOString(), event, ...fields }), fd);
|
|
101
|
+
}
|
|
102
|
+
function logFatal(label, phase, error, fd = 1) {
|
|
103
|
+
writeStructuredLogSync('error', 'process_fatal', {
|
|
104
|
+
service: label,
|
|
105
|
+
// Keep the established operator-facing diagnostic inside the structured
|
|
106
|
+
// record. The CLI supervisor copies this line verbatim into its own log,
|
|
107
|
+
// and older tooling searches it for the exit and cause markers.
|
|
108
|
+
message: formatFatalLines(label, phase, error).join('\n'),
|
|
109
|
+
phase,
|
|
110
|
+
exitCode: 1,
|
|
111
|
+
pid: process.pid,
|
|
112
|
+
nodeVersion: process.version,
|
|
113
|
+
nodeModuleVersion: process.versions.modules,
|
|
114
|
+
error: describeFatalError(error),
|
|
115
|
+
hint: fatalHint(error),
|
|
116
|
+
}, fd);
|
|
104
117
|
}
|
|
105
118
|
function logFatalAndExit(label, phase, error) {
|
|
106
119
|
logFatal(label, phase, error);
|
|
107
120
|
process.exit(1);
|
|
108
121
|
}
|
|
109
122
|
/** Startup fingerprint — makes "which Node ran this?" answerable after the fact. */
|
|
110
|
-
function logProcessStart(label, fields, fd =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.
|
|
114
|
-
|
|
123
|
+
function logProcessStart(label, fields, fd = 1) {
|
|
124
|
+
writeStructuredLogSync('info', 'process_start', {
|
|
125
|
+
service: label,
|
|
126
|
+
pid: process.pid,
|
|
127
|
+
nodeVersion: process.version,
|
|
128
|
+
nodeModuleVersion: process.versions.modules,
|
|
129
|
+
...fields,
|
|
130
|
+
}, fd);
|
|
115
131
|
}
|
|
116
|
-
function logExit(label, exitCode, reason, fd =
|
|
117
|
-
|
|
132
|
+
function logExit(label, exitCode, reason, fd = 1) {
|
|
133
|
+
writeStructuredLogSync(exitCode === 0 ? 'info' : 'error', 'process_exit', {
|
|
134
|
+
service: label,
|
|
135
|
+
exitCode,
|
|
136
|
+
reason,
|
|
137
|
+
}, fd);
|
|
118
138
|
}
|
|
119
139
|
/**
|
|
120
140
|
* Crashes outside the startup try/catch (a rejected background promise, a throw
|
package/dist/lib/fatal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fatal.js","sourceRoot":"","sources":["../../src/lib/fatal.ts"],"names":[],"mappings":";;;;;AAUA,gDASC;AAGD,8BAmCC;AAED,4CAWC;AAMD,oCAmBC;
|
|
1
|
+
{"version":3,"file":"fatal.js","source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,CAAC,OAAO;QAC3C,GAAG,MAAM;KACV,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,SAAgB,OAAO,CAAC,KAAiB,EAAE,QAAgB,EAAE,MAAc,EAAE,EAAE,GAAG,CAAC;IACjF,sBAAsB,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE;QACxE,OAAO,EAAE,KAAK;QACd,QAAQ;QACR,MAAM;KACP,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,KAAiB;IACpD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;QACxC,eAAe,CAAC,KAAK,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;QAC1C,eAAe,CAAC,KAAK,EAAE,6BAA6B,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { FatalLabel } from './fatal';
|
|
3
|
+
type ShutdownProcess = Pick<NodeJS.Process, 'once' | 'removeListener' | 'exit'>;
|
|
4
|
+
export type GracefulShutdownOptions = {
|
|
5
|
+
label: FatalLabel;
|
|
6
|
+
close: () => Promise<void>;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
processRef?: ShutdownProcess;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The production backend shutdown close, shared with the shutdown test
|
|
12
|
+
* fixture: server.close() stops accepting and releases the listener, and
|
|
13
|
+
* the tracked in-flight request is additionally awaited so process exit
|
|
14
|
+
* cannot precede the response even if server.close() resolves early
|
|
15
|
+
* (CI showed server.close() alone resolving while a live handler still
|
|
16
|
+
* ran: client ECONNRESET, shutdown_complete ~1ms after shutdown_started).
|
|
17
|
+
* Both src/index.ts and the fixture call this, so the SIGTERM test proves
|
|
18
|
+
* what production does instead of its own drain.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createTrackedClose(server: FastifyInstance): () => Promise<void>;
|
|
21
|
+
/** Count live HTTP requests; resolves when none remain in flight. */
|
|
22
|
+
export declare function trackInFlightRequests(server: FastifyInstance): () => Promise<void>;
|
|
23
|
+
/** Stop accepting work, drain active requests, and exit before the deadline. */
|
|
24
|
+
export declare function installGracefulShutdown(options: GracefulShutdownOptions): () => void;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=graceful-shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graceful-shutdown.d.ts","sourceRoot":"","sources":["../../src/lib/graceful-shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,MAAM,CAAC,CAAC;AAEhF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B,CAAC;AAUF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAO/E;AAED,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAoBlF;AAED,gFAAgF;AAChF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,IAAI,CA2CpF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTrackedClose = createTrackedClose;
|
|
4
|
+
exports.trackInFlightRequests = trackInFlightRequests;
|
|
5
|
+
exports.installGracefulShutdown = installGracefulShutdown;
|
|
6
|
+
function writeJsonLog(level, event, fields) {
|
|
7
|
+
process.stdout.write(`${JSON.stringify({ level, time: new Date().toISOString(), event, ...fields })}\n`);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The production backend shutdown close, shared with the shutdown test
|
|
11
|
+
* fixture: server.close() stops accepting and releases the listener, and
|
|
12
|
+
* the tracked in-flight request is additionally awaited so process exit
|
|
13
|
+
* cannot precede the response even if server.close() resolves early
|
|
14
|
+
* (CI showed server.close() alone resolving while a live handler still
|
|
15
|
+
* ran: client ECONNRESET, shutdown_complete ~1ms after shutdown_started).
|
|
16
|
+
* Both src/index.ts and the fixture call this, so the SIGTERM test proves
|
|
17
|
+
* what production does instead of its own drain.
|
|
18
|
+
*/
|
|
19
|
+
function createTrackedClose(server) {
|
|
20
|
+
const waitForDrain = trackInFlightRequests(server);
|
|
21
|
+
return async () => {
|
|
22
|
+
const closing = server.close();
|
|
23
|
+
await waitForDrain();
|
|
24
|
+
await closing;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Count live HTTP requests; resolves when none remain in flight. */
|
|
28
|
+
function trackInFlightRequests(server) {
|
|
29
|
+
let inFlight = 0;
|
|
30
|
+
let notifyDrained = null;
|
|
31
|
+
server.addHook('onRequest', async () => {
|
|
32
|
+
inFlight += 1;
|
|
33
|
+
});
|
|
34
|
+
server.addHook('onResponse', async () => {
|
|
35
|
+
inFlight -= 1;
|
|
36
|
+
if (inFlight === 0) {
|
|
37
|
+
const notify = notifyDrained;
|
|
38
|
+
notifyDrained = null;
|
|
39
|
+
notify?.();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
if (inFlight === 0)
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
notifyDrained = resolve;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Stop accepting work, drain active requests, and exit before the deadline. */
|
|
51
|
+
function installGracefulShutdown(options) {
|
|
52
|
+
const processRef = options.processRef ?? process;
|
|
53
|
+
// Leave one second for the container runtime to reap the process before a
|
|
54
|
+
// ten-second stop grace period expires.
|
|
55
|
+
const timeoutMs = options.timeoutMs ?? 9_000;
|
|
56
|
+
let shuttingDown = false;
|
|
57
|
+
const shutdown = async (signal) => {
|
|
58
|
+
if (shuttingDown)
|
|
59
|
+
return;
|
|
60
|
+
shuttingDown = true;
|
|
61
|
+
writeJsonLog('info', 'shutdown_started', { service: options.label, signal });
|
|
62
|
+
const deadline = setTimeout(() => {
|
|
63
|
+
writeJsonLog('error', 'shutdown_timeout', { service: options.label, signal, timeoutMs });
|
|
64
|
+
processRef.exit(1);
|
|
65
|
+
}, timeoutMs);
|
|
66
|
+
deadline.unref?.();
|
|
67
|
+
try {
|
|
68
|
+
await options.close();
|
|
69
|
+
clearTimeout(deadline);
|
|
70
|
+
writeJsonLog('info', 'shutdown_complete', { service: options.label, signal, exitCode: 0 });
|
|
71
|
+
processRef.exit(0);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
clearTimeout(deadline);
|
|
75
|
+
writeJsonLog('error', 'shutdown_failed', {
|
|
76
|
+
service: options.label,
|
|
77
|
+
signal,
|
|
78
|
+
message: error instanceof Error ? error.message : String(error),
|
|
79
|
+
});
|
|
80
|
+
processRef.exit(1);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const onSigint = () => void shutdown('SIGINT');
|
|
84
|
+
const onSigterm = () => void shutdown('SIGTERM');
|
|
85
|
+
processRef.once('SIGINT', onSigint);
|
|
86
|
+
processRef.once('SIGTERM', onSigterm);
|
|
87
|
+
return () => {
|
|
88
|
+
processRef.removeListener('SIGINT', onSigint);
|
|
89
|
+
processRef.removeListener('SIGTERM', onSigterm);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=graceful-shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graceful-shutdown.js","sourceRoot":"","sources":["../../src/lib/graceful-shutdown.ts"],"names":[],"mappings":";;AA+BA,gDAOC;AAGD,sDAoBC;AAGD,0DA2CC;AA9FD,SAAS,YAAY,CACnB,KAAuB,EACvB,KAAa,EACb,MAA+B;IAE/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;AAC3G,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAAC,MAAuB;IACxD,MAAM,YAAY,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACnD,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAC/B,MAAM,YAAY,EAAE,CAAC;QACrB,MAAM,OAAO,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,SAAgB,qBAAqB,CAAC,MAAuB;IAC3D,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,aAAa,GAAwB,IAAI,CAAC;IAC9C,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;QACrC,QAAQ,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;QACtC,QAAQ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AAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-oauth-discovery.d.ts","sourceRoot":"","sources":["../../src/lib/mcp-oauth-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AAmBvC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAuJF,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA2CjG"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.discoverMcpOAuthRequirements = discoverMcpOAuthRequirements;
|
|
4
4
|
const oauth_provider_guides_1 = require("../data/oauth-provider-guides");
|
|
5
|
+
const destination_guard_1 = require("./destination-guard");
|
|
5
6
|
function finalizeOAuthDiscovery(serviceUrl, oauth, authServers = []) {
|
|
6
7
|
const provider = oauth.provider ?? (0, oauth_provider_guides_1.inferOAuthProvider)(serviceUrl, authServers);
|
|
7
8
|
const setupMode = (0, oauth_provider_guides_1.resolveOAuthSetupMode)(provider, oauth.supportsDynamicRegistration);
|
|
@@ -26,7 +27,7 @@ function protectedResourceCandidates(serviceUrl) {
|
|
|
26
27
|
}
|
|
27
28
|
async function fetchJson(url) {
|
|
28
29
|
try {
|
|
29
|
-
const response = await
|
|
30
|
+
const response = await (0, destination_guard_1.guardedFetch)(url, {
|
|
30
31
|
headers: { Accept: 'application/json' },
|
|
31
32
|
});
|
|
32
33
|
if (!response.ok) {
|
|
@@ -34,7 +35,9 @@ async function fetchJson(url) {
|
|
|
34
35
|
}
|
|
35
36
|
return response.json();
|
|
36
37
|
}
|
|
37
|
-
catch {
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof destination_guard_1.DestinationGuardError)
|
|
40
|
+
throw error;
|
|
38
41
|
return null;
|
|
39
42
|
}
|
|
40
43
|
}
|
|
@@ -102,13 +105,15 @@ async function probeWwwAuthenticate(serviceUrl) {
|
|
|
102
105
|
headers,
|
|
103
106
|
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} }),
|
|
104
107
|
};
|
|
105
|
-
const response = await
|
|
108
|
+
const response = await (0, destination_guard_1.guardedFetch)(serviceUrl, init);
|
|
106
109
|
const wwwAuth = response.headers.get('www-authenticate');
|
|
107
110
|
if (wwwAuth) {
|
|
108
111
|
return wwwAuth;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
catch {
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof destination_guard_1.DestinationGuardError)
|
|
116
|
+
throw error;
|
|
112
117
|
// try next method
|
|
113
118
|
}
|
|
114
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-oauth-discovery.js","sourceRoot":"","sources":["../../src/lib/mcp-oauth-discovery.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"mcp-oauth-discovery.js","sourceRoot":"","sources":["../../src/lib/mcp-oauth-discovery.ts"],"names":[],"mappings":";;AA0LA,oEA2CC;AArOD,yEAIuC;AACvC,2DAA0E;AAgC1E,SAAS,sBAAsB,CAC7B,UAAkB,EAClB,KAAwB,EACxB,cAAwB,EAAE;IAE1B,MAAM,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AAC;QACf,KAAK,CAAC,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;IAClF,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-console.d.ts","sourceRoot":"","sources":["../../src/lib/structured-console.ts"],"names":[],"mappings":"AAOA,iFAAiF;AACjF,wBAAgB,wBAAwB,IAAI,IAAI,CAiB/C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installStructuredConsole = installStructuredConsole;
|
|
4
|
+
function normalize(value) {
|
|
5
|
+
if (value instanceof Error) {
|
|
6
|
+
return { name: value.name, message: value.message, stack: value.stack };
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
/** Route application console output through newline-delimited JSON on stdout. */
|
|
11
|
+
function installStructuredConsole() {
|
|
12
|
+
const write = (level, args) => {
|
|
13
|
+
const [first, ...rest] = args;
|
|
14
|
+
const record = {
|
|
15
|
+
level,
|
|
16
|
+
time: new Date().toISOString(),
|
|
17
|
+
message: typeof first === 'string' ? first : 'application_log',
|
|
18
|
+
};
|
|
19
|
+
const values = (typeof first === 'string' ? rest : args).map(normalize);
|
|
20
|
+
if (values.length > 0)
|
|
21
|
+
record.values = values;
|
|
22
|
+
process.stdout.write(`${JSON.stringify(record)}\n`);
|
|
23
|
+
};
|
|
24
|
+
console.log = (...args) => write('info', args);
|
|
25
|
+
console.info = (...args) => write('info', args);
|
|
26
|
+
console.warn = (...args) => write('warn', args);
|
|
27
|
+
console.error = (...args) => write('error', args);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=structured-console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-console.js","sourceRoot":"","sources":["../../src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C3D,OAAO,CAAC,IAAI,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC3D,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/mcp-index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const mcp_server_1 = require("./mcp-server");
|
|
4
4
|
const fatal_1 = require("./lib/fatal");
|
|
5
|
+
const graceful_shutdown_1 = require("./lib/graceful-shutdown");
|
|
5
6
|
(0, fatal_1.installFatalHandlers)('mcp');
|
|
6
7
|
async function startMCPServer() {
|
|
7
8
|
const port = process.env.AGENT_DECK_MCP_PORT
|
|
@@ -15,20 +16,7 @@ async function startMCPServer() {
|
|
|
15
16
|
const mcpServer = new mcp_server_1.AgentDeckMCPServer(port, backendUrl, undefined, host);
|
|
16
17
|
await mcpServer.start();
|
|
17
18
|
console.log('✅ Agent Deck MCP Server is ready to accept connections');
|
|
18
|
-
|
|
19
|
-
const shutdown = async (signal) => {
|
|
20
|
-
(0, fatal_1.logExit)('mcp', 0, `signal ${signal}`);
|
|
21
|
-
console.log('\n🛑 Shutting down MCP server...');
|
|
22
|
-
try {
|
|
23
|
-
await mcpServer.stop();
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
(0, fatal_1.logFatalAndExit)('mcp', `shutdown after ${signal} failed`, error);
|
|
27
|
-
}
|
|
28
|
-
process.exit(0);
|
|
29
|
-
};
|
|
30
|
-
process.on('SIGINT', () => void shutdown('SIGINT'));
|
|
31
|
-
process.on('SIGTERM', () => void shutdown('SIGTERM'));
|
|
19
|
+
(0, graceful_shutdown_1.installGracefulShutdown)({ label: 'mcp', close: () => mcpServer.stop() });
|
|
32
20
|
}
|
|
33
21
|
catch (error) {
|
|
34
22
|
// logFatalAndExit writes the message, the cause and a hint, synchronously.
|
package/dist/mcp-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-index.js","sourceRoot":"","sources":["../src/mcp-index.ts"],"names":[],"mappings":";;AAAA,6CAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"mcp-index.js","sourceRoot":"","sources":["../src/mcp-index.ts"],"names":[],"mappings":";;AAAA,6CAAkD;AAClD,uCAAqF;AACrF,+DAAkE;AAElE,IAAA,4BAAoB,EAAC,KAAK,CAAC,CAAC;AAE5B,KAAK,UAAU,cAAc;IAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB;QAC1C,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC;QACtD,CAAC,CAAC,IAAI,CAAC;IACT,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,WAAW,CAAC;IAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,uBAAuB,CAAC;IAEjF,IAAA,uBAAe,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IAEnD,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QAEpD,MAAM,SAAS,GAAG,IAAI,+BAAkB,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAC5E,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QAExB,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;QAEtE,IAAA,2CAAuB,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,2EAA2E;QAC3E,IAAA,uBAAe,EAAC,KAAK,EAAE,sCAAsC,IAAI,IAAI,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IACtF,CAAC;AACH,CAAC;AAED,cAAc,EAAE,CAAC"}
|
package/dist/mcp-server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { ClientGrantStore } from './auth/client-grants';
|
|
3
3
|
import { McpToolProfile } from './mcp-tools/profile';
|
|
4
|
+
import { AuditStore } from './audit/store';
|
|
4
5
|
/**
|
|
5
6
|
* NOT-318: hosted-mode flag. When `AGENT_DECK_MCP_REQUIRE_BEARER=1`, every
|
|
6
7
|
* `/mcp` request requires a valid per-agent grant secret, regardless of
|
|
@@ -11,6 +12,8 @@ import { McpToolProfile } from './mcp-tools/profile';
|
|
|
11
12
|
* bearer-free with zero config change.
|
|
12
13
|
*/
|
|
13
14
|
export declare const MCP_REQUIRE_BEARER_ENV_VAR = "AGENT_DECK_MCP_REQUIRE_BEARER";
|
|
15
|
+
export declare const MCP_INITIALIZE_RATE_LIMIT = 30;
|
|
16
|
+
export declare const MCP_INITIALIZE_RATE_WINDOW_MS = 60000;
|
|
14
17
|
export declare function isBearerGrantRequired(raw?: string | undefined): boolean;
|
|
15
18
|
/**
|
|
16
19
|
* NOT-309: keep-alive touch cadence for idle-but-connected MCP sessions.
|
|
@@ -29,6 +32,24 @@ export declare function isBearerGrantRequired(raw?: string | undefined): boolean
|
|
|
29
32
|
*/
|
|
30
33
|
export declare const DEFAULT_LIVE_TOUCH_KEEPALIVE_MS: number;
|
|
31
34
|
export declare const LIVE_TOUCH_KEEPALIVE_ENV_VAR = "AGENT_DECK_MCP_LIVE_TOUCH_KEEPALIVE_MS";
|
|
35
|
+
/**
|
|
36
|
+
* NOT-191: idle retention for MCP transport sessions. A session with no
|
|
37
|
+
* client traffic — no tool calls, no heartbeat pulse — is closed and fully
|
|
38
|
+
* cleaned once it has been idle this long. Twenty-four hours keeps a laptop
|
|
39
|
+
* asleep overnight recoverable (the bridge re-initializes on wake) while
|
|
40
|
+
* still reclaiming transports abandoned by crashed hosts. Kept separate
|
|
41
|
+
* from the 30-minute live-display lease on purpose: the display is what the
|
|
42
|
+
* status line reads, the transport is just retained state.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_TRANSPORT_IDLE_TTL_MS: number;
|
|
45
|
+
/** Cadence of the idle-transport sweep. */
|
|
46
|
+
export declare const DEFAULT_TRANSPORT_SWEEP_INTERVAL_MS = 60000;
|
|
47
|
+
/**
|
|
48
|
+
* NOT-191: bound on concurrent live-display unregisters, shared by the idle
|
|
49
|
+
* sweep and server shutdown so a mass expiry cannot fan out into hundreds of
|
|
50
|
+
* simultaneous backend calls.
|
|
51
|
+
*/
|
|
52
|
+
export declare const DEFAULT_UNREGISTER_CONCURRENCY = 8;
|
|
32
53
|
export declare function resolveLiveTouchKeepAliveMs(raw: string | undefined, staleMs: number): number;
|
|
33
54
|
export declare class AgentDeckMCPServer {
|
|
34
55
|
/** Cap on remembered stale session ids — the tally is diagnostics, not a ledger. */
|
|
@@ -49,8 +70,51 @@ export declare class AgentDeckMCPServer {
|
|
|
49
70
|
private lastTouchAtMs;
|
|
50
71
|
/** NOT-309: keep-alive timer proving idle-but-connected sessions still live. */
|
|
51
72
|
private liveTouchKeepAliveTimer;
|
|
52
|
-
/**
|
|
53
|
-
|
|
73
|
+
/**
|
|
74
|
+
* NOT-191: session cleanups in flight, keyed by MCP session id. Doubles as
|
|
75
|
+
* the re-entrancy guard — `transport.onclose` and the sweep/stop paths all
|
|
76
|
+
* funnel through `startCleanupSession`, and a second call for the same id
|
|
77
|
+
* joins the first instead of unregistering twice. Resolves to whether the
|
|
78
|
+
* live-display unregister succeeded (for aggregate batch summaries).
|
|
79
|
+
*/
|
|
80
|
+
private cleanupTasks;
|
|
81
|
+
/** NOT-191: clock for activity/TTL bookkeeping (tests inject a fake clock). */
|
|
82
|
+
private readonly nowFn;
|
|
83
|
+
/** NOT-191: idle bound for transport retention (24h default; `0` disables). */
|
|
84
|
+
private readonly transportIdleTtlMs;
|
|
85
|
+
/** NOT-191: cadence of the idle-transport sweep (`0` disables the timer). */
|
|
86
|
+
private readonly transportSweepIntervalMs;
|
|
87
|
+
/** NOT-191: bound on concurrent live-display unregisters (sweep + shutdown). */
|
|
88
|
+
private readonly unregisterConcurrency;
|
|
89
|
+
/** NOT-191: bound on one live-display unregister (option or env override). */
|
|
90
|
+
private readonly unregisterTimeoutMsValue;
|
|
91
|
+
/** NOT-191: keep-alive override (tests); otherwise the env resolution wins. */
|
|
92
|
+
private readonly liveTouchKeepAliveMsOverride;
|
|
93
|
+
/**
|
|
94
|
+
* NOT-191: last real client traffic per session — tool calls, handshakes,
|
|
95
|
+
* stream connects, heartbeat pulses. Server-generated keep-alive touches
|
|
96
|
+
* never write here, so they cannot extend transport retention.
|
|
97
|
+
*/
|
|
98
|
+
private lastClientActivityAtMs;
|
|
99
|
+
/** NOT-191: sessions whose bridge owns the heartbeat (no server touch needed). */
|
|
100
|
+
private heartbeatCapableSessions;
|
|
101
|
+
/** NOT-191: POST requests currently inside `transport.handleRequest` per session. */
|
|
102
|
+
private inFlightRequests;
|
|
103
|
+
/**
|
|
104
|
+
* NOT-191: sessions whose `DELETE` arrived while a host request was in
|
|
105
|
+
* flight. The close is deferred — never executed under running work — and
|
|
106
|
+
* runs when the last in-flight request lands or the next sweep finds the
|
|
107
|
+
* session idle.
|
|
108
|
+
*/
|
|
109
|
+
private pendingSessionClose;
|
|
110
|
+
/** NOT-191: idle-transport sweep timer. */
|
|
111
|
+
private transportSweepTimer;
|
|
112
|
+
/** NOT-191: re-entrancy guard so a slow sweep never overlaps the next tick. */
|
|
113
|
+
private transportSweepRunning;
|
|
114
|
+
/** NOT-191: unregister semaphore state; `unregisterPeak` is read by tests. */
|
|
115
|
+
private unregisterActive;
|
|
116
|
+
private unregisterPeak;
|
|
117
|
+
private unregisterWaiters;
|
|
54
118
|
/** Changes on every process start — how a client detects it outlived the server. */
|
|
55
119
|
private readonly instanceId;
|
|
56
120
|
private readonly startedAt;
|
|
@@ -72,8 +136,24 @@ export declare class AgentDeckMCPServer {
|
|
|
72
136
|
private grantStoreOverride;
|
|
73
137
|
/** Lazily opened grant store for hosted mode (shared backend database file). */
|
|
74
138
|
private grantStoreCache;
|
|
139
|
+
private auditStoreOverride;
|
|
140
|
+
private auditStoreCache;
|
|
141
|
+
private sharedSecurityDb;
|
|
142
|
+
private readonly initializeLimiter;
|
|
75
143
|
constructor(port?: number, backendUrl?: string, toolProfile?: McpToolProfile, host?: string, options?: {
|
|
76
144
|
grantStore?: ClientGrantStore | null;
|
|
145
|
+
auditStore?: AuditStore | null;
|
|
146
|
+
now?: () => number;
|
|
147
|
+
/** NOT-191: idle bound for transport retention (`0` disables TTL expiry). */
|
|
148
|
+
transportIdleTtlMs?: number;
|
|
149
|
+
/** NOT-191: idle-sweep cadence (`0` disables the timer). */
|
|
150
|
+
transportSweepIntervalMs?: number;
|
|
151
|
+
/** NOT-191: bound on concurrent live-display unregisters. */
|
|
152
|
+
unregisterConcurrency?: number;
|
|
153
|
+
/** NOT-191: bound on one live-display unregister (overrides the env var). */
|
|
154
|
+
unregisterTimeoutMs?: number;
|
|
155
|
+
/** NOT-191: live-touch keep-alive cadence (overrides the env var). */
|
|
156
|
+
liveTouchKeepAliveMs?: number;
|
|
77
157
|
});
|
|
78
158
|
/**
|
|
79
159
|
* NOT-318: grant metadata store. An injected store (tests) wins; otherwise
|
|
@@ -82,6 +162,7 @@ export declare class AgentDeckMCPServer {
|
|
|
82
162
|
* and existing tests never touch the database file.
|
|
83
163
|
*/
|
|
84
164
|
private getGrantStore;
|
|
165
|
+
private getAuditStore;
|
|
85
166
|
/**
|
|
86
167
|
* NOT-318: authenticate one bearer token to a grant principal. Every
|
|
87
168
|
* failure mode (missing store, malformed, unknown id, secret mismatch,
|
|
@@ -96,10 +177,33 @@ export declare class AgentDeckMCPServer {
|
|
|
96
177
|
* so concurrent requests cannot steal another session's backend authority.
|
|
97
178
|
*/
|
|
98
179
|
private createMcpServer;
|
|
180
|
+
/**
|
|
181
|
+
* NOT-375: initialize-time server instructions for an assigned deck.
|
|
182
|
+
* The bound deck's non-empty operating instructions ride the initialize
|
|
183
|
+
* response as a bootstrap hint where the SDK/host surfaces them; empty
|
|
184
|
+
* instructions omit the field. This value is frozen at connect time and
|
|
185
|
+
* never updates after a hot deck switch — `get_session_context` is the
|
|
186
|
+
* authoritative live read. Any failure here falls back to no instructions
|
|
187
|
+
* rather than failing the handshake; the bootstrap tool call surfaces the
|
|
188
|
+
* underlying deck error instead.
|
|
189
|
+
*/
|
|
190
|
+
private resolveInitializeInstructions;
|
|
99
191
|
private fetchDeck;
|
|
100
192
|
private buildBindingPayload;
|
|
101
193
|
private registerLiveDisplay;
|
|
102
194
|
private static readonly TOUCH_DEBOUNCE_MS;
|
|
195
|
+
/** NOT-191: injected clock for activity/TTL bookkeeping. */
|
|
196
|
+
private nowMs;
|
|
197
|
+
/**
|
|
198
|
+
* NOT-191: record real client traffic — a tool call, handshake, stream
|
|
199
|
+
* connect, or heartbeat pulse — as transport activity, and adopt the
|
|
200
|
+
* bridge-liveness capability whenever the marker is present. Called only
|
|
201
|
+
* for authenticated requests on a live session; server-generated
|
|
202
|
+
* keep-alive touches never come through here, so they cannot extend the
|
|
203
|
+
* transport idle TTL. A client pulse also refreshes the display lease via
|
|
204
|
+
* the per-request `touchLiveDisplay` at the same call sites.
|
|
205
|
+
*/
|
|
206
|
+
private noteClientActivity;
|
|
103
207
|
/**
|
|
104
208
|
* Fire-and-forget lastActivityAt bump; only for sessions this process
|
|
105
209
|
* registered (badge-holding). `force` bypasses the per-request debounce —
|
|
@@ -122,11 +226,68 @@ export declare class AgentDeckMCPServer {
|
|
|
122
226
|
* no tool calls. Only badge-holding (registered) sessions are touched; the
|
|
123
227
|
* backend ignores touches for sessions it never saw, so unassigned or
|
|
124
228
|
* half-initialized sessions are harmless no-ops by construction.
|
|
229
|
+
*
|
|
230
|
+
* NOT-191: heartbeat-capable sessions are skipped — their bridge owns the
|
|
231
|
+
* pulse now, and a server-generated touch here is what used to defeat the
|
|
232
|
+
* stale sweep for abandoned bridges. Legacy/unknown sessions keep the
|
|
233
|
+
* compatibility touch, but it never counts as transport activity.
|
|
125
234
|
*/
|
|
126
235
|
private touchAllLiveDisplays;
|
|
127
236
|
private startLiveDisplayKeepAlive;
|
|
128
237
|
private stopLiveDisplayKeepAlive;
|
|
129
|
-
|
|
238
|
+
/**
|
|
239
|
+
* NOT-191: one live-display unregister, bounded and silent. Returns whether
|
|
240
|
+
* it succeeded; failures aggregate into a single batch summary at the sweep
|
|
241
|
+
* and shutdown call sites instead of one stack trace per session. Runs
|
|
242
|
+
* while the session binding still resolves — `runCleanupSession` clears it
|
|
243
|
+
* only after this returns.
|
|
244
|
+
*/
|
|
245
|
+
private unregisterLiveDisplayQuiet;
|
|
246
|
+
/**
|
|
247
|
+
* NOT-191: run `fn` under the shared unregister semaphore so the idle
|
|
248
|
+
* sweep and server shutdown together never exceed the bound, however many
|
|
249
|
+
* sessions expire at once.
|
|
250
|
+
*/
|
|
251
|
+
private withUnregisterSlot;
|
|
252
|
+
/**
|
|
253
|
+
* NOT-191: one aggregate line for a batch of unregisters — attempted,
|
|
254
|
+
* succeeded, failed — logged only when something failed. A clean batch
|
|
255
|
+
* stays silent; a failing one never logs per-session stacks.
|
|
256
|
+
*/
|
|
257
|
+
private logUnregisterSummary;
|
|
258
|
+
/**
|
|
259
|
+
* NOT-191 session cleanup. Every transport/session end funnels through
|
|
260
|
+
* here — `transport.onclose` (clean `DELETE`), the idle sweep, deferred
|
|
261
|
+
* closes, and server shutdown — so no path can strand part of a session's
|
|
262
|
+
* state. Removes the transport/server entry, unregisters the live display
|
|
263
|
+
* under the shared concurrency bound, then disconnects the trusted
|
|
264
|
+
* runtime session (revoking nothing reusable — the grant row stays valid
|
|
265
|
+
* for the next handshake), and finally clears the binding, badge, touch,
|
|
266
|
+
* activity, capability, and in-flight bookkeeping. The unregister runs
|
|
267
|
+
* before the disconnect because it authenticates with the runtime session
|
|
268
|
+
* the disconnect revokes. Idempotent per session id: a second call joins
|
|
269
|
+
* the first.
|
|
270
|
+
*/
|
|
271
|
+
private startCleanupSession;
|
|
272
|
+
private runCleanupSession;
|
|
273
|
+
/**
|
|
274
|
+
* NOT-191: close every session that is idle past the transport TTL or has
|
|
275
|
+
* a deferred close pending — unless a host request is in flight, in which
|
|
276
|
+
* case it waits for the next sweep. Unregisters run concurrently under the
|
|
277
|
+
* shared bound and their failures collapse into one summary line.
|
|
278
|
+
*/
|
|
279
|
+
private sweepIdleTransports;
|
|
280
|
+
private startTransportSweep;
|
|
281
|
+
private stopTransportSweep;
|
|
282
|
+
/**
|
|
283
|
+
* NOT-191: run one POST inside the per-session in-flight guard. A session
|
|
284
|
+
* with work in flight is never expired or deleted; when the last request
|
|
285
|
+
* lands, a deferred close runs immediately instead of waiting for the
|
|
286
|
+
* sweep. (The long-lived GET stream is deliberately not counted — it stays
|
|
287
|
+
* open for the session's whole life, so counting it would pin every
|
|
288
|
+
* session against the TTL forever.)
|
|
289
|
+
*/
|
|
290
|
+
private handleTransportPost;
|
|
130
291
|
private callBackendAPI;
|
|
131
292
|
private getBoundDeckId;
|
|
132
293
|
private toolResult;
|