阶段1-rpa-core建包: engine+31个纯Node能力迁入packages/rpa-core, 领域类型单一源化, createEngine工厂收拢模块级状态

- engine/(registry/types/runtime/expression)物理迁入包, 解耦shared/types(域类型归包, 宿主type-only re-export)
- 31个纯Node能力+27个测试迁入包; 宿主留守Electron/浏览器/AI依赖能力, index.ts经@rpa/core/capabilities拉起
- 新增createEngine()/defaultEngine: excel缓存/Excel句柄/db连接/FTP客户端/OCR实例/拟真设置挂引擎实例
- remaining-core子流程依赖改为host-bridge注入, 包内不再import宿主flows
- 宿主main/index.ts启动时注入子流程源; electron-vite/vitest/tsconfig配@rpa/core源码别名
- 验证: typecheck绿, 快照909个id diff为零, 332测试过(2个桌面冒烟因会话无交互SetForegroundWindow被拒, 环境阻塞)
This commit is contained in:
yu authored and trae-solo-agent committed 2026-11-04 12:36:03 +08:00
1 parent 4139400dbd
commit caa8e19332
111 files changed
+581 -337

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
import type { Client } from "basic-ftp";
import type { Workbook as ExcelJSWorkbook } from "exceljs";
/** 人为拟真操作的开关与随机参数(desktop 能力的进程级设置)。 */
export interface ManualOperationSettings {
enabled: boolean;
randomMove: boolean;
randomClick: boolean;
randomSleep: boolean;
minMs: number;
maxMs: number;
}
/**
* 引擎实例状态容器(任务 1.3,R4:模块级全局状态收拢)。
*
* 折中方案(决策记录 2026-11-04):能力文件的 register() 调用与全局注册表保持不变,
* 但 Excel 缓存、数据库连接、FTP 客户端等进程级可变状态统一挂到引擎实例上。
* 包内各能力模块通过 defaultEngine 访问;宿主/CLI 可用 createEngine() 产生隔离实例,
* 或拿到 defaultEngine 做测试间重置。
*/
export class RpaEngine {
/** excel-store:路径 → ExcelJS 工作簿共享缓存 */
readonly excelCache = new Map<string, ExcelJSWorkbook>();
/** office.ts:Excel 句柄 id → 工作簿 */
readonly excelHandles = new Map<string, ExcelJSWorkbook>();
/** remaining-core:连接 id → 数据库连接(mysql2/pg/mssql) */
readonly dbConnections = new Map<string, unknown>();
/** ftp.ts:当前 FTP 连接 */
ftpClient?: Client;
/** ocr-caps.ts:懒加载的 OCR 实例 */
ocrInstance?: unknown;
/** desktop.ts:人为拟真操作设置 */
manualOperation: ManualOperationSettings = {
enabled: false,
randomMove: true,
randomClick: true,
randomSleep: true,
minMs: 1000,
maxMs: 3000
};
}
export function createEngine(): RpaEngine {
return new RpaEngine();
}
/** 能力模块内部使用的默认引擎实例(与全局注册表配套的进程级单例)。 */
export const defaultEngine = createEngine();