stage-dev-cua-plugin-runtime.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { existsSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { isRealComputerUseProducerInstalled } from "../packages/desktop/scripts/computer-use-producer.mjs";
  4. import { stageSharpIntoBundledAgents } from "../packages/desktop/scripts/sharp-package-assets.mjs";
  5. const repositoryRoot = resolve(import.meta.dirname, "..");
  6. export function stageDevCuaPluginRuntime({
  7. env = process.env,
  8. platform = process.platform,
  9. arch = process.arch,
  10. desktopPackageRoot = resolve(repositoryRoot, "packages", "desktop"),
  11. pluginRoot = resolve(repositoryRoot, "apps", "zcode-cli", "packages", "zcode-cua-plugin"),
  12. } = {}) {
  13. if (env.ZCODE_CUA_DEV_MODE !== "1") return [];
  14. // 开源占位包不提供 Computer Use 原生能力,也不随附 Sharp:没有真实 producer 时不暂存。
  15. if (!isRealComputerUseProducerInstalled({ desktopPackageRoot })) return [];
  16. const manifestPath = resolve(pluginRoot, ".zcode-plugin", "plugin.json");
  17. if (!existsSync(manifestPath)) {
  18. throw new Error(
  19. `[stage-dev-cua-plugin-runtime] CUA plugin manifest is missing: ${manifestPath}`,
  20. );
  21. }
  22. // 修复原因:sync:cache 过去只把 Sharp 写入最终缓存,桌面重启时 bootstrap
  23. // 会用源码 plugin 原子替换该缓存并删除 Sharp。先补全 CUA filesystem seed source,
  24. // 才能让每次重建都得到可独立加载原生依赖的 CUA plugin;Browser Use 只提供
  25. // shared node_repl host,不再作为 CUA native 依赖的解析根目录。
  26. return stageSharpIntoBundledAgents({
  27. desktopPackageRoot,
  28. glmDir: pluginRoot,
  29. targetPlatform: {
  30. os: platform,
  31. arch,
  32. key: `${platform}-${arch}`,
  33. },
  34. });
  35. }