httpapi

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

Package httpapi is the product's HTTP delivery layer. It streams run events over Server-Sent Events and accepts prompts and permission answers over POST requests.

Everything it serves lives below the application composition root, so another client can drive the same conversations without owning product construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProjectEvent

func ProjectEvent(ev engine.Event) ([]byte, bool)

ProjectEvent maps a UI-neutral coding event to the HTTP wire protocol.

func ProjectHistory

func ProjectHistory(items []engine.HistoryItem) []wireEvent

ProjectHistory maps a UI-neutral conversation snapshot to the same event shapes the browser already renders for live activity.

Types

type ApprovalBroker

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

ApprovalBroker asks the browser to decide one permission request and waits until it responds or the active run is cancelled.

func NewApprovalBroker

func NewApprovalBroker(hub *Hub) *ApprovalBroker

func (*ApprovalBroker) Decide

Decide implements permission.Approver.

func (*ApprovalBroker) HasPending

func (b *ApprovalBroker) HasPending() bool

func (*ApprovalBroker) PendingEvents

func (b *ApprovalBroker) PendingEvents() []wireEvent

PendingEvents returns the approvals a refreshed browser must restore.

func (*ApprovalBroker) Resolve

func (b *ApprovalBroker) Resolve(id string, choice permission.ApprovalChoice) bool

Resolve atomically claims and answers a pending approval.

type BrowserBroker

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

BrowserBroker delivers one session's agent navigation commands to its connected desktop client and waits for the first terminal acknowledgement.

func NewBrowserBroker

func NewBrowserBroker(hub *Hub) *BrowserBroker

func (*BrowserBroker) BrowserTabs

func (b *BrowserBroker) BrowserTabs(ctx context.Context) (tools.BrowserTabsResult, error)

func (*BrowserBroker) Close

func (b *BrowserBroker) Close()

Close releases every waiter when its session transport is replaced or shut down. The hub is closed immediately afterwards, so no terminal event is sent.

func (*BrowserBroker) HasPending

func (b *BrowserBroker) HasPending() bool

func (*BrowserBroker) InspectBrowser

func (b *BrowserBroker) InspectBrowser(ctx context.Context, tabID string) (tools.BrowserInspectionResult, error)

func (*BrowserBroker) OpenBrowser

func (b *BrowserBroker) OpenBrowser(
	ctx context.Context,
	request tools.BrowserRequest,
) (tools.BrowserResult, error)

OpenBrowser implements tools.BrowserController.

func (*BrowserBroker) PendingEvents

func (b *BrowserBroker) PendingEvents() []wireEvent

PendingEvents returns commands a history snapshot must restore after a renderer reconnects.

func (*BrowserBroker) Resolve

func (b *BrowserBroker) Resolve(id string, result tools.BrowserResult) bool

Resolve atomically claims one pending command. Unknown and duplicate IDs do not mutate broker state.

func (*BrowserBroker) ResolveInspection

func (b *BrowserBroker) ResolveInspection(id string, result tools.BrowserInspectionResult) bool

func (*BrowserBroker) ResolveTabs

func (b *BrowserBroker) ResolveTabs(id string, result tools.BrowserTabsResult) bool

type Hub

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

Hub fans one session's events out to every connected browser over SSE. Each client has a buffered channel; a slow client is disconnected so EventSource can reconnect and replay from its Last-Event-ID without blocking the run.

func NewHub

func NewHub() *Hub

NewHub returns an empty Hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(data []byte)

Broadcast sends data to every connected client, skipping any whose buffer is full.

func (*Hub) Close

func (h *Hub) Close()

Close disconnects every viewer and rejects later broadcasts or subscribers.

type Options

type Options struct {
	Conversations        *conversation.Manager
	Transports           *SessionTransports
	Ledger               *usage.Store
	Workspaces           *workspace.Registry
	Registry             *llm.ProviderRegistry
	Providers            *provider.Store
	ProviderTests        *provider.ConnectionTester
	MCP                  *mcp.Manager
	MCPConfigPath        string
	ObservabilityLogPath string
	RequestSnapshots     snapshot.Reader
}

Options contains the product services exposed through HTTP. Construction belongs to internal/app; this package only translates between HTTP and those services.

type QuestionBroker

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

QuestionBroker asks the browser to answer one set of agent questions and waits until it responds or the active run is cancelled. It is the question counterpart to ApprovalBroker: same pending-and-resolve shape, but the reply carries the user's choices rather than a permission verdict.

There is deliberately no timeout. A question can sit unanswered for as long as the user needs to think; abandoning it is what aborting the run is for.

func NewQuestionBroker

func NewQuestionBroker(hub *Hub) *QuestionBroker

func (*QuestionBroker) Ask

func (b *QuestionBroker) Ask(
	ctx context.Context,
	questions []tools.Question,
) ([]tools.Answer, error)

Ask implements tools.Asker.

func (*QuestionBroker) HasPending

func (b *QuestionBroker) HasPending() bool

func (*QuestionBroker) PendingEvents

func (b *QuestionBroker) PendingEvents() []wireEvent

PendingEvents returns the questions a refreshed browser must restore.

func (*QuestionBroker) Resolve

func (b *QuestionBroker) Resolve(id string, answers []tools.Answer) bool

Resolve atomically claims and answers a pending question.

type Server

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

Server wires the multi-session API: session discovery plus scoped history, SSE, prompt, approval, and abort endpoints. Each field is the store one group of routes actually reads. Handlers reach for the store they need and never through another component to find it.

func NewServer

func NewServer(opts Options) *Server

NewServer builds the HTTP delivery layer from already-created services.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler for the coding API.

Each mount function owns one group of routes and lives in its own file. A new module is a new file plus one line here; nothing else in this package has to learn about it.

type SessionTransports

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

SessionTransports owns the HTTP delivery links created for conversations. The conversation manager controls each link's lifetime through Transport.Close; handlers only look up an existing link by session ID.

func NewSessionTransports

func NewSessionTransports() *SessionTransports

NewSessionTransports returns an empty session transport registry.

func (*SessionTransports) New

func (r *SessionTransports) New(sessionID string) conversation.Transport

New creates and registers one conversation transport.

func (*SessionTransports) PreviewHandler added in v0.6.15

func (s *SessionTransports) PreviewHandler() http.Handler

PreviewHandler serves grant-scoped workspace files on the unauthenticated, preview-only loopback origin. It intentionally exposes no product API.

Directories

Path Synopsis
internal
genwire command
Command genwire generates the browser's TypeScript wire DTOs from the Go structs and string enums in wire_contract.go.
Command genwire generates the browser's TypeScript wire DTOs from the Go structs and string enums in wire_contract.go.

Jump to

Keyboard shortcuts

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