{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/aimeat-io/json-schema/aimeat-io-direct-message-wire-schema.json",
  "title": "DirectMessageWire",
  "description": "The message payload carried in a federation delivery (subset of the record).",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/aimeat-io-federation-api-openapi.yml#/components/schemas/DirectMessageWire",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "conversationId": {
      "type": "string"
    },
    "senderGhii": {
      "type": "string"
    },
    "recipientGhii": {
      "type": "string"
    },
    "body": {
      "type": "string"
    },
    "attachments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DirectMessageAttachment"
      }
    },
    "interactive": {
      "$ref": "#/$defs/InteractivePayload"
    },
    "replyToId": {
      "type": "string",
      "format": "uuid"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "$defs": {
    "DirectMessageAttachment": {
      "type": "object",
      "description": "A media object referenced by a direct message (inline via cid:{id} or appended).",
      "properties": {
        "id": {
          "type": "string"
        },
        "inline": {
          "type": "boolean"
        },
        "storageKey": {
          "type": "string"
        },
        "ownerGhii": {
          "type": "string"
        },
        "originNodeId": {
          "type": "string"
        },
        "mode": {
          "type": "string",
          "enum": [
            "reference",
            "duplicate"
          ],
          "description": "duplicate = recipient's local copy (the norm); reference = transient (pending/awaiting quota)."
        },
        "localKey": {
          "type": "string"
        },
        "version": {
          "type": "string",
          "description": "The sent file's createdAt at the send, stamped by the sending node. A copy or a storage grant serves this version only. Absent on attachments stored before 2026-10-22."
        },
        "mime": {
          "type": "string"
        },
        "size": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "image",
            "audio",
            "video",
            "file"
          ]
        },
        "durationSeconds": {
          "type": "number",
          "description": "Playing length of audio/video, measured when it was recorded. Lets a thread show \"0:14\" before any bytes are fetched.\n"
        },
        "transcript": {
          "type": "object",
          "description": "Text of a spoken attachment. `by: sender` arrived WITH the message and is identical in both mailbox copies (so the recipient reads it without paying). `by: recipient` was produced locally with the reader's own key and exists ONLY in their copy — updateMessageAttachments is owner-keyed, so there is no path back to the sender.\n",
          "properties": {
            "text": {
              "type": "string",
              "maxLength": 20000
            },
            "by": {
              "type": "string",
              "enum": [
                "sender",
                "recipient"
              ],
              "description": "Server-set on send; a client claim of `recipient` is overwritten with `sender`."
            },
            "model": {
              "type": "string"
            },
            "lang": {
              "type": "string"
            },
            "seconds": {
              "type": "number"
            },
            "at": {
              "type": "string",
              "format": "date-time"
            }
          }
        }
      }
    },
    "InteractivePayload": {
      "type": "object",
      "description": "Structured AskUserQuestion payload on a direct message. role=questions → an agent asks the human a set of option-based questions (rendered as an inline form in the inbox: radio for single-select, checkboxes for multiSelect, plus an always-available \"Other\" freeform). role=answers → the human's reply, with machine-readable picks keyed by question id (the message body still carries a human-readable summary so the thread reads naturally on any peer).",
      "required": [
        "role"
      ],
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "questions",
            "answers"
          ]
        },
        "v": {
          "type": "integer",
          "default": 1
        },
        "questions": {
          "type": "array",
          "description": "Present when role=questions.",
          "items": {
            "type": "object",
            "required": [
              "id",
              "header",
              "prompt",
              "options"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "header": {
                "type": "string",
                "description": "Short chip label (≈ ≤12 chars)."
              },
              "prompt": {
                "type": "string"
              },
              "multiSelect": {
                "type": "boolean",
                "default": false
              },
              "allowOther": {
                "type": "boolean",
                "default": true
              },
              "required": {
                "type": "boolean",
                "default": false
              },
              "options": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "label"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "submitLabel": {
          "type": "string",
          "description": "Optional submit-button label (role=questions)."
        },
        "answersFor": {
          "type": "string",
          "description": "The question message id this answers (role=answers)."
        },
        "answers": {
          "type": "object",
          "description": "Map of question id → { selected:[optionId], other } (role=answers).",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "selected": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "other": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      }
    }
  }
}