refactor(lab): move execution to Worker and manage replay and transfer lifecycles
This commit is contained in:
@@ -17,6 +17,12 @@ import {
|
||||
import { CanonicalVegetationRerunReplay } from "../../components/laboratory/CanonicalVegetationRerunReplay";
|
||||
import { AICompositionReplay } from "../../components/laboratory/AICompositionReplay";
|
||||
import { PortableResultReplay } from "../../components/laboratory/PortableResultReplay";
|
||||
import { useLocalLabStorage } from "../../core/storage/localLabStorage";
|
||||
import { FailedRunActions } from "../../components/observatory/FailedRunActions";
|
||||
import { failedRunDetail } from "../../core/observatory/failedRunHistory";
|
||||
import { LabCopyActions, type LabCopyProgress as CopyProgress } from "../../components/observatory/LabCopyActions";
|
||||
import { LabReplayProgress } from "../../components/laboratory/LabReplayProgress";
|
||||
import { formatLocalLabSize } from "../../core/storage/localLabPresentation";
|
||||
import { AIConfigurationWindow } from "../../components/observatory/AIConfigurationWindow";
|
||||
import type { ObservationSessionStatus } from "../../core/observation/sessionArchive";
|
||||
import { createObservationReplayCoordinator } from "../../core/observation/replayCoordinator";
|
||||
@@ -273,7 +279,7 @@ function aiJobStageDetail(
|
||||
recordingDurationSeconds: number,
|
||||
): string {
|
||||
if (job.state === "failed") {
|
||||
return "Не удалось запустить модель. Конфигурацию можно отправить повторно";
|
||||
return failedRunDetail(job);
|
||||
}
|
||||
if (job.publication.state === "failed") {
|
||||
return "Результат рассчитан, но не сохранён в AI Inference";
|
||||
@@ -299,23 +305,6 @@ function aiJobStageDetail(
|
||||
return "Собираем, передаём и сохраняем результат";
|
||||
}
|
||||
|
||||
function presentAIJob(job: ObservatoryRecordedJob): boolean {
|
||||
if (job.state === "failed") return true;
|
||||
if (job.publication.state === "pending" || job.publication.state === "failed") return true;
|
||||
return job.state !== "succeeded";
|
||||
}
|
||||
|
||||
function presentLatestAIJobs(
|
||||
jobs: readonly ObservatoryRecordedJob[],
|
||||
): readonly ObservatoryRecordedJob[] {
|
||||
const seenSetups = new Set<string>();
|
||||
return jobs.filter((job) => {
|
||||
if (seenSetups.has(job.setupId)) return false;
|
||||
seenSetups.add(job.setupId);
|
||||
return presentAIJob(job);
|
||||
});
|
||||
}
|
||||
|
||||
function compositionProgressPercent(
|
||||
run: AICompositionRun,
|
||||
progress: Readonly<Record<string, RecordedProgressView>>,
|
||||
@@ -344,6 +333,7 @@ export function ObservatoryWorkspace({
|
||||
definition: WorkspaceDefinition;
|
||||
}) {
|
||||
const controller = useObservatoryCatalog();
|
||||
const localStorage = useLocalLabStorage();
|
||||
const [selectedSessionId, setSelectedSessionId] = useState("");
|
||||
const [aiConfigurationOpen, setAIConfigurationOpen] = useState(false);
|
||||
const [evidenceSortDirection, setEvidenceSortDirection] = useState<EvidenceSortDirection>("newest");
|
||||
@@ -360,6 +350,9 @@ export function ObservatoryWorkspace({
|
||||
ObservatoryMutationReconciliation | null
|
||||
>(null);
|
||||
const overviewRef = useRef<HTMLDivElement | null>(null);
|
||||
const [copyProgress, setCopyProgress] = useState<Record<string, CopyProgress | null>>({});
|
||||
const updateCopyProgress = (id: string, value: CopyProgress | null) =>
|
||||
setCopyProgress((current) => ({ ...current, [id]: value }));
|
||||
const replayCoordinatorRef = useRef(createObservationReplayCoordinator());
|
||||
const refreshedPublishedJobRef = useRef<string | null>(null);
|
||||
const items = controller.catalog?.items ?? EMPTY_OBSERVATORY_ITEMS;
|
||||
@@ -400,8 +393,9 @@ export function ObservatoryWorkspace({
|
||||
const compositionJobIds = useMemo(() => new Set(
|
||||
presentedCompositionRuns.flatMap((run) => run.jobIds),
|
||||
), [presentedCompositionRuns]);
|
||||
const presentedAIJobs = presentLatestAIJobs(aiJobsController.jobs).filter(
|
||||
(job) => !compositionJobIds.has(job.jobId),
|
||||
const presentedAIJobs = aiJobsController.jobs.filter(
|
||||
(job) => !compositionJobIds.has(job.jobId)
|
||||
&& !presentedEvidence.some((evidence) => evidence.lab.resultId === job.resultId),
|
||||
);
|
||||
const presentedRows = useMemo<readonly ObservatoryEvidenceRow[]>(() => {
|
||||
const rows: ObservatoryEvidenceRow[] = [
|
||||
@@ -509,7 +503,6 @@ export function ObservatoryWorkspace({
|
||||
}, [closeReplay]);
|
||||
|
||||
const openRename = useCallback((evidence: ObservatoryEvidence) => {
|
||||
if (!evidence.recordedRun) return;
|
||||
setCompositionRenameTarget(null);
|
||||
setCompositionDeleteTarget(null);
|
||||
setDeleteTarget(null);
|
||||
@@ -520,7 +513,6 @@ export function ObservatoryWorkspace({
|
||||
}, []);
|
||||
|
||||
const openDelete = useCallback((evidence: ObservatoryEvidence) => {
|
||||
if (!evidence.recordedRun) return;
|
||||
setCompositionRenameTarget(null);
|
||||
setCompositionDeleteTarget(null);
|
||||
setRenameTarget(null);
|
||||
@@ -567,7 +559,7 @@ export function ObservatoryWorkspace({
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!renameTarget?.recordedRun || mutationPending !== null) return;
|
||||
if (!renameTarget || mutationPending !== null) return;
|
||||
const requestedDisplayName = renameValue.trim();
|
||||
const reconciliation: ObservatoryMutationReconciliation = {
|
||||
kind: "rename",
|
||||
@@ -579,7 +571,7 @@ export function ObservatoryWorkspace({
|
||||
setMutationReconciliation(reconciliation);
|
||||
try {
|
||||
const result = await renameObservatoryLabProjection(
|
||||
renameTarget.recordedRun,
|
||||
renameTarget,
|
||||
renameValue,
|
||||
);
|
||||
controller.applyEvidenceRename(result.sessionId, result.displayName);
|
||||
@@ -621,7 +613,7 @@ export function ObservatoryWorkspace({
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!deleteTarget?.recordedRun || mutationPending !== null) return;
|
||||
if (!deleteTarget || mutationPending !== null) return;
|
||||
const reconciliation: ObservatoryMutationReconciliation = {
|
||||
kind: "delete",
|
||||
sessionId: deleteTarget.sessionId,
|
||||
@@ -639,7 +631,7 @@ export function ObservatoryWorkspace({
|
||||
closeReplay();
|
||||
});
|
||||
}
|
||||
await deleteObservatoryLabProjection(deleteTarget.recordedRun);
|
||||
await deleteObservatoryLabProjection(deleteTarget);
|
||||
controller.applyEvidenceDeletion(deleteTarget.sessionId);
|
||||
setDeleteTarget(null);
|
||||
setMutationReconciliation(null);
|
||||
@@ -800,7 +792,7 @@ export function ObservatoryWorkspace({
|
||||
<header>
|
||||
<div>
|
||||
<span className="section-eyebrow">СВЯЗАННЫЕ РЕЗУЛЬТАТЫ</span>
|
||||
<h3>Лабораторные доказательства</h3>
|
||||
<h3>История запусков</h3>
|
||||
</div>
|
||||
<div className="observatory-evidence__ordering">
|
||||
<StatusBadge tone={presentedRows.length > 0 ? "accent" : "neutral"}>
|
||||
@@ -852,15 +844,21 @@ export function ObservatoryWorkspace({
|
||||
</div>
|
||||
) : null}
|
||||
<small>{run.state === "ready"
|
||||
? formatTimestamp(row.timestamp)
|
||||
? `${formatTimestamp(row.timestamp)} / ${formatLocalLabSize(localStorage.data?.entries[run.runId], !!localStorage.data && !localStorage.error)}`
|
||||
: `${compositionStage(run, aiJobsController.progress)} · ${formatTimestamp(row.timestamp)}`}</small>
|
||||
</div>
|
||||
{active ? (
|
||||
<StatusBadge tone="accent">{Math.round(progressPercent)}%</StatusBadge>
|
||||
) : failed ? <StatusBadge tone="danger">Ошибка</StatusBadge> : null}
|
||||
|
||||
{copyProgress[run.runId] ? <LabReplayProgress progress={copyProgress[run.runId]!} /> : null}
|
||||
<div className="observatory-evidence-card__actions">
|
||||
{run.state === "ready" ? (
|
||||
<>
|
||||
<LabCopyActions id={run.runId} sourceId={run.sourceSessionId} composition
|
||||
onProgress={(value) => updateCopyProgress(run.runId, value)}
|
||||
copy={localStorage.data?.entries[run.runId]} available={!!localStorage.data}
|
||||
storageError={localStorage.error} />
|
||||
<IconButton
|
||||
label={`Удалить ${run.displayName ?? run.presentation.configurationLabel} из AI Inference`}
|
||||
onClick={() => openCompositionDelete(run)}
|
||||
@@ -927,6 +925,9 @@ export function ObservatoryWorkspace({
|
||||
{active ? (
|
||||
<StatusBadge tone={aiJobTone(job)}>{Math.round(progressPercent)}%</StatusBadge>
|
||||
) : failed ? <StatusBadge tone="danger">Ошибка</StatusBadge> : null}
|
||||
{job.state === "failed" && job.resultId === null ? (
|
||||
<FailedRunActions job={job} onDeleted={aiJobsController.refresh} />
|
||||
) : null}
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
@@ -946,11 +947,19 @@ export function ObservatoryWorkspace({
|
||||
)}</strong>
|
||||
<small>
|
||||
{formatTimestamp(row.timestamp)}
|
||||
{evidence.recordedRun?.kind === "portable-result-review"
|
||||
? ` / ${formatLocalLabSize(localStorage.data?.entries[evidence.lab.resultId], !!localStorage.data && !localStorage.error)}` : ""}
|
||||
{!evidence.recordedRun ? " · Просмотр этого формата пока недоступен" : ""}
|
||||
</small>
|
||||
</div>
|
||||
{copyProgress[evidence.lab.resultId] ? <LabReplayProgress progress={copyProgress[evidence.lab.resultId]!} /> : null}
|
||||
<div className="observatory-evidence-card__actions">
|
||||
{evidence.recordedRun ? (
|
||||
<>
|
||||
<>
|
||||
{evidence.recordedRun?.kind === "portable-result-review" ? <LabCopyActions
|
||||
id={evidence.lab.resultId} sourceId={evidence.lab.sourceSessionId}
|
||||
onProgress={(value) => updateCopyProgress(evidence.lab.resultId, value)}
|
||||
copy={localStorage.data?.entries[evidence.lab.resultId]} available={!!localStorage.data}
|
||||
storageError={localStorage.error} /> : null}
|
||||
<IconButton
|
||||
label={`Удалить ${evidence.lab.labId} из AI Inference`}
|
||||
onClick={() => openDelete(evidence)}
|
||||
@@ -963,7 +972,7 @@ export function ObservatoryWorkspace({
|
||||
>
|
||||
<Icon name="edit" size={16} />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
{evidence.recordedRun ? <IconButton
|
||||
label={`Открыть визуальный разбор: ${evidence.lab.labId}`}
|
||||
disabled={
|
||||
replay.kind === "loading"
|
||||
@@ -975,9 +984,8 @@ export function ObservatoryWorkspace({
|
||||
&& replay.binding.evidenceSessionId === evidence.sessionId
|
||||
? <ActivityIndicator size="compact" />
|
||||
: <Icon name="eye" size={16} />}
|
||||
</IconButton>
|
||||
</IconButton> : null}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
@@ -1161,23 +1169,23 @@ export function ObservatoryWorkspace({
|
||||
|
||||
<ConfirmationModal
|
||||
open={deleteTarget !== null || compositionDeleteTarget !== null}
|
||||
title="Удалить результат из AI Inference?"
|
||||
title="Удалить LAB безвозвратно?"
|
||||
description={deleteTarget || compositionDeleteTarget ? (
|
||||
<div className="observatory-delete-confirmation">
|
||||
<p>
|
||||
Будут удалены только каталожная проекция <strong>{deleteTarget?.label ?? compositionDeleteTarget?.displayName ?? compositionDeleteTarget?.presentation.configurationLabel}</strong>
|
||||
{" "}и её отображаемое название в AI Inference.
|
||||
Будут удалены LAB <strong>{deleteTarget?.label ?? compositionDeleteTarget?.displayName ?? compositionDeleteTarget?.presentation.configurationLabel}</strong>
|
||||
{" "}и её данные на этом устройстве и на Worker, включая закреплённую локальную копию.
|
||||
</p>
|
||||
<p>
|
||||
Исходная сессия, запечатанный лабораторный результат и файлы доказательств
|
||||
останутся неизменными.
|
||||
Исходная запись и данные, используемые другими LAB, сохранятся.
|
||||
Отменить удаление нельзя.
|
||||
</p>
|
||||
{mutationError ? (
|
||||
<p className="observatory-mutation-error" role="alert">{mutationError}</p>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
confirmLabel="Удалить из AI Inference"
|
||||
confirmLabel="Удалить LAB"
|
||||
pendingLabel="Удаляем…"
|
||||
danger
|
||||
onClose={() => {
|
||||
|
||||
Reference in New Issue
Block a user