43 lines
1.9 KiB
TypeScript
43 lines
1.9 KiB
TypeScript
import { Plugin } from "@opencode/plugin"
|
|
import { execFile } from "node:child_process"
|
|
import { fileURLToPath } from "node:url"
|
|
import { promisify } from "node:util"
|
|
|
|
const run = promisify(execFile)
|
|
const bundledServer = fileURLToPath(new URL("./bundle/serve.py", import.meta.url))
|
|
|
|
export default Plugin.define({
|
|
id: "cad-dashboard",
|
|
async setup(ctx) {
|
|
await ctx.tool.transform((editor) => {
|
|
editor.namespace({ name: "cad_dashboard", description: "Локальная панель CAD Factory" })
|
|
editor.add({
|
|
name: "ensure",
|
|
description: "Создаёт недостающие файлы в dashboard/ текущего CAD-проекта, запускает или находит панель и возвращает локальную ссылку.",
|
|
options: { namespace: "cad_dashboard", codemode: true },
|
|
input: { type: "object", properties: {}, additionalProperties: false },
|
|
async execute(_, context) {
|
|
await ctx.permission.assert({
|
|
sessionID: context.sessionID,
|
|
agent: context.agent,
|
|
source: { type: "tool", messageID: context.messageID, id: context.id },
|
|
action: "cad_dashboard",
|
|
resources: ["ensure"],
|
|
save: ["ensure"],
|
|
})
|
|
const root = ctx.location.directory
|
|
try {
|
|
const { stdout } = await run("python3", [
|
|
"-I", bundledServer, "--install", "--ensure", "--root", root,
|
|
], { cwd: root, signal: context.signal, timeout: 15_000, maxBuffer: 8192 })
|
|
return { content: stdout.trim() }
|
|
} catch (error) {
|
|
if (context.signal.aborted) throw error
|
|
return { content: "Панель не удалось запустить. Для ручного запуска запустите bundle/serve.py из комплекта плагина с --root <каталог проекта>." }
|
|
}
|
|
},
|
|
})
|
|
})
|
|
},
|
|
})
|