{
  "$id": "https://comitiva.dev/schema/HubRunFinishResult.json",
  "title": "HubRunFinishResult",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "message": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "conversationId": {
          "type": "string",
          "minLength": 1
        },
        "role": {
          "type": "string",
          "enum": [
            "user",
            "assistant",
            "tool"
          ]
        },
        "content": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "text"
                  },
                  "text": {
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "text"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "image"
                  },
                  "source": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "base64"
                          },
                          "mediaType": {
                            "type": "string"
                          },
                          "data": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "kind",
                          "mediaType",
                          "data"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "file"
                          },
                          "path": {
                            "type": "string"
                          },
                          "mediaType": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "kind",
                          "path"
                        ]
                      }
                    ]
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "source"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "document"
                  },
                  "name": {
                    "type": "string"
                  },
                  "mediaType": {
                    "type": "string"
                  },
                  "source": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "base64"
                          },
                          "mediaType": {
                            "type": "string"
                          },
                          "data": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "kind",
                          "mediaType",
                          "data"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "file"
                          },
                          "path": {
                            "type": "string"
                          },
                          "mediaType": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "kind",
                          "path"
                        ]
                      }
                    ]
                  }
                },
                "required": [
                  "type",
                  "name",
                  "mediaType",
                  "source"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "tool_use"
                  },
                  "id": {
                    "type": "string"
                  },
                  "toolServerId": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "input": {},
                  "signature": {
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "id",
                  "toolServerId",
                  "name",
                  "input"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "tool_result"
                  },
                  "toolUseId": {
                    "type": "string"
                  },
                  "content": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "text"
                            },
                            "text": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "text"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "image"
                            },
                            "source": {
                              "oneOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "base64"
                                    },
                                    "mediaType": {
                                      "type": "string"
                                    },
                                    "data": {
                                      "type": "string"
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "mediaType",
                                    "data"
                                  ]
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "file"
                                    },
                                    "path": {
                                      "type": "string"
                                    },
                                    "mediaType": {
                                      "type": "string"
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "path"
                                  ]
                                }
                              ]
                            },
                            "name": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "source"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "document"
                            },
                            "name": {
                              "type": "string"
                            },
                            "mediaType": {
                              "type": "string"
                            },
                            "source": {
                              "oneOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "base64"
                                    },
                                    "mediaType": {
                                      "type": "string"
                                    },
                                    "data": {
                                      "type": "string"
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "mediaType",
                                    "data"
                                  ]
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "kind": {
                                      "type": "string",
                                      "const": "file"
                                    },
                                    "path": {
                                      "type": "string"
                                    },
                                    "mediaType": {
                                      "type": "string"
                                    }
                                  },
                                  "required": [
                                    "kind",
                                    "path"
                                  ]
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "name",
                            "mediaType",
                            "source"
                          ]
                        }
                      ]
                    }
                  },
                  "isError": {
                    "type": "boolean"
                  },
                  "durationMs": {
                    "type": "number",
                    "minimum": 0
                  }
                },
                "required": [
                  "type",
                  "toolUseId",
                  "content",
                  "isError"
                ]
              }
            ]
          }
        },
        "status": {
          "type": "string",
          "enum": [
            "streaming",
            "complete",
            "cancelled",
            "error"
          ]
        },
        "seq": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
        },
        "error": {
          "default": null,
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "auth_failed",
                    "rate_limited",
                    "provider_unavailable",
                    "provider_error",
                    "binary_not_found",
                    "not_logged_in",
                    "sandbox_unavailable",
                    "outside_roots",
                    "read_only_root",
                    "approval_denied",
                    "tool_failed",
                    "tool_server_failed",
                    "invalid_request",
                    "not_implemented",
                    "unknown_provider",
                    "not_found",
                    "unsupported_content",
                    "attachment_too_large",
                    "unsupported_attachment",
                    "attachment_too_many",
                    "update_failed",
                    "connection_in_use",
                    "connection_disabled",
                    "model_required",
                    "secret_missing",
                    "secret_store_unavailable",
                    "oauth_not_configured",
                    "oauth_failed",
                    "oauth_cancelled",
                    "google_not_connected",
                    "google_reconnect_required",
                    "runner_crashed",
                    "runner_unavailable",
                    "conversation_busy",
                    "interrupted",
                    "hub_unreachable",
                    "hub_auth_required",
                    "hub_incompatible",
                    "forbidden",
                    "run_expired",
                    "agent_not_linked",
                    "invitation_invalid",
                    "invalid_credentials",
                    "email_taken",
                    "timeout",
                    "internal"
                  ]
                },
                "message": {
                  "type": "string"
                },
                "retryable": {
                  "type": "boolean"
                }
              },
              "required": [
                "code",
                "message",
                "retryable"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "author": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name"
              ]
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "conversationId",
        "role",
        "content",
        "status",
        "seq",
        "createdAt"
      ]
    },
    "conversation": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "agentId": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "idle",
            "running",
            "awaiting-approval",
            "error"
          ]
        },
        "harnessSessionId": {
          "type": [
            "string",
            "null"
          ]
        },
        "archived": {
          "type": "boolean"
        },
        "lastActivityAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
        }
      },
      "required": [
        "id",
        "agentId",
        "title",
        "status",
        "harnessSessionId",
        "archived",
        "lastActivityAt",
        "createdAt"
      ]
    }
  },
  "required": [
    "message",
    "conversation"
  ]
}
