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
@@ -4,6 +4,7 @@ import { runCli } from "../cli/runner.js";
|
||||
import { runAiProCli } from "../aipro-cli.js";
|
||||
import { loadCorpConfigs, loadGlobalConfig } from "../core/config/loader.js";
|
||||
import { getOpenApiSchema } from "../packaging/embedded-openapi.js";
|
||||
import { getAiProWebUiHtml } from "../packaging/embedded-webui.js";
|
||||
import { tokenizeCommand, normalizeCliArgs } from "../server.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import { renderDocsHtml } from "./docs.js";
|
||||
@@ -118,6 +119,12 @@ export async function handleHttpRequest(
|
||||
return;
|
||||
}
|
||||
|
||||
// AI PRO 本地 Web 控制台:单文件内嵌,仅监听 127.0.0.1
|
||||
if (isAiPro && method === "GET" && (pathname === "/report" || pathname.startsWith("/report/"))) {
|
||||
sendHtml(res, 200, getAiProWebUiHtml());
|
||||
return;
|
||||
}
|
||||
|
||||
if (method === "GET" && pathname === "/docs") {
|
||||
sendHtml(res, 200, renderDocsHtml());
|
||||
return;
|
||||
|
||||
+2
-1
@@ -48,7 +48,8 @@ export async function startHttpServer(options: HttpServerOptions = {}): Promise<
|
||||
if (!isAiPro) {
|
||||
console.error(` 企业列表接口: GET http://${host}:${port}/v1/corps\n`);
|
||||
} else {
|
||||
console.error(` 网关状态接口: GET http://${host}:${port}/v1/status\n`);
|
||||
console.error(` 网关状态接口: GET http://${host}:${port}/v1/status`);
|
||||
console.error(` Web 控制台: http://${host}:${port}/report\n`);
|
||||
}
|
||||
}
|
||||
resolve(server);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { Server } from "node:http";
|
||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { startHttpServer } from "./server.js";
|
||||
import { handleHttpRequest } from "./routes.js";
|
||||
import { getAiProWebUiHtml } from "../packaging/embedded-webui.js";
|
||||
|
||||
const PORT = 18989;
|
||||
const BASE = `http://127.0.0.1:${PORT}`;
|
||||
|
||||
describe("AI PRO HTTP daemon Web 控制台", () => {
|
||||
let server: Server | undefined;
|
||||
|
||||
beforeAll(async () => {
|
||||
server = await startHttpServer({ app: "hose-aipro", port: PORT, silent: true });
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
server?.close();
|
||||
});
|
||||
|
||||
test("GET /report 返回完整的内嵌 HTML", async () => {
|
||||
const response = await fetch(`${BASE}/report`);
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toContain("text/html");
|
||||
const html = await response.text();
|
||||
expect(html).toContain('<div id="app">');
|
||||
expect(html).toContain("合思 AI PRO 控制台");
|
||||
expect(html).not.toContain('src="/static/');
|
||||
});
|
||||
|
||||
test("带子路径的 /report/ 同样返回控制台(hash 路由兜底)", async () => {
|
||||
const response = await fetch(`${BASE}/report/sessions`);
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.text()).toBe(getAiProWebUiHtml());
|
||||
});
|
||||
|
||||
test("hose-use 路由不暴露 /report", async () => {
|
||||
// 直接调路由处理器,避免 Bun fetch 在同一 host 跨端口复用连接造成误判
|
||||
let body = "";
|
||||
const res = {
|
||||
setHeader: () => undefined,
|
||||
writeHead: () => undefined,
|
||||
end: (value?: string) => { body = value ?? ""; },
|
||||
headersSent: false,
|
||||
};
|
||||
await handleHttpRequest(
|
||||
{ method: "GET", url: "/report", headers: { host: "localhost" } } as never,
|
||||
res as never,
|
||||
{ app: "hose-use" }
|
||||
);
|
||||
expect(body).not.toContain('<div id="app">');
|
||||
expect(body).toContain("Cannot GET /report");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user