@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,801 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FastActionAgent = exports.SingleAgent = void 0;
|
|
4
|
-
const ai_1 = require("ai");
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const types_1 = require("../../../reporter/types");
|
|
7
|
-
const utils_1 = require("../../../common/utils");
|
|
8
|
-
const hook_manager_1 = require("./hook_manager");
|
|
9
|
-
const subagent_manager_1 = require("./subagent_manager");
|
|
10
|
-
const scroll_search_agent_1 = require("./scroll_search_agent");
|
|
11
|
-
const compressed_session_1 = require("../../memory/compressed_session");
|
|
12
|
-
const image_helper_1 = require("../../../common/image_helper");
|
|
13
|
-
const image_utils_1 = require("./image_utils");
|
|
14
|
-
const model_1 = require("../../../common/model");
|
|
15
|
-
const logger_1 = require("../../../common/logger");
|
|
16
|
-
const prompt_loader_1 = require("../../prompt/prompt_loader");
|
|
17
|
-
const skill_manager_1 = require("../../skill/skill_manager");
|
|
18
|
-
const cache_transport_1 = require("../../../common/llm_cache/cache_transport");
|
|
19
|
-
const MAX_HISTORY_IMAGES = 3;
|
|
20
|
-
const MAX_HISTORY_ACTIONS = 10;
|
|
21
|
-
const CLICK_LIKE_TOOLS = new Set(['click', 'double_click', 'long_press', 'long_click', 'tap', 'double_tap']);
|
|
22
|
-
const SWIPE_LIKE_TOOLS = new Set(['swipe', 'drag']);
|
|
23
|
-
const COMMON_ERRORS_PROMPT = `
|
|
24
|
-
常见错误提示:
|
|
25
|
-
- 坐标偏移:如果点击没反应,检查坐标是否准确,尝试微调
|
|
26
|
-
- 滑动无效:确保起点在可滑动区域内,滑动距离适中
|
|
27
|
-
- 页面未加载:操作后适当等待
|
|
28
|
-
- 重复操作:避免对同一位置重复点击超过3次`;
|
|
29
|
-
class SingleAgent {
|
|
30
|
-
adapter;
|
|
31
|
-
config;
|
|
32
|
-
hooks;
|
|
33
|
-
reportGenerator;
|
|
34
|
-
stepNumber = 0;
|
|
35
|
-
maxSteps;
|
|
36
|
-
maxResultRetries;
|
|
37
|
-
lastScreenshot = null;
|
|
38
|
-
previousScreenshotB64 = null;
|
|
39
|
-
lastActionInfo = null;
|
|
40
|
-
llmCaller;
|
|
41
|
-
task = '';
|
|
42
|
-
session = null;
|
|
43
|
-
historyActions = [];
|
|
44
|
-
toolCount = 0;
|
|
45
|
-
constructor(adapter, config, reportGenerator, hooks, llmCaller) {
|
|
46
|
-
this.adapter = adapter;
|
|
47
|
-
this.config = config;
|
|
48
|
-
this.reportGenerator = reportGenerator;
|
|
49
|
-
this.hooks = hooks;
|
|
50
|
-
this.maxSteps = config.agent.unified.maxSteps;
|
|
51
|
-
this.maxResultRetries = config.agent.unified.maxResultRetries;
|
|
52
|
-
this.llmCaller = llmCaller ?? new model_1.LLMCaller(new cache_transport_1.CacheTransport(config.agent.unified.enableCache));
|
|
53
|
-
}
|
|
54
|
-
async run(args) {
|
|
55
|
-
const task = args.task;
|
|
56
|
-
this.task = task;
|
|
57
|
-
const testCase = args.caseNum ?? args.taskName ?? task;
|
|
58
|
-
this.reportGenerator.setTask(task);
|
|
59
|
-
this.reportGenerator.setTestCase(testCase);
|
|
60
|
-
this.reportGenerator.startTask();
|
|
61
|
-
// Initialize compressed session (replaces raw conversationHistory + trimHistory).
|
|
62
|
-
//
|
|
63
|
-
this.session = new compressed_session_1.CompressedSession({
|
|
64
|
-
autoCompress: true,
|
|
65
|
-
modelConfig: this.config.model.unified,
|
|
66
|
-
reportGenerator: this.reportGenerator,
|
|
67
|
-
getCurrentStepNumber: () => this.stepNumber,
|
|
68
|
-
maxHistoryImage: this.config.agent.unified.maxHistoryImage,
|
|
69
|
-
compressionConfig: this.config.contextCompression ?? { enabled: true, maxTokens: 7000, maxRecentMessages: 6 },
|
|
70
|
-
reflectionConfig: this.config.reflection ?? { enabled: true, initialStep: 25, interval: 15, recentMessages: 10 },
|
|
71
|
-
});
|
|
72
|
-
if (this.hooks) {
|
|
73
|
-
await this.hooks.onAgentStart('single');
|
|
74
|
-
}
|
|
75
|
-
await hook_manager_1.hookManager.fireEvent('on_agent_start', { agentName: 'single' });
|
|
76
|
-
let finalOutput = '';
|
|
77
|
-
let finalStatus = 'UNKNOWN';
|
|
78
|
-
let stepsUsed = 0;
|
|
79
|
-
for (let attempt = 0; attempt <= this.maxResultRetries; attempt++) {
|
|
80
|
-
this.stepNumber = 0;
|
|
81
|
-
finalStatus = 'UNKNOWN';
|
|
82
|
-
//
|
|
83
|
-
// (max(3, original_max_steps - steps_used)) instead of the full maxSteps.
|
|
84
|
-
const attemptMaxSteps = attempt === 0 ? this.maxSteps : Math.max(3, this.maxSteps - stepsUsed);
|
|
85
|
-
finalOutput = '';
|
|
86
|
-
while (this.stepNumber < attemptMaxSteps) {
|
|
87
|
-
this.stepNumber++;
|
|
88
|
-
if (this.adapter.isAborted()) {
|
|
89
|
-
finalStatus = 'STOP_BY_USER';
|
|
90
|
-
finalOutput = 'Task stopped by user';
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
this.reportGenerator.addEvent({
|
|
94
|
-
eventType: types_1.EventType.STEP_START,
|
|
95
|
-
timestamp: new Date().toISOString(),
|
|
96
|
-
content: `Step ${this.stepNumber} started`,
|
|
97
|
-
data: {},
|
|
98
|
-
stepNumber: this.stepNumber,
|
|
99
|
-
});
|
|
100
|
-
// Register scroll_search subagent
|
|
101
|
-
const sm = (0, subagent_manager_1.getSubagentManager)();
|
|
102
|
-
sm.register('scroll_search', '滑动查找目标使其进入可见区域(列表/导航栏/时间选择器等)', async (task, opts) => {
|
|
103
|
-
const sub = new scroll_search_agent_1.ScrollSearchAgent(this.adapter, this.config.model.unified, undefined, this.reportGenerator);
|
|
104
|
-
const result = await sub.run(task, '');
|
|
105
|
-
return {
|
|
106
|
-
name: 'scroll_search',
|
|
107
|
-
success: result.success,
|
|
108
|
-
output: result.success ? `找到目标: ${result.message}` : `未找到: ${result.message}`,
|
|
109
|
-
stepsUsed: result.totalSteps,
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
if (this.hooks) {
|
|
113
|
-
await this.hooks.onLLMStart('single', this.stepNumber);
|
|
114
|
-
}
|
|
115
|
-
await hook_manager_1.hookManager.fireEvent('on_step_start', { agentName: 'single', step: this.stepNumber });
|
|
116
|
-
await this.injectScreenshot('observation');
|
|
117
|
-
const stepResult = await this.callLLMStep();
|
|
118
|
-
if (!stepResult.action) {
|
|
119
|
-
const extracted = this.extractResult(stepResult.thinking);
|
|
120
|
-
if (extracted.status === 'PASS' || extracted.status === 'FAIL') {
|
|
121
|
-
finalStatus = extracted.status;
|
|
122
|
-
finalOutput = extracted.tip;
|
|
123
|
-
logger_1.logger.info(`Step ${this.stepNumber} final result: ${finalStatus} - ${finalOutput.slice(0, 100)}`);
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (stepResult.action) {
|
|
128
|
-
const actionResult = await this.executeAction(stepResult.action);
|
|
129
|
-
if (actionResult.finished) {
|
|
130
|
-
this.reportGenerator.addEvent({
|
|
131
|
-
eventType: types_1.EventType.STEP_END,
|
|
132
|
-
timestamp: new Date().toISOString(),
|
|
133
|
-
content: `Step ${this.stepNumber} finished: ${actionResult.message ?? ''}`,
|
|
134
|
-
data: { success: actionResult.success },
|
|
135
|
-
stepNumber: this.stepNumber,
|
|
136
|
-
});
|
|
137
|
-
const extracted = this.extractResult(actionResult.message ?? stepResult.thinking);
|
|
138
|
-
if (extracted.status === 'PASS' || extracted.status === 'FAIL') {
|
|
139
|
-
finalStatus = extracted.status;
|
|
140
|
-
finalOutput = extracted.tip;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (actionResult.aborted) {
|
|
145
|
-
finalStatus = 'FAIL';
|
|
146
|
-
finalOutput = actionResult.message ?? 'Task aborted';
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (this.config.agent.unified.stepEndWaitTime > 0) {
|
|
151
|
-
await new Promise((r) => setTimeout(r, this.config.agent.unified.stepEndWaitTime * 1000));
|
|
152
|
-
}
|
|
153
|
-
this.reportGenerator.addEvent({
|
|
154
|
-
eventType: types_1.EventType.STEP_END,
|
|
155
|
-
timestamp: new Date().toISOString(),
|
|
156
|
-
content: `Step ${this.stepNumber} completed`,
|
|
157
|
-
data: {},
|
|
158
|
-
stepNumber: this.stepNumber,
|
|
159
|
-
});
|
|
160
|
-
this.reportGenerator.saveJson();
|
|
161
|
-
if (this.hooks) {
|
|
162
|
-
await this.hooks.onLLMEnd('single', this.stepNumber, stepResult);
|
|
163
|
-
}
|
|
164
|
-
await hook_manager_1.hookManager.fireEvent('on_step_end', { agentName: 'single', step: this.stepNumber });
|
|
165
|
-
}
|
|
166
|
-
stepsUsed += this.stepNumber;
|
|
167
|
-
if (this.stepNumber >= attemptMaxSteps && finalStatus === 'UNKNOWN') {
|
|
168
|
-
finalStatus = 'FAIL';
|
|
169
|
-
finalOutput = `任务结果: 不通过 (超过最大步数 ${attemptMaxSteps})`;
|
|
170
|
-
}
|
|
171
|
-
const hasVerdict = (finalOutput.includes('任务结果') || finalOutput.includes('判定结果')) &&
|
|
172
|
-
(finalOutput.includes('通过') || finalOutput.includes('不通过'));
|
|
173
|
-
if (hasVerdict || finalStatus === 'PASS' || attempt >= this.maxResultRetries) {
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
logger_1.logger.warn(`No verdict in output, retrying (${attempt + 1}/${this.maxResultRetries})...`);
|
|
177
|
-
await this.session.addItems([{
|
|
178
|
-
role: 'user',
|
|
179
|
-
content: '请继续完成当前任务。如果所有步骤已执行完毕,请输出最终结果。',
|
|
180
|
-
}]);
|
|
181
|
-
}
|
|
182
|
-
this.reportGenerator.endTask(finalOutput, finalStatus);
|
|
183
|
-
if (this.hooks) {
|
|
184
|
-
await this.hooks.onAgentEnd('single', { finalOutput, status: finalStatus });
|
|
185
|
-
}
|
|
186
|
-
await hook_manager_1.hookManager.fireEvent('on_agent_end', { agentName: 'single', result: finalOutput });
|
|
187
|
-
const savedFiles = await this.reportGenerator.saveAll();
|
|
188
|
-
return {
|
|
189
|
-
finalOutput,
|
|
190
|
-
status: finalStatus,
|
|
191
|
-
savedFiles,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
async injectScreenshot(phase = 'observation') {
|
|
195
|
-
try {
|
|
196
|
-
const screenshot = await this.adapter.getScreenshot();
|
|
197
|
-
// Save current screenshot as previous for next step
|
|
198
|
-
if (phase === 'observation' && this.lastScreenshot?.base64Data) {
|
|
199
|
-
this.previousScreenshotB64 = this.lastScreenshot.base64Data;
|
|
200
|
-
}
|
|
201
|
-
this.lastScreenshot = screenshot;
|
|
202
|
-
if (screenshot.base64Data) {
|
|
203
|
-
const screenshotPath = this.reportGenerator.saveScreenshot(screenshot.base64Data, screenshot.layoutData, `step_${this.stepNumber}_${phase}`);
|
|
204
|
-
this.reportGenerator.addEvent({
|
|
205
|
-
eventType: types_1.EventType.SCREENSHOT,
|
|
206
|
-
timestamp: new Date().toISOString(),
|
|
207
|
-
content: `Screenshot ${phase}: step ${this.stepNumber}`,
|
|
208
|
-
data: { phase, width: screenshot.width, height: screenshot.height, path: screenshotPath },
|
|
209
|
-
screenshotPath,
|
|
210
|
-
stepNumber: this.stepNumber,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
this.reportGenerator.addEvent({
|
|
216
|
-
eventType: types_1.EventType.SCREENSHOT,
|
|
217
|
-
timestamp: new Date().toISOString(),
|
|
218
|
-
content: `Screenshot capture failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
219
|
-
data: { error: true, phase },
|
|
220
|
-
stepNumber: this.stepNumber,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
extractResult(output) {
|
|
225
|
-
const verdictKeyword = output.includes('任务结果') ? '任务结果'
|
|
226
|
-
: output.includes('判定结果') ? '判定结果'
|
|
227
|
-
: output.match(/PASS/i) ? 'PASS'
|
|
228
|
-
: output.match(/FAIL/i) ? 'FAIL'
|
|
229
|
-
: null;
|
|
230
|
-
if (verdictKeyword) {
|
|
231
|
-
if (output.includes('不通过') || output.match(/FAIL/i)) {
|
|
232
|
-
const idx = output.indexOf(verdictKeyword);
|
|
233
|
-
return { status: 'FAIL', tip: idx >= 0 ? output.slice(idx).trim() : output };
|
|
234
|
-
}
|
|
235
|
-
if (output.includes('通过') || output.match(/PASS/i)) {
|
|
236
|
-
const idx = output.indexOf(verdictKeyword);
|
|
237
|
-
return { status: 'PASS', tip: idx >= 0 ? output.slice(idx).trim() : output };
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (output.includes('任务结果: 不通过') || output.includes('任务结果:不通过') ||
|
|
241
|
-
output.includes('判定结果: 不通过') || output.includes('判定结果:不通过')) {
|
|
242
|
-
return { status: 'FAIL', tip: output };
|
|
243
|
-
}
|
|
244
|
-
if (output.includes('任务结果: 通过') || output.includes('任务结果:通过') ||
|
|
245
|
-
output.includes('判定结果: 通过') || output.includes('判定结果:通过')) {
|
|
246
|
-
return { status: 'PASS', tip: output };
|
|
247
|
-
}
|
|
248
|
-
return { status: 'UNKNOWN', tip: output };
|
|
249
|
-
}
|
|
250
|
-
async executeAction(action) {
|
|
251
|
-
const toolName = (action.tool ?? action.name ?? action.action);
|
|
252
|
-
const toolArgs = (action.args ?? action.parameters ?? {});
|
|
253
|
-
if (!toolName) {
|
|
254
|
-
return {
|
|
255
|
-
success: false,
|
|
256
|
-
finished: false,
|
|
257
|
-
thinking: 'No action specified',
|
|
258
|
-
message: 'No action specified',
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
this.toolCount++;
|
|
262
|
-
const actionLog = this.formatActionLog(toolName, toolArgs);
|
|
263
|
-
this.historyActions.push(`${this.stepNumber}. ${actionLog}`);
|
|
264
|
-
if (this.historyActions.length > MAX_HISTORY_ACTIONS) {
|
|
265
|
-
this.historyActions = this.historyActions.slice(-MAX_HISTORY_ACTIONS);
|
|
266
|
-
}
|
|
267
|
-
this.reportGenerator.addEvent({
|
|
268
|
-
eventType: types_1.EventType.PLANNER_TOOL_CALL,
|
|
269
|
-
timestamp: new Date().toISOString(),
|
|
270
|
-
content: `Called: ${toolName}`,
|
|
271
|
-
data: { tool_name: toolName, arguments: toolArgs },
|
|
272
|
-
stepNumber: this.stepNumber,
|
|
273
|
-
});
|
|
274
|
-
let beforeScreenshotPath = null;
|
|
275
|
-
if (this.lastScreenshot?.base64Data) {
|
|
276
|
-
try {
|
|
277
|
-
beforeScreenshotPath = this.reportGenerator.saveScreenshot(this.lastScreenshot.base64Data, this.lastScreenshot.layoutData, `step_${this.stepNumber}_before`);
|
|
278
|
-
}
|
|
279
|
-
catch { /* non-blocking */ }
|
|
280
|
-
}
|
|
281
|
-
const toolStartData = { toolName, args: toolArgs };
|
|
282
|
-
if (['click', 'double_click', 'long_press', 'long_click'].includes(toolName)) {
|
|
283
|
-
toolStartData.action = toolName;
|
|
284
|
-
if (toolArgs && 'x' in toolArgs && 'y' in toolArgs) {
|
|
285
|
-
toolStartData.point = [Number(toolArgs.x), Number(toolArgs.y)];
|
|
286
|
-
}
|
|
287
|
-
else if (toolArgs && 'pos' in toolArgs && Array.isArray(toolArgs.pos) && toolArgs.pos.length === 2) {
|
|
288
|
-
toolStartData.point = [Number(toolArgs.pos[0]), Number(toolArgs.pos[1])];
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
else if (toolName === 'swipe' && toolArgs) {
|
|
292
|
-
if ('start' in toolArgs && 'end' in toolArgs) {
|
|
293
|
-
const start = toolArgs.start;
|
|
294
|
-
const end = toolArgs.end;
|
|
295
|
-
if (Array.isArray(start) && start.length === 2 && Array.isArray(end) && end.length === 2) {
|
|
296
|
-
toolStartData.action = 'swipe';
|
|
297
|
-
toolStartData.start = [start[0], start[1]];
|
|
298
|
-
toolStartData.end = [end[0], end[1]];
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else if ('start_x' in toolArgs && 'start_y' in toolArgs && 'end_x' in toolArgs && 'end_y' in toolArgs) {
|
|
302
|
-
toolStartData.action = 'swipe';
|
|
303
|
-
toolStartData.start = [Number(toolArgs.start_x), Number(toolArgs.start_y)];
|
|
304
|
-
toolStartData.end = [Number(toolArgs.end_x), Number(toolArgs.end_y)];
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
this.reportGenerator.addEvent({
|
|
308
|
-
eventType: types_1.EventType.MCP_TOOL_START,
|
|
309
|
-
timestamp: new Date().toISOString(),
|
|
310
|
-
content: `Tool call: ${toolName}`,
|
|
311
|
-
data: toolStartData,
|
|
312
|
-
screenshotPath: beforeScreenshotPath,
|
|
313
|
-
stepNumber: this.stepNumber,
|
|
314
|
-
});
|
|
315
|
-
if (this.hooks) {
|
|
316
|
-
await this.hooks.onToolStart('single', toolName, toolArgs);
|
|
317
|
-
}
|
|
318
|
-
await hook_manager_1.hookManager.fireEvent('on_tool_start', { agentName: 'single', toolName, toolArgs, step: this.stepNumber });
|
|
319
|
-
// 坐标防御层:模型可能输出 0-1000 千分制坐标,执行前归一化到 0-1
|
|
320
|
-
(0, utils_1.normalizeToolCoordinates)(toolName, toolArgs);
|
|
321
|
-
// Save action info for drawing markers on next step's screenshots.
|
|
322
|
-
//
|
|
323
|
-
const lowerName = toolName.toLowerCase();
|
|
324
|
-
if (CLICK_LIKE_TOOLS.has(lowerName)) {
|
|
325
|
-
const pos = toolArgs['pos'] ?? toolArgs['point'];
|
|
326
|
-
if (Array.isArray(pos) && pos.length === 2) {
|
|
327
|
-
this.lastActionInfo = { action: lowerName, point: [pos[0], pos[1]] };
|
|
328
|
-
}
|
|
329
|
-
else if (typeof toolArgs['x'] === 'number' && typeof toolArgs['y'] === 'number') {
|
|
330
|
-
this.lastActionInfo = { action: lowerName, point: [toolArgs['x'], toolArgs['y']] };
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
else if (SWIPE_LIKE_TOOLS.has(lowerName)) {
|
|
334
|
-
const startVal = toolArgs['start'];
|
|
335
|
-
const endVal = toolArgs['end'];
|
|
336
|
-
if (Array.isArray(startVal) && startVal.length === 2 && Array.isArray(endVal) && endVal.length === 2) {
|
|
337
|
-
this.lastActionInfo = {
|
|
338
|
-
action: lowerName,
|
|
339
|
-
start: [startVal[0], startVal[1]],
|
|
340
|
-
end: [endVal[0], endVal[1]],
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
try {
|
|
345
|
-
// Subagent delegation: run_subagent 不走 adapter.callTool,委托 SubagentManager
|
|
346
|
-
let result;
|
|
347
|
-
if (toolName === 'run_subagent') {
|
|
348
|
-
const sm = (0, subagent_manager_1.getSubagentManager)();
|
|
349
|
-
sm.setParentStep(this.stepNumber);
|
|
350
|
-
const subName = toolArgs['name'] ?? '';
|
|
351
|
-
const subTask = toolArgs['task_description'] ?? '';
|
|
352
|
-
const subResult = await sm.runSubagent(subName, subTask, this.reportGenerator);
|
|
353
|
-
result = subResult.success ? subResult.output : `Sub-agent '${subName}' failed: ${subResult.output}`;
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
result = await this.adapter.callTool(toolName, toolArgs);
|
|
357
|
-
}
|
|
358
|
-
const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
|
|
359
|
-
let afterScreenshotPath = null;
|
|
360
|
-
//
|
|
361
|
-
// screenshot when screenshotOnToolEnd is enabled (skip for fast/minimal modes).
|
|
362
|
-
if (this.config.agent.unified.screenshotOnToolEnd) {
|
|
363
|
-
try {
|
|
364
|
-
const afterScreenshot = await this.adapter.getScreenshot();
|
|
365
|
-
if (afterScreenshot.base64Data) {
|
|
366
|
-
afterScreenshotPath = this.reportGenerator.saveScreenshot(afterScreenshot.base64Data, afterScreenshot.layoutData, `step_${this.stepNumber}_after`);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
catch { /* non-blocking */ }
|
|
370
|
-
}
|
|
371
|
-
if (this.config.agent.unified.actionInterval > 0) {
|
|
372
|
-
await new Promise((r) => setTimeout(r, this.config.agent.unified.actionInterval * 1000));
|
|
373
|
-
}
|
|
374
|
-
this.reportGenerator.addEvent({
|
|
375
|
-
eventType: types_1.EventType.MCP_TOOL_END,
|
|
376
|
-
timestamp: new Date().toISOString(),
|
|
377
|
-
content: `${toolName} -> ${resultStr.slice(0, 200)}`,
|
|
378
|
-
data: { toolName, result: resultStr },
|
|
379
|
-
screenshotPath: afterScreenshotPath,
|
|
380
|
-
stepNumber: this.stepNumber,
|
|
381
|
-
});
|
|
382
|
-
if (this.hooks) {
|
|
383
|
-
await this.hooks.onToolEnd('single', toolName, resultStr, this.stepNumber);
|
|
384
|
-
}
|
|
385
|
-
await hook_manager_1.hookManager.fireEvent('on_tool_end', { agentName: 'single', toolName, toolArgs, result: resultStr, step: this.stepNumber });
|
|
386
|
-
const toolCallId = action.toolCallId;
|
|
387
|
-
if (toolCallId) {
|
|
388
|
-
await this.session.addItems([{
|
|
389
|
-
role: 'tool',
|
|
390
|
-
content: [
|
|
391
|
-
{ type: 'tool-result', toolCallId, toolName, output: { type: 'text', value: resultStr } },
|
|
392
|
-
],
|
|
393
|
-
}]);
|
|
394
|
-
}
|
|
395
|
-
const extracted = this.extractResult(resultStr);
|
|
396
|
-
const aborted = this.shouldAbort(toolName, resultStr);
|
|
397
|
-
return {
|
|
398
|
-
success: !aborted,
|
|
399
|
-
finished: extracted.status !== 'UNKNOWN' || aborted,
|
|
400
|
-
thinking: resultStr,
|
|
401
|
-
message: resultStr,
|
|
402
|
-
action,
|
|
403
|
-
aborted,
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
catch (err) {
|
|
407
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
408
|
-
this.reportGenerator.addEvent({
|
|
409
|
-
eventType: types_1.EventType.MCP_TOOL_END,
|
|
410
|
-
timestamp: new Date().toISOString(),
|
|
411
|
-
content: `Tool error: ${errMsg}`,
|
|
412
|
-
data: { toolName, error: errMsg },
|
|
413
|
-
stepNumber: this.stepNumber,
|
|
414
|
-
});
|
|
415
|
-
const toolCallId = action.toolCallId;
|
|
416
|
-
if (toolCallId) {
|
|
417
|
-
await this.session.addItems([{
|
|
418
|
-
role: 'tool',
|
|
419
|
-
content: [
|
|
420
|
-
{ type: 'tool-result', toolCallId, toolName, output: { type: 'text', value: errMsg }, isError: true },
|
|
421
|
-
],
|
|
422
|
-
}]);
|
|
423
|
-
}
|
|
424
|
-
const aborted = this.shouldAbort(toolName, errMsg);
|
|
425
|
-
return {
|
|
426
|
-
success: false,
|
|
427
|
-
finished: aborted,
|
|
428
|
-
thinking: errMsg,
|
|
429
|
-
message: errMsg,
|
|
430
|
-
aborted,
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
shouldAbort(toolName, resultStr) {
|
|
435
|
-
const lower = resultStr.toLowerCase();
|
|
436
|
-
if (toolName === 'start_app' && (lower.includes('failed') || lower.includes('"iserror":true'))) {
|
|
437
|
-
logger_1.logger.warn(`start_app failed, aborting task: ${resultStr.slice(0, 200)}`);
|
|
438
|
-
return true;
|
|
439
|
-
}
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
formatActionLog(toolName, args) {
|
|
443
|
-
if (args.log && typeof args.log === 'string') {
|
|
444
|
-
return args.log;
|
|
445
|
-
}
|
|
446
|
-
const argStr = Object.entries(args)
|
|
447
|
-
.filter(([k]) => k !== 'log')
|
|
448
|
-
.map(([k, v]) => {
|
|
449
|
-
if (Array.isArray(v) && v.length === 2 && typeof v[0] === 'number') {
|
|
450
|
-
return `${k}=(${v[0]},${v[1]})`;
|
|
451
|
-
}
|
|
452
|
-
return `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`;
|
|
453
|
-
})
|
|
454
|
-
.join(' ');
|
|
455
|
-
return `${toolName}(${argStr})`;
|
|
456
|
-
}
|
|
457
|
-
async callLLMStep() {
|
|
458
|
-
this.reportGenerator.addEvent({
|
|
459
|
-
eventType: types_1.EventType.LLM_CALL,
|
|
460
|
-
timestamp: new Date().toISOString(),
|
|
461
|
-
content: `LLM call for step ${this.stepNumber}`,
|
|
462
|
-
data: {},
|
|
463
|
-
stepNumber: this.stepNumber,
|
|
464
|
-
});
|
|
465
|
-
// Prompt priority:
|
|
466
|
-
// 1. explicit systemPrompt override
|
|
467
|
-
// 2. promptName (loadByName) — e.g. --prompt-name single_v2.0
|
|
468
|
-
// 3. SINGLE category with promptType
|
|
469
|
-
let systemPrompt = this.config.agent.unified.systemPrompt;
|
|
470
|
-
if (!systemPrompt) {
|
|
471
|
-
const promptName = this.config.agent.unified.promptName;
|
|
472
|
-
if (promptName) {
|
|
473
|
-
systemPrompt = (0, prompt_loader_1.loadByName)(promptName) ?? undefined;
|
|
474
|
-
}
|
|
475
|
-
if (!systemPrompt) {
|
|
476
|
-
systemPrompt = (0, prompt_loader_1.load)(prompt_loader_1.PromptCategory.SINGLE, this.config.model.unified.promptType);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
// Fill {skills_metadata} placeholder with available skills
|
|
480
|
-
if (systemPrompt && systemPrompt.includes('{skills_metadata}')) {
|
|
481
|
-
try {
|
|
482
|
-
const sm = new skill_manager_1.SkillManager();
|
|
483
|
-
systemPrompt = systemPrompt.replace('{skills_metadata}', sm.getSkillsMetadata());
|
|
484
|
-
}
|
|
485
|
-
catch {
|
|
486
|
-
systemPrompt = systemPrompt.replace('{skills_metadata}', 'No skills available.');
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
let promptText;
|
|
490
|
-
if (this.stepNumber === 1) {
|
|
491
|
-
promptText = `Task: ${this.task}\n\nStep ${this.stepNumber}: Execute the next action based on current screenshot and task context.`;
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
promptText = `Step ${this.stepNumber}: Observe the new screenshot and continue executing the task.`;
|
|
495
|
-
if (this.historyActions.length > 0) {
|
|
496
|
-
promptText += `\n\n## 历史操作\n${this.historyActions.join('\n')}`;
|
|
497
|
-
}
|
|
498
|
-
promptText += `\n${COMMON_ERRORS_PROMPT}`;
|
|
499
|
-
}
|
|
500
|
-
const userContent = [
|
|
501
|
-
{ type: 'text', text: promptText },
|
|
502
|
-
];
|
|
503
|
-
//
|
|
504
|
-
// 1. Inject previous screenshot with action marker (red dot + crosshair)
|
|
505
|
-
const maxPixels = this.config.agent.unified.screenshotMaxPixels || 1500;
|
|
506
|
-
const prevCompressRatio = this.config.agent.unified.previousScreenshotCompressRatio ?? 0.7;
|
|
507
|
-
const includePrev = this.config.agent.unified.includePreviousScreenshot;
|
|
508
|
-
const actionMarkers = this.config.agent.unified.actionMarkers ?? false;
|
|
509
|
-
if (includePrev && this.previousScreenshotB64 && this.stepNumber > 1) {
|
|
510
|
-
const prevPixels = Math.round(maxPixels * prevCompressRatio);
|
|
511
|
-
let prevB64 = await (0, image_helper_1.compressBase64Image)(this.previousScreenshotB64, prevPixels, 70);
|
|
512
|
-
let prevText = '** 上一步页面截图 **';
|
|
513
|
-
if (actionMarkers && this.lastActionInfo) {
|
|
514
|
-
const actionType = CLICK_LIKE_TOOLS.has(this.lastActionInfo.action) ? 'click' : 'swipe';
|
|
515
|
-
const markerInfo = actionType === 'click' && this.lastActionInfo.point
|
|
516
|
-
? { type: 'click', point: this.lastActionInfo.point }
|
|
517
|
-
: actionType === 'swipe' && this.lastActionInfo.start && this.lastActionInfo.end
|
|
518
|
-
? { type: 'swipe', start: this.lastActionInfo.start, end: this.lastActionInfo.end }
|
|
519
|
-
: null;
|
|
520
|
-
if (markerInfo) {
|
|
521
|
-
prevB64 = await (0, image_utils_1.drawActionMarker)(prevB64, markerInfo);
|
|
522
|
-
if (actionType === 'click') {
|
|
523
|
-
prevText = '** 上一步页面截图 **\n图中标记说明:红色圆点+十字线 = 上一步的点击位置';
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
prevText = '** 上一步页面截图 **\n图中标记说明:红色箭头 = 上一步的滑动方向和距离(起点圆点 → 箭头终点)';
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
userContent.push({ type: 'text', text: prevText });
|
|
531
|
-
userContent.push({
|
|
532
|
-
type: 'file',
|
|
533
|
-
data: `data:image/jpeg;base64,${prevB64}`,
|
|
534
|
-
mediaType: 'image/jpeg',
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
if (this.lastScreenshot?.base64Data) {
|
|
538
|
-
let curB64 = this.lastScreenshot.base64Data;
|
|
539
|
-
let curText = '** 当前页面截图 **';
|
|
540
|
-
// Compress screenshot before sending to LLM (reduces tokens → faster response).
|
|
541
|
-
const finalB64 = await (0, image_helper_1.compressBase64Image)(curB64, maxPixels, 70);
|
|
542
|
-
userContent.push({ type: 'text', text: curText });
|
|
543
|
-
userContent.push({
|
|
544
|
-
type: 'file',
|
|
545
|
-
data: `data:image/jpeg;base64,${finalB64}`,
|
|
546
|
-
mediaType: 'image/jpeg',
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
await this.session.addItems([{ role: 'user', content: userContent }]);
|
|
550
|
-
const llmResult = await this.llmCaller.callWithMessages({
|
|
551
|
-
messages: await this.session.getItems(),
|
|
552
|
-
systemPrompt,
|
|
553
|
-
tools: this.getDeviceTools(),
|
|
554
|
-
modelConfig: this.config.model.unified,
|
|
555
|
-
});
|
|
556
|
-
if (llmResult.responseMessages && llmResult.responseMessages.length > 0) {
|
|
557
|
-
await this.session.addItems(llmResult.responseMessages);
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
await this.session.addItems([{
|
|
561
|
-
role: 'assistant',
|
|
562
|
-
content: llmResult.text || '(no response)',
|
|
563
|
-
}]);
|
|
564
|
-
}
|
|
565
|
-
if (llmResult.tokenUsage) {
|
|
566
|
-
this.reportGenerator.addTokenUsage(llmResult.tokenUsage, 'single_agent', this.stepNumber);
|
|
567
|
-
}
|
|
568
|
-
const thinkingContent = this.parseThinkingTags(llmResult.text);
|
|
569
|
-
const judgmentContent = this.parseJudgmentTags(llmResult.text);
|
|
570
|
-
this.reportGenerator.addEvent({
|
|
571
|
-
eventType: types_1.EventType.LLM_RESPONSE,
|
|
572
|
-
timestamp: new Date().toISOString(),
|
|
573
|
-
content: llmResult.text,
|
|
574
|
-
data: {
|
|
575
|
-
text: llmResult.text,
|
|
576
|
-
reasoning: llmResult.reasoning,
|
|
577
|
-
thinking: thinkingContent,
|
|
578
|
-
judgment: judgmentContent,
|
|
579
|
-
finishReason: llmResult.finishReason,
|
|
580
|
-
},
|
|
581
|
-
stepNumber: this.stepNumber,
|
|
582
|
-
});
|
|
583
|
-
let action;
|
|
584
|
-
if (llmResult.toolCalls && llmResult.toolCalls.length > 0) {
|
|
585
|
-
const tc = llmResult.toolCalls[0];
|
|
586
|
-
action = { tool: tc.toolName, args: tc.args, toolCallId: tc.toolCallId };
|
|
587
|
-
logger_1.logger.info(`Step ${this.stepNumber} tool call: ${tc.toolName} ${JSON.stringify(tc.args)}`);
|
|
588
|
-
for (let i = 1; i < llmResult.toolCalls.length; i++) {
|
|
589
|
-
const extra = llmResult.toolCalls[i];
|
|
590
|
-
logger_1.logger.info(`Step ${this.stepNumber} additional tool call ${i + 1}: ${extra.toolName} ${JSON.stringify(extra.args)}`);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
const textAction = this.parseTextAction(llmResult.text);
|
|
595
|
-
if (textAction)
|
|
596
|
-
action = textAction;
|
|
597
|
-
}
|
|
598
|
-
if (llmResult.reasoning) {
|
|
599
|
-
logger_1.logger.info(`Step ${this.stepNumber} reasoning:\n${llmResult.reasoning}`);
|
|
600
|
-
}
|
|
601
|
-
logger_1.logger.info(`Step ${this.stepNumber} response:\n${llmResult.text}`);
|
|
602
|
-
return {
|
|
603
|
-
success: true,
|
|
604
|
-
finished: false,
|
|
605
|
-
thinking: llmResult.reasoning
|
|
606
|
-
? `${llmResult.reasoning}\n\n${llmResult.text}`
|
|
607
|
-
: llmResult.text,
|
|
608
|
-
action,
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
// trimHistory removed: CompressedSession auto-compresses + filters images.
|
|
612
|
-
parseThinkingTags(text) {
|
|
613
|
-
const match = text.match(/<thinking>([\s\S]*?)<\/thinking>/i);
|
|
614
|
-
return match ? match[1].trim() : null;
|
|
615
|
-
}
|
|
616
|
-
parseJudgmentTags(text) {
|
|
617
|
-
const match = text.match(/<judgment>([\s\S]*?)<\/judgment>/i)
|
|
618
|
-
?? text.match(/##\s*判定过程\s*([\s\S]*?)(?:\n##|\n---|\n$|$)/i);
|
|
619
|
-
return match ? match[1].trim() : null;
|
|
620
|
-
}
|
|
621
|
-
getDeviceTools() {
|
|
622
|
-
// 放开坐标 schema:允许模型输出 0-1 浮点或 0-1000 千分制整数,
|
|
623
|
-
// 由 normalizeToolCoordinates 在执行前归一化(防御部分模型遵守 integer schema)。
|
|
624
|
-
const coord = zod_1.z.tuple([zod_1.z.number(), zod_1.z.number()]);
|
|
625
|
-
const logParam = zod_1.z.string().optional().describe('一句话简要描述操作意图');
|
|
626
|
-
return {
|
|
627
|
-
click: (0, ai_1.tool)({
|
|
628
|
-
description: '在指定坐标执行点击操作。坐标为相对坐标,(0.0,0.0)为屏幕左上角,(1.0,1.0)为右下角。',
|
|
629
|
-
inputSchema: zod_1.z.object({
|
|
630
|
-
pos: coord.describe('点击坐标 (x, y),相对坐标,取值范围 0.0~1.0'),
|
|
631
|
-
log: logParam,
|
|
632
|
-
}),
|
|
633
|
-
}),
|
|
634
|
-
long_click: (0, ai_1.tool)({
|
|
635
|
-
description: '在指定坐标执行长按操作',
|
|
636
|
-
inputSchema: zod_1.z.object({
|
|
637
|
-
pos: coord.describe('坐标 (x, y),0.0~1.0'),
|
|
638
|
-
duration: zod_1.z.number().optional().describe('长按持续时间(秒),默认2'),
|
|
639
|
-
log: logParam,
|
|
640
|
-
}),
|
|
641
|
-
}),
|
|
642
|
-
double_click: (0, ai_1.tool)({
|
|
643
|
-
description: '在指定坐标执行双击操作',
|
|
644
|
-
inputSchema: zod_1.z.object({
|
|
645
|
-
pos: coord.describe('坐标 (x, y),0.0~1.0'),
|
|
646
|
-
log: logParam,
|
|
647
|
-
}),
|
|
648
|
-
}),
|
|
649
|
-
swipe: (0, ai_1.tool)({
|
|
650
|
-
description: '从起点滑动到终点。起点必须在可滑动区域内,滑动距离建议小于0.2。',
|
|
651
|
-
inputSchema: zod_1.z.object({
|
|
652
|
-
start: coord.describe('起点坐标 (x, y),0.0~1.0,必须在可滑动区域内'),
|
|
653
|
-
end: coord.describe('终点坐标 (x, y),0.0~1.0'),
|
|
654
|
-
direction: zod_1.z.enum(['left', 'right', 'up', 'down']).optional().describe('滑动方向'),
|
|
655
|
-
log: logParam,
|
|
656
|
-
}),
|
|
657
|
-
}),
|
|
658
|
-
drag: (0, ai_1.tool)({
|
|
659
|
-
description: '从起点拖拽到终点',
|
|
660
|
-
inputSchema: zod_1.z.object({
|
|
661
|
-
start: coord.describe('起点坐标 (x, y),0.0~1.0'),
|
|
662
|
-
end: coord.describe('终点坐标 (x, y),0.0~1.0'),
|
|
663
|
-
log: logParam,
|
|
664
|
-
}),
|
|
665
|
-
}),
|
|
666
|
-
input_text: (0, ai_1.tool)({
|
|
667
|
-
description: '在当前光标位置输入文本',
|
|
668
|
-
inputSchema: zod_1.z.object({
|
|
669
|
-
text: zod_1.z.string().describe('要输入的文本'),
|
|
670
|
-
log: logParam,
|
|
671
|
-
}),
|
|
672
|
-
}),
|
|
673
|
-
go_back: (0, ai_1.tool)({
|
|
674
|
-
description: '返回上一级',
|
|
675
|
-
inputSchema: zod_1.z.object({
|
|
676
|
-
times: zod_1.z.number().int().optional().describe('返回次数,默认1'),
|
|
677
|
-
log: logParam,
|
|
678
|
-
}),
|
|
679
|
-
}),
|
|
680
|
-
go_home: (0, ai_1.tool)({
|
|
681
|
-
description: '返回桌面',
|
|
682
|
-
inputSchema: zod_1.z.object({
|
|
683
|
-
times: zod_1.z.number().int().optional().describe('返回次数,默认1'),
|
|
684
|
-
log: logParam,
|
|
685
|
-
}),
|
|
686
|
-
}),
|
|
687
|
-
start_app: (0, ai_1.tool)({
|
|
688
|
-
description: '在设备上启动应用程序',
|
|
689
|
-
inputSchema: zod_1.z.object({
|
|
690
|
-
app_name: zod_1.z.string().describe('应用包名或显示名称,如"华为商城"或"com.huawei.hmos.vmall"'),
|
|
691
|
-
cold_start: zod_1.z.boolean().optional().describe('是否冷启动(先停止再启动)'),
|
|
692
|
-
log: logParam,
|
|
693
|
-
}),
|
|
694
|
-
}),
|
|
695
|
-
start_app_by_deep_link: (0, ai_1.tool)({
|
|
696
|
-
description: '通过 deeplink URI 启动应用(如 settings://wifi、myapp://page1)',
|
|
697
|
-
inputSchema: zod_1.z.object({
|
|
698
|
-
uri: zod_1.z.string().describe('deeplink URI'),
|
|
699
|
-
bundle_name: zod_1.z.string().optional().describe('应用包名(可选,显式指定)'),
|
|
700
|
-
ability_name: zod_1.z.string().optional().describe('Ability 名称(可选)'),
|
|
701
|
-
log: logParam,
|
|
702
|
-
}),
|
|
703
|
-
}),
|
|
704
|
-
stop_app: (0, ai_1.tool)({
|
|
705
|
-
description: '在设备上停止应用程序',
|
|
706
|
-
inputSchema: zod_1.z.object({
|
|
707
|
-
app_name: zod_1.z.string().describe('应用包名或显示名称'),
|
|
708
|
-
log: logParam,
|
|
709
|
-
}),
|
|
710
|
-
}),
|
|
711
|
-
wait: (0, ai_1.tool)({
|
|
712
|
-
description: '等待指定时间',
|
|
713
|
-
inputSchema: zod_1.z.object({
|
|
714
|
-
duration: zod_1.z.number().describe('等待时间(秒)'),
|
|
715
|
-
log: logParam,
|
|
716
|
-
}),
|
|
717
|
-
}),
|
|
718
|
-
press_key: (0, ai_1.tool)({
|
|
719
|
-
description: '按下物理按键',
|
|
720
|
-
inputSchema: zod_1.z.object({
|
|
721
|
-
key_name: zod_1.z.enum(['home', 'power', 'volume_up', 'volume_down']).describe('按键名称'),
|
|
722
|
-
log: logParam,
|
|
723
|
-
}),
|
|
724
|
-
}),
|
|
725
|
-
screen_on: (0, ai_1.tool)({
|
|
726
|
-
description: '打开设备屏幕(点亮屏幕)',
|
|
727
|
-
inputSchema: zod_1.z.object({
|
|
728
|
-
log: logParam,
|
|
729
|
-
}),
|
|
730
|
-
}),
|
|
731
|
-
unlock_screen: (0, ai_1.tool)({
|
|
732
|
-
description: '解锁设备屏幕(解除锁屏状态)',
|
|
733
|
-
inputSchema: zod_1.z.object({
|
|
734
|
-
log: logParam,
|
|
735
|
-
}),
|
|
736
|
-
}),
|
|
737
|
-
clear_recent_task: (0, ai_1.tool)({
|
|
738
|
-
description: '清空最近任务(清后台)',
|
|
739
|
-
inputSchema: zod_1.z.object({
|
|
740
|
-
log: logParam,
|
|
741
|
-
}),
|
|
742
|
-
}),
|
|
743
|
-
run_subagent: (0, ai_1.tool)({
|
|
744
|
-
description: '委托子代理执行特定任务(如滚动搜索、时间选择器等)。子代理在独立的步骤范围内运行,完成后返回结果。',
|
|
745
|
-
inputSchema: zod_1.z.object({
|
|
746
|
-
name: zod_1.z.string().describe('子代理名称(如 scroll_search, time_picker)'),
|
|
747
|
-
task_description: zod_1.z.string().describe('子代理的任务描述'),
|
|
748
|
-
}),
|
|
749
|
-
}),
|
|
750
|
-
judge: (0, ai_1.tool)({
|
|
751
|
-
description: '判定任务执行结论:输入任务执行的结论描述,返回 passed(是否通过)/should_continue(是否继续)/reason(原因)',
|
|
752
|
-
inputSchema: zod_1.z.object({
|
|
753
|
-
conclusion: zod_1.z.string().describe('任务执行的结论描述,包含执行结果、遇到的问题等信息'),
|
|
754
|
-
}),
|
|
755
|
-
}),
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
parseTextAction(text) {
|
|
759
|
-
const actionMatch = text.match(/action\s*:\s*(\w+)/i);
|
|
760
|
-
if (!actionMatch)
|
|
761
|
-
return null;
|
|
762
|
-
const toolName = actionMatch[1];
|
|
763
|
-
const argsMatch = text.match(/args\s*:\s*(\{[^}]*\})/i);
|
|
764
|
-
let args = {};
|
|
765
|
-
if (argsMatch) {
|
|
766
|
-
try {
|
|
767
|
-
args = JSON.parse(argsMatch[1]);
|
|
768
|
-
}
|
|
769
|
-
catch {
|
|
770
|
-
args = {};
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
return { tool: toolName, args };
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
exports.SingleAgent = SingleAgent;
|
|
777
|
-
/**
|
|
778
|
-
* FastActionAgent — ≤5-step quick-execute mode. Applies fast defaults: maxSteps=5,
|
|
779
|
-
* no retries, no post-tool screenshots, minimal inject, FAST_ACTION prompt.
|
|
780
|
-
*/
|
|
781
|
-
class FastActionAgent extends SingleAgent {
|
|
782
|
-
constructor(adapter, config, reportGenerator, hooks, llmCaller) {
|
|
783
|
-
const fastConfig = {
|
|
784
|
-
...config,
|
|
785
|
-
agent: {
|
|
786
|
-
...config.agent,
|
|
787
|
-
unified: {
|
|
788
|
-
...config.agent.unified,
|
|
789
|
-
maxSteps: 5,
|
|
790
|
-
maxResultRetries: 0,
|
|
791
|
-
screenshotOnToolEnd: false,
|
|
792
|
-
minimalInject: true,
|
|
793
|
-
parseMode: 'custom',
|
|
794
|
-
promptName: 'fast_action_v1.0',
|
|
795
|
-
},
|
|
796
|
-
},
|
|
797
|
-
};
|
|
798
|
-
super(adapter, fastConfig, reportGenerator, hooks, llmCaller);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
exports.FastActionAgent = FastActionAgent;
|