From 4579dad2517d0590bb0f4ee757b1e565c4ed1875 Mon Sep 17 00:00:00 2001 From: newbie Date: Fri, 13 Nov 2026 11:11:20 +0800 Subject: [PATCH] feat(mcp): searchable connection list with filters, select-all and batch actions (0.9.5) --- client/index.js | 267 ++++++++++++++++++++++++++++++++++++++++- lib/index.js | 2 +- lib/mnemon/index.js | 2 +- package.json | 2 +- src/index.ts | 2 +- src/mnemon/index.ts | 2 +- verify-card-render.mjs | 10 ++ verify-full-load.mjs | 2 +- verify-upgrade.mjs | 2 +- 9 files changed, 280 insertions(+), 11 deletions(-) diff --git a/client/index.js b/client/index.js index bd6be24..9e436ca 100644 --- a/client/index.js +++ b/client/index.js @@ -1424,7 +1424,7 @@ window.__ModuleLoader__.load({ var skills = skillsState[0] var setSkills = skillsState[1] - var mcpState = React.useState({ status: 'idle', items: [], error: null, tools: {}, busy: '', confirm: null }) + var mcpState = React.useState({ status: 'idle', items: [], error: null, tools: {}, busy: '', confirm: null, search: '', filter: 'all', selection: [], bulk: null, confirmBulk: false }) var mcp = mcpState[0] var setMcp = mcpState[1] @@ -1960,6 +1960,59 @@ window.__ModuleLoader__.load({ }) } + function mcpSelected() { + return Array.isArray(mcp.selection) ? mcp.selection : [] + } + + function selectMcpMany(list, on) { + var next = mcpSelected().slice() + list.forEach(function (item) { + var at = next.indexOf(item.key) + if (on === true && at < 0) next.push(item.key) + if (on !== true && at >= 0) next.splice(at, 1) + }) + patchMcp({ selection: next, confirmBulk: false }) + } + + function runMcpBulk(actionLabel, method, paramsOf) { + var chosen = mcpSelected() + var targets = (Array.isArray(mcp.items) ? mcp.items : []).filter(function (item) { + return chosen.indexOf(item.key) >= 0 + }) + if (targets.length === 0) return Promise.resolve() + patchMcp({ busy: 'bulk', confirm: null, confirmBulk: false, bulk: { label: actionLabel, done: 0, total: targets.length } }) + var failures = [] + var chain = Promise.resolve() + targets.forEach(function (item) { + chain = chain.then(function () { + return mcpCall(method, paramsOf(item)).then( + function (result) { + if (!(result.status === 200 && result.body !== null && result.body.ok === true)) { + var reason = result.body !== null && typeof result.body.message === 'string' ? result.body.message : 'HTTP ' + String(result.status) + failures.push(String(item.name === undefined ? item.key : item.name) + '(' + reason + ')') + } + patchMcp(function (previous) { + var bulk = previous.bulk === null || previous.bulk === undefined ? { label: actionLabel, done: 0, total: targets.length } : Object.assign({}, previous.bulk) + bulk.done = (bulk.done === undefined ? 0 : bulk.done) + 1 + return Object.assign({}, previous, { bulk: bulk }) + }) + }, + function (failure) { + failures.push(String(item.name === undefined ? item.key : item.name) + '(' + messageOf(failure) + ')') + }, + ) + }) + }) + return chain.then(function () { + patchMcp({ busy: '', bulk: null, selection: [], confirmBulk: false }) + setNotice({ + tone: failures.length === 0 ? 'ok' : 'warn', + text: actionLabel + '完成:成功 ' + String(targets.length - failures.length) + ' / ' + String(targets.length) + ' 项' + (failures.length === 0 ? '。' : ';失败:' + failures.join('、')), + }) + return probeMcp() + }) + } + // ---- render ------------------------------------------------------- if (error !== null && snapshot === null) { @@ -2980,6 +3033,44 @@ window.__ModuleLoader__.load({ var mcpTab = null if (tab === 'mcp') { var items = Array.isArray(mcp.items) ? mcp.items : [] + var mcpSearch = String(mcp.search === undefined ? '' : mcp.search) + var mcpNeedle = mcpSearch.trim().toLowerCase() + var mcpFilter = String(mcp.filter === undefined ? 'all' : mcp.filter) + var mcpChosen = Array.isArray(mcp.selection) ? mcp.selection : [] + var mcpBulk = mcp.bulk === null || mcp.bulk === undefined ? null : mcp.bulk + var stateOf = function (item) { + return String(item.connectionState === undefined ? 'unknown' : item.connectionState) + } + var isProblem = function (item) { + var state = stateOf(item) + return state !== 'connected' && state !== 'disabled' + } + var haystackOf = function (item) { + var state = stateOf(item) + return [ + item.name, item.key, item.transport, item.authMode, item.injectionLabel, + MCP_STATE_LABELS[state] === undefined ? state : MCP_STATE_LABELS[state], + item.lastError, + item.scope === undefined || item.scope === null ? '' : item.scope.visibility, + ] + .map(function (value) { return String(value === undefined || value === null ? '' : value) }) + .join(' ') + .toLowerCase() + } + var matchesMcp = function (item) { + if (mcpFilter === 'connected' && stateOf(item) !== 'connected') return false + if (mcpFilter === 'disabled' && !(item.enabled === false || stateOf(item) === 'disabled')) return false + if (mcpFilter === 'problem' && !isProblem(item)) return false + if (mcpNeedle === '') return true + return haystackOf(item).indexOf(mcpNeedle) >= 0 + } + var visibleItems = items.filter(matchesMcp) + var mcpCounts = { + connected: items.filter(function (item) { return stateOf(item) === 'connected' }).length, + disabled: items.filter(function (item) { return item.enabled === false || stateOf(item) === 'disabled' }).length, + problem: items.filter(isProblem).length, + } + var matchedSelected = visibleItems.filter(function (item) { return mcpChosen.indexOf(item.key) >= 0 }).length var bridgeBox = null if (mcp.status === 'missing') { bridgeBox = h( @@ -3001,11 +3092,167 @@ window.__ModuleLoader__.load({ }, bridgeBox, mcp.status === 'ok' && items.length === 0 ? h('p', { style: styles.hint }, '宿主还没有登记任何 MCP 连接。') : null, - mcp.status === 'ok' + mcp.status === 'ok' && items.length > 0 ? h( 'div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, - items.map(function (item) { + h( + 'div', + { style: styles.pills }, + h(Pill, { label: '共', value: String(items.length), tone: 'muted' }), + h(Pill, { label: '匹配', value: String(visibleItems.length), tone: visibleItems.length === 0 ? 'muted' : 'ok' }), + h(Pill, { label: '已选', value: String(mcpChosen.length), tone: mcpChosen.length === 0 ? 'muted' : 'ok' }), + h(Pill, { label: '已连接', value: String(mcpCounts.connected), tone: 'ok' }), + h(Pill, { label: '异常', value: String(mcpCounts.problem), tone: mcpCounts.problem === 0 ? 'muted' : 'warn' }), + ), + h( + 'div', + { style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' } }, + h('input', { + type: 'search', + style: Object.assign({}, styles.input, { flex: '1 1 220px', minWidth: 0 }), + value: mcpSearch, + placeholder: '搜索连接:名称 / key / 传输 / 鉴权 / 状态', + 'aria-label': '搜索 MCP 连接', + onChange: function (event) { + patchMcp({ search: event.target.value }) + }, + }), + mcpSearch !== '' + ? h(Btn, { + label: '清空搜索', + variant: 'small', + onClick: function () { + patchMcp({ search: '' }) + }, + }) + : null, + ), + h( + 'div', + { style: Object.assign({}, styles.actions, { flexWrap: 'wrap' }) }, + h(Btn, { + label: '筛选:全部(' + String(items.length) + ')', + variant: mcpFilter === 'all' ? 'primary' : 'small', + onClick: function () { + patchMcp({ filter: 'all' }) + }, + }), + h(Btn, { + label: '已连接(' + String(mcpCounts.connected) + ')', + variant: mcpFilter === 'connected' ? 'primary' : 'small', + onClick: function () { + patchMcp({ filter: 'connected' }) + }, + }), + h(Btn, { + label: '已停用(' + String(mcpCounts.disabled) + ')', + variant: mcpFilter === 'disabled' ? 'primary' : 'small', + onClick: function () { + patchMcp({ filter: 'disabled' }) + }, + }), + h(Btn, { + label: '异常(' + String(mcpCounts.problem) + ')', + variant: mcpFilter === 'problem' ? 'primary' : 'small', + onClick: function () { + patchMcp({ filter: 'problem' }) + }, + }), + ), + h( + 'div', + { style: Object.assign({}, styles.actions, { flexWrap: 'wrap' }) }, + h(Btn, { + label: '全选匹配结果(' + String(visibleItems.length) + ')', + variant: 'small', + disabled: visibleItems.length === 0, + onClick: function () { + selectMcpMany(visibleItems, true) + }, + }), + h(Btn, { + label: '全选全部(' + String(items.length) + ')', + variant: 'small', + disabled: items.length === 0 || mcpChosen.length === items.length, + onClick: function () { + selectMcpMany(items, true) + }, + }), + h(Btn, { + label: '取消勾选匹配项(' + String(matchedSelected) + ')', + variant: 'small', + disabled: matchedSelected === 0, + onClick: function () { + selectMcpMany(visibleItems, false) + }, + }), + h(Btn, { + label: '清空已选', + variant: 'small', + disabled: mcpChosen.length === 0, + onClick: function () { + patchMcp({ selection: [], confirmBulk: false }) + }, + }), + ), + h( + 'div', + { style: Object.assign({}, styles.actions, { flexWrap: 'wrap' }) }, + h(Btn, { + label: '批量健康检查', + variant: 'small', + disabled: mcpChosen.length === 0 || mcp.busy !== '', + onClick: function () { + runMcpBulk('批量健康检查', 'healthCheck', function (item) { return { connectorId: item.connectorId } }) + }, + }), + h(Btn, { + label: '批量启用', + variant: 'small', + disabled: mcpChosen.length === 0 || mcp.busy !== '', + onClick: function () { + runMcpBulk('批量启用', 'setEnabled', function (item) { return { key: item.key, enabled: true } }) + }, + }), + h(Btn, { + label: '批量停用', + variant: 'small', + disabled: mcpChosen.length === 0 || mcp.busy !== '', + onClick: function () { + runMcpBulk('批量停用', 'setEnabled', function (item) { return { key: item.key, enabled: false } }) + }, + }), + h(Btn, { + label: '批量重连', + variant: 'small', + disabled: mcpChosen.length === 0 || mcp.busy !== '', + onClick: function () { + runMcpBulk('批量重连', 'reconnect', function (item) { return { key: item.key } }) + }, + }), + mcp.confirmBulk === true + ? h(Btn, { + label: '确认批量移除(' + String(mcpChosen.length) + ')', + variant: 'danger', + disabled: mcpChosen.length === 0 || mcp.busy !== '', + onClick: function () { + runMcpBulk('批量移除', 'disconnect', function (item) { return { key: item.key } }) + }, + }) + : h(Btn, { + label: '批量移除…', + variant: 'small', + disabled: mcpChosen.length === 0 || mcp.busy !== '', + onClick: function () { + patchMcp({ confirmBulk: true }) + setNotice({ tone: 'warn', text: '批量移除会断开所选 ' + String(mcpChosen.length) + ' 条连接定义;再点一次「确认批量移除」才执行。' }) + }, + }), + ), + mcpBulk === null ? null : h('p', { style: styles.hint }, String(mcpBulk.label) + ' 进行中:' + String(mcpBulk.done) + ' / ' + String(mcpBulk.total)), + visibleItems.length === 0 ? h('p', { style: styles.hint }, '没有匹配「' + mcpSearch + '」的连接。换个关键词或切回「全部」筛选。') : null, + visibleItems.map(function (item) { var state = String(item.connectionState === undefined ? 'unknown' : item.connectionState) var tools = mcp.tools[item.key] return h( @@ -3014,7 +3261,19 @@ window.__ModuleLoader__.load({ h( 'div', { style: styles.rowHead }, - h('span', { style: styles.rowTitle }, String(item.name === undefined ? item.key : item.name)), + h( + 'label', + { style: { display: 'inline-flex', alignItems: 'center', gap: '8px', minWidth: 0 } }, + h('input', { + type: 'checkbox', + checked: mcpChosen.indexOf(item.key) >= 0, + 'aria-label': '选择连接 ' + String(item.name === undefined ? item.key : item.name), + onChange: function (event) { + selectMcpMany([item], event.target.checked === true) + }, + }), + h('span', { style: styles.rowTitle }, String(item.name === undefined ? item.key : item.name)), + ), h( 'div', { style: styles.pills }, diff --git a/lib/index.js b/lib/index.js index 61b6af4..bfa7474 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,7 @@ export const name = 'dsh-brain'; /** Services required before `apply` runs. */ export const inject = ['webServer']; /** Version reported by the status card. */ -const VERSION = '0.9.4'; +const VERSION = '0.9.5'; /** How often the skill directory is reconciled with the cloud center. */ const SKILL_SYNC_INTERVAL_MS = 15 * 60_000; /** How often queued reports are retried. */ diff --git a/lib/mnemon/index.js b/lib/mnemon/index.js index db8ca4f..02de124 100644 --- a/lib/mnemon/index.js +++ b/lib/mnemon/index.js @@ -17,7 +17,7 @@ import { descriptor } from "./descriptor.js"; import { LongMemoryProvider } from "./driver.js"; export { LongMemoryProvider, descriptor }; /** Keep in sync with the package version (asserted by the verify script). */ -const PROVIDER_VERSION = '0.9.4'; +const PROVIDER_VERSION = '0.9.5'; export const definition = defineMemorySpaceProviderDefinition({ manifest: { apiVersion: MEMORY_SPACE_PROVIDER_API_VERSION, diff --git a/package.json b/package.json index 253ec8b..8e51248 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-brain", - "version": "0.9.4", + "version": "0.9.5", "description": "Cloud memory for DSH: report one activity turn per conversation round and expose memory_search / memory_read / memory_add tools against a LongMemory cloud endpoint.", "type": "module", "license": "MIT", diff --git a/src/index.ts b/src/index.ts index 4a1adaa..da2a94b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,7 @@ export const name = 'dsh-brain' export const inject = ['webServer'] /** Version reported by the status card. */ -const VERSION = '0.9.4' +const VERSION = '0.9.5' /** How often the skill directory is reconciled with the cloud center. */ const SKILL_SYNC_INTERVAL_MS = 15 * 60_000 diff --git a/src/mnemon/index.ts b/src/mnemon/index.ts index 49366b8..32b5e34 100644 --- a/src/mnemon/index.ts +++ b/src/mnemon/index.ts @@ -23,7 +23,7 @@ import { LongMemoryProvider } from './driver.ts' export { LongMemoryProvider, descriptor } /** Keep in sync with the package version (asserted by the verify script). */ -const PROVIDER_VERSION = '0.9.4' +const PROVIDER_VERSION = '0.9.5' export const definition = defineMemorySpaceProviderDefinition({ manifest: { diff --git a/verify-card-render.mjs b/verify-card-render.mjs index 0f7225a..65d4095 100644 --- a/verify-card-render.mjs +++ b/verify-card-render.mjs @@ -507,6 +507,16 @@ check('the MCP tab renders the host connection', mcpText.includes('我的连接' check('MCP state, transport and auth are shown', mcpText.includes('已连接') && mcpText.includes('http') && mcpText.includes('bearer')) check('MCP actions are offered', mcpText.includes('健康检查') && mcpText.includes('工具列表') && mcpText.includes('移除连接')) check('the injected tools cache starts empty', mcpText.includes('工具可见不等于业务可调用')) +check('the MCP list has search, filters and select-all', + mcpText.includes('全选匹配结果') && + mcpText.includes('全选全部') && + mcpText.includes('清空已选') && + mcpText.includes('筛选:全部') && + mcpText.includes('批量健康检查')) + +const mcpChosen = await drive('mcp', true, '全选匹配结果(1)') +check('selecting all matched connections reveals the batch removal confirm', + mcpChosen.includes('批量移除…') && mcpChosen.includes('批量停用')) const missing = await drive('mcp', false) check('a missing bridge becomes a stated capability gap', missing.includes('MCP 管理当前不可用') && missing.includes('MCP 服务器配置')) diff --git a/verify-full-load.mjs b/verify-full-load.mjs index 80874a2..25a149d 100644 --- a/verify-full-load.mjs +++ b/verify-full-load.mjs @@ -57,7 +57,7 @@ async function post(path, body) { } const caps = await get('/dsh-brain/capabilities') -check('capabilities answers with 0.9.4', caps.body?.version === '0.9.4', String(caps.body?.version)) +check('capabilities answers with 0.9.5', caps.body?.version === '0.9.5', String(caps.body?.version)) check('P3 market is advertised with one provider', caps.body?.features?.skillsMarketplace === true && caps.body?.features?.marketProviders === 1) check('P3 update and sync-resolve are advertised', caps.body?.features?.skillUpdate === true && caps.body?.features?.syncResolve === true) check('P4/P5/v1.1 flags are advertised', caps.body?.features?.multiClient === true && caps.body?.features?.brainMigration === 'ready') diff --git a/verify-upgrade.mjs b/verify-upgrade.mjs index ee9189d..584de12 100644 --- a/verify-upgrade.mjs +++ b/verify-upgrade.mjs @@ -74,7 +74,7 @@ for (const name of readdirSync(libDir)) { } check('no personal domain remains in shipped lib/', leaked.length === 0, leaked.join(',')) const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8')) -check('package version is the delivery version', pkg.version === '0.9.4', pkg.version) +check('package version is the delivery version', pkg.version === '0.9.5', pkg.version) const passed = results.filter((r) => r.ok).length console.log(`\n${passed}/${results.length} passed`)