SuperAPI AI 工具集

copilotkit-setup

通用与其它

查看项目

更新于 10-15 20:28

技能介绍

用途:在已有项目或从零新建项目中接入 CopilotKit,完成框架检测、依赖安装、服务端运行时与前端聊天界面配置。

前置条件:Node.js >= 18;一个 AI 供应商 API Key(OPENAI_API_KEY、ANTHROPIC_API_KEY 或 GOOGLE_API_KEY);React 前端(Next.js App Router、Next.js Pages Router、Vite + React 或 Angular);可运行运行时的后端(同应用 API 路由,或独立 Express/Hono 服务)。插件自带 MCP 服务器 copilotkit-docs,提供 search-docs、search-code 工具查询实时文档与源码;Claude Code 由 .mcp.json 自动配置,Codex 需手动配置。

框架检测:通过根目录信号文件判断,如 next.config 加 app/ 或 pages/ 目录、angular.json、vite.config 加 React 依赖。

安装:前端 npm install @copilotkit/react @copilotkit/core;后端 npm install @copilotkit/runtime @copilotkit/agent。Express 还需 express cors 及类型包。

运行时配置:多路由用 createCopilotEndpoint(需 catch-all 路由),单路由用 createCopilotEndpointSingleRoute 或 createCopilotEndpointSingleRouteExpress。Express 多路由用 createCopilotEndpointExpress。运行时类有 CopilotRuntime、CopilotSseRuntime、CopilotIntelligenceRuntime;默认 InMemoryAgentRunner。模型以 "provider/model-name" 指定。

前端:用 CopilotKitProvider 包裹应用并引入 @copilotkit/react/styles.css,可选用 CopilotChat、CopilotSidebar、CopilotPopup。外部运行时需设 runtimeUrl,单路由需加 useSingleEndpoint。

环境变量:在 .env.local 或 .env 中配置 API Key,BuiltInAgent 按模型前缀自动解析。

云平台连接:默认建议连接,运行 npx copilotkit auth 完成浏览器认证,获得 ck_ 开头的 license key 并传给 Provider,或存入 COPILOTKIT_LICENSE_KEY。

验证:启动开发服务器,确认聊天界面渲染并连接运行时,发送测试消息,检查 /info 端点。

限制:仅覆盖上述框架与模型;官方未提供具体收费、价格与效果数据。