### Frontend API Integration with TypeScript Source: https://context7.com/nemo-docs/attd/llms.txt This TypeScript example showcases how to use the provided API client (`repoApi`, `chatQaApi`, `pageApi`) for type-safe backend communication. It includes examples for cloning a repository, retrieving repository data, and starting a chat session, with built-in error handling for API requests. ```typescript import { repoApi, chatQaApi, pageApi } from '@/lib/api'; // Clone a repository try { const result = await repoApi.createRepo({ github_url: 'https://github.com/username/repository' }); if ('error' in result) { console.error('Failed to clone repo:', result.error); } else { console.log('Repository cloned:', result.repo_hash); // Get repository documentation const repoData = await repoApi.getRepo(result.repo_hash); console.log('Project intro:', repoData.project_intro); // Start a chat about the repository const chatResponse = await chatQaApi.sendMessage({ message: 'What are the main features?', repoHash: result.repo_hash, userId: '1234567890123456', thinkLevel: 'simple' }); console.log('AI response:', chatResponse.response); } } catch (error) { if (error instanceof ApiError) { console.error(`API Error ${error.status}:`, error.message); } } ``` -------------------------------- ### MCP Server Page Management with TypeScript SDK Source: https://context7.com/nemo-docs/attd/llms.txt This TypeScript example demonstrates integration with the Model Context Protocol (MCP) server using the provided SDK. It shows how to initialize the client, connect to the MCP server with authentication, and utilize tools to create, retrieve all, or retrieve a specific page. ```typescript import { Client } from "@modelcontextprotocol/sdk/client/index.js"; const client = new Client({ name: "attd-client", version: "1.0.0" }, { capabilities: { tools: {} } }); // Connect to MCP server with authentication await client.connect(new StdioClientTransport({ command: "python", args: ["mcp/main.py"], env: { ...process.env, CLERK_SECRET_KEY: "your_clerk_secret" } })); // Create page via MCP const result = await client.callTool({ name: "create_page", arguments: { title: "Architecture Overview", content: "# Architecture\n\nThis system uses..." } }); // Get all pages const pages = await client.callTool({ name: "get_all_pages", arguments: {} }); // Get specific page const page = await client.callTool({ name: "get_page_by_id", arguments: { page_id: "page_1234567890" } }); ``` -------------------------------- ### GET /api/pages/ Source: https://context7.com/nemo-docs/attd/llms.txt Retrieves a list of all documentation pages for a specific user, supporting pagination. ```APIDOC ## GET /api/pages/ ### Description Retrieves a list of all documentation pages for a specific user, supporting pagination. ### Method GET ### Endpoint /api/pages/ ### Parameters #### Query Parameters - **user_id** (string) - Required - The ID of the user whose pages are to be retrieved. ### Response #### Success Response (200) - **pages** (array) - An array of page objects: - **id** (string) - The unique identifier for the page. - **user_id** (string) - The ID of the user who owns the page. - **title** (string) - The title of the page. - **content** (string) - The markdown content of the page. - **created_at** (string) - The timestamp when the page was created. - **updated_at** (string) - The timestamp when the page was last updated. - **total_count** (integer) - The total number of pages available for the user. #### Response Example ```json { "pages": [ { "id": "page_1111111111", "user_id": "1234567890123456", "title": "Getting Started", "content": "# Getting Started\n\n...", "created_at": "2025-01-10T08:00:00Z", "updated_at": "2025-01-12T14:30:00Z" } ], "total_count": 1 } ``` ``` -------------------------------- ### GET /api/git-repo/{repo_hash} Source: https://context7.com/nemo-docs/attd/llms.txt This endpoint retrieves cached documentation for a specific repository using its hash, including project introduction, data flow diagram, and file explanations. Authentication via Clerk JWT is required. It provides a quick way to access generated docs without re-analysis. ```APIDOC ## GET /api/git-repo/{repo_hash} ### Description Get cached project introduction, data flow diagram, and cursory file explanations by repository hash. ### Method GET ### Endpoint /api/git-repo/{repo_hash} ### Parameters #### Path Parameters - **repo_hash** (string) - Required - The unique hash of the repository. #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response (200) - **repo_hash** (string) - Repository hash. - **project_intro** (string) - Project introduction text. - **project_data_flow_diagram** (string) - Mermaid diagram code for data flow. - **project_cursory_explanation** (string) - File-by-file explanations. - **github_url** (string) - GitHub URL. - **name** (string) - Repository name. #### Response Example { "repo_hash": "a1b2c3d4e5f6...", "project_intro": "This is a FastAPI-based web application...", "project_data_flow_diagram": "graph TD\n A[User] --> B[API]...", "project_cursory_explanation": "### src/main.py\nEntry point...", "github_url": "https://github.com/username/repository", "name": "repository" } ``` -------------------------------- ### GET /api/auto-generation/definitions/{repoHash} Source: https://context7.com/nemo-docs/attd/llms.txt Retrieves all parsed function and class definitions from a repository, used for @mention autocomplete functionality. ```APIDOC ## GET /api/auto-generation/definitions/{repoHash} ### Description Retrieves all parsed function and class definitions from a repository, used for @mention autocomplete functionality. ### Method GET ### Endpoint /api/auto-generation/definitions/{repoHash} ### Parameters #### Path Parameters - **repoHash** (string) - Required - The hash identifier for the repository. ### Response #### Success Response (200) - An array of definition objects, each containing: - **node_name** (string) - The name of the function or class. - **file_name** (string) - The path to the file where the definition is located. - **start_end_lines** (array) - An array containing the start and end line numbers of the definition. - **node_type** (string) - The type of the node (e.g., 'function', 'class'). #### Response Example ```json [ { "node_name": "UserService", "file_name": "src/services/user.py", "start_end_lines": [10, 85], "node_type": "class" }, { "node_name": "authenticate_user", "file_name": "src/auth.py", "start_end_lines": [23, 45], "node_type": "function" } ] ``` ``` -------------------------------- ### Get Code Definitions via cURL Source: https://context7.com/nemo-docs/attd/llms.txt Shows how to retrieve all parsed function and class definitions from a repository for @mention autocomplete functionality. Requires a repository hash and JWT token for authorization. ```bash curl -X GET http://localhost:8000/api/auto-generation/definitions/a1b2c3d4e5f6 \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" # Response: # [ # { # "node_name": "UserService", # "file_name": "src/services/user.py", # "start_end_lines": [10, 85], # "node_type": "class" # }, # { # "node_name": "authenticate_user", # "file_name": "src/auth.py", # "start_end_lines": [23, 45], # "node_type": "function" # } # ] ``` -------------------------------- ### Get Inline Q&A Answer using REST API Source: https://context7.com/nemo-docs/attd/llms.txt This snippet illustrates how to obtain contextual AI answers based on cursor position within a documentation editor using a POST request to the `/api/inline-qna/answer` endpoint. It requires authentication and sends the user's query text, cursor position, and the relevant page ID in the JSON request body. The response contains the AI-generated answer. ```bash curl -X POST http://localhost:8000/api/inline-qna/answer \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" \ -d '{ "text": "The authentication system uses JWT tokens. How do refresh tokens work?", "cursor_position": 45, "page_id": "page_9876543210" }' ``` -------------------------------- ### Get Conversation Messages via cURL Source: https://context7.com/nemo-docs/attd/llms.txt Demonstrates how to fetch all messages in a conversation thread with user queries and AI responses. Requires a conversation ID, user ID, and JWT token for authorization. ```bash curl -X GET "http://localhost:8000/api/chat-qa/conversation/conv_1234567890?user_id=1234567890123456" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" # Response: # { # "messages": [ # { # "id": "msg_0001", # "message": "What does this project do?", # "response": "This project is a FastAPI-based documentation generator...", # "conversation_id": "conv_1234567890", # "model_used": "openai/gpt-5-mini", # "tokens_used": 450, # "created_at": "2025-01-15T10:00:00Z" # } # ] # } ``` -------------------------------- ### GET /api/chat-qa/conversation/{conversation_id} Source: https://context7.com/nemo-docs/attd/llms.txt Fetches all messages within a specific conversation thread, including both user queries and AI responses. ```APIDOC ## GET /api/chat-qa/conversation/{conversation_id} ### Description Fetches all messages within a specific conversation thread, including both user queries and AI responses. ### Method GET ### Endpoint /api/chat-qa/conversation/{conversation_id} ### Parameters #### Path Parameters - **conversation_id** (string) - Required - The ID of the conversation to retrieve messages from. #### Query Parameters - **user_id** (string) - Required - The ID of the user requesting the conversation messages. ### Response #### Success Response (200) - **messages** (array) - An array of message objects within the conversation: - **id** (string) - The unique identifier for the message. - **message** (string) - The user's query or message. - **response** (string) - The AI's response to the message. - **conversation_id** (string) - The ID of the conversation this message belongs to. - **model_used** (string) - The AI model used to generate the response. - **tokens_used** (integer) - The number of tokens used for the response. - **created_at** (string) - The timestamp when the message was created. #### Response Example ```json { "messages": [ { "id": "msg_0001", "message": "What does this project do?", "response": "This project is a FastAPI-based documentation generator...", "conversation_id": "conv_1234567890", "model_used": "openai/gpt-5-mini", "tokens_used": 450, "created_at": "2025-01-15T10:00:00Z" } ] } ``` ``` -------------------------------- ### GET /api/chat-qa/conversations Source: https://context7.com/nemo-docs/attd/llms.txt Retrieves a list of all conversations for a specific user. Includes metadata such as message counts and creation/update timestamps. ```APIDOC ## GET /api/chat-qa/conversations ### Description Retrieves a list of all conversations for a specific user. Includes metadata such as message counts and creation/update timestamps. ### Method GET ### Endpoint /api/chat-qa/conversations ### Parameters #### Query Parameters - **user_id** (string) - Required - The ID of the user whose conversations are to be retrieved. ### Response #### Success Response (200) - An array of conversation objects, each containing: - **id** (string) - The unique identifier for the conversation. - **title** (string) - The title of the conversation. - **page_id** (string) - The ID of the associated page, if any. - **message_count** (integer) - The number of messages in the conversation. - **created_at** (string) - The timestamp when the conversation was created. - **updated_at** (string) - The timestamp when the conversation was last updated. - **user_id** (string) - The ID of the user who owns the conversation. #### Response Example ```json [ { "id": "conv_1111111111", "title": "General Questions", "page_id": null, "message_count": 15, "created_at": "2025-01-10T08:00:00Z", "updated_at": "2025-01-15T09:45:00Z", "user_id": "1234567890123456" }, { "id": "conv_2222222222", "title": "Bug Investigation", "page_id": "page_5555555555", "message_count": 8, "created_at": "2025-01-14T14:20:00Z", "updated_at": "2025-01-15T10:15:00Z", "user_id": "1234567890123456" } ] ``` ``` -------------------------------- ### Environment Configuration Variables Source: https://context7.com/nemo-docs/attd/llms.txt This section lists essential environment variables required for setting up the backend, frontend, and MCP server components of the Attd project. These variables cover API keys, database connections, storage details, and server URLs. ```bash # Backend .env OPENROUTER_API_KEY="sk-or-v1-..." MONGODB_URI="mongodb://localhost:27017" DB_NAME="attd_db" PARENT_DIR="/var/repos" AWS_ACCESS_KEY_ID="AKIA..." AWS_SECRET_ACCESS_KEY="..." AWS_REGION="us-east-1" S3_BUCKET_NAME="attd-repos" FRONTEND_BASE_URL="http://localhost:3000" LANGFUSE_SECRET_KEY="sk-lf-..." LANGFUSE_PUBLIC_KEY="pk-lf-..." LANGFUSE_BASE_URL="https://cloud.langfuse.com" CLERK_SECRET_KEY="sk_live_..." ``` -------------------------------- ### Create Documentation Page via cURL Source: https://context7.com/nemo-docs/attd/llms.txt Shows how to create a new documentation page with title and optional markdown content for a specific user. Requires a user ID and JWT token for authorization. Returns the created page details. ```bash curl -X POST http://localhost:8000/api/pages/create \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" \ -d '{ "user_id": "1234567890123456", "title": "API Architecture", "content": "# API Architecture\n\nThis document describes..." }' # Response: # { # "page": { # "id": "page_9876543210", # "user_id": "1234567890123456", # "title": "API Architecture", # "content": "# API Architecture\n\nThis document describes...", # "created_at": "2025-01-15T10:30:00Z", # "updated_at": "2025-01-15T10:30:00Z" # }, # "message": "Page created successfully" # } ``` -------------------------------- ### POST /api/git-repo/create Source: https://context7.com/nemo-docs/attd/llms.txt This endpoint clones a GitHub repository, uploads it to S3, and generates initial documentation including project introduction, data flow diagram, and file explanations. It requires authentication via Clerk JWT token. The response provides a unique repo_hash for further interactions. ```APIDOC ## POST /api/git-repo/create ### Description Create a new repository entry by cloning from GitHub, uploading to S3, and generating initial documentation with project intro, data flow diagram, and file explanations. ### Method POST ### Endpoint /api/git-repo/create ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **github_url** (string) - Required - The GitHub repository URL to clone. ### Request Example { "github_url": "https://github.com/username/repository" } ### Response #### Success Response (200) - **repo_hash** (string) - Unique hash for the repository. - **github_url** (string) - The provided GitHub URL. - **name** (string) - Repository name. #### Response Example { "repo_hash": "a1b2c3d4e5f6...", "github_url": "https://github.com/username/repository", "name": "repository" } ``` -------------------------------- ### POST /api/pages/create Source: https://context7.com/nemo-docs/attd/llms.txt Creates a new documentation page. Allows specifying a title and optional markdown content for a new page associated with a user. ```APIDOC ## POST /api/pages/create ### Description Creates a new documentation page. Allows specifying a title and optional markdown content for a new page associated with a user. ### Method POST ### Endpoint /api/pages/create ### Parameters #### Request Body - **user_id** (string) - Required - The ID of the user for whom the page is created. - **title** (string) - Required - The title of the new documentation page. - **content** (string) - Optional - The markdown content for the documentation page. ### Request Example ```json { "user_id": "1234567890123456", "title": "API Architecture", "content": "# API Architecture\n\nThis document describes..." } ``` ### Response #### Success Response (200) - **page** (object) - Contains the details of the created page: - **id** (string) - The unique identifier for the new page. - **user_id** (string) - The ID of the user who owns the page. - **title** (string) - The title of the page. - **content** (string) - The markdown content of the page. - **created_at** (string) - The timestamp when the page was created. - **updated_at** (string) - The timestamp when the page was last updated. - **message** (string) - A confirmation message indicating successful page creation. #### Response Example ```json { "page": { "id": "page_9876543210", "user_id": "1234567890123456", "title": "API Architecture", "content": "# API Architecture\n\nThis document describes...", "created_at": "2025-01-15T10:30:00Z", "updated_at": "2025-01-15T10:30:00Z" }, "message": "Page created successfully" } ``` ``` -------------------------------- ### MCP Server Page Management (TypeScript SDK) Source: https://context7.com/nemo-docs/attd/llms.txt Shows how to integrate with the Model Context Protocol (MCP) server using its TypeScript SDK to manage documentation pages. ```APIDOC ## MCP Server Page Management (TypeScript SDK) ### Description Use Model Context Protocol tools to manage pages from AI assistants with authenticated context. ### Usage Instantiate the MCP client, connect to the server, and then use `callTool` to perform operations like creating, retrieving, or listing pages. ### Code Example ```typescript // MCP client integration example import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/transports/stdio.js"; const client = new Client({ name: "attd-client", version: "1.0.0" }, { capabilities: { tools: {} } }); // Connect to MCP server with authentication await client.connect(new StdioClientTransport({ command: "python", args: ["mcp/main.py"], env: { ...process.env, CLERK_SECRET_KEY: "your_clerk_secret" // Replace with your actual secret key } })); // Create page via MCP const createResult = await client.callTool({ name: "create_page", arguments: { title: "Architecture Overview", content: "# Architecture\n\nThis system uses..." } }); console.log('Page created:', createResult); // Get all pages const pages = await client.callTool({ name: "get_all_pages", arguments: {} }); console.log('All pages:', pages); // Get specific page const page = await client.callTool({ name: "get_page_by_id", arguments: { page_id: "page_1234567890" // Replace with a valid page ID } }); console.log('Specific page:', page); ``` ### Key MCP Tools - **create_page**: Creates a new documentation page. - **get_all_pages**: Retrieves a list of all available pages. - **get_page_by_id**: Retrieves a specific page using its ID. ``` -------------------------------- ### Register User using REST API Source: https://context7.com/nemo-docs/attd/llms.txt This code demonstrates how to register a new user or ensure a user exists in the system using a POST request to the `/api/user/register` endpoint. It requires authentication and sends a 16-digit `user_id` in the JSON request body for multi-tenancy support. The response confirms successful registration and provides user details. ```bash curl -X POST http://localhost:8000/api/user/register \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" \ -d '{ "user_id": "1234567890123456" }' ``` -------------------------------- ### List All Pages via cURL Source: https://context7.com/nemo-docs/attd/llms.txt Demonstrates how to retrieve all documentation pages for a user with pagination support. Requires a user ID and JWT token for authorization. Returns an array of page objects with metadata. ```bash curl -X GET "http://localhost:8000/api/pages/?user_id=1234567890123456" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" # Response: # { # "pages": [ # { # "id": "page_1111111111", # "user_id": "1234567890123456", # "title": "Getting Started", # "content": "# Getting Started\n\n...", # "created_at": "2025-01-10T08:00:00Z", # "updated_at": "2025-01-12T14:30:00Z" # } # ], # "total_count": 1 # } ``` -------------------------------- ### POST /api/inline-qna/answer Source: https://context7.com/nemo-docs/attd/llms.txt Provides contextual AI answers based on cursor position within a documentation editor for inline assistance. ```APIDOC ## POST /api/inline-qna/answer ### Description Get contextual AI answers based on cursor position within a documentation editor for inline assistance. ### Method POST ### Endpoint `/api/inline-qna/answer` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **text** (string) - Required - The text content from the editor, including the current context. - **cursor_position** (integer) - Required - The current cursor position within the text. - **page_id** (string) - Required - The identifier of the page being edited. ### Request Example ```json { "text": "The authentication system uses JWT tokens. How do refresh tokens work?", "cursor_position": 45, "page_id": "page_9876543210" } ``` ### Response #### Success Response (200) - **answer** (string) - The AI-generated answer based on the provided context. #### Response Example ```json { "answer": "Refresh tokens work by allowing users to obtain new access tokens..." } ``` ``` -------------------------------- ### Frontend and Backend Environment Variables Source: https://context7.com/nemo-docs/attd/llms.txt Environment variables for frontend and backend configurations. Includes API keys, base URLs, and server ports. These are typically loaded from .env files. ```dotenv NEXT_PUBLIC_BACKEND_BASE_URL="http://localhost:8000" NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_live_..." CLERK_SECRET_KEY="sk_live_..." NEXT_PUBLIC_JWT_TEMPLATE_API_KEY="your_jwt_template" BACKEND_BASE_URL="http://localhost:8000" FRONTEND_BASE_URL="http://localhost:3000" CLERK_SECRET_KEY="sk_live_..." PORT=8080 ``` -------------------------------- ### Frontend API Integration (TypeScript Client) Source: https://context7.com/nemo-docs/attd/llms.txt Demonstrates how to use the provided TypeScript API client for type-safe backend communication, including cloning repositories, fetching data, and initiating chats. ```APIDOC ## Frontend API Integration (TypeScript Client) ### Description Use the TypeScript API client for type-safe backend communication with automatic error handling and request formatting. ### Usage Import the necessary API modules and use their methods for interacting with the backend. Error handling is built-in. ### Code Example ```typescript import { repoApi, chatQaApi, pageApi } from '@/lib/api'; // Clone a repository try { const result = await repoApi.createRepo({ github_url: 'https://github.com/username/repository' }); if ('error' in result) { console.error('Failed to clone repo:', result.error); } else { console.log('Repository cloned:', result.repo_hash); // Get repository documentation const repoData = await repoApi.getRepo(result.repo_hash); console.log('Project intro:', repoData.project_intro); // Start a chat about the repository const chatResponse = await chatQaApi.sendMessage({ message: 'What are the main features?', repoHash: result.repo_hash, userId: '1234567890123456', thinkLevel: 'simple' }); console.log('AI response:', chatResponse.response); } } catch (error) { // Handle potential API errors (e.g., network issues, server errors) if (error instanceof ApiError) { console.error(`API Error ${error.status}:`, error.message); } else { console.error('An unexpected error occurred:', error); } } ``` ### Key Components - **repoApi**: For repository-related operations (cloning, fetching). - **chatQaApi**: For interacting with the AI chat functionality. - **pageApi**: For documentation page management (not shown in example). - **ApiError**: A custom error class for handling API-specific errors. ``` -------------------------------- ### POST /api/user/register Source: https://context7.com/nemo-docs/attd/llms.txt Registers a new user in the system, ensuring they have a 16-digit ID for multi-tenancy support. ```APIDOC ## POST /api/user/register ### Description Ensure a user exists in the system with a 16-digit ID for multi-tenancy support. ### Method POST ### Endpoint `/api/user/register` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **user_id** (string) - Required - A 16-digit unique identifier for the user. ### Request Example ```json { "user_id": "1234567890123456" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating successful user registration. - **user** (object) - Details of the registered user. - **user_id** (string) - The user's unique identifier. - **created_at** (string) - Timestamp of user creation. - **updated_at** (string) - Timestamp of last user update. #### Response Example ```json { "message": "User registered successfully", "user": { "user_id": "1234567890123456", "created_at": "2025-01-15T10:30:00Z", "updated_at": "2025-01-15T10:30:00Z" } } ``` ``` -------------------------------- ### Create New Conversation via cURL Source: https://context7.com/nemo-docs/attd/llms.txt Demonstrates how to initialize a new chat conversation with optional title and page context. Requires a user ID and JWT token for authorization. Returns conversation details including ID and timestamps. ```bash curl -X POST http://localhost:8000/api/chat-qa/conversation \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" \ -d '{ "title": "Architecture Discussion", "page_id": "page_5555555555", "user_id": "1234567890123456" }' # Response: # { # "id": "conv_1234567890", # "title": "Architecture Discussion", # "page_id": "page_5555555555", # "message_count": 0, # "created_at": "2025-01-15T10:30:00Z", # "updated_at": "2025-01-15T10:30:00Z", # "user_id": "1234567890123456" # } ``` -------------------------------- ### POST /api/chat-qa/conversation Source: https://context7.com/nemo-docs/attd/llms.txt Initializes a new chat conversation. It allows setting an optional title and page context for organizing related messages within a user's session. ```APIDOC ## POST /api/chat-qa/conversation ### Description Initializes a new chat conversation. It allows setting an optional title and page context for organizing related messages within a user's session. ### Method POST ### Endpoint /api/chat-qa/conversation ### Parameters #### Request Body - **title** (string) - Optional - The title for the new conversation. - **page_id** (string) - Optional - The ID of the page associated with this conversation. - **user_id** (string) - Required - The ID of the user initiating the conversation. ### Request Example ```json { "title": "Architecture Discussion", "page_id": "page_5555555555", "user_id": "1234567890123456" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the newly created conversation. - **title** (string) - The title of the conversation. - **page_id** (string) - The ID of the associated page, if provided. - **message_count** (integer) - The number of messages in the conversation (initially 0). - **created_at** (string) - The timestamp when the conversation was created. - **updated_at** (string) - The timestamp when the conversation was last updated. - **user_id** (string) - The ID of the user who owns the conversation. #### Response Example ```json { "id": "conv_1234567890", "title": "Architecture Discussion", "page_id": "page_5555555555", "message_count": 0, "created_at": "2025-01-15T10:30:00Z", "updated_at": "2025-01-15T10:30:00Z", "user_id": "1234567890123456" } ``` ``` -------------------------------- ### POST /api/chat-qa/message Source: https://context7.com/nemo-docs/attd/llms.txt This endpoint sends a message to the AI chat system for contextual responses based on repository analysis. It supports conversation threading, repo-specific context, and optional code mentions. Authentication via Clerk JWT is required; responses include AI-generated explanations and token usage. ```APIDOC ## POST /api/chat-qa/message ### Description Send a message to the intelligent chat system with optional conversation context, repository hash, and code mentions for contextual AI responses. ### Method POST ### Endpoint /api/chat-qa/message ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **message** (string) - Required - The user's query or message. - **conversation_id** (string) - Optional - ID for conversation threading. - **repo_hash** (string) - Optional - Repository hash for context. - **diagram_mode** (boolean) - Optional - Enable diagram generation (default: false). - **think_level** (string) - Optional - Response detail level (e.g., "detailed", "simple"). - **user_id** (string) - Optional - User identifier. ### Request Example { "message": "Explain the authentication flow in this project", "conversation_id": "conv_1234567890", "repo_hash": "a1b2c3d4e5f6", "diagram_mode": false, "think_level": "detailed", "user_id": "1234567890123456" } ### Response #### Success Response (200) - **id** (string) - Message ID. - **message** (string) - Original message. - **response** (string) - AI-generated response. - **conversation_id** (string) - Conversation ID. - **page_id** (string or null) - Page context ID. - **diagram_mode** (boolean) - Diagram mode flag. - **model_used** (string) - AI model used. - **tokens_used** (integer) - Tokens consumed. - **created_at** (string) - Timestamp. - **user_id** (string) - User ID. #### Response Example { "id": "msg_9876543210", "message": "Explain the authentication flow in this project", "response": "The authentication flow uses JWT tokens with Clerk...", "conversation_id": "conv_1234567890", "page_id": null, "diagram_mode": false, "model_used": "anthropic/claude-3.7-sonnet", "tokens_used": 1250, "created_at": "2025-01-15T10:30:00Z", "user_id": "1234567890123456" } ``` -------------------------------- ### Query with Code Mentions in TypeScript Source: https://context7.com/nemo-docs/attd/llms.txt Demonstrates how to send a message with code mentions to the chat API. The message references specific functions or classes with @mentions, and includes their definitions for precise responses. Requires a conversation ID, repository hash, and user ID. ```typescript import { chatQaApi } from '@/lib/api'; const response = await chatQaApi.sendMessage({ message: "How does @parseFileContent work with @FileParser?", conversationId: "conv_1234567890", repoHash: "a1b2c3d4e5f6", userId: "1234567890123456", mentionedDefinations: [ { node_name: "parseFileContent", file_name: "src/parser.py", start_end_lines: [45, 78], node_type: "function" }, { node_name: "FileParser", file_name: "src/parser.py", start_end_lines: [12, 43], node_type: "class" } ] }); console.log(response.response); // "The parseFileContent function works with the FileParser class by..." ``` -------------------------------- ### PUT /api/pages/{page_id} Source: https://context7.com/nemo-docs/attd/llms.txt Updates the title or content of an existing documentation page. Supports partial updates. ```APIDOC ## PUT /api/pages/{page_id} ### Description Modifies an existing page's title or content with partial updates supported. ### Method PUT ### Endpoint `/api/pages/{page_id}` ### Parameters #### Path Parameters - **page_id** (string) - Required - The unique identifier of the page to update. - **user_id** (string) - Required - The unique identifier of the user associated with the page. #### Query Parameters None #### Request Body - **title** (string) - Optional - The new title for the page. - **content** (string) - Optional - The new content for the page. ### Request Example ```json { "title": "Updated API Architecture", "content": "# Updated API Architecture\n\nRevised documentation..." } ``` ### Response #### Success Response (200) - **page** (object) - Contains the updated page details. - **id** (string) - The page ID. - **user_id** (string) - The user ID associated with the page. - **title** (string) - The updated title of the page. - **content** (string) - The updated content of the page. - **created_at** (string) - Timestamp of page creation. - **updated_at** (string) - Timestamp of last page update. - **message** (string) - Confirmation message. #### Response Example ```json { "page": { "id": "page_9876543210", "user_id": "1234567890123456", "title": "Updated API Architecture", "content": "# Updated API Architecture\n\nRevised documentation...", "created_at": "2025-01-15T10:30:00Z", "updated_at": "2025-01-15T11:00:00Z" }, "message": "Page updated successfully" } ``` ``` -------------------------------- ### List All Conversations via cURL Source: https://context7.com/nemo-docs/attd/llms.txt Shows how to retrieve all conversations for a specific user with metadata including message counts and timestamps. Requires a user ID and JWT token for authorization. ```bash curl -X GET "http://localhost:8000/api/chat-qa/conversations?user_id=1234567890123456" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" # Response: # [ # { # "id": "conv_1111111111", # "title": "General Questions", # "page_id": null, # "message_count": 15, # "created_at": "2025-01-10T08:00:00Z", # "updated_at": "2025-01-15T09:45:00Z", # "user_id": "1234567890123456" # }, # { # "id": "conv_2222222222", # "title": "Bug Investigation", # "page_id": "page_5555555555", # "message_count": 8, # "created_at": "2025-01-14T14:20:00Z", # "updated_at": "2025-01-15T10:15:00Z", # "user_id": "1234567890123456" # } # ] ``` -------------------------------- ### POST /api/chat-qa/sendMessage Source: https://context7.com/nemo-docs/attd/llms.txt Sends a message to the chat QA API. It supports referencing specific code definitions using @mentions to receive code-aware responses, including line numbers and file locations. ```APIDOC ## POST /api/chat-qa/sendMessage ### Description Sends a message to the chat QA API. It supports referencing specific code definitions using @mentions to receive code-aware responses, including line numbers and file locations. ### Method POST ### Endpoint /api/chat-qa/sendMessage ### Parameters #### Request Body - **message** (string) - Required - The user's message content. - **conversationId** (string) - Required - The ID of the ongoing conversation. - **repoHash** (string) - Required - The hash identifier for the repository context. - **userId** (string) - Required - The ID of the user sending the message. - **mentionedDefinations** (array) - Optional - A list of code definitions being referenced in the message: - **node_name** (string) - Required - The name of the code definition (function, class, etc.). - **file_name** (string) - Required - The name of the file where the definition is located. - **start_end_lines** (array) - Required - An array containing the start and end line numbers. - **node_type** (string) - Required - The type of the code definition (e.g., 'function', 'class'). ### Request Example ```json { "message": "How does @parseFileContent work with @FileParser?", "conversationId": "conv_1234567890", "repoHash": "a1b2c3d4e5f6", "userId": "1234567890123456", "mentionedDefinations": [ { "node_name": "parseFileContent", "file_name": "src/parser.py", "start_end_lines": [45, 78], "node_type": "function" }, { "node_name": "FileParser", "file_name": "src/parser.py", "start_end_lines": [12, 43], "node_type": "class" } ] } ``` ### Response #### Success Response (200) - **response** (string) - The AI's response to the user's message, potentially including code-aware information. #### Response Example ```json { "response": "The parseFileContent function works with the FileParser class by..." } ``` ``` -------------------------------- ### Update Page Content using REST API Source: https://context7.com/nemo-docs/attd/llms.txt This snippet demonstrates how to update an existing page's title or content using a PUT request to the `/api/pages/{page_id}` endpoint. It requires authentication via a JWT token and specifies the `Content-Type` as JSON. The request body contains the fields to be updated, and the response includes the updated page details. ```bash curl -X PUT "http://localhost:8000/api/pages/page_9876543210?user_id=1234567890123456" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_CLERK_JWT_TOKEN" \ -d '{ "title": "Updated API Architecture", "content": "# Updated API Architecture\n\nRevised documentation..." }' ``` -------------------------------- ### React Chat Hook for Chat Management Source: https://context7.com/nemo-docs/attd/llms.txt A custom React hook `useChat` to manage chat state, parse commands, extract mentions, and handle auto-scrolling. It requires repository hash and user ID as initial parameters. ```typescript import { useChat } from '@/hooks/useChat'; function ChatInterface() { const { messages, input, setInput, isLoading, error, sendMessage, suggestedPrompts, conversationId, createNewConversation } = useChat({ repoHash: 'a1b2c3d4e5f6', userId: '1234567890123456' }); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // Check for canvas command: "explain auth /canvas" const { isCanvas, text } = parseCanvasCommand(input); if (isCanvas) { // Open side-by-side editor with explanation openCanvasEditor(text); } else { await sendMessage(text); } }; return (