Skip to main content
The protocol contract is the language-neutral wire contract for Hiro League messages. It defines the JSON shapes that move between Hiro Server, channel plugins, Hiro Gate, and device apps. Python, Dart, and any future client implementation must parse and emit the same contract.

Contract surfaces

SurfaceOwnerPurpose
UnifiedMessageHiro protocolCanonical message, event, request, and response envelope.
Gateway relay envelopeHiro Gate protocolRoutes payloads between connected devices and the devices channel plugin.
Auth framesHiro Gate protocolAuthenticates an already-paired device connection.
Pairing framesHiro Gate protocolPairs a new device with a workspace.
Request and response bodyHiro protocolCarries device RPC calls and server replies inside JSON content items.
Metadata keysHiro protocolCarries routing extras such as device identity and channel context.
The machine-readable contract lives under the repo-level protocol/ folder. The explanatory protocol references live under docs/protocol/.

UnifiedMessage

UnifiedMessage is the canonical cross-channel message envelope.
FieldTypeRequiredMeaning
versionstringyesProtocol version. Current value is "0.1".
message_typestringyesOne of message, event, request, response, or reserved stream.
request_idstring or nullnoCorrelation ID for request/response messages.
routingobjectyesSender, recipient, channel, direction, timestamp, and metadata.
contentarrayyesOrdered content items. Empty for event messages.
eventobject or nullnoEvent payload. Present only for event messages.

Message type rules

message_typeRequired shape
messagecontent has at least one item. event is absent or null.
eventevent is present. content is empty.
requestrequest_id is present. content contains a JSON request body.
responserequest_id matches the request. content contains a JSON response body.
streamReserved for future streaming chunks.

Routing

routing identifies where the message came from, where it should go, and how it should be grouped.
FieldMeaning
idMessage identifier.
channelChannel name, such as devices or telegram.
directionDirection from the Hiro Server perspective.
sender_idOriginating device, user, service, or server actor.
recipient_idTarget device, user, service, or null for broadcast or server-directed messages.
timestampMessage timestamp.
metadataProtocol-defined routing extras.
direction is normalized before a message enters Hiro Server:
ValueMeaning
inboundArriving into Hiro Server from a device, plugin, or third-party app.
outboundLeaving Hiro Server toward a device, plugin, or third-party app.
Device-originated messages are normalized by the devices channel before they enter Communication Manager. Inside Hiro Server, consumers can treat direction as server-relative.

Content items

Each content item represents one authored payload.
FieldMeaning
content_typePayload kind, such as text, audio, image, file, or json.
bodyPayload value. Text content is plain text. Binary media is represented by a URL, path, or encoded value according to the content type.
metadataContent-specific extras such as filename, MIME type, duration, transcript, or adapter error.
Content order is meaningful. Consumers preserve the order emitted by the sender.

Events

Event messages use message_type: "event" and carry an event payload.
FieldMeaning
typeDotted event name.
ref_idOptional ID of the message or entity the event refers to.
dataEvent-specific payload.
Active message events:
EventPurpose
message.receivedAcknowledges that an inbound message was accepted.
message.transcribedAdds transcript data for an audio message.
message.voicedAdds synthesized voice data for a text reply.
resource.changedTells connected devices to refresh a workspace resource.

Requests and responses

Requests and responses are UnifiedMessage objects with content_type: "json". Request body:
{
  "method": "channels.list",
  "params": {}
}
Response body:
{
  "status": "ok",
  "data": {}
}
Error response body:
{
  "status": "error",
  "error": {
    "code": "method_not_found",
    "message": "Unknown method"
  }
}
request_id is generated by the caller and echoed by the responder.

Gateway envelopes

Hiro Gate wraps forwarded device payloads in a relay envelope.
{
  "sender_device_id": "device-id",
  "target_device_id": "optional-target-device-id",
  "payload": {}
}
sender_device_id identifies the connected device that produced the payload. target_device_id is optional and targets a specific connected device when present. payload contains the protocol payload being relayed.

Auth and pairing frames

Gateway auth and pairing frames are type-discriminated JSON objects.
Frame typeDirectionPurpose
auth_challengeGateway to deviceStarts device authentication.
auth_responseDevice to gatewayProves the device has valid pairing credentials.
auth_okGateway to deviceConfirms the authenticated connection.
pairing_requestDevice to gatewayStarts pairing for a new device.
pairing_pendingGateway to deviceConfirms that pairing is waiting for server approval.
pairing_responseGateway to deviceReturns approved pairing credentials or a rejection.

Metadata keys

Protocol metadata keys are part of the contract when behavior depends on them.
KeyLocationMeaning
channel_idrouting.metadataConversation or channel grouping key.
device_namerouting.metadataHuman-readable device name.
sender_device_idrouting.metadataDevice ID attached by the gateway or devices channel.
friendly_namerouting.metadataDisplay name for a device or participant.
request_voice_replyrouting.metadataRequests a voice reply when the server can produce one.

Compatibility contract

The protocol is valid when all supported implementations agree on the same fixtures:
Fixture classRequirement
Valid fixturesPython and Dart parse them successfully.
Invalid fixturesPython and Dart reject them consistently.
Outbound fixturesSerialization from each implementation matches the documented wire shape.
Schema files and fixtures are the reviewable source of truth. Runtime models in Python and Dart implement that contract.

See also

UnifiedMessage reference

Detailed field reference, validation rules, constants, and wire examples.

Communication Manager

How Hiro Server validates, routes, adapts, and dispatches UnifiedMessages.

Channel Manager

How channel plugins send and receive UnifiedMessages through Hiro Server.

Gateway runtime

How Hiro Gate handles device connections.

Channel Plugins

The plugin-side JSON-RPC contract around UnifiedMessage payloads.