正在打开每日关注
正在打开每日关注
createChat 用脚本化对话复现流式生命周期,支持 AI 组件预览与确定性测试。
We’re open sourcing @shadcn/helpers, a new package for small, focused utils to help you build and test components faster. Starting with `createChat` for AI SDK and TanStack AI. It lets you script a conversation between a user & assistant then run it through `useChat`. Your components receive native messages through the framework’s real streaming lifecycle. createChat supports reasoning, tool calls, data, files, sources and parts. Use it to build components, previews, scripted demos and deterministic tests.
是什么
推文介绍 createChat:把用户与助手的多轮对话写成可执行脚本,再接入 useChat 的真实流式生命周期,驱动 AI 组件。它可描述消息顺序、等待、推理、工具调用、结构化输出与最终文本。
核心设计
配图展示链式 API 先声明消息,用 sleep(500) 模拟时序;writer 写入 reasoning、调用 getReleaseNotes、输出 highlights,最后写入文本。第二张图将 chat.get(0) 与 chat.transport() 交给 useChat。关键不是伪造静态消息,而是让组件经历框架原生的 streaming lifecycle;同一场景可用于组件开发、预览、演示和确定性回归测试。
关键洞察 它把“对话行为”从 UI 实现中抽离成可复用 fixture,降低复杂 AI 状态的复现成本,并把 reasoning、tool call 等非纯文本部件纳入测试对象。对 Agent 工程来说,这是将模型交互协议转为可控开发数据源。
边界与风险
sleep 只是延迟近似,不能替代真实模型、网络、错误与取消流程测试;确定性也依赖 AI SDK/TanStack AI 适配器对事件顺序和 parts 的处理。落地仍需覆盖异常、中断、并发和多模态内容。