chore: rpa-cli 显式注册+engine.execute;V2 现状表同步阶段1修复状态
This commit is contained in:
1 parent
5e8fc9686f
commit
9bb5a44b95
2 files changed
+37
-38
No files matched your search
+14
-15
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* rpa-core CLI host(任务 5.1):Node 直接拉起 createEngine() + WindowsDriver,
|
||||
* 不经过 Electron,验证包的零宿主可运行性。
|
||||
* rpa-core CLI host(任务 5.1;迁移阶段1-T4 重写):
|
||||
* Node/Bun 直接拉起 createEngine(),按需显式注册 5 个能力域(不再副作用全量注册),
|
||||
* 能力调用统一走 engine.execute(ADR-R1 语义真实化),验证包的零宿主可运行性。
|
||||
*
|
||||
* 跑通 5 个代表能力(全部只读或落在临时目录,可重复执行):
|
||||
* 1. 桌面(PowerShell user32):Window_GetActiveWindow —— 读前台窗口标题
|
||||
@@ -17,12 +18,9 @@ import path from "node:path";
|
||||
import {
|
||||
createEngine,
|
||||
capabilityCount,
|
||||
getHandler,
|
||||
registerAll,
|
||||
type CapabilityHandler,
|
||||
type RunContext
|
||||
} from "@rpa/core";
|
||||
import "@rpa/core/capabilities";
|
||||
|
||||
const ctx = {
|
||||
runId: "rpa-cli",
|
||||
@@ -37,26 +35,27 @@ const ctx = {
|
||||
} as unknown as RunContext;
|
||||
const node = (componentId: string) => ({ id: "rpa-cli", componentId, position: { x: 0, y: 0 }, values: {}, options: {} });
|
||||
|
||||
async function run(name: string, handler: CapabilityHandler, args: Record<string, unknown>): Promise<void> {
|
||||
async function run(engine: import("@rpa/core").RpaEngine, name: string, args: Record<string, unknown>): Promise<void> {
|
||||
process.stdout.write(`[${name}] `);
|
||||
const result = await handler(ctx, node(name), args, undefined as never);
|
||||
const result = await engine.execute(name, args, ctx, node(name));
|
||||
console.log("OK ->", typeof result === "string" ? result.slice(0, 120) : JSON.stringify(result)?.slice(0, 200));
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const engine = createEngine();
|
||||
await registerAll(engine);
|
||||
console.log(`rpa-core CLI host:引擎已创建,注册能力 ${capabilityCount()} 个\n`);
|
||||
// 显式注册本 CLI 用到的 5 个能力域(迁移后 Agent-Employee 侧同样按域注册)
|
||||
await registerAll(engine, ["desktop", "commonFinal", "excelCommon", "files", "http"]);
|
||||
console.log(`rpa-core CLI host:引擎已创建(注入 driver 可用 createEngine({ driver })),注册能力 ${capabilityCount()} 个\n`);
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "rpa-cli-"));
|
||||
try {
|
||||
await run("Window_GetActiveWindow", getHandler("Window_GetActiveWindow")!, {});
|
||||
await run("Window_GetScreenSize", getHandler("Window_GetScreenSize")!, {});
|
||||
await run("Excel_Cs_NewV5", getHandler("Excel_Cs_NewV5")!, { filePath: tmpDir, name: "rpa-cli-demo.xlsx" });
|
||||
await run(engine, "Window_GetActiveWindow", {});
|
||||
await run(engine, "Window_GetScreenSize", {});
|
||||
await run(engine, "Excel_Cs_NewV5", { filePath: tmpDir, name: "rpa-cli-demo.xlsx" });
|
||||
const file = path.join(tmpDir, "hello.txt");
|
||||
await run("File_Write", getHandler("File_Write")!, { path: file, content: "hello from rpa-core CLI" });
|
||||
await run("File_Read", getHandler("File_Read")!, { path: file });
|
||||
await run("Http_Get", getHandler("Http_Get")!, { url: "https://www.baidu.com", timeout: 15 });
|
||||
await run(engine, "File_Write", { path: file, content: "hello from rpa-core CLI" });
|
||||
await run(engine, "File_Read", { path: file });
|
||||
await run(engine, "Http_Get", { url: "https://www.baidu.com", timeout: 15 });
|
||||
console.log("\n5 项代表能力全部通过 ✓");
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
|
||||
Reference in new issue
Block a user