gui: settings page — theme, language, about; deeper panel palette
A gear in the header opens Preferences: appearance (system/light/dark) and language (system/English/中文), applied at once and kept in ~/.config/dial/settings.json. The About card shows the version, config folder (copy/open) and gateway URL. Every visible string goes through t() with a Chinese table in i18n.js. The panel gets a tonal ladder of its own (bg, card, pill) with hairline edges and a legible --faint, instead of the pale flat wash.
This commit is contained in:
+41
-7
@@ -19,15 +19,20 @@ import (
|
||||
"github.com/yetone/dial/internal/gateway"
|
||||
"github.com/yetone/dial/internal/profile"
|
||||
"github.com/yetone/dial/internal/provider"
|
||||
"github.com/yetone/dial/internal/settings"
|
||||
)
|
||||
|
||||
// Version is the build's version string, shown in Settings.
|
||||
var Version = "dev"
|
||||
|
||||
//go:embed assets
|
||||
var assets embed.FS
|
||||
|
||||
// Windows is what the API needs from the host application.
|
||||
type Windows interface {
|
||||
HidePanel()
|
||||
ShowMain()
|
||||
// ShowMain brings the window up, on the named tab when view is set.
|
||||
ShowMain(view string)
|
||||
Quit()
|
||||
// OpenURL hands a link to the system browser.
|
||||
OpenURL(url string)
|
||||
@@ -56,10 +61,24 @@ type profileJSON struct {
|
||||
}
|
||||
|
||||
type stateJSON struct {
|
||||
Agents []agentJSON `json:"agents"`
|
||||
Profiles []profileJSON `json:"profiles"`
|
||||
Catalog string `json:"catalog"`
|
||||
Notice string `json:"notice,omitempty"` // advice after a change, e.g. "restart Codex"
|
||||
Agents []agentJSON `json:"agents"`
|
||||
Profiles []profileJSON `json:"profiles"`
|
||||
Catalog string `json:"catalog"`
|
||||
Notice string `json:"notice,omitempty"` // advice after a change, e.g. "restart Codex"
|
||||
Settings settings.Settings `json:"settings"`
|
||||
}
|
||||
|
||||
// settingsJSON is the Settings page: the two choices plus the facts it shows.
|
||||
type settingsJSON struct {
|
||||
settings.Settings
|
||||
Version string `json:"version"`
|
||||
Dir string `json:"dir"` // where dial keeps its files, as shown
|
||||
Path string `json:"path"` // the same, absolute, for opening it
|
||||
Gateway string `json:"gateway"` // the local endpoint
|
||||
}
|
||||
|
||||
func settingsState() settingsJSON {
|
||||
return settingsJSON{Settings: settings.Load(), Version: Version, Dir: tilde(settings.Dir()), Path: settings.Dir(), Gateway: gateway.URL()}
|
||||
}
|
||||
|
||||
// Handler serves the embedded UI and the JSON API.
|
||||
@@ -145,12 +164,27 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
})
|
||||
providerRoutes(mux, w, gw)
|
||||
usageRoutes(mux)
|
||||
mux.HandleFunc("GET /api/settings", func(rw http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
mux.HandleFunc("POST /api/settings", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in settings.Settings
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
if err := settings.Save(in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
mux.HandleFunc("POST /api/window/{action}", func(rw http.ResponseWriter, r *http.Request) {
|
||||
switch r.PathValue("action") {
|
||||
case "hide":
|
||||
w.HidePanel()
|
||||
case "main":
|
||||
w.ShowMain()
|
||||
w.ShowMain(r.URL.Query().Get("view"))
|
||||
case "quit":
|
||||
w.Quit()
|
||||
case "fit":
|
||||
@@ -165,7 +199,7 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
}
|
||||
|
||||
func state() stateJSON {
|
||||
s := stateJSON{Agents: []agentJSON{}, Profiles: []profileJSON{}, Catalog: catalog.Source()}
|
||||
s := stateJSON{Agents: []agentJSON{}, Profiles: []profileJSON{}, Catalog: catalog.Source(), Settings: settings.Load()}
|
||||
for _, a := range agent.Detected() {
|
||||
vals := a.Values()
|
||||
aj := agentJSON{ID: a.ID, Name: a.Name, Icon: a.Icon, Path: tilde(a.Path)}
|
||||
|
||||
+9
-4
@@ -26,11 +26,15 @@ type host struct {
|
||||
tray *application.SystemTray
|
||||
|
||||
panelHeight int
|
||||
query string // what the windows' URLs carry (a forced theme)
|
||||
}
|
||||
|
||||
func (h *host) HidePanel() { h.panel.Hide() }
|
||||
func (h *host) ShowMain() {
|
||||
func (h *host) ShowMain(view string) {
|
||||
h.panel.Hide()
|
||||
if view != "" {
|
||||
h.main.SetURL("/?view=" + view + h.query)
|
||||
}
|
||||
h.main.Show()
|
||||
h.main.Focus()
|
||||
}
|
||||
@@ -73,7 +77,8 @@ func Run(version string, showMain bool) error {
|
||||
if t := os.Getenv("DIAL_THEME"); t != "" {
|
||||
theme = "&theme=" + t
|
||||
}
|
||||
h := &host{}
|
||||
Version = version
|
||||
h := &host{query: theme}
|
||||
h.app = application.New(application.Options{
|
||||
Name: "dial",
|
||||
Description: "one dial for every coding agent's model",
|
||||
@@ -124,7 +129,7 @@ func Run(version string, showMain bool) error {
|
||||
})
|
||||
|
||||
menu := h.app.NewMenu()
|
||||
menu.Add("Open dial").OnClick(func(*application.Context) { h.ShowMain() })
|
||||
menu.Add("Open dial").OnClick(func(*application.Context) { h.ShowMain("") })
|
||||
menu.AddSeparator()
|
||||
menu.Add("Version " + version).SetEnabled(false)
|
||||
menu.Add("Quit dial").OnClick(func(*application.Context) { h.app.Quit() })
|
||||
@@ -140,7 +145,7 @@ func Run(version string, showMain bool) error {
|
||||
h.tray.AttachWindow(h.panel).WindowOffset(6)
|
||||
|
||||
if showMain {
|
||||
h.app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) { h.ShowMain() })
|
||||
h.app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) { h.ShowMain("") })
|
||||
}
|
||||
return h.app.Run()
|
||||
}
|
||||
|
||||
+27
-12
@@ -83,16 +83,16 @@ body {
|
||||
cursor: default;
|
||||
}
|
||||
/* The tray panel sits on a frosted NSVisualEffectView, so its own paint is thin. */
|
||||
body.panel { background: color-mix(in srgb, var(--bg) 78%, transparent); border-radius: 12px; }
|
||||
body.panel { background: color-mix(in srgb, var(--bg) 93%, transparent); border-radius: 12px; }
|
||||
/* on the frosted panel the surfaces are tints of the backdrop, not flat paint */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root:not([data-theme="light"]) body.panel { --card: rgba(255, 255, 255, .05); --card-2: rgba(255, 255, 255, .03); --line: rgba(255, 255, 255, .09); --line-2: rgba(255, 255, 255, .07); --pill: rgba(255, 255, 255, .085); --pill-hover: rgba(255, 255, 255, .14); }
|
||||
:root:not([data-theme="light"]) body.panel { --bg: #1b1c20; --card: #25262c; --card-2: #212227; --line: rgba(255, 255, 255, .07); --line-2: rgba(255, 255, 255, .06); --pill: #2e2f36; --pill-hover: #383942; --pill-line: rgba(255, 255, 255, .11); --pill-shadow: 0 1px 2px rgba(0, 0, 0, .28); --muted: #9c9ca6; --faint: #7c7c87; --card-edge: inset 0 0 0 1px rgba(255, 255, 255, .06); }
|
||||
}
|
||||
:root[data-theme="dark"] body.panel { --card: rgba(255, 255, 255, .05); --card-2: rgba(255, 255, 255, .03); --line: rgba(255, 255, 255, .09); --line-2: rgba(255, 255, 255, .07); --pill: rgba(255, 255, 255, .085); --pill-hover: rgba(255, 255, 255, .14); }
|
||||
:root[data-theme="dark"] body.panel { --bg: #1b1c20; --card: #25262c; --card-2: #212227; --line: rgba(255, 255, 255, .07); --line-2: rgba(255, 255, 255, .06); --pill: #2e2f36; --pill-hover: #383942; --pill-line: rgba(255, 255, 255, .11); --pill-shadow: 0 1px 2px rgba(0, 0, 0, .28); --muted: #9c9ca6; --faint: #7c7c87; --card-edge: inset 0 0 0 1px rgba(255, 255, 255, .06); }
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root:not([data-theme="dark"]) body.panel { --card: rgba(255, 255, 255, .72); --line: rgba(0, 0, 0, .07); --line-2: rgba(0, 0, 0, .06); --pill: rgba(0, 0, 0, .05); --pill-hover: rgba(0, 0, 0, .09); }
|
||||
:root:not([data-theme="dark"]) body.panel { --bg: #f2f2f5; --card: #ffffff; --card-2: #f8f8fa; --line: rgba(0, 0, 0, .07); --line-2: rgba(0, 0, 0, .06); --pill: #ffffff; --pill-hover: #f4f4f7; --pill-line: rgba(0, 0, 0, .12); --pill-shadow: 0 1px 1px rgba(0, 0, 0, .06); --faint: #9a9aa3; --card-edge: 0 0 0 1px rgba(0, 0, 0, .05), 0 1px 2px rgba(0, 0, 0, .04); }
|
||||
}
|
||||
:root[data-theme="light"] body.panel { --card: rgba(255, 255, 255, .72); --line: rgba(0, 0, 0, .07); --line-2: rgba(0, 0, 0, .06); --pill: rgba(0, 0, 0, .05); --pill-hover: rgba(0, 0, 0, .09); }
|
||||
:root[data-theme="light"] body.panel { --bg: #f2f2f5; --card: #ffffff; --card-2: #f8f8fa; --line: rgba(0, 0, 0, .07); --line-2: rgba(0, 0, 0, .06); --pill: #ffffff; --pill-hover: #f4f4f7; --pill-line: rgba(0, 0, 0, .12); --pill-shadow: 0 1px 1px rgba(0, 0, 0, .06); --faint: #9a9aa3; --card-edge: 0 0 0 1px rgba(0, 0, 0, .05), 0 1px 2px rgba(0, 0, 0, .04); }
|
||||
button { font: inherit; color: inherit; background: none; border: 0; cursor: default; }
|
||||
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||||
input { font: inherit; color: var(--fg); }
|
||||
@@ -127,7 +127,7 @@ body.panel .seg { display: none; }
|
||||
color: var(--muted);
|
||||
transition: background .12s, color .12s;
|
||||
}
|
||||
.icon:hover { background: var(--pill); color: var(--fg); }
|
||||
.icon:hover, .icon.on { background: var(--pill); color: var(--fg); }
|
||||
.icon.spin svg { animation: spin .9s linear infinite; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
@@ -136,13 +136,13 @@ body.panel .seg { display: none; }
|
||||
body.window .view { padding: 2px 16px 8px; }
|
||||
.view::-webkit-scrollbar { width: 0; }
|
||||
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
|
||||
body.panel .list { border: 0; border-radius: 10px; }
|
||||
body.panel .list { border: 0; border-radius: 10px; box-shadow: var(--card-edge); }
|
||||
.row { display: flex; align-items: center; gap: 9px; min-height: 40px; padding: 5px 9px 5px 11px; }
|
||||
body.window .row { min-height: 48px; padding: 7px 12px 7px 14px; gap: 12px; }
|
||||
.row + .row, .editor + .row, .row + .editor { border-top: 1px solid var(--line-2); }
|
||||
.row .ic { width: 18px; height: 18px; }
|
||||
body.window .row .ic { width: 22px; height: 22px; }
|
||||
.row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
||||
.row .name { font-weight: 500; letter-spacing: -.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
||||
.row .who { min-width: 0; flex: 1 1 auto; }
|
||||
.row .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
|
||||
.empty-state { padding: 36px 20px; text-align: center; color: var(--muted); }
|
||||
@@ -163,15 +163,18 @@ body.panel .fields { width: 272px; grid-template-columns: minmax(0, 1fr) 118px;
|
||||
font-size: 12.5px;
|
||||
transition: background .12s, box-shadow .12s;
|
||||
}
|
||||
body.panel .field { height: 24px; font-size: 12px; }
|
||||
/* on the panel a control is a real pop-up button: hairline edge, a breath of shadow */
|
||||
body.panel .field { height: 24px; font-size: 12px; box-shadow: inset 0 0 0 1px var(--pill-line), var(--pill-shadow); }
|
||||
body.panel .field:hover { box-shadow: inset 0 0 0 1px var(--pill-line), var(--pill-shadow); }
|
||||
body.panel .field.open { box-shadow: inset 0 0 0 1px var(--accent), var(--pill-shadow); }
|
||||
.field.main, .field.solo { justify-self: end; }
|
||||
.field.solo { grid-column: 1 / -1; }
|
||||
.field:hover, .field.open { background: var(--pill-hover); }
|
||||
.field.open { box-shadow: inset 0 0 0 1px var(--accent); }
|
||||
.row .field .ic, body.window .row .field .ic { width: 14px; height: 14px; }
|
||||
.field .k { color: var(--muted); font-size: 11.5px; flex: none; }
|
||||
.field .v { min-width: 0; flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
|
||||
.field .v.empty { color: var(--fg-2); }
|
||||
.field .k { color: var(--faint); font-size: 11.5px; flex: none; }
|
||||
.field .v { min-width: 0; flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; font-weight: 500; }
|
||||
.field .v.empty { color: var(--muted); font-weight: 400; }
|
||||
.field .chev { color: var(--faint); display: inline-flex; margin-left: auto; padding-left: 1px; }
|
||||
.field:hover .chev, .field.open .chev { color: var(--muted); }
|
||||
.field.flash { animation: flash 1.2s ease-out; }
|
||||
@@ -488,3 +491,15 @@ body.panel .editor { padding-left: 14px; }
|
||||
.mfoot { display: flex; align-items: center; gap: 6px; }
|
||||
.mfoot input { max-width: 200px; height: 25px !important; }
|
||||
.mfoot .text { padding: 2px 7px; }
|
||||
|
||||
/* ---------- settings ---------- */
|
||||
#view-settings .row-head { margin: 4px 0 6px; padding: 0 2px; }
|
||||
#view-settings .row-head + .list { margin-bottom: 8px; }
|
||||
.row.pref { min-height: 50px; padding: 8px 12px 8px 14px; gap: 14px; }
|
||||
.row.pref .who { flex: 1 1 auto; }
|
||||
.row.pref .sub { margin-top: 2px; }
|
||||
.row.pref .segs { flex: none; margin-left: auto; }
|
||||
.prefs .val { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; min-width: 0; max-width: 60%; flex: none; }
|
||||
.prefs .val code { font-size: 12px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: text; -webkit-user-select: text; padding: 0 6px; }
|
||||
.prefs .val .text { padding: 3px 6px; }
|
||||
|
||||
|
||||
+212
-146
@@ -6,7 +6,8 @@ const mode = params.get("mode") || "window";
|
||||
document.body.classList.add(mode);
|
||||
if (params.get("theme")) document.documentElement.dataset.theme = params.get("theme");
|
||||
|
||||
let state = { agents: [], profiles: [], catalog: "" };
|
||||
let state = { agents: [], profiles: [], catalog: "", settings: {} };
|
||||
let prefs = null; // the settings page: theme, lang, version, dir, gateway
|
||||
let providers = null; // { providers, presets, gateway }
|
||||
let view = "agents";
|
||||
let period = "30d"; // usage window
|
||||
@@ -99,7 +100,7 @@ function renderAgents() {
|
||||
list.replaceChildren();
|
||||
if (!state.agents.length) {
|
||||
const e = el("div", "empty-state");
|
||||
e.append(el("b", "", "No coding agents found"), el("span", "", "Install Claude Code, Codex, Gemini CLI, OpenCode… and dial will list them here."));
|
||||
e.append(el("b", "", t("No coding agents found")), el("span", "", t("Install Claude Code, Codex, Gemini CLI, OpenCode… and dial will list them here.")));
|
||||
list.append(e);
|
||||
}
|
||||
for (const a of state.agents) {
|
||||
@@ -116,10 +117,10 @@ function renderAgents() {
|
||||
for (const f of sorted) {
|
||||
const b = el("button", "field " + (sorted.length === 1 ? "solo" : wide(f) ? "main" : "side"));
|
||||
const opt = optionFor(f, f.value);
|
||||
b.title = `${f.label}: ${f.value || "agent default"}` + (opt?.note ? ` · ${opt.note}` : "");
|
||||
b.title = t("{label}: {value}", { label: t(f.label), value: f.value || t("agent default") }) + (opt?.note ? ` · ${opt.note}` : "");
|
||||
if (opt?.icon) b.append(icon(opt.icon));
|
||||
else if (!wide(f) || !f.value) b.append(el("span", "k", f.label));
|
||||
b.append(el("span", "v" + (f.value ? "" : " empty"), opt?.label || f.value || "default"));
|
||||
else if (!wide(f) || !f.value) b.append(el("span", "k", t(f.label)));
|
||||
b.append(el("span", "v" + (f.value ? "" : " empty"), opt?.label || f.value || t("default")));
|
||||
const c = el("span", "chev");
|
||||
c.append(svg(CHEV, 11, 1.7));
|
||||
b.append(c);
|
||||
@@ -132,13 +133,13 @@ function renderAgents() {
|
||||
|
||||
const chips = $("#profiles");
|
||||
chips.replaceChildren();
|
||||
if (!state.profiles.length) chips.append(el("span", "hint", "none yet · save the setup to switch back in one click"));
|
||||
if (!state.profiles.length) chips.append(el("span", "hint", t("none yet · save the setup to switch back in one click")));
|
||||
for (const p of state.profiles) {
|
||||
const c = el("button", "chip");
|
||||
c.title = p.summary;
|
||||
c.append(el("span", "", p.name));
|
||||
const x = el("span", "x", "×");
|
||||
x.title = "Delete profile";
|
||||
x.title = t("Delete profile");
|
||||
x.onclick = (ev) => { ev.stopPropagation(); profileAction("delete", p.name); };
|
||||
c.append(x);
|
||||
c.onclick = () => profileAction("use", p.name);
|
||||
@@ -157,9 +158,11 @@ function fit() {
|
||||
async function load() {
|
||||
try {
|
||||
state = await api("state");
|
||||
applyPrefs(state.settings);
|
||||
renderAgents();
|
||||
if (view === "providers" || view === "gateway") await loadProviders();
|
||||
if (view === "usage") await loadUsage();
|
||||
if (view === "settings") await loadSettings();
|
||||
} catch (e) {
|
||||
status(e.message, "err");
|
||||
}
|
||||
@@ -203,9 +206,9 @@ function openPicker(agent, field, anchor, ev, only) {
|
||||
// current value first, then the rest in catalog order
|
||||
const i = options.findIndex((o) => o.value === cur);
|
||||
if (i > 0) { const [c] = options.splice(i, 1); options.unshift({ ...c, group: "" }); }
|
||||
else if (i < 0 && cur && !only) options.unshift({ value: cur, note: "current value" });
|
||||
else if (i < 0 && cur && !only) options.unshift({ value: cur, note: t("current value") });
|
||||
// the agent's own default: dial's wiring comes out and the key is removed
|
||||
if (!only) options.unshift({ value: "", label: "Default", note: `what ${agent.name} ships with`, icon: agent.icon, reset: true });
|
||||
if (!only) options.unshift({ value: "", label: t("Default"), note: t("what {agent} ships with", { agent: agent.name }), icon: agent.icon, reset: true });
|
||||
pick = { agent, field, options, anchor, cursor: 0, free: !only };
|
||||
anchor.classList.add("open");
|
||||
const pop = $("#pop");
|
||||
@@ -213,7 +216,7 @@ function openPicker(agent, field, anchor, ev, only) {
|
||||
placePop(anchor, options.some((o) => o.note && o.note !== o.value) ? 372 : 300, 340);
|
||||
const q = $("#q");
|
||||
q.value = "";
|
||||
q.placeholder = field.label === "model" ? (only ? "Filter models…" : "Filter, or type any model id…") : `Filter ${field.label}…`;
|
||||
q.placeholder = field.label === "model" ? (only ? t("Filter models…") : t("Filter, or type any model id…")) : t("Filter {field}…", { field: t(field.label) });
|
||||
filter();
|
||||
q.focus();
|
||||
}
|
||||
@@ -227,7 +230,7 @@ function filter() {
|
||||
pick.items = scored.map((x) => x.o);
|
||||
const typed = $("#q").value.trim();
|
||||
if (typed && pick.free && pick.field.label === "model" && !pick.items.some((o) => o.value === typed)) {
|
||||
pick.items.push({ value: typed, note: "use as typed", custom: true });
|
||||
pick.items.push({ value: typed, note: t("use as typed"), custom: true });
|
||||
}
|
||||
pick.cursor = 0;
|
||||
renderList();
|
||||
@@ -236,7 +239,7 @@ function filter() {
|
||||
function renderList() {
|
||||
const list = $("#list");
|
||||
list.replaceChildren();
|
||||
if (!pick.items.length) { list.append(el("div", "none", "No matches.")); return; }
|
||||
if (!pick.items.length) { list.append(el("div", "none", t("No matches."))); return; }
|
||||
const hasIcons = pick.items.some((o) => o.icon);
|
||||
const q = $("#q").value.trim();
|
||||
let group = null;
|
||||
@@ -279,7 +282,7 @@ async function commit(value) {
|
||||
b?.classList.add("flash");
|
||||
const shown = opt?.label || value;
|
||||
if (state.notice) status(`${agent.name} → ${shown}. ${state.notice}`, "warn", 9000);
|
||||
else status(`${agent.name} ${field.label} → ${shown}`, "ok");
|
||||
else status(`${agent.name} ${t(field.label)} → ${shown}`, "ok");
|
||||
if (providers) loadProviders();
|
||||
} catch (e) {
|
||||
status(e.message, "err");
|
||||
@@ -312,9 +315,9 @@ async function profileAction(action, name) {
|
||||
const data = await api("profile/" + action, { name });
|
||||
state = data;
|
||||
renderAgents();
|
||||
if (action === "use") status(`${name} applied · ${data.changed} setting${data.changed === 1 ? "" : "s"} changed`, "ok");
|
||||
else if (action === "save") status(`Saved ${name}`, "ok");
|
||||
else status(`Deleted ${name}`);
|
||||
if (action === "use") status(t(data.changed === 1 ? "{name} applied · {n} setting changed" : "{name} applied · {n} settings changed", { name, n: data.changed }), "ok");
|
||||
else if (action === "save") status(t("Saved {name}", { name }), "ok");
|
||||
else status(t("Deleted {name}", { name }));
|
||||
} catch (e) {
|
||||
status(e.message, "err");
|
||||
}
|
||||
@@ -324,7 +327,7 @@ $("#save").onclick = () => {
|
||||
const chips = $("#profiles");
|
||||
if (chips.querySelector(".chip-input")) return;
|
||||
const input = el("input", "chip-input");
|
||||
input.placeholder = "Profile name";
|
||||
input.placeholder = t("Profile name");
|
||||
input.onkeydown = (e) => {
|
||||
if (e.key === "Enter" && input.value.trim()) profileAction("save", input.value.trim());
|
||||
else if (e.key === "Escape") input.remove();
|
||||
@@ -361,22 +364,22 @@ function renderProviders() {
|
||||
row.dataset.id = p.id;
|
||||
const who = el("div", "who");
|
||||
const name = el("div", "name", p.name);
|
||||
if (p.sponsored) name.append(el("span", "badge", "sponsored"));
|
||||
if (p.sponsored) name.append(el("span", "badge", t("sponsored")));
|
||||
const n = p.models.filter((m) => m.on).length;
|
||||
const models = n ? `${n} model${n === 1 ? "" : "s"}` : "no models exposed";
|
||||
who.append(name, el("div", "sub", (p.account ? "signed in as " + p.account.user : p.host) + " · " + models));
|
||||
const models = n ? t(n === 1 ? "{n} model" : "{n} models", { n }) : t("no models exposed");
|
||||
who.append(name, el("div", "sub", (p.account ? t("signed in as {user}", { user: p.account.user }) : p.host) + " · " + models));
|
||||
const using = p.agents.filter((a) => a.current);
|
||||
const uses = el("div", "uses");
|
||||
for (const a of using) {
|
||||
const b = el("button", "use");
|
||||
b.title = `${a.name} · ${a.model} — click to change`;
|
||||
b.title = t("{name} · {model} — click to change", { name: a.name, model: a.model });
|
||||
b.append(icon(a.icon));
|
||||
b.onclick = (ev) => pickForAgent(a, p, b, ev);
|
||||
uses.append(b);
|
||||
}
|
||||
if (p.agents.some((a) => !a.current && canUse(a, p))) {
|
||||
const b = el("button", "use add");
|
||||
b.title = using.length ? "Point another agent at " + p.name : "Point an agent at " + p.name;
|
||||
b.title = t(using.length ? "Point another agent at {p}" : "Point an agent at {p}", { p: p.name });
|
||||
b.append(svg(PLUS, 11, 1.8));
|
||||
b.onclick = (ev) => { ev.stopPropagation(); editing = p.id; draft = null; adding = false; renderProviders(); };
|
||||
uses.append(b);
|
||||
@@ -384,10 +387,10 @@ function renderProviders() {
|
||||
let key;
|
||||
if (p.account) {
|
||||
key = el("span", "key acct", accountPlan(p.account));
|
||||
key.title = `${p.account.agentName} is signed in; its models are here for every other agent`;
|
||||
key.title = t("{agent} is signed in; its models are here for every other agent", { agent: p.account.agentName });
|
||||
} else {
|
||||
key = el("span", "key " + (p.key.set ? "on" : p.ready ? "free" : "none"), p.key.set ? p.key.masked : p.ready ? "no key" : "needs a key");
|
||||
key.title = p.key.set ? "API key " + p.key.masked : p.ready ? "Local servers need no key" : "Open the row and paste an API key";
|
||||
key = el("span", "key " + (p.key.set ? "on" : p.ready ? "free" : "none"), p.key.set ? p.key.masked : p.ready ? t("no key") : t("needs a key"));
|
||||
key.title = p.key.set ? t("API key {masked}", { masked: p.key.masked }) : p.ready ? t("Local servers need no key") : t("Open the row and paste an API key");
|
||||
}
|
||||
const chev = el("span", "chev");
|
||||
chev.append(svg(CHEV_R, 11, 1.7));
|
||||
@@ -409,7 +412,7 @@ function renderExcluded() {
|
||||
for (const x of providers.excluded) {
|
||||
const r = el("div", "excluded");
|
||||
r.append(icon(x.agentIcon), el("span", "", ""));
|
||||
r.lastChild.append(el("b", "", x.agentName + " is signed in, but stays out of this list. "), x.why);
|
||||
r.lastChild.append(el("b", "", t("{agent} is signed in, but stays out of this list. ", { agent: x.agentName })), x.why);
|
||||
box.append(r);
|
||||
}
|
||||
}
|
||||
@@ -418,7 +421,7 @@ function renderExcluded() {
|
||||
function accountPlan(a) {
|
||||
if (a.agent === "codex") return "ChatGPT" + (a.plan ? " " + a.plan[0].toUpperCase() + a.plan.slice(1) : "");
|
||||
if (a.agent === "copilot") return "GitHub";
|
||||
return "signed in";
|
||||
return t("signed in");
|
||||
}
|
||||
|
||||
// ---------- gateway view ----------
|
||||
@@ -428,11 +431,11 @@ function accountPlan(a) {
|
||||
// and a snippet in whichever language the reader is holding.
|
||||
|
||||
async function copy(text, what) {
|
||||
try { await navigator.clipboard.writeText(text); status(what + " copied", "ok"); } catch { status(text); }
|
||||
try { await navigator.clipboard.writeText(text); status(t("{what} copied", { what }), "ok"); } catch { status(text); }
|
||||
}
|
||||
function copyBtn(text, what) {
|
||||
const b = el("button", "copy");
|
||||
b.title = "Copy";
|
||||
b.title = t("Copy");
|
||||
b.append(svg("M5.5 5.5V3.5h7v7h-2M3.5 5.5h7v7h-7z", 12, 1.5));
|
||||
b.onclick = (ev) => { ev.stopPropagation(); copy(text, what); };
|
||||
return b;
|
||||
@@ -452,18 +455,18 @@ function renderGateway() {
|
||||
box.replaceChildren();
|
||||
const dot = el("span", "dot " + (g.running ? "on" : ""));
|
||||
const who = el("div", "who");
|
||||
const name = el("div", "name", "Gateway");
|
||||
name.append(el("span", "state", g.running ? (g.mine ? "running" : "running · served by another dial") : "not running"));
|
||||
const name = el("div", "name", t("Gateway"));
|
||||
name.append(el("span", "state", t(g.running ? (g.mine ? "running" : "running · served by another dial") : "not running")));
|
||||
const routed = new Set();
|
||||
for (const p of providers.providers) for (const a of p.agents) if (a.current) routed.add(a.id);
|
||||
const n = routed.size;
|
||||
who.append(name, el("div", "sub", g.running
|
||||
? `${g.models} model${g.models === 1 ? "" : "s"} · ${n ? `${n} agent${n === 1 ? "" : "s"} routed through it` : "no agent routed through it yet"} · four APIs, one URL`
|
||||
: "start it with dial serve, or open dial at login"));
|
||||
? [t(g.models === 1 ? "{n} model" : "{n} models", { n: g.models }), n ? t(n === 1 ? "{n} agent routed through it" : "{n} agents routed through it", { n }) : t("no agent routed through it yet"), t("four APIs, one URL")].join(" · ")
|
||||
: t("start it with dial serve, or open dial at login")));
|
||||
const url = el("button", "url");
|
||||
url.append(el("code", "", g.url));
|
||||
url.title = "Copy the gateway URL";
|
||||
url.onclick = () => copy(g.url, "Gateway URL");
|
||||
url.title = t("Copy the gateway URL");
|
||||
url.onclick = () => copy(g.url, t("Gateway URL"));
|
||||
box.append(dot, who, url);
|
||||
}
|
||||
|
||||
@@ -593,21 +596,21 @@ function renderConnect() {
|
||||
const model = exampleModel || "provider/model";
|
||||
const f = FLAVORS[flavor] || FLAVORS.openai;
|
||||
const base = f.base(g.url);
|
||||
$("#connectNote").textContent = "Loopback only · the key can be anything";
|
||||
$("#connectNote").textContent = t("Loopback only · the key can be anything");
|
||||
|
||||
box.append(...field("API", segs(Object.entries(FLAVORS).map(([k, v]) => [k, v.name]), flavor, (id) => { flavor = id; localStorage.setItem("dial.flavor", id); renderConnect(); }), f.note));
|
||||
box.append(...field("API", segs(Object.entries(FLAVORS).map(([k, v]) => [k, v.name]), flavor, (id) => { flavor = id; localStorage.setItem("dial.flavor", id); renderConnect(); }), t(f.note)));
|
||||
|
||||
const b = el("div", "val");
|
||||
b.append(el("code", "", base), copyBtn(base, "Base URL"));
|
||||
box.append(...field("Base URL", b, `What ${f.baseEnv} takes.`));
|
||||
box.append(...field("Base URL", b, t("What {env} takes.", { env: f.baseEnv })));
|
||||
|
||||
const k = el("div", "val");
|
||||
k.append(el("code", "", "dial"), copyBtn("dial", "Key"));
|
||||
box.append(...field("API key", k, `${f.keyEnv}=dial. The gateway trusts everything on loopback, so any value works.`));
|
||||
k.append(el("code", "", "dial"), copyBtn("dial", t("Key")));
|
||||
box.append(...field(t("API key"), k, t("{env}=dial. The gateway trusts everything on loopback, so any value works.", { env: f.keyEnv })));
|
||||
|
||||
const m = el("div", "val");
|
||||
m.append(el("code", "", model), copyBtn(model, "Model id"));
|
||||
box.append(...field("Model", m, models.length ? "provider/model, as listed below. Click a model there to put it in the snippets." : "No models yet. Add a provider, or sign in to Codex or Copilot."));
|
||||
m.append(el("code", "", model), copyBtn(model, t("Model id")));
|
||||
box.append(...field(t("Model"), m, t(models.length ? "provider/model, as listed below. Click a model there to put it in the snippets." : "No models yet. Add a provider, or sign in to Codex or Copilot.")));
|
||||
|
||||
const ex = el("div", "stack");
|
||||
ex.append(segs(LANGS, lang, (id) => { lang = id; localStorage.setItem("dial.lang", id); renderConnect(); }));
|
||||
@@ -617,9 +620,9 @@ function renderConnect() {
|
||||
const pre = el("pre", "snip");
|
||||
const c = el("code");
|
||||
c.append(highlight(code, lang));
|
||||
pre.append(c, copyBtn(code, "Snippet"));
|
||||
pre.append(c, copyBtn(code, t("Snippet")));
|
||||
ex.append(pre);
|
||||
box.append(...field("Example", ex, lang === "shell" ? "Put these in the shell (or the tool's settings) and the tool talks to dial instead of the vendor." : ""));
|
||||
box.append(...field(t("Example"), ex, lang === "shell" ? t("Put these in the shell (or the tool's settings) and the tool talks to dial instead of the vendor.") : ""));
|
||||
}
|
||||
|
||||
// A small highlighter for the four snippet dialects: strings, comments,
|
||||
@@ -658,17 +661,17 @@ function renderGatewayModels() {
|
||||
list.replaceChildren();
|
||||
const models = gatewayModels();
|
||||
$("#copyModels").hidden = !models.length;
|
||||
$("#copyModels").onclick = () => copy(models.map((m) => m.id).join("\n"), "Model ids");
|
||||
$("#copyModels").onclick = () => copy(models.map((m) => m.id).join("\n"), t("Model ids"));
|
||||
if (!models.length) {
|
||||
list.append(el("div", "empty-state", "")).append(el("b", "", "No models exposed yet"), "Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.");
|
||||
list.append(el("div", "empty-state", "")).append(el("b", "", t("No models exposed yet")), t("Add a provider, or sign in to Codex or Copilot; their models show up here for every agent."));
|
||||
return;
|
||||
}
|
||||
for (const m of models) {
|
||||
const row = el("div", "row model" + (m.id === exampleModel ? " selected" : ""));
|
||||
const who = el("div", "who");
|
||||
who.append(el("div", "name", m.id), el("div", "sub", m.name && m.name !== m.id.split("/")[1] ? `${m.name} · ${m.provider.name}` : m.provider.name));
|
||||
row.append(icon(m.provider.icon || "generic"), who, copyBtn(m.id, "Model id"));
|
||||
row.title = "Use this model in the snippets";
|
||||
row.append(icon(m.provider.icon || "generic"), who, copyBtn(m.id, t("Model id")));
|
||||
row.title = t("Use this model in the snippets");
|
||||
row.onclick = () => { exampleModel = m.id; localStorage.setItem("dial.model", m.id); renderConnect(); renderGatewayModels(); };
|
||||
list.append(row);
|
||||
}
|
||||
@@ -678,9 +681,9 @@ function renderActivity() {
|
||||
const g = providers.gateway;
|
||||
const box = $("#activity");
|
||||
box.replaceChildren();
|
||||
$("#callsNote").textContent = g.running && !g.mine ? "shown by the dial that serves the gateway" : "";
|
||||
$("#callsNote").textContent = g.running && !g.mine ? t("shown by the dial that serves the gateway") : "";
|
||||
const calls = g.calls.slice(0, 20);
|
||||
if (!calls.length) { box.append(el("div", "none", "No requests yet. Point an agent at a model, or run the example above; every call shows up here as it happens.")); return; }
|
||||
if (!calls.length) { box.append(el("div", "none", t("No requests yet. Point an agent at a model, or run the example above; every call shows up here as it happens."))); return; }
|
||||
for (const c of calls) {
|
||||
const r = el("div", "call" + (c.status >= 400 ? " bad" : ""));
|
||||
r.append(el("span", "when", new Date(c.time).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" })));
|
||||
@@ -710,7 +713,7 @@ function pickForAgent(a, p, btn, ev) {
|
||||
const pre = ofProvider(p);
|
||||
if (!field.options.some((o) => pre.test(o.value))) {
|
||||
ev.stopPropagation();
|
||||
status(`${p.name} exposes no models yet — pick some below`, "warn");
|
||||
status(t("{p} exposes no models yet — pick some below", { p: p.name }), "warn");
|
||||
editing = p.id; draft = null; renderProviders();
|
||||
return;
|
||||
}
|
||||
@@ -726,13 +729,13 @@ function renderAdd() {
|
||||
$("#addProvider").hidden = adding;
|
||||
if (!adding) return;
|
||||
const head = el("div", "row-head");
|
||||
head.append(el("span", "label", providers.providers.length ? "Add a provider" : "Add your first provider"), el("span", "grow"));
|
||||
const q = input(presetQuery, "Find a vendor…");
|
||||
head.append(el("span", "label", t(providers.providers.length ? "Add a provider" : "Add your first provider")), el("span", "grow"));
|
||||
const q = input(presetQuery, t("Find a vendor…"));
|
||||
q.className = "find";
|
||||
q.oninput = () => { presetQuery = q.value; drawTiles(); };
|
||||
head.append(q);
|
||||
if (providers.providers.length) {
|
||||
const x = el("button", "text", "Close");
|
||||
const x = el("button", "text", t("Close"));
|
||||
x.onclick = () => { adding = false; editing = null; draft = null; presetQuery = ""; renderProviders(); };
|
||||
head.append(x);
|
||||
}
|
||||
@@ -748,7 +751,7 @@ function renderAdd() {
|
||||
const ps = providers.presets.filter((p) => p.kind === kind && hit(p));
|
||||
if (!ps.length && !(kind === "local" && !f)) continue;
|
||||
any = true;
|
||||
tiles.append(el("div", "kind", title));
|
||||
tiles.append(el("div", "kind", t(title)));
|
||||
const grid = el("div", "grid");
|
||||
for (const pr of ps) grid.append(tile(pr));
|
||||
if (kind === "local" && !f) {
|
||||
@@ -756,7 +759,7 @@ function renderAdd() {
|
||||
const ic = el("span", "ic plus");
|
||||
ic.append(svg(PLUS, 13, 1.8));
|
||||
c.append(ic, el("span", "tt"));
|
||||
c.lastChild.append(el("span", "n", "Custom"), el("span", "s", "any compatible URL"));
|
||||
c.lastChild.append(el("span", "n", t("Custom")), el("span", "s", t("any compatible URL")));
|
||||
c.onclick = () => { editing = { custom: true }; draft = null; renderProviders(); };
|
||||
grid.append(c);
|
||||
}
|
||||
@@ -764,8 +767,8 @@ function renderAdd() {
|
||||
}
|
||||
if (!any) {
|
||||
const none = el("div", "none");
|
||||
none.append(`Nothing called “${presetQuery.trim()}”. `);
|
||||
const b = el("button", "link", "Add it as a custom provider");
|
||||
none.append(t("Nothing called “{q}”. ", { q: presetQuery.trim() }));
|
||||
const b = el("button", "link", t("Add it as a custom provider"));
|
||||
b.onclick = () => { editing = { custom: true }; draft = null; renderProviders(); };
|
||||
none.append(b);
|
||||
tiles.append(none);
|
||||
@@ -776,23 +779,23 @@ function renderAdd() {
|
||||
}
|
||||
|
||||
function tile(pr) {
|
||||
const t = el("button", "tile" + (pr.added ? " added" : "") + (editing?.preset === pr.id ? " on" : ""));
|
||||
t.append(icon(pr.icon || "generic"));
|
||||
const b = el("button", "tile" + (pr.added ? " added" : "") + (editing?.preset === pr.id ? " on" : ""));
|
||||
b.append(icon(pr.icon || "generic"));
|
||||
const tt = el("span", "tt");
|
||||
const n = el("span", "n", pr.name);
|
||||
if (pr.sponsored) n.append(el("span", "badge", "sponsored"));
|
||||
if (pr.sponsored) n.append(el("span", "badge", t("sponsored")));
|
||||
tt.append(n, el("span", "s", pr.note || hostOf(pr.chat || pr.responses || pr.anthropic)));
|
||||
t.append(tt);
|
||||
b.append(tt);
|
||||
if (pr.added) {
|
||||
const ck = el("span", "check");
|
||||
ck.append(svg(CHECK, 10, 2));
|
||||
t.append(ck);
|
||||
t.title = `${pr.name} is already added — open it`;
|
||||
t.onclick = () => { editing = pr.id; adding = false; draft = null; renderProviders(); };
|
||||
b.append(ck);
|
||||
b.title = t("{name} is already added — open it", { name: pr.name });
|
||||
b.onclick = () => { editing = pr.id; adding = false; draft = null; renderProviders(); };
|
||||
} else {
|
||||
t.onclick = () => { editing = { preset: pr.id }; draft = null; renderProviders(); };
|
||||
b.onclick = () => { editing = { preset: pr.id }; draft = null; renderProviders(); };
|
||||
}
|
||||
return t;
|
||||
return b;
|
||||
}
|
||||
|
||||
function field(label, control, hint) {
|
||||
@@ -830,7 +833,7 @@ function renderEditor(p, presetID) {
|
||||
|
||||
if (isNew) {
|
||||
const h = el("div", "ehead");
|
||||
h.append(icon(pr?.icon || "generic"), el("b", "", pr ? pr.name : "Custom provider"));
|
||||
h.append(icon(pr?.icon || "generic"), el("b", "", pr ? pr.name : t("Custom provider")));
|
||||
if (pr?.note) h.append(el("span", "note", pr.note));
|
||||
h.append(el("span", "grow"));
|
||||
if (pr?.website) { const b = el("button", "link", hostOf(pr.website) + " ↗"); b.onclick = () => api("open", { url: pr.website }); h.append(b); }
|
||||
@@ -845,23 +848,23 @@ function renderEditor(p, presetID) {
|
||||
const c = el("button", "achip" + (a.current ? " on" : ""));
|
||||
c.append(icon(a.icon), el("span", "n", a.name));
|
||||
if (a.current) c.append(el("span", "m", a.model));
|
||||
c.title = a.current ? `${a.name} is on ${a.model} — click to change` : `Point ${a.name} at a ${p.name} model`;
|
||||
c.title = a.current ? t("{agent} is on {model} — click to change", { agent: a.name, model: a.model }) : t("Point {agent} at a {p} model", { agent: a.name, p: p.name });
|
||||
c.onclick = (ev) => pickForAgent(a, p, c, ev);
|
||||
chips.append(c);
|
||||
}
|
||||
ed.append(...field("Agents", chips, p.agents.some((a) => a.current) ? "" : "None yet. Click an agent to pick one of these models for it."));
|
||||
ed.append(...field(t("Agents"), chips, p.agents.some((a) => a.current) ? "" : t("None yet. Click an agent to pick one of these models for it.")));
|
||||
}
|
||||
|
||||
let name, url;
|
||||
if (custom) {
|
||||
name = input(draft.name, "e.g. My Relay");
|
||||
name = input(draft.name, t("e.g. My Relay"));
|
||||
name.oninput = () => { draft.name = name.value; if (isNew) draft.id = slug(name.value); };
|
||||
ed.append(...field("Name", name));
|
||||
ed.append(...field(t("Name"), name));
|
||||
|
||||
const seg = el("div", "segs");
|
||||
for (const [v, l, hint] of [["openai", "OpenAI compatible", "…/v1 — chat completions, and responses when the vendor has it"], ["anthropic", "Anthropic compatible", "the root URL, what ANTHROPIC_BASE_URL would take"]]) {
|
||||
const b = el("button", "opt" + (draft.api === v ? " on" : ""), l);
|
||||
b.title = hint;
|
||||
const b = el("button", "opt" + (draft.api === v ? " on" : ""), t(l));
|
||||
b.title = t(hint);
|
||||
b.onclick = () => { draft.api = v; const u = url.value; if (v === "anthropic") { draft.anthropic = u; draft.chat = ""; } else { draft.chat = u; draft.anthropic = ""; } for (const x of seg.children) x.classList.toggle("on", x === b); url.placeholder = v === "anthropic" ? "https://…" : "https://…/v1"; };
|
||||
seg.append(b);
|
||||
}
|
||||
@@ -877,89 +880,89 @@ function renderEditor(p, presetID) {
|
||||
const a = p.account;
|
||||
const acct = el("div", "acct");
|
||||
acct.append(icon(a.agentIcon), el("span", "n", a.user), el("span", "plan", accountPlan(a)));
|
||||
ed.append(...field("Account", acct, `${a.agentName}'s sign-in, read from its own files. Sign out there and this provider goes away.`));
|
||||
ed.append(...field("Models", renderModels(p), ""));
|
||||
ed.append(...field("Endpoints", renderEndpoints(p, null)));
|
||||
ed.append(...field(t("Account"), acct, t("{agent}'s sign-in, read from its own files. Sign out there and this provider goes away.", { agent: a.agentName })));
|
||||
ed.append(...field(t("Models"), renderModels(p), ""));
|
||||
ed.append(...field(t("Endpoints"), renderEndpoints(p, null)));
|
||||
const bar = el("div", "bar");
|
||||
bar.append(el("span", "grow"));
|
||||
const cancel = el("button", "text", "Cancel");
|
||||
const cancel = el("button", "text", t("Cancel"));
|
||||
cancel.onclick = cancelEdit;
|
||||
const saveBtn = el("button", "text primary", "Save");
|
||||
saveBtn.onclick = () => { saveBtn.classList.add("busy"); providerAction("save", { id: p.id, models: draft.chosen }, `${p.name} saved`, p.id); };
|
||||
const saveBtn = el("button", "text primary", t("Save"));
|
||||
saveBtn.onclick = () => { saveBtn.classList.add("busy"); providerAction("save", { id: p.id, models: draft.chosen }, t("{name} saved", { name: p.name }), p.id); };
|
||||
bar.append(cancel, saveBtn);
|
||||
ed.append(bar);
|
||||
return ed;
|
||||
}
|
||||
|
||||
const key = input("", p?.key.set ? `${p.key.masked} · paste a new key to replace it` : pr?.noKey || p?.key.optional ? "optional for local servers" : "paste an API key", "password");
|
||||
const key = input("", p?.key.set ? t("{masked} · paste a new key to replace it", { masked: p.key.masked }) : t(pr?.noKey || p?.key.optional ? "optional for local servers" : "paste an API key"), "password");
|
||||
key.oninput = () => { draft.key = key.value; };
|
||||
key.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter" && isNew) save(); else if (e.key === "Escape") cancelEdit(); };
|
||||
const side = el("div", "side");
|
||||
const eye = el("button", "text", "Show");
|
||||
const eye = el("button", "text", t("Show"));
|
||||
let revealed = false; // the saved key is in the box, not a draft
|
||||
eye.onclick = async () => {
|
||||
if (key.type === "password") {
|
||||
if (!key.value && p?.key.set) {
|
||||
try { key.value = (await api("provider/key", { id: p.id })).key; revealed = true; } catch (e) { status(e.message, "err"); return; }
|
||||
}
|
||||
key.type = "text"; eye.textContent = "Hide";
|
||||
key.type = "text"; eye.textContent = t("Hide");
|
||||
} else {
|
||||
if (revealed && !draft.key) key.value = "";
|
||||
revealed = false;
|
||||
key.type = "password"; eye.textContent = "Show";
|
||||
key.type = "password"; eye.textContent = t("Show");
|
||||
}
|
||||
};
|
||||
side.append(eye);
|
||||
const keysUrl = p?.keysUrl || pr?.keysUrl;
|
||||
if (keysUrl) { const b = el("button", "link", "Get a key ↗"); b.onclick = () => api("open", { url: keysUrl }); side.append(b); }
|
||||
if (keysUrl) { const b = el("button", "link", t("Get a key ↗")); b.onclick = () => api("open", { url: keysUrl }); side.append(b); }
|
||||
const keyWrap = el("div", "pair");
|
||||
keyWrap.append(key, side);
|
||||
ed.append(...field("API key", keyWrap, isNew ? "Kept in ~/.config/dial/providers.json, readable by you alone. Nothing is read from your shell." : ""));
|
||||
ed.append(...field(t("API key"), keyWrap, isNew ? t("Kept in ~/.config/dial/providers.json, readable by you alone. Nothing is read from your shell.") : ""));
|
||||
|
||||
if (p) ed.append(...field("Models", renderModels(p), ""));
|
||||
if (p) ed.append(...field(t("Models"), renderModels(p), ""));
|
||||
else if (custom) {
|
||||
const ex = input("", "model ids, comma separated · e.g. gpt-5.5, claude-sonnet-5");
|
||||
const ex = input("", t("model ids, comma separated · e.g. gpt-5.5, claude-sonnet-5"));
|
||||
ex.oninput = () => { draft.extra = ex.value.split(/[,\s]+/).filter(Boolean); };
|
||||
ed.append(...field("Models", ex, "Optional: dial asks the vendor for its list after saving."));
|
||||
ed.append(...field(t("Models"), ex, t("Optional: dial asks the vendor for its list after saving.")));
|
||||
}
|
||||
|
||||
if (!custom) ed.append(...field("Endpoints", renderEndpoints(p, pr)));
|
||||
if (!custom) ed.append(...field(t("Endpoints"), renderEndpoints(p, pr)));
|
||||
|
||||
if (custom) {
|
||||
const more = el("details", "more");
|
||||
more.append(el("summary", "", "More endpoints"));
|
||||
more.append(el("summary", "", t("More endpoints")));
|
||||
const inner = el("div", "inner");
|
||||
const add = (label, key, ph, hint) => {
|
||||
const i = input(draft[key], ph, "url");
|
||||
i.oninput = () => { draft[key] = i.value; };
|
||||
inner.append(...field(label, i, hint));
|
||||
inner.append(...field(t(label), i, t(hint)));
|
||||
};
|
||||
if (draft.api === "anthropic") add("OpenAI URL", "chat", "https://…/v1", "if the vendor also serves chat completions");
|
||||
else add("Anthropic URL", "anthropic", "https://…", "if the vendor also serves Anthropic messages");
|
||||
add("Responses URL", "responses", "https://…/v1", "if the vendor serves the OpenAI Responses API (Codex uses it natively)");
|
||||
const cat = input(draft.catalog, "models.dev id, e.g. openai");
|
||||
const cat = input(draft.catalog, t("models.dev id, e.g. openai"));
|
||||
cat.oninput = () => { draft.catalog = cat.value; };
|
||||
inner.append(...field("Catalog", cat, "Display names and reasoning levels for the models"));
|
||||
inner.append(...field(t("Catalog"), cat, t("Display names and reasoning levels for the models")));
|
||||
more.append(inner);
|
||||
ed.append(more);
|
||||
}
|
||||
|
||||
const bar = el("div", "bar");
|
||||
if (p) {
|
||||
const del = el("button", "text danger", "Remove");
|
||||
del.onclick = () => providerAction("delete", { id: p.id }, `${p.name} removed`);
|
||||
const del = el("button", "text danger", t("Remove"));
|
||||
del.onclick = () => providerAction("delete", { id: p.id }, t("{name} removed", { name: p.name }));
|
||||
bar.append(del);
|
||||
}
|
||||
bar.append(el("span", "grow"));
|
||||
const cancel = el("button", "text", "Cancel");
|
||||
const cancel = el("button", "text", t("Cancel"));
|
||||
cancel.onclick = cancelEdit;
|
||||
const saveBtn = el("button", "text primary", isNew ? "Add" : "Save");
|
||||
const saveBtn = el("button", "text primary", t(isNew ? "Add" : "Save"));
|
||||
const save = () => {
|
||||
const body = { id: draft.id, name: draft.name, preset: draft.preset, key: draft.key || "", chat: draft.chat, responses: draft.responses, anthropic: draft.anthropic, catalog: draft.catalog, models: p ? draft.chosen : draft.extra };
|
||||
if (isNew && custom && !body.name) { name.focus(); return status("Give it a name", "warn"); }
|
||||
if (isNew && custom && !body.chat && !body.anthropic) { url.focus(); return status("A base URL is needed", "warn"); }
|
||||
if (isNew && custom && !body.name) { name.focus(); return status(t("Give it a name"), "warn"); }
|
||||
if (isNew && custom && !body.chat && !body.anthropic) { url.focus(); return status(t("A base URL is needed"), "warn"); }
|
||||
saveBtn.classList.add("busy");
|
||||
providerAction("save", body, `${draft.name || draft.id} ${isNew ? "added" : "saved"}`, body.id || slug(body.name));
|
||||
providerAction("save", body, t(isNew ? "{name} added" : "{name} saved", { name: draft.name || draft.id }), body.id || slug(body.name));
|
||||
};
|
||||
saveBtn.onclick = save;
|
||||
bar.append(cancel, saveBtn);
|
||||
@@ -979,26 +982,26 @@ function renderEndpoints(p, pr) {
|
||||
if (!src[proto]) continue;
|
||||
const e = el("div", "ep");
|
||||
const pl = el("span", "pl", label);
|
||||
pl.title = hint;
|
||||
pl.title = t(hint);
|
||||
e.append(pl, el("code", "", src[proto]), slots[proto] = el("span", "res"));
|
||||
eps.append(e);
|
||||
}
|
||||
if (p) {
|
||||
const test = el("button", "text", "Test");
|
||||
test.title = "Send a tiny request through each endpoint";
|
||||
const test = el("button", "text", t("Test"));
|
||||
test.title = t("Send a tiny request through each endpoint");
|
||||
test.onclick = async () => {
|
||||
test.classList.add("busy");
|
||||
for (const s of Object.values(slots)) { s.className = "res wait"; s.textContent = "…"; }
|
||||
try {
|
||||
const r = await api("provider/test", { id: p.id });
|
||||
for (const t of r.results) {
|
||||
const s = slots[t.protocol];
|
||||
for (const x of r.results) {
|
||||
const s = slots[x.protocol];
|
||||
if (!s) continue;
|
||||
s.className = "res " + (t.ok ? "ok" : "bad");
|
||||
s.className = "res " + (x.ok ? "ok" : "bad");
|
||||
s.replaceChildren();
|
||||
s.append(svg(t.ok ? CHECK : "M4.5 4.5l7 7M11.5 4.5l-7 7", 10, 2));
|
||||
s.append(el("span", "", t.ok ? `${t.ms} ms` : t.status ? `${t.status} · ${t.error}` : t.error));
|
||||
s.title = t.ok ? `model ${t.model}` : t.error;
|
||||
s.append(svg(x.ok ? CHECK : "M4.5 4.5l7 7M11.5 4.5l-7 7", 10, 2));
|
||||
s.append(el("span", "", x.ok ? `${x.ms} ms` : x.status ? `${x.status} · ${x.error}` : x.error));
|
||||
s.title = x.ok ? t("model {model}", { model: x.model }) : x.error;
|
||||
}
|
||||
} catch (e) { for (const s of Object.values(slots)) { s.className = "res"; s.textContent = ""; } status(e.message, "err"); }
|
||||
test.classList.remove("busy");
|
||||
@@ -1011,7 +1014,7 @@ function renderEndpoints(p, pr) {
|
||||
function renderModels(p) {
|
||||
const box = el("div", "models");
|
||||
const chips = el("div", "mchips");
|
||||
const q = p.models.length > 24 ? input("", `filter ${p.models.length} models…`) : null;
|
||||
const q = p.models.length > 24 ? input("", t("filter {n} models…", { n: p.models.length })) : null;
|
||||
const draw = () => {
|
||||
chips.replaceChildren();
|
||||
const f = (q?.value || "").trim().toLowerCase();
|
||||
@@ -1024,34 +1027,34 @@ function renderModels(p) {
|
||||
if (m.name && m.name !== m.id) c.title = m.id;
|
||||
c.onclick = () => { draft.chosen = on ? draft.chosen.filter((x) => x !== m.id) : [...draft.chosen, m.id]; draw(); };
|
||||
chips.append(c);
|
||||
if (++shown >= 80 && !f) { chips.append(el("span", "hint", `… ${p.models.length - shown} more, filter to find them`)); break; }
|
||||
if (++shown >= 80 && !f) { chips.append(el("span", "hint", t("… {n} more, filter to find them", { n: p.models.length - shown }))); break; }
|
||||
}
|
||||
for (const id of draft.chosen) {
|
||||
if (p.models.some((m) => m.id === id)) continue;
|
||||
const c = el("button", "mchip on own");
|
||||
c.append(el("span", "", id));
|
||||
c.title = "Added by hand";
|
||||
c.title = t("Added by hand");
|
||||
c.onclick = () => { draft.chosen = draft.chosen.filter((x) => x !== id); draw(); };
|
||||
chips.append(c);
|
||||
}
|
||||
if (!p.models.length && !draft.chosen.length) chips.append(el("span", "hint", "The vendor's list is empty. Refresh, or type a model id."));
|
||||
if (!p.models.length && !draft.chosen.length) chips.append(el("span", "hint", t("The vendor's list is empty. Refresh, or type a model id.")));
|
||||
};
|
||||
if (q) { q.oninput = draw; box.append(q); }
|
||||
box.append(chips);
|
||||
const foot = el("div", "mfoot");
|
||||
const add = input("", "add a model id…");
|
||||
const add = input("", t("add a model id…"));
|
||||
add.onkeydown = (e) => {
|
||||
e.stopPropagation();
|
||||
if (e.key === "Enter" && add.value.trim()) { const id = add.value.trim(); if (!draft.chosen.includes(id)) draft.chosen.push(id); add.value = ""; draw(); }
|
||||
else if (e.key === "Escape") cancelEdit();
|
||||
};
|
||||
const refresh = el("button", "text", "Refresh");
|
||||
refresh.title = "Ask the vendor which models it serves";
|
||||
const refresh = el("button", "text", t("Refresh"));
|
||||
refresh.title = t("Ask the vendor which models it serves");
|
||||
refresh.onclick = async () => {
|
||||
refresh.classList.add("busy");
|
||||
try {
|
||||
const r = await api("provider/models", { id: p.id });
|
||||
status(`${p.name}: ${r.count} models`, "ok");
|
||||
status(t("{p}: {n} models", { p: p.name, n: r.count }), "ok");
|
||||
const chosen = draft.chosen;
|
||||
await loadProviders();
|
||||
draft = draft || {};
|
||||
@@ -1060,8 +1063,8 @@ function renderModels(p) {
|
||||
} catch (e) { status(e.message, "err"); refresh.classList.remove("busy"); }
|
||||
};
|
||||
foot.append(add, refresh);
|
||||
if (p.fetched) foot.append(el("span", "hint", `vendor list · ${p.fetched}`));
|
||||
else if (p.models.length) foot.append(el("span", "hint", "from models.dev · Refresh asks the vendor"));
|
||||
if (p.fetched) foot.append(el("span", "hint", t("vendor list · {when}", { when: p.fetched })));
|
||||
else if (p.models.length) foot.append(el("span", "hint", t("from models.dev · Refresh asks the vendor")));
|
||||
box.append(foot);
|
||||
draw();
|
||||
return box;
|
||||
@@ -1119,7 +1122,7 @@ function renderUsage() {
|
||||
const seg = $("#period");
|
||||
seg.replaceChildren();
|
||||
for (const [id, name] of PERIODS) {
|
||||
const b = el("button", "opt" + (id === period ? " on" : ""), name);
|
||||
const b = el("button", "opt" + (id === period ? " on" : ""), t(name));
|
||||
b.onclick = () => { period = id; loadUsage().catch((e) => status(e.message, "err")); };
|
||||
seg.append(b);
|
||||
}
|
||||
@@ -1127,10 +1130,10 @@ function renderUsage() {
|
||||
cost.replaceChildren();
|
||||
const c = fmtCost(u);
|
||||
if (c) {
|
||||
cost.append(el("b", "", "≈" + c), el("span", "", "list price"));
|
||||
cost.title = u.unpriced ? `${u.unpriced} call${u.unpriced === 1 ? "" : "s"} had no known price and are not counted` : "At each model's list price on models.dev";
|
||||
cost.append(el("b", "", "≈" + c), el("span", "", t("list price")));
|
||||
cost.title = u.unpriced ? t(u.unpriced === 1 ? "{n} call had no known price and is not counted" : "{n} calls had no known price and are not counted", { n: u.unpriced }) : t("At each model's list price on models.dev");
|
||||
} else if (u.calls) {
|
||||
cost.append(el("span", "", "no price for these models"));
|
||||
cost.append(el("span", "", t("no price for these models")));
|
||||
}
|
||||
|
||||
const stats = $("#stats");
|
||||
@@ -1141,8 +1144,8 @@ function renderUsage() {
|
||||
for (const h of $$("#view-usage .row-head")) h.hidden = empty;
|
||||
if (empty) {
|
||||
stats.classList.add("empty");
|
||||
const when = { today: "today", "7d": "in the last 7 days", "30d": "in the last 30 days", all: "yet" }[period];
|
||||
stats.append(el("div", "none", `No calls ${when}. Point an agent at a catalog model and use it; every call through the gateway is counted here.`));
|
||||
const none = { today: "No calls today.", "7d": "No calls in the last 7 days.", "30d": "No calls in the last 30 days.", all: "No calls yet." }[period];
|
||||
stats.append(el("div", "none", t(none) + " " + t("Point an agent at a catalog model and use it; every call through the gateway is counted here.")));
|
||||
$("#usageNote").textContent = "";
|
||||
return;
|
||||
}
|
||||
@@ -1153,10 +1156,10 @@ function renderUsage() {
|
||||
if (sub) t.append(el("small", "", sub));
|
||||
stats.append(t);
|
||||
};
|
||||
tile(fmtN(tokensOf(u)), "tokens", `${fmtN(u.input)} in · ${fmtN(u.output)} out`);
|
||||
tile(fmtN(u.cache_read), "cache read", u.cache_write ? `${fmtN(u.cache_write)} written` : "");
|
||||
tile(fmtN(u.reasoning), "reasoning", "inside output");
|
||||
tile(String(u.calls), u.calls === 1 ? "call" : "calls", u.errors ? `${u.errors} failed` : "");
|
||||
tile(fmtN(tokensOf(u)), t("tokens"), t("{a} in · {b} out", { a: fmtN(u.input), b: fmtN(u.output) }));
|
||||
tile(fmtN(u.cache_read), t("cache read"), u.cache_write ? t("{n} written", { n: fmtN(u.cache_write) }) : "");
|
||||
tile(fmtN(u.reasoning), t("reasoning"), t("inside output"));
|
||||
tile(String(u.calls), t(u.calls === 1 ? "call" : "calls"), u.errors ? t("{n} failed", { n: u.errors }) : "");
|
||||
|
||||
// the timeline: one bar per hour, day or week; output sits on top of input
|
||||
const chart = $("#chart");
|
||||
@@ -1172,8 +1175,8 @@ function renderUsage() {
|
||||
inp.style.height = (100 * p.input / peak).toFixed(1) + "%";
|
||||
out.style.height = (100 * p.output / peak).toFixed(1) + "%";
|
||||
b.append(out, inp);
|
||||
const when = u.bucket === "hour" ? `${p.label}:00` : (u.bucket === "week" ? "week of " : "") + p.label;
|
||||
b.title = p.calls ? `${when} · ${fmtN(tokensOf(p))} tokens · ${p.calls} call${p.calls === 1 ? "" : "s"}${fmtCost(p) ? " · ≈" + fmtCost(p) : ""}` : `${when} · nothing`;
|
||||
const when = u.bucket === "hour" ? `${p.label}:00` : u.bucket === "week" ? t("week of {label}", { label: p.label }) : p.label;
|
||||
b.title = p.calls ? t(p.calls === 1 ? "{when} · {tokens} tokens · {n} call" : "{when} · {tokens} tokens · {n} calls", { when, tokens: fmtN(tokensOf(p)), n: p.calls }) + (fmtCost(p) ? " · ≈" + fmtCost(p) : "") : t("{when} · nothing", { when });
|
||||
bars.append(b);
|
||||
const last = i === n - 1 && (n - 1) % every >= every / 2;
|
||||
labels.append(el("span", "", i % every === 0 || last ? p.label : ""));
|
||||
@@ -1191,18 +1194,18 @@ function renderUsage() {
|
||||
who.append(el("div", "name", g.name));
|
||||
const sub = [];
|
||||
if (g.sub) sub.push(g.sub);
|
||||
sub.push(`${g.calls} call${g.calls === 1 ? "" : "s"}`);
|
||||
if (g.errors) sub.push(`${g.errors} failed`);
|
||||
sub.push(t(g.calls === 1 ? "{n} call" : "{n} calls", { n: g.calls }));
|
||||
if (g.errors) sub.push(t("{n} failed", { n: g.errors }));
|
||||
who.append(el("div", "sub", sub.join(" · ")));
|
||||
r.append(who);
|
||||
const share = el("div", "share");
|
||||
const fill = el("i");
|
||||
fill.style.width = Math.max(1.5, 100 * tokensOf(g) / total).toFixed(1) + "%";
|
||||
share.append(fill);
|
||||
share.title = Math.round(100 * tokensOf(g) / total) + "% of tokens";
|
||||
share.title = t("{n}% of tokens", { n: Math.round(100 * tokensOf(g) / total) });
|
||||
r.append(share);
|
||||
const num = el("div", "num");
|
||||
num.append(el("b", "", fmtN(tokensOf(g))), el("small", "", `${fmtN(g.input)} in · ${fmtN(g.output)} out${g.cache_read ? " · " + fmtN(g.cache_read) + " cached" : ""}`));
|
||||
num.append(el("b", "", fmtN(tokensOf(g))), el("small", "", t("{a} in · {b} out", { a: fmtN(g.input), b: fmtN(g.output) }) + (g.cache_read ? " · " + t("{n} cached", { n: fmtN(g.cache_read) }) : "")));
|
||||
r.append(num);
|
||||
r.append(el("div", "cost", fmtCost(g) ? "≈" + fmtCost(g) : ""));
|
||||
box.append(r);
|
||||
@@ -1210,23 +1213,86 @@ function renderUsage() {
|
||||
};
|
||||
list("usageAgents", u.agents);
|
||||
list("usageModels", u.models);
|
||||
$("#usageNote").textContent = `Counted from the providers' own usage reports on every call through the gateway · ${u.path}`;
|
||||
$("#usageNote").textContent = t("Counted from the providers' own usage reports on every call through the gateway · {path}", { path: u.path });
|
||||
}
|
||||
|
||||
// ---------- settings ----------
|
||||
//
|
||||
// Two choices (palette, language) and the facts people come looking for:
|
||||
// the version, where dial keeps its files, the gateway's address.
|
||||
|
||||
const THEMES = [["system", "System"], ["light", "Light"], ["dark", "Dark"]];
|
||||
const LOCALES = [["system", "System"], ["en", "English"], ["zh", "中文"]];
|
||||
|
||||
// applyPrefs paints and speaks as the saved settings say. A ?theme= or
|
||||
// ?locale= in the URL wins, so a forced look stays forced.
|
||||
function applyPrefs(s) {
|
||||
s = s || {};
|
||||
if (!params.get("theme")) {
|
||||
if (!s.theme || s.theme === "system") delete document.documentElement.dataset.theme;
|
||||
else document.documentElement.dataset.theme = s.theme;
|
||||
}
|
||||
const was = locale;
|
||||
setLocale(s.lang);
|
||||
return was !== locale;
|
||||
}
|
||||
|
||||
async function loadSettings() {
|
||||
prefs = await api("settings");
|
||||
renderSettings();
|
||||
}
|
||||
|
||||
function renderSettings() {
|
||||
const s = prefs;
|
||||
$("#themeSegs").replaceChildren(segs(THEMES.map(([id, name]) => [id, t(name)]), s.theme, (theme) => savePrefs({ theme, lang: s.lang })));
|
||||
$("#langSegs").replaceChildren(segs(LOCALES.map(([id, name]) => [id, t(name)]), s.lang, (lang) => savePrefs({ theme: s.theme, lang })));
|
||||
|
||||
const about = $("#about");
|
||||
about.replaceChildren();
|
||||
const row = (name, sub, value, ...tools) => {
|
||||
const r = el("div", "row pref");
|
||||
const who = el("div", "who");
|
||||
who.append(el("div", "name", name));
|
||||
if (sub) who.append(el("div", "sub", sub));
|
||||
const val = el("div", "val");
|
||||
val.append(el("code", "", value), ...tools);
|
||||
r.append(who, val);
|
||||
about.append(r);
|
||||
};
|
||||
row(t("Version"), "", s.version);
|
||||
const open = el("button", "text", t("Open"));
|
||||
open.onclick = () => api("open", { url: "file://" + s.path });
|
||||
row(t("Config folder"), t("providers, profiles and these settings"), s.dir, copyBtn(s.dir, t("Path")), open);
|
||||
row(t("Gateway URL"), t("the address every agent is pointed at"), s.gateway, copyBtn(s.gateway, t("Gateway URL")));
|
||||
}
|
||||
|
||||
async function savePrefs(body) {
|
||||
try {
|
||||
prefs = await api("settings", body);
|
||||
state.settings = prefs;
|
||||
const spoke = applyPrefs(prefs);
|
||||
renderSettings();
|
||||
if (spoke) { renderAgents(); providers = null; usage = null; }
|
||||
status(t("Saved"), "ok", 1500);
|
||||
} catch (e) {
|
||||
status(e.message, "err");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- header / footer ----------
|
||||
|
||||
function show(v) {
|
||||
view = v;
|
||||
for (const b of $("#nav").children) b.classList.toggle("on", b.dataset.view === v);
|
||||
$("#view-agents").hidden = v !== "agents";
|
||||
$("#view-providers").hidden = v !== "providers";
|
||||
$("#view-gateway").hidden = v !== "gateway";
|
||||
$("#view-usage").hidden = v !== "usage";
|
||||
if (mode === "window") for (const b of $("#nav").children) b.classList.toggle("on", b.dataset.view === v);
|
||||
$("#prefs").classList.toggle("on", v === "settings");
|
||||
for (const id of ["agents", "providers", "gateway", "usage", "settings"]) $("#view-" + id).hidden = v !== id;
|
||||
closePicker();
|
||||
if (v === "providers" || v === "gateway") loadProviders().catch((e) => status(e.message, "err"));
|
||||
if (v === "usage") loadUsage().catch((e) => status(e.message, "err"));
|
||||
if (v === "settings") loadSettings().catch((e) => status(e.message, "err"));
|
||||
}
|
||||
for (const b of $("#nav").children) b.onclick = () => { show(b.dataset.view); b.blur(); };
|
||||
if (mode === "window") for (const b of $("#nav").children) b.onclick = () => { show(b.dataset.view); b.blur(); };
|
||||
$("#prefs").onclick = () => { if (mode === "window") show("settings"); else api("window/main?view=settings", {}); $("#prefs").blur(); };
|
||||
|
||||
$("#sync").onclick = async () => {
|
||||
const b = $("#sync");
|
||||
@@ -1235,9 +1301,9 @@ $("#sync").onclick = async () => {
|
||||
state = await api("sync", {});
|
||||
renderAgents();
|
||||
if (providers) await loadProviders();
|
||||
status("Model lists refreshed", "ok");
|
||||
status(t("Model lists refreshed"), "ok");
|
||||
} catch (e) {
|
||||
status("Sync failed: " + e.message, "err");
|
||||
status(t("Sync failed: {e}", { e: e.message }), "err");
|
||||
} finally {
|
||||
b.classList.remove("spin");
|
||||
}
|
||||
@@ -1252,5 +1318,5 @@ else { $("#nav").remove(); }
|
||||
// the panel comes back into view.
|
||||
document.addEventListener("visibilitychange", () => { if (!document.hidden) load(); });
|
||||
window.addEventListener("focus", load);
|
||||
if (mode === "window" && ["providers", "gateway", "usage"].includes(params.get("view"))) show(params.get("view"));
|
||||
if (mode === "window" && ["providers", "gateway", "usage", "settings"].includes(params.get("view"))) show(params.get("view"));
|
||||
load();
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
// dial speaks English by default; this is every other language it knows.
|
||||
// Keys are the English strings as written in app.js and index.html; a
|
||||
// missing key falls back to English, so a half-translated language still
|
||||
// works. {name} slots are filled by t(str, vars).
|
||||
const I18N = {
|
||||
zh: {
|
||||
// header, nav, footer
|
||||
"Agents": "Agent",
|
||||
"Providers": "供应商",
|
||||
"Gateway": "网关",
|
||||
"Usage": "用量",
|
||||
"Settings": "设置",
|
||||
"Refresh model lists (models.dev and every vendor)": "刷新模型列表(models.dev 与各供应商)",
|
||||
"Open as a window": "在窗口中打开",
|
||||
"Open dial": "打开 dial",
|
||||
"Quit": "退出",
|
||||
"Filter…": "筛选…",
|
||||
|
||||
// agents
|
||||
"No coding agents found": "没有找到编码 Agent",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and dial will list them here.": "安装 Claude Code、Codex、Gemini CLI、OpenCode…… 之后,dial 会在这里列出它们。",
|
||||
"model": "模型",
|
||||
"effort": "推理强度",
|
||||
"thinking": "思考",
|
||||
"small": "小模型",
|
||||
"large": "大模型",
|
||||
"auth": "认证",
|
||||
"agent default": "Agent 默认值",
|
||||
"default": "默认",
|
||||
"{label}: {value}": "{label}:{value}",
|
||||
"Profiles": "方案",
|
||||
"+ Save current": "+ 保存当前",
|
||||
"none yet · save the setup to switch back in one click": "还没有 · 保存当前设置,之后一键切回",
|
||||
"Delete profile": "删除方案",
|
||||
"Profile name": "方案名称",
|
||||
"{name} applied · {n} setting changed": "已应用 {name} · 更改了 {n} 项设置",
|
||||
"{name} applied · {n} settings changed": "已应用 {name} · 更改了 {n} 项设置",
|
||||
"Saved {name}": "已保存 {name}",
|
||||
"Deleted {name}": "已删除 {name}",
|
||||
|
||||
// picker
|
||||
"Default": "默认",
|
||||
"what {agent} ships with": "{agent} 自带的默认值",
|
||||
"current value": "当前值",
|
||||
"use as typed": "按输入使用",
|
||||
"Filter models…": "筛选模型…",
|
||||
"Filter, or type any model id…": "筛选,或输入任意模型 ID…",
|
||||
"Filter {field}…": "筛选{field}…",
|
||||
"No matches.": "没有匹配项。",
|
||||
|
||||
// providers
|
||||
"sponsored": "赞助",
|
||||
"{n} model": "{n} 个模型",
|
||||
"{n} models": "{n} 个模型",
|
||||
"no models exposed": "未暴露模型",
|
||||
"signed in as {user}": "已登录 {user}",
|
||||
"{name} · {model} — click to change": "{name} · {model} — 点击更改",
|
||||
"Point another agent at {p}": "让另一个 Agent 使用 {p}",
|
||||
"Point an agent at {p}": "让某个 Agent 使用 {p}",
|
||||
"{agent} is signed in; its models are here for every other agent": "{agent} 已登录;它的模型在这里供其他 Agent 使用",
|
||||
"no key": "无需密钥",
|
||||
"needs a key": "需要密钥",
|
||||
"API key {masked}": "API 密钥 {masked}",
|
||||
"Local servers need no key": "本地服务无需密钥",
|
||||
"Open the row and paste an API key": "展开这一行并粘贴 API 密钥",
|
||||
"{agent} is signed in, but stays out of this list. ": "{agent} 已登录,但不在此列表中。",
|
||||
"signed in": "已登录",
|
||||
"{p} exposes no models yet — pick some below": "{p} 尚未暴露模型 — 在下方选几个",
|
||||
"+ Add provider": "+ 添加供应商",
|
||||
"Add a provider": "添加供应商",
|
||||
"Add your first provider": "添加第一个供应商",
|
||||
"Find a vendor…": "查找供应商…",
|
||||
"Close": "关闭",
|
||||
"Vendors": "供应商",
|
||||
"Relays · many vendors behind one key": "中转 · 一个密钥背后多家供应商",
|
||||
"On this machine": "本机",
|
||||
"Custom": "自定义",
|
||||
"any compatible URL": "任意兼容的 URL",
|
||||
"Nothing called “{q}”. ": "没有叫“{q}”的。",
|
||||
"Add it as a custom provider": "添加为自定义供应商",
|
||||
"{name} is already added — open it": "{name} 已添加 — 点击打开",
|
||||
|
||||
// provider editor
|
||||
"Chat Completions — most agents": "Chat Completions — 多数 Agent",
|
||||
"OpenAI Responses — what Codex speaks": "OpenAI Responses — Codex 使用",
|
||||
"Anthropic Messages — what Claude Code speaks": "Anthropic Messages — Claude Code 使用",
|
||||
"Custom provider": "自定义供应商",
|
||||
"{agent} is on {model} — click to change": "{agent} 正在使用 {model} — 点击更改",
|
||||
"Point {agent} at a {p} model": "让 {agent} 使用 {p} 的模型",
|
||||
"None yet. Click an agent to pick one of these models for it.": "还没有。点击一个 Agent,为它选一个这里的模型。",
|
||||
"e.g. My Relay": "例如 My Relay",
|
||||
"Name": "名称",
|
||||
"OpenAI compatible": "OpenAI 兼容",
|
||||
"…/v1 — chat completions, and responses when the vendor has it": "…/v1 — chat completions,供应商支持时也含 responses",
|
||||
"Anthropic compatible": "Anthropic 兼容",
|
||||
"the root URL, what ANTHROPIC_BASE_URL would take": "根地址,即 ANTHROPIC_BASE_URL 的值",
|
||||
"Account": "账号",
|
||||
"{agent}'s sign-in, read from its own files. Sign out there and this provider goes away.": "{agent} 的登录信息,读取自它自己的文件。在那里退出登录,此供应商即消失。",
|
||||
"Models": "模型",
|
||||
"Endpoints": "端点",
|
||||
"Cancel": "取消",
|
||||
"Save": "保存",
|
||||
"{name} saved": "已保存 {name}",
|
||||
"{masked} · paste a new key to replace it": "{masked} · 粘贴新密钥以替换",
|
||||
"optional for local servers": "本地服务可不填",
|
||||
"paste an API key": "粘贴 API 密钥",
|
||||
"Show": "显示",
|
||||
"Hide": "隐藏",
|
||||
"Get a key ↗": "获取密钥 ↗",
|
||||
"API key": "API 密钥",
|
||||
"Kept in ~/.config/dial/providers.json, readable by you alone. Nothing is read from your shell.": "保存在 ~/.config/dial/providers.json,仅你本人可读。不会从你的 shell 读取任何内容。",
|
||||
"model ids, comma separated · e.g. gpt-5.5, claude-sonnet-5": "模型 ID,逗号分隔 · 例如 gpt-5.5, claude-sonnet-5",
|
||||
"Optional: dial asks the vendor for its list after saving.": "可选:保存后 dial 会向供应商获取模型列表。",
|
||||
"More endpoints": "更多端点",
|
||||
"OpenAI URL": "OpenAI 地址",
|
||||
"if the vendor also serves chat completions": "如果供应商也提供 chat completions",
|
||||
"Anthropic URL": "Anthropic 地址",
|
||||
"if the vendor also serves Anthropic messages": "如果供应商也提供 Anthropic messages",
|
||||
"Responses URL": "Responses 地址",
|
||||
"if the vendor serves the OpenAI Responses API (Codex uses it natively)": "如果供应商提供 OpenAI Responses API(Codex 原生使用)",
|
||||
"models.dev id, e.g. openai": "models.dev 上的 ID,例如 openai",
|
||||
"Catalog": "目录",
|
||||
"Display names and reasoning levels for the models": "模型的显示名称与推理等级",
|
||||
"Remove": "移除",
|
||||
"{name} removed": "已移除 {name}",
|
||||
"Add": "添加",
|
||||
"{name} added": "已添加 {name}",
|
||||
"Give it a name": "先起个名字",
|
||||
"A base URL is needed": "需要填写 Base URL",
|
||||
"Test": "测试",
|
||||
"Send a tiny request through each endpoint": "向每个端点发送一个小请求",
|
||||
"model {model}": "模型 {model}",
|
||||
"filter {n} models…": "筛选 {n} 个模型…",
|
||||
"… {n} more, filter to find them": "…… 还有 {n} 个,用筛选查找",
|
||||
"Added by hand": "手动添加",
|
||||
"The vendor's list is empty. Refresh, or type a model id.": "供应商列表为空。刷新,或输入一个模型 ID。",
|
||||
"add a model id…": "添加模型 ID…",
|
||||
"Refresh": "刷新",
|
||||
"Ask the vendor which models it serves": "向供应商询问它提供哪些模型",
|
||||
"{p}: {n} models": "{p}:{n} 个模型",
|
||||
"vendor list · {when}": "供应商列表 · {when}",
|
||||
"from models.dev · Refresh asks the vendor": "来自 models.dev · 刷新可向供应商获取",
|
||||
|
||||
// gateway
|
||||
"running": "运行中",
|
||||
"running · served by another dial": "运行中 · 由另一个 dial 提供",
|
||||
"not running": "未运行",
|
||||
"{n} agent routed through it": "{n} 个 Agent 经由此路由",
|
||||
"{n} agents routed through it": "{n} 个 Agent 经由此路由",
|
||||
"no agent routed through it yet": "尚无 Agent 经由此路由",
|
||||
"four APIs, one URL": "四种 API,一个地址",
|
||||
"start it with dial serve, or open dial at login": "用 dial serve 启动,或让 dial 开机自启",
|
||||
"Copy the gateway URL": "复制网关地址",
|
||||
"Gateway URL": "网关地址",
|
||||
"Copy": "复制",
|
||||
"{what} copied": "已复制{what}",
|
||||
"Connect": "接入",
|
||||
"Loopback only · the key can be anything": "仅限本机回环 · 密钥可以随意填",
|
||||
"Chat Completions, the API most tools speak. Anything with an OpenAI base-URL setting works.": "Chat Completions,多数工具使用的 API。任何可设置 OpenAI base URL 的工具都能用。",
|
||||
"OpenAI's newer API: reasoning, built-in tool items, encrypted reasoning. Codex speaks this.": "OpenAI 较新的 API:推理、内置工具项、加密推理。Codex 使用它。",
|
||||
"Messages API. Claude Code reads ANTHROPIC_AUTH_TOKEN instead of the key; the Agents tab sets that for you.": "Messages API。Claude Code 读取 ANTHROPIC_AUTH_TOKEN 而非密钥;Agent 页会替你设置。",
|
||||
"Google's generateContent API, v1beta. Gemini CLI and the google-genai SDKs speak this.": "Google 的 generateContent API(v1beta)。Gemini CLI 和 google-genai SDK 使用它。",
|
||||
"What {env} takes.": "填入 {env}。",
|
||||
"Key": "密钥",
|
||||
"{env}=dial. The gateway trusts everything on loopback, so any value works.": "{env}=dial。网关信任本机回环上的一切请求,随便填什么都行。",
|
||||
"Model": "模型",
|
||||
"Model id": "模型 ID",
|
||||
"Model ids": "模型 ID",
|
||||
"provider/model, as listed below. Click a model there to put it in the snippets.": "格式为 provider/model,见下方列表。点击某个模型即可放入示例。",
|
||||
"No models yet. Add a provider, or sign in to Codex or Copilot.": "还没有模型。添加一个供应商,或登录 Codex / Copilot。",
|
||||
"Example": "示例",
|
||||
"Snippet": "代码片段",
|
||||
"Put these in the shell (or the tool's settings) and the tool talks to dial instead of the vendor.": "把这些放进 shell(或工具的设置)里,工具就会改为与 dial 通信,而不是直连供应商。",
|
||||
"Copy all ids": "复制全部 ID",
|
||||
"No models exposed yet": "尚未暴露任何模型",
|
||||
"Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.": "添加一个供应商,或登录 Codex / Copilot;它们的模型会出现在这里,供所有 Agent 使用。",
|
||||
"Use this model in the snippets": "在示例中使用此模型",
|
||||
"Recent calls": "最近调用",
|
||||
"shown by the dial that serves the gateway": "由提供网关的那个 dial 显示",
|
||||
"No requests yet. Point an agent at a model, or run the example above; every call shows up here as it happens.": "还没有请求。让某个 Agent 使用一个模型,或运行上面的示例;每次调用都会实时显示在这里。",
|
||||
|
||||
// usage
|
||||
"Today": "今天",
|
||||
"7 days": "7 天",
|
||||
"30 days": "30 天",
|
||||
"All": "全部",
|
||||
"list price": "标价",
|
||||
"{n} call had no known price and is not counted": "{n} 次调用没有已知价格,未计入",
|
||||
"{n} calls had no known price and are not counted": "{n} 次调用没有已知价格,未计入",
|
||||
"At each model's list price on models.dev": "按 models.dev 上各模型的标价计算",
|
||||
"no price for these models": "这些模型没有价格信息",
|
||||
"No calls today.": "今天没有调用。",
|
||||
"No calls in the last 7 days.": "最近 7 天没有调用。",
|
||||
"No calls in the last 30 days.": "最近 30 天没有调用。",
|
||||
"No calls yet.": "还没有调用。",
|
||||
"Point an agent at a catalog model and use it; every call through the gateway is counted here.": "让某个 Agent 使用目录中的模型;每次经过网关的调用都会计入这里。",
|
||||
"tokens": "token",
|
||||
"{a} in · {b} out": "输入 {a} · 输出 {b}",
|
||||
"cache read": "缓存读取",
|
||||
"{n} written": "写入 {n}",
|
||||
"reasoning": "推理",
|
||||
"inside output": "计入输出",
|
||||
"call": "次调用",
|
||||
"calls": "次调用",
|
||||
"{n} failed": "{n} 次失败",
|
||||
"week of {label}": "{label} 起的一周",
|
||||
"{when} · {tokens} tokens · {n} call": "{when} · {tokens} token · {n} 次调用",
|
||||
"{when} · {tokens} tokens · {n} calls": "{when} · {tokens} token · {n} 次调用",
|
||||
"{when} · nothing": "{when} · 无",
|
||||
"{n} call": "{n} 次调用",
|
||||
"{n} calls": "{n} 次调用",
|
||||
"{n}% of tokens": "占 token 的 {n}%",
|
||||
"{n} cached": "缓存 {n}",
|
||||
"Counted from the providers' own usage reports on every call through the gateway · {path}": "根据供应商在每次网关调用中返回的用量统计 · {path}",
|
||||
|
||||
// sync
|
||||
"Model lists refreshed": "模型列表已刷新",
|
||||
"Sync failed: {e}": "同步失败:{e}",
|
||||
|
||||
// settings
|
||||
"Preferences": "偏好",
|
||||
"Appearance": "外观",
|
||||
"Light or dark, or whatever the system is showing": "浅色、深色,或跟随系统",
|
||||
"Language": "语言",
|
||||
"Applies at once, no restart": "立即生效,无需重启",
|
||||
"System": "跟随系统",
|
||||
"Light": "浅色",
|
||||
"Dark": "深色",
|
||||
"About": "关于",
|
||||
"Version": "版本",
|
||||
"Config folder": "配置目录",
|
||||
"providers, profiles and these settings": "供应商、方案与这些设置",
|
||||
"Open": "打开",
|
||||
"Path": "路径",
|
||||
"the address every agent is pointed at": "各 Agent 指向的地址",
|
||||
"Saved": "已保存",
|
||||
},
|
||||
};
|
||||
|
||||
// The active language: a ?locale= URL parameter wins, then the saved
|
||||
// preference, then the system.
|
||||
let locale = "en";
|
||||
function setLocale(pref) {
|
||||
const p = params.get("locale") || pref || "system";
|
||||
locale = p === "system" ? ((navigator.language || "").toLowerCase().startsWith("zh") ? "zh" : "en") : p;
|
||||
document.documentElement.lang = locale === "zh" ? "zh-CN" : "en";
|
||||
translateStatic();
|
||||
}
|
||||
|
||||
function t(s, vars) {
|
||||
let out = I18N[locale]?.[s] ?? s;
|
||||
if (vars) for (const k in vars) out = out.split("{" + k + "}").join(vars[k]);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Static text in index.html: elements marked data-t (text) or data-tt
|
||||
// (title) keep their English in a data attribute and are re-rendered on a
|
||||
// language change.
|
||||
function translateStatic() {
|
||||
for (const e of document.querySelectorAll("[data-t]")) {
|
||||
if (e.dataset.en === undefined) e.dataset.en = e.textContent;
|
||||
e.textContent = t(e.dataset.en);
|
||||
}
|
||||
for (const e of document.querySelectorAll("[data-tt]")) {
|
||||
if (e.dataset.enTitle === undefined) e.dataset.enTitle = e.title;
|
||||
e.title = t(e.dataset.enTitle);
|
||||
}
|
||||
for (const e of document.querySelectorAll("[data-tp]")) {
|
||||
if (e.dataset.enPlaceholder === undefined) e.dataset.enPlaceholder = e.placeholder;
|
||||
e.placeholder = t(e.dataset.enPlaceholder);
|
||||
}
|
||||
}
|
||||
@@ -13,27 +13,30 @@
|
||||
<span>dial</span>
|
||||
</div>
|
||||
<nav class="seg" id="nav" style="--wails-draggable:no-drag">
|
||||
<button data-view="agents" class="on">Agents</button>
|
||||
<button data-view="providers">Providers</button>
|
||||
<button data-view="gateway">Gateway</button>
|
||||
<button data-view="usage">Usage</button>
|
||||
<button data-view="agents" class="on" data-t>Agents</button>
|
||||
<button data-view="providers" data-t>Providers</button>
|
||||
<button data-view="gateway" data-t>Gateway</button>
|
||||
<button data-view="usage" data-t>Usage</button>
|
||||
</nav>
|
||||
<div class="actions" style="--wails-draggable:no-drag">
|
||||
<button class="icon" id="sync" title="Refresh model lists (models.dev and every vendor)">
|
||||
<button class="icon" id="sync" title="Refresh model lists (models.dev and every vendor)" data-tt>
|
||||
<svg viewBox="0 0 16 16" width="14" height="14"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2v3h-3" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
</button>
|
||||
<button class="icon" id="open" title="Open as a window">
|
||||
<button class="icon" id="open" title="Open as a window" data-tt>
|
||||
<svg viewBox="0 0 16 16" width="14" height="14"><path d="M6 3H3.5A1.5 1.5 0 0 0 2 4.5v8A1.5 1.5 0 0 0 3.5 14h8a1.5 1.5 0 0 0 1.5-1.5V10M9 2h5v5M14 2 8 8" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
</button>
|
||||
<button class="icon" id="prefs" title="Settings" data-tt>
|
||||
<svg viewBox="0 0 24 24" width="14" height="14"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g></svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="view" id="view-agents">
|
||||
<div class="list" id="agents"></div>
|
||||
<section class="profiles">
|
||||
<span class="label">Profiles</span>
|
||||
<span class="label" data-t>Profiles</span>
|
||||
<div id="profiles" class="chips"></div>
|
||||
<button class="text" id="save">+ Save current</button>
|
||||
<button class="text" id="save" data-t>+ Save current</button>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
@@ -41,7 +44,7 @@
|
||||
<div class="list" id="providers"></div>
|
||||
<div id="excluded"></div>
|
||||
<div class="after-list">
|
||||
<button class="text" id="addProvider">+ Add provider</button>
|
||||
<button class="text" id="addProvider" data-t>+ Add provider</button>
|
||||
</div>
|
||||
<section class="sheet" id="addSheet" hidden></section>
|
||||
</main>
|
||||
@@ -50,11 +53,11 @@
|
||||
<div class="list gwcard">
|
||||
<div class="row gw" id="gateway"></div>
|
||||
</div>
|
||||
<div class="row-head"><span class="label">Connect</span><span class="grow"></span><span class="note" id="connectNote"></span></div>
|
||||
<div class="row-head"><span class="label" data-t>Connect</span><span class="grow"></span><span class="note" id="connectNote"></span></div>
|
||||
<section class="list connect" id="connect"></section>
|
||||
<div class="row-head"><span class="label">Models</span><span class="grow"></span><button class="text" id="copyModels">Copy all ids</button></div>
|
||||
<div class="row-head"><span class="label" data-t>Models</span><span class="grow"></span><button class="text" id="copyModels" data-t>Copy all ids</button></div>
|
||||
<div class="list" id="gwModels"></div>
|
||||
<div class="row-head"><span class="label">Recent calls</span><span class="grow"></span><span class="note" id="callsNote"></span></div>
|
||||
<div class="row-head"><span class="label" data-t>Recent calls</span><span class="grow"></span><span class="note" id="callsNote"></span></div>
|
||||
<div class="list activity" id="activity"></div>
|
||||
</main>
|
||||
|
||||
@@ -66,28 +69,45 @@
|
||||
</div>
|
||||
<section class="stats" id="stats"></section>
|
||||
<section class="chart" id="chart"></section>
|
||||
<div class="row-head"><span class="label">Agents</span></div>
|
||||
<div class="row-head"><span class="label" data-t>Agents</span></div>
|
||||
<div class="list" id="usageAgents"></div>
|
||||
<div class="row-head"><span class="label">Models</span></div>
|
||||
<div class="row-head"><span class="label" data-t>Models</span></div>
|
||||
<div class="list" id="usageModels"></div>
|
||||
<p class="usage-note" id="usageNote"></p>
|
||||
</main>
|
||||
|
||||
<main class="view" id="view-settings" hidden>
|
||||
<div class="row-head"><span class="label" data-t>Preferences</span></div>
|
||||
<div class="list prefs">
|
||||
<div class="row pref">
|
||||
<div class="who"><div class="name" data-t>Appearance</div><div class="sub" data-t>Light or dark, or whatever the system is showing</div></div>
|
||||
<div id="themeSegs"></div>
|
||||
</div>
|
||||
<div class="row pref">
|
||||
<div class="who"><div class="name" data-t>Language</div><div class="sub" data-t>Applies at once, no restart</div></div>
|
||||
<div id="langSegs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-head"><span class="label" data-t>About</span></div>
|
||||
<div class="list prefs" id="about"></div>
|
||||
</main>
|
||||
|
||||
<footer class="foot">
|
||||
<span id="status" class="status"></span>
|
||||
<span class="grow"></span>
|
||||
<button class="text" id="openMain">Open dial</button>
|
||||
<button class="text" id="quit">Quit</button>
|
||||
<button class="text" id="openMain" data-t>Open dial</button>
|
||||
<button class="text" id="quit" data-t>Quit</button>
|
||||
</footer>
|
||||
|
||||
<div id="pop" class="pop" hidden>
|
||||
<div class="search">
|
||||
<svg viewBox="0 0 16 16" width="13" height="13"><circle cx="7" cy="7" r="4.5" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="m10.5 10.5 3 3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
|
||||
<input id="q" type="text" spellcheck="false" autocomplete="off" placeholder="Filter…">
|
||||
<input id="q" type="text" spellcheck="false" autocomplete="off" placeholder="Filter…" data-tp>
|
||||
</div>
|
||||
<ul id="list"></ul>
|
||||
</div>
|
||||
|
||||
<script src="i18n.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Package settings keeps the few preferences the desktop app has: which
|
||||
// palette to paint with and which language to speak. Everything else dial
|
||||
// knows is derived from the agents' own files.
|
||||
//
|
||||
// The file is ~/.config/dial/settings.json; a missing file means "follow
|
||||
// the system" for both.
|
||||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// Settings is what the user chose. "" and "system" both mean "follow the OS".
|
||||
type Settings struct {
|
||||
Theme string `json:"theme,omitempty"` // system | light | dark
|
||||
Lang string `json:"lang,omitempty"` // system | en | zh
|
||||
}
|
||||
|
||||
// Themes and Langs are the accepted values, in the order the UI offers them.
|
||||
var (
|
||||
Themes = []string{"system", "light", "dark"}
|
||||
Langs = []string{"system", "en", "zh"}
|
||||
)
|
||||
|
||||
// Path is the settings file.
|
||||
func Path() string {
|
||||
if x := os.Getenv("XDG_CONFIG_HOME"); x != "" {
|
||||
return filepath.Join(x, "dial", "settings.json")
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, ".config", "dial", "settings.json")
|
||||
}
|
||||
|
||||
// Dir is the folder every dial file lives in.
|
||||
func Dir() string { return filepath.Dir(Path()) }
|
||||
|
||||
// Load reads the settings; anything missing or unreadable is the default.
|
||||
func Load() Settings {
|
||||
var s Settings
|
||||
if b, err := os.ReadFile(Path()); err == nil {
|
||||
_ = json.Unmarshal(b, &s)
|
||||
}
|
||||
return s.normal()
|
||||
}
|
||||
|
||||
// Save validates and writes the settings.
|
||||
func Save(s Settings) error {
|
||||
s = s.normal()
|
||||
if !slices.Contains(Themes, s.Theme) {
|
||||
return fmt.Errorf("theme must be one of %v, not %q", Themes, s.Theme)
|
||||
}
|
||||
if !slices.Contains(Langs, s.Lang) {
|
||||
return fmt.Errorf("language must be one of %v, not %q", Langs, s.Lang)
|
||||
}
|
||||
if err := os.MkdirAll(Dir(), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := json.MarshalIndent(s, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(Path(), append(b, '\n'), 0o644)
|
||||
}
|
||||
|
||||
func (s Settings) normal() Settings {
|
||||
if s.Theme == "" {
|
||||
s.Theme = "system"
|
||||
}
|
||||
if s.Lang == "" {
|
||||
s.Lang = "system"
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
if s := Load(); s.Theme != "system" || s.Lang != "system" {
|
||||
t.Fatalf("defaults: %+v", s)
|
||||
}
|
||||
if err := Save(Settings{Theme: "dark", Lang: "zh"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := Load(); s.Theme != "dark" || s.Lang != "zh" {
|
||||
t.Fatalf("saved: %+v", s)
|
||||
}
|
||||
if err := Save(Settings{Theme: "sepia"}); err == nil {
|
||||
t.Fatal("bad theme accepted")
|
||||
}
|
||||
if Save(Settings{}) != nil || Load().Theme != "system" {
|
||||
t.Fatal("empty means system")
|
||||
}
|
||||
if filepath.Base(Path()) != "settings.json" {
|
||||
t.Fatal(Path())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user