Files
maestro/app/vite.config.js
wangjia d6ae4dbe13 feat(app): 阶段2 接真实数据——REST + WS 直连本地 daemon
前端从 mock 切换到真实数据源(按 ⑧ 前端 API 契约,复用现有 :4517 daemon API):

- src/api.js:REST 封装 + WS 单向订阅(断线指数退避重连)
- src/adapt.js:纯映射层,把 API 的 camelCase 行映射成各 surface 期望形状
  (扁平任务→children 树、priority 整数→P0/1/2、complexity→cplx、终态→归档卡)
- src/app.jsx:改为 useEffect 拉取 + WS 增量刷新;decide/sync 走真实 POST;
  审批闸收紧到 plan/spec/exec_review 三态(needs_attention 仍在任务树可见)
- vite.config.js:加 /api + /ws 反代到 :4517;去掉 jsxInject(surface 走全局
  React,避免生产构建 rollup 从 design/ 解析 react 失败)
- main.jsx:移除 data.js mock 导入

验证:dev + 生产构建双通过;真实数据渲染(4 项目/审批闸带 diff/真实配额),
WS 已连接,0 console 错误。token/成本类(agentSummary)属 ⑧ ★ 新 /api/usage
(预算特性),暂留空待补。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 14:29:19 +08:00

30 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from 'vite';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// 复刻策略:设计系统(design/)为单源。surface/.jsx 源文件不改,用经典 JSX 转换 +
// 注入 React 直接加载;编译好的 _ds_bundle.js 走全局 window.React(见 src/globals.js)。
export default defineConfig({
resolve: {
alias: { '@ds': path.resolve(__dirname, '../design') },
},
// surface/.jsx 与 app.jsx 统一走全局 Reactglobals.js 注入 window.React),
// 不向各模块注入 import——否则生产构建时 rollup 会试图从 design/ 解析 react 而失败。
esbuild: {
jsx: 'transform',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
},
server: {
port: 4519,
fs: { allow: [path.resolve(__dirname, '..')] }, // 允许访问仓库内的 design/
// 把 REST + WS 反代到本地 daemon(:4517),客户端用同源相对路径
proxy: {
'/api': { target: 'http://127.0.0.1:4517', changeOrigin: true },
'/ws': { target: 'http://127.0.0.1:4517', ws: true, changeOrigin: true },
},
},
});