web

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 56 Imported by: 0

Documentation

Overview

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor.

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor

Package web provides browser-based setup wizard and configuration editor

Index

Constants

This section is empty.

Variables

View Source
var EditorSections = []SectionCategory{
	{
		Title: "Configuration",
		Items: []SectionItem{
			{ID: "llm", Label: "Model Chains", ConfigPath: "/llm", Type: SectionTypeFormDef, Expandable: true},
			{ID: "llm-providers", Label: "LLM Providers", ConfigPath: "/llm", Type: SectionTypeFormDef},
			{ID: "local-llm", Label: "Local LLM", ConfigPath: "/llm", Type: SectionTypeCustom},
			{ID: "voicellm", Label: "VoiceLLM", ConfigPath: "/voicellm", Type: SectionTypeFormDef},
			{ID: "acp", Label: "Coding Agents", ConfigPath: "/acp", Type: SectionTypeFormDef},
			{ID: "a2a", Label: "A2A Networking", ConfigPath: "/a2a", Type: SectionTypeFormDef},
			{ID: "gateway", Label: "Gateway", ConfigPath: "/", Type: SectionTypeFormDef},
			{ID: "session", Label: "Session", ConfigPath: "/session", Type: SectionTypeFormDef},
		},
	},
	{
		Title: "Channels",
		Items: []SectionItem{
			{ID: "telegram", Label: "Telegram", ConfigPath: "/channels/telegram", Type: SectionTypeFormDef},
			{ID: "http", Label: "HTTP Server", ConfigPath: "/channels/http", Type: SectionTypeFormDef},
			{ID: "whatsapp", Label: "WhatsApp", ConfigPath: "/channels/whatsapp", Type: SectionTypeFormDef},
		},
	},
	{
		Title: "Services",
		Items: []SectionItem{
			{ID: "transcript", Label: "Transcript", ConfigPath: "/transcript", Type: SectionTypeFormDef},
			{ID: "memorygraph", Label: "Memory Graph", ConfigPath: "/memoryGraph", Type: SectionTypeFormDef},
			{ID: "stt", Label: "Speech-to-Text", ConfigPath: "/stt", Type: SectionTypeFormDef},
			{ID: "skills", Label: "Skills", ConfigPath: "/skills", Type: SectionTypeFormDef},
			{ID: "cron", Label: "Cron", ConfigPath: "/cron", Type: SectionTypeFormDef},
			{ID: "tools", Label: "Tools", ConfigPath: "/tools", Type: SectionTypeFormDef},
		},
	},
	{
		Title: "System",
		Items: []SectionItem{
			{ID: "sandbox", Label: "Sandbox", ConfigPath: "/sandbox", Type: SectionTypeFormDef},
			{ID: "auth", Label: "Auth", ConfigPath: "/auth", Type: SectionTypeFormDef},
			{ID: "a2a-peers", Label: "A2A Peers", ConfigPath: "/a2a", Type: SectionTypeCustom},
			{ID: "users", Label: "Users", ConfigPath: "/", Type: SectionTypeCustom},
			{ID: "roles", Label: "Roles", ConfigPath: "/roles", Type: SectionTypeFormDef},
			{ID: "media", Label: "Media", ConfigPath: "/media", Type: SectionTypeFormDef},
		},
	},
}

EditorSections defines the full sidebar structure for the configuration editor. Some sections may be filtered out at runtime based on mode/capabilities.

View Source
var ErrNoUIAvailable = fmt.Errorf("no UI available")

ErrNoUIAvailable is returned when neither webview nor browser is available

View Source
var WizardSteps = []WizardStep{
	{ID: "welcome", Title: "Welcome to GoClaw", Description: "Let's get you set up with your personal AI assistant."},
	{ID: "agent", Title: "Agent Identity", Description: "Set your assistant name, emoji, and typing style."},
	{ID: "workspace", Title: "Workspace", Description: "Choose where GoClaw will store files and configurations."},
	{ID: "user", Title: "Owner Account", Description: "Create your owner account for authentication."},
	{ID: "channels", Title: "Communication Channels", Description: "Configure how you'll interact with GoClaw."},
	{ID: "pairing", Title: "Channel Pairing", Description: "Pair each enabled owner channel before you continue."},
	{ID: "llm", Title: "LLM Provider", Description: "Choose between a managed local model, a cloud provider, or an existing llama.cpp server."},
	{ID: "voice", Title: "Voice Settings", Description: "Configure speech-to-text and voice LLM (optional)."},
	{ID: "security", Title: "Security & Skills", Description: "Configure sandboxing and skill installation sources."},
	{ID: "review", Title: "Review & Finish", Description: "Review your settings and complete the setup."},
}

WizardSteps defines all steps in the setup wizard

Functions

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath returns the default config path

func GetFormDef

func GetFormDef(sectionID string) *forms.FormDef

GetFormDef returns the FormDef for a section, or nil if not found

func RegisterFormDef

func RegisterFormDef(sectionID string, getter FormDefGetter)

RegisterFormDef allows dynamic registration of FormDef getters

func RegisterSetupRoutes

func RegisterSetupRoutes(srv HTTPServer, configPath string, a2aRuntime A2ARuntimeProvider) error

RegisterSetupRoutes registers setup wizard and editor routes on the main HTTP server

func RenderFormHTML

func RenderFormHTML(def forms.FormDef, _ string) (template.HTML, error)

RenderFormHTML converts a FormDef into Bootstrap-oriented HTML with data hooks. The returned markup is hydrated by the setup jQuery runtime.

func RunWebEditor

func RunWebEditor(configPath string) error

RunWebEditor runs the browser-based config editor Returns ErrNoUIAvailable if neither webview nor browser works

func RunWebEditorWithOptions

func RunWebEditorWithOptions(configPath string, devMode bool) error

RunWebEditorWithOptions runs the browser-based config editor with options

func RunWebWizard

func RunWebWizard(configPath string) error

RunWebWizard runs the browser-based setup wizard Returns ErrNoUIAvailable if neither webview nor browser works

func RunWebWizardWithOptions

func RunWebWizardWithOptions(configPath string, devMode bool) error

RunWebWizardWithOptions runs the browser-based setup wizard with options

func ValidateAllSectionContractsStrict

func ValidateAllSectionContractsStrict() error

ValidateAllSectionContractsStrict validates all setup/editor section contracts. It enforces JSON-pointer config roots and strict JSON-key dotted FormDef paths.

Types

type A2APeerRequest added in v0.1.14

type A2APeerRequest struct {
	Type      string   `json:"type"`
	Alias     string   `json:"alias"`
	PeerID    string   `json:"peerId"`
	Addrs     []string `json:"addrs"`
	LocalUser string   `json:"localUser"`
	Enabled   bool     `json:"enabled"`
	Notes     string   `json:"notes"`
}

type A2APeersAPI added in v0.1.14

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

func NewA2APeersAPI added in v0.1.14

func NewA2APeersAPI(configPath string, runtime A2ARuntimeProvider) *A2APeersAPI

func (*A2APeersAPI) HandleConfig added in v0.1.14

func (a *A2APeersAPI) HandleConfig(w http.ResponseWriter, r *http.Request)

func (*A2APeersAPI) HandlePairing added in v0.1.14

func (a *A2APeersAPI) HandlePairing(w http.ResponseWriter, r *http.Request)

func (*A2APeersAPI) HandlePeer added in v0.1.14

func (a *A2APeersAPI) HandlePeer(w http.ResponseWriter, r *http.Request)

func (*A2APeersAPI) HandlePeers added in v0.1.14

func (a *A2APeersAPI) HandlePeers(w http.ResponseWriter, r *http.Request)

func (*A2APeersAPI) HandlePing added in v0.1.14

func (a *A2APeersAPI) HandlePing(w http.ResponseWriter, r *http.Request)

func (*A2APeersAPI) HandleRuntime added in v0.1.14

func (a *A2APeersAPI) HandleRuntime(w http.ResponseWriter, r *http.Request)

type A2APingRequest added in v0.1.14

type A2APingRequest struct {
	PeerID string `json:"peerId"`
}

type A2ARuntimeProvider added in v0.1.14

type A2ARuntimeProvider interface {
	GetA2AStatus() a2a.Status
	ListA2APeers(filter string) []a2a.PeerRecord
	GetA2APairingPayload() a2a.PairingPayload
	PingA2APeer(ctx context.Context, target string) (a2a.PingResult, error)
	A2APeerRegistry() *a2apeers.Registry
	RefreshA2ATrustedPeers()
}

type API

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

API provides JSON API handlers for the setup wizard and editor

func NewAPI

func NewAPI(configPath string, applyCaller configapply.Caller, sections []SectionCategory) *API

NewAPI creates a new API handler

func (*API) HandleApply

func (a *API) HandleApply(w http.ResponseWriter, r *http.Request)

HandleApply determines how saved config should take effect.

func (*API) HandleGetConfig

func (a *API) HandleGetConfig(w http.ResponseWriter, r *http.Request)

HandleGetConfig returns the full configuration as JSON

func (*API) HandleGetDrivers added in v0.1.3

func (a *API) HandleGetDrivers(w http.ResponseWriter, r *http.Request)

HandleGetDrivers returns supported runtime LLM drivers from the llm registry.

func (*API) HandleGetModels

func (a *API) HandleGetModels(w http.ResponseWriter, r *http.Request)

HandleGetModels returns full model details for a provider alias

func (*API) HandleGetPresets

func (a *API) HandleGetPresets(w http.ResponseWriter, r *http.Request)

HandleGetPresets returns available LLM provider presets from models.json

func (*API) HandleGetProviders

func (a *API) HandleGetProviders(w http.ResponseWriter, r *http.Request)

HandleGetProviders returns configured LLM provider aliases with metadata

func (*API) HandleGetSections

func (a *API) HandleGetSections(w http.ResponseWriter, r *http.Request)

HandleGetSections returns the sidebar sections structure

func (*API) HandleLocalLLM added in v0.1.14

func (a *API) HandleLocalLLM(w http.ResponseWriter, r *http.Request)

func (*API) HandleSection

func (a *API) HandleSection(w http.ResponseWriter, r *http.Request)

HandleSection handles GET (fetch section config) and POST (save section config)

func (*API) HandleSectionAction added in v0.1.8

func (a *API) HandleSectionAction(w http.ResponseWriter, r *http.Request)

HandleSectionAction runs a form action for a section.

type APIResponse

type APIResponse struct {
	Success bool              `json:"success"`
	Data    interface{}       `json:"data,omitempty"`
	Errors  map[string]string `json:"errors,omitempty"`
	Message string            `json:"message,omitempty"`
}

APIResponse is the standard JSON response format

type CreateUserRequest

type CreateUserRequest struct {
	Username      string  `json:"username"`
	Name          string  `json:"name"`
	Role          string  `json:"role"`
	TelegramID    string  `json:"telegram_id,omitempty"`
	WhatsAppID    string  `json:"whatsapp_id,omitempty"`
	Password      string  `json:"password,omitempty"`
	ACPAllowed    *bool   `json:"acpAllowed,omitempty"`
	Thinking      *bool   `json:"thinking,omitempty"`
	ThinkingLevel *string `json:"thinking_level,omitempty"`
	Sandbox       *bool   `json:"sandbox,omitempty"`
}

CreateUserRequest represents a request to create a new user

type FormDefGetter

type FormDefGetter func() forms.FormDef

FormDefGetter is a function that returns a FormDef for a config section

type HTTPServer

type HTTPServer interface {
	Mux() *http.ServeMux
	WrapHandler(h http.HandlerFunc) http.HandlerFunc
	Users() *user.Registry
}

HTTPServer interface for integration with main HTTP server

type Handlers

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

Handlers provides HTTP handlers for the setup wizard and editor

func NewHandlers

func NewHandlers(setupMode bool, enableA2APeers bool) (*Handlers, error)

NewHandlers creates new setup handlers

func (*Handlers) HandleEdit

func (h *Handlers) HandleEdit(w http.ResponseWriter, r *http.Request)

HandleEdit serves the configuration editor page

func (*Handlers) HandleWizard

func (h *Handlers) HandleWizard(w http.ResponseWriter, r *http.Request)

HandleWizard serves the wizard page

func (*Handlers) RegisterRoutes

func (h *Handlers) RegisterRoutes(mux *http.ServeMux, configPath string)

RegisterRoutes is kept for compatibility with older call sites. New code should prefer mountSetup for pages, APIs, and static assets together.

type PairingAPI added in v0.1.9

type PairingAPI struct{}

func NewPairingAPI added in v0.1.9

func NewPairingAPI() *PairingAPI

func (*PairingAPI) HandleAction added in v0.1.9

func (p *PairingAPI) HandleAction(w http.ResponseWriter, r *http.Request)

type SectionCategory

type SectionCategory struct {
	Title string        `json:"title"`
	Items []SectionItem `json:"items"`
}

SectionCategory groups related section items

func EditorSectionsForMode added in v0.1.14

func EditorSectionsForMode(enableA2APeers bool) []SectionCategory

func GetSectionsJSON

func GetSectionsJSON(enableA2APeers bool) []SectionCategory

GetSectionsJSON returns the sections structure for JavaScript consumption

type SectionItem

type SectionItem struct {
	ID         string      `json:"id"`         // Unique identifier
	Label      string      `json:"label"`      // Display name
	ConfigPath string      `json:"configPath"` // JSON Pointer in config (e.g., "/channels/telegram")
	Type       SectionType `json:"type"`       // formdef or custom
	Expandable bool        `json:"expandable"` // Has nested items (LLM providers)
}

SectionItem represents a single menu item in the editor sidebar

func FindSection

func FindSection(categories []SectionCategory, id string) *SectionItem

FindSection looks up a section by ID across all categories.

type SectionType

type SectionType string

SectionType indicates how a section should be rendered

const (
	// SectionTypeFormDef renders section using FormDef to HTML conversion
	SectionTypeFormDef SectionType = "formdef"
	// SectionTypeCustom uses custom UI (e.g., Users CRUD)
	SectionTypeCustom SectionType = "custom"
)

type Server

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

Server is the ephemeral HTTP server for standalone setup wizard

func NewServer

func NewServer(configPath string) (*Server, error)

NewServer creates a new ephemeral setup server

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server

func (*Server) Start

func (s *Server) Start() error

Start begins serving requests

func (*Server) URL

func (s *Server) URL() string

URL returns the server URL

func (*Server) WaitForCompletion

func (s *Server) WaitForCompletion()

WaitForCompletion blocks until the server is signaled to shut down

type SetPasswordRequest

type SetPasswordRequest struct {
	Password string `json:"password"`
}

SetPasswordRequest represents a request to set a user's password

type TemplateData

type TemplateData struct {
	StandaloneMode bool       // true for standalone setup process
	WizardMode     bool       // true when rendering wizard page
	EditMode       bool       // true when rendering setup editor page
	User           *user.User // authenticated user (nil in standalone mode)
	Title          string
	Categories     []SectionCategory // sidebar categories
	Content        template.HTML     // main content
	CurrentNav     string            // active nav item
	AssetVersion   string
}

TemplateData holds common data for all templates

type UpdateOwnerPairingRequest added in v0.1.9

type UpdateOwnerPairingRequest struct {
	TelegramID string `json:"telegram_id,omitempty"`
	WhatsAppID string `json:"whatsapp_id,omitempty"`
}

UpdateOwnerPairingRequest stages resolved owner channel identities at save time.

type UpdateUserRequest

type UpdateUserRequest struct {
	Name          string  `json:"name"`
	Role          string  `json:"role"`
	TelegramID    string  `json:"telegram_id,omitempty"`
	WhatsAppID    string  `json:"whatsapp_id,omitempty"`
	Password      *string `json:"password,omitempty"`
	ClearPassword bool    `json:"clear_password,omitempty"`
	ACPAllowed    *bool   `json:"acpAllowed,omitempty"`
	Thinking      *bool   `json:"thinking,omitempty"`
	ThinkingLevel *string `json:"thinking_level,omitempty"`
	Sandbox       *bool   `json:"sandbox,omitempty"`
}

UpdateUserRequest represents a request to update a user

type UserResponse

type UserResponse struct {
	Username      string  `json:"username"`
	Name          string  `json:"name"`
	Role          string  `json:"role"`
	TelegramID    string  `json:"telegram_id,omitempty"`
	WhatsAppID    string  `json:"whatsapp_id,omitempty"`
	HasPassword   bool    `json:"has_password"`
	ACPAllowed    *bool   `json:"acpAllowed,omitempty"`
	Thinking      *bool   `json:"thinking,omitempty"`
	ThinkingLevel *string `json:"thinking_level,omitempty"`
	Sandbox       *bool   `json:"sandbox,omitempty"`
}

UserResponse represents a user in API responses (without password hash)

type UsersAPI

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

UsersAPI provides API endpoints for user management

func NewUsersAPI

func NewUsersAPI(configPath string) *UsersAPI

NewUsersAPI creates a new users API handler

func (*UsersAPI) HandleCreateUser

func (u *UsersAPI) HandleCreateUser(w http.ResponseWriter, r *http.Request)

HandleCreateUser creates a new user (POST /setup/api/users)

func (*UsersAPI) HandleListUsers

func (u *UsersAPI) HandleListUsers(w http.ResponseWriter, r *http.Request)

HandleListUsers returns all users (GET /setup/api/users)

func (*UsersAPI) HandleRoles

func (u *UsersAPI) HandleRoles(w http.ResponseWriter, r *http.Request)

HandleRoles returns available roles (GET /setup/api/roles)

func (*UsersAPI) HandleUpdateOwnerPairing added in v0.1.9

func (u *UsersAPI) HandleUpdateOwnerPairing(w http.ResponseWriter, r *http.Request)

HandleUpdateOwnerPairing applies staged owner channel identities.

func (*UsersAPI) HandleUser

func (u *UsersAPI) HandleUser(w http.ResponseWriter, r *http.Request)

HandleUser handles GET, PUT, DELETE for a specific user

type WizardAPI

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

WizardAPI provides API endpoints for the wizard

func NewWizardAPI

func NewWizardAPI(configPath string, _ configapply.Caller) *WizardAPI

NewWizardAPI creates a new wizard API handler

func (*WizardAPI) HandleFinish

func (w *WizardAPI) HandleFinish(rw http.ResponseWriter, r *http.Request)

HandleFinish saves the final configuration

func (*WizardAPI) HandleGetModels

func (w *WizardAPI) HandleGetModels(rw http.ResponseWriter, r *http.Request)

HandleGetModels returns available models for a provider

func (*WizardAPI) HandleGetState

func (w *WizardAPI) HandleGetState(rw http.ResponseWriter, r *http.Request)

HandleGetState returns the current wizard state

func (*WizardAPI) HandleGetStep

func (w *WizardAPI) HandleGetStep(rw http.ResponseWriter, r *http.Request)

HandleGetStep returns the FormDef and current data for a specific step

func (*WizardAPI) HandlePairingAction added in v0.1.9

func (w *WizardAPI) HandlePairingAction(rw http.ResponseWriter, r *http.Request)

HandlePairingAction handles wizard pairing start/status/cancel requests.

func (*WizardAPI) HandlePrevStep

func (w *WizardAPI) HandlePrevStep(rw http.ResponseWriter, r *http.Request)

HandlePrevStep goes back to the previous step

func (*WizardAPI) HandleSubmitStep

func (w *WizardAPI) HandleSubmitStep(rw http.ResponseWriter, r *http.Request)

HandleSubmitStep validates and saves data for the current step

func (*WizardAPI) Reset added in v0.1.3

func (w *WizardAPI) Reset()

Reset reloads wizard data and returns the wizard to step 1.

type WizardState

type WizardState struct {
	Step            int               `json:"step"`
	Data            *setup.WizardData `json:"data"`
	PairingSessions map[string]string `json:"-"`
	// contains filtered or unexported fields
}

WizardState holds the current wizard session state

type WizardStep

type WizardStep struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

WizardStep defines a single step in the setup wizard

Jump to

Keyboard shortcuts

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