import { useEffect, useRef, useState } from 'react'; import { ArrowRight, Check, Download, Fingerprint, Link2, LoaderCircle, Play, RefreshCw, Square, Unplug } from 'lucide-react'; import { api, downloadEngineReport } from './api'; import { Modal } from './components'; import type { ArtifactPreview, EngineAvailability, EngineJob, Project, Session } from './types'; import './EnginePanel.css'; const active = ['queued', 'starting', 'initializing', 'checking', 'stopping']; const states: Record = { queued: '等待启动', starting: '原程序启动中', initializing: '正在连接', checking: '正在核验', stopping: '正在停止', completed: '连接通过', failed: '连接未通过', cancelled: '已停止', unknown: '结果待核对' }; const date = (value: string) => new Date(value).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); type Preview = { job: EngineJob; page: ArtifactPreview }; export function EnginePanel({ project, session, busy, onSession, onError }: { project: Project; session: Session; busy: boolean; onSession: (value: Session) => void; onError: (error: unknown) => void; }) { const [root, setRoot] = useState(''), [installation, setInstallation] = useState(null); const [checking, setChecking] = useState(false), [pending, setPending] = useState(false); const [retry, setRetry] = useState(null), [preview, setPreview] = useState(null); const [viewBusy, setViewBusy] = useState(false), [notice, setNotice] = useState(''); const mounted = useRef(true), detection = useRef(0), scope = useRef(0), viewRequest = useRef(0); const taskId = session.execution?.task?.id ?? null; const jobs = (session.execution?.engineJobs ?? []).slice().reverse(); const running = jobs.some(job => active.includes(job.status)), disabled = busy || running || pending; useEffect(() => { mounted.current = true; return () => { mounted.current = false; detection.current++; scope.current++; viewRequest.current++; }; }, []); useEffect(() => { scope.current++; viewRequest.current++; setPreview(null); setRetry(null); setViewBusy(false); setPending(false); setNotice(''); }, [taskId]); useEffect(() => { void detect(); }, []); async function detect(candidate = root) { const current = ++detection.current; setChecking(true); setNotice(''); try { const value = await api('/engines/deepseek/availability' + (candidate.trim() ? '?root=' + encodeURIComponent(candidate.trim()) : '')); if (mounted.current && current === detection.current) { setInstallation(value); if (!candidate.trim() && value.root) setRoot(value.root); } } catch (error) { if (mounted.current && current === detection.current) onError(error); } finally { if (mounted.current && current === detection.current) setChecking(false); } } function editRoot(value: string) { detection.current++; setRoot(value); setInstallation(null); setChecking(false); setNotice('目录已改变,请先检测这个安装。'); } async function start(previous?: EngineJob) { const current = scope.current; setPending(true); setNotice(''); try { const value = await api<{ job: EngineJob; session: Session }>('/sessions/' + session.id + '/engines/jobs', { root: previous?.installation.root ?? installation?.root ?? root.trim(), ...(previous ? { retry: true } : { identitySha256: installation?.identitySha256 }), }); if (mounted.current && current === scope.current) { onSession(value.session); setRetry(null); } } catch (error) { if (mounted.current && current === scope.current) onError(error); } finally { if (mounted.current && current === scope.current) setPending(false); } } async function stop() { const current = scope.current; setPending(true); try { const value = await api('/sessions/' + session.id + '/engines/stop', {}); if (mounted.current && current === scope.current) onSession(value); } catch (error) { if (mounted.current && current === scope.current) onError(error); } finally { if (mounted.current && current === scope.current) setPending(false); } } async function openRecord(job: EngineJob, offset = 0) { const current = ++viewRequest.current, currentScope = scope.current; setViewBusy(true); try { const page = await api('/sessions/' + session.id + '/engines/jobs/' + job.id + '/report?offset=' + offset + '&limit=4000'); if (mounted.current && currentScope === scope.current && current === viewRequest.current) setPreview({ job, page }); } catch (error) { if (mounted.current && currentScope === scope.current && current === viewRequest.current) onError(error); } finally { if (mounted.current && currentScope === scope.current && current === viewRequest.current) setViewBusy(false); } } async function download(job: EngineJob) { const current = scope.current; try { await downloadEngineReport(session.id, job.id); } catch (error) { if (mounted.current && current === scope.current) onError(error); } } return
{project.name} · 当前任务

连接本地代理引擎

核对本机的 DeepSeek Harness,并将实际检查记录保存到这个任务。

{checking ? '正在检测安装' : installation?.status === 'available' ? '已找到 ' + installation.version : '等待检测'}
{ event.preventDefault(); void detect(); }}>

DeepSeek Harness

{installation &&

{installation.message}

} {notice &&

{notice}

} {installation?.status === 'available' &&
发行版本
{installation.version}
连接范围
启动、协议、会话目录与停止
运行环境
Node.js {installation.node?.version}
}

当前可用能力

原程序连接与独立进程停止

同任务保存原记录与来源

工程执行接入中

本次检查不发送模型任务。完成连接核验后,继续接入工程工具与交付流程。

连接与执行范围

每次检查启动一个独立进程。停止只作用于这个检查;SDK 会话目录、协议版本与完整错误保存在原记录。当前版本没有开放外部引擎修改工程。

本任务连接记录 {jobs.length}

{running && }
{!jobs.length &&
先验证这个安装能否连接

检查完成后,可以查看实际启动、协议返回和进程结束记录;检查不会调用已配置的模型。

} {jobs.map(job => { const verified = job.status === 'completed' && job.verification?.verified === true; return
DeepSeek Harness {job.installation.version}{date(job.startedAt)}
{active.includes(job.status) && }{states[job.status] ?? job.status}

{job.summary}

安装身份{job.installation.identitySha256?.slice(0, 12) ?? '等待核对'}
启动完成{job.readiness ? 'PID ' + job.readiness.pid : '尚无信号'}
协议返回{job.serverInfo?.version ?? '尚无返回'}
进程结束{job.reportSummary?.rootExited ? '已核对' : job.finishedAt ? '待核对' : '检查中'}
{!active.includes(job.status) && }
任务与安装来源
项目
{project.name}
Task
{job.taskId}
Run
{job.runId}
SDK 会话
{job.sdkSessionId}
安装目录
{job.installation.root}
安装 SHA256
{job.installation.identitySha256}
原记录 SHA256
{job.reportSha256 ?? '尚未封存'}
模型请求
{job.reportSummary?.modelRequests ?? '尚未核对'}
; })}
{retry && setRetry(null)}>

{retry.installation.root}

将重新核对当前安装、启动完成、SDK 返回和进程关闭。本次不会发送模型任务。

} {preview && { viewRequest.current++; setPreview(null); setViewBusy(false); }}>
原记录 SHA256{preview.page.sha256}
{preview.page.content}
{preview.page.offset.toLocaleString()}–{(preview.page.offset + preview.page.content.length).toLocaleString()} / {preview.page.totalCharacters.toLocaleString()} 字符
}
; }