{
  "openapi": "3.1.0",
  "info": {
    "title": "DARKOZA Physical Intelligence API",
    "version": "0.9.0",
    "description": "Account-scoped planning-only robotics API with deterministic R0 and three-agent fleet simulation, plus atomically validated multi-robot mission plans. No physical actuation or task dispatch."
  },
  "servers": [
    {
      "url": "/robotics-api"
    }
  ],
  "security": [
    {
      "darkozaAccountSession": []
    }
  ],
  "components": {
    "securitySchemes": {
      "darkozaAccountSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "access_token",
        "description": "Existing Darkoza account session. The server also requires the matching csrf_token cookie and validates the session against the account service. Host-prefixed cookie names are also accepted. Do not copy tokens into third-party clients."
      }
    },
    "schemas": {
      "Robot": {
        "type": "object",
        "required": [
          "robot_id",
          "vendor",
          "model",
          "embodiment",
          "capabilities"
        ],
        "properties": {
          "robot_id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{1,63}$"
          },
          "vendor": {
            "type": "string",
            "enum": [
              "abb",
              "agility",
              "anybotics",
              "boston_dynamics",
              "clearpath",
              "custom",
              "darkoza",
              "dji",
              "dobot",
              "figure",
              "franka",
              "generic",
              "kuka",
              "simulation",
              "tesla",
              "unitree",
              "universal_robots"
            ]
          },
          "model": {
            "type": "string",
            "maxLength": 120
          },
          "embodiment": {
            "type": "string",
            "enum": [
              "aerial",
              "fixed_manipulator",
              "humanoid",
              "industrial_arm",
              "industrial_mobile",
              "mobile_base",
              "mobile_manipulator",
              "other",
              "quadruped",
              "service_robot",
              "simulation",
              "tracked_vehicle",
              "underwater"
            ]
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "dexterity",
                "human_detection",
                "interaction",
                "locomotion",
                "manipulation",
                "mapping",
                "navigation",
                "object_detection",
                "perception",
                "simulation",
                "speech",
                "telemetry"
              ]
            },
            "maxItems": 12,
            "minItems": 1,
            "uniqueItems": true
          },
          "metadata": {
            "type": "object"
          },
          "connection_state": {
            "type": "string",
            "enum": [
              "disconnected",
              "simulated"
            ]
          }
        }
      },
      "TaskPlan": {
        "type": "object",
        "required": [
          "robot_id",
          "goal"
        ],
        "properties": {
          "robot_id": {
            "type": "string"
          },
          "goal": {
            "type": "string",
            "maxLength": 1000
          },
          "required_capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 12
          },
          "approval_required": {
            "type": "boolean",
            "enum": [
              true
            ]
          }
        }
      },
      "SimulationRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "robot_id",
          "scenario"
        ],
        "properties": {
          "robot_id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{1,63}$"
          },
          "scenario": {
            "type": "string",
            "enum": [
              "nominal_route",
              "sensor_loss",
              "heartbeat_loss",
              "obstacle_intrusion",
              "emergency_stop",
              "stale_command",
              "fleet_cooperative_delivery",
              "fleet_crossing_conflict",
              "fleet_member_dropout"
            ]
          }
        }
      },
      "MissionStep": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "step_id",
          "robot_id",
          "goal"
        ],
        "properties": {
          "step_id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_-]{1,39}$"
          },
          "robot_id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{1,63}$"
          },
          "goal": {
            "type": "string",
            "maxLength": 1000
          },
          "required_capabilities": {
            "type": "array",
            "maxItems": 12,
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "depends_on": {
            "type": "array",
            "maxItems": 11,
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          }
        }
      },
      "MissionPlan": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title",
          "steps"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "maxLength": 1000
          },
          "steps": {
            "type": "array",
            "minItems": 2,
            "maxItems": 12,
            "items": {
              "$ref": "#/components/schemas/MissionStep"
            }
          }
        }
      },
      "MissionPlanResult": {
        "type": "object",
        "required": [
          "mission_id",
          "title",
          "steps",
          "status",
          "approval_required",
          "execution_enabled",
          "physical_actuation",
          "task_dispatch"
        ],
        "properties": {
          "mission_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "planned"
            ]
          },
          "approval_required": {
            "type": "boolean",
            "const": true
          },
          "execution_enabled": {
            "type": "boolean",
            "const": false
          },
          "physical_actuation": {
            "type": "boolean",
            "const": false
          },
          "task_dispatch": {
            "type": "boolean",
            "const": false
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "security": [],
        "summary": "Non-sensitive service health",
        "responses": {
          "200": {
            "description": "Planning-only service health"
          }
        }
      }
    },
    "/v1/capabilities": {
      "get": {
        "security": [],
        "summary": "Supported capability and vendor catalog",
        "responses": {
          "200": {
            "description": "Capability catalog"
          }
        }
      }
    },
    "/v1/robots": {
      "get": {
        "summary": "List robots belonging to the signed-in account",
        "responses": {
          "200": {
            "description": "Account-scoped robot list"
          },
          "401": {
            "description": "Authentication required"
          },
          "503": {
            "description": "Account verification unavailable"
          }
        }
      },
      "post": {
        "summary": "Register a disconnected or simulated robot profile",
        "description": "Requires Origin https://darkoza.com and a valid Darkoza access + CSRF cookie pair. Physical connections are rejected.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Robot"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Robot profile registered"
          },
          "400": {
            "description": "Invalid robot profile"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Origin rejected"
          },
          "409": {
            "description": "Robot ID already exists in this account"
          }
        }
      }
    },
    "/v1/tasks": {
      "get": {
        "summary": "List task plans belonging to the signed-in account",
        "responses": {
          "200": {
            "description": "Account-scoped task plans"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "summary": "Create a task plan without executing it",
        "description": "Human approval is mandatory. The task is persisted as planned and cannot be dispatched by API v0.2.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TaskPlan"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Task plan created"
          },
          "400": {
            "description": "Invalid plan"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Robot not found in this account"
          }
        }
      }
    },
    "/v1/execute": {
      "post": {
        "security": [],
        "summary": "Execution is disabled",
        "responses": {
          "403": {
            "description": "Physical execution disabled in this release"
          }
        },
        "description": "Physical execution and dispatch remain disabled. Returns HTTP 403."
      }
    },
    "/v1/bootstrap": {
      "post": {
        "summary": "Create a reference R0 profile for an empty account",
        "description": "Requires a valid Darkoza account session, matching CSRF cookie and Origin https://darkoza.com. Idempotent. Creates only a disconnected reference digital-twin profile, and only if the account has no robot profiles. Does not connect hardware or run a simulator.",
        "responses": {
          "201": {
            "description": "Reference R0 profile created"
          },
          "200": {
            "description": "Account already has robot profiles; no change"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Origin rejected"
          },
          "503": {
            "description": "Account verification unavailable"
          }
        }
      }
    },
    "/v1/simulation/status": {
      "get": {
        "summary": "Read the R0 simulation runtime status for the signed-in account",
        "description": "Read-only runtime status for the signed-in account. The separately available request-scoped Python kinematic twin is not ROS 2/Gazebo physics. Runtime telemetry is fail-closed when stale. Never dispatches commands or enables physical actuation.",
        "responses": {
          "200": {
            "description": "Process state and read-only ROS safety state; hardware_connected and physical_actuation are always false"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "No reference R0 simulation profile exists for this account"
          },
          "503": {
            "description": "Account verification unavailable"
          }
        }
      }
    },
    "/v1/simulations": {
      "get": {
        "summary": "List the signed-in account's latest 25 simulation runs",
        "description": "Requires the authoritative account session. Results are tenant-scoped and do not include hardware telemetry.",
        "responses": {
          "200": {
            "description": "Account-scoped simulation run history"
          },
          "401": {
            "description": "Authentication required"
          },
          "503": {
            "description": "Account verification unavailable"
          }
        }
      },
      "post": {
        "summary": "Run a bounded deterministic R0 software-kinematic scenario",
        "description": "Requires the authoritative account session, same-origin Origin and CSRF. Accepts only a registered vendor=simulation, embodiment=simulation profile belonging to the current account. The six R0 scenarios use the pure-Python kinematic twin; three fleet scenarios use a deterministic discrete-grid scheduler for three abstract agents. No arbitrary speed, network address, ROS topic, actuator or hardware command is accepted. Fleet grid coordinates are abstract cells, not metres. No ROS 2/Gazebo physics, distributed device communication, hardware-in-loop or certification.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SimulationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Simulation result and safety evidence persisted"
          },
          "400": {
            "description": "Invalid scenario or request fields"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Wrong origin or non-simulation robot profile"
          },
          "404": {
            "description": "Robot profile not registered in this account"
          },
          "429": {
            "description": "Per-account retained simulation limit reached"
          }
        }
      }
    },
    "/v1/mission-plans": {
      "get": {
        "summary": "List the signed-in account's latest 25 multi-robot mission plans",
        "responses": {
          "200": {
            "description": "Account-scoped mission plans"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "summary": "Atomically validate and store a 2-12 step multi-robot mission plan without dispatch",
        "security": [
          {
            "accountSession": []
          },
          {
            "csrfOrigin": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MissionPlan"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Planned mission and its approval-required task rows",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MissionPlanResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid step, dependency or robot capability"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Origin or robot profile blocked"
          },
          "404": {
            "description": "Robot not owned by this account"
          },
          "429": {
            "description": "Mission plan retention quota reached"
          }
        }
      }
    },
    "/v1/mission-plans/{mission_id}/assurance": {
      "get": {
        "summary": "Run a read-only structural assurance check for an account-owned multi-robot mission plan",
        "operationId": "getMissionPlanAssurance",
        "parameters": [
          {
            "name": "mission_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Structural assurance report; physical execution remains blocked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "schema": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "PASS",
                        "FAIL"
                      ]
                    },
                    "checks": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "plan_sha256": {
                      "type": "string"
                    },
                    "execution_gate": {
                      "type": "string",
                      "const": "BLOCKED"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Account authentication required"
          },
          "404": {
            "description": "Mission plan not found for this account"
          }
        }
      }
    }
  }
}
