{
  "openapi": "3.1.0",
  "info": {
    "title": "PHOS Local API",
    "version": "1.10.0",
    "description": "Provider-neutral local control and observation API. It exposes semantic PHOS state only; it never exposes hardware, GPIO, provider, camera-frame, or renderer implementation details. Disabled, unavailable, stale, and warming-up subsystems remain explicit in responses."
  },
  "servers": [{"url": "/", "description": "The same configured PHOS Web Admin/API listener that served this document"}],
  "security": [{"phosAdminSession": []}],
  "tags": [{"name": "Status"}, {"name": "Control"}, {"name": "Configuration"}, {"name": "Events"}],
  "paths": {
    "/api/v1/speak": {"post": {"tags": ["Control"], "summary": "Speak a short phrase through the configured PHOS TTS path", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["text"], "additionalProperties": false, "properties": {"text": {"type": "string", "minLength": 1, "maxLength": 500}}, "example": {"text": "Hello from PHOS."}}}}}, "responses": {"202": {"description": "Speech accepted by the main PHOS runtime", "content": {"application/json": {"schema": {"type": "object", "required": ["status"], "properties": {"status": {"const": "accepted"}}}}}}, "400": {"description": "Missing, invalid, blank, or overlong speech text"}, "409": {"description": "PHOS is already speaking"}, "503": {"$ref": "#/components/responses/Unavailable"}, "500": {"$ref": "#/components/responses/InternalError"}}}},
    "/api/v1/status": {"get": {"tags": ["Status"], "summary": "Get consolidated PHOS status", "responses": {"200": {"description": "Current semantic status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/RobotStatus"}}}}, "500": {"$ref": "#/components/responses/InternalError"}}}},
    "/api/v1/presence": {"get": {"tags": ["Status"], "summary": "Get provider-neutral human-presence state", "responses": {"200": {"description": "Current presence interpretation", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PresenceState"}}}}}}},
    "/api/v1/attention": {"get": {"tags": ["Status"], "summary": "Get provider-neutral attention target state", "responses": {"200": {"description": "Current attention interpretation", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/AttentionState"}}}}}}},
    "/api/v1/observed-expression": {"get": {"tags": ["Status"], "summary": "Get the latest uncertain selected-face expression observation", "responses": {"200": {"description": "Current classifier observation; unavailable is a valid non-error state.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ObservedExpression"}}}}}}},
    "/api/v1/state": {"get": {"tags": ["Status"], "summary": "Get robot lifecycle state", "responses": {"200": {"description": "State", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/RobotState"}}}}}}, "post": {"tags": ["Control"], "summary": "Set a semantic robot state", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/StateCommand"}, "example": {"state": "sleeping"}}}}, "responses": {"200": {"description": "Applied state", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/RobotState"}}}}, "400": {"$ref": "#/components/responses/InvalidState"}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/environment": {"get": {"tags": ["Status"], "summary": "Get environmental reading availability", "responses": {"200": {"description": "Environmental status; measurements are null while unavailable or stale.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/EnvironmentStatus"}}}}}}},
    "/api/v1/motion": {"get": {"tags": ["Status"], "summary": "Get motion sensor availability", "responses": {"200": {"description": "Motion status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/MotionStatus"}}}}}}},
    "/api/v1/health": {"get": {"tags": ["Status"], "summary": "Get runtime and subsystem health", "responses": {"200": {"description": "Health summary", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HealthStatus"}}}}}}},
    "/api/v1/voice": {"get": {"tags": ["Status"], "summary": "Get voice and STT status", "responses": {"200": {"description": "Voice status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/VoiceStatus"}}}}}}},
    "/api/v1/voice/listen": {"post": {"tags": ["Control"], "summary": "Start one explicit voice-capture session", "responses": {"200": {"description": "Voice status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/VoiceStatus"}}}}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/voice/stop": {"post": {"tags": ["Control"], "summary": "Stop a voice-capture session", "responses": {"200": {"description": "Voice status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/VoiceStatus"}}}}}}},
    "/api/v1/voice/cancel": {"post": {"tags": ["Control"], "summary": "Cancel and discard a voice session", "responses": {"200": {"description": "Voice status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/VoiceStatus"}}}}}}},
    "/api/v1/capabilities": {"get": {"tags": ["Status"], "summary": "Get supported semantic capabilities", "description": "Operation-oriented semantic contract. Commands identify exactly what can be submitted; observable states are readable runtime vocabulary only.", "responses": {"200": {"description": "Supported semantic commands and observable states", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Capabilities"}, "example": {"commands": {"set_robot_state": {"method": "POST", "endpoint": "/api/v1/state", "field": "state", "allowed_values": ["idle", "listening", "thinking", "speaking", "sleeping"]}, "set_expression": {"method": "POST", "endpoint": "/api/v1/expression", "field": "expression", "allowed_values": ["neutral", "happy", "curious", "surprised", "sad", "angry", "focused", "tired", "confused", "scared", "skeptical"]}, "set_visual_source": {"method": "POST", "endpoint": "/api/v1/visual-source", "field": "source", "allowed_values": ["manual", "environment", "state"]}}, "observable_states": {"robot_state": ["idle", "listening", "thinking", "speaking", "sleeping", "error"], "motion_state": ["still", "moving", "tilt_left", "tilt_right", "tilt_forward", "tilt_back", "shake", "impact"], "environmental_state": ["normal", "cold", "warm", "air_quality_warning", "air_quality_bad"], "environmental_overlays": {"temperature": ["none", "cold", "warm"], "air_quality": ["none", "warning", "bad"]}}}}}}}}},
    "/api/v1/overlay": {"get": {"tags": ["Status"], "summary": "Get environmental, manual, and resolved overlay intent", "responses": {"200": {"description": "Current overlay arbitration", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/OverlayState"}}}}}}, "post": {"tags": ["Control"], "summary": "Set a temporary semantic overlay override", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/OverlayOverrideRequest"}}}}, "responses": {"200": {"description": "Applied overlay arbitration", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/OverlayState"}}}}, "400": {"$ref": "#/components/responses/InvalidOverlay"}}}, "delete": {"tags": ["Control"], "summary": "Clear the manual overlay override", "responses": {"200": {"description": "Environmental overlay restored", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/OverlayState"}}}}}}},
    "/api/v1/config": {"get": {"tags": ["Configuration"], "summary": "Get saved and active configuration", "responses": {"200": {"description": "Canonical configuration", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ConfigStatus"}}}}, "503": {"$ref": "#/components/responses/Unavailable"}}}, "patch": {"tags": ["Configuration"], "summary": "Validate and update supported canonical configuration fields", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ConfigPatch"}, "example": {"display": {"base_visual_source": "environment"}}}}}, "responses": {"200": {"description": "Saved configuration and application result", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ConfigUpdate"}}}}, "400": {"$ref": "#/components/responses/InvalidConfiguration"}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/mqtt/discovery/candidates": {"get": {"tags": ["Configuration"], "summary": "List inactive MQTT discovery candidates", "responses": {"200": {"description": "Bounded untrusted candidate metadata", "content": {"application/json": {"schema": {"type": "object", "required": ["candidates"], "properties": {"candidates": {"type": "array", "items": {"type": "object"}}}}}}}, "503": {"$ref": "#/components/responses/Unavailable"}}}, "post": {"tags": ["Configuration"], "summary": "Edit, approve, reject or revoke a discovery candidate", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object"}}}}, "responses": {"200": {"description": "Review operation result"}, "400": {"$ref": "#/components/responses/InvalidConfiguration"}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/settings/mcp": {"get": {"tags": ["Configuration"], "summary": "Get MCP listener settings and runtime status", "responses": {"200": {"description": "Current MCP listener configuration and status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/McpSettings"}}}}, "503": {"$ref": "#/components/responses/Unavailable"}, "500": {"$ref": "#/components/responses/InternalError"}}}, "patch": {"tags": ["Configuration"], "summary": "Enable or disable MCP and rebind its listener port", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/McpSettingsPatch"}, "example": {"enabled": true, "port": 8100}}}}, "responses": {"200": {"description": "Applied MCP listener configuration and status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/McpSettings"}}}}, "400": {"$ref": "#/components/responses/InvalidMcpSettings"}, "409": {"$ref": "#/components/responses/McpPortUnavailable"}, "503": {"$ref": "#/components/responses/Unavailable"}, "500": {"$ref": "#/components/responses/InternalError"}}}},
    "/api/v1/backgrounds/assets": {"get": {"tags": ["Configuration"], "summary": "List managed background assets", "responses": {"200": {"description": "Safe managed image assets", "content": {"application/json": {"schema": {"type": "array", "items": {"$ref": "#/components/schemas/BackgroundAsset"}}}}}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/backgrounds": {"post": {"tags": ["Configuration"], "summary": "Configure semantic state backgrounds", "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "description": "Validated partial display.backgrounds configuration."}}}}, "responses": {"200": {"description": "Saved background configuration", "content": {"application/json": {"schema": {"type": "object"}}}}, "400": {"$ref": "#/components/responses/InvalidConfiguration"}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/expression": {"post": {"tags": ["Control"], "summary": "Trigger a semantic expression", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ExpressionCommand"}, "example": {"expression": "happy"}}}}, "responses": {"200": {"description": "Expression accepted", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ExpressionState"}}}}, "400": {"$ref": "#/components/responses/InvalidExpression"}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/visual-source": {"post": {"tags": ["Control"], "summary": "Set the semantic visual source", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/VisualSourceCommand"}, "example": {"source": "environment"}}}}, "responses": {"200": {"description": "Visual source accepted", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/VisualSourceState"}}}}, "400": {"$ref": "#/components/responses/InvalidVisualSource"}}}},
    "/api/v1/signal": {"post": {"tags": ["Control"], "summary": "Apply a semantic user signal", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/SignalCommand"}, "example": {"signal": "success"}}}}, "responses": {"200": {"description": "Semantic signal accepted", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/SemanticLedStatus"}}}}, "400": {"$ref": "#/components/responses/InvalidSignal"}, "503": {"$ref": "#/components/responses/Unavailable"}}}},
    "/api/v1/events": {"get": {"tags": ["Events"], "summary": "Subscribe to low-rate semantic events", "description": "WSGI compatibility transport: Server-Sent Events, not a WebSocket. Event payloads are emitted only for meaningful changes and duplicate consecutive payloads are suppressed.", "responses": {"200": {"description": "SSE event stream", "content": {"text/event-stream": {"schema": {"type": "string"}, "example": "event: health_changed\\ndata: {\\\"type\\\":\\\"health_changed\\\",\\\"timestamp\\\":\\\"2026-09-27T12:00:00.000+00:00\\\",\\\"payload\\\":{}}\\n\\n"}}}}}}
  },
  "components": {"schemas": {
    "RobotState": {"type": "object", "required": ["state", "current", "running", "writable", "allowed_next"], "properties": {"state": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping", "error"]}, "current": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping", "error"]}, "running": {"type": "boolean"}, "writable": {"type": "array", "items": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping"]}}, "allowed_next": {"type": "array", "items": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping"]}}}},
    "ExpressionState": {"type": "object", "required": ["expression"], "properties": {"expression": {"type": "string", "enum": ["neutral", "happy", "curious", "surprised", "sleepy", "worried", "sad", "angry", "focused", "tired", "confused", "scared", "skeptical"]}}},
    "VisualSource": {"type": "string", "enum": ["manual", "environment", "state"]},
    "VisualSourceCommand": {"type": "object", "required": ["source"], "properties": {"source": {"$ref": "#/components/schemas/VisualSource"}}},
    "VisualSourceState": {"type": "object", "required": ["source"], "properties": {"source": {"$ref": "#/components/schemas/VisualSource"}}},
    "SignalCommand": {"type": "object", "required": ["signal"], "additionalProperties": false, "properties": {"signal": {"type": "string", "enum": ["success", "warning", "error", "attention"]}}},
    "SemanticLedStatus": {"type": "object", "required": ["active_intent", "winning_source", "resolved_animation", "available"], "properties": {"active_intent": {"type": ["string", "null"]}, "winning_source": {"type": ["string", "null"]}, "resolved_animation": {"type": ["object", "null"]}, "available": {"type": "boolean"}}},
    "StateCommand": {"type": "object", "required": ["state"], "properties": {"state": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping"], "description": "ERROR is a readable runtime-only state and cannot be set remotely."}}},
    "ExpressionCommand": {"type": "object", "required": ["expression"], "properties": {"expression": {"type": "string", "enum": ["neutral", "happy", "curious", "surprised", "sad", "angry", "focused", "tired", "confused", "scared", "skeptical"], "description": "Writable expressions only; other expressions are readable runtime outcomes."}}},
    "VisualState": {"type": "object", "properties": {"expression": {"$ref": "#/components/schemas/ExpressionState/properties/expression"}, "accent": {"type": "string", "enum": ["neutral", "warm", "cool", "curious", "alert", "sleepy", "error"]}, "ambient_overlay": {"$ref": "#/components/schemas/EnvironmentalOverlayState"}, "motion_state": {"type": ["string", "null"]}}},
    "EnvironmentalOverlayState": {"type": "object", "properties": {"temperature": {"type": "string", "enum": ["none", "cold", "warm"]}, "air_quality": {"type": "string", "enum": ["none", "air_quality_warning", "air_quality_bad"]}}},
    "EnvironmentStatus": {"type": "object", "required": ["status", "available"], "properties": {"status": {"type": "string", "enum": ["available", "warming_up", "stale", "unavailable", "disabled", "starting", "stopped"]}, "available": {"type": "boolean"}, "measurements": {"type": ["object", "null"], "description": "Null when no current reading is available."}, "last_update": {"type": ["string", "null"], "format": "date-time"}, "age_seconds": {"type": ["number", "null"]}, "error": {"type": ["string", "null"]}}},
    "MotionStatus": {"$ref": "#/components/schemas/EnvironmentStatus"},
    "SubsystemHealth": {"type": "object", "required": ["state"], "properties": {"state": {"type": "string", "enum": ["ok", "warming_up", "stale", "unavailable"]}, "detail": {"type": "string"}}},
    "HealthStatus": {"type": "object", "required": ["uptime_seconds", "python", "subsystems"], "properties": {"uptime_seconds": {"type": "number", "minimum": 0}, "python": {"type": "string"}, "subsystems": {"type": "object", "additionalProperties": {"$ref": "#/components/schemas/SubsystemHealth"}}}},
    "VoiceStatus": {"type": "object", "required": ["enabled", "state", "listening", "speech_detected", "stt_provider", "stt_available", "last_transcript", "last_confidence", "language", "last_transcription_at", "last_transcription_duration_ms", "last_error"], "properties": {"enabled": {"type": "boolean"}, "state": {"type": "string", "enum": ["idle", "listening", "thinking"]}, "listening": {"type": "boolean"}, "speech_detected": {"type": "boolean"}, "stt_provider": {"type": ["string", "null"]}, "stt_available": {"type": "boolean"}, "last_transcript": {"type": ["string", "null"]}, "last_confidence": {"type": ["number", "null"]}, "language": {"type": ["string", "null"]}, "last_transcription_at": {"type": ["string", "null"]}, "last_transcription_duration_ms": {"type": ["integer", "null"]}, "last_error": {"type": ["string", "null"]}}},
    "Capabilities": {"type": "object", "required": ["commands", "observable_states"], "properties": {"commands": {"type": "object", "required": ["set_robot_state", "set_expression", "set_visual_source", "set_overlay", "clear_overlay"], "properties": {"set_robot_state": {"$ref": "#/components/schemas/SetRobotStateCapability"}, "set_expression": {"$ref": "#/components/schemas/SetExpressionCapability"}, "set_visual_source": {"$ref": "#/components/schemas/SetVisualSourceCapability"}, "set_overlay": {"$ref": "#/components/schemas/SetOverlayCapability"}, "clear_overlay": {"$ref": "#/components/schemas/ClearOverlayCapability"}}}, "observable_states": {"type": "object", "required": ["robot_state", "motion_state", "environmental_state", "environmental_overlays"], "properties": {"robot_state": {"type": "array", "items": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping", "error"]}}, "motion_state": {"type": "array", "items": {"type": "string", "enum": ["still", "moving", "tilt_left", "tilt_right", "tilt_forward", "tilt_back", "shake", "impact"]}}, "environmental_state": {"type": "array", "items": {"type": "string", "enum": ["normal", "cold", "warm", "air_quality_warning", "air_quality_bad"]}}, "environmental_overlays": {"type": "object", "properties": {"temperature": {"type": "array", "items": {"type": "string", "enum": ["none", "cold", "warm"]}}, "air_quality": {"type": "array", "items": {"type": "string", "enum": ["none", "warning", "bad"]}}}}}}}},
    "SetRobotStateCapability": {"type": "object", "required": ["method", "endpoint", "field", "allowed_values", "transitions"], "properties": {"method": {"const": "POST"}, "endpoint": {"const": "/api/v1/state"}, "field": {"const": "state"}, "allowed_values": {"type": "array", "items": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping"]}}, "transitions": {"type": "object", "additionalProperties": {"type": "array", "items": {"type": "string", "enum": ["idle", "listening", "thinking", "speaking", "sleeping"]}}}}},
    "SetExpressionCapability": {"type": "object", "required": ["method", "endpoint", "field", "allowed_values"], "properties": {"method": {"const": "POST"}, "endpoint": {"const": "/api/v1/expression"}, "field": {"const": "expression"}, "allowed_values": {"type": "array", "items": {"type": "string", "enum": ["neutral", "happy", "curious", "surprised", "sad", "angry", "focused", "tired", "confused", "scared", "skeptical"]}}}},
    "SetVisualSourceCapability": {"type": "object", "required": ["method", "endpoint", "field", "allowed_values"], "properties": {"method": {"const": "POST"}, "endpoint": {"const": "/api/v1/visual-source"}, "field": {"const": "source"}, "allowed_values": {"type": "array", "items": {"type": "string", "enum": ["manual", "environment", "state"]}}}},
    "SetOverlayCapability": {"type": "object", "required": ["method", "endpoint", "fields"], "properties": {"method": {"const": "POST"}, "endpoint": {"const": "/api/v1/overlay"}, "fields": {"type": "object", "properties": {"temperature": {"type": "object", "properties": {"allowed_values": {"type": "array", "items": {"enum": ["none", "cold", "warm"]}}}}, "air_quality": {"type": "object", "properties": {"allowed_values": {"type": "array", "items": {"enum": ["none", "warning", "bad"]}}}}, "duration_ms": {"type": "object", "properties": {"type": {"const": "integer"}, "optional": {"const": true}}}}}}},
    "ClearOverlayCapability": {"type": "object", "required": ["method", "endpoint"], "properties": {"method": {"const": "DELETE"}, "endpoint": {"const": "/api/v1/overlay"}}},
    "OverlayIntent": {"type": "object", "required": ["temperature", "air_quality"], "properties": {"temperature": {"type": "string", "enum": ["none", "cold", "warm"]}, "air_quality": {"type": "string", "enum": ["none", "warning", "bad"]}}},
    "OverlayOverride": {"type": "object", "required": ["active", "temperature", "air_quality", "expires_at"], "properties": {"active": {"type": "boolean"}, "temperature": {"type": ["string", "null"], "enum": ["none", "cold", "warm", null]}, "air_quality": {"type": ["string", "null"], "enum": ["none", "warning", "bad", null]}, "expires_at": {"type": ["string", "null"], "format": "date-time"}}},
    "OverlayState": {"type": "object", "required": ["environmental", "override", "resolved"], "properties": {"environmental": {"$ref": "#/components/schemas/OverlayIntent"}, "override": {"$ref": "#/components/schemas/OverlayOverride"}, "resolved": {"$ref": "#/components/schemas/OverlayIntent"}}},
    "OverlayOverrideRequest": {"type": "object", "anyOf": [{"required": ["temperature"]}, {"required": ["air_quality"]}], "properties": {"temperature": {"type": "string", "enum": ["none", "cold", "warm"]}, "air_quality": {"type": "string", "enum": ["none", "warning", "bad"]}, "duration_ms": {"type": "integer", "minimum": 1}}, "additionalProperties": false},
    "PresenceState": {"type": "object", "required": ["state", "people_count", "primary_candidate_id", "visible_since", "last_seen", "confidence"], "properties": {"state": {"type": "string", "enum": ["no_one", "person_present", "person_engaged"]}, "people_count": {"type": "integer", "minimum": 0}, "primary_candidate_id": {"type": ["string", "null"]}, "visible_since": {"type": ["number", "null"]}, "last_seen": {"type": ["number", "null"]}, "confidence": {"type": ["number", "null"], "minimum": 0, "maximum": 1}}},
    "AttentionTarget": {"type": "object", "required": ["id", "x", "y", "confidence"], "properties": {"id": {"type": ["string", "null"]}, "x": {"type": ["number", "null"], "minimum": -1, "maximum": 1}, "y": {"type": ["number", "null"], "minimum": -1, "maximum": 1}, "confidence": {"type": ["number", "null"], "minimum": 0, "maximum": 1}}},
    "AttentionState": {"type": "object", "required": ["state", "target"], "properties": {"state": {"type": "string", "enum": ["idle", "acquiring", "tracking", "lost"]}, "target": {"anyOf": [{"$ref": "#/components/schemas/AttentionTarget"}, {"type": "null"}]}, "acquired_at": {"type": ["number", "null"]}, "last_seen": {"type": ["number", "null"]}}},
    "ObservedExpression": {"type": "object", "required": ["available", "label", "confidence", "provider", "model", "observed_at", "unavailable_reason"], "properties": {"available": {"type": "boolean"}, "label": {"type": ["string", "null"]}, "confidence": {"type": ["number", "null"], "minimum": 0, "maximum": 1}, "provider": {"type": ["string", "null"]}, "model": {"type": ["string", "null"]}, "observed_at": {"type": ["number", "null"]}, "unavailable_reason": {"type": ["string", "null"], "description": "Classifier/read-model availability reason, never a presence decision."}}},
    "ExpressionReaction": {"type": "object", "required": ["active", "reaction", "observed_label", "remaining_ms"], "properties": {"active": {"type": "boolean"}, "reaction": {"type": ["string", "null"]}, "observed_label": {"type": ["string", "null"]}, "remaining_ms": {"type": "integer", "minimum": 0}}},
    "RobotStatus": {"type": "object", "required": ["robot", "visual", "environment", "motion", "health", "presence", "attention", "observed_expression", "expression_reaction", "voice"], "properties": {"robot": {"$ref": "#/components/schemas/RobotState"}, "visual": {"$ref": "#/components/schemas/VisualState"}, "environment": {"$ref": "#/components/schemas/EnvironmentStatus"}, "motion": {"$ref": "#/components/schemas/MotionStatus"}, "health": {"$ref": "#/components/schemas/HealthStatus"}, "presence": {"$ref": "#/components/schemas/PresenceState"}, "attention": {"$ref": "#/components/schemas/AttentionState"}, "observed_expression": {"$ref": "#/components/schemas/ObservedExpression"}, "expression_reaction": {"$ref": "#/components/schemas/ExpressionReaction"}, "voice": {"$ref": "#/components/schemas/VoiceStatus"}}},
    "Config": {"type": "object", "description": "Full canonical non-secret RuntimeConfig document.", "additionalProperties": true},
    "ConfigPatch": {"type": "object", "description": "Partial canonical configuration document. Unknown fields are rejected.", "additionalProperties": true},
    "ConfigStatus": {"type": "object", "properties": {"saved": {"$ref": "#/components/schemas/Config"}, "active": {"$ref": "#/components/schemas/Config"}, "pending": {"type": "array", "items": {"type": "string"}}}},
    "ConfigUpdate": {"type": "object", "properties": {"saved": {"$ref": "#/components/schemas/Config"}, "applied": {"type": "array", "items": {"type": "string"}}, "pending": {"type": "array", "items": {"type": "string"}}}},
    "McpSettings": {"type": "object", "required": ["enabled", "port", "status", "bound_port", "endpoint", "error"], "properties": {"enabled": {"type": "boolean"}, "port": {"type": "integer", "minimum": 1, "maximum": 65535}, "status": {"type": "string", "enum": ["disabled", "starting", "running", "stopping", "error"]}, "bound_port": {"type": ["integer", "null"], "minimum": 1, "maximum": 65535}, "endpoint": {"type": ["string", "null"], "format": "uri"}, "error": {"type": ["string", "null"]}}},
    "McpSettingsPatch": {"type": "object", "required": ["enabled", "port"], "additionalProperties": false, "properties": {"enabled": {"type": "boolean"}, "port": {"type": "integer", "minimum": 1, "maximum": 65535}}},
    "BackgroundAsset": {"type": "object", "required": ["name", "format"], "properties": {"name": {"type": "string"}, "format": {"type": "string", "enum": ["png", "jpg", "jpeg"]}}},
    "ApiError": {"type": "object", "required": ["error"], "properties": {"error": {"type": "object", "required": ["code", "message", "details"], "properties": {"code": {"type": "string"}, "message": {"type": "string"}, "details": {"type": "object"}}}}}
  }, "securitySchemes": {"phosAdminSession": {"type": "apiKey", "in": "cookie", "name": "phos_admin", "description": "Existing PHOS Web Admin HttpOnly session cookie. Log in through /login first; Swagger UI runs at the same origin and reuses that browser session."}}, "responses": {
    "InvalidVisualSource": {"description": "Unsupported visual source", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}, "example": {"error": {"code": "invalid_visual_source", "message": "Unsupported visual source.", "details": {"source": "GPIO18"}}}}}},
    "InvalidSignal": {"description": "Unsupported semantic signal", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}},
    "InvalidMcpSettings": {"description": "MCP settings must contain only enabled and port, with a valid TCP port", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}, "example": {"error": {"code": "invalid_mcp_settings", "message": "MCP port must be an integer between 1 and 65535.", "details": {}}}}}},
    "McpPortUnavailable": {"description": "MCP could not bind or rebind the requested port; the previous listener is retained when available", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}, "example": {"error": {"code": "port_in_use", "message": "MCP could not start on port 8100. MCP remains available on port 8001.", "details": {}}}}}},
    "InvalidOverlay": {"description": "Rejected overlay override", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}},
    "Unauthorized": {"description": "Authentication required", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}, "example": {"error": {"code": "unauthorized", "message": "Authentication required.", "details": {}}}}}}, "Forbidden": {"description": "Authenticated but not authorized", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}}, "InvalidExpression": {"description": "Unsupported expression", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}}, "InvalidState": {"description": "Unsupported state", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}}, "InvalidConfiguration": {"description": "Rejected configuration", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}}, "Unavailable": {"description": "Runtime or service unavailable", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}}, "InternalError": {"description": "Internal runtime error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiError"}}}}
  }}
}
