消息列表
传入 messages 即可默认渲染 Chat Message 与 MessagePart,不需要手写循环或查找表。每条消息必须有稳定、唯一的 messageId 和可读 author;正文放在 parts,对齐、状态、元信息和操作沿用 Message 的字段。
默认使用 actionsVisibility="auto":消息序列最后一条的操作与时间常驻,较早消息的整组 footer 在桌面 hover/focus 时出现。尾部是用户消息时,不会错误地让上一条助手回复继续常驻。always 让每条 footer 常驻,hover 让非必要 footer 按需出现;触屏和键盘仍能访问。单条 message.actionsVisibility、message.latest 可覆盖列表默认策略。生成停止、错误恢复等必要动作不被隐藏。
这里只展示一个会话内的消息,不包含会话导航、标题栏或输入框。Conversation / Thread 描述一段会话;多会话导航与这里的消息序列是不同的展示对象。
组合输入框
与 Chat Composer 并列即可组成 Chat。标题栏和外框由此示例组合,不是列表的内置 UI。示例只模拟本地回复。
默认正文列最大 48rem;列表提供两侧 surface 留白。共同祖先的 --qk-chat-content-width 可调整阅读宽度,Composer 外侧保留相同留白即可对齐。
跟随与历史阅读
初次挂载跟随底部;上滚阅读后暂停追尾,“回到最新”恢复跟随。hasOlder 显示历史入口;收到 loadOlder 时同步设置 loadingOlder,完成后 prepend 数据,失败则解除 pending 以重试。
height 默认 24rem,100% 要求父容器有确定高度。实例方法 scrollToMessage(messageId) 定位并暂停跟随,缺失返回 false;scrollToLatest() 恢复跟随。conversationId 改变时重建消息子树并返回底部,不保存跨会话阅读位置。
示例显示消息编号、总数和操作反馈。清空后可以直接追加或生成新回复;“重置示例”才恢复初始记录。 加载历史图片时保持阅读位置,用“查看图片”定位。清空、重置和切换会话会取消尚未完成的演示请求。
接入自己的数据
业务角色、事件和协议由宿主投影为展示字段,UI 不导入特定 AI SDK。不要使用数组下标作为消息或 Part 身份。
text/reasoning/tool-input/tool-output/custom 插槽替换对应 Part 的内容;message({ message, index, latest, actionsVisibility }) 替换整条消息,此时自定义组件使用解析后的操作策略并自行连接事件。
默认 Message 的 action/branchChange/copy/copyError 事件携带 messageId 转发。列表不执行重试、分支持久化或分页请求。列表只按消息顺序判定 latest,不推断业务角色或有无操作;更特殊的回合策略由宿主通过 message.latest 指定。
本组件不虚拟化消息,不解析 Markdown。Chat 组件可从 @quirekit/ui/vue/chat 或 @quirekit/ui/vue 导入;类型从 @quirekit/ui 导入。样式与主题配置见开始使用。
API
QuireChatMessageList Props
Slots 内容位置
message替换默认 Message;自定义组件事件由消费端连接。
{ /** 当前消息的中立展示数据。 */ message: { /** 会话内唯一、非空且稳定的身份;不要使用数组下标。 */ messageId: string; /** 可见发送者名称,也是 article 的辅助名称。 */ author: string; /** 逻辑起始/结束位置,随 RTL 方向变化。 */ align?: undefined | "start" | "end"; /** plain 用于正文;soft 为短消息提供轻背景。 */ variant?: undefined | "soft" | "plain"; /** 是否显示作者行,默认 false;隐藏时仍保留 article 的辅助名称。 */ showHeader?: boolean | undefined; /** 宿主格式化的尾部时间或次要说明。 */ meta?: undefined | string; /** 有序稳定 Part;default slot 存在时由该 slot 接管内容。 */ parts?: undefined | readonly ({ /** 正文判别项。 */ kind: "text"; /** 原始内容,默认安全转义并保留换行。 */ text: string; /** plain 为默认值;markdown 无 renderer 时显示带说明的源文本。 */ format?: "plain" | "markdown" | undefined; /** 内容接收状态,默认 complete。 */ state?: QuireKitChatPartState | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** 推理判别项。 */ kind: "reasoning"; /** 标题;省略时使用语言包中的默认标题。 */ title?: string | undefined; /** 可选单行摘要,不由 UI 猜测或定时生成。 */ summary?: string | undefined; /** 宿主提供的耗时等次要文案。 */ meta?: string | undefined; /** 完整推理文本。 */ text: string; /** 推理状态,默认 complete;不会改变用户的展开选择。 */ state?: QuireKitChatPartState | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** 工具判别项。 */ kind: "tool"; /** 可读工具名称。 */ title: string; /** 公共 Icon 名称,默认 terminal;由宿主表达读取、编辑、图片等工具类别。 */ icon?: string | undefined; /** 一行任务摘要。 */ summary?: string | undefined; /** 耗时等由宿主提供的元信息。 */ meta?: string | undefined; /** 权威展示状态,不能根据 output 是否存在猜测。 */ state: QuireKitChatToolState; /** 自定义状态文案,例如具体等待原因。 */ stateLabel?: string | undefined; /** 可选原始输入文本。 */ input?: string | undefined; /** 可选原始输出文本。 */ output?: string | undefined; /** 输入代码语言标签,默认 text。 */ inputLanguage?: string | undefined; /** 输出代码语言标签,默认 text。 */ outputLanguage?: string | undefined; /** 可读错误说明;不替换已有输出。 */ error?: string | undefined; /** 仅提供部分输出时必须传入的截断说明;默认禁止复制不完整输出。 */ outputTruncated?: string | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** 提示判别项。 */ kind: "notice"; /** 可见标题。 */ title: string; /** 补充说明。 */ description?: string | undefined; /** 语义色,默认 neutral;不会隐式改变整条消息状态。 */ color?: QuireKitAlertColor | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** 扩展判别项,未知业务类型应显式投影到这里。 */ kind: "custom"; /** 扩展内容的可读名称。 */ name: string; /** 无 renderer 时显示的安全回退文本,不自动转储 data。 */ fallback: string; /** 不透明业务数据,仅转交自定义 slot。 */ data?: unknown; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** 附件判别项;一个 Part 可展示一组相关附件。 */ kind: "attachment"; /** 公共附件投影,保留每个附件的稳定身份。 */ items: readonly QuireKitAttachmentItem[]; /** 默认 list;图片集合可使用 grid,紧凑上下文可用 inline。 */ layout?: QuireKitAttachmentLayout | undefined; /** 集合辅助名称。 */ label?: string | undefined; /** 是否允许图片预览,默认 true。 */ preview?: boolean | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** Source list discriminator. */ kind: "sources"; /** Ordered source projections; retrieval and access control stay with the host. */ sources: readonly QuireKitSource[]; /** Optional disclosure title. */ title?: string | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; } | { /** Approval Part discriminator. */ kind: "confirmation"; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; /** Stable request identity, distinct from message or tool identity. */ requestId: string; /** Action the user is being asked to authorize. */ title: string; /** Concise scope or consequence of the action. */ description?: string | undefined; /** Host-owned state; clicks never imply approval. */ state: QuireKitChatConfirmationState; /** Failure reason, retained while the same request can be retried. */ error?: string | undefined; /** Wording of the decision; defaults to `permission`. */ intent?: QuireKitChatConfirmationIntent | undefined; } | { /** Question Part discriminator. */ kind: "question"; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: readonly QuireKitChatAction[] | undefined; /** Stable request identity; a change resets only the component's uncontrolled draft. */ requestId: string; /** Request title. */ title: string; /** Optional introductory text. */ description?: string | undefined; /** Ordered, stable questions. */ questions: readonly QuireKitChatQuestionItem[]; /** Host-owned lifecycle. */ state: QuireKitChatQuestionState; /** Render answer controls or a compact transcript prompt; defaults to form. */ presentation?: QuireKitChatQuestionPresentation | undefined; /** Controlled answer draft, independent of the ordinary Composer draft. */ draft?: readonly QuireKitChatQuestionAnswer[] | undefined; /** Initial uncontrolled answer draft. */ defaultDraft?: readonly QuireKitChatQuestionAnswer[] | undefined; /** Confirmed answers shown in the answered state. */ answers?: readonly QuireKitChatQuestionAnswer[] | undefined; /** Submission error, shown without clearing the draft. */ error?: string | undefined; })[]; /** 整条消息的展示状态,不从 Part 状态推断。 */ state?: undefined | "error" | "pending" | "complete" | "streaming" | "stopped"; /** 覆盖当前状态的可读说明,error 时可解释恢复方式。 */ statusText?: string | undefined; /** 权威复制原文;省略时不显示内置复制,不从 DOM 提取。 */ copyText?: string | undefined; /** 消息级操作;组件只发 intent,执行由宿主负责。 */ actions?: readonly QuireKitChatAction[] | undefined; /** 受控分支;数量不足二时不渲染导航。 */ branch?: undefined | { /** 有序、唯一、非空的分支身份。 */ ids: readonly string[]; /** 由宿主确认的当前分支。 */ selectedId: string; }; /** auto 默认:最新消息的操作与时间常驻,历史 footer 在桌面 hover/focus 时显示;触屏常驻。 */ actionsVisibility?: undefined | "always" | "auto" | "hover"; /** 是否为最新消息,默认 true;由消费者投影,不扫描会话。 */ latest?: boolean | undefined; }; /** 当前显示顺序;不可作为持久身份。 */ index: number; /** 当前项是否为消息序列最后一条,显式 message.latest 优先。 */ latest: boolean; /** 列表策略与单条消息覆盖后的操作展示模式。 */ actionsVisibility: "always" | "auto" | "hover"; }empty无消息时的内容。
anytext正文/Markdown renderer。
{ part: { /** 正文判别项。 */ kind: "text"; /** 原始内容,默认安全转义并保留换行。 */ text: string; /** plain 为默认值;markdown 无 renderer 时显示带说明的源文本。 */ format?: undefined | "plain" | "markdown"; /** 内容接收状态,默认 complete。 */ state?: undefined | "error" | "complete" | "streaming" | "stopped"; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: undefined | readonly ({ /** 在所属操作组内稳定且唯一的标识。 */ id: string; /** 可见名称或图标操作的辅助名称。 */ label: string; /** IconProvider 中的图标名;省略时显示文字按钮。 */ icon?: string | undefined; /** 明确不可执行时禁用。 */ disabled?: boolean | undefined; /** 宿主正在处理此操作;阻止重复触发。 */ busy?: boolean | undefined; /** 内联反馈/开关类操作的受控按下状态;有此状态的操作保持内联。 */ pressed?: boolean | undefined; /** 需要危险语义的操作。 */ danger?: boolean | undefined; /** inline 留在操作栏,more 放进紧凑的公共 Menu。 */ placement?: "inline" | "more" | undefined; /** 消息级默认 settled,Part 级默认 always;active 用于停止,always 用于必要恢复/确认。 */ when?: "settled" | "active" | "always" | undefined; })[]; }; }reasoning推理详情 renderer;展开行为仍由 Part 持有。
{ part: { /** 推理判别项。 */ kind: "reasoning"; /** 标题;省略时使用语言包中的默认标题。 */ title?: undefined | string; /** 可选单行摘要,不由 UI 猜测或定时生成。 */ summary?: string | undefined; /** 宿主提供的耗时等次要文案。 */ meta?: string | undefined; /** 完整推理文本。 */ text: string; /** 推理状态,默认 complete;不会改变用户的展开选择。 */ state?: undefined | "error" | "complete" | "streaming" | "stopped"; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: undefined | readonly ({ /** 在所属操作组内稳定且唯一的标识。 */ id: string; /** 可见名称或图标操作的辅助名称。 */ label: string; /** IconProvider 中的图标名;省略时显示文字按钮。 */ icon?: string | undefined; /** 明确不可执行时禁用。 */ disabled?: boolean | undefined; /** 宿主正在处理此操作;阻止重复触发。 */ busy?: boolean | undefined; /** 内联反馈/开关类操作的受控按下状态;有此状态的操作保持内联。 */ pressed?: boolean | undefined; /** 需要危险语义的操作。 */ danger?: boolean | undefined; /** inline 留在操作栏,more 放进紧凑的公共 Menu。 */ placement?: "inline" | "more" | undefined; /** 消息级默认 settled,Part 级默认 always;active 用于停止,always 用于必要恢复/确认。 */ when?: "settled" | "active" | "always" | undefined; })[]; }; }tool-input工具参数 renderer。
{ part: { /** 工具判别项。 */ kind: "tool"; /** 可读工具名称。 */ title: string; /** 公共 Icon 名称,默认 terminal;由宿主表达读取、编辑、图片等工具类别。 */ icon?: undefined | string; /** 一行任务摘要。 */ summary?: string | undefined; /** 耗时等由宿主提供的元信息。 */ meta?: string | undefined; /** 权威展示状态,不能根据 output 是否存在猜测。 */ state: "failed" | "queued" | "running" | "waiting" | "succeeded" | "cancelled" | "interrupted"; /** 自定义状态文案,例如具体等待原因。 */ stateLabel?: string | undefined; /** 可选原始输入文本。 */ input?: string | undefined; /** 可选原始输出文本。 */ output?: string | undefined; /** 输入代码语言标签,默认 text。 */ inputLanguage?: string | undefined; /** 输出代码语言标签,默认 text。 */ outputLanguage?: string | undefined; /** 可读错误说明;不替换已有输出。 */ error?: string | undefined; /** 仅提供部分输出时必须传入的截断说明;默认禁止复制不完整输出。 */ outputTruncated?: string | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: undefined | readonly ({ /** 在所属操作组内稳定且唯一的标识。 */ id: string; /** 可见名称或图标操作的辅助名称。 */ label: string; /** IconProvider 中的图标名;省略时显示文字按钮。 */ icon?: string | undefined; /** 明确不可执行时禁用。 */ disabled?: boolean | undefined; /** 宿主正在处理此操作;阻止重复触发。 */ busy?: boolean | undefined; /** 内联反馈/开关类操作的受控按下状态;有此状态的操作保持内联。 */ pressed?: boolean | undefined; /** 需要危险语义的操作。 */ danger?: boolean | undefined; /** inline 留在操作栏,more 放进紧凑的公共 Menu。 */ placement?: "inline" | "more" | undefined; /** 消息级默认 settled,Part 级默认 always;active 用于停止,always 用于必要恢复/确认。 */ when?: "settled" | "active" | "always" | undefined; })[]; }; }tool-output工具输出 renderer,包括业务预览或审批组合。
{ part: { /** 工具判别项。 */ kind: "tool"; /** 可读工具名称。 */ title: string; /** 公共 Icon 名称,默认 terminal;由宿主表达读取、编辑、图片等工具类别。 */ icon?: undefined | string; /** 一行任务摘要。 */ summary?: string | undefined; /** 耗时等由宿主提供的元信息。 */ meta?: string | undefined; /** 权威展示状态,不能根据 output 是否存在猜测。 */ state: "failed" | "queued" | "running" | "waiting" | "succeeded" | "cancelled" | "interrupted"; /** 自定义状态文案,例如具体等待原因。 */ stateLabel?: string | undefined; /** 可选原始输入文本。 */ input?: string | undefined; /** 可选原始输出文本。 */ output?: string | undefined; /** 输入代码语言标签,默认 text。 */ inputLanguage?: string | undefined; /** 输出代码语言标签,默认 text。 */ outputLanguage?: string | undefined; /** 可读错误说明;不替换已有输出。 */ error?: string | undefined; /** 仅提供部分输出时必须传入的截断说明;默认禁止复制不完整输出。 */ outputTruncated?: string | undefined; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: undefined | readonly ({ /** 在所属操作组内稳定且唯一的标识。 */ id: string; /** 可见名称或图标操作的辅助名称。 */ label: string; /** IconProvider 中的图标名;省略时显示文字按钮。 */ icon?: string | undefined; /** 明确不可执行时禁用。 */ disabled?: boolean | undefined; /** 宿主正在处理此操作;阻止重复触发。 */ busy?: boolean | undefined; /** 内联反馈/开关类操作的受控按下状态;有此状态的操作保持内联。 */ pressed?: boolean | undefined; /** 需要危险语义的操作。 */ danger?: boolean | undefined; /** inline 留在操作栏,more 放进紧凑的公共 Menu。 */ placement?: "inline" | "more" | undefined; /** 消息级默认 settled,Part 级默认 always;active 用于停止,always 用于必要恢复/确认。 */ when?: "settled" | "active" | "always" | undefined; })[]; }; }custom扩展内容 renderer,不存在时保留可读回退。
{ part: { /** 扩展判别项,未知业务类型应显式投影到这里。 */ kind: "custom"; /** 扩展内容的可读名称。 */ name: string; /** 无 renderer 时显示的安全回退文本,不自动转储 data。 */ fallback: string; /** 不透明业务数据,仅转交自定义 slot。 */ data?: unknown; /** 消息内唯一、非空的稳定 ID,跨 chunk 和终态保持。 */ id: string; /** 可选的局部操作。 */ actions?: undefined | readonly ({ /** 在所属操作组内稳定且唯一的标识。 */ id: string; /** 可见名称或图标操作的辅助名称。 */ label: string; /** IconProvider 中的图标名;省略时显示文字按钮。 */ icon?: string | undefined; /** 明确不可执行时禁用。 */ disabled?: boolean | undefined; /** 宿主正在处理此操作;阻止重复触发。 */ busy?: boolean | undefined; /** 内联反馈/开关类操作的受控按下状态;有此状态的操作保持内联。 */ pressed?: boolean | undefined; /** 需要危险语义的操作。 */ danger?: boolean | undefined; /** inline 留在操作栏,more 放进紧凑的公共 Menu。 */ placement?: "inline" | "more" | undefined; /** 消息级默认 settled,Part 级默认 always;active 用于停止,always 用于必要恢复/确认。 */ when?: "settled" | "active" | "always" | undefined; })[]; }; }
Events 组件事件
action[details: QuireKitChatActionDetails]copy[details: QuireKitChatMessageListCopyDetails]copyError[details: QuireKitChatMessageListCopyErrorDetails]loadOlder[]followingChange[following: boolean]attachmentAction[details: QuireKitChatAttachmentActionDetails]sourceNavigate[details: QuireKitChatSourceNavigateDetails]confirmationDecision[details: QuireKitChatConfirmationDecisionDetails]questionDraftChange[details: QuireKitChatQuestionDraftDetails]questionOpen[details: QuireKitChatQuestionOpenPartDetails]questionSubmit[details: QuireKitChatQuestionSubmitPartDetails]branchChange[details: QuireKitChatBranchChangeDetails]
公开实例成员
scrollToLatest跳到底部并恢复跟随,不移动焦点。
() => voidscrollToMessage按 key 定位并暂停跟随;不存在时返回 false。
(messageId: string) => boolean