@agent-deck/backend 2.0.0 → 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/mcp-server.d.ts +143 -3
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +384 -37
- package/dist/mcp-server.js.map +1 -1
- package/package.json +2 -2
- package/static-ui/assets/{index-ClYpYc1K.js → index-ynIby2JK.js} +1 -1
- package/static-ui/index.html +1 -1
package/dist/mcp-server.d.ts
CHANGED
|
@@ -32,6 +32,24 @@ export declare function isBearerGrantRequired(raw?: string | undefined): boolean
|
|
|
32
32
|
*/
|
|
33
33
|
export declare const DEFAULT_LIVE_TOUCH_KEEPALIVE_MS: number;
|
|
34
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;
|
|
35
53
|
export declare function resolveLiveTouchKeepAliveMs(raw: string | undefined, staleMs: number): number;
|
|
36
54
|
export declare class AgentDeckMCPServer {
|
|
37
55
|
/** Cap on remembered stale session ids — the tally is diagnostics, not a ledger. */
|
|
@@ -52,8 +70,51 @@ export declare class AgentDeckMCPServer {
|
|
|
52
70
|
private lastTouchAtMs;
|
|
53
71
|
/** NOT-309: keep-alive timer proving idle-but-connected sessions still live. */
|
|
54
72
|
private liveTouchKeepAliveTimer;
|
|
55
|
-
/**
|
|
56
|
-
|
|
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;
|
|
57
118
|
/** Changes on every process start — how a client detects it outlived the server. */
|
|
58
119
|
private readonly instanceId;
|
|
59
120
|
private readonly startedAt;
|
|
@@ -83,6 +144,16 @@ export declare class AgentDeckMCPServer {
|
|
|
83
144
|
grantStore?: ClientGrantStore | null;
|
|
84
145
|
auditStore?: AuditStore | null;
|
|
85
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;
|
|
86
157
|
});
|
|
87
158
|
/**
|
|
88
159
|
* NOT-318: grant metadata store. An injected store (tests) wins; otherwise
|
|
@@ -121,6 +192,18 @@ export declare class AgentDeckMCPServer {
|
|
|
121
192
|
private buildBindingPayload;
|
|
122
193
|
private registerLiveDisplay;
|
|
123
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;
|
|
124
207
|
/**
|
|
125
208
|
* Fire-and-forget lastActivityAt bump; only for sessions this process
|
|
126
209
|
* registered (badge-holding). `force` bypasses the per-request debounce —
|
|
@@ -143,11 +226,68 @@ export declare class AgentDeckMCPServer {
|
|
|
143
226
|
* no tool calls. Only badge-holding (registered) sessions are touched; the
|
|
144
227
|
* backend ignores touches for sessions it never saw, so unassigned or
|
|
145
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.
|
|
146
234
|
*/
|
|
147
235
|
private touchAllLiveDisplays;
|
|
148
236
|
private startLiveDisplayKeepAlive;
|
|
149
237
|
private stopLiveDisplayKeepAlive;
|
|
150
|
-
|
|
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;
|
|
151
291
|
private callBackendAPI;
|
|
152
292
|
private getBoundDeckId;
|
|
153
293
|
private toolResult;
|
package/dist/mcp-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAcA,OAAO,OAA8B,MAAM,SAAS,CAAC;AAQrD,OAAO,EACL,gBAAgB,EAIjB,MAAM,sBAAsB,CAAC;AAY9B,OAAO,EAAE,cAAc,EAAyB,MAAM,qBAAqB,CAAC;AAc5E,OAAO,EAAE,UAAU,EAAoC,MAAM,eAAe,CAAC;AA0C7E;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,kCAAkC,CAAC;AAC1E,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD,wBAAgB,qBAAqB,CAAC,GAAG,GAAE,MAAM,GAAG,SAAmD,GAAG,OAAO,CAEhH;AAaD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM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