handler

package
v0.0.0-...-7fc3621 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler contains all HTTP handlers for the agent API.

func New

func New(agentCwd string, conversations *agent.ConversationManager, hookManager *hooks.Manager, serviceManager *services.Manager, defaultAgent *agentimpl.DefaultAgent, options ...any) *Handler

New creates a new Handler.

func (*Handler) AttachExec

func (h *Handler) AttachExec(w http.ResponseWriter, r *http.Request)

AttachExec handles GET /exec/{id}/attach.

func (*Handler) AuthorizeSudo

func (h *Handler) AuthorizeSudo(w http.ResponseWriter, r *http.Request)

AuthorizeSudo handles POST /sudo/authorize. It is called by the sandbox sudo wrapper before the wrapper executes the real sudo binary.

func (*Handler) CancelChat

func (h *Handler) CancelChat(w http.ResponseWriter, r *http.Request)

CancelChat handles POST /threads/{id}/chat/cancel — cancels in-progress completion.

func (*Handler) ChatStatus

func (h *Handler) ChatStatus(w http.ResponseWriter, r *http.Request)

ChatStatus handles GET /threads/{id}/chat/status — returns whether a completion is active. Unlike ChatStream, this never opens an SSE connection; it is safe to poll frequently.

func (*Handler) ChatStream

func (h *Handler) ChatStream(w http.ResponseWriter, r *http.Request)

ChatStream handles GET /threads/{id}/chat/stream — streams SSE events for a thread. Fresh requests (no Last-Event-ID, or an invalid one) replay the full persisted UI message history first using named SSE events, then send the current in-memory chunk snapshot before history-end, and finally continue with live deltas. Valid Last-Event-ID reconnects keep the existing resume-only behavior. The SSE protocol is explicit:

  • history-start / history-message / history-end for replayed UIMessage values
  • chunk for UIMessageChunk deltas
  • ping while the stream is otherwise idle

Unlike the previous one-completion model, this endpoint stays connected until the client disconnects so later conversations on the same thread can arrive on the same SSE connection. There is no terminal "done" event; completion boundaries are internal and the connection remains reusable for later turns.

func (*Handler) CloseWriteExec

func (h *Handler) CloseWriteExec(w http.ResponseWriter, r *http.Request)

CloseWriteExec handles POST /exec/{id}/close-write.

func (*Handler) ControlSocket

func (h *Handler) ControlSocket(w http.ResponseWriter, r *http.Request)

ControlSocket accepts the server-initiated sandbox control WebSocket.

func (*Handler) CreateExec

func (h *Handler) CreateExec(w http.ResponseWriter, r *http.Request)

CreateExec handles POST /exec.

func (*Handler) CreateThread

func (h *Handler) CreateThread(w http.ResponseWriter, r *http.Request)

CreateThread handles POST /threads — creates a new thread.

func (*Handler) DecodeJSON

func (h *Handler) DecodeJSON(r *http.Request, v any) error

DecodeJSON decodes the request body as JSON.

func (*Handler) DeleteExec

func (h *Handler) DeleteExec(w http.ResponseWriter, r *http.Request)

DeleteExec handles DELETE /exec/{id}.

func (*Handler) DeleteFile

func (h *Handler) DeleteFile(w http.ResponseWriter, r *http.Request)

DeleteFile handles POST /files/delete — deletes a file or directory.

func (*Handler) DeleteQueuedPrompt

func (h *Handler) DeleteQueuedPrompt(w http.ResponseWriter, r *http.Request)

DeleteQueuedPrompt handles DELETE /threads/{id}/queue/{queueId} — removes a queued prompt.

func (*Handler) DeleteThread

func (h *Handler) DeleteThread(w http.ResponseWriter, r *http.Request)

DeleteThread handles DELETE /threads/{id} — removes a thread.

func (*Handler) Error

func (h *Handler) Error(w http.ResponseWriter, status int, message string)

Error writes a JSON error response.

func (*Handler) ExecCapabilities

func (h *Handler) ExecCapabilities(w http.ResponseWriter, _ *http.Request)

ExecCapabilities handles GET /exec/capabilities.

func (*Handler) ExecEvents

func (h *Handler) ExecEvents(w http.ResponseWriter, r *http.Request)

ExecEvents handles GET /exec/{id}/events.

func (*Handler) ExecOutput

func (h *Handler) ExecOutput(w http.ResponseWriter, r *http.Request)

ExecOutput handles GET /exec/{id}/output.

func (*Handler) GetBrowserSession

func (h *Handler) GetBrowserSession(w http.ResponseWriter, r *http.Request)

func (*Handler) GetCommits

func (h *Handler) GetCommits(w http.ResponseWriter, r *http.Request)

GetCommits handles GET /commits — returns format-patch output for changes relative to a target commit. Query params:

  • target: optional, the base commit hash
  • head: optional, the tip commit hash to export instead of the current HEAD
  • cwd: optional, the git working directory to read from

func (*Handler) GetDiff

func (h *Handler) GetDiff(w http.ResponseWriter, r *http.Request)

GetDiff handles GET /diff — returns workspace diff. Query params:

  • path: optional, single file diff
  • format: optional, "full" (default) or "files"
  • target: optional commit/ref to diff against (defaults to HEAD)

func (*Handler) GetExec

func (h *Handler) GetExec(w http.ResponseWriter, r *http.Request)

GetExec handles GET /exec/{id}.

func (*Handler) GetMCPServerOAuth

func (h *Handler) GetMCPServerOAuth(w http.ResponseWriter, r *http.Request)

GetMCPServerOAuth handles GET /mcp/servers/{name}/oauth. Returns the OAuth authorization URL for a server that is waiting for user authorization. Returns 404 if the server is not in oauth_required state.

func (*Handler) GetPendingQuestion

func (h *Handler) GetPendingQuestion(w http.ResponseWriter, r *http.Request)

GetPendingQuestion handles GET /threads/{id}/chat/question — returns the current pending AskUserQuestion for the thread, if any.

func (*Handler) GetQuestion

func (h *Handler) GetQuestion(w http.ResponseWriter, r *http.Request)

GetQuestion handles GET /threads/{id}/chat/question/{questionId} — returns a pending user question.

func (*Handler) GetSessionActivity

func (h *Handler) GetSessionActivity(w http.ResponseWriter, _ *http.Request)

GetSessionActivity handles GET /threads/activity — returns one aggregate snapshot of non-idle activity for the whole sandbox session.

func (*Handler) GetThread

func (h *Handler) GetThread(w http.ResponseWriter, r *http.Request)

GetThread handles GET /threads/{id} — returns thread metadata.

func (*Handler) GetThreadTokenUsage

func (h *Handler) GetThreadTokenUsage(w http.ResponseWriter, r *http.Request)

GetThreadTokenUsage handles GET /threads/{id}/token-usage.

func (*Handler) Health

func (h *Handler) Health(w http.ResponseWriter, _ *http.Request)

Health handles GET /health — detailed health status.

func (*Handler) HookOutput

func (h *Handler) HookOutput(w http.ResponseWriter, r *http.Request)

HookOutput handles GET /hooks/{hookId}/output — returns hook output log.

func (*Handler) HookOutputDownload

func (h *Handler) HookOutputDownload(w http.ResponseWriter, r *http.Request)

HookOutputDownload handles GET /hooks/{hookId}/output/download — returns hook output log as an attachment.

func (*Handler) HooksState

func (h *Handler) HooksState(w http.ResponseWriter, _ *http.Request)

HooksState handles GET /hooks/state — returns hook status and inline outputs.

func (*Handler) HooksStatus

func (h *Handler) HooksStatus(w http.ResponseWriter, _ *http.Request)

HooksStatus handles GET /hooks/status — returns hook evaluation status.

func (*Handler) JSON

func (h *Handler) JSON(w http.ResponseWriter, status int, data any)

JSON writes a JSON response with the given status code.

func (*Handler) KillExec

func (h *Handler) KillExec(w http.ResponseWriter, r *http.Request)

KillExec handles POST /exec/{id}/kill.

func (*Handler) ListCommands

func (h *Handler) ListCommands(w http.ResponseWriter, _ *http.Request)

ListCommands handles GET /commands.

func (*Handler) ListExec

func (h *Handler) ListExec(w http.ResponseWriter, r *http.Request)

ListExec handles GET /exec.

func (*Handler) ListFiles

func (h *Handler) ListFiles(w http.ResponseWriter, r *http.Request)

ListFiles handles GET /files — lists directory contents.

func (*Handler) ListMCPServers

func (h *Handler) ListMCPServers(w http.ResponseWriter, _ *http.Request)

ListMCPServers handles GET /mcp/servers. Returns the connection status of all configured MCP servers, including the OAuth authorization URL when a server is awaiting user authorization.

func (*Handler) ListMessages

func (h *Handler) ListMessages(w http.ResponseWriter, r *http.Request)

ListMessages handles GET /threads/{id}/messages — returns thread history as UI-projected messages.

func (*Handler) ListPorts

func (h *Handler) ListPorts(w http.ResponseWriter, r *http.Request)

ListPorts handles GET /ports — lists TCP listening ports owned by visible processes.

func (*Handler) ListServices

func (h *Handler) ListServices(w http.ResponseWriter, _ *http.Request)

ListServices handles GET /services — lists all services with status.

func (*Handler) ListThreads

func (h *Handler) ListThreads(w http.ResponseWriter, _ *http.Request)

ListThreads handles GET /threads — lists all threads.

func (*Handler) ListWorkspaceChangeCommits

func (h *Handler) ListWorkspaceChangeCommits(w http.ResponseWriter, _ *http.Request)

ListWorkspaceChangeCommits handles GET /workspace-change-commits — returns Discobot workspace change workspace change commits for this session with per-commit diffstat.

func (*Handler) OnTurnComplete

func (h *Handler) OnTurnComplete(threadID string, _ error)

OnTurnComplete handles handler-owned turn completion bookkeeping.

func (*Handler) OnTurnStart

func (h *Handler) OnTurnStart(threadID string)

OnTurnStart handles handler-owned turn startup bookkeeping.

func (*Handler) PostAnswer

func (h *Handler) PostAnswer(w http.ResponseWriter, r *http.Request)

PostAnswer handles POST /threads/{id}/chat/answer/{questionId} — submits answers to a pending question.

func (*Handler) PostChat

func (h *Handler) PostChat(w http.ResponseWriter, r *http.Request)

PostChat handles POST /threads/{id}/chat — starts or queues a completion and returns its status.

func (*Handler) PostMCPServerOAuthCode

func (h *Handler) PostMCPServerOAuthCode(w http.ResponseWriter, r *http.Request)

PostMCPServerOAuthCode handles POST /mcp/servers/{name}/oauth/code. Submits the OAuth authorization code (and state) to complete the OAuth flow for a server that is blocked waiting for user authorization. Body: { "code": "...", "state": "..." }

func (*Handler) ProxyBrowserCDP

func (h *Handler) ProxyBrowserCDP(w http.ResponseWriter, r *http.Request)

func (*Handler) ReadFile

func (h *Handler) ReadFile(w http.ResponseWriter, r *http.Request)

ReadFile handles GET /files/read — reads file content.

func (*Handler) ReadThreadArtifact

func (h *Handler) ReadThreadArtifact(w http.ResponseWriter, r *http.Request)

ReadThreadArtifact handles GET /threads/{id}/artifacts/read — reads a thread-local artifact via its artifacts:// URI.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(r chi.Router)

RegisterRoutes registers all API routes on the given router and records metadata in the global routes registry (used by GET /api/routes).

func (*Handler) RenameFile

func (h *Handler) RenameFile(w http.ResponseWriter, r *http.Request)

RenameFile handles POST /files/rename — renames/moves a file or directory.

func (*Handler) RerunHook

func (h *Handler) RerunHook(w http.ResponseWriter, r *http.Request)

RerunHook handles POST /hooks/{hookId}/rerun — manually reruns a hook.

func (*Handler) ResizeExec

func (h *Handler) ResizeExec(w http.ResponseWriter, r *http.Request)

ResizeExec handles POST /exec/{id}/resize.

func (*Handler) Root

func (h *Handler) Root(w http.ResponseWriter, _ *http.Request)

Root handles GET / — service status check.

func (*Handler) SearchFiles

func (h *Handler) SearchFiles(w http.ResponseWriter, r *http.Request)

SearchFiles handles GET /files/search — fuzzy search files in workspace.

func (*Handler) ServiceOutput

func (h *Handler) ServiceOutput(w http.ResponseWriter, r *http.Request)

ServiceOutput handles GET /services/{serviceId}/output — streams service output via SSE.

func (*Handler) ServiceProxy

func (h *Handler) ServiceProxy(w http.ResponseWriter, r *http.Request)

ServiceProxy handles ALL /services/{serviceId}/http/* — HTTP reverse proxy to service port.

func (*Handler) StartService

func (h *Handler) StartService(w http.ResponseWriter, r *http.Request)

StartService handles POST /services/{serviceId}/start — starts a service.

func (*Handler) StopService

func (h *Handler) StopService(w http.ResponseWriter, r *http.Request)

StopService handles POST /services/{serviceId}/stop — stops a service.

func (*Handler) StreamSession

func (h *Handler) StreamSession(w http.ResponseWriter, r *http.Request)

StreamSession handles GET /session/stream. It streams agent-owned session resource snapshots. A fresh connection starts with history-start, sends a complete resource snapshot, then history-end, and remains open for live session-level resource changes.

func (*Handler) UpdateHookExecution

func (h *Handler) UpdateHookExecution(w http.ResponseWriter, r *http.Request)

UpdateHookExecution handles PATCH /hooks/{hookId}/execution — toggles execution for one hook.

func (*Handler) UpdateHooksExecution

func (h *Handler) UpdateHooksExecution(w http.ResponseWriter, r *http.Request)

UpdateHooksExecution handles PATCH /hooks/execution — toggles hook execution.

func (*Handler) UpdateQueuedPrompt

func (h *Handler) UpdateQueuedPrompt(w http.ResponseWriter, r *http.Request)

UpdateQueuedPrompt handles PATCH /threads/{id}/queue/{queueId} — updates a queued prompt.

func (*Handler) UpdateThread

func (h *Handler) UpdateThread(w http.ResponseWriter, r *http.Request)

UpdateThread handles PUT/PATCH /threads/{id} — updates thread metadata.

func (*Handler) User

func (h *Handler) User(w http.ResponseWriter, _ *http.Request)

User handles GET /user — current user info for terminal sessions.

func (*Handler) WriteFile

func (h *Handler) WriteFile(w http.ResponseWriter, r *http.Request)

WriteFile handles POST /files/write — writes file content.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL