{
  "openapi": "3.0.3",
  "info": {
    "title": "Mnemosyne API",
    "description": "API for the Mnemosyne application, which handles audio recording, transcription, \nand summarization functionalities.\n",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:8000",
      "description": "Local development server"
    }
  ],
  "components": {
    "schemas": {
      "TranscriptSegment": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "description": "The transcribed text"
          },
          "timestamp": {
            "type": "number",
            "format": "float",
            "description": "Unix timestamp of the segment"
          },
          "speaker": {
            "type": "string",
            "description": "Speaker identifier (e.g., \"Speaker 1\")"
          },
          "start": {
            "type": "number",
            "format": "float",
            "description": "Start time of the segment in seconds"
          },
          "end": {
            "type": "number",
            "format": "float",
            "description": "End time of the segment in seconds"
          }
        },
        "required": [
          "text",
          "timestamp",
          "speaker"
        ]
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the model"
          },
          "name": {
            "type": "string",
            "description": "Human-readable name of the model"
          },
          "provider": {
            "type": "string",
            "description": "Provider of the model (e.g., \"OpenAI\")"
          },
          "size": {
            "type": "string",
            "description": "Size/version of the model"
          }
        },
        "required": [
          "id",
          "name",
          "provider"
        ]
      },
      "Participant": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the participant"
          },
          "name": {
            "type": "string",
            "description": "Human-readable name of the participant"
          }
        },
        "required": [
          "id",
          "name"
        ]
      },
      "Session": {
        "type": "object",
        "properties": {
          "session_id": {
            "type": "string",
            "description": "Unique identifier for the session"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the session was created"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "recording",
              "processing",
              "completed",
              "error"
            ],
            "description": "Current status of the session"
          },
          "model": {
            "type": "string",
            "description": "The model used for transcription/summarization"
          },
          "device_ids": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "IDs of audio devices used for recording"
          },
          "recording_file": {
            "type": "string",
            "description": "Path to the recording file"
          },
          "transcript_file": {
            "type": "string",
            "description": "Path to the transcript file"
          },
          "is_recording": {
            "type": "boolean",
            "description": "Whether the session is currently recording"
          },
          "summary_length": {
            "type": "integer",
            "description": "Length of the summary in characters"
          },
          "transcript_length": {
            "type": "integer",
            "description": "Number of transcript segments"
          },
          "name": {
            "type": "string",
            "description": "Custom name for the session"
          },
          "participants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Participant"
            },
            "description": "List of participants in the session"
          }
        },
        "required": [
          "session_id",
          "created_at",
          "status",
          "is_recording",
          "device_ids"
        ]
      },
      "SessionListResponse": {
        "type": "object",
        "properties": {
          "sessions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Session"
            }
          }
        },
        "required": [
          "sessions"
        ]
      },
      "SessionCreateRequest": {
        "type": "object",
        "properties": {
          "session_id": {
            "type": "string",
            "description": "Optional session ID (generated if not provided)"
          }
        }
      },
      "RenameSessionRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "New name for the session"
          }
        },
        "required": [
          "name"
        ]
      },
      "UpdateParticipantRequest": {
        "type": "object",
        "properties": {
          "participant_id": {
            "type": "string",
            "description": "ID of the participant to update"
          },
          "name": {
            "type": "string",
            "description": "New name for the participant"
          }
        },
        "required": [
          "participant_id",
          "name"
        ]
      },
      "AudioDevice": {
        "type": "object",
        "properties": {
          "id": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Unique identifier for the device"
          },
          "name": {
            "type": "string",
            "description": "Human-readable name of the device"
          },
          "channels": {
            "type": "integer",
            "description": "Number of audio channels"
          },
          "default": {
            "type": "boolean",
            "description": "Whether this is the default device"
          },
          "is_monitor": {
            "type": "boolean",
            "description": "Whether this is a monitor device"
          }
        },
        "required": [
          "id",
          "name",
          "channels",
          "default"
        ]
      },
      "TranscriptFile": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string",
            "description": "Path to the transcript file"
          },
          "filename": {
            "type": "string",
            "description": "Name of the transcript file"
          },
          "date": {
            "type": "string",
            "description": "Date the transcript was created"
          },
          "size": {
            "type": "integer",
            "description": "Size of the transcript file in bytes"
          },
          "session_id": {
            "type": "string",
            "description": "ID of the session that created this transcript"
          }
        },
        "required": [
          "path",
          "filename",
          "date",
          "size"
        ]
      },
      "ResummarizeRequest": {
        "type": "object",
        "properties": {
          "transcript_file": {
            "type": "string",
            "description": "Path to the transcript file to resummarize"
          },
          "model": {
            "type": "string",
            "description": "Optional model to use for resummarization"
          },
          "session_id": {
            "type": "string",
            "description": "Optional session ID to associate with the resummarization"
          }
        },
        "required": [
          "transcript_file"
        ]
      },
      "StartRecordingRequest": {
        "type": "object",
        "properties": {
          "device_ids": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "IDs of audio devices to record from"
          },
          "model": {
            "type": "string",
            "description": "Optional model to use for transcription"
          },
          "session_id": {
            "type": "string",
            "description": "Optional session ID to use"
          }
        },
        "required": [
          "device_ids"
        ]
      }
    },
    "responses": {
      "ErrorResponse": {
        "description": "Error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "detail": {
                  "type": "string",
                  "description": "Error message"
                }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/sessions": {
      "post": {
        "summary": "Create a new transcription session",
        "operationId": "createSession",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SessionCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List all available sessions",
        "operationId": "listSessions",
        "responses": {
          "200": {
            "description": "List of sessions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{session_id}": {
      "get": {
        "summary": "Get a specific session by ID",
        "operationId": "getSession",
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "include_data",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "If true, include the full transcript and summary data"
          }
        ],
        "responses": {
          "200": {
            "description": "Session details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      },
      "delete": {
        "summary": "Delete a session by ID",
        "operationId": "deleteSession",
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/sessions/{session_id}/rename": {
      "post": {
        "summary": "Rename a session",
        "operationId": "renameSession",
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RenameSessionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session renamed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "session_id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/sessions/{session_id}/participants/extract": {
      "post": {
        "summary": "Extract participants from a session's transcript",
        "operationId": "extractParticipants",
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Participants extracted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "session_id": {
                      "type": "string"
                    },
                    "participants": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Participant"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorResponse"
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/sessions/{session_id}/participants/{participant_id}": {
      "put": {
        "summary": "Update a participant's information",
        "operationId": "updateParticipant",
        "parameters": [
          {
            "name": "session_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "participant_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateParticipantRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Participant updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "session_id": {
                      "type": "string"
                    },
                    "participant_id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorResponse"
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/devices": {
      "get": {
        "summary": "Get available audio devices",
        "operationId": "getDevices",
        "responses": {
          "200": {
            "description": "List of available audio devices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "devices": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AudioDevice"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ws": {
      "get": {
        "summary": "WebSocket endpoint for real-time communication",
        "description": "Connect to the WebSocket to receive real-time updates about sessions,\ntranscriptions, and summaries. The WebSocket accepts JSON messages with the following types:\n- `subscribe`: Subscribe to a specific session\n- `unsubscribe`: Unsubscribe from the current session\n",
        "responses": {
          "101": {
            "description": "Switching Protocols to WebSocket"
          }
        }
      }
    },
    "/upload": {
      "post": {
        "summary": "Upload an audio file for transcription and summarization",
        "operationId": "uploadFile",
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The audio file to upload"
                  },
                  "session_id": {
                    "type": "string",
                    "description": "Optional session ID to use"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "session_id": {
                      "type": "string"
                    },
                    "transcript_file": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/models": {
      "get": {
        "summary": "Get available models for summarization",
        "operationId": "getModels",
        "responses": {
          "200": {
            "description": "List of available models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "models": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/transcripts": {
      "get": {
        "summary": "Get available transcript files",
        "operationId": "getTranscripts",
        "responses": {
          "200": {
            "description": "List of available transcript files",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transcripts": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TranscriptFile"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/resummarize": {
      "post": {
        "summary": "Re-summarize a transcript file using a specified model",
        "operationId": "resummarize",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResummarizeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transcript re-summarized successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session_id": {
                      "type": "string"
                    },
                    "transcript_file": {
                      "type": "string"
                    },
                    "summary": {
                      "type": "string"
                    },
                    "model": {
                      "type": "string"
                    },
                    "file_updated": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorResponse"
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/start": {
      "post": {
        "summary": "Start recording audio",
        "operationId": "startRecording",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartRecordingRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Recording started successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "session_id": {
                      "type": "string"
                    },
                    "model": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorResponse"
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/stop": {
      "post": {
        "summary": "Stop recording audio",
        "operationId": "stopRecording",
        "parameters": [
          {
            "name": "session_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional session ID to stop recording (uses the first recording session if not provided)"
          }
        ],
        "responses": {
          "200": {
            "description": "Recording stopped successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "session_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorResponse"
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    }
  }
}