@autotest/agent 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/api/agent_api.d.ts +2 -2
- package/dist/autotest-cli.js +1 -397
- package/dist/common/config/config.yaml +4 -0
- package/dist/common/config/manager.d.ts +4 -4
- package/dist/common/config/types.d.ts +5 -0
- package/dist/common/dfx/index.d.ts +1 -1
- package/dist/core/agent/single_agent/agent.d.ts +1 -0
- package/dist/core/device/device_protocol.d.ts +1 -1
- package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
- package/dist/core/knowledge/vectordb.d.ts +5 -5
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +1 -0
- package/dist/core/mcp/mcp_tools.d.ts +1 -0
- package/dist/core/mcp/verify_tool.d.ts +12 -0
- package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
- package/dist/data_types/device.d.ts +1 -1
- package/dist/data_types/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -163
- package/dist/tools/batch_runner.js +1 -745
- package/dist/tools/case_runner/runner.js +1 -410
- package/dist/tools/config/config_tool.js +1 -339
- package/dist/tools/prompt_compare/compare_runner.js +1 -360
- package/package.json +2 -2
- package/dist/api/agent_api.js +0 -550
- package/dist/api/autotest_agent.js +0 -205
- package/dist/api/types.js +0 -11
- package/dist/common/case_manager.js +0 -91
- package/dist/common/collect_case.js +0 -128
- package/dist/common/common_errors.js +0 -66
- package/dist/common/config/config_validator.js +0 -28
- package/dist/common/config/manager.js +0 -257
- package/dist/common/config/output.js +0 -59
- package/dist/common/config/types.js +0 -185
- package/dist/common/dfx/client_factory.js +0 -62
- package/dist/common/dfx/context.js +0 -23
- package/dist/common/dfx/index.js +0 -15
- package/dist/common/dfx/recorder.js +0 -191
- package/dist/common/dfx/recording_fetch.js +0 -228
- package/dist/common/dfx/source.js +0 -13
- package/dist/common/image_cacher.js +0 -36
- package/dist/common/image_helper.js +0 -128
- package/dist/common/image_similarity.js +0 -171
- package/dist/common/llm_cache/cache_transport.js +0 -102
- package/dist/common/llm_cache/prompt_cache.js +0 -113
- package/dist/common/logger.js +0 -158
- package/dist/common/model/custom_model.js +0 -487
- package/dist/common/model/index.js +0 -5
- package/dist/common/path_utils.js +0 -88
- package/dist/common/result_parser.js +0 -49
- package/dist/common/usage/token_usage.js +0 -117
- package/dist/common/utils.js +0 -125
- package/dist/core/agent/layered_agent/ability_helper.js +0 -125
- package/dist/core/agent/layered_agent/agent.js +0 -37
- package/dist/core/agent/layered_agent/agent_registry.js +0 -82
- package/dist/core/agent/layered_agent/decision.js +0 -518
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
- package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
- package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
- package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
- package/dist/core/agent/report_analyzer_agent/config.js +0 -22
- package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
- package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
- package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
- package/dist/core/agent/report_analyzer_agent/index.js +0 -52
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
- package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
- package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
- package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
- package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
- package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
- package/dist/core/agent/report_analyzer_agent/types.js +0 -274
- package/dist/core/agent/rewrite_agent/agent.js +0 -209
- package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
- package/dist/core/agent/rewrite_agent/mapping.js +0 -56
- package/dist/core/agent/rewrite_agent/parse.js +0 -121
- package/dist/core/agent/rewrite_agent/types.js +0 -37
- package/dist/core/agent/single_agent/agent.js +0 -801
- package/dist/core/agent/single_agent/hook_manager.js +0 -59
- package/dist/core/agent/single_agent/hooks.js +0 -288
- package/dist/core/agent/single_agent/image_utils.js +0 -158
- package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
- package/dist/core/agent/single_agent/subagent_manager.js +0 -72
- package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
- package/dist/core/agent/types.js +0 -2
- package/dist/core/agent/utils/message_builder.js +0 -138
- package/dist/core/device/device_protocol.js +0 -2
- package/dist/core/device/hdc/apps.js +0 -437
- package/dist/core/device/hdc/device.js +0 -219
- package/dist/core/device/hdc/index.js +0 -31
- package/dist/core/device/hdc/input.js +0 -74
- package/dist/core/device/hdc/screenshot.js +0 -171
- package/dist/core/device/index.js +0 -70
- package/dist/core/device/types.js +0 -2
- package/dist/core/knowledge/knowledge_manager.js +0 -70
- package/dist/core/knowledge/vectordb.js +0 -283
- package/dist/core/mcp/adapter_factory.js +0 -99
- package/dist/core/mcp/android_adapter.js +0 -286
- package/dist/core/mcp/base_adapter.js +0 -86
- package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
- package/dist/core/mcp/ios_adapter.js +0 -286
- package/dist/core/mcp/local_tools.js +0 -41
- package/dist/core/mcp/mcp_tools.js +0 -473
- package/dist/core/mcp/types.js +0 -6
- package/dist/core/memory/_utils.js +0 -140
- package/dist/core/memory/compressed_session.js +0 -182
- package/dist/core/memory/context_compressor.js +0 -176
- package/dist/core/memory/index.js +0 -22
- package/dist/core/memory/memory_manager.js +0 -28
- package/dist/core/memory/reflector.js +0 -95
- package/dist/core/memory/replan_manager.js +0 -12
- package/dist/core/memory/session_factory.js +0 -29
- package/dist/core/memory/tool_player.js +0 -225
- package/dist/core/memory/tool_player_popup.js +0 -276
- package/dist/core/memory/tool_player_replan.js +0 -226
- package/dist/core/memory/tool_player_xpath.js +0 -139
- package/dist/core/memory/tool_recorder.js +0 -126
- package/dist/core/preprocessor/task_splitter.js +0 -112
- package/dist/core/prompt/prompt_loader.js +0 -315
- package/dist/core/skill/skill_manager.js +0 -302
- package/dist/data_types/action.js +0 -2
- package/dist/data_types/agent.js +0 -2
- package/dist/data_types/case.js +0 -57
- package/dist/data_types/device.js +0 -2
- package/dist/data_types/index.js +0 -11
- package/dist/data_types/report.js +0 -6
- package/dist/data_types/screen.js +0 -23
- package/dist/data_types/task.js +0 -2
- package/dist/loop/cli.js +0 -127
- package/dist/loop/orchestrator.js +0 -314
- package/dist/loop/result_writer.js +0 -260
- package/dist/loop/types.js +0 -82
- package/dist/mcp-server/server.js +0 -341
- package/dist/mcp-server/types.js +0 -224
- package/dist/reporter/batch_summary.js +0 -197
- package/dist/reporter/generator.js +0 -286
- package/dist/reporter/html_template/index.js +0 -529
- package/dist/reporter/json_report.js +0 -6
- package/dist/reporter/types.js +0 -45
- package/dist/tools/case_runner/report.js +0 -264
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DashScopeTokenUsage = exports.TokenUsage = void 0;
|
|
4
|
-
exports.resolveTokenType = resolveTokenType;
|
|
5
|
-
const DASHSCOPE_DOMAINS = new Set(['dashscope.aliyuncs.com']);
|
|
6
|
-
class TokenUsage {
|
|
7
|
-
inputTokens;
|
|
8
|
-
outputTokens;
|
|
9
|
-
totalTokens;
|
|
10
|
-
cachedTokens;
|
|
11
|
-
reasoningTokens;
|
|
12
|
-
constructor(inputTokens = 0, outputTokens = 0, totalTokens = 0, cachedTokens = 0, reasoningTokens = 0) {
|
|
13
|
-
this.inputTokens = inputTokens;
|
|
14
|
-
this.outputTokens = outputTokens;
|
|
15
|
-
this.totalTokens = totalTokens;
|
|
16
|
-
this.cachedTokens = cachedTokens;
|
|
17
|
-
this.reasoningTokens = reasoningTokens;
|
|
18
|
-
}
|
|
19
|
-
get uncachedTokens() {
|
|
20
|
-
return this.inputTokens - this.cachedTokens;
|
|
21
|
-
}
|
|
22
|
-
get normalizedTokens() {
|
|
23
|
-
return this.uncachedTokens * 1.0 + this.cachedTokens * 0.2 + this.outputTokens * 1.0;
|
|
24
|
-
}
|
|
25
|
-
toDict() {
|
|
26
|
-
return {
|
|
27
|
-
input_tokens: this.inputTokens,
|
|
28
|
-
output_tokens: this.outputTokens,
|
|
29
|
-
total_tokens: this.totalTokens,
|
|
30
|
-
cached_tokens: this.cachedTokens,
|
|
31
|
-
reasoning_tokens: this.reasoningTokens,
|
|
32
|
-
normalized_tokens: Math.round(this.normalizedTokens * 10) / 10,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
toString() {
|
|
36
|
-
return (`Tokens: total=${this.totalTokens} ` +
|
|
37
|
-
`input=${this.inputTokens} output=${this.outputTokens} ` +
|
|
38
|
-
`cached=${this.cachedTokens} ` +
|
|
39
|
-
`reasoning=${this.reasoningTokens} ` +
|
|
40
|
-
`normalized=${this.normalizedTokens.toFixed(1)}`);
|
|
41
|
-
}
|
|
42
|
-
static fromUsageObj(usageObj) {
|
|
43
|
-
if (!usageObj)
|
|
44
|
-
return null;
|
|
45
|
-
const inputTokens = usageObj.input_tokens ?? 0;
|
|
46
|
-
const outputTokens = usageObj.output_tokens ?? 0;
|
|
47
|
-
const totalTokens = usageObj.total_tokens ?? 0;
|
|
48
|
-
let cachedTokens = 0;
|
|
49
|
-
let reasoningTokens = 0;
|
|
50
|
-
const inputDetails = usageObj.input_tokens_details;
|
|
51
|
-
if (inputDetails) {
|
|
52
|
-
cachedTokens = inputDetails.cached_tokens ?? 0;
|
|
53
|
-
}
|
|
54
|
-
const outputDetails = usageObj.output_tokens_details;
|
|
55
|
-
if (outputDetails) {
|
|
56
|
-
reasoningTokens = outputDetails.reasoning_tokens ?? 0;
|
|
57
|
-
}
|
|
58
|
-
return new TokenUsage(inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.TokenUsage = TokenUsage;
|
|
62
|
-
class DashScopeTokenUsage extends TokenUsage {
|
|
63
|
-
cacheCreationTokens;
|
|
64
|
-
constructor(inputTokens = 0, outputTokens = 0, totalTokens = 0, cachedTokens = 0, reasoningTokens = 0, cacheCreationTokens = 0) {
|
|
65
|
-
super(inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens);
|
|
66
|
-
this.cacheCreationTokens = cacheCreationTokens;
|
|
67
|
-
}
|
|
68
|
-
get uncachedTokens() {
|
|
69
|
-
return this.inputTokens - this.cachedTokens - this.cacheCreationTokens;
|
|
70
|
-
}
|
|
71
|
-
get normalizedTokens() {
|
|
72
|
-
return (this.uncachedTokens * 1.0 +
|
|
73
|
-
this.cacheCreationTokens * 1.25 +
|
|
74
|
-
this.cachedTokens * 0.2 +
|
|
75
|
-
this.outputTokens * 1.0);
|
|
76
|
-
}
|
|
77
|
-
toString() {
|
|
78
|
-
return (`Tokens: total=${this.totalTokens} ` +
|
|
79
|
-
`input=${this.inputTokens} output=${this.outputTokens} ` +
|
|
80
|
-
`cached=${this.cachedTokens} ` +
|
|
81
|
-
`reasoning=${this.reasoningTokens} ` +
|
|
82
|
-
`cache_creation=${this.cacheCreationTokens} ` +
|
|
83
|
-
`normalized=${this.normalizedTokens.toFixed(1)}`);
|
|
84
|
-
}
|
|
85
|
-
static fromUsageObj(usageObj) {
|
|
86
|
-
if (!usageObj)
|
|
87
|
-
return null;
|
|
88
|
-
const base = TokenUsage.fromUsageObj(usageObj);
|
|
89
|
-
if (!base)
|
|
90
|
-
return null;
|
|
91
|
-
let cacheCreationTokens = 0;
|
|
92
|
-
const inputDetails = usageObj.input_tokens_details;
|
|
93
|
-
if (inputDetails) {
|
|
94
|
-
cacheCreationTokens = inputDetails.cache_creation_input_tokens ?? 0;
|
|
95
|
-
}
|
|
96
|
-
return new DashScopeTokenUsage(base.inputTokens, base.outputTokens, base.totalTokens, base.cachedTokens, base.reasoningTokens, cacheCreationTokens);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.DashScopeTokenUsage = DashScopeTokenUsage;
|
|
100
|
-
function resolveTokenType(baseUrl) {
|
|
101
|
-
if (!baseUrl)
|
|
102
|
-
return TokenUsage;
|
|
103
|
-
try {
|
|
104
|
-
const url = new URL(baseUrl);
|
|
105
|
-
const domain = url.hostname.toLowerCase();
|
|
106
|
-
if (DASHSCOPE_DOMAINS.has(domain))
|
|
107
|
-
return DashScopeTokenUsage;
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
const lower = baseUrl.toLowerCase();
|
|
111
|
-
for (const d of DASHSCOPE_DOMAINS) {
|
|
112
|
-
if (lower.includes(d))
|
|
113
|
-
return DashScopeTokenUsage;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return TokenUsage;
|
|
117
|
-
}
|
package/dist/common/utils.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* General utility functions
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sanitizeFilename = sanitizeFilename;
|
|
7
|
-
exports.applyThinkingConfig = applyThinkingConfig;
|
|
8
|
-
exports.normalizeCoord = normalizeCoord;
|
|
9
|
-
exports.normalizeToolCoordinates = normalizeToolCoordinates;
|
|
10
|
-
exports.formatTokenDisplay = formatTokenDisplay;
|
|
11
|
-
/** Windows-invalid filename chars and control chars are stripped/replaced. */
|
|
12
|
-
const INVALID_FILENAME_CHARS = '/\\:*?"<>|';
|
|
13
|
-
/**
|
|
14
|
-
* Sanitize a string into a safe filename (Windows-compatible).
|
|
15
|
-
*
|
|
16
|
-
* Mirrors `sanitize_filename`: replaces `/ \ : * ? " < > |` with `_`,
|
|
17
|
-
* drops control chars, strips leading/trailing dots and spaces, collapses
|
|
18
|
-
* repeated underscores, and truncates to `maxLength`.
|
|
19
|
-
*/
|
|
20
|
-
function sanitizeFilename(name, maxLength = 50) {
|
|
21
|
-
if (!name)
|
|
22
|
-
return 'unnamed';
|
|
23
|
-
let s = name;
|
|
24
|
-
for (const ch of INVALID_FILENAME_CHARS) {
|
|
25
|
-
s = s.split(ch).join('_');
|
|
26
|
-
}
|
|
27
|
-
// Remove control chars (\x00-\x1f, \x7f-\x9f)
|
|
28
|
-
s = s.replace(/[\x00-\x1f\x7f-\x9f]/g, '');
|
|
29
|
-
// Strip leading/trailing dots and spaces
|
|
30
|
-
s = s.replace(/^[.\s]+/, '').replace(/[.\s]+$/, '');
|
|
31
|
-
// Collapse repeated underscores
|
|
32
|
-
s = s.replace(/_+/g, '_');
|
|
33
|
-
if (s.length > maxLength) {
|
|
34
|
-
s = s.slice(0, maxLength).replace(/_+$/, '');
|
|
35
|
-
}
|
|
36
|
-
return s || 'unnamed';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Inject `enable_thinking` into the LLM request `extra_body`.
|
|
40
|
-
*
|
|
41
|
-
* Mirrors `apply_thinking_config`. Tri-state: `null` = skip (use model
|
|
42
|
-
* default), `true`/`false` = explicit value, written into
|
|
43
|
-
* `chat_template_kwargs.enable_thinking` (vLLM format). Mutates and returns
|
|
44
|
-
* `extraBody` in place.
|
|
45
|
-
*/
|
|
46
|
-
function applyThinkingConfig(extraBody, enableThinking) {
|
|
47
|
-
if (enableThinking !== null) {
|
|
48
|
-
const kwargs = extraBody.chat_template_kwargs;
|
|
49
|
-
if (kwargs) {
|
|
50
|
-
kwargs.enable_thinking = enableThinking;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
extraBody.chat_template_kwargs = { enable_thinking: enableThinking };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return extraBody;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Normalize a single coordinate: keep if already in [0,1], else divide by 1000
|
|
60
|
-
* (per-mille → 0-1). Mirrors `normalize_coord`.
|
|
61
|
-
*/
|
|
62
|
-
function normalizeCoord(coord) {
|
|
63
|
-
if (coord >= 0 && coord <= 1)
|
|
64
|
-
return coord;
|
|
65
|
-
return coord / 1000;
|
|
66
|
-
}
|
|
67
|
-
const _COORD_TOOLS_POINT = new Set(['click', 'double_click', 'long_press', 'long_click', 'tap', 'double_tap']);
|
|
68
|
-
const _COORD_TOOLS_SWIPE = new Set(['swipe', 'drag']);
|
|
69
|
-
/**
|
|
70
|
-
* Coordinate defense layer: detect per-mille (0-1000) coordinates and
|
|
71
|
-
* selectively divide >1 values by 1000 to normalize to the 0-1 range.
|
|
72
|
-
*
|
|
73
|
-
* Mirrors `normalize_tool_coordinates`. Covers both combine format
|
|
74
|
-
* (`pos`/`start`/`end` as [x,y]) and split format (`x`/`y`,
|
|
75
|
-
* `start_x`/`start_y`, `end_x`/`end_y`). Only values >1 are converted; values
|
|
76
|
-
* already in [0,1] are preserved (handles mixed output like [0.85, 780]).
|
|
77
|
-
*
|
|
78
|
-
* Mutates `args` in place. Returns true if any conversion occurred.
|
|
79
|
-
*/
|
|
80
|
-
function normalizeToolCoordinates(toolName, args) {
|
|
81
|
-
const name = String(toolName ?? '').toLowerCase();
|
|
82
|
-
if (!_COORD_TOOLS_POINT.has(name) && !_COORD_TOOLS_SWIPE.has(name))
|
|
83
|
-
return false;
|
|
84
|
-
let converted = false;
|
|
85
|
-
const isNum = (v) => typeof v === 'number';
|
|
86
|
-
// ---- combine format: value is [x, y] ----
|
|
87
|
-
for (const field of ['pos', 'start', 'end']) {
|
|
88
|
-
const val = args[field];
|
|
89
|
-
if (Array.isArray(val) && val.length === 2 && isNum(val[0]) && isNum(val[1])) {
|
|
90
|
-
const [a, b] = val;
|
|
91
|
-
if (a > 1.0 || b > 1.0) {
|
|
92
|
-
args[field] = [
|
|
93
|
-
a > 1.0 ? a / 1000 : a,
|
|
94
|
-
b > 1.0 ? b / 1000 : b,
|
|
95
|
-
];
|
|
96
|
-
converted = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// ---- split format: paired scalar coords ----
|
|
101
|
-
for (const [xKey, yKey] of [['x', 'y'], ['start_x', 'start_y'], ['end_x', 'end_y']]) {
|
|
102
|
-
if (xKey in args && yKey in args) {
|
|
103
|
-
const xv = args[xKey];
|
|
104
|
-
const yv = args[yKey];
|
|
105
|
-
if (isNum(xv) && isNum(yv)) {
|
|
106
|
-
if (xv > 1.0 || yv > 1.0) {
|
|
107
|
-
if (xv > 1.0)
|
|
108
|
-
args[xKey] = xv / 1000;
|
|
109
|
-
if (yv > 1.0)
|
|
110
|
-
args[yKey] = yv / 1000;
|
|
111
|
-
converted = true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return converted;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Format a token count for display.
|
|
120
|
-
*
|
|
121
|
-
* Values >= 1000 are shown as `X.XK`, otherwise the raw number is returned.
|
|
122
|
-
*/
|
|
123
|
-
function formatTokenDisplay(total) {
|
|
124
|
-
return total >= 1000 ? `${(total / 1000).toFixed(1)}K` : String(total);
|
|
125
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHapInfo = getHapInfo;
|
|
4
|
-
exports.getHapVersionCode = getHapVersionCode;
|
|
5
|
-
exports.getBundleInfo = getBundleInfo;
|
|
6
|
-
exports.getIconAbilities = getIconAbilities;
|
|
7
|
-
exports.getMainAbility = getMainAbility;
|
|
8
|
-
function getHapInfo(hapPath) {
|
|
9
|
-
try {
|
|
10
|
-
const { execSync } = require('child_process');
|
|
11
|
-
const result = execSync(process.platform === 'win32'
|
|
12
|
-
? `powershell -Command "Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::OpenRead('${hapPath}').GetEntry('pack.info').Open() | ForEach-Object { [System.IO.StreamReader]::new($_).ReadToEnd() }"`
|
|
13
|
-
: `unzip -p "${hapPath}" pack.info`, { encoding: 'utf-8', timeout: 10000, windowsHide: true });
|
|
14
|
-
return JSON.parse(result);
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function getHapVersionCode(hapPath) {
|
|
21
|
-
const info = getHapInfo(hapPath);
|
|
22
|
-
try {
|
|
23
|
-
const summary = info.summary;
|
|
24
|
-
const app = summary?.app;
|
|
25
|
-
const version = app?.version;
|
|
26
|
-
const code = version?.code;
|
|
27
|
-
return typeof code === 'number' ? code : -1;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return -1;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function getBundleInfo(driver, bundleName) {
|
|
34
|
-
const info = driver.executeShellCommand(`bm dump -n ${bundleName}`);
|
|
35
|
-
let bundleInfo = null;
|
|
36
|
-
const start = info.indexOf(':');
|
|
37
|
-
if (start < 0) {
|
|
38
|
-
throw new Error(`Can't get bundle-info for [${bundleName}], please check if application installed`);
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const jsonData = info.slice(start + 1).trim();
|
|
42
|
-
bundleInfo = JSON.parse(jsonData);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
driver.logError?.(`Fail get bundle info: ${e instanceof Error ? e.message : String(e)}`);
|
|
46
|
-
}
|
|
47
|
-
if (bundleInfo === null) {
|
|
48
|
-
throw new Error(`Can't get bundle-info for [${bundleName}], please check if application installed`);
|
|
49
|
-
}
|
|
50
|
-
return bundleInfo;
|
|
51
|
-
}
|
|
52
|
-
function isLauncherAbility(abilityInfo) {
|
|
53
|
-
const skills = abilityInfo.skills;
|
|
54
|
-
if (!skills || skills.length <= 0) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
for (const skill of skills) {
|
|
58
|
-
const actions = skill.actions ?? [];
|
|
59
|
-
if (actions.includes('action.system.home') || actions.includes('ohos.want.action.home')) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
function getIconAbilities(driver, bundleName) {
|
|
67
|
-
const result = [];
|
|
68
|
-
const bundleInfo = getBundleInfo(driver, bundleName);
|
|
69
|
-
const hapModuleInfos = bundleInfo.hapModuleInfos ?? [];
|
|
70
|
-
const mainEntry = bundleInfo.mainEntry;
|
|
71
|
-
for (const hapModuleInfo of hapModuleInfos) {
|
|
72
|
-
const abilityInfos = hapModuleInfo.abilityInfos;
|
|
73
|
-
const moduleMain = hapModuleInfo.mainAbility;
|
|
74
|
-
if (!abilityInfos) {
|
|
75
|
-
driver.logWarning?.('Fail to parse moduleInfo item, missing abilityInfos');
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
for (const abilityInfo of abilityInfos) {
|
|
79
|
-
try {
|
|
80
|
-
if (isLauncherAbility(abilityInfo)) {
|
|
81
|
-
result.push({
|
|
82
|
-
name: abilityInfo.name,
|
|
83
|
-
moduleName: abilityInfo.moduleName,
|
|
84
|
-
moduleMainAbility: moduleMain,
|
|
85
|
-
mainModule: mainEntry,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
driver.logWarning?.(`Fail to parse ability_info item, ${e instanceof Error ? e.message : String(e)}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
function isEqualAndNotNone(a, b) {
|
|
97
|
-
return a === b && a !== null && a !== undefined && a !== '';
|
|
98
|
-
}
|
|
99
|
-
function getMainAbility(driver, bundleName) {
|
|
100
|
-
const abilities = getIconAbilities(driver, bundleName);
|
|
101
|
-
if (abilities.length <= 0) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
for (const item of abilities) {
|
|
105
|
-
let score = 0;
|
|
106
|
-
const name = item.name;
|
|
107
|
-
const moduleMainAbility = item.moduleMainAbility;
|
|
108
|
-
const moduleName = item.moduleName;
|
|
109
|
-
const mainModule = item.mainModule;
|
|
110
|
-
if (isEqualAndNotNone(name, moduleMainAbility)) {
|
|
111
|
-
score += 20;
|
|
112
|
-
}
|
|
113
|
-
if (isEqualAndNotNone(moduleName, mainModule)) {
|
|
114
|
-
score += 100;
|
|
115
|
-
}
|
|
116
|
-
item.score = score;
|
|
117
|
-
}
|
|
118
|
-
abilities.sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
|
|
119
|
-
driver.logDebug?.(`all icon abilities: ${JSON.stringify(abilities)}`);
|
|
120
|
-
if (abilities.length > 1) {
|
|
121
|
-
const names = abilities.map((ability) => ability.name);
|
|
122
|
-
driver.logWarning?.(`bundle has multiple abilities, ${JSON.stringify(names)}`);
|
|
123
|
-
}
|
|
124
|
-
return abilities[0];
|
|
125
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LayeredAgent = void 0;
|
|
4
|
-
const decision_1 = require("./decision");
|
|
5
|
-
const agent_registry_1 = require("./agent_registry");
|
|
6
|
-
class LayeredAgent {
|
|
7
|
-
adapter;
|
|
8
|
-
config;
|
|
9
|
-
reportGenerator;
|
|
10
|
-
hooks;
|
|
11
|
-
llmCaller;
|
|
12
|
-
constructor(adapter, config, reportGenerator, hooks, llmCaller) {
|
|
13
|
-
this.adapter = adapter;
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.reportGenerator = reportGenerator;
|
|
16
|
-
this.hooks = hooks;
|
|
17
|
-
this.llmCaller = llmCaller;
|
|
18
|
-
}
|
|
19
|
-
async run(args) {
|
|
20
|
-
agent_registry_1.agentRegistry.clear();
|
|
21
|
-
const result = await (0, decision_1.decisionChat)({
|
|
22
|
-
config: this.config,
|
|
23
|
-
adapter: this.adapter,
|
|
24
|
-
reportGenerator: this.reportGenerator,
|
|
25
|
-
args,
|
|
26
|
-
hooks: this.hooks,
|
|
27
|
-
llmCaller: this.llmCaller,
|
|
28
|
-
});
|
|
29
|
-
const status = (result.status || 'UNKNOWN');
|
|
30
|
-
return {
|
|
31
|
-
finalOutput: result.finalOutput,
|
|
32
|
-
status,
|
|
33
|
-
savedFiles: result.savedFiles,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.LayeredAgent = LayeredAgent;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Global agent registry.
|
|
4
|
-
*
|
|
5
|
-
* Singleton for managing cross-module shared state: executor agent, tool
|
|
6
|
-
* manager (adapter), report generator, last click info, and generic key-value
|
|
7
|
-
* state. Backward-compatible with the old layered-only API (setExecutorAgent /
|
|
8
|
-
* getExecutorAgent delegate to the generic set/get).
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.agentRegistry = void 0;
|
|
12
|
-
const logger_1 = require("../../../common/logger");
|
|
13
|
-
class AgentRegistryImpl {
|
|
14
|
-
static instance = null;
|
|
15
|
-
_state = new Map();
|
|
16
|
-
_initialized = false;
|
|
17
|
-
static getInstance() {
|
|
18
|
-
if (AgentRegistryImpl.instance === null) {
|
|
19
|
-
AgentRegistryImpl.instance = new AgentRegistryImpl();
|
|
20
|
-
}
|
|
21
|
-
return AgentRegistryImpl.instance;
|
|
22
|
-
}
|
|
23
|
-
// ---- Generic set/get ----
|
|
24
|
-
set(key, value) {
|
|
25
|
-
this._state.set(key, value);
|
|
26
|
-
this._initialized = true;
|
|
27
|
-
}
|
|
28
|
-
get(key, defaultValue) {
|
|
29
|
-
return this._state.get(key) ?? defaultValue;
|
|
30
|
-
}
|
|
31
|
-
clearKey(key) {
|
|
32
|
-
this._state.delete(key);
|
|
33
|
-
}
|
|
34
|
-
// ---- Executor agent (backward compat with layered agent_registry) ----
|
|
35
|
-
setExecutorAgent(agent) {
|
|
36
|
-
this.set('executor_agent', agent);
|
|
37
|
-
}
|
|
38
|
-
getExecutorAgent() {
|
|
39
|
-
return this.get('executor_agent', null);
|
|
40
|
-
}
|
|
41
|
-
// ---- Tool manager / adapter ----
|
|
42
|
-
setToolManager(adapter) {
|
|
43
|
-
this.set('tool_manager', adapter);
|
|
44
|
-
logger_1.logger.debug('[AgentRegistry] tool_manager (adapter) registered');
|
|
45
|
-
}
|
|
46
|
-
getToolManager() {
|
|
47
|
-
return this.get('tool_manager', null);
|
|
48
|
-
}
|
|
49
|
-
// ---- Report generator ----
|
|
50
|
-
setReportGenerator(rg) {
|
|
51
|
-
this.set('report_generator', rg);
|
|
52
|
-
}
|
|
53
|
-
getReportGenerator() {
|
|
54
|
-
return this.get('report_generator', null);
|
|
55
|
-
}
|
|
56
|
-
// ---- Last click info ----
|
|
57
|
-
setLastClickInfo(info) {
|
|
58
|
-
this.set('last_click_info', info);
|
|
59
|
-
}
|
|
60
|
-
getLastClickInfo() {
|
|
61
|
-
return this.get('last_click_info', null);
|
|
62
|
-
}
|
|
63
|
-
clearLastClickInfo() {
|
|
64
|
-
this.clearKey('last_click_info');
|
|
65
|
-
}
|
|
66
|
-
// ---- App config (for tools that need model config, e.g. judge) ----
|
|
67
|
-
setAppConfig(config) {
|
|
68
|
-
this.set('app_config', config);
|
|
69
|
-
}
|
|
70
|
-
getAppConfig() {
|
|
71
|
-
return this.get('app_config', null);
|
|
72
|
-
}
|
|
73
|
-
// ---- Status / cleanup ----
|
|
74
|
-
isInitialized() {
|
|
75
|
-
return this._initialized;
|
|
76
|
-
}
|
|
77
|
-
clear() {
|
|
78
|
-
this._state.clear();
|
|
79
|
-
this._initialized = false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.agentRegistry = AgentRegistryImpl.getInstance();
|