feat(ui): add search to Skills and MCP toolbox lists (#3731)
parent
3206e15e83
commit
9d4cc233c6
|
|
@ -7,12 +7,13 @@ import test from 'node:test'
|
|||
import { compileScript, parse } from '@vue/compiler-sfc'
|
||||
import ts from 'typescript'
|
||||
import { createRenderer, nextTick, reactive } from 'vue'
|
||||
import { matchesResourceQuery } from '../../utils/resourceListSearch'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const filename = fileURLToPath(new URL('./McpSettings.vue', import.meta.url))
|
||||
const { descriptor } = parse(readFileSync(filename, 'utf8'), { filename })
|
||||
const script = compileScript(descriptor, { id: 'mcp-settings-test' }).content
|
||||
.replace('__expose();', '')
|
||||
.replace(/__expose\([^;]*\);/g, '')
|
||||
.replace('return __returned__', '__expose(__returned__); return __returned__')
|
||||
const compiled = ts.transpileModule(script, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 } }).outputText
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ async function fixture(update: () => Promise<void> = async () => {}, admin = tru
|
|||
runInNewContext(compiled, {
|
||||
exports, console: { error() {} },
|
||||
require(name: string) {
|
||||
if (name === '@/utils/resourceListSearch') return { matchesResourceQuery }
|
||||
if (name === 'vue') return require('vue')
|
||||
if (name === 'vue-i18n') return { useI18n: () => ({ t: (key: string) => key }) }
|
||||
if (name === '@/stores/auth') return { useAuthStore: () => ({ hasRole: () => admin }) }
|
||||
|
|
@ -46,6 +48,7 @@ async function fixture(update: () => Promise<void> = async () => {}, admin = tru
|
|||
})
|
||||
const app = renderer.createApp(component)
|
||||
const vm: any = app.mount({})
|
||||
await new Promise<void>(resolve => setImmediate(resolve))
|
||||
await nextTick()
|
||||
return { vm, service, calls, errors, deletes, close: () => app.unmount() }
|
||||
}
|
||||
|
|
@ -111,3 +114,58 @@ test('viewer controls and builtin mutations cannot update services', async () =>
|
|||
assert.equal(builtin.deletes.length, 0)
|
||||
} finally { viewer.close(); builtin.close() }
|
||||
})
|
||||
|
||||
const rows = () => [
|
||||
{ id: 'builtin', name: 'Knowledge', description: 'Search docs', enabled: false, is_builtin: true, transport_type: 'http-streamable' },
|
||||
{ id: 'logs', name: '日志 Logs', description: 'hidden legacy text', usage_instructions: 'Audit REPORT', enabled: true, transport_type: 'sse', headers: { Authorization: 'secret-fixture' } },
|
||||
{ id: 'local', name: 'Local', description: '', enabled: false, transport_type: 'stdio' },
|
||||
]
|
||||
const ids = (vm: any) => Array.from(vm.filteredServices, (row: any) => row.id)
|
||||
|
||||
test('MCP search matches visible metadata and clearing restores every service', async () => {
|
||||
const f = await fixture()
|
||||
try {
|
||||
f.vm.services = rows()
|
||||
f.vm.query = ' 日志 report '
|
||||
assert.deepEqual(ids(f.vm), ['logs'])
|
||||
f.vm.query = 'knowledge docs'
|
||||
assert.deepEqual(ids(f.vm), ['builtin'])
|
||||
for (const query of ['secret-fixture', 'hidden legacy', 'missing']) {
|
||||
f.vm.query = query
|
||||
assert.deepEqual(ids(f.vm), [])
|
||||
}
|
||||
f.vm.query = ' '
|
||||
assert.deepEqual(ids(f.vm), ['builtin', 'logs', 'local'])
|
||||
} finally { f.close() }
|
||||
})
|
||||
|
||||
test('search results keep service identity for editing and toggling', async () => {
|
||||
const f = await fixture()
|
||||
try {
|
||||
f.vm.services = rows()
|
||||
f.vm.query = 'logs'
|
||||
const service = f.vm.filteredServices[0]
|
||||
assert.equal(service, f.vm.services[1])
|
||||
f.vm.handleEdit(service)
|
||||
assert.equal(f.vm.currentService.id, 'logs')
|
||||
await f.vm.handleToggleEnabled(service)
|
||||
assert.equal(f.calls[0]?.id, 'logs')
|
||||
assert.equal(service.enabled, false)
|
||||
assert.deepEqual(ids(f.vm), ['logs'])
|
||||
assert.equal(f.vm.services.length, 3)
|
||||
service.name = 'Renamed'
|
||||
assert.deepEqual(ids(f.vm), [])
|
||||
} finally { f.close() }
|
||||
})
|
||||
|
||||
test('a failed MCP save keeps the row in the search results', async () => {
|
||||
const f = await fixture(async () => { throw new Error('unavailable') })
|
||||
try {
|
||||
f.vm.services = rows()
|
||||
f.vm.query = 'logs'
|
||||
await f.vm.handleToggleEnabled(f.vm.filteredServices[0])
|
||||
assert.deepEqual(ids(f.vm), ['logs'])
|
||||
assert.equal(f.vm.filteredServices[0].enabled, true)
|
||||
assert.deepEqual(f.errors, ['mcpSettings.toasts.updateStateFailed'])
|
||||
} finally { f.close() }
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,12 +12,23 @@
|
|||
</div>
|
||||
|
||||
<template v-else>
|
||||
<t-input v-if="services.length > 0" v-model="query" class="list-search" :placeholder="$t('menu.search')"
|
||||
:aria-label="$t('menu.search')" clearable>
|
||||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
<div v-if="services.length === 0 && !authStore.hasRole('admin')" class="empty-state">
|
||||
<t-empty :description="$t('mcpSettings.empty')" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="services.length > 0 && filteredServices.length === 0" class="empty-state">
|
||||
<t-empty :description="$t('common.noResult')" />
|
||||
<t-button variant="outline" @click="query = ''">{{ $t('common.clear') }}</t-button>
|
||||
<t-button v-if="authStore.hasRole('admin')" variant="text" @click="handleAdd">
|
||||
{{ $t('mcpSettings.addService') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div v-else class="services-grid">
|
||||
<article v-for="service in services" :key="service.id" class="service-card">
|
||||
<article v-for="service in filteredServices" :key="service.id" class="service-card">
|
||||
<div class="service-card__main">
|
||||
<div class="service-card__body">
|
||||
<div class="service-card__header">
|
||||
|
|
@ -109,7 +120,7 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { computed, ref, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { AddIcon } from 'tdesign-icons-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
|
@ -122,6 +133,7 @@ import {
|
|||
import McpServiceDialog from './components/McpServiceDialog.vue'
|
||||
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { matchesResourceQuery } from '@/utils/resourceListSearch'
|
||||
|
||||
const emit = defineEmits<{ count: [value: number] }>()
|
||||
const { t } = useI18n()
|
||||
|
|
@ -136,6 +148,10 @@ const currentService = ref<MCPService | null>(null)
|
|||
const dialogInitialStep = ref<0 | 1>(0)
|
||||
const togglingIds = ref(new Set<string>())
|
||||
const serviceUsage = (service: MCPService) => service.usage_instructions?.trim() || service.description?.trim() || ''
|
||||
const query = ref('')
|
||||
const filteredServices = computed(() => services.value.filter((service) =>
|
||||
matchesResourceQuery({ name: service.name, description: serviceUsage(service) }, query.value),
|
||||
))
|
||||
|
||||
// Load MCP services
|
||||
const loadServices = async () => {
|
||||
|
|
@ -256,6 +272,10 @@ defineExpose({ openAdd: handleAdd })
|
|||
.settings-section-header();
|
||||
}
|
||||
|
||||
.list-search {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
padding: 40px 0;
|
||||
text-align: center;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,126 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { runInNewContext } from 'node:vm'
|
||||
import test from 'node:test'
|
||||
import { compileScript, parse } from '@vue/compiler-sfc'
|
||||
import ts from 'typescript'
|
||||
import { createRenderer, nextTick, ref } from 'vue'
|
||||
import { matchesResourceQuery } from '../../utils/resourceListSearch'
|
||||
import * as skillTarget from '../../utils/skillTarget'
|
||||
import * as skillUpgrade from '../../utils/skillUpgrade'
|
||||
import type { SkillCatalogItem } from '../../api/skill'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const filename = fileURLToPath(new URL('./SkillSettings.vue', import.meta.url))
|
||||
const { descriptor } = parse(readFileSync(filename, 'utf8'), { filename })
|
||||
const script = compileScript(descriptor, { id: 'skill-filters-test' }).content
|
||||
.replace(/__expose\([^;]*\);/g, '')
|
||||
.replace('return __returned__', '__expose(__returned__); return __returned__')
|
||||
const compiled = ts.transpileModule(script, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
||||
}).outputText
|
||||
|
||||
function item(id: string, statuses: string[] = []): SkillCatalogItem {
|
||||
return {
|
||||
id, name: id, description: '', created_at: '', updated_at: '',
|
||||
installations: statuses.map((status, index) => ({
|
||||
skill_id: `${id}-${index}`, sandbox_config_id: `sandbox-${index}`,
|
||||
status, enabled: false, updated_at: '',
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
async function fixture(initial: SkillCatalogItem[], host = false) {
|
||||
let catalog = initial
|
||||
const exports: any = {}
|
||||
const mocks: Record<string, unknown> = {
|
||||
'vue': require('vue'),
|
||||
'vue-i18n': { useI18n: () => ({ t: (key: string) => key, te: () => false }) },
|
||||
'tdesign-vue-next': { MessagePlugin: { error: assert.fail } },
|
||||
'@/stores/ui': { useUIStore: () => ({}) },
|
||||
'@/stores/deploymentCapabilities': {
|
||||
useDeploymentCapabilitiesStore: () => ({
|
||||
ensureLoaded: async () => {},
|
||||
isSupported: (key: string) => key.endsWith('.host') ? host : !host,
|
||||
}),
|
||||
},
|
||||
'@/components/settings/useConfirmDelete': { useConfirmDelete: () => () => {} },
|
||||
'@/composables/useSkillInstallerModel': {
|
||||
useSkillInstallerModel: () => ({ installerModelId: ref(''), savingInstallerModel: ref(false) }),
|
||||
},
|
||||
'@/composables/useConfigSkillInstallProgress': {
|
||||
useConfigSkillInstallProgress: () => ({ percentOf: () => null, sync() {}, stopAll() {} }),
|
||||
},
|
||||
'@/api/skill': { listSkillCatalog: async () => ({ data: catalog }) },
|
||||
'@/api/system': { listSandboxConfigs: async () => ({ data: [] }) },
|
||||
'@/utils/resourceListSearch': { matchesResourceQuery },
|
||||
'@/utils/skillTarget': skillTarget,
|
||||
'@/utils/skillUpgrade': skillUpgrade,
|
||||
'@/utils': {},
|
||||
'@/types/mention': { SKILL_ICON: 'tools' },
|
||||
'tdesign-icons-vue-next': {},
|
||||
}
|
||||
runInNewContext(compiled, {
|
||||
exports,
|
||||
window: { setInterval: () => 1, clearInterval() {} },
|
||||
require(name: string) {
|
||||
if (name.endsWith('.vue')) return { default: {} }
|
||||
assert.ok(name in mocks, `Unexpected import: ${name}`)
|
||||
return mocks[name]
|
||||
},
|
||||
})
|
||||
const component = exports.default
|
||||
component.render = () => null
|
||||
const renderer = createRenderer<any, any>({
|
||||
createElement: () => ({}), createText: () => ({}), createComment: () => ({}),
|
||||
insert() {}, remove() {}, setElementText() {}, setText() {}, patchProp() {},
|
||||
parentNode: () => null, nextSibling: () => null,
|
||||
})
|
||||
const app = renderer.createApp(component)
|
||||
const vm: any = app.mount({})
|
||||
await new Promise<void>(resolve => setImmediate(resolve))
|
||||
await nextTick()
|
||||
return {
|
||||
vm, close: () => app.unmount(),
|
||||
reload: async (rows: SkillCatalogItem[]) => { catalog = rows; await vm.loadCatalog(true) },
|
||||
}
|
||||
}
|
||||
|
||||
const ids = (vm: any) => Array.from(vm.filteredCatalog, (row: any) => row.id)
|
||||
|
||||
test('skill search matches names and descriptions without changing order or row identity', async () => {
|
||||
const data = [item('财务 Report', ['ready']), item('未安装'), item('mixed', ['ready', 'failed'])]
|
||||
data[2]!.description = '财务 REPORT'
|
||||
const f = await fixture(data)
|
||||
try {
|
||||
f.vm.query = ' 财务 report '
|
||||
assert.deepEqual(ids(f.vm), ['财务 Report', 'mixed'])
|
||||
assert.equal(f.vm.filteredCatalog[1], f.vm.catalog[2])
|
||||
f.vm.openCatalogFiles(f.vm.filteredCatalog[1])
|
||||
assert.equal(f.vm.filesCatalogId, 'mixed')
|
||||
assert.equal(f.vm.catalog.length, 3)
|
||||
f.vm.query = 'missing'
|
||||
assert.deepEqual(ids(f.vm), [])
|
||||
f.vm.query = ' '
|
||||
assert.deepEqual(ids(f.vm), data.map(row => row.id))
|
||||
} finally { f.close() }
|
||||
})
|
||||
|
||||
for (const host of [false, true]) {
|
||||
test(`skill search updates on catalog reload (${host ? 'Lite' : 'Standard'})`, async () => {
|
||||
const f = await fixture([item('report'), item('other')], host)
|
||||
try {
|
||||
f.vm.query = 'report'
|
||||
assert.deepEqual(ids(f.vm), ['report'])
|
||||
const updated = item('new')
|
||||
updated.description = 'Report tools'
|
||||
await f.reload([item('other'), updated])
|
||||
assert.deepEqual(ids(f.vm), ['new'])
|
||||
assert.equal(f.vm.query, 'report')
|
||||
await f.reload([])
|
||||
assert.deepEqual(ids(f.vm), [])
|
||||
} finally { f.close() }
|
||||
})
|
||||
}
|
||||
|
|
@ -24,6 +24,10 @@
|
|||
</div>
|
||||
|
||||
<template v-else>
|
||||
<t-input v-if="catalog.length > 0" v-model="query" class="list-search" :placeholder="$t('menu.search')"
|
||||
:aria-label="$t('menu.search')" clearable>
|
||||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
<div v-if="catalog.length === 0" class="empty-state">
|
||||
<t-empty :description="skillText('emptyDesc')" />
|
||||
<p v-if="skillConfigs.length === 0" class="empty-hint">
|
||||
|
|
@ -40,8 +44,15 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="filteredCatalog.length === 0" class="empty-state">
|
||||
<t-empty :description="$t('common.noResult')" />
|
||||
<div class="empty-actions">
|
||||
<t-button variant="outline" @click="query = ''">{{ $t('common.clear') }}</t-button>
|
||||
<t-button variant="text" @click="openAdd">{{ $t('settings.skills.addSkill') }}</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="skill-list">
|
||||
<article v-for="item in catalog" :key="item.id" class="skill-card" :class="{
|
||||
<article v-for="item in filteredCatalog" :key="item.id" class="skill-card" :class="{
|
||||
'skill-card--focused': focusedCatalogId === item.id,
|
||||
'skill-card--installed': liveInstalls(item).length > 0,
|
||||
'skill-card--idle': liveInstalls(item).length === 0,
|
||||
|
|
@ -354,6 +365,7 @@ import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
|||
import ModelSelector from '@/components/ModelSelector.vue'
|
||||
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||
import { useConfigSkillInstallProgress } from '@/composables/useConfigSkillInstallProgress'
|
||||
import { matchesResourceQuery } from '@/utils/resourceListSearch'
|
||||
import { SKILL_ICON } from '@/types/mention'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { useDeploymentCapabilitiesStore } from '@/stores/deploymentCapabilities'
|
||||
|
|
@ -409,6 +421,8 @@ const records = ref<SandboxConfigRecord[]>([])
|
|||
const scriptsDisabled = ref(false)
|
||||
const policySaving = ref(false)
|
||||
const catalog = ref<SkillCatalogItem[]>([])
|
||||
const query = ref('')
|
||||
const filteredCatalog = computed(() => catalog.value.filter((item) => matchesResourceQuery(item, query.value)))
|
||||
const focusedCatalogId = ref('')
|
||||
const deletingId = ref('')
|
||||
const showAdd = ref(false)
|
||||
|
|
@ -1312,6 +1326,10 @@ onUnmounted(() => {
|
|||
|
||||
@import (reference) '@/components/css/settings-section.less';
|
||||
|
||||
.list-search {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.skill-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ MCP 用于智能体与外部工具之间的连接。WeKnora 支持接入外部 M
|
|||
|
||||
## 接入外部工具
|
||||
|
||||
MCP 管理页支持按服务名称和卡片显示的用途说明搜索。搜索忽略大小写,空格分隔的关键词需全部匹配;未填写用途说明时搜索服务描述。无匹配结果时可清空搜索。
|
||||
|
||||
新建服务分两步:
|
||||
|
||||
1. **连接配置**:填写名称和服务 URL,选择 SSE 或 Streamable HTTP 传输,并配置认证(无 / 自定义 Header、API Key / Token、OAuth 2.0)和超时、重试。也可以用「从代码导入」粘贴标准 `mcpServers` JSON 自动填表;只含 `command` / `args` 的 stdio 配置不支持。保存后可测试连接;OAuth 服务点「去授权」时会先自动保存,再按当前用户发起授权。
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
## 管理安装与更新 {#目录、安装和更新}
|
||||
|
||||
技能管理页支持按名称和描述搜索。搜索忽略大小写,空格分隔的关键词需全部匹配。无匹配结果时可清空搜索,或继续添加技能。
|
||||
|
||||
空间目录保存一份技能包;每个沙箱配置各有安装记录和包含技能的镜像快照。同一技能可以装到多个沙箱,安装进度和失败原因分别记录。
|
||||
|
||||
| 操作 | 结果 |
|
||||
|
|
|
|||
Loading…
Reference in New Issue