Browse Source
重构主布局组件,将侧边栏和 Copilot 提供者逻辑提取到 MainLayout 组件 优化动态表单,支持编辑模式并完善错误处理 移除测试提示信息并更新环境变量配置main
8 changed files with 89 additions and 76 deletions
@ -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); |
|
||||||
}; |
|
||||||
@ -0,0 +1,26 @@ |
|||||||
|
"use client"; |
||||||
|
|
||||||
|
import { usePathname } from "next/navigation"; |
||||||
|
import Sidebar from "./Sidebar"; |
||||||
|
import CopilotProvider from "./CopilotProvider"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 主布局组件,根据当前路径决定是否渲染侧边栏和 AI 助理 |
||||||
|
*/ |
||||||
|
export default function MainLayout({ children }: { children: React.ReactNode }) { |
||||||
|
const pathname = usePathname(); |
||||||
|
const isLoginPage = pathname === "/login"; |
||||||
|
|
||||||
|
if (isLoginPage) { |
||||||
|
return <main className="w-full h-full">{children}</main>; |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<CopilotProvider> |
||||||
|
<Sidebar /> |
||||||
|
<div className="flex-1 overflow-y-auto"> |
||||||
|
{children} |
||||||
|
</div> |
||||||
|
</CopilotProvider> |
||||||
|
); |
||||||
|
} |
||||||
Loading…
Reference in new issue