@autotest/agent 0.0.6 → 0.0.8
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/README.md +7 -0
- package/dist/.buildstamp +1 -0
- package/dist/api/agent_api.d.ts +2 -2
- package/dist/autotest-cli.js +1 -397
- package/dist/common/config/config.yaml +4 -0
- package/dist/common/config/manager.d.ts +4 -4
- package/dist/common/config/types.d.ts +5 -0
- package/dist/common/dfx/index.d.ts +1 -1
- package/dist/core/agent/single_agent/agent.d.ts +1 -0
- package/dist/core/device/device_protocol.d.ts +1 -1
- package/dist/core/device/hdc/device.d.ts +5 -2
- package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
- package/dist/core/knowledge/vectordb.d.ts +5 -5
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +2 -0
- package/dist/core/mcp/mcp_tools.d.ts +1 -0
- package/dist/core/mcp/verify_tool.d.ts +12 -0
- package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
- package/dist/data_types/device.d.ts +1 -1
- package/dist/data_types/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -163
- package/dist/tools/batch_runner.js +1 -745
- package/dist/tools/case_runner/runner.js +1 -410
- package/dist/tools/config/config_tool.js +1 -339
- package/dist/tools/prompt_compare/compare_runner.js +1 -360
- package/package.json +2 -2
- package/dist/api/agent_api.js +0 -550
- package/dist/api/autotest_agent.js +0 -205
- package/dist/api/types.js +0 -11
- package/dist/common/case_manager.js +0 -91
- package/dist/common/collect_case.js +0 -128
- package/dist/common/common_errors.js +0 -66
- package/dist/common/config/config_validator.js +0 -28
- package/dist/common/config/manager.js +0 -257
- package/dist/common/config/output.js +0 -59
- package/dist/common/config/types.js +0 -185
- package/dist/common/dfx/client_factory.js +0 -62
- package/dist/common/dfx/context.js +0 -23
- package/dist/common/dfx/index.js +0 -15
- package/dist/common/dfx/recorder.js +0 -191
- package/dist/common/dfx/recording_fetch.js +0 -228
- package/dist/common/dfx/source.js +0 -13
- package/dist/common/image_cacher.js +0 -36
- package/dist/common/image_helper.js +0 -128
- package/dist/common/image_similarity.js +0 -171
- package/dist/common/llm_cache/cache_transport.js +0 -102
- package/dist/common/llm_cache/prompt_cache.js +0 -113
- package/dist/common/logger.js +0 -158
- package/dist/common/model/custom_model.js +0 -487
- package/dist/common/model/index.js +0 -5
- package/dist/common/path_utils.js +0 -88
- package/dist/common/result_parser.js +0 -49
- package/dist/common/usage/token_usage.js +0 -117
- package/dist/common/utils.js +0 -125
- package/dist/core/agent/layered_agent/ability_helper.js +0 -125
- package/dist/core/agent/layered_agent/agent.js +0 -37
- package/dist/core/agent/layered_agent/agent_registry.js +0 -82
- package/dist/core/agent/layered_agent/decision.js +0 -518
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
- package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
- package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
- package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
- package/dist/core/agent/report_analyzer_agent/config.js +0 -22
- package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
- package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
- package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
- package/dist/core/agent/report_analyzer_agent/index.js +0 -52
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
- package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
- package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
- package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
- package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
- package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
- package/dist/core/agent/report_analyzer_agent/types.js +0 -274
- package/dist/core/agent/rewrite_agent/agent.js +0 -209
- package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
- package/dist/core/agent/rewrite_agent/mapping.js +0 -56
- package/dist/core/agent/rewrite_agent/parse.js +0 -121
- package/dist/core/agent/rewrite_agent/types.js +0 -37
- package/dist/core/agent/single_agent/agent.js +0 -801
- package/dist/core/agent/single_agent/hook_manager.js +0 -59
- package/dist/core/agent/single_agent/hooks.js +0 -288
- package/dist/core/agent/single_agent/image_utils.js +0 -158
- package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
- package/dist/core/agent/single_agent/subagent_manager.js +0 -72
- package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
- package/dist/core/agent/types.js +0 -2
- package/dist/core/agent/utils/message_builder.js +0 -138
- package/dist/core/device/device_protocol.js +0 -2
- package/dist/core/device/hdc/apps.js +0 -437
- package/dist/core/device/hdc/device.js +0 -219
- package/dist/core/device/hdc/index.js +0 -31
- package/dist/core/device/hdc/input.js +0 -74
- package/dist/core/device/hdc/screenshot.js +0 -171
- package/dist/core/device/index.js +0 -70
- package/dist/core/device/types.js +0 -2
- package/dist/core/knowledge/knowledge_manager.js +0 -70
- package/dist/core/knowledge/vectordb.js +0 -283
- package/dist/core/mcp/adapter_factory.js +0 -99
- package/dist/core/mcp/android_adapter.js +0 -286
- package/dist/core/mcp/base_adapter.js +0 -86
- package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
- package/dist/core/mcp/ios_adapter.js +0 -286
- package/dist/core/mcp/local_tools.js +0 -41
- package/dist/core/mcp/mcp_tools.js +0 -473
- package/dist/core/mcp/types.js +0 -6
- package/dist/core/memory/_utils.js +0 -140
- package/dist/core/memory/compressed_session.js +0 -182
- package/dist/core/memory/context_compressor.js +0 -176
- package/dist/core/memory/index.js +0 -22
- package/dist/core/memory/memory_manager.js +0 -28
- package/dist/core/memory/reflector.js +0 -95
- package/dist/core/memory/replan_manager.js +0 -12
- package/dist/core/memory/session_factory.js +0 -29
- package/dist/core/memory/tool_player.js +0 -225
- package/dist/core/memory/tool_player_popup.js +0 -276
- package/dist/core/memory/tool_player_replan.js +0 -226
- package/dist/core/memory/tool_player_xpath.js +0 -139
- package/dist/core/memory/tool_recorder.js +0 -126
- package/dist/core/preprocessor/task_splitter.js +0 -112
- package/dist/core/prompt/prompt_loader.js +0 -315
- package/dist/core/skill/skill_manager.js +0 -302
- package/dist/data_types/action.js +0 -2
- package/dist/data_types/agent.js +0 -2
- package/dist/data_types/case.js +0 -57
- package/dist/data_types/device.js +0 -2
- package/dist/data_types/index.js +0 -11
- package/dist/data_types/report.js +0 -6
- package/dist/data_types/screen.js +0 -23
- package/dist/data_types/task.js +0 -2
- package/dist/loop/cli.js +0 -127
- package/dist/loop/orchestrator.js +0 -314
- package/dist/loop/result_writer.js +0 -260
- package/dist/loop/types.js +0 -82
- package/dist/mcp-server/server.js +0 -341
- package/dist/mcp-server/types.js +0 -224
- package/dist/reporter/batch_summary.js +0 -197
- package/dist/reporter/generator.js +0 -286
- package/dist/reporter/html_template/index.js +0 -529
- package/dist/reporter/json_report.js +0 -6
- package/dist/reporter/types.js +0 -45
- package/dist/tools/case_runner/report.js +0 -264
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Loop 结果落盘 —
|
|
4
|
-
*
|
|
5
|
-
* writeLoopResultJson: 序列化 LoopResult → loop_result.json(写在 finalReportDir 父目录)。
|
|
6
|
-
* writeLoopSummaryHtml: 生成 loop_summary.html(Loop 汇总 + 各轮执行/分析报告 iframe 标签页)。
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.writeLoopResultJson = writeLoopResultJson;
|
|
43
|
-
exports.writeLoopSummaryHtml = writeLoopSummaryHtml;
|
|
44
|
-
const fs = __importStar(require("fs"));
|
|
45
|
-
const path = __importStar(require("path"));
|
|
46
|
-
const logger_1 = require("../common/logger");
|
|
47
|
-
const types_1 = require("./types");
|
|
48
|
-
function findReportHtml(reportDir) {
|
|
49
|
-
if (!reportDir || !fs.existsSync(reportDir))
|
|
50
|
-
return null;
|
|
51
|
-
const conventional = path.join(reportDir, `${path.basename(reportDir)}.html`);
|
|
52
|
-
if (fs.existsSync(conventional))
|
|
53
|
-
return conventional;
|
|
54
|
-
const htmls = fs
|
|
55
|
-
.readdirSync(reportDir)
|
|
56
|
-
.filter((f) => f.endsWith('.html'))
|
|
57
|
-
.sort();
|
|
58
|
-
return htmls.length > 0 ? path.join(reportDir, htmls[0]) : null;
|
|
59
|
-
}
|
|
60
|
-
function findAnalysisHtml(reportDir) {
|
|
61
|
-
if (!reportDir || !fs.existsSync(reportDir))
|
|
62
|
-
return null;
|
|
63
|
-
// Node.js analyzer 写 analysis_report/, 写 analysis/,兼容两者
|
|
64
|
-
for (const sub of ['analysis_report', 'analysis']) {
|
|
65
|
-
const dir = path.join(reportDir, sub);
|
|
66
|
-
if (fs.existsSync(dir)) {
|
|
67
|
-
const htmls = fs.readdirSync(dir).filter((f) => f.endsWith('.html')).sort();
|
|
68
|
-
if (htmls.length > 0)
|
|
69
|
-
return path.join(dir, htmls[0]);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
function escapeHtml(s) {
|
|
75
|
-
return (s ?? '')
|
|
76
|
-
.replace(/&/g, '&')
|
|
77
|
-
.replace(/</g, '<')
|
|
78
|
-
.replace(/>/g, '>')
|
|
79
|
-
.replace(/"/g, '"');
|
|
80
|
-
}
|
|
81
|
-
const ACTION_LABELS = {
|
|
82
|
-
rewrite_task: '改写任务',
|
|
83
|
-
add_knowledge: '追加知识',
|
|
84
|
-
both: '改写+知识',
|
|
85
|
-
no_rewrite: '无需改写',
|
|
86
|
-
};
|
|
87
|
-
function buildIterationOverviewHtml(iterations) {
|
|
88
|
-
if (iterations.length === 0)
|
|
89
|
-
return '<p class="warn">无迭代记录</p>';
|
|
90
|
-
const rows = iterations
|
|
91
|
-
.map((it) => {
|
|
92
|
-
const summary = it.analyzerOutputSummary ?? {};
|
|
93
|
-
const iterStatus = String(summary['task_result_status'] ?? '—') || '—';
|
|
94
|
-
const rc = summary['root_cause'];
|
|
95
|
-
const iterCategory = rc ? String(rc['category'] ?? '—') : '—';
|
|
96
|
-
const iterSubCategory = rc ? String(rc['sub_category'] ?? '—') : '—';
|
|
97
|
-
const actionRaw = it.rewriteAction ?? '';
|
|
98
|
-
const actionLabel = actionRaw === '' ? '—' : ACTION_LABELS[actionRaw] ?? actionRaw;
|
|
99
|
-
return (`<tr><td>${it.iteration}</td>` +
|
|
100
|
-
`<td class="status-${escapeHtml(iterStatus.toLowerCase())}">${escapeHtml(iterStatus)}</td>` +
|
|
101
|
-
`<td>${escapeHtml(iterCategory)}</td>` +
|
|
102
|
-
`<td>${escapeHtml(iterSubCategory)}</td>` +
|
|
103
|
-
`<td>${escapeHtml(actionLabel)}</td></tr>`);
|
|
104
|
-
})
|
|
105
|
-
.join('');
|
|
106
|
-
return ('<div class="iteration-overview"><h2>各轮概览</h2>' +
|
|
107
|
-
'<table class="iter-overview-table"><thead><tr>' +
|
|
108
|
-
'<th>轮次</th><th>执行结果</th><th>根因分类</th><th>根因子类</th><th>改写动作</th>' +
|
|
109
|
-
`</tr></thead><tbody>${rows}</tbody></table></div>`);
|
|
110
|
-
}
|
|
111
|
-
function buildTaskEvolutionHtml(originalTask, finalTask, iterations) {
|
|
112
|
-
const rewriteEntries = [];
|
|
113
|
-
for (const it of iterations) {
|
|
114
|
-
if ((it.rewriteAction === 'rewrite_task' || it.rewriteAction === 'both') &&
|
|
115
|
-
it.rewrittenTask) {
|
|
116
|
-
rewriteEntries.push({ iter: it.iteration, task: it.rewrittenTask });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const cards = [];
|
|
120
|
-
cards.push(`<div class="evolution-card evolution-start"><div class="card-label">原始任务</div>` +
|
|
121
|
-
`<div class="card-text">${escapeHtml(originalTask)}</div></div>`);
|
|
122
|
-
for (const e of rewriteEntries) {
|
|
123
|
-
cards.push(`<div class="evolution-card evolution-rewrite"><div class="card-label">第 ${e.iter} 轮改写</div>` +
|
|
124
|
-
`<div class="card-text">${escapeHtml(e.task)}</div></div>`);
|
|
125
|
-
}
|
|
126
|
-
cards.push(`<div class="evolution-card evolution-end"><div class="card-label">最终任务</div>` +
|
|
127
|
-
`<div class="card-text">${escapeHtml(finalTask)}</div></div>`);
|
|
128
|
-
const note = rewriteEntries.length === 0 && originalTask === finalTask
|
|
129
|
-
? '<p class="evolution-note">任务未发生变化</p>'
|
|
130
|
-
: '';
|
|
131
|
-
return (`<div class="task-evolution"><h2>任务演进</h2>` +
|
|
132
|
-
`<div class="evolution-timeline">${cards.join('')}</div>${note}</div>`);
|
|
133
|
-
}
|
|
134
|
-
/** 写 loop_result.json。finalReportDir 为空时安全降级返回 null。 */
|
|
135
|
-
function writeLoopResultJson(result, finalReportDir) {
|
|
136
|
-
if (!finalReportDir) {
|
|
137
|
-
logger_1.logger.warn('writeLoopResultJson: finalReportDir 为空,跳过 loop_result.json');
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const outputPath = path.join(path.dirname(finalReportDir), 'loop_result.json');
|
|
141
|
-
try {
|
|
142
|
-
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
143
|
-
fs.writeFileSync(outputPath, JSON.stringify((0, types_1.loopResultToDict)(result), null, 2), 'utf-8');
|
|
144
|
-
logger_1.logger.info(`Loop result written to ${outputPath}`);
|
|
145
|
-
return outputPath;
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
logger_1.logger.error(`Failed to write loop_result.json to ${outputPath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/** 生成 loop_summary.html(iframe 内嵌各轮报告)。 */
|
|
153
|
-
function writeLoopSummaryHtml(result, finalReportDir) {
|
|
154
|
-
if (!finalReportDir) {
|
|
155
|
-
logger_1.logger.warn('writeLoopSummaryHtml: finalReportDir 为空,跳过 loop_summary.html');
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
// report 根:多轮(iter_N)→ 父目录;单轮 → 本身
|
|
159
|
-
const summaryDir = path.basename(finalReportDir).startsWith('iter_')
|
|
160
|
-
? path.dirname(finalReportDir)
|
|
161
|
-
: finalReportDir;
|
|
162
|
-
const outputPath = path.join(summaryDir, 'loop_summary.html');
|
|
163
|
-
try {
|
|
164
|
-
fs.mkdirSync(summaryDir, { recursive: true });
|
|
165
|
-
}
|
|
166
|
-
catch (e) {
|
|
167
|
-
logger_1.logger.error(`Failed to create summary dir ${summaryDir}: ${e instanceof Error ? e.message : String(e)}`);
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
const tabButtons = [];
|
|
171
|
-
const tabContents = [];
|
|
172
|
-
let lastIterNum = 0;
|
|
173
|
-
// Tab 1: Loop 汇总
|
|
174
|
-
tabButtons.push(`<button class="tab" onclick="showTab('loop-summary')">Loop 汇总</button>`);
|
|
175
|
-
const iterOverview = buildIterationOverviewHtml(result.iterations);
|
|
176
|
-
const taskEvolution = buildTaskEvolutionHtml(result.originalTask, result.finalTask, result.iterations);
|
|
177
|
-
tabContents.push(`<div class="tab-content" id="loop-summary" style="display:none">` +
|
|
178
|
-
`<div class="header"><h1>Loop 汇总报告</h1>` +
|
|
179
|
-
`<p><strong>终止原因:</strong><span class="term">${escapeHtml(result.terminationReason || 'unknown')}</span></p>` +
|
|
180
|
-
`<p><strong>总迭代数:</strong>${result.totalIterations}</p>` +
|
|
181
|
-
`<p><strong>原始任务:</strong>${escapeHtml(result.originalTask)}</p>` +
|
|
182
|
-
`<p><strong>最终任务:</strong>${escapeHtml(result.finalTask)}</p></div>` +
|
|
183
|
-
`${iterOverview}${taskEvolution}</div>`);
|
|
184
|
-
// 各轮:执行报告 + 分析报告
|
|
185
|
-
for (const it of result.iterations) {
|
|
186
|
-
lastIterNum = it.iteration;
|
|
187
|
-
tabButtons.push(`<button class="tab" onclick="showTab('iter-${it.iteration}-exec')">Iter ${it.iteration} 执行报告</button>`);
|
|
188
|
-
tabButtons.push(`<button class="tab" onclick="showTab('iter-${it.iteration}-analysis')">Iter ${it.iteration} 分析报告</button>`);
|
|
189
|
-
const execHtml = findReportHtml(it.reportDir);
|
|
190
|
-
const execContent = execHtml
|
|
191
|
-
? `<iframe src="${escapeHtml(path.relative(summaryDir, execHtml).split(path.sep).join('/'))}"></iframe>`
|
|
192
|
-
: '<p class="warn">未找到执行报告 HTML</p>';
|
|
193
|
-
tabContents.push(`<div class="tab-content" id="iter-${it.iteration}-exec" style="display:none">${execContent}</div>`);
|
|
194
|
-
const analysisHtml = findAnalysisHtml(it.reportDir);
|
|
195
|
-
const analysisContent = analysisHtml
|
|
196
|
-
? `<iframe src="${escapeHtml(path.relative(summaryDir, analysisHtml).split(path.sep).join('/'))}"></iframe>`
|
|
197
|
-
: '<p class="warn">未找到分析报告 HTML</p>';
|
|
198
|
-
tabContents.push(`<div class="tab-content" id="iter-${it.iteration}-analysis" style="display:none">${analysisContent}</div>`);
|
|
199
|
-
}
|
|
200
|
-
const defaultTab = lastIterNum > 0 ? `'iter-${lastIterNum}-exec'` : `'loop-summary'`;
|
|
201
|
-
const pageHtml = `<!DOCTYPE html>
|
|
202
|
-
<html lang="zh">
|
|
203
|
-
<head><meta charset="utf-8"><title>Loop 汇总报告</title>
|
|
204
|
-
<style>
|
|
205
|
-
body { font-family: -apple-system, "Segoe UI", sans-serif; margin: 0; display: flex; flex-direction: column; height: 100vh; background: #f7f7f7; }
|
|
206
|
-
.header { background: #fff; padding: 16px 20px; border-radius: 8px; margin: 12px 20px 16px 20px; }
|
|
207
|
-
.header h1 { margin: 0 0 12px 0; font-size: 22px; }
|
|
208
|
-
.header p { margin: 4px 0; font-size: 14px; word-break: break-all; }
|
|
209
|
-
.term { color: #c0392b; font-weight: 600; }
|
|
210
|
-
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex-shrink: 0; }
|
|
211
|
-
.tab { padding: 8px 16px; border: 1px solid #ddd; border-bottom: none; border-radius: 6px 6px 0 0; background: #eee; cursor: pointer; font-size: 14px; color: #555; outline: none; }
|
|
212
|
-
.tab:hover { background: #e0e0e0; }
|
|
213
|
-
.tab.active { background: #fff; color: #2980b9; font-weight: 600; }
|
|
214
|
-
.tab-content { background: #fff; flex: 1; overflow: auto; padding: 0; }
|
|
215
|
-
iframe { width: 100%; height: 100%; border: none; background: #fff; }
|
|
216
|
-
.warn { color: #b8860b; font-style: italic; font-size: 13px; padding: 12px 20px; }
|
|
217
|
-
.iteration-overview, .task-evolution { margin: 0 20px 16px 20px; }
|
|
218
|
-
.iteration-overview h2, .task-evolution h2 { font-size: 18px; margin: 0 0 10px 0; }
|
|
219
|
-
.iter-overview-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
220
|
-
.iter-overview-table th, .iter-overview-table td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
|
|
221
|
-
.iter-overview-table th { background: #f5f5f5; font-weight: 600; }
|
|
222
|
-
.iter-overview-table .status-pass { color: #27ae60; font-weight: 600; }
|
|
223
|
-
.iter-overview-table .status-fail { color: #c0392b; font-weight: 600; }
|
|
224
|
-
.evolution-timeline { position: relative; padding-left: 24px; border-left: 2px solid #ddd; }
|
|
225
|
-
.evolution-card { position: relative; margin-bottom: 14px; padding: 10px 14px; background: #f9f9f9; border-radius: 6px; border: 1px solid #eee; }
|
|
226
|
-
.evolution-card::before { content: ''; position: absolute; left: -30px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: #3498db; border: 2px solid #fff; }
|
|
227
|
-
.card-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
|
|
228
|
-
.card-text { font-size: 13px; word-break: break-all; white-space: pre-wrap; }
|
|
229
|
-
.evolution-note { color: #7f8c8d; font-style: italic; font-size: 13px; margin: 8px 0 0 0; }
|
|
230
|
-
</style>
|
|
231
|
-
</head>
|
|
232
|
-
<body>
|
|
233
|
-
<div class="tabs">${tabButtons.join('')}</div>
|
|
234
|
-
${tabContents.join('')}
|
|
235
|
-
<script>
|
|
236
|
-
function showTab(tabId) {
|
|
237
|
-
var contents = document.querySelectorAll('.tab-content');
|
|
238
|
-
for (var i = 0; i < contents.length; i++) { contents[i].style.display = 'none'; }
|
|
239
|
-
var target = document.getElementById(tabId);
|
|
240
|
-
if (target) target.style.display = 'block';
|
|
241
|
-
var tabs = document.querySelectorAll('.tab');
|
|
242
|
-
for (var i = 0; i < tabs.length; i++) {
|
|
243
|
-
tabs[i].classList.remove('active');
|
|
244
|
-
if (tabs[i].getAttribute('onclick') === "showTab('" + tabId + "')") { tabs[i].classList.add('active'); }
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
showTab(${defaultTab});
|
|
248
|
-
</script>
|
|
249
|
-
</body>
|
|
250
|
-
</html>`;
|
|
251
|
-
try {
|
|
252
|
-
fs.writeFileSync(outputPath, pageHtml, 'utf-8');
|
|
253
|
-
logger_1.logger.info(`Loop summary HTML written to ${outputPath}`);
|
|
254
|
-
return outputPath;
|
|
255
|
-
}
|
|
256
|
-
catch (e) {
|
|
257
|
-
logger_1.logger.error(`Failed to write loop_summary.html to ${outputPath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
}
|
package/dist/loop/types.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Loop 闭环类型定义 —
|
|
4
|
-
*
|
|
5
|
-
* 5 种执行模式 + 6 个状态机状态 + 5 类终止原因 + 迭代记录 + 闭环结果。
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.TerminationReason = exports.LoopStatus = exports.LoopMode = void 0;
|
|
9
|
-
exports.createLoopResult = createLoopResult;
|
|
10
|
-
exports.iterationRecordToDict = iterationRecordToDict;
|
|
11
|
-
exports.loopResultToDict = loopResultToDict;
|
|
12
|
-
/** Loop 执行模式枚举(决定状态机跳步策略)。 */
|
|
13
|
-
var LoopMode;
|
|
14
|
-
(function (LoopMode) {
|
|
15
|
-
/** 完整闭环:执行→归因→改写→重执行,最多 max_loops 轮,生成 iter_N 目录 + loop_summary.html + loop_result.json */
|
|
16
|
-
LoopMode["FULL_LOOP"] = "full_loop";
|
|
17
|
-
/** 执行 + 归因(不触发改写,单轮即终止) */
|
|
18
|
-
LoopMode["EXECUTE_ANALYZE"] = "execute_analyze";
|
|
19
|
-
/** 仅执行(不做归因和改写,单轮即终止) */
|
|
20
|
-
LoopMode["EXECUTE_ONLY"] = "execute_only";
|
|
21
|
-
/** 仅归因(跳过执行,直接对已有报告做根因分析) */
|
|
22
|
-
LoopMode["ANALYZE_ONLY"] = "analyze_only";
|
|
23
|
-
/** 仅改写(跳过执行和归因,直接对已有分析结果做改写) */
|
|
24
|
-
LoopMode["REWRITE_ONLY"] = "rewrite_only";
|
|
25
|
-
})(LoopMode || (exports.LoopMode = LoopMode = {}));
|
|
26
|
-
/** Loop 编排器状态枚举(状态机各阶段)。 */
|
|
27
|
-
var LoopStatus;
|
|
28
|
-
(function (LoopStatus) {
|
|
29
|
-
LoopStatus["INIT"] = "init";
|
|
30
|
-
LoopStatus["EXECUTING"] = "executing";
|
|
31
|
-
LoopStatus["ATTRIBUTING"] = "attributing";
|
|
32
|
-
LoopStatus["REWRITING"] = "rewriting";
|
|
33
|
-
LoopStatus["RE_EXECUTING"] = "re_executing";
|
|
34
|
-
LoopStatus["TERMINATED"] = "terminated";
|
|
35
|
-
})(LoopStatus || (exports.LoopStatus = LoopStatus = {}));
|
|
36
|
-
/** Loop 终止原因枚举。 */
|
|
37
|
-
var TerminationReason;
|
|
38
|
-
(function (TerminationReason) {
|
|
39
|
-
/** 任务通过 */
|
|
40
|
-
TerminationReason["PASSED"] = "passed";
|
|
41
|
-
/** 不可改写(应用/环境/无问题/未知 category/决策表 NO_REWRITE) */
|
|
42
|
-
TerminationReason["UNREWRITEABLE"] = "unrewriteable";
|
|
43
|
-
/** 达到 max_loops 上限 */
|
|
44
|
-
TerminationReason["MAX_LOOPS"] = "max_loops";
|
|
45
|
-
/** 连续 2 次相同 failure signature */
|
|
46
|
-
TerminationReason["DEAD_LOOP"] = "dead_loop";
|
|
47
|
-
/** analyzer 或 rewriter 异常 */
|
|
48
|
-
TerminationReason["ERROR"] = "error";
|
|
49
|
-
})(TerminationReason || (exports.TerminationReason = TerminationReason = {}));
|
|
50
|
-
/** 构造一个空的 LoopResult。 */
|
|
51
|
-
function createLoopResult() {
|
|
52
|
-
return {
|
|
53
|
-
iterations: [],
|
|
54
|
-
finalReportDir: null,
|
|
55
|
-
terminationReason: '',
|
|
56
|
-
totalIterations: 0,
|
|
57
|
-
originalTask: '',
|
|
58
|
-
finalTask: '',
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/** 序列化 IterationRecord 为普通对象(用于 JSON 落盘)。 */
|
|
62
|
-
function iterationRecordToDict(it) {
|
|
63
|
-
return {
|
|
64
|
-
iteration: it.iteration,
|
|
65
|
-
report_dir: it.reportDir,
|
|
66
|
-
analyzer_output_summary: it.analyzerOutputSummary,
|
|
67
|
-
rewrite_action: it.rewriteAction,
|
|
68
|
-
rewritten_task: it.rewrittenTask ?? null,
|
|
69
|
-
knowledge_text: it.knowledgeText ?? '',
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/** 序列化 LoopResult 为普通对象(用于 loop_result.json 落盘)。 */
|
|
73
|
-
function loopResultToDict(result) {
|
|
74
|
-
return {
|
|
75
|
-
iterations: result.iterations.map(iterationRecordToDict),
|
|
76
|
-
final_report_dir: result.finalReportDir,
|
|
77
|
-
termination_reason: result.terminationReason,
|
|
78
|
-
total_iterations: result.totalIterations,
|
|
79
|
-
original_task: result.originalTask,
|
|
80
|
-
final_task: result.finalTask,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.McpServerImpl = void 0;
|
|
37
|
-
const http = __importStar(require("http"));
|
|
38
|
-
const types_1 = require("./types");
|
|
39
|
-
const SCHEMA_MAP = {
|
|
40
|
-
// Device operations (35)
|
|
41
|
-
[types_1.McpServerToolName.CLICK]: types_1.ClickInputSchema,
|
|
42
|
-
[types_1.McpServerToolName.DOUBLE_CLICK]: types_1.DoubleClickInputSchema,
|
|
43
|
-
[types_1.McpServerToolName.LONG_CLICK]: types_1.LongClickInputSchema,
|
|
44
|
-
[types_1.McpServerToolName.SWIPE]: types_1.SwipeInputSchema,
|
|
45
|
-
[types_1.McpServerToolName.DRAG]: types_1.DragInputSchema,
|
|
46
|
-
[types_1.McpServerToolName.INPUT_TEXT]: types_1.InputTextInputSchema,
|
|
47
|
-
[types_1.McpServerToolName.CLEAR_TEXT]: types_1.ClearTextInputSchema,
|
|
48
|
-
[types_1.McpServerToolName.GO_BACK]: types_1.GoBackInputSchema,
|
|
49
|
-
[types_1.McpServerToolName.GO_HOME]: types_1.GoHomeInputSchema,
|
|
50
|
-
[types_1.McpServerToolName.START_APP]: types_1.StartAppInputSchema,
|
|
51
|
-
[types_1.McpServerToolName.STOP_APP]: types_1.StopAppInputSchema,
|
|
52
|
-
[types_1.McpServerToolName.CLEAR_APP_DATA]: types_1.ClearAppDataInputSchema,
|
|
53
|
-
[types_1.McpServerToolName.WAIT]: types_1.WaitInputSchema,
|
|
54
|
-
[types_1.McpServerToolName.PRESS_KEY]: types_1.PressKeyInputSchema,
|
|
55
|
-
[types_1.McpServerToolName.SCREEN_ON]: types_1.ScreenOnInputSchema,
|
|
56
|
-
[types_1.McpServerToolName.SCREEN_OFF]: types_1.ScreenOffInputSchema,
|
|
57
|
-
[types_1.McpServerToolName.UNLOCK_SCREEN]: types_1.UnlockScreenInputSchema,
|
|
58
|
-
[types_1.McpServerToolName.CLEAR_RECENT_TASK]: types_1.ClearRecentTaskInputSchema,
|
|
59
|
-
[types_1.McpServerToolName.ENTER_RECENT_TASK]: types_1.EnterRecentTaskInputSchema,
|
|
60
|
-
[types_1.McpServerToolName.GET_CURRENT_APP]: types_1.GetCurrentAppInputSchema,
|
|
61
|
-
[types_1.McpServerToolName.SCREENSHOT]: types_1.ScreenshotInputSchema,
|
|
62
|
-
[types_1.McpServerToolName.LAYOUT]: types_1.LayoutInputSchema,
|
|
63
|
-
[types_1.McpServerToolName.MCP_CLEAN_UP]: types_1.McpCleanUpInputSchema,
|
|
64
|
-
[types_1.McpServerToolName.OPEN_CONTROL_CENTER]: types_1.OpenControlCenterInputSchema,
|
|
65
|
-
[types_1.McpServerToolName.OPEN_NOTIFICATION_CENTER]: types_1.OpenNotificationCenterInputSchema,
|
|
66
|
-
[types_1.McpServerToolName.PINCH_IN]: types_1.PinchInInputSchema,
|
|
67
|
-
[types_1.McpServerToolName.PINCH_OUT]: types_1.PinchOutInputSchema,
|
|
68
|
-
[types_1.McpServerToolName.ROTATE_GESTURE]: types_1.RotateGestureInputSchema,
|
|
69
|
-
[types_1.McpServerToolName.ROTATE_SCREEN]: types_1.RotateScreenInputSchema,
|
|
70
|
-
[types_1.McpServerToolName.STOP_ALL_APP]: types_1.StopAllAppInputSchema,
|
|
71
|
-
[types_1.McpServerToolName.START_LISTEN_TOAST]: types_1.StartListenToastInputSchema,
|
|
72
|
-
[types_1.McpServerToolName.GET_TOAST]: types_1.GetToastInputSchema,
|
|
73
|
-
[types_1.McpServerToolName.START_DATA_COLLECT]: types_1.StartDataCollectInputSchema,
|
|
74
|
-
[types_1.McpServerToolName.STOP_DATA_COLLECT]: types_1.StopDataCollectInputSchema,
|
|
75
|
-
[types_1.McpServerToolName.GENERATE_REPORT]: types_1.GenerateReportInputSchema,
|
|
76
|
-
// Management (7)
|
|
77
|
-
[types_1.McpServerToolName.LIST_DEVICES]: types_1.ListDevicesInputSchema,
|
|
78
|
-
[types_1.McpServerToolName.RUN_TASK]: types_1.RunTaskInputSchema,
|
|
79
|
-
[types_1.McpServerToolName.GET_TASK_RESULT]: types_1.GetTaskResultInputSchema,
|
|
80
|
-
[types_1.McpServerToolName.RESUME_TASK]: types_1.ResumeTaskInputSchema,
|
|
81
|
-
[types_1.McpServerToolName.ANALYZE_FAILURE]: types_1.AnalyzeFailureInputSchema,
|
|
82
|
-
[types_1.McpServerToolName.GET_CONFIG]: types_1.GetConfigInputSchema,
|
|
83
|
-
[types_1.McpServerToolName.UPDATE_CONFIG]: types_1.UpdateConfigInputSchema,
|
|
84
|
-
};
|
|
85
|
-
const DEVICE_TOOL_NAMES = new Set([
|
|
86
|
-
types_1.McpServerToolName.CLICK,
|
|
87
|
-
types_1.McpServerToolName.DOUBLE_CLICK,
|
|
88
|
-
types_1.McpServerToolName.LONG_CLICK,
|
|
89
|
-
types_1.McpServerToolName.SWIPE,
|
|
90
|
-
types_1.McpServerToolName.DRAG,
|
|
91
|
-
types_1.McpServerToolName.INPUT_TEXT,
|
|
92
|
-
types_1.McpServerToolName.CLEAR_TEXT,
|
|
93
|
-
types_1.McpServerToolName.GO_BACK,
|
|
94
|
-
types_1.McpServerToolName.GO_HOME,
|
|
95
|
-
types_1.McpServerToolName.START_APP,
|
|
96
|
-
types_1.McpServerToolName.STOP_APP,
|
|
97
|
-
types_1.McpServerToolName.CLEAR_APP_DATA,
|
|
98
|
-
types_1.McpServerToolName.WAIT,
|
|
99
|
-
types_1.McpServerToolName.PRESS_KEY,
|
|
100
|
-
types_1.McpServerToolName.SCREEN_ON,
|
|
101
|
-
types_1.McpServerToolName.SCREEN_OFF,
|
|
102
|
-
types_1.McpServerToolName.UNLOCK_SCREEN,
|
|
103
|
-
types_1.McpServerToolName.CLEAR_RECENT_TASK,
|
|
104
|
-
types_1.McpServerToolName.ENTER_RECENT_TASK,
|
|
105
|
-
types_1.McpServerToolName.GET_CURRENT_APP,
|
|
106
|
-
types_1.McpServerToolName.SCREENSHOT,
|
|
107
|
-
types_1.McpServerToolName.LAYOUT,
|
|
108
|
-
types_1.McpServerToolName.MCP_CLEAN_UP,
|
|
109
|
-
types_1.McpServerToolName.OPEN_CONTROL_CENTER,
|
|
110
|
-
types_1.McpServerToolName.OPEN_NOTIFICATION_CENTER,
|
|
111
|
-
types_1.McpServerToolName.PINCH_IN,
|
|
112
|
-
types_1.McpServerToolName.PINCH_OUT,
|
|
113
|
-
types_1.McpServerToolName.ROTATE_GESTURE,
|
|
114
|
-
types_1.McpServerToolName.ROTATE_SCREEN,
|
|
115
|
-
types_1.McpServerToolName.STOP_ALL_APP,
|
|
116
|
-
types_1.McpServerToolName.START_LISTEN_TOAST,
|
|
117
|
-
types_1.McpServerToolName.GET_TOAST,
|
|
118
|
-
types_1.McpServerToolName.START_DATA_COLLECT,
|
|
119
|
-
types_1.McpServerToolName.STOP_DATA_COLLECT,
|
|
120
|
-
types_1.McpServerToolName.GENERATE_REPORT,
|
|
121
|
-
]);
|
|
122
|
-
class McpServerImpl {
|
|
123
|
-
server = null;
|
|
124
|
-
config;
|
|
125
|
-
agentApi;
|
|
126
|
-
constructor(config, agentApi) {
|
|
127
|
-
this.config = config;
|
|
128
|
-
this.agentApi = agentApi;
|
|
129
|
-
}
|
|
130
|
-
async start() {
|
|
131
|
-
this.server = http.createServer((req, res) => this.handleRequest(req, res));
|
|
132
|
-
await new Promise((resolve, reject) => {
|
|
133
|
-
this.server.listen(this.config.port, this.config.host, () => resolve());
|
|
134
|
-
this.server.on('error', (err) => reject(err));
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async stop() {
|
|
138
|
-
if (!this.server)
|
|
139
|
-
return;
|
|
140
|
-
await new Promise((resolve) => {
|
|
141
|
-
this.server.close(() => resolve());
|
|
142
|
-
});
|
|
143
|
-
this.server = null;
|
|
144
|
-
}
|
|
145
|
-
handleRequest(req, res) {
|
|
146
|
-
if (req.method !== 'POST') {
|
|
147
|
-
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
148
|
-
res.end(JSON.stringify({ error: 'Method not allowed' }));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
let body = '';
|
|
152
|
-
req.on('data', (chunk) => { body += chunk; });
|
|
153
|
-
req.on('end', async () => {
|
|
154
|
-
let response;
|
|
155
|
-
try {
|
|
156
|
-
const rpcReq = JSON.parse(body);
|
|
157
|
-
response = await this.routeRequest(rpcReq);
|
|
158
|
-
}
|
|
159
|
-
catch (err) {
|
|
160
|
-
response = {
|
|
161
|
-
jsonrpc: '2.0',
|
|
162
|
-
id: null,
|
|
163
|
-
error: {
|
|
164
|
-
code: -32700,
|
|
165
|
-
message: 'Parse error',
|
|
166
|
-
data: err instanceof Error ? err.message : String(err),
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
171
|
-
res.end(JSON.stringify(response));
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
async routeRequest(req) {
|
|
175
|
-
const id = req.id ?? null;
|
|
176
|
-
if (req.method === 'tools/list') {
|
|
177
|
-
const tools = Object.values(types_1.McpServerToolName).map((name) => {
|
|
178
|
-
const schema = SCHEMA_MAP[name];
|
|
179
|
-
return {
|
|
180
|
-
name,
|
|
181
|
-
description: types_1.TOOL_DESCRIPTIONS[name] ?? `Tool: ${name}`,
|
|
182
|
-
inputSchema: schema ? this.zodToJsonSchema(schema) : {},
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
return { jsonrpc: '2.0', id, result: { tools } };
|
|
186
|
-
}
|
|
187
|
-
if (req.method === 'tools/call') {
|
|
188
|
-
const params = req.params ?? {};
|
|
189
|
-
const toolName = params.name;
|
|
190
|
-
const args = (params.arguments ?? params.input ?? {});
|
|
191
|
-
return await this.callTool(toolName, args, id);
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
jsonrpc: '2.0',
|
|
195
|
-
id,
|
|
196
|
-
error: { code: -32601, message: `Method not found: ${req.method}` },
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
async callTool(toolName, args, id) {
|
|
200
|
-
const schema = SCHEMA_MAP[toolName];
|
|
201
|
-
if (!schema) {
|
|
202
|
-
return {
|
|
203
|
-
jsonrpc: '2.0',
|
|
204
|
-
id,
|
|
205
|
-
error: { code: -32601, message: `Unknown tool: ${toolName}` },
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
const parsed = schema.safeParse(args);
|
|
209
|
-
if (!parsed.success) {
|
|
210
|
-
return {
|
|
211
|
-
jsonrpc: '2.0',
|
|
212
|
-
id,
|
|
213
|
-
error: {
|
|
214
|
-
code: -32602,
|
|
215
|
-
message: 'Invalid params',
|
|
216
|
-
data: parsed.error.issues,
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
try {
|
|
221
|
-
let result;
|
|
222
|
-
switch (toolName) {
|
|
223
|
-
case types_1.McpServerToolName.LIST_DEVICES:
|
|
224
|
-
result = await this.agentApi.listDevices();
|
|
225
|
-
break;
|
|
226
|
-
case types_1.McpServerToolName.RUN_TASK: {
|
|
227
|
-
const input = parsed.data;
|
|
228
|
-
result = await this.agentApi.runTask(input.task, {
|
|
229
|
-
agentMode: input.agentMode,
|
|
230
|
-
deviceId: input.deviceId,
|
|
231
|
-
platform: input.platform,
|
|
232
|
-
promptVersion: input.promptVersion,
|
|
233
|
-
configOverrides: input.configOverrides,
|
|
234
|
-
reportDir: input.reportDir,
|
|
235
|
-
feedbackMode: input.feedbackMode,
|
|
236
|
-
callbackUrl: input.callbackUrl,
|
|
237
|
-
});
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case types_1.McpServerToolName.GET_TASK_RESULT: {
|
|
241
|
-
const input = parsed.data;
|
|
242
|
-
result = await this.agentApi.getTaskResult(input.taskId);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
case types_1.McpServerToolName.RESUME_TASK: {
|
|
246
|
-
const input = parsed.data;
|
|
247
|
-
result = await this.agentApi.resumeTask(input.taskId, input.startIndex);
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
case types_1.McpServerToolName.ANALYZE_FAILURE: {
|
|
251
|
-
const input = parsed.data;
|
|
252
|
-
result = await this.agentApi.analyzeFailure(input.taskId, input.caseIdx);
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
case types_1.McpServerToolName.GET_CONFIG:
|
|
256
|
-
result = this.agentApi.getConfig();
|
|
257
|
-
break;
|
|
258
|
-
case types_1.McpServerToolName.UPDATE_CONFIG:
|
|
259
|
-
{
|
|
260
|
-
const input = parsed.data;
|
|
261
|
-
result = this.agentApi.updateConfig(input.partial);
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
// Device operations: delegate to adapter.callTool()
|
|
265
|
-
if (DEVICE_TOOL_NAMES.has(toolName)) {
|
|
266
|
-
result = await this.agentApi.callDeviceTool(toolName, parsed.data);
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
default:
|
|
270
|
-
return {
|
|
271
|
-
jsonrpc: '2.0',
|
|
272
|
-
id,
|
|
273
|
-
error: { code: -32601, message: `Unhandled tool: ${toolName}` },
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
return { jsonrpc: '2.0', id, result };
|
|
277
|
-
}
|
|
278
|
-
catch (err) {
|
|
279
|
-
return {
|
|
280
|
-
jsonrpc: '2.0',
|
|
281
|
-
id,
|
|
282
|
-
error: {
|
|
283
|
-
code: -32603,
|
|
284
|
-
message: 'Internal error',
|
|
285
|
-
data: err instanceof Error ? err.message : String(err),
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
zodToJsonSchema(schema) {
|
|
291
|
-
const def = schema._def;
|
|
292
|
-
if (!def)
|
|
293
|
-
return { type: 'object' };
|
|
294
|
-
const typeName = def.typeName;
|
|
295
|
-
if (typeName === 'ZodObject') {
|
|
296
|
-
const shape = def.shape ?? {};
|
|
297
|
-
const properties = {};
|
|
298
|
-
const required = [];
|
|
299
|
-
for (const [key, val] of Object.entries(shape)) {
|
|
300
|
-
properties[key] = this.zodToJsonSchema(val);
|
|
301
|
-
const innerDef = val._def;
|
|
302
|
-
if (innerDef?.typeName !== 'ZodDefault' &&
|
|
303
|
-
innerDef?.typeName !== 'ZodOptional') {
|
|
304
|
-
required.push(key);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return {
|
|
308
|
-
type: 'object',
|
|
309
|
-
properties,
|
|
310
|
-
required,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
if (typeName === 'ZodString')
|
|
314
|
-
return { type: 'string' };
|
|
315
|
-
if (typeName === 'ZodNumber')
|
|
316
|
-
return { type: 'number' };
|
|
317
|
-
if (typeName === 'ZodBoolean')
|
|
318
|
-
return { type: 'boolean' };
|
|
319
|
-
if (typeName === 'ZodInteger')
|
|
320
|
-
return { type: 'integer' };
|
|
321
|
-
if (typeName === 'ZodEnum') {
|
|
322
|
-
return { type: 'string', enum: def.values ?? [] };
|
|
323
|
-
}
|
|
324
|
-
if (typeName === 'ZodDefault') {
|
|
325
|
-
return this.zodToJsonSchema(def.innerType);
|
|
326
|
-
}
|
|
327
|
-
if (typeName === 'ZodOptional') {
|
|
328
|
-
return this.zodToJsonSchema(def.innerType);
|
|
329
|
-
}
|
|
330
|
-
if (typeName === 'ZodNullable') {
|
|
331
|
-
return this.zodToJsonSchema(def.innerType);
|
|
332
|
-
}
|
|
333
|
-
if (typeName === 'ZodRecord')
|
|
334
|
-
return { type: 'object' };
|
|
335
|
-
if (typeName === 'ZodArray') {
|
|
336
|
-
return { type: 'array', items: this.zodToJsonSchema(def.element) };
|
|
337
|
-
}
|
|
338
|
-
return { type: 'object' };
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
exports.McpServerImpl = McpServerImpl;
|