API Fixes and Store Updates Summary
Issues Fixed
1. API Endpoint Mismatches (404 Errors)
The web application was failing with 404 errors because the frontend was calling API endpoints that didn't exist in the backend. For example:
GET /api/projects/{id}/agents- 404 (doesn't exist)
2. WebSocket Connection Failures (500 Error)
WebSocket handshake was failing with HTTP 500 error due to nil pointer dereference in client registration.
Root Cause
Mismatch between frontend API calls and backend route definitions:
- Backend uses query parameters for filtering (e.g.,
/api/agents?project_id=xxx) - Frontend was using nested resource routes (e.g.,
/api/projects/{id}/agents)
Changes Made
Backend Changes (Go)
1. Updated Task Handler (internal/handlers/tasks.go)
- Modified
ListTasksto support optional query parameters instead of requiringproject_id - Now supports filtering by:
project_id- filter tasks by projectagent_id- filter tasks by assigned agentstatus- filter tasks by status
- Returns all tasks if no filters are provided
2. Added Missing Handlers
GetAgent(internal/handlers/agents.go) - Get single agent by IDUpdateTaskStatus(internal/handlers/tasks.go) - Update only task status
3. Updated Routes (cmd/server/main.go)
Added missing route registrations:
// Agents
api.HandleFunc("/agents/{id}", agentHandler.GetAgent).Methods("GET")
// Tasks
api.HandleFunc("/tasks/{id}/status", taskHandler.UpdateTaskStatus).Methods("PUT")
Frontend Changes (JavaScript/Vue)
1. API Service (web/src/services/api.js)
Fixed all endpoint paths to match backend routes:
Before:
getProjectAgents(projectId) {
return api.get(`/projects/${projectId}/agents`)
}
getProjectTasks(projectId) {
return api.get(`/projects/${projectId}/tasks`)
}
After:
getProjectAgents(projectId) {
return api.get('/agents', { params: { project_id: projectId } })
}
getProjectTasks(projectId) {
return api.get('/tasks', { params: { project_id: projectId } })
}
Added missing CRUD methods:
updateProject(id, data)/deleteProject(id)updateAgent(id, data)/deleteAgent(id)updateTask(id, data)/deleteTask(id)
2. Store Updates
Project Store (web/src/stores/projectStore.js)
- Added
updateProjectanddeleteProjectactions - Added
clearErrorhelper - Improved error handling with proper error messages
- Return values from async actions for better component integration
Agent Store (web/src/stores/agentStore.js)
- Added
currentAgentstate - Added
fetchAgentaction for single agent retrieval - Added
updateAgentanddeleteAgentactions - Updated
fetchAgentsto accept optionalprojectIdparameter - Improved
updateAgentStatusto update both local state and current agent - Added
clearErrorhelper
Task Store (web/src/stores/taskStore.js)
- Added
currentTaskstate - Added
fetchTaskaction for single task retrieval - Updated
fetchTasksto accept optional filter parameters - Added
updateTaskanddeleteTaskactions - Improved
updateTaskStatusto update both local state and current task - Added
clearErrorhelper
Context Store (web/src/stores/contextStore.js)
- Improved error handling and logging
- Better state synchronization for current context
- Added
clearErrorhelper
API Endpoint Reference
Correct Endpoint Usage
Projects
GET /api/projects- List all projectsGET /api/projects/{id}- Get single projectPOST /api/projects- Create project
Agents
GET /api/agents- List all agentsGET /api/agents?project_id={id}- List agents for a projectGET /api/agents/{id}- Get single agentPOST /api/agents- Create agentPUT /api/agents/{id}/status- Update agent status
Tasks
GET /api/tasks- List all tasksGET /api/tasks?project_id={id}- List tasks for a projectGET /api/tasks?agent_id={id}- List tasks for an agentGET /api/tasks?status={status}- List tasks by statusGET /api/tasks/{id}- Get single taskPOST /api/tasks- Create taskPUT /api/tasks/{id}- Update task (full update)PUT /api/tasks/{id}/status- Update task status only
Contexts
GET /api/contexts- List all contextsGET /api/contexts?project_id={id}- List contexts for a projectGET /api/contexts/{id}- Get single contextPOST /api/contexts- Create contextPUT /api/contexts/{id}- Update contextDELETE /api/contexts/{id}- Delete context
Testing
To verify the fixes:
-
Start the backend:
cd c:\Sources\GitHub\agent-shaker .\bin\mcp-server.exe -
Start the frontend:
cd c:\Sources\GitHub\agent-shaker\web npm run dev -
Test key endpoints:
- Navigate to projects page and create a project
- View project details - should load agents without 404 errors
- Create an agent for the project
- View agents list filtered by project
- Create tasks and assign to agents
- Update task statuses
Benefits
- Consistency - Frontend and backend now use the same API contract
- Flexibility - Backend supports multiple filtering strategies
- Better Error Handling - All stores now properly catch, log, and report errors
- Complete CRUD - All stores support full Create, Read, Update, Delete operations
- State Management - Improved synchronization between list views and detail views
- Developer Experience - Clear error messages in console for debugging
Breaking Changes
None - these are bug fixes to align with the existing backend implementation.
Next Steps
Consider adding:
- API documentation generation (Swagger/OpenAPI)
- Integration tests for all endpoints
- Frontend validation before API calls
- Optimistic UI updates with rollback on error
- Request/response interceptors for auth tokens