@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,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompressedSession = void 0;
|
|
4
|
-
exports.makeSessionInputFilter = makeSessionInputFilter;
|
|
5
|
-
const logger_1 = require("../../common/logger");
|
|
6
|
-
const context_compressor_1 = require("./context_compressor");
|
|
7
|
-
const reflector_1 = require("./reflector");
|
|
8
|
-
class CompressedSession {
|
|
9
|
-
sessionId;
|
|
10
|
-
autoCompress;
|
|
11
|
-
_items = [];
|
|
12
|
-
_compressedSummary = null;
|
|
13
|
-
_compressionConfig;
|
|
14
|
-
_reflector;
|
|
15
|
-
_maxHistoryImage;
|
|
16
|
-
_modelConfig;
|
|
17
|
-
_reportGenerator;
|
|
18
|
-
_getCurrentStepNumber;
|
|
19
|
-
constructor(opts = {}) {
|
|
20
|
-
this.sessionId = opts.sessionId ?? crypto.randomUUID();
|
|
21
|
-
this.autoCompress = opts.autoCompress ?? true;
|
|
22
|
-
this._compressionConfig = opts.compressionConfig ?? { enabled: true, maxTokens: 7000, maxRecentMessages: 6 };
|
|
23
|
-
this._reflector = new reflector_1.Reflector(opts.reflectionConfig);
|
|
24
|
-
this._maxHistoryImage = opts.maxHistoryImage ?? 3;
|
|
25
|
-
this._modelConfig = opts.modelConfig ?? null;
|
|
26
|
-
this._reportGenerator = opts.reportGenerator ?? null;
|
|
27
|
-
this._getCurrentStepNumber = opts.getCurrentStepNumber ?? null;
|
|
28
|
-
}
|
|
29
|
-
get items() {
|
|
30
|
-
return this._items;
|
|
31
|
-
}
|
|
32
|
-
get compressedSummary() {
|
|
33
|
-
return this._compressedSummary;
|
|
34
|
-
}
|
|
35
|
-
async getItems(limit) {
|
|
36
|
-
if (limit === undefined) {
|
|
37
|
-
await this._maybeReflect();
|
|
38
|
-
return [...this._items];
|
|
39
|
-
}
|
|
40
|
-
return this._items.slice(-limit);
|
|
41
|
-
}
|
|
42
|
-
async addItems(newItems) {
|
|
43
|
-
this._items.push(...newItems);
|
|
44
|
-
this._items = this._filterImagesToKeepRecent(this._items);
|
|
45
|
-
if (this.autoCompress) {
|
|
46
|
-
await this._maybeCompress();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
popItem() {
|
|
50
|
-
return this._items.pop();
|
|
51
|
-
}
|
|
52
|
-
clearSession() {
|
|
53
|
-
this._items = [];
|
|
54
|
-
this._compressedSummary = null;
|
|
55
|
-
this._reflector.resetReflection(0);
|
|
56
|
-
}
|
|
57
|
-
_filterImagesToKeepRecent(items) {
|
|
58
|
-
const imagePositions = [];
|
|
59
|
-
for (let i = 0; i < items.length; i++) {
|
|
60
|
-
const content = items[i].content;
|
|
61
|
-
if (Array.isArray(content)) {
|
|
62
|
-
for (let j = 0; j < content.length; j++) {
|
|
63
|
-
const part = content[j];
|
|
64
|
-
if (typeof part === 'object' && part !== null) {
|
|
65
|
-
const type = part.type;
|
|
66
|
-
if (type === 'input_image' || type === 'image_url' || type === 'image') {
|
|
67
|
-
imagePositions.push([i, j]);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (imagePositions.length <= this._maxHistoryImage)
|
|
74
|
-
return items;
|
|
75
|
-
const positionsToRemove = new Set(imagePositions.slice(0, -this._maxHistoryImage).map(([i, j]) => `${i},${j}`));
|
|
76
|
-
return items.map((item, i) => {
|
|
77
|
-
const content = item.content;
|
|
78
|
-
if (!Array.isArray(content))
|
|
79
|
-
return item;
|
|
80
|
-
const newContent = content.filter((_, j) => !positionsToRemove.has(`${i},${j}`));
|
|
81
|
-
return { ...item, content: newContent };
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async _maybeCompress() {
|
|
85
|
-
if (!this._compressionConfig.enabled)
|
|
86
|
-
return;
|
|
87
|
-
const originalCount = this._items.length;
|
|
88
|
-
const originalTokenCount = (0, context_compressor_1.estimateTokens)(this._items);
|
|
89
|
-
if (originalTokenCount <= this._compressionConfig.maxTokens)
|
|
90
|
-
return;
|
|
91
|
-
const keepCount = this._compressionConfig.maxRecentMessages;
|
|
92
|
-
const oldItems = this._items.slice(0, Math.max(0, this._items.length - keepCount));
|
|
93
|
-
const recentItems = this._items.slice(Math.max(0, this._items.length - keepCount));
|
|
94
|
-
if (oldItems.length === 0)
|
|
95
|
-
return;
|
|
96
|
-
await this._compressAsync(oldItems, recentItems, originalCount, originalTokenCount);
|
|
97
|
-
}
|
|
98
|
-
async _compressAsync(oldItems, recentItems, originalCount, originalTokenCount) {
|
|
99
|
-
try {
|
|
100
|
-
const config = {
|
|
101
|
-
contextCompression: this._compressionConfig,
|
|
102
|
-
model: { unified: this._modelConfig },
|
|
103
|
-
};
|
|
104
|
-
const [compressedItems, result] = await (0, context_compressor_1.compressContext)(this._items, config);
|
|
105
|
-
if (result) {
|
|
106
|
-
this._compressedSummary = result.compressedText;
|
|
107
|
-
this._items = compressedItems;
|
|
108
|
-
this._reflector.resetReflection(this._items.length);
|
|
109
|
-
logger_1.logger.info(`[CompressedSession] Compressed: ${originalCount} -> ${this._items.length} items, ` +
|
|
110
|
-
`${originalTokenCount} -> ${result.compressedTokenCount} tokens (${(result.compressionRatio * 100).toFixed(1)}% reduction)`);
|
|
111
|
-
this._addReportEvent('compression', `上下文压缩: ${originalCount} 条 -> ${this._items.length} 条`, {
|
|
112
|
-
original_count: originalCount,
|
|
113
|
-
compressed_count: this._items.length,
|
|
114
|
-
original_token_count: originalTokenCount,
|
|
115
|
-
compressed_token_count: result.compressedTokenCount,
|
|
116
|
-
compression_ratio: result.compressionRatio,
|
|
117
|
-
compressed_text: result.compressedText,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
logger_1.logger.warning(`[CompressedSession] Failed to compress: ${e instanceof Error ? e.message : String(e)}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
async _maybeReflect() {
|
|
126
|
-
const currentStep = this._getCurrentStepNumber?.() ?? this._items.length;
|
|
127
|
-
if (!this._reflector.shouldReflect(currentStep))
|
|
128
|
-
return;
|
|
129
|
-
logger_1.logger.info(`[Reflection] Triggering reflection at step ${currentStep}...`);
|
|
130
|
-
await this._reflectAsync(currentStep);
|
|
131
|
-
}
|
|
132
|
-
async _reflectAsync(currentStep) {
|
|
133
|
-
try {
|
|
134
|
-
const result = await this._reflector.performReflection(this._items, this._modelConfig);
|
|
135
|
-
this._reflector.markReflectionDone(currentStep);
|
|
136
|
-
if (result) {
|
|
137
|
-
const msg = this._reflector.createReflectionMessage(result, currentStep);
|
|
138
|
-
this._items.push(msg);
|
|
139
|
-
logger_1.logger.info(`[Reflection] Reflection added at step ${currentStep}`);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
logger_1.logger.warning(`[Reflection] No output at step ${currentStep}`);
|
|
143
|
-
}
|
|
144
|
-
this._addReportEvent('reflection', `执行反思: 第 ${currentStep} 步`, {
|
|
145
|
-
step_number: currentStep,
|
|
146
|
-
items_count: this._items.length,
|
|
147
|
-
reflection_text: result ?? '',
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
logger_1.logger.warning(`[Reflection] Failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
_addReportEvent(eventType, content, data) {
|
|
155
|
-
if (!this._reportGenerator)
|
|
156
|
-
return;
|
|
157
|
-
try {
|
|
158
|
-
const stepNumber = this._getCurrentStepNumber?.() ?? null;
|
|
159
|
-
this._reportGenerator.addEvent({
|
|
160
|
-
eventType: eventType,
|
|
161
|
-
timestamp: new Date().toISOString(),
|
|
162
|
-
content,
|
|
163
|
-
data,
|
|
164
|
-
screenshotPath: null,
|
|
165
|
-
stepNumber,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
logger_1.logger.warning(`[CompressedSession] Failed to add report event: ${e instanceof Error ? e.message : String(e)}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.CompressedSession = CompressedSession;
|
|
174
|
-
function makeSessionInputFilter(session) {
|
|
175
|
-
return async (data) => {
|
|
176
|
-
const sessionHistory = await session.getItems();
|
|
177
|
-
if (sessionHistory.length > 0) {
|
|
178
|
-
return { input: sessionHistory, instructions: data.instructions };
|
|
179
|
-
}
|
|
180
|
-
return data;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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);
|
|
@@ -1,28 +0,0 @@
|
|
|
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; } });
|
|
@@ -1,95 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Replan manager facade.
|
|
4
|
-
*
|
|
5
|
-
* Ported from python core/memory/replan_manager.py.
|
|
6
|
-
* Re-exports the replan functionality from tool_player_replan so callers
|
|
7
|
-
* can import it from core/memory/replan_manager.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ReplanMixin = void 0;
|
|
11
|
-
var tool_player_replan_1 = require("./tool_player_replan");
|
|
12
|
-
Object.defineProperty(exports, "ReplanMixin", { enumerable: true, get: function () { return tool_player_replan_1.ReplanMixin; } });
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|