agent-discover 1.0.18 → 1.0.19
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/agent-desk-plugin.json +1 -1
- package/dist/transport/ws.d.ts +2 -5
- package/dist/transport/ws.d.ts.map +1 -1
- package/dist/transport/ws.js +32 -136
- package/dist/transport/ws.js.map +1 -1
- package/package.json +2 -2
package/agent-desk-plugin.json
CHANGED
package/dist/transport/ws.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type WsHandle } from 'agent-common';
|
|
2
2
|
import type { Server } from 'http';
|
|
3
3
|
import type { AppContext } from '../context.js';
|
|
4
|
-
export
|
|
5
|
-
wss: WebSocketServer;
|
|
6
|
-
close(): void;
|
|
7
|
-
}
|
|
4
|
+
export type WebSocketHandle = WsHandle;
|
|
8
5
|
export declare function setupWebSocket(httpServer: Server, ctx: AppContext): WebSocketHandle;
|
|
9
6
|
//# sourceMappingURL=ws.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/transport/ws.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/transport/ws.ts"],"names":[],"mappings":"AAQA,OAAO,EAAuC,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;AAEvC,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,eAAe,CAsBnF"}
|
package/dist/transport/ws.js
CHANGED
|
@@ -1,146 +1,42 @@
|
|
|
1
1
|
// =============================================================================
|
|
2
2
|
// agent-discover — WebSocket transport
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// Thin wrapper around agent-common's setupWebSocket. Streams full state with
|
|
5
|
+
// a single fingerprint (servers+active count). Both categories return the
|
|
6
|
+
// full payload so any DB change refreshes all connected clients.
|
|
6
7
|
// =============================================================================
|
|
7
|
-
import {
|
|
8
|
+
import { setupWebSocket as setupKitWebSocket } from 'agent-common';
|
|
8
9
|
import { version } from '../version.js';
|
|
9
|
-
const MAX_WS_MESSAGE_SIZE = 4096;
|
|
10
|
-
const MAX_WS_CONNECTIONS = 50;
|
|
11
|
-
const PING_INTERVAL_MS = 30_000;
|
|
12
|
-
const DB_POLL_INTERVAL_MS = 2_000;
|
|
13
10
|
export function setupWebSocket(httpServer, ctx) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
sendFullState(ws, ctx, clients);
|
|
26
|
-
ws.on('pong', () => {
|
|
27
|
-
const clientState = clients.get(ws);
|
|
28
|
-
if (clientState)
|
|
29
|
-
clientState.alive = true;
|
|
30
|
-
});
|
|
31
|
-
ws.on('message', (raw) => {
|
|
32
|
-
let parsed;
|
|
33
|
-
try {
|
|
34
|
-
parsed = JSON.parse(raw.toString());
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
ws.send(JSON.stringify({ type: 'error', message: 'Invalid JSON' }));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
41
|
-
ws.send(JSON.stringify({
|
|
42
|
-
type: 'error',
|
|
43
|
-
message: 'Message must be a JSON object',
|
|
44
|
-
}));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const msg = parsed;
|
|
48
|
-
if (msg.type === 'refresh') {
|
|
49
|
-
const clientState = clients.get(ws);
|
|
50
|
-
if (clientState)
|
|
51
|
-
clientState.fingerprint = null;
|
|
52
|
-
sendFullState(ws, ctx, clients);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
ws.on('error', () => clients.delete(ws));
|
|
56
|
-
ws.on('close', () => clients.delete(ws));
|
|
57
|
-
});
|
|
58
|
-
const pingInterval = setInterval(() => {
|
|
59
|
-
for (const [ws, state] of clients) {
|
|
60
|
-
if (!state.alive) {
|
|
61
|
-
ws.terminate();
|
|
62
|
-
clients.delete(ws);
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
state.alive = false;
|
|
66
|
-
ws.ping();
|
|
67
|
-
}
|
|
68
|
-
}, PING_INTERVAL_MS);
|
|
69
|
-
pingInterval.unref();
|
|
70
|
-
const dbPollInterval = setInterval(() => {
|
|
71
|
-
if (clients.size === 0)
|
|
72
|
-
return;
|
|
73
|
-
try {
|
|
74
|
-
const fp = getFingerprint(ctx);
|
|
75
|
-
for (const [ws, clientState] of clients) {
|
|
76
|
-
if (ws.readyState !== WebSocket.OPEN)
|
|
77
|
-
continue;
|
|
78
|
-
if (clientState.fingerprint !== fp) {
|
|
79
|
-
sendFullState(ws, ctx, clients);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
process.stderr.write('[agent-discover] WS DB poll error: ' +
|
|
85
|
-
(err instanceof Error ? err.message : String(err)) +
|
|
86
|
-
'\n');
|
|
87
|
-
}
|
|
88
|
-
}, DB_POLL_INTERVAL_MS);
|
|
89
|
-
dbPollInterval.unref();
|
|
90
|
-
return {
|
|
91
|
-
wss,
|
|
92
|
-
close() {
|
|
93
|
-
clearInterval(pingInterval);
|
|
94
|
-
clearInterval(dbPollInterval);
|
|
95
|
-
for (const [ws] of clients) {
|
|
96
|
-
ws.close(1001, 'Server shutting down');
|
|
97
|
-
}
|
|
98
|
-
clients.clear();
|
|
99
|
-
wss.close();
|
|
11
|
+
return setupKitWebSocket({
|
|
12
|
+
httpServer,
|
|
13
|
+
getFingerprints: () => {
|
|
14
|
+
const row = ctx.db.queryOne(`SELECT
|
|
15
|
+
COALESCE((SELECT COUNT(*) FROM servers), 0)
|
|
16
|
+
|| ':' || COALESCE((SELECT MAX(id) FROM servers), 0)
|
|
17
|
+
|| ':' || COALESCE((SELECT MAX(updated_at) FROM servers), '')
|
|
18
|
+
|| ':' || COALESCE((SELECT COUNT(*) FROM server_tools), 0)
|
|
19
|
+
AS fp`);
|
|
20
|
+
const active = ctx.proxy.getActiveServerNames().length;
|
|
21
|
+
return { registry: (row?.fp ?? '') + ':' + active };
|
|
100
22
|
},
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
function getFingerprint(ctx) {
|
|
107
|
-
const row = ctx.db.queryOne(`SELECT
|
|
108
|
-
COALESCE((SELECT COUNT(*) FROM servers), 0)
|
|
109
|
-
|| ':' || COALESCE((SELECT MAX(id) FROM servers), 0)
|
|
110
|
-
|| ':' || COALESCE((SELECT MAX(updated_at) FROM servers), '')
|
|
111
|
-
|| ':' || COALESCE((SELECT COUNT(*) FROM server_tools), 0)
|
|
112
|
-
AS fp`);
|
|
113
|
-
const activeCount = ctx.proxy.getActiveServerNames().length;
|
|
114
|
-
return (row?.fp ?? '') + ':' + activeCount;
|
|
23
|
+
getCategoryData: () => buildStatePayload(ctx),
|
|
24
|
+
getFullState: () => ({ version, ...buildStatePayload(ctx) }),
|
|
25
|
+
logError: (err) => process.stderr.write('[agent-discover] WS error: ' + (err instanceof Error ? err.message : String(err)) + '\n'),
|
|
26
|
+
});
|
|
115
27
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const activeServers = activeNames.map((name) => ({
|
|
130
|
-
name,
|
|
131
|
-
tools: ctx.proxy.getServerTools(name),
|
|
132
|
-
}));
|
|
133
|
-
ws.send(JSON.stringify({
|
|
134
|
-
type: 'state',
|
|
135
|
-
version,
|
|
136
|
-
servers: serversWithStatus,
|
|
137
|
-
active: activeServers,
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
catch (err) {
|
|
141
|
-
process.stderr.write('[agent-discover] WS send error: ' +
|
|
142
|
-
(err instanceof Error ? err.message : String(err)) +
|
|
143
|
-
'\n');
|
|
144
|
-
}
|
|
28
|
+
function buildStatePayload(ctx) {
|
|
29
|
+
const servers = ctx.registry.list();
|
|
30
|
+
const serversWithStatus = servers.map((s) => ({
|
|
31
|
+
...s,
|
|
32
|
+
active: ctx.proxy.isActive(s.name),
|
|
33
|
+
tools: ctx.registry.getTools(s.id),
|
|
34
|
+
}));
|
|
35
|
+
const activeNames = ctx.proxy.getActiveServerNames();
|
|
36
|
+
const active = activeNames.map((name) => ({
|
|
37
|
+
name,
|
|
38
|
+
tools: ctx.proxy.getServerTools(name),
|
|
39
|
+
}));
|
|
40
|
+
return { servers: serversWithStatus, active };
|
|
145
41
|
}
|
|
146
42
|
//# sourceMappingURL=ws.js.map
|
package/dist/transport/ws.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/transport/ws.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,uCAAuC;AACvC,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src/transport/ws.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,uCAAuC;AACvC,EAAE;AACF,6EAA6E;AAC7E,0EAA0E;AAC1E,iEAAiE;AACjE,gFAAgF;AAEhF,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAiB,MAAM,cAAc,CAAC;AAGlF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,MAAM,UAAU,cAAc,CAAC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C,oBAAoB,EAAE,CAAC;IACrD,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxC,IAAI;QACJ,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC;KACtC,CAAC,CAAC,CAAC;IAEJ,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-discover",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"mcpName": "io.github.keshrath/agent-discover",
|
|
5
5
|
"description": "MCP server registry and marketplace — discover, install, activate, and manage MCP tools on demand",
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
52
|
-
"agent-common": "^1.0.
|
|
52
|
+
"agent-common": "^1.0.2",
|
|
53
53
|
"better-sqlite3": "12.8.0",
|
|
54
54
|
"morphdom": "^2.7.8",
|
|
55
55
|
"ws": "8.20.0"
|