{
  "asyncapi": "3.0.0",
  "info": {
    "title": "Interactive Online Textbooks",
    "version": "0.0.1-pre1",
    "description": "Beautiful and Engaging Learning Materials"
  },
  "servers": {
    "development": {
      "host": "localhost:8000",
      "protocol": "ws"
    }
  },
  "channels": {
    "chat": {
      "address": "ws/ai/chat",
      "title": "chat",
      "description": "Chat with AI Assistant",
      "messages": {
        "chatHistory": {
          "$ref": "#/components/messages/chatHistory"
        },
        "chatInput": {
          "$ref": "#/components/messages/chatInput"
        },
        "chatMessage": {
          "$ref": "#/components/messages/chatMessage"
        },
        "getChatHistory": {
          "$ref": "#/components/messages/getChatHistory"
        },
        "pingMessage": {
          "$ref": "#/components/messages/pingMessage"
        },
        "pongMessage": {
          "$ref": "#/components/messages/pongMessage"
        }
      },
      "tags": [
        {
          "name": "ai"
        },
        {
          "name": "chat"
        }
      ]
    }
  },
  "operations": {
    "handleChatInput": {
      "action": "receive",
      "channel": {
        "$ref": "#/channels/chat"
      },
      "description": "Send a new chat message from the user to the assistant",
      "summary": "Handle Chat Input",
      "messages": [
        {
          "$ref": "#/channels/chat/messages/chatInput"
        }
      ],
      "reply": {
        "channel": {
          "$ref": "#/channels/chat"
        },
        "messages": [
          {
            "$ref": "#/channels/chat/messages/chatMessage"
          }
        ]
      }
    },
    "handleGetChatHistory": {
      "action": "receive",
      "channel": {
        "$ref": "#/channels/chat"
      },
      "description": "Retrieve the full chat history from the server",
      "summary": "Get Chat History",
      "messages": [
        {
          "$ref": "#/channels/chat/messages/getChatHistory"
        }
      ],
      "reply": {
        "channel": {
          "$ref": "#/channels/chat"
        },
        "messages": [
          {
            "$ref": "#/channels/chat/messages/chatHistory"
          }
        ]
      }
    },
    "handlePing": {
      "action": "receive",
      "channel": {
        "$ref": "#/channels/chat"
      },
      "description": "Simple ping-pong for connectivity testing",
      "summary": "Handle Ping Requests",
      "messages": [
        {
          "$ref": "#/channels/chat/messages/pingMessage"
        }
      ],
      "reply": {
        "channel": {
          "$ref": "#/channels/chat"
        },
        "messages": [
          {
            "$ref": "#/channels/chat/messages/pongMessage"
          }
        ]
      }
    }
  },
  "components": {
    "messages": {
      "chatHistory": {
        "payload": {
          "$ref": "#/components/schemas/ChatHistory"
        }
      },
      "chatInput": {
        "payload": {
          "$ref": "#/components/schemas/ChatInput"
        }
      },
      "chatMessage": {
        "payload": {
          "$ref": "#/components/schemas/ChatMessage"
        }
      },
      "getChatHistory": {
        "payload": {
          "$ref": "#/components/schemas/GetChatHistory"
        }
      },
      "pingMessage": {
        "payload": {
          "$ref": "#/components/schemas/PingMessage"
        }
      },
      "pongMessage": {
        "payload": {
          "$ref": "#/components/schemas/PongMessage"
        }
      }
    },
    "schemas": {
      "ChatHistory": {
        "description": "Full chat history.",
        "properties": {
          "action": {
            "const": "chat_history",
            "default": "chat_history",
            "title": "Action",
            "type": "string"
          },
          "payload": {
            "$ref": "#/components/schemas/ChatHistoryPayload"
          }
        },
        "required": [
          "payload"
        ],
        "title": "ChatHistory",
        "type": "object"
      },
      "ChatHistoryPayload": {
        "description": "Payload containing the full chat history.",
        "properties": {
          "messages": {
            "items": {
              "$ref": "#/components/schemas/ChatMessagePayload"
            },
            "title": "Messages",
            "type": "array"
          }
        },
        "required": [
          "messages"
        ],
        "title": "ChatHistoryPayload",
        "type": "object"
      },
      "ChatInput": {
        "description": "Chat input sent by the user to the assistant.",
        "properties": {
          "action": {
            "const": "chat_input",
            "default": "chat_input",
            "title": "Action",
            "type": "string"
          },
          "payload": {
            "$ref": "#/components/schemas/ChatInputPayload"
          }
        },
        "required": [
          "payload"
        ],
        "title": "ChatInput",
        "type": "object"
      },
      "ChatInputPayload": {
        "description": "Payload for incoming user chat messages.",
        "properties": {
          "format": {
            "enum": [
              "markdown",
              "json",
              "image"
            ],
            "title": "Format",
            "type": "string"
          },
          "content": {
            "title": "Content",
            "type": "string"
          }
        },
        "required": [
          "format",
          "content"
        ],
        "title": "ChatInputPayload",
        "type": "object"
      },
      "ChatMessage": {
        "description": "A single chat message within a larger chat conversation. This is the data that\nthe server uses internally to drive the AI chat functionality and persist the\nchat history.",
        "properties": {
          "action": {
            "const": "chat_message",
            "default": "chat_message",
            "title": "Action",
            "type": "string"
          },
          "payload": {
            "$ref": "#/components/schemas/ChatMessagePayload"
          }
        },
        "required": [
          "payload"
        ],
        "title": "ChatMessage",
        "type": "object"
      },
      "ChatMessagePayload": {
        "description": "Payload for a single chat message.",
        "properties": {
          "id": {
            "title": "Id",
            "type": "string"
          },
          "datetime": {
            "format": "date-time",
            "title": "Datetime",
            "type": "string"
          },
          "sender": {
            "enum": [
              "user",
              "assistant"
            ],
            "title": "Sender",
            "type": "string"
          },
          "type": {
            "enum": [
              "normal",
              "status",
              "thought",
              "action",
              "system"
            ],
            "title": "Type",
            "type": "string"
          },
          "severity": {
            "enum": [
              "info",
              "warning",
              "error",
              "critical"
            ],
            "title": "Severity",
            "type": "string"
          },
          "guardRails": {
            "$ref": "#/components/schemas/GuardRailCheckResult"
          },
          "format": {
            "enum": [
              "markdown",
              "json",
              "image"
            ],
            "title": "Format",
            "type": "string"
          },
          "content": {
            "title": "Content",
            "type": "string"
          },
          "finished": {
            "title": "Finished",
            "type": "boolean"
          }
        },
        "required": [
          "datetime",
          "sender",
          "type",
          "severity",
          "guardRails",
          "format",
          "content",
          "finished"
        ],
        "title": "ChatMessagePayload",
        "type": "object"
      },
      "GetChatHistory": {
        "description": "Message sent by the client to retrieve the full chat history from the server.",
        "properties": {
          "action": {
            "const": "get_chat_history",
            "default": "get_chat_history",
            "title": "Action",
            "type": "string"
          },
          "payload": {
            "default": null,
            "title": "Payload",
            "type": "null"
          }
        },
        "title": "GetChatHistory",
        "type": "object"
      },
      "GuardRailCheckResult": {
        "description": "Guard rails check incoming chat messages for disallowed or dangerous content.\nThis type defines the data structure for the check results.",
        "properties": {
          "findings": {
            "enum": [
              "none",
              "offensive_language",
              "dangerous_content",
              "others"
            ],
            "title": "Findings",
            "type": "string"
          },
          "explanation": {
            "title": "Explanation",
            "type": "string"
          }
        },
        "required": [
          "findings",
          "explanation"
        ],
        "title": "GuardRailCheckResult",
        "type": "object"
      },
      "PingMessage": {
        "description": "Simple ping message to check WebSocket connection status.",
        "properties": {
          "action": {
            "const": "ping",
            "default": "ping",
            "title": "Action",
            "type": "string"
          },
          "payload": {
            "default": null,
            "title": "Payload",
            "type": "null"
          }
        },
        "title": "PingMessage",
        "type": "object"
      },
      "PongMessage": {
        "description": "Simple pong message response to ping requests.",
        "properties": {
          "action": {
            "const": "pong",
            "default": "pong",
            "title": "Action",
            "type": "string"
          },
          "payload": {
            "default": null,
            "title": "Payload",
            "type": "null"
          }
        },
        "title": "PongMessage",
        "type": "object"
      }
    }
  }
}