refactor(frontend): remove unused components and share tag selection logic

main
wizardchen 2026-09-16 20:42:33 +08:00 committed by lyingbug
parent d5efe5cedd
commit bfa7f0ed69
19 changed files with 387 additions and 3944 deletions

View File

@ -0,0 +1,113 @@
# 代码瘦身审计与第一批改动
审计日期:2026-09-16。基线:`d5efe5ced`。目标:保留现有功能,减少重复维护和理解成本。
## 扫描范围与口径
- 统计 Git 跟踪的源码物理行数,包含注释、空行;分开统计测试、生成文件、翻译与 i18n 辅助代码。行数用于定位,不作为质量评分。
- 对 `frontend/src` 的 TypeScript 和 Vue script 建立静态 import、re-export、字面量动态 import 依赖图,从 `main.ts`、`embed-main.ts` 两个实际入口遍历;额外检查模板名称、路由、全局组件注册、glob 和构建入口。
- 对 `internal` 下 Go 文件进行 AST 扫描,统计函数长度,寻找包内没有其他标识符引用的非导出自由函数;计入测试文件引用。另对重复代码块、相同函数体进行候选扫描并抽查调用方。
- 检查最近 200 个非 merge commit 的文件变更频率,结合重复程度和状态复杂度排序。
- `cli`、`client`、`docreader`、`mcp-server`、`packages`、`miniprogram` 做体量与结构初筛;本轮没有完成这些子项目的逐函数调用审计。
- 依赖图不是运行时覆盖证明;后端候选未经过所有平台、构建标签和集成测试验证,不等同于可直接删除的清单。
基线体量:
| 范围 | 生产源码行数 | 测试行数 |
| --- | ---: | ---: |
| `frontend/src` | 189,597 | 13,930 |
| `internal` | 319,317 | 181,900 |
前端另有 39,411 行翻译/i18n 辅助代码、693 行生成代码。整个仓库的测试和生成代码不应被当作优先削减对象。
## 第一批已实施
### 删除 10 个不可达组件
两个应用入口均无法到达以下组件;仓库内没有引用其文件路径的测试、脚本或注册入口。Vite 未配置组件自动注册,发现的资源 glob 用于 provider SVG,不会加载这些 Vue 文件。
| 文件(相对 `frontend/src`) | 行数 | 核查结果 |
| --- | ---: | --- |
| `views/settings/StorageEngineSettings.vue` | 1,687 | `Settings.vue` 实际导入 `StorageBackendSettings.vue`;同步修正了旧组件别名 |
| `views/organization/OrganizationEditorModal.vue` | 914 | 组织列表实际使用 `OrganizationSettingsModal.vue` |
| `views/settings/components/McpTestResultBody.vue` | 434 | 没有 import、注册或动态加载入口 |
| `components/SourceSwitcherDropdown.vue` | 163 | 没有 import、注册或动态加载入口 |
| `components/settings/SettingCard.vue` | 152 | 仅剩过时注释提及,注释一并清理 |
| `views/organization/JoinOrganization.vue` | 127 | `/join` 已重定向到组织列表,通过 `invite_code` 处理加入 |
| `components/SessionGroupByDropdown.vue` | 123 | 没有 import、注册或动态加载入口 |
| `views/knowledge/settings/KBIndexingStrategy.vue` | 109 | 没有 import、注册或动态加载入口 |
| `views/chat/components/sendMsg.vue` | 22 | 与仍在使用的 `sendMsg` 函数同名,但组件本身没有入口 |
| `views/platform/RoutePlaceholder.vue` | 7 | 没有路由或组件引用 |
共删除 3,738 行失效组件。它们原本不在应用入口依赖链中,因此这是源码维护收益,不能换算为构建产物缩小比例。
### 合并标签选择与创建逻辑
`TagEditDialog.vue`、`BatchTagDialog.vue` 共享新的 `composables/useKnowledgeTagSelection.ts`:
- 选择集合、名称映射、搜索过滤、切换与清空。
- 打开时恢复父组件选中值,重新打开时清空草稿。
- 创建标签的加载状态、结果处理、错误回调;手动输入沿用精确同名复用规则。
- 接口调用和通知通过参数提供,两个组件保留各自提交、关闭和 loading 行为。
两个弹窗的 template 和 style 与基线逐字节一致。新增 7 项行为测试,覆盖父数据更新、缺失标签 ID、搜索、创建响应、失败重试和实例隔离。
第一批生产源码净减少 **3,819 行**,已计入新增共享逻辑,未把新增测试和本文档计入生产源码。
## 后续优先级
| 优先级 | 证据 | 建议边界 | 验证重点 |
| --- | --- | --- | --- |
| P1 | `SandboxSkillsPanel.vue:1240` 与 `SkillSettings.vue:891` 重复安装模型读取、持久化、错误处理;面板最近 200 个非 merge commit 中变更 10 次 | 提取安装模型配置 composable;先统一这一块,再让面板复用已有 `useConfigSkillInstallProgress` | 默认模型回退、保存失败、同 skill 重试、卸载进度、配置切换与取消订阅 |
| P1 | `useChatCitationPopover.ts` 与 `useEmbedCitationPopover.ts` 重复浮层状态、定位、计时和事件绑定 | 共享交互状态;通过参数提供内容加载、缓存作用域和点击行为 | 普通/嵌入鉴权、缓存隔离、根节点替换、悬停竞争与卸载 |
| P2 | `AgentEditorModal.vue` 6,756 行,其中 script 3,023 行;近期变更 9 次 | 按提示词编辑、知识库选择、工具配置分离状态和表单序列化责任 | 编辑回填、模式切换、保存 payload 保持兼容 |
| P2 | `WikiBrowser.vue` 6,592 行,其中 script 4,086 行;`FAQEntryManager.vue` 5,650 行,其中 style 2,780 行 | 分开文档导航/编辑状态、批量动作与可复用展示区域 | 页面切换后的异步结果、选中项、保存与批量操作 |
| P2 | `knowledge_process.go` 4,091 行;`processChunks` 470 行、`ProcessDocument` 441 行 | 先划分分块入库、摘要、问题生成、重解析阶段的输入与输出,再抽函数 | 任务归属、取消、失败回写、重试与索引状态 |
| P2 | `wiki_ingest_batch.go` 的 `ProcessWikiIngest` 718 行、`mapOneDocument` 446 行、`reduceSlugUpdates` 422 行 | 分离任务协调、单文档处理、页面归并;保留现有检查点 | 删除 KB、重复投递、部分失败、并发归并 |
| P2 | `internal/im/service.go` 3,493 行,`handleMessageStream` 450 行 | 按通道生命周期、请求准备、流式回复拆责任 | completion/error 顺序、取消、最终持久化与平台发送失败 |
这些条目的行号、长度和变更频率是本次基线快照。仅按长度分文件不会自动降低复杂度,验收应检查状态归属和业务规则是否集中。
### 后端重复的具体判断
- Qdrant 与 Weaviate 的 `tokenizeQuery` 函数体相同,但只有 Qdrant 的关键字检索调用它;Weaviate 使用 `WithQuery(params.Query)`。后续应验证并删除 Weaviate 的失效函数,而非为了它增加共享分词层。
- IMA、语雀的 `sanitizeFileName` 函数体相同,可以共享;RSS 的近似实现另外处理首尾空白和换行,合并时必须保留这些差异。
- Milvus/Qdrant/Weaviate 的结果映射体相似,但接收不同后端类型。当前各约 17 行,为此引入通用接口或泛型转换层未必减少维护成本。
- 终端和桌面 WebSocket ticket handler 重复检查会话、用户、租户和 token,但签发方式不同。后续可共享前置身份校验,保留 ticket 和连接生命周期各自的契约。
- 资源权限已经有 `internal/application/access`;继续沿已有授权边界收敛,避免新建与其并行的权限工具层。
### 未引用 Go 私有自由函数候选
扫描发现 16 个,第一批暂未改动后端。后续逐包确认调用、构建入口和测试后处理:
| 文件(相对 `internal`) | 函数 |
| --- | --- |
| `application/repository/retriever/weaviate/repository.go` | `tokenizeQuery` |
| `im/wechat/crypto.go` | `encryptAES128ECB` |
| `application/repository/retriever/milvus/filter.go` | `formatValue` |
| `agent/tools/todo_write.go` | `getStringArrayField`、`getStringField` |
| `agent/prompts.go` | `formatFileSize` |
| `utils/inject.go` | `extractTableAliasMap` |
| `application/service/wiki_ingest_dedup.go` | `countEntityConceptPages` |
| `agent/tools/sandbox_ls.go` | `relativeSkillFileFromImagePath` |
| `infrastructure/docparser/json_converter.go` | `indentJSON` |
| `handler/knowledge.go` | `mimeTypeByExt` |
| `application/service/tenant_skill_source.go` | `normalizeFetchedSkillArchive` |
| `sandbox/gateway_transport.go` | `newGatewayDataTransport` |
| `application/service/knowledge_process.go` | `buildSplitterConfig` |
| `im/service.go` | `imLocalStorageBaseDir` |
| `handler/session/helpers.go` | `getRequestID` |
## 测试维护与验证结果
抽查发现,标签弹窗、安装进度的部分测试通过正则检查源码文本;IM 部分流式测试使用镜像状态结构,同时也存在直接调用生产路径的退出/投递测试。重构时应逐步补真实行为覆盖,不应只调整正则或同时修改两份镜像逻辑来获得通过。
第一批验证:
- 修改前 `npm run type-check` 通过,作为类型检查基线。
- 11 项定向测试通过,其中 7 项是新增行为测试。
- `scripts/verify_frontend_pr.sh` 完整通过:907 项测试、`vue-tsc --build`、Vite 生产构建。
- 构建仍报告大 chunk 提示;本轮未以 bundle 体积为目标,也没有测量构建前后的体积差异。
- 未修改后端,未运行后端测试;未做浏览器视觉验收。
下一批优先处理 Skill 安装模型配置与进度重复。涉及聊天、任务重试、权限或共享状态的改动应单独成批,以可验证的行为等价为边界。

View File

@ -1,123 +0,0 @@
<template>
<t-popup
v-model:visible="visible"
trigger="click"
placement="bottom-left"
:overlay-style="{ padding: 0 }"
:overlay-inner-style="{ padding: 0 }"
>
<template #content>
<div class="session-group-card">
<div class="session-group-header">{{ headerLabel }}</div>
<div class="session-group-list">
<button
v-for="item in modes"
:key="item.value"
type="button"
class="session-group-row"
:class="{ active: item.value === current }"
@click="handleSelect(item.value)"
>
<span class="session-group-row-name">{{ item.label }}</span>
<t-icon
v-if="item.value === current"
name="check"
class="session-group-row-check"
size="14px"
/>
</button>
</div>
</div>
</template>
<slot />
</t-popup>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SessionGroupMode } from './sessionGrouping'
interface GroupModeItem {
value: SessionGroupMode
label: string
}
defineProps<{
modes: GroupModeItem[]
current: SessionGroupMode
headerLabel: string
}>()
const emit = defineEmits<{
(e: 'select', value: SessionGroupMode): void
}>()
const visible = ref(false)
const handleSelect = (value: SessionGroupMode): void => {
visible.value = false
emit('select', value)
}
</script>
<style scoped lang="less">
.session-group-card {
min-width: 180px;
max-width: 240px;
display: flex;
flex-direction: column;
padding: 0;
overflow: hidden;
}
.session-group-header {
padding: 8px 12px 6px;
font-size: 11px;
font-weight: 600;
color: var(--td-text-color-placeholder);
border-bottom: 1px solid var(--td-component-border);
user-select: none;
}
.session-group-list {
padding: 6px;
display: flex;
flex-direction: column;
gap: 1px;
}
.session-group-row {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border: none;
border-radius: 6px;
background: transparent;
color: var(--td-text-color-primary);
font-size: 13px;
line-height: 1.4;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease;
text-align: left;
width: 100%;
&:hover {
background: var(--td-bg-color-secondarycontainer);
}
&.active {
color: var(--td-brand-color);
font-weight: 500;
}
}
.session-group-row-name {
flex: 1 1 auto;
}
.session-group-row-check {
flex: 0 0 auto;
color: var(--td-brand-color);
}
</style>

View File

@ -1,163 +0,0 @@
<template>
<t-popup
v-model:visible="visible"
trigger="click"
placement="bottom-left"
:overlay-style="{ padding: 0 }"
:overlay-inner-style="{ padding: 0 }"
>
<template #content>
<div class="source-switcher-card">
<div class="source-switcher-list">
<button
v-for="item in sortedList"
:key="item.value"
type="button"
class="source-switcher-row"
:class="{ active: item.value === current }"
@click="handleSelect(item.value)"
>
<img
v-if="item.logo"
:src="item.logo"
:alt="item.label"
class="source-switcher-row-logo"
/>
<t-icon
v-else
name="user"
class="source-switcher-row-icon"
size="16px"
/>
<span class="source-switcher-row-name" :title="item.label">{{ item.label }}</span>
<t-icon
v-if="item.value === current"
name="check"
class="source-switcher-row-check"
size="14px"
/>
</button>
</div>
</div>
</template>
<slot />
</t-popup>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
// A dumb scope switcher mirroring KBSwitcherDropdown's visual grammar. Logos are
// pre-resolved by the caller; web (no logo) falls back to a generic icon.
interface SourceItem {
value: string
label: string
logo?: string
}
const props = defineProps<{
sources: SourceItem[]
current: string
}>()
const emit = defineEmits<{
(e: 'select', value: string): void
}>()
// t-popup only closes on outside click; selecting an item must close it
// explicitly, otherwise the panel lingers and overlays the list below
// (switching source reloads in place, so nothing else dismisses it).
const visible = ref(false)
// Pin the current source to the top so users always see "where they are" without
// scrolling — same as KBSwitcherDropdown. The rest keeps the caller's order
// (web first, then configured platforms).
const sortedList = computed<SourceItem[]>(() => {
const all = props.sources || []
const current = all.find((s) => s.value === props.current)
if (!current) return all
return [current, ...all.filter((s) => s.value !== props.current)]
})
const handleSelect = (value: string): void => {
visible.value = false
if (value === props.current) return
emit('select', value)
}
</script>
<style scoped lang="less">
/* Mirrors KBSwitcherDropdown so both scope switchers stay visually identical. */
.source-switcher-card {
min-width: 200px;
max-width: 300px;
max-height: min(60vh, 420px);
display: flex;
flex-direction: column;
padding: 6px;
overflow: hidden;
}
.source-switcher-list {
flex: 1 1 auto;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 1px;
}
.source-switcher-row {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border: none;
border-radius: 6px;
background: transparent;
color: var(--td-text-color-primary);
font-size: 13px;
line-height: 1.4;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease;
text-align: left;
&:hover {
background: var(--td-bg-color-secondarycontainer);
}
&.active {
background: var(--td-brand-color-light, rgba(0, 82, 217, 0.08));
color: var(--td-brand-color);
font-weight: 500;
}
}
.source-switcher-row-logo {
flex: 0 0 auto;
width: 16px;
height: 16px;
border-radius: 3px;
object-fit: contain;
}
.source-switcher-row-icon {
flex: 0 0 auto;
color: var(--td-text-color-placeholder);
.source-switcher-row.active & {
color: var(--td-brand-color);
}
}
.source-switcher-row-name {
flex: 1 1 auto;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.source-switcher-row-check {
flex: 0 0 auto;
color: var(--td-brand-color);
}
</style>

View File

@ -1,152 +0,0 @@
<template>
<div class="setting-card" :class="{ 'setting-card--disabled': disabled }">
<div class="setting-card__header">
<h3 class="setting-card__title" :title="title">{{ title }}</h3>
<div class="setting-card__header-right">
<slot name="controls" />
<t-dropdown
v-if="actions && actions.length > 0"
:options="actions"
placement="bottom-right"
attach="body"
@click="(data: any) => emit('action', data.value)"
>
<t-button variant="text" shape="square" size="small" class="setting-card__more">
<t-icon name="more" />
</t-button>
</t-dropdown>
</div>
</div>
<div v-if="$slots.tags" class="setting-card__tags">
<slot name="tags" />
</div>
<p v-if="description" class="setting-card__desc">{{ description }}</p>
<div v-if="$slots.meta" class="setting-card__meta">
<slot name="meta" />
</div>
</div>
</template>
<script setup lang="ts">
interface DropdownOption {
content: string
value: string
theme?: 'default' | 'success' | 'warning' | 'error' | 'primary'
}
interface Props {
title: string
description?: string
disabled?: boolean
actions?: DropdownOption[]
}
withDefaults(defineProps<Props>(), {
description: '',
disabled: false,
actions: () => []
})
const emit = defineEmits<{
(e: 'action', value: string): void
}>()
</script>
<style lang="less" scoped>
.setting-card {
display: flex;
flex-direction: column;
gap: 8px;
padding: 16px;
border: 1px solid var(--td-component-stroke);
border-radius: 8px;
background: var(--td-bg-color-container);
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
min-width: 0;
&:hover {
border-color: var(--td-brand-color);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
&--disabled {
background: var(--td-bg-color-secondarycontainer);
.setting-card__title {
color: var(--td-text-color-secondary);
}
&:hover {
border-color: var(--td-brand-color-light);
box-shadow: none;
}
}
}
.setting-card__header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
min-width: 0;
}
.setting-card__title {
flex: 1;
min-width: 0;
margin: 0;
font-size: 15px;
font-weight: 600;
line-height: 1.4;
color: var(--td-text-color-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.setting-card__header-right {
display: flex;
align-items: center;
gap: 4px;
flex-shrink: 0;
}
.setting-card__more {
color: var(--td-text-color-placeholder);
padding: 4px;
&:hover {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-primary);
}
}
.setting-card__tags {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
min-height: 20px;
}
.setting-card__desc {
margin: 0;
font-size: 13px;
line-height: 1.5;
color: var(--td-text-color-secondary);
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-all;
}
.setting-card__meta {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
font-size: 12px;
color: var(--td-text-color-placeholder);
}
</style>

View File

@ -0,0 +1,149 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { effectScope, nextTick, ref } from 'vue'
import { useKnowledgeTagSelection, type KnowledgeTag } from './useKnowledgeTagSelection.ts'
function harness(createTag: Parameters<typeof useKnowledgeTagSelection>[0]['createTag'] = async () => {
throw new Error('unexpected creation')
}) {
const visible = ref(false)
const kbId = ref('kb-a')
const tags = ref<KnowledgeTag[]>([{ id: 'a', name: 'Alpha' }, { id: 'b', name: 'Beta' }])
const selectedIds = ref(['a'])
const errors: unknown[] = []
let created = 0
const scope = effectScope()
const selection = scope.run(() => useKnowledgeTagSelection({
visible: () => visible.value,
kbId: () => kbId.value,
tags: () => tags.value,
selectedIds: () => selectedIds.value,
createTag,
onCreated: () => { created++ },
onError: error => errors.push(error),
}))!
return { selection, visible, kbId, tags, selectedIds, errors, created: () => created, stop: () => scope.stop() }
}
test('opening hydrates selection and reopening discards edits using the latest parent values', async (t) => {
const h = harness()
t.after(h.stop)
h.visible.value = true
await nextTick()
assert.deepEqual([...h.selection.selectedSet.value], ['a'])
h.selection.toggleTag('b')
h.selection.searchQuery.value = 'draft search'
h.selection.newTagName.value = 'draft tag'
h.selectedIds.value = ['b']
await nextTick()
assert.deepEqual([...h.selection.selectedSet.value], ['a', 'b'], 'parent refresh must not overwrite an open draft')
h.visible.value = false
await nextTick()
h.visible.value = true
await nextTick()
assert.deepEqual([...h.selection.selectedSet.value], ['b'])
assert.equal(h.selection.searchQuery.value, '')
assert.equal(h.selection.newTagName.value, '')
})
test('search excludes selected tags, tracks refreshed names, and preserves IDs absent from the current list', async (t) => {
const h = harness()
t.after(h.stop)
h.selectedIds.value = ['a', 'not-loaded']
h.visible.value = true
await nextTick()
assert.deepEqual(h.selection.selectedTagsList.value.map(tag => tag.id), ['a'])
assert.deepEqual([...h.selection.selectedSet.value], ['a', 'not-loaded'])
h.selection.searchQuery.value = ' BETA '
assert.deepEqual(h.selection.availableTagsList.value.map(tag => tag.id), ['b'])
h.selection.toggleTag('b')
assert.deepEqual(h.selection.availableTagsList.value, [])
h.selection.toggleTag('b')
h.tags.value = [{ id: 'a', name: 'Renamed' }, { id: 'b', name: 'Gamma' }]
assert.equal(h.selection.selectedTagsList.value[0]?.name, 'Renamed')
assert.deepEqual(h.selection.availableTagsList.value, [])
h.selection.searchQuery.value = ''
h.selection.clearAll()
assert.equal(h.selection.selectedSet.value.size, 0)
assert.equal(h.selection.availableTagsList.value.length, 2)
})
test('search creation uses the current KB, selects the returned tag and clears only the search input', async (t) => {
const requests: [string, { name: string }][] = []
const h = harness(async (kbId, data) => {
requests.push([kbId, data])
return { data: { id: 'new', name: data.name } }
})
t.after(h.stop)
h.kbId.value = 'kb-b'
h.selection.searchQuery.value = ' New tag '
h.selection.newTagName.value = 'separate draft'
await h.selection.handleCreateTag()
assert.deepEqual(requests, [['kb-b', { name: 'New tag' }]])
assert.deepEqual([...h.selection.selectedSet.value], ['new'])
assert.equal(h.selection.searchQuery.value, '')
assert.equal(h.selection.newTagName.value, 'separate draft')
assert.equal(h.created(), 1)
assert.equal(h.selection.creatingTag.value, false)
h.tags.value.push({ id: 'new', name: 'New tag' })
assert.equal(h.selection.selectedTagsList.value[0]?.name, 'New tag')
})
test('manual entry reuses an exact existing name without creating or announcing a new tag', async (t) => {
const h = harness()
t.after(h.stop)
h.selection.newTagName.value = ' Alpha '
await h.selection.handleAddNewTag()
assert.deepEqual([...h.selection.selectedSet.value], ['a'])
assert.equal(h.selection.newTagName.value, '')
assert.equal(h.created(), 0)
assert.deepEqual(h.errors, [])
})
test('manual creation accepts an unwrapped response without clearing a separate search', async (t) => {
const h = harness(async (_, data) => ({ id: 'new', name: data.name }))
t.after(h.stop)
h.selection.newTagName.value = 'New'
h.selection.searchQuery.value = 'retained search'
await h.selection.handleAddNewTag()
assert.deepEqual([...h.selection.selectedSet.value], ['new'])
assert.equal(h.selection.newTagName.value, '')
assert.equal(h.selection.searchQuery.value, 'retained search')
assert.equal(h.created(), 1)
})
test('failed creation preserves the draft and selection, releases loading and permits retry', async (t) => {
let reject!: (error: Error) => void
const h = harness(() => new Promise((_, rejectRequest) => { reject = rejectRequest }))
t.after(h.stop)
h.selection.toggleTag('a')
h.selection.newTagName.value = 'retry me'
const pending = h.selection.handleAddNewTag()
assert.equal(h.selection.creatingTag.value, true)
const failure = new Error('denied')
reject(failure)
await pending
assert.equal(h.selection.creatingTag.value, false)
assert.equal(h.selection.newTagName.value, 'retry me')
assert.deepEqual([...h.selection.selectedSet.value], ['a'])
assert.deepEqual(h.errors, [failure])
assert.equal(h.created(), 0)
const retry = h.selection.handleAddNewTag()
assert.equal(h.selection.creatingTag.value, true)
reject(failure)
await retry
assert.equal(h.errors.length, 2)
})
test('empty inputs do not create tags and dialogs keep independent selection state', async (t) => {
const first = harness(), second = harness()
t.after(first.stop)
t.after(second.stop)
first.selection.searchQuery.value = ' '
first.selection.newTagName.value = ' '
await first.selection.handleCreateTag()
await first.selection.handleAddNewTag()
assert.deepEqual(first.errors, [])
first.selection.toggleTag('a')
assert.equal(second.selection.selectedSet.value.size, 0)
})

View File

@ -0,0 +1,89 @@
import { computed, ref, watch, type Ref } from 'vue'
export interface KnowledgeTag {
id: string
name: string
color?: string
knowledge_count?: number
}
interface TagSelectionOptions {
visible: () => boolean
kbId: () => string
tags: () => KnowledgeTag[]
selectedIds: () => string[]
createTag: (kbId: string, data: { name: string }) => Promise<KnowledgeTag | { data: KnowledgeTag }>
onCreated: () => void
onError: (error: unknown) => void
}
/** Shared selection and creation state; each dialog owns its submit/close behavior. */
export function useKnowledgeTagSelection(options: TagSelectionOptions) {
const searchQuery = ref('')
const newTagName = ref('')
const selectedSet = ref(new Set<string>())
const creatingTag = ref(false)
watch(options.visible, (visible) => {
if (visible) {
selectedSet.value = new Set(options.selectedIds())
searchQuery.value = ''
newTagName.value = ''
}
})
const tagMap = computed(() => new Map(options.tags().map(tag => [tag.id, tag])))
const selectedTagsList = computed(() => Array.from(selectedSet.value)
.map(id => tagMap.value.get(id))
.filter((tag): tag is KnowledgeTag => Boolean(tag)))
const availableTagsList = computed(() => {
const query = searchQuery.value.trim().toLowerCase()
return options.tags().filter(tag => !selectedSet.value.has(tag.id)
&& (!query || (tag.name || '').toLowerCase().includes(query)))
})
function selectTag(id: string) {
selectedSet.value = new Set([...selectedSet.value, id])
}
function toggleTag(id: string) {
const next = new Set(selectedSet.value)
if (next.has(id)) next.delete(id)
else next.add(id)
selectedSet.value = next
}
function clearAll() {
selectedSet.value = new Set()
}
async function createFrom(input: Ref<string>, reuseExisting: boolean) {
const name = input.value.trim()
if (!name) return
const existing = reuseExisting && options.tags().find(tag => tag.name === name)
if (existing) {
selectTag(existing.id)
input.value = ''
return
}
creatingTag.value = true
try {
const response = await options.createTag(options.kbId(), { name })
const tag = 'data' in response ? response.data : response
selectTag(tag.id)
input.value = ''
options.onCreated()
} catch (error) {
options.onError(error)
} finally {
creatingTag.value = false
}
}
return {
searchQuery, newTagName, selectedSet, creatingTag, selectedTagsList, availableTagsList,
toggleTag, clearAll,
handleCreateTag: () => createFrom(searchQuery, false),
handleAddNewTag: () => createFrom(newTagName, true),
}
}

View File

@ -1,22 +0,0 @@
<template>
<div>
<t-textarea resize="none" :autosize="false" v-model="value" :placeholder="$t('chat.enterDescription')" name="description" @change="onChange" />
</div>
</template>
<script setup>
import { onMounted, watch, computed, ref, reactive } from 'vue';
import { useI18n } from 'vue-i18n';
const value = ref('');
const { t } = useI18n();
const onChange = (value,e) => {
console.log(value)
}
</script>
<style lang="less">
.chat {
width: 800px;
font-size: 20px;
margin: 0px auto
}
</style>

View File

@ -87,17 +87,11 @@
</template>
<script setup lang="ts">
import { ref, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { MessagePlugin } from 'tdesign-vue-next';
import { createKnowledgeBaseTag } from '@/api/knowledge-base';
interface Tag {
id: string;
name: string;
color?: string;
knowledge_count?: number;
}
import { useKnowledgeTagSelection, type KnowledgeTag as Tag } from '@/composables/useKnowledgeTagSelection';
const props = defineProps<{
visible: boolean;
@ -118,101 +112,22 @@ const emit = defineEmits<{
const { t } = useI18n();
const searchQuery = ref('');
const selectedSet = ref<Set<string>>(new Set());
const creatingTag = ref(false);
const newTagName = ref('');
watch(
() => props.visible,
(val) => {
if (val) {
selectedSet.value = new Set(props.preSelectedTagIds ?? []);
searchQuery.value = '';
newTagName.value = '';
}
const {
searchQuery, newTagName, selectedSet, creatingTag, selectedTagsList, availableTagsList,
toggleTag, clearAll, handleCreateTag, handleAddNewTag,
} = useKnowledgeTagSelection({
visible: () => props.visible,
kbId: () => props.kbId,
tags: () => props.tagList,
selectedIds: () => props.preSelectedTagIds ?? [],
createTag: createKnowledgeBaseTag,
onCreated: () => {
emit('tag-created');
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
},
);
const tagMap = computed(() => new Map(props.tagList.map((tag) => [tag.id, tag])));
const selectedTagsList = computed(() => {
return Array.from(selectedSet.value)
.map((id) => tagMap.value.get(id))
.filter((tag): tag is Tag => Boolean(tag));
onError: (error: any) => MessagePlugin.error(error?.message || t('common.operationFailed')),
});
const availableTagsList = computed(() => {
const query = searchQuery.value.trim().toLowerCase();
return props.tagList.filter((tag) => {
if (selectedSet.value.has(tag.id)) return false;
if (query && !(tag.name || '').toLowerCase().includes(query)) return false;
return true;
});
});
function toggleTag(tagId: string) {
const next = new Set(selectedSet.value);
if (next.has(tagId)) {
next.delete(tagId);
} else {
next.add(tagId);
}
selectedSet.value = next;
}
function clearAll() {
selectedSet.value = new Set();
}
async function handleCreateTag() {
const name = searchQuery.value.trim();
if (!name) return;
creatingTag.value = true;
try {
const res: any = await createKnowledgeBaseTag(props.kbId, { name });
const newTag = res?.data || res;
const next = new Set(selectedSet.value);
next.add(newTag.id);
selectedSet.value = next;
searchQuery.value = '';
emit('tag-created');
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
} catch (error: any) {
MessagePlugin.error(error?.message || t('common.operationFailed'));
} finally {
creatingTag.value = false;
}
}
async function handleAddNewTag() {
const name = newTagName.value.trim();
if (!name) return;
const exists = props.tagList.find((t) => t.name === name);
if (exists) {
const next = new Set(selectedSet.value);
next.add(exists.id);
selectedSet.value = next;
newTagName.value = '';
return;
}
creatingTag.value = true;
try {
const res: any = await createKnowledgeBaseTag(props.kbId, { name });
const newTag = res?.data || res;
const next = new Set(selectedSet.value);
next.add(newTag.id);
selectedSet.value = next;
newTagName.value = '';
emit('tag-created');
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
} catch (error: any) {
MessagePlugin.error(error?.message || t('common.operationFailed'));
} finally {
creatingTag.value = false;
}
}
function handleConfirm() {
if (props.confirmLoading) return;
emit('confirm', Array.from(selectedSet.value));

View File

@ -87,17 +87,12 @@
</template>
<script setup lang="ts">
import { ref, computed, watch } from 'vue';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { MessagePlugin } from 'tdesign-vue-next';
import { createKnowledgeBaseTag } from '@/api/knowledge-base';
interface Tag {
id: string;
name: string;
color?: string;
knowledge_count?: number;
}
import { useKnowledgeTagSelection, type KnowledgeTag as Tag } from '@/composables/useKnowledgeTagSelection';
const props = defineProps<{
visible: boolean;
@ -117,101 +112,23 @@ const emit = defineEmits<{
const { t } = useI18n();
const searchQuery = ref('');
const selectedSet = ref<Set<string>>(new Set());
const creatingTag = ref(false);
const saving = ref(false);
const newTagName = ref('');
watch(
() => props.visible,
(val) => {
if (val) {
selectedSet.value = new Set(props.selectedTags.map((t) => t.id));
searchQuery.value = '';
newTagName.value = '';
}
const {
searchQuery, newTagName, selectedSet, creatingTag, selectedTagsList, availableTagsList,
toggleTag, clearAll, handleCreateTag, handleAddNewTag,
} = useKnowledgeTagSelection({
visible: () => props.visible,
kbId: () => props.kbId,
tags: () => props.tagList,
selectedIds: () => props.selectedTags.map(tag => tag.id),
createTag: createKnowledgeBaseTag,
onCreated: () => {
emit('tag-created');
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
},
);
const tagMap = computed(() => new Map(props.tagList.map((tag) => [tag.id, tag])));
const selectedTagsList = computed(() => {
return Array.from(selectedSet.value)
.map((id) => tagMap.value.get(id))
.filter((tag): tag is Tag => Boolean(tag));
onError: (error: any) => MessagePlugin.error(error?.message || t('common.operationFailed')),
});
const availableTagsList = computed(() => {
const query = searchQuery.value.trim().toLowerCase();
return props.tagList.filter((tag) => {
if (selectedSet.value.has(tag.id)) return false;
if (query && !(tag.name || '').toLowerCase().includes(query)) return false;
return true;
});
});
function toggleTag(tagId: string) {
const next = new Set(selectedSet.value);
if (next.has(tagId)) {
next.delete(tagId);
} else {
next.add(tagId);
}
selectedSet.value = next;
}
function clearAll() {
selectedSet.value = new Set();
}
async function handleCreateTag() {
const name = searchQuery.value.trim();
if (!name) return;
creatingTag.value = true;
try {
const res: any = await createKnowledgeBaseTag(props.kbId, { name });
const newTag = res?.data || res;
const next = new Set(selectedSet.value);
next.add(newTag.id);
selectedSet.value = next;
searchQuery.value = '';
emit('tag-created');
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
} catch (error: any) {
MessagePlugin.error(error?.message || t('common.operationFailed'));
} finally {
creatingTag.value = false;
}
}
async function handleAddNewTag() {
const name = newTagName.value.trim();
if (!name) return;
const exists = props.tagList.find((t) => t.name === name);
if (exists) {
const next = new Set(selectedSet.value);
next.add(exists.id);
selectedSet.value = next;
newTagName.value = '';
return;
}
creatingTag.value = true;
try {
const res: any = await createKnowledgeBaseTag(props.kbId, { name });
const newTag = res?.data || res;
const next = new Set(selectedSet.value);
next.add(newTag.id);
selectedSet.value = next;
newTagName.value = '';
emit('tag-created');
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
} catch (error: any) {
MessagePlugin.error(error?.message || t('common.operationFailed'));
} finally {
creatingTag.value = false;
}
}
const saving = ref(false);
async function handleConfirm() {
saving.value = true;

View File

@ -2773,7 +2773,7 @@ const drawerConfirmText = computed(() => {
</style>
<!--
Drawer header logo — same white badge as list cards / StorageEngineSettings.
Drawer header logo — same white badge as the data-source list cards.
-->
<style lang="less">
.datasource-editor-drawer .setting-drawer__header-icon:has(.datasource-header-icon__img) {

View File

@ -1,109 +0,0 @@
<template>
<div class="kb-multimodal-settings">
<div class="section-header">
<h2>{{ $t('knowledgeEditor.indexing.title') }}</h2>
<p class="section-description">{{ $t('knowledgeEditor.indexing.description') }}</p>
</div>
<div class="settings-group">
<!-- Hybrid Search (vector + keyword combined) -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('knowledgeEditor.indexing.searchTitle') }}</label>
<p class="desc">{{ $t('knowledgeEditor.indexing.searchDesc') }}</p>
</div>
<div class="setting-control">
<t-switch
:model-value="searchEnabled"
@change="handleSearchToggle"
size="medium"
/>
</div>
</div>
<!-- Wiki -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('knowledgeEditor.indexing.wikiTitle') }}</label>
<p class="desc">{{ $t('knowledgeEditor.indexing.wikiDesc') }}</p>
</div>
<div class="setting-control">
<t-switch
:model-value="modelValue.wikiEnabled"
@change="(val: boolean) => update('wikiEnabled', val)"
size="medium"
/>
</div>
</div>
<!-- Wiki sub-settings (inline when enabled) -->
<template v-if="modelValue.wikiEnabled">
<slot name="wiki-settings" />
</template>
<!-- Knowledge Graph -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('knowledgeEditor.indexing.graphTitle') }}</label>
<p class="desc">{{ $t('knowledgeEditor.indexing.graphDesc') }}</p>
</div>
<div class="setting-control">
<t-switch
:model-value="modelValue.graphEnabled"
@change="(val: boolean) => update('graphEnabled', val)"
size="medium"
/>
</div>
</div>
<!-- Graph sub-settings (inline when enabled) -->
<template v-if="modelValue.graphEnabled">
<slot name="graph-settings" />
</template>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
export interface IndexingStrategy {
vectorEnabled: boolean
keywordEnabled: boolean
wikiEnabled: boolean
graphEnabled: boolean
}
const props = defineProps<{
modelValue: IndexingStrategy
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: IndexingStrategy): void
}>()
// Search = vector + keyword combined (the system always uses hybrid search internally)
const searchEnabled = computed(() => props.modelValue.vectorEnabled || props.modelValue.keywordEnabled)
const handleSearchToggle = (val: boolean) => {
emit('update:modelValue', {
...props.modelValue,
vectorEnabled: val,
keywordEnabled: val,
})
}
const update = (field: keyof IndexingStrategy, value: boolean) => {
emit('update:modelValue', {
...props.modelValue,
[field]: value,
})
}
</script>
<style lang="less">
/* NOT scoped — these classes must match the parent modal's scoped styles.
Since slot content is rendered in the parent scope, only the wrapper
elements defined HERE need their own styles. We replicate the same
design tokens used by .kb-multimodal-settings in the parent. */
</style>

View File

@ -1,127 +0,0 @@
<template>
<div class="join-page">
<div class="join-card">
<div class="join-icon">
<t-icon name="user-add" size="48px" />
</div>
<h2 class="join-title">{{ $t('organization.join.title') }}</h2>
<p v-if="loading" class="join-message">{{ $t('organization.join.joining') }}</p>
<p v-else-if="error" class="join-message error">{{ error }}</p>
<p v-else class="join-message success">{{ $t('organization.join.success') }}</p>
<t-button
v-if="!loading"
theme="primary"
@click="goToOrganizations"
>
{{ $t('organization.join.goToOrganizations') }}
</t-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { MessagePlugin } from 'tdesign-vue-next'
import { useOrganizationStore } from '@/stores/organization'
import { useAuthStore } from '@/stores/auth'
const route = useRoute()
const router = useRouter()
const { t } = useI18n()
const orgStore = useOrganizationStore()
const authStore = useAuthStore()
const loading = ref(true)
const error = ref('')
onMounted(async () => {
const code = route.query.code as string
if (!code) {
error.value = t('organization.join.noCode')
loading.value = false
return
}
// 后端 POST /organizations/join 要求当前空间角色 ≥ admin,先在前端拦截以给出友好提示
if (!authStore.hasRole('admin') && !authStore.canAccessAllTenants) {
error.value = t('organization.rbac.cannotJoin')
loading.value = false
return
}
try {
const result = await orgStore.join(code)
if (result) {
MessagePlugin.success(t('organization.join.success'))
} else {
error.value = orgStore.error || t('organization.join.failed')
}
} catch (e: any) {
error.value = e?.message || t('organization.join.failed')
} finally {
loading.value = false
}
})
const goToOrganizations = () => {
router.push('/platform/organizations')
}
</script>
<style scoped lang="less">
.join-page {
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: var(--td-bg-color-container);
padding: 20px;
}
.join-card {
background: var(--td-bg-color-container);
border-radius: 16px;
padding: 48px;
text-align: center;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
max-width: 400px;
width: 100%;
}
.join-icon {
width: 80px;
height: 80px;
margin: 0 auto 24px;
border-radius: 50%;
background: var(--td-success-color-light);
display: flex;
align-items: center;
justify-content: center;
color: var(--td-success-color);
}
.join-title {
font-size: 20px;
font-weight: 600;
color: var(--td-text-color-primary);
margin: 0 0 16px;
}
.join-message {
font-size: 14px;
color: var(--td-text-color-secondary);
margin: 0 0 24px;
&.error {
color: var(--td-error-color);
}
&.success {
color: var(--td-success-color);
}
}
</style>

View File

@ -1,914 +0,0 @@
<template>
<Teleport to="body">
<Transition name="modal">
<div v-if="visible" class="settings-overlay" @click.self="handleClose">
<div class="settings-modal" :class="{ 'join-mode': mode === 'join' }">
<!-- 关闭按钮 -->
<button class="close-btn" @click="handleClose" :aria-label="$t('common.close')">
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
<path d="M15 5L5 15M5 5L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
</button>
<div class="settings-container">
<!-- 左侧导航 -->
<div class="settings-sidebar">
<div class="sidebar-header">
<h2 class="sidebar-title">{{ modalTitle }}</h2>
</div>
<div class="settings-nav">
<div
v-for="(item, index) in navItems"
:key="index"
:class="['nav-item', { 'active': currentSection === item.key }]"
@click="currentSection = item.key"
>
<t-icon :name="item.icon" class="nav-icon" />
<span class="nav-label">{{ item.label }}</span>
</div>
</div>
</div>
<!-- 右侧内容区域 -->
<div class="settings-content">
<div class="content-wrapper">
<!-- 创建组织 - 基本信息 -->
<div v-if="mode === 'create'" v-show="currentSection === 'basic'" class="section">
<div class="section-content">
<div class="section-header">
<h3 class="section-title">{{ $t('organization.editor.basicTitle') }}</h3>
<p class="section-desc">{{ $t('organization.editor.basicDesc') }}</p>
</div>
<div class="section-body">
<div class="form-item">
<label class="form-label required">{{ $t('organization.name') }}</label>
<div class="name-input-wrapper">
<SpaceAvatar :name="createForm.name || '?'" size="medium" />
<t-input
v-model="createForm.name"
:placeholder="$t('organization.namePlaceholder')"
:maxlength="100"
class="name-input"
/>
</div>
<p class="form-tip">{{ $t('organization.editor.nameTip') }}</p>
</div>
<div class="form-item">
<label class="form-label">{{ $t('organization.description') }}</label>
<t-textarea
v-model="createForm.description"
:placeholder="$t('organization.descriptionPlaceholder')"
:maxlength="500"
:autosize="{ minRows: 3, maxRows: 6 }"
/>
<p class="form-tip">{{ $t('organization.editor.descriptionTip') }}</p>
</div>
</div>
</div>
</div>
<!-- 创建组织 - 权限说明 -->
<div v-if="mode === 'create'" v-show="currentSection === 'permissions'" class="section">
<div class="section-content">
<div class="section-header">
<h3 class="section-title">{{ $t('organization.editor.permissionsTitle') }}</h3>
<p class="section-desc">{{ $t('organization.editor.permissionsDesc') }}</p>
</div>
<div class="section-body">
<div class="permissions-info">
<div class="permission-card">
<div class="permission-header">
<div class="permission-icon admin">
<t-icon name="user-safety" />
</div>
<div class="permission-title">
<span class="role-name">{{ $t('organization.role.admin') }}</span>
<t-tag size="small" theme="primary">{{ $t('organization.editor.fullAccess') }}</t-tag>
</div>
</div>
<ul class="permission-list">
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.adminPerm1') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.adminPerm2') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.adminPerm3') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.adminPerm4') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.useSharedAgentsPerm') }}</li>
</ul>
</div>
<div class="permission-card">
<div class="permission-header">
<div class="permission-icon editor">
<t-icon name="edit" />
</div>
<div class="permission-title">
<span class="role-name">{{ $t('organization.role.editor') }}</span>
<t-tag size="small" theme="warning">{{ $t('organization.editor.editAccess') }}</t-tag>
</div>
</div>
<ul class="permission-list">
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.editorPerm1') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.editorPerm2') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.useSharedAgentsPerm') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.shareKBPerm') }}</li>
<li><t-icon name="close" class="close-icon" />{{ $t('organization.editor.editorPerm3') }}</li>
</ul>
</div>
<div class="permission-card">
<div class="permission-header">
<div class="permission-icon viewer">
<t-icon name="browse" />
</div>
<div class="permission-title">
<span class="role-name">{{ $t('organization.role.viewer') }}</span>
<t-tag size="small">{{ $t('organization.editor.viewAccess') }}</t-tag>
</div>
</div>
<ul class="permission-list">
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.viewerPerm1') }}</li>
<li><t-icon name="check" class="check-icon" />{{ $t('organization.editor.useSharedAgentsPerm') }}</li>
<li><t-icon name="close" class="close-icon" />{{ $t('organization.editor.shareKBPerm') }}</li>
<li><t-icon name="close" class="close-icon" />{{ $t('organization.editor.viewerPerm2') }}</li>
<li><t-icon name="close" class="close-icon" />{{ $t('organization.editor.viewerPerm3') }}</li>
</ul>
</div>
</div>
<div class="info-notice">
<t-icon name="info-circle" />
<span>{{ $t('organization.editor.ownerNote') }}</span>
</div>
</div>
</div>
</div>
<!-- 加入组织 -->
<div v-if="mode === 'join'" v-show="currentSection === 'join'" class="section">
<div class="section-content">
<div class="section-header">
<h3 class="section-title">{{ $t('organization.editor.joinTitle') }}</h3>
<p class="section-desc">{{ $t('organization.editor.joinDesc') }}</p>
</div>
<div class="section-body">
<div class="join-illustration">
<div class="illustration-icon">
<t-icon name="user-add" size="48px" />
</div>
<p class="illustration-text">{{ $t('organization.editor.joinIllustration') }}</p>
</div>
<div class="form-item">
<label class="form-label required">{{ $t('organization.inviteCode') }}</label>
<t-input
v-model="joinForm.invite_code"
:placeholder="$t('organization.inviteCodePlaceholder')"
:maxlength="32"
size="medium"
class="invite-code-input"
/>
<p class="form-tip">{{ $t('organization.editor.inviteCodeTip') }}</p>
</div>
<div class="join-steps">
<div class="step-title">{{ $t('organization.editor.howToGetCode') }}</div>
<div class="step-list">
<div class="step-item">
<span class="step-number">1</span>
<span class="step-text">{{ $t('organization.editor.step1') }}</span>
</div>
<div class="step-item">
<span class="step-number">2</span>
<span class="step-text">{{ $t('organization.editor.step2') }}</span>
</div>
<div class="step-item">
<span class="step-number">3</span>
<span class="step-text">{{ $t('organization.editor.step3') }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 底部按钮 -->
<div class="settings-footer">
<t-button theme="default" variant="outline" @click="handleClose">
{{ $t('common.cancel') }}
</t-button>
<t-button theme="primary" @click="handleSubmit" :loading="submitting">
{{ mode === 'create' ? $t('common.create') : $t('organization.join.preview') }}
</t-button>
</div>
</div>
</div>
</div>
</div>
</Transition>
<!-- 加入确认弹窗 -->
<t-dialog
v-model:visible="showJoinConfirm"
:header="$t('organization.join.confirmTitle')"
:confirm-btn="previewInfo?.is_already_member ? $t('common.close') : $t('organization.join.confirm')"
:cancel-btn="previewInfo?.is_already_member ? null : $t('common.cancel')"
:confirm-on-enter="!previewInfo?.is_already_member"
@confirm="previewInfo?.is_already_member ? (showJoinConfirm = false) : confirmJoin()"
@cancel="showJoinConfirm = false"
:confirm-loading="joining"
>
<div v-if="previewInfo" class="join-confirm-content">
<div class="org-preview-card">
<div class="org-preview-header">
<div class="org-avatar">
<t-icon name="usergroup" size="24px" />
</div>
<div class="org-info">
<h4 class="org-name">{{ previewInfo.name }}</h4>
<p class="org-desc">{{ previewInfo.description || $t('organization.noDescription') }}</p>
</div>
</div>
<div class="org-stats">
<div class="stat-item">
<t-icon name="user" />
<span>{{ $t('organization.join.memberCount', { count: previewInfo.member_count }) }}</span>
</div>
<div class="stat-item">
<t-icon name="folder" />
<span>{{ $t('organization.join.shareCount', { count: previewInfo.share_count }) }}</span>
</div>
<div class="stat-item stat-item-agent">
<img src="@/assets/img/agent.svg" class="stat-agent-icon" alt="" aria-hidden="true" />
<span>{{ $t('organization.join.agentShareCount', { count: previewInfo.agent_share_count ?? 0 }) }}</span>
</div>
</div>
</div>
<div v-if="previewInfo.is_already_member" class="already-member-notice">
<t-icon name="check-circle-filled" />
<span>{{ $t('organization.join.alreadyMember') }}</span>
</div>
</div>
</t-dialog>
</Teleport>
</template>
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { MessagePlugin } from 'tdesign-vue-next'
import { useOrganizationStore } from '@/stores/organization'
import { useI18n } from 'vue-i18n'
import type { OrganizationPreview } from '@/api/organization'
import SpaceAvatar from '@/components/SpaceAvatar.vue'
const { t } = useI18n()
const orgStore = useOrganizationStore()
// Props
const props = defineProps<{
visible: boolean
mode: 'create' | 'join'
}>()
// Emits
const emit = defineEmits<{
(e: 'update:visible', value: boolean): void
(e: 'success'): void
}>()
const currentSection = ref<string>('basic')
const submitting = ref(false)
const showJoinConfirm = ref(false)
const previewInfo = ref<OrganizationPreview | null>(null)
const joining = ref(false)
const createForm = ref({
name: '',
description: ''
})
const joinForm = ref({
invite_code: ''
})
// 计算属性
const modalTitle = computed(() => {
return props.mode === 'create'
? t('organization.createOrg')
: t('organization.joinOrg')
})
const navItems = computed(() => {
if (props.mode === 'create') {
return [
{ key: 'basic', icon: 'info-circle', label: t('organization.editor.navBasic') },
{ key: 'permissions', icon: 'user-safety', label: t('organization.editor.navPermissions') }
]
} else {
return [
{ key: 'join', icon: 'user-add', label: t('organization.editor.navJoin') }
]
}
})
// 方法
const resetForm = () => {
createForm.value = { name: '', description: '' }
joinForm.value = { invite_code: '' }
currentSection.value = props.mode === 'create' ? 'basic' : 'join'
showJoinConfirm.value = false
previewInfo.value = null
}
const handleClose = () => {
emit('update:visible', false)
setTimeout(resetForm, 300)
}
const handleSubmit = async () => {
if (props.mode === 'create') {
await handleCreate()
} else {
await handleJoin()
}
}
const handleCreate = async () => {
if (!createForm.value.name.trim()) {
MessagePlugin.warning(t('organization.nameRequired'))
currentSection.value = 'basic'
return
}
submitting.value = true
try {
const result = await orgStore.create(
createForm.value.name.trim(),
createForm.value.description.trim()
)
if (result) {
MessagePlugin.success(t('organization.createSuccess'))
emit('success')
handleClose()
} else {
MessagePlugin.error(orgStore.error || t('organization.createFailed'))
}
} catch (error: any) {
MessagePlugin.error(error?.message || t('organization.createFailed'))
} finally {
submitting.value = false
}
}
const handleJoin = async () => {
if (!joinForm.value.invite_code.trim()) {
MessagePlugin.warning(t('organization.inviteCodeRequired'))
return
}
submitting.value = true
try {
// First preview the organization
const preview = await orgStore.preview(joinForm.value.invite_code.trim())
if (preview) {
previewInfo.value = preview
showJoinConfirm.value = true
} else {
MessagePlugin.error(orgStore.error || t('organization.join.invalidCode'))
}
} catch (error: any) {
MessagePlugin.error(error?.message || t('organization.join.invalidCode'))
} finally {
submitting.value = false
}
}
const confirmJoin = async () => {
if (!joinForm.value.invite_code.trim()) {
return
}
joining.value = true
try {
const result = await orgStore.join(joinForm.value.invite_code.trim())
if (result) {
MessagePlugin.success(t('organization.joinSuccess'))
showJoinConfirm.value = false
emit('success')
handleClose()
} else {
MessagePlugin.error(orgStore.error || t('organization.joinFailed'))
}
} catch (error: any) {
MessagePlugin.error(error?.message || t('organization.joinFailed'))
} finally {
joining.value = false
}
}
// 监听
watch(() => props.visible, (newVal) => {
if (newVal) {
resetForm()
}
})
watch(() => props.mode, () => {
currentSection.value = props.mode === 'create' ? 'basic' : 'join'
})
</script>
<style scoped lang="less">
.settings-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
backdrop-filter: blur(4px);
}
.settings-modal {
position: relative;
width: 90vw;
max-width: 900px;
height: 80vh;
max-height: 650px;
background: var(--td-bg-color-container);
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
display: flex;
flex-direction: column;
overflow: hidden;
&.join-mode {
max-width: 700px;
max-height: 580px;
}
}
.close-btn {
position: absolute;
top: 20px;
right: 20px;
width: 32px;
height: 32px;
border: none;
background: var(--td-bg-color-secondarycontainer);
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: var(--td-text-color-secondary);
transition: all 0.2s ease;
z-index: 10;
&:hover {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-primary);
}
}
.settings-container {
display: flex;
height: 100%;
overflow: hidden;
}
.settings-sidebar {
width: 200px;
background: var(--td-bg-color-secondarycontainer);
border-right: 1px solid var(--td-component-stroke);
display: flex;
flex-direction: column;
flex-shrink: 0;
}
.sidebar-header {
padding: 24px 20px;
border-bottom: 1px solid var(--td-component-stroke);
}
.sidebar-title {
margin: 0;
font-family: var(--app-font-family);
font-size: 18px;
font-weight: 600;
color: var(--td-text-color-primary);
}
.settings-nav {
flex: 1;
padding: 12px 8px;
overflow-y: auto;
}
.nav-item {
display: flex;
align-items: center;
padding: 10px 12px;
margin-bottom: 4px;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
font-family: var(--app-font-family);
font-size: 14px;
color: var(--td-text-color-secondary);
&:hover {
background: var(--td-bg-color-container-hover);
color: var(--td-text-color-primary);
}
&.active {
background: var(--td-bg-color-secondarycontainer);
color: var(--td-brand-color);
font-weight: 500;
}
}
.nav-icon {
margin-right: 8px;
font-size: 18px;
flex-shrink: 0;
}
.nav-label {
flex: 1;
}
.settings-content {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.content-wrapper {
flex: 1;
overflow-y: auto;
padding: 24px 32px;
}
.section {
margin-bottom: 32px;
}
.section-content {
.section-header {
margin-bottom: 24px;
}
.section-title {
margin: 0 0 8px 0;
font-family: var(--app-font-family);
font-size: 16px;
font-weight: 600;
color: var(--td-text-color-primary);
}
.section-desc {
margin: 0;
font-family: var(--app-font-family);
font-size: 14px;
color: var(--td-text-color-placeholder);
line-height: 22px;
}
}
.form-item {
margin-bottom: 24px;
&:last-child {
margin-bottom: 0;
}
}
.form-label {
display: block;
margin-bottom: 8px;
font-family: var(--app-font-family);
font-size: 14px;
font-weight: 500;
color: var(--td-text-color-primary);
&.required::after {
content: '*';
color: var(--td-error-color);
margin-left: 4px;
}
}
.form-tip {
margin-top: 8px;
font-size: 12px;
color: var(--td-text-color-placeholder);
line-height: 18px;
}
.name-input-wrapper {
display: flex;
align-items: center;
gap: 12px;
}
.name-input-wrapper .name-input {
flex: 1;
min-width: 0;
}
// 权限说明样式
.permissions-info {
display: flex;
flex-direction: column;
gap: 16px;
}
.permission-card {
background: var(--td-bg-color-secondarycontainer);
border-radius: 8px;
padding: 16px;
border: 1px solid var(--td-component-stroke);
}
.permission-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 12px;
}
.permission-icon {
width: 40px;
height: 40px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: var(--td-text-color-anti);
&.admin {
background: linear-gradient(135deg, var(--td-brand-color), var(--td-brand-color-active));
}
&.editor {
background: linear-gradient(135deg, var(--td-warning-color), var(--td-warning-color-active));
}
&.viewer {
background: var(--td-bg-color-component-disabled);
}
}
.permission-title {
display: flex;
align-items: center;
gap: 8px;
.role-name {
font-size: 15px;
font-weight: 600;
color: var(--td-text-color-primary);
}
}
.permission-list {
margin: 0;
padding: 0;
list-style: none;
li {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 0;
font-size: 13px;
color: var(--td-text-color-secondary);
}
.check-icon {
color: var(--td-brand-color);
font-size: 14px;
}
.close-icon {
color: var(--td-error-color);
font-size: 14px;
}
}
.info-notice {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 20px;
padding: 12px 16px;
background: var(--td-brand-color-light);
border-radius: 8px;
color: var(--td-brand-color);
font-size: 13px;
line-height: 20px;
.t-icon {
flex-shrink: 0;
margin-top: 2px;
}
}
// 加入组织样式
.join-illustration {
text-align: center;
padding: 24px 0 32px;
.illustration-icon {
width: 80px;
height: 80px;
margin: 0 auto 16px;
background: linear-gradient(135deg, var(--td-brand-color-light), #07c05f0d);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: var(--td-brand-color);
}
.illustration-text {
margin: 0;
font-size: 14px;
color: var(--td-text-color-placeholder);
}
}
.invite-code-input {
:deep(.t-input__inner) {
font-size: 16px;
letter-spacing: 1px;
text-align: center;
}
}
.join-steps {
margin-top: 32px;
padding: 20px;
background: var(--td-bg-color-secondarycontainer);
border-radius: 8px;
.step-title {
font-size: 14px;
font-weight: 500;
color: var(--td-text-color-primary);
margin-bottom: 16px;
}
.step-list {
display: flex;
flex-direction: column;
gap: 12px;
}
.step-item {
display: flex;
align-items: center;
gap: 12px;
}
.step-number {
width: 24px;
height: 24px;
background: var(--td-brand-color);
color: var(--td-text-color-anti);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: 600;
flex-shrink: 0;
}
.step-text {
font-size: 13px;
color: var(--td-text-color-secondary);
}
}
.settings-footer {
padding: 16px 32px;
border-top: 1px solid var(--td-component-stroke);
display: flex;
justify-content: flex-end;
gap: 12px;
flex-shrink: 0;
}
// 过渡动画
.modal-enter-active,
.modal-leave-active {
transition: all 0.3s ease;
}
.modal-enter-from,
.modal-leave-to {
opacity: 0;
.settings-modal {
transform: scale(0.95);
}
}
// 加入确认弹窗样式
.join-confirm-content {
padding: 8px 0;
}
.org-preview-card {
background: var(--td-bg-color-secondarycontainer);
border-radius: 8px;
padding: 16px;
border: 1px solid var(--td-component-stroke);
}
.org-preview-header {
display: flex;
gap: 12px;
margin-bottom: 16px;
}
.org-avatar {
width: 48px;
height: 48px;
background: linear-gradient(135deg, var(--td-brand-color), var(--td-brand-color-active));
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: var(--td-text-color-anti);
flex-shrink: 0;
}
.org-info {
flex: 1;
min-width: 0;
}
.org-name {
margin: 0 0 4px 0;
font-size: 16px;
font-weight: 600;
color: var(--td-text-color-primary);
}
.org-desc {
margin: 0;
font-size: 13px;
color: var(--td-text-color-placeholder);
line-height: 20px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.org-stats {
display: flex;
gap: 24px;
padding-top: 12px;
border-top: 1px solid var(--td-component-stroke);
}
.stat-item {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
color: var(--td-text-color-secondary);
.t-icon {
font-size: 16px;
color: var(--td-text-color-placeholder);
}
&.stat-item-agent .stat-agent-icon {
width: 16px;
height: 16px;
flex-shrink: 0;
}
}
.already-member-notice {
display: flex;
align-items: center;
gap: 8px;
margin-top: 16px;
padding: 12px 16px;
background: var(--td-brand-color-light);
border-radius: 8px;
color: var(--td-brand-color);
font-size: 14px;
.t-icon {
font-size: 18px;
color: var(--td-brand-color);
}
}
</style>

View File

@ -1,7 +0,0 @@
<template><div class="route-placeholder" aria-hidden="true" /></template>
<style scoped>
.route-placeholder {
display: none;
}
</style>

View File

@ -1161,8 +1161,8 @@ onMounted(loadAll)
</style>
<!--
Non-scoped block: per-engine header-icon coloring. Same approach as
StorageEngineSettings — keep these rules global so they always apply
Non-scoped block: per-engine header-icon coloring. Keep these rules global
so they always apply
regardless of whether the drawer panel inherits the parent's scoped
data attributes. Each rule mirrors the matching .engine-card--{name}
.engine-card__badge from the scoped block above.

View File

@ -151,7 +151,7 @@
<!-- 存储引擎 -->
<div v-if="currentSection === 'storage'" class="section">
<StorageEngineSettings />
<StorageBackendSettings />
</div>
<!-- 沙箱 -->
@ -249,7 +249,7 @@ import EnvVarSettings from './EnvVarSettings.vue'
import MemoryWorkspaceSettings from './MemoryWorkspaceSettings.vue'
import VectorStoreSettings from './VectorStoreSettings.vue'
import ParserEngineSettings from './ParserEngineSettings.vue'
import StorageEngineSettings from './StorageBackendSettings.vue'
import StorageBackendSettings from './StorageBackendSettings.vue'
import SandboxSettings from './SandboxSettings.vue'
import SkillSettings from './SkillSettings.vue'
import WeKnoraCloudSettings from './WeKnoraCloudSettings.vue'

File diff suppressed because it is too large Load Diff

View File

@ -7,9 +7,7 @@
<h3 class="list-section-title">{{ t('webSearchSettings.providersTitle') }}</h3>
<!-- Provider List —— 与 ModelSettings 的卡片同形:左侧标识徽章 + 标题 / 副标题 / proxy URL 三段式。
不复用 SettingCard 的原因和 Models 一样:每页有微妙不同的右上侧栏需求(这里没有控件,
Mcp 有开关),SettingCard 仍服务于其它消费者。 -->
<!-- Provider cards keep their page-specific actions beside the provider details. -->
<div v-if="providerEntities.length === 0 && !authStore.hasRole('admin')" class="empty-state">
<t-empty :description="t('webSearchSettings.noProvidersDesc')" />
</div>

View File

@ -1,434 +0,0 @@
<template>
<div v-if="result" class="mtr">
<!-- 状态条 -->
<div class="mtr-status" :class="result.success ? 'is-success' : 'is-error'">
<t-icon :name="result.success ? 'check-circle-filled' : 'close-circle-filled'" />
<span>{{ result.success ? $t('mcp.testResult.connectionSuccess') : $t('mcp.testResult.connectionFailed') }}</span>
</div>
<p v-if="result.message" class="mtr-message">{{ result.message }}</p>
<div v-if="result.success && result.description" class="mtr-service-desc">
<span>{{ $t('mcp.testResult.descriptionLabel') }}</span>
<p>{{ result.description }}</p>
</div>
<template v-if="result.success">
<!-- 工具列表 -->
<div v-if="result.tools && result.tools.length > 0" class="mtr-group">
<div class="mtr-group-title">
<span>{{ $t('mcp.testResult.toolsTitle') }}</span>
<t-tag theme="primary" variant="light" size="small">{{ result.tools.length }}</t-tag>
</div>
<div class="mtr-list">
<div
v-for="(tool, index) in displayTools"
:key="index"
class="mtr-item"
:class="{ 'is-open': expandedToolIndex === index }"
>
<div class="mtr-item-head" @click="toggleTool(index)">
<t-icon name="tools" class="mtr-item-icon" />
<span class="mtr-item-name">{{ tool.name }}</span>
<div class="mtr-item-actions" @click.stop>
<t-tooltip v-if="serviceId" :content="$t('mcp.testResult.toolEnabledTip')" placement="top">
<span class="mtr-approval">
<span class="mtr-approval-label">{{ $t('mcp.testResult.toolEnabled') }}</span>
<t-switch
:value="tool.enabled !== false"
:loading="toolLoading[tool.name]"
:disabled="isToolPolicyBusy(tool.name)"
size="small"
@change="(v: boolean) => onToolEnabledChange(tool.name, v)"
/>
</span>
</t-tooltip>
<t-tooltip v-if="serviceId" :content="$t('mcp.testResult.requireApprovalTip')" placement="top">
<span class="mtr-approval">
<t-icon name="error-circle-filled" class="mtr-approval-icon" />
<span class="mtr-approval-label">{{ $t('mcp.testResult.requireApproval') }}</span>
<t-switch
:value="tool.require_approval"
:loading="approvalLoading[tool.name]"
:disabled="isToolPolicyBusy(tool.name)"
size="small"
@change="(v: boolean) => onRequireApprovalChange(tool.name, v)"
/>
</span>
</t-tooltip>
</div>
<t-icon
:name="expandedToolIndex === index ? 'chevron-up' : 'chevron-down'"
class="mtr-chevron"
/>
</div>
<div
v-if="tool.description"
class="mtr-item-desc"
:class="{ 'is-clamped': expandedToolIndex !== index }"
>
{{ tool.description }}
</div>
<div v-if="expandedToolIndex === index && tool.inputSchema" class="mtr-item-schema">
<div class="mtr-schema-label">{{ $t('mcp.testResult.schemaLabel') }}</div>
<pre>{{ formatSchema(tool.inputSchema) }}</pre>
</div>
</div>
</div>
</div>
<!-- 资源列表 -->
<div v-if="result.resources && result.resources.length > 0" class="mtr-group">
<div class="mtr-group-title">
<span>{{ $t('mcp.testResult.resourcesTitle') }}</span>
<t-tag theme="primary" variant="light" size="small">{{ result.resources.length }}</t-tag>
</div>
<div class="mtr-list">
<div v-for="(resource, index) in result.resources" :key="index" class="mtr-item">
<div class="mtr-item-head is-static">
<t-icon name="file" class="mtr-item-icon" />
<span class="mtr-item-name">{{ resource.name || resource.uri }}</span>
<t-tag v-if="resource.mimeType" theme="default" variant="light-outline" size="small">
{{ resource.mimeType }}
</t-tag>
</div>
<div v-if="resource.description" class="mtr-item-desc">{{ resource.description }}</div>
<div v-if="resource.uri" class="mtr-item-uri">
<t-icon name="link" />
<span>{{ resource.uri }}</span>
</div>
</div>
</div>
</div>
<!-- 空状态 -->
<t-empty
v-if="(!result.tools || result.tools.length === 0) && (!result.resources || result.resources.length === 0)"
:description="$t('mcp.testResult.emptyDescription')"
class="mtr-empty"
/>
</template>
</div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import type { MCPTestResult, MCPTool } from '@/api/mcp-service'
import { getMCPToolApprovals, setMCPToolApproval, setMCPToolEnabled } from '@/api/mcp-service'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
interface Props {
result: MCPTestResult | null
/** When set, loads/saves per-tool approval flags */
serviceId?: string
/** When true, (re)loads approval flags. Lets the dialog gate the fetch on
* visibility; defaults to true for always-rendered inline usage. */
active?: boolean
}
const props = withDefaults(defineProps<Props>(), { active: true })
const expandedToolIndex = ref<number | null>(null)
const { t } = useI18n()
const displayTools = ref<MCPTool[]>([])
const approvalLoading = ref<Record<string, boolean>>({})
const toolLoading = ref<Record<string, boolean>>({})
const isToolPolicyBusy = (toolName: string) =>
Boolean(toolLoading.value[toolName] || approvalLoading.value[toolName])
const mergeApprovals = async () => {
const tools = props.result?.tools
if (!tools?.length) {
displayTools.value = []
return
}
if (!props.serviceId) {
displayTools.value = tools.map((x) => ({ ...x }))
return
}
try {
const rows = await getMCPToolApprovals(props.serviceId)
const map = new Map(rows.map((r) => [r.tool_name, r]))
displayTools.value = tools.map((tool) => ({
...tool,
require_approval: map.get(tool.name)?.require_approval || false,
enabled: map.get(tool.name)?.enabled !== false,
}))
} catch {
displayTools.value = tools.map((x) => ({ ...x }))
}
}
const onToolEnabledChange = async (toolName: string, value: boolean) => {
if (!props.serviceId) return
toolLoading.value = { ...toolLoading.value, [toolName]: true }
try {
await setMCPToolEnabled(props.serviceId, toolName, value)
displayTools.value = displayTools.value.map((x) =>
x.name === toolName ? { ...x, enabled: value } : x
)
} catch (e) {
console.error(e)
MessagePlugin.error(t('mcp.testResult.toolEnabledSaveFailed'))
} finally {
toolLoading.value = { ...toolLoading.value, [toolName]: false }
}
}
watch(
() => [props.active, props.serviceId, props.result?.tools],
() => {
if (props.active) {
void mergeApprovals()
}
},
{ deep: true, immediate: true }
)
const onRequireApprovalChange = async (toolName: string, value: boolean) => {
if (!props.serviceId) return
approvalLoading.value = { ...approvalLoading.value, [toolName]: true }
try {
await setMCPToolApproval(props.serviceId, toolName, value)
displayTools.value = displayTools.value.map((x) =>
x.name === toolName ? { ...x, require_approval: value } : x
)
} catch (e) {
console.error(e)
MessagePlugin.error(t('mcp.testResult.approvalSaveFailed'))
} finally {
approvalLoading.value = { ...approvalLoading.value, [toolName]: false }
}
}
const toggleTool = (index: number) => {
expandedToolIndex.value = expandedToolIndex.value === index ? null : index
}
const formatSchema = (schema: any): string => {
if (!schema) return ''
return JSON.stringify(schema, null, 2)
}
</script>
<style scoped lang="less">
.mtr {
display: flex;
flex-direction: column;
gap: 16px;
}
/* 状态条 */
.mtr-status {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
&.is-success {
color: var(--td-success-color);
background: var(--td-success-color-1, var(--td-bg-color-secondarycontainer));
}
&.is-error {
color: var(--td-error-color);
background: var(--td-error-color-1, var(--td-bg-color-secondarycontainer));
}
:deep(.t-icon) {
font-size: 18px;
}
}
.mtr-message {
margin: 0;
font-size: 13px;
color: var(--td-text-color-secondary);
line-height: 1.6;
word-break: break-word;
}
.mtr-service-desc {
padding: 10px 12px;
border: 1px solid var(--td-component-stroke);
border-radius: 6px;
background: var(--td-bg-color-secondarycontainer);
span {
display: block;
margin-bottom: 4px;
color: var(--td-text-color-placeholder);
font-size: 12px;
font-weight: 600;
}
p {
margin: 0;
color: var(--td-text-color-primary);
font-size: 13px;
line-height: 1.6;
word-break: break-word;
}
}
/* 分组 */
.mtr-group {
display: flex;
flex-direction: column;
gap: 10px;
}
.mtr-group-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
font-weight: 600;
color: var(--td-text-color-secondary);
}
/* 列表:扁平卡片,靠分隔与圆角,无重阴影,贴合抽屉 */
.mtr-list {
display: flex;
flex-direction: column;
border: 1px solid var(--td-component-stroke);
border-radius: 8px;
overflow: hidden;
}
.mtr-item {
padding: 12px 14px;
background: var(--td-bg-color-container);
& + .mtr-item {
border-top: 1px solid var(--td-component-stroke);
}
&.is-open {
background: var(--td-bg-color-secondarycontainer);
}
}
.mtr-item-head {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
user-select: none;
&.is-static {
cursor: default;
}
}
.mtr-item-icon {
flex-shrink: 0;
font-size: 16px;
color: var(--td-brand-color);
}
.mtr-item-name {
flex: 1;
min-width: 0;
font-size: 14px;
font-weight: 600;
color: var(--td-text-color-primary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.mtr-item-actions {
display: flex;
align-items: center;
gap: 10px;
flex-shrink: 0;
}
.mtr-approval {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: var(--td-text-color-secondary);
.mtr-approval-icon {
font-size: 15px;
color: var(--td-warning-color);
}
.mtr-approval-label {
white-space: nowrap;
}
}
.mtr-chevron {
font-size: 16px;
color: var(--td-text-color-placeholder);
flex-shrink: 0;
}
/* 描述:独占整行,绝不与右侧开关挤在一起 */
.mtr-item-desc {
margin-top: 6px;
font-size: 13px;
color: var(--td-text-color-placeholder);
line-height: 1.6;
word-break: break-word;
&.is-clamped {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
}
.mtr-item-schema {
margin-top: 10px;
.mtr-schema-label {
font-size: 12px;
font-weight: 600;
color: var(--td-text-color-placeholder);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 6px;
}
pre {
margin: 0;
padding: 10px 12px;
border-radius: 6px;
background: var(--td-bg-color-page);
border: 1px solid var(--td-component-stroke);
overflow-x: auto;
font-size: 12px;
font-family: var(--app-font-family-mono);
color: var(--td-text-color-primary);
line-height: 1.6;
}
}
.mtr-item-uri {
display: flex;
align-items: center;
gap: 6px;
margin-top: 8px;
font-size: 12px;
color: var(--td-text-color-placeholder);
span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.mtr-empty {
padding: 24px 0;
}
</style>