收口 INI 面板 persistence summary 发布门禁

This commit is contained in:
2026-06-16 09:00:29 +08:00
parent 65e95327b3
commit d3ee5d49ff
21 changed files with 1458 additions and 46 deletions

View File

@@ -156,6 +156,156 @@ export function createMachineSessionWorkflowStatus(state = {}) {
};
}
export function createMachineSessionPersistenceSummary({
state = {},
report = createMachineSessionStateReport(state),
workflowStatus = createMachineSessionWorkflowStatus(state),
readonlyStatus = null,
handoffSummary = null,
handoffWorkflowSummary = null,
} = {}) {
const readiness = report.readiness ?? {};
const machineFiles = state.machineFiles ?? {};
const session = report.session ?? {};
const loaded = report.loaded ?? {};
const sessionReadiness = report.sessionReadiness ?? workflowStatus.sessionReadiness ?? null;
const opfsReady = String(readiness.opfs ?? "").toLowerCase().includes("ready");
const machineFileLabels = [
machineFiles.iniOpfsPath || session.ini ? "ini" : null,
machineFiles.parameterOpfsPath || session.parameters ? "parameters" : null,
machineFiles.toolTableOpfsPath || session.toolTable ? "tool-table" : null,
machineFiles.gcodeOpfsPath || session.gcode ? "g-code" : null,
].filter(Boolean);
const machineFilesReady = machineFileLabels.length > 0;
const snapshotReady = Boolean(session.snapshotLabel);
const sessionReadinessReady = sessionReadiness?.ready === true;
const sessionLoadReady = Boolean(loaded.iniWasmPath);
const readonlyStatusValue = readonlyStatus
? (readonlyStatus.ready === true ? "ready" : readonlyStatus.phase ?? "available")
: "not-provided";
const handoffValue = handoffWorkflowSummary
? (handoffWorkflowSummary.ready === true ? "ready" : handoffWorkflowSummary.phase ?? "blocked")
: (
handoffSummary
? (handoffSummary.ready === true ? "ready" : handoffSummary.phase ?? "blocked")
: "not-provided"
);
const checks = {
opfs: opfsReady,
machineFiles: machineFilesReady,
sessionSnapshot: snapshotReady,
sessionReadiness: sessionReadinessReady,
sessionLoad: sessionLoadReady,
};
const missing = Object.entries(checks)
.filter(([, passed]) => !passed)
.map(([name]) => name);
const ready = missing.length === 0;
return {
apiName: "machine-session-persistence-summary",
summaryVersion: 1,
phase: ready ? "ready" : "waiting",
ready,
checks,
missing,
counts: {
machineFiles: machineFileLabels.length,
missing: missing.length,
},
rows: [
{
id: "opfs",
label: "OPFS",
value: readiness.opfs ?? "missing",
},
{
id: "machine-files",
label: "Machine files",
value: machineFileLabels.length > 0 ? machineFileLabels.join(", ") : "missing",
},
{
id: "session-snapshot",
label: "Session snapshot",
value: session.snapshotLabel ?? "missing",
},
{
id: "session-readiness",
label: "Session readiness",
value: sessionReadiness
? (sessionReadiness.ready ? "ready" : `blocked: ${sessionReadiness.missing?.join(", ") || "unknown"}`)
: "missing",
},
{
id: "session-load",
label: "Session load",
value: loaded.iniWasmPath ? `loaded: ${loaded.iniWasmPath}` : "missing",
},
{
id: "readonly-status",
label: "Readonly status",
value: readonlyStatusValue,
},
{
id: "handoff-readiness",
label: "Handoff readiness",
value: handoffValue,
},
],
};
}
export function createMachineSessionPersistenceDisplayViewModel(
summary = createMachineSessionPersistenceSummary(),
) {
const missing = Array.isArray(summary?.missing) ? summary.missing : [];
const rows = Array.isArray(summary?.rows)
? summary.rows.map(({ id, label, value }) => ({
id,
label,
value: value == null ? "" : String(value),
}))
: [];
return {
phase: summary?.phase === "ready" ? "ready" : "waiting",
title: "OPFS/session persistence",
statusText: summary?.ready ? "Ready" : "Waiting",
detailText: missing.length > 0 ? missing.join(", ") : "No missing persistence requirements",
rows,
};
}
export function createMachineSessionPersistenceRenderState(
displayViewModel = createMachineSessionPersistenceDisplayViewModel(),
) {
const rows = Array.isArray(displayViewModel?.rows)
? displayViewModel.rows.map(({ id, label, value }) => ({
id,
label,
value: value == null ? "" : String(value),
}))
: [];
const ready = displayViewModel?.phase === "ready" && displayViewModel?.statusText === "Ready";
const statusText = displayViewModel?.statusText ?? (ready ? "Ready" : "Waiting");
const detailText = displayViewModel?.detailText ?? "No missing persistence requirements";
return {
apiName: "machine-session-persistence-render-state",
renderStateVersion: 1,
phase: ready ? "ready" : "waiting",
ready,
title: displayViewModel?.title ?? "OPFS/session persistence",
statusText,
detailText,
statusLine: `${statusText}: ${detailText}`,
rows,
dataset: {
persistencePhase: ready ? "ready" : "waiting",
persistenceReady: ready ? "true" : "false",
persistenceScope: "opfs-session",
},
};
}
export function createMachineSessionWorkflowOverview(report = {}) {
const readiness = report.readiness ?? {};
const loaded = report.loaded ?? {};