{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "conversation.get-history result",
  "type": "object",
  "required": ["history"],
  "properties": {
    "history": {
      "type": "object",
      "required": ["messages", "conversationId"],
      "properties": {
        "conversationId": { "type": "string", "minLength": 1 },
        "messages": {
          "type": "array",
          "items": { "$ref": "#/definitions/conversationMessage" }
        },
        "hasMore": { "type": ["boolean", "null"] },
        "nextCursor": { "type": ["string", "null"] },
        "messageCount": { "type": ["integer", "null"], "minimum": 0 }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true,
  "definitions": {
    "conversationMessage": {
      "type": "object",
      "required": ["id", "content", "role", "sequence", "createdAt"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "conversationId": { "type": "string", "minLength": 1 },
        "content": { "type": "string" },
        "role": { "type": "string", "enum": ["user", "assistant", "system", "tool", "function"] },
        "userId": { "type": ["string", "null"] },
        "sequence": { "type": "integer", "minimum": 0 },
        "createdAt": { "type": "string", "format": "date-time" },
        "metadata": { "$ref": "#/definitions/messageMetadata" }
      },
      "additionalProperties": true
    },
    "messageMetadata": {
      "type": "object",
      "properties": {
        "secondOpinion": {
          "type": "object",
          "required": ["primary"],
          "properties": {
            "primary": { "$ref": "#/definitions/modelOpinion" },
            "secondaryOpinions": {
              "type": "array",
              "items": { "$ref": "#/definitions/modelOpinion" }
            },
            "synthesis": { "$ref": "#/definitions/synthesis" }
          },
          "additionalProperties": true
        },
        "persistenceStatus": { "$ref": "#/definitions/persistenceStatus" }
      },
      "additionalProperties": true
    },
    "modelOpinion": {
      "type": "object",
      "required": ["model", "response"],
      "properties": {
        "model": { "type": "string", "minLength": 1 },
        "response": { "type": "string" },
        "tokensUsed": { "type": "integer", "minimum": 0 },
        "latencyMs": { "type": "number", "minimum": 0 },
        "citations": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["title", "url"],
            "properties": {
              "title": { "type": "string" },
              "url": { "type": "string", "format": "uri" },
              "snippet": { "type": "string" }
            },
            "additionalProperties": true
          }
        }
      },
      "additionalProperties": true
    },
    "synthesis": {
      "type": "object",
      "required": ["model", "response"],
      "properties": {
        "model": { "type": "string", "minLength": 1 },
        "response": { "type": "string", "minLength": 1 },
        "modelId": { "type": "string" },
        "modelDisplayName": { "type": "string" },
        "tokensUsed": { "type": "integer", "minimum": 0 },
        "latencyMs": { "type": "number", "minimum": 0 },
        "cost": { "type": "number" },
        "sources": { "type": "array", "items": {} },
        "error": { "type": "boolean" }
      },
      "additionalProperties": true
    },
    "persistenceStatus": {
      "type": "object",
      "properties": {
        "userMessageSaved": { "type": "boolean" },
        "assistantMessageSaved": { "type": "boolean" },
        "userMessageId": { "type": ["string", "null"] },
        "assistantMessageId": { "type": ["string", "null"] },
        "error": { "type": ["string", "null"] }
      },
      "additionalProperties": true
    }
  }
}
