feat(web): add agent management UI and improve launcher integration (#1358)
* Improve the web launcher and gateway integration across backend and frontend.
- add runtime model availability checks for local and OAuth-backed models
- support launcher-driven gateway host overrides and websocket URL resolution
- add gateway log clearing and keep incremental log sync consistent after resets
- migrate session history APIs to JSONL metadata-backed storage with legacy fallback
- expose session titles and improve chat history loading and error handling
- move shared backend runtime helpers into the web utils package
- avoid blocking web startup when automatic onboard initialization fails
- add backend tests covering gateway readiness, host resolution, models, logs, and sessions
* feat(agent): add skills and tools management APIs and UI
- add backend APIs to list, view, import, and delete skills
- add tool status and toggle endpoints with dependency-aware config updates
- add agent skills/tools pages, routes, sidebar entries, and i18n strings
- add backend tests for the new skills and tools flows
* chore(frontend): upgrade shadcn to 4.0.5 and refresh lockfile
* chore(web): keep backend dist placeholder tracked
2026-03-11 10:37:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
2026-03-17 10:46:00 +00:00
|
|
|
"net/url"
|
feat(web): add agent management UI and improve launcher integration (#1358)
* Improve the web launcher and gateway integration across backend and frontend.
- add runtime model availability checks for local and OAuth-backed models
- support launcher-driven gateway host overrides and websocket URL resolution
- add gateway log clearing and keep incremental log sync consistent after resets
- migrate session history APIs to JSONL metadata-backed storage with legacy fallback
- expose session titles and improve chat history loading and error handling
- move shared backend runtime helpers into the web utils package
- avoid blocking web startup when automatic onboard initialization fails
- add backend tests covering gateway readiness, host resolution, models, logs, and sessions
* feat(agent): add skills and tools management APIs and UI
- add backend APIs to list, view, import, and delete skills
- add tool status and toggle endpoints with dependency-aware config updates
- add agent skills/tools pages, routes, sidebar entries, and i18n strings
- add backend tests for the new skills and tools flows
* chore(frontend): upgrade shadcn to 4.0.5 and refresh lockfile
* chore(web): keep backend dist placeholder tracked
2026-03-11 10:37:00 +00:00
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (h *Handler) effectiveLauncherPublic() bool {
|
|
|
|
|
if h.serverPublicExplicit {
|
|
|
|
|
return h.serverPublic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := h.loadLauncherConfig()
|
|
|
|
|
if err == nil {
|
|
|
|
|
return cfg.Public
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h.serverPublic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *Handler) gatewayHostOverride() string {
|
|
|
|
|
if h.effectiveLauncherPublic() {
|
|
|
|
|
return "0.0.0.0"
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *Handler) effectiveGatewayBindHost(cfg *config.Config) string {
|
|
|
|
|
if override := h.gatewayHostOverride(); override != "" {
|
|
|
|
|
return override
|
|
|
|
|
}
|
|
|
|
|
if cfg == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return strings.TrimSpace(cfg.Gateway.Host)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func gatewayProbeHost(bindHost string) string {
|
|
|
|
|
if bindHost == "" || bindHost == "0.0.0.0" {
|
|
|
|
|
return "127.0.0.1"
|
|
|
|
|
}
|
|
|
|
|
return bindHost
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 10:46:00 +00:00
|
|
|
func (h *Handler) gatewayProxyURL() *url.URL {
|
|
|
|
|
cfg, err := config.LoadConfig(h.configPath)
|
|
|
|
|
port := 18790
|
|
|
|
|
bindHost := ""
|
|
|
|
|
if err == nil && cfg != nil {
|
|
|
|
|
if cfg.Gateway.Port != 0 {
|
|
|
|
|
port = cfg.Gateway.Port
|
|
|
|
|
}
|
|
|
|
|
bindHost = h.effectiveGatewayBindHost(cfg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &url.URL{
|
|
|
|
|
Scheme: "http",
|
|
|
|
|
Host: net.JoinHostPort(gatewayProbeHost(bindHost), strconv.Itoa(port)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat(web): add agent management UI and improve launcher integration (#1358)
* Improve the web launcher and gateway integration across backend and frontend.
- add runtime model availability checks for local and OAuth-backed models
- support launcher-driven gateway host overrides and websocket URL resolution
- add gateway log clearing and keep incremental log sync consistent after resets
- migrate session history APIs to JSONL metadata-backed storage with legacy fallback
- expose session titles and improve chat history loading and error handling
- move shared backend runtime helpers into the web utils package
- avoid blocking web startup when automatic onboard initialization fails
- add backend tests covering gateway readiness, host resolution, models, logs, and sessions
* feat(agent): add skills and tools management APIs and UI
- add backend APIs to list, view, import, and delete skills
- add tool status and toggle endpoints with dependency-aware config updates
- add agent skills/tools pages, routes, sidebar entries, and i18n strings
- add backend tests for the new skills and tools flows
* chore(frontend): upgrade shadcn to 4.0.5 and refresh lockfile
* chore(web): keep backend dist placeholder tracked
2026-03-11 10:37:00 +00:00
|
|
|
func requestHostName(r *http.Request) string {
|
|
|
|
|
reqHost, _, err := net.SplitHostPort(r.Host)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return reqHost
|
|
|
|
|
}
|
|
|
|
|
if strings.TrimSpace(r.Host) != "" {
|
|
|
|
|
return r.Host
|
|
|
|
|
}
|
|
|
|
|
return "127.0.0.1"
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 08:25:16 +00:00
|
|
|
func requestWSScheme(r *http.Request) string {
|
|
|
|
|
if forwarded := strings.TrimSpace(r.Header.Get("X-Forwarded-Proto")); forwarded != "" {
|
|
|
|
|
proto := strings.ToLower(strings.TrimSpace(strings.Split(forwarded, ",")[0]))
|
|
|
|
|
if proto == "https" || proto == "wss" {
|
|
|
|
|
return "wss"
|
|
|
|
|
}
|
|
|
|
|
if proto == "http" || proto == "ws" {
|
|
|
|
|
return "ws"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if r.TLS != nil {
|
|
|
|
|
return "wss"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "ws"
|
|
|
|
|
}
|
|
|
|
|
|
feat(web): add agent management UI and improve launcher integration (#1358)
* Improve the web launcher and gateway integration across backend and frontend.
- add runtime model availability checks for local and OAuth-backed models
- support launcher-driven gateway host overrides and websocket URL resolution
- add gateway log clearing and keep incremental log sync consistent after resets
- migrate session history APIs to JSONL metadata-backed storage with legacy fallback
- expose session titles and improve chat history loading and error handling
- move shared backend runtime helpers into the web utils package
- avoid blocking web startup when automatic onboard initialization fails
- add backend tests covering gateway readiness, host resolution, models, logs, and sessions
* feat(agent): add skills and tools management APIs and UI
- add backend APIs to list, view, import, and delete skills
- add tool status and toggle endpoints with dependency-aware config updates
- add agent skills/tools pages, routes, sidebar entries, and i18n strings
- add backend tests for the new skills and tools flows
* chore(frontend): upgrade shadcn to 4.0.5 and refresh lockfile
* chore(web): keep backend dist placeholder tracked
2026-03-11 10:37:00 +00:00
|
|
|
func (h *Handler) buildWsURL(r *http.Request, cfg *config.Config) string {
|
|
|
|
|
host := h.effectiveGatewayBindHost(cfg)
|
|
|
|
|
if host == "" || host == "0.0.0.0" {
|
|
|
|
|
host = requestHostName(r)
|
|
|
|
|
}
|
2026-03-17 09:36:06 +00:00
|
|
|
// Use web server port instead of gateway port to avoid exposing extra ports
|
|
|
|
|
// The WebSocket connection will be proxied by the backend to the gateway
|
|
|
|
|
wsPort := h.serverPort
|
|
|
|
|
if wsPort == 0 {
|
|
|
|
|
wsPort = 18800 // default web server port
|
|
|
|
|
}
|
|
|
|
|
return requestWSScheme(r) + "://" + net.JoinHostPort(host, strconv.Itoa(wsPort)) + "/pico/ws"
|
feat(web): add agent management UI and improve launcher integration (#1358)
* Improve the web launcher and gateway integration across backend and frontend.
- add runtime model availability checks for local and OAuth-backed models
- support launcher-driven gateway host overrides and websocket URL resolution
- add gateway log clearing and keep incremental log sync consistent after resets
- migrate session history APIs to JSONL metadata-backed storage with legacy fallback
- expose session titles and improve chat history loading and error handling
- move shared backend runtime helpers into the web utils package
- avoid blocking web startup when automatic onboard initialization fails
- add backend tests covering gateway readiness, host resolution, models, logs, and sessions
* feat(agent): add skills and tools management APIs and UI
- add backend APIs to list, view, import, and delete skills
- add tool status and toggle endpoints with dependency-aware config updates
- add agent skills/tools pages, routes, sidebar entries, and i18n strings
- add backend tests for the new skills and tools flows
* chore(frontend): upgrade shadcn to 4.0.5 and refresh lockfile
* chore(web): keep backend dist placeholder tracked
2026-03-11 10:37:00 +00:00
|
|
|
}
|