Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Endpoints to Manage Chat History #2154

Closed
6 tasks
Tracked by #2142
humansinstitute opened this issue Dec 11, 2024 · 3 comments · Fixed by #2156
Closed
6 tasks
Tracked by #2142

Generate Endpoints to Manage Chat History #2154

humansinstitute opened this issue Dec 11, 2024 · 3 comments · Fixed by #2156
Assignees
Labels

Comments

@humansinstitute
Copy link
Contributor

humansinstitute commented Dec 11, 2024

Add Chat Management Endpoints and Handlers

Description

Add endpoints and handlers to manage Chat and ChatMessage entities, following existing patterns in the codebase. The endpoints will provide operations for chat creation, message sending, history retrieval, and response processing.

Implementation Details

1. Update routes/chat.go

// Add routes for chat management
func ChatRoutes() chi.Router {
    r := chi.NewRouter()
    chatHandler := handlers.NewChatHandler(http.DefaultClient, db.DB)

    // Public endpoint
    r.Post("/response", chatHandler.ProcessChatResponse)

    // Protected routes
    r.Group(func(r chi.Router) {
        r.Use(auth.PubKeyContext)
        r.Post("/", chatHandler.CreateChat)
        r.Post("/send", chatHandler.SendMessage)
        r.Get("/history/{uuid}", chatHandler.GetChatHistory)
    })

    return r
}

2. Add Handler Functions in handlers/chat.go

  • Implement NewChatHandler constructor
  • Add ChatResponse struct for consistent response formatting
  • Add handler functions:
    • CreateChat: Create new chat sessions
    • SendMessage: Send messages to stakwork (stub out)
    • GetChatHistory: Retrieve chat history
    • ProcessChatResponse: Handle Stakwork responses (stub out)

3. Use DB Interface in db/chat.go

type ChatDB interface {
    AddChat(chat *Chat) (Chat, error)
    GetChatByChatID(chatID string) (Chat, error)
    AddChatMessage(message *ChatMessage) (ChatMessage, error)
    GetChatMessagesForChatID(chatID string) ([]ChatMessage, error)
}

Required Features

  • Chat creation with workspace association
  • Message sending with Stakwork integration
  • Chat history retrieval
  • Stakwork response processing
  • WebSocket notifications for real-time updates
  • Proper error handling and status codes
  • Authorization checks

Task List

  1. Update database functions in db/chat.go
  2. Create chat routes in routes/chat.go
  3. Implement handler functions in handlers/chat.go
  4. Add proper error handling and response formatting
  5. Implement Stakwork integration
  6. Add WebSocket notification support
  7. Test all endpoints with authorization

Acceptance Criteria

  • All endpoints are implemented and accessible
  • Handler functions properly integrate with DB functions
  • Authorization is properly checked
  • Error handling follows existing patterns
  • Status codes match REST conventions
  • Stakwork integration is stubbed out

API Endpoints

POST /chat

Create a new chat session

Request:
{
    "workspaceId": "string",
    "title": "string"
}

Response:
{
    "success": true,
    "message": "Chat created successfully",
    "data": {
        "id": "string",
        "workspaceId": "string",
        "title": "string",
        "createdAt": "timestamp",
        "updatedAt": "timestamp"
    }
}

POST /chat/send

Send a message in an existing chat

Request:
{
    "chatId": "string",
    "message": "string",
    "contextTags": [
        {
            "type": "string",
            "id": "string"
        }
    ]
}

Response:
{
    "success": true,
    "message": "Message sent successfully",
    "data": {
        "id": "string",
        "chatId": "string",
        "message": "string",
        "role": "user",
        "timestamp": "timestamp",
        "status": "sending"
    }
}

GET /chat/history/{uuid}

Retrieve chat history

Response:
{
    "success": true,
    "data": [
        {
            "id": "string",
            "chatId": "string",
            "message": "string",
            "role": "string",
            "timestamp": "timestamp",
            "contextTags": [],
            "status": "string",
            "source": "string"
        }
    ]
}

POST /chat/response

Process Stakwork responses (public endpoint)

Request:
{
    "chatId": "string",
    "message": "string"
}

Response:
200 OK
@AhsanFarooqDev
Copy link
Contributor

@humansinstitute can i help?

@Shoaibdev7
Copy link
Contributor

@humansinstitute Please assign me?

@MahtabBukhari
Copy link
Contributor

@humansinstitute assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants