serve-software-dashboard.ts 1.4 KB

12345678910111213141516171819
  1. import { parseArgs } from "node:util"
  2. import { loadAgentPaaSConfig, requestJSON } from "../.opencode/lib/agentpaas"
  3. import { startSoftwareReviewPanel } from "../.opencode/lib/software-review-panel"
  4. const args = parseArgs({ options: { review: { type: "string" }, port: { type: "string" } } }).values
  5. if (!args.review || !/^[a-f0-9]{32}$/.test(args.review)) throw new Error("使用 --review <真实审阅编号>;凭证通过现有 AGENTPAAS 配置读取")
  6. const base = await loadAgentPaaSConfig()
  7. const url = process.env.AGENTPAAS_SOFTWARE_REVIEW_URL?.replace(/\/+$/, "") || base.url
  8. const target = new URL(url)
  9. const origin = new URL(base.url)
  10. if (target.hostname !== origin.hostname || target.protocol !== origin.protocol || target.username || target.password || target.search || target.hash || target.pathname !== "/") throw new Error("审阅 API 必须与 PaaS 使用相同主机与协议")
  11. const port = args.port ? Number(args.port) : 0
  12. if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("无效端口")
  13. const config = { ...base, url }
  14. await requestJSON(config, `/software-reviews/${args.review}`, new AbortController().signal)
  15. const panel = startSoftwareReviewPanel(config, args.review, port, "dashboard")
  16. console.log(JSON.stringify({ url: panel.url, review_id: args.review, read_only: true }))
  17. process.on("SIGTERM", () => { panel.server.stop(true); process.exit(0) })
  18. process.on("SIGINT", () => { panel.server.stop(true); process.exit(0) })