feat: integrate approved MCP tools and recovery for 1.12

This commit is contained in:
Agent Workbench Dev
2026-10-30 20:34:54 +08:00
parent 601f13c4f8
commit 3f6797b8ee
80 changed files with 5141 additions and 70 deletions
+7 -1
View File
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { Activity, Brain, ClipboardCheck, RotateCw, ArrowDownToLine, ArrowRight, ArrowUp, BookOpenText, Check, ChevronDown, ChevronRight, Code2, Copy, File, FileCode2, Folder, FolderOpen, GitBranch, Link2, LoaderCircle, Maximize2, MessageSquare, Minimize2, PanelLeftClose, PanelLeftOpen, Pencil, Play, Plus, Search, Server as ModelServer, Settings2, ShieldCheck, Square, SquareTerminal, Trash2, X } from 'lucide-react';
import { Activity, Brain, ClipboardCheck, RotateCw, ArrowDownToLine, ArrowRight, ArrowUp, BookOpenText, Check, ChevronDown, ChevronRight, Code2, Copy, File, FileCode2, Folder, FolderOpen, GitBranch, Link2, LoaderCircle, Maximize2, MessageSquare, Minimize2, PanelLeftClose, PanelLeftOpen, Pencil, Play, Plus, Puzzle, Search, Server as ModelServer, Settings2, ShieldCheck, Square, SquareTerminal, Trash2, X } from 'lucide-react';
import type { Bootstrap, Change, Config, FileEntry, OpenFile, Project, ResearchDoc, Session, SessionBrief, ToolEvent, RuntimeDiagnostics, RuntimeFailure } from './types';
import { api, downloadBlob, exportSession, setToken } from './api';
import { DiffView, EmptyInspector, IconButton, Modal, ResearchContent, Status, ToolRow, FailureCard } from './components';
@@ -12,8 +12,10 @@ import { EnginePanel } from './EnginePanel';
import { ModelCenter } from './ModelCenter';
import { ProjectMemoryPanel } from './ProjectMemoryPanel';
import { SkillCenter } from './SkillCenter';
import { McpPanel } from './McpPanel';
const activeStates = ['running', 'awaiting_approval', 'stopping'];
const activeMcpStates = ['queued', 'connecting', 'discovering', 'calling', 'closing', 'stopping'];
const defaultConfig: Config = { mode: 'demo', baseUrl: 'http://127.0.0.1:11434/v1', model: '', contextLimit: 16000, maxSteps: 12, maxOutputTokens: 2048, hasKey: false, maxRunDurationMs: 600000, maxRunTokens: 200000, maxTaskTokens: 1000000 };
export default function App() {
@@ -70,6 +72,7 @@ export default function App() {
const [modelCenterOpen, setModelCenterOpen] = useState(false);
const [memoryOpen, setMemoryOpen] = useState(false);
const [skillsOpen, setSkillsOpen] = useState(false);
const [mcpOpen, setMcpOpen] = useState(false);
const [researchDocs, setResearchDocs] = useState<ResearchDoc[]>([]);
const [report, setReport] = useState<{ title: string; content: string } | null>(null);
const chatEnd = useRef<HTMLDivElement>(null);
@@ -95,6 +98,7 @@ export default function App() {
|| session.execution?.workspaces?.some(value => ['creating', 'verifying', 'registering'].includes(value.status)) === true
|| session.execution?.researchJobs?.some(value => ['queued', 'connecting', 'analyzing', 'stopping'].includes(value.status)) === true
|| session.execution?.engineJobs?.some(value => ['queued', 'starting', 'initializing', 'checking', 'stopping'].includes(value.status)) === true
|| session.execution?.mcpJobs?.some(value => activeMcpStates.includes(value.status)) === true
|| session.execution?.browserJobs?.some(value => ['queued', 'snapshotting', 'launching', 'running', 'closing'].includes(value.status)) === true);
const anyRunning = isRunning || briefs.some(item => activeStates.includes(item.status));
const pending = session?.changes.filter(change => ['pending', 'conflict'].includes(change.status)) || [];
@@ -513,6 +517,7 @@ export default function App() {
<div className="task-toolbar"><span className="task-local"><GitBranch size={13} />本地项目</span>{session ? <Status value={session.status} /> : <span className="subtle">等待新任务</span>}<div className="toolbar-actions">
<IconButton label="运行诊断" onClick={() => openDiagnostics()}><Activity size={15} /></IconButton>
<IconButton label="项目技能" onClick={() => setSkillsOpen(true)} disabled={!selectedProject}><BookOpenText size={15} /></IconButton>
<IconButton label="项目MCP工具" onClick={() => setMcpOpen(true)} disabled={!selectedProject}><Puzzle size={15} /></IconButton>
<IconButton label="查看任务记录" onClick={() => showInspector('task')}><ClipboardCheck size={15} /></IconButton>
<IconButton label="本地代理引擎" onClick={() => setEngineOpen(true)} disabled={!session}><Link2 size={15} /></IconButton>
<IconButton label="REA 工件研究" onClick={() => void openRea()} disabled={!selectedProject || creatingSession}><BookOpenText size={15} /></IconButton>
@@ -559,6 +564,7 @@ export default function App() {
{modelCenterOpen && <Modal title="模型中心" description="连接、模型池与执行健康统一管理。" wide onClose={() => setModelCenterOpen(false)}><ModelCenter busy={anyRunning} onConfig={setConfig} onLegacy={() => { setModelCenterOpen(false); openSettings(); }} /></Modal>}
{memoryOpen && selectedProject && <Modal title="项目记忆" description="项目事实与决策绑定源码指纹,变化后自动要求重新核对。" wide onClose={() => setMemoryOpen(false)}><ProjectMemoryPanel key={selectedProject.id + ':' + (session?.id ?? '')} project={selectedProject} session={session?.projectId === selectedProject.id ? session : null} /></Modal>}
{skillsOpen && selectedProject && <Modal title="项目技能" description="管理当前项目的技能来源、版本与启用状态。" wide onClose={() => setSkillsOpen(false)}><SkillCenter key={selectedProject.id} projectId={selectedProject.id} busy={isRunning} /></Modal>}
{mcpOpen && selectedProject && <Modal title="项目 MCP 工具" description="实际探测本地 stdio 服务,选择可以请求的工具,并核对每次运行原记录。" wide onClose={() => setMcpOpen(false)}><McpPanel key={selectedProject.id + ':' + (session?.id ?? '')} projectId={selectedProject.id} session={session?.projectId === selectedProject.id ? session : null} busy={isRunning} onSession={acceptSession} onError={session ? failureFor(session) : failure} /></Modal>}
{toast && <div className="toast" role="status"><span>{toast}</span><IconButton label="关闭提示" onClick={() => setToast('')}><X size={14} /></IconButton></div>}
</div>
);
+70
View File
@@ -0,0 +1,70 @@
import { useEffect, useRef, useState } from 'react';
import { AlertTriangle, Check, CircleAlert, Clock3, Download, FileText, LoaderCircle, ShieldCheck } from 'lucide-react';
import type { McpJob, Session } from './types';
import { api } from './api';
import { Modal } from './components';
import './McpPanel.css';
const active = ['queued', 'connecting', 'discovering', 'calling', 'closing', 'stopping'];
const labels: Record<string, string> = { queued: '排队', connecting: '正在连接', discovering: '发现工具', calling: '正在调用', closing: '正在关闭', stopping: '正在停止', completed: '完成', failed: '失败', cancelled: '已停止', unknown: '结果待核对' };
const timestamp = (value: string | null) => value ? new Date(value).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }) : '进行中';
type Evidence = { job: McpJob; report: Record<string, unknown> | null; input: { artifactId: string; sha256: string; input: Record<string, unknown> }; evidenceSha256: string; note: string };
export function McpJobHistory({ session, jobs, busy, onSession, onError }: {
session: Session; jobs: McpJob[]; busy: boolean; onSession: (value: Session) => void; onError: (error: unknown) => void;
}) {
const [selected, setSelected] = useState<Evidence | null>(null);
const [review, setReview] = useState<Evidence | null>(null);
const [working, setWorking] = useState(false);
const request = useRef(0);
const currentTask = session.execution?.task?.id;
const visible = jobs.filter(job => job.taskId === currentTask || job.requiresVerification).slice().reverse();
useEffect(() => { request.current++; setSelected(null); setReview(null); setWorking(false); }, [session.id, currentTask]);
async function open(job: McpJob, forReview = false) {
const id = ++request.current; setWorking(true);
try {
const value = await api<Evidence>('/sessions/' + session.id + '/mcp/jobs/' + job.id + '/evidence');
if (request.current === id) { setSelected(value); if (forReview) setReview(value); }
}
catch (error) { if (request.current === id) onError(error); }
finally { if (request.current === id) setWorking(false); }
}
async function acknowledge() {
if (!review) return; const id = ++request.current; setWorking(true);
try {
await api('/sessions/' + session.id + '/mcp/jobs/' + review.job.id + '/acknowledge', { confirm: true, evidence_sha256: review.evidenceSha256 });
const updated = await api<Session>('/sessions/' + session.id);
if (request.current === id) { onSession(updated); setReview(null); }
} catch (error) { if (request.current === id) onError(error); }
finally { if (request.current === id) setWorking(false); }
}
return <>
<section className="task-record-section mcp-history" aria-label="MCP运行记录">
<div className="record-heading"><ShieldCheck size={15} /><h3>MCP 运行记录</h3><span>{visible.length} 项</span></div>
{visible.length ? <div className="mcp-history-list">{visible.map(job => <article className={'mcp-history-row state-' + job.status} key={job.id}>
<div className="mcp-history-title"><div><strong>{job.input?.call?.tool || (job.operation === 'probe' ? '协议与工具探测' : '工具调用')}</strong><small>{timestamp(job.startedAt)} · {job.operation === 'probe' ? '探测' : '调用'}</small></div>
<span className={'mcp-job-state state-' + job.status}>{active.includes(job.status) && <LoaderCircle size={12} className="spin" />}{job.requiresVerification && <CircleAlert size={12} />}{job.status === 'unknown' && job.reviewedAt && !job.requiresVerification ? '已人工核对 · 原结果未知' : labels[job.status] ?? job.status}</span></div>
<div className="mcp-history-meta"><span>Task {job.taskId.slice(0, 8)}</span><span>Run {job.runId.slice(0, 8)}</span><span>PID {job.pid ?? '未启动'}</span>
<span>{job.cleanup?.rootExited ? '所属进程已退出' : job.finishedAt ? '进程退出待核对' : '进程运行中'}</span></div>
{job.error?.message && <p className="mcp-history-error">{job.error.message}</p>}
<div className="mcp-history-actions"><button type="button" className="button secondary" disabled={!job.inputArtifactId || working} onClick={() => void open(job)}><FileText size={14} />{job.reportArtifactId ? '查看原报告' : '查看原始输入'}</button>
{job.requiresVerification && <button type="button" className="button secondary" disabled={busy || working || !job.inputArtifactId} onClick={() => void open(job, true)}><AlertTriangle size={14} />人工核对结果</button>}</div>
</article>)}</div> : <p className="mcp-history-empty"><Clock3 size={15} />当前任务还没有 MCP 操作记录。</p>}
{selected && <section className="mcp-report" aria-label="MCP原报告"><header><strong>{selected.report ? '原始 MCP 报告' : '已封存的原始输入'}</strong><button type="button" className="text-button" onClick={() => setSelected(null)}>关闭</button></header>
<div className="mcp-report-meta"><span>SHA256</span><code>{selected.job.reportSha256 ?? selected.input.sha256}</code><span>Task / Run</span><code>{selected.job.taskId} / {selected.job.runId}</code></div>
<p className="mcp-boundary-note">报告绑定原 Task/Run 和工具输入。独立所属进程不等于 OS 沙箱,报告也不能证明外部程序没有网络或其他副作用。</p>
<details className="mcp-original-input"><summary>查看原始操作输入 · SHA256 {selected.input.sha256.slice(0, 16)}</summary><pre>{JSON.stringify(selected.input.input, null, 2)}</pre></details>
{selected.report ? <pre tabIndex={0}>{JSON.stringify(selected.report, null, 2)}</pre> : <p className="mcp-history-error">{selected.note}</p>}
<button type="button" className="text-button" onClick={() => { const blob = new Blob([JSON.stringify(selected.report ?? selected, null, 2)], { type: 'application/json' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = (selected.report ? 'mcp-report-' : 'mcp-recovery-') + selected.job.id + '.json'; link.click(); setTimeout(() => URL.revokeObjectURL(link.href), 1000); }}><Download size={13} />{selected.report ? '下载显示的原报告' : '下载已保存的记录'}</button>
</section>}
</section>
{review && <Modal title="核对未知的外部结果" description="这只记录人工核对,不会把未知结果改成成功。" onClose={() => setReview(null)}>
<div className="mcp-review-warning"><AlertTriangle size={17} /><p>外部副作用可能已经发生。请核对原输入、当前文件和程序状态;历史PID仅供核对,不会被用来停止进程。</p></div>
<p className="mcp-boundary-note">{review.note}</p>
<details className="mcp-original-input"><summary>查看已校验原始输入</summary><pre>{JSON.stringify(review.input.input, null, 2)}</pre></details>
<div className="modal-actions"><button type="button" className="button secondary" disabled={working} onClick={() => setReview(null)}>返回</button><button type="button" className="button primary" disabled={working || !review.evidenceSha256} onClick={() => void acknowledge()}>{working ? <LoaderCircle size={14} className="spin" /> : <Check size={14} />}{review.report ? '我已查看原报告' : '我已核对原输入和进程'}</button></div>
</Modal>}
</>;
}
+99
View File
@@ -0,0 +1,99 @@
.mcp-panel { color: #253b4b; --mcp-line: #cad5dc; --mcp-ink: #183849; --mcp-muted: #607584; --mcp-surface: #f2f6f6; }
.mcp-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.mcp-kicker { display: flex; align-items: center; gap: 7px; color: #496f73; font-size: 11px; font-weight: 700; }
.mcp-heading h3 { margin: 8px 0; color: var(--mcp-ink); font: 700 23px/1.35 'Microsoft YaHei UI', 'Segoe UI', sans-serif; }
.mcp-heading p { max-width: 640px; margin: 0; color: var(--mcp-muted); font-size: 13px; line-height: 1.7; }
.mcp-heading > button { flex: 0 0 auto; }
.mcp-status-bar { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; padding: 12px 2px; border-block: 1px solid var(--mcp-line); color: #496171; font-size: 12px; }
.mcp-status-bar > span { display: inline-flex; align-items: center; gap: 7px; }
.mcp-light { width: 7px; height: 7px; border-radius: 50%; background: #2f816b; }
.mcp-alert, .mcp-notice, .mcp-warning, .mcp-boundary { display: flex; align-items: start; gap: 9px; padding: 11px 12px; margin: 12px 0; border: 1px solid #d8c4b8; background: #fff7f1; color: #92563c; font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.mcp-alert svg, .mcp-notice svg, .mcp-boundary svg { flex: 0 0 auto; margin-top: 2px; }
.mcp-notice { border-color: #bdd8cb; background: #eff7f3; color: #356b5e; }
.mcp-warning { border: 0; padding: 0; background: transparent; color: #8f642d; }
.mcp-boundary { border-color: #c5d8d8; background: #f0f7f6; color: #456d6a; }
.mcp-registration-list { display: grid; gap: 12px; margin-top: 14px; }
.mcp-registration { min-width: 0; padding: 16px; border: 1px solid var(--mcp-line); border-left: 4px solid #6c8990; border-radius: 5px; background: #fff; }
.mcp-registration.status-changed { border-left-color: #aa6548; }
.mcp-registration-heading { display: flex; align-items: start; gap: 10px; }
.mcp-registration-heading > svg { flex: 0 0 auto; margin-top: 2px; color: #4d7479; }
.mcp-registration-heading > div { flex: 1; min-width: 0; }
.mcp-registration-heading h4 { margin: 0 0 4px; color: #203f4b; font-size: 15px; overflow-wrap: anywhere; }
.mcp-registration-heading p { margin: 0; color: var(--mcp-muted); font-size: 11px; }
.mcp-enabled { flex: 0 0 auto; padding: 4px 7px; border: 1px solid #d0d9dc; color: #60717a; font-size: 10px; border-radius: 3px; }
.mcp-enabled.on { color: #276855; border-color: #b6d2c7; background: #edf6f1; }
.mcp-source { display: grid; gap: 9px; margin: 14px 0; padding: 11px; background: var(--mcp-surface); font-size: 11px; }
.mcp-source > div { display: grid; gap: 3px; min-width: 0; }
.mcp-source > div > span, .mcp-source > span { color: #637781; }
.mcp-source code, .mcp-source small { overflow-wrap: anywhere; word-break: break-word; }
.mcp-source code { color: #243e4c; font: 11px/1.55 Consolas, monospace; }
.mcp-source small { display: flex; align-items: center; gap: 5px; color: #648077; font-size: 10px; }
.mcp-contract-line { display: flex; align-items: center; gap: 6px; margin: 12px 0; color: #357566; font-size: 11px; overflow-wrap: anywhere; }
.mcp-tool-list { border-top: 1px solid #e1e8e8; padding-top: 11px; }
.mcp-tool-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 12px; }
.mcp-tool-heading span { color: var(--mcp-muted); font-size: 10px; }
.mcp-tool-option { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 9px; padding: 10px 7px; border-top: 1px solid #ebefef; }
.mcp-tool-option > input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: #347b70; }
.mcp-tool-option > span { min-width: 0; display: grid; gap: 4px; }
.mcp-tool-option strong { color: #294a54; font-size: 12px; overflow-wrap: anywhere; }
.mcp-tool-option em { color: #9a5b42; font-size: 10px; font-style: normal; }
.mcp-tool-option small { color: #687c84; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.mcp-tool-option details { color: #526d72; font-size: 10px; }
.mcp-tool-option summary { width: fit-content; min-height: 26px; padding: 4px 0; cursor: pointer; }
.mcp-tool-option pre, .mcp-report pre { max-height: 260px; overflow: auto; padding: 10px; background: #f1f5f5; color: #314e59; white-space: pre-wrap; overflow-wrap: anywhere; font: 10px/1.6 Consolas, monospace; }
.mcp-tool-option.unsupported { opacity: .7; }
.mcp-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.mcp-register { margin-top: 18px; padding: 16px; border: 1px solid var(--mcp-line); border-radius: 5px; background: var(--mcp-surface); }
.mcp-register-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 13px; }
.mcp-register-heading h4 { display: flex; align-items: center; gap: 6px; margin: 0; color: #294753; font-size: 13px; }
.mcp-register-heading span { color: var(--mcp-muted); font-size: 10px; }
.mcp-form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 11px; }
.mcp-form-grid label { display: grid; gap: 5px; min-width: 0; color: #4d6571; font-size: 11px; font-weight: 600; }
.mcp-full { grid-column: 1 / -1; }
.mcp-panel input:not([type="checkbox"]) { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid #c7d3d6; border-radius: 3px; background: #fff; color: #233d49; font: 12px/1.45 'Segoe UI', 'Microsoft YaHei UI', sans-serif; }
.mcp-panel input:focus-visible, .mcp-panel summary:focus-visible, .mcp-report pre:focus-visible { outline: 2px solid #4b8580; outline-offset: 2px; }
.mcp-register footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--mcp-muted); font-size: 10px; line-height: 1.5; }
.mcp-empty, .mcp-history-empty { display: flex; flex-direction: column; align-items: center; gap: 9px; padding: 24px 12px; margin: 12px 0; border: 1px dashed #c9d6d9; color: #657b82; text-align: center; font-size: 12px; }
.mcp-empty strong { color: #36565d; font-size: 13px; }
.mcp-empty p { max-width: 530px; margin: 0; line-height: 1.65; }
.mcp-history { margin-top: 18px; }
.mcp-history-list { display: grid; gap: 8px; }
.mcp-history-row { padding: 11px; border: 1px solid #d4dfe0; border-left: 3px solid #66888a; border-radius: 4px; background: #fff; }
.mcp-history-row.state-unknown { border-left-color: #b45d44; background: #fffaf7; }
.mcp-history-title { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.mcp-history-title > div { min-width: 0; display: grid; gap: 3px; }
.mcp-history-title strong { color: #2b4650; font-size: 12px; overflow-wrap: anywhere; }
.mcp-history-title small { color: #6e8086; font-size: 10px; }
.mcp-job-state { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 5px; color: #46786b; font-size: 10px; }
.mcp-job-state.state-failed, .mcp-job-state.state-unknown { color: #a34e3d; }
.mcp-history-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 8px; color: #6a7e83; font-size: 10px; overflow-wrap: anywhere; }
.mcp-history-error { color: #9a5240; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.mcp-history-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.mcp-report { margin-top: 12px; border: 1px solid #c8d7d7; border-radius: 4px; overflow: hidden; }
.mcp-report header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 11px; background: #eaf2f1; color: #355b5a; font-size: 12px; }
.mcp-report-meta { display: grid; grid-template-columns: 75px minmax(0, 1fr); gap: 5px 9px; padding: 10px 11px 0; color: #6a7f80; font-size: 10px; }
.mcp-report-meta code { min-width: 0; color: #48656a; overflow-wrap: anywhere; }
.mcp-report pre { max-height: 360px; margin: 0; }
.mcp-original-input { padding: 8px 11px; border-top: 1px solid #dce6e5; color: #536e70; font-size: 10px; }
.mcp-original-input summary { min-height: 26px; padding: 4px 0; cursor: pointer; overflow-wrap: anywhere; }
.mcp-original-input pre { max-height: 220px; margin: 5px 0 0; overflow: auto; padding: 10px; background: #f1f5f5; color: #314e59; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/1.6 Consolas, monospace; }
.mcp-report > .text-button { margin: 8px; }
.mcp-boundary-note { padding: 0 11px; color: #7c6954; font-size: 10px; line-height: 1.55; }
.mcp-review-warning { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; align-items: start; padding: 12px; border: 1px solid #e0c7b8; background: #fff7f1; color: #89533e; font-size: 12px; line-height: 1.65; }
.mcp-review-warning p { margin: 0; }
.mcp-probe-summary { display: grid; gap: 8px; padding: 12px; border: 1px solid #cad9d9; background: #f3f7f6; font-size: 12px; }
.mcp-probe-summary code { overflow-wrap: anywhere; color: #39575e; font: 11px/1.5 Consolas, monospace; }
.mcp-probe-summary span { color: #7d5e48; line-height: 1.55; }
@media (max-width: 620px) {
.mcp-heading { flex-direction: column; gap: 12px; }
.mcp-heading h3 { font-size: 20px; }
.mcp-registration, .mcp-register { padding: 12px; }
.mcp-form-grid { grid-template-columns: minmax(0, 1fr); }
.mcp-full { grid-column: auto; }
.mcp-register footer { flex-direction: column; align-items: stretch; }
.mcp-register footer .button { justify-content: center; }
.mcp-controls > .button { flex: 1 1 auto; justify-content: center; }
.mcp-history-title { flex-direction: column; }
.mcp-history-actions > .button { flex: 1; justify-content: center; }
.mcp-panel .button { min-height: 44px; }
}
+148
View File
@@ -0,0 +1,148 @@
import { useEffect, useRef, useState } from 'react';
import type { FormEvent } from 'react';
import { AlertTriangle, Check, CircleAlert, Fingerprint, LoaderCircle, PlugZap, Plus, Power, RefreshCw, ShieldCheck, Terminal } from 'lucide-react';
import type { McpJob, McpRegistration, Session } from './types';
import { api } from './api';
import { Modal } from './components';
import { McpJobHistory } from './McpJobHistory';
import './McpPanel.css';
const active = ['queued', 'connecting', 'discovering', 'calling', 'closing', 'stopping'];
const stateName: Record<string, string> = { verified: '握手已核验', unverified: '尚未探测', changed: '来源或契约异常' };
type View = { projectId: string; revision: number; protocolVersion: string; boundary: string; limits: Record<string, number>; registrations: McpRegistration[] };
type Draft = { name: string; executable: string; entry: string; timeoutMs: number };
export function McpPanel({ projectId, session, busy, onSession, onError }: {
projectId: string; session: Session | null; busy: boolean; onSession: (value: Session) => void; onError: (error: unknown) => void;
}) {
const [view, setView] = useState<View | null>(null), [jobs, setJobs] = useState<McpJob[]>([]);
const [working, setWorking] = useState(false), [error, setError] = useState(''), [notice, setNotice] = useState('');
const [selectedTools, setSelectedTools] = useState<Record<string, string[]>>({});
const [draft, setDraft] = useState<Draft>({ name: '', executable: '', entry: '', timeoutMs: 15000 });
const [probeTarget, setProbeTarget] = useState<McpRegistration | null>(null);
const [requestError, setRequestError] = useState('');
const generation = useRef(0), revisions = useRef(new Map<string, number>()), mounted = useRef(true);
const url = '/projects/' + projectId + '/mcp';
const busyJobs = jobs.some(job => active.includes(job.status));
const locked = busy || busyJobs || working;
useEffect(() => { mounted.current = true; return () => { mounted.current = false; generation.current++; }; }, []);
async function load(current = generation.current) {
const [nextView, nextJobs] = await Promise.all([
api<View>(url), session ? api<McpJob[]>('/sessions/' + session.id + '/mcp/jobs') : Promise.resolve([] as McpJob[]),
]);
if (!mounted.current || current !== generation.current) return;
setView(nextView); setJobs(nextJobs);
setSelectedTools(previous => {
const next = { ...previous };
for (const registration of nextView.registrations) if (revisions.current.get(registration.id) !== registration.configurationRevision) {
next[registration.id] = [...registration.allowedTools]; revisions.current.set(registration.id, registration.configurationRevision);
}
return next;
});
}
useEffect(() => {
const current = ++generation.current; setView(null); setJobs([]); setError(''); setNotice(''); setProbeTarget(null);
void load(current).catch(cause => { if (mounted.current && generation.current === current) setError(cause instanceof Error ? cause.message : String(cause)); });
return () => { if (generation.current === current) generation.current++; };
}, [projectId, session?.id]);
useEffect(() => {
if (!session || !jobs.some(job => active.includes(job.status))) return;
const current = generation.current, previous = jobs;
const timer = window.setInterval(() => { void api<McpJob[]>('/sessions/' + session.id + '/mcp/jobs').then(async next => {
if (!mounted.current || generation.current !== current) return;
setJobs(next);
if (previous.some(job => active.includes(job.status)) && !next.some(job => active.includes(job.status))) setView(await api<View>(url));
}).catch(cause => { if (generation.current === current) setError(cause instanceof Error ? cause.message : String(cause)); }); }, 900);
return () => window.clearInterval(timer);
}, [jobs, projectId, session?.id]);
async function perform(action: () => Promise<unknown>, message: string) {
const current = generation.current; setWorking(true); setError(''); setNotice('');
try { await action(); if (current === generation.current) { setNotice(message); await load(current); } }
catch (cause) { if (current === generation.current) setError(cause instanceof Error ? cause.message : String(cause)); }
finally { if (current === generation.current) setWorking(false); }
}
function register(event: FormEvent) {
event.preventDefault();
void perform(async () => {
await api(url, { name: draft.name.trim(), executable: draft.executable.trim(), ...(draft.entry.trim() ? { entry: draft.entry.trim() } : {}), timeoutMs: draft.timeoutMs });
setDraft({ name: '', executable: '', entry: '', timeoutMs: 15000 });
}, '程序已登记并保持停用。请先实际探测,再选择允许的工具。');
}
async function probe() {
if (!probeTarget || !session) return;
const target = probeTarget; setWorking(true); setError(''); setNotice(''); setRequestError('');
try {
const result = await api<{ job: McpJob; session: Session }>('/sessions/' + session.id + '/mcp/probe', { id: target.id, configurationRevision: target.configurationRevision, confirm: true });
onSession(result.session); setProbeTarget(null); setNotice('探测已启动;完成后根据实际握手和参数契约选择工具。');
const current = generation.current; await load(current);
setJobs(previous => previous.some(job => job.id === result.job.id) ? previous : [result.job, ...previous].slice(0, 30));
} catch (cause) { setRequestError(cause instanceof Error ? cause.message : String(cause)); }
finally { setWorking(false); }
}
async function stop() {
if (!session) return;
await perform(async () => { const updated = await api<Session>('/sessions/' + session.id + '/mcp/stop', {}); onSession(updated); }, 'MCP 操作已停止,已发出的调用若没有结果会保留为待核对。');
}
const saveTools = (registration: McpRegistration) => perform(async () => {
const value = await api<McpRegistration>(url + '/configure', { id: registration.id, configurationRevision: registration.configurationRevision,
enabled: !!selectedTools[registration.id]?.length, allowedTools: selectedTools[registration.id] ?? [] });
revisions.current.set(value.id, -1);
}, selectedTools[registration.id]?.length ? '已保存所选工具并启用。每次调用仍需单独确认。' : '已停用该 MCP。');
const disable = (registration: McpRegistration) => perform(async () => {
await api(url + '/configure', { id: registration.id, configurationRevision: registration.configurationRevision, enabled: false, allowedTools: [] });
revisions.current.set(registration.id, -1);
}, '该 MCP 已停用,后续请求不会再发送它的工具目录。');
return <section className="mcp-panel" aria-label="项目MCP工具管理" aria-busy={working}>
<header className="mcp-heading"><div><span className="mcp-kicker"><PlugZap size={15} />项目能力 / MCP</span><h3>受控连接外部工具</h3><p>登记本地 stdio 程序,读取实际握手与参数契约。每次探测和工具调用都需要确认,启用不代表自动执行。</p></div>
<button type="button" className="button secondary" disabled={working} onClick={() => void perform(() => load(), '项目 MCP 状态已重新核对。')}><RefreshCw size={14} className={working ? 'spin' : ''} />刷新</button></header>
<div className="mcp-status-bar"><span><i className="mcp-light" />{view?.registrations.filter(item => item.enabled && item.status === 'verified').length ?? 0} 项已启用</span><span>{view?.registrations.length ?? 0} 项已登记</span><span>协议 {view?.protocolVersion ?? '2025-03-26'}</span><span><ShieldCheck size={14} />调用逐次审批</span></div>
{error && <p className="mcp-alert" role="alert"><CircleAlert size={16} />{error}</p>}
{notice && <p className="mcp-notice" role="status"><Check size={16} />{notice}</p>}
{busy && <p className="mcp-warning">当前项目正在执行;完成或停止后才能修改 MCP 配置。</p>}
<div className="mcp-boundary"><ShieldCheck size={16} /><span>{view?.boundary ?? '每次操作使用独立所属进程。进程隔离不等于 OS 沙箱,外部服务和程序可能拥有自己的网络或副作用。'}</span></div>
{view?.registrations.length ? <div className="mcp-registration-list">{view.registrations.map(registration => {
const chosen = selectedTools[registration.id] ?? registration.allowedTools;
return <article className={'mcp-registration status-' + registration.status} key={registration.id}>
<div className="mcp-registration-heading"><Terminal size={18} /><div><h4>{registration.name}</h4><p>{stateName[registration.status] ?? registration.status} · 配置修订 {registration.configurationRevision}</p></div><span className={'mcp-enabled ' + (registration.enabled ? 'on' : '')}>{registration.enabled ? '已启用' : '已停用'}</span></div>
<div className="mcp-source"><div><span>可执行文件</span><code>{registration.launch.executable.path}</code><small><Fingerprint size={12} /> SHA256 {registration.launch.executable.sha256.slice(0, 16)} · {registration.launch.executable.bytes.toLocaleString()} B</small></div>
{registration.launch.entry && <div><span>脚本入口</span><code>{registration.launch.entry.path}</code><small>SHA256 {registration.launch.entry.sha256.slice(0, 16)} · {registration.launch.entry.bytes.toLocaleString()} B</small></div>}
<span>请求上限 {registration.timeoutMs.toLocaleString()} ms</span></div>
{registration.reason && <p className="mcp-warning">{registration.reason}</p>}
{registration.contract && <div className="mcp-contract-line"><Check size={13} />实际契约 SHA256 {registration.contract.sha256.slice(0, 16)} · 发现 {registration.tools.length} 项工具</div>}
{registration.contract && <div className="mcp-tool-list"><div className="mcp-tool-heading"><strong>允许模型请求的工具</strong><span>已选择 {chosen.length} / 12</span></div>
{registration.tools.map(tool => <label className={'mcp-tool-option ' + (tool.unsupported ? 'unsupported' : '')} key={tool.name}>
<input type="checkbox" checked={chosen.includes(tool.name)} disabled={locked || !!tool.unsupported || registration.status !== 'verified' || chosen.length >= 12 && !chosen.includes(tool.name)} onChange={event => setSelectedTools(previous => ({ ...previous,
[registration.id]: event.target.checked ? [...chosen, tool.name] : chosen.filter(name => name !== tool.name) }))} />
<span><strong>{tool.name}</strong>{tool.unsupported && <em>参数契约不受支持</em>}<small>{tool.description || '未提供用途说明'}</small>
<details><summary>查看参数契约</summary><pre>{JSON.stringify(tool.inputSchema, null, 2)}</pre>{tool.unsupported && <code>{tool.unsupported}</code>}</details></span>
</label>)}
{!registration.tools.length && <p className="mcp-empty">实际服务没有声明可发现工具。</p>}
</div>}
<div className="mcp-controls"><button type="button" className="button secondary" disabled={locked || !session || registration.status === 'changed'} onClick={() => { setRequestError(''); setProbeTarget(registration); }}><PlugZap size={14} />实际探测</button>
{registration.contract && <button type="button" className={registration.enabled ? 'button secondary' : 'button primary'} disabled={locked || registration.status !== 'verified' || !!selectedTools[registration.id]?.length && !registration.contract} onClick={() => void saveTools(registration)}><Power size={14} />{chosen.length ? '保存并启用所选工具' : '停用 MCP'}</button>}
{registration.enabled && <button type="button" className="button secondary" disabled={locked} onClick={() => void disable(registration)}><Power size={14} />立即停用</button>}
{busyJobs && session && <button type="button" className="button danger" disabled={working} onClick={() => void stop()}><AlertTriangle size={14} />停止当前 MCP 操作</button>}</div>
</article>;
})}</div> : view && <div className="mcp-empty"><PlugZap size={24} /><strong>尚未登记项目 MCP</strong><p>只登记你已审查的本地可执行文件。程序和 Node 入口会在探测及启用前重新计算 SHA256。</p></div>}
{!view && !error && <p className="mcp-empty"><LoaderCircle size={18} className="spin" />正在读取项目注册</p>}
<form className="mcp-register" onSubmit={register}>
<div className="mcp-register-heading"><h4><Plus size={16} />登记本地 MCP</h4><span>绝对路径 · 默认停用 · 最多 {view?.limits.registrations ?? 16} 项</span></div>
<div className="mcp-form-grid"><label>显示名称<input required value={draft.name} maxLength={100} onChange={event => setDraft({ ...draft, name: event.target.value })} placeholder="例如:项目只读检索" /></label>
<label>请求超时(毫秒)<input required type="number" min={500} max={45000} step={500} value={draft.timeoutMs} onChange={event => setDraft({ ...draft, timeoutMs: Number(event.target.value) })} /></label>
<label className="mcp-full">可执行文件绝对路径<input required value={draft.executable} onChange={event => setDraft({ ...draft, executable: event.target.value })} placeholder="C:\Tools\my-mcp.exe 或当前 Node.js 可执行文件" /></label>
<label className="mcp-full">Node 脚本入口(可选)<input value={draft.entry} onChange={event => setDraft({ ...draft, entry: event.target.value })} placeholder="仅接受 .js、.mjs、.cjs;留空表示直接启动可执行文件" /></label></div>
<footer><span>仅保留系统路径与临时目录环境,不传入模型 Key;不安装脚本、不使用 shell。</span><button type="submit" className="button primary" disabled={locked || !draft.name.trim() || !draft.executable.trim()}>{working ? <LoaderCircle size={14} className="spin" /> : <Plus size={14} />}登记后保持停用</button></footer>
</form>
{session && <McpJobHistory session={session} jobs={jobs} busy={locked} onSession={onSession} onError={onError} />}
{!session && <p className="mcp-empty">选择或创建一个任务会话后,可以对已登记程序执行探测。</p>}
{probeTarget && <Modal title="启动 MCP 实际探测" description="工作台将启动该登记程序、核对固定协议并读取实际工具 schema,不调用工具或模型。" onClose={() => { setProbeTarget(null); setRequestError(''); }}>
<div className="mcp-probe-summary"><strong>{probeTarget.name}</strong><code>{probeTarget.launch.executable.path}</code>{probeTarget.launch.entry && <code>{probeTarget.launch.entry.path}</code>}
<span>程序会以当前 Windows 用户权限运行;独立进程不等于 OS 沙箱。探测期间不会继承工作台模型凭据。</span></div>
{requestError && <p className="mcp-alert" role="alert"><CircleAlert size={15} />{requestError}</p>}
<div className="modal-actions"><button type="button" className="button secondary" disabled={working} onClick={() => setProbeTarget(null)}>取消</button><button type="button" className="button primary" disabled={working || busy} onClick={() => void probe()}>{working ? <LoaderCircle size={14} className="spin" /> : <PlugZap size={14} />}确认启动并探测</button></div>
</Modal>}
</section>;
}
+4 -2
View File
@@ -1,4 +1,4 @@
.modal:has(.model-center){width:min(1260px,calc(100vw - 48px));max-width:none;height:min(900px,calc(100dvh - 48px));display:flex;flex-direction:column;padding:0;overflow:hidden}.modal:has(.model-center)>.modal-header{padding:20px 28px 16px;border-bottom:1px solid #cbd5df;flex-shrink:0}.modal:has(.model-center)>.modal-body{padding:0;display:flex;min-height:0;overflow:hidden;flex:1}
.modal:has(.model-center){width:min(1260px,calc(100vw - 48px));max-width:none;height:min(900px,calc(100dvh - 48px));display:flex;flex-direction:column;padding:0;overflow:hidden}.modal:has(.model-center)>.modal-heading{padding:20px 28px 16px;margin:0;border-bottom:1px solid #cbd5df;flex-shrink:0;background:#fff}.modal:has(.model-center)>.modal-heading h2{color:#16324c;font-size:20px;font-weight:700}.modal:has(.model-center)>.modal-heading p{color:#53647c;font-size:12px;margin-top:6px}.modal:has(.model-center)>.modal-heading>.icon-button{margin:0;min-width:36px;min-height:36px;color:#53647c}
.model-center{display:flex;flex-direction:column;width:100%;min-width:0;min-height:0;color:#15283f;background:#f1f4f7;font-size:13px}.mc-overview{padding:25px 28px;display:flex;align-items:center;gap:25px;background:#e7edf2;border-bottom:1px solid #cbd5df;flex-shrink:0}.mc-eyebrow{font-family:Bahnschrift,sans-serif;letter-spacing:.13em;font-size:10px;font-weight:650;color:#526782}.mc-overview h2{font-size:25px;font-weight:650;letter-spacing:-.04em;margin:8px 0;line-height:1.3}.mc-overview p,.mc-section-title p{color:#52647a;font-size:12px;line-height:1.7}.mc-current{margin-left:auto;display:flex;gap:12px;align-items:center;padding:14px 18px;background:#fff;border:1px solid #c2d0dd;border-radius:8px;min-width:220px}.mc-current>span{font-size:11px;color:#62728a}.mc-current strong{display:block;font-size:14px;color:#15283f;margin-top:3px;overflow-wrap:anywhere}.mc-current .mc-count{margin-left:auto;white-space:nowrap}
.mc-tabs{display:flex;gap:4px;padding:0 24px;flex-shrink:0;border-bottom:1px solid #cbd5df;background:white;overflow-x:auto}.mc-tabs button{display:flex;align-items:center;gap:8px;white-space:nowrap;min-height:49px;padding:12px 15px;border-bottom:3px solid transparent;color:#53647c;font-weight:600}.mc-tabs button[aria-current]{color:#215b96;border-bottom-color:#2560a3}.mc-tabs button:hover{background:#edf2f7}.mc-tabs .mc-refresh{margin-left:auto;padding:12px}.mc-content{padding:24px 28px 32px;overflow:auto;min-height:0;flex:1;scrollbar-gutter:stable}.mc-section-title{display:flex;gap:20px;align-items:center;justify-content:space-between;margin-bottom:20px}.mc-section-title h3{font-size:17px;margin-bottom:5px}.mc-section-title>.button{flex-shrink:0}.mc-notice{padding:12px 28px;line-height:1.7;border-bottom:1px solid #e0b777;color:#734c1c;background:#fff5df;overflow-wrap:anywhere;flex-shrink:0}
.mc-connections{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.mc-connection{background:white;border:1px solid #c7d3de;border-radius:9px;padding:19px;min-width:0;box-shadow:0 2px 5px #15283f06}.mc-card-heading{display:flex;gap:12px;align-items:center;margin-bottom:18px}.mc-card-heading>div{min-width:0;flex:1}.mc-card-heading h4{font-size:15px;overflow-wrap:anywhere}.mc-card-heading>div>span{font-size:11px;color:#62728a;display:block;margin-top:4px}.mc-service-icon{display:grid;place-items:center;flex-shrink:0;border:1px solid #b9c9d8;border-radius:7px;width:41px;height:41px;color:#2560a3;background:#edf3fa}.mc-state{display:inline-flex;padding:4px 7px;border-radius:4px;font-size:11px;font-weight:600;background:#e9eef3;color:#4a5d74;white-space:nowrap;border:1px solid #d1dbe4}.mc-state-completed,.mc-state-passed{color:#216d5f;background:#e6f3ee;border-color:#b9d9cb}.mc-state-configured{color:#255d91;background:#edf4fd;border-color:#bcd0e7}.mc-state-failed,.mc-state-needs_attention{color:#a7353e;background:#fff0f0;border-color:#e8bac0}.mc-state-needs_key,.mc-state-cooling,.mc-state-unknown,.mc-state-attention{color:#8b5c12;background:#fff4d9;border-color:#e6d09d}.mc-connection dl{display:grid;grid-template-columns:86px minmax(0,1fr);gap:10px 7px;margin:0}.mc-connection dt{color:#67788d;font-size:11px}.mc-connection dd{margin:0;overflow-wrap:anywhere;font-size:12px;line-height:1.5;font-family:"Cascadia Code",Consolas,"Microsoft YaHei",monospace}.mc-capabilities{display:flex;flex-wrap:wrap;gap:6px;margin-top:17px}.mc-capabilities span{padding:4px 6px;color:#61738b;border:1px solid #d7e0e9;border-radius:4px;font-size:10px}.mc-connection footer{border-top:1px solid #e0e6ec;padding-top:14px;margin-top:15px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}.mc-icon-action{display:flex;gap:5px;align-items:center;font-size:11px;padding:8px}.mc-probe{width:100%;text-align:left;color:#476180;font-size:11px;padding:7px 0 0}.mc-disabled{background:#f7f9fb}.mc-card-warning{font-size:12px;line-height:1.7;overflow-wrap:anywhere;color:#8b4a39;margin-top:12px}
@@ -6,4 +6,6 @@
.mc-pool{display:flex;gap:18px;align-items:flex-start;background:white;border:1px solid #c7d3de;border-radius:8px;padding:21px;margin-bottom:14px}.mc-pool>svg{color:#2560a3;margin-top:2px}.mc-pool>div:first-of-type{flex:1;min-width:0}.mc-pool h4{font-size:15px}.mc-pool p{font-size:12px;color:#64748b;line-height:1.8;margin-top:6px}.mc-pool .mc-actions{margin:0}.mc-members{display:flex;gap:6px;flex-wrap:wrap;margin-top:13px}.mc-members span{font-size:11px;color:#4b607d;padding:4px 8px;background:#eff3f8;border-radius:4px}.mc-editor fieldset{border:1px solid #d0dae5;border-radius:5px;margin:16px 0 0;padding:5px 14px}.mc-editor legend{font-size:12px;color:#566a83;padding:0 6px}.mc-member-choice{display:flex;align-items:center;gap:12px;padding:12px 0;border-bottom:1px solid #e2e8ef}.mc-member-choice:last-child{border:0}.mc-member-choice>span{flex:1;font-size:13px}.mc-member-choice small{display:block;margin-top:3px;font-size:11px;color:#6c7e94}.mc-member-choice>input[type=number]{width:60px;padding:7px;border:1px solid #c6d2df;border-radius:4px}
.mc-attempts article{padding:17px 18px;background:white;border:1px solid #cbd6e2;border-left:3px solid #748eac;margin-bottom:10px;border-radius:4px}.mc-attempts article>div{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.mc-attempts strong{font-size:13px}.mc-attempts time{font-size:11px;color:#637891;margin-left:auto}.mc-attempts p{font-size:12px;color:#556b87;line-height:1.7;margin-top:9px}.mc-attempts code{font-size:10px;color:#7a8ca0;display:block;margin-top:7px;overflow-wrap:anywhere}.mc-checks{display:grid;gap:11px}.mc-checks article{display:flex;align-items:flex-start;gap:14px;border:1px solid #cbd6e2;border-radius:6px;padding:18px;background:white}.mc-checks h4{font-size:14px}.mc-checks p{font-size:12px;color:#5d7088;line-height:1.8;margin-top:5px}.mc-import-source{padding:17px;background:white;border:1px solid #cbd6e2;margin-bottom:10px;display:flex;align-items:center;gap:15px;flex-wrap:wrap;border-radius:6px}.mc-import-source code{flex:1;overflow-wrap:anywhere;font-size:11px;min-width:140px}.mc-import-source>span,.mc-import-source p{font-size:12px;color:#64778e}
@media(max-width:940px){.mc-connections{grid-template-columns:1fr}.mc-overview h2{font-size:22px}.mc-pool{flex-wrap:wrap}.mc-pool .mc-actions{width:100%}}
@media(max-width:620px){.modal:has(.model-center){width:100vw;height:100dvh;max-height:100dvh;border-radius:0}.modal:has(.model-center)>.modal-header{padding:17px 16px}.mc-overview{padding:17px 16px;display:block}.mc-overview h2{font-size:21px}.mc-current{padding:10px 12px;margin:13px 0 0;min-width:0}.mc-current strong{font-size:13px}.mc-tabs{padding:0 8px}.mc-tabs button{padding:12px 10px;min-height:48px;font-size:12px}.mc-content{padding:18px 15px 28px}.mc-section-title{gap:12px;align-items:flex-start;flex-direction:column}.mc-form-grid{grid-template-columns:1fr}.mc-form-grid .mc-full{grid-column:auto}.mc-editor{padding:18px 14px}.mc-connection{padding:16px 13px}.mc-card-heading{gap:9px}.mc-service-icon{width:34px;height:34px}.mc-card-heading h4{font-size:14px}.mc-connection dl{grid-template-columns:72px minmax(0,1fr)}.mc-notice{padding:12px 16px}.model-center button{min-height:44px}.mc-state{font-size:10px}.mc-attempts time{margin-left:0}.mc-import-source{gap:9px}.mc-member-choice input[type=number]{min-height:44px}.mc-form-grid input,.mc-form-grid select{min-height:44px}}
@media(max-width:620px){.modal:has(.model-center){width:100vw;height:100dvh;max-height:100dvh;border-radius:0}.modal:has(.model-center)>.modal-heading{padding:17px 16px}.mc-overview{padding:17px 16px;display:block}.mc-overview h2{font-size:21px}.mc-current{padding:10px 12px;margin:13px 0 0;min-width:0}.mc-current strong{font-size:13px}.mc-tabs{padding:0 8px}.mc-tabs button{padding:12px 10px;min-height:48px;font-size:12px}.mc-content{padding:18px 15px 28px}.mc-section-title{gap:12px;align-items:flex-start;flex-direction:column}.mc-form-grid{grid-template-columns:1fr}.mc-form-grid .mc-full{grid-column:auto}.mc-editor{padding:18px 14px}.mc-connection{padding:16px 13px}.mc-card-heading{gap:9px}.mc-service-icon{width:34px;height:34px}.mc-card-heading h4{font-size:14px}.mc-connection dl{grid-template-columns:72px minmax(0,1fr)}.mc-notice{padding:12px 16px}.model-center button{min-height:44px}.mc-state{font-size:10px}.mc-attempts time{margin-left:0}.mc-import-source{gap:9px}.mc-member-choice input[type=number]{min-height:44px}.mc-form-grid input,.mc-form-grid select{min-height:44px}}
@media(max-width:620px){.modal:has(.model-center)>.modal-heading>.icon-button{min-width:44px;min-height:44px}}
+2
View File
@@ -9,6 +9,7 @@ import { WorkspacePanel } from './WorkspacePanel';
import { BrowserPanel } from './BrowserPanel';
import { TaskPlanPanel } from './TaskPlanPanel';
import { TaskCheckpointPanel } from './TaskCheckpointPanel';
import { McpJobHistory } from './McpJobHistory';
import './TaskPanel.css';
const stopReasons: Record<string, string> = { no_progress: '重复读取未推进任务,请核对后继续', context_limit: '完整任务要求超过请求上下文预算', time_limit: '到达运行时间预算', token_limit: '到达本次 token 预算', task_token_limit: '到达任务累计预算', step_limit: '到达工具轮次上限', cancelled: '用户停止', model_error: '模型请求失败', interrupted: '进程中断' };
@@ -88,6 +89,7 @@ export function TaskPanel({ project, session, onSession, onError, busy, onWorksp
{task && <TaskPlanPanel session={session} busy={busy} onSession={onSession} onError={onError} openArtifact={openArtifact} />}
{task && <TaskCheckpointPanel session={session} busy={busy} onSession={onSession} onError={onError} openArtifact={openArtifact} />}
{execution?.progress.requiresVerification.length ? <section className="verification-note" role="status"><ShieldQuestion size={17} /><div><strong>{execution.progress.requiresVerification.length} 项结果需要核对</strong><p>这些调用已进入执行,但缺少可靠结果。继续任务会保留记录。</p>{execution.progress.requiresVerification.map(tool => <code key={tool.id}>{tool.tool} · {tool.id.slice(0, 8)}</code>)}</div></section> : null}
{task && !!execution?.mcpJobs?.length && <McpJobHistory session={session} jobs={execution.mcpJobs} busy={busy} onSession={onSession} onError={onError} />}
{task && <section className="task-record-section">
<div className="record-heading"><h3>运行记录</h3><span>{execution?.runs.filter(item => item.taskId === task.id).length} 次</span></div>
<label className="run-picker">选择一次运行<select aria-label="选择运行记录" value={id} onChange={event => setRunId(event.target.value)}>{execution?.runs.filter(item => item.taskId === task.id).map((item, index) => <option key={item.id} value={item.id}>第 {index + 1} 次 · {time(item.startedAt)}{item.resumeOf ? ' · 接续' : ''}</option>)}</select></label>
+15 -1
View File
@@ -160,7 +160,21 @@ export interface TaskPlanView {
contract_artifact_id?: string; contract_sha256?: string; checked_at?: string; error?: string;
}
export interface TaskPlanReply { session: Session; plan: TaskPlanView; verification?: { status: string; reused?: boolean; proof_id: string; message?: string } }
export interface ExecutionSnapshot { schemaVersion: number; task: Task | null; run: Run | null; runs: RunBrief[]; progress: { totalTools: number; completedTools: number; requiresVerification: { id: string; tool: string; state: string; callId: string }[] }; artifacts: Artifact[]; checks: CheckJob[]; plans?: CheckPlan[]; deliveries?: DeliveryJob[]; deliveryPlans?: DeliveryPlan[]; changeSets?: ChangeSet[]; contextPlans?: ContextPlan[]; workspaces?: WorkspaceRecord[]; researchTargets?: ResearchTarget[]; researchJobs?: ResearchJob[]; engineJobs?: EngineJob[]; browserPlans?: BrowserPlan[]; browserJobs?: BrowserJob[]; taskPlans?: TaskPlanRecord[]; taskProofs?: { id: string; planId: string; stepKey: string; status: string }[]; workspaceIdentity?: WorkspaceIdentity; accountedTaskTokens: number }
export interface ExecutionSnapshot { schemaVersion: number; task: Task | null; run: Run | null; runs: RunBrief[]; progress: { totalTools: number; completedTools: number; requiresVerification: { id: string; tool: string; state: string; callId: string }[] }; artifacts: Artifact[]; checks: CheckJob[]; mcpJobs?: McpJob[]; plans?: CheckPlan[]; deliveries?: DeliveryJob[]; deliveryPlans?: DeliveryPlan[]; changeSets?: ChangeSet[]; contextPlans?: ContextPlan[]; workspaces?: WorkspaceRecord[]; researchTargets?: ResearchTarget[]; researchJobs?: ResearchJob[]; engineJobs?: EngineJob[]; browserPlans?: BrowserPlan[]; browserJobs?: BrowserJob[]; taskPlans?: TaskPlanRecord[]; taskProofs?: { id: string; planId: string; stepKey: string; status: string }[]; workspaceIdentity?: WorkspaceIdentity; accountedTaskTokens: number }
export interface McpTool { name: string; description: string; inputSchema: Record<string, unknown>; unsupported?: string }
export interface McpRegistration {
id: string; projectId: string; name: string; launch: { executable: { path: string; sha256: string; bytes: number }; entry: { path: string; sha256: string; bytes: number } | null; args: string[]; environment: string; identityScope: string };
timeoutMs: number; configurationRevision: number; enabled: boolean; allowedTools: string[];
contract: { artifactId: string; sha256: string } | null; createdAt: string; updatedAt: string; status: string; reason: string; tools: McpTool[];
}
export interface McpJob {
id: string; sessionId: string; projectId: string; taskId: string; runId: string; registrationId: string; configurationRevision: number;
invocationId?: string | null; reviewedAt?: string; reviewedBy?: string; evidenceSha256?: string;
operation: 'probe' | 'call'; status: string; startedAt: string; finishedAt: string | null; requiresVerification: boolean; dispatched: boolean; processStarted: boolean;
input?: { launch?: unknown; protocolVersion?: string; contractSha256?: string | null; call?: { tool: string; arguments: Record<string, unknown> }; timeoutMs?: number }; inputArtifactId?: string; inputSha256?: string; pid?: number;
reportArtifactId?: string; reportSha256?: string; cleanup?: { connectionId?: string; pid: number | null; rootExited: boolean; forced?: boolean; scope?: string; exit?: { code: number | null; signal: string | null } | null };
error?: { code: string; message: string } | null;
}
export interface EngineAvailability {
engineId: string; name: string; status: string; root: string | null; profile: string; expectedVersion: string; version?: string; message: string;
identitySha256?: string; node?: { path: string; version: string; sha256: string };