82e8c8905b
* feat: replace agent_type with agent_profile_id - Replace agent_type field with agent_profile_id across backend and frontend - Add ProfileResolver interface and StoreProfileResolver implementation - Update task creation/update to use agent_profile_id - Change default agent runtime from docker to standalone - Fix workspace state types to include all required fields - Fix websocket handlers type mismatches for environments, executors, workspaces - Update integration tests to use agent_profile_id * feat: pass model as CLI argument to agents - Add ModelFlag field to AgentTypeConfig for specifying the CLI flag - Set ModelFlag to '--model' for all agents (auggie, claude, codex, gemini, opencode, copilot) - Update launchStandalone to append model flag to agent command - Update launchDocker/buildContainerConfig to append model flag to container command - Model is passed when both agent supports ModelFlag and profile has Model configured * fix: make WebSocket message handling async to prevent blocking When a long-running handler like orchestrator.prompt was executing, it blocked the ReadPump loop, preventing other requests (like workspace.tree.get) from being processed until the handler completed. Now each message is handled in its own goroutine, allowing concurrent message handling so file tree requests work while the agent is working. * feat: show task description as first message in chat - Add 'Task' label with distinct styling (lighter background, border) - Pass taskDescription from page to TaskChatPanel component - Differentiate from regular user messages visually
161 lines
4.7 KiB
Go
161 lines
4.7 KiB
Go
// Package controller provides the business logic coordination layer for the orchestrator.
|
|
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/kandev/kandev/internal/orchestrator"
|
|
"github.com/kandev/kandev/internal/orchestrator/dto"
|
|
)
|
|
|
|
// Controller coordinates orchestrator business logic
|
|
type Controller struct {
|
|
service *orchestrator.Service
|
|
}
|
|
|
|
// NewController creates a new orchestrator controller
|
|
func NewController(svc *orchestrator.Service) *Controller {
|
|
return &Controller{
|
|
service: svc,
|
|
}
|
|
}
|
|
|
|
// GetStatus returns the orchestrator status
|
|
func (c *Controller) GetStatus(ctx context.Context, req dto.GetStatusRequest) (dto.StatusResponse, error) {
|
|
status := c.service.GetStatus()
|
|
return dto.StatusResponse{
|
|
Running: status.Running,
|
|
ActiveAgents: status.ActiveAgents,
|
|
QueuedTasks: status.QueuedTasks,
|
|
MaxConcurrent: 0, // Not available from service Status; would need scheduler access
|
|
}, nil
|
|
}
|
|
|
|
// GetQueue returns the queued tasks
|
|
func (c *Controller) GetQueue(ctx context.Context, req dto.GetQueueRequest) (dto.QueueResponse, error) {
|
|
queuedTasks := c.service.GetQueuedTasks()
|
|
|
|
tasks := make([]dto.QueuedTaskDTO, 0, len(queuedTasks))
|
|
for _, qt := range queuedTasks {
|
|
tasks = append(tasks, dto.QueuedTaskDTO{
|
|
TaskID: qt.TaskID,
|
|
Priority: qt.Priority,
|
|
QueuedAt: qt.QueuedAt.Format("2006-01-02T15:04:05Z"),
|
|
})
|
|
}
|
|
|
|
return dto.QueueResponse{
|
|
Tasks: tasks,
|
|
Total: len(tasks),
|
|
}, nil
|
|
}
|
|
|
|
// TriggerTask triggers a task for execution
|
|
func (c *Controller) TriggerTask(ctx context.Context, req dto.TriggerTaskRequest) (dto.TriggerTaskResponse, error) {
|
|
// For now, just return success - the service would need task details
|
|
return dto.TriggerTaskResponse{
|
|
Success: true,
|
|
Message: "Task triggered",
|
|
TaskID: req.TaskID,
|
|
}, nil
|
|
}
|
|
|
|
// StartTask starts task execution
|
|
func (c *Controller) StartTask(ctx context.Context, req dto.StartTaskRequest) (dto.StartTaskResponse, error) {
|
|
execution, err := c.service.StartTask(ctx, req.TaskID, req.AgentProfileID, req.Priority)
|
|
if err != nil {
|
|
return dto.StartTaskResponse{}, err
|
|
}
|
|
|
|
resp := dto.StartTaskResponse{
|
|
Success: true,
|
|
TaskID: execution.TaskID,
|
|
AgentInstanceID: execution.AgentInstanceID,
|
|
Status: string(execution.Status),
|
|
}
|
|
|
|
// Include worktree info if available
|
|
if execution.WorktreePath != "" {
|
|
resp.WorktreePath = &execution.WorktreePath
|
|
}
|
|
if execution.WorktreeBranch != "" {
|
|
resp.WorktreeBranch = &execution.WorktreeBranch
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
// StopTask stops task execution
|
|
func (c *Controller) StopTask(ctx context.Context, req dto.StopTaskRequest) (dto.SuccessResponse, error) {
|
|
reason := req.Reason
|
|
if reason == "" {
|
|
reason = "stopped via API"
|
|
}
|
|
|
|
if err := c.service.StopTask(ctx, req.TaskID, reason, req.Force); err != nil {
|
|
return dto.SuccessResponse{}, err
|
|
}
|
|
|
|
return dto.SuccessResponse{Success: true}, nil
|
|
}
|
|
|
|
// PromptTask sends a prompt to a running task
|
|
func (c *Controller) PromptTask(ctx context.Context, req dto.PromptTaskRequest) (dto.PromptTaskResponse, error) {
|
|
result, err := c.service.PromptTask(ctx, req.TaskID, req.Prompt)
|
|
if err != nil {
|
|
return dto.PromptTaskResponse{}, err
|
|
}
|
|
|
|
return dto.PromptTaskResponse{
|
|
Success: true,
|
|
StopReason: result.StopReason,
|
|
}, nil
|
|
}
|
|
|
|
// CompleteTask marks a task as complete
|
|
func (c *Controller) CompleteTask(ctx context.Context, req dto.CompleteTaskRequest) (dto.CompleteTaskResponse, error) {
|
|
if err := c.service.CompleteTask(ctx, req.TaskID); err != nil {
|
|
return dto.CompleteTaskResponse{}, err
|
|
}
|
|
|
|
return dto.CompleteTaskResponse{
|
|
Success: true,
|
|
Message: "task completed",
|
|
}, nil
|
|
}
|
|
|
|
// RespondToPermission responds to a permission request
|
|
func (c *Controller) RespondToPermission(ctx context.Context, req dto.PermissionRespondRequest) (dto.PermissionRespondResponse, error) {
|
|
if err := c.service.RespondToPermission(ctx, req.TaskID, req.PendingID, req.OptionID, req.Cancelled); err != nil {
|
|
return dto.PermissionRespondResponse{}, err
|
|
}
|
|
|
|
return dto.PermissionRespondResponse{
|
|
Success: true,
|
|
TaskID: req.TaskID,
|
|
PendingID: req.PendingID,
|
|
}, nil
|
|
}
|
|
|
|
// GetTaskExecution returns the execution state for a task
|
|
func (c *Controller) GetTaskExecution(ctx context.Context, req dto.GetTaskExecutionRequest) (dto.TaskExecutionResponse, error) {
|
|
execution, exists := c.service.GetTaskExecution(req.TaskID)
|
|
if !exists {
|
|
return dto.TaskExecutionResponse{
|
|
HasExecution: false,
|
|
TaskID: req.TaskID,
|
|
}, nil
|
|
}
|
|
|
|
return dto.TaskExecutionResponse{
|
|
HasExecution: true,
|
|
TaskID: execution.TaskID,
|
|
AgentInstanceID: execution.AgentInstanceID,
|
|
AgentProfileID: execution.AgentProfileID,
|
|
Status: string(execution.Status),
|
|
Progress: execution.Progress,
|
|
StartedAt: execution.StartedAt.Format("2006-01-02T15:04:05Z"),
|
|
}, nil
|
|
}
|
|
|