Documentation
¶
Index ¶
- func ClientIPFromRequest(r *http.Request) net.IP
- func IsLANScopeIP(ip net.IP) bool
- type AuthHandler
- type AuthStatusResponse
- type DevicesHandler
- type DiscoverHandler
- type DiscoveryHandler
- type DynamicToolsHandler
- type EventBroadcaster
- type GatewayEvent
- type Handler
- type LANHandler
- type LogBuffer
- type PairRequest
- type PairResponse
- type ProvisioningHandler
- type VerifyResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientIPFromRequest ¶
ClientIPFromRequest 返回用于访问策略的客户端 IP。 默认仅使用 RemoteAddr;开启 MOONHUB_TRUST_PROXY 后才会读取转发头。
func IsLANScopeIP ¶
IsLANScopeIP 判断 IP 是否属于当前阶段允许的「局域网直连」范围:回环、私网/CGNAT/ULA、链路本地(含 IPv4 APIPA)。
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler handles device pairing and authentication API requests.
func NewAuthHandler ¶
func NewAuthHandler(pairingManager *devices.PairingManager, deviceStore *devices.DeviceStore) *AuthHandler
NewAuthHandler creates a new auth API handler.
func (*AuthHandler) RegisterRoutes ¶
func (h *AuthHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers auth routes with the mux.
type AuthStatusResponse ¶
type AuthStatusResponse struct {
Success bool `json:"success"`
Data struct {
Code string `json:"code"`
Paired bool `json:"paired"`
} `json:"data"`
}
AuthStatusResponse represents the auth status response.
type DevicesHandler ¶
type DevicesHandler struct {
// contains filtered or unexported fields
}
DevicesHandler handles paired devices API requests.
func NewDevicesHandler ¶
func NewDevicesHandler(store *devices.DeviceStore) *DevicesHandler
NewDevicesHandler creates a new devices API handler.
func (*DevicesHandler) RegisterRoutes ¶
func (h *DevicesHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers devices routes with the mux.
type DiscoverHandler ¶
type DiscoverHandler struct {
// contains filtered or unexported fields
}
DiscoverHandler handles mDNS device discovery API requests.
func NewDiscoverHandler ¶
func NewDiscoverHandler(client *mdns.Client) *DiscoverHandler
NewDiscoverHandler creates a new discover API handler.
func (*DiscoverHandler) RegisterRoutes ¶
func (h *DiscoverHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers discovery routes with the mux.
type DiscoveryHandler ¶
type DiscoveryHandler struct {
// contains filtered or unexported fields
}
DiscoveryHandler handles device discovery API requests.
func NewDiscoveryHandler ¶
func NewDiscoveryHandler(deviceStore *devices.DeviceStore) *DiscoveryHandler
NewDiscoveryHandler creates a new discovery API handler.
func (*DiscoveryHandler) RegisterRoutes ¶
func (h *DiscoveryHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers discovery routes with the mux.
type DynamicToolsHandler ¶
type DynamicToolsHandler struct {
// contains filtered or unexported fields
}
DynamicToolsHandler handles dynamic tools API requests.
func NewDynamicToolsHandler ¶
func NewDynamicToolsHandler(configPath string) (*DynamicToolsHandler, error)
NewDynamicToolsHandler creates a DynamicToolsHandler with a SQLite-backed ToolManager and a SchemaEngine. The database is stored at <moonhub-home>/dynamic_tools.db.
func (*DynamicToolsHandler) Close ¶
func (h *DynamicToolsHandler) Close()
Close releases the underlying database connection.
func (*DynamicToolsHandler) RegisterRoutes ¶
func (h *DynamicToolsHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers dynamic tools routes on the given ServeMux.
type EventBroadcaster ¶
type EventBroadcaster struct {
// contains filtered or unexported fields
}
EventBroadcaster manages SSE client subscriptions and broadcasts events.
func NewEventBroadcaster ¶
func NewEventBroadcaster() *EventBroadcaster
NewEventBroadcaster creates a new broadcaster.
func (*EventBroadcaster) Broadcast ¶
func (b *EventBroadcaster) Broadcast(event GatewayEvent)
Broadcast sends a GatewayEvent to all connected SSE clients.
func (*EventBroadcaster) Subscribe ¶
func (b *EventBroadcaster) Subscribe() chan string
Subscribe adds a new listener channel and returns it. The caller must call Unsubscribe when done.
func (*EventBroadcaster) Unsubscribe ¶
func (b *EventBroadcaster) Unsubscribe(ch chan string)
Unsubscribe removes a listener channel and closes it.
type GatewayEvent ¶
type GatewayEvent struct {
Status string `json:"gateway_status"` // "running", "starting", "restarting", "stopped", "error"
PID int `json:"pid,omitempty"`
BootDefaultModel string `json:"boot_default_model,omitempty"`
ConfigDefaultModel string `json:"config_default_model,omitempty"`
RestartRequired bool `json:"gateway_restart_required,omitempty"`
}
GatewayEvent represents a state change event for the gateway process.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves HTTP API requests.
func NewHandler ¶
func NewHandler(configPath string, deviceStore *devices.DeviceStore, pairingManager *devices.PairingManager) *Handler
NewHandler creates an instance of the API handler.
func (*Handler) RegisterRoutes ¶
RegisterRoutes binds all API endpoint handlers to the ServeMux.
func (*Handler) SetProvisioningHandler ¶
func (h *Handler) SetProvisioningHandler(handler *ProvisioningHandler)
SetProvisioningHandler sets the provisioning handler for device management.
func (*Handler) SetServerOptions ¶
func (h *Handler) SetServerOptions(port int, public bool, publicExplicit bool, allowedCIDRs []string)
SetServerOptions stores current backend listen options for fallback behavior.
func (*Handler) TryAutoStartGateway ¶
func (h *Handler) TryAutoStartGateway()
TryAutoStartGateway checks whether gateway start preconditions are met and starts it when possible. Intended to be called by the backend at startup.
type LANHandler ¶
type LANHandler struct {
// contains filtered or unexported fields
}
LANHandler handles LAN API requests for chat functionality.
func NewLANHandler ¶
func NewLANHandler( deviceStore *devices.DeviceStore, agentLoop *agent.AgentLoop, deviceID, deviceName, version string, ) *LANHandler
NewLANHandler creates a new LAN API handler.
func NewLANHandlerWithConfig ¶
func NewLANHandlerWithConfig( deviceStore *devices.DeviceStore, agentLoop *agent.AgentLoop, deviceID, deviceName string, ) *LANHandler
NewLANHandlerWithConfig creates a LAN handler with config-based version.
func (*LANHandler) GetSessionManager ¶
func (h *LANHandler) GetSessionManager() *social.SessionManager
GetSessionManager returns the session manager for testing purposes.
func (*LANHandler) RegisterRoutes ¶
func (h *LANHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers LAN API routes with the mux.
func (*LANHandler) SetAgentLoop ¶
func (h *LANHandler) SetAgentLoop(loop *agent.AgentLoop)
SetAgentLoop updates the agent loop reference. This is useful when the agent is initialized after the handler is created.
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
LogBuffer is a thread-safe ring buffer that stores the most recent N log lines. It supports incremental reads via LinesSince and tracks a runID that increments whenever the buffer is reset or cleared so clients can detect log history resets.
func NewLogBuffer ¶
NewLogBuffer creates a LogBuffer with the given capacity.
func (*LogBuffer) Append ¶
Append adds a line to the buffer. If the buffer is full, the oldest line is evicted.
func (*LogBuffer) Clear ¶
func (b *LogBuffer) Clear()
Clear removes all buffered lines and increments the runID so clients treat subsequent reads as a new log stream.
func (*LogBuffer) LinesSince ¶
LinesSince returns lines appended after the given offset, the current total count, and the runID. If offset >= total, no lines are returned. If offset is too old (evicted), all buffered lines are returned.
type PairRequest ¶
type PairRequest struct {
Code string `json:"code"`
DeviceID string `json:"deviceId,omitempty"`
DeviceName string `json:"deviceName,omitempty"`
}
PairRequest represents a pairing request.
func (*PairRequest) UnmarshalJSON ¶
func (p *PairRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts camelCase fields and snake_case aliases (device_id, device_name).
type PairResponse ¶
type PairResponse struct {
Success bool `json:"success"`
Data struct {
Token string `json:"token,omitempty"`
TokenExpiresAt time.Time `json:"tokenExpiresAt,omitempty"`
Device *devices.PairedDevice `json:"device,omitempty"`
} `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
PairResponse represents a pairing response.
type ProvisioningHandler ¶
type ProvisioningHandler struct {
// contains filtered or unexported fields
}
ProvisioningHandler handles device provisioning API requests.
func NewProvisioningHandler ¶
func NewProvisioningHandler(manager *provisioning.DeviceManager) *ProvisioningHandler
NewProvisioningHandler creates a new provisioning API handler.
func (*ProvisioningHandler) RegisterRoutes ¶
func (h *ProvisioningHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes registers provisioning routes with the mux.