"希望 可以在不同的 agent中选择是否显示供应商名字,现在只能统一开关":
Provider in model names was one switch for every agent. An agent's
Details on the Agents page now has a Provider in model names row: As in
Settings · <mode> (the default, kept for everyone), On, Not on names I
set, or Off, for that agent alone. The CLI has the same thing:
`magpie model suffix <agent> [on|own|off|every]`.
- settings.AgentSuffix keeps the agent's own mode by the id its lists are
kept by (Agent.ListsFor, lower-cased, without @wsl: or #profile). An
agent with none follows PlainNames/PlainOwnNames as before, so nothing
a user already set changes.
- provider.LabelsFor(agent, es) reads that agent's mode. Every place
that named models with Labels for an agent now passes the agent: Codex's
catalog, the agents' written lists (route.go, Pi's extension), the
gateway's /v1/models (by agentOf(r)), Muse, Antigravity, Ollama, Claude
Desktop's catalog and descriptions, Claude Science. Labels is
LabelsFor("").
- POST /api/settings/agent-suffix sets it and rewrites the agents'
configs (catalog.Touched), as Settings' switch does.
- docs/subsystems/agent-wiring.md says where the mode is kept and read.
- The picker is in agentsuffix.js, imported when an agent's Details open,
so the core grows by the one line that loads it (1,529,335 of its
1,533,802 budget, after the previous commit's move). An agent whose
list takes no names of magpie's (noNames) has no row.
Tests, each red on the old code: TestAgentSuffix (provider: modes, keys
with @wsl and #profile, reset, bad input), TestAgentSuffixReachesItsFileAlone
(agent: Pi's file follows its own mode while Codex's follows Settings'),
TestModelsListFollowsAgentSuffix (gateway /v1/models per agent),
TestModelSuffixAgentCmd (cli), settings_keep (AgentSuffix survives a
Settings save), agent-suffix.test.cjs (5 languages x 1180/390 x chromium
and webkit, and a noNames agent has no row).
Broken by hand (a copy with LabelsFor ignoring the agent and the picker
reading no own mode): TestAgentSuffix, TestAgentSuffixReachesItsFileAlone,
TestModelsListFollowsAgentSuffix and every agent-suffix GUI case went red.
TestModelSuffixAgentCmd stayed green; it checks what is saved, not the
names.
Run on mote at this change on top of 720200092: gofmt -l clean; go vet darwin, GOOS=linux
-tags nogui and GOOS=windows clean; go test -count=1 of internal/provider,
cli, gui, settings, settingsapi and agent: ok; internal/gateway in an earlier
run of this change at 3b261932e: ok (1044s), and at this head -run
'Desktop|Models|Suffix|Science|Muse|Ollama|Antigravity|Codex.*Catalog': ok.
node --test of every agent-*, i18n-* and gui-* file plus old-webkit, both
engines: 1026 of 1049. The reds are all on main or under load:
agent-switch-accounts' 20 not-connected cases (red at origin/main 7c41060c2
too, filed as #5925), old-webkit's Safari 15 styles (#5919), and one case
each of agent-compact (#5607) and agent-stale-copies (#1949), which pass
44/44 when run alone. panel-fold's 'keeps what was clicked' is red on main
too (#5796).
Rebased on 0f94acc99 and run again at this change (9d82986ea): gofmt
clean, go vet clean for darwin, linux (nogui) and windows; provider,
gui, settings, settingsapi and agent ok, the gateway's suffix and
agentOf tests ok; GUI agent-suffix, old-webkit, agent-bulk-visibility,
visibility-saving, i18n-keys and i18n-en-no-cjk in chromium and webkit,
57 of 58, the one red Safari 15's styles (#5919). internal/cli was red
only on /api/model-price having no command, from main's 40ca0c88d;
the next commit names it. Rebased again on ccc96b4a7 before the push
(proc, codex, claudetui, a remote window, routing rules, redact;
no conflict), core budget test ok there.
Not tried: a real agent with a real account picking its own mode; WSL and
Windows agents (the @wsl: key is covered by a unit test only).
419 lines
19 KiB
Go
419 lines
19 KiB
Go
// Package settingsapi is what the Settings page's save writes: the fields
|
|
// POST /api/settings takes from the page, how a value is checked, and the
|
|
// save itself. The window's handler and `magpie settings` both save through
|
|
// Apply, so a value the CLI sets is checked and kept exactly as one the
|
|
// page sets (#4745).
|
|
package settingsapi
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"reflect"
|
|
"slices"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// Keys are the settings POST /api/settings saves from what it is sent, by
|
|
// their JSON names, in the order `magpie settings list` shows them. Every
|
|
// other field of settings.Settings is carried from the file (Merge), set
|
|
// by a route of its own or kept by settings.Save. TestKeysAreWhatTheSaveWrites
|
|
// fails when a field the save writes is missing here, or one here isn't
|
|
// written.
|
|
var Keys = []string{
|
|
// Appearance
|
|
"theme", "colorblind", "reduceMotion", "noBird", "lang", "uiFont", "codeFont",
|
|
// the tray, the Dock and this computer
|
|
"tray", "dock", "dockWindow", "dockNever", "lightweight", "keepAwake", "keepAwakeDisplay",
|
|
"noWSLAgents", "sessionTerminal", "signInLinkOnly", "quitNoAsk",
|
|
// the menu bar's allowance cards
|
|
"trayUsages", "trayUsage", "trayUsageEvery", "trayNoLogos", "trayNoBird", "trayNoNumber", "trayPace", "trayNoCost", "trayWindows",
|
|
// usage and alerts
|
|
"currency", "chineseUnits", "usageAlert", "balanceAlert", "resetReminder", "turnDoneAlert", "maskAlert",
|
|
// network
|
|
"proxy", "pluginProxy",
|
|
// privacy
|
|
"redact", "redactPersonal", "redactKinds", "redactWords", "redactWordsAnyCase", "redactWordsWhole", "redactShape",
|
|
"noStats", "noUsageStats", "otel",
|
|
// warm-ups and check-ins
|
|
"codexWarmup", "claudeWarmup", "codexWarmAt", "claudeWarmAt", "codexWarmAts", "claudeWarmAts",
|
|
"workbuddyCheckin", "traeCheckin", "minimaxCheckin", "qoderCheckin", "checkinAt",
|
|
// models: replies, vision, images, search
|
|
"replyModel", "noLoopGuard", "claudeLeanPrompt", "claudePrintMode", "refusalRetries", "retryAfterCap",
|
|
"vision", "visionEffort", "imageGen", "videoGen", "imageTimeout", "classifyTimeout",
|
|
// what every routing group does that says nothing of its own
|
|
"groupSink", "groupFirstToken", "groupPatience",
|
|
"searcher", "searcherThen", "searcherEffort", "searchFirst",
|
|
// updates
|
|
"noUpdatePill", "noAutoUpdate", "updateEvery", "noAutoDownload", "autoRestart", "updateChannel",
|
|
}
|
|
|
|
// Choices are the values a setting with a closed set takes, for
|
|
// `magpie settings list` to name: settings' own lists, which settings.Save
|
|
// checks a saved value against (a value outside them is refused there,
|
|
// from the window as from the CLI). A setting's "" is its default.
|
|
var Choices = map[string][]string{
|
|
"theme": settings.Themes,
|
|
"lang": settings.Langs,
|
|
"tray": settings.Trays,
|
|
"currency": settings.Currencies,
|
|
"codexWarmup": {"off", "week", "all"},
|
|
"claudeWarmup": {"off", "week", "all"},
|
|
"trayUsageEvery": ints(settings.TrayEvery),
|
|
"updateChannel": {settings.UpdateStable},
|
|
"updateEvery": ints(settings.UpdateEveries),
|
|
"searchFirst": {settings.SearchFirstModel, settings.SearchFirstAPI},
|
|
"replyModel": settings.ReplyModels,
|
|
}
|
|
|
|
func ints(v []int) []string {
|
|
out := make([]string, len(v))
|
|
for i, n := range v {
|
|
out[i] = strconv.Itoa(n)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Field is the struct field of settings.Settings saved under the JSON name
|
|
// key, and whether there is one.
|
|
func Field(key string) (reflect.StructField, bool) {
|
|
t := reflect.TypeFor[settings.Settings]()
|
|
for i := range t.NumField() {
|
|
f := t.Field(i)
|
|
if name, _, _ := strings.Cut(f.Tag.Get("json"), ","); name == key {
|
|
return f, true
|
|
}
|
|
}
|
|
return reflect.StructField{}, false
|
|
}
|
|
|
|
// Value is key's value in s, as it is saved.
|
|
func Value(s settings.Settings, key string) (any, bool) {
|
|
f, ok := Field(key)
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
return reflect.ValueOf(s).FieldByIndex(f.Index).Interface(), true
|
|
}
|
|
|
|
// Known says whether key is one Apply saves.
|
|
func Known(key string) bool { return slices.Contains(Keys, key) }
|
|
|
|
// Body is what the Settings page sends to set key to value (its JSON) and
|
|
// leave everything else as cur has it: cur whole, with key sent even when
|
|
// it is a zero value, which a field omitted would not be (an omitted
|
|
// noBird is "keep", false is "show the bird").
|
|
func Body(cur settings.Settings, key string, value json.RawMessage) ([]byte, error) {
|
|
if !Known(key) {
|
|
return nil, fmt.Errorf("unknown setting %q", key)
|
|
}
|
|
b, err := json.Marshal(cur)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var m map[string]json.RawMessage
|
|
if err := json.Unmarshal(b, &m); err != nil {
|
|
return nil, err
|
|
}
|
|
m[key] = value
|
|
return json.Marshal(m)
|
|
}
|
|
|
|
// Apply is POST /api/settings: body read over the settings saved now
|
|
// (Merge), checked and saved. It returns what was saved and what was there
|
|
// before, for the caller's reactions to a change (the window's Dock, fonts,
|
|
// tray menu and alerts). web is a page served to a browser, whose fonts are
|
|
// another computer's and never saved.
|
|
func Apply(body []byte, web bool) (in, cur settings.Settings, err error) {
|
|
// Unreadable settings are never carried as the defaults (an empty
|
|
// allow list, every address let in): Save would refuse them too.
|
|
cur, err = settings.LoadChecked()
|
|
if err != nil {
|
|
return in, cur, err
|
|
}
|
|
in, err = Merge(body, cur, web)
|
|
if err != nil {
|
|
return in, cur, err
|
|
}
|
|
if err := settings.Save(in); err != nil {
|
|
return in, cur, err
|
|
}
|
|
// whether agents are told every model takes images follows Vision
|
|
// (provider.Described)
|
|
if strings.TrimSpace(in.Vision) != strings.TrimSpace(cur.Vision) {
|
|
catalog.Touched()
|
|
}
|
|
return in, cur, nil
|
|
}
|
|
|
|
// Merge is the settings body sets over cur: the page's own choices from
|
|
// body, and everything else as cur has it. It writes nothing.
|
|
func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, error) {
|
|
var in settings.Settings
|
|
dec := json.NewDecoder(bytes.NewReader(body))
|
|
var raw json.RawMessage
|
|
if err := dec.Decode(&raw); err != nil {
|
|
return in, err
|
|
}
|
|
if err := json.Unmarshal(raw, &in); err != nil {
|
|
return in, err
|
|
}
|
|
var fields map[string]json.RawMessage
|
|
_ = json.Unmarshal(raw, &fields)
|
|
// the Settings page sends its own choices; how the agents are
|
|
// arranged is the Agents page's, and the window's size its own; both stay as they are.
|
|
// Older pages do not send fonts. An explicit null restores the
|
|
// default, while an omitted field (or a browser save) preserves it.
|
|
if _, sent := fields["uiFont"]; !sent || web {
|
|
in.UIFont = cur.UIFont
|
|
}
|
|
if _, sent := fields["codeFont"]; !sent || web {
|
|
in.CodeFont = cur.CodeFont
|
|
}
|
|
// and pages from before it do not send how often a refusal is asked
|
|
// again, which null sets back to every one left
|
|
if _, sent := fields["refusalRetries"]; !sent {
|
|
in.RefusalRetries = cur.RefusalRetries
|
|
}
|
|
// nor the longest wait an agent is told (#5371)
|
|
if _, sent := fields["retryAfterCap"]; !sent {
|
|
in.RetryAfterCap = cur.RetryAfterCap
|
|
}
|
|
// nor whether updates download by themselves (#2296)
|
|
if _, sent := fields["noAutoDownload"]; !sent {
|
|
in.NoAutoDownload = cur.NoAutoDownload
|
|
}
|
|
// nor the update channel (ssharpcc on X)
|
|
if _, sent := fields["updateChannel"]; !sent {
|
|
in.UpdateChannel = cur.UpdateChannel
|
|
}
|
|
// nor whether the masked words match in any case
|
|
if _, sent := fields["redactWordsAnyCase"]; !sent {
|
|
in.RedactWordsAnyCase = cur.RedactWordsAnyCase
|
|
}
|
|
// nor whether they match only as whole words
|
|
if _, sent := fields["redactWordsWhole"]; !sent {
|
|
in.RedactWordsWhole = cur.RedactWordsWhole
|
|
}
|
|
// nor whether a key goes as a made-up one of its form
|
|
if _, sent := fields["redactShape"]; !sent {
|
|
in.RedactShape = cur.RedactShape
|
|
}
|
|
// nor how long an image is given to be drawn
|
|
// nor the video model, picked in its own row
|
|
if _, sent := fields["videoGen"]; !sent {
|
|
in.VideoGen = cur.VideoGen
|
|
}
|
|
if _, sent := fields["imageTimeout"]; !sent {
|
|
in.ImageTimeout = cur.ImageTimeout
|
|
}
|
|
// nor how long a routing group's classifier is given (#2934)
|
|
if _, sent := fields["classifyTimeout"]; !sent {
|
|
in.ClassifyTimeout = cur.ClassifyTimeout
|
|
}
|
|
// nor what every routing group does that says nothing of its own,
|
|
// which the Routing groups page sets (jiezhengj on Discord)
|
|
if _, sent := fields["groupSink"]; !sent {
|
|
in.GroupSink = cur.GroupSink
|
|
}
|
|
if _, sent := fields["groupFirstToken"]; !sent {
|
|
in.GroupFirstToken = cur.GroupFirstToken
|
|
}
|
|
if _, sent := fields["groupPatience"]; !sent {
|
|
in.GroupPatience = cur.GroupPatience
|
|
}
|
|
// nor whether animations are stilled (#3813)
|
|
if _, sent := fields["reduceMotion"]; !sent {
|
|
in.ReduceMotion = cur.ReduceMotion
|
|
}
|
|
// nor whether the loading bird is kept off
|
|
if _, sent := fields["noBird"]; !sent {
|
|
in.NoBird = cur.NoBird
|
|
}
|
|
// nor whether a Quit asks first while agents go through magpie
|
|
// (zhujiu on Discord), which the Quit question sets too
|
|
if _, sent := fields["quitNoAsk"]; !sent {
|
|
in.QuitNoAsk = cur.QuitNoAsk
|
|
}
|
|
// nor what a reply's model name says, which they sent as memberModel:
|
|
// a change of it is that, and else the name stays as it is (vendor
|
|
// too, which they can't show). memberModel itself is only ever
|
|
// written beside replyModel (settings' normal).
|
|
if _, sent := fields["replyModel"]; sent {
|
|
in.MemberModel = false
|
|
} else {
|
|
in.ReplyModel = cur.ReplyModel
|
|
if _, sent := fields["memberModel"]; sent && in.MemberModel != (cur.ReplyModel == settings.ReplyMember) {
|
|
in.ReplyModel = settings.ReplyAsked
|
|
if in.MemberModel {
|
|
in.ReplyModel = settings.ReplyMember
|
|
}
|
|
}
|
|
in.MemberModel = false
|
|
}
|
|
// nor whether a value masked for the first time is told (Must2333)
|
|
if _, sent := fields["maskAlert"]; !sent {
|
|
in.MaskAlert = cur.MaskAlert
|
|
}
|
|
in.AgentOrder, in.AgentsHidden, in.AgentsShown, in.AgentsHere = cur.AgentOrder, cur.AgentsHidden, cur.AgentsShown, cur.AgentsHere
|
|
in.Window, in.WindowMaximised, in.WindowAt = cur.Window, cur.WindowMaximised, cur.WindowAt // the window's own, as it was last resized and moved
|
|
// and what other pages keep here: which models an agent is shown, and
|
|
// everything the user said of a model anywhere else in the app, set on
|
|
// its own. The per-model maps are carried whole rather than named one
|
|
// by one, so a map added later is not silently dropped here.
|
|
//
|
|
// HiddenModels, PickedModels and OrderedModels are the other way
|
|
// round — keyed by agent, not by "<provider>/<model>" — so they are
|
|
// not among them, and belong to the Agents page.
|
|
in.Visible, in.HiddenModels, in.OrderedModels = cur.Visible, cur.HiddenModels, cur.OrderedModels
|
|
in.PickedModels = cur.PickedModels // "only models I pick" (#1337)
|
|
in.OwnModelsHidden = cur.OwnModelsHidden // an agent's own models left out (#1642)
|
|
in.FastPicks = cur.FastPicks // switched in the agents' pickers (#954)
|
|
in.UltraPicks = cur.UltraPicks // and sent Ultrafast (#1954)
|
|
in.AgentEfforts = cur.AgentEfforts // picked in an agent's row (#1003)
|
|
in.PluginCheckins = cur.PluginCheckins // set on its own (plugin-checkin)
|
|
in.PluginOptions = cur.PluginOptions // set on its own (plugin-option)
|
|
in.CheckinOff = cur.CheckinOff // set on its own (checkin-account)
|
|
settings.CarryPerModel(&in, &cur)
|
|
in.LAN, in.LANKey = cur.LAN, cur.LANKey
|
|
in.LANKeyID = cur.LANKeyID
|
|
in.Port = cur.Port // set on its own (port), which moves the gateway
|
|
in.CORSOrigins = cur.CORSOrigins // set on its own (cors)
|
|
in.AllowIPs = cur.AllowIPs // set on its own (allowips)
|
|
in.MTLS = cur.MTLS // set on its own (mtls)
|
|
in.FetchPrivate = cur.FetchPrivate // in settings.json only
|
|
in.RouterNote = cur.RouterNote // set on its own (the Library's servers/hub-note)
|
|
in.RouterAllTools = cur.RouterAllTools // set on its own (the Library's servers/hub-tools)
|
|
in.GitHubToken = cur.GitHubToken // set on its own (github-token), never sent to the page
|
|
in.ProxyCustom = cur.ProxyCustom // set by settings.Save from the proxy, never by the page
|
|
in.PluginProxyCustom = cur.PluginProxyCustom // and plugin downloads' from theirs
|
|
in.RequestArchive = cur.RequestArchive // the Gateway page's, set on its own
|
|
in.RequestArchiveMaxMB = cur.RequestArchiveMaxMB // in settings.json only
|
|
in.ClaudeRunsMost = cur.ClaudeRunsMost // magpie claude-code runs, or settings.json (#2956)
|
|
in.GatewayConversations = cur.GatewayConversations // Sessions' explicit recording consent
|
|
in.RedactRules = cur.RedactRules // the masking rules, set on their own
|
|
in.RedactModel = cur.RedactModel // set on its own (privacy-model)
|
|
in.RedactModelName = cur.RedactModelName // set on its own (privacy-model)
|
|
in.RedactModelScore = cur.RedactModelScore // set on its own (privacy-model)
|
|
in.RedactModelOff = cur.RedactModelOff // set on its own (privacy-model)
|
|
in.RedactModelAuto = cur.RedactModelAuto // set on its own (masking)
|
|
in.RedactActions = cur.RedactActions // set on their own (redact-actions)
|
|
in.RedactAllow = cur.RedactAllow // set on its own (redact-allow)
|
|
in.DisabledModels = cur.DisabledModels // set on their own (disabled-models, #1867)
|
|
// the request archive on this computer: the archive's switch while no
|
|
// S3 bucket, and its size in settings.json only
|
|
in.RequestArchiveLocal, in.RequestArchiveLocalMB = cur.RequestArchiveLocal, cur.RequestArchiveLocalMB
|
|
// used or left is the Usage page's toggle as much as Settings', set on its own
|
|
in.QuotaLeft = cur.QuotaLeft
|
|
in.QuotaReads = cur.QuotaReads // set on its own (quota-reads)
|
|
in.SearchAll = cur.SearchAll // set on its own (search-all)
|
|
in.SearchCount = cur.SearchCount // and so is this (search-count)
|
|
in.UsageOrder = cur.UsageOrder // the Usage page's, dragged there
|
|
// and what the tray panel's Allowances tab leaves out, set there
|
|
in.PanelUsageHidden = cur.PanelUsageHidden
|
|
// and the clients the Usage page's Agents list leaves out, set there
|
|
in.UsageAgentsHidden = cur.UsageAgentsHidden
|
|
// and the allowance cards the Usage page's Overview leaves out, set there
|
|
in.UsageCardsHidden = cur.UsageCardsHidden
|
|
// and the names models' usage is counted under (magpie model alias)
|
|
in.UsageAliases = cur.UsageAliases
|
|
// and the clears of usage made on the Usage page
|
|
in.UsageCleared = cur.UsageCleared
|
|
// and the clients it counts as agents, set there too (#1958)
|
|
in.ClientAgents = cur.ClientAgents
|
|
// how agents' lists name models, set on its own for the agents to be told
|
|
in.PlainNames, in.PlainOwnNames = cur.PlainNames, cur.PlainOwnNames
|
|
in.AgentSuffix = cur.AgentSuffix // and each agent's own (agent-suffix)
|
|
in.BareModelIDs = cur.BareModelIDs // set on its own (bare-ids)
|
|
in.BusyLoad = cur.BusyLoad // and so is this (busy-load)
|
|
in.CodexAgentsV1 = cur.CodexAgentsV1
|
|
in.FullContext = cur.FullContext // set on its own (full-context)
|
|
in.CompactAt = cur.CompactAt // and so is the threshold
|
|
in.AgentCompacts = cur.AgentCompacts // and each agent's own (agent-compact)
|
|
// Codex's background compaction, set on its own (codex-async-compact)
|
|
in.CodexAsyncCompact, in.CodexAsyncCompactPercent = cur.CodexAsyncCompact, cur.CodexAsyncCompactPercent
|
|
// Claude Desktop's list, set in its row on the Agents page
|
|
in.DesktopLongest = cur.DesktopLongest
|
|
// and whether it runs in a folder of its own, set there too (#5671)
|
|
in.DesktopIsolated = cur.DesktopIsolated
|
|
// and the Get started card put away, from the card itself
|
|
in.GuideHidden = cur.GuideHidden
|
|
|
|
in.CodexTitles = cur.CodexTitles // set on its own (codex-titles)
|
|
in.CodexDescriptions = cur.CodexDescriptions // set on its own (codex-descriptions)
|
|
in.CodexPredictions = cur.CodexPredictions // and codex-predictions
|
|
// and so is the model Codex's auto-review runs on (codex-auto-review)
|
|
in.CodexAutoReview = cur.CodexAutoReview
|
|
// and the models Codex's and Desktop's subagents are put on, set
|
|
// in their Agents rows
|
|
in.CodexSubagentModel = cur.CodexSubagentModel
|
|
in.DesktopSubagentModel = cur.DesktopSubagentModel
|
|
in.CodexServiceTier = cur.CodexServiceTier // codex-service-tier
|
|
// and the model DeepSeek Harness compacts on, set in its row
|
|
in.DshCompactModel = cur.DshCompactModel
|
|
// and the model for requests masking would change (redact-route)
|
|
in.RedactRouteTo = cur.RedactRouteTo
|
|
in.DesktopSubagentEffort = cur.DesktopSubagentEffort
|
|
in.ChinaMirror = cur.ChinaMirror // the Plugins page's, set on its own
|
|
in.NPMRegistry = cur.NPMRegistry // and its npm registry
|
|
// which Codex accounts spend a reset by themselves, set on the Usage card
|
|
in.CodexAutoReset = cur.CodexAutoReset
|
|
in.CodexAutoResetOnly = cur.CodexAutoResetOnly // and at which of the two times
|
|
in.CodexResetLead = cur.CodexResetLead // and how early before one expires (codex-reset-lead)
|
|
// and which of them spend their credits, set there too
|
|
in.CodexNoCredits = cur.CodexNoCredits
|
|
in.CodexCreditsLast = cur.CodexCreditsLast // and which only after everything else
|
|
in.CodexCreditsFirst = cur.CodexCreditsFirst // and which before another account
|
|
// and each Codex account's own daily warm-up (codex-warm-at)
|
|
in.CodexWarmAtOf = cur.CodexWarmAtOf
|
|
// and the text size, which the keyboard changes too (text-size)
|
|
in.TextSize = cur.TextSize
|
|
// and the quick panel's shortcut, set on its own (panel-shortcut)
|
|
in.PanelShortcut = cur.PanelShortcut
|
|
// the Dock choice's reading, which the page never sets: the file's
|
|
// as read (settings.DockSettled), so a save from the page doesn't
|
|
// read its With window as an older file's Hide
|
|
in.DockSettled = cur.DockSettled
|
|
// the version the Update pill was hidden for, set from the pill
|
|
in.UpdateSkip = cur.UpdateSkip
|
|
// the GitHub mirror updates come through, set by magpie update mirror
|
|
in.UpdateMirror = cur.UpdateMirror
|
|
// gateway mode, set on its own (gateway-mode)
|
|
in.GatewayMode = cur.GatewayMode
|
|
in.NoAccountDiscovery = cur.NoAccountDiscovery // set on its own (account-discovery, or the CLI)
|
|
if v := strings.TrimSpace(in.Vision); v != "" && v != "off" && v != cur.Vision {
|
|
if _, _, ok := provider.Resolve(v); !ok {
|
|
return in, fmt.Errorf("no model %s to describe images", v)
|
|
}
|
|
}
|
|
if v := strings.TrimSpace(in.ImageGen); v != "" && v != "off" && v != cur.ImageGen {
|
|
if _, _, ok := provider.Resolve(v); !ok {
|
|
return in, fmt.Errorf("no model %s to generate images", v)
|
|
}
|
|
}
|
|
if v := strings.TrimSpace(in.VideoGen); v != "" && v != cur.VideoGen && gateway.VideomakerMissingOf(v) != "" {
|
|
return in, fmt.Errorf("no model %s to make videos", v)
|
|
}
|
|
// the searchers after the one named, set in their own row: a save
|
|
// that doesn't send them (prefsKeep has none) keeps them, and an
|
|
// empty list clears them
|
|
if in.SearcherThen == nil {
|
|
in.SearcherThen = cur.SearcherThen
|
|
}
|
|
for _, v := range append([]string{in.Searcher}, in.SearcherThen...) {
|
|
if v = strings.TrimSpace(v); v != "" && v != "off" && v != cur.Searcher && !slices.Contains(cur.SearcherThen, v) {
|
|
id, _, _ := strings.Cut(v, "/")
|
|
if !slices.ContainsFunc(gateway.Searchers(), func(c gateway.SearcherChoice) bool { return c.Provider.ID == id }) {
|
|
return in, fmt.Errorf("%s can't search the web for other models", id)
|
|
}
|
|
}
|
|
}
|
|
return in, nil
|
|
}
|