{
  "asyncapi": "3.1.0",
  "id": "urn:waraps.api-declarations",
  "info": {
    "title": "WARA-PS Declarations MQTT API",
    "version": "1.0.4",
    "description": "### Overview\nDeclarative channels for WARA-PS agent communication. These messages announce an agent's existence and capabilities to the system. Start here for any new integration -- every other spec assumes the agent is already declaring itself on these channels.\n\n### Quick Start\nOn startup, every agent begins publishing **Heartbeat** immediately and keeps doing so on an interval for its whole lifetime -- this is how the rest of the system knows it exists. Which other declarations are also mandatory depends on the agent's level:\n- **Level 1 (Sensor agents):** an agent that only sends sensor/status data. In addition to Heartbeat, it also publishes **Sensor Info**, once and whenever the set of provided sensors changes.\n- **Level 2 (Task agents):** normally a Level 1 sensor agent with the added capability to receive commands. In addition to Heartbeat and Sensor Info, it also publishes **Direct Execution Info**, once and whenever available tasks or the currently executing task changes.\n- **Level 3 (Mission agents):** normally a Level 2 task agent with the added capability to handle complex, completely specified tasks (e.g. via Behavior Trees or Task Specification Trees). Not covered by this API specification.\n- **Level 4 (Mission agents):** normally a Level 3 mission agent with the added capability to handle complex tasks that are not fully specified, filling in the remaining parameters itself. Not covered by this API specification.\n\nOnce these declarations are in place, telemetry (see the Sensors spec) and commands (see the Tasks spec) can flow normally.\n\n### Channels\n- **Heartbeat** — Mandatory for all agents. Periodic signal indicating the agent is alive, including identity, type, model, and capability levels.\n- **Sensor Info** — Mandatory for Level 1 agents (sensor agents). Declares which sensor data the agent provides.\n- **Direct Execution Info** — Mandatory for Level 2+ agents (task agents). Declares available tasks, supported signals, and currently executing tasks.",
    "contact": {
      "name": "waraps.org",
      "url": "https://portal.waraps.org/",
      "email": "info@waraps.org"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "defaultContentType": "application/json",
  "servers": {
    "localhost": {
      "host": "localhost:1883",
      "protocol": "mqtt",
      "protocolVersion": "3.1.1+",
      "description": "Development MQTT broker",
      "variables": {
        "port": {
          "enum": [
            "1882",
            "1883"
          ],
          "default": "1883",
          "description": "The port used for connecting to the locally hosted MQTT broker"
        }
      },
      "security": []
    },
    "production": {
      "host": "broker.waraps.org:8883",
      "protocol": "mqtt",
      "protocolVersion": "3.1.1+",
      "description": "Production MQTT broker",
      "variables": {
        "port": {
          "enum": [
            "8883"
          ],
          "default": "8883",
          "description": "The port used for connecting to the production MQTT broker"
        }
      },
      "security": [
        {
          "$ref": "#/components/securitySchemes/tls"
        }
      ]
    }
  },
  "channels": {
    "heartbeatChannel": {
      "address": "{AgentBaseTopic}/heartbeat",
      "bindings": {
        "$ref": "#/components/channelBindings/DeclarationMqttSettings"
      },
      "messages": {
        "sendHeartbeatDeclaration.message": {
          "$ref": "#/components/messages/HeartbeatMessage"
        }
      },
      "description": "Sends heartbeat declaration. Mandatory for all agent types.",
      "parameters": {
        "AgentBaseTopic": {
          "$ref": "#/components/parameters/AgentBaseTopic"
        }
      }
    },
    "sensorInfoChannel": {
      "address": "{AgentBaseTopic}/sensor_info",
      "bindings": {
        "$ref": "#/components/channelBindings/DeclarationMqttSettings"
      },
      "messages": {
        "sendSensorInfoDeclaration.message": {
          "$ref": "#/components/messages/SensorInfoMessage"
        }
      },
      "description": "Sends sensor info declaration. Mandatory for agents with sensors.",
      "parameters": {
        "AgentBaseTopic": {
          "$ref": "#/components/parameters/AgentBaseTopic"
        }
      }
    },
    "directExecutionInfoChannel": {
      "address": "{AgentBaseTopic}/direct_execution_info",
      "bindings": {
        "$ref": "#/components/channelBindings/DeclarationMqttSettings"
      },
      "messages": {
        "sendDirectExecutionInfoDeclaration.message": {
          "$ref": "#/components/messages/DirectExecutionInfoMessage"
        }
      },
      "description": "Sends direct execution info declaration. Mandatory for agents that can receive and execute commands.",
      "parameters": {
        "AgentBaseTopic": {
          "$ref": "#/components/parameters/AgentBaseTopic"
        }
      }
    }
  },
  "operations": {
    "sendHeartbeatDeclaration": {
      "action": "send",
      "title": "Sends a heartbeat message",
      "channel": {
        "$ref": "#/channels/heartbeatChannel"
      },
      "summary": "Sends a heartbeat message",
      "messages": [
        {
          "$ref": "#/channels/heartbeatChannel/messages/sendHeartbeatDeclaration.message"
        }
      ]
    },
    "sendSensorInfoDeclaration": {
      "action": "send",
      "title": "Sends sensor information",
      "channel": {
        "$ref": "#/channels/sensorInfoChannel"
      },
      "summary": "Sends sensor information",
      "messages": [
        {
          "$ref": "#/channels/sensorInfoChannel/messages/sendSensorInfoDeclaration.message"
        }
      ]
    },
    "sendDirectExecutionInfoDeclaration": {
      "action": "send",
      "title": "Sends direct execution information",
      "channel": {
        "$ref": "#/channels/directExecutionInfoChannel"
      },
      "summary": "Sends direct execution information",
      "messages": [
        {
          "$ref": "#/channels/directExecutionInfoChannel/messages/sendDirectExecutionInfoDeclaration.message"
        }
      ]
    }
  },
  "components": {
    "channelBindings": {
      "DeclarationMqttSettings": {
        "mqtt": {
          "qos": 0,
          "retain": false
        }
      }
    },
    "securitySchemes": {
      "tls": {
        "type": "X509",
        "x-securityScheme": "tls",
        "description": "TLS client certificate for secure connection"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "user",
        "description": "An API key is required for connecting to the MQTT broker"
      }
    },
    "parameters": {
      "AgentBaseTopic": {
        "description": "Full agent topic path: {organization}/{category}/{domain}/{real_sim}/{agent_name}. Field roles: Organization, Category, Domain, Real_Sim, Agent_name. See AgentBaseTopic schema for structure."
      }
    },
    "schemas": {
      "AgentBaseTopic": {
        "description": "Base topic string composed of organization, category, domain, real_sim, agent_name. Field roles are Organization, Category, Domain, Real_Sim, Agent_name. This schema (and its Organization/Category/Domain/RealSim/AgentName parts) is defined identically in every API document that builds topics from it, so each document is self-contained. The value itself only ever appears substituted into a channel address, never as a message payload field.",
        "type": "string",
        "example": "waraps/unit/surface/simulation/SimUSV1",
        "pattern": "^[^/]+\\/(unit|service|general)\\/(air|ground|surface|subsurface|space|virtual)\\/(real|simulation)\\/[^/]+$"
      },
      "AgentDescription": {
        "description": "The description of the agent.",
        "type": "string",
        "example": "surface vessel"
      },
      "AgentLevel": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/AgentLevelTypes"
        }
      },
      "AgentLevelTypes": {
        "description": "Declaration of agent properties, e.g. L1 = sensor, L2 = direct execution, etc.",
        "type": "string",
        "enum": [
          "sensor",
          "direct execution",
          "tst execution",
          "delegation"
        ],
        "example": "sensor, direct execution"
      },
      "AgentModel": {
        "description": "Identification of 3D model of the agent.",
        "type": "string",
        "example": "usv.mini_usv"
      },
      "AgentName": {
        "description": "The name/ID of the agent.",
        "type": "string",
        "example": "SimUSV1"
      },
      "AgentUUID": {
        "type": "string",
        "description": "Agent UUID (UUID v4) that is unique for each agent. Should be reused between sessions.",
        "format": "uuid",
        "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
      },
      "AvailableSensors": {
        "description": "Declaration of provided sensors.",
        "type": "array",
        "items": {
          "type": "string",
          "enum": [
            "position",
            "speed",
            "heading",
            "course",
            "battery_status",
            "energy_level",
            "waypoints",
            "control_system_version",
            "cargo",
            "armable",
            "mode",
            "state",
            "ip_address",
            "videoserver_url"
          ],
          "example": "position, speed, course, heading"
        }
      },
      "AvailableSignals": {
        "type": "string",
        "description": "Declaration of supported signals for provided tasks.",
        "enum": [
          "$abort",
          "$enough",
          "$pause",
          "$continue"
        ],
        "examples": [
          "$abort",
          "$enough",
          "$pause",
          "$continue"
        ]
      },
      "AvailableTasks": {
        "description": "Declaration of provided tasks with signals.",
        "type": "string",
        "enum": [
          "move-to",
          "move-path",
          "search-area",
          "look-at-position",
          "look-at-agent",
          "follow-lead",
          "collect",
          "release",
          "go-home",
          "observe-position",
          "set-speed",
          "reset-speed",
          "set-geofence",
          "reset-geofence",
          "add-no-go-zone",
          "reset-no-go-zones",
          "set-heading-thrust",
          "deliver"
        ],
        "example": "move-to"
      },
      "Category": {
        "type": "string",
        "description": "The category of the agent.",
        "enum": [
          "unit",
          "service",
          "general"
        ]
      },
      "Domain": {
        "type": "string",
        "description": "The domain of the agent.",
        "enum": [
          "air",
          "ground",
          "surface",
          "subsurface",
          "space",
          "virtual"
        ],
        "example": "surface"
      },
      "Organization": {
        "type": "string",
        "description": "The organization/owner of the agent. Open-ended and intentionally not enum-restricted: new organizations may join WARA-PS over time.",
        "examples": [
          "waraps",
          "saab",
          "aiics",
          "fmw",
          "liu"
        ]
      },
      "Rate": {
        "type": "number",
        "description": "Rate in frequency (Hz), e.g. 0.2 for declarations, 2.0 for position related sensors.",
        "example": 0.2,
        "format": "float"
      },
      "RealSim": {
        "type": "string",
        "description": "Indicates if agent is real or simulation.",
        "enum": [
          "real",
          "simulation"
        ]
      },
      "Stamp": {
        "type": "number",
        "description": "UTC timestamp in unix epoch format with millisecond precision.",
        "example": 1614080475.108,
        "format": "float"
      },
      "TaskUUID": {
        "type": "string",
        "description": "Task UUID (UUID v4) that is unique for each sent task. Used for connecting signals($abort, $pause, ...) to its task.",
        "format": "uuid",
        "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
      }
    },
    "messages": {
      "HeartbeatMessage": {
        "name": "heartbeat",
        "description": "Message to indicate the existence of an agent.",
        "contentType": "application/json",
        "payload": {
          "type": "object",
          "properties": {
            "name": {
              "$ref": "#/components/schemas/AgentName"
            },
            "agent-uuid": {
              "$ref": "#/components/schemas/AgentUUID"
            },
            "agent-type": {
              "$ref": "#/components/schemas/Domain"
            },
            "agent-description": {
              "$ref": "#/components/schemas/AgentDescription"
            },
            "agent-model": {
              "$ref": "#/components/schemas/AgentModel"
            },
            "levels": {
              "$ref": "#/components/schemas/AgentLevel"
            },
            "rate": {
              "$ref": "#/components/schemas/Rate"
            },
            "stamp": {
              "$ref": "#/components/schemas/Stamp"
            },
            "type": {
              "type": "string",
              "const": "HeartBeat",
              "example": "HeartBeat"
            }
          },
          "required": [
            "name",
            "agent-uuid",
            "agent-type",
            "levels",
            "rate",
            "stamp",
            "type"
          ]
        },
        "examples": [
          {
            "name": "SimUSV1 heartbeat",
            "summary": "Heartbeat from a simulated surface vessel",
            "payload": {
              "name": "SimUSV1",
              "agent-uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
              "agent-type": "surface",
              "agent-description": "surface vessel",
              "agent-model": "usv.mini_usv",
              "levels": [
                "sensor",
                "direct execution"
              ],
              "rate": 0.2,
              "stamp": 1614080475.108,
              "type": "HeartBeat"
            }
          }
        ]
      },
      "SensorInfoMessage": {
        "name": "sensor_info",
        "description": "Message containing information about which sensors an agent has.",
        "contentType": "application/json",
        "payload": {
          "type": "object",
          "properties": {
            "name": {
              "$ref": "#/components/schemas/AgentName"
            },
            "sensor-data-provided": {
              "$ref": "#/components/schemas/AvailableSensors"
            },
            "rate": {
              "$ref": "#/components/schemas/Rate"
            },
            "stamp": {
              "$ref": "#/components/schemas/Stamp"
            },
            "type": {
              "type": "string",
              "const": "SensorInfo",
              "example": "SensorInfo"
            }
          },
          "required": [
            "name",
            "sensor-data-provided",
            "rate",
            "stamp",
            "type"
          ]
        },
        "examples": [
          {
            "name": "SimUSV1 sensor info",
            "summary": "A moving surface vessel declaring its sensors",
            "payload": {
              "name": "SimUSV1",
              "sensor-data-provided": [
                "position",
                "speed",
                "heading",
                "energy_level"
              ],
              "rate": 0.2,
              "stamp": 1614080475.108,
              "type": "SensorInfo"
            }
          }
        ]
      },
      "DirectExecutionInfoMessage": {
        "name": "direct_execution_info",
        "description": "Message providing information on tasks an agent can execute.",
        "contentType": "application/json",
        "payload": {
          "type": "object",
          "properties": {
            "name": {
              "$ref": "#/components/schemas/AgentName"
            },
            "tasks-available": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "$ref": "#/components/schemas/AvailableTasks"
                  },
                  "signals": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/AvailableSignals"
                    },
                    "example": [
                      "$abort",
                      "$enough",
                      "$pause",
                      "$continue"
                    ]
                  }
                }
              }
            },
            "tasks-executing": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "task-name": {
                    "$ref": "#/components/schemas/AvailableTasks"
                  },
                  "task-uuid": {
                    "$ref": "#/components/schemas/TaskUUID"
                  }
                }
              }
            },
            "rate": {
              "$ref": "#/components/schemas/Rate"
            },
            "stamp": {
              "$ref": "#/components/schemas/Stamp"
            },
            "type": {
              "type": "string",
              "const": "DirectExecutionInfo",
              "example": "DirectExecutionInfo"
            }
          },
          "required": [
            "name",
            "tasks-available",
            "rate",
            "stamp",
            "type"
          ]
        },
        "examples": [
          {
            "name": "SimUSV1 direct execution info, idle",
            "summary": "A Level 2 agent declaring available tasks with no task currently executing",
            "payload": {
              "name": "SimUSV1",
              "tasks-available": [
                {
                  "name": "move-to",
                  "signals": [
                    "$abort",
                    "$pause",
                    "$continue"
                  ]
                },
                {
                  "name": "move-path",
                  "signals": [
                    "$abort",
                    "$pause",
                    "$continue"
                  ]
                }
              ],
              "tasks-executing": [],
              "rate": 0.2,
              "stamp": 1614080475.108,
              "type": "DirectExecutionInfo"
            }
          }
        ]
      }
    }
  }
}
