@cannbot-plugin/cannbot-dsh-server 0.0.0-stage → 1.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ import { n as WorkspaceModes, o as ContentManager, u as packageRoot } from "./workspace-mode-BUX9fB3R.js";
2
+ import { createRequire } from "node:module";
3
+ import { join, resolve } from "node:path";
4
+ import { mkdir } from "node:fs/promises";
5
+ // plugin/backend/initialize-workspace.ts
6
+ /** CLI initialization keeps the user's real terminal, before DSH Web is started. */
7
+ async function initializeBeforeLaunch(directory, workflow) {
8
+ if (process.platform !== "linux") throw new Error("工作流终端初始化需要 Linux 环境。");
9
+ if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("请在交互终端中执行初始化,以便回答工作流问卷。");
10
+ const require = createRequire(import.meta.url);
11
+ const content = new ContentManager(resolve(packageRoot(), "workflow-defaults.json"));
12
+ const catalog = require.resolve("@cannbot-plugin/workflow-catalog/package.json"), dependencies = createRequire(catalog);
13
+ await content.installDependencies(catalog, (name) => dependencies.resolve(name + "/package.json"));
14
+ const path = resolve(directory);
15
+ await mkdir(path, { recursive: true });
16
+ const unavailable = async () => {
17
+ throw new Error("Host is not running");
18
+ };
19
+ const modes = new WorkspaceModes(join(content.root, "workspace-modes"), {
20
+ available: (id) => content.getSource().catalog.plugins.some((item) => item.id === id),
21
+ prepare: (cwd, id) => content.prepare(cwd, id),
22
+ createWorkspace: unavailable,
23
+ listWorkspaces: unavailable,
24
+ readSession: unavailable
25
+ });
26
+ content.setPreparationGuard((cwd, id, run) => modes.withPreparation(cwd, id, run));
27
+ await modes.prepareBeforeLaunch(path, workflow);
28
+ console.log("工作流初始化完成,即将启动工作台。");
29
+ }
30
+ export { initializeBeforeLaunch };