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 utils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"runtime"
|
2026-03-18 10:03:24 +00:00
|
|
|
|
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
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
|
|
|
)
|
|
|
|
|
|
2026-03-18 06:43:58 +00:00
|
|
|
// GetPicoclawHome returns the picoclaw home directory.
|
|
|
|
|
// Priority: $PICOCLAW_HOME > ~/.picoclaw
|
|
|
|
|
func GetPicoclawHome() string {
|
2026-03-18 10:03:24 +00:00
|
|
|
if home := os.Getenv(config.EnvHome); home != "" {
|
2026-03-18 06:43:58 +00:00
|
|
|
return home
|
|
|
|
|
}
|
|
|
|
|
home, _ := os.UserHomeDir()
|
|
|
|
|
return filepath.Join(home, ".picoclaw")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 10:03:24 +00:00
|
|
|
// GetDefaultConfigPath returns the default path to the picoclaw config file.
|
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 GetDefaultConfigPath() string {
|
2026-03-18 10:03:24 +00:00
|
|
|
if configPath := os.Getenv(config.EnvConfig); configPath != "" {
|
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
|
|
|
return configPath
|
|
|
|
|
}
|
2026-03-18 06:43:58 +00:00
|
|
|
return filepath.Join(GetPicoclawHome(), "config.json")
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FindPicoclawBinary locates the picoclaw executable.
|
|
|
|
|
// Search order:
|
|
|
|
|
// 1. PICOCLAW_BINARY environment variable (explicit override)
|
|
|
|
|
// 2. Same directory as the current executable
|
|
|
|
|
// 3. Falls back to "picoclaw" and relies on $PATH
|
|
|
|
|
func FindPicoclawBinary() string {
|
|
|
|
|
binaryName := "picoclaw"
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
binaryName = "picoclaw.exe"
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 10:03:24 +00:00
|
|
|
if p := os.Getenv(config.EnvBinary); p != "" {
|
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
|
|
|
if info, _ := os.Stat(p); info != nil && !info.IsDir() {
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if exe, err := os.Executable(); err == nil {
|
|
|
|
|
candidate := filepath.Join(filepath.Dir(exe), binaryName)
|
|
|
|
|
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
|
|
|
|
|
return candidate
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "picoclaw"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetLocalIP returns the local IP address of the machine.
|
|
|
|
|
func GetLocalIP() string {
|
|
|
|
|
addrs, err := net.InterfaceAddrs()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
for _, a := range addrs {
|
|
|
|
|
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil {
|
|
|
|
|
return ipnet.IP.String()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OpenBrowser automatically opens the given URL in the default browser.
|
|
|
|
|
func OpenBrowser(url string) error {
|
|
|
|
|
switch runtime.GOOS {
|
|
|
|
|
case "linux":
|
|
|
|
|
return exec.Command("xdg-open", url).Start()
|
|
|
|
|
case "windows":
|
|
|
|
|
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
|
|
|
|
case "darwin":
|
|
|
|
|
return exec.Command("open", url).Start()
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unsupported platform")
|
|
|
|
|
}
|
|
|
|
|
}
|