refactor(mcp): skeleton connection rows with details toggle, collapse the two heavy sections (0.9.8)

This commit is contained in:
newbie 2026-11-13 11:50:17 +08:00
parent d9339a9094
commit 881f822c69
10 changed files with 146 additions and 101 deletions

View File

@ -991,6 +991,7 @@ window.__ModuleLoader__.load({
// plugin market instead of a broken embedded panel.
function McpCustomSection(props) {
var open = React.useState(false)
var tuple = React.useState({ transport: 'streamable-http', name: '', serverName: '', url: '', command: '', args: '', cwd: '', authMode: 'none', bearerToken: '', apiKeyHeader: 'X-Api-Key', apiKeyValue: '', importJson: '', busy: '', notice: null })
var s = tuple[0]
var set = tuple[1]
@ -1025,8 +1026,17 @@ window.__ModuleLoader__.load({
if (ok && typeof props.onChanged === 'function') props.onChanged()
})
}
return h(Section, { title: '新增 / 导入连接', hint: 'HTTP 与 stdio 都由宿主校验并保存凭据;本卡不回显已有密钥。stdio 的启动命令由你显式填写,云端不会执行任何本机命令。' },
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
return h(Section, {
title: '新增 / 导入连接',
hint: 'HTTP 与 stdio 都由宿主校验并保存凭据;本卡不回显已有密钥。stdio 的启动命令由你显式填写,云端不会执行任何本机命令。',
aside: h(Btn, {
label: open[0] ? '收起' : '展开',
ariaLabel: '展开新增连接',
variant: 'small',
onClick: function () { open[1](!open[0]) },
}),
},
open[0] ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
h('div', { style: styles.grid },
h(Field, { label: '名称', value: s.name, onChange: function (v) { patch({ name: v }) } }),
h(Field, { label: 'Server 名(可选)', value: s.serverName, onChange: function (v) { patch({ serverName: v }) } }),
@ -1065,12 +1075,13 @@ window.__ModuleLoader__.load({
h('textarea', { value: s.importJson, rows: 5, style: Object.assign({}, styles.input, { fontFamily: 'monospace', resize: 'vertical' }), placeholder: '{"mcpServers":{"name":{"url":"…"}}}', onChange: function (e) { patch({ importJson: e.target.value }) } }),
h('div', { style: styles.actions }, h(Btn, { label: s.busy === 'import' ? '导入中…' : '导入 JSON', disabled: s.busy !== '', onClick: importJson })),
s.notice === null ? null : h(Banner, { tone: s.notice.tone }, s.notice.text),
),
) : null,
)
}
function McpConfigSection(props) {
var items = Array.isArray(props.items) ? props.items : []
var open = React.useState(false)
var tuple = React.useState({ key: '', json: '', busy: '', notice: null, scopePreview: null, targetScope: 'global', workspaceId: '', gov: null, policyPreview: null })
var s = tuple[0]
var set = tuple[1]
@ -1139,8 +1150,17 @@ window.__ModuleLoader__.load({
})
}
var gov = s.gov
return h(Section, { title: '连接配置、范围与治理', hint: '配置编辑使用宿主的保留标记合并,空输入不会清空已有密钥;作用域与策略都带 revision 预览后再提交。' },
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
return h(Section, {
title: '连接配置、范围与治理',
hint: '配置编辑使用宿主的保留标记合并,空输入不会清空已有密钥;作用域与策略都带 revision 预览后再提交。',
aside: h(Btn, {
label: open[0] ? '收起' : '展开',
ariaLabel: '展开连接配置',
variant: 'small',
onClick: function () { open[1](!open[0]) },
}),
},
open[0] ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
itemSelect(items, s.key, choose),
s.key === '' ? h('p', { style: styles.hint }, '选择一条连接后可编辑配置、调整范围或设置治理策略。') : h('div', { style: styles.nested },
h('p', { style: styles.hint }, '可编辑配置(保留标记 <KEEP_EXISTING> 表示保留原密钥):'),
@ -1176,7 +1196,7 @@ window.__ModuleLoader__.load({
),
),
s.notice === null ? null : h(Banner, { tone: s.notice.tone }, s.notice.text),
),
) : null,
)
}
@ -1536,7 +1556,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, search: '', filter: 'all', selection: [], bulk: null, confirmBulk: false })
var mcpState = React.useState({ status: 'idle', items: [], error: null, tools: {}, busy: '', confirm: null, search: '', filter: 'all', selection: [], bulk: null, confirmBulk: false, details: {} })
var mcp = mcpState[0]
var setMcp = mcpState[1]
@ -3378,8 +3398,11 @@ window.__ModuleLoader__.load({
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 state = stateOf(item)
var tools = mcp.tools[item.key]
var details = mcp.details === null || mcp.details === undefined ? {} : mcp.details
var open = details[item.key] === true
var label = String(item.name === undefined ? item.key : item.name)
return h(
'div',
{ key: String(item.key), style: styles.row },
@ -3388,101 +3411,117 @@ window.__ModuleLoader__.load({
{ style: styles.rowHead },
h(
'label',
{ style: { display: 'inline-flex', alignItems: 'center', gap: '8px', minWidth: 0 } },
{ style: { display: 'inline-flex', alignItems: 'center', gap: '8px', minWidth: 0, flex: '1 1 auto' } },
h('input', {
type: 'checkbox',
checked: mcpChosen.indexOf(item.key) >= 0,
'aria-label': '选择连接 ' + String(item.name === undefined ? item.key : item.name),
'aria-label': '选择连接 ' + label,
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 },
h('span', { style: styles.rowTitle }, label),
h(Pill, { label: '状态', value: MCP_STATE_LABELS[state] === undefined ? state : MCP_STATE_LABELS[state], tone: state === 'connected' ? 'ok' : state === 'disabled' ? 'muted' : 'warn' }),
h(Pill, { label: '传输', value: String(item.transport === undefined ? '—' : item.transport), tone: 'muted' }),
h(Pill, { label: '鉴权', value: String(item.authMode === undefined ? 'none' : item.authMode), tone: 'muted' }),
h(Pill, { label: '注入', value: String(item.injectionLabel === undefined ? '—' : item.injectionLabel), tone: 'muted' }),
),
h(Btn, {
label: open ? '收起' : '详情',
ariaLabel: (open ? '收起详情 ' : '详情 ') + label,
variant: 'small',
onClick: function () {
patchMcp({ details: Object.assign({}, details, { [String(item.key)]: !open }) })
},
}),
),
h(
'p',
{ style: styles.hint },
'范围:' + (item.scope === undefined || item.scope === null ? '未知' : String(item.scope.visibility === undefined ? JSON.stringify(item.scope) : item.scope.visibility)) + ' · 健康检查:' + formatIso(item.healthCheckedAt) + (item.lastError === null || item.lastError === undefined ? '' : ' · 最近错误:' + String(item.lastError)),
),
h(
'div',
{ style: styles.actions },
h(Btn, {
label: '健康检查',
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction('健康检查 ' + String(item.name), 'healthCheck', { connectorId: item.connectorId }).then(function () {
probeMcp()
})
},
}),
h(Btn, {
label: '工具列表',
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
loadTools(item)
},
}),
h(Btn, {
label: item.enabled === false ? '启用' : '停用',
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction(item.enabled === false ? '启用连接' : '停用连接', 'setEnabled', { key: item.key, enabled: item.enabled === false }).then(function () {
probeMcp()
})
},
}),
h(Btn, {
label: '重连',
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction('重连', 'reconnect', { key: item.key }).then(function () {
probeMcp()
})
},
}),
mcp.confirm === item.key
? h(Btn, {
label: '确认移除',
variant: 'danger',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction('移除连接', 'disconnect', { key: item.key }).then(function () {
patchMcp({ confirm: null })
probeMcp()
})
},
})
: h(Btn, {
label: '移除连接…',
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
patchMcp({ confirm: item.key })
setNotice({ tone: 'warn', text: '再次点击「确认移除」才会断开该连接定义。' })
},
}),
),
tools === undefined
? null
: h(
open
? h(
'div',
{ style: styles.nested },
h('p', { style: styles.hint }, '工具缓存(' + formatTime(tools.at) + '):' + (tools.items.length === 0 ? '空' : tools.items.map(function (tool) { return String(tool.name === undefined ? tool : tool.name) }).join('、'))),
),
{ style: { display: 'flex', flexDirection: 'column', gap: '6px' } },
h(
'div',
{ style: styles.pills },
h(Pill, { label: '鉴权', value: String(item.authMode === undefined ? 'none' : item.authMode), tone: 'muted' }),
h(Pill, { label: '注入', value: String(item.injectionLabel === undefined ? '—' : item.injectionLabel), tone: 'muted' }),
h(Pill, { label: '范围', value: item.scope === undefined || item.scope === null ? '未知' : String(item.scope.visibility === undefined ? JSON.stringify(item.scope) : item.scope.visibility), tone: 'muted' }),
h(Pill, { label: '健康检查', value: formatIso(item.healthCheckedAt), tone: 'muted' }),
),
item.lastError === null || item.lastError === undefined
? null
: h('p', { style: styles.hint }, '最近错误:' + String(item.lastError)),
h(
'div',
{ style: styles.actions },
h(Btn, {
label: '健康检查',
ariaLabel: '健康检查 ' + label,
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction('健康检查 ' + label, 'healthCheck', { connectorId: item.connectorId }).then(function () {
probeMcp()
})
},
}),
h(Btn, {
label: '工具列表',
ariaLabel: '工具列表 ' + label,
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
loadTools(item)
},
}),
h(Btn, {
label: item.enabled === false ? '启用' : '停用',
ariaLabel: '启停 ' + label,
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction(item.enabled === false ? '启用连接' : '停用连接', 'setEnabled', { key: item.key, enabled: item.enabled === false }).then(function () {
probeMcp()
})
},
}),
h(Btn, {
label: '重连',
ariaLabel: '重连 ' + label,
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction('重连', 'reconnect', { key: item.key }).then(function () {
probeMcp()
})
},
}),
mcp.confirm === item.key
? h(Btn, {
label: '确认移除',
ariaLabel: '确认移除 ' + label,
variant: 'danger',
disabled: mcp.busy !== '',
onClick: function () {
mcpAction('移除连接', 'disconnect', { key: item.key }).then(function () {
patchMcp({ confirm: null })
probeMcp()
})
},
})
: h(Btn, {
label: '移除连接…',
ariaLabel: '移除连接 ' + label,
variant: 'small',
disabled: mcp.busy !== '',
onClick: function () {
patchMcp({ confirm: item.key })
setNotice({ tone: 'warn', text: '再次点击「确认移除」才会断开该连接定义。' })
},
}),
),
tools === undefined
? null
: h('p', { style: styles.hint }, '工具缓存(' + formatTime(tools.at) + '):' + (tools.items.length === 0 ? '空' : tools.items.map(function (tool) { return String(tool.name === undefined ? tool : tool.name) }).join('、'))),
)
: null,
)
}),
h('p', { style: styles.hint }, '工具可见不等于业务可调用:连接状态与工具缓存分开显示。'),

View File

@ -199,7 +199,7 @@ refreshCatalog, toolsList, toolSearch, toolExplorer, toolDetail`
| 区块 | 能力 |
|---|---|
| 我的连接 | 搜索(名称/key/传输/鉴权/状态/最近错误)、状态筛选、多选与全选、批量健康检查/启用/停用/重连/两段式批量移除;单条连接的读取、健康检查、工具缓存、启停、重连、两段式移除 |
| 我的连接 | 默认一行骨架(名称 + 状态 + 传输 + 「详情」),展开后才显示鉴权/注入/范围/健康检查/最近错误与单条操作;上方有搜索、状态筛选、多选与全选、批量健康检查/启用/停用/重连/两段式批量移除 |
| ~~MCP 市场~~ | **0.9.6 已删除**:宿主的 `catalog` 方法在当前 dsh-mcp-connector 上返回 `HTTP 405`,内嵌面板只能显示错误条。目录浏览与安装回到宿主自己的插件市场,本卡不再渲染该区块 |
| 新增 / 导入 | 自定义 Streamable HTTP 与 stdio 连接(显示实际启动命令,云端不执行)、`importJson` 批量导入 |
| 配置编辑 | `editableConnectionConfig` 读取(敏感值以 `<KEEP_EXISTING>` 保留标记返回),`reconfigureConnection` 保存;空输入不清除已有密钥 |

View File

@ -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.7';
const VERSION = '0.9.8';
/** 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. */

View File

@ -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.7';
const PROVIDER_VERSION = '0.9.8';
export const definition = defineMemorySpaceProviderDefinition({
manifest: {
apiVersion: MEMORY_SPACE_PROVIDER_API_VERSION,

View File

@ -1,6 +1,6 @@
{
"name": "dsh-brain",
"version": "0.9.7",
"version": "0.9.8",
"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",

View File

@ -30,7 +30,7 @@ export const name = 'dsh-brain'
export const inject = ['webServer']
/** Version reported by the status card. */
const VERSION = '0.9.7'
const VERSION = '0.9.8'
/** How often the skill directory is reconciled with the cloud center. */
const SKILL_SYNC_INTERVAL_MS = 15 * 60_000

View File

@ -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.7'
const PROVIDER_VERSION = '0.9.8'
export const definition = defineMemorySpaceProviderDefinition({
manifest: {

View File

@ -510,8 +510,14 @@ check('no render boundary error on the skills tab', !skillsText.includes('渲染
const mcpText = await drive('mcp', true)
check('the MCP tab renders the host connection', mcpText.includes('我的连接') && mcpText.includes('demo-mcp'))
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('collapsed rows keep only name, state and transport',
mcpText.includes('已连接') && mcpText.includes('http') && !mcpText.includes('bearer'))
check('the heavier MCP sections start collapsed',
!mcpText.includes('校验并保存连接') && !mcpText.includes('预览作用域') && mcpText.includes('展开'))
const mcpDetail = await drive('mcp', true, '详情 demo-mcp')
check('expanding a connection reveals auth, scope and actions',
mcpDetail.includes('bearer') && mcpDetail.includes('健康检查') && mcpDetail.includes('工具列表') && mcpDetail.includes('移除连接'))
check('the injected tools cache starts empty', mcpText.includes('工具可见不等于业务可调用'))
check('the MCP list has search, filters and select-all',
mcpText.includes('全选匹配结果') &&

View File

@ -57,7 +57,7 @@ async function post(path, body) {
}
const caps = await get('/dsh-brain/capabilities')
check('capabilities answers with 0.9.7', caps.body?.version === '0.9.7', String(caps.body?.version))
check('capabilities answers with 0.9.8', caps.body?.version === '0.9.8', 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')

View File

@ -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.7', pkg.version)
check('package version is the delivery version', pkg.version === '0.9.8', pkg.version)
const passed = results.filter((r) => r.ok).length
console.log(`\n${passed}/${results.length} passed`)