ai-chatbot/lib/ai/zcode-agent/native-runtime.ts

19 lines
920 B
TypeScript

import "server-only";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import type { runNativeZcode as NativeRun } from "@/services/zcode-agent/runner.mjs";
/** Load the installed host adapter outside Next's filesystem tracer. Task state
* and native session trees are runtime data, never web build input assets. */
export const runNativeZcode: typeof NativeRun = async options => {
const root = process.env.CANVAS_ZCODE_RUNTIME_DIR || "/opt/yedir-canvas-zcode/current";
const url = pathToFileURL(join(/* turbopackIgnore: true */ root, "host/runner.mjs")).href;
let module: { runNativeZcode: typeof NativeRun };
try {
module = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ url);
} catch {
throw new Error("原生 ZCode 运行环境尚未正确安装,未启动任务。禁止在宿主直接执行。");
}
return module.runNativeZcode(options);
};