Files
magpie/web_cli.go
T
yetone 1534382ff9 gui, web: gateway mode — magpie web on a server that is only a gateway shows no Agents, Sessions or Library (Player on Discord) — a magpie web run on a server or NAS for other machines' agents showed the Agents, Sessions and Library pages and the settings written into this machine's agents, none of which do anything there. In gateway mode the page has Providers, Gateway, Routing, Usage, Plugins and Settings; an address kept for a page left out opens Providers. Settings leaves out provider in model names, Codex subagents, long conversations, Codex thread titles, the usage/balance alerts and reset reminders, on top of the tray, open at login, Dock, text size and lightweight rows magpie web already hid; Language, theme, currency, proxy, redaction, vision/image models, sync, updates and the rest stay. magpie web is in it by itself when it finds no agents on its machine (the Docker image, a NAS) and with the new magpie web --gateway; Settings › General › Gateway mode (Automatic / On / Off, saying why it is on) wins over both and Off brings every page back at once. The choice is this machine's own (KeepOwn: never synced or restored from another computer), set only by POST /api/settings/gateway-mode, never by the Settings page's save. The app's own windows are never in gateway mode. boot.js tells the page before it paints. en/zh/ja/de; docs/reference.md (Docker › NAS, CLI list). TestGatewayMode (temp HOME: no agents → on, agents → off, --gateway → on, Off wins over --gateway, the Settings save leaves it, On with agents, Automatic, an unknown mode refused, the app window never told, KeepOwn) is new; TestSettingsSaveKeepsWhatItDoesNotSend sets it. gateway-mode.test.cjs (WebKit, en and zh: the tabs, ?view=agents/sessions/library open Providers, the switch and why, the seven rows hidden, Off posts "off" and brings tabs and rows back with Settings kept open and Agents opening, Automatic hides them again, the Settings save never sends it, no scroll, no select, no left border; web with agents and the app window keep every tab, the switch is magpie web's alone) fails without the change. mobile-web's desktop comparison differs from origin/main on Settings only, by the new row. settings-sections, settings-groups, click-scroll, cli-path, plain-names, codex-titles and agent-grip pass in WebKit. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
2026-10-05 18:20:28 +08:00

70 lines
2.1 KiB
Go

package main
import (
"fmt"
"net"
"os"
"strings"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/gui"
)
// webAddr is where `magpie web` listens unless told: beside the gateway.
const webAddr = "127.0.0.1:3430"
// webCmd: magpie web [--addr host:port] [--lan] [--no-open] [--gateway] —
// the app's window in a browser, for a computer that can't show the app;
// --gateway shows it in gateway mode (gui.WebGateway) unless Settings says
// otherwise.
func webCmd(args []string) error {
addr, lan, open := webAddr, false, true
for i := 0; i < len(args); i++ {
switch a := args[i]; {
case a == "--addr" && i+1 < len(args):
i++
addr = args[i]
case strings.HasPrefix(a, "--addr="):
addr = strings.TrimPrefix(a, "--addr=")
case a == "--lan":
lan = true
case a == "--no-open":
open = false
case a == "--gateway":
gui.WebGateway.Store(true)
default:
return fmt.Errorf("magpie web: unknown %q · magpie web [--addr host:port] [--lan] [--no-open] [--gateway], MAGPIE_WEB_KEY to keep one key", a)
}
}
if lan && addr == webAddr {
_, port, _ := net.SplitHostPort(webAddr)
addr = "0.0.0.0:" + port
}
w, err := gui.StartWeb(addr, version)
if err != nil {
return err
}
fmt.Println(green.Render("●"), "magpie web on", bold.Render(w.Link))
host, _, _ := net.SplitHostPort(w.Addr)
if ip := net.ParseIP(host); ip != nil && !ip.IsLoopback() {
_, port, _ := net.SplitHostPort(w.Addr)
key := w.Link[strings.Index(w.Link, "/?k="):]
for _, l := range gui.NetworkLinks(port, key) {
fmt.Println(muted.Render(" on the network"), l)
}
if gateway.ContainerAddrs() {
fmt.Println(muted.Render(" " + containerNote))
}
fmt.Println(amber.Render("!"), "anyone with the link can change magpie and see its keys, and the network carries it unencrypted")
}
carries := "this run's key (MAGPIE_WEB_KEY keeps one across runs)"
if os.Getenv("MAGPIE_WEB_KEY") != "" {
carries = "MAGPIE_WEB_KEY"
}
fmt.Println(muted.Render(" the link carries " + carries + " · gateway " + advertisedURL() + " · Ctrl-C to stop"))
if open {
openInBrowser(w.Link)
}
return w.Wait()
}