@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,91 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CaseManager = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const logger_1 = require("./logger");
|
|
40
|
+
class CaseManager {
|
|
41
|
+
casesDir;
|
|
42
|
+
cases = new Map();
|
|
43
|
+
constructor(casesDir) {
|
|
44
|
+
this.casesDir = casesDir ?? path.join(process.cwd(), 'resources', 'cases');
|
|
45
|
+
this.loadCases();
|
|
46
|
+
}
|
|
47
|
+
listCases() {
|
|
48
|
+
return Array.from(this.cases.keys());
|
|
49
|
+
}
|
|
50
|
+
loadCase(caseName) {
|
|
51
|
+
const data = this.cases.get(caseName);
|
|
52
|
+
if (!data) {
|
|
53
|
+
logger_1.logger.warn(`Case not found: ${caseName}`);
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
findCase(taskDescription) {
|
|
59
|
+
logger_1.logger.debug(`CaseManager.findCase: task="${taskDescription}" (mock)`);
|
|
60
|
+
for (const [name, data] of this.cases) {
|
|
61
|
+
const steps = String(data.test_steps ?? '');
|
|
62
|
+
if (steps.toLowerCase().includes(taskDescription.toLowerCase())) {
|
|
63
|
+
return name;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
loadCases() {
|
|
69
|
+
if (!fs.existsSync(this.casesDir)) {
|
|
70
|
+
logger_1.logger.warn(`Cases directory not found: ${this.casesDir}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const files = fs.readdirSync(this.casesDir).filter((f) => f.endsWith('.jsonl') || f.endsWith('.json'));
|
|
74
|
+
for (const file of files) {
|
|
75
|
+
try {
|
|
76
|
+
const content = fs.readFileSync(path.join(this.casesDir, file), 'utf-8');
|
|
77
|
+
const lines = content.split('\n').filter((l) => l.trim());
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
const data = JSON.parse(line);
|
|
80
|
+
const caseName = String(data.case_id ?? path.basename(file, path.extname(file)));
|
|
81
|
+
this.cases.set(caseName, data);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
logger_1.logger.error(`Failed to load case file ${file}: ${e}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
logger_1.logger.info(`Loaded ${this.cases.size} cases from ${this.casesDir}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.CaseManager = CaseManager;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Collect test cases from a data file and convert them to JSON format.
|
|
4
|
+
*
|
|
5
|
+
* Supports JSON array and JSONL (one object per line) inputs. Excel (.xlsx)
|
|
6
|
+
* inputs are not supported without an external spreadsheet library; convert
|
|
7
|
+
* them to CSV/JSON first.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.collectTestCase = collectTestCase;
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const logger_1 = require("./logger");
|
|
47
|
+
/** Default column mapping (matches the original Excel header names). */
|
|
48
|
+
const DEFAULT_COLUMN_MAPPING = {
|
|
49
|
+
caseName: '\u7528\u4f8b_\u540d\u79f0',
|
|
50
|
+
bundleName: '\u7528\u4f8b_APKRelativity',
|
|
51
|
+
appName: '\u5e94\u7528\u540d',
|
|
52
|
+
testSteps: '\u7528\u4f8b_\u6d4b\u8bd5\u6b65\u9aa4',
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Collect test cases from a JSON/JSONL file and write them out as JSON.
|
|
56
|
+
* @param inputFile Path to the input JSON or JSONL file.
|
|
57
|
+
* @param outputFile Path to the output JSON file (default: test_cases.json).
|
|
58
|
+
* @param mapping Column mapping override.
|
|
59
|
+
* @returns The output file path.
|
|
60
|
+
*/
|
|
61
|
+
function collectTestCase(inputFile, outputFile = 'test_cases.json', mapping = DEFAULT_COLUMN_MAPPING) {
|
|
62
|
+
if (!fs.existsSync(inputFile)) {
|
|
63
|
+
throw new Error(`Input file does not exist: ${inputFile}`);
|
|
64
|
+
}
|
|
65
|
+
const records = readRecords(inputFile);
|
|
66
|
+
const testCases = [];
|
|
67
|
+
for (const record of records) {
|
|
68
|
+
const caseName = String(record[mapping.caseName] ?? '');
|
|
69
|
+
const bundleName = String(record[mapping.bundleName] ?? '');
|
|
70
|
+
const appName = String(record[mapping.appName] ?? '');
|
|
71
|
+
const steps = String(record[mapping.testSteps] ?? '');
|
|
72
|
+
if (!caseName && !steps) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
testCases.push({
|
|
76
|
+
caseName,
|
|
77
|
+
bundleName,
|
|
78
|
+
appName,
|
|
79
|
+
testSteps: `Launch ${appName} app, ${steps}`.trim(),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const outputDir = path.dirname(outputFile);
|
|
83
|
+
if (outputDir && !fs.existsSync(outputDir)) {
|
|
84
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
85
|
+
}
|
|
86
|
+
fs.writeFileSync(outputFile, JSON.stringify(testCases, null, 2), 'utf-8');
|
|
87
|
+
logger_1.logger.info(`Successfully processed ${testCases.length} test cases, saved to: ${outputFile}`);
|
|
88
|
+
return outputFile;
|
|
89
|
+
}
|
|
90
|
+
/** Read a JSON array or JSONL file into an array of records. */
|
|
91
|
+
function readRecords(inputFile) {
|
|
92
|
+
const content = stripBom(fs.readFileSync(inputFile, 'utf-8')).trim();
|
|
93
|
+
if (!content) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
const ext = path.extname(inputFile).toLowerCase();
|
|
97
|
+
if (ext === '.json') {
|
|
98
|
+
const parsed = JSON.parse(content);
|
|
99
|
+
if (Array.isArray(parsed)) {
|
|
100
|
+
return parsed;
|
|
101
|
+
}
|
|
102
|
+
if (parsed && typeof parsed === 'object') {
|
|
103
|
+
return [parsed];
|
|
104
|
+
}
|
|
105
|
+
throw new Error('JSON content is not an array or object');
|
|
106
|
+
}
|
|
107
|
+
if (ext === '.jsonl' || ext === '.csv' || ext === '.txt' || ext === '') {
|
|
108
|
+
// JSONL: one object per line
|
|
109
|
+
const records = [];
|
|
110
|
+
for (const line of content.split('\n')) {
|
|
111
|
+
const trimmed = line.trim();
|
|
112
|
+
if (!trimmed)
|
|
113
|
+
continue;
|
|
114
|
+
try {
|
|
115
|
+
records.push(JSON.parse(trimmed));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// skip non-JSON lines
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return records;
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Unsupported input format: ${ext}. Convert Excel files to JSON/JSONL first.`);
|
|
124
|
+
}
|
|
125
|
+
/** Strip a leading UTF-8 BOM if present. */
|
|
126
|
+
function stripBom(text) {
|
|
127
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
128
|
+
}
|
|
@@ -27,4 +27,3 @@ export declare class LLMNotFollowRuleError extends AgentError {
|
|
|
27
27
|
constructor(rawOutput: string, retryCount: number, context?: Record<string, unknown>, userMessage?: string);
|
|
28
28
|
}
|
|
29
29
|
export declare const COMMON_ERRORS_PROMPT = "\u5E38\u89C1\u9519\u8BEF\u63D0\u793A\uFF1A\n1. \u6B7B\u5FAA\u73AF\uFF1AAgent\u53CD\u590D\u6267\u884C\u76F8\u540C\u64CD\u4F5C\uFF0C\u65E0\u6CD5\u53D6\u5F97\u8FDB\u5C55\u3002\u8BF7\u68C0\u67E5\u76EE\u6807\u5143\u7D20\u5B9A\u4F4D\u662F\u5426\u6B63\u786E\uFF0C\u6216\u8C03\u6574\u64CD\u4F5C\u7B56\u7565\u3002\n2. \u5750\u6807\u5B9A\u4F4D\u9519\u8BEF\uFF1A\u70B9\u51FB/\u6ED1\u52A8\u5750\u6807\u504F\u5DEE\u5BFC\u81F4\u64CD\u4F5C\u5931\u8D25\u3002\u8BF7\u91CD\u65B0\u89C2\u5BDF\u622A\u56FE\uFF0C\u786E\u8BA4\u5143\u7D20\u4F4D\u7F6E\u3002\n3. Bug\u5224\u65AD\u9519\u8BEF\uFF1A\u5C06\u6B63\u5E38\u884C\u4E3A\u8BEF\u5224\u4E3ABug\uFF0C\u6216\u5C06Bug\u6F0F\u5224\u3002\u8BF7\u4ED4\u7EC6\u5BF9\u6BD4\u9884\u671F\u7ED3\u679C\u4E0E\u5B9E\u9645\u7ED3\u679C\u3002";
|
|
30
|
-
//# sourceMappingURL=common_errors.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMMON_ERRORS_PROMPT = exports.LLMNotFollowRuleError = exports.AgentError = exports.AgentErrorSuggestedActionsMap = exports.AgentErrorRecoverableMap = void 0;
|
|
4
|
+
exports.AgentErrorRecoverableMap = {
|
|
5
|
+
DEVICE_NOT_CONNECTED: true,
|
|
6
|
+
MCP_SERVICE_TIMEOUT: true,
|
|
7
|
+
CASE_FAILED: false,
|
|
8
|
+
TASK_NOT_FOUND: false,
|
|
9
|
+
CONFIG_VALIDATION_FAILED: true,
|
|
10
|
+
LLM_API_ERROR: true,
|
|
11
|
+
};
|
|
12
|
+
exports.AgentErrorSuggestedActionsMap = {
|
|
13
|
+
DEVICE_NOT_CONNECTED: ['listDevices', 'retry'],
|
|
14
|
+
MCP_SERVICE_TIMEOUT: ['restartMcpService'],
|
|
15
|
+
CASE_FAILED: ['analyzeFailure'],
|
|
16
|
+
TASK_NOT_FOUND: [],
|
|
17
|
+
CONFIG_VALIDATION_FAILED: ['updateConfig'],
|
|
18
|
+
LLM_API_ERROR: ['retry', 'updateConfig'],
|
|
19
|
+
};
|
|
20
|
+
class AgentError extends Error {
|
|
21
|
+
code;
|
|
22
|
+
recoverable;
|
|
23
|
+
suggestedActions;
|
|
24
|
+
context;
|
|
25
|
+
constructor(code, message, options) {
|
|
26
|
+
super(message.length > 500 ? message.slice(0, 500) : message);
|
|
27
|
+
this.name = 'AgentError';
|
|
28
|
+
this.code = code;
|
|
29
|
+
this.recoverable = options?.recoverable ?? exports.AgentErrorRecoverableMap[code];
|
|
30
|
+
this.suggestedActions = options?.suggestedActions ?? exports.AgentErrorSuggestedActionsMap[code];
|
|
31
|
+
this.context = options?.context ?? {};
|
|
32
|
+
}
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
code: this.code,
|
|
36
|
+
message: this.message,
|
|
37
|
+
recoverable: this.recoverable,
|
|
38
|
+
suggestedActions: this.suggestedActions,
|
|
39
|
+
context: this.context,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.AgentError = AgentError;
|
|
44
|
+
class LLMNotFollowRuleError extends AgentError {
|
|
45
|
+
rawOutput;
|
|
46
|
+
rawContent;
|
|
47
|
+
retryCount;
|
|
48
|
+
userMessage;
|
|
49
|
+
constructor(rawOutput, retryCount, context, userMessage) {
|
|
50
|
+
super('LLM_API_ERROR', `LLM输出未遵循规则: 缺少PASS/FAIL判定(重试第${retryCount}次)`, {
|
|
51
|
+
recoverable: true,
|
|
52
|
+
suggestedActions: ['retry'],
|
|
53
|
+
context: { rawOutput, retryCount, ...context },
|
|
54
|
+
});
|
|
55
|
+
this.name = 'LLMNotFollowRuleError';
|
|
56
|
+
this.rawOutput = rawOutput;
|
|
57
|
+
this.rawContent = rawOutput;
|
|
58
|
+
this.retryCount = retryCount;
|
|
59
|
+
this.userMessage = userMessage ?? '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.LLMNotFollowRuleError = LLMNotFollowRuleError;
|
|
63
|
+
exports.COMMON_ERRORS_PROMPT = `常见错误提示:
|
|
64
|
+
1. 死循环:Agent反复执行相同操作,无法取得进展。请检查目标元素定位是否正确,或调整操作策略。
|
|
65
|
+
2. 坐标定位错误:点击/滑动坐标偏差导致操作失败。请重新观察截图,确认元素位置。
|
|
66
|
+
3. Bug判断错误:将正常行为误判为Bug,或将Bug漏判。请仔细对比预期结果与实际结果。`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfig = validateConfig;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
function validateConfig(config) {
|
|
6
|
+
const issues = [];
|
|
7
|
+
const unified = config.model?.unified;
|
|
8
|
+
if (unified && unified.provider === 'openai' && !unified.baseUrl) {
|
|
9
|
+
issues.push({ field: 'model.unified.base_url', message: 'base_url is required when provider is openai' });
|
|
10
|
+
}
|
|
11
|
+
if (unified && unified.provider === 'azure' && !unified.apiVersion) {
|
|
12
|
+
issues.push({ field: 'model.unified.api_version', message: 'api_version is required when provider is azure' });
|
|
13
|
+
}
|
|
14
|
+
const agent = config.agent;
|
|
15
|
+
if (agent) {
|
|
16
|
+
const mode = agent.unified.mode;
|
|
17
|
+
if (mode && !['single', 'hypium', 'layered'].includes(mode)) {
|
|
18
|
+
issues.push({ field: 'agent.unified.mode', message: `Unknown agent mode: ${mode}` });
|
|
19
|
+
}
|
|
20
|
+
if (agent.unified.maxSteps !== undefined && agent.unified.maxSteps < 1) {
|
|
21
|
+
issues.push({ field: 'agent.max_steps', message: 'max_steps must be >= 1' });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (issues.length > 0) {
|
|
25
|
+
logger_1.logger.warning(`Config validation issues found:\n${issues.map((i) => ` ${i.field}: ${i.message}`).join('\n')}`);
|
|
26
|
+
}
|
|
27
|
+
return issues;
|
|
28
|
+
}
|
|
@@ -35,4 +35,3 @@ export declare function resolveModelConfig(config: AppConfig, agentName: string)
|
|
|
35
35
|
* resolve_agent_config until extra_agents support lands.
|
|
36
36
|
*/
|
|
37
37
|
export declare function resolveAgentConfig(config: AppConfig, _agentName: string): AgentConfig;
|
|
38
|
-
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1,257 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ConfigManager = void 0;
|
|
37
|
+
exports.getModel = getModel;
|
|
38
|
+
exports.resolveModelConfig = resolveModelConfig;
|
|
39
|
+
exports.resolveAgentConfig = resolveAgentConfig;
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const yaml = __importStar(require("js-yaml"));
|
|
43
|
+
const types_1 = require("./types");
|
|
44
|
+
const common_errors_1 = require("../../common/common_errors");
|
|
45
|
+
class ConfigManager {
|
|
46
|
+
config;
|
|
47
|
+
loadedConfigFile = null;
|
|
48
|
+
constructor(initial) {
|
|
49
|
+
if (initial) {
|
|
50
|
+
this.config = this.validateWithZod(this.deepMerge(types_1.AppConfigSchema.parse({}), initial));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.config = types_1.AppConfigSchema.parse({});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
loadYamlFile(filePath) {
|
|
57
|
+
const raw = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
58
|
+
const parsed = yaml.load(raw);
|
|
59
|
+
const converted = this.convertKeysToCamel(parsed);
|
|
60
|
+
this.config = this.validateWithZod(this.deepMerge(this.config, converted));
|
|
61
|
+
}
|
|
62
|
+
loadDefaultConfig() {
|
|
63
|
+
const baseDir = path.dirname(__filename);
|
|
64
|
+
const layers = [];
|
|
65
|
+
const defaultConfig = path.join(baseDir, 'config.yaml');
|
|
66
|
+
if ((0, fs_1.existsSync)(defaultConfig)) {
|
|
67
|
+
layers.push(defaultConfig);
|
|
68
|
+
this.loadedConfigFile = defaultConfig;
|
|
69
|
+
}
|
|
70
|
+
const pkgLocalConfig = path.join(baseDir, 'config.local.yaml');
|
|
71
|
+
if ((0, fs_1.existsSync)(pkgLocalConfig)) {
|
|
72
|
+
layers.push(pkgLocalConfig);
|
|
73
|
+
}
|
|
74
|
+
const cwdConfig = path.join(process.cwd(), 'config.yaml');
|
|
75
|
+
if (cwdConfig !== defaultConfig && (0, fs_1.existsSync)(cwdConfig)) {
|
|
76
|
+
layers.push(cwdConfig);
|
|
77
|
+
this.loadedConfigFile = cwdConfig;
|
|
78
|
+
}
|
|
79
|
+
const cwdLocalConfig = path.join(process.cwd(), 'config.local.yaml');
|
|
80
|
+
if ((0, fs_1.existsSync)(cwdLocalConfig)) {
|
|
81
|
+
layers.push(cwdLocalConfig);
|
|
82
|
+
}
|
|
83
|
+
for (const f of layers) {
|
|
84
|
+
try {
|
|
85
|
+
const raw = (0, fs_1.readFileSync)(f, 'utf-8');
|
|
86
|
+
const parsed = yaml.load(raw);
|
|
87
|
+
const converted = this.convertKeysToCamel(parsed);
|
|
88
|
+
this.config = this.validateWithZod(this.deepMerge(this.config, converted));
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.error(`Error loading config file: ${f}: ${e}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (layers.length > 0) {
|
|
95
|
+
console.log(`Loaded config files: ${layers.join(', ')}`);
|
|
96
|
+
}
|
|
97
|
+
// Run validation (aligned with python _validate: catches misconfig early)
|
|
98
|
+
const { validateConfig } = require('./config_validator');
|
|
99
|
+
const issues = validateConfig(this.config);
|
|
100
|
+
if (issues.length > 0) {
|
|
101
|
+
console.warn(`Config validation found ${issues.length} issue(s)`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Layer 4: Load a --config override file (highest priority, aligned with python
|
|
106
|
+
* ConfigManager Layer 4). Merges after loadDefaultConfig, prints loaded file,
|
|
107
|
+
* and validates.
|
|
108
|
+
*/
|
|
109
|
+
loadFileConfig(configFile) {
|
|
110
|
+
if (!(0, fs_1.existsSync)(configFile)) {
|
|
111
|
+
console.warn(`Config file not found: ${configFile}`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const raw = (0, fs_1.readFileSync)(configFile, 'utf-8');
|
|
116
|
+
const parsed = yaml.load(raw);
|
|
117
|
+
const converted = this.convertKeysToCamel(parsed);
|
|
118
|
+
this.config = this.validateWithZod(this.deepMerge(this.config, converted));
|
|
119
|
+
this.loadedConfigFile = configFile;
|
|
120
|
+
console.log(`Loaded config (Layer 4 --config): ${configFile}`);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
console.error(`Error loading --config file: ${configFile}: ${e}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
convertKeysToCamel(obj) {
|
|
127
|
+
if (obj === null || typeof obj !== 'object')
|
|
128
|
+
return obj;
|
|
129
|
+
if (Array.isArray(obj))
|
|
130
|
+
return obj.map((item) => this.convertKeysToCamel(item));
|
|
131
|
+
const result = {};
|
|
132
|
+
for (const key of Object.keys(obj)) {
|
|
133
|
+
const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
134
|
+
result[camelKey] = this.convertKeysToCamel(obj[key]);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
deepMerge(target, source) {
|
|
139
|
+
const result = { ...target };
|
|
140
|
+
for (const key of Object.keys(source)) {
|
|
141
|
+
if (source[key] !== null &&
|
|
142
|
+
source[key] !== undefined &&
|
|
143
|
+
typeof source[key] === 'object' &&
|
|
144
|
+
!Array.isArray(source[key]) &&
|
|
145
|
+
typeof result[key] === 'object' &&
|
|
146
|
+
result[key] !== null &&
|
|
147
|
+
!Array.isArray(result[key])) {
|
|
148
|
+
result[key] = this.deepMerge(result[key], source[key]);
|
|
149
|
+
}
|
|
150
|
+
else if (source[key] !== undefined || source[key] === null) {
|
|
151
|
+
result[key] = source[key];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
validateWithZod(data) {
|
|
157
|
+
// Backward compat: migrate old flat `agent: { mode: ... }` → `agent: { unified: { mode: ... } }`
|
|
158
|
+
// Also handles merged state (deepMerge of old flat + new nested): move stray flat fields into unified.
|
|
159
|
+
const agent = data['agent'];
|
|
160
|
+
if (agent && typeof agent === 'object' && !Array.isArray(agent)) {
|
|
161
|
+
const agentObj = agent;
|
|
162
|
+
const knownFields = [
|
|
163
|
+
'mode', 'maxSteps', 'lang', 'enablePreprocess', 'streamLog', 'debugMode', 'adapterType',
|
|
164
|
+
'actionInterval', 'maxHistoryImage', 'stepEndWaitTime', 'cleanRecentTask', 'systemPrompt',
|
|
165
|
+
'verbose', 'jsonOutput', 'apirec', 'defaultTask', 'promptVersion', 'maxResultRetries',
|
|
166
|
+
'screenshotMaxPixels', 'includePreviousScreenshot', 'previousScreenshotCompressRatio',
|
|
167
|
+
'enableCache', 'parseMode', 'toolProvider', 'promptName', 'role', 'sessionType',
|
|
168
|
+
'maxLoops', 'maxHistoryActions', 'screenshotOnToolEnd', 'minimalInject', 'enableAttributionAnalysis',
|
|
169
|
+
];
|
|
170
|
+
if (!('unified' in agentObj) && !('extraAgents' in agentObj)) {
|
|
171
|
+
// Old flat format — wrap in unified
|
|
172
|
+
data['agent'] = { unified: agentObj, extraAgents: {} };
|
|
173
|
+
}
|
|
174
|
+
else if ('unified' in agentObj) {
|
|
175
|
+
// Merged: stray flat fields from YAML/update mixed alongside unified from default.
|
|
176
|
+
// Move them into unified (overwrite defaults with explicit values).
|
|
177
|
+
const unified = (agentObj['unified'] ?? {});
|
|
178
|
+
for (const field of knownFields) {
|
|
179
|
+
if (field in agentObj) {
|
|
180
|
+
unified[field] = agentObj[field];
|
|
181
|
+
delete agentObj[field];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
agentObj['unified'] = unified;
|
|
185
|
+
if (!('extraAgents' in agentObj))
|
|
186
|
+
agentObj['extraAgents'] = {};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const result = types_1.AppConfigSchema.safeParse(data);
|
|
190
|
+
if (!result.success) {
|
|
191
|
+
throw new common_errors_1.AgentError('CONFIG_VALIDATION_FAILED', result.error.message, {
|
|
192
|
+
recoverable: true,
|
|
193
|
+
suggestedActions: ['updateConfig'],
|
|
194
|
+
context: { validationErrors: result.error.issues },
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return result.data;
|
|
198
|
+
}
|
|
199
|
+
getEffectiveConfig() {
|
|
200
|
+
return { ...this.config };
|
|
201
|
+
}
|
|
202
|
+
updateConfig(partial) {
|
|
203
|
+
this.config = this.validateWithZod(this.deepMerge(this.config, partial));
|
|
204
|
+
return this.getEffectiveConfig();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.ConfigManager = ConfigManager;
|
|
208
|
+
// ---- Per-agent config resolvers (aligned with python ModelGroupConfig.get_model / resolve_model_config) ----
|
|
209
|
+
const MODEL_SLOTS = ['unified', 'execute', 'decision', 'verify', 'reflection', 'analyze'];
|
|
210
|
+
/** A ModelConfig is "configured" if it carries a name/baseUrl/apiKey (not pure defaults). */
|
|
211
|
+
function isModelConfigured(m) {
|
|
212
|
+
return !!m && (!!(m.name) || !!(m.baseUrl) || !!(m.apiKey));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Resolve a model config by agent name with unified fallback.
|
|
216
|
+
* Mirrors python ModelGroupConfig.get_model:
|
|
217
|
+
* 1. direct slot match (unified/execute/decision/verify/reflection/analyze)
|
|
218
|
+
* 2. `_agent` suffix aliasing (e.g. `execute_agent` → `execute` slot)
|
|
219
|
+
* 3. extra_models[name]
|
|
220
|
+
* 4. fallback to `unified`
|
|
221
|
+
*/
|
|
222
|
+
function getModel(group, name) {
|
|
223
|
+
const trySlot = (slot) => {
|
|
224
|
+
if (slot === 'unified')
|
|
225
|
+
return isModelConfigured(group.unified) ? group.unified : undefined;
|
|
226
|
+
const v = group[slot];
|
|
227
|
+
return isModelConfigured(v) ? v : undefined;
|
|
228
|
+
};
|
|
229
|
+
const direct = trySlot(name);
|
|
230
|
+
if (direct)
|
|
231
|
+
return direct;
|
|
232
|
+
if (name.endsWith('_agent')) {
|
|
233
|
+
const base = name.slice(0, -'_agent'.length);
|
|
234
|
+
if (MODEL_SLOTS.includes(base)) {
|
|
235
|
+
const aliased = trySlot(base);
|
|
236
|
+
if (aliased)
|
|
237
|
+
return aliased;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const extra = group.extraModels?.[name];
|
|
241
|
+
if (isModelConfigured(extra))
|
|
242
|
+
return extra;
|
|
243
|
+
return group.unified;
|
|
244
|
+
}
|
|
245
|
+
/** Resolve a model config for an agent name from the app config. */
|
|
246
|
+
function resolveModelConfig(config, agentName) {
|
|
247
|
+
return getModel(config.model, agentName);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Resolve an agent config by name. Node's config.agent is currently a flat
|
|
251
|
+
* AgentConfig (AgentGroupConfig restructure deferred), so this returns the
|
|
252
|
+
* flat config for any name — kept for API parity with python
|
|
253
|
+
* resolve_agent_config until extra_agents support lands.
|
|
254
|
+
*/
|
|
255
|
+
function resolveAgentConfig(config, _agentName) {
|
|
256
|
+
return config.agent.unified;
|
|
257
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.initOutputDir = initOutputDir;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const logger_1 = require("../logger");
|
|
40
|
+
const path_utils_1 = require("../path_utils");
|
|
41
|
+
function initOutputDir(taskName, config) {
|
|
42
|
+
const rootDir = config?.rootDir || path.join((0, path_utils_1.findProjectRoot)(), 'reports');
|
|
43
|
+
const now = new Date();
|
|
44
|
+
const dateStr = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}`;
|
|
45
|
+
const timeStr = `${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`;
|
|
46
|
+
// Aligned with python output.py: <date>/<time>_<task> structure (date as parent dir)
|
|
47
|
+
const sanitizedTask = taskName.replace(/[^a-zA-Z0-9_]/g, '_').slice(0, 50);
|
|
48
|
+
const reportDir = path.join(rootDir, 'web_tasks', dateStr, `${timeStr}_${sanitizedTask}`);
|
|
49
|
+
const screenPath = path.join(reportDir, 'screenPath');
|
|
50
|
+
const layoutDir = path.join(reportDir, 'layout');
|
|
51
|
+
const logDir = path.join(reportDir, 'log');
|
|
52
|
+
for (const dir of [reportDir, screenPath, layoutDir, logDir]) {
|
|
53
|
+
if (!fs.existsSync(dir)) {
|
|
54
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
logger_1.logger.info(`Output directory initialized: ${reportDir}`);
|
|
58
|
+
return { rootDir, reportDir, screenPath, layoutDir, logDir };
|
|
59
|
+
}
|