/** * 语句注册表:按类型分发解析与执行到各语句脚本 * 除 fun 外,每种语句对应一个 *-parser.js(types + parse + execute) */ const actionModules = [ require('./delay-parser.js'), require('./set-parser.js'), require('./keyevent-parser.js'), require('./echo-parser.js'), require('./log-parser.js'), require('./random-parser.js'), require('./scroll-parser.js'), require('./swipe-parser.js'), require('./string-press-parser.js'), // 待补充:adb-parser, locate-parser, click-parser, input-parser, ocr-parser, extract-messages-parser, // save-messages-parser, generate-summary-parser, ai-generate-parser, schedule-parser, if-parser, for-parser, // while-parser, read-last-message-parser, read-txt-parser, save-txt-parser, smart-chat-append-parser, // img-bounding-box-location-parser, img-center-point-location-parser, img-cropping-parser, press-parser ] const registry = {} actionModules.forEach(mod => { const types = mod.types ? (Array.isArray(mod.types) ? mod.types : [mod.types]) : [] types.forEach(t => { registry[t] = { parse: mod.parse, execute: mod.execute } }) }) function parseAction(type, action, parseContext) { const entry = registry[type] if (!entry || !entry.parse) return { ...action, type } return entry.parse(action, parseContext) } async function executeAction(type, action, executeContext) { const entry = registry[type] if (!entry || !entry.execute) return { success: false, error: `未知操作类型: ${type}` } return entry.execute(action, executeContext) } module.exports = { registry, parseAction, executeAction }