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 Engine ¶ added in v0.6.4
type Engine struct {
// contains filtered or unexported fields
}
Engine is the per-task run state of the web server — one independent top-level session (a "task"). It holds exactly the fields that were Server singletons in the single-active design: the agent, its conversation history, recorder, per-task token tracker, approval axis, working dir, and event handler.
The refactor toward concurrent tasks proceeds in stages:
- INC-3 (this): the fields move out of Server into Engine, Server embeds one bootstrap *Engine, and field promotion keeps every existing s.<field> reference compiling and behaving identically (concurrency stays 1).
- INC-5: handlers resolve an Engine by task_id (Server.tasks) instead of relying on the promoted bootstrap.
- INC-7+: the global run gate is removed so multiple Engines run at once; `running` becomes the per-task busy flag and each Engine gets its own ctx.
Kernel types (session.Recorder, tools.Env, runner.ApprovalState, handler.WebHandler, model.TokenUsage) are reused unchanged — parallelism is achieved by instantiating one set of them per Engine, never by editing them.
type EngineConfig ¶ added in v0.6.4
type EngineConfig struct {
TaskID string
Pwd string
Mode string
ProviderName string
ModelName string
Agent *adk.ChatModelAgent
Env *tools.Env
TodoStore *tools.TodoStore
Recorder *session.Recorder
TokenUsage *model.TokenUsage
ApprovalState *runner.ApprovalState
Handler *handler.WebHandler
EventHandler handler.AgentEventHandler
BreakdownFn func() usage.ContextBreakdown
CreateAgent func(providerName, modelName string) (*adk.ChatModelAgent, error)
RebuildForMode func(planMode bool) (*adk.ChatModelAgent, error)
}
EngineConfig carries the per-task pieces a factory (command.buildWebTask) produces for one task. The web package owns Engine's unexported fields, so the command package hands them over through this exported struct and the server assembles the Engine via newEngine.
type Server ¶
type Server struct {
// Engine is the bootstrap/active task's run state. Its fields (agent, history,
// recorder, pwd, env, tokenUsage, approvalState, handler, …) are PROMOTED onto
// Server, so existing s.<field> accesses resolve to s.Engine.<field> while
// there is a single active task. Per-task routing (Server.tasks) supersedes
// this promotion in a later increment. Always non-nil after NewServer.
*Engine
// contains filtered or unexported fields
}
Server is the jcode web server.
func (*Server) CloseAllEngines ¶ added in v0.6.4
func (s *Server) CloseAllEngines()
CloseAllEngines tears down every live engine. Called on server shutdown.
func (*Server) Handler ¶
func (s *Server) Handler() *handler.WebHandler
Handler returns the underlying WebHandler for external wiring (e.g. approval routing).
func (*Server) SubmitMessage ¶ added in v0.1.1
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)
NewEngine func(taskID, pwd, mode string) (*EngineConfig, error) // factory for new concurrent task engines (local)
NewRemoteEngine func(taskID string, executor tools.RemoteExecutor, remotePwd, mode string) (*EngineConfig, error) // remote sibling of NewEngine (SSH or Docker)
InitialMode string // unified startup mode string ("approval"/"plan"/"full_access")
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
ReloadMCP func(servers map[string]*config.MCPServer) ([]tools.MCPStatus, error) // optional: hot-reload MCP tools
InitialMCPStatuses []tools.MCPStatus // statuses from the startup MCP load
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)
ContextBreakdownFn func() usage.ContextBreakdown // optional: live per-task context breakdown
}
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 (*WSBroker) ClientCount ¶
ClientCount returns the number of connected clients.
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"`
// TaskID tags the event with the task (engine) it came from so the client can
// route it to the right task view, and so the broker can deliver it only to
// clients subscribed to that task. Empty for global/server-wide events
// (mcp_changed, model_changed, pong, …), which every client receives.
TaskID string `json:"task_id,omitempty"`
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.