web

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 32 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

This section is empty.

Types

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.

func (*Server) SubmitMessage added in v0.1.1

func (s *Server) SubmitMessage(message, source string) bool

SubmitMessage submits a message for agent processing from an external source (e.g. WeChat inbound message). Returns false if the agent is busy.

type ServerConfig

type ServerConfig struct {
	Port           int
	Host           string
	OpenBrowser    bool
	Pwd            string
	Version        string
	Agent          *adk.ChatModelAgent
	CreateAgent    func(providerName, modelName string) (*adk.ChatModelAgent, error)
	RebuildForMode func(planMode bool) (*adk.ChatModelAgent, error)
	InitialMode    string // unified startup mode string ("ask"/"plan"/"autopilot")
	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
	WechatClient   channel.Channel           // optional WeChat channel
	WebHandler     *handler.WebHandler       // optional: pre-created handler for sharing with tools
	EventHandler   handler.AgentEventHandler // optional: handler for runner (e.g. NotifyingHandler)
	NeedsSetup     bool                      // true when no providers are configured (setup mode)
	TokenUsage     *model.TokenUsage         // optional: shared token tracker (created when nil)
}

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