@autotest/agent 0.0.1 → 0.0.3
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 +43 -27
- package/dist/api/agent_api.d.ts +1 -1
- package/dist/api/agent_api.js +555 -0
- package/dist/api/autotest_agent.d.ts +0 -1
- package/dist/api/autotest_agent.js +205 -0
- package/dist/api/types.d.ts +0 -1
- package/dist/api/types.js +11 -0
- package/dist/autotest-cli.d.ts +1 -1
- package/dist/autotest-cli.js +391 -0
- package/dist/common/case_manager.d.ts +0 -1
- package/dist/common/case_manager.js +91 -0
- package/dist/common/collect_case.d.ts +0 -1
- package/dist/common/collect_case.js +128 -0
- package/dist/common/common_errors.d.ts +0 -1
- package/dist/common/common_errors.js +66 -0
- package/dist/common/config/config_validator.d.ts +0 -1
- package/dist/common/config/config_validator.js +28 -0
- package/dist/common/config/manager.d.ts +0 -1
- package/dist/common/config/manager.js +257 -0
- package/dist/common/config/output.d.ts +0 -1
- package/dist/common/config/output.js +59 -0
- package/dist/common/config/types.d.ts +2243 -2244
- package/dist/common/config/types.js +184 -0
- package/dist/common/dfx/client_factory.d.ts +0 -1
- package/dist/common/dfx/client_factory.js +62 -0
- package/dist/common/dfx/context.d.ts +0 -1
- package/dist/common/dfx/context.js +23 -0
- package/dist/common/dfx/index.d.ts +0 -1
- package/dist/common/dfx/index.js +15 -0
- package/dist/common/dfx/recorder.d.ts +0 -1
- package/dist/common/dfx/recorder.js +191 -0
- package/dist/common/dfx/recording_fetch.d.ts +0 -1
- package/dist/common/dfx/recording_fetch.js +228 -0
- package/dist/common/dfx/source.d.ts +0 -1
- package/dist/common/dfx/source.js +13 -0
- package/dist/common/image_cacher.d.ts +0 -1
- package/dist/common/image_cacher.js +36 -0
- package/dist/common/image_helper.d.ts +0 -1
- package/dist/common/image_helper.js +128 -0
- package/dist/common/image_similarity.d.ts +0 -1
- package/dist/common/image_similarity.js +171 -0
- package/dist/common/llm_cache/cache_transport.d.ts +2 -1
- package/dist/common/llm_cache/cache_transport.js +102 -0
- package/dist/common/llm_cache/prompt_cache.d.ts +53 -0
- package/dist/common/llm_cache/prompt_cache.js +113 -0
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +158 -0
- package/dist/common/model/custom_model.d.ts +0 -1
- package/dist/common/model/custom_model.js +467 -0
- package/dist/common/model/index.d.ts +0 -1
- package/dist/common/model/index.js +5 -0
- package/dist/common/path_utils.d.ts +0 -1
- package/dist/common/path_utils.js +81 -0
- package/dist/common/result_parser.d.ts +0 -1
- package/dist/common/result_parser.js +49 -0
- package/dist/common/usage/token_usage.d.ts +0 -1
- package/dist/common/usage/token_usage.js +117 -0
- package/dist/common/utils.d.ts +0 -1
- package/dist/common/utils.js +125 -0
- package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -1
- package/dist/core/agent/layered_agent/ability_helper.js +125 -0
- package/dist/core/agent/layered_agent/agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent.js +37 -0
- package/dist/core/agent/layered_agent/agent_registry.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent_registry.js +75 -0
- package/dist/core/agent/layered_agent/decision.d.ts +0 -1
- package/dist/core/agent/layered_agent/decision.js +478 -0
- package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +155 -0
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +1 -2
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +41 -0
- package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +112 -0
- package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +207 -0
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +241 -0
- package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +34 -0
- package/dist/core/agent/layered_agent/execute_agent/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.js +67 -0
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +316 -0
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +154 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +243 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +139 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +9 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +94 -0
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +109 -0
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +33 -0
- package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.js +52 -0
- package/dist/core/agent/report_analyzer_agent/agent.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.js +565 -0
- package/dist/core/agent/report_analyzer_agent/config.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/config.js +22 -0
- package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.js +255 -0
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.js +99 -0
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.js +31 -0
- package/dist/core/agent/report_analyzer_agent/index.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/index.js +52 -0
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +42 -0
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.js +133 -0
- package/dist/core/agent/report_analyzer_agent/parse.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.js +375 -0
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.js +300 -0
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.js +558 -0
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.js +150 -0
- package/dist/core/agent/report_analyzer_agent/types.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/types.js +274 -0
- package/dist/core/agent/rewrite_agent/agent.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/agent.js +209 -0
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.js +95 -0
- package/dist/core/agent/rewrite_agent/mapping.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/mapping.js +56 -0
- package/dist/core/agent/rewrite_agent/parse.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/parse.js +121 -0
- package/dist/core/agent/rewrite_agent/types.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/types.js +37 -0
- package/dist/core/agent/single_agent/agent.d.ts +0 -1
- package/dist/core/agent/single_agent/agent.js +798 -0
- package/dist/core/agent/single_agent/hook_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/hook_manager.js +60 -0
- package/dist/core/agent/single_agent/hooks.d.ts +0 -1
- package/dist/core/agent/single_agent/hooks.js +288 -0
- package/dist/core/agent/single_agent/image_utils.d.ts +0 -1
- package/dist/core/agent/single_agent/image_utils.js +159 -0
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.js +376 -0
- package/dist/core/agent/single_agent/subagent_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/subagent_manager.js +73 -0
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.js +42 -0
- package/dist/core/agent/types.d.ts +0 -1
- package/dist/core/agent/types.js +2 -0
- package/dist/core/agent/utils/message_builder.d.ts +0 -1
- package/dist/core/agent/utils/message_builder.js +138 -0
- package/dist/core/device/device_protocol.d.ts +0 -1
- package/dist/core/device/device_protocol.js +2 -0
- package/dist/core/device/hdc/apps.d.ts +0 -1
- package/dist/core/device/hdc/apps.js +437 -0
- package/dist/core/device/hdc/device.d.ts +0 -1
- package/dist/core/device/hdc/device.js +219 -0
- package/dist/core/device/hdc/index.d.ts +0 -1
- package/dist/core/device/hdc/index.js +31 -0
- package/dist/core/device/hdc/input.d.ts +0 -1
- package/dist/core/device/hdc/input.js +74 -0
- package/dist/core/device/hdc/screenshot.d.ts +0 -1
- package/dist/core/device/hdc/screenshot.js +171 -0
- package/dist/core/device/index.d.ts +0 -1
- package/dist/core/device/index.js +70 -0
- package/dist/core/device/types.d.ts +0 -1
- package/dist/core/device/types.js +2 -0
- package/dist/core/knowledge/knowledge_manager.d.ts +0 -1
- package/dist/core/knowledge/knowledge_manager.js +70 -0
- package/dist/core/knowledge/vectordb.d.ts +0 -1
- package/dist/core/knowledge/vectordb.js +283 -0
- package/dist/core/mcp/adapter_factory.d.ts +0 -1
- package/dist/core/mcp/adapter_factory.js +99 -0
- package/dist/core/mcp/android_adapter.d.ts +1 -2
- package/dist/core/mcp/android_adapter.js +286 -0
- package/dist/core/mcp/base_adapter.d.ts +0 -1
- package/dist/core/mcp/base_adapter.js +86 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +9 -1
- package/dist/core/mcp/harmony_hdc_adapter.js +782 -0
- package/dist/core/mcp/ios_adapter.d.ts +1 -2
- package/dist/core/mcp/ios_adapter.js +286 -0
- package/dist/core/mcp/local_tools.d.ts +0 -1
- package/dist/core/mcp/local_tools.js +41 -0
- package/dist/core/mcp/mcp_tools.d.ts +0 -1
- package/dist/core/mcp/mcp_tools.js +382 -0
- package/dist/core/mcp/types.d.ts +0 -1
- package/dist/core/mcp/types.js +6 -0
- package/dist/core/memory/compressed_session.d.ts +0 -1
- package/dist/core/memory/compressed_session.js +182 -0
- package/dist/core/memory/context_compressor.d.ts +0 -1
- package/dist/core/memory/context_compressor.js +176 -0
- package/dist/core/memory/index.d.ts +0 -1
- package/dist/core/memory/index.js +22 -0
- package/dist/core/memory/memory_manager.d.ts +0 -1
- package/dist/core/memory/memory_manager.js +28 -0
- package/dist/core/memory/reflector.d.ts +0 -1
- package/dist/core/memory/reflector.js +95 -0
- package/dist/core/memory/session_factory.d.ts +0 -1
- package/dist/core/memory/session_factory.js +29 -0
- package/dist/core/memory/tool_player.d.ts +0 -1
- package/dist/core/memory/tool_player.js +225 -0
- package/dist/core/memory/tool_recorder.d.ts +0 -1
- package/dist/core/memory/tool_recorder.js +126 -0
- package/dist/core/preprocessor/task_splitter.d.ts +0 -1
- package/dist/core/preprocessor/task_splitter.js +112 -0
- package/dist/core/prompt/prompt_loader.d.ts +0 -1
- package/dist/core/prompt/prompt_loader.js +313 -0
- package/dist/core/skill/skill_manager.d.ts +0 -1
- package/dist/core/skill/skill_manager.js +299 -0
- package/dist/data_types/action.d.ts +0 -1
- package/dist/data_types/action.js +2 -0
- package/dist/data_types/agent.d.ts +0 -1
- package/dist/data_types/agent.js +2 -0
- package/dist/data_types/device.d.ts +0 -1
- package/dist/data_types/device.js +2 -0
- package/dist/data_types/index.d.ts +0 -1
- package/dist/data_types/index.js +6 -0
- package/dist/data_types/report.d.ts +0 -1
- package/dist/data_types/report.js +6 -0
- package/dist/data_types/task.d.ts +0 -1
- package/dist/data_types/task.js +2 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +164 -1
- package/dist/loop/cli.d.ts +0 -1
- package/dist/loop/cli.js +127 -0
- package/dist/loop/orchestrator.d.ts +0 -1
- package/dist/loop/orchestrator.js +314 -0
- package/dist/loop/result_writer.d.ts +0 -1
- package/dist/loop/result_writer.js +260 -0
- package/dist/loop/types.d.ts +0 -1
- package/dist/loop/types.js +82 -0
- package/dist/mcp-server/server.d.ts +0 -1
- package/dist/mcp-server/server.js +341 -0
- package/dist/mcp-server/types.d.ts +283 -118
- package/dist/mcp-server/types.js +202 -0
- package/dist/reporter/batch_summary.d.ts +0 -1
- package/dist/reporter/batch_summary.js +197 -0
- package/dist/reporter/generator.d.ts +0 -1
- package/dist/reporter/generator.js +772 -0
- package/dist/reporter/types.d.ts +14 -15
- package/dist/reporter/types.js +44 -0
- package/dist/tools/batch_runner.d.ts +1 -1
- package/dist/tools/batch_runner.js +731 -0
- package/package.json +5 -3
- package/dist/common/config/config.yaml +0 -113
- package/dist/hypium_generator/generator.d.ts +0 -38
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_COMPRESSION_CONFIG = void 0;
|
|
4
|
+
exports.estimateTokens = estimateTokens;
|
|
5
|
+
exports.countImagesInMessages = countImagesInMessages;
|
|
6
|
+
exports.extractTextFromMessage = extractTextFromMessage;
|
|
7
|
+
exports.filterImagesFromMessage = filterImagesFromMessage;
|
|
8
|
+
exports.compressContext = compressContext;
|
|
9
|
+
const logger_1 = require("../../common/logger");
|
|
10
|
+
const custom_model_1 = require("../../common/model/custom_model");
|
|
11
|
+
exports.DEFAULT_COMPRESSION_CONFIG = {
|
|
12
|
+
enabled: true,
|
|
13
|
+
maxTokens: 7000,
|
|
14
|
+
maxRecentMessages: 6,
|
|
15
|
+
};
|
|
16
|
+
const COMPRESSION_PROMPT = `你是一个对话摘要专家。你的任务是将一段对话历史压缩成一个简洁的摘要,同时保留关键信息。
|
|
17
|
+
|
|
18
|
+
## 要求
|
|
19
|
+
1. 保留所有重要的任务进展和操作步骤
|
|
20
|
+
2. 保留所有关键的观察结果和发现
|
|
21
|
+
3. 保留所有的错误、问题和解决方案
|
|
22
|
+
4. 移除冗余的、重复的或无关紧要的内容
|
|
23
|
+
5. 使用简洁的语言,但要确保信息完整
|
|
24
|
+
|
|
25
|
+
## 输出格式
|
|
26
|
+
输出应该是一个简洁的摘要,格式如下:
|
|
27
|
+
|
|
28
|
+
【对话摘要】
|
|
29
|
+
- 任务目标:[描述用户的目标]
|
|
30
|
+
- 已完成步骤:[列出已完成的关键步骤]
|
|
31
|
+
- 当前状态:[描述当前的屏幕状态或应用状态]
|
|
32
|
+
- 关键发现:[记录重要的观察结果]
|
|
33
|
+
- 待完成任务:[列出还需要完成的任务]
|
|
34
|
+
|
|
35
|
+
请根据以下对话历史生成摘要:
|
|
36
|
+
|
|
37
|
+
{conversation_history}
|
|
38
|
+
`;
|
|
39
|
+
function estimateTokens(messages) {
|
|
40
|
+
// Aligned with python: filter out image/file base64 data BEFORE estimating tokens.
|
|
41
|
+
// Base64 image data (~400KB/screenshot) would inflate token count ~67x if counted
|
|
42
|
+
// as text, causing compression to trigger on every getItems() call.
|
|
43
|
+
const filtered = messages.map(msg => filterImagesFromMessage(msg));
|
|
44
|
+
const jsonStr = JSON.stringify(filtered);
|
|
45
|
+
return Math.floor(jsonStr.length / 3);
|
|
46
|
+
}
|
|
47
|
+
function countImagesInMessages(messages) {
|
|
48
|
+
const result = [];
|
|
49
|
+
for (let i = 0; i < messages.length; i++) {
|
|
50
|
+
const content = messages[i]?.content;
|
|
51
|
+
if (Array.isArray(content)) {
|
|
52
|
+
for (const part of content) {
|
|
53
|
+
if (typeof part === 'object' && part !== null) {
|
|
54
|
+
const type = part.type;
|
|
55
|
+
if (type === 'input_image' || type === 'image_url') {
|
|
56
|
+
result.push([i, type]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function extractTextFromMessage(msg) {
|
|
65
|
+
const content = msg.content;
|
|
66
|
+
if (typeof content === 'string')
|
|
67
|
+
return content;
|
|
68
|
+
if (Array.isArray(content)) {
|
|
69
|
+
const texts = [];
|
|
70
|
+
for (const part of content) {
|
|
71
|
+
if (typeof part === 'object' && part !== null) {
|
|
72
|
+
const p = part;
|
|
73
|
+
if (p.type === 'text' && typeof p.text === 'string') {
|
|
74
|
+
texts.push(p.text);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (typeof part === 'string') {
|
|
78
|
+
texts.push(part);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return texts.join('\n');
|
|
82
|
+
}
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
function filterImagesFromMessage(msg) {
|
|
86
|
+
const content = msg.content;
|
|
87
|
+
if (!Array.isArray(content))
|
|
88
|
+
return msg;
|
|
89
|
+
const filtered = content.filter((part) => {
|
|
90
|
+
if (typeof part === 'object' && part !== null) {
|
|
91
|
+
const p = part;
|
|
92
|
+
const type = p.type;
|
|
93
|
+
// Filter out all image-bearing part types:
|
|
94
|
+
// - input_image / image_url / image (OpenAI SDK format, used by Python)
|
|
95
|
+
// - file (Vercel AI SDK format, used by Node agent — contains data:image/jpeg;base64,...)
|
|
96
|
+
if (type === 'input_image' || type === 'image_url' || type === 'image')
|
|
97
|
+
return false;
|
|
98
|
+
if (type === 'file') {
|
|
99
|
+
// Only filter if it contains image data (data:image or mediaType starts with image/)
|
|
100
|
+
const data = typeof p.data === 'string' ? p.data : '';
|
|
101
|
+
const mediaType = typeof p.mediaType === 'string' ? p.mediaType : '';
|
|
102
|
+
if (data.startsWith('data:image') || mediaType.startsWith('image/'))
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
});
|
|
108
|
+
return { ...msg, content: filtered };
|
|
109
|
+
}
|
|
110
|
+
async function compressContext(items, config) {
|
|
111
|
+
const compressionConfig = config?.contextCompression ?? exports.DEFAULT_COMPRESSION_CONFIG;
|
|
112
|
+
if (!compressionConfig.enabled) {
|
|
113
|
+
return [items, null];
|
|
114
|
+
}
|
|
115
|
+
const originalTokenCount = estimateTokens(items);
|
|
116
|
+
if (originalTokenCount <= compressionConfig.maxTokens) {
|
|
117
|
+
return [items, null];
|
|
118
|
+
}
|
|
119
|
+
const keepCount = compressionConfig.maxRecentMessages;
|
|
120
|
+
const oldItems = items.slice(0, Math.max(0, items.length - keepCount));
|
|
121
|
+
const recentItems = items.slice(Math.max(0, items.length - keepCount));
|
|
122
|
+
if (oldItems.length === 0) {
|
|
123
|
+
return [items, null];
|
|
124
|
+
}
|
|
125
|
+
const conversationHistory = oldItems
|
|
126
|
+
.map((msg) => {
|
|
127
|
+
const role = msg.role ?? 'unknown';
|
|
128
|
+
const text = extractTextFromMessage(msg);
|
|
129
|
+
return text ? `${role}: ${text}` : '';
|
|
130
|
+
})
|
|
131
|
+
.filter(Boolean)
|
|
132
|
+
.join('\n');
|
|
133
|
+
if (!conversationHistory.trim()) {
|
|
134
|
+
return [items, null];
|
|
135
|
+
}
|
|
136
|
+
const llmCaller = new custom_model_1.LLMCaller();
|
|
137
|
+
const modelConfig = config?.model?.unified;
|
|
138
|
+
if (!modelConfig) {
|
|
139
|
+
logger_1.logger.warn('[ContextCompressor] No model config available, skipping compression');
|
|
140
|
+
return [items, null];
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const prompt = COMPRESSION_PROMPT.replace('{conversation_history}', conversationHistory);
|
|
144
|
+
const result = await llmCaller.call({
|
|
145
|
+
systemPrompt: 'You are a conversation summarization expert.',
|
|
146
|
+
userPrompt: prompt,
|
|
147
|
+
modelConfig,
|
|
148
|
+
});
|
|
149
|
+
if (!result.text) {
|
|
150
|
+
logger_1.logger.warn('[ContextCompressor] LLM returned empty text');
|
|
151
|
+
return [items, null];
|
|
152
|
+
}
|
|
153
|
+
const compressedMessage = {
|
|
154
|
+
role: 'user',
|
|
155
|
+
content: `【对话摘要】\n${result.text}`,
|
|
156
|
+
};
|
|
157
|
+
const compressedItems = [compressedMessage, ...recentItems];
|
|
158
|
+
const compressedTokenCount = estimateTokens(compressedItems);
|
|
159
|
+
const ratio = originalTokenCount > 0 ? 1 - compressedTokenCount / originalTokenCount : 0;
|
|
160
|
+
logger_1.logger.info(`[ContextCompressor] Compressed: ${originalTokenCount} -> ${compressedTokenCount} tokens ` +
|
|
161
|
+
`(${(ratio * 100).toFixed(1)}% reduction), ${oldItems.length} old -> 1 summary + ${recentItems.length} recent`);
|
|
162
|
+
return [
|
|
163
|
+
compressedItems,
|
|
164
|
+
{
|
|
165
|
+
compressedText: result.text,
|
|
166
|
+
originalTokenCount,
|
|
167
|
+
compressedTokenCount,
|
|
168
|
+
compressionRatio: ratio,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
logger_1.logger.warning(`[ContextCompressor] Failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
174
|
+
return [items, null];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* Memory subsystem barrel (aligned with python core/memory/__init__.py).
|
|
19
|
+
*
|
|
20
|
+
* Re-exports the memory facade plus the session input filter helper.
|
|
21
|
+
*/
|
|
22
|
+
__exportStar(require("./memory_manager"), exports);
|
|
@@ -18,4 +18,3 @@ export type { ToolPlayerOptions, PlaybackResult } from './tool_player';
|
|
|
18
18
|
export { ToolPlayer } from './tool_player';
|
|
19
19
|
export type { SessionType } from './session_factory';
|
|
20
20
|
export { createSession, createSessionFromConfig } from './session_factory';
|
|
21
|
-
//# sourceMappingURL=memory_manager.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Memory subsystem facade (aligned with python core/memory/memory_manager.py).
|
|
4
|
+
*
|
|
5
|
+
* The legacy monolithic MemoryManager (apps/summary markdown store) was removed
|
|
6
|
+
* together with the hypium_agent package. This module now re-exports the new
|
|
7
|
+
* memory components (compressed session, context compressor, reflector, tool
|
|
8
|
+
* recorder/player, session factory) so callers can import from a single entry.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createSessionFromConfig = exports.createSession = exports.ToolPlayer = exports.ToolRecorder = exports.DEFAULT_REFLECTION_CONFIG = exports.Reflector = exports.compressContext = exports.estimateTokens = exports.DEFAULT_COMPRESSION_CONFIG = exports.makeSessionInputFilter = exports.CompressedSession = void 0;
|
|
12
|
+
var compressed_session_1 = require("./compressed_session");
|
|
13
|
+
Object.defineProperty(exports, "CompressedSession", { enumerable: true, get: function () { return compressed_session_1.CompressedSession; } });
|
|
14
|
+
Object.defineProperty(exports, "makeSessionInputFilter", { enumerable: true, get: function () { return compressed_session_1.makeSessionInputFilter; } });
|
|
15
|
+
var context_compressor_1 = require("./context_compressor");
|
|
16
|
+
Object.defineProperty(exports, "DEFAULT_COMPRESSION_CONFIG", { enumerable: true, get: function () { return context_compressor_1.DEFAULT_COMPRESSION_CONFIG; } });
|
|
17
|
+
Object.defineProperty(exports, "estimateTokens", { enumerable: true, get: function () { return context_compressor_1.estimateTokens; } });
|
|
18
|
+
Object.defineProperty(exports, "compressContext", { enumerable: true, get: function () { return context_compressor_1.compressContext; } });
|
|
19
|
+
var reflector_1 = require("./reflector");
|
|
20
|
+
Object.defineProperty(exports, "Reflector", { enumerable: true, get: function () { return reflector_1.Reflector; } });
|
|
21
|
+
Object.defineProperty(exports, "DEFAULT_REFLECTION_CONFIG", { enumerable: true, get: function () { return reflector_1.DEFAULT_REFLECTION_CONFIG; } });
|
|
22
|
+
var tool_recorder_1 = require("./tool_recorder");
|
|
23
|
+
Object.defineProperty(exports, "ToolRecorder", { enumerable: true, get: function () { return tool_recorder_1.ToolRecorder; } });
|
|
24
|
+
var tool_player_1 = require("./tool_player");
|
|
25
|
+
Object.defineProperty(exports, "ToolPlayer", { enumerable: true, get: function () { return tool_player_1.ToolPlayer; } });
|
|
26
|
+
var session_factory_1 = require("./session_factory");
|
|
27
|
+
Object.defineProperty(exports, "createSession", { enumerable: true, get: function () { return session_factory_1.createSession; } });
|
|
28
|
+
Object.defineProperty(exports, "createSessionFromConfig", { enumerable: true, get: function () { return session_factory_1.createSessionFromConfig; } });
|
|
@@ -17,4 +17,3 @@ export declare class Reflector {
|
|
|
17
17
|
performReflection(items: Array<Record<string, unknown>>, modelConfig?: ModelConfig): Promise<string | null>;
|
|
18
18
|
createReflectionMessage(reflectionResult: string, currentStep: number): Record<string, unknown>;
|
|
19
19
|
}
|
|
20
|
-
//# sourceMappingURL=reflector.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Reflector = exports.DEFAULT_REFLECTION_CONFIG = void 0;
|
|
4
|
+
const logger_1 = require("../../common/logger");
|
|
5
|
+
const custom_model_1 = require("../../common/model/custom_model");
|
|
6
|
+
const context_compressor_1 = require("./context_compressor");
|
|
7
|
+
exports.DEFAULT_REFLECTION_CONFIG = {
|
|
8
|
+
enabled: false,
|
|
9
|
+
initialStep: 25,
|
|
10
|
+
interval: 15,
|
|
11
|
+
};
|
|
12
|
+
const REFLECTION_PROMPT = `
|
|
13
|
+
你是一个执行反思专家。请分析当前的对话历史,进行深度反思:
|
|
14
|
+
|
|
15
|
+
1. **任务目标**:用户的原始任务是什么?
|
|
16
|
+
2. **已完成步骤**:目前为止执行了哪些关键步骤?
|
|
17
|
+
3. **当前进度**:任务完成度如何?还有哪些步骤待完成?
|
|
18
|
+
4. **问题检测**:是否存在重复操作、死循环或偏离目标的情况?
|
|
19
|
+
5. **建议**:接下来应该如何调整策略以更好地完成任务?
|
|
20
|
+
|
|
21
|
+
如果检测到反复尝试同一个操作,进入死循环,一般是用例步骤不清晰或应用功能和用例不匹配导致,请建议提前终止测试,不要进行过度探索。
|
|
22
|
+
|
|
23
|
+
**选择器场景检测**:若当前界面出现时间选择器(timepicker)、日期选择器(datepicker)或数字选择器(number picker)等需要滚动调整值的控件,且常规滑动/点击难以定位目标值,建议切换到 scroll_search 子代理以滚动方式精确查找目标值,避免在滚轮上盲目点击。
|
|
24
|
+
请用简洁的中文输出反思结果。`;
|
|
25
|
+
class Reflector {
|
|
26
|
+
_config;
|
|
27
|
+
_lastReflectionStep = 0;
|
|
28
|
+
_triggerTimes = 0;
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this._config = config ?? exports.DEFAULT_REFLECTION_CONFIG;
|
|
31
|
+
}
|
|
32
|
+
shouldReflect(currentCount) {
|
|
33
|
+
if (!this._config.enabled)
|
|
34
|
+
return false;
|
|
35
|
+
if (currentCount < this._config.initialStep)
|
|
36
|
+
return false;
|
|
37
|
+
if (Math.floor(currentCount / this._config.interval) <= this._triggerTimes)
|
|
38
|
+
return false;
|
|
39
|
+
if (currentCount === this._lastReflectionStep)
|
|
40
|
+
return false;
|
|
41
|
+
this._triggerTimes++;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
markReflectionDone(currentCount) {
|
|
45
|
+
this._lastReflectionStep = currentCount;
|
|
46
|
+
}
|
|
47
|
+
resetReflection(currentCount) {
|
|
48
|
+
if (currentCount >= this._config.initialStep) {
|
|
49
|
+
const intervalsPassed = Math.floor((currentCount - this._config.initialStep) / this._config.interval);
|
|
50
|
+
this._lastReflectionStep = this._config.initialStep + intervalsPassed * this._config.interval;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this._lastReflectionStep = 0;
|
|
54
|
+
}
|
|
55
|
+
this._triggerTimes = 0;
|
|
56
|
+
}
|
|
57
|
+
buildReflectionPrompt(items) {
|
|
58
|
+
const filtered = items.map((msg) => (0, context_compressor_1.filterImagesFromMessage)(msg));
|
|
59
|
+
const conversationHistory = filtered
|
|
60
|
+
.map((msg) => {
|
|
61
|
+
const role = msg.role ?? 'unknown';
|
|
62
|
+
const text = (0, context_compressor_1.extractTextFromMessage)(msg);
|
|
63
|
+
return text ? `${role}: ${text}` : '';
|
|
64
|
+
})
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join('\n');
|
|
67
|
+
return `${REFLECTION_PROMPT}\n\n对话历史:\n${conversationHistory}`;
|
|
68
|
+
}
|
|
69
|
+
async performReflection(items, modelConfig) {
|
|
70
|
+
if (!modelConfig) {
|
|
71
|
+
logger_1.logger.warn('[Reflector] No model config available');
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const llmCaller = new custom_model_1.LLMCaller();
|
|
76
|
+
const result = await llmCaller.call({
|
|
77
|
+
systemPrompt: 'You are a reflection expert.',
|
|
78
|
+
userPrompt: this.buildReflectionPrompt(items),
|
|
79
|
+
modelConfig,
|
|
80
|
+
});
|
|
81
|
+
return result.text || null;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
logger_1.logger.warning(`[Reflector] Failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
createReflectionMessage(reflectionResult, currentStep) {
|
|
89
|
+
return {
|
|
90
|
+
role: 'user',
|
|
91
|
+
content: `【执行反思 - 第${currentStep}步】\n${reflectionResult}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.Reflector = Reflector;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSession = createSession;
|
|
4
|
+
exports.createSessionFromConfig = createSessionFromConfig;
|
|
5
|
+
const logger_1 = require("../../common/logger");
|
|
6
|
+
const compressed_session_1 = require("./compressed_session");
|
|
7
|
+
function createSession(type, opts) {
|
|
8
|
+
switch (type) {
|
|
9
|
+
case 'compressed':
|
|
10
|
+
return new compressed_session_1.CompressedSession(opts);
|
|
11
|
+
case 'memory':
|
|
12
|
+
return new compressed_session_1.CompressedSession({ ...opts, autoCompress: false });
|
|
13
|
+
default:
|
|
14
|
+
logger_1.logger.warn(`[SessionFactory] Unknown session type: ${type}, defaulting to compressed`);
|
|
15
|
+
return new compressed_session_1.CompressedSession(opts);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function createSessionFromConfig(config, reportGenerator, getCurrentStepNumber) {
|
|
19
|
+
const agentConfig = config?.agent;
|
|
20
|
+
const sessionType = (agentConfig?.sessionType ?? 'compressed');
|
|
21
|
+
return createSession(sessionType, {
|
|
22
|
+
compressionConfig: agentConfig?.contextCompression,
|
|
23
|
+
reflectionConfig: agentConfig?.reflection,
|
|
24
|
+
maxHistoryImage: agentConfig?.maxHistoryImage,
|
|
25
|
+
modelConfig: config?.model?.unified,
|
|
26
|
+
reportGenerator: reportGenerator,
|
|
27
|
+
getCurrentStepNumber,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolPlayer = exports.ACTION_MAP = exports.DEFAULT_POPUP_CONFIG = void 0;
|
|
4
|
+
const logger_1 = require("../../common/logger");
|
|
5
|
+
const tool_recorder_1 = require("./tool_recorder");
|
|
6
|
+
const custom_model_1 = require("../../common/model/custom_model");
|
|
7
|
+
exports.DEFAULT_POPUP_CONFIG = {
|
|
8
|
+
enabled: true,
|
|
9
|
+
maxRetryAttempts: 1,
|
|
10
|
+
skipPopupSteps: true,
|
|
11
|
+
};
|
|
12
|
+
/** Map recorded tool names to device action display names (aligned with python ACTION_MAP). */
|
|
13
|
+
exports.ACTION_MAP = {
|
|
14
|
+
click: 'Tap',
|
|
15
|
+
double_click: 'Double Tap',
|
|
16
|
+
long_click: 'Long Press',
|
|
17
|
+
drag: 'Drag',
|
|
18
|
+
swipe: 'Swipe',
|
|
19
|
+
pinch_in: 'Pinch In',
|
|
20
|
+
pinch_out: 'Pinch Out',
|
|
21
|
+
input_text: 'Type',
|
|
22
|
+
clear_text: 'Clear Text',
|
|
23
|
+
};
|
|
24
|
+
class ToolPlayer {
|
|
25
|
+
_recording;
|
|
26
|
+
_device;
|
|
27
|
+
_modelConfig;
|
|
28
|
+
_maxRetries;
|
|
29
|
+
_popupConfig;
|
|
30
|
+
_replanCallback;
|
|
31
|
+
_currentIndex = 0;
|
|
32
|
+
_stepCount = 0;
|
|
33
|
+
_replanTriggered = false;
|
|
34
|
+
_lastPlaybackResults = null;
|
|
35
|
+
_popupStats = { detected: 0, closed: 0, skipped: 0, retrySuccess: 0 };
|
|
36
|
+
constructor(opts) {
|
|
37
|
+
this._recording = opts.recording ?? null;
|
|
38
|
+
this._device = opts.device;
|
|
39
|
+
this._modelConfig = opts.modelConfig;
|
|
40
|
+
this._maxRetries = opts.maxRetries ?? 3;
|
|
41
|
+
this._popupConfig = opts.popupConfig ?? exports.DEFAULT_POPUP_CONFIG;
|
|
42
|
+
this._replanCallback = opts.replanCallback;
|
|
43
|
+
}
|
|
44
|
+
/** Load a recording from a file. Returns true on success. */
|
|
45
|
+
loadRecord(filePath) {
|
|
46
|
+
const session = tool_recorder_1.ToolRecorder.loadFromFile(filePath);
|
|
47
|
+
if (session) {
|
|
48
|
+
this._recording = session;
|
|
49
|
+
logger_1.logger.info(`[ToolPlayer] Loaded ${session.records.length} records from ${filePath}`);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
logger_1.logger.warn(`[ToolPlayer] Failed to load recording from ${filePath}`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/** Load a recording by task name (md5 hash lookup). */
|
|
56
|
+
loadByTask(task, memoryDir) {
|
|
57
|
+
const session = tool_recorder_1.ToolRecorder.findRecording(task, memoryDir);
|
|
58
|
+
if (session) {
|
|
59
|
+
this._recording = session;
|
|
60
|
+
logger_1.logger.info(`[ToolPlayer] Loaded ${session.records.length} records for task "${task}"`);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
logger_1.logger.warn(`[ToolPlayer] No recording found for task "${task}"`);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
/** Get the loaded session. */
|
|
67
|
+
getSession() {
|
|
68
|
+
return this._recording;
|
|
69
|
+
}
|
|
70
|
+
getTotalSteps() {
|
|
71
|
+
return this._recording?.records.length ?? 0;
|
|
72
|
+
}
|
|
73
|
+
getCurrentStep() {
|
|
74
|
+
return this._currentIndex;
|
|
75
|
+
}
|
|
76
|
+
lastPlaybackResults() {
|
|
77
|
+
return this._lastPlaybackResults;
|
|
78
|
+
}
|
|
79
|
+
/** Play back the recorded tool calls in order. */
|
|
80
|
+
async play() {
|
|
81
|
+
if (!this._recording) {
|
|
82
|
+
return { totalSteps: 0, replayedSteps: 0, successCount: 0, failureCount: 0, result: 'fail', summary: 'No recording loaded' };
|
|
83
|
+
}
|
|
84
|
+
const records = this._recording.records;
|
|
85
|
+
let replayed = 0;
|
|
86
|
+
let success = 0;
|
|
87
|
+
let failure = 0;
|
|
88
|
+
const details = [];
|
|
89
|
+
for (let i = 0; i < records.length; i++) {
|
|
90
|
+
this._currentIndex = i;
|
|
91
|
+
this._stepCount++;
|
|
92
|
+
const record = records[i];
|
|
93
|
+
let attemptSuccess = false;
|
|
94
|
+
let lastError;
|
|
95
|
+
for (let attempt = 0; attempt <= this._maxRetries; attempt++) {
|
|
96
|
+
try {
|
|
97
|
+
const result = await this._device.callTool(record.toolName, record.arguments);
|
|
98
|
+
const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
|
|
99
|
+
// Popup detection (aligned with python PopupMixin — basic version)
|
|
100
|
+
if (this._popupConfig.enabled && this._detectPopup(resultStr)) {
|
|
101
|
+
this._popupStats.detected++;
|
|
102
|
+
const closed = await this._tryClosePopup();
|
|
103
|
+
if (closed) {
|
|
104
|
+
this._popupStats.closed++;
|
|
105
|
+
if (attempt > 0)
|
|
106
|
+
this._popupStats.retrySuccess++;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this._popupStats.skipped++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (resultStr.includes('failed') || resultStr.includes('error')) {
|
|
113
|
+
lastError = resultStr.slice(0, 200);
|
|
114
|
+
if (attempt < this._maxRetries)
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
attemptSuccess = true;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
lastError = e instanceof Error ? e.message : String(e);
|
|
124
|
+
if (attempt < this._maxRetries)
|
|
125
|
+
continue;
|
|
126
|
+
logger_1.logger.warning(`[ToolPlayer] Step ${i + 1} ${record.toolName} failed: ${lastError}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
replayed++;
|
|
130
|
+
if (attemptSuccess)
|
|
131
|
+
success++;
|
|
132
|
+
else {
|
|
133
|
+
failure++;
|
|
134
|
+
details.push({ step: i + 1, tool: record.toolName, success: false, error: lastError });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Replan trigger (aligned with python ReplanMixin — basic version)
|
|
138
|
+
if (failure > 0 && this._replanCallback && !this._replanTriggered) {
|
|
139
|
+
this._replanTriggered = true;
|
|
140
|
+
logger_1.logger.info('[ToolPlayer] Triggering replan due to playback failures');
|
|
141
|
+
try {
|
|
142
|
+
await this._replanCallback(`Playback failed at ${failure}/${replayed} steps. Please replan.`);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
logger_1.logger.warning(`[ToolPlayer] Replan callback failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const result = failure === 0 ? 'pass' : success > failure ? 'unknown' : 'fail';
|
|
149
|
+
const summary = `Replayed ${replayed}/${records.length} steps: ${success} success, ${failure} fail`;
|
|
150
|
+
logger_1.logger.info(`[ToolPlayer] ${summary} (popups: ${JSON.stringify(this._popupStats)})`);
|
|
151
|
+
this._lastPlaybackResults = details.map((d) => ({ ...d }));
|
|
152
|
+
return {
|
|
153
|
+
totalSteps: records.length,
|
|
154
|
+
replayedSteps: replayed,
|
|
155
|
+
successCount: success,
|
|
156
|
+
failureCount: failure,
|
|
157
|
+
result: result,
|
|
158
|
+
summary,
|
|
159
|
+
details,
|
|
160
|
+
popupStats: { ...this._popupStats },
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** Basic popup detection: check result text for popup-related keywords. */
|
|
164
|
+
_detectPopup(resultStr) {
|
|
165
|
+
return /popup|dialog|modal|permission|allow|deny|close.*button|dismiss/i.test(resultStr);
|
|
166
|
+
}
|
|
167
|
+
/** Basic popup close: try pressing back/home to dismiss. */
|
|
168
|
+
async _tryClosePopup() {
|
|
169
|
+
try {
|
|
170
|
+
await this._device.callTool('go_back', {});
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** Judge the playback result with a detailed LLM prompt (aligned with python judge_result). */
|
|
178
|
+
async judgeResult(playbackResult) {
|
|
179
|
+
if (!this._modelConfig)
|
|
180
|
+
return playbackResult.summary;
|
|
181
|
+
const taskInfo = this._recording?.task ?? '(unknown task)';
|
|
182
|
+
const resultsText = playbackResult.details
|
|
183
|
+
? playbackResult.details.map((d) => `Step ${d.step}: ${d.tool} — ${d.success ? 'PASS' : `FAIL (${d.error ?? 'unknown'})`}`).join('\n')
|
|
184
|
+
: playbackResult.summary;
|
|
185
|
+
const prompt = this._buildJudgePrompt(taskInfo, resultsText, playbackResult);
|
|
186
|
+
try {
|
|
187
|
+
const llmCaller = new custom_model_1.LLMCaller();
|
|
188
|
+
const result = await llmCaller.call({
|
|
189
|
+
systemPrompt: 'You are a test result judge. Analyze the playback results and determine if the test passed or failed.',
|
|
190
|
+
userPrompt: prompt,
|
|
191
|
+
modelConfig: this._modelConfig,
|
|
192
|
+
});
|
|
193
|
+
return result.text;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return playbackResult.summary;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** Build the detailed judge prompt (aligned with python _build_judge_prompt). */
|
|
200
|
+
_buildJudgePrompt(taskInfo, resultsText, playbackResult) {
|
|
201
|
+
return `## Task
|
|
202
|
+
${taskInfo}
|
|
203
|
+
|
|
204
|
+
## Playback Results
|
|
205
|
+
${resultsText}
|
|
206
|
+
|
|
207
|
+
## Summary
|
|
208
|
+
Total steps: ${playbackResult.totalSteps}
|
|
209
|
+
Replayed: ${playbackResult.replayedSteps}
|
|
210
|
+
Success: ${playbackResult.successCount}
|
|
211
|
+
Failure: ${playbackResult.failureCount}
|
|
212
|
+
Popup stats: ${JSON.stringify(playbackResult.popupStats ?? {})}
|
|
213
|
+
|
|
214
|
+
## Instructions
|
|
215
|
+
Based on the playback results above, determine whether the test passed or failed.
|
|
216
|
+
|
|
217
|
+
Consider:
|
|
218
|
+
1. Did all critical steps succeed?
|
|
219
|
+
2. Were any failures due to popups or transient issues (not real test failures)?
|
|
220
|
+
3. Was the overall task intent achieved despite minor failures?
|
|
221
|
+
|
|
222
|
+
Output your judgment as either "PASS" or "FAIL" followed by a brief explanation.`;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.ToolPlayer = ToolPlayer;
|