feat(lab): publish M4.7 Worker graph evidence
This commit is contained in:
@@ -37,8 +37,10 @@ import { fetchE46IGroundingDinoFullReplay } from "./e46iGroundingDinoFullReplay"
|
||||
import { fetchE46JRawFisheyeRealtime } from "./e46jRawFisheyeRealtime";
|
||||
import { fetchE47SemanticSlamResult } from "./e47SemanticSlam";
|
||||
import { fetchM4ThreatReplayResult } from "./m4ReplayThreat";
|
||||
import { fetchM47ReferenceGraphLab } from "./m47ReferenceGraph";
|
||||
|
||||
export type AdvancedLaboratoryWorkId =
|
||||
| "m47-reference-graph-shadow"
|
||||
| "m4-replay-threat"
|
||||
| "l3-pointpillars-visual-audit"
|
||||
| "l31-pointpillars-ravnoves"
|
||||
@@ -80,6 +82,7 @@ export interface AdvancedLaboratoryIndexItem {
|
||||
}
|
||||
|
||||
const WORK_IDS: readonly AdvancedLaboratoryWorkId[] = [
|
||||
"m47-reference-graph-shadow",
|
||||
"m4-replay-threat",
|
||||
"l3-pointpillars-visual-audit",
|
||||
"l31-pointpillars-ravnoves",
|
||||
@@ -116,6 +119,7 @@ const WORK_IDS: readonly AdvancedLaboratoryWorkId[] = [
|
||||
];
|
||||
|
||||
const RESULT_PREFIX: Readonly<Record<AdvancedLaboratoryWorkId, string>> = {
|
||||
"m47-reference-graph-shadow": "m47-reference-graph-lab",
|
||||
"m4-replay-threat": "m4-threat-replay",
|
||||
"l3-pointpillars-visual-audit": "l3-pointpillars-visual-audit",
|
||||
"l31-pointpillars-ravnoves": "l31-pointpillars-ravnoves",
|
||||
@@ -159,6 +163,7 @@ export function isAdvancedLaboratoryWorkId(
|
||||
|
||||
export function emptyAdvancedLaboratoryResults(): AdvancedLaboratoryResults {
|
||||
return {
|
||||
m47Graph: null,
|
||||
m4Threat: null,
|
||||
l3: null,
|
||||
l31: null,
|
||||
@@ -283,7 +288,8 @@ export function advancedLaboratoryResultAvailable(
|
||||
workId: AdvancedLaboratoryWorkId,
|
||||
results: AdvancedLaboratoryResults,
|
||||
): boolean {
|
||||
return workId === "m4-replay-threat" ? results.m4Threat !== null
|
||||
return workId === "m47-reference-graph-shadow" ? results.m47Graph !== null
|
||||
: workId === "m4-replay-threat" ? results.m4Threat !== null
|
||||
: workId === "l3-pointpillars-visual-audit" ? results.l3 !== null
|
||||
: workId === "l31-pointpillars-ravnoves" ? results.l31 !== null
|
||||
: workId === "l32-pointpillars-camera-review" ? results.l32 !== null
|
||||
@@ -323,13 +329,24 @@ export async function fetchAdvancedLaboratoryResult(
|
||||
{
|
||||
fetcher = fetch,
|
||||
signal,
|
||||
resultId,
|
||||
}: {
|
||||
fetcher?: LaboratoryFetch;
|
||||
signal?: AbortSignal;
|
||||
resultId?: string;
|
||||
} = {},
|
||||
): Promise<AdvancedLaboratoryResults> {
|
||||
const results = emptyAdvancedLaboratoryResults();
|
||||
if (workId === "m4-replay-threat") {
|
||||
if (workId === "m47-reference-graph-shadow") {
|
||||
if (!resultId) {
|
||||
throw new AdvancedLaboratoryContractError("M4.7 LAB identity не выбрана.");
|
||||
}
|
||||
results.m47Graph = await fetchM47ReferenceGraphLab({
|
||||
resultId,
|
||||
fetcher,
|
||||
signal,
|
||||
});
|
||||
} else if (workId === "m4-replay-threat") {
|
||||
results.m4Threat = await fetchM4ThreatReplayResult({ fetcher, signal });
|
||||
} else if (workId === "l3-pointpillars-visual-audit") {
|
||||
results.l3 = await fetchL3PointPillarsVisualAudit({ fetcher, signal });
|
||||
|
||||
@@ -33,8 +33,10 @@ import type { E46IGroundingDinoFullReplayResult } from "./e46iGroundingDinoFullR
|
||||
import type { E46JRawFisheyeRealtimeResult } from "./e46jRawFisheyeRealtime";
|
||||
import type { E47SemanticSlamResult } from "./e47SemanticSlam";
|
||||
import type { M4ThreatReplayResult } from "./m4ReplayThreat";
|
||||
import type { M47ReferenceGraphLabResult } from "./m47ReferenceGraph";
|
||||
|
||||
export interface AdvancedLaboratoryResults {
|
||||
m47Graph: M47ReferenceGraphLabResult | null;
|
||||
m4Threat: M4ThreatReplayResult | null;
|
||||
l3: L3PointPillarsVisualAuditResult | null;
|
||||
l31: L31PointPillarsRavnovesResult | null;
|
||||
|
||||
@@ -967,7 +967,7 @@ export async function fetchAdvancedLaboratoryResults({
|
||||
const e39 = settledCatalogValue(settled[7]);
|
||||
const e40 = settledCatalogValue(settled[8]);
|
||||
return {
|
||||
m4Threat: null,
|
||||
m47Graph: null, m4Threat: null,
|
||||
l3: null, l31: null,
|
||||
l32: null,
|
||||
l33: null,
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import {
|
||||
fetchLaboratoryEvidenceReport,
|
||||
type JsonValue,
|
||||
} from "./evidenceReport";
|
||||
import {
|
||||
fetchM4ThreatReplayResult,
|
||||
type M4ThreatReplayResult,
|
||||
} from "./m4ReplayThreat";
|
||||
|
||||
export interface M47ReferenceGraphLabResult {
|
||||
resultId: string;
|
||||
createdAtUtc: string;
|
||||
graphResultId: string;
|
||||
linkedVisualResultId: string;
|
||||
graphId: "reference-perception-graph/v2";
|
||||
worker: {
|
||||
id: "worker-006";
|
||||
node: string;
|
||||
artifactSha256: string;
|
||||
codeRevision: string;
|
||||
elapsedSeconds: number;
|
||||
};
|
||||
frames: {
|
||||
expected: 4489;
|
||||
admitted: 4489;
|
||||
delivered: 4489;
|
||||
};
|
||||
parityMismatchCounts: Readonly<Record<
|
||||
| "source_binding"
|
||||
| "current"
|
||||
| "rolling_retained"
|
||||
| "held"
|
||||
| "expired"
|
||||
| "camera_uncertainty"
|
||||
| "threat_assessments",
|
||||
0
|
||||
>>;
|
||||
queueHighWatermarks: Readonly<Record<
|
||||
"detector" | "geometry" | "temporal" | "rolling" | "threat",
|
||||
number
|
||||
>>;
|
||||
limitations: readonly string[];
|
||||
visual: M4ThreatReplayResult;
|
||||
}
|
||||
|
||||
type LaboratoryFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
||||
|
||||
class M47ReferenceGraphContractError extends Error {}
|
||||
|
||||
function object(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new M47ReferenceGraphContractError(`${label}: ожидался объект.`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function text(value: unknown, label: string): string {
|
||||
if (typeof value !== "string" || !value.trim()) {
|
||||
throw new M47ReferenceGraphContractError(`${label}: ожидалась строка.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function exact<T extends string | number | boolean>(
|
||||
value: unknown,
|
||||
expected: T,
|
||||
label: string,
|
||||
): T {
|
||||
if (value !== expected) {
|
||||
throw new M47ReferenceGraphContractError(`${label}: нарушен контракт.`);
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
|
||||
function finite(value: unknown, label: string): number {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
||||
throw new M47ReferenceGraphContractError(`${label}: ожидалось неотрицательное число.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function digest(value: unknown, label: string, length: 40 | 64): string {
|
||||
const parsed = text(value, label);
|
||||
if (!new RegExp(`^[a-f0-9]{${length}}$`).test(parsed)) {
|
||||
throw new M47ReferenceGraphContractError(`${label}: нарушена digest-идентичность.`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function zeroParity(value: unknown): M47ReferenceGraphLabResult["parityMismatchCounts"] {
|
||||
const document = object(value, "M4.7 parity");
|
||||
const keys = [
|
||||
"source_binding",
|
||||
"current",
|
||||
"rolling_retained",
|
||||
"held",
|
||||
"expired",
|
||||
"camera_uncertainty",
|
||||
"threat_assessments",
|
||||
] as const;
|
||||
if (
|
||||
Object.keys(document).length !== keys.length
|
||||
|| keys.some((key) => document[key] !== 0)
|
||||
) {
|
||||
throw new M47ReferenceGraphContractError("M4.7 parity: обнаружено расхождение.");
|
||||
}
|
||||
return Object.fromEntries(keys.map((key) => [key, 0])) as unknown as (
|
||||
M47ReferenceGraphLabResult["parityMismatchCounts"]
|
||||
);
|
||||
}
|
||||
|
||||
function queueWatermarks(
|
||||
value: unknown,
|
||||
): M47ReferenceGraphLabResult["queueHighWatermarks"] {
|
||||
const document = object(value, "M4.7 queue watermarks");
|
||||
const keys = ["detector", "geometry", "temporal", "rolling", "threat"] as const;
|
||||
if (Object.keys(document).length !== keys.length) {
|
||||
throw new M47ReferenceGraphContractError("M4.7 queues: состав стадий изменился.");
|
||||
}
|
||||
return Object.fromEntries(keys.map((key) => {
|
||||
const watermark = finite(document[key], `M4.7 queue ${key}`);
|
||||
if (!Number.isInteger(watermark) || watermark > 2) {
|
||||
throw new M47ReferenceGraphContractError(`M4.7 queue ${key}: нарушена граница.`);
|
||||
}
|
||||
return [key, watermark];
|
||||
})) as unknown as M47ReferenceGraphLabResult["queueHighWatermarks"];
|
||||
}
|
||||
|
||||
function stringArray(value: JsonValue | undefined, label: string): readonly string[] {
|
||||
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !item.trim())) {
|
||||
throw new M47ReferenceGraphContractError(`${label}: ожидался список строк.`);
|
||||
}
|
||||
return value as string[];
|
||||
}
|
||||
|
||||
export async function fetchM47ReferenceGraphLab({
|
||||
resultId,
|
||||
fetcher = fetch,
|
||||
signal,
|
||||
}: {
|
||||
resultId: string;
|
||||
fetcher?: LaboratoryFetch;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<M47ReferenceGraphLabResult> {
|
||||
if (!/^m47-reference-graph-lab-[a-f0-9]{64}$/.test(resultId)) {
|
||||
throw new M47ReferenceGraphContractError("M4.7 result id: нарушена идентичность.");
|
||||
}
|
||||
const evidence = await fetchLaboratoryEvidenceReport({
|
||||
workId: "m47-reference-graph-shadow",
|
||||
resultId,
|
||||
fetcher,
|
||||
signal,
|
||||
});
|
||||
const report = evidence.rawReport;
|
||||
exact(
|
||||
report.schema_version,
|
||||
"missioncore.reference-perception-graph-lab-report/v1",
|
||||
"M4.7 report schema",
|
||||
);
|
||||
exact(report.result_id, resultId, "M4.7 report result");
|
||||
const source = object(report.source, "M4.7 source");
|
||||
const method = object(report.method, "M4.7 method");
|
||||
const execution = object(report.execution, "M4.7 execution");
|
||||
const metrics = object(report.metrics, "M4.7 metrics");
|
||||
const frames = object(metrics.frames, "M4.7 frames");
|
||||
const acceptance = object(report.acceptance, "M4.7 acceptance");
|
||||
const authority = object(report.authority, "M4.7 authority");
|
||||
const visualEvidence = object(report.visual_evidence, "M4.7 visual evidence");
|
||||
exact(acceptance.accepted, true, "M4.7 acceptance");
|
||||
exact(authority.commands_enabled, false, "M4.7 commands");
|
||||
exact(authority.actuation_allowed, false, "M4.7 actuation");
|
||||
exact(authority.navigation_or_safety_accepted, false, "M4.7 safety authority");
|
||||
exact(visualEvidence.shared_recorded_clock, true, "M4.7 recorded clock");
|
||||
exact(
|
||||
visualEvidence.video_camera_3d_plan_available,
|
||||
true,
|
||||
"M4.7 visual evidence",
|
||||
);
|
||||
const linkedVisualResultId = text(
|
||||
visualEvidence.linked_result_id,
|
||||
"M4.7 linked visual result",
|
||||
);
|
||||
if (!/^m4-threat-replay-[a-f0-9]{64}$/.test(linkedVisualResultId)) {
|
||||
throw new M47ReferenceGraphContractError("M4.7 visual binding: нарушена идентичность.");
|
||||
}
|
||||
const visual = await fetchM4ThreatReplayResult({
|
||||
resultId: linkedVisualResultId,
|
||||
fetcher,
|
||||
signal,
|
||||
});
|
||||
if (!visual || visual.resultId !== linkedVisualResultId) {
|
||||
throw new M47ReferenceGraphContractError(
|
||||
"M4.7 visual binding: сервер вернул другой replay result.",
|
||||
);
|
||||
}
|
||||
const graphResultId = text(source.graph_result_id, "M4.7 graph result");
|
||||
if (!/^m47-reference-graph-[a-f0-9]{64}$/.test(graphResultId)) {
|
||||
throw new M47ReferenceGraphContractError("M4.7 graph result: нарушена идентичность.");
|
||||
}
|
||||
return {
|
||||
resultId,
|
||||
createdAtUtc: text(evidence.createdAtUtc, "M4.7 created at"),
|
||||
graphResultId,
|
||||
linkedVisualResultId,
|
||||
graphId: exact(method.graph_id, "reference-perception-graph/v2", "M4.7 graph id"),
|
||||
worker: {
|
||||
id: exact(execution.worker_id, "worker-006", "M4.7 worker"),
|
||||
node: text(execution.worker_node, "M4.7 worker node"),
|
||||
artifactSha256: digest(execution.artifact_sha256, "M4.7 artifact", 64),
|
||||
codeRevision: digest(execution.code_revision, "M4.7 revision", 40),
|
||||
elapsedSeconds: finite(execution.elapsed_seconds, "M4.7 elapsed"),
|
||||
},
|
||||
frames: {
|
||||
expected: exact(frames.expected, 4489, "M4.7 expected frames"),
|
||||
admitted: exact(frames.admitted, 4489, "M4.7 admitted frames"),
|
||||
delivered: exact(frames.delivered, 4489, "M4.7 delivered frames"),
|
||||
},
|
||||
parityMismatchCounts: zeroParity(metrics.parity_mismatch_counts),
|
||||
queueHighWatermarks: queueWatermarks(metrics.queue_high_watermarks),
|
||||
limitations: stringArray(report.limitations, "M4.7 limitations"),
|
||||
visual,
|
||||
};
|
||||
}
|
||||
@@ -315,22 +315,59 @@ function parseMetricVisual(value: unknown): M4ThreatMetricVisual {
|
||||
}
|
||||
|
||||
export async function fetchM4ThreatReplayResult({
|
||||
resultId: requestedResultId,
|
||||
fetcher = fetch,
|
||||
signal,
|
||||
}: {
|
||||
resultId?: string;
|
||||
fetcher?: LaboratoryFetch;
|
||||
signal?: AbortSignal;
|
||||
} = {}): Promise<M4ThreatReplayResult | null> {
|
||||
const response = await fetcher("/api/v1/laboratory/m4-threat/results?limit=1", {
|
||||
headers: { Accept: "application/json" },
|
||||
signal,
|
||||
});
|
||||
if (
|
||||
requestedResultId !== undefined
|
||||
&& !/^m4-threat-replay-[a-f0-9]{64}$/.test(requestedResultId)
|
||||
) {
|
||||
throw new M4ThreatContractError("M4.6 requested result id: нарушена идентичность.");
|
||||
}
|
||||
let response = await fetcher(
|
||||
requestedResultId === undefined
|
||||
? "/api/v1/laboratory/m4-threat/results?limit=1"
|
||||
: `/api/v1/laboratory/m4-threat/results/${requestedResultId}`,
|
||||
{ headers: { Accept: "application/json" }, signal },
|
||||
);
|
||||
// Rolling deployments may briefly pair the new UI with the previous read-only
|
||||
// API. Preserve exact-result binding by selecting the requested result from
|
||||
// the catalog instead of silently falling back to whatever happens to be latest.
|
||||
let catalogFallback = false;
|
||||
if (requestedResultId !== undefined && response.status === 404) {
|
||||
response = await fetcher("/api/v1/laboratory/m4-threat/results?limit=10", {
|
||||
headers: { Accept: "application/json" },
|
||||
signal,
|
||||
});
|
||||
catalogFallback = true;
|
||||
}
|
||||
if (!response.ok) throw new M4ThreatContractError(`M4.6 LAB недоступен: HTTP ${response.status}.`);
|
||||
const catalog = object(await response.json(), "M4.6 catalog");
|
||||
exact(catalog.schema_version, "missioncore.m4-threat-replay-catalog/v1", "M4.6 catalog schema");
|
||||
const items = array(catalog.items, "M4.6 results");
|
||||
if (!items.length) return null;
|
||||
const item = object(items[0], "M4.6 result");
|
||||
const payload = await response.json();
|
||||
let item: Record<string, unknown>;
|
||||
if (requestedResultId === undefined || catalogFallback) {
|
||||
const catalog = object(payload, "M4.6 catalog");
|
||||
exact(catalog.schema_version, "missioncore.m4-threat-replay-catalog/v1", "M4.6 catalog schema");
|
||||
const items = array(catalog.items, "M4.6 results");
|
||||
if (!items.length) return null;
|
||||
const selected = requestedResultId === undefined
|
||||
? items[0]
|
||||
: items.find((candidate) => (
|
||||
typeof candidate === "object"
|
||||
&& candidate !== null
|
||||
&& (candidate as Record<string, unknown>).result_id === requestedResultId
|
||||
));
|
||||
if (selected === undefined) {
|
||||
throw new M4ThreatContractError("M4.6 requested result: точный результат отсутствует в каталоге.");
|
||||
}
|
||||
item = object(selected, "M4.6 result");
|
||||
} else {
|
||||
item = object(payload, "M4.6 result");
|
||||
}
|
||||
exact(item.schema_version, "missioncore.m4-threat-replay-view/v1", "M4.6 view schema");
|
||||
exact(item.accepted, true, "M4.6 acceptance");
|
||||
exact(item.authority, "replay-simulated", "M4.6 authority");
|
||||
@@ -349,8 +386,12 @@ export async function fetchM4ThreatReplayResult({
|
||||
const configuration = object(item.configuration, "M4.6 configuration");
|
||||
const configuredBodyFrame = object(configuration.body_frame, "M4.6 configured body frame");
|
||||
const sourceResultIds = object(item.source_result_ids, "M4.6 sources");
|
||||
const parsedResultId = resultId(item.result_id);
|
||||
if (requestedResultId !== undefined) {
|
||||
exact(parsedResultId, requestedResultId, "M4.6 requested result");
|
||||
}
|
||||
return {
|
||||
resultId: resultId(item.result_id),
|
||||
resultId: parsedResultId,
|
||||
createdAtUtc: text(item.created_at_utc, "M4.6 created"),
|
||||
profileId: text(item.profile_id, "M4.6 profile"),
|
||||
rigProfileId: text(item.rig_profile_id, "M4.6 rig"),
|
||||
|
||||
Reference in New Issue
Block a user