mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 18:35:48 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
45
runtime/hooks/ts_hook_runner.ts
Normal file
45
runtime/hooks/ts_hook_runner.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Invoked as: npx --yes tsx ts_hook_runner.ts <absolute-handler.ts> [exportName]
|
||||
* stdin: JSON { type, action, sessionKey, context, messages?, timestamp? }
|
||||
* stdout: JSON { "context"?: object } merged into the hook event in Python
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const handlerPath = process.argv[2];
|
||||
const exportName = (process.argv[3] || "default").trim();
|
||||
|
||||
if (!handlerPath) {
|
||||
console.error("oclaw: ts_hook_runner: missing handler path");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const raw = readFileSync(0, "utf-8");
|
||||
const data = JSON.parse(raw) as Record<string, unknown>;
|
||||
const event = {
|
||||
type: data.type,
|
||||
action: data.action,
|
||||
sessionKey: data.sessionKey,
|
||||
context: (typeof data.context === "object" && data.context) ? (data.context as Record<string, unknown>) : {},
|
||||
messages: Array.isArray(data.messages) ? data.messages : [],
|
||||
timestamp: data.timestamp,
|
||||
};
|
||||
|
||||
const mod: Record<string, unknown> = (await import(pathToFileURL(handlerPath).href)) as Record<string, unknown>;
|
||||
let fn: ((ev: unknown) => unknown) | undefined;
|
||||
if (exportName && exportName !== "default" && mod[exportName] && typeof mod[exportName] === "function") {
|
||||
fn = mod[exportName] as (ev: unknown) => unknown;
|
||||
} else {
|
||||
fn = (mod.default ?? mod.handle ?? mod.handler) as (ev: unknown) => unknown;
|
||||
}
|
||||
if (typeof fn !== "function") {
|
||||
console.error("oclaw: ts_hook_runner: no function export in", handlerPath, "export", exportName);
|
||||
process.exit(3);
|
||||
}
|
||||
const r = fn(event);
|
||||
if (r && typeof (r as { then?: unknown }).then === "function") {
|
||||
await (r as Promise<unknown>);
|
||||
}
|
||||
process.stdout.write(
|
||||
JSON.stringify({ context: event.context }, (_k, v) => (typeof v === "bigint" ? v.toString() : v), 0),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue