@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,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GeneralParser = void 0;
|
|
4
|
-
function lenientParse(text) {
|
|
5
|
-
const trimmed = text.trim();
|
|
6
|
-
try {
|
|
7
|
-
return JSON.parse(trimmed);
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
// fall through
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
const normalized = trimmed
|
|
14
|
-
.replace(/'/g, '"')
|
|
15
|
-
.replace(/\bTrue\b/g, 'true')
|
|
16
|
-
.replace(/\bFalse\b/g, 'false')
|
|
17
|
-
.replace(/\bNone\b/g, 'null');
|
|
18
|
-
return JSON.parse(normalized);
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// fall through
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
class GeneralParser {
|
|
26
|
-
get coordinateScale() {
|
|
27
|
-
return 1;
|
|
28
|
-
}
|
|
29
|
-
parse(rawResponse, screenWidth, screenHeight) {
|
|
30
|
-
const content = rawResponse.trim();
|
|
31
|
-
const complete = this.extractCompleteGoal(content);
|
|
32
|
-
if (complete !== null) {
|
|
33
|
-
return { _metadata: 'finish', message: complete };
|
|
34
|
-
}
|
|
35
|
-
const errorMessage = this.extractTagContent(content, 'error');
|
|
36
|
-
if (errorMessage) {
|
|
37
|
-
return { _metadata: 'finish', message: errorMessage };
|
|
38
|
-
}
|
|
39
|
-
const logContent = this.extractTagContent(content, 'log');
|
|
40
|
-
const actionType = this.extractTagContent(content, 'action-type');
|
|
41
|
-
if (!actionType) {
|
|
42
|
-
throw new Error('Missing action-type');
|
|
43
|
-
}
|
|
44
|
-
const actionParams = this.extractTagContent(content, 'action-param-json');
|
|
45
|
-
const params = this.parseParams(actionParams);
|
|
46
|
-
const action = this.mapAction(actionType.trim(), params, screenWidth, screenHeight);
|
|
47
|
-
if (action === null) {
|
|
48
|
-
return { _metadata: 'finish', message: `Unsupported action: ${actionType}` };
|
|
49
|
-
}
|
|
50
|
-
if (logContent) {
|
|
51
|
-
action.log = logContent.trim();
|
|
52
|
-
}
|
|
53
|
-
return action;
|
|
54
|
-
}
|
|
55
|
-
extractCompleteGoal(content) {
|
|
56
|
-
const match = content.match(/<complete-goal\b[^>]*>([\s\S]*?)<\/complete-goal>/i);
|
|
57
|
-
if (!match) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const message = match[1].trim();
|
|
61
|
-
return message || 'Task completed';
|
|
62
|
-
}
|
|
63
|
-
extractTagContent(content, tag) {
|
|
64
|
-
const pattern = new RegExp(`<${tag}>([\\s\\S]*?)<\\/${tag}>`, 'i');
|
|
65
|
-
const match = content.match(pattern);
|
|
66
|
-
if (!match) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
return match[1].trim();
|
|
70
|
-
}
|
|
71
|
-
parseParams(text) {
|
|
72
|
-
if (!text) {
|
|
73
|
-
return {};
|
|
74
|
-
}
|
|
75
|
-
const trimmed = text.trim();
|
|
76
|
-
const value = lenientParse(trimmed);
|
|
77
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
return {};
|
|
81
|
-
}
|
|
82
|
-
mapAction(actionType, params, screenWidth, screenHeight) {
|
|
83
|
-
if (actionType === 'Tap') {
|
|
84
|
-
const point = this.resolvePoint(params.element ?? params.locate, screenWidth, screenHeight);
|
|
85
|
-
if (point) {
|
|
86
|
-
return { _metadata: 'do', action: 'Tap', element: point };
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
if (actionType === 'Double Tap') {
|
|
91
|
-
const point = this.resolvePoint(params.element ?? params.locate, screenWidth, screenHeight);
|
|
92
|
-
if (point) {
|
|
93
|
-
return { _metadata: 'do', action: 'Double Tap', element: point };
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
if (actionType === 'Long Press') {
|
|
98
|
-
const point = this.resolvePoint(params.element ?? params.locate, screenWidth, screenHeight);
|
|
99
|
-
if (point) {
|
|
100
|
-
return { _metadata: 'do', action: 'Long Press', element: point };
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
if (actionType === 'Type') {
|
|
105
|
-
const text = params.text ?? params.value ?? '';
|
|
106
|
-
return { _metadata: 'do', action: 'Type', text };
|
|
107
|
-
}
|
|
108
|
-
if (actionType === 'Swipe') {
|
|
109
|
-
const start = this.resolvePoint(params.start, screenWidth, screenHeight);
|
|
110
|
-
const end = this.resolvePoint(params.end, screenWidth, screenHeight);
|
|
111
|
-
if (start && end) {
|
|
112
|
-
return { _metadata: 'do', action: 'Swipe', start, end };
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
if (actionType === 'Back') {
|
|
117
|
-
return { _metadata: 'do', action: 'Back' };
|
|
118
|
-
}
|
|
119
|
-
if (actionType === 'Home') {
|
|
120
|
-
return { _metadata: 'do', action: 'Home' };
|
|
121
|
-
}
|
|
122
|
-
if (actionType === 'Launch') {
|
|
123
|
-
const app = params.app ?? params.uri;
|
|
124
|
-
if (app) {
|
|
125
|
-
return { _metadata: 'do', action: 'Launch', app };
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
if (actionType === 'Wait') {
|
|
130
|
-
const duration = params.duration ?? '1 seconds';
|
|
131
|
-
return { _metadata: 'do', action: 'Wait', duration };
|
|
132
|
-
}
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
resolvePoint(value, screenWidth, screenHeight) {
|
|
136
|
-
if (value === null || value === undefined) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
140
|
-
const obj = value;
|
|
141
|
-
const bbox = obj.bbox;
|
|
142
|
-
if (Array.isArray(bbox)) {
|
|
143
|
-
if (bbox.length === 4) {
|
|
144
|
-
const x1 = this.normalizeCoord(bbox[0], screenWidth);
|
|
145
|
-
const y1 = this.normalizeCoord(bbox[1], screenHeight);
|
|
146
|
-
const x2 = this.normalizeCoord(bbox[2], screenWidth);
|
|
147
|
-
const y2 = this.normalizeCoord(bbox[3], screenHeight);
|
|
148
|
-
if (x1 !== null && y1 !== null && x2 !== null && y2 !== null) {
|
|
149
|
-
return [Math.floor((x1 + x2) / 2), Math.floor((y1 + y2) / 2)];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (obj.x !== undefined && obj.y !== undefined) {
|
|
154
|
-
const x = this.normalizeCoord(obj.x, screenWidth);
|
|
155
|
-
const y = this.normalizeCoord(obj.y, screenHeight);
|
|
156
|
-
if (x !== null && y !== null) {
|
|
157
|
-
return [x, y];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
if (Array.isArray(value)) {
|
|
163
|
-
if (value.length === 2) {
|
|
164
|
-
const x = this.normalizeCoord(value[0], screenWidth);
|
|
165
|
-
const y = this.normalizeCoord(value[1], screenHeight);
|
|
166
|
-
if (x !== null && y !== null) {
|
|
167
|
-
return [x, y];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (value.length === 4) {
|
|
171
|
-
return this.resolvePoint({ bbox: value }, screenWidth, screenHeight);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
normalizeCoord(value, total) {
|
|
177
|
-
const coord = typeof value === 'string' ? parseFloat(value) : typeof value === 'number' ? value : NaN;
|
|
178
|
-
if (Number.isNaN(coord)) {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
if (coord <= 1) {
|
|
182
|
-
return Math.floor(coord * total);
|
|
183
|
-
}
|
|
184
|
-
if (coord <= this.coordinateScale) {
|
|
185
|
-
return Math.floor((coord / this.coordinateScale) * total);
|
|
186
|
-
}
|
|
187
|
-
return Math.floor(coord);
|
|
188
|
-
}
|
|
189
|
-
normalizeDistance(value, total, fallbackRatio) {
|
|
190
|
-
if (value === null || value === undefined) {
|
|
191
|
-
return total * fallbackRatio;
|
|
192
|
-
}
|
|
193
|
-
const dist = typeof value === 'string' ? parseFloat(value) : typeof value === 'number' ? value : NaN;
|
|
194
|
-
if (Number.isNaN(dist)) {
|
|
195
|
-
return total * fallbackRatio;
|
|
196
|
-
}
|
|
197
|
-
if (dist <= 1) {
|
|
198
|
-
return total * dist;
|
|
199
|
-
}
|
|
200
|
-
if (dist <= this.coordinateScale) {
|
|
201
|
-
return total * (dist / this.coordinateScale);
|
|
202
|
-
}
|
|
203
|
-
return dist;
|
|
204
|
-
}
|
|
205
|
-
buildSwipeByDirection(direction, distance, screenWidth, screenHeight) {
|
|
206
|
-
if (direction !== 'up' && direction !== 'down' && direction !== 'left' && direction !== 'right') {
|
|
207
|
-
return { start: null, end: null };
|
|
208
|
-
}
|
|
209
|
-
const centerX = Math.floor(screenWidth * 0.5);
|
|
210
|
-
const centerY = Math.floor(screenHeight * 0.5);
|
|
211
|
-
let start;
|
|
212
|
-
let end;
|
|
213
|
-
if (direction === 'up' || direction === 'down') {
|
|
214
|
-
const dist = this.normalizeDistance(distance, screenHeight, 0.4);
|
|
215
|
-
if (direction === 'up') {
|
|
216
|
-
start = [centerX, Math.floor(centerY + dist / 2)];
|
|
217
|
-
end = [centerX, Math.floor(centerY - dist / 2)];
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
start = [centerX, Math.floor(centerY - dist / 2)];
|
|
221
|
-
end = [centerX, Math.floor(centerY + dist / 2)];
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
const dist = this.normalizeDistance(distance, screenWidth, 0.4);
|
|
226
|
-
if (direction === 'left') {
|
|
227
|
-
start = [Math.floor(centerX + dist / 2), centerY];
|
|
228
|
-
end = [Math.floor(centerX - dist / 2), centerY];
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
start = [Math.floor(centerX - dist / 2), centerY];
|
|
232
|
-
end = [Math.floor(centerX + dist / 2), centerY];
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
start = [this.clamp(start[0], 0, screenWidth), this.clamp(start[1], 0, screenHeight)];
|
|
236
|
-
end = [this.clamp(end[0], 0, screenWidth), this.clamp(end[1], 0, screenHeight)];
|
|
237
|
-
return { start, end };
|
|
238
|
-
}
|
|
239
|
-
clamp(value, minValue, maxValue) {
|
|
240
|
-
return Math.max(minValue, Math.min(value, maxValue));
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.GeneralParser = GeneralParser;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GLMParser = void 0;
|
|
4
|
-
function lenientParseValue(valueStr) {
|
|
5
|
-
const trimmed = valueStr.trim();
|
|
6
|
-
if (!trimmed) {
|
|
7
|
-
return '';
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(trimmed);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
// fall through
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const normalized = trimmed
|
|
17
|
-
.replace(/'/g, '"')
|
|
18
|
-
.replace(/\bTrue\b/g, 'true')
|
|
19
|
-
.replace(/\bFalse\b/g, 'false')
|
|
20
|
-
.replace(/\bNone\b/g, 'null');
|
|
21
|
-
return JSON.parse(normalized);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return trimmed;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
class GLMParser {
|
|
28
|
-
get coordinateScale() {
|
|
29
|
-
return 1;
|
|
30
|
-
}
|
|
31
|
-
parse(rawResponse, screenWidth, screenHeight) {
|
|
32
|
-
const actionStr = rawResponse.trim();
|
|
33
|
-
if (actionStr.startsWith('finish(')) {
|
|
34
|
-
return this.parseFinish(actionStr);
|
|
35
|
-
}
|
|
36
|
-
if (actionStr.startsWith('do(')) {
|
|
37
|
-
return this.parseDo(actionStr, screenWidth, screenHeight);
|
|
38
|
-
}
|
|
39
|
-
throw new Error(`Unknown action format: ${actionStr}`);
|
|
40
|
-
}
|
|
41
|
-
parseFinish(actionStr) {
|
|
42
|
-
try {
|
|
43
|
-
const params = this.extractParams(actionStr, 'finish');
|
|
44
|
-
return {
|
|
45
|
-
_metadata: 'finish',
|
|
46
|
-
message: params.message ?? 'Task completed',
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
throw new Error(`Failed to parse finish action: ${e instanceof Error ? e.message : String(e)}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
parseDo(actionStr, screenWidth, screenHeight) {
|
|
54
|
-
try {
|
|
55
|
-
const params = this.extractParams(actionStr, 'do');
|
|
56
|
-
const actionName = params.action ?? '';
|
|
57
|
-
const result = {
|
|
58
|
-
_metadata: 'do',
|
|
59
|
-
action: actionName,
|
|
60
|
-
};
|
|
61
|
-
for (const [key, value] of Object.entries(params)) {
|
|
62
|
-
if (key !== 'action') {
|
|
63
|
-
if ((key === 'element' || key === 'start' || key === 'end') &&
|
|
64
|
-
Array.isArray(value)) {
|
|
65
|
-
result[key] = this.convertRelativeToAbsolute(value, screenWidth, screenHeight);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
result[key] = value;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
throw new Error(`Failed to parse do action: ${e instanceof Error ? e.message : String(e)}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
convertRelativeToAbsolute(element, screenWidth, screenHeight) {
|
|
79
|
-
if (element.length !== 2) {
|
|
80
|
-
return [...element];
|
|
81
|
-
}
|
|
82
|
-
const x = Math.floor((element[0] / 1000) * screenWidth);
|
|
83
|
-
const y = Math.floor((element[1] / 1000) * screenHeight);
|
|
84
|
-
return [x, y];
|
|
85
|
-
}
|
|
86
|
-
extractParams(actionStr, functionName) {
|
|
87
|
-
const prefix = `${functionName}(`;
|
|
88
|
-
if (!actionStr.startsWith(prefix)) {
|
|
89
|
-
throw new Error(`Action does not start with ${prefix}`);
|
|
90
|
-
}
|
|
91
|
-
const paramsStr = actionStr.slice(prefix.length, -1);
|
|
92
|
-
const params = {};
|
|
93
|
-
let currentKey = null;
|
|
94
|
-
let currentValue = '';
|
|
95
|
-
let inQuotes = false;
|
|
96
|
-
let quoteChar = null;
|
|
97
|
-
let bracketDepth = 0;
|
|
98
|
-
for (let i = 0; i < paramsStr.length; i++) {
|
|
99
|
-
const char = paramsStr[i];
|
|
100
|
-
if ((char === '"' || char === "'") && (i === 0 || paramsStr[i - 1] !== '\\')) {
|
|
101
|
-
if (!inQuotes) {
|
|
102
|
-
inQuotes = true;
|
|
103
|
-
quoteChar = char;
|
|
104
|
-
}
|
|
105
|
-
else if (char === quoteChar) {
|
|
106
|
-
inQuotes = false;
|
|
107
|
-
quoteChar = null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (!inQuotes) {
|
|
111
|
-
if (char === '[' || char === '{') {
|
|
112
|
-
bracketDepth += 1;
|
|
113
|
-
}
|
|
114
|
-
else if (char === ']' || char === '}') {
|
|
115
|
-
bracketDepth -= 1;
|
|
116
|
-
}
|
|
117
|
-
if (char === '=' && bracketDepth === 0) {
|
|
118
|
-
currentKey = currentValue.trim();
|
|
119
|
-
currentValue = '';
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (char === ',' && bracketDepth === 0) {
|
|
123
|
-
if (currentKey) {
|
|
124
|
-
params[currentKey] = lenientParseValue(currentValue.trim());
|
|
125
|
-
currentKey = null;
|
|
126
|
-
currentValue = '';
|
|
127
|
-
}
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
currentValue += char;
|
|
132
|
-
}
|
|
133
|
-
if (currentKey) {
|
|
134
|
-
params[currentKey] = lenientParseValue(currentValue.trim());
|
|
135
|
-
}
|
|
136
|
-
return params;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.GLMParser = GLMParser;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MaiUiParser = exports.GLMParser = exports.GeneralParser = void 0;
|
|
4
|
-
var general_parser_1 = require("./general_parser");
|
|
5
|
-
Object.defineProperty(exports, "GeneralParser", { enumerable: true, get: function () { return general_parser_1.GeneralParser; } });
|
|
6
|
-
var glm_parser_1 = require("./glm_parser");
|
|
7
|
-
Object.defineProperty(exports, "GLMParser", { enumerable: true, get: function () { return glm_parser_1.GLMParser; } });
|
|
8
|
-
var mai_ui_parser_1 = require("./mai_ui_parser");
|
|
9
|
-
Object.defineProperty(exports, "MaiUiParser", { enumerable: true, get: function () { return mai_ui_parser_1.MaiUiParser; } });
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MaiUiParser = void 0;
|
|
4
|
-
class MaiUiParser {
|
|
5
|
-
get coordinateScale() {
|
|
6
|
-
return 1;
|
|
7
|
-
}
|
|
8
|
-
parse(llmOutput, _screenWidth, _screenHeight) {
|
|
9
|
-
const result = this.parseTaggedText(llmOutput);
|
|
10
|
-
if (!result.toolCall) {
|
|
11
|
-
throw new Error('No tool call found in output');
|
|
12
|
-
}
|
|
13
|
-
return result.toolCall;
|
|
14
|
-
}
|
|
15
|
-
parseTaggedText(text) {
|
|
16
|
-
const result = {
|
|
17
|
-
thinking: null,
|
|
18
|
-
toolCall: null,
|
|
19
|
-
};
|
|
20
|
-
// Extract thinking content (handles both standard closing tag and
|
|
21
|
-
// thinking-model style where the closing tag may be omitted/mangled).
|
|
22
|
-
const thinkingMatch = text.match(/<thinking>([\s\S]*?)(<\/thinking>|$)/i);
|
|
23
|
-
if (thinkingMatch) {
|
|
24
|
-
result.thinking = thinkingMatch[1].trim().replace(/^"|"$/g, '');
|
|
25
|
-
}
|
|
26
|
-
const afterThinking = thinkingMatch ? text.slice(thinkingMatch.index + thinkingMatch[0].length) : text;
|
|
27
|
-
const jsonText = this.extractJsonBlock(afterThinking) ?? this.extractFirstJsonObject(afterThinking);
|
|
28
|
-
if (jsonText) {
|
|
29
|
-
try {
|
|
30
|
-
const parsed = JSON.parse(jsonText);
|
|
31
|
-
const name = parsed.name ?? '';
|
|
32
|
-
const argumentsObj = parsed.arguments ?? {};
|
|
33
|
-
result.toolCall = { name, arguments: argumentsObj };
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
throw new Error(`Invalid JSON in tool_call: ${e instanceof Error ? e.message : String(e)}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
extractJsonBlock(text) {
|
|
42
|
-
const fenceMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
43
|
-
if (fenceMatch) {
|
|
44
|
-
return fenceMatch[1].trim();
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
extractFirstJsonObject(text) {
|
|
49
|
-
const start = text.indexOf('{');
|
|
50
|
-
if (start < 0) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
let depth = 0;
|
|
54
|
-
let inString = false;
|
|
55
|
-
let escape = false;
|
|
56
|
-
for (let i = start; i < text.length; i++) {
|
|
57
|
-
const ch = text[i];
|
|
58
|
-
if (inString) {
|
|
59
|
-
if (escape) {
|
|
60
|
-
escape = false;
|
|
61
|
-
}
|
|
62
|
-
else if (ch === '\\') {
|
|
63
|
-
escape = true;
|
|
64
|
-
}
|
|
65
|
-
else if (ch === '"') {
|
|
66
|
-
inString = false;
|
|
67
|
-
}
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (ch === '"') {
|
|
71
|
-
inString = true;
|
|
72
|
-
}
|
|
73
|
-
else if (ch === '{') {
|
|
74
|
-
depth += 1;
|
|
75
|
-
}
|
|
76
|
-
else if (ch === '}') {
|
|
77
|
-
depth -= 1;
|
|
78
|
-
if (depth === 0) {
|
|
79
|
-
return text.slice(start, i + 1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
convertRelativeToAbsolute(element, screenWidth, screenHeight) {
|
|
86
|
-
if (element.length !== 2) {
|
|
87
|
-
return [...element];
|
|
88
|
-
}
|
|
89
|
-
const x = Math.floor((element[0] / 1000) * screenWidth);
|
|
90
|
-
const y = Math.floor((element[1] / 1000) * screenHeight);
|
|
91
|
-
return [x, y];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.MaiUiParser = MaiUiParser;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SYSTEM_PROMPT = void 0;
|
|
4
|
-
exports.SYSTEM_PROMPT = `You are the execution-layer Agent, responsible for strictly executing instructions from the superior (decision layer).
|
|
5
|
-
|
|
6
|
-
## Core Positioning (Highest Priority)
|
|
7
|
-
|
|
8
|
-
You are the execution layer, not the decision layer.
|
|
9
|
-
- Your responsibility: execute instructions from the superior, do not judge whether the instruction is meaningful.
|
|
10
|
-
- Your superior (Planner): responsible for decisions, judging whether the task is complete.
|
|
11
|
-
- Your role: tool executor, not task decision-maker.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Mandatory Execution Rules (Must Follow)
|
|
16
|
-
|
|
17
|
-
Must execute:
|
|
18
|
-
- Receive an instruction from the superior then must execute, do not judge whether it is meaningful.
|
|
19
|
-
- The superior asks to swipe then must swipe, do not judge whether there is content.
|
|
20
|
-
- The superior asks to click then must click, do not judge whether it is correct.
|
|
21
|
-
|
|
22
|
-
Forbidden autonomous behaviors:
|
|
23
|
-
- Forbidden to autonomously terminate (task completion is judged by the superior).
|
|
24
|
-
- Forbidden to autonomously go back (going back is decided by the superior).
|
|
25
|
-
- Forbidden to autonomously explore (exploration is planned by the superior).
|
|
26
|
-
- Forbidden to judge whether an operation is meaningful.
|
|
27
|
-
- Forbidden to think about whether you should go back to the previous level.
|
|
28
|
-
- Forbidden to think about whether the task is complete.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## Output Format
|
|
33
|
-
|
|
34
|
-
Each operation must contain two parts:
|
|
35
|
-
1. Thinking process: describe observation and localization inside thinking tags.
|
|
36
|
-
2. Action instruction: return a JSON function call inside a json code fence.
|
|
37
|
-
|
|
38
|
-
Example:
|
|
39
|
-
|
|
40
|
-
${'<thinking>\n' +
|
|
41
|
-
'**Observation**: The current screen shows a short-video playback interface, the superior asks to swipe up.\n' +
|
|
42
|
-
'**Localization**: The superior asks to swipe in the middle area of the screen, the coordinate area is about [0.3-0.7, 0.4-0.6].\n' +
|
|
43
|
-
'**Execution**: Swipe from bottom to top in the middle of the screen.\n' +
|
|
44
|
-
'</thinking>\n' +
|
|
45
|
-
'```json\n' +
|
|
46
|
-
'{"name": "swipe", "arguments": {"direction": "up", "coordinate": [0.5, 0.5]}}\n' +
|
|
47
|
-
'```'}
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## Action Space (Strictly Follow)
|
|
52
|
-
|
|
53
|
-
### Basic Operations
|
|
54
|
-
- Click: {"name": "click", "arguments": {"coordinate": [x, y]}}
|
|
55
|
-
Used to click the UI element specified by the superior.
|
|
56
|
-
|
|
57
|
-
- Long press: {"name": "long_press", "arguments": {"coordinate": [x, y]}}
|
|
58
|
-
Used to long-press the element specified by the superior.
|
|
59
|
-
|
|
60
|
-
- Type text: {"name": "type", "arguments": {"text": "text to input"}}
|
|
61
|
-
You must click the input box to focus it first, then use this action to input text.
|
|
62
|
-
|
|
63
|
-
### Swipe Operations
|
|
64
|
-
- Swipe: {"name": "swipe", "arguments": {"direction": "up|down|left|right", "coordinate": [x, y]}}
|
|
65
|
-
direction options: up (swipe up), down (swipe down), left (swipe left), right (swipe right).
|
|
66
|
-
coordinate: specifies the swipe start point (the position specified by the superior).
|
|
67
|
-
|
|
68
|
-
- Drag: {"name": "drag", "arguments": {"start_coordinate": [x1, y1], "end_coordinate": [x2, y2]}}
|
|
69
|
-
Used to drag an element to a new position (the start and end points specified by the superior).
|
|
70
|
-
|
|
71
|
-
### System Operations
|
|
72
|
-
- Open app: {"name": "open", "arguments": {"text": "app name"}}
|
|
73
|
-
Used to open the app specified by the superior.
|
|
74
|
-
|
|
75
|
-
### Wait Operations
|
|
76
|
-
- Wait: {"name": "wait", "arguments": {}}
|
|
77
|
-
Used to wait for the page to load (only used when the superior instruction includes waiting).
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Coordinate System
|
|
82
|
-
- Range: both x and y are between [0.000, 1.000].
|
|
83
|
-
- Origin: (0.000, 0.000) is the top-left corner of the screen.
|
|
84
|
-
- Boundary: (1.000, 1.000) is the bottom-right corner of the screen.
|
|
85
|
-
- Precision: coordinates are normalized and will be automatically mapped to the actual screen resolution.
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
## Thinking Process Template (Strictly Follow)
|
|
90
|
-
|
|
91
|
-
Only three parts:
|
|
92
|
-
1. Observation: What does the current screen show? What is the operation target requested by the superior?
|
|
93
|
-
2. Localization: Where is the element the superior asks to operate on? What are the coordinates?
|
|
94
|
-
3. Execution: Return the execution instruction.
|
|
95
|
-
|
|
96
|
-
Forbidden to include:
|
|
97
|
-
- Whether this operation is meaningful.
|
|
98
|
-
- Whether you should go back to the previous level.
|
|
99
|
-
- Whether the task is complete.
|
|
100
|
-
- What to do when the target element cannot be found.
|
|
101
|
-
- Slide to view when the page content is not fully displayed.
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Mandatory Principles Reiteration (Must Strictly Follow)
|
|
106
|
-
|
|
107
|
-
- Strict execution: receive the instruction and must execute, do not judge the meaning.
|
|
108
|
-
- No autonomy: no terminate, no autonomous back, no autonomous explore.
|
|
109
|
-
- Observe-Locate-Execute: the thinking process only includes the three steps of observation, localization, and execution.`;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleReporter = void 0;
|
|
4
|
-
class SimpleReporter {
|
|
5
|
-
addEvent(event) {
|
|
6
|
-
console.log(JSON.stringify(event));
|
|
7
|
-
}
|
|
8
|
-
addTokenUsage(_usage, _source, _stepNumber) {
|
|
9
|
-
// no-op
|
|
10
|
-
}
|
|
11
|
-
setTask(_task) {
|
|
12
|
-
// no-op
|
|
13
|
-
}
|
|
14
|
-
setTestCase(_testCase) {
|
|
15
|
-
// no-op
|
|
16
|
-
}
|
|
17
|
-
startTask() {
|
|
18
|
-
// no-op
|
|
19
|
-
}
|
|
20
|
-
endTask(_result, _status) {
|
|
21
|
-
// no-op
|
|
22
|
-
}
|
|
23
|
-
saveScreenshot(_base64Data, _layoutData, _prefix) {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
saveAll(_baseFilename) {
|
|
27
|
-
return Promise.resolve({});
|
|
28
|
-
}
|
|
29
|
-
getReportDir() {
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.SimpleReporter = SimpleReporter;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sleep = sleep;
|
|
4
|
-
exports.sleepSync = sleepSync;
|
|
5
|
-
exports.waitIfNotExceed = waitIfNotExceed;
|
|
6
|
-
exports.asyncWaitIfNotExceed = asyncWaitIfNotExceed;
|
|
7
|
-
exports.runAsyncFunc = runAsyncFunc;
|
|
8
|
-
function sleep(seconds) {
|
|
9
|
-
return new Promise((resolve) => setTimeout(resolve, Math.max(0, seconds * 1000)));
|
|
10
|
-
}
|
|
11
|
-
function sleepSync(seconds) {
|
|
12
|
-
const ms = Math.max(0, seconds * 1000);
|
|
13
|
-
const end = Date.now() + ms;
|
|
14
|
-
while (Date.now() < end) {
|
|
15
|
-
// Synchronous sleep used only for short waits that must not yield the event loop.
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function waitIfNotExceed(waitTime, startTimestamp) {
|
|
19
|
-
if (startTimestamp === undefined || startTimestamp === null) {
|
|
20
|
-
sleepSync(waitTime);
|
|
21
|
-
return waitTime;
|
|
22
|
-
}
|
|
23
|
-
const elapse = (Date.now() - startTimestamp * 1000) / 1000;
|
|
24
|
-
if (elapse >= waitTime) {
|
|
25
|
-
return 0;
|
|
26
|
-
}
|
|
27
|
-
const actualWaitTime = waitTime - elapse;
|
|
28
|
-
sleepSync(actualWaitTime);
|
|
29
|
-
return actualWaitTime;
|
|
30
|
-
}
|
|
31
|
-
async function asyncWaitIfNotExceed(waitTime, startTimestamp) {
|
|
32
|
-
if (startTimestamp === undefined || startTimestamp === null) {
|
|
33
|
-
await sleep(waitTime);
|
|
34
|
-
return waitTime;
|
|
35
|
-
}
|
|
36
|
-
const elapse = (Date.now() - startTimestamp * 1000) / 1000;
|
|
37
|
-
if (elapse >= waitTime) {
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
const actualWaitTime = waitTime - elapse;
|
|
41
|
-
await sleep(actualWaitTime);
|
|
42
|
-
return actualWaitTime;
|
|
43
|
-
}
|
|
44
|
-
async function runAsyncFunc(fn, timeout) {
|
|
45
|
-
if (timeout !== undefined && timeout > 0) {
|
|
46
|
-
return await Promise.race([
|
|
47
|
-
fn(),
|
|
48
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error(`Operation timed out after ${timeout}s`)), timeout * 1000)),
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
51
|
-
return await fn();
|
|
52
|
-
}
|