@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,126 @@
|
|
|
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.ToolRecorder = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const logger_1 = require("../../common/logger");
|
|
40
|
+
class ToolRecorder {
|
|
41
|
+
_records = [];
|
|
42
|
+
_taskId;
|
|
43
|
+
_storageDir;
|
|
44
|
+
_order = 0;
|
|
45
|
+
constructor(taskId, storageDir) {
|
|
46
|
+
this._taskId = taskId;
|
|
47
|
+
this._storageDir = storageDir ?? path.join(process.cwd(), 'reports', 'tool_recordings');
|
|
48
|
+
if (!fs.existsSync(this._storageDir)) {
|
|
49
|
+
fs.mkdirSync(this._storageDir, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_taskHash() {
|
|
53
|
+
const c = require('crypto');
|
|
54
|
+
return c.createHash('md5').update(this._taskId).digest('hex');
|
|
55
|
+
}
|
|
56
|
+
record(toolName, args, result, success, stepNumber, clickCache) {
|
|
57
|
+
const record = {
|
|
58
|
+
order: this._order++,
|
|
59
|
+
toolName,
|
|
60
|
+
arguments: args,
|
|
61
|
+
result: result.slice(0, 500),
|
|
62
|
+
success,
|
|
63
|
+
timestamp: new Date().toISOString(),
|
|
64
|
+
stepNumber,
|
|
65
|
+
...(clickCache ? { clickCache } : {}),
|
|
66
|
+
};
|
|
67
|
+
this._records.push(record);
|
|
68
|
+
logger_1.logger.debug(`[ToolRecorder] Recorded: ${toolName} (step ${stepNumber}, success=${success})`);
|
|
69
|
+
}
|
|
70
|
+
save() {
|
|
71
|
+
const filePath = path.join(this._storageDir, `${this._taskId}.json`);
|
|
72
|
+
const session = {
|
|
73
|
+
task: this._taskId,
|
|
74
|
+
taskHash: this._taskHash(),
|
|
75
|
+
totalCalls: this._records.length,
|
|
76
|
+
records: this._records,
|
|
77
|
+
createdAt: new Date().toISOString(),
|
|
78
|
+
};
|
|
79
|
+
fs.writeFileSync(filePath, JSON.stringify(session, null, 2), 'utf-8');
|
|
80
|
+
logger_1.logger.info(`[ToolRecorder] Saved ${this._records.length} records to ${filePath}`);
|
|
81
|
+
return filePath;
|
|
82
|
+
}
|
|
83
|
+
static loadFromFile(filePath) {
|
|
84
|
+
try {
|
|
85
|
+
const data = fs.readFileSync(filePath, 'utf-8');
|
|
86
|
+
return JSON.parse(data);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
static loadByTask(taskId, storageDir) {
|
|
93
|
+
const dir = storageDir ?? path.join(process.cwd(), 'reports', 'tool_recordings');
|
|
94
|
+
const filePath = path.join(dir, `${taskId}.json`);
|
|
95
|
+
return ToolRecorder.loadFromFile(filePath);
|
|
96
|
+
}
|
|
97
|
+
static findRecording(identifier, storageDir) {
|
|
98
|
+
// Look up by task id (filename) first, then by md5 hash match.
|
|
99
|
+
const byId = ToolRecorder.loadByTask(identifier, storageDir);
|
|
100
|
+
if (byId)
|
|
101
|
+
return byId;
|
|
102
|
+
const dir = storageDir ?? path.join(process.cwd(), 'reports', 'tool_recordings');
|
|
103
|
+
const c = require('crypto');
|
|
104
|
+
const hash = c.createHash('md5').update(identifier).digest('hex');
|
|
105
|
+
try {
|
|
106
|
+
for (const f of fs.readdirSync(dir)) {
|
|
107
|
+
if (!f.endsWith('.json'))
|
|
108
|
+
continue;
|
|
109
|
+
const s = ToolRecorder.loadFromFile(path.join(dir, f));
|
|
110
|
+
if (s && (s.task === identifier || s.taskHash === hash))
|
|
111
|
+
return s;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// ignore
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
get records() {
|
|
120
|
+
return this._records;
|
|
121
|
+
}
|
|
122
|
+
get recordCount() {
|
|
123
|
+
return this._records.length;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.ToolRecorder = ToolRecorder;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskSplitter = void 0;
|
|
4
|
+
exports.stepToText = stepToText;
|
|
5
|
+
exports.taskSplitResultToText = taskSplitResultToText;
|
|
6
|
+
const logger_1 = require("../../common/logger");
|
|
7
|
+
const common_errors_1 = require("../../common/common_errors");
|
|
8
|
+
const custom_model_1 = require("../../common/model/custom_model");
|
|
9
|
+
const prompt_loader_1 = require("../prompt/prompt_loader");
|
|
10
|
+
function stepToText(step) {
|
|
11
|
+
return `${step.stepId}. ${step.description}(expected:${step.expectedResult})`;
|
|
12
|
+
}
|
|
13
|
+
function taskSplitResultToText(result) {
|
|
14
|
+
return result.steps.map((s) => `${s.stepId}. ${s.description}(expected:${s.expectedResult})`).join('\n');
|
|
15
|
+
}
|
|
16
|
+
const DEFAULT_SYSTEM_PROMPT = 'You are a test task splitting expert. Split the user task into a sequence of ' +
|
|
17
|
+
'clear, reasonable steps. Output ONLY the step list in this exact format, nothing else:\n' +
|
|
18
|
+
'1. [step description](expected:[expected result])\n' +
|
|
19
|
+
'2. [step description](expected:[expected result])\n' +
|
|
20
|
+
'Rules: continuous numeric numbering, one independent action per step, ' +
|
|
21
|
+
'expected results must be verifiable and specific.';
|
|
22
|
+
class TaskSplitter {
|
|
23
|
+
modelConfig;
|
|
24
|
+
llmCaller;
|
|
25
|
+
systemPrompt;
|
|
26
|
+
constructor(modelConfig, llmCaller) {
|
|
27
|
+
this.modelConfig = modelConfig;
|
|
28
|
+
this.llmCaller = llmCaller ?? new custom_model_1.LLMCaller();
|
|
29
|
+
this.systemPrompt = this.loadSystemPrompt();
|
|
30
|
+
}
|
|
31
|
+
async splitTask(task) {
|
|
32
|
+
logger_1.logger.info(`TaskSplitter.splitTask: splitting task "${task}"`);
|
|
33
|
+
const userPrompt = `Please split the following task into steps:\n\n${task}`;
|
|
34
|
+
let llmResult;
|
|
35
|
+
try {
|
|
36
|
+
llmResult = await this.llmCaller.call({
|
|
37
|
+
systemPrompt: this.systemPrompt,
|
|
38
|
+
userPrompt,
|
|
39
|
+
modelConfig: this.modelConfig,
|
|
40
|
+
extraBody: { enable_thinking: false },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e instanceof common_errors_1.AgentError)
|
|
45
|
+
throw e;
|
|
46
|
+
throw new common_errors_1.AgentError('LLM_API_ERROR', `Task split LLM call failed: ${e}`);
|
|
47
|
+
}
|
|
48
|
+
const text = llmResult.text;
|
|
49
|
+
if (!text) {
|
|
50
|
+
throw new common_errors_1.AgentError('LLM_API_ERROR', 'Model returned empty content for task split');
|
|
51
|
+
}
|
|
52
|
+
logger_1.logger.debug(`TaskSplitter: model response:\n${text}`);
|
|
53
|
+
if (llmResult.tokenUsage) {
|
|
54
|
+
logger_1.logger.info(`[Preprocess] Token Usage: Input=${llmResult.tokenUsage.inputTokens}, ` +
|
|
55
|
+
`Output=${llmResult.tokenUsage.outputTokens}, ` +
|
|
56
|
+
`Total=${llmResult.tokenUsage.totalTokens}`);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const steps = this.parseSteps(text);
|
|
60
|
+
return {
|
|
61
|
+
originalTask: task,
|
|
62
|
+
steps,
|
|
63
|
+
tokenUsage: llmResult.tokenUsage ?? null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
logger_1.logger.error(`TaskSplitter: parse failed: ${e}\nRaw output:\n${text}`);
|
|
68
|
+
throw new common_errors_1.AgentError('LLM_API_ERROR', `Failed to parse model output for task split: ${e}`, { context: { rawOutput: text } });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
loadSystemPrompt() {
|
|
72
|
+
try {
|
|
73
|
+
return (0, prompt_loader_1.load)(prompt_loader_1.PromptCategory.SPLITTER, undefined, true);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return DEFAULT_SYSTEM_PROMPT;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
parseSteps(text) {
|
|
80
|
+
const steps = [];
|
|
81
|
+
const pattern = /(\d+)\.\s*(.+?)\(([^::]+)[::]\s*(.+?)\)/g;
|
|
82
|
+
let match;
|
|
83
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
84
|
+
const stepId = parseInt(match[1], 10);
|
|
85
|
+
const description = match[2].trim();
|
|
86
|
+
const expectedResult = match[4].trim().replace(/\)\s*$/, '');
|
|
87
|
+
if (description && expectedResult) {
|
|
88
|
+
steps.push({ stepId, description, expectedResult });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (steps.length === 0) {
|
|
92
|
+
const fallback = /(\d+)\.\s*(.+)/g;
|
|
93
|
+
let fallbackMatch;
|
|
94
|
+
while ((fallbackMatch = fallback.exec(text)) !== null) {
|
|
95
|
+
const stepId = parseInt(fallbackMatch[1], 10);
|
|
96
|
+
const description = fallbackMatch[2].trim();
|
|
97
|
+
if (description) {
|
|
98
|
+
steps.push({
|
|
99
|
+
stepId,
|
|
100
|
+
description,
|
|
101
|
+
expectedResult: 'Operation completed successfully',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (steps.length === 0) {
|
|
107
|
+
throw new Error('No valid step format found in model output');
|
|
108
|
+
}
|
|
109
|
+
return steps;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.TaskSplitter = TaskSplitter;
|
|
@@ -21,4 +21,3 @@ export declare function registerScanPaths(paths: string[]): void;
|
|
|
21
21
|
/** Return the registered extra scan directories. */
|
|
22
22
|
export declare function getScanDirs(): string[];
|
|
23
23
|
export declare function loadByName(name: string, keepHeaders?: boolean): string | null;
|
|
24
|
-
//# sourceMappingURL=prompt_loader.d.ts.map
|
|
@@ -0,0 +1,313 @@
|
|
|
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.DEFAULT_VERSIONS = exports.PromptCategory = void 0;
|
|
37
|
+
exports.clearCache = clearCache;
|
|
38
|
+
exports.getAvailableVersions = getAvailableVersions;
|
|
39
|
+
exports.load = load;
|
|
40
|
+
exports.getPromptVersions = getPromptVersions;
|
|
41
|
+
exports.listAllPrompts = listAllPrompts;
|
|
42
|
+
exports.registerScanPaths = registerScanPaths;
|
|
43
|
+
exports.getScanDirs = getScanDirs;
|
|
44
|
+
exports.loadByName = loadByName;
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const path_utils_1 = require("../../common/path_utils");
|
|
48
|
+
const logger_1 = require("../../common/logger");
|
|
49
|
+
var PromptCategory;
|
|
50
|
+
(function (PromptCategory) {
|
|
51
|
+
PromptCategory["SINGLE"] = "single";
|
|
52
|
+
PromptCategory["HYPIUM"] = "hypium";
|
|
53
|
+
PromptCategory["PLANNER"] = "planner";
|
|
54
|
+
PromptCategory["SPLITTER"] = "splitter";
|
|
55
|
+
PromptCategory["FAST_ACTION"] = "fast_action";
|
|
56
|
+
PromptCategory["EXECUTOR"] = "executor";
|
|
57
|
+
})(PromptCategory || (exports.PromptCategory = PromptCategory = {}));
|
|
58
|
+
exports.DEFAULT_VERSIONS = {
|
|
59
|
+
[PromptCategory.SINGLE]: 'v2.0',
|
|
60
|
+
[PromptCategory.HYPIUM]: 'v2.0',
|
|
61
|
+
[PromptCategory.PLANNER]: 'v2.0',
|
|
62
|
+
[PromptCategory.SPLITTER]: 'v1.0',
|
|
63
|
+
[PromptCategory.FAST_ACTION]: 'v1.0',
|
|
64
|
+
[PromptCategory.EXECUTOR]: 'v1.0',
|
|
65
|
+
};
|
|
66
|
+
const TEMPLATES_DIR = path.join((0, path_utils_1.findDistRoot)(), 'core', 'prompt', 'templates');
|
|
67
|
+
const _cache = new Map();
|
|
68
|
+
function clearCache() {
|
|
69
|
+
_cache.clear();
|
|
70
|
+
}
|
|
71
|
+
function _getPrefix(category) {
|
|
72
|
+
switch (category) {
|
|
73
|
+
case PromptCategory.SINGLE:
|
|
74
|
+
return 'single';
|
|
75
|
+
case PromptCategory.HYPIUM:
|
|
76
|
+
return 'hypium';
|
|
77
|
+
case PromptCategory.PLANNER:
|
|
78
|
+
return 'planner';
|
|
79
|
+
case PromptCategory.SPLITTER:
|
|
80
|
+
return 'task_splitter';
|
|
81
|
+
case PromptCategory.FAST_ACTION:
|
|
82
|
+
return 'fast_action';
|
|
83
|
+
default:
|
|
84
|
+
return category;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function _parseVersionFromFilename(filename, prefix) {
|
|
88
|
+
const pattern = new RegExp(`^${prefix}_([v]?[\\d.]+(?:-[a-zA-Z]+)?)\\.md$`);
|
|
89
|
+
const match = filename.match(pattern);
|
|
90
|
+
if (match) {
|
|
91
|
+
let version = match[1];
|
|
92
|
+
if (!version.startsWith('v')) {
|
|
93
|
+
version = 'v' + version;
|
|
94
|
+
}
|
|
95
|
+
return version;
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
function _getCategoryDir(category) {
|
|
100
|
+
return path.join(TEMPLATES_DIR, category);
|
|
101
|
+
}
|
|
102
|
+
function getAvailableVersions(category) {
|
|
103
|
+
const catDir = _getCategoryDir(category);
|
|
104
|
+
if (!fs.existsSync(catDir)) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
const prefix = _getPrefix(category);
|
|
108
|
+
const versions = [];
|
|
109
|
+
const files = fs.readdirSync(catDir);
|
|
110
|
+
for (const file of files) {
|
|
111
|
+
if (file.startsWith(prefix) && file.endsWith('.md')) {
|
|
112
|
+
const version = _parseVersionFromFilename(file, prefix);
|
|
113
|
+
if (version) {
|
|
114
|
+
versions.push(version);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return versions.sort((a, b) => b.localeCompare(a));
|
|
119
|
+
}
|
|
120
|
+
function _getPromptPath(category, version) {
|
|
121
|
+
if (!version.startsWith('v')) {
|
|
122
|
+
version = 'v' + version;
|
|
123
|
+
}
|
|
124
|
+
const catDir = _getCategoryDir(category);
|
|
125
|
+
if (!fs.existsSync(catDir)) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const prefix = _getPrefix(category);
|
|
129
|
+
const files = fs.readdirSync(catDir);
|
|
130
|
+
for (const file of files) {
|
|
131
|
+
if (file.startsWith(prefix) && file.endsWith('.md')) {
|
|
132
|
+
const fileVersion = _parseVersionFromFilename(file, prefix);
|
|
133
|
+
if (fileVersion === version) {
|
|
134
|
+
return path.join(catDir, file);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function _cleanMarkdownLine(line, keepHeaders) {
|
|
141
|
+
if (line.startsWith('```')) {
|
|
142
|
+
return '';
|
|
143
|
+
}
|
|
144
|
+
if (keepHeaders) {
|
|
145
|
+
return line;
|
|
146
|
+
}
|
|
147
|
+
if (line.startsWith('### ')) {
|
|
148
|
+
return line.slice(4);
|
|
149
|
+
}
|
|
150
|
+
if (line.startsWith('## ')) {
|
|
151
|
+
return line.slice(3);
|
|
152
|
+
}
|
|
153
|
+
if (line.startsWith('# ')) {
|
|
154
|
+
return line.slice(2);
|
|
155
|
+
}
|
|
156
|
+
return line;
|
|
157
|
+
}
|
|
158
|
+
function _extractPromptContent(mdContent, keepHeaders) {
|
|
159
|
+
const lines = mdContent.split('\n');
|
|
160
|
+
const resultLines = [];
|
|
161
|
+
let skipMeta = true;
|
|
162
|
+
for (const line of lines) {
|
|
163
|
+
if (skipMeta) {
|
|
164
|
+
if (line.startsWith('##') || line.trim() === '---') {
|
|
165
|
+
skipMeta = false;
|
|
166
|
+
}
|
|
167
|
+
if (line.startsWith('>') || line.startsWith('# ') || !line.trim()) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!skipMeta) {
|
|
172
|
+
const cleanedLine = _cleanMarkdownLine(line, keepHeaders);
|
|
173
|
+
resultLines.push(cleanedLine);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return resultLines.join('\n').trim();
|
|
177
|
+
}
|
|
178
|
+
function load(category, version, keepHeaders = true) {
|
|
179
|
+
let targetVersion = version ?? exports.DEFAULT_VERSIONS[category] ?? 'v1.0';
|
|
180
|
+
if (!targetVersion.startsWith('v')) {
|
|
181
|
+
targetVersion = 'v' + targetVersion;
|
|
182
|
+
}
|
|
183
|
+
const cacheKey = `${category}:${targetVersion}_headers_${keepHeaders}`;
|
|
184
|
+
if (_cache.has(cacheKey)) {
|
|
185
|
+
return _cache.get(cacheKey);
|
|
186
|
+
}
|
|
187
|
+
const promptPath = _getPromptPath(category, targetVersion);
|
|
188
|
+
if (!promptPath) {
|
|
189
|
+
const available = getAvailableVersions(category);
|
|
190
|
+
throw new Error(`Prompt version '${targetVersion}' not found for ${category}. Available versions: ${available.join(', ')}`);
|
|
191
|
+
}
|
|
192
|
+
const content = fs.readFileSync(promptPath, 'utf-8');
|
|
193
|
+
const promptText = _extractPromptContent(content, keepHeaders);
|
|
194
|
+
_cache.set(cacheKey, promptText);
|
|
195
|
+
return promptText;
|
|
196
|
+
}
|
|
197
|
+
function _getVersionInfo(category, version) {
|
|
198
|
+
if (!version.startsWith('v')) {
|
|
199
|
+
version = 'v' + version;
|
|
200
|
+
}
|
|
201
|
+
const promptPath = _getPromptPath(category, version);
|
|
202
|
+
if (!promptPath) {
|
|
203
|
+
return { version, date: '', description: 'Not found' };
|
|
204
|
+
}
|
|
205
|
+
const content = fs.readFileSync(promptPath, 'utf-8');
|
|
206
|
+
const info = {
|
|
207
|
+
version,
|
|
208
|
+
date: '',
|
|
209
|
+
description: '',
|
|
210
|
+
};
|
|
211
|
+
for (const line of content.split('\n')) {
|
|
212
|
+
if (line.startsWith('> 版本:')) {
|
|
213
|
+
info.version = line.split(':').slice(1).join(':').trim();
|
|
214
|
+
}
|
|
215
|
+
else if (line.startsWith('> 更新日期:')) {
|
|
216
|
+
info.date = line.split(':').slice(1).join(':').trim();
|
|
217
|
+
}
|
|
218
|
+
else if (line.startsWith('> 描述:')) {
|
|
219
|
+
info.description = line.split(':').slice(1).join(':').trim();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return info;
|
|
223
|
+
}
|
|
224
|
+
function getPromptVersions(category) {
|
|
225
|
+
return getAvailableVersions(category);
|
|
226
|
+
}
|
|
227
|
+
function listAllPrompts(category) {
|
|
228
|
+
const versions = getAvailableVersions(category);
|
|
229
|
+
return versions.map((v) => _getVersionInfo(category, v));
|
|
230
|
+
}
|
|
231
|
+
const _extraScanPaths = [];
|
|
232
|
+
/** Register extra directories to scan for prompts (aligned with python register_scan_paths). */
|
|
233
|
+
function registerScanPaths(paths) {
|
|
234
|
+
for (const p of paths) {
|
|
235
|
+
if (!p)
|
|
236
|
+
continue;
|
|
237
|
+
const abs = path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);
|
|
238
|
+
if (!_extraScanPaths.includes(abs))
|
|
239
|
+
_extraScanPaths.push(abs);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** Return the registered extra scan directories. */
|
|
243
|
+
function getScanDirs() {
|
|
244
|
+
return [..._extraScanPaths];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Find a prompt by filename, searching extra scan paths (recursive, highest
|
|
248
|
+
* priority) before the built-in templates dir. Aligned with python
|
|
249
|
+
* _find_prompt_by_name. Returns raw file content or null.
|
|
250
|
+
*/
|
|
251
|
+
function _findPromptByName(name) {
|
|
252
|
+
const target = name.replace(/\.md$/i, '');
|
|
253
|
+
const tryFile = (filePath) => {
|
|
254
|
+
try {
|
|
255
|
+
const baseName = path.basename(filePath, '.md');
|
|
256
|
+
if (baseName === target || path.basename(filePath) === name) {
|
|
257
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
// ignore unreadable
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
};
|
|
265
|
+
const scanDir = (dir) => {
|
|
266
|
+
try {
|
|
267
|
+
const entries = fs.readdirSync(dir, { recursive: true });
|
|
268
|
+
for (const entry of entries) {
|
|
269
|
+
if (!entry.endsWith('.md'))
|
|
270
|
+
continue;
|
|
271
|
+
const full = path.isAbsolute(entry) ? entry : path.join(dir, entry);
|
|
272
|
+
const hit = tryFile(full);
|
|
273
|
+
if (hit)
|
|
274
|
+
return hit;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
// ignore unreadable dir
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
};
|
|
282
|
+
// Aligned with python: built-in templates first, then extra scan paths
|
|
283
|
+
// 1. built-in templates (recursive)
|
|
284
|
+
const hit1 = scanDir(TEMPLATES_DIR);
|
|
285
|
+
if (hit1)
|
|
286
|
+
return hit1;
|
|
287
|
+
// 2. extra scan paths
|
|
288
|
+
for (const dir of _extraScanPaths) {
|
|
289
|
+
const hit = scanDir(dir);
|
|
290
|
+
if (hit)
|
|
291
|
+
return hit;
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
function loadByName(name, keepHeaders = true) {
|
|
296
|
+
// 1. category/version match (e.g. single_v2.0)
|
|
297
|
+
const categories = Object.values(PromptCategory);
|
|
298
|
+
for (const category of categories) {
|
|
299
|
+
const prefix = _getPrefix(category);
|
|
300
|
+
const versions = getAvailableVersions(category);
|
|
301
|
+
for (const v of versions) {
|
|
302
|
+
if (`${prefix}_${v}` === name || `${prefix}_${v}.md` === name) {
|
|
303
|
+
return load(category, v);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// 2. priority filename search (extra scan paths > built-in templates)
|
|
308
|
+
const content = _findPromptByName(name);
|
|
309
|
+
if (content)
|
|
310
|
+
return _extractPromptContent(content, keepHeaders);
|
|
311
|
+
logger_1.logger.warn(`Prompt not found by name: ${name}`);
|
|
312
|
+
return null;
|
|
313
|
+
}
|