54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import type { Client } from "basic-ftp";
|
||
import type { Workbook as ExcelJSWorkbook } from "exceljs";
|
||
import { WindowsDriver } from "../driver/windows/windows-driver";
|
||
import type { AutomationDriver } from "../driver/types";
|
||
|
||
/** 人为拟真操作的开关与随机参数(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
|
||
};
|
||
/** 桌面自动化驱动(任务 3.4 注入点,默认 PowerShell 版 WindowsDriver) */
|
||
readonly driver: AutomationDriver = new WindowsDriver();
|
||
}
|
||
|
||
export function createEngine(): RpaEngine {
|
||
return new RpaEngine();
|
||
}
|
||
|
||
/** 能力模块内部使用的默认引擎实例(与全局注册表配套的进程级单例)。 */
|
||
export const defaultEngine = createEngine();
|