From 0d3d09f2806b614a7303b196d62a51c383311de4 Mon Sep 17 00:00:00 2001 From: Boom <654612@qq.com> Date: Wed, 25 Mar 2026 20:36:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E4=B8=BB=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E5=B9=B6=E4=BC=98=E5=8C=96=E5=8A=A8=E6=80=81=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构主布局组件,将侧边栏和 Copilot 提供者逻辑提取到 MainLayout 组件 优化动态表单,支持编辑模式并完善错误处理 移除测试提示信息并更新环境变量配置 --- .antigravity/BASELINE.md | 16 ++++----- src/app/api/copilotkit/route.ts | 32 ----------------- src/app/data/[entityCode]/page.tsx | 21 ++++++----- src/app/layout.tsx | 10 +++--- src/app/page.tsx | 1 - src/components/CopilotProvider.tsx | 2 +- src/components/DynamicForm.tsx | 57 +++++++++++++++++++----------- src/components/MainLayout.tsx | 26 ++++++++++++++ 8 files changed, 89 insertions(+), 76 deletions(-) delete mode 100644 src/app/api/copilotkit/route.ts create mode 100644 src/components/MainLayout.tsx diff --git a/.antigravity/BASELINE.md b/.antigravity/BASELINE.md index 734a08e..ea22a3e 100644 --- a/.antigravity/BASELINE.md +++ b/.antigravity/BASELINE.md @@ -5,8 +5,9 @@ - **核心理念**:通过 AI 驱动的消息流实现动态 UI 生成和业务处理。 - **技术栈**:Next.js 15 (App Router) + Tailwind CSS + Lucide Icons。 - **关键组件**: - - `UniversalModuleRenderer.tsx`: 后端 AI 下发 UI 指令的监听与执行枢纽,负责实时绘制界面。 - - `DynamicForm.tsx`: 基于 JSON Schema 的动态表单渲染器,支持实体关联选择 (`x-link-entity`)。 + - `UniversalModuleRenderer.tsx`: 后端 AI 下发 UI 指令的监听与执行枢纽。 + - `CopilotProvider.tsx`: **已更新**,取消本地 AI 运行时,改为直连后端 `/api/copilotkit` 端口。 + - `DynamicForm.tsx`: 基于 JSON Schema 的动态表单渲染器。 - `EntityDataPage`: 动态列表展示页面,通过 AI 代理执行编辑和删除操作。 ## 💼 业务逻辑 (Business Logic) @@ -16,17 +17,16 @@ ## 📈 当前开发进度 (Current Progress) - [x] **AI 动态 UI 渲染**:`UniversalModuleRenderer` 基础架构就绪。 - [x] **动态表单与关联**:支持枚举、模式匹配及实体级联选择。 -- [x] **会话隔离适配**:前端已实现 Header 注入逻辑。 -- [x] **CORS 联调**:已完成与后端的跨域联调。 +- [x] **安全优化**:移除了前端 API Key,所有 AI 请求通过后端转发。 +- [x] **业务模块共享**:适配后端变更,侧边栏现可按公共定义渲染所有活跃模块。 ## ⚠️ 尚未解决的隐患 (Known Issues/Risks) +- **共享冲突提示**:缺乏对公共模块并发编辑的 UI 级冲突提示。 - **状态同步**:多组件间由于 AI 异步返回导致的 UI 闪烁问题。 -- **离线能力**:目前完全依赖实时 AI 交互,缺乏离线暂存机制。 ## 🚀 下一步计划 (Next Steps) -1. **AI 智能搜索界面**:对接后端的 AI 增强搜索功能。 -2. **动态看板 (Dashboard)**:实现可视化图表的 AI 渲染支持。 -3. **引导流程优化**:提升用户通过对话创建新模块的体验。 +1. **数据权限展示**:在 UI 层面区分公共数据与私人数据。 +2. **AI 智能搜索界面**:对接后端的 AI 增强搜索功能。 --- *Last Updated: 2026-03-25 by Antigravity* diff --git a/src/app/api/copilotkit/route.ts b/src/app/api/copilotkit/route.ts deleted file mode 100644 index 866b517..0000000 --- a/src/app/api/copilotkit/route.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - CopilotRuntime, - GoogleGenerativeAIAdapter, - copilotRuntimeNextJSAppRouterEndpoint -} from "@copilotkit/runtime"; -import { GoogleGenerativeAI } from "@google/generative-ai"; - -export const POST = async (req: Request) => { - // 1. 初始化 Google Gemini 客户端 - const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY || ""); - - // 2. 选择模型 (使用 3.1 Pro) - const model = genAI.getGenerativeModel({ - model: "gemini-3.1-pro", - // 如果需要启用思维模型等高级参数,可以在这里或 adapter 层级配置 - }); - - const runtime = new CopilotRuntime(); - - // 3. 使用 GoogleGenerativeAIAdapter - const serviceAdapter = new GoogleGenerativeAIAdapter({ - model: "gemini-1.5-pro" - }); - - const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({ - runtime, - serviceAdapter, - endpoint: "/api/copilotkit", - }); - - return handleRequest(req); -}; \ No newline at end of file diff --git a/src/app/data/[entityCode]/page.tsx b/src/app/data/[entityCode]/page.tsx index 8bbad81..773faba 100644 --- a/src/app/data/[entityCode]/page.tsx +++ b/src/app/data/[entityCode]/page.tsx @@ -123,27 +123,32 @@ export default function EntityDataPage({ params: paramsPromise }: DataPageProps) }, [entityCode]); const handleDelete = async (id: string) => { - if (!confirm("确定要物理删除这条数据吗?该操作不可撤销,将由 AI 执行。")) return; + if (!confirm("确定要删除这条数据吗?该操作不可撤销。")) return; try { const userId = localStorage.getItem("crm_user_id") || "anonymous"; const res = await fetch(`/api/agent/chat?sessionId=${userId}_OP`, { method: 'POST', headers: { 'X-Creator-Id': userId }, - body: `请执行核心物理删除指令:删除记录 ID 为 ${id} 的数据。` + body: `请执行删除操作:物理删除记录 ID 为 ${id} 的数据。` }); if (res.ok) { - alert("✅ AI 已同步执行删除操作。"); - loadData(); + const result = await res.json(); + if (result.code === 200) { + loadData(); + } else { + alert(`删除失败: ${result.msg || "未知错误"}`); + } + } else { + alert("删除失败: 请求异常"); } } catch (err) { - alert("删除失败"); + alert("删除失败: 网络故障"); } }; const handleEdit = (row: any) => { - // 排除系统字段 - const { _id, _createdAt, ...businessData } = row; - setEditingData(businessData); + const { _createdAt, ...editData } = row; + setEditingData(editData); setIsModalOpen(true); }; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index c08be0b..fc14fef 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -15,6 +15,7 @@ const geistMono = Geist_Mono({ import Sidebar from "@/components/Sidebar"; import CopilotProvider from "@/components/CopilotProvider"; import AuthGuard from "@/components/AuthGuard"; +import MainLayout from "@/components/MainLayout"; export const metadata: Metadata = { title: "AI-Native CRM", @@ -33,12 +34,9 @@ export default function RootLayout({ >