feat(observatory): ship modular AI inference labs
This commit is contained in:
+117
-13
@@ -49,7 +49,10 @@ from k1link.viewer.recorded import (
|
||||
from k1link.viewer.recorded import (
|
||||
RecordedBlueprintError,
|
||||
recorded_blueprint_rrd,
|
||||
recorded_blueprint_sessions,
|
||||
)
|
||||
from k1link.viewer.recorded_blueprint_lifecycle import BlueprintSessionReleased
|
||||
from k1link.viewer.recorded_camera_bounds import recorded_orbital_radius_limit
|
||||
from k1link.viewer.rerun_bridge import RerunSceneSettings
|
||||
|
||||
DEFAULT_REPLAY_ACTION_ID = "stream.start-replay"
|
||||
@@ -102,7 +105,7 @@ class ReplayRequest(StrictApiModel):
|
||||
loop: bool = False
|
||||
|
||||
|
||||
class RecordedBlueprintRequest(StrictApiModel):
|
||||
class RecordedBlueprintIdentity(StrictApiModel):
|
||||
application_id: Literal["nodedc_mission_core_recorded"]
|
||||
recording_id: str = Field(
|
||||
min_length=1,
|
||||
@@ -114,25 +117,58 @@ class RecordedBlueprintRequest(StrictApiModel):
|
||||
max_length=32,
|
||||
pattern=r"^[a-f0-9]{32}$",
|
||||
)
|
||||
accumulation_seconds: float = Field(strict=True, ge=0.0, le=3600.0)
|
||||
|
||||
|
||||
class RecordedBlueprintLifecycleRequest(RecordedBlueprintIdentity):
|
||||
action: Literal["renew", "release"]
|
||||
|
||||
|
||||
EyeCoordinate = Annotated[float, Field(strict=True, allow_inf_nan=False)]
|
||||
EyeVector = tuple[EyeCoordinate, EyeCoordinate, EyeCoordinate]
|
||||
|
||||
|
||||
class RecordedBlueprintRequest(RecordedBlueprintIdentity):
|
||||
accumulation_seconds: float = Field(strict=True, ge=0.0, allow_inf_nan=False)
|
||||
show_points: StrictBool
|
||||
show_trajectory: StrictBool
|
||||
show_grid: StrictBool
|
||||
point_size: float = Field(default=2.5, strict=True, ge=0.1, le=32.0)
|
||||
point_size: float = Field(default=2.5, strict=True, ge=0.1, allow_inf_nan=False)
|
||||
color_mode: Literal["intensity", "height", "distance", "rgb", "class"] = "intensity"
|
||||
palette: Literal["turbo", "viridis", "plasma", "grayscale", "custom"] = "turbo"
|
||||
custom_color: str = Field(default="#f7f8f4", pattern=r"^#[0-9A-Fa-f]{6}$")
|
||||
active_view: Literal["spatial", "perception", "perception3d", "metrics"] = "spatial"
|
||||
view_reset_generation: Literal[0, 1] = 0
|
||||
unified_perception: StrictBool = False
|
||||
unified_camera_share: float = Field(strict=True, ge=0.1, le=0.9, default=0.46)
|
||||
semantic_layer: Literal["city", "vegetation"] | None = None
|
||||
plan_view: StrictBool = False
|
||||
show_detections_2d: StrictBool = False
|
||||
show_camera_image: StrictBool = True
|
||||
show_segmentation: StrictBool = False
|
||||
show_cuboids_3d: StrictBool = False
|
||||
show_costmap: StrictBool = False
|
||||
reactivate_updates: StrictBool = False
|
||||
follow_trajectory: StrictBool = False
|
||||
eye_position: EyeVector | None = None
|
||||
eye_look_target: EyeVector | None = None
|
||||
eye_up: EyeVector | None = None
|
||||
current_time_ns: int | None = Field(default=None, strict=True, ge=0, le=MAX_SAFE_INTEGER)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_eye_vectors(self) -> RecordedBlueprintRequest:
|
||||
vectors = (self.eye_position, self.eye_look_target, self.eye_up)
|
||||
if any(vector is None for vector in vectors):
|
||||
if not all(vector is None for vector in vectors):
|
||||
raise ValueError("all eye vectors must be supplied together")
|
||||
return self
|
||||
assert self.eye_position is not None
|
||||
assert self.eye_look_target is not None
|
||||
assert self.eye_up is not None
|
||||
if self.eye_position == self.eye_look_target:
|
||||
raise ValueError("eye position and look target must differ")
|
||||
if sum(value * value for value in self.eye_up) <= 1.0e-12:
|
||||
raise ValueError("eye up vector must be non-zero")
|
||||
return self
|
||||
|
||||
|
||||
class RecordedPerceptionRequest(StrictApiModel):
|
||||
@@ -365,6 +401,7 @@ def build_session_router(
|
||||
cursor: str | None = Query(default=None, max_length=128),
|
||||
scope: Literal["all", "source", "laboratory"] = "all",
|
||||
lab_contract: Literal["v1", "v2", "v3"] = "v1",
|
||||
pagination: Literal["cursor-v1"] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
_refresh_catalog(catalog_refresher)
|
||||
@@ -375,6 +412,14 @@ def build_session_router(
|
||||
include_capability_projections=lab_contract in ("v2", "v3"),
|
||||
)
|
||||
return {
|
||||
**(
|
||||
{
|
||||
"schema_version": "missioncore.observation-session-page/v1",
|
||||
"next_cursor": page.next_cursor,
|
||||
}
|
||||
if pagination == "cursor-v1"
|
||||
else {}
|
||||
),
|
||||
"items": [
|
||||
{
|
||||
"id": item.session_id,
|
||||
@@ -391,9 +436,7 @@ def build_session_router(
|
||||
else item.capture_attestation.as_dict()
|
||||
),
|
||||
**(
|
||||
{
|
||||
"lab": lab_catalog_document(item, lab_contract)
|
||||
}
|
||||
{"lab": lab_catalog_document(item, lab_contract)}
|
||||
if item.lab is not None
|
||||
else {}
|
||||
),
|
||||
@@ -411,7 +454,7 @@ def build_session_router(
|
||||
}
|
||||
for item in page.items
|
||||
if item.started_at_utc is not None
|
||||
]
|
||||
],
|
||||
}
|
||||
except SessionNotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
@@ -870,9 +913,7 @@ def build_session_router(
|
||||
**response_kwargs,
|
||||
)
|
||||
|
||||
@router.get(
|
||||
"/api/v1/observation-sessions/{session_id}/canonical-lab/spatial-frame"
|
||||
)
|
||||
@router.get("/api/v1/observation-sessions/{session_id}/canonical-lab/spatial-frame")
|
||||
async def get_observation_session_canonical_lab_spatial_frame(
|
||||
session_id: str,
|
||||
generation: Annotated[str, Query(min_length=64, max_length=64)],
|
||||
@@ -937,20 +978,37 @@ def build_session_router(
|
||||
headers={
|
||||
"Cache-Control": "private, max-age=31536000, immutable",
|
||||
"ETag": (
|
||||
f'"{generation}:{CANONICAL_LAB_SPATIAL_PROFILE}:'
|
||||
f'{payload["source_time_ns"]}"'
|
||||
f'"{generation}:{CANONICAL_LAB_SPATIAL_PROFILE}:{payload["source_time_ns"]}"'
|
||||
),
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
)
|
||||
|
||||
@router.post("/api/v1/observation-sessions/{session_id}/blueprint-lifecycle")
|
||||
async def update_recorded_blueprint_lifecycle(
|
||||
session_id: str,
|
||||
request: RecordedBlueprintLifecycleRequest,
|
||||
) -> Response:
|
||||
# Releasing an ephemeral owner must still work after source removal.
|
||||
# The random viewport identity authorizes only its own memory resource;
|
||||
# this route never materializes or deletes recordings/artifacts.
|
||||
if not SAFE_SOURCE_ID.fullmatch(session_id):
|
||||
raise HTTPException(status_code=422, detail="Некорректный идентификатор сессии.")
|
||||
key = (request.application_id, request.recording_id, request.blueprint_session_id)
|
||||
if request.action == "release":
|
||||
await run_in_threadpool(recorded_blueprint_sessions.release, key)
|
||||
else:
|
||||
await run_in_threadpool(recorded_blueprint_sessions.renew, key)
|
||||
return Response(status_code=204, headers={"Cache-Control": "no-store"})
|
||||
|
||||
@router.post("/api/v1/observation-sessions/{session_id}/blueprint.rrd")
|
||||
async def get_observation_session_blueprint(
|
||||
session_id: str,
|
||||
request: RecordedBlueprintRequest,
|
||||
) -> Response:
|
||||
camera_max_orbital_radius: float | None = None
|
||||
try:
|
||||
await run_in_threadpool(
|
||||
command = await run_in_threadpool(
|
||||
_prepare_replay,
|
||||
store,
|
||||
catalog_refresher,
|
||||
@@ -977,19 +1035,55 @@ def build_session_router(
|
||||
active_view=request.active_view,
|
||||
view_reset_generation=request.view_reset_generation,
|
||||
unified_perception=request.unified_perception,
|
||||
unified_camera_share=request.unified_camera_share,
|
||||
semantic_layer=request.semantic_layer,
|
||||
plan_view=request.plan_view,
|
||||
show_detections_2d=request.show_detections_2d,
|
||||
show_camera_image=request.show_camera_image,
|
||||
show_segmentation=request.show_segmentation,
|
||||
show_cuboids_3d=request.show_cuboids_3d,
|
||||
show_costmap=request.show_costmap,
|
||||
reactivate_updates=request.reactivate_updates,
|
||||
follow_trajectory=request.follow_trajectory,
|
||||
eye_position=request.eye_position,
|
||||
eye_look_target=request.eye_look_target,
|
||||
eye_up=request.eye_up,
|
||||
)
|
||||
if request.current_time_ns is not None:
|
||||
camera_recording = None
|
||||
if recording_preparation_manager is not None:
|
||||
snapshot = recording_preparation_manager.status(session_id)
|
||||
if (
|
||||
snapshot is not None
|
||||
and snapshot.state == "ready"
|
||||
and snapshot.recording is not None
|
||||
):
|
||||
camera_recording = snapshot.recording
|
||||
# A composition replay consumes the immutable base launch but
|
||||
# does not GET its recording. Its short launch reservation can
|
||||
# therefore expire while the combined RRD remains open. Restore
|
||||
# the already-published base descriptor with bounded stat checks
|
||||
# so later layer toggles still receive the native zoom limit.
|
||||
if camera_recording is None and recording_materializer is not None:
|
||||
camera_recording = await run_in_threadpool(
|
||||
recording_materializer.restore_published,
|
||||
command,
|
||||
)
|
||||
if camera_recording is not None:
|
||||
camera_max_orbital_radius = await run_in_threadpool(
|
||||
recorded_orbital_radius_limit,
|
||||
camera_recording.path,
|
||||
current_time_ns=request.current_time_ns,
|
||||
accumulation_seconds=request.accumulation_seconds,
|
||||
show_points=request.show_points,
|
||||
show_trajectory=request.show_trajectory,
|
||||
)
|
||||
except SessionNotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
except (SessionNotReplayableError, SessionIntegrityError) as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
except BlueprintSessionReleased as exc:
|
||||
raise HTTPException(status_code=410, detail="Сессия визуализатора закрыта.") from exc
|
||||
except RecordedBlueprintError as exc:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
@@ -1007,6 +1101,16 @@ def build_session_router(
|
||||
"Cache-Control": "no-store",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"Content-Disposition": 'inline; filename="blueprint.rrd"',
|
||||
**(
|
||||
{
|
||||
"X-MissionCore-Camera-Max-Orbital-Radius": format(
|
||||
camera_max_orbital_radius,
|
||||
".9g",
|
||||
)
|
||||
}
|
||||
if camera_max_orbital_radius is not None
|
||||
else {}
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user