react-core
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCopilotKit React Core
CopilotKit React Core
@copilotkit/react-coreThis SKILL.md is the index. Read the reference under that matches
your task — do not try to absorb the whole package from this file.
references/@copilotkit/react-core本 SKILL.md 是索引文档。请根据你的任务阅读 下对应的参考文档,不要试图通过本文档掌握整个包的全部内容。
references/Mental model — three shells you compose
心智模型——三个可组合的层级
- Provider shell — at or near the root (inside
CopilotKitProviderfor Next.js App Router). Carries"use client"(orruntimeUrlfor SPA),publicLicenseKey,headers,credentials,properties,onError,debug.showDevConsole - Chat shell — /
CopilotChat/CopilotPopupor a composedCopilotSidebar+ slot primitives (CopilotChatView,CopilotChatInput, etc.). All chat components ship fromCopilotChatMessageView.@copilotkit/react-core/v2does not exist — it's a common hallucination.CopilotPanel - Hook shell — inside any component under the provider, call ,
useAgent,useFrontendTool, etc. Every hook takes optionaluseRenderToolfor agent-scoped registration.{ agentId }
- Provider 层级 — 在应用根节点或接近根节点的位置挂载 (在 Next.js App Router 中需置于
CopilotKitProvider代码块内)。包含"use client"(SPA 模式下使用runtimeUrl)、publicLicenseKey、headers、credentials、properties、onError、debug等配置项。showDevConsole - 聊天组件层级 — 使用 /
CopilotChat/CopilotPopup,或组合使用CopilotSidebar+ 插槽原语(CopilotChatView、CopilotChatInput等)。所有聊天组件均来自CopilotChatMessageView。@copilotkit/react-core/v2不存在——这是常见的误解。CopilotPanel - 钩子层级 — 在 Provider 之下的任何组件中,调用 、
useAgent、useFrontendTool等钩子。每个钩子都可传入可选的useRenderTool参数,以实现 Agent 范围的注册。{ agentId }
When to load which reference
何时加载对应参考文档
| Task | Reference |
|---|---|
Mount | |
Drop in | |
File / image attachments via | |
Client-side debug tooling — | |
Read / subscribe to an agent ( | |
Feature-gate UI on declared agent capabilities ( | |
Build a multi-agent UI (per-panel | |
List / rename / archive / delete durable Intelligence threads ( | |
Register browser-side tools ( | |
Render per-tool UI ( | |
Gate tool execution behind user approval ( | |
Configure dynamic or static suggestion pills ( | |
Render non-chat activity messages ( | |
Inject custom UI before/after specific messages ( | |
| 任务 | 参考文档 |
|---|---|
挂载 | |
引入 | |
通过 | |
客户端调试工具—— | |
读取/订阅 Agent( | |
根据已声明的 Agent 能力对 UI 进行功能管控( | |
构建多 Agent UI(每个面板使用 | |
列出/重命名/归档/删除持久化智能线程( | |
注册浏览器端工具( | |
渲染工具专属 UI( | |
将工具执行置于用户审批流程之后( | |
配置动态或静态建议胶囊( | |
渲染非聊天类活动消息( | |
在特定消息前后注入自定义 UI( | |
Invariants and gotchas (load-once, before any reference)
不变规则与常见陷阱(阅读任何参考文档前请先了解)
- is canonical.
publicLicenseKeyis a deprecated alias — expect it in legacy code.publicApiKey - and
agents__unsafe_dev_onlyare dev-only aliases of each other. Not production-safe. SeeselfManagedAgentsor thepackages/a2ui-rendererlifecycle skill for the supported SPA path.spa-without-runtime - does not exist. v2 chat components ship from
CopilotPanel— notreact-core/v2(v2react-uiis CSS-only).react-ui - No hook exists. Discover agents via
useAgents().copilotkit.subscribe({ onAgentsChanged }) - is a resolver (for custom chat surfaces), not a registration hook. Register with
useRenderToolCall/useRenderTool/useComponent.useDefaultRenderTool - UI-kit detection rule — any or tool-call UI MUST reuse the consumer's shadcn / MUI / Chakra / Ant / Mantine primitives before writing raw JSX. This applies across
render,client-side-tools, andrendering-tool-calls.human-in-the-loop - Tool-call values are camelCase:
status. In-progress args are'inProgress' | 'executing' | 'complete'.Partial<T> - synthesized handler MUST call
useHumanInTheLoop(including reject paths), otherwise the agent run hangs.respond(result)isrespondoutsideundefinedstatus. Unmounting mid-Executing abandons the run.Executing - errors with
useThreadsoutside Intelligence mode.'Runtime URL is not configured' - migration renames:
v1 → v2→useCopilotAction+useFrontendTool;useHumanInTheLoop→imageUploadsEnabled. See theattachmentslifecycle skill.v1-to-v2-migration
- 是标准配置项。
publicLicenseKey是已废弃的别名——仅会在旧代码中出现。publicApiKey - 和
agents__unsafe_dev_only是彼此的开发环境专用别名。不可用于生产环境。如需了解支持的 SPA 路径,请查看selfManagedAgents或packages/a2ui-renderer生命周期技能文档。spa-without-runtime - 不存在。v2 聊天组件来自
CopilotPanel——而非react-core/v2(v2 的react-ui仅提供 CSS)。react-ui - 不存在 钩子。可通过
useAgents()发现 Agent。copilotkit.subscribe({ onAgentsChanged }) - 是一个解析器(用于自定义聊天界面),不是注册钩子。请使用
useRenderToolCall/useRenderTool/useComponent进行注册。useDefaultRenderTool - UI 套件检测规则——任何 或工具调用 UI 必须优先复用用户的 shadcn / MUI / Chakra / Ant / Mantine 原语,再编写原生 JSX。此规则适用于
render、client-side-tools和rendering-tool-calls相关内容。human-in-the-loop - 工具调用的 值采用小驼峰命名:
status。进行中的参数为'inProgress' | 'executing' | 'complete'类型。Partial<T> - 合成的处理函数必须调用
useHumanInTheLoop(包括拒绝路径),否则 Agent 运行会挂起。仅在respond(result)状态下Executing才会存在。执行过程中卸载组件会终止运行。respond - 在智能模式之外使用 会抛出
useThreads错误。'Runtime URL is not configured' - v1 → v2 迁移的重命名:→
useCopilotAction+useFrontendTool;useHumanInTheLoop→imageUploadsEnabled。请查看attachments生命周期技能文档了解详情。v1-to-v2-migration
Reading order for a first-time reader
首次阅读的推荐顺序
- — mount the provider.
provider-setup - — wire a chat surface.
chat-components - — talk to agents.
agent-access - +
client-side-tools— add tool-call UI.rendering-tool-calls - Anything else as your feature requires.
- — 挂载 Provider。
provider-setup - — 配置聊天界面。
chat-components - — 与 Agent 交互。
agent-access - +
client-side-tools— 添加工具调用 UI。rendering-tool-calls - 根据你的功能需求阅读其他文档。