关于 react-core
react-core 是 CopilotKit 的 React 前端技能索引,供开发者配置提供程序、聊天界面及 Agent 交互。它按任务指向参考文档,覆盖工具注册、渲染和人工审批等界面功能。
主要功能
- 01配置 CopilotKit 提供程序
- 02组合聊天组件与插槽
- 03访问 Agent 与上下文
- 04注册前端工具并渲染调用
- 05人工审批与建议界面
适用场景
- 01在 React 应用中接入 CopilotKit
- 02构建聊天界面与多 Agent 界面
- 03实现浏览器端工具及其界面
- 04加入工具执行审批
MCP 相关
文档指出运行时可配置 MCP Apps 中间件;未说明此 React 技能如何连接或管理 MCP 服务。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ copilotkit/ copilotkit --skill react-core安装后在 Claude Code 中输入/react-core确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/agent-access.mdattachments.mdcapabilities.mdchat-components.mdclient-side-tools.mdcustom-message-renderers.mddebug-mode.mdhuman-in-the-loop.mdprovider-setup.mdrendering-activity-messages.mdrendering-tool-calls.mdsuggestions.mdswitching-agents-recipes.mdswitching-agents.mdthreads.md详细介绍
CopilotKit React Core
@copilotkit/react-core 是 CopilotKit 的 React 前端部分:它挂载 provider,
通过 SSE 以 AG-UI 与 runtime(或在 SPA 模式下直接与 CopilotKit Intelligence)通信,并
为每个交互界面暴露 hooks。
本 SKILL.md 是索引。请阅读 references/ 下与你任务匹配的参考文档——不要试图从本文件中吸收整个包的内容。
心智模型——你组合的三个 shell
- Provider shell——
CopilotKitprovider(来自@copilotkit/react-core/v2)位于或接近根节点(对于 Next.js App Router,位于"use client"内)。携带runtimeUrl(必需)、headers、credentials、properties、onError、debug、enableInspector。 - Chat shell——
CopilotChat/CopilotPopup/CopilotSidebar,或组合使用CopilotChatView+ slot 原语(CopilotChatInput、CopilotChatMessageView等)。 所有聊天组件均从@copilotkit/react-core/v2提供。CopilotPanel并不 存在——它是一个常见的幻觉。 - Hook shell——在 provider 下的任意组件内,调用
useAgent、useFrontendTool、useRenderTool等。每个 hook 都接受可选的{ agentId },用于 按 agent 范围的注册。
何时加载哪个参考
| 任务 | 参考 |
|---|---|
挂载 CopilotKit provider,将 runtimeUrl 指向 runtime,RSC 边界规则 | references/provider-setup.md |
引入 CopilotChat / CopilotPopup / CopilotSidebar,用插槽原语组合 CopilotChatView | references/chat-components.md |
通过 useAttachments 处理文件 / 图片附件 — 拖放、点击、粘贴、自定义上传 | references/attachments.md |
客户端调试工具 — enableInspector、debug prop、懒加载的 web inspector | references/debug-mode.md |
读取 / 订阅 Agent(useAgent)并推送全局上下文(useAgentContext) | references/agent-access.md |
基于声明的 Agent 能力对 UI 进行功能门控(useCapabilities) | references/capabilities.md |
构建多 Agent UI(每个面板的 useAgent、Agent 作用域工具、key 重新挂载模式) | references/switching-agents.md(+ switching-agents-recipes.md 用于具体布局) |
列出 / 重命名 / 归档 / 删除持久化的 Intelligence 线程(useThreads) | references/threads.md(需要 runtime Intelligence 模式) |
注册浏览器端工具(useFrontendTool) | references/client-side-tools.md |
渲染每个工具的 UI(useRenderTool、useComponent、useDefaultRenderTool、useRenderToolCall) | references/rendering-tool-calls.md |
将工具执行置于用户批准之后(useHumanInTheLoop) | references/human-in-the-loop.md |
配置动态或静态建议胶囊(useConfigureSuggestions、useSuggestions) | references/suggestions.md |
渲染非聊天活动消息(useRenderActivityMessage) | references/rendering-activity-messages.md |
在特定消息之前 / 之后注入自定义 UI(useRenderCustomMessages) | references/custom-message-renderers.md |
不变量与注意事项(一次性加载,先于任何参考文档)
runtimeUrl为必填项;生产环境中若缺少它,提供方会抛出异常。CopilotKit Intelligence 配置在 runtime 上,绝不在提供方上。agents__unsafe_dev_only与selfManagedAgents是彼此的开发专用别名。不安全用于生产环境。 受支持的 SPA 路径请参见packages/a2ui-renderer或spa-without-runtime生命周期技能。CopilotPanel并不存在。v2 聊天组件由react-core/v2提供——并非react-ui(v2 的react-ui仅含 CSS)。- 不存在
useAgents()Hook。请通过copilotkit.subscribe({ onAgentsChanged })发现 Agent。 useRenderToolCall是一个解析器(用于自定义聊天界面),不是注册 Hook。请使用useRenderTool/useComponent/useDefaultRenderTool进行注册。- UI 套件检测规则——任何
render或工具调用 UI 在编写原生 JSX 之前,必须先复用使用方的 shadcn / MUI / Chakra / Ant / Mantine 基础组件。这适用于client-side-tools、rendering-tool-calls和human-in-the-loop。 - 工具调用的
status值为 camelCase:'inProgress' | 'executing' | 'complete'。进行中的参数为Partial<T>。 useHumanInTheLoop合成的处理函数必须调用respond(result)(包括拒绝路径),否则 Agent 运行会挂起。在Executing状态之外,respond为undefined。在 Executing 中途卸载会放弃该次运行。- 在 Intelligence 模式之外,
useThreads会报错'Runtime URL is not configured'。 useAgent返回{ agent, isReady }。当isReady为false时,agent是一个临时替身,会在/info解析完成后被替换为真实实例——agent会改变引用,所有依赖它的 effect 都会重新运行。切勿在以agent为键的 effect 内初始化应用状态(关联映射、进行中请求记录)。- React 的
key会丢弃其下方的所有状态。key={activeAgent}/key={threadId}应放在真正拥有该状态的最小子树上——放在布局级 provider 上会静默清除无关的应用状态,而在接入 Intelligence 后,线程 id 会在挂载后异步变化,因此它会在交互中途触发。 v1 → v2迁移重命名:useCopilotAction→useFrontendTool+useHumanInTheLoop;imageUploadsEnabled→attachments。请参见v1-to-v2-migration生命周期技能。
首次阅读者的阅读顺序
provider-setup— 挂载 provider。chat-components— 接入聊天界面。agent-access— 与 Agent 通信。client-side-tools+rendering-tool-calls— 添加工具调用 UI。- 根据你的功能需求阅读其他任何内容。
评论
支持 Markdown