/** * 星环OPC中心 — 产品官网/文档页 * * 路由: / (根路径) * 纯静态 HTML 单页,展示产品功能和安装指南 */ import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import type { IncomingMessage, ServerResponse } from "node:http"; import type { OpenClawPluginApi } from "openclaw/plugin-sdk"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); function sendHtml(res: ServerResponse, html: string): void { res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); res.end(html); } const MODULES = [ { icon: "🏢", name: "核心管理", tool: "opc_core", desc: "公司注册、AI员工创建、客户关系、交易记录", phase: 1 }, { icon: "💰", name: "财税管理", tool: "opc_finance", desc: "发票管理、增值税/所得税计算、纳税申报、税务日历", phase: 2 }, { icon: "⚖", name: "法务合同", tool: "opc_legal", desc: "合同全生命周期、风险评估、到期提醒", phase: 2 }, { icon: "👥", name: "人力资源", tool: "opc_hr", desc: "员工档案、薪资核算、社保公积金、入离职管理", phase: 2 }, { icon: "📷", name: "新媒体运营", tool: "opc_media", desc: "内容创建、多平台发布、排期管理、数据分析", phase: 2 }, { icon: "📋", name: "项目管理", tool: "opc_project", desc: "项目规划、任务分配、进度追踪、预算管控", phase: 2 }, { icon: "📈", name: "投融资", tool: "opc_investment", desc: "融资轮次、投资人管理、股权结构(Cap Table)、估值历史", phase: 3 }, { icon: "🛒", name: "服务采购", tool: "opc_procurement", desc: "服务项目管理、采购订单、费用分类统计", phase: 3 }, { icon: "🏆", name: "生命周期", tool: "opc_lifecycle", desc: "里程碑管理、大事记、时间线、公司综合报告", phase: 3 }, { icon: "📊", name: "运营监控", tool: "opc_monitoring", desc: "指标记录、告警管理、KPI看板、跨表数据聚合", phase: 3 }, ]; function buildLandingHtml(): string { const moduleCards = MODULES.map(m => `
${m.icon}

${m.name}

${m.desc}

Phase ${m.phase} ${m.tool}
` ).join("\n"); return ` 星环OPC中心 — 一人公司 AI 管家

星环OPC中心

一人公司 AI 管家
10 大 AI 工具模块 · 覆盖公司全生命周期 · 零代码接入
进入管理后台

功能一览

从公司注册到融资退出,AI 员工全程代办

${moduleCards}

快速开始

三步接入,即刻拥有 AI 公司管家

1

下载插件

将 opc-platform 插件放入 extensions 目录

extensions/
  opc-platform/
    index.ts
    package.json
    openclaw.plugin.json
2

配置启用

在 openclaw.json 中启用插件

{
  "plugins": {
    "opc-platform": {
      "enabled": true,
      "config": {
        "dbPath": "~/.openclaw/opc/opc.db"
      }
    }
  }
}
3

启动使用

启动 Gateway,通过对话即可使用全部功能

pnpm build && pnpm start

# 访问管理后台
http://localhost:18789/opc/admin

# 访问产品官网
http://localhost:18789/

使用示例

自然语言驱动,像和助理对话一样管理公司

"帮我注册一家科技公司,注册资金10万"
AI 调用 opc_core 创建公司记录,自动生成唯一 ID,设置行业和注册资本
"给客户A开一张5万元的服务费发票"
AI 调用 opc_finance 创建销项发票,自动计算 6% 增值税,生成含税总额
"查看当前股权结构"
AI 调用 opc_investment cap_table,聚合所有投资人股权,计算创始人剩余比例
"生成公司综合报告"
AI 调用 opc_lifecycle generate_report,聚合财务/团队/项目/合同/融资等全景数据
"查看这个月的KPI"
AI 调用 opc_monitoring kpi_summary,跨表聚合收入/员工/项目/合同/告警数据
`; } export function registerLandingPage(api: OpenClawPluginApi): void { // opc-homepage 前端页面路径(项目根目录下) const homepageDir = path.resolve(__dirname, "../../../../opc-homepage"); const homepageIndexPath = path.join(homepageDir, "index.html"); const handler = async (req: IncomingMessage, res: ServerResponse): Promise => { const rawUrl = req.url ?? ""; const urlObj = new URL(rawUrl, "http://localhost"); const pathname = urlObj.pathname; // 1. 根路径 `/` → 返回 opc-homepage/index.html if (pathname === "/" || pathname === "") { try { if (fs.existsSync(homepageIndexPath)) { const html = fs.readFileSync(homepageIndexPath, "utf-8"); sendHtml(res, html); return true; } } catch (err) { api.logger.warn(`opc: 无法读取主页文件: ${err instanceof Error ? err.message : String(err)}`); } // 降级到内置页面 sendHtml(res, buildLandingHtml()); return true; } // 2. 静态资源 `/galaxy.png` 等 → 返回 opc-homepage/ 下的文件 if (pathname.match(/^\/(galaxy.*\.png|.*\.jpg|.*\.svg|.*\.css|.*\.js)$/)) { try { const filename = path.basename(pathname); const filePath = path.join(homepageDir, filename); if (fs.existsSync(filePath)) { const ext = path.extname(filename).toLowerCase(); const mimeTypes: Record = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".svg": "image/svg+xml", ".css": "text/css", ".js": "application/javascript", }; const contentType = mimeTypes[ext] || "application/octet-stream"; const fileContent = fs.readFileSync(filePath); res.writeHead(200, { "Content-Type": contentType }); res.end(fileContent); return true; } } catch (err) { api.logger.warn(`opc: 无法读取静态资源: ${err instanceof Error ? err.message : String(err)}`); } return false; } return false; }; const apiAny = api as unknown as { registerHttpHandler?: (h: (req: IncomingMessage, res: ServerResponse) => Promise | boolean) => void; registerHttpRoute?: (r: { path: string; handler: (req: IncomingMessage, res: ServerResponse) => Promise | boolean | void; auth: string; match?: string }) => void; }; if (typeof apiAny.registerHttpHandler === "function") { // 旧版 openclaw:通过 registerHttpHandler 注册,返回 false 时 openclaw 继续处理聊天 UI apiAny.registerHttpHandler(handler); api.logger.info("opc: 已注册产品官网 (/)"); } else { // 新版 openclaw (2026.3.2+):跳过官网注册,保留 openclaw 原生聊天 UI 在 / // 用户通过 /opc/admin 直接访问管理后台 api.logger.info("opc: 跳过官网注册(新版 openclaw,聊天 UI 保留在 /)"); } }