feat: add bounded connection network diagnostics
This commit is contained in:
@@ -10,6 +10,7 @@ import { NativeParameters } from './NativeParameters';
|
||||
import { ModelErrorDetails } from './ModelErrorDetails';
|
||||
import { ModelBudgetSettings } from './ModelBudgetSettings';
|
||||
import { modelRequestUrl, protocolLabel } from '../shared/contracts/model-endpoint.mjs';
|
||||
import { ModelNetworkDiagnostics } from './ModelNetworkDiagnostics';
|
||||
|
||||
const previewUrl = (value: { protocol: string; baseUrl: string }) => { try { return modelRequestUrl(value); } catch { return '请填写有效的接口根地址'; } };
|
||||
|
||||
@@ -42,6 +43,7 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig:
|
||||
const [working, setWorking] = useState(false), [notice, setNotice] = useState('');
|
||||
const [noticeFailure, setNoticeFailure] = useState<RuntimeFailure | null>(null);
|
||||
const [probeScopes, setProbeScopes] = useState<Record<string, string>>({});
|
||||
const [networkTarget, setNetworkTarget] = useState('');
|
||||
const [operations, setOperations] = useState<Operations | null>(null), [autoInspect, setAutoInspect] = useState(false);
|
||||
const [importPath, setImportPath] = useState(''), [importSource, setImportSource] = useState('ccswitch');
|
||||
const [preview, setPreview] = useState<{ id: string; entries: { id: string; name: string; model: string; baseUrl: string; hasKey: boolean }[]; notices: string[] } | null>(null);
|
||||
@@ -87,7 +89,7 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig:
|
||||
const locked = working || busy;
|
||||
return <section className="model-center" aria-label="模型控制台" aria-busy={working}>
|
||||
<div className="mc-overview"><div><span className="mc-eyebrow">MODEL CONTROL</span><h2>选择模型,继续开发。</h2><p>连接、模型池和实际请求使用同一个入口。</p></div><div className="mc-current"><Route size={18} /><span>新任务默认<strong>{runtimeConfig?.mode === 'demo' ? '离线演示' : selectionName || '正在读取'}</strong></span><span className="mc-count">{view?.waiting ?? 0} 等待</span></div></div>
|
||||
<nav ref={tabsRef} className="mc-tabs" aria-label="模型中心分类">{[['connections', '模型连接', Server], ['pools', '模型池', Layers3], ['budgets', '运行预算', Settings2], ['waits', '等待时限', Settings2], ['attempts', '请求账本', Route], ['imports', '配置导入', Settings2], ['credentials', '凭据保存', KeyRound], ['operations', '运行巡检', Activity]].map(([id, title, Icon]) => {
|
||||
<nav ref={tabsRef} className="mc-tabs" aria-label="模型中心分类">{[['connections', '模型连接', Server], ['network', '连接诊断', Activity], ['pools', '模型池', Layers3], ['budgets', '运行预算', Settings2], ['waits', '等待时限', Settings2], ['attempts', '请求账本', Route], ['imports', '配置导入', Settings2], ['credentials', '凭据保存', KeyRound], ['operations', '运行巡检', Activity]].map(([id, title, Icon]) => {
|
||||
const Symbol = Icon as typeof Server; return <button key={id as string} type="button" aria-current={tab === id ? 'page' : undefined} onClick={() => { setTab(id as string); setNotice(''); }}><Symbol size={16} />{title as string}</button>;
|
||||
})}<button className="mc-refresh" type="button" disabled={working} onClick={() => void act(refresh)} aria-label="刷新模型中心"><RefreshCw size={16} /></button></nav>
|
||||
{notice && <div className="mc-notice" role="status">{notice}{noticeFailure && <ModelErrorDetails failure={noticeFailure} />}</div>}
|
||||
@@ -117,6 +119,7 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig:
|
||||
{value.health.reason && <p className="mc-card-warning">{value.health.reason}{!!value.health.cooldownUntil && value.health.cooldownUntil > Date.now() && ' · 冷却至 ' + new Date(value.health.cooldownUntil).toLocaleTimeString()}</p>}
|
||||
<footer><button className="button secondary" disabled={locked || !value.enabled} onClick={() => void act(async () => { const result = await api<{ config: Config }>('/model-center/select', { type: value.id === 'legacy-default' ? 'legacy' : 'connection', id: value.id }); onConfig(result.config, { type: value.id === 'legacy-default' ? 'legacy' : 'connection', id: value.id, name: value.name }); })}>{selected?.id === value.id ? <Check size={14} /> : <Route size={14} />}{selected?.id === value.id ? '当前使用' : '用于新任务'}</button>
|
||||
<button className="button secondary" disabled={locked} onClick={() => { if (value.id === 'legacy-default') { onLegacy(); return; } setDraft({ ...initial, ...value, modelIdentityAliasesText: (value.modelIdentityAliases ?? []).join(', '), streaming: value.streaming === true, capabilityDeclarations: { ...initial.capabilityDeclarations, ...value.capabilityDeclarations } }); setKey(''); setPersistKey(false); setEditing(true); }}>编辑</button>
|
||||
<button className="button secondary" onClick={() => { setNetworkTarget(value.id); setTab('network'); }}>连接诊断</button>
|
||||
{value.id !== 'legacy-default' && <button className="mc-icon-action" aria-label={(value.enabled ? '停用' : '启用') + value.name} disabled={working} onClick={() => void act(async () => { await api('/model-center/toggle', { id: value.id, enabled: !value.enabled }); })}><Power size={15} />{value.enabled ? '停用' : '启用'}</button>}
|
||||
<label className="mc-probe-scope">检测范围<select aria-label={value.name + '检测范围'} value={probeScopes[value.id] ?? 'text'} disabled={locked} onChange={event => setProbeScopes({ ...probeScopes, [value.id]: event.target.value })}><option value="text">文本响应</option><option value="tools">工具调用</option><option value="streaming">流式文本</option><option value="vision">合成图像识别</option></select></label>
|
||||
<button className="button secondary" disabled={locked} onClick={() => { setNativeTarget(value); setEditing(false); }}>原生参数</button><button className="mc-probe" disabled={locked || !value.enabled} onClick={() => void act(async () => { const result = await api<{ scope: string }>('/model-center/probe', { id: value.id, scope: probeScopes[value.id] ?? 'text' }); if (alive.current) setNotice(capabilityLabels[result.scope] + '检测通过;只验证所选能力,原请求与用量已记入账本。'); })}>验证响应(调用模型)</button></footer>
|
||||
@@ -147,6 +150,7 @@ export function ModelCenter({ onConfig, onLegacy, busy, runModel }: { onConfig:
|
||||
<div className="mc-actions"><button className="button secondary" type="button" onClick={() => { setEditing(false); setKey(''); }}>取消</button><button className="button primary" disabled={locked || persistKey && !key.trim()} type="submit">保存模型连接</button></div>
|
||||
</form>}
|
||||
</>}
|
||||
{tab === 'network' && <ModelNetworkDiagnostics connections={view.connections} initialId={networkTarget || (selected?.type !== 'pool' ? selected?.id : undefined)} disabled={locked} />}
|
||||
{tab === 'credentials' && <section aria-label="本机加密凭据">
|
||||
<div className="mc-section-title"><div><h3>本机加密凭据</h3><p>使用当前Windows用户加密。保存后的 Key 不会回显或包含在导出中。</p></div></div>
|
||||
{!credentialView ? <p className="mc-empty">正在核对本机保存状态…</p> : <>
|
||||
|
||||
Reference in New Issue
Block a user