feat(k1): complete canonical control lifecycle
This commit is contained in:
@@ -2,6 +2,7 @@ import type { RuntimePhase, SourceMode as RuntimeSourceMode } from "@mission-cor
|
||||
|
||||
import type {
|
||||
AcquisitionState,
|
||||
XgridsApplicationControlPhase,
|
||||
XgridsAcquisition,
|
||||
XgridsK1State,
|
||||
XgridsOperation,
|
||||
@@ -22,6 +23,25 @@ const FAILED_OPERATION_STATUSES = new Set([
|
||||
]);
|
||||
|
||||
export type LiveStartPlan = "prepare" | "resume-prepared" | "already-running" | "blocked";
|
||||
export type ControlSessionEntryPlan =
|
||||
| "open"
|
||||
| "continue"
|
||||
| "failed"
|
||||
| "duplicate-open";
|
||||
|
||||
export function controlSessionEntryPlan(
|
||||
phase: XgridsApplicationControlPhase,
|
||||
openedByCurrentOperatorAction: boolean,
|
||||
canOpen: boolean,
|
||||
): ControlSessionEntryPlan {
|
||||
if (phase === "failed") {
|
||||
return !openedByCurrentOperatorAction && canOpen ? "open" : "failed";
|
||||
}
|
||||
if (["idle", "closed", "completed"].includes(phase)) {
|
||||
return openedByCurrentOperatorAction ? "duplicate-open" : "open";
|
||||
}
|
||||
return "continue";
|
||||
}
|
||||
|
||||
export function isTerminalAcquisitionState(
|
||||
state: AcquisitionState | null | undefined,
|
||||
@@ -119,7 +139,12 @@ export function normalizeRuntimePhase(
|
||||
}
|
||||
if (acquisitionState === "prepared") return "connected";
|
||||
if (phase === "error") return "error";
|
||||
if (phase === "connected") return "connected";
|
||||
if (phase === "connected") {
|
||||
const controlPhase = state?.application_control_session?.state;
|
||||
return controlPhase && !["idle", "connecting", "closed", "completed", "failed"].includes(controlPhase)
|
||||
? "connected"
|
||||
: "configuring";
|
||||
}
|
||||
if (phase === "starting_live") return "starting";
|
||||
if (phase === "live") return "streaming";
|
||||
if (phase === "replay") return "replaying";
|
||||
|
||||
Reference in New Issue
Block a user