feat: serialize public hardware execution
This commit is contained in:
@@ -61,6 +61,7 @@ from cognitive_agent.infrastructure.llm.openai_responses import ( # noqa: E402
|
||||
)
|
||||
from cognitive_agent.infrastructure.can.hardware import ( # noqa: E402
|
||||
HardwareSafetyError,
|
||||
PHYSICAL_BENCH_COORDINATOR,
|
||||
SeatHardwareSettings,
|
||||
)
|
||||
from cognitive_agent.runtime.contracts import ContractValidator # noqa: E402
|
||||
@@ -138,6 +139,7 @@ class SeatDemoService:
|
||||
repository_root / "platforms" / "t2g_seat_bench" / "calibration" / "seat.yaml",
|
||||
)
|
||||
self.hardware_settings = SeatHardwareSettings.from_env(repository_root)
|
||||
self.hardware_execution = PHYSICAL_BENCH_COORDINATOR
|
||||
# Shared by the short-lived hardware executor instances. A process must
|
||||
# establish a fresh physical four-axis reference before trusting stored
|
||||
# Hall counts, and a firmware replacement invalidates it again.
|
||||
@@ -177,6 +179,8 @@ class SeatDemoService:
|
||||
runtime.runtime_info() for runtime in self.domain_runtimes.values()
|
||||
]
|
||||
default_vehicle = self.vehicle_profiles.default()
|
||||
hardware_info = self.hardware_settings.public_info()
|
||||
hardware_info.update(self.hardware_execution.public_info())
|
||||
return {
|
||||
"service": "cabin-cognitive-orchestrator",
|
||||
"domain": "cabin",
|
||||
@@ -184,7 +188,7 @@ class SeatDemoService:
|
||||
"execution_mode": "dry_run",
|
||||
"execution_modes": ["dry_run", "simulated_hardware", "hardware"],
|
||||
"hardware_execution_allowed": self.hardware_settings.configured,
|
||||
"hardware": self.hardware_settings.public_info(),
|
||||
"hardware": hardware_info,
|
||||
"seat_position_memory_synchronized": bool(
|
||||
self._seat_position_memory_state.get("synchronized", False)
|
||||
),
|
||||
@@ -243,6 +247,16 @@ class SeatDemoService:
|
||||
self,
|
||||
conversation_id: str,
|
||||
vehicle_id: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Read the bench only when no physical execution currently owns it."""
|
||||
|
||||
with self.hardware_execution.reserve():
|
||||
return self._synchronize_hardware_state_once(conversation_id, vehicle_id)
|
||||
|
||||
def _synchronize_hardware_state_once(
|
||||
self,
|
||||
conversation_id: str,
|
||||
vehicle_id: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Read the bench and project it into the current passenger conversation."""
|
||||
|
||||
@@ -308,6 +322,37 @@ class SeatDemoService:
|
||||
approval_token: str | None = None,
|
||||
vehicle_id: str | None = None,
|
||||
simulation_fault: str = "normal",
|
||||
) -> dict[str, Any]:
|
||||
if execution_mode != "hardware":
|
||||
return self._process_once(
|
||||
utterance,
|
||||
provider,
|
||||
conversation_id,
|
||||
execution_mode,
|
||||
approval_token,
|
||||
vehicle_id,
|
||||
simulation_fault,
|
||||
)
|
||||
with self.hardware_execution.reserve():
|
||||
return self._process_once(
|
||||
utterance,
|
||||
provider,
|
||||
conversation_id,
|
||||
execution_mode,
|
||||
approval_token,
|
||||
vehicle_id,
|
||||
simulation_fault,
|
||||
)
|
||||
|
||||
def _process_once(
|
||||
self,
|
||||
utterance: str,
|
||||
provider: str = "auto",
|
||||
conversation_id: str | None = None,
|
||||
execution_mode: str = "dry_run",
|
||||
approval_token: str | None = None,
|
||||
vehicle_id: str | None = None,
|
||||
simulation_fault: str = "normal",
|
||||
) -> dict[str, Any]:
|
||||
utterance = utterance.strip()
|
||||
if not utterance:
|
||||
|
||||
Reference in New Issue
Block a user