openapi: "3.0.0" info: title: "AI Assistant API" version: "1.1.0" description: "API documentation for the AI Assistant application." servers: - url: "https://ai-assistant-chatbot-server.vercel.app" description: "Production server" - url: "http://localhost:3000" description: "Local server" tags: - name: "Auth" description: "Endpoints for user authentication and account management" - name: "Chat" description: "Endpoints for chat interactions with the AI assistant" - name: "Conversations" description: "Endpoints for managing user conversations" - name: "Knowledge" description: "Endpoints for managing RAG knowledge sources (Admin only)" paths: /api/auth/signup: post: tags: - "Auth" summary: "Sign Up a new user" description: "Create a new user account with the provided email and password." requestBody: required: true content: application/json: schema: type: object properties: email: type: string format: email password: type: string required: - email - password example: email: "user@example.com" password: "yourpassword" responses: '200': description: "User created successfully." content: application/json: schema: type: object properties: message: type: string example: message: "User created successfully" '400': description: "User already exists." '500': description: "Server error." /api/auth/login: post: tags: - "Auth" summary: "Log in a user" description: "Authenticate a user with email and password and return a JWT token." requestBody: required: true content: application/json: schema: type: object properties: email: type: string format: email password: type: string required: - email - password example: email: "user@example.com" password: "yourpassword" responses: '200': description: "Successfully authenticated." content: application/json: schema: type: object properties: token: type: string example: token: "your.jwt.token" '400': description: "Invalid credentials or user does not exist." '500': description: "Server error." /api/auth/verify-email: get: tags: - "Auth" summary: "Verify if an email exists" description: "Checks whether a user with the specified email exists." parameters: - name: email in: query description: "Email address to verify." required: true schema: type: string format: email responses: '200': description: "Email verification result." content: application/json: schema: type: object properties: exists: type: boolean example: exists: true '400': description: "Email is required." '500': description: "Server error." /api/auth/passkey/register/options: post: tags: - "Auth" summary: "Begin passkey registration" description: "Generate WebAuthn registration options for the authenticated user. The returned `challengeId` must be echoed back to `/register/verify` together with the browser's attestation response." security: - bearerAuth: [] requestBody: required: false content: application/json: schema: type: object properties: nickname: type: string description: "Friendly label persisted with the credential when verification succeeds." responses: '200': description: "Registration options + opaque challengeId." content: application/json: schema: type: object properties: options: type: object description: "PublicKeyCredentialCreationOptionsJSON to pass into @simplewebauthn/browser startRegistration()." challengeId: type: string '401': description: "Authorization header missing." '403': description: "Invalid token." '404': description: "User not found." /api/auth/passkey/register/verify: post: tags: - "Auth" summary: "Complete passkey registration" description: "Verify the WebAuthn attestation produced by the browser and persist the new credential on the user." security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object required: - challengeId - response properties: challengeId: type: string nickname: type: string response: type: object description: "RegistrationResponseJSON returned by startRegistration()." responses: '200': description: "Credential registered." content: application/json: schema: type: object properties: ok: type: boolean credential: $ref: '#/components/schemas/PasskeySummary' '400': description: "Invalid challenge or verification failed." /api/auth/passkey/login/options: post: tags: - "Auth" summary: "Begin passkey login" description: "Generate WebAuthn authentication options. If `email` is supplied the response is scoped to that user's credentials; otherwise discoverable (usernameless) login is used." requestBody: required: false content: application/json: schema: type: object properties: email: type: string format: email responses: '200': description: "Authentication options + opaque challengeId." content: application/json: schema: type: object properties: options: type: object challengeId: type: string /api/auth/passkey/login/verify: post: tags: - "Auth" summary: "Complete passkey login" description: "Verify the WebAuthn assertion and return a JWT (same shape as password login)." requestBody: required: true content: application/json: schema: type: object required: - challengeId - response properties: challengeId: type: string response: type: object description: "AuthenticationResponseJSON returned by startAuthentication()." responses: '200': description: "Successfully authenticated." content: application/json: schema: type: object properties: token: type: string '400': description: "Invalid challenge or verification failed." /api/auth/passkey: get: tags: - "Auth" summary: "List the authenticated user's passkeys" security: - bearerAuth: [] responses: '200': description: "List of registered passkeys." content: application/json: schema: type: object properties: credentials: type: array items: $ref: '#/components/schemas/PasskeySummary' /api/auth/passkey/{credentialId}: delete: tags: - "Auth" summary: "Remove a registered passkey" security: - bearerAuth: [] parameters: - name: credentialId in: path required: true schema: type: string responses: '200': description: "Passkey removed." '404': description: "Credential not found." /api/auth/reset-password: post: tags: - "Auth" summary: "Reset user password" description: "Resets the password for a user identified by the email." requestBody: required: true content: application/json: schema: type: object properties: email: type: string format: email newPassword: type: string required: - email - newPassword example: email: "user@example.com" newPassword: "newpassword123" responses: '200': description: "Password reset successfully." content: application/json: schema: type: object properties: message: type: string example: message: "Password reset successfully" '400': description: "Email and new password are required, or user does not exist." '500': description: "Server error." /api/chat/auth: post: tags: - "Chat" summary: "Chat with the AI assistant as an authenticated user" description: "Sends a chat message to the AI assistant. Requires a valid JWT in the Authorization header. The conversation is stored in MongoDB's Conversation collection." parameters: - name: Authorization in: header description: "JWT token in the format 'Bearer {token}'" required: true schema: type: string requestBody: required: true content: application/json: schema: type: object properties: message: type: string conversationId: type: string required: - message example: message: "Hello, AI!" conversationId: "60d5ec49f5a3c80015c0d9a4" responses: '200': description: "AI response for authenticated user." content: application/json: schema: type: object properties: answer: type: string conversationId: type: string example: answer: "Hi there! How can I help you today?" conversationId: "60d5ec49f5a3c80015c0d9a4" '400': description: "Bad Request" '401': description: "Unauthorized (invalid or missing token)" '404': description: "Conversation not found" '500': description: "Server error." /api/chat/guest: post: tags: - "Chat" summary: "Chat with the AI assistant as a guest (unauthenticated)" description: "Sends a chat message to the AI assistant. No token required. The conversation is stored in MongoDB's GuestConversation collection, keyed by a guestId." requestBody: required: true content: application/json: schema: type: object properties: message: type: string guestId: type: string required: - message - guestId example: message: "Hello from a guest user" guestId: "123e4567-e89b-12d3-a456-426614174000" responses: '200': description: "AI response for guest user." content: application/json: schema: type: object properties: answer: type: string guestId: type: string example: answer: "Hi there! How can I help you today?" guestId: "123e4567-e89b-12d3-a456-426614174000" '400': description: "Bad Request" '500': description: "Server error." /api/conversations: post: tags: - "Conversations" summary: "Create a new conversation" description: "Creates a new conversation for the authenticated user with a default title of 'New Conversation'." responses: '200': description: "A conversation object." content: application/json: schema: $ref: '#/components/schemas/Conversation' example: id: "60d5ec49f5a3c80015c0d9a4" title: "New Conversation" messages: [] createdAt: "2025-02-07T12:34:56Z" updatedAt: "2025-02-07T12:34:56Z" '500': description: "Internal server error." get: tags: - "Conversations" summary: "Get all conversations for the authenticated user" description: "Returns conversation metadata only (messages are omitted) for the sidebar list. Fetch a single conversation by ID to load its messages." responses: '200': description: "A list of conversation summaries (messages omitted)." content: application/json: schema: type: array items: $ref: '#/components/schemas/ConversationSummary' example: - id: "60d5ec49f5a3c80015c0d9a4" title: "New Conversation" createdAt: "2025-02-07T12:34:56Z" updatedAt: "2025-02-07T12:34:56Z" '500': description: "Internal server error." /api/conversations/{id}: get: tags: - "Conversations" summary: "Get a conversation by ID" parameters: - name: id in: path required: true description: "The conversation ID." schema: type: string responses: '200': description: "A conversation object." content: application/json: schema: $ref: '#/components/schemas/Conversation' example: id: "60d5ec49f5a3c80015c0d9a4" title: "New Conversation" messages: [] createdAt: "2025-02-07T12:34:56Z" updatedAt: "2025-02-07T12:34:56Z" '404': description: "Conversation not found." '500': description: "Internal server error." put: tags: - "Conversations" summary: "Rename (update) a conversation's title" parameters: - name: id in: path required: true description: "The conversation ID." schema: type: string requestBody: required: true content: application/json: schema: type: object properties: title: type: string required: - title example: title: "Updated Conversation Title" responses: '200': description: "The updated conversation object." content: application/json: schema: $ref: '#/components/schemas/Conversation' example: id: "60d5ec49f5a3c80015c0d9a4" title: "Updated Conversation Title" messages: [] createdAt: "2025-02-07T12:34:56Z" updatedAt: "2025-02-07T12:35:56Z" '404': description: "Conversation not found." '500': description: "Internal server error." delete: tags: - "Conversations" summary: "Delete a conversation" parameters: - name: id in: path required: true description: "The conversation ID to delete." schema: type: string responses: '200': description: "Conversation deleted successfully." content: application/json: schema: type: object properties: message: type: string example: message: "Conversation deleted successfully" '404': description: "Conversation not found." '500': description: "Internal server error." /api/conversations/search/{query}: get: tags: - "Conversations" summary: "Search conversations by title or message content" parameters: - name: query in: path required: true description: "The search query." schema: type: string responses: '200': description: "A list of conversation summaries matching the search criteria (messages omitted)." content: application/json: schema: type: array items: $ref: '#/components/schemas/ConversationSummary' example: - id: "60d5ec49f5a3c80015c0d9a4" title: "Search Result Conversation" createdAt: "2025-02-07T12:34:56Z" updatedAt: "2025-02-07T12:34:56Z" '500': description: "Internal server error." /api/knowledge: get: tags: - "Knowledge" summary: "List knowledge sources" description: "Retrieve a paginated list of knowledge sources. Note: The `content` field is excluded from list responses for performance." security: - bearerAuth: [] parameters: - name: page in: query schema: type: integer minimum: 1 default: 1 - name: limit in: query schema: type: integer minimum: 1 maximum: 100 default: 20 - name: type in: query schema: type: string enum: [resume, note, link, project, bio, other] - name: search in: query schema: type: string responses: '200': description: "A paginated list of sources." content: application/json: schema: type: object required: [sources, pagination] properties: sources: type: array items: $ref: '#/components/schemas/KnowledgeSource' pagination: type: object required: [page, limit, total, pages] properties: page: type: integer limit: type: integer total: type: integer pages: type: integer '403': description: "Admin access required." post: tags: - "Knowledge" summary: "Create a new knowledge source" description: "Creates a new source, chunks the content, embeds it into Pinecone, and ingests it into Neo4j." security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object required: [title, content, sourceType] properties: title: type: string content: type: string sourceType: type: string enum: [resume, note, link, project, bio, other] sourceUrl: type: string tags: type: array items: type: string externalId: type: string responses: '201': description: "Source created and embedded." /api/knowledge/{id}: get: tags: - "Knowledge" summary: "Get a single knowledge source" description: "Retrieve one source with its full `content` field included (unlike the list endpoint)." security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string responses: '200': description: "The knowledge source, with content." content: application/json: schema: type: object required: [source] properties: source: $ref: '#/components/schemas/KnowledgeSource' '400': description: "Invalid id format." '403': description: "Admin access required." '404': description: "Knowledge source not found." patch: tags: - "Knowledge" summary: "Update a knowledge source" description: "Updates source metadata. If `content` is provided, the old vectors are deleted and new content is embedded." security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object properties: title: type: string content: type: string sourceType: type: string enum: [resume, note, link, project, bio, other] sourceUrl: type: string tags: type: array items: type: string externalId: type: string responses: '200': description: "Source updated." delete: tags: - "Knowledge" summary: "Delete a knowledge source" description: "Removes the source from MongoDB, deletes its vectors from Pinecone, and removes related nodes from Neo4j." security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string responses: '200': description: "Source deleted." /api/knowledge/{id}/reindex: post: tags: - "Knowledge" summary: "Re-index a knowledge source" description: "Deletes existing vectors and re-embeds the current content for a source." security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string responses: '200': description: "Source re-indexed." /api/knowledge/sync: post: tags: - "Knowledge" summary: "Bulk sync manifest" description: "Upserts multiple sources based on `externalId`. Useful for keeping external static files synced." security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object required: [sources] properties: sources: type: array items: type: object responses: '200': description: "Sync complete." components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT schemas: KnowledgeSource: type: object properties: _id: type: string title: type: string content: type: string sourceType: type: string enum: [resume, note, link, project, bio, other] sourceUrl: type: string tags: type: array items: type: string externalId: type: string chunkCount: type: integer createdAt: type: string format: date-time updatedAt: type: string format: date-time PasskeySummary: type: object properties: credentialID: type: string description: "Base64url-encoded credential ID. Stable across sign-ins; safe to expose." nickname: type: string transports: type: array items: type: string deviceType: type: string description: "Either 'singleDevice' or 'multiDevice' (synced)." backedUp: type: boolean createdAt: type: string format: date-time lastUsedAt: type: string format: date-time Conversation: type: object properties: id: type: string description: "Unique identifier of the conversation." title: type: string description: "Title of the conversation." messages: type: array description: "List of messages in the conversation." items: $ref: '#/components/schemas/Message' createdAt: type: string format: date-time description: "Creation timestamp." updatedAt: type: string format: date-time description: "Last update timestamp." required: - id - title ConversationSummary: type: object description: "Conversation metadata without messages, used for list and search responses." properties: id: type: string description: "Unique identifier of the conversation." title: type: string description: "Title of the conversation." createdAt: type: string format: date-time description: "Creation timestamp." updatedAt: type: string format: date-time description: "Last update timestamp." required: - id - title Message: type: object properties: sender: type: string description: "Sender of the message, e.g. 'user' or 'assistant'." content: type: string description: "The message content." timestamp: type: string format: date-time description: "The time the message was sent." required: - sender - content - timestamp