Documentation
¶
Overview ¶
Package web is a reference web transport for the OSS agent-harness: a browser chat UI served by an in-process net/http server, wired into the transport seam. The Channel implements channel.Channel — browser POSTs become inbound turns (Receiver) and turn stream events fan out to per-thread SSE subscribers (Publisher). It is stdlib-only (no external deps); pair it with a turn.Runner whose Publisher is this Channel and drive it with runtime.RunLoop.
Index ¶
- Variables
- func OpenBrowser(url string) error
- type Channel
- func (c *Channel) Enqueue(ctx context.Context, in channel.Inbound) error
- func (c *Channel) FetchTask(ctx context.Context) (channel.Inbound, error)
- func (c *Channel) PublishEvent(_ context.Context, e channel.Event) error
- func (c *Channel) PublishSessionEvent(_ context.Context, event spec.SessionEvent) error
- func (c *Channel) Subscribe(threadID string) (<-chan channel.Event, func())
- func (c *Channel) SubscribeSession(sessionID string) (<-chan spec.SessionEvent, func())
- type HistoryStore
- type Index
- type Server
- type Session
- type SessionService
Constants ¶
This section is empty.
Variables ¶
var NewIndex = threadindex.NewIndex
Functions ¶
func OpenBrowser ¶
OpenBrowser best-effort opens url in the default browser. It returns any launch error but callers typically ignore it — opening a browser is a convenience, not a requirement.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is an in-process web transport. Inbound turns arrive via Enqueue (the HTTP chat handler) and are drained by FetchTask; egress stream events are routed to SSE subscribers keyed by thread id.
func (*Channel) Enqueue ¶
Enqueue submits an inbound turn. It blocks only while the inbox buffer is full (or until ctx is cancelled).
func (*Channel) FetchTask ¶
FetchTask implements channel.Receiver. It blocks until an inbound turn is available or ctx is cancelled; idleness simply blocks (it never returns ErrNoTask), which suits runtime.RunLoop.
func (*Channel) PublishEvent ¶
PublishEvent implements channel.Publisher: fan the event out to every subscriber on its thread. Sends are non-blocking — a full subscriber buffer drops the event for that client so a slow browser never stalls a turn.
func (*Channel) PublishSessionEvent ¶ added in v0.0.2
PublishSessionEvent fans a retained cursor-bearing event out to resumable stream subscribers. It deliberately mirrors PublishEvent's non-blocking slow consumer policy.
func (*Channel) Subscribe ¶
Subscribe registers an SSE listener for a thread. The returned channel receives events until cancel is called. The channel is intentionally never closed (PublishEvent may race a cancel); abandoned buffers are GC'd once the caller drops its reference.
func (*Channel) SubscribeSession ¶ added in v0.0.2
func (c *Channel) SubscribeSession(sessionID string) (<-chan spec.SessionEvent, func())
SubscribeSession registers for cursor-bearing events for sessionID. Events may span workspaces with the same session ID; consumers must filter the resolved workspace before exposing them.
type HistoryStore ¶ added in v0.0.2
type HistoryStore interface {
LoadHistory(ctx context.Context, threadID string) ([]protocol.ChatMessage, error)
DeleteHistory(ctx context.Context, threadID string) error
}
HistoryStore is the transcript surface used by the web REST handlers.
type Index ¶
type Index = threadindex.Index
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP surface for the web UI: a REST/SSE API plus the embedded single-page app. It is transport glue only — turns run through the Channel and the turn runner wired in cmd.
The server has NO authentication and is intended for localhost (loopback) use. State-changing endpoints carry a same-origin CSRF guard, but anyone able to reach the listen address can drive the agent — do not expose it beyond loopback without your own auth layer in front.
func New ¶
func New(ch *Channel, fs HistoryStore, sessions *Index, canceller *turncancel.Canceller) *Server
New builds the HTTP server. canceller may be nil (the /api/cancel endpoint then reports nothing cancelled).
func NewWithSessionService ¶ added in v0.0.2
func NewWithSessionService(ch *Channel, fs HistoryStore, sessions *Index, canceller *turncancel.Canceller, session SessionService) *Server
NewWithSessionService builds the server with the resumable session API.
type Session ¶
type Session = threadindex.Session
type SessionService ¶ added in v0.0.2
type SessionService interface {
Attach(ctx context.Context, request spec.SessionAttachRequest) (spec.SessionAttachResult, error)
ResetSession(ctx context.Context, requestedWorkspace, sessionID string) (spec.SessionCursor, error)
}
SessionService is the spec-native attach/reset surface supplied by the host. It stays optional so embedders using only the legacy REST/SSE API are unaffected.