feat: AI PRO 本地 Web 控制台与聚合报表
持久化常驻复用现有 hose-aipro service start(detached + pid 文件、
127.0.0.1:8889),本次只补前端与数据出口,不做端口/K8s 化改造。
是否映射公网由使用者自行决定,工具仍只监听回环地址。
- web/:Vue 3.5 + Vite 6 + TS + vue-router + Tailwind 3 子工程,配置对齐
本机 twc-approval-go-bridge/web(base /static/、outDir 到后端内嵌目录、
dev proxy → 8889、hash 路由)。5 个视图:总览、审批会话、规则与要点、
审计流水、命令终端;统一经 POST /api/cli 调用现有 CLI 能力。
- scripts/build/build-webui.mjs:把 Vite 产物 JS/CSS 内联成单文件 HTML,
生成 src/packaging/generated/webui.txt。生成物随 git 提交,编译二进制
与 CI 不需要安装前端依赖;.webui-dist/ 为忽略的中间产物。
- src/packaging/embedded-webui.ts:with { type: text } 内嵌。用 .txt 后缀
而非 .html,避开 Bun 对 .html 的 HTMLBundle 类型推断导致 tsc 报错。
- src/http/routes.ts:AI Pro daemon 暴露 GET /report(含 /report/* 兜底);
server.ts 启动日志补控制台地址;hose-use daemon 不暴露该路由。
- src/cli/commands/aipro/report.ts:新增 report --json 聚合命令,一次返回
场景/规则/会话/要点/流水/授权状态;单据快照等大字段不下发,避免撑爆
浏览器。命令在统一门禁之后,未激活仍会被拦截。
- 新增 embedded-webui / webui 路由 / report 聚合三组测试;同步
SKILL.md、README.md、packaging README、.gitignore 与 package.json 脚本。
校验:bun test 1108 pass / 0 fail,bun run check、check:readme 全通过;
编译二进制实测 GET /report 返回 200 且资源全内联(140KB、零外链),
POST /api/cli report --json 返回真实聚合数据(2 场景/3 规则/45 条流水)。
本次不打 tag、不发版,留待 0.9.4。
This commit is contained in:
1 parent
b51152276d
commit
36e21e5dc2
34 files changed
+1668
-1
No files matched your search
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* 构建 web/ 下的 Vue 控制台,并把 JS/CSS 内联成单个 HTML 供二进制内嵌。
|
||||
*
|
||||
* 前置:bun install --cwd web(仅开发机需要;生成物随 git 提交,CI 不需要)
|
||||
* 用法:bun run web:build
|
||||
*/
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
const root = resolve(import.meta.dirname, "../..");
|
||||
const webDir = join(root, "web");
|
||||
const outDir = join(root, ".webui-dist");
|
||||
// 后缀用 .txt 而非 .html:Bun 对 .html 的 text import 会推断成 HTMLBundle,
|
||||
// 导致 tsc 报错;内容仍是完整 HTML,由 HTTP 层按 text/html 返回。
|
||||
const target = join(root, "src", "packaging", "generated", "webui.txt");
|
||||
|
||||
if (!existsSync(join(webDir, "node_modules"))) {
|
||||
console.error("[build:webui] web/ 依赖未安装,请先执行: bun install --cwd web");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("[build:webui] building Vue app...");
|
||||
execFileSync("bun", ["run", "build"], { cwd: webDir, stdio: "inherit" });
|
||||
|
||||
const indexPath = join(outDir, "index.html");
|
||||
if (!existsSync(indexPath)) {
|
||||
console.error(`[build:webui] 找不到构建产物: ${indexPath}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let html = readFileSync(indexPath, "utf8");
|
||||
const files = readdirSync(outDir);
|
||||
|
||||
for (const file of files.filter((name) => name.endsWith(".css"))) {
|
||||
const css = readFileSync(join(outDir, file), "utf8");
|
||||
html = html.replace(/<link[^>]+href="[^"]*\.css"[^>]*>/g, () => `<style>${css}</style>`);
|
||||
}
|
||||
|
||||
for (const file of files.filter((name) => name.endsWith(".js"))) {
|
||||
const js = readFileSync(join(outDir, file), "utf8").replaceAll("</script>", "<\\/script>");
|
||||
html = html.replace(/<script[^>]+src="[^"]*\.js"[^>]*><\/script>/g, () => `<script type="module">${js}</script>`);
|
||||
}
|
||||
|
||||
if (/<script[^>]+src=/.test(html) || /<link[^>]+href="[^"]*\.css"/.test(html)) {
|
||||
console.warn("[build:webui] 警告: 仍有外链资源未被内联,页面在纯本地环境可能加载失败");
|
||||
}
|
||||
|
||||
mkdirSync(dirname(target), { recursive: true });
|
||||
writeFileSync(target, html, "utf8");
|
||||
console.log(`[build:webui] ✓ ${target} (${(html.length / 1024).toFixed(1)} KiB)`);
|
||||
Reference in new issue
Block a user