@autotest/agent 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/.buildstamp +1 -0
- package/dist/api/agent_api.d.ts +2 -2
- package/dist/autotest-cli.js +1 -397
- package/dist/common/config/config.yaml +4 -0
- package/dist/common/config/manager.d.ts +4 -4
- package/dist/common/config/types.d.ts +5 -0
- package/dist/common/dfx/index.d.ts +1 -1
- package/dist/core/agent/single_agent/agent.d.ts +1 -0
- package/dist/core/device/device_protocol.d.ts +1 -1
- package/dist/core/device/hdc/device.d.ts +5 -2
- package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
- package/dist/core/knowledge/vectordb.d.ts +5 -5
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +2 -0
- package/dist/core/mcp/mcp_tools.d.ts +1 -0
- package/dist/core/mcp/verify_tool.d.ts +12 -0
- package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
- package/dist/data_types/device.d.ts +1 -1
- package/dist/data_types/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -163
- package/dist/tools/batch_runner.js +1 -745
- package/dist/tools/case_runner/runner.js +1 -410
- package/dist/tools/config/config_tool.js +1 -339
- package/dist/tools/prompt_compare/compare_runner.js +1 -360
- package/package.json +2 -2
- package/dist/api/agent_api.js +0 -550
- package/dist/api/autotest_agent.js +0 -205
- package/dist/api/types.js +0 -11
- package/dist/common/case_manager.js +0 -91
- package/dist/common/collect_case.js +0 -128
- package/dist/common/common_errors.js +0 -66
- package/dist/common/config/config_validator.js +0 -28
- package/dist/common/config/manager.js +0 -257
- package/dist/common/config/output.js +0 -59
- package/dist/common/config/types.js +0 -185
- package/dist/common/dfx/client_factory.js +0 -62
- package/dist/common/dfx/context.js +0 -23
- package/dist/common/dfx/index.js +0 -15
- package/dist/common/dfx/recorder.js +0 -191
- package/dist/common/dfx/recording_fetch.js +0 -228
- package/dist/common/dfx/source.js +0 -13
- package/dist/common/image_cacher.js +0 -36
- package/dist/common/image_helper.js +0 -128
- package/dist/common/image_similarity.js +0 -171
- package/dist/common/llm_cache/cache_transport.js +0 -102
- package/dist/common/llm_cache/prompt_cache.js +0 -113
- package/dist/common/logger.js +0 -158
- package/dist/common/model/custom_model.js +0 -487
- package/dist/common/model/index.js +0 -5
- package/dist/common/path_utils.js +0 -88
- package/dist/common/result_parser.js +0 -49
- package/dist/common/usage/token_usage.js +0 -117
- package/dist/common/utils.js +0 -125
- package/dist/core/agent/layered_agent/ability_helper.js +0 -125
- package/dist/core/agent/layered_agent/agent.js +0 -37
- package/dist/core/agent/layered_agent/agent_registry.js +0 -82
- package/dist/core/agent/layered_agent/decision.js +0 -518
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
- package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
- package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
- package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
- package/dist/core/agent/report_analyzer_agent/config.js +0 -22
- package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
- package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
- package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
- package/dist/core/agent/report_analyzer_agent/index.js +0 -52
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
- package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
- package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
- package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
- package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
- package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
- package/dist/core/agent/report_analyzer_agent/types.js +0 -274
- package/dist/core/agent/rewrite_agent/agent.js +0 -209
- package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
- package/dist/core/agent/rewrite_agent/mapping.js +0 -56
- package/dist/core/agent/rewrite_agent/parse.js +0 -121
- package/dist/core/agent/rewrite_agent/types.js +0 -37
- package/dist/core/agent/single_agent/agent.js +0 -801
- package/dist/core/agent/single_agent/hook_manager.js +0 -59
- package/dist/core/agent/single_agent/hooks.js +0 -288
- package/dist/core/agent/single_agent/image_utils.js +0 -158
- package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
- package/dist/core/agent/single_agent/subagent_manager.js +0 -72
- package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
- package/dist/core/agent/types.js +0 -2
- package/dist/core/agent/utils/message_builder.js +0 -138
- package/dist/core/device/device_protocol.js +0 -2
- package/dist/core/device/hdc/apps.js +0 -437
- package/dist/core/device/hdc/device.js +0 -219
- package/dist/core/device/hdc/index.js +0 -31
- package/dist/core/device/hdc/input.js +0 -74
- package/dist/core/device/hdc/screenshot.js +0 -171
- package/dist/core/device/index.js +0 -70
- package/dist/core/device/types.js +0 -2
- package/dist/core/knowledge/knowledge_manager.js +0 -70
- package/dist/core/knowledge/vectordb.js +0 -283
- package/dist/core/mcp/adapter_factory.js +0 -99
- package/dist/core/mcp/android_adapter.js +0 -286
- package/dist/core/mcp/base_adapter.js +0 -86
- package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
- package/dist/core/mcp/ios_adapter.js +0 -286
- package/dist/core/mcp/local_tools.js +0 -41
- package/dist/core/mcp/mcp_tools.js +0 -473
- package/dist/core/mcp/types.js +0 -6
- package/dist/core/memory/_utils.js +0 -140
- package/dist/core/memory/compressed_session.js +0 -182
- package/dist/core/memory/context_compressor.js +0 -176
- package/dist/core/memory/index.js +0 -22
- package/dist/core/memory/memory_manager.js +0 -28
- package/dist/core/memory/reflector.js +0 -95
- package/dist/core/memory/replan_manager.js +0 -12
- package/dist/core/memory/session_factory.js +0 -29
- package/dist/core/memory/tool_player.js +0 -225
- package/dist/core/memory/tool_player_popup.js +0 -276
- package/dist/core/memory/tool_player_replan.js +0 -226
- package/dist/core/memory/tool_player_xpath.js +0 -139
- package/dist/core/memory/tool_recorder.js +0 -126
- package/dist/core/preprocessor/task_splitter.js +0 -112
- package/dist/core/prompt/prompt_loader.js +0 -315
- package/dist/core/skill/skill_manager.js +0 -302
- package/dist/data_types/action.js +0 -2
- package/dist/data_types/agent.js +0 -2
- package/dist/data_types/case.js +0 -57
- package/dist/data_types/device.js +0 -2
- package/dist/data_types/index.js +0 -11
- package/dist/data_types/report.js +0 -6
- package/dist/data_types/screen.js +0 -23
- package/dist/data_types/task.js +0 -2
- package/dist/loop/cli.js +0 -127
- package/dist/loop/orchestrator.js +0 -314
- package/dist/loop/result_writer.js +0 -260
- package/dist/loop/types.js +0 -82
- package/dist/mcp-server/server.js +0 -341
- package/dist/mcp-server/types.js +0 -224
- package/dist/reporter/batch_summary.js +0 -197
- package/dist/reporter/generator.js +0 -286
- package/dist/reporter/html_template/index.js +0 -529
- package/dist/reporter/json_report.js +0 -6
- package/dist/reporter/types.js +0 -45
- package/dist/tools/case_runner/report.js +0 -264
|
@@ -1,205 +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 __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.AutoTestAgent = void 0;
|
|
37
|
-
const path = __importStar(require("path"));
|
|
38
|
-
const fs = __importStar(require("fs"));
|
|
39
|
-
const manager_1 = require("../common/config/manager");
|
|
40
|
-
const agent_api_1 = require("./agent_api");
|
|
41
|
-
const adapter_factory_1 = require("../core/mcp/adapter_factory");
|
|
42
|
-
const logger_1 = require("../common/logger");
|
|
43
|
-
class AutoTestAgent {
|
|
44
|
-
api;
|
|
45
|
-
configManager;
|
|
46
|
-
constructor(config) {
|
|
47
|
-
const configManager = new manager_1.ConfigManager();
|
|
48
|
-
if (config.configPath && fs.existsSync(config.configPath)) {
|
|
49
|
-
configManager.loadYamlFile(config.configPath);
|
|
50
|
-
}
|
|
51
|
-
const overrides = {};
|
|
52
|
-
const modelOverrides = {};
|
|
53
|
-
if (config.apiKey)
|
|
54
|
-
modelOverrides.apiKey = config.apiKey;
|
|
55
|
-
if (config.modelName)
|
|
56
|
-
modelOverrides.name = config.modelName;
|
|
57
|
-
if (config.baseUrl)
|
|
58
|
-
modelOverrides.baseUrl = config.baseUrl;
|
|
59
|
-
if (config.provider)
|
|
60
|
-
modelOverrides.provider = config.provider;
|
|
61
|
-
// Layered mode: set execute/decision model slots if provided
|
|
62
|
-
const modelGroup = {};
|
|
63
|
-
if (Object.keys(modelOverrides).length > 0) {
|
|
64
|
-
modelGroup.unified = modelOverrides;
|
|
65
|
-
}
|
|
66
|
-
if (config.executeModel) {
|
|
67
|
-
const exec = {};
|
|
68
|
-
if (config.executeModel.apiKey)
|
|
69
|
-
exec.apiKey = config.executeModel.apiKey;
|
|
70
|
-
if (config.executeModel.modelName)
|
|
71
|
-
exec.name = config.executeModel.modelName;
|
|
72
|
-
if (config.executeModel.baseUrl)
|
|
73
|
-
exec.baseUrl = config.executeModel.baseUrl;
|
|
74
|
-
if (config.executeModel.provider)
|
|
75
|
-
exec.provider = config.executeModel.provider;
|
|
76
|
-
if (config.executeModel.temperature !== undefined)
|
|
77
|
-
exec.temperature = config.executeModel.temperature;
|
|
78
|
-
if (config.executeModel.topP !== undefined)
|
|
79
|
-
exec.topP = config.executeModel.topP;
|
|
80
|
-
if (config.executeModel.maxTokens !== undefined)
|
|
81
|
-
exec.maxTokens = config.executeModel.maxTokens;
|
|
82
|
-
if (Object.keys(exec).length > 0)
|
|
83
|
-
modelGroup.execute = exec;
|
|
84
|
-
}
|
|
85
|
-
if (config.decisionModel) {
|
|
86
|
-
const dec = {};
|
|
87
|
-
if (config.decisionModel.apiKey)
|
|
88
|
-
dec.apiKey = config.decisionModel.apiKey;
|
|
89
|
-
if (config.decisionModel.modelName)
|
|
90
|
-
dec.name = config.decisionModel.modelName;
|
|
91
|
-
if (config.decisionModel.baseUrl)
|
|
92
|
-
dec.baseUrl = config.decisionModel.baseUrl;
|
|
93
|
-
if (config.decisionModel.provider)
|
|
94
|
-
dec.provider = config.decisionModel.provider;
|
|
95
|
-
if (config.decisionModel.temperature !== undefined)
|
|
96
|
-
dec.temperature = config.decisionModel.temperature;
|
|
97
|
-
if (config.decisionModel.topP !== undefined)
|
|
98
|
-
dec.topP = config.decisionModel.topP;
|
|
99
|
-
if (config.decisionModel.maxTokens !== undefined)
|
|
100
|
-
dec.maxTokens = config.decisionModel.maxTokens;
|
|
101
|
-
if (Object.keys(dec).length > 0)
|
|
102
|
-
modelGroup.decision = dec;
|
|
103
|
-
}
|
|
104
|
-
if (Object.keys(modelGroup).length > 0) {
|
|
105
|
-
overrides.model = modelGroup;
|
|
106
|
-
}
|
|
107
|
-
const agentOverrides = {};
|
|
108
|
-
if (config.agentMode)
|
|
109
|
-
agentOverrides.mode = config.agentMode;
|
|
110
|
-
if (config.maxSteps)
|
|
111
|
-
agentOverrides.maxSteps = config.maxSteps;
|
|
112
|
-
if (config.enableCache !== undefined)
|
|
113
|
-
agentOverrides.enableCache = config.enableCache;
|
|
114
|
-
if (Object.keys(agentOverrides).length > 0) {
|
|
115
|
-
overrides.agent = agentOverrides;
|
|
116
|
-
}
|
|
117
|
-
const deviceOverrides = {};
|
|
118
|
-
if (config.deviceSn !== undefined)
|
|
119
|
-
deviceOverrides.deviceSn = config.deviceSn;
|
|
120
|
-
if (config.ip)
|
|
121
|
-
deviceOverrides.ip = config.ip;
|
|
122
|
-
if (config.port)
|
|
123
|
-
deviceOverrides.port = config.port;
|
|
124
|
-
if (Object.keys(deviceOverrides).length > 0) {
|
|
125
|
-
overrides.device = deviceOverrides;
|
|
126
|
-
}
|
|
127
|
-
if (config.reportDir) {
|
|
128
|
-
overrides.output = {
|
|
129
|
-
rootDir: path.isAbsolute(config.reportDir)
|
|
130
|
-
? config.reportDir
|
|
131
|
-
: path.resolve(process.cwd(), config.reportDir),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
if (Object.keys(overrides).length > 0) {
|
|
135
|
-
configManager.updateConfig(overrides);
|
|
136
|
-
}
|
|
137
|
-
if (config.configOverrides) {
|
|
138
|
-
configManager.updateConfig(config.configOverrides);
|
|
139
|
-
}
|
|
140
|
-
const effectiveConfig = configManager.getEffectiveConfig();
|
|
141
|
-
const deviceSn = effectiveConfig.device.deviceSn ?? '';
|
|
142
|
-
let adapter;
|
|
143
|
-
try {
|
|
144
|
-
let platform = config.platform;
|
|
145
|
-
if (!platform) {
|
|
146
|
-
platform = (0, adapter_factory_1.detectDevicePlatform)(deviceSn, {
|
|
147
|
-
ip: effectiveConfig.device.ip,
|
|
148
|
-
port: effectiveConfig.device.port,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
if (platform) {
|
|
152
|
-
adapter = (0, adapter_factory_1.createAdapterFromDeviceInfo)({ platform, deviceSn, ip: effectiveConfig.device.ip, port: effectiveConfig.device.port }, configManager);
|
|
153
|
-
logger_1.logger.info(`Device adapter created: platform=${platform}, sn=${deviceSn || '(auto)'}`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
logger_1.logger.warn(`Device adapter not created: ${e instanceof Error ? e.message : String(e)}`);
|
|
158
|
-
}
|
|
159
|
-
this.configManager = configManager;
|
|
160
|
-
this.api = new agent_api_1.AgentAPIImpl(configManager, adapter);
|
|
161
|
-
}
|
|
162
|
-
async runTask(task, options) {
|
|
163
|
-
const effectiveConfig = this.api.getConfig();
|
|
164
|
-
if (options?.maxSteps) {
|
|
165
|
-
this.api.updateConfig({ agent: { maxSteps: options.maxSteps } });
|
|
166
|
-
}
|
|
167
|
-
if (options?.configOverrides) {
|
|
168
|
-
this.api.updateConfig(options.configOverrides);
|
|
169
|
-
}
|
|
170
|
-
return this.api.runTask(task, {
|
|
171
|
-
agentMode: options?.agentMode ?? effectiveConfig.agent.unified.mode,
|
|
172
|
-
deviceId: options?.deviceSn ?? effectiveConfig.device.deviceSn ?? '',
|
|
173
|
-
platform: options?.platform ?? 'harmony',
|
|
174
|
-
ip: options?.ip,
|
|
175
|
-
port: options?.port,
|
|
176
|
-
reportDir: options?.reportDir,
|
|
177
|
-
taskName: options?.taskName,
|
|
178
|
-
caseNum: options?.caseNum,
|
|
179
|
-
promptVersion: options?.promptVersion,
|
|
180
|
-
runId: options?.runId,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
async listDevices() {
|
|
184
|
-
return this.api.listDevices();
|
|
185
|
-
}
|
|
186
|
-
async getTaskResult(taskId) {
|
|
187
|
-
return this.api.getTaskResult(taskId);
|
|
188
|
-
}
|
|
189
|
-
async analyzeFailure(taskId, caseIdx) {
|
|
190
|
-
return this.api.analyzeFailure(taskId, caseIdx);
|
|
191
|
-
}
|
|
192
|
-
stopTask() {
|
|
193
|
-
this.api.stopTask();
|
|
194
|
-
}
|
|
195
|
-
getConfig() {
|
|
196
|
-
return this.api.getConfig();
|
|
197
|
-
}
|
|
198
|
-
getConfigManager() {
|
|
199
|
-
return this.configManager;
|
|
200
|
-
}
|
|
201
|
-
updateConfig(partial) {
|
|
202
|
-
return this.api.updateConfig(partial);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
exports.AutoTestAgent = AutoTestAgent;
|
package/dist/api/types.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaskStateTransitions = void 0;
|
|
4
|
-
exports.TaskStateTransitions = {
|
|
5
|
-
pending: ['running', 'cancelled'],
|
|
6
|
-
running: ['completed', 'failed', 'cancelled', 'interrupted'],
|
|
7
|
-
completed: [],
|
|
8
|
-
failed: [],
|
|
9
|
-
cancelled: [],
|
|
10
|
-
interrupted: [],
|
|
11
|
-
};
|
|
@@ -1,91 +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 __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;
|
|
@@ -1,128 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
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漏判。请仔细对比预期结果与实际结果。`;
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|