claude-desktop: a tier's pick runs with its tier's Claude prompt (behavesAs)
moer2831 on Discord: a model picked for one of Claude Desktop's tiers ran
in the Code tab on Claude Code's generic prompt, not the one of the
Claude model of that tier ("通用提示词和对应模型提示词差距挺大的,感觉直接
蠢了一个度"). Desktop 4.29 and later hand Claude Code behavesAs only from
a profile's inferenceModels (z3t in 4.4212's app.asar: modelPicker
options with each entry's behavesAs).
What changed:
- gateway.DesktopInferenceModels: while a model is picked for a tier,
the list is every row /v1/models gives Desktop, by its id and in its
order (a non-empty list replaces discovery, pzn), with supports1m,
prefer1m and labelOverride as Desktop read them off the row, and a
pick's anthropicFamilyTier/isFamilyDefault. A pick that isn't a Claude
model gets behavesAs = its tier's newest Claude id (claude-opus-5-5,
claude-sonnet-5-5, claude-haiku-5-5, claude-fable-5-1). Nothing picked
(or a pick no longer listed): no list. Unreadable picks are unknown.
- agent: desktopSyncModels writes it into magpie's Desktop profile on a
tier's Set, as Desktop comes on magpie and on Sync; temp+rename, only
when it changed; taken away when nothing is picked. The list is
magpie's only while its hash is one magpie recorded (stash mark
claude-desktop.models); any other list (the user's) is never written
over or removed.
- Claude Code's modelSettings gets the pick's own window even when it
matches the default (claudeBudget.behaves), since behavesAs would
otherwise give it the Claude model's.
- GUI: the tiers menu ends with one line, "Claude Desktop reads the
tiers as it starts: restart it after a change." (en, zh, zh-TW, ja,
de). The Agents row's Restart already lights from the profile hash.
- docs/subsystems/agent-wiring.md and gateway-routing.md.
Run on mote at this tree (base c86fa2a34): gofmt -l clean; GOOS=linux
(-tags nogui) and GOOS=windows go vet ./internal/agent ./internal/gateway;
go test -count=1 -timeout 45m ./internal/agent ./internal/gateway
./internal/gui ./internal/cli ./internal/tui ./internal/backup
./internal/davsync ./internal/library ./internal/profile ./internal/stats
./internal/uninstall: ok but internal/gateway's
TestCodexPoolSaysTheClientsVersion (passes alone here and at main; #4807)
and internal/gui's TestMainWindowCorners (red the same at origin/main
6a6e4fefa; #3949). GUI (chromium + webkit, every
language they cover): desktop-tiers, i18n-keys, and every file named for
tiers, picks, roles, Desktop, i18n or a language (887 tests,
871 pass; the 16 reds are 4 files red the same at origin/main 6a6e4fefa:
found-skill-pick-remove #4097, menu-input-scroll #3402,
phone-connect-menu #4706/#4707, provider-picks-stay #4397). Not the
whole GUI suite.
Rebased on origin/main a5c1fa4b4 (nothing there touches agent, gateway or
GUI assets but routing.css), then again at the pushed head: go vet
./internal/agent ./internal/gateway; the size budgets,
TestDesktopInferenceModels, TestClaudeDesktop*, TestClaudePlan;
desktop-tiers and i18n-keys in both engines: ok.
Broken by hand, each red: behavesAs left out (TestDesktopInferenceModels);
the window write's behaves check dropped (TestClaudePlan); the sync on a
tier's Set dropped (TestClaudeDesktopModelsList); the user-list guard
off (TestClaudeDesktopModelsList); the menu's line not shown
(desktop-tiers 0 of 4).
Not tried: a real Claude Desktop 4.29 or later (none on mote; this
Mac's is 2.7032 and live). Builds before 4.29 ignore behavesAs and take
the names. Desktop 1.x gets the mythos ids. A user's own gateway profile
applied in Desktop makes magpie's list do nothing.
Thanks moer2831 for the report.
This commit is contained in:
@@ -122,6 +122,7 @@ something else shows up as drift.
|
||||
- Claude Code's "subagents" field is `env.CLAUDE_CODE_SUBAGENT_MODEL`. Unset, magpie writes nothing there (`writeTiers`, `setSubagent`), and Claude Code picks: the Agent tool call's model, then the subagent's own frontmatter model, then the variable, then the lead's model (Claude Code 2.1.306; the built-in Explore inherits, capped at opus). So the GUI calls unset "Claude Code's own pick" (`claudePicks` in app.js), not "same as model" (KorenKrita on Discord). Its effort is written only with a model: unset, a saved subagent effort is kept (`claude.subagent_effort` in the stash) and not applied, since writing the main model at that effort into the variable would pin every subagent to the main model (KorenKrita on Discord). A model picked later takes it. A value an older magpie wrote that way (the main model at an effort, not own) is moved into the stash and taken out of the env by `writeTiers` and Sync (`subagentFollowing`, `TestClaudeSubagentEffortNeedsAModel`). The window draws that effort at the right of the Subagents row like a tier's, disabled at Default while the model is unset (`effortBtn` in `connectPanel`, `claude-subagent-effort-row.test.cjs`); the tray panel keeps its own square.
|
||||
- Codex's "subagent model" field writes nothing to Codex's config: its lead names each subagent's model in `spawn_agent`, which `[agents]` can't overrule. It is magpie's setting (`settings.CodexSubagentModel`, [`codex_subagent.go`](../../internal/provider/codex_subagent.go)), and the gateway moves the subagent's request onto it (see [gateway routing](gateway-routing.md)). Its options are every model and routing group Codex's own lists show (`CatalogFor("codex")`, so a model taken out of them or not picked is left out here too), ChatGPT accounts' first (#1633: a lead on a chat provider wants its subagents there too). A task a ChatGPT-backed lead sealed opens only on a ChatGPT account, so the gateway keeps such a subagent on its own model when the one set is another provider's. Its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup put back on another computer still applies (`ApplyFields` stops at the first failed Set), and refuses one of Codex's own bare names.
|
||||
- Claude Desktop's "subagent model" field (`subagent_model`, `desktopSubagentField` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)) writes nothing to Desktop's config: Desktop runs its Code tab's Claude Code with `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1`, under which Claude Code ignores `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` and the tier variables in its settings files' `env` ("Ignoring … this session's provider routing is managed by the host", Claude Code 2.1.295), and the env Desktop builds for the Code tab has no key for it (Desktop 2.31226). It is magpie's setting (`settings.DesktopSubagentModel`, [`desktop_subagent.go`](../../internal/provider/desktop_subagent.go)), and the gateway moves each subagent's turn onto it (see [gateway routing](gateway-routing.md)). It is labelled as Codex's, so the Agents page gives it the same square. Its options are magpie's models and groups as Desktop's list shows them (`viaMagpie("claude-desktop")`), while Desktop is on magpie, as for the tiers. A Desktop alias picked is kept by its catalog id (`DesktopCatalogID`). Like Codex's, its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup still applies, and refuses a bare name. It is `Live`: the gateway reads it on each request.
|
||||
- Claude Desktop's tiers also write magpie's profile's `inferenceModels` (`desktopSyncModels` in [`claudedesktop_models.go`](../../internal/agent/claudedesktop_models.go)), the list `gateway.DesktopInferenceModels` gives (see [gateway routing](gateway-routing.md)): on a tier's `Set`, as Desktop comes on magpie, and on the agent's `Sync`, so a provider saved or removed reaches it through `SyncCatalog`. It is written through temp-and-rename and only when it changed, and taken away when no tier is picked. The list is magpie's only while its hash is one magpie recorded (`desktopModelsMark` in the stash, the next hash recorded before each write); any other list, the user's own or one carried from their own gateway profile, is never written over or taken away. A pick that runs as a Claude model (`behavesAs`) is told its own window in Claude Code's `modelSettings` (`claudeBudget.behaves`), since Claude Code would otherwise run it at that Claude model's. Desktop reads the list as it starts. Not tried against a real Desktop 4.29 or later; a Desktop below 2 (no mythos word) is given the mythos ids `/v1/models` gives 2 and up. `TestClaudeDesktopModelsList`.
|
||||
- Claude Desktop's "subagent effort" (`desktopSubagentEffortField`, `settings.DesktopSubagentEffort`) is also Quiet and Live. Default keeps the effort the request asks for, including disabled thinking; it never selects a new default. A picked level works independently of the subagent model: no model pick, the same model and an unavailable model pick all still take the effort. While wired, the field offers the selected model's levels, or the standard levels when its model is inherited or unavailable; a model marked reasonless offers none. The stored pick survives model changes. A disconnected preference can be saved or cleared without connecting Desktop or showing restart advice, so profile restoration and Disconnect can restore a value saved before connecting; reconnect returns to the last live pick. `subEffortTitle` gives Desktop the Claude Code default explanation; Codex's default meaning is unchanged. The gateway fits each attempt to its actual model and preserves fixed group-member efforts (see [gateway routing](gateway-routing.md)).
|
||||
- Claude Desktop picks its userData in its main process before any window opens: while a 3p configuration is applied and `deploymentMode` isn't `"1p"`, it is `Claude-3p` (Desktop 2.7032's `index.pre.js`, `app.setPath("userData", …-3p)`). So turning Desktop onto magpie shows none of the chats, projects and Code sessions of the Anthropic sign-in, which stay in `Claude` (xgddm88 on X: 之前的工程和会话记录全没了). magpie writes nothing in `Claude` but `deploymentMode` in its `claude_desktop_config.json`, and reads its `config.json` for the language; Off brings that history back. A row not yet connected says so before it is turned on (`CONNECT_BEFORE` in `app.js`), the opened row once it is on (`CONNECT_COST`), and the notice after each change (`noticeClaudedesktop3`, `noticeClaudedesktop4`; `TestClaudeDesktopKeepsTheSignedInHistory`, `desktop-history.test.cjs`). Opus beside the gateway's other models in that mode comes from a Claude subscription added in magpie. With `disableDeploymentModeChooser` unset Desktop's login screen would offer Claude.ai sign-in too; magpie still seeds it (as CC Switch does), so the way back is Off. The drift check asks Desktop's own question (`desktop3p`, `m4` in 4.4212's and 2.7032's `index.pre.js`): Desktop is off magpie only when Claude-3p's `deploymentMode` is `"1p"` and the applied profile leaves the chooser on. The `Claude` folder's `deploymentMode` isn't read, and Desktop 4.4212 deletes Claude-3p's itself (a stored `"1p"` with no claude.ai sign-in is dropped at start, `deploymentMode written { mode: undefined }`), so a missing one is still magpie (dev_quj on X; `TestClaudeDesktopModeAsDesktopReadsIt`).
|
||||
- Claude Desktop's 3p mode runs in a userData of its own (`Claude-3p`), whose `config.json` (Desktop's own settings, not `claude_desktop_config.json`) starts with no `locale`, so Desktop on magpie came up in the system's language rather than the one picked signed in with Anthropic (memory and Osal on Discord). Turning Desktop onto magpie copies that one key, `locale`, from the signed-in userData's `config.json` (`Claude`, `%APPDATA%\Claude` on Windows, the first set's before the others) into `Claude-3p/config.json` when that file is missing or a JSON object without one (`desktopCarryLocale` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)); only a name Desktop takes for a catalog is carried. A `locale` already in `Claude-3p`, Desktop's or set by hand, is never written over, and no other key of that file is ever written. Off removes the file only when magpie made it and it still holds nothing but the language carried (`TestClaudeDesktopCarriesTheLanguage`, `TestClaudeDesktopKeepsThe3pLanguage`, `TestClaudeDesktopUserEditsThenReapply`). Desktop shows the language only where its 3p window has that catalog: the window is Desktop's bundled UI (`Resources/ion-dist`, 11 catalogs and no Chinese in 2.7032, 2.9939, 3.6556.2 and 4.4212.0 (packed as `Resources/ion-dist.asar` there), while 3.6556.2's main process has `zh-Hans` and `zh-Hant` for the signed-in window). On every start that window asks the main process for its own pick (`requestLocaleChange`: its localStorage, else `navigator.languages` mapped onto its 11, else `en-US`), and the main process writes it into `Claude-3p/config.json`. So a Chinese `locale` there, carried or set by hand, is `en-US` again after each start, written by Desktop and not by magpie (Dx25 on Discord, Windows); nothing magpie writes can keep it. So the GUI says it to a Chinese reader: Claude Desktop's opened row on Agents has a line that Desktop on magpie is Anthropic's gateway window, with no Chinese, and that its Chinese comes back once disconnected, and the switch-on notice says the same in Chinese (GZXYMH on X, `desktop-lang.test.cjs`).
|
||||
|
||||
@@ -306,6 +306,7 @@ recorded as a prediction failure (`noPrediction`).
|
||||
- A request translated to a Chat or Responses upstream that carries no `prompt_cache_key` of the client's (every Anthropic client's) gets one for its conversation when the provider is OpenAI's API with a key or one the user added by its address (`ownCacheKey`, `cacheKeyOf` in [`gateway.go`](../../internal/gateway/gateway.go)): a hash, in a UUID's shape, of the session the client names, else of its first user message, so every turn of it has the same key and nothing in it names the client or magpie. A relay can turn a request away without one ("prompt_cache_key is required", CyberCaius's AnyRouter). A vendor's preset, a signed-in account, a plugin, Bedrock and Vertex get none, nor does a provider whose extraBody names `prompt_cache_key` (the user's value is sent). An upstream whose 400 names the field is asked again without it and not sent it again; another 400 is not asked again for it, so an unrelated refusal is tried as often as before.
|
||||
- Claude Desktop's check that a gateway model answers (`{"max_tokens":1,"messages":[{"role":"user","content":"."}]}`, sent as it starts and by its settings' Test connection on the shortest id it is listed with haiku in it, else sonnet, else opus, else the first model listed; `desktopProbe` in [`desktop.go`](../../internal/gateway/desktop.go)) goes to the model the user chose in one of Desktop's own model menus that magpie still serves (`desktopChosen`: `__model_selector_state` in Claude-3p's `local-agent-mode-sessions/<account>/<org>/cowork_account_settings.json`, in the order Code, Cowork, Chat; cybercaius's DeepSeek in the Code tab, v0.1.2033), unless a session's turn was sent after that file was last written: then the model that turn was for (`desktopPicked`), while magpie serves it, the newer of the two being what the user is on now (before, the last session's model came first whenever any menu still held it, so the Code tab switched off DeepSeek with Cowork left on it kept the check on DeepSeek, cybercaius on Discord, v0.1.2212), else to Desktop's default model, the first one listed to it (`desktopDefault`; Desktop's own settings call the first listed model the default), never to the haiku it names, which is another provider's quota, nor, with no menu chosen, to the model the last session ran on (`desktopPicked`), which can be days old: v0.1.1821 sent it there, a relay's GPT model CyberCaius had left for his routing group, and the relay turned it away (Discord, v0.1.1838). It is asked for 16 tokens upstream (`desktopProbeTokens`): OpenAI's models refuse fewer, and a relay in front of one (AnyRouter's "bad response status code 400") passes on no floor for `tokenFloor` to ask again at. A relay that needs `prompt_cache_key` gets one (above). It is recorded with kind `connection_check` (`KindDesktopCheck`), which the Routing page tags "Connection check" with why its model is the id Desktop named and not the one chosen in the conversation: a list with no Claude-named id made the row read "requested deepseek-flash" while the menu's gpt-6.1-sol answered (cybercaius on Discord, v0.1.2212). `TestClaudeDesktopProbeToDefaultModel`, `TestClaudeDesktopProbeToChosenModel`. `TestClaudeDesktopProbeAsksNoClassifier` checks the kind.
|
||||
- Claude Desktop's `/v1/models` tags a model with `anthropic_family_tier` only when the user picked it for that tier (`DesktopTiers`, the Agents page's opus, sonnet, haiku and fable). Before, a Claude model magpie served was tagged with its own tier unpicked, so Desktop's Code tab told Claude Code to run its haiku calls (its small, fast model) on whichever provider served a `claude-haiku-…`: a chat on AgentRouter's gpt-6.1-sol sent them to Leee's `claude-haiku-5-5` (cybercaius on Discord). Untagged, Claude Code asks for its own id of the tier. A background call (no tools) or a subagent's turn asking for a Claude model by Claude's own id that is no catalog id (`claudeOwnID`) stays on the chat's provider (`desktopPicked`), even when another provider serves a model of that name: `servedBeside` gives that provider's model of that name, else its newest model of the tier, beside the chat's model first, else the call goes to the chat's model. The provider's Claude models stand in only when the chat itself is on one of them: a chat on Leee's DeepSeek had Claude Code's sonnet calls sent to Leee's `claude-sonnet-5-5`, which its key may not use (403, CyberCaius on Discord), so Claude Code's own calls in a chat on another vendor's model go to the chat's model, and a tier the user picked takes Claude Code's own id of it even where a provider lists a model by that name (`TestClaudeDesktopNonClaudeChatKeepsTierCalls`). A lead's turn and an id the user picked for a tier (a catalog id) go as asked. `TestClaudeDesktopBackgroundStaysOnChatProvider`.
|
||||
- While a model is picked for one of Claude Desktop's tiers, magpie's Desktop profile also lists Desktop's models in `inferenceModels` (`DesktopInferenceModels` in [`desktop_list.go`](../../internal/gateway/desktop_list.go)), so a pick that isn't a Claude model runs in the Code tab with the prompt of its tier's newest Claude model (`behavesAs`: `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, `claude-fable-5-1`, Desktop's catalog v3739), not Claude Code's generic one (moer2831 on Discord). Desktop 4.29 and later hand Claude Code `behavesAs` only from that list (z3t in its app.asar, 4.4212: `modelPicker.options` with each entry's `behavesAs`); the gateway's `behaves_as` row field feeds Desktop's own effort profile only. A non-empty list replaces `/v1/models` in Desktop's menus (pzn: a discovered row gives only its name and description, by id), so the list is every row `/v1/models` gives Desktop, by its id and in its order, each with what Desktop would have read off the row: `supports1m` for a window of 1M and up, `prefer1m` (and the row's `display_name` as `labelOverride`, where Desktop names the row by display_name) for a model listed by its `[1m]` id, and a pick's `anthropicFamilyTier` with `isFamilyDefault`. A Claude model picked runs as itself. Nothing picked (or a pick of a model no longer listed): no list, and Desktop finds the models as before. Picks that can't be read are unknown, and what is written stays. Older builds take the entries' names and drop the rest (2.7032's entry is a zod object, which strips unknown keys). Desktop reads its profile only as it starts, so the tiers' menu says to restart it, and the Agents row's Restart shows (`AppBehind` reads the profile). `TestDesktopInferenceModels`.
|
||||
- Antigravity answers a system instruction holding one of a few lines with a 429 "Resource has been exhausted" whatever quota is left, on every model (`agTurnedAway` in [`codeassist.go`](../../internal/gateway/codeassist.go)): Claude Code's billing line, the Claude Agent SDK's identity line, Codex's identity lines for its GPT-5 models (which a Codex thread begun on a GPT model keeps after a switch), and Hermes Agent's earlier default persona. An Antigravity account's system instruction goes with a zero-width space after each such line's first letter (`antigravityCloak`, in `codeAssistBody`), which Google lets through and the model reads the same; every other provider, Gemini CLI's sign-in on the same envelope included, is sent the prompt as written. `magpie provider set antigravity prompt=as-written` (`Provider.PromptAsWritten`) turns it off. The refusal is still told against the system prompt as the agent wrote it (`antigravityTurnedAway`): a 400 with the hint for that prompt, the account not rested, and a group skipping Antigravity for that prompt for 6 hours after a refusal (`antigravityForeseen`).
|
||||
- Claude Code's advisor (`/advisor`, `--advisor`) is Anthropic's server tool `advisor_20260301`, its `model` named as Claude Code names its own: on magpie, by magpie's id (the tier an alias like `opus` is on), which no vendor knows, so the request was turned away whole (JackChou on Discord). Relayed on Messages (`passthrough`), the advisor's model goes as the upstream's own name for it when it is the same provider's Claude model, or a Claude id naming no provider (`advisorTools` in [`advisor.go`](../../internal/gateway/advisor.go)); one it can't run there (another provider's, a group, not Claude's) is left out, as is every advisor when the request's own model isn't a Claude model (a vendor's Messages API knows no such tool), and the turn is answered without one. A translation drops it with every other server tool. Claude Code (2.1.300) also puts the advisor in the conversation: a `{role: "system"}` message whose text ends in its instructions ("# Advisor Tool … call advisor BEFORE substantive work") and a `tool_addition` naming it. Where the advisor is left out, that `tool_addition` goes too (and a message it leaves empty), and the instructions become Claude Code's own "The advisor tool is no longer available; disregard the earlier advisor instructions." (`withoutAdvisor` on Messages, `advisorGoneIn` in `parseAnthropic` for a translation): left there, the model called `advisor()` as one of the agent's tools and Claude Code answered "No such tool available: advisor" (JackChou on Discord). The Claude subscription's run declares only magpie's tools, so it never has one. `TestAdvisorModelAsTheUpstreamNamesIt`, `TestAdvisorLeftOutOnTranslation`.
|
||||
- Kiro is told where to cache the prompt (plugins#110: a Kiro subscription read 0 from its cache). Its API takes Bedrock's `cachePoint: {"type":"default"}` on a `userInputMessage`, an `assistantResponseMessage` or as a tool entry. The built-in (`buildKiro` in [`kiro.go`](../../internal/gateway/kiro.go)) marks the first message when there is a system prompt, which it folds into that message, and the current message, as `buildAnthropic` marks Anthropic's. A moved Kiro's plugin (opencode-kiro-auth 0.1.10, the mover's `min`) turns each `cache_control` in the Anthropic body it is handed into one, at most 4, the last kept.
|
||||
|
||||
@@ -1231,9 +1231,10 @@ func claudeIn(at place) *Agent {
|
||||
var models []claudeBudget
|
||||
if desktopOn() {
|
||||
shown, _ := provider.CatalogFor("claude-desktop")
|
||||
behaves, _ := gateway.DesktopBehavesAs()
|
||||
for _, e := range shown {
|
||||
if id := gateway.DesktopID(e); claudeName(id) == "" {
|
||||
models = append(models, claudeBudget{id: id, window: e.Context, long: gateway.DesktopListed1M(e), compact: work(e.ID)})
|
||||
models = append(models, claudeBudget{id: id, window: e.Context, long: gateway.DesktopListed1M(e), compact: work(e.ID), behaves: behaves[id] != ""})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ type claudeBudget struct {
|
||||
// the auto-compact window magpie gives it: 0 for the top-level one
|
||||
// (base), below 0 for none, its whole window
|
||||
compact int
|
||||
// Claude Code runs it as a Claude model it knows (a Desktop tier's
|
||||
// pick, behavesAs: gateway.DesktopBehavesAs), and so at that model's
|
||||
// window, not at the one it is told: it always gets its own entry
|
||||
behaves bool
|
||||
}
|
||||
|
||||
// claudeLong is the window Claude Code takes a "[1m]" model for.
|
||||
@@ -109,7 +113,7 @@ func claudePlan(models []claudeBudget, base int, theirs map[string]string) (top
|
||||
if base > 0 {
|
||||
had = min(base, assumed)
|
||||
}
|
||||
if want == had {
|
||||
if want == had && !m.behaves {
|
||||
continue
|
||||
}
|
||||
id := strings.TrimSuffix(m.id, "[1m]")
|
||||
|
||||
@@ -61,6 +61,13 @@ func TestClaudePlan(t *testing.T) {
|
||||
if top != 1000000 || !reflect.DeepEqual(entries, map[string]int{"g": 272000}) {
|
||||
t.Fatalf("[1m] beside 272K: %d %v", top, entries)
|
||||
}
|
||||
// a Desktop tier's pick Claude Code runs as a Claude model
|
||||
// (behavesAs, moer2831) would run at that model's window: it is told
|
||||
// its own, even where it is the largest
|
||||
top, entries = claudePlan([]claudeBudget{{id: "a", window: 1000000}, {id: "b", window: 1000000, behaves: true}, {id: "c", window: 400000, behaves: true}}, 0, nil)
|
||||
if top != 1000000 || !reflect.DeepEqual(entries, map[string]int{"b": 1000000, "c": 400000}) {
|
||||
t.Fatalf("behavesAs: %d %v", top, entries)
|
||||
}
|
||||
// an id magpie's editor can't put in a key path gets no entry
|
||||
if _, entries = claudePlan([]claudeBudget{{id: "a", window: 400000}, {id: "b*", window: 100000}}, 0, nil); len(entries) != 0 {
|
||||
t.Fatalf("b*: %v", entries)
|
||||
|
||||
@@ -193,7 +193,7 @@ func claudeDesktop(home string) *Agent {
|
||||
return []Option{{Value: magpieID, Label: "magpie", Icon: "magpie",
|
||||
Note: "Desktop's third-party gateway: Code and Cowork on magpie's models, no Anthropic sign-in (restart Desktop)"}}
|
||||
},
|
||||
}}, append(desktopTierFields(ps), desktopSubagentField(ps), desktopSubagentEffortField(ps))...),
|
||||
}}, append(desktopTierFields(home, ps), desktopSubagentField(ps), desktopSubagentEffortField(ps))...),
|
||||
// a Desktop already on magpie gets the import policy too
|
||||
// (desktopSeedImport), and a profile for magpie's gateway it
|
||||
// applies a key the gateway takes (desktopKeyApplied)
|
||||
@@ -207,6 +207,11 @@ func claudeDesktop(home string) *Agent {
|
||||
if err := desktopKeyApplied(p); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
// the models and picks as they are now (a provider
|
||||
// saved or removed reaches it through SyncCatalog)
|
||||
if err := desktopSyncModels(p); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
// a Desktop on magpie from before the servers were
|
||||
// carried gets them once
|
||||
if stashShared()[desktopMCPSeen+p.key] == "" {
|
||||
@@ -361,8 +366,9 @@ func desktopKeyApplied(p desktopPaths) error {
|
||||
// on a Claude model, its provider's model of the tier: another provider's
|
||||
// Claude model, or a Claude model beside a chat on another vendor's, is
|
||||
// never used unpicked. Desktop reads them from the
|
||||
// gateway's /v1/models when it starts.
|
||||
func desktopTierFields(ps []desktopPaths) []Field {
|
||||
// gateway's /v1/models when it starts, and a pick's behavesAs from its
|
||||
// profile's inferenceModels (desktopSyncModels), also at start-up.
|
||||
func desktopTierFields(home string, ps []desktopPaths) []Field {
|
||||
var fields []Field
|
||||
for _, tier := range gateway.DesktopTierNames {
|
||||
fields = append(fields, Field{
|
||||
@@ -373,7 +379,22 @@ func desktopTierFields(ps []desktopPaths) []Field {
|
||||
if v != "" && !isMagpie(v) {
|
||||
return fmt.Errorf("%s: %q is not a model magpie serves", tier, v)
|
||||
}
|
||||
return gateway.SetDesktopTier(tier, v)
|
||||
if err := gateway.SetDesktopTier(tier, v); err != nil {
|
||||
return err
|
||||
}
|
||||
// the profile's list of models, whose behavesAs a pick
|
||||
// has, and the window the Code tab's Claude Code holds it
|
||||
// to (claudeBudget's behaves)
|
||||
var errs []error
|
||||
for _, p := range ps {
|
||||
if err := desktopSyncModels(p); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
if desktopWiredAny(ps) {
|
||||
_ = claude(home).Sync()
|
||||
}
|
||||
return joinErrs(errs)
|
||||
},
|
||||
Options: func(map[string]string) []Option {
|
||||
if !desktopWiredAny(ps) {
|
||||
@@ -525,7 +546,7 @@ const (
|
||||
desktopMCPSeen = "claude-desktop.mcp-seen"
|
||||
)
|
||||
|
||||
var desktopStashKeys = []string{desktopStashed, desktopMode, desktopMode3p, desktopApplied, desktopMade, desktopProfile, desktopLocale, desktopImport, desktopMCP, desktopMCPSeen}
|
||||
var desktopStashKeys = []string{desktopStashed, desktopMode, desktopMode3p, desktopApplied, desktopMade, desktopProfile, desktopLocale, desktopImport, desktopMCP, desktopMCPSeen, desktopModelsMark}
|
||||
|
||||
// desktopAdoptStash moves the stash a packaged Desktop's folders got
|
||||
// before they had keys of their own (when magpie wrote only one set) onto
|
||||
@@ -651,6 +672,10 @@ func desktopOn(p desktopPaths) error {
|
||||
if err := desktopCarryMCP(p); err != nil {
|
||||
return err
|
||||
}
|
||||
// a pick for a tier: the list its behavesAs goes in
|
||||
if err := desktopSyncModels(p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// the mode last: until here Desktop still starts as it did
|
||||
for _, f := range []string{p.config3p, p.config} {
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
|
||||
// While a model is picked for one of Claude Desktop's tiers, magpie's
|
||||
// profile carries inferenceModels (gateway.DesktopInferenceModels): the
|
||||
// list Desktop's Code tab hands Claude Code each pick's behavesAs from,
|
||||
// so a pick runs with the prompt of the Claude model of its tier
|
||||
// (moer2831). Without a pick there is none, and Desktop finds magpie's
|
||||
// models on its own as before. The list is magpie's only while it is what
|
||||
// magpie wrote: desktopModelsMark keeps the hash of each list magpie
|
||||
// wrote (the one before a write too, until the write is done), and a list
|
||||
// with any other hash is the user's, which magpie never writes over or
|
||||
// takes away. Desktop reads its profile at start-up only.
|
||||
const desktopModelsMark = "claude-desktop.models"
|
||||
|
||||
// desktopModelsHash is a list's hash, the same however it is spaced.
|
||||
func desktopModelsHash(raw []byte) string {
|
||||
var v any
|
||||
if json.Unmarshal(raw, &v) != nil {
|
||||
return ""
|
||||
}
|
||||
b, _ := json.Marshal(v)
|
||||
sum := sha256.Sum256(b)
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
// desktopSyncModels writes p's inferenceModels as magpie lists them now,
|
||||
// takes away the one magpie wrote when nothing is picked, and leaves the
|
||||
// user's own alone.
|
||||
func desktopSyncModels(p desktopPaths) error {
|
||||
if !desktopWired(p) {
|
||||
return nil
|
||||
}
|
||||
want, ok := gateway.DesktopInferenceModels()
|
||||
if !ok {
|
||||
return nil // the picks unknown: what is there stays
|
||||
}
|
||||
key := desktopModelsMark + p.key
|
||||
marks := strings.Fields(stashShared()[key])
|
||||
b, err := edit.Read(p.prof)
|
||||
if err != nil || b == nil {
|
||||
return err // no profile: desktopOn writes one, then this
|
||||
}
|
||||
raw, has := edit.GetJSONRaw(p.prof, "inferenceModels")
|
||||
if has && !slices.Contains(marks, desktopModelsHash([]byte(raw))) {
|
||||
return nil // the user's
|
||||
}
|
||||
if want == nil {
|
||||
if has {
|
||||
if err := edit.DelJSON(p.prof, "inferenceModels"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
forget(key)
|
||||
return nil
|
||||
}
|
||||
next, err := json.Marshal(want)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h := desktopModelsHash(next)
|
||||
if has && desktopModelsHash([]byte(raw)) == h {
|
||||
stash(map[string]string{key: h})
|
||||
return nil
|
||||
}
|
||||
// marked before it is written: a write cut short leaves a list magpie
|
||||
// still knows for its own
|
||||
stash(map[string]string{key: strings.Join(append(marks, h), " ")})
|
||||
if err := edit.SetJSON(p.prof, edit.KV{Path: "inferenceModels", Value: json.RawMessage(next)}); err != nil {
|
||||
return err
|
||||
}
|
||||
stash(map[string]string{key: h})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// moer2831 on Discord: a model picked for a Claude Desktop tier ran in its
|
||||
// Code tab on Claude Code's generic prompt. While a tier is picked,
|
||||
// magpie's profile lists Desktop's models in inferenceModels, the pick's
|
||||
// with behavesAs, and Claude Code is told the pick's window, since it
|
||||
// would take the behavesAs model's. The list follows the picks and the
|
||||
// catalog, is written only when it changes, goes when nothing is picked,
|
||||
// and a list the user wrote is theirs. Picks that can't be read leave it
|
||||
// as it is.
|
||||
func TestClaudeDesktopModelsList(t *testing.T) {
|
||||
home, p := desktopSandbox(t)
|
||||
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"a", "b"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := catalog.SaveLive("v", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "a", Context: 272000}, {ID: "b", Context: 128000}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cc := filepath.Join(home, ".claude", "settings.json")
|
||||
writeFile(t, cc, `{"theme":"dark"}`)
|
||||
d := claudeDesktop(home)
|
||||
set := func(key, v string) {
|
||||
t.Helper()
|
||||
if err := d.Field(key).Set(v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
id := func(ref string) string {
|
||||
for _, e := range provider.Catalog() {
|
||||
if e.ID == ref {
|
||||
return gateway.DesktopID(e)
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s not in the catalog", ref)
|
||||
return ""
|
||||
}
|
||||
list := func() []map[string]any {
|
||||
t.Helper()
|
||||
raw, ok := edit.GetJSONRaw(p.prof, "inferenceModels")
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
var out []map[string]any
|
||||
if err := json.Unmarshal([]byte(raw), &out); err != nil {
|
||||
t.Fatalf("%v: %s", err, raw)
|
||||
}
|
||||
return out
|
||||
}
|
||||
entry := func(ref string) map[string]any {
|
||||
t.Helper()
|
||||
for _, e := range list() {
|
||||
if e["name"] == id(ref) {
|
||||
return e
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s not listed: %v", ref, list())
|
||||
return nil
|
||||
}
|
||||
|
||||
set("provider", "magpie")
|
||||
if l := list(); l != nil {
|
||||
t.Fatalf("nothing picked: %v", l)
|
||||
}
|
||||
|
||||
// a's pick for sonnet: the list, a as Sonnet 5.5, and its window told
|
||||
set("sonnet", "v/a")
|
||||
if l := list(); len(l) != 2 {
|
||||
t.Fatalf("a for sonnet: %v", l)
|
||||
}
|
||||
if e := entry("v/a"); e["behavesAs"] != "claude-sonnet-5-5" || e["anthropicFamilyTier"] != "sonnet" {
|
||||
t.Fatalf("a: %v", e)
|
||||
}
|
||||
if e := entry("v/b"); e["behavesAs"] != nil {
|
||||
t.Fatalf("b unpicked: %v", e)
|
||||
}
|
||||
if v, _ := edit.GetJSON(cc, budgetPath(id("v/a"))); v != "272000" {
|
||||
t.Fatalf("a's window in Claude Code's settings: %q\n%s", v, readFile(cc))
|
||||
}
|
||||
|
||||
// unchanged: not written again
|
||||
st, _ := os.Stat(p.prof)
|
||||
old := st.ModTime().Add(-2 * time.Second)
|
||||
os.Chtimes(p.prof, old, old)
|
||||
if err := d.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if st, _ := os.Stat(p.prof); !st.ModTime().Equal(old) {
|
||||
t.Fatal("the profile was written with nothing changed")
|
||||
}
|
||||
|
||||
// a model added reaches the list with the catalog
|
||||
if err := provider.Save(provider.Provider{ID: "w", Name: "W", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"c"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := d.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if l := list(); len(l) != 3 {
|
||||
t.Fatalf("after w/c: %v", l)
|
||||
}
|
||||
|
||||
// picks that can't be read: the list stays
|
||||
tiers := filepath.Join(settings.Dir(), "claude-desktop.tiers.json")
|
||||
good, err := os.ReadFile(tiers)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeFile(t, tiers, `{"sonnet":`)
|
||||
if err := d.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if l := list(); len(l) != 3 {
|
||||
t.Fatalf("unreadable picks: %v", l)
|
||||
}
|
||||
writeFile(t, tiers, string(good))
|
||||
|
||||
// nothing picked: the list goes
|
||||
set("sonnet", "")
|
||||
if l := list(); l != nil {
|
||||
t.Fatalf("pick cleared: %v", l)
|
||||
}
|
||||
if _, ok := edit.GetJSONRaw(p.prof, "inferenceGatewayBaseUrl"); !ok {
|
||||
t.Fatal("the rest of the profile went with the list")
|
||||
}
|
||||
|
||||
// the user's own list is theirs, through a pick and its clearing
|
||||
set("haiku", "v/b")
|
||||
if err := edit.SetJSON(p.prof, edit.KV{Path: "inferenceModels", Value: []any{map[string]any{"name": "mine"}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mine, _ := edit.GetJSONRaw(p.prof, "inferenceModels")
|
||||
set("sonnet", "v/a")
|
||||
set("haiku", "")
|
||||
set("sonnet", "")
|
||||
if now, _ := edit.GetJSONRaw(p.prof, "inferenceModels"); now != mine {
|
||||
t.Fatalf("the user's list: %s, was %s", now, mine)
|
||||
}
|
||||
}
|
||||
@@ -227,13 +227,7 @@ func desktopModels(entries []provider.Entry, knowsMythos bool) []map[string]any
|
||||
// chat was on AgentRouter's gpt-6.1-sol (cybercaius on Discord).
|
||||
// Untagged, Claude Code asks for its own id of the tier, which
|
||||
// desktopTurn keeps on the chat's provider (servedBeside).
|
||||
picked := DesktopTiers()
|
||||
tierOf := map[string]string{}
|
||||
for _, t := range DesktopTierNames {
|
||||
if id := picked[t]; id != "" && tierOf[id] == "" {
|
||||
tierOf[id] = t
|
||||
}
|
||||
}
|
||||
tierOf := desktopTierOf(DesktopTiers())
|
||||
longest := settings.Load().DesktopLongest
|
||||
labels := provider.Labels(entries)
|
||||
data := make([]map[string]any, 0, len(entries))
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// A model the user picks for one of Claude Desktop's tiers is, for the
|
||||
// Code tab's Claude Code, a model it doesn't know: it runs it with its
|
||||
// generic prompt, not the one it has for the Claude model of that tier
|
||||
// (moer2831 on Discord: 通用提示词和对应模型提示词差距挺大的). Desktop
|
||||
// 4.29 and later take behavesAs, the Claude model whose prompt profile,
|
||||
// capability and effort defaults apply, only from the inferenceModels list
|
||||
// of a profile (models.list in its app.asar, 4.4212: z3t hands Claude Code
|
||||
// modelPicker.options with each entry's behavesAs; the gateway's
|
||||
// behaves_as feeds Desktop's own effort profile only). A list there
|
||||
// replaces the gateway's /v1/models in Desktop's menu (pzn: a discovered
|
||||
// row gives only its name and description, by id), so the list magpie
|
||||
// writes is the whole of what /v1/models gives Desktop, in its order, by
|
||||
// its ids, each with what Desktop would have read off the row: supports1m
|
||||
// for a window of 1M and up (and prefer1m for a model listed by its 1M id
|
||||
// alone), the tier of a pick. Older builds take the entries' names and
|
||||
// drop the rest (2.7032's entry is a zod object, which strips unknown
|
||||
// keys).
|
||||
|
||||
// desktopBehavesAs is the newest Claude model of each tier in Claude
|
||||
// Desktop's own model catalog (v3739), which Claude Code 2.1.316 knows.
|
||||
var desktopBehavesAs = map[string]string{
|
||||
"opus": "claude-opus-5-5",
|
||||
"sonnet": "claude-sonnet-5-5",
|
||||
"haiku": "claude-haiku-5-5",
|
||||
"fable": "claude-fable-5-1",
|
||||
}
|
||||
|
||||
// DesktopBehavesAs is the Claude model each picked tier's model runs as in
|
||||
// Desktop's Code tab, by the id Desktop hands Claude Code (DesktopID); a
|
||||
// model that is a Claude model itself has its own already. ok is false
|
||||
// when the picks can't be read.
|
||||
func DesktopBehavesAs() (as map[string]string, ok bool) {
|
||||
picked, ok := desktopTiersKnown()
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
tierOf := desktopTierOf(picked)
|
||||
shown, _ := provider.CatalogFor("claude-desktop")
|
||||
as = map[string]string{}
|
||||
for _, e := range shown {
|
||||
if t := tierOf[e.ID]; t != "" && claudeModel(e) == "" {
|
||||
as[DesktopID(e)] = desktopBehavesAs[t]
|
||||
}
|
||||
}
|
||||
return as, true
|
||||
}
|
||||
|
||||
// DesktopInferenceModels is the inferenceModels list magpie gives Claude
|
||||
// Desktop's profile: nil while no model it lists is picked for a tier,
|
||||
// when Desktop finds magpie's models on its own (/v1/models). ok is false
|
||||
// when the picks can't be read: whatever is written stays.
|
||||
func DesktopInferenceModels() (list []map[string]any, ok bool) {
|
||||
picked, ok := desktopTiersKnown()
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
tierOf := desktopTierOf(picked)
|
||||
shown, _ := provider.CatalogFor("claude-desktop")
|
||||
rows := desktopModels(shown, true)
|
||||
tagged := false
|
||||
for i, m := range rows {
|
||||
e := shown[i]
|
||||
id, _ := m["id"].(string)
|
||||
name, long := strings.CutSuffix(id, "[1m]")
|
||||
entry := map[string]any{"name": name}
|
||||
if long {
|
||||
entry["supports1m"], entry["prefer1m"] = true, true
|
||||
// Desktop names it by the id it looks up (name), which
|
||||
// /v1/models lists with "[1m]": the label it had there
|
||||
if DesktopNumber(e) == "" {
|
||||
entry["labelOverride"] = m["display_name"]
|
||||
}
|
||||
} else if e.Context >= desktop1M {
|
||||
entry["supports1m"] = true
|
||||
}
|
||||
if t := tierOf[e.ID]; t != "" {
|
||||
tagged = true
|
||||
entry["anthropicFamilyTier"], entry["isFamilyDefault"] = t, true
|
||||
if claudeModel(e) == "" {
|
||||
entry["behavesAs"] = desktopBehavesAs[t]
|
||||
}
|
||||
}
|
||||
list = append(list, entry)
|
||||
}
|
||||
if !tagged {
|
||||
return nil, true
|
||||
}
|
||||
return list, true
|
||||
}
|
||||
|
||||
// desktopTierOf is the tier each picked model is tagged with: a model
|
||||
// picked for two, the first (desktopModels).
|
||||
func desktopTierOf(picked map[string]string) map[string]string {
|
||||
tierOf := map[string]string{}
|
||||
for _, t := range DesktopTierNames {
|
||||
if id := picked[t]; id != "" && tierOf[id] == "" {
|
||||
tierOf[id] = t
|
||||
}
|
||||
}
|
||||
return tierOf
|
||||
}
|
||||
|
||||
// desktopTiersKnown is DesktopTiers, ok false when the file is there and
|
||||
// can't be read or parsed: no picks is something else than unknown picks.
|
||||
func desktopTiersKnown() (map[string]string, bool) {
|
||||
out := map[string]string{}
|
||||
b, err := os.ReadFile(desktopTiersPath())
|
||||
switch {
|
||||
case errors.Is(err, os.ErrNotExist):
|
||||
return out, true
|
||||
case err != nil:
|
||||
return nil, false
|
||||
}
|
||||
if json.Unmarshal(b, &out) != nil {
|
||||
return nil, false
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// moer2831 on Discord: a model picked for one of Claude Desktop's tiers ran
|
||||
// in its Code tab on Claude Code's generic prompt, not the one of the
|
||||
// Claude model of that tier ("直接蠢了一个度"). Desktop 4.29 hands Claude Code
|
||||
// behavesAs only from a profile's inferenceModels, so while a tier is
|
||||
// picked magpie lists Desktop's models there: every row /v1/models gives
|
||||
// Desktop, by its id and in its order, a pick tagged with its tier and
|
||||
// run as that tier's newest Claude model, a Claude model as itself.
|
||||
// Nothing picked, no list: Desktop finds the models on its own, as before.
|
||||
// Picks that can't be read are unknown, and leave what is written alone.
|
||||
func TestDesktopInferenceModels(t *testing.T) {
|
||||
setup(t, provider.Anthropic, &fake{})
|
||||
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Anthropic: "https://fake.example",
|
||||
Models: []string{"m1", "claude-sonnet-5", "m2"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, err := provider.Find("fake")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SetContext(*p, "m2", 1_000_000); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
served := func() []map[string]any {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest("GET", "/v1/models?limit=1000", nil)
|
||||
req.Header.Set("x-api-key", Token+"-claude-desktop")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 Claude/4.4212.0 Chrome/140")
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
var list struct {
|
||||
Data []map[string]any `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return list.Data
|
||||
}
|
||||
byName := func(list []map[string]any, id string) map[string]any {
|
||||
t.Helper()
|
||||
for _, e := range list {
|
||||
if e["name"] == id {
|
||||
return e
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s not listed: %v", id, list)
|
||||
return nil
|
||||
}
|
||||
ref := func(id string) string {
|
||||
for _, e := range provider.Catalog() {
|
||||
if e.ID == id {
|
||||
return DesktopID(e)
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s not in the catalog", id)
|
||||
return ""
|
||||
}
|
||||
|
||||
// nothing picked: no list
|
||||
if list, ok := DesktopInferenceModels(); !ok || list != nil {
|
||||
t.Fatalf("nothing picked: %v %v", list, ok)
|
||||
}
|
||||
|
||||
// m1 for sonnet, claude-sonnet-5 for haiku
|
||||
if err := SetDesktopTier("sonnet", "fake/m1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := SetDesktopTier("haiku", "fake/claude-sonnet-5"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
list, ok := DesktopInferenceModels()
|
||||
if !ok || list == nil {
|
||||
t.Fatalf("picked: %v %v", list, ok)
|
||||
}
|
||||
rows := served()
|
||||
if len(list) != len(rows) {
|
||||
t.Fatalf("%d entries for %d rows of /v1/models", len(list), len(rows))
|
||||
}
|
||||
for i, r := range rows {
|
||||
if want := strings.TrimSuffix(r["id"].(string), "[1m]"); list[i]["name"] != want {
|
||||
t.Fatalf("entry %d is %v, /v1/models has %s there", i, list[i]["name"], want)
|
||||
}
|
||||
}
|
||||
m1 := byName(list, ref("fake/m1"))
|
||||
if m1["behavesAs"] != "claude-sonnet-5-5" || m1["anthropicFamilyTier"] != "sonnet" || m1["isFamilyDefault"] != true {
|
||||
t.Fatalf("m1 for sonnet: %v", m1)
|
||||
}
|
||||
claude := byName(list, ref("fake/claude-sonnet-5"))
|
||||
if _, has := claude["behavesAs"]; has || claude["anthropicFamilyTier"] != "haiku" {
|
||||
t.Fatalf("a Claude model for haiku runs as itself: %v", claude)
|
||||
}
|
||||
m2 := byName(list, ref("fake/m2"))
|
||||
if _, has := m2["behavesAs"]; has || m2["anthropicFamilyTier"] != nil || m2["supports1m"] != true || m2["prefer1m"] != nil {
|
||||
t.Fatalf("m2, 1M, unpicked: %v", m2)
|
||||
}
|
||||
if as, ok := DesktopBehavesAs(); !ok || len(as) != 1 || as[ref("fake/m1")] != "claude-sonnet-5-5" {
|
||||
t.Fatalf("behaves as: %v %v", as, ok)
|
||||
}
|
||||
|
||||
// listed by its 1M id: named by it without the suffix, which Desktop
|
||||
// adds back, and labelled as /v1/models labels it
|
||||
s := settings.Load()
|
||||
s.DesktopLongest = true
|
||||
if err := settings.Save(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
list, _ = DesktopInferenceModels()
|
||||
m2 = byName(list, ref("fake/m2"))
|
||||
var shown string
|
||||
for _, r := range served() {
|
||||
if r["id"] == ref("fake/m2")+"[1m]" {
|
||||
shown, _ = r["display_name"].(string)
|
||||
}
|
||||
}
|
||||
if shown == "" || m2["supports1m"] != true || m2["prefer1m"] != true || m2["labelOverride"] != shown {
|
||||
t.Fatalf("m2 by its [1m] id (%q): %v", shown, m2)
|
||||
}
|
||||
|
||||
// a pick of a model no longer listed is no pick
|
||||
if err := SetDesktopTier("sonnet", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Anthropic: "https://fake.example",
|
||||
Models: []string{"m1", "m2"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if list, ok := DesktopInferenceModels(); !ok || list != nil {
|
||||
t.Fatalf("haiku's model gone: %v %v", list, ok)
|
||||
}
|
||||
|
||||
// picks that don't parse are unknown
|
||||
if err := os.WriteFile(desktopTiersPath(), []byte(`{"sonnet":`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if list, ok := DesktopInferenceModels(); ok || list != nil {
|
||||
t.Fatalf("unreadable picks: %v %v", list, ok)
|
||||
}
|
||||
if _, ok := DesktopBehavesAs(); ok {
|
||||
t.Fatal("unreadable picks read as known")
|
||||
}
|
||||
}
|
||||
@@ -2379,6 +2379,7 @@ body .foot .status.lift { white-space: normal; overflow-wrap: anywhere; text-ove
|
||||
offered, and what to do, below the choices */
|
||||
.pop li.kept, .pop.model-picker li.kept { height: auto; align-items: flex-start; padding: 8px; margin-top: 3px; border-top: 1px solid var(--line); border-radius: 0; white-space: normal; cursor: default; }
|
||||
.pop li.kept .ic { margin-top: 1px; flex: none; }
|
||||
.pop li.menu-foot { height: auto; padding: 8px; margin-top: 3px; border-top: 1px solid var(--line); border-radius: 0; white-space: normal; cursor: default; font-size: 11.5px; line-height: 1.45; color: var(--muted); }
|
||||
.pop li.kept .kept-words { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; font-size: 11.5px; line-height: 1.45; color: var(--muted); }
|
||||
.pop li.kept .kept-words b { color: var(--fg); font-weight: 500; font-size: 12.5px; }
|
||||
.pop li.kept .text.action { flex: none; align-self: center; height: 25px; }
|
||||
|
||||
@@ -4162,6 +4162,9 @@ function tierMenu(a) {
|
||||
const name = (f) => optionFor(f, f.value)?.label || f.value;
|
||||
return {
|
||||
key: "tiers", label: omp ? "roles" : "tiers", value: "", menu: true, custom: custom.length > 0,
|
||||
// Desktop reads magpie's list of its models, a pick's prompt with it,
|
||||
// only as it starts
|
||||
foot: a.id === "claude-desktop" ? DESKTOP_TIERS_FOOT : "",
|
||||
summary: custom.length ? custom.map((f) => level(effortOf(f)) ? `${t(f.label)} (${level(effortOf(f))})` : t(f.label)).join(", ") : main ? t("same as model") : t("not set"),
|
||||
options: tiers.flatMap((f) => {
|
||||
const model = {
|
||||
@@ -4174,6 +4177,8 @@ function tierMenu(a) {
|
||||
};
|
||||
}
|
||||
|
||||
const DESKTOP_TIERS_FOOT = "Claude Desktop reads the tiers as it starts: restart it after a change.";
|
||||
|
||||
// levelUnset: what a role's level is when none is set
|
||||
const levelUnset = (a) => ompAgent(a) ? t("the session's thinking level") : t("the effort Claude Code asks for");
|
||||
|
||||
@@ -5454,6 +5459,7 @@ function renderList() {
|
||||
list.append(li);
|
||||
});
|
||||
for (const m of pick.kept || []) list.append(keptNote(m));
|
||||
if (pick.field.foot) list.append(el("li", "menu-foot", t(pick.field.foot)));
|
||||
list.querySelector(`li[data-i="${pick.cursor}"]`)?.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
|
||||
|
||||
@@ -815,6 +815,7 @@ const I18N = {
|
||||
"haiku effort": "haiku 推理强度",
|
||||
"fable effort": "fable 推理强度",
|
||||
"the effort Claude Code asks for": "跟随 Claude Code 请求的推理强度",
|
||||
"Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop 在启动时读取分档:改动后请重启它。",
|
||||
"Set a subagent model first": "先设置子代理模型",
|
||||
"the session's effort, or the subagent model's own default": "跟随会话的推理强度,或子代理模型的默认强度",
|
||||
"slow": "慢模型",
|
||||
@@ -5263,6 +5264,7 @@ const I18N = {
|
||||
"haiku effort": "haiku 推理強度",
|
||||
"fable effort": "fable 推理強度",
|
||||
"the effort Claude Code asks for": "跟隨 Claude Code 請求的推理強度",
|
||||
"Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop 在啟動時讀取分檔:改動後請重新啟動它。",
|
||||
"Set a subagent model first": "先設定子代理模型",
|
||||
"the session's effort, or the subagent model's own default": "跟隨會話的推理強度,或子代理模型的預設強度",
|
||||
"slow": "慢模型",
|
||||
@@ -9676,6 +9678,7 @@ const I18N = {
|
||||
"haiku effort": "haiku の推論レベル",
|
||||
"fable effort": "fable の推論レベル",
|
||||
"the effort Claude Code asks for": "Claude Code が要求する推論レベル",
|
||||
"Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop は起動時に階層を読み込みます。変更したら再起動してください。",
|
||||
"Set a subagent model first": "先にサブエージェントのモデルを設定してください",
|
||||
"the session's effort, or the subagent model's own default": "セッションの推論レベル、またはサブエージェントのモデル自身のデフォルト",
|
||||
"slow": "低速",
|
||||
@@ -14107,6 +14110,7 @@ const I18N = {
|
||||
"haiku effort": "Reasoning-Effort haiku",
|
||||
"fable effort": "Reasoning-Effort fable",
|
||||
"the effort Claude Code asks for": "der von Claude Code angeforderte Reasoning-Effort",
|
||||
"Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop liest die Stufen beim Start: nach einer Änderung neu starten.",
|
||||
"Set a subagent model first": "Lege zuerst ein Modell für die Subagenten fest",
|
||||
"the session's effort, or the subagent model's own default": "der Reasoning-Effort der Sitzung oder der Standard des Subagent-Modells",
|
||||
"slow": "langsam",
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
// no model field here for them to follow: the tiers' square says what an
|
||||
// unset one runs on instead, and its picker's reset entry is "Not set", not
|
||||
// "Same as model". Connected to magpie, the square is in the row opened from
|
||||
// its link. In English and Chinese. No backend: the API is faked here.
|
||||
// its link. Desktop reads the tiers (and magpie's list of its models, a
|
||||
// pick's behavesAs with it, moer2831) only as it starts, so the tiers' menu
|
||||
// ends with one line saying so. In English and Chinese. No backend: the
|
||||
// API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -52,8 +55,8 @@ function server(lang, sets) {
|
||||
}
|
||||
|
||||
const W = {
|
||||
en: { unset: "the chat's model; for a Claude chat, its provider's model of the tier", reset: "Not set", summary: "tiers: haiku" },
|
||||
zh: { unset: "对话的模型;对话用 Claude 模型时,用其供应商的该档位模型", reset: "未设置", summary: "分档:haiku" },
|
||||
en: { unset: "the chat's model; for a Claude chat, its provider's model of the tier", reset: "Not set", summary: "tiers: haiku", foot: "Claude Desktop reads the tiers as it starts: restart it after a change." },
|
||||
zh: { unset: "对话的模型;对话用 Claude 模型时,用其供应商的该档位模型", reset: "未设置", summary: "分档:haiku", foot: "Claude Desktop 在启动时读取分档:改动后请重启它。" },
|
||||
};
|
||||
|
||||
const cd = '.row.agent[data-id="claude-desktop"]';
|
||||
@@ -80,10 +83,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const y = await page.evaluate(() => scrollY);
|
||||
await square.click();
|
||||
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
|
||||
const rows = await page.locator("#list li").evaluateAll((es) => es.map((e) => [e.querySelector(".v")?.textContent, e.querySelector(".n")?.textContent || ""]));
|
||||
const rows = await page.locator("#list li[data-i]").evaluateAll((es) => es.map((e) => [e.querySelector(".v")?.textContent, e.querySelector(".n")?.textContent || ""]));
|
||||
assert.deepEqual(rows.map((r) => r[0]), tiers);
|
||||
assert.equal(rows[0][1], w.unset);
|
||||
assert.equal(rows[2][1], "Flash");
|
||||
// the restart line, last, whole and not a choice
|
||||
const foot = await page.locator("#list li").last().evaluate((e) => ({ cls: e.className, text: e.textContent, i: e.dataset.i, cut: e.scrollWidth > e.clientWidth }));
|
||||
assert.deepEqual(foot, { cls: "menu-foot", text: w.foot, i: undefined, cut: false });
|
||||
|
||||
// sonnet's picker: the reset entry, then magpie's models; GLM picked
|
||||
await page.locator("#list li").nth(1).click();
|
||||
|
||||
Reference in New Issue
Block a user