@autotest/agent 0.0.6 → 0.0.7
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/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/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 +1 -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,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Replan mixin for ToolPlayer.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Contains the replan prompt builder and the triggerReplan method.
|
|
7
|
-
* Delegates to a replanCallback callable so the host application owns the
|
|
8
|
-
* replanning lifecycle.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ReplanMixin = void 0;
|
|
12
|
-
const logger_1 = require("../../common/logger");
|
|
13
|
-
class ReplanMixin {
|
|
14
|
-
host;
|
|
15
|
-
constructor(host) {
|
|
16
|
-
this.host = host;
|
|
17
|
-
}
|
|
18
|
-
buildReplanPrompt(originalTask, fullHistory, failureInfo) {
|
|
19
|
-
const failureReason = failureInfo.failureReason ?? failureInfo.failure_reason ?? '未知原因';
|
|
20
|
-
const failedStep = failureInfo.failedStep ?? failureInfo.failed_step ?? '未知步骤';
|
|
21
|
-
const suggestion = failureInfo.suggestion ?? '';
|
|
22
|
-
const historyText = ReplanMixin.formatHistoryForReplan(fullHistory);
|
|
23
|
-
return `## 任务执行失败,需要重新规划
|
|
24
|
-
|
|
25
|
-
### 原始任务
|
|
26
|
-
${originalTask}
|
|
27
|
-
|
|
28
|
-
### 已回放的步骤
|
|
29
|
-
${historyText}
|
|
30
|
-
|
|
31
|
-
### 当前失败信息
|
|
32
|
-
- **失败原因**: ${failureReason}
|
|
33
|
-
- **失败步骤**: ${failedStep}
|
|
34
|
-
|
|
35
|
-
### 重新规划要求
|
|
36
|
-
请分析失败原因和执行历史,重新规划执行方案:
|
|
37
|
-
1. 查看完整执行历史,理解之前的成功步骤和当前失败
|
|
38
|
-
2. 检查失败原因,判断是否需要更换操作方式
|
|
39
|
-
3. 如果目标选项不存在,尝试寻找替代方案
|
|
40
|
-
4. 如果操作方式不对,调整操作策略
|
|
41
|
-
5. 输出新的执行指令
|
|
42
|
-
|
|
43
|
-
${suggestion ? suggestion + '\n' : ''}
|
|
44
|
-
请根据以上分析,给出新的执行方案。
|
|
45
|
-
`;
|
|
46
|
-
}
|
|
47
|
-
static formatHistoryForReplan(fullHistory) {
|
|
48
|
-
if (!fullHistory || fullHistory.length === 0)
|
|
49
|
-
return '无执行历史';
|
|
50
|
-
const lines = [];
|
|
51
|
-
for (let i = 0; i < fullHistory.length; i++) {
|
|
52
|
-
const rec = fullHistory[i];
|
|
53
|
-
const toolName = rec.toolName ?? rec.tool_name ?? 'unknown';
|
|
54
|
-
const args = rec.arguments ?? {};
|
|
55
|
-
const result = rec.result ?? '';
|
|
56
|
-
const messageRaw = args['message'];
|
|
57
|
-
let messageText;
|
|
58
|
-
if (typeof messageRaw === 'string') {
|
|
59
|
-
messageText = messageRaw;
|
|
60
|
-
}
|
|
61
|
-
else if (messageRaw !== null && messageRaw !== undefined) {
|
|
62
|
-
messageText = String(messageRaw);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
messageText = '';
|
|
66
|
-
}
|
|
67
|
-
if (typeof messageText === 'string' && messageText.trim().startsWith('{')) {
|
|
68
|
-
messageText = ReplanMixin.extractActionDescription(messageText);
|
|
69
|
-
}
|
|
70
|
-
const [resultText, isSuccess] = ReplanMixin.parseResultSummary(result);
|
|
71
|
-
let stepSummary;
|
|
72
|
-
if (toolName === 'execute') {
|
|
73
|
-
stepSummary = `执行:${messageText || '操作'}`;
|
|
74
|
-
}
|
|
75
|
-
else if (toolName === 'verify') {
|
|
76
|
-
const desc = args['description'] ?? '检查';
|
|
77
|
-
stepSummary = `验证:${desc}`;
|
|
78
|
-
if (resultText && resultText.length > 5) {
|
|
79
|
-
stepSummary += ` - ${resultText.slice(0, 40)}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
stepSummary = toolName;
|
|
84
|
-
if (resultText && resultText.length > 5) {
|
|
85
|
-
stepSummary += ` - ${resultText.slice(0, 40)}`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const statusIcon = isSuccess ? '✅' : '❌';
|
|
89
|
-
lines.push(` ${i + 1}. ${statusIcon} ${stepSummary}`);
|
|
90
|
-
}
|
|
91
|
-
return lines.join('\n');
|
|
92
|
-
}
|
|
93
|
-
static extractActionDescription(messageText) {
|
|
94
|
-
try {
|
|
95
|
-
const msgData = JSON.parse(messageText);
|
|
96
|
-
const action = msgData['action'] ?? '操作';
|
|
97
|
-
const log = msgData['log'];
|
|
98
|
-
if (log)
|
|
99
|
-
return log;
|
|
100
|
-
const actionDescriptions = {
|
|
101
|
-
click: '点击', double_click: '双击', long_click: '长按',
|
|
102
|
-
swipe: '滑动', input: '输入',
|
|
103
|
-
};
|
|
104
|
-
return actionDescriptions[action] ?? action;
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
return messageText;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
static parseResultSummary(result) {
|
|
111
|
-
if (result === null || result === undefined)
|
|
112
|
-
return ['无结果', true];
|
|
113
|
-
if (typeof result === 'boolean')
|
|
114
|
-
return [result ? '成功' : '失败', result];
|
|
115
|
-
if (typeof result === 'object' && !Array.isArray(result)) {
|
|
116
|
-
const obj = result;
|
|
117
|
-
let isSuccess = true;
|
|
118
|
-
if ('success' in obj)
|
|
119
|
-
isSuccess = Boolean(obj['success']);
|
|
120
|
-
let resultText = '';
|
|
121
|
-
if ('result' in obj)
|
|
122
|
-
resultText = String(obj['result']);
|
|
123
|
-
else if ('message' in obj)
|
|
124
|
-
resultText = String(obj['message']);
|
|
125
|
-
else if ('error' in obj) {
|
|
126
|
-
resultText = String(obj['error']);
|
|
127
|
-
isSuccess = false;
|
|
128
|
-
}
|
|
129
|
-
else
|
|
130
|
-
resultText = String(result);
|
|
131
|
-
return [resultText, isSuccess];
|
|
132
|
-
}
|
|
133
|
-
if (Array.isArray(result)) {
|
|
134
|
-
if (result.length === 0)
|
|
135
|
-
return ['空列表', true];
|
|
136
|
-
if (result.length === 1)
|
|
137
|
-
return ReplanMixin.parseResultSummary(result[0]);
|
|
138
|
-
return [`列表(${result.length}项)`, true];
|
|
139
|
-
}
|
|
140
|
-
if (typeof result === 'string') {
|
|
141
|
-
let resultText = result;
|
|
142
|
-
let isSuccess = true;
|
|
143
|
-
if (resultText.startsWith('{') || resultText.startsWith('[')) {
|
|
144
|
-
try {
|
|
145
|
-
const parsed = JSON.parse(resultText);
|
|
146
|
-
return ReplanMixin.parseResultSummary(parsed);
|
|
147
|
-
}
|
|
148
|
-
catch { /* ignore */ }
|
|
149
|
-
}
|
|
150
|
-
if (resultText.includes('[FAILURE]') || resultText.includes('[FAIL]') || resultText.includes('[ERROR]')) {
|
|
151
|
-
isSuccess = false;
|
|
152
|
-
}
|
|
153
|
-
else if (resultText.includes('[SUCCESS]') || resultText.includes('[OK]') || resultText.includes('[DONE]')) {
|
|
154
|
-
isSuccess = true;
|
|
155
|
-
}
|
|
156
|
-
else if (resultText.toLowerCase().startsWith('error')) {
|
|
157
|
-
isSuccess = false;
|
|
158
|
-
}
|
|
159
|
-
if (resultText.includes('[SUCCESS]')) {
|
|
160
|
-
const match = resultText.match(/\[SUCCESS\]\s*([\s\S]+)/);
|
|
161
|
-
if (match)
|
|
162
|
-
resultText = match[1].trim().split('\n')[0].slice(0, 60);
|
|
163
|
-
}
|
|
164
|
-
else if (resultText.includes('[FAILURE]')) {
|
|
165
|
-
const match = resultText.match(/\[FAILURE\]\s*([\s\S]+)/);
|
|
166
|
-
if (match)
|
|
167
|
-
resultText = match[1].trim().split('\n')[0].slice(0, 60);
|
|
168
|
-
}
|
|
169
|
-
return [resultText, isSuccess];
|
|
170
|
-
}
|
|
171
|
-
return [String(result), true];
|
|
172
|
-
}
|
|
173
|
-
async triggerReplan(failureInfo, remainingTimeout) {
|
|
174
|
-
if (this.host.replanTriggered) {
|
|
175
|
-
logger_1.logger.warning('[ToolPlayer] Replan already triggered, skipping duplicate call');
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
this.host.replanTriggered = true;
|
|
179
|
-
if (!this.host.replanCallback) {
|
|
180
|
-
logger_1.logger.warning('[ToolPlayer] No replanCallback available, cannot replan');
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const originalTask = this.host.currentSession?.task ?? failureInfo.originalTask ?? failureInfo.original_task ?? '未知任务';
|
|
184
|
-
const failedStepIndex = failureInfo.failedStepIndex ?? failureInfo.failed_step_index ?? 0;
|
|
185
|
-
const fullHistory = this.host.currentRecordings.slice(0, failedStepIndex);
|
|
186
|
-
const replanPrompt = this.buildReplanPrompt(originalTask, fullHistory, failureInfo);
|
|
187
|
-
logger_1.logger.warning(`[ToolPlayer] Triggering replan with prompt:\n${replanPrompt}`);
|
|
188
|
-
const timeout = remainingTimeout ?? this.host.config?.taskTimeout ?? this.host.config?.task_timeout ?? 1800;
|
|
189
|
-
logger_1.logger.info(`[ToolPlayer] Replan timeout: ${timeout}s`);
|
|
190
|
-
try {
|
|
191
|
-
const replanPromise = this.host.replanCallback(replanPrompt);
|
|
192
|
-
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout * 1000));
|
|
193
|
-
const replanResult = await Promise.race([replanPromise, timeoutPromise]);
|
|
194
|
-
const resultStr = replanResult ? String(replanResult) : '';
|
|
195
|
-
logger_1.logger.info(`[ToolPlayer] Replan completed: ${resultStr}`);
|
|
196
|
-
if (!this.host.lastPlaybackResults)
|
|
197
|
-
this.host.lastPlaybackResults = [];
|
|
198
|
-
this.host.lastPlaybackResults.push({
|
|
199
|
-
order: -1,
|
|
200
|
-
tool_name: 'replan',
|
|
201
|
-
arguments: { prompt: replanPrompt },
|
|
202
|
-
original_result: null,
|
|
203
|
-
playback_result: resultStr,
|
|
204
|
-
success: true,
|
|
205
|
-
is_replan: true,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
catch (e) {
|
|
209
|
-
const errMsg = e instanceof Error ? e.message : String(e);
|
|
210
|
-
logger_1.logger.error(`[ToolPlayer] Replan failed: ${errMsg}`);
|
|
211
|
-
if (!this.host.lastPlaybackResults)
|
|
212
|
-
this.host.lastPlaybackResults = [];
|
|
213
|
-
this.host.lastPlaybackResults.push({
|
|
214
|
-
order: -1,
|
|
215
|
-
tool_name: 'replan',
|
|
216
|
-
arguments: { prompt: replanPrompt },
|
|
217
|
-
original_result: null,
|
|
218
|
-
playback_result: errMsg.includes('timeout') ? `Timeout after ${timeout}s` : errMsg,
|
|
219
|
-
success: false,
|
|
220
|
-
error: errMsg,
|
|
221
|
-
is_replan: true,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.ReplanMixin = ReplanMixin;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* XPath-based component finding and tool execution mixin for ToolPlayer.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* NOTE: The version depends on `hypium` (a -only HarmonyOS UI
|
|
8
|
-
* test framework that provides XPath-based component finding via UiDriver)
|
|
9
|
-
* and the `agents` SDK (ToolContext/Usage). Neither exists in Node.js.
|
|
10
|
-
*
|
|
11
|
-
* The framework-agnostic helpers (coordinate parsing, normalization, bounds
|
|
12
|
-
* center calculation) are ported faithfully. The hypium-dependent methods
|
|
13
|
-
* (tryXpathExecution, findBestComponentByXpath, getDriver, getHypiumBy)
|
|
14
|
-
* are structural stubs that log warnings and return null, signaling the
|
|
15
|
-
* caller to fall back to tool-registry execution.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.XpathMixin = exports.ACTION_MAP = void 0;
|
|
19
|
-
const logger_1 = require("../../common/logger");
|
|
20
|
-
const _utils_1 = require("./_utils");
|
|
21
|
-
exports.ACTION_MAP = {
|
|
22
|
-
click: 'Tap',
|
|
23
|
-
double_click: 'Double Tap',
|
|
24
|
-
long_click: 'Long Press',
|
|
25
|
-
drag: 'Drag',
|
|
26
|
-
swipe: 'Swipe',
|
|
27
|
-
pinch_in: 'Pinch In',
|
|
28
|
-
pinch_out: 'Pinch Out',
|
|
29
|
-
input_text: 'Type',
|
|
30
|
-
clear_text: 'Clear Text',
|
|
31
|
-
};
|
|
32
|
-
class XpathMixin {
|
|
33
|
-
host;
|
|
34
|
-
constructor(host) {
|
|
35
|
-
this.host = host;
|
|
36
|
-
}
|
|
37
|
-
static parseBoundsCenter(bounds) {
|
|
38
|
-
if (!bounds)
|
|
39
|
-
return null;
|
|
40
|
-
const match = String(bounds).match(/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/);
|
|
41
|
-
if (!match)
|
|
42
|
-
return null;
|
|
43
|
-
const [, x1, y1, x2, y2] = match.map(Number);
|
|
44
|
-
return [Math.floor((x1 + x2) / 2), Math.floor((y1 + y2) / 2)];
|
|
45
|
-
}
|
|
46
|
-
static normalizeCachedPoint(x, y) {
|
|
47
|
-
if (x === null || x === undefined || y === null || y === undefined)
|
|
48
|
-
return null;
|
|
49
|
-
try {
|
|
50
|
-
return [parseInt(String(x), 10), parseInt(String(y), 10)];
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
static getDriver() {
|
|
57
|
-
logger_1.logger.warning('[ToolPlayer] getDriver: hypium UiDriver not available in Node.js, returning null');
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
static getHypiumBy() {
|
|
61
|
-
logger_1.logger.warning('[ToolPlayer] getHypiumBy: hypium BY not available in Node.js, returning null');
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
static getToolRegistry() {
|
|
65
|
-
try {
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return {};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async tryXpathExecution(_toolName, _arguments, clickCache, _screenshot, _toolStartTime) {
|
|
73
|
-
const xpath = clickCache['xpath'];
|
|
74
|
-
if (xpath) {
|
|
75
|
-
logger_1.logger.info(`[ToolPlayer] Cached xpath available: ${xpath}, but hypium not available in Node.js — falling back to execute`);
|
|
76
|
-
}
|
|
77
|
-
logger_1.logger.warning('[ToolPlayer] tryXpathExecution: hypium-based XPath finding not available in Node.js');
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
async tryTextAction(clickCache, arguments_, screenshot, toolStartTime) {
|
|
81
|
-
const textAction = clickCache['action'];
|
|
82
|
-
const text = clickCache['text'] ?? '';
|
|
83
|
-
if (textAction === 'input_text' && text) {
|
|
84
|
-
try {
|
|
85
|
-
await this.host.device.callTool('input_text', { text });
|
|
86
|
-
const result = JSON.stringify({ action: 'input_text', text, message: `Input text: ${text.slice(0, 50)}...` });
|
|
87
|
-
this.reportAction({ _metadata: 'do', action: exports.ACTION_MAP['input_text'] ?? 'Type', log: arguments_['message'] ?? '', element: [] }, screenshot, toolStartTime);
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return '{"error": "input_text failed"}';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (textAction === 'clear_text') {
|
|
95
|
-
try {
|
|
96
|
-
await this.host.device.callTool('clear_text', {});
|
|
97
|
-
const result = JSON.stringify({ action: 'clear_text', message: 'Cleared text' });
|
|
98
|
-
this.reportAction({ _metadata: 'do', action: exports.ACTION_MAP['clear_text'] ?? 'Clear Text', log: arguments_['message'] ?? '', element: [] }, screenshot, toolStartTime);
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return '{"error": "clear_text failed"}';
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
async executeViaToolRegistry(toolName, arguments_, screenshot, toolStartTime) {
|
|
108
|
-
try {
|
|
109
|
-
const result = await this.host.device.callTool(toolName, arguments_);
|
|
110
|
-
const resultStr = result ? (typeof result === 'string' ? result : JSON.stringify(result)) : 'OK';
|
|
111
|
-
this.reportAction({ _metadata: 'do', action: toolName, log: `执行工具${toolName}`, element: [] }, screenshot, toolStartTime);
|
|
112
|
-
return resultStr;
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
115
|
-
logger_1.logger.error(`[ToolPlayer] ${toolName} failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
116
|
-
return `{"error": "${e instanceof Error ? e.message : String(e)}"}`;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
reportAction(action, screenshot, toolStartTime) {
|
|
120
|
-
try {
|
|
121
|
-
const toolEndTime = new Date();
|
|
122
|
-
const timeCalcStart = new _utils_1.TimeCalculate(toolStartTime, toolStartTime);
|
|
123
|
-
const reportGen = this.host.reportGenerator;
|
|
124
|
-
if (reportGen && typeof reportGen['execute_agent_do_start'] === 'function') {
|
|
125
|
-
reportGen['execute_agent_do_start']({
|
|
126
|
-
timeCalculate: timeCalcStart,
|
|
127
|
-
thinking: '',
|
|
128
|
-
screenshot,
|
|
129
|
-
action,
|
|
130
|
-
stepCount: this.host.currentIndex + 1,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
logger_1.logger.warning(`[ToolPlayer] reportAction failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.XpathMixin = XpathMixin;
|
|
@@ -1,126 +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.ToolRecorder = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const logger_1 = require("../../common/logger");
|
|
40
|
-
class ToolRecorder {
|
|
41
|
-
_records = [];
|
|
42
|
-
_taskId;
|
|
43
|
-
_storageDir;
|
|
44
|
-
_order = 0;
|
|
45
|
-
constructor(taskId, storageDir) {
|
|
46
|
-
this._taskId = taskId;
|
|
47
|
-
this._storageDir = storageDir ?? path.join(process.cwd(), 'reports', 'tool_recordings');
|
|
48
|
-
if (!fs.existsSync(this._storageDir)) {
|
|
49
|
-
fs.mkdirSync(this._storageDir, { recursive: true });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
_taskHash() {
|
|
53
|
-
const c = require('crypto');
|
|
54
|
-
return c.createHash('md5').update(this._taskId).digest('hex');
|
|
55
|
-
}
|
|
56
|
-
record(toolName, args, result, success, stepNumber, clickCache) {
|
|
57
|
-
const record = {
|
|
58
|
-
order: this._order++,
|
|
59
|
-
toolName,
|
|
60
|
-
arguments: args,
|
|
61
|
-
result: result.slice(0, 500),
|
|
62
|
-
success,
|
|
63
|
-
timestamp: new Date().toISOString(),
|
|
64
|
-
stepNumber,
|
|
65
|
-
...(clickCache ? { clickCache } : {}),
|
|
66
|
-
};
|
|
67
|
-
this._records.push(record);
|
|
68
|
-
logger_1.logger.debug(`[ToolRecorder] Recorded: ${toolName} (step ${stepNumber}, success=${success})`);
|
|
69
|
-
}
|
|
70
|
-
save() {
|
|
71
|
-
const filePath = path.join(this._storageDir, `${this._taskId}.json`);
|
|
72
|
-
const session = {
|
|
73
|
-
task: this._taskId,
|
|
74
|
-
taskHash: this._taskHash(),
|
|
75
|
-
totalCalls: this._records.length,
|
|
76
|
-
records: this._records,
|
|
77
|
-
createdAt: new Date().toISOString(),
|
|
78
|
-
};
|
|
79
|
-
fs.writeFileSync(filePath, JSON.stringify(session, null, 2), 'utf-8');
|
|
80
|
-
logger_1.logger.info(`[ToolRecorder] Saved ${this._records.length} records to ${filePath}`);
|
|
81
|
-
return filePath;
|
|
82
|
-
}
|
|
83
|
-
static loadFromFile(filePath) {
|
|
84
|
-
try {
|
|
85
|
-
const data = fs.readFileSync(filePath, 'utf-8');
|
|
86
|
-
return JSON.parse(data);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
static loadByTask(taskId, storageDir) {
|
|
93
|
-
const dir = storageDir ?? path.join(process.cwd(), 'reports', 'tool_recordings');
|
|
94
|
-
const filePath = path.join(dir, `${taskId}.json`);
|
|
95
|
-
return ToolRecorder.loadFromFile(filePath);
|
|
96
|
-
}
|
|
97
|
-
static findRecording(identifier, storageDir) {
|
|
98
|
-
// Look up by task id (filename) first, then by md5 hash match.
|
|
99
|
-
const byId = ToolRecorder.loadByTask(identifier, storageDir);
|
|
100
|
-
if (byId)
|
|
101
|
-
return byId;
|
|
102
|
-
const dir = storageDir ?? path.join(process.cwd(), 'reports', 'tool_recordings');
|
|
103
|
-
const c = require('crypto');
|
|
104
|
-
const hash = c.createHash('md5').update(identifier).digest('hex');
|
|
105
|
-
try {
|
|
106
|
-
for (const f of fs.readdirSync(dir)) {
|
|
107
|
-
if (!f.endsWith('.json'))
|
|
108
|
-
continue;
|
|
109
|
-
const s = ToolRecorder.loadFromFile(path.join(dir, f));
|
|
110
|
-
if (s && (s.task === identifier || s.taskHash === hash))
|
|
111
|
-
return s;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
// ignore
|
|
116
|
-
}
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
get records() {
|
|
120
|
-
return this._records;
|
|
121
|
-
}
|
|
122
|
-
get recordCount() {
|
|
123
|
-
return this._records.length;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.ToolRecorder = ToolRecorder;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaskSplitter = void 0;
|
|
4
|
-
exports.stepToText = stepToText;
|
|
5
|
-
exports.taskSplitResultToText = taskSplitResultToText;
|
|
6
|
-
const logger_1 = require("../../common/logger");
|
|
7
|
-
const common_errors_1 = require("../../common/common_errors");
|
|
8
|
-
const custom_model_1 = require("../../common/model/custom_model");
|
|
9
|
-
const prompt_loader_1 = require("../prompt/prompt_loader");
|
|
10
|
-
function stepToText(step) {
|
|
11
|
-
return `${step.stepId}. ${step.description}(expected:${step.expectedResult})`;
|
|
12
|
-
}
|
|
13
|
-
function taskSplitResultToText(result) {
|
|
14
|
-
return result.steps.map((s) => `${s.stepId}. ${s.description}(expected:${s.expectedResult})`).join('\n');
|
|
15
|
-
}
|
|
16
|
-
const DEFAULT_SYSTEM_PROMPT = 'You are a test task splitting expert. Split the user task into a sequence of ' +
|
|
17
|
-
'clear, reasonable steps. Output ONLY the step list in this exact format, nothing else:\n' +
|
|
18
|
-
'1. [step description](expected:[expected result])\n' +
|
|
19
|
-
'2. [step description](expected:[expected result])\n' +
|
|
20
|
-
'Rules: continuous numeric numbering, one independent action per step, ' +
|
|
21
|
-
'expected results must be verifiable and specific.';
|
|
22
|
-
class TaskSplitter {
|
|
23
|
-
modelConfig;
|
|
24
|
-
llmCaller;
|
|
25
|
-
systemPrompt;
|
|
26
|
-
constructor(modelConfig, llmCaller) {
|
|
27
|
-
this.modelConfig = modelConfig;
|
|
28
|
-
this.llmCaller = llmCaller ?? new custom_model_1.LLMCaller();
|
|
29
|
-
this.systemPrompt = this.loadSystemPrompt();
|
|
30
|
-
}
|
|
31
|
-
async splitTask(task) {
|
|
32
|
-
logger_1.logger.info(`TaskSplitter.splitTask: splitting task "${task}"`);
|
|
33
|
-
const userPrompt = `Please split the following task into steps:\n\n${task}`;
|
|
34
|
-
let llmResult;
|
|
35
|
-
try {
|
|
36
|
-
llmResult = await this.llmCaller.call({
|
|
37
|
-
systemPrompt: this.systemPrompt,
|
|
38
|
-
userPrompt,
|
|
39
|
-
modelConfig: this.modelConfig,
|
|
40
|
-
extraBody: { enable_thinking: false },
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
if (e instanceof common_errors_1.AgentError)
|
|
45
|
-
throw e;
|
|
46
|
-
throw new common_errors_1.AgentError('LLM_API_ERROR', `Task split LLM call failed: ${e}`);
|
|
47
|
-
}
|
|
48
|
-
const text = llmResult.text;
|
|
49
|
-
if (!text) {
|
|
50
|
-
throw new common_errors_1.AgentError('LLM_API_ERROR', 'Model returned empty content for task split');
|
|
51
|
-
}
|
|
52
|
-
logger_1.logger.debug(`TaskSplitter: model response:\n${text}`);
|
|
53
|
-
if (llmResult.tokenUsage) {
|
|
54
|
-
logger_1.logger.info(`[Preprocess] Token Usage: Input=${llmResult.tokenUsage.inputTokens}, ` +
|
|
55
|
-
`Output=${llmResult.tokenUsage.outputTokens}, ` +
|
|
56
|
-
`Total=${llmResult.tokenUsage.totalTokens}`);
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const steps = this.parseSteps(text);
|
|
60
|
-
return {
|
|
61
|
-
originalTask: task,
|
|
62
|
-
steps,
|
|
63
|
-
tokenUsage: llmResult.tokenUsage ?? null,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
logger_1.logger.error(`TaskSplitter: parse failed: ${e}\nRaw output:\n${text}`);
|
|
68
|
-
throw new common_errors_1.AgentError('LLM_API_ERROR', `Failed to parse model output for task split: ${e}`, { context: { rawOutput: text } });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
loadSystemPrompt() {
|
|
72
|
-
try {
|
|
73
|
-
return (0, prompt_loader_1.load)(prompt_loader_1.PromptCategory.SPLITTER, undefined, true);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return DEFAULT_SYSTEM_PROMPT;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
parseSteps(text) {
|
|
80
|
-
const steps = [];
|
|
81
|
-
const pattern = /(\d+)\.\s*(.+?)\(([^::]+)[::]\s*(.+?)\)/g;
|
|
82
|
-
let match;
|
|
83
|
-
while ((match = pattern.exec(text)) !== null) {
|
|
84
|
-
const stepId = parseInt(match[1], 10);
|
|
85
|
-
const description = match[2].trim();
|
|
86
|
-
const expectedResult = match[4].trim().replace(/\)\s*$/, '');
|
|
87
|
-
if (description && expectedResult) {
|
|
88
|
-
steps.push({ stepId, description, expectedResult });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (steps.length === 0) {
|
|
92
|
-
const fallback = /(\d+)\.\s*(.+)/g;
|
|
93
|
-
let fallbackMatch;
|
|
94
|
-
while ((fallbackMatch = fallback.exec(text)) !== null) {
|
|
95
|
-
const stepId = parseInt(fallbackMatch[1], 10);
|
|
96
|
-
const description = fallbackMatch[2].trim();
|
|
97
|
-
if (description) {
|
|
98
|
-
steps.push({
|
|
99
|
-
stepId,
|
|
100
|
-
description,
|
|
101
|
-
expectedResult: 'Operation completed successfully',
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (steps.length === 0) {
|
|
107
|
-
throw new Error('No valid step format found in model output');
|
|
108
|
-
}
|
|
109
|
-
return steps;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.TaskSplitter = TaskSplitter;
|