import { useEffect, useRef, useState } from 'react'; import { ClipboardCheck, FolderOpen, Monitor, RotateCw, Square } from 'lucide-react'; import type { OpenFile, Project, Session } from './types'; import { desktop, type DesktopHostStatus, type DesktopTaskScope } from './desktop'; export function DesktopPanel({ project, session, file, onProject, onReview }: { project?: Project; session: Session | null; file: OpenFile | null; onProject(project: Project): Promise; onReview(scope: DesktopTaskScope): void; }) { const [status, setStatus] = useState(null), [busy, setBusy] = useState(''), [error, setError] = useState(''); const alive = useRef(true); useEffect(() => { alive.current = true; void refresh(); return () => { alive.current = false; }; }, []); async function act(name: string, action: () => Promise) { if (busy || !desktop) return; setBusy(name); setError(''); try { await action(); } catch (value) { if (alive.current) setError(value instanceof Error ? value.message : '本机操作失败,请核对当前宿主。'); } finally { if (alive.current) setBusy(''); } } async function refresh() { await act('refresh', async () => { const value = await desktop!.status(); if (alive.current) setStatus(value); }); } const task = session?.execution?.task, scope = project && session && task ? { projectId: project.id, sessionId: session.id, taskId: task.id } : null; return
{status?.state === 'ready' ? '执行宿主正在运行' : status?.state === 'stopping' ? '所属任务正在停止' : '正在核对执行宿主'}

关闭窗口后,后台任务继续。重新打开可查看原任务进度。

{status?.identity &&
当前程序
v{status.identity.version} · PID {status.identity.pid}
后台任务
{status.activity?.active ? '有所属操作正在执行' : '当前没有活动操作'} · {status.activity?.unresolvedTools || 0} 项结果待核对
桌面窗口
{status.desktopWindows?.count || 0} 个已登记窗口
会话与连接
{status.identity.dataRoot}
运行目录
{status.identity.runtimeRoot}
}
{!scope &&

选择已有任务后,可核对任务归属并审查成果。读取文件后可在文件管理器中定位。

} {error &&

{error}

}
退出执行宿主

停止所属任务、模型请求和工具进程,再退出桌面。系统会要求确认。

; }