35aa50cfb33a427681841ca2eb366b0cda5ebdc7
182
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
4ac4d9ba99 |
plugins: the gateway's middleware point; JS middleware and privacy masking are built-in plugins, masking fails closed (P3)
P3's third point (docs/subsystems/plugin-runtime.md). internal/gwmw has two
places, each with its own failure policy:
- Agent: a middleware on an agent's request in its own API and on its reply.
serveAgent runs each registered one. The JS gateway middleware is the one
there (middleware.Chain), registered by the new built-in plugin
`middleware`. Its place, API, limits and fail-open are unchanged. InUse is
middleware.On(). Off, no middleware runs.
- Masker: what goes to a vendor, masked, and the values back in what comes
back. The new built-in plugin `redact` serves masking.Masker (in
internal/masking, since settings imports redact). InUse is masking.Wanted.
It fails closed: masking asked for with no masker serving, or a masker that
panics, is a 503 "nothing was sent" at every call site that masked before
(serve, count_tokens, embeddings and audio, transcriptions, images, video,
search stand-ins and their queries, the Codex backend).
With no masker, or with no agent middleware while plugins.json has one on,
the gateway asks pluginrt.Refresh, at most once a second. A setting or
middleware added a moment ago serves the request that needs it.
pluginrt.KeepFresh also watches plugins.json now.
Run (on origin/main
|
||
|
|
b1d02fa612 |
groups: the user's own routing groups are the groups plugin's, served only while it is on (P3 router strategy)
The groups plugin now owns the user's own routing groups at the router strategy point. The groups magpie finds (auto-<model>, one model several providers serve) stay core, as Smart does: a new install has groups off under Essentials, and taking those would silently drop cross-provider failover. planGroup and the walk over a group's members stay core too. - provider.GateGroups / ServeGroups (group_serve.go): the gateway holds the gate while it serves; the plugin holds ServeGroups while on. Gated with none served, groupsIn drops every group not Auto, so FindGroup, GroupFor, the catalog and /v1/models go without them. The CLI and TUI are never gated. Nothing derived from groups is cached past a call, so a flip is seen by the next lookup. - Gated and off, a lookup that finds a user group asks the gate's refresh (pluginrt.Refresh in the gateway) at most once a second, never re-entrantly, then looks again. Without this, `magpie group add` was 404 for up to 2s until KeepFresh turned the plugin on (seen in the sandbox). - plugins/groups and plugins/routing: InUse is provider.NamedGroups, the file's non-Auto, non-hidden groups read past the gate; an unreadable providers.json is an error, so the plugin stays on. Run before rebasing onto |
||
|
|
af9bd6c3e2 |
gateway, routes, plugins: the routings besides Smart are the rotation plugin's, on the gateway's router strategy point (P3)
The second P3 extension point (docs/subsystems/plugin-runtime.md). A
router strategy orders one pool of routes: a provider's accounts or keys,
or the heads of a group's members. The gateway still lists the pool and
keeps rests, affinity, rules, pins and failover; a strategy only orders.
- internal/routes: Seat, Strategy{Order, Exact, ByUse}, Register (stacks,
the last serves), Find, Served, and Apply, which fails open: a strategy
that panics or answers what isn't a permutation leaves the pool in its
listed order, logged. Smart is the core's; Ordered, Rotate, LeastUsed,
Pace and Weighted are routes.Builtin, moved out of the gateway with the
rotate turns and the smooth weighted round (Round, MoveRound, Forget).
- plugins/rotation (Essential): registers routes.Builtin. InUse counts the
providers and groups providers.json routes by one of them
(provider.Routings), an unreadable file is an error, so it stays on. The
gateway's KeepFresh watches providers.json too.
- Off, a routing no strategy serves is its listed order, and routingOf
reads it as "order" wherever the core asks (a turn's mark, sinks, a
rotate group's sessions, a group's heads, weightedKept).
- GUI: the routing pickers (provider editor, Routing page pools and group
editor) mark the five as data-feature="rotation" (routingSegs), so off
they offer Smart alone. i18n zh, zh-TW, ja, de.
- Docs: plugin-runtime.md router strategy section, gateway-routing.md
(also drops a duplicated sentence about a lone key), reference.md.
Run in the worktree at this change (on origin/main
|
||
|
|
c3bef99efd |
provider: magpie://import links take gemini=, and its host is named before adding (#2251, ggbdpq)
An import link could set chat=, responses= and anthropic= but not
gemini=, though the editor and the TUI take a Gemini base URL; a link
with only gemini= failed with "it needs chat=, responses= or anthropic=".
ParseImport now reads gemini= under the same base-URL rules, and the
error names it (ggbdpq's patch, with docs/reference.md and the en/zh
docs rows).
Its siblings that listed the three base URLs:
- the GUI's import dialog warned "Your prompts and this key will go to ;"
with no host for a gemini-only link: it names the Gemini host now;
- the site's handoff page (site/public/import.html) left it out of
"Sends to";
- the docs' link builder (en, zh, ja) had no Gemini field and didn't
count it as a base URL; the ja docs lacked the table row, and all
three said one of chat/responses/anthropic is required.
Run:
- TestParseImportGemini fails on the old importurl.go ("the link gives
no base URL: it needs chat=, responses= or anthropic="), passes now;
go test -run Import ./internal/provider/ ./internal/gui/: ok.
- import-link-gemini.test.cjs: 20/20 (chromium+webkit, en/zh/zh-TW/ja/de,
1100 and 420 px); against the old app.js the warning reads "will go to
;" and it fails.
- docs builder (en/zh/ja) and handoff page in Chromium from file://: a
gemini-only builder gives magpie://import?name=…&gemini=…, no errors;
the handoff page lists gem.example under Sends to.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
Not tried: a real magpie://import click through the OS handler.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
|
||
|
|
9916a94608 |
gateway, usage, plugins: OTel export is the first plugin on the gateway's observer point (P3)
P3 of docs/subsystems/plugin-runtime.md opens the gateway to plugins. The
observer point is first: it only reads, so it carries the least risk.
With plugins/otel off, the gateway exports nothing and does no observing
work. It keeps no reply whole and adds no request context.
- usage.Observer:
- Methods: Serve, Bodies, Begin(Request) Watch and Ledger(Record). Watch
has Attempt and End.
- Observe(o) registers an observer until its remove is called.
- ServeObservers is counted, and only Server.ListenAndServe calls it.
- ObservedBodies takes the most any observer wants.
- Record.SkipOTel becomes Watched, set by appendUsage for a request an
observer watched.
- The gateway's otel.go becomes observe.go:
- observeRequest asks each observer through Begin.
- attempt and end call each Watch. Bodies are added only when an
observer asks for them, and the whole reply only for WholeBodies.
- internal/otlp: the exporter (otel*.go) moves out of internal/usage, and
the gateway's per-request span state moves into request.go. otlp.New()
is an Exporter, a usage.Observer. What it sends is unchanged.
- plugins/otel:
- Apply registers otlp.New() and disposes of it when turned off.
- InUse is 1 while settings.OTelExport says to send. A user who exports
only through MAGPIE_OTEL_* keeps the plugin on under Essentials.
- pluginrt.KeepFresh: the process serving the gateway refreshes every 2s
when plugins.yml or settings.json changes. A switch made in the window or
the CLI reaches a running gateway, or a headless serve, without a restart.
- docs: plugin-runtime.md gets a P3 section, a gateway runtime path and an
updated failure section; reference.md says the export is the otel plugin.
Run at this tree on origin/main
|
||
|
|
b476dc5a93 |
agent, gateway, gui: Claude Desktop's subagents can have a reasoning effort of their own
After #2081 gave Desktop a subagent model, its effort still came from the request. Add subagent_effort beside that model, using the existing effort slider. The live setting DesktopSubagentEffort belongs to magpie; no Claude client file or binary is changed. Empty preserves the request's effort, including disabled thinking. A pick applies only to Desktop requests with an agent id and tools, independently of model replacement: unset, equal and unavailable model picks all work. Reuse the attempt-level fitting; fixed group-member efforts and reasonless models keep their existing precedence. count_tokens applies the pick after unmasked-body restoration. A Codex SubagentPick is not evidence of a Desktop tool turn. Route.Effort keeps the incoming level, SubagentEffort records the configured pick, and tries/usage keep the actual level. Routing explains the pick even without a model replacement. Options follow the target model; a saved level survives a model change. POST /api/settings preserves it. Disconnected preferences, Disconnect/reconnect and restored settings work; a Live pick gives restart advice only when it actually connects the agent. Codex's own settings and default-effort explanation are unchanged. Verification on |
||
|
|
7c5bfd7a1d |
gateway: auto affinity keeps a conversation where a vendor's cache is kept without saying so (#2230, JasonBuildAI)
A vendor that keeps the prompt cached by itself and reports nothing of it —
OpenAI's automatic prefix cache, Gemini — says neither a read nor a write of
the turn that built the cache. affine judged that turn's stick by what the
reply read and wrote (0 + 0), found it under cacheWorth and moved the
conversation's second turn as "no-cache": the whole prompt went afresh to
another key or account and was paid for in full, on every turn after the
first, for anyone with more than one key or account and Affinity auto (the
default).
7f968b95b named this as not covered: "a vendor that caches without reporting
a write (OpenAI's automatic prefix cache, Gemini) still reports CacheWrite 0
on a first turn, so its second turn may still move".
What such a vendor holds of the conversation after a turn is the prompt that
turn was sent, which is what its cache now has. answered takes the reply's
usage rather than its two cache counts, and where the reply reports neither
a read nor a write, the prompt it was sent (Input) stands for the write: the
second turn stays to read it, as it does for a turn that wrote its cache. A
reply that reports no usage at all (Input 0) counts as no cache, as before,
and a prompt under cacheWorth (1024) still moves. A read or a write the
vendor does report is used as it was, and resting, spent, cold, strict, turn
and rotate are judged before this, so nothing else changes.
The observable change: with Affinity auto, a conversation whose last reply
reported neither a cache read nor a cache write, and was sent at least 1024
tokens, is kept where it was (Why "cache", Kept true) rather than moved
(Why "no-cache"). Its stick, affinity.json and the trace's
Affinity.CacheWrite carry the prompt sent, and Affinity.CacheRead stays 0,
which is what the Routing page shows as read and written; the page itself is
unchanged.
Tests:
- affinity_silent_cache_test.go (new): TestAffinityKeepsACacheTheVendorKept
Silently. Two keys, least-used routing, and a Chat vendor reporting
prompt_tokens 3000 with cached_tokens 0 — what OpenAI and Gemini send of a
first turn — keeps the second turn on k1 as "cache", with the trace
telling CacheRead 0 and CacheWrite 3000; a vendor reporting no usage at
all still moves to k2 as "no-cache".
- TestAffinityKeepsACacheJustWritten, its "too little either way" (300/300,
no-cache) case included, passes as it did.
Run:
- go test -tags nogui -count=1 -run TestAffinity ./internal/gateway: ok,
80.982s (TestAffinity 39.36s, TestAffinityKeepsACacheJustWritten 26.54s,
TestAffinityKeepsACacheTheVendorKeptSilently 9.68s).
- go test -tags nogui -count=1 -timeout 45m ./...: every package passes
except 21 tests red on this Windows machine — agent 4
(TestInstallWithoutNodeParses, TestWSLClaudeFollowerOnTheMainModelIsNoDrift,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
TestQoderSettingsFromAnIDEPluginIsNotTheCLI), gui 4
(TestGatewayHeldByAContainer, TestGatewayFixQuitsOnlyAMagpie,
TestFXStateDoesNotWait, TestUpdateThatWontStart), library 3
(TestAgentsSkillsFolders, TestRemoveFoundSkill,
TestHooksCodexTrustMovesWithTheGroups), gateway 2 (TestClaudeAsRootEnv,
TestSweepBridgeProjectsTakesOnlyTheBridgesFolders) and one each in backup,
davsync, pluginrt, provider, sessions, update and usage. A fresh worktree
at the base
|
||
|
|
3d3a834d62 |
gateway: a held key its owner lets see quotas is told those of the providers and accounts it may use, not none (#2216, Kenoia)
#1981 refused every quota route to a gateway key held to a budget, models
or accounts, so a Remote magpie set up with such a key showed none of the
providers it may use. A key's owner can now let it be told them:
access.Key.Quotas, set from the key's new "Quotas" badge on the Gateway
page or `magpie gateway-key quotas <id> on|off`. Off stays the default,
so #1981's answer is unchanged for every key until its owner says so.
With it on, /v1/magpie/quotas (and ?kept=1), /quotas/history,
/quotas/cards and POST /quotas/refresh go through scopeQuotas
(internal/gateway/quotas_scope.go):
- a provider is told only when the key may use every model the catalog
lists of it: a key with some of a provider's models is told nothing of
it, since the models it may not use spend the same quota;
- of those, only cards of accounts and keys AllowsAccount lets it use,
matched by the card's User against AccountIDs (a name two accounts
share needs both; a card no account is known by only where the key's
list names none of that provider's); a provider's only key's card,
named by no one, is that key's;
- cards read from another magpie (From) are never told;
- a refresh of a card outside the scope is 403 gateway_key_held, one
naming no card reads again only the scope's cards, not ReadAllCards;
- a scope with no card answers the cards routes 403 gateway_key_held, so
the remote shows the key's own card rather than "nothing read".
/v1/magpie/concurrency and /v1/magpie/usage still refuse a held key.
Run at the reviewed head:
- gofmt -l: clean; go vet ./... (darwin), GOOS=linux -tags nogui,
GOOS=windows: clean.
- go test -tags nogui -timeout 45m ./... in a sandbox HOME, after the
rebase onto
|
||
|
|
f299faef48 |
gateway keys: a key holds several limits at once, every one must pass, and the 429 names the one that resets last (#2227, oxsean)
A key may now hold up to five limits, each in its own window (5 hours
and a week, say). A request needs every one: budget.Reserve checks
each, holds one reservation per window and settles each, and when some
are spent refuses with the spent limit that resets last, so
X-Magpie-Limit-Reset and Retry-After say when the key is really back.
Two limits in one window are refused (change that one instead).
Saved format: the first limit stays in "limit", which older magpie
reads, the rest go in "moreLimits". A file without moreLimits reads as
before.
- access: Change.Index adds (index = len), replaces (keeps its Since)
or removes (nil) one limit; reset-limit-key with an index resets one,
without resets all; the plain limit-key replaces all, as before.
- /v1/magpie/limit: "limit" is the binding one (what older clients
read), "limits" is each. A remote key card shows a window per cap of
each limit and falls back to "limit" from an older remote.
- CLI: magpie gateway-key limit <id> list | add <period> ... |
remove <n> | reset [<n>]; the single-limit form still replaces all.
- GUI: the key's badge names the limit holding it most and "+N limit(s)",
a line per limit under the row, and the editor has a tab per limit
with Add a limit / Remove this limit. Strings in en, zh, zh-TW, ja, de.
- docs/reference.md and docs/subsystems/gateway-routing.md say so.
Run (worktree on
|
||
|
|
27a0458de1 |
gateway: /v1/magpie/concurrency lists each request in flight, its agent, model, start and phase, for a status bar's hover (#2132, bigbitbox)
The concurrency read now carries `active` beside requests/waiting/tools:
one entry per agent request counted for Busy, oldest first, [] when idle:
id, agent, model and provider (once routed, from the routing trace),
session when the agent sends one, started and ms, route (the trace id),
and phase only where the gateway knows it: "slot" waiting in a key's or
account's queue, "rpm" waiting for room in the minute, "upstream" while a
try is out at the vendor. No prompt, reply or key. The entry lives on the
request's context from `counted` (so a GET, this poll included, is never
listed), routing ties it to its first route in trace.beginFor, and
lanes.take / rpms.wait / the try loop note the phase, putting the one
before back when they return. Access is the endpoint's: this machine,
another with a gateway key, never a held key (TestHeldKeyToldNoAccounts).
Nothing in routing or limits reads it.
Run (worktree on
|
||
|
|
7f968b95dd |
gateway: auto affinity keeps a conversation on the cache its last reply wrote, not only one it read (vilicvane on Discord)
Affinity's auto mode kept a conversation on its last answerer across turns only while that reply had read at least cacheWorth (1024) tokens from the vendor's cache. A first turn reads nothing and writes the whole prompt (Anthropic's cache_creation_input_tokens), so the second turn was moved as "no-cache" and the cache just built was thrown away (vilicvane on Discord, 「会话保持 → 自动」: 「新的 cache 都建好了,再切走不可惜吗?」). answered() is now given the usage's CacheWrite beside CacheRead (both already parsed at that call site for every route: Anthropic, Chat's cache_write_tokens / cache_creation_input_tokens, Cursor, Command Code, plugins), and affine counts read + written against cacheWorth. The stick keeps cacheWrite in memory and in affinity.json (`cacheWrite`, omitempty); a file from before has no such field and reads as 0, so an old stick is judged by its read alone, as before. The trace's Affinity carries CacheWrite, and the Routing page's "cache" and "no-cache" explanations say what was read and what was written (en, zh, zh-TW, ja, de). Not covered: a vendor that caches without reporting a write (OpenAI's automatic prefix cache, Gemini) still reports CacheWrite 0 on a first turn, so its second turn may still move. Noted in gateway-routing.md. Docs: docs/subsystems/gateway-routing.md (affinity bullet), docs/reference.md (step 6 of how magpie picks an account). Run: - TestAffinityKeepsACacheJustWritten (new): an Anthropic Messages upstream streaming cache_creation_input_tokens 3000 / read 0; the second turn is kept as "cache", also across a restart (affinity.json reloaded); 600+600 is kept, 300+300 moves as "no-cache". Broken by hand twice and watched red: the old `st.cacheRead < cacheWorth` (written: why no-cache), and stickOf not reading CacheWrite from the file (restarted: no-cache). - routing-affinity-cache-write.test.cjs (new): chromium and webkit, 1100 and 420 wide, en/zh/zh-TW/ja/de, 20/20 pass; red on the old routing.js and i18n.js. i18n-keys.test.cjs and routing-account-identity.test.cjs pass. - gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows for internal/gateway. - go test ./internal/gateway/...: all pass except TestAgentGoneInTheRetryPause/group_replan, which failed in two full runs at load average 150-380 and passes alone (-count=3); its fixed 100ms sleep before cancelling assumes the pause has begun. Filed as #2175; it never reaches the affinity path this changes (a first request). - go test -timeout 40m ./... at load ~300-377: 50 packages ok; agent and gateway hit the 40m package timeout (no test failed before it); gui's TestSetAnswersWhileDevinAndProvidersHang (#1375) and TestMainWindowCorners (#1936) failed, both filed load reds. internal/agent rerun alone: ok (1008s at load ~200). - Not tried against a real Anthropic account. |
||
|
|
22512cde53 |
provider, gateway: rest-cap off never rests a provider's keys after an unknown failure (Kismet Alan on Discord)
A relay or account pool fails now and then with errors that say nothing
of why (a 5xx, a dropped connection), and the next request often goes
through. Every such failure rested the key or account a minute, doubling
up to 10, and `rest-cap` could only move that cap (1 minute at least;
`off` read as `default`).
`magpie provider rest-cap <id> off` (provider.RestCapOff, restCap: -1 in
providers.json) now has a failure that says nothing of why (failOther)
rest nobody and not count toward the backoff: restAfterMarked returns a
Rest by "off" with no time left. What says why still rests as before: a
401 or 403, a model not served (restID), an account's window full, a
rate limit (magpie's own 30-minute cap; RestCapOr treats off as unset),
quota, credit, a restriction. `rest-cap <id> 30s` is turned away and names
1m and off (the first rest is a minute already). The Routing page tells a
try rested by "off" as not resting (one new string, zh/zh-TW/ja/de).
No "fail N times before switching" counter: a failed try already moves
the same request on to the next key or member, so a count would only
keep requests on a failing upstream longer.
Run:
- TestRestCapOff (gateway), TestRestCapCmd (cli), TestOwnRestCap: pass;
each goes red with the change taken out by hand (the early return
disabled: "#1 500: rests 59.99s by backoff"; restMinutes in place of
restCapMinutes: "off: <nil> 0").
- routing-rest-off.test.cjs: 20/20 (chromium, webkit; 1100, 420; en zh
zh-TW ja de); red 10/10 with the "off" case renamed.
routing-wb-restricted 20/20. rest-try-now and routing-model-rest fail
a varying few under load average 200-420 here, and fail more on
origin/main
|
||
|
|
8c5190a203 |
provider: a routing group keeps its thinking members' levels beside a member known not to think, so Codex shows its effort control (#2127, cnlove7777777-art)
#2127: with a routing group as its model, Codex showed an effort but no control to change it, and new sessions and subagents ran at medium. A group offers agents the levels its members have in common (groupEntries), and a member magpie knows doesn't think (Entry.Quiet: its vendor's list says no reasoning) counted as having none, so the intersection came out empty. The group still reasons when one member does, so Codex got its entry with reasoning but no supported_reasoning_levels and no default_reasoning_level: no slider, and Codex's own medium. Since #950 the gateway sends such a member no reasoning ask at all (withoutReasoningAsk, quiet.go), as it does a reasonless one ( |
||
|
|
4faa931325 |
provider: Vertex AI's preset offers Gemini 4 Argon at global, and its test asks it at low (#2155, TomXPRIME)
Gemini 4 Argon went live on Vertex AI's global location on 2026-10-13
(gemini-4-argon), and the preset's fixed list (Vertex has no list to ask)
didn't have it, so a fetch never showed it. It is added to the preset's
models, which are global's; us, eu and the regions are left as they
answered on 2026-10-06, since nothing says Argon is served there (typed
in by hand it still goes).
Its metadata (1,048,576 context, 65,536 output, low/medium/high, $2/$10)
comes from models.dev's google-vertex entry, which lists it as of today,
so nothing is hard-coded here. The gateway already tells Gemini 4 a
thinking level at the level asked (
|
||
|
|
7d4ad7c628 |
gui: the menu bar's total is every token, cache too, marked Σ, as the Requests tab sums it (NextCommit)
NextCommit on Discord: the menu bar's usage showed only input tokens, and
more input than the Usage page. It showed input + output, unlabelled, so
it read as the input and came out above the page's input. And it was summed
as the Overview sums (usage.SummarizeTop: the gateway's calls only, cache
aside), while a click opens the panel's Usage tab, which sums the ledger
(the agents' own session-file calls too) and counts the cache's tokens
in its Tokens. Two numbers under one name.
- trayTotalSum is the ledger's cached sum, usage.QueryPage(p, {}, 0, 1).Sum,
the one the panel's Usage tab and the window's Requests tab show.
- The cell's top row is every token (in + out + cache read + write, as
allTokens) prefixed Σ; the cost stays under it. The tooltip spells out
"N tokens (a in · b out · c cached)".
- With the window as the tray's, a click opens the Requests tab at the
period (quotaView), not the Overview, which sums differently.
- docs/reference.md and gui-shell.md say so.
Run:
- TestTrayTotalIsTheLedgers (new): a Codex session-file call of 1000 in,
200 out, 8000 cache read; the menu bar's sum equals ledgerPage's and the
cell reads Σ9.2K. With trayTotalSum put back to SummarizeTop it fails
(menu bar all zeros, ledger 1 call).
- TestTrayTotals/BesideCards updated for Σ, the cache and tab=requests.
- go test -tags nogui ./internal/gui (sandbox HOME via the package): ok.
- tray-totals, tray-usages, tray-cell-click .test.cjs, chromium and
webkit, five languages, 1100 and 420: 70 pass.
- The Mac cell rendered with trayImagePNG and looked at: "Σ6.3M" over
"$3.40", "Σ47M" alone, both inside the row width.
- gofmt -l, go vet darwin, GOOS=linux -tags nogui, GOOS=windows; builds.
Not tried: the real menu bar on the reporter's data.
|
||
|
|
1a5128747b |
cli: magpie provider refresh-every and auto-include set a list's schedule and rules (#2135)
`magpie provider refresh-every <id> 6h|1d|off` and `magpie provider auto-include <id> 'gpt-*' 're:claude-.*'|none` set the fields the previous commit added; `magpie provider <id>` shows them, and `magpie provider refresh` prints the models its rules took. TestRefreshEveryAndAutoIncludeCmds: a too-short or unreadable time and a plain id as a rule are refused, the rule takes the current matches, and none/off clear both while keeping the picks. Run with the go test in the previous commit's body. |
||
|
|
3b6ca05571 |
gateway: /v1/magpie/concurrency tells the whole gateway's requests in flight, waiting and tool turns, 0 when idle, with or without a limit (#2132, bigbitbox)
A status bar (SketchyBar) polling /v1/magpie/concurrency got
{"data":{},"object":"concurrency"} with no limit set: the lanes hold only
keys and accounts with a limit, so an idle gateway and a busy one with no
limits read the same. The answer now carries, beside data:
- requests: Busy().Requests, every agent request in flight, those waiting
for a slot among them; a GET (this poll included) is never counted;
- waiting: how many of those wait for a slot, summed over the lanes;
- tools: Claude subscription turns waiting on their caller's tool results.
Each is 0 when idle. Access is unchanged: this machine, another only with a
gateway key, a held key refused (refuseHeld). docs/reference.md says so
beside the usage API.
Run: TestConcurrencyTellsTheWholeGateway (new) fails without the change
("idle: tools = <nil>, want 0 (map[data:map[] object:concurrency])") and
passes with it, -count=5; it covers no limit anywhere (the reporter's
case), and three in flight on a one-slot provider with one waiting.
gofmt -l (nothing); go vet, GOOS=linux go vet -tags nogui, GOOS=windows go
vet on internal/gateway (ok). go test -tags nogui -count=1 ./internal/gateway
in a sandbox HOME: ok in 835s with -timeout 40m (on 0ad9661b6; the default
10m ran out while three other gateway suites ran on this machine), then
the concurrency, busy, held-key and LAN tests -count=3 after rebasing on
|
||
|
|
20350dafaf |
gateway, agent, gui: Claude Desktop's subagents can be held to one model, set in its row on the Agents page
Claude Code in a terminal holds every subagent to one model through
CLAUDE_CODE_SUBAGENT_MODEL (its "subagents" field), and Codex through
magpie's own setting (settings.CodexSubagentModel). Claude Desktop runs
its Code tab's Claude Code with CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1,
and Claude Code 2.1.295 then ignores CLAUDE_CODE_SUBAGENT_MODEL,
CLAUDE_CODE_SUBAGENT_MODEL_FORCE and the tier variables in its settings
files ("Ignoring … this session's provider routing is managed by the
host"). The env Desktop 2.31226 builds for the Code tab has no key for it
either. So Desktop's subagents ran on the lead's model or on a tier's, and
only the tiers could be picked.
Claude Desktop's row now has a "subagent model" square, the same square
and strings as Codex's. It is magpie's setting
(settings.DesktopSubagentModel), which the gateway applies
(desktopSubagentPick):
- Only a claude-desktop request with x-claude-code-agent-id and tools is
moved: a subagent's turn. The lead's turns, the tool-less helper calls
Claude Code makes inside a subagent (on the haiku tier's model),
terminal Claude Code and every other agent stay as asked.
- It is applied after desktopTurn, the tiers and the groups. A turn
already on the model set isn't marked as moved. Route.Subagent,
Route.Model and the ledger's Requested keep the model asked for; Kind
stays empty.
- The model set must be served by its exact id (Resolve takes any model
name under a provider that is on), enabled, and allowed to a gateway key
held to some models (groupAllowed for a group). Otherwise the subagent
stays on the model asked for and the trace says why, in the reasons
Codex's subagent model already has.
- count_tokens counts on the same model.
- It is read on each request, so Desktop needn't restart. The field is
Live (a new Field flag): /api/set and `magpie <agent> <field> <value>`
leave Desktop's restart notice out after it, unless the pick connected
Desktop. Codex's subagent model is unchanged.
- The getter follows a provider renamed since it was set (RenamedRef).
The setter takes any provider/model or group/<id>, also one not served
now (a restored profile), refuses a bare name, and keeps a Desktop
alias by its catalog id. Options are shown while Desktop is on magpie.
- POST /api/settings keeps it; a stopped WSL distro's field copy keeps
Live.
- The Routing page says why a Desktop subagent was moved or kept
(subagentWhy, for a route with a subagent pick and no kind). "it is
disabled in magpie" gets its zh, zh-TW, ja and de, which Codex's kept
reason lacked as well.
- Unset, the pick costs one held settings read (no body decode, no
catalog build).
Not changed: a Desktop on another computer that reaches magpie with a
named gateway key is read as Claude Code (agentOf), so none of Desktop's
routing applies to it, this included. There is no fallback when the model
set has a smaller window than the lead's.
Verified at this head, on
|
||
|
|
f70c0525aa |
access, gui, cli: a gateway key's limit can run every N hours, a 5-hour cycle among them (#2102)
A key's limit window was a calendar day, week or month, or every N days (#1509). #2102 asks for a shorter cycle, every 5 hours, like a vendor's own 5-hour window. Limit gains period "hours" with Hours (1..8760), counted in absolute time from Since, as the N-day cycle is; a change to N or from days restarts the cycle, a cap change keeps it, Reset starts a new one. Budget status, the 429's wording ("this 5-hour cycle"), X-Magpie-Limit-Reset, /v1/magpie/limit and a remote magpie's key card carry Hours. The GUI's window menu has "Every N hours" with an Hours field beside it (no native select); the CLI takes `<N>h` (magpie gateway-key limit <id> 5h --tokens 200k). Docs: reference.md and docker.html (en, zh, ja). Strings in zh, zh-TW, ja, de. Run: - go test ./internal/access (TestLimitHoursCycle across NY DST, UTC, UTC+8; TestLimitHoursSetAndReset), -tags nogui ./internal/cli (5h, rejects 0h/8761h/xh/1.5h/hours), ./internal/gateway (TestKeyLimitHoursCycle: 429 and reset header, /v1/magpie/limit, Reserve at the boundary, Reset; remote key card 5h), plus the full access, budget, cli, gateway, provider and gui packages. The gateway package hit go test's 10-minute default once with the load average near 270; rerun with -timeout 40m it passed in 1536s. - Broke cycle() for hours by hand: TestLimitHoursSetAndReset and TestKeyLimitHoursCycle went red; restored. - GUI: gateway-key-cycle (extended with the hours case: menu, field, validation, Save body, badge, Reset confirm, one-column at 500px) in chromium and webkit x en/zh/zh-TW/ja/de, 10/10; i18n-keys, gateway-key-limit, gateway-caller-keys, phone-rows, gateway-keys-off, gateway-own-key, api-key-theme 63/63; an ad-hoc check of the hours editor at 1100 and 420 in both engines and 5 languages (no overflow, screenshots looked at). - gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows. Not tried: a real gateway under load across a 5-hour boundary; the Windows box. |
||
|
|
62378c5f84 |
cli, usage: magpie usage takes --last <dur> and --days <n>, a window ending now, with or without --csv and --account (#2075, tinysnake, fcy222fcy)
today, 7d and 30d begin at a local midnight, so a caller wanting "the
last few hours" just after midnight had to take 7d's CSV, seven days of
rows for one. `magpie usage [--csv [--account <name>]] --last 24h` (any
Go duration, 90m) or `--days 1.5` now reads a window that began that
long ago; the presets are unchanged.
From fcy222fcy's branch (usage-rolling-window, 60472c661): a rolling
window is a period "last:<dur>" (usage.LastOf / Period.Last) that Since,
Known, shown and the chart's timeline answer for, so the ledger, Direct
and the summary read the same window.
Review fixes on top:
- a summary of a rolling window is worked out each time, like a picked
range: kept, its start didn't move with the clock while the log
stayed the same (reachable through the web API's ?period=last:24h);
- the CSV export's file name has no colon from "last:24h0m0s", which
Windows refuses;
- `--last 24h 7d` is refused rather than silently taking --last;
- --days refuses NaN, Inf and over a century;
- the help line and docs/reference.md name the flags.
Run: new TestRollingWindowIsNotKeptStale fails with the cache fix taken
out ("an hour later: 1 calls, want 0"); TestCSVStamp fails without the
colon fix ("magpie-requests-last:24h0m0s-2026-09-30");
TestUsageRollingWindowRejectsJunk fails without the preset/--days
checks; TestUsageRollingWindow and the new ...WithAccount fail (3 rows,
want 2) with Since moved back. go test -tags nogui ./internal/usage/...
./internal/cli/... ./internal/usageapi/... ./internal/gui/... in a
sandbox HOME: ok. gofmt -l clean; go vet darwin, GOOS=linux -tags nogui,
GOOS=windows; go build darwin, linux nogui, windows.
Real use: the built binary on a sandbox HOME with a generated 50,000-call
7-day usage.jsonl: --csv 7d 47,233 rows / 6.97 MB; today 4,376; --last
24h 7,140 / 1.05 MB; --last 90m 444; --days 1.5 10,712; --account me@x
--last 24h 3,570 (that account's half); oldest row of each at the
window's start.
Not tried: the full go test ./... suite; the process still parses the
whole usage.jsonl into its in-memory index on each run (as every period
does), so the cut is in rows decoded and written, not bytes read.
Co-authored-by: fchengyan <3181088318@qq.com>
|
||
|
|
11b1fb1db7 |
cli: magpie quota refresh <provider> [<account>] reads that card again, as its refresh button does (#2104)
magpie quota refresh <provider> [<account>] [--json] runs the Usage card's
refresh (RefreshUsage's path) from a terminal and prints that card alone;
no other vendor is asked. provider.RefreshReport returns the read's own
cards (refreshCards, shared with RefreshUsage), since a fresh process's
caches don't hold a partial read's subscription and plan cards. A second
refresh of the same card within 30s asks nobody and prints the kept
reading, saying so on stderr; the times live in the cache dir's
quota-refresh.json, so the gap holds across processes. --json prints
magpie quota --json's shape, with readAt and error. The account may be a
login, an alias or <provider>/<account>.
Run:
- go test -tags nogui ./internal/cli ./internal/provider ./internal/tui:
ok (provider 591s under load ~200; an earlier run hit the 600s default
timeout, the rerun with -timeout 25m passed)
- TestQuotaRefreshReadsOneCard / TestQuotaRefreshGapPerCard; with the gap
check disabled by hand the first goes red ("asked a 2 times")
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on the
three packages
- the built binary in a sandbox HOME (MAGPIE_ADDR=127.0.0.1:47614) against
a local fake balance endpoint: refresh free-relay showed 12.50; a second
run at once didn't hit the endpoint and said so; after 31s it read 11.00;
"Free Relay" resolved by name; --json carried readAt, and a 404 gave
"error": "404 Not Found"; an unknown provider exits 1.
Not tried: a real subscription (Codex, Claude) or a remote magpie's cards.
Reading from the caches instead of RefreshReport doesn't turn the test red
for a key balance (its cache holds the read in-process); the subscription
path that needs it is covered by reading only, not by a test.
|
||
|
|
d9ca84a2f4 |
gateway: built-in TLS, magpie serve/web/daemon install --tls-cert --tls-key, reloaded on renewal (RoderickZH)
magpie serve, magpie web and magpie daemon install take --tls-cert <file> --tls-key <file> (or MAGPIE_TLS_CERT / MAGPIE_TLS_KEY). The gateway and the web UI on its listener then serve HTTPS to other computers. Without them nothing changes. - Half a pair, a file that doesn't parse, or a flag with no value is refused at start with a message naming the missing flag. - The pair is re-read when either file's mtime or size changes (certbot renewal), with no restart. A renewal that doesn't parse keeps the certificate already served and is logged once. - Other computers get HTTPS only. Plain HTTP from them gets net/http's 400 "Client sent an HTTP request to an HTTPS server". - This computer (loopback, or a peer address equal to the local one) may still use plain http on the same port. Its connections are sniffed on their own goroutine (a first byte of 0x16 is TLS) for up to 10s, so a silent client holds nobody else up. gateway.URL() stays http://127.0.0.1:<port>, which agents, MCP servers, ServedBy, the healthcheck and daemon status all use, and no certificate covers loopback. - WSL NAT and containers count as other computers. - ALPN is http/1.1 only (hijacked connections and websockets need it), with TLS 1.2 as the minimum. - Printed links, LAN addresses, publicURL, the serve/web banners and daemon install show https:// for other computers' addresses. - The DNS-rebinding Host checks (foreignPage, rebound, the MCP loopbackHost) don't depend on the scheme and are unchanged. - daemon install carries MAGPIE_TLS_* into the unit or plist. A reinstall or `daemon web on` that names no certificate keeps the installed pair, and --no-tls removes it. - Docs: reference.md gets an HTTPS section that names Caddy as the alternative, gateway-routing.md gets a TLS row, and docker.html (en, zh, ja) gets the env rows. What was run: - New tests: internal/gateway/tls_test.go (others HTTPS-only, this computer both, a silent local client holds no other, renewed certificate served, CheckTLS, addresses, Relisten keeps TLS), internal/cli/tls_cli_test.go and daemon TestInstallCarriesTLS (linux and darwin, paths with space, %, & and "). - Each was broken by hand and went red: no wrap in listen, no reload, a synchronous sniff, a bad renewal dropping the certificate, http in publicURL or the pinned LANURLs, the carried entries removed, and keepTLS as a no-op. - Real use under a sandbox HOME, with a self-signed pair, on 0.0.0.0:3461: - Half a pair, a garbage certificate, a flag with no value, and the env set to half a pair each exit 1 with the message. - curl -k https://127.0.0.1 and https://<LAN IP>/v1/models with a key: 200. Plain http on loopback: 200. - The cert files were swapped for a second pair while it ran. openssl s_client then showed the new CN and serial, and curl --cacert with the new pair got 200. A junk key file then kept the second pair, logged once. - From the Windows box over the LAN: plain http got 400; https with the key got 200, and without it 401. - magpie web --addr 0.0.0.0:3462: https network links. From Windows, http got 400 and https with the key got 303. - gofmt -l clean. go vet passed on darwin, GOOS=linux -tags nogui and GOOS=windows. - go test -tags nogui for ./internal/cli, ./internal/daemon, and the TLS tests of ./internal/gateway and ./internal/gui: all pass at the rebased head. - Two reds in the full suite (`go test -tags nogui ./...`) are the same on origin/main f074996d9; both are filed: - TestGatewayHeldByAContainer failed 2 of 5 there (#2107). - The gateway package runs past go test's default 10m under load: 1208s on main and 1221s here, both passing with -timeout 40m (#2108). |
||
|
|
33da86c71a |
provider: removing a plugin sets its providers' model picks in providers.json aside, and adding it again puts them back (#2057, dawn1095)
A plugin's provider leaves a record in providers.json once the user picks its models: its id and nothing of its own (OnlyPicks). Removing the plugin left those records behind. Nothing listed them, `magpie provider rm` couldn't reach them, and a sync or backup asked for a sign-in to them on every run. RemovePlugin now finds the ids the plugin's providers are stored under (PluginID of each provider plugin.Listed gives for its spec), and moves the records with those ids that hold only picks into providers.json's new pluginLeft, under the plugin's package name. Left alone: - any record with an endpoint or a key (the user's own provider, whatever its id); - a built-in's ids (accountIDs) and "magpie"; - an id another installed plugin serves too; - everything, when the plugins' listing isn't known (no cache and no plugin-providers.json): unknown is not "none is the user's". provider.AddPlugin (CLI, GUI, backup restore) puts the set-aside records back, each one whose id has no record now; one the user has given to a provider since stays aside. plugin.Listed is new: the cached listing, or plugin-providers.json. Run: - plugin_left_test.go, four tests with user-owned records beside the plugin's (a user "zap" with an endpoint next to the plugin's zap-plugin, a hand-made "mine", a built-in's picks, another plugin's and a shared id). Each guarantee broken by hand turned its test red: no set-aside, no OnlyPicks check, no other-plugin exclusion, no unknown-listing guard, take-back over the user's record, no take-back. - go test ./... in a sandbox HOME; gofmt -l; go vet darwin, linux (-tags nogui), windows. Not done: records left by plugins removed before this change stay where they are; turning a plugin off (not removing it) sets nothing aside; `magpie provider rm` still can't name such a leftover. The move flow (installPlugin) still adds through plugin.Add, since its own migration owns those records. Not tried with a real plugin removal in the GUI. |
||
|
|
ccffdadb8a |
gateway: /v1/audio/transcriptions passes speech-to-text through to the provider (#2053, niyoh120)
niyoh120 asked for an OpenAI-style speech-to-text endpoint so a client's voice input can go through magpie like its chat does. magpie had no /v1/audio route, so the request 404ed. What changed: - POST /v1/audio/transcriptions and /v1/audio/translations (and the /audio/... spellings) route through the same core as embeddings and rerank. embeddings.go's routing is pulled out into serveRetrieval, so disabled models, key access, groups, pause rules, account holds, failover, redaction and usage records are shared rather than copied. - transcribe.go reads the multipart form only to find `model` (as provider/model) and `prompt`. The form goes to the provider byte for byte; it is rebuilt part by part, under the same boundary, only when the model name is rewritten or the prompt was masked. The audio part is always copied as sent. - Only providers with an OpenAI-style base are tried; an Anthropic-only provider gets a 400 saying so. A body that isn't multipart, a form with no model, or one that doesn't parse gets a 400 and nothing is sent. - The vendor's answer type passes through (response_format text/srt/vtt stays text/plain). Usage records output tokens from usage.output_tokens. - The 404 message, the info api list, remote magpie's suffix list, the CORS and LAN tests, docs/reference.md, gateway-routing.md and the remote docs (en, zh, ja) name the new paths. What was run, at 9c36c3a0 (this change rebased on |
||
|
|
2076943915 |
plugin: a plugin declares its own switches, shown in its provider's editor and read by the plugin (#2038, Vocllum)
Vocllum asked that a plugin can offer the user generic on/off options
without magpie knowing what each one is for. A plugin now declares them
on its auth hook, beside checkin:
auth.options: [{ key, label, description?, default?, confirm? }]
and reads the user's values through input.magpie.option(provider, key)
or input.magpie.options(provider). Each call reads the current values,
so a change reaches the plugin without a restart. magpie only keeps the
value and hands it over: nothing is scheduled or run when an option
changes. The check-in switch (settings.pluginCheckins) and the check-in
plugins are unchanged.
- host.js: optionsOf keeps a key matching [a-z0-9_-]{1,40} with a
non-empty label, drops repeats, caps the label at 60 characters and
the description and confirm at 300, takes default only when it is
true, and keeps at most 16. The values come at init and through
setProviderOptions.
- Go: plugin.Option, Provider.Options, OptionOn and SetProviderOptions
(sent only to a host that is running). settings.PluginOptions is kept
by the plugin's provider id, then the key. POST
/api/settings/plugin-option {provider, key, on} checks the key the same
way and hands the values to the host. The generic settings save keeps
them, as it keeps PluginCheckins. /api/providers' plugins[].options
carry each option's resolved `on`.
- GUI: a "Plugin options" field in a plugin provider's editor. Each
option is a segs Off/On beside the plugin's label and description, put
in with textContent. A confirm text is asked through confirmAction
before turning an option on. Changes wait for Save, which posts each
one before the provider. Strings are added for zh, zh-TW, ja and de.
- Docs: provider-plugins.md (a new section), reference.md, gui-shell.md
and the tests README.
Run:
- TestPluginOptions (a real host with testdata/options). Red with the
old host.js (no options listed) and red with setProviderOptions turned
into a no-op (the plugin still reads the old value).
- TestPluginOptionSetting and TestSettingsSaveKeepsWhatItDoesNotSend.
Both red with the generic save's PluginOptions line removed.
- plugin-options.test.cjs: 22/22 in Chromium and WebKit, at 1100 and 420
wide, in en, zh, zh-TW, ja and de. Red on the old app.js (no field).
The screenshots were looked at: long text wraps and the page has no
sideways scroll at 420.
- provider-concurrency, plugin-signin, plugin-checkin, provider-price-rate
and plugin-move-unserved: 68/68.
- go test ./internal/plugin/... ./internal/settings/... ./internal/gui/...
./internal/provider/..., gofmt -l, and go vet on darwin, linux
(-tags nogui) and windows.
Not tried with a real community plugin, since none declares options yet.
The check-in row doesn't take a plugin-declared label or hint; it is
left as it was.
|
||
|
|
82f3befd29 |
daemon: magpie daemon install --web serves the browser page from the service, with a link that lasts (HuanCheng Bai)
HuanCheng Bai on Discord runs `magpie daemon` on a Linux server and asked
for the daemon to serve the web page too, or for an option to turn it on.
`magpie web` run beside it is a second process, and he read it as not
seeing the daemon's state.
- `magpie serve --web[=host:port]` serves the gateway and `magpie web`'s
page from one process (stats, StartWeb, Wait). The default page address
is 127.0.0.1:3430. Any other argument is refused, where before it was
ignored.
- `magpie daemon install --web | --lan | --addr host:port | --no-web` and
`magpie daemon web [on|off] [--lan] [--addr host:port]`. The unit's
ExecStart and the plist's ProgramArguments become `serve --web=<addr>`,
and the key goes into the 0600 file's environment as MAGPIE_WEB_KEY. The
key is made once. A reinstall with no flags keeps the page and its key
(read back from the file by daemon.Web), so the link survives restarts
and reinstalls. `web off` drops it. MAGPIE_WEB_KEY in the shell, when
set, is used and checked like magpie web's. The page defaults to
loopback; --lan or a non-loopback --addr prints the network links and
magpie web --lan's warning.
- `magpie daemon status`, install and `daemon web` print the page's link.
- `magpie web` while the service serves a page prints that page's link and
exits. Beside a gateway another magpie serves, it says so and points to
`magpie daemon web on`.
- docs/reference.md (the service section and the Use list), and the
site's start page (en, zh, ja). The READMEs don't cover the daemon.
Run:
- Tests: TestInstallWithWeb (systemd and launchd, plutil lint, read back,
reinstall without the page, the shell's key not carried, no key
refused), TestWebNotInstalled, TestParseDaemon, TestWebOptions,
TestDaemonStatusPrintsPage and TestServeArgs. Each of these went red
with its line reverted by hand: withKey, prevKey in webOptions, and the
status page line.
- Sandbox HOME with a fake launchctl:
- `daemon install --web --lan` wrote a 0600 plist with
`serve --web=0.0.0.0:3430` and the key. plutil said OK, and it printed
the link, the network links and the warning.
- Reinstalling with no flags kept the key. `daemon status` showed the
link.
- `daemon web off` / `daemon web` / `daemon web on` behaved as above,
with a new key after off.
- `daemon web bogus` and `serve --lan` gave the usage errors.
- `serve --web=127.0.0.1:3462` served the gateway (3461) and the page in
one process. The page answered 200 with the key and 401 without, and the
page and /v1/models both showed 3 models. `magpie web --no-open` beside
it printed the service's link and exited 0.
- gofmt -l; go vet (gui), and go vet -tags nogui for darwin, linux and
windows; go test -tags nogui ./... in a sandbox HOME.
Not tried: a real systemd on Linux. The unit text is checked by test only.
|
||
|
|
8f03b78069 |
cli, gateway: magpie statusline prints the session's model and each account's windows for Claude Code's status line (#1997, kensenzhao)
kensenzhao asked for magpie's routing and quota in Claude Code's status
line. Claude Code runs the statusLine command on every update and cancels
the run that is still going, so the command must answer fast. It must never
make a vendor read.
- `magpie statusline [<provider|account>]` reads Claude Code's statusLine
JSON from stdin. It prints "→ <served model>" from
/v1/magpie/route?session=<session_id>, then each subscription account's
windows ("claude a@x* 5h 62% 7d 41%"). `*` marks the account that served
last. A window whose reset has passed shows 0%. With the gateway off it
prints an empty line. Each request times out after 1s.
- /v1/magpie/quotas?kept=1 (provider.KeptQuotaReport) builds the same
report from the kept cards (CachedCards) and never starts a vendor read.
The plain endpoint can take up to 12s.
- magpie never writes statusLine into Claude Code's settings. The user
adds `"statusLine": {"type": "command", "command": "magpie statusline"}`
themselves (magpie statusline's help, docs/reference.md).
Run: go test -tags nogui ./internal/cli ./internal/provider
./internal/gateway in a sandbox HOME; gofmt -l; go vet natively and with
GOOS=linux and GOOS=windows.
Broken by hand, each went red:
- the CLI asking without kept=1 (TestStatuslineTellsRouteAndEveryAccount);
- dropping the route line (same test);
- KeptQuotaReport calling QuotaReport (TestKeptQuotaReportAsksNobody).
Real use: a built binary against a sandbox gateway on 127.0.0.1:3517.
- kept=1 answered in 0.07s and route in under 1ms.
- `magpie statusline` with Claude-style stdin printed an empty line, since
the sandbox has no accounts.
- Its ~1.1s wall time matches `magpie version`, so that is process start.
Not tried: real accounts, or the line inside a real Claude Code statusLine.
|
||
|
|
f71155591e |
provider: a provider at a vendor's own endpoint is priced from that endpoint's models.dev catalog (#2052, mengyianx)
A custom provider added by its address alone, with no catalog named, was priced only by the model's maker. Qwen3.8-27B, whose maker (Alibaba) sells no such model on any of its seven models.dev catalogs, read "no price is known for it" even at AMD's own endpoint, where models.dev's amd lists it at $0, a price. - catalog: models.dev's provider "api" is read; AtEndpoint names the catalogs at a base URL (trailing slash and case ignored). - provider: EndpointCatalog is the one catalog models.dev lists at one of a key's provider's endpoints (an Anthropic base, kept as its root, also with /v1), used by ListPrice when the provider has no catalog of its own. Never for a subscription's account, never when two catalogs share the address (minimax / minimax-coding-plan), never a plan's catalog (an id with -plan, or membershipCatalogs), whose $0 is the membership's. A user's price and a named catalog still come first; a relay's endpoint matches nothing and its model stays unpriced (no reseller guess). - cli: `magpie model price p/m` with no price gives the two commands that set one (p/m and */m); a price from an endpoint's catalog names it. - gui: the Catalog field's hint says it also sets list prices (en, zh, zh-TW, ja, de). - docs: reference.md's "What a model costs", providers-accounts.md row. What was run: - Reporter's exact case, built binary (go build -tags nogui), sandbox HOME with a copy of this machine's models.dev cache (2026-10-14, same amd entry as the report), providers 001 (relay), 002 and amd at https://developer.amd.com.cn/radeon/api/v1: 001/gpt-5.5 $5/$30, tiers, as before 001/Qwen3.8-27B no price, now with the two commands to set one 002/Qwen3.8-27B $0/$0, "what models.dev's amd lists at its endpoint" amd/Qwen3.8-27B $0/$0 The two suggested commands were run and took effect. - TestEndpointCatalogPrices / TestEndpointCatalogOnlyItsOwn, fixture testdata/endpoint_catalog.json trimmed from the real models.dev cache. Break checks, each FAILs with the case named: ListPrice not using EndpointCatalog -> 002/amd/001 at AMD unpriced, EffectivePrice(002, Qwen3.8-27B) unpriced plan exclusion removed -> "a plan's endpoint: EndpointCatalog() = alibaba-coding-plan", qwen3.5-plus at $0 instead of $0.4/$2.4 single-match rule removed -> "an endpoint two catalogs share: EndpointCatalog() = minimax" Account check removed -> "a subscription's account ... = amd" Anthropic /v1 match removed -> thinkingmachines unmatched - GUI: internal/gui/tests/catalog-hint.test.cjs, chromium and webkit, en zh zh-TW ja de, widths 1100 and 420: 20/20 pass, plus i18n-keys; with the old app.js/i18n.js it fails "one hint names list prices". - go test -tags nogui -timeout 45m ./internal/catalog ./internal/provider ./internal/cli: ok (provider 244s, cli 125s, catalog 3s). gofmt -l clean; go vet (darwin), GOOS=linux go vet -tags nogui and GOOS=windows go vet -tags nogui on those packages: clean. |
||
|
|
b6cf5e3eab |
gui: magpie web keeps its sign-in when another service on the same address fills or clears the host's cookies, and a page opened without it says why and takes the key (#2033, 321sssrt-bit)
A browser keeps cookies per host, not per port. magpie web's sign-in cookie on http://<tailscale-ip>:3430 is the same host's as every other service on that IP's other ports, so one of them could take it away, and a bookmark then answered only "open the link magpie web printed when it started". Reproduced in Docker (linux/arm64, MAGPIE_WEB_KEY fixed, as the reporter runs it) with Chromium and WebKit on the old binary: - docker restart, recreate (an update), browser restart: still signed in (the key, its derivation and the 400-day cookie are fine); - another port on the same host setting ~400 cookies: Chromium evicts the sign-in (401), WebKit keeps it; - another port answering Clear-Site-Data: "cookies" (a sign-out often does): 401 in both; - the page opened by another name for the host (localhost vs IP): 401. Changed: - the sign-in cookie is sent with Priority=High, so Chrome evicts it last when the host's cookies overflow (with it, the flood case stays signed in); - every magpie_web_<port> cookie the browser sends is tried, so a stale one sent first no longer hides the right one; - an HTML page opened without the sign-in gets a page that says which case it is (no cookie sent for this address, or a cookie holding another key) and a field to paste MAGPIE_WEB_KEY into; POST /_magpie/sign-in sets the cookie and goes back to the page asked for (local paths only: no scheme, host, //, /\ or the sign-in itself). The key is never in the page. API calls get a plain 401 that now says the reason too, and the turn-away is logged with it. - docs/reference.md's Docker web section says how long a sign-in lasts and what can take it away. Run: - TestWebGuardBookmark (link cookie has Priority=High; stale cookie first still passes; both reasons; API 401; wrong key 401 with no cookie; right key 303 to /?view=usage with a 400-day cookie; external, //, /\, javascript:, empty, sign-in-path and CRLF back values all go to /). Broken by hand: the old guard fails it (link without Priority), dropping Priority alone fails it, reading only the first cookie fails it (stale cookie: 401). - The Docker matrix above again on the new binary: the flood keeps the sign-in in Chromium; Clear-Site-Data and the other name get the form, and the form signs in (wrong key turned away, right key back to /?view=usage, 200) in Chromium and WebKit; the log says "turned away ... no cookie sent". - go test -tags nogui ./internal/gui (ok, 173s), gofmt -l, go vet darwin, GOOS=linux -tags nogui, GOOS=windows. Not tried: the reporter's own browser and Tailscale address; which service on their host takes the cookie is not known. |
||
|
|
bf25842714 |
gateway: a provider's own cap on how long a key that keeps failing rests (#2008, Gaudi-XIX)
A key that keeps failing doubles its rest from a minute up to 10 minutes, and one rate limited again as soon as its rest is over up to 30; both caps were fixed, so a free key down for hours was asked again every 10 or 30 minutes all the while. `magpie provider rest-cap <id> 4h` (Provider.RestCap, minutes, at most MaxQuotaRest, 8 days) sets where both ladders stop for that provider's keys and accounts (RestCapOr in restAfterMarked's default branch and in rateRest); `default` gives back the gateway's own. A time the vendor names still stands over it. Unset, nothing differs. It is kept by the editor's save, the account copy and normalize. Run: go test -tags nogui ./internal/provider ./internal/gateway ./internal/cli ./internal/gui (temp HOME). Broken by hand: both ladders back on the fixed caps fail TestOwnRestCap (rate-long #6: 30m, want 32m); the GUI keep removed fails TestSaveKeepsQuotaResetAt. Not tried against a real vendor's outage. |
||
|
|
064cffdbfd |
gateway: a key out of a daily allowance rests until the time of day it comes back (#2008, Gaudi-XIX)
A free tier's "You've reached today's free-model token quota" says nothing of when it is back, so it rested 15 minutes (or the provider's own quota-rest), and was asked again all day. A vendor Retry-After over an hour was cut to the hour, and that hour then stood over the user's own longer rest. - Provider.QuotaResetAt: "08:00" on this computer's clock, or "00:00+08:00" on the vendor's. `magpie provider quota-rest <id> until 08:00` sets it; a number of minutes set after it replaces it, and default clears both. normalize drops one that isn't a time of day. It is kept by the editor's save and the account copy. - restAfterMarked's quota branch rests until its next occurrence (OwnQuotaRest). A time the vendor names, or a window's end, still stands over it; a Retry-After stands unless it was cut to longestWait while the user's own rest is longer. - Defaults are unchanged: nothing set, nothing differs. Run: go test -tags nogui ./internal/provider ./internal/gateway ./internal/cli ./internal/gui (temp HOME). Broken by hand, each fails: OwnQuotaRest replaced by QuotaRestFor (TestQuotaRestsUntilTheTimeOfDaySet, 3 asserts), the Retry-After guard removed (the 7200 case), the GUI keep removed (TestSaveKeepsQuotaResetAt), default not clearing it (TestQuotaRestUntil). Not tried against a real free-tier vendor. |
||
|
|
591ed58b53 |
provider: Nous Portal is a vendor preset, Nous Research's API with a Portal key (#392, Vocllum, laojianzi)
Nous Research makes the Hermes models and serves them, with other makers' models, through Nous Portal. #392 was wrongly answered as a relay. A new preset, nous ("Nous Portal", KindVendor with Hosts, lobe-icons nousresearch icon), points chat completions at https://inference-api.nousresearch.com/v1. A Portal API key goes in as a Bearer, the way Hermes Agent's own nous-api provider uses NOUS_API_KEY. The model list is the Portal's /v1/models, which uses vendor/model ids. An entry another app has at that URL, such as Hermes Agent's base_url, now imports as the preset. The preset sets no Anthropic endpoint. The Portal's /v1/messages serves only its anthropic/* models (Hermes Agent's test_nous_portal_anthropic_wire.py), so Claude Code's requests are translated to chat completions for every model. It sets no Responses endpoint either, because none is documented. The preset is added to the README (en, zh), docs/reference.md, and the site's import pages and icon. Sources: - hermes-agent docs: integrations/nous-portal, integrations/providers, features/subscription-proxy. - hermes-agent source at 6e7b83a2: hermes_cli/auth_constants.py (DEFAULT_NOUS_INFERENCE_URL), plugins/model-providers/nous, cli-config.yaml.example ("nous-api - Nous Portal API key (requires: NOUS_API_KEY)"), agent/anthropic_endpoints.py, and tests/e2e/core/live/_helpers.py, whose live run calls the Portal with NOUS_API_KEY. Probed without a key: - /v1/models answers 200 with 423 models. - /v1/chat/completions with a bad Bearer answers 401 "Your API key is invalid, blocked or out of funds". - /v1/messages answers an Anthropic-shaped 401. Not tried: a real Portal key or a real request, since no key was available. Also not built: OAuth sign-in with the 1-hour token and its refresh (Hermes Agent's ~/.hermes/auth.json). Run: - TestNousPortalPreset fails without the preset (no preset "nous") and with an Anthropic endpoint added (endpoints: … "https://inference-api.nousresearch.com"). - go test -tags nogui of internal/provider, internal/gui and internal/catalog passes. - gofmt -l is clean. - go vet, GOOS=linux go vet and GOOS=windows go vet -tags nogui on ./internal/provider pass. - add-sheet and add-button GUI tests pass in Chromium and WebKit (6/6). |
||
|
|
916e30a4f8 |
docs: every file in ~/.config/magpie says what it is for (#2028, emo172)
#2028 asked to sort ~/.config/magpie into subfolders. It stays flat: backups, sync, Docker volume mounts and older magpies all find each file by its name there, and moving them would break each of those for a cosmetic gain. What the report really lacked is knowing what each file is, so the reference's Files section now lists every file magpie writes, grouped by what it holds (what you set, accounts and sign-ins, what magpie set on agents, the gateway and usage, the window's state, and ~/.cache/magpie), with which are written 0600 and what .lock and .bak files are. Each line was checked against the code that writes the file (the path helpers and their doc comments). Docs only; nothing was run. |
||
|
|
db0af71864 |
gui: the menu bar can show today's or the last 7 days' tokens and cost (#1984)
Settings → Usage → "In the menu bar" lists two more rows after the
subscriptions: "Tokens and cost today" and "Tokens and cost, last 7 days",
ticked and saved as a card is (ids "usage:today", "usage:7d" in
trayUsages; provider ids are [a-z0-9-], so the prefix can't collide). They
show beside the allowances or alone.
- trayusage.go: a total is a card built from usage.SummarizeTop(p, 0)'s
Totals (the Usage page's own cached numbers, Input+Output as its
tokensOf counts them): tokens over cost, in the currency Settings picks,
"+" when some requests had no known price. On the Mac it is a Plain cell
(no vendor logo; the bird beside it says whose it is); on Windows/Linux
the tray's text label and tooltip ("Today in magpie / 1.2M tokens (912K
in · 318K out) / ≈$3.40+ / 152 requests…"). Quotas aren't fetched when
only totals are picked.
- Clicked, a total opens the Usage page's Overview at its period
(quotaView → ?view=usage&tab=usage&period=…, read and dropped from the
URL) or the panel's Usage tab at that period (panelUseFocus).
- Only today and 7d: the Usage page has no 3-day window, and a menu-bar
number nobody can open in magpie at the same span would disagree with it.
- The pill names a lone total, and counts a mix as "{n} shown" rather than
calling it subscriptions. Strings in en/zh/zh-TW/ja/de.
- docs/reference.md and gui-shell.md say so.
Run:
- go test -tags nogui ./internal/gui/ (sandbox HOME): ok. The new
TestTrayTotals/BesideCards/TrayCount went red with each piece broken by
hand (no Plain, no text branch, no quotaView branch, 3d accepted).
- tray-totals.test.cjs (new) plus tray-usages, tray-inuse,
proto-menu-overflow (updated for the two rows), i18n-keys, panel-usage,
allowance-open-read, tray-cell-click: 46/46 in Chromium and WebKit, five
languages, 1100 and 420 wide. tray-totals fails 5/5 against the old
app.js.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- The Mac cell image rendered and looked at (bird, "1.2M" over "$3.40").
Not tried: a real macOS menu bar, nor a Windows or Linux tray; the tray
tooltip is English, as the existing tray tooltips are.
|
||
|
|
f64d9312ff |
site, docs: a Privacy page lists everything magpie sends and how to turn it off (#1986)
#1986 asked what the daily count sends, where the id lives and how to stop it. The answer was spread over one README paragraph and the reference. A new page, /docs/privacy (en, zh, ja), lists it from the code: - the daily PostHog batch (internal/stats): a whole example, the label rules for agents/providers/models, partner counts, the $process_person_profile:false flag; - every switch: Settings -> Privacy's two toggles, noStats/noUsageStats, DO_NOT_TRACK / MAGPIE_NO_STATS, noAutoUpdate (About -> Automatic updates), and that a change applies at the next hourly look; - the files: install-id (made at the first send, not at first run, as the issue said) and stats-sent in settings.Dir(), partner-counts.json in the cache folder, their paths per OS and portable, and deleting them; - what usemagpie.ai sees whatever the settings (update feed every 6h, notes, partner list with its 1-in-10 sampled count, /go links, the icon proxy) and the Cloudflare Web Analytics on the site's own pages; - public lists fetched (models.dev, open.er-api.com, npm, GitHub) and providers' quota reads with the user's own accounts; - OTLP export, off by default, its env vars; - why the count stays on by default in releases. Every docs page in all three languages gets a Privacy link in its nav and footer. README (en, zh) and start.html's "What does magpie send about me?" (en, zh, ja) link to the page. docs/reference.md's Files list gains install-id, stats-sent and partner-counts.json, and Counting users says when the id is made, the hourly try, and links the page. Checked against: internal/stats/stats.go, usage.go, provider/partner_events.go, settings (NoStats, NoUsageStats, NoAutoUpdate, UpdateEvery 360, otel.go), appdir, update, fx, catalog, site/worker.js, and the GUI's Settings tabs/labels in index.html, app.js and i18n.js (zh, ja). Run: Playwright (Chromium and WebKit) on all three pages at 1100 and 420 wide, light and dark: no horizontal scroll, no element past the viewport, no page errors (24/24), screenshots looked at for zh at 420 dark. Every href/anchor in site/public/docs resolves; relative links in README and reference resolve. node site/worker.test.mjs passes. Not run: the page on the deployed worker (the site deploys by hand with wrangler, so it is live at the next deploy); the language redirect for /docs/privacy was not exercised beyond the worker's existing tests. |
||
|
|
9e76fcdc68 |
plugin, cli, gui: a plugin's "password" question is typed unseen, as an API key is (#1982)
A sign-in method's prompts could only be "text" or "select", so a token a plugin asks for (the Qoder plugin's PAT sign-in, magpie-community/plugins#103) showed on screen as it was typed, in the app and in `magpie plugin login`. What changed: - internal/gui/assets/app.js renderPluginAsk: a prompt of type "password" gets a password field (masked), the same field an "api" method's key gets. A "text" prompt is unchanged. - internal/cli/plugins_cli.go askPrompt: on a terminal a "password" prompt is read with term.ReadPassword (no echo); piped in it is read as a line, as a script answers it, and an empty answer still goes to the plugin's validate, as a text one does. - internal/plugin/providers.go: the Prompt type lists "password". host.js passes the type through untouched, so nothing there changes. The TUI has no plugin sign-in. - Docs: docs/reference.md and site/public/docs (en, zh, ja) plugins.html say what "password" does and that it is magpie's own (OpenCode has text and select). The answer is only sent to /api/plugin-signin/prompt and the sign-in, as a text answer is; nothing logs or shows it. What was run: - TestAskPromptPasswordIsUnseen (internal/cli): with the password branch disabled by hand it fails with `password on a terminal = "typed-in-the-open", <nil>, hidden reads 0; want pt-secret read unseen`; restored it passes. - plugin-password-prompt.test.cjs: Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and 420 wide, 11/11 each. With app.js put back it fails with expected 'password', actual 'text'. plugin-signin and plugin-signed-out-account 16/16 in both engines; i18n-keys passes in both. - gofmt -l clean; go vet for darwin, GOOS=linux -tags nogui and GOOS=windows on internal/cli, internal/plugin, internal/gui; go test -tags nogui of those three packages in a sandbox HOME: ok. Not tried: a real Qoder PAT through the community plugin (its PR isn't merged), and the CLI on a real Windows console (term.ReadPassword is the same call `magpie plugin login` already uses for an API key). |
||
|
|
12ecb6d8e9 |
gateway: a gateway key held to a budget, models or accounts is told none of this magpie's accounts, only its own limit and routes (#1981)
321sssrt-bit shared magpie on the LAN with a gateway key held to a budget, and that key still read every account's quota and balance. A held key (heldKey: a budget, models or accounts) is someone else's to use, so it now gets 403 with code gateway_key_held (refuseHeld) on /v1/magpie/quotas, quotas/history, quotas/cards, POST quotas/refresh and /v1/magpie/concurrency. That holds from loopback as well as the LAN, the same as usageSummary already did. /v1/magpie/route tells it only the routes of its own requests. Route.callerKey is set by trace.beginFor at all five begin sites, so a route begun without it fails closed. It still reads its own limit at /v1/magpie/limit. Unrestricted keys and the local owner are unchanged. Client side (remote magpie): a 403 gateway_key_held drops the cards kept from before and shows only the key's own card, instead of "isn't shared". The cache is now keyed by provider and key (remoteCardsID), so a changed key never shows what the old one was told, and keepRemoteCards keeps a read only over one asked before it, so a slow pre-held answer can't bring cards back. Decided against letting an account-held key see its own accounts' cards: that would still show the host's account email and balance to the key's holder. Run: - New TestHeldKeyToldNoAccounts covers keys held by budget, models and accounts plus one held to nothing, from 127.0.0.1 and 192.168.1.9. Every route goes red with the refuseHeld calls or the route filter removed by hand. - New TestRemoteMagpieHeldKeyShowsOnlyItsOwnCard goes red with the errKeyHeld mapping removed. TestRemoteMagpieCardsKeptByKey goes red with the cache keyed by p.ID alone. - gofmt -l and go vet (darwin, linux -tags nogui, windows) are clean. - go test -tags nogui ./internal/gateway ./internal/provider -count=1 passes in a sandbox HOME. Not tried: two real machines over the LAN; the tests drive the handler with LAN remote addresses. An older client shows "isn't shared" (or its cached cards until they expire) against an updated host until it updates too. |
||
|
|
ea1ba22c32 |
gateway, gui: Codex's composer predictions go where Settings › General says, Off among them (#1970)
pluo's Usage view showed Codex calls of kind composer_predictions at
133k-231k tokens each with no cache read: ChatGPT.app's Codex guesses the
user's next message with a hidden turn on a fork of the thread, on the
thread's own model, reading the whole conversation again each time. It
asks only when the thread's provider is "openai", so through Codex's own
ChatGPT sign-in (and a custom table pointed at magpie). The app's bundle
(fge) asks for {suggestion: string|null} and uses b.suggestion||null.
What changed:
- settings.CodexPredictions: "" as Codex sends it, "off", or a model id
(provider/model, group/<id>); anything else is refused on load.
- gateway: codexPredictionsTo + codexPrediction, wired beside the
descriptions at both entrypoints (gateway.go and codex_backend.go).
Off answers {"suggestion":null} from magpie and sends nothing (the
title Off path made generic as sentNowhere). A model's answer goes back
only as the object Codex asked for (predictionJSON: think tags and code
fences stripped, suggestion trimmed, blank = null). Plain text is never
taken as a suggestion, since Codex would put it in the user's composer
as their next message; it gives null and is recorded as a failure
("prediction: ...").
- usage: purpose "Prediction" for composer_predictions (purposes.js
regenerated).
- gui: POST /api/settings/codex-predictions, kept by the general save;
Settings › General row "Codex composer predictions" (Codex's own / Off /
magpie's models, the app's picker), hidden in gateway mode; Routing's
story for the kind says Codex's own switch (Settings › General › Show
predictions) and magpie's. i18n in zh, zh-TW, ja, de.
- docs: gateway-routing.md's Codex section, reference.md's gateway-mode
list. site/ docs left for the owner.
What was run:
- go test -tags nogui ./internal/gateway/ (full, -timeout 40m),
./internal/gui/ ./internal/settings/ ./internal/usage/: pass.
New: TestCodexPredictionsSetting (default to ChatGPT, off sent nowhere,
model routed, plain turn untouched, ledger kinds), TestNoPrediction,
TestCodexPredictionOnMagpie (/v1/responses and the backend path),
TestPredictionJSON; gui TestCodexPredictionsSetting.
- Broken by hand, each went red: backend wiring removed; plain text
accepted as a suggestion; the general save not keeping the setting;
the Routing story's kind check.
- Playwright codex-predictions.test.cjs: chromium + webkit, 1100 and 420
wide, en/zh/zh-TW/ja/de (20 pass). routing-kind (with the new kind),
codex-descriptions, codex-titles, i18n-keys, gateway-mode,
purpose-filter, routing-purpose-state, settings-general,
settings-sections, settings-search: pass.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows.
Not tried: the real ChatGPT.app's predictions against magpie (the
feature is gated server-side by /wham/predictions/config and isn't on for
the owner's account); the reply shape is from the app's bundle.
|
||
|
|
05edac2c36 |
daemon: the service's PATH has the Node a terminal gets, nvm's default among them (bookyue on Discord)
What changed: `magpie daemon install` now widens PATH before writing it into the systemd unit or launch agent, the way the app does when opened from the Dock (proc.UserPath): the version managers' and npm's folders that exist, nvm's default Node (not its newest), then the login shell's own PATH (proc.LoginPath), each after the folders the install's shell already had. When no node is found even then, the install says so. Why: the service has only the PATH written into it. With nvm loaded lazily, or an install run over ssh without a login shell, that PATH had no node, and plugins (and the MCP servers and agent CLIs they start) couldn't find it under systemd (bookyue, #feedback 838099). Run: gofmt -l; go vet darwin, linux -tags nogui, windows (daemon, cli); go test ./internal/daemon ./internal/cli -count=1 on macOS; the daemon test binary for linux/arm64 in debian:bookworm-slim (all pass). TestInstallFindsNvmNode uses the real widening with a sandbox HOME holding nvm v20 (default) and v22: the unit's PATH has v20's bin, not v22's, after the shell's own. With the widenPath() call removed by hand it fails (PATH is the shell's alone, Node() empty). Not run: a real systemd install with nvm since this change (the earlier container run, before it, covered install/restart/linger); not tried with fnm or volta, which UserPath handles the same way for the app. |
||
|
|
5617281f55 |
cli: magpie daemon install|uninstall|start|stop|restart|status keeps the gateway running as a service (HuanCheng on Discord)
What changed: a new internal/daemon package and `magpie daemon`, which run
`magpie serve` as the user's own service, with no window and no desktop
session.
- Linux: a systemd user unit at ~/.config/systemd/user/magpie.service
(Restart=on-failure), driven by systemctl --user. status reads
`systemctl --user show`, and says `sudo loginctl enable-linger $USER`
when the user doesn't linger. su/sudo without the user's bus, no
systemd, and WSL without systemd each get an error that says what to
do.
- macOS: a launch agent, com.yetone.magpie.serve (RunAtLoad, KeepAlive on
failure), loaded with launchctl bootstrap gui/$UID. Its log is
~/Library/Logs/magpie/serve.log.
- Windows and Android: refused, pointing to `magpie autostart on` (or to
WSL).
- The service carries PATH, the proxy variables, MAGPIE_*, the XDG folders
and the agents' folder variables from the install shell. The file is
0600 because a proxy can hold a password. It runs magpie by its PATH
name when that is the same file, so Homebrew's link survives updates.
It refuses a go-build binary and an AppTranslocation copy.
- Install is refused while `magpie autostart` is on: the tray app serves
the gateway too, and the two would crash-loop on the port.
- Docs: a reference.md section, and one sentence on the site's start page
(en, zh, ja).
Why: users on headless Linux boxes asked for a supported way to keep
`magpie serve` up across reboots instead of hand-written units. The
existing `magpie autostart` needs a desktop session (an XDG autostart
entry).
What was run:
- gofmt -l; go vet on darwin, GOOS=linux -tags nogui, and GOOS=windows.
- go test ./internal/daemon ./internal/cli on macOS, at origin/main
|
||
|
|
5e30d58fe4 |
usage: a request's row says the upstream's own stop reason on the Requests page, in /v1/magpie/usage/requests and in the CSV (#1927, Gluxggg)
What changed: the gateway has recorded why the upstream said each reply ended (Record.Stop: a Responses reply's "completed", Chat's "stop" or "tool_calls", Anthropic's "end_turn") since |
||
|
|
b8e23db45a |
backup, davsync: an import or a sync installs the plugins and names the subscriptions to sign in to (yapechan)
yapechan on Discord (Windows, Synology WebDAV): after an import or a WebDAV
sync no providers showed on the other computer; adding the same provider by
hand made the synced settings and usage apply. No error, a restart didn't
help.
Cause. A backup and a sync carry providers.json as stored. For a
subscription that is its model picks and settings alone (no endpoint, no
key), and sign-ins are never carried by design; allProviders lists such an
entry only once an account is signed in here. plugins.json was not carried
at all, so a provider served by a plugin (every moved subscription, any
plugin provider) had nothing to come from on the other side. The import
said "N added" and "Needs a key: , " (the picks entries have no name and no
key), and the sync said nothing. API-key providers do come over: tried with
a nogui build in two sandbox HOMEs (DeepSeek, a custom relay, Kimi Code all
listed after `magpie restore`). No Windows-only path issue found.
What changed:
- provider.Carried(keys): the plugins added from npm or git, on/off and
their options (without keys, options whose names look like a key are left
out, as secret headers are). Folder plugins and plugin-auth.json stay.
- backup.Bundle.Plugins (nil from an older magpie). Restore installs the
ones not here through provider.AddPlugins (plugin.Add, then Off and
Options, then HandOver once); it never removes or changes one already
here. A failed install is reported, not a failed restore.
- Result.SignIn / provider.NotSignedIn: the subscriptions brought with no
account here. NeedKey no longer lists picks-only entries (provider.OnlyPicks).
- davsync: the providers part's hash covers the plugins (unchanged for a
setup without any), take/bring carry them, bring installs (logged on
failure), and Status().SignIn names what to sign in to.
- CLI restore and `magpie webdav`/`s3` status print both; the GUI's import
result and the sync row show them (en, zh, zh-TW, ja, de).
- docs/reference.md says what a backup carries now.
Run:
- go test -tags nogui ./internal/provider ./internal/backup ./internal/davsync
./internal/cli ./internal/gui in a sandbox HOME.
- New tests fail with the change broken by hand: TestPluginsCarried
(installed-skip and the HandOver guard), TestNotSignedIn,
TestRestorePluginsAndSignIn ("Needs a key: [ Acme]" without OnlyPicks),
TestSyncPluginsAndSignIn (bring not installing, Status not naming),
sync-sign-in.test.cjs (the lines removed).
- sync-sign-in.test.cjs: Chromium and WebKit, en/zh/ja/de, 900 and 440px,
16/16; it also caught subNames throwing while providers was still null.
sync-*.test.cjs, s3-sync, i18n-keys, gui-ja, gui-de pass.
- gofmt -l, go vet, GOOS=linux and GOOS=windows go vet -tags nogui on the
touched packages.
Not tried: a real plugin install from a real sync (the installs are stubbed
in tests); a real Synology server.
|
||
|
|
f82aba090b |
davsync, gui, cli: GitHub sync refuses a repository that isn't private (#1130)
The sealed setup is committed on every sync, so a public repository would hand anyone every version of it, the whole history, to try passphrases on offline. prepare now reads the repository's "private" field and refuses before writing when it is false or missing, naming the repository and what to do. The form's hint, the CLI usage and docs/reference.md say the repository must be private; sync-backup.md lists the rule and its verification command now points at ./internal/cli. Run: go test -tags nogui ./internal/davsync/ and the cli tests (TestGitHubCmd|TestWebdavCmd|TestS3Cmd|Help) green; TestGitHubPublicRepositoryRefused goes red with the check removed. GUI: github-sync, s3-sync, webdav-settings-refresh, sync-other-kind, sync-not-backup, i18n-keys, gui-zh-tw, gui-ja, gui-de in Chromium and WebKit, 72/72. Not tried against the real GitHub API. |
||
|
|
1af326806f |
sync: magpie's setup syncs to an encrypted file in a GitHub repository, beside WebDAV and S3 (#1130)
A third sync kind: github://owner/repo[/folder] keeps the same sealed backup WebDAV and S3 keep, as <folder>/magpie/magpie.magpie-backup in a repository the user already has, written through GitHub's Contents API with a fine-grained token of its own (Contents read and write), kept in sync.json apart from the library's GitHub token. The token goes only to api.github.com: a redirect anywhere else is refused, and the passphrase may not equal it. Each update is a commit; an empty repository is initialised by the first backup. Settings › Sync gets a GitHub kind with Repository, Branch, Folder and token; magpie github mirrors magpie s3. Inactive servers of every kind are kept in Config.Servers (Other stays for older clients). Squashed from yetone/magpie#1130 at 6b5b1c693e1a3a23e177b4d376f3f7f70f3bc23d onto main. Merge resolutions: the CLI moved to internal/cli since the PR was cut, so github_cli_test.go moved there (package cli) and the github command, its help line and `magpie help github` were wired in internal/cli/main.go and help_cli.go; README's Sync row kept main's links and took the PR's wording; i18n.js zh-TW kept both sides. |
||
|
|
1133ca0fe2 |
gui: the window opens on the page you last left, as a Mac app comes back as it was
molvqingtai on Discord asked for Routing to be the first page, and lc for
the sidebar to be reordered by drag. Rather than a setting or a reorder,
the window now reopens on the page the reader last left: show() keeps the
page in localStorage magpie.lastView, and keptView() opens it at start.
- A page asked for in the address (?view=: the tray's links, a reload)
still wins, Agents too.
- A kept name that is no page opens the first page; one gateway mode
leaves out (Agents, Library) opens Providers, through show()'s and
setGatewayMode's existing fallback.
- localStorage is how the window already keeps magpie.navLayout and
magpie.panelTab across restarts; checked on a copy of the installed
app's WebKit store (~/Library/WebKit/com.yetone.magpie), which holds
those keys from earlier runs.
- Opening on the kept page scrolls nothing.
docs/reference.md and docs/subsystems/gui-shell.md say so.
Run:
- internal/gui/tests/last-page.test.cjs (new), Chromium and WebKit, at
1100 (sidebar) and 420 (header tabs): left on Routing, opened again with
no ?view= and reloaded -> Routing, nothing scrolled; Settings kept;
?view=usage and ?view=agents win; an unknown kept name -> Agents;
gateway mode with agents/library kept -> Providers, routing kept ->
Routing. Broken by hand, it goes red: with show() not saving, with the
kept page not restored, with the kept page beating ?view=, and with
both gateway fallbacks removed.
- model-rate.test.cjs opened "/" after Providers and took it for Agents;
it now asks for ?view=agents.
- 171 GUI files that navigate more than once or touch the start page
(gateway-mode, sidebar*, nav-*, click-scroll, view-*, getting-started,
side-toggle, panel-*...) plus 151 that open the bare root URL, both
engines, 5-6 files at once: all green but model-rate (fixed above) and
load flakes that pass alone here and on origin/main
|
||
|
|
419ef30219 |
gateway: Claude Code gets a safety refusal as Anthropic's own, and switches to its fallback model; how many more accounts are asked is a setting (#1925, DD on Discord)
DD on Discord: through magpie, Claude's safety filter refusing a turn never makes Claude Code move to its fallback model, as it does on Anthropic's API. magpie asked every other account and group member (#248), then told Claude Code a 400 "<model> refused this request", which it takes as an API error. Claude Code 2.1.296 switches on stop_reason "refusal" in a 200 reply (the stream's message_delta or a whole message, stop_details giving the category), and only with a fallback model set; a 400, Anthropic's "Output blocked by content filtering policy" or magpie's, is never retried. What changed: - When nobody is left after a refusal, an agent on Anthropic's Messages API gets the held refusal itself, the vendor's 200 with stop_reason and stop_details, streamed or whole (holdWriter.handBack): keyed Anthropic providers, groups, the Claude subscription. Codex and Chat clients keep the 400, since an empty-looking whole reply makes Codex ask again. - Settings' refusalRetries counts how many more candidates (accounts, then group members, another model among them) a refusal is asked of. Unset is every one, #248's behaviour (Koohoko asked for it); 0 hands it straight back. GUI: Settings > Models > Replies > "Ask again after a refusal" (Never ask again, 1, 2, 3, All), en/zh/zh-TW/ja/de. Global, no CLI: magpie has no general settings CLI (as noLoopGuard). Other 400s are still never asked again; refusals still rest nobody. - disabled-models.test.cjs wheels to Enable, which the new row put past the window's foot at webkit de 420. - Docs: reference.md "When the safety filter refuses", gateway-routing.md. Run: - go test -tags nogui ./internal/gateway (full, -timeout 40m: a first run hit the 10m default at load ~70 from other sessions), ./internal/gui, ./internal/settings; gofmt -l clean; GOOS=linux and windows go vet. - GUI: refusal-retries-setting (en, zh, zh-TW, ja, de at 1100 and 420) with gui-zh-tw, gui-ja, gui-de, i18n-keys and every tab=models suite (disabled-models, images-*, loop-guard-setting, member-model-setting, search-*, searcher-pick, vision-mcp), chromium and webkit: 176 pass. - refusal-retries-setting under load (8 runs at once, load ~200): first 4 of 8 failed at en/ja 420, a press landing on the first save's "Saved" note over the row, then WebKit's wheel still moving the view as the press was measured. It now reaches each button clear of anything drawn over it (reader.cjs reach) and waits for the scroll to rest: 16 of 16. Broken by hand: - handBack off: TestRefusalRetriesNoneHandsClaudeCodeTheRefusal, ...CountsTheTries, ...Group, ...ClaudeSubscription and TestRefusalWithNobodyLeftIsAnError fail (400 "refused this request"). - count ignored: those plus ...CodexStillTold400 fail (the next key answers). - GUI keep-on-omit dropped: TestSettingsRefusalRetries fails; the GUI test fails with All sent as undefined, and with the row not appended. Not tried: a real Claude account's refusal, or Claude Code's fallback switch end to end; the refusal shapes are from Claude Code's source and Anthropic's docs. |
||
|
|
ab1006bb80 |
gui: each WorkBuddy, Trae CN, MiniMax, Qoder or plugin account's daily check-in can be turned off on its own (#1902, magicLaLa)
settings.CheckinOff lists the accounts left out, by their entry in the
vendor's check-in file ("workbuddy|<uid>", "trae-cn|<uid>", a plugin's
"<provider>|<account>"). checkinNow skips them, both in the loop and on
Check in now. provider.CheckinAccounts() lists every account a check-in
reaches; /api/settings carries it as checkinAccounts, and
POST /api/settings/checkin-account {key,on} turns one off or on. A full
/api/settings save keeps the list. Settings shows an Off/On switch per
account under each vendor's Daily check-in row when it has 2 or more
accounts; the Usage card says "Auto check-in is off for this account" and
offers no Check in now for it. en, zh, zh-TW, ja, de.
Run (on 63a361b5f's tree, then targeted again on
|
||
|
|
d6fd9b3a36 |
provider, agent, gui, cli: Codex can switch only its own sign-in between accounts, never through the gateway (#1907, foobra)
foobra wants Codex Desktop and the CLI kept on their own ChatGPT subscription, moved to the next saved account when the signed-in one is used up and back when it resets, without magpie's gateway in the way. magpie already did the switch (codex_switch.go: 98%, 100% In order, back under 90%, unknown usage never switches), but with more than one Codex account on it also wrote openai_base_url into config.toml so a refused request fails over through the gateway (codexFailover). There was no way to have the first without the second. Now Codex's subscription has SwitchOnly (providers.json "switchOnly", opt-in, off by default so nothing changes for anyone who doesn't tick it): - provider.SetSwitchOnly / provider.SwitchOnly; only Codex's own subscription takes it. An unreadable providers.json reads as on, so magpie's own failover is never written on a guess. - agent.codexFailover is false when it is on: no openai_base_url, no failover note, no magpie models in Codex's list. A base URL the user wrote stays. - The account Save copy keeps it. - GUI: "Only switch Codex's sign-in" tick under Providers > Codex's accounts (with more than one on), posting provider/switchonly; the Agents row's failover title points at it. zh, zh-TW, ja, de. - CLI: magpie accounts switch-only codex [on|off]. - docs/reference.md and providers-accounts.md say what it does and that an open Codex app or app-server stays on its account until reopened. Run (darwin, sandbox HOME, -tags nogui): - go test ./internal/provider -run 'TestCodexSwitchOnly|TestCodexSwitchedWhenUsedUp|KeepLogin' - go test ./internal/agent -run 'TestCodexSwitchOnly|TestCodexFailover|TestCodexOwnModelThroughMagpie|TestCodexHandWritten' - Broken by hand, each red: codexFailover guard removed (agent test), SwitchOnly dropped from the Save copy, SwitchOnly reading false on an unreadable file (provider test), the tick drawn unticked (GUI, 16/16). - GUI: switch-only (new), keep-login, agent-failover, gui-ja, gui-de, gui-zh-tw in Chromium and WebKit, en/zh/ja/de at 1100 and 420: 77 pass. - The built binary's `accounts switch-only` in an empty sandbox HOME: reads off, refuses on with no Codex provider, refuses claude. - gofmt -l clean; darwin go vet. Reviewed and rerun after rebasing onto |
||
|
|
30869e35a7 |
usage, gateway: each request's log row says the service tier asked, the one each try was sent at, and the one the vendor said it ran at (#1784, zhenghaowen0967)
What changed
- usage.Record has tier_asked, tier_sent and tier_served, and the CSV gets
them as its last three columns.
- tier_asked is the client body's service_tier (Claude's speed fast reads
"fast").
- tier_sent is the tier the try's last request actually went out at. It
is noted in forwardOnce after every rewrite (a fast pick's priority,
Ultrafast turned to priority on a plan without it, buildResponses
dropping a tier the host can't take) onto the per-attempt wireAt. So a
handed-on try's own row has its own tier.
- tier_served is only what the reply said: service_tier at the top level,
in response.service_tier, or in an Anthropic usage. It is read by the
relay sniffer and by both translated readers, and is empty when the
reply says nothing. It is never filled in from the ask.
- Codex's own relayed sign-in (codex_backend) records the same three.
- /v1/magpie/route: Route.tier (asked), and each Try has tier and
tierServed. The session route has asked_tier, tier, tier_served and each
try's tier and tier_served.
- docs/reference.md (CSV columns) and gateway-routing.md describe them.
Why
zhenghaowen0967 asked that a request whose Ultrafast was sent as priority
to an account without it show that in usage, per try, without calling
the served tier confirmed unless the reply says so.
What was run
- TestTierRecordedPerTry. With Pro out, the first try is recorded
ultrafast, the second priority, and the final record has asked=ultrafast,
sent=priority and served empty while the fake doesn't echo. With an
echoing fake, served is what it said ("ultrafast", and "default" when
none was asked). It also checks the CSV columns, and the Codex relay path
with priority.
- TestUpstreamTierShapes covers the Chat chunk, Responses
response.completed, a Responses body, an Anthropic message_start and
message_delta usage, null, an over-long tier and non-JSON, as well as
bodyTier per protocol.
- Broke it by hand:
- with forwardOnce's noteWireTier removed, TestTierRecordedPerTry goes
red (route tries' tier empty, TierSent empty);
- with the sniffer's Tier line removed, TestUpstreamTierShapes goes red,
and so does the Codex relay case of TestTierRecordedPerTry.
- go test -tags nogui ./internal/gateway ./internal/usage ./internal/cli;
ledger_test's CSV expectations gain the three empty columns.
- gofmt -l; go vet on darwin; GOOS=linux and GOOS=windows go vet -tags
nogui.
Not done
- The served-tier fixtures are built from the shapes OpenAI and Anthropic
document, not from saved replies. Whether chatgpt.com's Codex backend
echoes service_tier wasn't tried against a real account.
- Bridges that don't go through forwardOnce (the Claude subscription,
Cursor's built-in) leave tier_sent empty.
- There is no price multiplier for priority/ultrafast and no GUI column.
|
||
|
|
eba7187368 |
gateway, provider, cli, gui: a group can route By weight, each member's share set beside it (#1910, DD on Discord)
DD asked for weighted round robin as a group routing, next to In turn.
A provider's keys could already route by weight (#841). Groups could not.
What changes:
- provider: Group.Weights maps a member's spelling to its weight, 1 to
1000. A member left out, or set to 0, weighs 1. SaveGroup accepts
routing "weight". It also cleans weights the way it cleans fast and
off: it strips :fast, drops weights of members that are gone and of
members weighing 1, and refuses a weight below 0 or above 1000.
Weights follow a member when it is renamed (RenameMember, Rename,
RenameGroup) and survive Share/Import.
- gateway: planLevel treats each member of a weight-routed group as one
unit: a model with its keys in its provider's order, or a nested group
routed its own way. weightedUnits orders the units by smooth WRR on a
round per group ("group/<id>"), sharing wrrPick with the keys. The
round's pick goes first and the rest stay in member order for
failover. A unit whose head is resting leaves the round. When a
conversation is kept on another member (session/turn/cache/strict),
the charge moves to that member (wrrSeat, wrrMove).
- cli: routing=weight (also weighted, wrr). weight=<model>=<n>[,...]
sets weights and keeps the rest; weight= on its own clears them. The
group view shows "· weight N" for each member.
- tui: By weight is in the group routing list.
- gui: the group editor offers By weight. Each member then shows
"Weight N · S%", its share among the members that are on. Clicking it
edits the number in place: Enter or blur keeps it, Escape cancels,
and a value outside 1 to 1000 shows a warning. The trace header uses
group wording for a weight-routed group. Strings are added in zh,
zh-TW, ja and de.
- docs: reference.md, gateway-routing.md, and site start pages in en,
zh and ja.
Run:
- go test -tags nogui ./internal/provider ./internal/cli ./internal/tui:
ok.
- ./internal/gateway: ok in 988s with -timeout 45m. The first run hit
the default 10m timeout at load average ~170. The test running at
that moment had been running for 2s; it was not a hang.
- go vet -tags nogui on those packages, for darwin, GOOS=linux and
GOOS=windows: clean. gofmt -l: clean.
- New group-member-weight.test.cjs: 8/8 in Chromium and WebKit, en and
zh at 1100, en and de at 420. The WebKit de 420 case also passed six
runs at once.
- gui-zh-tw, gui-ja, gui-de, i18n-keys, routing-*, group-*,
panel-routing*, settings-groups and agent-model-groups: all green
except two.
- routing-steady (WebKit) is #1804. It is red 2/3 alone on origin/main
|