「智能体执行过程」包含在 Pro 里,开通会员后显示预览。
用法
import { ChatAgentRun } from './ChatAgentRun.jsx'
export function BookingRun({ runId }) {
return (
<ChatAgentRun
locale="en"
stage="idle"
// Another kind of task: your options and the plan's lines (the line with option takes the approved one).
options={rooms} // [{ name, detail, price, rating, tag?, image? }]
summary={[{ id: 'room', icon: 'home', label: 'Room', option: true }, { id: 'fee', icon: 'tag', label: 'Service', text: 'Booking fee', price: 4 }]}
currency="USD"
// Resolves when the step is done on the server; a rejection marks it failed with Try again.
onStep={(step) => fetch('/api/runs/' + runId + '/steps/' + step.id, { method: 'POST' })}
onApprove={(room) => fetch('/api/runs/' + runId + '/approve', { method: 'POST', body: JSON.stringify({ room: room.name }) })}
/>
)
}属性
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | 内置文案、示例执行过程和价格所用的语言。 |
task | string | sample | 访客提出的请求,显示在步骤上方。 |
steps | { id, icon, title, running, result, approval?, tool?: { name, input, output } }[] | sample | 按顺序排列的步骤。带 `approval` 的一步会等访客确认;带 `tool` 的可展开查看调用的输入和结果。 |
options | { name, detail, price, rating, tag?, image?, art? }[] | sample | 等待确认的一步提供的选项,点“换一家”依次切换。`image`(图片地址)或 `art`(元素)可替换默认画的小房子。 |
summary | { id, icon?, label, text?, price?, option? }[] | sample | 所有步骤完成后显示的结果,每项一行。`option: true` 的那一行显示访客确认的选项;合计把所有价格相加。`icon` 是 kit 图标名或 train。 |
currency | string | by locale | 所有价格的 ISO 货币代码。 |
stage | 'idle' | 'approval' | 'approval' | 打开时所处的阶段:尚未开始(显示开始按钮),或停在等待确认的那一步。 |
onStep | (step, index) => Promise | — | 执行一步。完成前显示进行中;失败时标为出错并显示重试。 |
onApprove | (option) => Promise | — | 访客确认后带着所选项调用;完成后继续执行剩下的步骤。 |
onStop | () => void | — | 访客停止执行时调用;正在进行的一步会暂停,之后可以继续。 |
loading | boolean | false | 启动时显示执行过程的占位骨架。 |
error | boolean | false | 打开时第二步已失败,并在该步显示重试。 |
labels | object | — | 替换任意内置文案(见 copy.js),如 status、approve、another、failText。 |
className | string | — | 加在根元素上,其他属性也传给根元素。 |
装进你的项目
Pro 包含这个区块的完整源码。复制指令,让你的 Agent 把它安装到项目中。
ChatAgentRun.jsxchat-agent-run.csscopy.jskit.jsxkit.cssui/base-button/ui/copy-button/ui/success-check/ui/agent-status/ui/skeleton-shimmer/tokens.cssREADME.md
区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。
