跳转到主内容
AI 组件 · Sidebar
侧边信息栏
展示 AI 场景下的配置和详情信息

使用场景 ​

侧边信息栏主要用于在 AI 场景下,用于信息展示,功能配置。包括 MCP 配置、参考来源、代码预览、富文本预览及编辑等功能

Vue 使用说明:从 @aifuxi/semi-ui-vue/sidebar 子路径引入组件,浏览器构建会自动按需加载默认主题。本页 Vue API 与示例以当前公开实现为准。

代码演示 ​

基础容器 ​

侧边信息栏的基础容器,基础容器是MCP 配置、参考来源、以及侧边消息栏的基础容器。

  • visible 控制显示状态,cancel 事件处理关闭请求
  • title设置标题
  • motion设置是否有展开动画
  • resizable设置宽度是否可伸缩,为 true 时候可通过 minSize,maxSize 设置最小,最大宽度
基础容器示例

MCP 配置 ​

使用 MCPConfigure 进行 MCP 工具的展示、启用/关闭、配置及搜索

  • 通过 options 和 customOptions 设置内置的 MCP 工具和自定义 MCP 工具
  • 通过 visible 设置组件的显示和隐藏, 监听 cancel 事件处理用户关闭行为
  • 监听 status-change 事件处理 MCP 工具的启用/关闭
  • 监听 add-click 事件处理自定义 MCP 页的新增操作
  • 通过 configure-click 监听内置 MCP 工具配置,通过 edit-click 监听自定义 MCP 工具配置

其他 MCPConfigure 的 API 见 MCPConfigureProps

传入 MCP 工具项的类型如下

查看代码 · ts
import type { VNodeChild } from 'vue';

interface MCPOption {
    icon?: VNodeChild;
    label?: string;
    value?: string;
    desc?: VNodeChild;
    active?: boolean;
    disabled?: boolean; 
    configure?: boolean //是否显示配置按钮
}

用例如下:

已激活 MCP 数: 0/2
支持 Semi 的文档、源码搜索,辅助开发
Figma MCP Server 连接Figma与AI开发工具的功能。它通过标准化的模型上下文协MCP),将组件、变量等设计数据和上下文暴露给AI,从而实现从设计稿到代码的智能生成,显著提升开发效率。

参考来源 ​

使用 Annotation 组件可以管理参考来源的展示

  • activeKey 配合 change 事件管理当前展开项
  • info 设置参考来源的具体内容
Semi design introduction
Semi Design is a design system designed1:13:52
Semi Design is a design system designed
Quick start00:56
Quick start
Use components in a modular way
Semi provides esm format dist, and the css of the component is only imported by the corresponding js. When used in Webpack, Rspack, create-react-app or Vite projects, there is no need to configure any compilation items.

代码展示 ​

可通过 Sidebar 中的 CodeItem 展示代码,CodeItem 基于 JsonViewer 以及 CodeHighlight 实现。

  • content: 内容字符串
  • isJson: 是否为 json
  • language: 编程语言名称,同 CodeHighlight 的 language
  • JsonViewerProps: 配置其他 JsonViewer 参数
  • CodeHighlightProps: 配置其他 CodeHighlight 参数

代码列表 ​

用户可通过 Sidebar 中的 CodeContent 组件展示代码列表信息。

Component.vue
<script setup lang="ts">
import { ref } from 'vue';
import { AutoComplete } from '@aifuxi/semi-ui-vue/auto-complete';
const value = ref('');
const data = ref<string[]>([]);
function search(text: string) {
  data.value = text ? ['gmail.com', '163.com', 'qq.com'].map(domain => text + domain) : [];
}
</script>
<template>
  <AutoComplete v-model="value" :data="data" show-clear placeholder="Search..." @search="search" />
</template>

富文本编辑器 ​

可通过 Sidebar 中的 FileItem 查看、编辑富文本内容, FileItem 基于 tiptap 实现。

  • content:富文本内容, 支持类型同 TiptapContent
  • editable: 设置是否可编辑
  • imgUploadProps: 设置图片上传路径以及图片上传后 src 的设置,通过 action 设置上传地址,通过 getUploadImageSrc 函数返回图片上传后地址,用于富文本中 img 节点的 src


Semi Design 介绍

Semi Design 是由 抖音前端团队和MED产品设计团队设计、开发并维护的设计系统。作为一个全面、易用、优质的现代应用UI解决方案,Semi Design从字节跳动各业务线的复杂场景中提炼而来,目前已经支撑了近千个平台产品,服务了内外部超过10万用户,详情见https://semi.design/zh-CN/start/introduction。Semi Design的特点包括:

  • 设计简洁、现代化。
  • 提供主题方案,可深度样式定制。

国际化,覆盖了简/繁体中文、英语、日语、韩语、葡萄牙语等20+种语言,日期时间组件提供全球时区支持,全部组件可自动适配阿拉伯文RTL布局。

body {
  display: none;
}

采用 Foundation 和 Adapter 跨框架技术方案,方便扩展。

Semi Design 是由抖音前端团队和MED产品设计团队设计、开发并维护的设计系统
— Semi Design
<h2> Semi Design 介绍 </h2> <p> Semi Design 是由 <strong>抖音前端团队</strong>和MED产品设计团队设计、开发并维护的<em>设计系统</em>。作为一个全面、易用、优质的现代应用UI解决方案,Semi Design从字节跳动各业务线的复杂场景中提炼而来,目前已经支撑了近千个平台产品,服务了内外部超过10万用户,详情见https://semi.design/zh-CN/start/introduction。Semi Design的特点包括: </p> <ul> <li> 设计简洁、现代化。 </li> <li> 提供主题方案,可深度样式定制。 </li> </ul> <p> 国际化,覆盖了简/繁体中文、英语、日语、韩语、葡萄牙语等20+种语言,日期时间组件提供全球时区支持,全部组件可自动适配阿拉伯文RTL布局。 </p> <pre><code class="language-css">body { display: none; }</code></pre> <p> 采用 Foundation 和 Adapter 跨框架技术方案,方便扩展。 </p> <blockquote> Semi Design 是由抖音前端团队和MED产品设计团队设计、开发并维护的设计系统 <br /> — Semi Design </blockquote>

富文本列表 ​

用户可通过 Sidebar 中的 FileContent 组件展示富文本列表信息。

Semi Design 介绍

Semi Design 介绍

Semi Design 是由 抖音前端团队和MED产品设计团队设计、开发并维护的设计系统。作为一个全面、易用、优质的现代应用UI解决方案,Semi Design从字节跳动各业务线的复杂场景中提炼而来,目前已经支撑了近千个平台产品,服务了内外部超过10万用户,详情见https://semi.design/zh-CN/start/introduction。Semi Design的特点包括:

  • 设计简洁、现代化。
  • 提供主题方案,可深度样式定制。

国际化,覆盖了简/繁体中文、英语、日语、韩语、葡萄牙语等20+种语言,日期时间组件提供全球时区支持,全部组件可自动适配阿拉伯文RTL布局。

body {
  display: none;
}

采用 Foundation 和 Adapter 跨框架技术方案,方便扩展。

Semi Design 是由抖音前端团队和MED产品设计团队设计、开发并维护的设计系统
— Semi Design

Semi Design 是由 抖音前端团队和MED产品设计团队设计、开发并维护的设计系统。作为一个全面、易用、优质的现代应用UI解决方案,Semi Design从字节跳动各业务线的复杂场景中提炼而来,目前已经支撑了近千个平台产品,服务了内外部超过10万用户,详情见https://semi.design/zh-CN/start/introduction。Semi Design的特点包括:

  • 设计简洁、现代化。
  • 提供主题方案,可深度样式定制。

国际化,覆盖了简/繁体中文、英语、日语、韩语、葡萄牙语等20+种语言,日期时间组件提供全球时区支持,全部组件可自动适配阿拉伯文RTL布局。

body {
  display: none;
}

采用 Foundation 和 Adapter 跨框架技术方案,方便扩展。

Semi Design 是由抖音前端团队和MED产品设计团队设计、开发并维护的设计系统
— Semi Design

Semi Design 是由 抖音前端团队和MED产品设计团队设计、开发并维护的设计系统。作为一个全面、易用、优质的现代应用UI解决方案,Semi Design从字节跳动各业务线的复杂场景中提炼而来,目前已经支撑了近千个平台产品,服务了内外部超过10万用户,详情见https://semi.design/zh-CN/start/introduction。Semi Design的特点包括:

  • 设计简洁、现代化。
  • 提供主题方案,可深度样式定制。

国际化,覆盖了简/繁体中文、英语、日语、韩语、葡萄牙语等20+种语言,日期时间组件提供全球时区支持,全部组件可自动适配阿拉伯文RTL布局。

body {
  display: none;
}

采用 Foundation 和 Adapter 跨框架技术方案,方便扩展。

Semi Design 是由抖音前端团队和MED产品设计团队设计、开发并维护的设计系统
— Semi Design

侧边信息栏 ​

侧边信息栏 Sidebar 有主视图(mode 为 main)和详情视图(mode 为 code、text 及其他)。

主视图可以通过 title 配置标题,通过 showClose 决定是否展示关闭按钮,通过 options 设置顶部的按钮组。

对于主视图的内容渲染,可通过 main-content 作用域插槽提供主视图内容;迁移代码也可继续使用 renderMainContent callback prop。可使用 Annotation 中的 AnnotationContent 渲染参考来源,使用 Sidebar 中内置的 FileContent 渲染富文本, CodeContent 渲染代码。

对于详情视图,如果是富文本或者代码,分别设置 mode 为 code、text,通过 detailContent 设置显示内容,即可通过内置的代码显示组件, 富文本编辑器进行显示,如果想要自定义详情视图的展示,则通过 detail-content 作用域插槽自行处理;迁移代码也可继续使用 renderDetailContent callback prop。

工作区占位
Agent 的工作空间
Component.vue
<script setup lang="ts">
import { ref } from 'vue';
import { AutoComplete } from '@aifuxi/semi-ui-vue/auto-complete';
const value = ref('');
const data = ref<string[]>([]);
function search(text: string) {
  data.value = text ? ['gmail.com', '163.com', 'qq.com'].map(domain => text + domain) : [];
}
</script>
<template>
  <AutoComplete v-model="value" :data="data" show-clear placeholder="Search..." @search="search" />
</template>

API 参考 ​

Vue 契约 ​

以下内容以 packages/ui/src/sidebar/types.ts、packages/ui/src/sidebar/index.ts 的公开类型为准。

Vue 用法 ​

  • renderHeader、renderOptionItem、renderMainContent、renderDetailHeader、renderDetailContent 与各 renderItem 是保留的迁移 callback props;Vue 代码优先使用对应插槽。
  • containerRef、MCP filter、SidebarImageUploadOptions.getUploadImageSrc 与 SidebarAnnotationItem.onClick 是真实 callback props,不是组件事件。
  • Sidebar 提供 Container、CodeContent、CodeItem、FileContent、FileItem 静态成员;Annotation 提供 AnnotationContent 静态成员,MCPConfigure 作为具名组件导出。

Vue 实例方法 ​

SidebarContainerExposed

方法签名说明
getContainerElement() => HTMLDivElement | null获取容器元素

Vue 事件 ​

Sidebar.Container

事件参数说明
cancel[event: MouseEvent | KeyboardEvent]点击关闭或按下 Escape
after-visible-change[visible: boolean]显隐动画完成

MCPConfigure

事件参数说明
cancel[event: MouseEvent | KeyboardEvent]点击关闭或按下 Escape
after-visible-change[visible: boolean]显隐动画完成
status-change[options: SidebarMCPOption[], custom: boolean]MCP 状态变化
search[inputValue: string, custom: boolean]搜索输入变化
add-click[event: MouseEvent]点击新增
configure-click[event: MouseEvent, option: SidebarMCPOption]点击配置
edit-click[event: MouseEvent, option: SidebarMCPOption]点击编辑

Annotation

事件参数说明
cancel[event: MouseEvent | KeyboardEvent]点击关闭或按下 Escape
after-visible-change[visible: boolean]显隐动画完成
change[activeKey: SidebarActiveKey]展开项变化
click[event: MouseEvent, item: SidebarAnnotationItem]点击参考来源

Sidebar

事件参数说明
cancel[event: MouseEvent | KeyboardEvent]点击关闭或按下 Escape
after-visible-change[visible: boolean]显隐动画完成
active-option-change[event: MouseEvent, activeKey: string]导航项变化
file-content-change[content: string]详情文件内容变化
back-ward[event: MouseEvent, mode: SidebarMode]返回主视图
detail-content-copy[event: MouseEvent, content: string, result: boolean]复制详情内容

Sidebar.CodeContent

事件参数说明
change[activeKey: SidebarActiveKey]展开项变化
expand[event: MouseEvent, code: SidebarCodeItemProps, mode: 'code']打开代码详情

Sidebar.FileContent

事件参数说明
change[activeKey: SidebarActiveKey]展开项变化
expand[event: MouseEvent, file: SidebarFileItemProps, mode: 'file']打开文件详情

Sidebar.FileItem

事件参数说明
content-change[content: string]富文本内容变化

Vue 插槽 ​

Sidebar.Container

插槽作用域参数说明
default{}容器内容
title{}标题内容
header{}完整自定义头部

Sidebar

插槽作用域参数说明
title{}主视图标题
option{ option: SidebarOption; onChange(event, activeKey): void }导航项
main-content{ activeKey?: string }主视图内容
detail-header{ mode: SidebarMode; detailContent: SidebarProps['detailContent'] }详情头部
detail-content{ mode: SidebarMode }详情内容

Annotation.AnnotationContent

插槽作用域参数说明
item{ annotation: SidebarAnnotationItem }参考来源项

MCPConfigureContent

插槽作用域参数说明
item{ option: SidebarMCPOption; custom: boolean }MCP 配置项

Container ​

属性说明类型默认值
title标题内容;title 插槽优先VNodeChild-
visible是否显示侧边栏booleanfalse
motion是否启用显隐动画booleantrue
minWidth可调整宽度时的最小宽度string | number150
maxWidth可调整宽度时的最大宽度string | number-
resizable是否允许调整宽度booleantrue
defaultSize可调整宽度时的默认尺寸SidebarSize-
showClose是否显示关闭按钮booleantrue
closeOnEsc是否允许按 Escape 请求关闭booleanfalse
classVue class 入口HTMLAttributes['class']—
className兼容 className 入口HTMLAttributes['class']-
style自定义内联样式StyleValue-
renderHeader头部渲染 callback prop;header 插槽优先() => VNodeChild-
containerRef容器元素回调 ref;模板 ref 另暴露 getContainerElement()(element: HTMLDivElement | null) => void-

MCPConfigure ​

支持 Container 的所有参数

属性说明类型默认值
title标题内容;title 插槽优先VNodeChild—
visible是否显示侧边栏booleanfalse
motion是否启用显隐动画booleantrue
minWidth可调整宽度时的最小宽度string | number150
maxWidth可调整宽度时的最大宽度string | number—
resizable是否允许调整宽度booleantrue
defaultSize可调整宽度时的默认尺寸SidebarSize—
showClose是否显示关闭按钮booleantrue
closeOnEsc是否允许按 Escape 请求关闭booleanfalse
classVue class 入口HTMLAttributes['class']—
className兼容 className 入口HTMLAttributes['class']-
style自定义内联样式StyleValue-
renderHeader头部渲染 callback prop;header 插槽优先() => VNodeChild—
containerRef容器元素回调 ref;模板 ref 另暴露 getContainerElement()(element: HTMLDivElement | null) => void—
options基础选项列表SidebarMCPOption[]-
customOptions自定义选项列表SidebarMCPOption[]-
filter筛选函数,用于根据输入值过滤选项(inputValue: string, option: SidebarMCPOption) => boolean-
placeholder输入框占位提示文字string请输入
renderItemMCP 项渲染 callback prop;item 插槽优先(props: { option: SidebarMCPOption; custom: boolean }) => VNodeChild-

SidebarMCPOption ​

属性说明类型默认值
icon图标元素VNodeChild-
label标签文本string-
value对应的值string-
desc描述内容VNodeChild-
active是否处于激活状态booleanfalse
disabled是否禁用,为 true 时用户无法更改配置的激活与否状态booleanfalse
configure是否显示配置相关操作/标识booleanfalse

Annotation ​

支持 Container 的所有参数

属性说明类型默认值
title标题内容;title 插槽优先VNodeChild—
visible是否显示侧边栏booleanfalse
motion是否启用显隐动画booleantrue
minWidth可调整宽度时的最小宽度string | number150
maxWidth可调整宽度时的最大宽度string | number—
resizable是否允许调整宽度booleantrue
defaultSize可调整宽度时的默认尺寸SidebarSize—
showClose是否显示关闭按钮booleantrue
closeOnEsc是否允许按 Escape 请求关闭booleanfalse
classVue class 入口HTMLAttributes['class']—
className兼容 className 入口HTMLAttributes['class']-
style自定义内联样式StyleValue-
renderHeader头部渲染 callback prop;header 插槽优先() => VNodeChild—
containerRef容器元素回调 ref;模板 ref 另暴露 getContainerElement()(element: HTMLDivElement | null) => void—
info注解信息列表,包含头部、键值、参考来源详情等内容SidebarAnnotationGroup[]-
renderItem参考来源渲染 callback prop;item 插槽优先(annotation: SidebarAnnotationItem) => VNodeChild-

AnnotationItem ​

属性说明类型默认值
type内容类型'video' | 'text'-
title内容标题string-
url资源链接,点击参考来源将跳转此地址string-
detail内容详情/补充说明(如视频简介、文本备注等)string-
logo站点/内容所属平台的 logo 图片地址string-
siteName内容所属的站点/平台名称string-
order引用序号(用于内容排序/标注序号展示)number-
img图片地址(如视频封面图、文本配图地址)string-
duration时长(通常为视频时长,单位:秒)number-
onClick数据项点击 callback;未提供 Annotation click 监听器时使用(event: MouseEvent, item: SidebarAnnotationItem) => void-
属性说明类型默认值
title标题内容;title 插槽优先VNodeChild—
visible是否显示侧边栏booleanfalse
motion是否启用显隐动画booleantrue
minWidth可调整宽度时的最小宽度string | number150
maxWidth可调整宽度时的最大宽度string | number—
resizable是否允许调整宽度booleantrue
defaultSize可调整宽度时的默认尺寸SidebarSize—
showClose是否显示关闭按钮booleantrue
closeOnEsc是否允许按 Escape 请求关闭booleanfalse
classVue class 入口HTMLAttributes['class']—
className兼容 className 入口HTMLAttributes['class']-
style自定义内联样式StyleValue-
renderHeader头部渲染 callback prop;header 插槽优先() => VNodeChild—
containerRef容器元素回调 ref;模板 ref 另暴露 getContainerElement()(element: HTMLDivElement | null) => void—
mode主视图、代码、文件或自定义详情模式SidebarModemain
activeKey当前导航项string—
options主视图导航项SidebarOption[]—
detailContent内置 code/file 详情数据SidebarCodeItemProps | SidebarFileItemProps | Record<string, unknown>—
fileEditable文件详情是否可编辑booleantrue
imgUploadProps文件详情中的图片上传配置SidebarImageUploadOptions-
renderOptionItem导航项渲染 callback prop;option 插槽优先( option: SidebarOption, onChange: (event: MouseEvent, activeKey: string) => void, ) => VNodeChild—
renderMainContent主内容渲染 callback prop;main-content 插槽优先(activeKey?: string) => VNodeChild-
renderDetailHeader详情头渲染 callback prop;detail-header 插槽优先( mode: SidebarMode, detailContent: SidebarProps['detailContent'], ) => VNodeChild—
renderDetailContent详情区渲染 callback prop;detail-content 插槽优先(mode: SidebarMode) => VNodeChild-

Code ​

属性说明类型默认值
activeKey当前激活项的标识,支持单个字符串(单选)或字符串数组(多选)SidebarActiveKey-
classVue class 入口HTMLAttributes['class']—
className自定义类名,用于覆盖组件样式HTMLAttributes['class']-
style自定义内联样式StyleValue-
codes代码详情列表SidebarCodeItemProps[]-

CodeItemProps ​

属性说明类型默认值
name展示名称string—
key唯一标识string—
isJson是否使用 JsonViewer 展示boolean-
language代码语言string-
content代码或 JSON 内容string-
jsonViewerPropsJsonViewer 配置JsonViewerProps-
codeHighlightPropsCodeHighlight 配置CodeHighlightProps—

File ​

FileContent ​

属性说明类型默认值
activeKey当前激活项的标识,支持单个字符串(单选)或字符串数组(多选)SidebarActiveKey-
classVue class 入口HTMLAttributes['class']—
className自定义类名,用于覆盖组件样式HTMLAttributes['class']-
style自定义内联样式,用于调整组件样式StyleValue-
files文件信息列表SidebarFileItemProps[]-

FileItemProps ​

属性说明类型默认值
key唯一标识string-
classVue class 入口HTMLAttributes['class']—
className自定义类名HTMLAttributes['class']-
name展示名称string—
style自定义内联样式StyleValue—
editable是否允许编辑booleantrue
content富文本 HTML 内容string-
extensions附加 Tiptap extensionsExtensions-
imgUploadProps富文本图片上传配置SidebarImageUploadOptions-