web

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package web implements the jcode web server and API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeSSE

func ServeSSE(w http.ResponseWriter, r *http.Request, events <-chan SSEEvent)

ServeSSE writes SSE events from a channel to an HTTP response.

Types

type SSEBroker

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

SSEBroker manages multiple SSE client connections and broadcasts events.

func NewSSEBroker

func NewSSEBroker() *SSEBroker

NewSSEBroker creates a new SSE broker.

func (*SSEBroker) Broadcast

func (b *SSEBroker) Broadcast(event SSEEvent)

Broadcast sends an event to all connected clients.

func (*SSEBroker) ClientCount

func (b *SSEBroker) ClientCount() int

ClientCount returns the number of connected clients.

func (*SSEBroker) Close

func (b *SSEBroker) Close()

Close shuts down the broker.

func (*SSEBroker) Subscribe

func (b *SSEBroker) Subscribe() (<-chan SSEEvent, func())

Subscribe registers a new client and returns a channel + unsubscribe func.

type SSEEvent

type SSEEvent struct {
	Event string `json:"event"`
	Data  any    `json:"data"`
}

SSEEvent is a single Server-Sent Event.

type Server

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

Server is the jcode web server.

func NewServer

func NewServer(cfg *ServerConfig) *Server

NewServer creates a new web server.

func (*Server) Handler

func (s *Server) Handler() *handler.WebHandler

Handler returns the underlying WebHandler for external wiring (e.g. approval routing).

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the web server. Blocks until context is cancelled.

type ServerConfig

type ServerConfig struct {
	Port          int
	Host          string
	Pwd           string
	Agent         *adk.ChatModelAgent
	CreateAgent   func(providerName, modelName string) (*adk.ChatModelAgent, error)
	SwitchProject func(newPwd string) (*adk.ChatModelAgent, *session.Recorder, error)
	TodoStore     *tools.TodoStore
	Recorder      *session.Recorder
	Tracer        *telemetry.LangfuseTracer
	Env           *tools.Env
	ProviderName  string
	ModelName     string
	Config        *config.Config
	Registry      *model.ModelRegistry
	ApprovalState *runner.ApprovalState
	SkillLoader   *skills.Loader
	WebHandler    *handler.WebHandler // optional: pre-created handler for sharing with tools
}

ServerConfig holds the configuration for creating a new Server.

type WSBroker

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

WSBroker manages WebSocket client connections and broadcasts events.

func NewWSBroker

func NewWSBroker() *WSBroker

NewWSBroker creates a new WebSocket broker.

func (*WSBroker) Broadcast

func (b *WSBroker) Broadcast(event WSEvent)

Broadcast sends an event to all connected WebSocket clients.

func (*WSBroker) ClientCount

func (b *WSBroker) ClientCount() int

ClientCount returns the number of connected clients.

func (*WSBroker) Close

func (b *WSBroker) Close()

Close shuts down the broker.

func (*WSBroker) Register

func (b *WSBroker) Register(conn *websocket.Conn) (uint64, *WSClient, func())

Register adds a new WebSocket client and returns an ID + unsubscribe func.

type WSClient

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

WSClient represents a connected WebSocket client.

type WSEvent

type WSEvent struct {
	Type string `json:"type"`
	Data any    `json:"data,omitempty"`
}

WSEvent is a WebSocket message envelope.

type WSIncoming

type WSIncoming struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
}

WSIncoming represents a message from the client over WebSocket.

Jump to

Keyboard shortcuts

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