组件目录

Collaboration Stream协作消息流

呈现智能体之间的消息、交接和待答问题,支持聚焦参与者的消息、预览附件与明细,以及引用回复和 @ 点名。

npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add collaboration-stream
MCP
Live
Orchestrator
to everyone

安装

在项目根目录运行,安装源码。

npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add collaboration-stream

使用

React
"use client";
import { useState } from "react";import { KalosCollaborationStream, type StreamAgent, type StreamMessage } from "@/components/ui/kalos-collaboration-stream";
const agents: StreamAgent[] = [  { id: "editor", name: "编辑助手", model: "Gemini Flash" },  { id: "reviewer", name: "审核助手" },];
export default function Example() {  const [messages, setMessages] = useState<StreamMessage[]>([    { id: "m1", from: "you", to: "editor", kind: "ask", text: "更新快速开始指南。" },    { id: "m2", from: "editor", to: "reviewer", kind: "handoff", text: "请核对成员邀请流程。",      attachments: [{ label: "onboarding.md", preview: "打开设置,进入成员页面并发送邀请。" }] },  ]);
  return <KalosCollaborationStream    agents={agents}    messages={messages}    task="更新快速开始指南"    live    onSend={({ text, to, replyTo }) => {      const id = crypto.randomUUID();      setMessages(current => [...current, { id, from: "you", to, kind: replyTo ? "reply" : "ask", text, replyTo }]);    }}  />;}

API

属性类型默认值说明
agentsreadonly StreamAgent[]—每项含唯一 id、name,可选 model 和 avatar。列表顺序决定标记图案与颜色,avatar 可以替换像素标记
messagesreadonly StreamMessage[]—按发出顺序传入 id、from、to、kind、text。from 和 to 使用参与者 ID,you 表示自己,to 也支持 all 或多个 ID
messages[].kind"ask" | "reply" | "handoff" | "share" | "question" | "spawn"—交接和待答问题显示对应状态,spawn 显示启动智能体记录。发给你的待答问题可通过 Reply 引用回复,回复后待答标记消失
messages[].at / replyTo / typingstring / string / boolean—时间、回复所引用的消息 ID 和生成状态。引用指向非相邻消息时可以跳转,生成状态结束后以同一 id 更新正文
messages[].attachmentsreadonly StreamAttachment[]—每项含 label,可选 kind、preview 和 meta。字符串预览按类型排版,目录以换行分隔条目,CSV / TSV 首行为表头,Markdown 支持标题和段落。可传 React 节点自定义正文
messages[].detailsStreamDetails—facts 为 { label, value } 数组,items 为 { label, detail?, icon? } 数组。仅有明细的消息会在点选时弹出浮层,点击浮层和气泡之外收起
task / titlestring / string— / Agent chat为消息区域提供可访问名称,task 用于区分多个协作任务
livebooleanfalse显示实时状态并播报新增消息。停留在底部时自动跟随,向上滚动时保留阅读位置,并可通过新消息计数跳转到最新一条
selected / onSelectedChangestring | null / (id: string | null) => void—控制展开明细的消息 ID,null 收起。省略 selected 时由组件管理
focusAgent / onFocusAgentChangestring | null / (id: string | null) => void—聚焦参与者发出或收到的消息,其余消息淡化并保留原位。null 恢复全部消息的亮度。省略 focusAgent 时由组件管理
onSend(message: StreamSend) => void—提供时显示输入区,回调返回 text、to 和可选 replyTo。to 优先使用 @ 点名,其次使用回复对象,默认是 ['all']。由调用方追加消息
placeholderstring请输入任务消息,可@对应智能体普通消息输入框为空时的提示
logosRecord<string, ReactNode>—在正文的指定名称前显示品牌图标,名称及大小写应与正文一致
maxHeight / classNamenumber / string520 / —组件最大高度和根样式类。有输入区时固定高度,消息区独立滚动

键盘操作

← / →
在参与者按钮间移动。Enter 或 Space 聚焦参与者
↑ / ↓
在消息间移动焦点,或在 @ 候选列表中移动
Home / End
在筛选栏或消息区跳到第一项和最后一项
Enter / Space
选中或取消选中消息。有明细时同步打开或关闭浮层。输入框中 Enter 发送,Shift + Enter 换行
@ / Tab
输入 @ 打开参与者候选列表。列表打开时用 Enter 或 Tab 选择候选
Esc
关闭附件预览、点名菜单或回复,也可清除当前消息选择和参与者聚焦