tool-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTool UI
Tool UI
Use this skill to move from request to working Tool UI integration quickly.
Prefer assistant-ui when the project has no existing chat UI/runtime. Treat assistant-ui as optional when the app already has a working runtime.
使用本技能可快速将需求转化为可用的Tool UI集成方案。
如果项目尚无现成的聊天UI/运行时,优先使用assistant-ui;若应用已有可用的运行时,则assistant-ui为可选组件。
Workflow
工作流程
- Run compatibility and doctor checks.
- Find candidate components or bundles.
- Install selected components.
- Generate scaffolds and integrate runtime wiring.
- Validate behavior and troubleshoot failures.
- 运行兼容性检查与诊断。
- 查找候选组件或组件包。
- 安装选定的组件。
- 生成脚手架并集成运行时连接。
- 验证行为并排查故障。
Step 1: Compatibility and Doctor
步骤1:兼容性检查与诊断
bash
python scripts/tool_ui_compat.py --project <repo-root>
python scripts/tool_ui_compat.py --project <repo-root> --doctorAuto-fix missing registry entry:
@tool-uibash
python scripts/tool_ui_compat.py --project <repo-root> --fixMinimum requirements:
- exists.
components.json - exists (typically
components.json.aliases.utils).@/lib/utils - equals
components.json.registries["@tool-ui"].https://tool-ui.com/r/{name}.json
bash
python scripts/tool_ui_compat.py --project <repo-root>
python scripts/tool_ui_compat.py --project <repo-root> --doctor自动修复缺失的注册表条目:
@tool-uibash
python scripts/tool_ui_compat.py --project <repo-root> --fix最低要求:
- 存在文件。
components.json - 存在(通常为
components.json.aliases.utils)。@/lib/utils - 的值等于
components.json.registries["@tool-ui"]。https://tool-ui.com/r/{name}.json
Step 2: Discover Components
步骤2:发现组件
Use intent-first discovery:
bash
python scripts/tool_ui_components.py list
python scripts/tool_ui_components.py find "<use case keywords>"
python scripts/tool_ui_components.py bundle
python scripts/tool_ui_components.py bundle planning-flowReferences:
references/components-catalog.mdreferences/recipes.md
基于需求意图进行组件查找:
bash
python scripts/tool_ui_components.py list
python scripts/tool_ui_components.py find "<use case keywords>"
python scripts/tool_ui_components.py bundle
python scripts/tool_ui_components.py bundle planning-flow参考文档:
references/components-catalog.mdreferences/recipes.md
Step 3: Install Components
步骤3:安装组件
Generate install command:
bash
python scripts/tool_ui_components.py install <component-id> [component-id...]Default install pattern:
bash
npx shadcn@latest add https://tool-ui.com/r/<component-id>.json生成安装命令:
bash
python scripts/tool_ui_components.py install <component-id> [component-id...]默认安装方式:
bash
npx shadcn@latest add https://tool-ui.com/r/<component-id>.jsonStep 4: Scaffold and Integrate
步骤4:生成脚手架与集成
Generate wiring snippet:
bash
python scripts/tool_ui_scaffold.py --mode assistant-backend --component plan
python scripts/tool_ui_scaffold.py --mode assistant-frontend --component option-list
python scripts/tool_ui_scaffold.py --mode manual --component stats-displayUse integration patterns for final adaptation:
references/integration-patterns.md
生成连接代码片段:
bash
python scripts/tool_ui_scaffold.py --mode assistant-backend --component plan
python scripts/tool_ui_scaffold.py --mode assistant-frontend --component option-list
python scripts/tool_ui_scaffold.py --mode manual --component stats-display使用集成模式完成最终适配:
references/integration-patterns.md
Step 5: Validate and Troubleshoot
步骤5:验证与故障排查
After integration:
- Run typecheck/lint.
- Trigger a real tool call.
- Confirm UI renders and interactions complete expected flow.
If broken, use:
references/troubleshooting.md
集成完成后:
- 运行类型检查/代码扫描。
- 触发一次真实的工具调用。
- 确认UI可正常渲染且交互能完成预期流程。
若出现问题,可参考:
references/troubleshooting.md
Action Model
动作模型
Tool UI uses two action surfaces, rendered as compound siblings outside the display component:
- : non-consequential side effects (export, copy, open link). Handlers must not call
ToolUI.LocalActions.addResult(...) - : consequential choices that produce a
ToolUI.DecisionActionsenvelope viaDecisionResult. The commit callback callscreateDecisionResult(...).addResult(...)
Compound wrapper pattern for display components with actions:
tsx
<ToolUI id={surfaceId}>
<ToolUI.Surface><DataTable {...props} /></ToolUI.Surface>
<ToolUI.Actions>
<ToolUI.LocalActions
actions={[{ id: "export-csv", label: "Export CSV" }]}
onAction={(actionId) => { /* side effects only */ }}
/>
</ToolUI.Actions>
</ToolUI>Three components are action-centric exceptions — they keep embedded action props instead of sibling surfaces. All three share a unified interface:
- : action buttons rendered by the component.
actions - : runs after the action and receives post-action state.
onAction(actionId, state) - : guard evaluated before an action runs.
onBeforeAction(actionId, state)
| Component | State type passed to handlers |
|---|---|
| |
| |
| |
ESLint enforces this model:
- — bans legacy
no-embedded-response-actions/responseActionsprops.onResponseAction - — prevents
no-add-result-in-local-actionsinside LocalActions handlers.addResult() - — requires
decision-actions-require-envelopein DecisionActions handlers.createDecisionResult(...)
Tool UI使用两个动作层,作为复合兄弟元素渲染在展示组件外部:
- :无影响的副作用操作(导出、复制、打开链接)。处理函数不得调用
ToolUI.LocalActions。addResult(...) - :会产生实际影响的选择操作,需通过
ToolUI.DecisionActions生成createDecisionResult(...)信封。提交回调需调用DecisionResult。addResult(...)
带动作的展示组件的复合包装模式:
tsx
<ToolUI id={surfaceId}>
<ToolUI.Surface><DataTable {...props} /></ToolUI.Surface>
<ToolUI.Actions>
<ToolUI.LocalActions
actions={[{ id: "export-csv", label: "Export CSV" }]}
onAction={(actionId) => { /* side effects only */ }}
/>
</ToolUI.Actions>
</ToolUI>有三个组件是动作中心的例外情况——它们保留嵌入式动作属性而非兄弟层。这三个组件共享统一的接口:
- :组件渲染的动作按钮。
actions - :动作执行后运行,接收动作后的状态。
onAction(actionId, state) - :动作执行前的守卫检查。
onBeforeAction(actionId, state)
| 组件 | 传递给处理函数的状态类型 |
|---|---|
| |
| |
| |
ESLint强制遵循该模型:
- —— 禁止使用旧版
no-embedded-response-actions/responseActions属性。onResponseAction - —— 禁止在LocalActions处理函数中调用
no-add-result-in-local-actions。addResult() - —— 要求在DecisionActions处理函数中使用
decision-actions-require-envelope。createDecisionResult(...)
Schema Boundary
Schema边界
Import from colocated entrypoints, not barrel :
index.tsxtsx
import { DataTable } from "@/components/tool-ui/data-table/data-table";
import { safeParseSerializableDataTable } from "@/components/tool-ui/data-table/schema";
import { ToolUI, createDecisionResult, type Action } from "@/components/tool-ui/shared";从同目录的入口文件导入,而非从桶文件导入:
index.tsxtsx
import { DataTable } from "@/components/tool-ui/data-table/data-table";
import { safeParseSerializableDataTable } from "@/components/tool-ui/data-table/schema";
import { ToolUI, createDecisionResult, type Action } from "@/components/tool-ui/shared";Operational Rules
操作规则
- Install the smallest set of components that solves the request.
- Validate one component first, then scale to multiple components.
- Keep payload schemas serializable and explicit.
- For decision flows, wire with
DecisionActionsand commit viacreateDecisionResult(...).addResult(...) - For display components that need actions, use the compound wrapper with
ToolUI.LocalActions
- 安装满足需求的最小组件集合。
- 先验证单个组件,再扩展到多个组件。
- 保持负载Schema可序列化且明确。
- 对于决策流程,需将与
DecisionActions连接,并通过createDecisionResult(...)提交。addResult(...) - 对于需要动作的展示组件,使用带的复合
LocalActions包装器。ToolUI
Maintainer Notes
维护者说明
Keep component metadata synchronized with Tool UI source:
bash
python scripts/sync_components.pyRun script tests:
bash
python -m unittest discover -s tests -p "test_*.py"保持组件元数据与Tool UI源同步:
bash
python scripts/sync_components.py运行脚本测试:
bash
python -m unittest discover -s tests -p "test_*.py"