@agentdevjs/viewer 0.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/chunk-OPBQEOJC.js +8568 -0
- package/dist/chunk-OPBQEOJC.js.map +1 -0
- package/dist/cli/server.d.ts +1 -0
- package/dist/cli/server.js +43 -0
- package/dist/cli/server.js.map +1 -0
- package/dist/cli/viewer.d.ts +1 -0
- package/dist/cli/viewer.js +42 -0
- package/dist/cli/viewer.js.map +1 -0
- package/dist/index.d.ts +330 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ViewerWorker
|
|
4
|
+
} from "../chunk-OPBQEOJC.js";
|
|
5
|
+
|
|
6
|
+
// src/cli/server.ts
|
|
7
|
+
import { getDefaultUDSPath } from "@agentdevjs/core";
|
|
8
|
+
var DEFAULT_PORT = 2026;
|
|
9
|
+
async function main() {
|
|
10
|
+
const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);
|
|
11
|
+
const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== "false" && process.argv[3] !== "false";
|
|
12
|
+
const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4];
|
|
13
|
+
console.log("=".repeat(50));
|
|
14
|
+
console.log("ViewerWorker \u670D\u52A1\u5668\u542F\u52A8\u4E2D...");
|
|
15
|
+
console.log(` HTTP \u7AEF\u53E3: ${port}`);
|
|
16
|
+
console.log(` UDS \u8DEF\u5F84: ${udsPath || getDefaultUDSPath()}`);
|
|
17
|
+
console.log(` \u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668: ${openBrowser ? "\u662F" : "\u5426"}`);
|
|
18
|
+
console.log("=".repeat(50));
|
|
19
|
+
const worker = new ViewerWorker(port, openBrowser, udsPath);
|
|
20
|
+
try {
|
|
21
|
+
await worker.start();
|
|
22
|
+
console.log("\n\u2713 \u670D\u52A1\u5668\u5DF2\u542F\u52A8!");
|
|
23
|
+
console.log(`
|
|
24
|
+
\u8C03\u8BD5\u9875\u9762: http://localhost:${port}`);
|
|
25
|
+
console.log("\n\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668\n");
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error("\n\u2717 \u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25:", err);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
process.on("SIGINT", () => {
|
|
32
|
+
console.log("\n\n[Server] \u6B63\u5728\u505C\u6B62\u670D\u52A1\u5668...");
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
process.on("SIGTERM", () => {
|
|
36
|
+
console.log("\n\n[Server] \u6B63\u5728\u505C\u6B62\u670D\u52A1\u5668...");
|
|
37
|
+
process.exit(0);
|
|
38
|
+
});
|
|
39
|
+
main().catch((err) => {
|
|
40
|
+
console.error("[Server] \u672A\u5904\u7406\u7684\u9519\u8BEF:", err);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/server.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * ViewerWorker 服务器启动程序\n *\n * 用途:独立启动调试查看器服务器\n * 运行:npm run server [port] [no-browser] [uds-path]\n *\n * 功能:\n * - 启动 ViewerWorker 独立进程\n * - 服务器运行期间可以被多个 Agent 连接\n * - Ctrl+C 关闭服务器\n *\n * 参数:\n * port - HTTP 端口(默认 2026)\n * no-browser - 不自动打开浏览器(传递字符串 \"false\")\n * uds-path - 自定义 UDS 路径(可选)\n *\n * 环境变量:\n * AGENTDEV_PORT - HTTP 端口(默认 2026)\n * AGENTDEV_OPEN_BROWSER - 是否打开浏览器(默认 true)\n * AGENTDEV_UDS_PATH - UDS 路径(默认自动检测平台)\n */\n\nimport { ViewerWorker } from '../viewer-worker.js';\nimport { getDefaultUDSPath } from '@agentdevjs/core';\n\nconst DEFAULT_PORT = 2026;\n\nasync function main() {\n const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);\n const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== 'false' && process.argv[3] !== 'false';\n const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4];\n\n console.log('='.repeat(50));\n console.log('ViewerWorker 服务器启动中...');\n console.log(` HTTP 端口: ${port}`);\n console.log(` UDS 路径: ${udsPath || getDefaultUDSPath()}`);\n console.log(` 自动打开浏览器: ${openBrowser ? '是' : '否'}`);\n console.log('='.repeat(50));\n\n const worker = new ViewerWorker(port, openBrowser, udsPath);\n\n try {\n await worker.start();\n\n console.log('\\n✓ 服务器已启动!');\n console.log(`\\n调试页面: http://localhost:${port}`);\n console.log('\\n按 Ctrl+C 停止服务器\\n');\n\n // 保持运行,直到用户中断\n } catch (err) {\n console.error('\\n✗ 服务器启动失败:', err);\n process.exit(1);\n }\n}\n\n// 优雅退出\nprocess.on('SIGINT', () => {\n console.log('\\n\\n[Server] 正在停止服务器...');\n process.exit(0);\n});\n\nprocess.on('SIGTERM', () => {\n console.log('\\n\\n[Server] 正在停止服务器...');\n process.exit(0);\n});\n\nmain().catch((err) => {\n console.error('[Server] 未处理的错误:', err);\n process.exit(1);\n});\n"],"mappings":";;;;;;AAwBA,SAAS,yBAAyB;AAElC,IAAM,eAAe;AAErB,eAAe,OAAO;AACpB,QAAM,OAAO,SAAS,QAAQ,IAAI,iBAAiB,QAAQ,KAAK,CAAC,KAAK,OAAO,YAAY,GAAG,EAAE;AAC9F,QAAM,cAAc,QAAQ,IAAI,0BAA0B,WAAW,QAAQ,KAAK,CAAC,MAAM;AACzF,QAAM,UAAU,QAAQ,IAAI,qBAAqB,QAAQ,KAAK,CAAC;AAE/D,UAAQ,IAAI,IAAI,OAAO,EAAE,CAAC;AAC1B,UAAQ,IAAI,sDAAwB;AACpC,UAAQ,IAAI,wBAAc,IAAI,EAAE;AAChC,UAAQ,IAAI,uBAAa,WAAW,kBAAkB,CAAC,EAAE;AACzD,UAAQ,IAAI,iDAAc,cAAc,WAAM,QAAG,EAAE;AACnD,UAAQ,IAAI,IAAI,OAAO,EAAE,CAAC;AAE1B,QAAM,SAAS,IAAI,aAAa,MAAM,aAAa,OAAO;AAE1D,MAAI;AACF,UAAM,OAAO,MAAM;AAEnB,YAAQ,IAAI,gDAAa;AACzB,YAAQ,IAAI;AAAA,6CAA4B,IAAI,EAAE;AAC9C,YAAQ,IAAI,kDAAoB;AAAA,EAGlC,SAAS,KAAK;AACZ,YAAQ,MAAM,wDAAgB,GAAG;AACjC,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAGA,QAAQ,GAAG,UAAU,MAAM;AACzB,UAAQ,IAAI,4DAAyB;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;AAED,QAAQ,GAAG,WAAW,MAAM;AAC1B,UAAQ,IAAI,4DAAyB;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;AAED,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,MAAM,kDAAoB,GAAG;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ViewerWorker
|
|
4
|
+
} from "../chunk-OPBQEOJC.js";
|
|
5
|
+
|
|
6
|
+
// src/cli/viewer.ts
|
|
7
|
+
import { getDefaultUDSPath } from "@agentdevjs/core";
|
|
8
|
+
var DEFAULT_PORT = 2026;
|
|
9
|
+
async function main() {
|
|
10
|
+
const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4] || getDefaultUDSPath();
|
|
11
|
+
const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);
|
|
12
|
+
const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== "false" && process.argv[3] !== "false";
|
|
13
|
+
console.log(`[Viewer Worker] \u6B63\u5728\u542F\u52A8...`);
|
|
14
|
+
console.log(`[Viewer Worker] UDS: ${udsPath}`);
|
|
15
|
+
console.log(`[Viewer Worker] HTTP: http://localhost:${port}`);
|
|
16
|
+
const worker = new ViewerWorker(port, openBrowser, udsPath);
|
|
17
|
+
try {
|
|
18
|
+
await worker.start();
|
|
19
|
+
console.log("[Viewer Worker] \u542F\u52A8\u6210\u529F");
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error("[Viewer Worker] \u542F\u52A8\u5931\u8D25:", err);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
process.on("SIGINT", () => {
|
|
25
|
+
console.log("[Viewer Worker] \u6536\u5230\u9000\u51FA\u4FE1\u53F7\uFF0C\u6B63\u5728\u5173\u95ED...");
|
|
26
|
+
process.exit(0);
|
|
27
|
+
});
|
|
28
|
+
process.on("SIGTERM", () => {
|
|
29
|
+
console.log("[Viewer Worker] \u6536\u5230\u7EC8\u6B62\u4FE1\u53F7\uFF0C\u6B63\u5728\u5173\u95ED...");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
});
|
|
32
|
+
process.on("uncaughtException", (err) => {
|
|
33
|
+
console.error("[Viewer Worker] \u672A\u6355\u83B7\u5F02\u5E38:", err);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
process.on("unhandledRejection", (reason) => {
|
|
37
|
+
console.error("[Viewer Worker] \u672A\u5904\u7406\u7684 Promise \u62D2\u7EDD:", reason);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
main();
|
|
42
|
+
//# sourceMappingURL=viewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/viewer.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Viewer Worker Standalone CLI\n *\n * 独立启动 ViewerWorker 服务器的命令行工具\n *\n * 使用方法:\n * agentdev-viewer [port] [no-browser] [uds-path]\n *\n * 参数:\n * port - HTTP 端口(默认 2026)\n * no-browser - 不自动打开浏览器(传递 \"false\")\n * uds-path - 自定义 UDS 路径(可选)\n *\n * 环境变量:\n * AGENTDEV_UDS_PATH - UDS 路径(默认自动检测平台)\n * AGENTDEV_PORT - HTTP 端口(默认 2026)\n * AGENTDEV_OPEN_BROWSER - 是否打开浏览器(默认 true)\n */\n\nimport { ViewerWorker } from '../viewer-worker.js';\nimport { getDefaultUDSPath } from '@agentdevjs/core';\n\nconst DEFAULT_PORT = 2026;\n\nasync function main() {\n const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4] || getDefaultUDSPath();\n const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);\n const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== 'false' && process.argv[3] !== 'false';\n\n console.log(`[Viewer Worker] 正在启动...`);\n console.log(`[Viewer Worker] UDS: ${udsPath}`);\n console.log(`[Viewer Worker] HTTP: http://localhost:${port}`);\n\n const worker = new ViewerWorker(port, openBrowser, udsPath);\n\n try {\n await worker.start();\n console.log('[Viewer Worker] 启动成功');\n } catch (err) {\n console.error('[Viewer Worker] 启动失败:', err);\n process.exit(1);\n }\n\n // 防止进程退出(保持运行)\n process.on('SIGINT', () => {\n console.log('[Viewer Worker] 收到退出信号,正在关闭...');\n process.exit(0);\n });\n\n process.on('SIGTERM', () => {\n console.log('[Viewer Worker] 收到终止信号,正在关闭...');\n process.exit(0);\n });\n\n // 添加未捕获异常处理\n process.on('uncaughtException', (err) => {\n console.error('[Viewer Worker] 未捕获异常:', err);\n process.exit(1);\n });\n\n process.on('unhandledRejection', (reason) => {\n console.error('[Viewer Worker] 未处理的 Promise 拒绝:', reason);\n process.exit(1);\n });\n}\n\nmain();\n"],"mappings":";;;;;;AAqBA,SAAS,yBAAyB;AAElC,IAAM,eAAe;AAErB,eAAe,OAAO;AACpB,QAAM,UAAU,QAAQ,IAAI,qBAAqB,QAAQ,KAAK,CAAC,KAAK,kBAAkB;AACtF,QAAM,OAAO,SAAS,QAAQ,IAAI,iBAAiB,QAAQ,KAAK,CAAC,KAAK,OAAO,YAAY,GAAG,EAAE;AAC9F,QAAM,cAAc,QAAQ,IAAI,0BAA0B,WAAW,QAAQ,KAAK,CAAC,MAAM;AAEzF,UAAQ,IAAI,6CAAyB;AACrC,UAAQ,IAAI,wBAAwB,OAAO,EAAE;AAC7C,UAAQ,IAAI,0CAA0C,IAAI,EAAE;AAE5D,QAAM,SAAS,IAAI,aAAa,MAAM,aAAa,OAAO;AAE1D,MAAI;AACF,UAAM,OAAO,MAAM;AACnB,YAAQ,IAAI,0CAAsB;AAAA,EACpC,SAAS,KAAK;AACZ,YAAQ,MAAM,6CAAyB,GAAG;AAC1C,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,UAAQ,GAAG,UAAU,MAAM;AACzB,YAAQ,IAAI,uFAAgC;AAC5C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAED,UAAQ,GAAG,WAAW,MAAM;AAC1B,YAAQ,IAAI,uFAAgC;AAC5C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAGD,UAAQ,GAAG,qBAAqB,CAAC,QAAQ;AACvC,YAAQ,MAAM,mDAA0B,GAAG;AAC3C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAED,UAAQ,GAAG,sBAAsB,CAAC,WAAW;AAC3C,YAAQ,MAAM,kEAAoC,MAAM;AACxD,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACH;AAEA,KAAK;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import { UserTurnInput, UserTurnSubmissionResult, AgentSession, AgentOverviewSnapshot, TodoPlanSnapshot, InputRequestCancelledMsg, HookInspectorSnapshot, AgentLogsResponse, DebugLogEntry } from '@agentdevjs/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Viewer Worker - 在独立进程中运行 HTTP 服务器
|
|
6
|
+
* 支持多 Agent 调试,共享单端口
|
|
7
|
+
* 支持通过 UDS(Unix Domain Socket)或 Windows Named Pipe 接收来自多进程的连接
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare class ViewerWorker {
|
|
11
|
+
private port;
|
|
12
|
+
private openBrowser;
|
|
13
|
+
private server;
|
|
14
|
+
private udsPath;
|
|
15
|
+
private udsServer?;
|
|
16
|
+
private udsClients;
|
|
17
|
+
private agentSessions;
|
|
18
|
+
private templateMounts;
|
|
19
|
+
private templatePayloads;
|
|
20
|
+
private readonly debuggerMcp;
|
|
21
|
+
private readonly MAX_MESSAGES;
|
|
22
|
+
private readonly MAX_BYTES;
|
|
23
|
+
private readonly MAX_LOGS;
|
|
24
|
+
constructor(port: number, openBrowser?: boolean, udsPath?: string);
|
|
25
|
+
start(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 停止服务器
|
|
28
|
+
*/
|
|
29
|
+
stop(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 启动 UDS 服务器
|
|
32
|
+
*/
|
|
33
|
+
private startUDSServer;
|
|
34
|
+
/**
|
|
35
|
+
* 处理 UDS 消息(复用现有处理方法)
|
|
36
|
+
*/
|
|
37
|
+
private handleUDSMessage;
|
|
38
|
+
private handleRequest;
|
|
39
|
+
/**
|
|
40
|
+
* 主页 - 带多 Agent 切换器
|
|
41
|
+
*/
|
|
42
|
+
private handleIndex;
|
|
43
|
+
/**
|
|
44
|
+
* API 端点路由
|
|
45
|
+
*/
|
|
46
|
+
private handleAPI;
|
|
47
|
+
/**
|
|
48
|
+
* GET /api/agents - 获取所有 Agent
|
|
49
|
+
*/
|
|
50
|
+
private handleGetAgents;
|
|
51
|
+
/**
|
|
52
|
+
* GET /api/templates/feature - 获取 Feature 模板映射
|
|
53
|
+
*/
|
|
54
|
+
handleGetFeatureTemplates(req: IncomingMessage, res: ServerResponse, searchParams?: URLSearchParams): void;
|
|
55
|
+
/**
|
|
56
|
+
* 解析 npm workspace 符号链接
|
|
57
|
+
* 当 Feature 来自 npm workspace 时,import.meta.url 返回的是符号链接的真实物理路径
|
|
58
|
+
* 需要检查 node_modules 目录中的符号链接来确定包名
|
|
59
|
+
*/
|
|
60
|
+
private npmWorkspaceCache;
|
|
61
|
+
private resolveNpmWorkspacePackage;
|
|
62
|
+
/**
|
|
63
|
+
* GET /api/agents/:id/messages - 获取指定 Agent 的消息
|
|
64
|
+
*/
|
|
65
|
+
private handleGetAgentMessages;
|
|
66
|
+
/**
|
|
67
|
+
* GET /api/agents/:id/tools - 获取指定 Agent 的工具
|
|
68
|
+
*/
|
|
69
|
+
private handleGetAgentTools;
|
|
70
|
+
private handleGetAgentHooks;
|
|
71
|
+
private handleGetAgentOverview;
|
|
72
|
+
private handleGetAgentTodoPlan;
|
|
73
|
+
/**
|
|
74
|
+
* GET /api/agents/:id/notification - 获取指定 Agent 的通知状态
|
|
75
|
+
*/
|
|
76
|
+
private handleGetAgentNotification;
|
|
77
|
+
private handleGetLogs;
|
|
78
|
+
private handleGetMCPInfo;
|
|
79
|
+
/**
|
|
80
|
+
* GET /api/agents/:id/connection - 获取指定 Agent 的真实连接状态
|
|
81
|
+
*/
|
|
82
|
+
private handleGetAgentConnection;
|
|
83
|
+
/**
|
|
84
|
+
* DELETE /api/agents/:id - 删除已断开的 Agent 会话
|
|
85
|
+
*/
|
|
86
|
+
private handleDeleteAgent;
|
|
87
|
+
/**
|
|
88
|
+
* 获取输入请求列表
|
|
89
|
+
*/
|
|
90
|
+
private handleGetInputRequests;
|
|
91
|
+
/**
|
|
92
|
+
* 提交用户输入
|
|
93
|
+
*/
|
|
94
|
+
private handlePostInput;
|
|
95
|
+
/**
|
|
96
|
+
* 提交一个不绑定 requestId 的新用户回合。
|
|
97
|
+
*
|
|
98
|
+
* inputLease 与 queuedInputs 都由 ViewerWorker 持有,因此仲裁必须
|
|
99
|
+
* 在这里原子完成,不能由宿主先 GET 再 POST 拼接,否则会产生 TOCTOU 竞态。
|
|
100
|
+
*/
|
|
101
|
+
submitUserTurn(agentId: string, input: UserTurnInput): UserTurnSubmissionResult;
|
|
102
|
+
private handlePostUserTurn;
|
|
103
|
+
private forwardInputResponse;
|
|
104
|
+
private createTextInputResponse;
|
|
105
|
+
private enqueueQueuedInput;
|
|
106
|
+
/**
|
|
107
|
+
* 获取排队中的用户输入
|
|
108
|
+
*/
|
|
109
|
+
private handleGetQueuedInputs;
|
|
110
|
+
/**
|
|
111
|
+
* 消费第一条排队消息
|
|
112
|
+
*/
|
|
113
|
+
private handleDequeueInput;
|
|
114
|
+
/**
|
|
115
|
+
* 中断正在运行的 Agent
|
|
116
|
+
*/
|
|
117
|
+
private handleInterrupt;
|
|
118
|
+
/**
|
|
119
|
+
* 查询 Agent 是否正在运行
|
|
120
|
+
*/
|
|
121
|
+
private handleGetRunning;
|
|
122
|
+
/**
|
|
123
|
+
* 获取或创建会话
|
|
124
|
+
*/
|
|
125
|
+
getOrCreateSession(agentId: string, name: string): AgentSession;
|
|
126
|
+
/**
|
|
127
|
+
* 更新会话活跃时间
|
|
128
|
+
*/
|
|
129
|
+
updateSessionActivity(agentId: string): void;
|
|
130
|
+
private isSessionConnected;
|
|
131
|
+
/**
|
|
132
|
+
* 应用内存限制
|
|
133
|
+
*/
|
|
134
|
+
enforceMemoryLimits(session: AgentSession): void;
|
|
135
|
+
/**
|
|
136
|
+
* 处理注册 Agent
|
|
137
|
+
*/
|
|
138
|
+
handleRegisterAgent(msg: any, clientId?: string): void;
|
|
139
|
+
handleUpdateAgentInspector(msg: any): void;
|
|
140
|
+
handleUpdateAgentOverview(msg: {
|
|
141
|
+
agentId: string;
|
|
142
|
+
overview: AgentOverviewSnapshot;
|
|
143
|
+
}): void;
|
|
144
|
+
handleUpdateTodoPlan(msg: {
|
|
145
|
+
agentId: string;
|
|
146
|
+
plan: TodoPlanSnapshot;
|
|
147
|
+
}): void;
|
|
148
|
+
/**
|
|
149
|
+
* 清空 Feature 模板装载(当 Agent 断开连接时调用):
|
|
150
|
+
* 移除该 agent 的载荷,并对 mount 注册表做引用计数回收。
|
|
151
|
+
*/
|
|
152
|
+
private clearFeatureTemplates;
|
|
153
|
+
/**
|
|
154
|
+
* 处理推送消息(带去重优化)
|
|
155
|
+
*
|
|
156
|
+
* 只有在消息真正变化时才更新会话并触发前端更新
|
|
157
|
+
*/
|
|
158
|
+
handlePushMessages(msg: any): void;
|
|
159
|
+
private createEmptyOverview;
|
|
160
|
+
private createEmptyTodoPlan;
|
|
161
|
+
private normalizeTodoPlan;
|
|
162
|
+
private createEmptyRuntimeState;
|
|
163
|
+
private cloneRuntimeState;
|
|
164
|
+
private getRuntimeStageFromLLMPhase;
|
|
165
|
+
private updateRuntimeStage;
|
|
166
|
+
private getSessionRuntimeState;
|
|
167
|
+
private getMergedOverview;
|
|
168
|
+
/**
|
|
169
|
+
* 检查消息是否发生变化
|
|
170
|
+
*/
|
|
171
|
+
private hasMessagesChanged;
|
|
172
|
+
/**
|
|
173
|
+
* 获取最后一条消息的签名(用于变化检测)
|
|
174
|
+
*
|
|
175
|
+
* 使用消息的 role、content 和 toolCalls 生成签名
|
|
176
|
+
*/
|
|
177
|
+
private getLastMessageSignature;
|
|
178
|
+
/**
|
|
179
|
+
* 处理注册工具
|
|
180
|
+
*/
|
|
181
|
+
handleRegisterTools(msg: any): void;
|
|
182
|
+
/**
|
|
183
|
+
* 处理注销 Agent
|
|
184
|
+
*/
|
|
185
|
+
handleUnregisterAgent(msg: any): void;
|
|
186
|
+
/**
|
|
187
|
+
* 处理停止
|
|
188
|
+
*/
|
|
189
|
+
handleStop(): void;
|
|
190
|
+
/**
|
|
191
|
+
* 处理推送通知
|
|
192
|
+
*/
|
|
193
|
+
handlePushNotification(msg: any): void;
|
|
194
|
+
private normalizeLogEntry;
|
|
195
|
+
private withSessionLogContext;
|
|
196
|
+
private parseNumberParam;
|
|
197
|
+
private listAgentSummaries;
|
|
198
|
+
private getAgentDetails;
|
|
199
|
+
private queryLogs;
|
|
200
|
+
private handleMCP;
|
|
201
|
+
/**
|
|
202
|
+
* 处理用户输入请求
|
|
203
|
+
*/
|
|
204
|
+
handleRequestInput(msg: any): void;
|
|
205
|
+
/**
|
|
206
|
+
* 处理输入请求取消(运行时中断/销毁时由 DebugHub 发出)
|
|
207
|
+
* 只有 requestId 匹配当前租约时才清除,避免误删紧随其后重开的新租约。
|
|
208
|
+
*/
|
|
209
|
+
handleInputRequestCancelled(msg: InputRequestCancelledMsg): void;
|
|
210
|
+
/**
|
|
211
|
+
* mountId:装载根目录的稳定哈希(sha1 前 12 hex)。与 agent 无关,
|
|
212
|
+
* 同一 root 跨 agent / 跨注册复用同一 ID,浏览器模块缓存天然共享。
|
|
213
|
+
*/
|
|
214
|
+
private static mountIdForRoot;
|
|
215
|
+
/**
|
|
216
|
+
* /tpl/{mountId}/{rel...} — 模板装载资产服务。
|
|
217
|
+
* mount root 下的字节级镜像:模板文件、tsup 共享 chunk、sourcemap 同构命中。
|
|
218
|
+
* 唯一安全边界:resolve 后必须仍在 mount root 内(路径穿越防护)。
|
|
219
|
+
*/
|
|
220
|
+
handleTplAsset(req: IncomingMessage, res: ServerResponse, url: string): void;
|
|
221
|
+
private getHtml;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
interface DebuggerAgentSummary {
|
|
225
|
+
id: string;
|
|
226
|
+
name: string;
|
|
227
|
+
createdAt: number;
|
|
228
|
+
lastActive: number;
|
|
229
|
+
connected: boolean;
|
|
230
|
+
messageCount: number;
|
|
231
|
+
toolCount: number;
|
|
232
|
+
logCount: number;
|
|
233
|
+
hasHookInspector: boolean;
|
|
234
|
+
}
|
|
235
|
+
interface DebuggerAgentDetails extends DebuggerAgentSummary {
|
|
236
|
+
projectRoot?: string;
|
|
237
|
+
currentStateType?: string | null;
|
|
238
|
+
pendingInputCount: number;
|
|
239
|
+
hookInspector?: HookInspectorSnapshot;
|
|
240
|
+
}
|
|
241
|
+
interface DebuggerLogQuery {
|
|
242
|
+
scope?: 'current' | 'all';
|
|
243
|
+
agentId?: string | null;
|
|
244
|
+
level?: string;
|
|
245
|
+
namespace?: string;
|
|
246
|
+
feature?: string;
|
|
247
|
+
lifecycle?: string;
|
|
248
|
+
from?: number;
|
|
249
|
+
to?: number;
|
|
250
|
+
limit?: number;
|
|
251
|
+
offset?: number;
|
|
252
|
+
search?: string;
|
|
253
|
+
}
|
|
254
|
+
interface DebuggerMCPDataSource {
|
|
255
|
+
listAgents(): DebuggerAgentSummary[];
|
|
256
|
+
getAgent(agentId: string): DebuggerAgentDetails | undefined;
|
|
257
|
+
getHooks(agentId: string): HookInspectorSnapshot | undefined;
|
|
258
|
+
queryLogs(query: DebuggerLogQuery): AgentLogsResponse;
|
|
259
|
+
}
|
|
260
|
+
declare const DEBUGGER_MCP_TOOL_DEFINITIONS: readonly [{
|
|
261
|
+
readonly name: "list_agents";
|
|
262
|
+
readonly description: "List all debugger-visible agents and basic session status.";
|
|
263
|
+
}, {
|
|
264
|
+
readonly name: "get_agent";
|
|
265
|
+
readonly description: "Get a single agent by id. Supports \"self\".";
|
|
266
|
+
}, {
|
|
267
|
+
readonly name: "get_hooks";
|
|
268
|
+
readonly description: "Get the hook inspector snapshot for an agent.";
|
|
269
|
+
}, {
|
|
270
|
+
readonly name: "query_logs";
|
|
271
|
+
readonly description: "Query structured logs. Prefer adding filters to narrow results; unfiltered queries are auto-truncated.";
|
|
272
|
+
}];
|
|
273
|
+
declare const DEBUGGER_MCP_RESOURCE_DEFINITIONS: readonly [{
|
|
274
|
+
readonly uri: "debug://agents";
|
|
275
|
+
readonly description: "All visible debugger agents.";
|
|
276
|
+
}, {
|
|
277
|
+
readonly uri: "debug://agents/{agentId}";
|
|
278
|
+
readonly description: "Detailed agent session snapshot for a specific agent.";
|
|
279
|
+
}, {
|
|
280
|
+
readonly uri: "debug://agents/{agentId}/hooks";
|
|
281
|
+
readonly description: "Hook inspector snapshot for a specific agent.";
|
|
282
|
+
}];
|
|
283
|
+
declare const DEBUGGER_MCP_PROMPT_DEFINITIONS: readonly [{
|
|
284
|
+
readonly name: "analyze_errors";
|
|
285
|
+
readonly description: "Summarize recent error logs for an agent and suggest likely causes.";
|
|
286
|
+
}, {
|
|
287
|
+
readonly name: "review_hooks";
|
|
288
|
+
readonly description: "Review an agent hook snapshot and identify ordering or binding issues.";
|
|
289
|
+
}, {
|
|
290
|
+
readonly name: "diagnose_agent";
|
|
291
|
+
readonly description: "Produce a high-level diagnosis from the current agent snapshot, hooks, and recent warnings/errors.";
|
|
292
|
+
}];
|
|
293
|
+
declare class DebuggerMCPServer {
|
|
294
|
+
private readonly dataSource;
|
|
295
|
+
constructor(dataSource: DebuggerMCPDataSource);
|
|
296
|
+
handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
297
|
+
private createServer;
|
|
298
|
+
private registerTools;
|
|
299
|
+
private registerResources;
|
|
300
|
+
private registerPrompts;
|
|
301
|
+
/**
|
|
302
|
+
* 解析 agent 引用。'self' 解析为 callerAgentId;'current' 伪 ID 已随服务端
|
|
303
|
+
* current 语义移除,显式报错引导调用方传显式 ID;缺省返回 null(由调用方决定
|
|
304
|
+
* 如何呈现"未指定")。
|
|
305
|
+
*/
|
|
306
|
+
private resolvePromptAgent;
|
|
307
|
+
private resolveAgentRef;
|
|
308
|
+
private stringVar;
|
|
309
|
+
}
|
|
310
|
+
declare function createDebuggerAgentSummary(session: AgentSession, connected: boolean): DebuggerAgentSummary;
|
|
311
|
+
declare function createDebuggerAgentDetails(session: AgentSession, connected: boolean): DebuggerAgentDetails;
|
|
312
|
+
declare function filterDebuggerLogs(logs: DebugLogEntry[], query: Omit<DebuggerLogQuery, 'scope'> & {
|
|
313
|
+
limit?: number;
|
|
314
|
+
offset?: number;
|
|
315
|
+
}): DebugLogEntry[];
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Viewer HTML Template - 调试器前端 HTML 模板(拆分版)
|
|
319
|
+
*
|
|
320
|
+
* 原始的单文件 viewer-html.ts 已按职责拆分为同目录下的多个模块。
|
|
321
|
+
* 本文件负责将各模块按正确顺序拼接为完整的 HTML 字符串。
|
|
322
|
+
*/
|
|
323
|
+
/**
|
|
324
|
+
* 生成调试器前端页面的完整 HTML
|
|
325
|
+
* @param port - HTTP 服务器端口号(保留用于 API 兼容,当前未使用)
|
|
326
|
+
* @returns 完整的 HTML 字符串
|
|
327
|
+
*/
|
|
328
|
+
declare function generateViewerHtml(port: number): string;
|
|
329
|
+
|
|
330
|
+
export { DEBUGGER_MCP_PROMPT_DEFINITIONS, DEBUGGER_MCP_RESOURCE_DEFINITIONS, DEBUGGER_MCP_TOOL_DEFINITIONS, type DebuggerAgentDetails, type DebuggerAgentSummary, type DebuggerLogQuery, DebuggerMCPServer, ViewerWorker, createDebuggerAgentDetails, createDebuggerAgentSummary, filterDebuggerLogs, generateViewerHtml };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEBUGGER_MCP_PROMPT_DEFINITIONS,
|
|
3
|
+
DEBUGGER_MCP_RESOURCE_DEFINITIONS,
|
|
4
|
+
DEBUGGER_MCP_TOOL_DEFINITIONS,
|
|
5
|
+
DebuggerMCPServer,
|
|
6
|
+
ViewerWorker,
|
|
7
|
+
createDebuggerAgentDetails,
|
|
8
|
+
createDebuggerAgentSummary,
|
|
9
|
+
filterDebuggerLogs,
|
|
10
|
+
generateViewerHtml
|
|
11
|
+
} from "./chunk-OPBQEOJC.js";
|
|
12
|
+
export {
|
|
13
|
+
DEBUGGER_MCP_PROMPT_DEFINITIONS,
|
|
14
|
+
DEBUGGER_MCP_RESOURCE_DEFINITIONS,
|
|
15
|
+
DEBUGGER_MCP_TOOL_DEFINITIONS,
|
|
16
|
+
DebuggerMCPServer,
|
|
17
|
+
ViewerWorker,
|
|
18
|
+
createDebuggerAgentDetails,
|
|
19
|
+
createDebuggerAgentSummary,
|
|
20
|
+
filterDebuggerLogs,
|
|
21
|
+
generateViewerHtml
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentdevjs/viewer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AgentDev debugger viewer: ViewerWorker HTTP/UDS host, web UI, read-only debugger MCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"agentdev-viewer": "dist/cli/viewer.js",
|
|
16
|
+
"agentdev-server": "dist/cli/server.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@agentdevjs/core": "^0.1.0",
|
|
32
|
+
"@modelcontextprotocol/node": "^2.0.0",
|
|
33
|
+
"@modelcontextprotocol/server": "^2.0.0",
|
|
34
|
+
"open": "^11.0.0",
|
|
35
|
+
"zod": "^4.1.5"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@modelcontextprotocol/client": "^2.0.0",
|
|
39
|
+
"@types/node": "^20.11.0",
|
|
40
|
+
"tsup": "^8.3.5",
|
|
41
|
+
"tsx": "^4.7.0",
|
|
42
|
+
"typescript": "^5.3.3",
|
|
43
|
+
"vitest": "^4.1.10"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"agentdev",
|
|
50
|
+
"debugger",
|
|
51
|
+
"viewer",
|
|
52
|
+
"mcp"
|
|
53
|
+
],
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/your-org/agentdev.git"
|
|
57
|
+
},
|
|
58
|
+
"license": "MIT"
|
|
59
|
+
}
|