@autotest/agent 0.0.5 → 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 +10 -0
- package/dist/api/agent_api.d.ts +2 -2
- package/dist/autotest-cli.js +1 -397
- package/dist/common/config/config.yaml +5 -0
- package/dist/common/config/manager.d.ts +7 -7
- package/dist/common/config/types.d.ts +33 -1
- package/dist/common/dfx/index.d.ts +1 -1
- package/dist/common/image_helper.d.ts +2 -2
- package/dist/common/llm_cache/cache_transport.d.ts +1 -1
- package/dist/common/llm_cache/prompt_cache.d.ts +2 -2
- package/dist/common/utils.d.ts +5 -5
- package/dist/core/agent/layered_agent/agent_registry.d.ts +3 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +1 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +1 -1
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +1 -1
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/agent.d.ts +5 -5
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/mapping.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/parse.d.ts +1 -1
- package/dist/core/agent/rewrite_agent/types.d.ts +1 -1
- package/dist/core/agent/single_agent/agent.d.ts +2 -2
- package/dist/core/agent/single_agent/hook_manager.d.ts +1 -2
- package/dist/core/agent/single_agent/image_utils.d.ts +1 -2
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +5 -5
- package/dist/core/agent/single_agent/subagent_manager.d.ts +1 -2
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +3 -3
- package/dist/core/device/device_protocol.d.ts +1 -1
- package/dist/core/device/hdc/device.d.ts +1 -1
- package/dist/core/device/index.d.ts +2 -2
- package/dist/core/knowledge/knowledge_manager.d.ts +1 -1
- package/dist/core/knowledge/vectordb.d.ts +1 -1
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +1 -0
- package/dist/core/mcp/mcp_tools.d.ts +11 -2
- package/dist/core/mcp/verify_tool.d.ts +12 -0
- package/dist/core/memory/_utils.d.ts +1 -1
- package/dist/core/memory/index.d.ts +1 -1
- package/dist/core/memory/memory_manager.d.ts +1 -1
- package/dist/core/memory/replan_manager.d.ts +1 -1
- package/dist/core/memory/tool_player.d.ts +5 -5
- package/dist/core/memory/tool_player_popup.d.ts +1 -1
- package/dist/core/memory/tool_player_replan.d.ts +1 -1
- package/dist/core/memory/tool_player_xpath.d.ts +3 -3
- package/dist/core/prompt/prompt_loader.d.ts +1 -1
- package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
- package/dist/core/skill/skill_manager.d.ts +2 -2
- package/dist/data_types/device.d.ts +1 -1
- package/dist/data_types/index.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -164
- package/dist/loop/cli.d.ts +4 -4
- package/dist/loop/orchestrator.d.ts +6 -6
- package/dist/loop/result_writer.d.ts +1 -1
- package/dist/loop/types.d.ts +1 -1
- package/dist/tools/batch_runner.js +1 -745
- package/dist/tools/case_runner/report.d.ts +1 -1
- package/dist/tools/case_runner/runner.d.ts +3 -3
- package/dist/tools/case_runner/runner.js +1 -410
- package/dist/tools/config/config_tool.d.ts +6 -6
- package/dist/tools/config/config_tool.js +1 -339
- package/dist/tools/prompt_compare/compare_runner.d.ts +2 -2
- 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 -184
- 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 -525
- 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 -75
- package/dist/core/agent/layered_agent/decision.js +0 -516
- 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 -798
- package/dist/core/agent/single_agent/hook_manager.js +0 -60
- package/dist/core/agent/single_agent/hooks.js +0 -288
- package/dist/core/agent/single_agent/image_utils.js +0 -159
- package/dist/core/agent/single_agent/scroll_search_agent.js +0 -376
- package/dist/core/agent/single_agent/subagent_manager.js +0 -73
- 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 -782
- 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 -410
- 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 -524
- 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,410 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* MCP tool definitions for the agent.
|
|
4
|
-
*
|
|
5
|
-
* Registers async tool functions that drive the executor device (start/stop
|
|
6
|
-
* apps, navigation, waiting, skill loading, verification, etc.). Tools are
|
|
7
|
-
* collected into a registry so they can be enumerated and invoked by name.
|
|
8
|
-
*/
|
|
9
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
-
var ownKeys = function(o) {
|
|
27
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
-
var ar = [];
|
|
29
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
-
return ar;
|
|
31
|
-
};
|
|
32
|
-
return ownKeys(o);
|
|
33
|
-
};
|
|
34
|
-
return function (mod) {
|
|
35
|
-
if (mod && mod.__esModule) return mod;
|
|
36
|
-
var result = {};
|
|
37
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
-
__setModuleDefault(result, mod);
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
})();
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.loadSkill = exports.login = exports.goHome = exports.wait = exports.goBackTwice = exports.goBack = exports.clearApp = exports.stopApp = exports.startApp = exports.chat = exports.TOOL_REGISTRY = void 0;
|
|
44
|
-
exports.addToBlacklist = addToBlacklist;
|
|
45
|
-
exports.collectFunctionTool = collectFunctionTool;
|
|
46
|
-
exports.getToolEntries = getToolEntries;
|
|
47
|
-
exports.getRegisteredTools = getRegisteredTools;
|
|
48
|
-
exports.getPackageNameMap = getPackageNameMap;
|
|
49
|
-
exports.getMainAbilityForBundle = getMainAbilityForBundle;
|
|
50
|
-
exports.verify = verify;
|
|
51
|
-
const fs = __importStar(require("fs"));
|
|
52
|
-
const logger_1 = require("../../common/logger");
|
|
53
|
-
const agent_registry_1 = require("../agent/layered_agent/agent_registry");
|
|
54
|
-
const skill_manager_1 = require("../skill/skill_manager");
|
|
55
|
-
const hdc_1 = require("../device/hdc");
|
|
56
|
-
const types_1 = require("../../reporter/types");
|
|
57
|
-
const custom_model_1 = require("../../common/model/custom_model");
|
|
58
|
-
/** Registry of all collected tool functions, keyed by name. */
|
|
59
|
-
exports.TOOL_REGISTRY = {};
|
|
60
|
-
/** Ordered list of tool entries with metadata (aligned with python _GLOBAL_TOOL_REGISTRY). */
|
|
61
|
-
const _TOOL_ENTRIES = [];
|
|
62
|
-
/** Tool blacklist — names excluded from getToolEntries() (aligned with python _TOOL_BLACKLIST). */
|
|
63
|
-
const _TOOL_BLACKLIST = new Set(['login']);
|
|
64
|
-
/** Add tool names to the blacklist. */
|
|
65
|
-
function addToBlacklist(...names) {
|
|
66
|
-
for (const n of names)
|
|
67
|
-
_TOOL_BLACKLIST.add(n);
|
|
68
|
-
logger_1.logger.debug(`[ToolRegistry] Blacklisted: ${names.join(', ')}`);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Register a tool function with metadata into the registry.
|
|
72
|
-
* Aligned with python collect_function_tool — stores both the function and
|
|
73
|
-
* its description/parameters so collectAllTools can build the Available Tools
|
|
74
|
-
* list dynamically instead of a hardcoded array.
|
|
75
|
-
*/
|
|
76
|
-
function collectFunctionTool(name, fn, meta) {
|
|
77
|
-
exports.TOOL_REGISTRY[name] = fn;
|
|
78
|
-
_TOOL_ENTRIES.push({
|
|
79
|
-
name,
|
|
80
|
-
description: meta?.description ?? `${name} tool`,
|
|
81
|
-
parameters: meta?.parameters ?? {},
|
|
82
|
-
fn,
|
|
83
|
-
});
|
|
84
|
-
logger_1.logger.debug(`[ToolRegistry] Registered: ${name}`);
|
|
85
|
-
return fn;
|
|
86
|
-
}
|
|
87
|
-
/** Get all registered tool entries, excluding blacklisted ones. */
|
|
88
|
-
function getToolEntries() {
|
|
89
|
-
if (_TOOL_BLACKLIST.size === 0)
|
|
90
|
-
return [..._TOOL_ENTRIES];
|
|
91
|
-
return _TOOL_ENTRIES.filter((e) => !_TOOL_BLACKLIST.has(e.name));
|
|
92
|
-
}
|
|
93
|
-
/** Get all registered tool functions. */
|
|
94
|
-
function getRegisteredTools() {
|
|
95
|
-
return Object.values(exports.TOOL_REGISTRY);
|
|
96
|
-
}
|
|
97
|
-
/** Get the current executor agent, throwing if none is registered. */
|
|
98
|
-
function getExecutorAgent() {
|
|
99
|
-
const agent = agent_registry_1.agentRegistry.getExecutorAgent();
|
|
100
|
-
if (!agent) {
|
|
101
|
-
throw new Error('Executor agent is not registered');
|
|
102
|
-
}
|
|
103
|
-
return agent;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the executor device for the current agent.
|
|
107
|
-
* Hybrid-style: prefers tool_manager (adapter) from registry, falls back to
|
|
108
|
-
* executor agent's device (aligned with python registry.get_tool_manager()._device).
|
|
109
|
-
*/
|
|
110
|
-
function getExecutorDevice() {
|
|
111
|
-
// Hybrid path: get adapter directly from registry
|
|
112
|
-
const adapter = agent_registry_1.agentRegistry.getToolManager();
|
|
113
|
-
if (adapter) {
|
|
114
|
-
return adapter;
|
|
115
|
-
}
|
|
116
|
-
// Fallback: legacy layered path
|
|
117
|
-
return getExecutorAgent().getDevice();
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Send a sub-task instruction to the executor model.
|
|
121
|
-
* @param message The sub-task instruction.
|
|
122
|
-
* @returns JSON with result, step count, success flag and filtered history.
|
|
123
|
-
*/
|
|
124
|
-
let _chatLock = null;
|
|
125
|
-
exports.chat = collectFunctionTool('chat', async (message) => {
|
|
126
|
-
// Serialize concurrent chat calls — aligned with Python's asyncio.Lock
|
|
127
|
-
while (_chatLock) {
|
|
128
|
-
await _chatLock.catch(() => { });
|
|
129
|
-
}
|
|
130
|
-
let resolveLock;
|
|
131
|
-
_chatLock = new Promise(r => { resolveLock = r; });
|
|
132
|
-
try {
|
|
133
|
-
return await _doChat(message);
|
|
134
|
-
}
|
|
135
|
-
finally {
|
|
136
|
-
_chatLock = null;
|
|
137
|
-
resolveLock('');
|
|
138
|
-
}
|
|
139
|
-
}, { description: 'Send a sub-task instruction to the executor (describe what to do in natural language, e.g. click a button, swipe, input text). The executor will look at the screen and perform the actual operation', parameters: { message: 'string' } });
|
|
140
|
-
async function _doChat(message) {
|
|
141
|
-
logger_1.logger.info(`\n[Executor] Running: ${message}`);
|
|
142
|
-
const executorAgent = getExecutorAgent();
|
|
143
|
-
const maxSteps = executorAgent.getAgentConfig().maxSteps;
|
|
144
|
-
try {
|
|
145
|
-
executorAgent.reset();
|
|
146
|
-
const result = await executorAgent.run(message);
|
|
147
|
-
const steps = executorAgent.stepCount;
|
|
148
|
-
logger_1.logger.info(`[Executor] Result (${steps} steps): ${result}`);
|
|
149
|
-
const filteredContext = [];
|
|
150
|
-
for (const msg of executorAgent.context) {
|
|
151
|
-
if (msg.role === 'system') {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const newMsg = { ...msg };
|
|
155
|
-
const content = msg.content;
|
|
156
|
-
if (Array.isArray(content)) {
|
|
157
|
-
newMsg.content = content.filter((item) => typeof item !== 'object' ||
|
|
158
|
-
item === null ||
|
|
159
|
-
(item.type !== 'image_url' &&
|
|
160
|
-
item.type !== 'image'));
|
|
161
|
-
}
|
|
162
|
-
filteredContext.push(newMsg);
|
|
163
|
-
}
|
|
164
|
-
const contextJson = JSON.stringify(filteredContext, null, 2);
|
|
165
|
-
if (steps >= maxSteps && result === 'Max steps reached') {
|
|
166
|
-
return JSON.stringify({
|
|
167
|
-
result: `Max step limit reached (${maxSteps} steps). The executor may have struggled and the task is incomplete. Please review the execution history. Suggestion: re-plan the task or split it into smaller sub-tasks.`,
|
|
168
|
-
steps: maxSteps,
|
|
169
|
-
success: false,
|
|
170
|
-
history: contextJson,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
return JSON.stringify({
|
|
174
|
-
result,
|
|
175
|
-
steps,
|
|
176
|
-
success: true,
|
|
177
|
-
history: contextJson,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
catch (e) {
|
|
181
|
-
logger_1.logger.info(`[Executor] Error: ${e instanceof Error ? e.message : String(e)}`);
|
|
182
|
-
return JSON.stringify({
|
|
183
|
-
result: e instanceof Error ? e.message : String(e),
|
|
184
|
-
success: false,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
/** Get the mapping of supported app display names to bundle names. */
|
|
189
|
-
async function getPackageNameMap() {
|
|
190
|
-
return hdc_1.APP_PACKAGES;
|
|
191
|
-
}
|
|
192
|
-
/** Resolve the main ability name for a bundle via runtime bm dump -n, defaulting to EntryAbility. */
|
|
193
|
-
function getMainAbility(bundleName) {
|
|
194
|
-
const result = hdc_1.APP_ABILITIES[bundleName];
|
|
195
|
-
if (result) {
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
|
-
// Try runtime resolution via bm dump -n
|
|
199
|
-
try {
|
|
200
|
-
const device = getExecutorDevice();
|
|
201
|
-
if (device && typeof device.driver?.shell === 'function') {
|
|
202
|
-
const output = device.driver.shell(`bm dump -n ${bundleName}`);
|
|
203
|
-
const match = output.match(/module-main-ability["']?\s*:\s*"([^"]+)"/);
|
|
204
|
-
if (match && match[1]) {
|
|
205
|
-
logger_1.logger.info(`Resolved main ability for ${bundleName} via bm dump: ${match[1]}`);
|
|
206
|
-
return match[1];
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
catch {
|
|
211
|
-
// Runtime resolution failed — fall through to default
|
|
212
|
-
}
|
|
213
|
-
logger_1.logger.info(`Fail to get main ability for bundle ${bundleName}, using default: EntryAbility`);
|
|
214
|
-
return 'EntryAbility';
|
|
215
|
-
}
|
|
216
|
-
/** Start an app by display name or bundle name (synchronous helper). */
|
|
217
|
-
async function doStartApp(appName) {
|
|
218
|
-
const bundleName = hdc_1.APP_PACKAGES[appName] ?? appName;
|
|
219
|
-
const device = getExecutorDevice();
|
|
220
|
-
const launched = await device.launchApp(appName);
|
|
221
|
-
if (!launched) {
|
|
222
|
-
return `start ${appName} failed!`;
|
|
223
|
-
}
|
|
224
|
-
// Poll for up to 10 seconds to confirm the app is in the foreground.
|
|
225
|
-
const startTime = Date.now();
|
|
226
|
-
while (Date.now() - startTime < 10000) {
|
|
227
|
-
const currentApp = await device.getCurrentApp();
|
|
228
|
-
if (currentApp === bundleName) {
|
|
229
|
-
return `start ${appName} successfully`;
|
|
230
|
-
}
|
|
231
|
-
await sleep(0.5);
|
|
232
|
-
}
|
|
233
|
-
return `start ${appName} failed!`;
|
|
234
|
-
}
|
|
235
|
-
/** Start an app by display name or bundle name. */
|
|
236
|
-
exports.startApp = collectFunctionTool('start_app', async (appName) => {
|
|
237
|
-
return doStartApp(appName);
|
|
238
|
-
}, { description: 'Start an application by display name or bundle name', parameters: { app_name: 'string' } });
|
|
239
|
-
/** Stop an app by display name or bundle name. */
|
|
240
|
-
exports.stopApp = collectFunctionTool('stop_app', async (appName) => {
|
|
241
|
-
const device = getExecutorDevice();
|
|
242
|
-
try {
|
|
243
|
-
await device.callTool('stop_app', { app_name: appName });
|
|
244
|
-
}
|
|
245
|
-
catch {
|
|
246
|
-
// fall back to home navigation
|
|
247
|
-
await device.home();
|
|
248
|
-
}
|
|
249
|
-
return `stop ${appName} successfully. Task finished. Please output the final result now.`;
|
|
250
|
-
}, { description: 'Stop an application by display name or bundle name', parameters: { app_name: 'string' } });
|
|
251
|
-
/** Clear an app's data to simulate a first-install state. */
|
|
252
|
-
exports.clearApp = collectFunctionTool('clear_app', async (appName) => {
|
|
253
|
-
const device = getExecutorDevice();
|
|
254
|
-
try {
|
|
255
|
-
await device.callTool('clear_app_data', { app_name: appName });
|
|
256
|
-
}
|
|
257
|
-
catch {
|
|
258
|
-
// ignore
|
|
259
|
-
}
|
|
260
|
-
return `clear ${appName} successfully`;
|
|
261
|
-
}, { description: 'Clear an application data to simulate first-install state', parameters: { app_name: 'string' } });
|
|
262
|
-
/** Press the back button once. */
|
|
263
|
-
exports.goBack = collectFunctionTool('go_back', async () => {
|
|
264
|
-
await getExecutorDevice().back();
|
|
265
|
-
return 'go back successfully';
|
|
266
|
-
}, { description: 'Press the back button once', parameters: {} });
|
|
267
|
-
/** Press the back button twice. */
|
|
268
|
-
exports.goBackTwice = collectFunctionTool('go_back_twice', async () => {
|
|
269
|
-
const device = getExecutorDevice();
|
|
270
|
-
await device.back();
|
|
271
|
-
await sleep(1);
|
|
272
|
-
await device.back();
|
|
273
|
-
return 'go back twice successfully';
|
|
274
|
-
}, { description: 'Press the back button twice', parameters: {} });
|
|
275
|
-
/** Wait for a number of seconds. */
|
|
276
|
-
exports.wait = collectFunctionTool('wait', async (times) => {
|
|
277
|
-
await sleep(times);
|
|
278
|
-
return JSON.stringify({
|
|
279
|
-
action: 'wait',
|
|
280
|
-
seconds: times,
|
|
281
|
-
message: `wait ${times} seconds successfully`,
|
|
282
|
-
});
|
|
283
|
-
}, { description: 'Wait for a specified number of seconds', parameters: { times: 'number' } });
|
|
284
|
-
/** Press the home button to return to the desktop. */
|
|
285
|
-
exports.goHome = collectFunctionTool('go_home', async () => {
|
|
286
|
-
await getExecutorDevice().home();
|
|
287
|
-
return 'go home successfully';
|
|
288
|
-
}, { description: 'Press the home button to return to the desktop', parameters: {} });
|
|
289
|
-
/** Login placeholder tool. */
|
|
290
|
-
exports.login = collectFunctionTool('login', async () => {
|
|
291
|
-
return JSON.stringify({ action: 'login', message: 'login successfully' });
|
|
292
|
-
}, { description: 'Login placeholder tool', parameters: {} });
|
|
293
|
-
/** Resolve the main ability name for a bundle name. */
|
|
294
|
-
function getMainAbilityForBundle(bundleName) {
|
|
295
|
-
return getMainAbility(bundleName);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Load the detailed steps for a named skill.
|
|
299
|
-
* @param skillName The skill name to load.
|
|
300
|
-
* @returns The skill content, or a not-found message.
|
|
301
|
-
*/
|
|
302
|
-
exports.loadSkill = collectFunctionTool('load_skill', async (skillName) => {
|
|
303
|
-
const skillManager = new skill_manager_1.SkillManager();
|
|
304
|
-
const content = skillManager.getSkillContent(skillName);
|
|
305
|
-
if (content) {
|
|
306
|
-
return `Skill '${skillName}' loaded successfully. Content:\n\n${content}`;
|
|
307
|
-
}
|
|
308
|
-
return `Skill '${skillName}' not found. Please check the skill name.`;
|
|
309
|
-
}, { description: 'Load the detailed steps for a named skill', parameters: { skill_name: 'string' } });
|
|
310
|
-
/**
|
|
311
|
-
* Verify the task result based on recent execution history (screenshots + logs).
|
|
312
|
-
* @param verificationDescription What to verify.
|
|
313
|
-
* @returns JSON with `verified` (boolean) and `reason` (string).
|
|
314
|
-
*/
|
|
315
|
-
async function verify(verificationDescription) {
|
|
316
|
-
const executorAgent = getExecutorAgent();
|
|
317
|
-
const reportGenerator = executorAgent.getReportGenerator();
|
|
318
|
-
if (!reportGenerator) {
|
|
319
|
-
return JSON.stringify({
|
|
320
|
-
verified: false,
|
|
321
|
-
reason: 'Report generator not available, cannot retrieve execution history.',
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
const events = getReportEvents(reportGenerator);
|
|
325
|
-
// Collect the most recent 10 events with screenshots, skipping
|
|
326
|
-
// PLANNER_OBSERVATION to avoid duplicating the initial screenshot.
|
|
327
|
-
const eventsWithScreenshots = [];
|
|
328
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
329
|
-
const event = events[i];
|
|
330
|
-
if (event.eventType === types_1.EventType.PLANNER_OBSERVATION) {
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
if (event.screenshotPath && fs.existsSync(event.screenshotPath)) {
|
|
334
|
-
eventsWithScreenshots.push(event);
|
|
335
|
-
}
|
|
336
|
-
if (eventsWithScreenshots.length >= 10) {
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
if (eventsWithScreenshots.length === 0) {
|
|
341
|
-
return JSON.stringify({
|
|
342
|
-
verified: false,
|
|
343
|
-
reason: 'No screenshots found in execution history.',
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
// Chronological order for the prompt.
|
|
347
|
-
eventsWithScreenshots.reverse();
|
|
348
|
-
const textParts = [
|
|
349
|
-
`Verification requirement: ${verificationDescription}\n\nRecent execution history (chronological):`,
|
|
350
|
-
];
|
|
351
|
-
const images = [];
|
|
352
|
-
for (const event of eventsWithScreenshots) {
|
|
353
|
-
try {
|
|
354
|
-
const imagePath = event.screenshotPath;
|
|
355
|
-
const base64Image = fs.readFileSync(imagePath).toString('base64');
|
|
356
|
-
const time = event.timestamp ? event.timestamp.split('T')[1]?.split('.')[0] ?? event.timestamp : '';
|
|
357
|
-
textParts.push(`Time: ${time}\nEvent type: ${event.eventType}\nContent: ${event.content}`);
|
|
358
|
-
images.push({ base64Data: base64Image, mimeType: 'image/jpeg' });
|
|
359
|
-
}
|
|
360
|
-
catch (e) {
|
|
361
|
-
logger_1.logger.warn(`Failed to read screenshot ${event.screenshotPath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
const modelConfig = executorAgent.getModelConfig();
|
|
365
|
-
const llmCaller = new custom_model_1.LLMCaller();
|
|
366
|
-
const systemPrompt = 'You are an automated test verification expert. Based on the provided recent execution steps (screenshots and logs), ' +
|
|
367
|
-
'verify whether the user verification requirement is satisfied. Carefully observe the UI state and text in the screenshots. ' +
|
|
368
|
-
'Output format: return JSON with "verified" (boolean) and "reason" (string) fields.';
|
|
369
|
-
try {
|
|
370
|
-
const llmResult = await llmCaller.call({
|
|
371
|
-
systemPrompt,
|
|
372
|
-
userPrompt: textParts.join('\n\n'),
|
|
373
|
-
images,
|
|
374
|
-
modelConfig,
|
|
375
|
-
});
|
|
376
|
-
if (llmResult.tokenUsage) {
|
|
377
|
-
logger_1.logger.info(`[Verify] Token Usage: Input=${llmResult.tokenUsage.inputTokens}, ` +
|
|
378
|
-
`Output=${llmResult.tokenUsage.outputTokens}, ` +
|
|
379
|
-
`Total=${llmResult.tokenUsage.totalTokens}`);
|
|
380
|
-
reportGenerator.addTokenUsage(llmResult.tokenUsage, 'Verify');
|
|
381
|
-
}
|
|
382
|
-
const resultJsonStr = llmResult.text;
|
|
383
|
-
logger_1.logger.info(`Verify result: ${resultJsonStr}`);
|
|
384
|
-
try {
|
|
385
|
-
const resultData = JSON.parse(resultJsonStr);
|
|
386
|
-
return JSON.stringify(resultData);
|
|
387
|
-
}
|
|
388
|
-
catch {
|
|
389
|
-
return JSON.stringify({
|
|
390
|
-
verified: false,
|
|
391
|
-
reason: `Verification model returned non-JSON output: ${resultJsonStr}`,
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
catch (e) {
|
|
396
|
-
logger_1.logger.error(`LLM verification failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
397
|
-
return JSON.stringify({
|
|
398
|
-
verified: false,
|
|
399
|
-
reason: `Verification process failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
/** Access the in-memory events of a report generator via structural cast. */
|
|
404
|
-
function getReportEvents(reportGenerator) {
|
|
405
|
-
const withEvents = reportGenerator;
|
|
406
|
-
return withEvents.events ?? [];
|
|
407
|
-
}
|
|
408
|
-
function sleep(seconds) {
|
|
409
|
-
return new Promise((resolve) => setTimeout(resolve, Math.max(0, seconds) * 1000));
|
|
410
|
-
}
|
package/dist/core/mcp/types.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Internal utility functions shared across memory module.
|
|
4
|
-
*
|
|
5
|
-
* Ported from python core/memory/_utils.py.
|
|
6
|
-
* Provides helpers for response text extraction, message filtering, retry
|
|
7
|
-
* decoration, and a lightweight TimeCalculate class used by ToolPlayer.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TimeCalculate = void 0;
|
|
11
|
-
exports.fallbackToGlobal = fallbackToGlobal;
|
|
12
|
-
exports.isValidModelConfig = isValidModelConfig;
|
|
13
|
-
exports.extractTextFromResponse = extractTextFromResponse;
|
|
14
|
-
exports.filterImagesFromMessage = filterImagesFromMessage;
|
|
15
|
-
exports.retryOnException = retryOnException;
|
|
16
|
-
const logger_1 = require("../../common/logger");
|
|
17
|
-
function fallbackToGlobal(config, extractor, validator = null, label = '', globalConfig) {
|
|
18
|
-
const isValid = (value) => {
|
|
19
|
-
if (validator)
|
|
20
|
-
return validator(value);
|
|
21
|
-
return value !== null && value !== undefined;
|
|
22
|
-
};
|
|
23
|
-
let result = null;
|
|
24
|
-
if (config !== null && config !== undefined) {
|
|
25
|
-
try {
|
|
26
|
-
result = extractor(config);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
logger_1.logger.debug(`Failed to extract ${label} from passed config: ${e instanceof Error ? e.message : String(e)}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (isValid(result))
|
|
33
|
-
return result;
|
|
34
|
-
if (globalConfig !== null && globalConfig !== undefined && globalConfig !== config) {
|
|
35
|
-
try {
|
|
36
|
-
result = extractor(globalConfig);
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
logger_1.logger.debug(`Failed to extract ${label} from global config: ${e instanceof Error ? e.message : String(e)}`);
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
if (isValid(result)) {
|
|
43
|
-
logger_1.logger.info(`${label} not found in passed config, using global config`);
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
function isValidModelConfig(modelConfig) {
|
|
50
|
-
if (!modelConfig || typeof modelConfig !== 'object')
|
|
51
|
-
return false;
|
|
52
|
-
const cfg = modelConfig;
|
|
53
|
-
return Boolean(cfg['name']) && Boolean(cfg['baseUrl'] || cfg['base_url']);
|
|
54
|
-
}
|
|
55
|
-
function extractTextFromResponse(response) {
|
|
56
|
-
if (!response || typeof response !== 'object')
|
|
57
|
-
return '';
|
|
58
|
-
const output = response['output'];
|
|
59
|
-
if (!Array.isArray(output))
|
|
60
|
-
return '';
|
|
61
|
-
const textParts = [];
|
|
62
|
-
for (const item of output) {
|
|
63
|
-
if (!item || typeof item !== 'object')
|
|
64
|
-
continue;
|
|
65
|
-
const itemType = item['type'];
|
|
66
|
-
if (itemType === 'reasoning') {
|
|
67
|
-
const summary = item['summary'];
|
|
68
|
-
if (Array.isArray(summary)) {
|
|
69
|
-
const thinkingParts = [];
|
|
70
|
-
for (const s of summary) {
|
|
71
|
-
if (s && typeof s === 'object' && s['type'] === 'summary_text') {
|
|
72
|
-
thinkingParts.push(String(s['text'] ?? ''));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (thinkingParts.length) {
|
|
76
|
-
logger_1.logger.debug(`\n[Model Thinking]\n${thinkingParts.join('')}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (itemType === 'message' && item['role'] === 'assistant') {
|
|
81
|
-
const content = item['content'];
|
|
82
|
-
if (Array.isArray(content)) {
|
|
83
|
-
for (const c of content) {
|
|
84
|
-
if (c && typeof c === 'object' && c['type'] === 'output_text') {
|
|
85
|
-
textParts.push(String(c['text'] ?? ''));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return textParts.join('');
|
|
92
|
-
}
|
|
93
|
-
function filterImagesFromMessage(message) {
|
|
94
|
-
if (!message || typeof message !== 'object')
|
|
95
|
-
return message;
|
|
96
|
-
if (Array.isArray(message))
|
|
97
|
-
return [...message];
|
|
98
|
-
const filtered = { ...message };
|
|
99
|
-
const content = filtered['content'];
|
|
100
|
-
if (Array.isArray(content)) {
|
|
101
|
-
filtered['content'] = content.filter((item) => {
|
|
102
|
-
if (item && typeof item === 'object') {
|
|
103
|
-
const type = item['type'];
|
|
104
|
-
return type !== 'input_image' && type !== 'image_url';
|
|
105
|
-
}
|
|
106
|
-
return true;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return filtered;
|
|
110
|
-
}
|
|
111
|
-
function retryOnException(fn, maxRetries = 3, delay = 1000, backoff = 2) {
|
|
112
|
-
return (async () => {
|
|
113
|
-
let currentDelay = delay;
|
|
114
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
115
|
-
try {
|
|
116
|
-
return await fn();
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
if (attempt === maxRetries - 1)
|
|
120
|
-
throw e;
|
|
121
|
-
logger_1.logger.warning(`retry failed (attempt ${attempt + 1}/${maxRetries}): ${e instanceof Error ? e.message : String(e)}`);
|
|
122
|
-
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
123
|
-
currentDelay *= backoff;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
throw new Error('unreachable');
|
|
127
|
-
})();
|
|
128
|
-
}
|
|
129
|
-
class TimeCalculate {
|
|
130
|
-
startTime;
|
|
131
|
-
endTime;
|
|
132
|
-
constructor(startTime, endTime) {
|
|
133
|
-
this.startTime = startTime ?? new Date();
|
|
134
|
-
this.endTime = endTime ?? new Date();
|
|
135
|
-
}
|
|
136
|
-
get duration() {
|
|
137
|
-
return (this.endTime.getTime() - this.startTime.getTime()) / 1000;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
exports.TimeCalculate = TimeCalculate;
|