Commit Graph
133 Commits
Author SHA1 Message Date
Junjie Zhouandmultica-agent 12d823211e provider: a multi-protocol provider's model catalog keeps every endpoint's models (#1006)
* provider: a multi-protocol provider's catalog is the union of every endpoint's models

A provider whose protocols sit at bases of their own kept only the first
list that answered, so the models of every other endpoint were nowhere in
the product: not in the agents' model lists, not in the catalog the routing
and the per-model preferences read, and not fixable by pinning a model's
protocol, which setModelAPI refuses for a model the provider does not list.
nyownm reported it as #904 and worked around it with one provider per
protocol.

fetchOne now asks every endpoint the provider speaks and merges the lists
by model id, the way fetchPerKey merges the lists of a vendor's keys: the
first list's fields stand, and an image capability both lists answer is
merged. The base kept is still the first protocol's, the one the drawer
list is fetched beside and the models are saved with. A models URL is
still asked alone, one base two protocols share is still asked once, and
a provider with no endpoint answering still fails with every URL it asked
named in the error.

Verified with go test -tags nogui ./internal/provider ./internal/catalog
and ./internal/gateway ./internal/agent, all green. TestFetchUnionsProtocolLists
and TestFetchUnionsProtocolListsWithoutChat fail on the base commit with
the single list the first protocol answered.

* provider: an endpoint that can't be asked keeps the models it listed

A provider whose protocols sit at bases of their own is asked every base
and the lists are merged, so one read that failed saved the union of the
rest as the whole list: the models of the failed base read as gone,
dropGonePicks took them out of the user's picks and stored that, and
nothing brought them back when the endpoint recovered (yetone's review of
#1006, on nyownm's #904). A read that failed says nothing about what the
vendor serves today, the rule fetchPerKey's keys already follow.

fetchOne keeps what each base listed and saves it beside the merged list,
in a new "sides" part of the catalog's live file, and a base it could not
ask takes its own part back for that fetch. What is kept is that base's own
models alone: a model the bases that answered have dropped is dropped here
too, however many of them dropped it and however many bases are down.
Keeping the whole list saved before would bring such a model back, which is
the same fault the other way round. A list saved before this kept no parts,
so a base whose part is missing keeps what no answering base lists, until
the next fetch with every base answering says which they are.

The parts are kept only where more than one base was asked: a single one
that fails is the fetch that fails, and its list is kept as it is, so a
provider of one protocol's cache is the file it was.

fetchOne answers one fetched list now — the models, the base kept for
routing, the parts — rather than three values. fetchPerKey marks the parts
with the keys that saw them, and keeps a plan's own models out of them.

Verified with go test ./internal/provider ./internal/catalog, all green,
and ./internal/gateway ./internal/agent.
TestFetchKeepsTheModelsAFailedProtocolListed,
TestFetchDropsAGoneModelWhileAnotherProtocolFails and
TestFetchKeepsTheModelsAFailedProtocolListedPerKey fail on 952d0b00 with
the model of the failed protocol taken out of the picks.

Co-authored-by: multica-agent <github@multica.ai>

* provider: a base that never answered keeps nothing, and is not saved as one that listed nothing

keepDeadSides read a part missing from the saved sides as the whole list
saved before, and kept what no answering base lists from it. Two things
were wrong with that, and both were reported on #1006 (nyownm's #904):

A base in none of the saved parts is one that has never answered. The
whole list is not its own, so a model its vendor had already dropped was
kept for it, and the keepDeadSides result was saved as sides[base] —
from then on that base had a part, and the model could never be dropped
again. An Anthropic base answering 404 from the start of a provider's
life was enough: one round after the Chat base dropped a model, that
model stayed in the catalog, and dropGonePicks could not take it out of
the user's picks.

The saving is the other half of the same fault. A part is what a base
listed, so one that never answered has none, and writing an empty one
fixes the reading of "never answered" as "listed nothing" for good. Only
a part read out of the file is written back; the list saved without any
parts at all — before this kept them — is the one case where a base may
stand in for a missing part, and what it stands in for is kept for that
fetch alone, never saved as its own.

So keepDeadSides answers two lists now: the models this fetch's list is
made of, and the parts to write beside it. fetchPerKey keeps a model a
key that could not be asked at all owns to the bases that listed it,
read out of the parts saved beside the list: kept as a whole list with
no part saying where it came from it belonged to no base, and was read
as gone the first time that key answered half-way — the same permanent
deletion of a picked model, one round later and needing no new base.

Verified with go test ./internal/provider ./internal/catalog
./internal/gateway ./internal/agent, all green, and -race -count=3 over
./internal/provider with the four failures it already had.
TestFetchDropsAModelWhileAnEndpointHasNeverAnswered and
TestFetchKeepsAModelsBaseAfterItsKeyFailedWhole fail on 6621f73e.

Co-authored-by: multica-agent <github@multica.ai>

* provider: a base that answered without a model does not keep owning it

fetchPerKey gave every model kept for a key that could not be asked at all
to the bases that listed it last time, and a part there said what the
bases listed when one of them had answered this round without it (yetone's
review of #1006, nyownm's #904). With two keys where both were served a
Claude model, and the Anthropic base stopping both of them in the round
the second key was down, sides[anthropic] kept a model the base had
plainly dropped, and the fetch after that read it as a base that couldn't
be asked and held the model one round longer than it should have. It is
self-healing — the next round with the base answering settles it — and it
is the same fault c8fabd70 was written to undo, read from the other side.

sides may only say what the bases listed. A model kept for a failed key
belongs to a base that was not asked this round for any of the model's own
keys: one that was, and answered without the model, has said what it
serves today and no longer owns it. Which is per key, not per provider:
fetchOne answers which of its bases replied, which a model of the second
key alone never saw an answer from, so the base's saying nothing about it
for the first key leaves it that base's. The keys a model is kept under
are read from the list saved before, since add clears the ones of the model
it is adding.

TestFetchDropsAModelABaseStoppedServingWhileAKeyIsDown fails on c8fabd70
with the part holding claude-b, and TestFetchKeepsAModelsBaseAfterItsKeyFailedWhole
goes on passing: the same two keys, a model only one of them sees.

Co-authored-by: multica-agent <github@multica.ai>

* provider, catalog: a page of a model list is not the list (#904)

A /v1/models that answers with has_more is one page of the vendor's
catalog. Read as the whole list, every model of a later page reads as one
the vendor has dropped, and the user's pick of it goes for good, on a
list that never said so. Such a reply is no answer: the base is treated
as one that could not be asked, which keeps what it listed last time
(#904's review of #1006).

OpenRouter's Anthropic base is not asked for the list at all. With the
Anthropic version header its /models answers with the catalog again,
twenty newest first, every id namespaced under `anthropic/`, and the
cursors of the pages after. None of those twenty is an id in OpenRouter's
own catalog, so merged they are entries of the model picker that name no
model: the long, cluttered list #904's reporter wrote of. Its Chat base
is that catalog, whole, and the fetch is one request where it was two.
The rule is OpenRouter's, by host, as the ones after it are scoped to
their vendors.

Co-authored-by: multica-agent <github@multica.ai>

* provider: the OpenRouter rule reads the base being asked (0fb16990)

It read the Chat base's host, so a provider with a Chat base of
OpenRouter's and an Anthropic base of another vendor's had that other
base skipped: its models were in neither the union nor the sides nor the
bases that could not be asked, so no keepDeadSides path found them and
the user's picks of them went for good. `magpie provider set <id>
anthropic=<url>` reaches that shape from the CLI.

The rule is about the vendor whose base is being asked, so that is what
it now reads, together with whether the provider asks at a base of its
own besides it: an OpenRouter Anthropic base alone is still asked, its
reply being the only catalog there would otherwise be, and
catalog.fetchOne is what keeps a page of it from being read as the whole.

Five combinations of the two bases and openrouter.ai, one assertion each;
three of them fail on 0fb16990.

Co-authored-by: multica-agent <github@multica.ai>

* catalog, provider: a model list is followed to its last page, not read as a page (#1006)

A reply with has_more was refused as no answer at all, which is right for a
provider with several bases and wrong for one with a single base: Anthropic's
own preset has no other base to fall back on, so once its list passes twenty
models — about sixteen today — the fetch answered an error and no models,
where main listed the twenty of the first page, and a pick of a model on a
later page went with them. catalog.fetchOne now reads a list to its end: the
first page as the URL stands, and every page after it with limit=1000 and
the after_id the page before ended at, up to twenty pages.

Half a list is still no answer, and that is what the following ends on: a
page that fails, a list that pages without naming the id to carry on from,
one that answers the page just asked again under the same id, and one still
paging at the cap all leave the base as one that could not be asked, which
keeps what it listed last time. The rule lives in catalog.Paged, and the
Kilo gateway's list — OpenRouter's shape, which pages the same way — is paged
by it instead of refused by a guard of its own; the comment on that guard
claimed OpenRouter's /models pages, which neither api.kilo.ai nor
openrouter.ai was answering with on 2026-10-06, and now says so.

One assertion of TestFetchOpenRouterRuleOverTheFourBaseCombinations follows
the rule rather than the old count: OpenRouter's Anthropic base alone is
asked for its first page and the page after it, which is the same page
again, where before it was asked once and refused.

Tests: TestFetchFollowsThePagesOfAList, TestFetchFollowsAPageAListAnswersItsOwnWay,
TestFetchTakesAPagedListAsNoAnswerWhenAPageFails, TestFetchTakesAPagedListWithoutAnIdAsNoAnswer,
TestFetchTakesAListThatPagesWithoutEndAsNoAnswer (catalog);
TestFetchFollowsThePagesOfASingleAnthropicBase (provider, the Anthropic preset's
one base, 25 models 20 to a page) and TestKiloModelsFollowThePagesOfTheList.

Co-authored-by: multica-agent <github@multica.ai>

* provider: OpenRouter's Anthropic base alone is asked, and refused (#1006)

The fake that stands for openrouter.ai answered every cursor with the same
twenty ids under the same last_id, so following the pages of a list stopped
where the rule of catalog.Paged says a list stops being readable, and the
single-base case looked covered: the twenty were refused and the fetch
failed. The endpoint does not answer that way. Asked with the Anthropic
version header on 2026-10-06, /api/v1/models gave those twenty with
has_more and a cursor, and under the cursor 413 more ids with has_more
false — a different set, and the end of the list. The two pages share
nothing, and following them lands deeper in the `anthropic/` namespace
rather than back at the catalog it was namespaced from: of the 433 ids, 4
are in the 466 OpenRouter serves without that header.

So the twenty were not a page to be refused but the first half of a list
that reads to the end, and the end is still not a catalog of models to
serve. The base is still asked — it is the only base there is, and refusing
to ask would leave the provider with nothing at all — and the list it
answers with is now refused as a whole, which is what the old rule did with
one page of it. It fails the fetch like any other base that could not be
asked, so the provider keeps the models it listed last time (#904).

The two replies are kept as they came, under testdata, and a test reads
them back: twenty, then 413, the cursor the first ends at, has_more true
and then false, and not one id of either page in the catalog OpenRouter
serves. The fake pages with after_id, as the endpoint does.

Tests: TestOpenRouterNamespacedPagesAreTheEndpointShape (new),
TestFetchOpenRouterRuleOverTheFourBaseCombinations (the single-base case now
asks exactly the two pages it answers with, keeps no list, and fails),
TestFetchKeepsPicksWhenAModelListIsPaginated, TestFetchDoesNotMergeOpenRouter's
NamespacedList, TestFetchOpenRouterAddsNoNamespacedModelAndKeepsPicks,
TestFetchKeepsAnotherVendorsAnthropicList.

Co-authored-by: multica-agent <github@multica.ai>

* provider: the message for a namespaced list counts nothing (#1006)

The reason a provider whose only base is OpenRouter's Anthropic one is
refused is still the one it was, and the base is still asked and refused
exactly as before: what changed is the sentence the user is left with, and
the comments around it.

That sentence counted the list it refused — "433 of them, of which 4 are
ids OpenRouter serves" — and those counts are of whatever OpenRouter's
catalog was that day, so the number a user reads is wrong tomorrow without
anyone touching it. It now says why the answer is no good and what to do
instead: give this provider OpenRouter's Chat base, which lists those
models under the ids OpenRouter serves, or type the model ids in by hand,
which is what the caller already appends to every base it could not ask.

The comments said the same counts as fact, and cited a probe file that is
not in the repository. The counts stay, marked as what was observed on
2026-10-06, and what does not move is now the point: following the pages
of the list lands deeper in the namespace, not back at the catalog it was
namespaced from. The dead file references are gone, and one test checks
that the message counts nothing at all, so a count cannot creep back in.

Tests: TestFetchOpenRouterRuleOverTheFourBaseCombinations (the message names
the Chat base and the ids to type, and holds no number but the version in
that base's path).

Co-authored-by: multica-agent <github@multica.ai>

* provider: a multi-protocol provider's catalog is the union of every endpoint's models

A provider whose protocols sit at bases of their own kept only the first
list that answered, so the models of every other endpoint were nowhere in
the product: not in the agents' model lists, not in the catalog the routing
and the per-model preferences read, and not fixable by pinning a model's
protocol, which setModelAPI refuses for a model the provider does not list.
nyownm reported it as #904 and worked around it with one provider per
protocol.

fetchOne now asks every endpoint the provider speaks and merges the lists
by model id, the way fetchPerKey merges the lists of a vendor's keys: the
first list's fields stand, and an image capability both lists answer is
merged. The base kept is still the first protocol's, the one the drawer
list is fetched beside and the models are saved with. A models URL is
still asked alone, one base two protocols share is still asked once, and
a provider with no endpoint answering still fails with every URL it asked
named in the error.

Verified with go test -tags nogui ./internal/provider ./internal/catalog
and ./internal/gateway ./internal/agent, all green. TestFetchUnionsProtocolLists
and TestFetchUnionsProtocolListsWithoutChat fail on the base commit with
the single list the first protocol answered.

Co-authored-by: multica-agent <github@multica.ai>

* provider: an endpoint that can't be asked keeps the models it listed

A provider whose protocols sit at bases of their own is asked every base
and the lists are merged, so one read that failed saved the union of the
rest as the whole list: the models of the failed base read as gone,
dropGonePicks took them out of the user's picks and stored that, and
nothing brought them back when the endpoint recovered (yetone's review of
vendor serves today, the rule fetchPerKey's keys already follow.

fetchOne keeps what each base listed and saves it beside the merged list,
in a new "sides" part of the catalog's live file, and a base it could not
ask takes its own part back for that fetch. What is kept is that base's own
models alone: a model the bases that answered have dropped is dropped here
too, however many of them dropped it and however many bases are down.
Keeping the whole list saved before would bring such a model back, which is
the same fault the other way round. A list saved before this kept no parts,
so a base whose part is missing keeps what no answering base lists, until
the next fetch with every base answering says which they are.

The parts are kept only where more than one base was asked: a single one
that fails is the fetch that fails, and its list is kept as it is, so a
provider of one protocol's cache is the file it was.

fetchOne answers one fetched list now — the models, the base kept for
routing, the parts — rather than three values. fetchPerKey marks the parts
with the keys that saw them, and keeps a plan's own models out of them.

Verified with go test ./internal/provider ./internal/catalog, all green,
and ./internal/gateway ./internal/agent.
TestFetchKeepsTheModelsAFailedProtocolListed,
TestFetchDropsAGoneModelWhileAnotherProtocolFails and
TestFetchKeepsTheModelsAFailedProtocolListedPerKey fail on 952d0b00 with
the model of the failed protocol taken out of the picks.

Co-authored-by: multica-agent <github@multica.ai>

* provider: a base that never answered keeps nothing, and is not saved as one that listed nothing

keepDeadSides read a part missing from the saved sides as the whole list
saved before, and kept what no answering base lists from it. Two things
were wrong with that, and both were reported on #1006 (nyownm's #904):

A base in none of the saved parts is one that has never answered. The
whole list is not its own, so a model its vendor had already dropped was
kept for it, and the keepDeadSides result was saved as sides[base] —
from then on that base had a part, and the model could never be dropped
again. An Anthropic base answering 404 from the start of a provider's
life was enough: one round after the Chat base dropped a model, that
model stayed in the catalog, and dropGonePicks could not take it out of
the user's picks.

The saving is the other half of the same fault. A part is what a base
listed, so one that never answered has none, and writing an empty one
fixes the reading of "never answered" as "listed nothing" for good. Only
a part read out of the file is written back; the list saved without any
parts at all — before this kept them — is the one case where a base may
stand in for a missing part, and what it stands in for is kept for that
fetch alone, never saved as its own.

So keepDeadSides answers two lists now: the models this fetch's list is
made of, and the parts to write beside it. fetchPerKey keeps a model a
key that could not be asked at all owns to the bases that listed it,
read out of the parts saved beside the list: kept as a whole list with
no part saying where it came from it belonged to no base, and was read
as gone the first time that key answered half-way — the same permanent
deletion of a picked model, one round later and needing no new base.

Verified with go test ./internal/provider ./internal/catalog
./internal/gateway ./internal/agent, all green, and -race -count=3 over
./internal/provider with the four failures it already had.
TestFetchDropsAModelWhileAnEndpointHasNeverAnswered and
TestFetchKeepsAModelsBaseAfterItsKeyFailedWhole fail on 6621f73e.

Co-authored-by: multica-agent <github@multica.ai>

* provider: a base that answered without a model does not keep owning it

fetchPerKey gave every model kept for a key that could not be asked at all
to the bases that listed it last time, and a part there said what the
bases listed when one of them had answered this round without it (yetone's
review of #1006, nyownm's #904). With two keys where both were served a
Claude model, and the Anthropic base stopping both of them in the round
the second key was down, sides[anthropic] kept a model the base had
plainly dropped, and the fetch after that read it as a base that couldn't
be asked and held the model one round longer than it should have. It is
self-healing — the next round with the base answering settles it — and it
is the same fault c8fabd70 was written to undo, read from the other side.

sides may only say what the bases listed. A model kept for a failed key
belongs to a base that was not asked this round for any of the model's own
keys: one that was, and answered without the model, has said what it
serves today and no longer owns it. Which is per key, not per provider:
fetchOne answers which of its bases replied, which a model of the second
key alone never saw an answer from, so the base's saying nothing about it
for the first key leaves it that base's. The keys a model is kept under
are read from the list saved before, since add clears the ones of the model
it is adding.

TestFetchDropsAModelABaseStoppedServingWhileAKeyIsDown fails on c8fabd70
with the part holding claude-b, and TestFetchKeepsAModelsBaseAfterItsKeyFailedWhole
goes on passing: the same two keys, a model only one of them sees.

Co-authored-by: multica-agent <github@multica.ai>

* provider, catalog: a page of a model list is not the list (#904)

A /v1/models that answers with has_more is one page of the vendor's
catalog. Read as the whole list, every model of a later page reads as one
the vendor has dropped, and the user's pick of it goes for good, on a
list that never said so. Such a reply is no answer: the base is treated
as one that could not be asked, which keeps what it listed last time
(#904's review of #1006).

OpenRouter's Anthropic base is not asked for the list at all. With the
Anthropic version header its /models answers with the catalog again,
twenty newest first, every id namespaced under `anthropic/`, and the
cursors of the pages after. None of those twenty is an id in OpenRouter's
own catalog, so merged they are entries of the model picker that name no
model: the long, cluttered list #904's reporter wrote of. Its Chat base
is that catalog, whole, and the fetch is one request where it was two.
The rule is OpenRouter's, by host, as the ones after it are scoped to
their vendors.

Co-authored-by: multica-agent <github@multica.ai>

* provider: the OpenRouter rule reads the base being asked (0fb16990)

It read the Chat base's host, so a provider with a Chat base of
OpenRouter's and an Anthropic base of another vendor's had that other
base skipped: its models were in neither the union nor the sides nor the
bases that could not be asked, so no keepDeadSides path found them and
the user's picks of them went for good. `magpie provider set <id>
anthropic=<url>` reaches that shape from the CLI.

The rule is about the vendor whose base is being asked, so that is what
it now reads, together with whether the provider asks at a base of its
own besides it: an OpenRouter Anthropic base alone is still asked, its
reply being the only catalog there would otherwise be, and
catalog.fetchOne is what keeps a page of it from being read as the whole.

Five combinations of the two bases and openrouter.ai, one assertion each;
three of them fail on 0fb16990.

Co-authored-by: multica-agent <github@multica.ai>

* catalog, provider: a model list is followed to its last page, not read as a page (#1006)

A reply with has_more was refused as no answer at all, which is right for a
provider with several bases and wrong for one with a single base: Anthropic's
own preset has no other base to fall back on, so once its list passes twenty
models — about sixteen today — the fetch answered an error and no models,
where main listed the twenty of the first page, and a pick of a model on a
later page went with them. catalog.fetchOne now reads a list to its end: the
first page as the URL stands, and every page after it with limit=1000 and
the after_id the page before ended at, up to twenty pages.

Half a list is still no answer, and that is what the following ends on: a
page that fails, a list that pages without naming the id to carry on from,
one that answers the page just asked again under the same id, and one still
paging at the cap all leave the base as one that could not be asked, which
keeps what it listed last time. The rule lives in catalog.Paged, and the
Kilo gateway's list — OpenRouter's shape, which pages the same way — is paged
by it instead of refused by a guard of its own; the comment on that guard
claimed OpenRouter's /models pages, which neither api.kilo.ai nor
openrouter.ai was answering with on 2026-10-06, and now says so.

One assertion of TestFetchOpenRouterRuleOverTheFourBaseCombinations follows
the rule rather than the old count: OpenRouter's Anthropic base alone is
asked for its first page and the page after it, which is the same page
again, where before it was asked once and refused.

Tests: TestFetchFollowsThePagesOfAList, TestFetchFollowsAPageAListAnswersItsOwnWay,
TestFetchTakesAPagedListAsNoAnswerWhenAPageFails, TestFetchTakesAPagedListWithoutAnIdAsNoAnswer,
TestFetchTakesAListThatPagesWithoutEndAsNoAnswer (catalog);
TestFetchFollowsThePagesOfASingleAnthropicBase (provider, the Anthropic preset's
one base, 25 models 20 to a page) and TestKiloModelsFollowThePagesOfTheList.

Co-authored-by: multica-agent <github@multica.ai>

* provider: OpenRouter's Anthropic base alone is asked, and refused (#1006)

The fake that stands for openrouter.ai answered every cursor with the same
twenty ids under the same last_id, so following the pages of a list stopped
where the rule of catalog.Paged says a list stops being readable, and the
single-base case looked covered: the twenty were refused and the fetch
failed. The endpoint does not answer that way. Asked with the Anthropic
version header on 2026-10-06, /api/v1/models gave those twenty with
has_more and a cursor, and under the cursor 413 more ids with has_more
false — a different set, and the end of the list. The two pages share
nothing, and following them lands deeper in the `anthropic/` namespace
rather than back at the catalog it was namespaced from: of the 433 ids, 4
are in the 466 OpenRouter serves without that header.

So the twenty were not a page to be refused but the first half of a list
that reads to the end, and the end is still not a catalog of models to
serve. The base is still asked — it is the only base there is, and refusing
to ask would leave the provider with nothing at all — and the list it
answers with is now refused as a whole, which is what the old rule did with
one page of it. It fails the fetch like any other base that could not be
asked, so the provider keeps the models it listed last time (#904).

The two replies are kept as they came, under testdata, and a test reads
them back: twenty, then 413, the cursor the first ends at, has_more true
and then false, and not one id of either page in the catalog OpenRouter
serves. The fake pages with after_id, as the endpoint does.

Tests: TestOpenRouterNamespacedPagesAreTheEndpointShape (new),
TestFetchOpenRouterRuleOverTheFourBaseCombinations (the single-base case now
asks exactly the two pages it answers with, keeps no list, and fails),
TestFetchKeepsPicksWhenAModelListIsPaginated, TestFetchDoesNotMergeOpenRouter's
NamespacedList, TestFetchOpenRouterAddsNoNamespacedModelAndKeepsPicks,
TestFetchKeepsAnotherVendorsAnthropicList.

Co-authored-by: multica-agent <github@multica.ai>

* provider: the message for a namespaced list counts nothing (#1006)

The reason a provider whose only base is OpenRouter's Anthropic one is
refused is still the one it was, and the base is still asked and refused
exactly as before: what changed is the sentence the user is left with, and
the comments around it.

That sentence counted the list it refused — "433 of them, of which 4 are
ids OpenRouter serves" — and those counts are of whatever OpenRouter's
catalog was that day, so the number a user reads is wrong tomorrow without
anyone touching it. It now says why the answer is no good and what to do
instead: give this provider OpenRouter's Chat base, which lists those
models under the ids OpenRouter serves, or type the model ids in by hand,
which is what the caller already appends to every base it could not ask.

The comments said the same counts as fact, and cited a probe file that is
not in the repository. The counts stay, marked as what was observed on
2026-10-06, and what does not move is now the point: following the pages
of the list lands deeper in the namespace, not back at the catalog it was
namespaced from. The dead file references are gone, and one test checks
that the message counts nothing at all, so a count cannot creep back in.

Tests: TestFetchOpenRouterRuleOverTheFourBaseCombinations (the message names
the Chat base and the ids to type, and holds no number but the version in
that base's path).

Co-authored-by: multica-agent <github@multica.ai>

* provider: the list of a multi-protocol vendor is asked once (#1006)

The dedup added in 952d0b00 is keyed by the base URL as it is configured,
which is neither of the two things that decide whether a list is asked
again: which list URL the request goes to, and what it authenticates with.
Both of a vendor's ends were lost to it. A Chat base and the Anthropic
base of the same remote magpie are two strings, one list — GET /v1/models
— and it was fetched twice, which #1282 says a remote's test does not do.
And one base string serving Chat, Anthropic and Gemini is three requests:
the Chat request refused a 401 took the other two for lists already had,
so a vendor whose models were all there was reported as serving none.

The key is now the list URL and the authentication, in catalog.Listed, and
it gives two rules. A list URL this key has listed is not asked again by
any protocol — the answer is the answer, so …/v1 and the bare host beside
it are one request. And a request already made is not made again, but a
URL refused under one authentication is not refused under the next, so
the Gemini and Anthropic lists of a base whose Chat request was refused
are asked, each with its own. The base string is left out of the key on
purpose: Chat and Responses at one base are one request because both send
Bearer at the same URL, not because the strings match.

A base whose every list was asked already and none answered says so with
catalog.ErrAsked, which the caller reads as "nothing new here" rather
than as a second refusal to put in the message the user reads.

Tests: TestFetchAsksEachAuthenticationAtOneBase, TestFetchAsksOneListOnce
ForTwoBasesOfIt, TestFetchReportsOneRefusalForOneBaseAskedTwice.

Co-authored-by: multica-agent <github@multica.ai>

* provider: a Gemini base that fails once no longer deletes the picked model it listed

The union fetch merges a Gemini base's list like any other protocol's, but
it kept none of the fetch's bookkeeping for it: what it listed was in no
`side`, so the parts saved beside the catalog said no base listed it, and a
base that could not be asked was in no `dead` either, so `keepDeadSides`
never saw it. A picked Gemini model was therefore dropped from the user's
provider for good the first time the Gemini endpoint answered 502 or timed
out — the fault the Anthropic base of the same fetch was fixed for in
#904. A Gemini base also went uncounted in `asked`, so a two-base provider's
parts were saved on the strength of one base asked.

A Gemini base now joins `asked` before it is asked, joins `sides` and
`answered` with what it listed, and joins `dead` when it cannot be asked.
What a failed Gemini base keeps is its own models alone, so a model its list
has really dropped is still dropped from the picks.

Verified at 20ee273aaedc10ab0baf06cffbd826ddc367be3c + this commit, Go
1.26.8, darwin/arm64, under a temporary HOME with GOPATH, GOMODCACHE and
GOCACHE pinned.

Without the change (internal/provider/models.go put back):

    go test ./internal/provider -run 'TestFetchKeepsTheModelsAFailedGeminiBaseListed|TestFetchDropsAGoneGeminiModelWhileAnotherProtocolFails'
    multiproto_models_test.go:713: picks after the Gemini base failed: [gpt-a], want [gpt-a claude-b]
    multiproto_models_test.go:824: picks after the Gemini list dropped a model: [gpt-a gpt-b claude-b claude-c], want [gpt-a gpt-b claude-b]
    FAIL (exit 1)

With it:

    go test ./internal/provider -run 'TestFetchKeepsTheModelsAFailedGeminiBaseListed|TestFetchDropsAGoneGeminiModelWhileAnotherProtocolFails'
    ok (exit 0)

    go test -tags nogui ./internal/provider -count=1
    ok  github.com/yetone/magpie/internal/provider  109.187s (exit 0)

    gofmt -l internal/provider/models.go internal/provider/multiproto_models_test.go   (prints nothing)
    go vet ./internal/provider                                                       (exit 0)
    GOOS=linux go vet -tags nogui ./...                                               (exit 0)
    GOOS=windows go vet ./...                                                         (exit 0)
    go build ./...                                                                     (exit 0)
    GOOS=linux go build -tags nogui ./...                                              (exit 0)
    GOOS=windows go build ./...                                                        (exit 0)

The maintainer's own reproduction of the first failure, run on 20ee273a
before anything was changed, is the same one line and exits 1:

    --- FAIL: TestZZGeminiSideKept (0.04s)
        zz_gem_test.go:81: picks after a protocol failed: [gpt-a], want [gpt-a claude-b]

The whole-repository `go test -tags nogui ./...` was not run: the change
touches only internal/provider, and that package's full suite is green.

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: multica-agent <github@multica.ai>
2026-10-13 13:42:56 +08:00
Kenoia 7df0a5bf32 catalog: a vendor's own model name is kept ahead of the catalog's, and fallback names never collide (#1188, fixes #1119)
Command Code's Flash Fast showed the catalog's "Flash", the same name as
plain Flash, so the picker had two "Flash" rows. An unprefixed `name`
from a vendor's /models now wins over the catalog fallback
(magpie_label and display_name still come first). A `Vendor: Model`
name such as OpenRouter's falls through to the catalog as before, so
OpenRouter's names don't change.

A catalog fallback that would give two ids one name keeps the id
instead. Exposed fills names only for unlisted picks and checks every
available name and id for a collision; listed picks keep exactly what
Available returned, Antigravity's id-only names among them.
TestNameOf's case-variant expectation changes on purpose: glm-5-turbo
and GLM-5-Turbo together keep their own ids.

Kenoia's PR head f538b19e, which conflicted with main in
internal/catalog/live.go and live_test.go; the conflict was resolved
keeping both main's live-name changes and this one.

Run on this tree (origin/main 848d2ea9 + the PR): gofmt -l clean;
go vet darwin, GOOS=linux -tags nogui and GOOS=windows on
internal/catalog and internal/provider; go test -tags nogui
./internal/catalog/ ok and ./internal/provider/ ok (805s, full
package, on the same change over 5b14ebf4), and -run Name|Catalog|Live
again on 848d2ea9. With the live.go fallback reverted, the new
live_test and model_names tests go red. Not tried against Command
Code's live /models with a real account.
2026-10-13 11:43:54 +08:00
ggbdpq 30f7ad0462 provider: a Grok window the id names without a k is signed and priced as its model
grokContextModels offers each window Grok lists beside the default as
<id>@<N>k, and grokWindowLabel writes a window that is no multiple of
1000 as bare digits (131072). grokWindowed took any size without the k
for no window at all: such an id went to Grok verbatim, as
x-grok-model-override "grok-4.7@131072" with no x-grok-context-window —
a model id Grok doesn't list — and pricedNames's grokWindow gave it no
price either.

What changed
- grokWindowed reads a bare-digit size as the window itself, as the
  label writes it; a k still means thousands.
- grokWindow (pricedNames) takes the window without the k too, so the
  id is priced as its model, as grok-4.7@500k is.

What was run
- New TestGrokSignsWindowWithoutK and TestGrokWindowWithoutKListPrice
  fail on the old code (the id sent verbatim as the override, no window
  header; ListPrice and MakerPrice give nothing) and pass with the
  change.
- go test -tags nogui -count=1 ./internal/provider ok; -race -count=5
  on the Grok tests ok.
- gofmt -l internal/ clean; go vet ./..., GOOS=linux go vet -tags nogui
  ./... and GOOS=windows go vet ./... clean but the known
  trayimage_darwin.go cgo -Wenum-conversion warning; go build,
  GOOS=linux go build -tags nogui and GOOS=windows go build ok;
  go test -tags nogui -count=1 ./... green under a temp HOME
  (TestPluginListSaysMiddleware once hit its 60s bound under the full
  run and passes alone and on a second full run; unrelated to this).
2026-10-13 10:40:35 +08:00
yetoneandmengyianx f31ae38aeb provider: Xiaomi MiMo is priced at xiaomi's list price, not its Token Plans' $0, and pay as you go looks only in xiaomi (#1873)
mengyianx found every pay-as-you-go MiMo call counted at $0.000:
models.dev's xiaomi-token-plan-cn, -sgp and -ams list all nine models
at cost 0 (the plan's per-token charge, not the model's price), the
preset's catalog was "xiaomi-token-plan-cn, xiaomi" at every region, and
catalog.PricedBy takes the first catalog with a cost field. makerCatalogs
puts the plan catalog ahead of xiaomi too, so the maker fallback gave $0
as well.

What changed:
- membershipCatalogs (never read for a price) gains the three
  xiaomi-token-plan catalogs, as #1370 did for Kimi Code. That covers
  ListPrice, MakerPrice and PricedName through makerPriceCatalogs.
  kimiCodeMember now checks a list of Kimi Code's plans of its own
  (kimiCodePlans), so a Xiaomi provider isn't taken for Kimi Code and
  its ids aren't mapped to Kimi's.
- Each Xiaomi region names its own catalog: plan-cn/sgp/ams
  "xiaomi-token-plan-<r>, xiaomi", pay as you go "xiaomi" alone. A plan
  user is priced at the API-equivalent price, the same meaning as #1370.
- PricedBy is unchanged: a catalog that lists a model at $0 still prices
  it at $0 (nvidia, modelscope have truly free models).
- docs/subsystems/providers-accounts.md says so.

Providers saved before this: the preset's own catalog stays
"xiaomi-token-plan-cn, xiaomi", the same string an existing provider
saved with the old default holds. normalize already lets a catalog that
equals the preset's or one of its regions' follow the region the
provider is at (the Tencent Cloud mechanism), on every read, so an old
default at pay-as-you-go reads as "xiaomi" and at Singapore as
"xiaomi-token-plan-sgp, xiaomi"; nothing is written to providers.json
until the user next saves it. Any other catalog the user typed is kept
as typed, and is priced right anyway because the plan catalogs are out
of pricing. The one value that can't be told apart is a bare "xiaomi"
typed at a plan region (the issue's workaround, which was for pay as
you go): it equals the pay-as-you-go region's catalog, so it reads as
that plan's "xiaomi-token-plan-<r>, xiaomi". Its prices are identical
either way; only the model-metadata lookup order differs. That is the
existing rule for every preset with region catalogs, kept rather than
special-cased.

Siblings: scanned the models.dev cache (read only) for catalogs whose
priced models are all or mostly $0. Of those, only kimi-code-plan-* and
xiaomi-token-plan-* are named by any preset or region. stepfun's
*-step-plan catalogs carry no cost at all, so they never shadowed a
price. alibaba/minimax/zai/zhipuai/volcengine/tencent coding and token
plan catalogs are all-$0 on models.dev but no preset uses them.

Tests (internal/provider/xiaomi_price_test.go, fixture
testdata/xiaomi_catalog.json cut from models.dev's real entries):
- TestXiaomiListPrice: every region, the old default, a user's own
  catalogs: mimo-v2.6-flash $0.14/$0.28/$0.0028, mimo-v2.6-pro
  $0.435/$0.87/$0.0036; MakerPrice; EffectivePrice of a saved provider;
  a relay's own $0 model ahead of xiaomi stays $0; a Xiaomi provider is
  not a Kimi Code member.
- TestXiaomiRegionCatalogs: each region resolves to its catalogs from
  the preset's, the old default and another region's; import links at
  each region; FromPreset; a user's catalog kept at two regions.

Broken by hand, each red, then restored:
- membershipCatalogs back to Kimi only: TestXiaomiListPrice FAIL, plan
  regions and MakerPrice at $0.
- region catalogs removed: TestXiaomiRegionCatalogs FAIL (api with the
  old default stays [xiaomi-token-plan-cn xiaomi], imports at sgp/ams
  get cn's).
- both: TestXiaomiListPrice FAIL, api with the old default at $0 (the
  reported bug).
- kimiCodeMember on membershipCatalogs: FAIL "a Xiaomi Token Plan
  provider counts as a Kimi Code membership".
- PricedBy's exact match skipping all-zero costs: FAIL "relay
  mimo-v2.6-flash: ... want its own $0".

Run: gofmt -l (nothing); go vet ./... on darwin, GOOS=linux -tags nogui,
GOOS=windows; go build on all three; go test -tags nogui -count=1
./internal/provider ./internal/catalog ./internal/cli ./internal/gui
./internal/usage, all ok, in a sandbox HOME with pinned caches.
Real use: built binaries before and after, sandbox HOME with a copy of
the real models.dev cache and a providers.json holding the reporter's
saved state. `magpie model price xiaomi/mimo-v2.6-flash` printed $0/$0
before and $0.14/$0.28 after; an old-default provider at Singapore went
$0 -> $0.14/$0.28 and shows catalog "xiaomi-token-plan-sgp, xiaomi";
one with the user's "openrouter, xiaomi" kept it; providers.json was
byte-identical afterwards. Not tried: a real MiMo key or call, the GUI
editor's region switch, the full go test ./... suite.

Co-authored-by: mengyianx <106875577+mengyianx@users.noreply.github.com>
2026-10-13 05:57:40 +08:00
yetone 841af36bfc gateway: models the user disabled are refused on every route, and leave every list (#1867)
oxsean asked for one place to turn a model (claude-fable-5) off for good:
not reached by a direct request, an old session, a routing group member,
a fallback, a sub-agent, count_tokens or a decision model.

What changed:
- settings.DisabledModels: patterns, an exact id or a glob (* any run, /
  included; ? one), matched ignoring case against provider/model, the
  bare id and its last segment (provider/disabled.go). Empty by default,
  so nothing changes for anyone who doesn't set it.
- Lists: buildEntries (entriesOff) leaves a disabled model out of the
  catalog, so /v1/models, agents' model files and pickers, Codex's list
  and every group go without it; membersIn skips it as a member, Deciders
  as a decision model; codexModels drops Codex's own disabled slugs and
  codexListTag changes so Codex refetches.
- Requests (gateway/disabled.go): 403 "model <id> is disabled in magpie"
  in each API's error shape, at #882's choke points: serve (idOff),
  perKeyBarred (no candidate: group next member, provider Fallback),
  count_tokens and Gemini :countTokens, serveSystemOne,
  serveDecisionGroup and postDecide, draw/video/embeddings, and
  codexBackend for Codex's own bare models. A group with a member left
  goes on without it; one with none left is refused naming them. A bare
  id the catalog no longer has is refused as disabled, not 404. A Codex
  sub-agent pick onto a disabled model stays on its lead's model.
- An unreadable settings.json is never "none disabled": the list read
  last stays; with none read, every request is refused; nothing is
  written over the file.
- CLI: magpie model disable <model|glob>..., enable ..., disabled
  (list-disabled).
- GUI: Settings > Models > Disabled models: each pattern with the models
  it matches now and Enable; Disable... opens the model picker, which
  also takes a typed glob. Says only requests through magpie are covered.
  POST /api/settings/disabled-models; POST /api/settings keeps the list.
  Strings in zh, zh-TW, ja, de.
- docs/subsystems/gateway-routing.md: Disabled models section.

What was run (worktree at origin/main 091593f7d, private GOCACHE, temp HOME):
- gofmt -l clean; go vet on darwin (touched pkgs), GOOS=linux -tags nogui
  ./..., GOOS=windows ./... clean; go build ./...
- go test -count=1 ./internal/provider ./internal/gateway ./internal/cli
  ./internal/gui ./internal/settings: all ok (gui after adding the field to
  TestSettingsSaveKeepsWhatItDoesNotSend's fixture, which it asked for).
- node --test internal/gui/tests/disabled-models.test.cjs: 16/16 (chromium
  + webkit, en/zh/ja/de, 1100/420); neighbouring Settings > Models tests
  and i18n-keys: 131/131.
- Broken by hand, each turned TestDisabled* red: serve's idOff (404
  instead of 403), perKeyBarred's filter (fallback reached spare), the
  catalog filter (/v1/models and Codex list), countOff (count_tokens 200),
  postDecide's check (decision call went out).
- Not tried with a real vendor account or a real agent.

Ref #1867
2026-10-13 05:34:13 +08:00
yetoneandwangru8080 b3805203d8 gateway: drawing reads a relay's whole model list for which key serves an image model, and a key's 404 about the model asks the next key (#1657)
What: Provider.Serves now reads a new catalog.LiveAll (the fetched list
with image and video models kept) instead of live(), which drops Draws and
Films models. The draw key loop and the custom video path move on to the
next key when a key answers 404 whose body says the model isn't served
(keyLacksModel = 404 + modelRefused's wording); any other 404 still stops.

Why: wangru8080's analysis on #1657. A relay whose per-key lists name
gpt-image-2 under one key only still had drawing try a key that lacks it:
Serves read a list with the image model filtered out, so every key looked
unlisted, and that key's 404 "Model ... is not supported by any configured
account in this group" ended the loop instead of asking the next key.
Embeddings already move on any error short of the last key.

Run (sandbox HOME, private GOCACHE, worktree at origin/main 97dfed0f3):
- TestDrawGoesPastAKeyTheRelayListsForText, TestCustomVideoGoesPastAKeyThatLacksTheModel.
  Break checks: old Serves -> subtest 1 asks key-a first; draw loop without
  keyLacksModel -> subtest 2 gets the 404; video loop off -> 404 on start.
  A bare 404 still never reaches key-b.
- gofmt -l; go vet ./... (darwin), GOOS=linux -tags nogui, GOOS=windows;
  go build for all three.
- go test -tags nogui ./internal/gateway ./internal/provider
  ./internal/catalog ./internal/codexcat: all ok.
Not tried against a real relay.

Co-authored-by: wangru8080 <22983744+wangru8080@users.noreply.github.com>
2026-10-13 05:05:23 +08:00
yetone fd03592331 provider: WorkBuddy AI's GLM models are text-only, so magpie's image-describing model reads their images; the plugin to 0.1.16 (Yirasumi on Discord)
What: for workbuddy-ai alone, a model whose id starts with glm- is listed
with ImageInput false (wbSite.textOnly), whatever /v3/config's
supportsImages says: in the list fetched, in the built-in list shown
before it, and in a list saved before this change (Provider.available).
The workbuddy movers' min goes to 0.1.16, where the plugin does the same
(magpie-community/plugins cb90931).

Why: checked on 2026-10-13 with the owner's real WorkBuddy AI account.
www.workbuddy.ai/v3/config marks every model supportsImages: true, but
its server takes the image out of a chat to glm-5.3-flash, glm-5.3 or
glm-5.2 and puts "[System reminder: the current model does not support
images. Content filtered. ...]" in its place. Its other models read
images, and WorkBuddy (China)'s glm-5.3-flash does too, so China and the
other families are left as the config says. A user's own answer in
Settings (ModelImages) still wins: entryFor applies it over the list.

Run:
- go test ./internal/provider (full, ok); go test ./internal/gateway
  -run 'WorkBuddy|WB|Vision|Describ|Image' (ok).
- TestWorkBuddyAIGLMIsTextOnly fails with textOnly turned off by hand;
  TestWorkBuddyAISavedGLMIsTextOnly fails without the models.go case.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- Sandbox gateway (own HOME, port 3486, built-in WorkBuddy AI login from
  the owner's migration backup, nothing live written): /v1/models lists
  glm-5.3-flash, glm-5.3, glm-5.2 as text, deepseek, kimi, gemini, gpt,
  grok with image. A blue|yellow split PNG sent to glm-5.3-flash was
  described by workbuddy-ai/deepseek-v4.1-flash (Routing kind "vision"),
  and glm-5.3-flash answered "left: blue, right: yellow". With
  modelImages {"workbuddy-ai/glm-5.3": true} in the sandbox settings,
  glm-5.3 listed image again and glm-5.3-flash stayed text.

Not run: the moved (plugin) path through a sandbox app; the plugin's own
bun tests cover its list, and magpie maps its input.image as ImageInput.
2026-10-13 02:03:25 +08:00
yetone 10d60b1899 provider: a provider saved with Select none serves no models, unlisted or not (#1818)
Select none saved `models: []`, which omitempty wrote as no models key at
all, so the provider read back as "no picks" and served the first 24 of
the vendor's list on /v1/models, in auto groups and on the card, while
the editor said none would be served.

What changed:
- Provider.NoModels (json noModels) records the choice; ServesNone() is
  NoModels with no picks. A file with no models key still serves the
  vendor's list as before.
- Exposed() is empty for it, so the catalog, /v1/models and auto groups
  leave it out; resolveIn refuses an explicit pid/model to it; listedBy
  and Deciders skip it (a decide-only provider is still a decider).
- SetModels and normalize clear NoModels once there are picks.
- GUI: the editor sends noModels on Save, an edit that omits it keeps it,
  the card's exposed count is 0, the hint says nothing is served; with
  unlisted the dashed chips explain they are only for groups. Strings in
  en, zh, zh-TW, ja, de.
- CLI: `magpie provider models <id> none`.
- docs/subsystems/providers-accounts.md describes it.

Decision (owner delegated): Select none means none, whether or not
unlisted is on; unlisted keeps meaning "hide from the list, still
usable by groups that name it".

Run:
- go test ./internal/provider ./internal/gui ./internal/cli -count=1
  (green; second pass ran too) with private GOCACHE and sandbox HOME.
- Broke Exposed's ServesNone check: TestSelectNoneServesNone red
  ("exposed 24"); broke resolveIn's: red ("watched/m0 resolved"); broke
  the GUI keep line: TestProviderSaveSelectNone red ("exposed 24").
- GUI tests chromium + webkit, 5 languages: provider-none-picked 20/20,
  provider-draft-picks 10/10 (red with noneChosen broken), plus 12
  related model/group/editor tests green.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows clean for the
  three packages.

Not run: the gateway package; Codex native model narrowing is unchanged.
searcher-pick.test.cjs fails 3 webkit cases (hover timeout) identically
on the unmodified base 556c01c80, unrelated.
2026-10-12 23:45:06 +08:00
yetone f340aecabc provider, agent: a context window the user typed on a routing group or a provider is the one Codex and Claude Code run to, not magpie's default 272K (#1809)
A DeepSeek V4.1 Flash routing group set to 500K reached the catalog as
Context 500000, but magpie's default working window (settings.Working,
272K, #876) cut it: Codex's magpie-models.json said context_window
272000, max_context_window 500000, and Codex runs to 95% of
context_window, the ~258K in the report. Claude Code showed 500K
(CLAUDE_CODE_MAX_CONTEXT_TOKENS) while magpie also wrote
CLAUDE_CODE_AUTO_COMPACT_WINDOW=272000, so it compacted at 272K too and
only displayed the larger number.

From Codex's source (openai/codex @0c7362d, codex-cli 0.162.1):
config.toml's model_context_window sets context_window to
min(value, max_context_window); usable = context_window x
effective_context_window_percent (95 by default); the auto-compact
limit is min(model_auto_compact_token_limit, 90% of context_window).
magpie writes neither config key and still doesn't, so a user's own
model_context_window keeps working as before.

magpie's default compaction now gives way to a window the user typed,
as it already gives way to Claude Code's own autoCompactWindow
(602d4ec6):
- provider: Entry.WindowSet marks a window typed on the provider for
  the model or all its models (ContextOf) or on the group (a size).
  CompactFor answers the threshold Codex is told: a per-model or
  provider Compact at first (CompactSet), else that whole typed window
  when no size is typed in Settings, else 0 (the default). Used by the
  gateway's Codex list (codexListed) and WindowTyped for Claude Code.
- agent: magpie-models.json (and the WSL twin) take CompactFor, so the
  group says context_window 500000 with no max; Claude Code gets no
  AUTO_COMPACT_WINDOW on a typed window unless Compact at is typed in
  Settings.
- A model nobody typed a window for keeps 272K, and a Compact at size
  typed in Settings still comes before a typed window.
- gui: unchanged. f36e744c3 shortened Settings > Long conversations to
  one line upstream; it no longer spells out precedence.

Run:
- internal/agent TestTypedWindowReachesCodexAndClaudeCode: group 500K,
  provider per-model 400K, an untyped 1M model, then Compact at 300K;
  checks magpie-models.json, the gateway's Codex list and Claude Code's
  env. On the old code it fails 6 ways (272000/500000 and 272000/400000
  on disk, list Compact 0, Claude compact 272000), checked by reverting
  the non-test files.
- Sandbox HOME with the built binary and real codex 0.162.1
  (`codex debug models`): old binary group/ds-flash 272000 / max
  500000; new 500000, no max. A per-model `context` override of 1m:
  old 272000 / 1000000, new 1000000. `magpie model compact 300k`:
  300000 with the typed window as max. Claude Code in the sandbox: old
  wrote AUTO_COMPACT_WINDOW=272000 + MAX_CONTEXT_TOKENS=500000, new
  only MAX_CONTEXT_TOKENS=500000.
- gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows), the
  three builds, go test -tags nogui ./...: 45 packages ok. At load
  average ~115 agent, gateway, library and provider hit the 10m
  timeout with no failure. Rerun with -timeout 40m, agent, library and
  provider pass. gateway failed three timing tests that pass 3 of 3
  alone: TestOTelWaterfallIncludesUnbilledFallback (#1794, already
  fixed on origin/main by 6ae6b3402), TestCodexHeardWithinItsIdleTimeout
  (#1800, open) and TestIntentClassifierFails (filed as #1829).

Not tried: a real `codex exec` turn against a sandbox gateway (the
catalog Codex reads was checked with `codex debug models` instead), and
Windows itself; the path is the same Go code on every OS.
2026-10-12 23:22:33 +08:00
yetone b0a904bd9a provider, catalog: a model listed with a 512-token window is told to agents at models.dev's window, or none, never 512 (H20 on Discord)
H20 and others saw free models (hy3, Cline's free ones) at a 512-token
context window, and Claude Code and Codex then treated them as unusable:
they compact at once. Every agent and the gateway read a model's window
from its catalog entry (Entry.Context, from WindowOf and ListedWindow),
which took any positive window the vendor's or plugin's list gave as said.

Where the 512 itself comes from isn't seen here: models.dev's cache
(2026-10-12), Cline's live /ai/cline/models and recommended feed, the
WorkBuddy and Cline plugins' static lists and magpie's own code give no
window under 4095 for any of these models. It is in a vendor's live list
read at run time (WorkBuddy's /v3/config maxInputTokens or a plugin's
list); so the floor is where every listed window is read:

- catalog.LeastWindow (2048) and catalog.Window: a window under it is not
  known. The smallest real chat windows are about 4096
  (gpt-3.5-turbo-instruct's 4095, mythomax's 4096) and stand.
- mdModel.window: a models.dev limit under it doesn't vote, so the other
  limit, or nothing, answers.
- ListedWindow: a vendor's window under it falls back to models.dev's
  for the model, else 0 (the agent's default).
- pluginCatalog: a plugin's input or context under it is none, so a
  512 prompt cap under a 192K window leaves 192K.
- planModels (Cline): a free model's 512 takes models.dev's too.
- A window the user sets (Contexts) is theirs, however small.

Tests, with the literal 512: TestTinyListedWindowIsUnknown (a Cline
plugin listing cline-free/mimo-v2.6-flash and cline-free/hy3 at 512 is
served at models.dev's 1048576 and 192000; one nothing knows at 0; a real
4096 stands; ListedWindow on a built-in's hy3 at 512 gives 192000; a
user-set 1024 stands) and four new cases in
TestWindowClampsInputAboveContext. Both fail on the code before (512, want
1048576 / 192000 / 0) and pass with it.

Not verified: the reporter's own list, so which vendor sent 512 is
inferred, not seen; not tried in a real Claude Code or Codex.

Run for both commits, on origin/main 94aa15397, sandbox HOME,
private GOCACHE (the shared one was being emptied under the build), load
average 70-86: gofmt -l clean; go vet ./... (darwin) and go vet -tags nogui
./... with GOOS=linux and GOOS=windows pass; go build -tags nogui ./...
passes. go test -tags nogui: catalog, agent, plugin, library pass;
provider -run 'Window|Listed|Plugin|Cline|Free|Catalog|Models' passes, and
the whole of provider passed before the rebase (794s) but for
TestCopilotSecretToolUsername, which fails only inside the command sandbox
(its secret-tool script can't run there) and passes outside it; gateway
-run 'TestVertex|Credit|Rest|Quota|Rate|Free|Plugin' passes. The whole
gateway and provider packages hit their 25m and 9m timeouts on this
machine's load, with stacks in tests still running (vertex, signin_proxy),
not stuck; those two packages weren't run whole at this head.
Rebased again onto 24350a372 (the doc's Verification list took both
lines): go vet -tags nogui ./internal/... and go test -tags nogui -run
'Credit|Rest|Quota|Rate|Free|Group|Window|Listed|AutoMode|Codex' on
gateway, catalog and provider pass.
2026-10-12 22:33:07 +08:00
yetone 974aaf7e22 gateway: an account out of credits on a model that costs them still serves its subscription's free models (Creat.wu on Discord)
Creat.wu (WorkBuddy AI) spent the credits on glm-5.3-flash, switched to a
free model, and magpie skipped the account. An out-of-credit refusal
rested the whole account (restKey) for 30 minutes: through the WorkBuddy
plugin, whose `explained` passes 14018 on as insufficient_quota, and on the
built-in, whose raw 429 {"error":{"data":{"code":14018,"msg":"Credits
exhausted…"}}} matched no credit word and was read as a rate limit, the
account benched a minute and longer on repeats.

- provider.PaidBesideFree: the model costs credits while the subscription
  lists others Free (catalog.Model.Free: WorkBuddy's x0.00, Qoder's
  is_free, Cline's free models, Command Code's).
- restAfterMarked: out of credit or quota on such a model rests that model
  alone (restID). A free model the vendor still refuses (WorkBuddy refuses
  0-rate models to an account with no package) rests the account on its
  own refusal, as before.
- brokeWords takes "credits exhausted", so the built-in's 429 is out of
  credit, not a rate limit. A rate limit naming credits in passing stays one.
- The fix is in the gateway, which both moved (plugin) and built-in users
  go through, so no plugin release or mover min is needed.
- docs/subsystems/gateway-routing.md says so, with the tests to run.

Tests: TestCreditsExhaustedIsOutOfCredit (literal 14018 body, raw and as
the plugin passes it) and TestOutOfCreditLeavesFreeModels (fake plugin,
two keys, deepseek-v4-pro answered 429 with the plugin's body, then fake-1
must go to the first key). With the restAfterMarked change taken out the
second fails (fakeco@api key rested 30m for credit); with brokeWords back
as before the first fails (rate, want credit). Both pass with the fix.

Not done: credit windows still count free models in Smart/Pace order and
the 98% affinity stop; the account isn't held out there (Credits has no
reset, so Full is 0), only ordered later. Not tried with a real WorkBuddy
AI account. gofmt, vet and the full suite: see the next commit's body.
2026-10-12 22:33:07 +08:00
yetone cbc96b5995 provider: Cursor's grok-4.7 fast ids are priced at Cursor's fast rate, so a routing group of them counts its cost (TradingLife on Discord)
A group of Cursor's and Grok's Grok 4.7 fast recorded calls with no cost.
Cursor's ids grok-4.7-fast, grok-4.7-<effort>-fast (and at a window,
@500k) had no price anywhere: no models.dev catalog lists them, and
30431e04 left fast ids unpriced on purpose rather than make one up. So
every usage record on them (provider cursor, model grok-4.7-fast) was
unpriced, and the group, whose price needs every member's, had none.

Cursor publishes the price (https://cursor.com/docs/models, read
2026-10-12): Grok 4.7 (Fast) $4 input / $1 cache read / $12 output per
million, "Fast mode for long context (>256k) is billed at 3x standard
rates". Provider.ListPrice now gives a Cursor account (the built-in's or
the Cursor plugin's) that price for its fast Grok 4.7 ids, with a tier
above 256k at $6 / $1.5 / $18. Scoped to Cursor: elsewhere a "-fast" Grok
id is a model of its own (xAI's grok-4-fast is $0.2 / $0.5), and Grok
Build's grok-4.7-build-fast (Grok's own list) has no published price, so
it stays unpriced, as does a fast id of a model Cursor gives no fast
price for.

Run: go test -tags nogui ./internal/provider ./internal/sessions
./internal/usage (ok); new TestCursorGrokFastPrice fails with the lookup
switched off; gofmt -l clean. Not done: a group member sent fast through
Group.Fast (the plugin's grok-4.7@256k with service_tier priority) is
still recorded at the standard price, since a usage record doesn't say
it went fast; not checked against the reporter's own usage log.
2026-10-12 22:08:57 +08:00
yetone 94aa153973 tui, provider, serve: a signed-in account's models are fetched at start, so Routing offers Cursor's whole list without m (#1789, reyoung)
The terminal and `magpie serve` never called provider.FetchNew, which the
window calls at start: a signed-in Cursor account's list exists only at
Cursor, so the TUI's Routing pickers (and a headless gateway's /v1/models)
offered the fallback cursor/auto alone until the list was fetched by hand
with m on the Providers page.

- tui: Init fetches the new lists (fetchModelsCmd, alongside the catalog
  sync). A model picker open when they arrive (Routing members, the
  classifier, a provider's models, an agent's model field) is filled in
  place through its relist, keeping its filter and the model under the
  cursor. A list left missing (no network) is asked for again a minute
  later (modelsRetry). Built on reyoung's branch and test.
- serve: FetchNew at start, again each minute while a list is missing.
- provider: FetchNew reports whether a list is missing, and waits for a
  CLI asked who is signed in for the first time (awaitIdentities), then
  lists the accounts again. With the real Cursor account in a fresh
  sandbox, `cursor-agent about` answered after a look's 3s firstAsk, so
  FetchNew saw no Cursor account and `magpie serve` still listed 1 model
  with the TUI fix alone. The window's startBackend gets the same wait.
- docs: providers-accounts.md says who fetches the lists and when.

Run:
- internal/tui TestTUIFetchesSubscriptionModels (6 views) and
  TestTUIAsksAgainForAMissingList, -race x3; red with the Init fetch,
  the relist, the cursor restore or the retry tick each removed by hand.
  A first `about` slowed to 12s injected: passes (the test re-asks).
- internal/provider TestFetchNewWaitsForASlowSignIn: red without
  awaitIdentities (no provider "cursor"); TestFetchNewAccount covers the
  missing result.
- Real Cursor account, sandbox HOME with a keychain holding only Cursor's
  two items: TUI on main showed cursor/auto only in Routing; the fix shows
  the full list and "24 models" on Providers. `magpie serve`: main 1
  Cursor model at /v1/models, the fix 24 within 5s.
- gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows), go test ./... in a
  sandbox HOME.

Not tried: Linux and Windows real Cursor CLIs (the fake CLI tests skip on
Windows); Devin's CLI identity goes through the same wait but wasn't
tried with a real account.
2026-10-12 20:49:41 +08:00
yetone f8214ec972 provider: a third-party Anthropic API that refuses x-api-key and Authorization together is sent one, picked in the editor or learned from its 401 (Aloha on Discord)
magpie sends a user's own Anthropic-compatible provider its key in both
x-api-key and Authorization: Bearer. Some relays answer 401 "鉴权 header,
x-api-key 和 Authorization 不可以同时存在", so every request failed.

- Provider.AuthHeader ("" both, "x-api-key", "bearer") picks which
  AuthHeaders sends on the Anthropic protocol. Anthropic's own API,
  Bedrock, Azure, Vertex and subscription accounts are untouched: they
  send x-api-key alone (or their own) whatever it says, and BothAuth()
  is false for them.
- Left at both, a 401 whose body catalog.BothAuthRefused tells as that
  refusal (names both headers and says they can't be together, Chinese or
  English) is asked once more with x-api-key alone, then Bearer alone
  (RetryOneAuth, in the gateway's forwardOnce and the provider test's
  probe; the model-list fetch through catalog.fetchOne too). The first not
  answered 401/403 is saved (LearnAuthHeader), never over a pick the user
  made. A request carrying the user's own Authorization/x-api-key header
  is never retried; any other 401 is passed on as it came, asked once.
- The editor has a "Key header" row (Both / x-api-key /
  Authorization: Bearer, the app's segmented control) while the provider
  has a third-party Anthropic URL; strings in zh, zh-TW, ja, de.
- docs/subsystems/providers-accounts.md: an "Anthropic key header" row.

Run (sandbox HOME, GOCACHE/GOMODCACHE pinned, set -o pipefail):
- gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; GOOS=linux/windows go build.
- go test -tags nogui ./...: 47 packages ok; agent and gateway timed out
  at 10m under load average ~50-98 (other sessions' test runs), so rerun
  with -p 1 -timeout 60m: agent ok; gateway ok but for
  TestOTelWaterfallIncludesUnbilledFallback, a load flake unrelated to
  this (it reads only the first 200ms OTel export; passes 5/5 alone),
  filed as #1794.
- New tests: internal/provider/authheader_test.go (official Anthropic and
  Bedrock unchanged for every pick; Aloha's 401 body retried with
  x-api-key and kept; Bearer-only relay learns bearer; the model list
  learns; another 401 and the user's own header aren't retried; a user's
  pick isn't overwritten), internal/gateway/authheader_test.go (a
  /v1/messages turn through the gateway to such a relay succeeds and the
  next Chat Completions turn goes with one header first).
- Broken by hand: RetryOneAuth returning at once and AuthHeaders ignoring
  the pick -> TestAuthHeaderChoice, TestRetryOneAuthLearns,
  TestRetryOneAuthBearer, TestOneAuthHeaderRelay FAIL; the list retry off
  in live.go -> TestListLearnsOneAuth FAIL.
- GUI: provider-auth-header.test.cjs 20/20 in chromium and webkit, en and
  zh, 390px wide; the editor's other tests (provider-*, nokey-editor,
  editor-short-window, segs-*, vertex-editor) 439/440, the one
  (provider-discovery, chromium zh) passing 26/26 alone.

Not tried: a real relay of Aloha's; the retry is built from the body the
user quoted.
2026-10-12 20:18:31 +08:00
yetone c533499446 provider, gui, cli: a group can keep its models out of the lists agents see, offered through the group alone (#1783)
cybershape asked for a client's model list to show only a group, not
every model behind it. A provider could already be kept for routing
groups (Provider.Unlisted), but that hides the whole provider, and the
models a group names may come from providers used elsewhere too.

Group.Unlists (json "unlists"): the models a group names (a member fixed
at an effort counts as its model) and those its patterns match leave
Catalog(), so `magpie models`, /v1/models and every agent's list
(CatalogFor) show the group without them. They stay in Served(), so a
group routes over them and a request naming one as provider/model is
still answered, and Unlisted() returns them for the GUI as it does an
unlisted provider's. A nested group keeps its own setting; a group
switched off or hidden keeps nothing out. With no group unlisting,
Catalog() takes a fast path and is unchanged.

- Routing view: the group editor's "Model lists" (Its models too / The
  group alone, segmented, with a hint), saved with Save; the card shows
  "Its models unlisted". Both group Save paths send unlists. zh, zh-TW,
  ja, de.
- CLI: `magpie group set <id> listed=no|yes`; `magpie group <id>` shows
  listed: no.
- TUI: the group member picker offered Catalog(), so models kept out of
  the lists (an unlisted provider's, before this too) couldn't be put in
  a group from the TUI. It offers Served(), as the GUI's picker does.
- docs/reference.md, Routing groups: listed=no.

Product call: a per-group switch, off by default, rather than hiding
members of every group, so existing lists don't change under anyone.

Run:
- go test ./internal/provider -run 'Group|Catalog|Unlisted|Served',
  ./internal/gui, root package, ./internal/tui: ok.
  TestGroupUnlistsItsModels fails with the Catalog filter removed;
  TestMemberOptionsOfferUnlistedModels fails with the picker on
  Catalog(); TestApplyGroupPairs covers listed=no/YES/maybe.
- GUI group-unlists.test.cjs, Chromium and WebKit, en zh zh-TW ja de, at
  1100px and 420px: 20/20. i18n-keys: ok.
- gofmt; go vet darwin, windows, linux (-tags nogui): clean.

Not tried: with the reporter's own client; a real agent's model file
written after toggling (CatalogFor is covered by the test).
2026-10-12 19:38:18 +08:00
yetone 9964535adc provider: a model models.dev has just listed without its reasoning levels takes its family's, so Codex's picker offers them for a relay's gpt-6.1-sol (NextCommit on Discord)
NextCommit's Codex showed no reasoning-effort picker for a relay's (an
OpenAI-compatible key provider) gpt-6.1-sol, while gpt-6-astra had one, and
magpie's log said the effort went from none to low. models.dev had listed
gpt-6.1-sol as a reasoning model but without reasoning_options yet, or not
at all, so magpie knew no levels for it: Codex's catalog got
supported_reasoning_levels [] (no picker), and the gateway, not knowing
"none" was one of the model's levels, sent Codex's "none" as "low" (#899).

What changed:
- catalog: a thinking model with no levels of its own and no budget takes
  the levels of the newest model of its models.dev family (same provider,
  thinking, with levels) released on or before it (mdProvider.levels).
  Used by Provider and ListedBy. A model with its own levels, a budgeted
  one, one that doesn't think, or one with no family is as before.
- catalog.KinEfforts: for an id no provider lists, the levels of the newest
  listed model of the same shape with the version numbers left out
  (gpt-6.1-sol -> gpt-#-sol), never a budgeted or non-thinking one.
- provider.borrowedEfforts: tries ListedBy, then EffortsOf, then
  KinEfforts. Entry.Efforts, which every agent's model list is built from
  (Codex, Claude Code, OpenCode, dsh, ...), goes through it, as do Known,
  Levelless, groups and plugins.
- Xiaomi's mimo, which takes a thinking switch only (#214), still gets no
  levels; gpt-4.1 gets none.

With levels known, an effort the user picks in Codex goes through as
picked. The none->low mapping remains for models whose levels are still
unknown (#899).

What was run:
- New tests: TestFamilyLevels (catalog) and
  TestNewModelTakesItsFamilysLevels (provider, Codex catalog levels for
  relay/gpt-6.1-sol). Both fail with levels() and the KinEfforts call
  neutered (levels "" against the family's), and pass with them.
- Real Codex CLI 0.162.1 under a sandbox HOME against a sandbox magpie
  gateway (127.0.0.1:3592) and a fake relay (127.0.0.1:3591) listing
  gpt-6.1-sol and gpt-6-astra. The models.dev cache had reasoning_options
  stripped from every gpt-6.1-sol entry to match the reporter's.
  - Built from origin/main: magpie-models.json gave relay/gpt-6.1-sol
    default None, levels [].
  - With this change: default medium, levels none..max,ultra.
  - Codex /model showed "Select Reasoning Level for GPT-6.1 Sol · relay".
    Picking Medium, High and None sent reasoning_effort "medium", "high"
    and "none" to the relay.
- gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; GOOS=linux and GOOS=windows builds: all
  clean.
- go test ./... under a temp HOME, with GOCACHE and GOMODCACHE
  pinned. Every package passed except four that hit the 10-minute default
  timeout with load average ~40 (TestCopilotSecretToolUsername's 5s
  secret-tool wait as well). Rerun with -timeout 40m -p 2, internal/agent,
  gateway, library and provider all passed.

Not tried: the Claude Code, OpenCode and dsh model files written for the
same relay model; they take Entry.Efforts like Codex.
2026-10-12 19:02:25 +08:00
yetone 2df2e0886d plugin, provider, gateway: a plugin's model is listed with every kind it takes and gives (audio, video, pdf), not image alone (#1595, tkhs101)
The plugin host read a model's capabilities.input only for "image", and
fromModelsDev hard-coded output to text, so /v1/models listed
opencode-zen-free's muse-spark-1.3-contributor-free (models.opencode.ai:
input text/image/audio/video/pdf) as ["text","image"] with no output.

- host.js: fromModelsDev and the config merge keep modalities.input and
  .output whole; the listing sends inputs/outputs, the kinds the
  capabilities object marks true, in OpenCode's order.
- plugin.Model gets Inputs/Outputs; pluginCatalog puts them on
  catalog.Model's new InputModalities/OutputModalities (input only where
  the plugin said what it takes, as ImageInput already is).
- catalog: models.dev entries and a vendor's live list (now reading
  modalities.output) fill the same fields; Decorate carries the catalog's
  when the live list says nothing, beside ImageInput.
- provider.Entry.Modalities() is what the gateway lists: the source's
  kinds, with "image" still decided by Images, so the user's own
  "takes images" override still wins and the other kinds stay.

Not changed: the 7 models the report lists as having lost their levels
have reasoning_options [] upstream (models.opencode.ai), so "reasoning,
no levels" is what they are; mimo-v2.6-flash turns away levels (#214).
DSH's model kinds and Muse's list still say text/image only.

Tests: TestPluginModelModalities (gateway) with the reporter's literal
metadata: muse-spark's config as opencode-zen-free 0.1.3's configModels
writes it, and mimo-v2.6-flash-free's capabilities as its models hook
lists them; a model said nothing of stays unlisted, and the image
override drops image only. TestFetchedModalitiesKeepEveryKind (catalog).
Broken by hand: host.js without inputs gives the report's [text image]
(red); Entry.Modalities without the Inputs branch (red); Decorate
without the fill (red). Run: go test catalog, plugin, provider, gateway;
gofmt -l; GOOS=linux and windows go vet on the four; go test ./...
green on 76db4c6c2+this; after rebasing on e9b16ca18 the four packages
again: catalog, plugin and gateway green; provider red once in a run of
all four together (the failing test's name was cut off by a tail), then
green 3 runs of 3, two of them concurrent.
2026-10-11 20:56:21 +08:00
yetone 9852eeb07a provider: a key whose model list didn't answer still takes requests, not left out as unlisted (#1598, wuwei0727)
A provider with several keys keeps the first in key/keyName and the
rest in keys; that split is how it is stored. When the vendor's /models
didn't answer the first key (a 429, a timeout) or a key was added since
the last fetch, the per-key catalog had no list carrying it, and
Provider.Serves read that as "this key sees none of the models". The
gateway's perKeyBarred then put it in unlisted on every request, and
Routing showed four of five keys.

Serves now treats a key that no list marks as unknown, which serves: a
failed list is not an empty one. A key whose own list did answer still
serves only what that list has. Nothing in the saved keys changes.

TestCountTokensKeyFailover's k-unlisted stood for a key outside m1's
list by being in no list at all, which now reads as unknown. Its list
now answers with another model (m2), which is the case the test guards:
it is still skipped.

Run: TestKeyWithNoListStillServes (the reporter's shape: xx1 in key,
xx2..xx5 in keys, xx1's list answers 429, xx5 lists one model) failed
before the fix and passes after; go test -tags nogui ./internal/provider
and ./internal/gateway ok; the full suite found the count_tokens fixture
above, nothing else; gofmt -l clean; GOOS=linux and GOOS=windows go vet
clean. Not tried: the reporter's own providers.json (the attached zip
returned 404) or a real multi-key vendor. A key whose list answers
empty is now tried too, as nothing marks it.
2026-10-11 20:09:14 +08:00
yetone b755607e63 provider: the built-in Grok offers each context window Grok lists, grok-4.7@500k beside grok-4.7, as the CLI's /context-window does (#1608, yhong91)
Grok's /v1/models lists each model at context_window 256000 (the
default) and context_windows [256000, 500000]. parseGrokModels read only
context_window, so magpie's catalog had every Grok model at 256K while
the Grok Build CLI offers 500K.

Now, as the grok plugin does since 0.1.12 (plugins#83, for moved users):
- grokContextModels offers the default at the plain id (a saved agent
  stays where it was) and each other listed window beside it as
  <id>@<N>k, named "<name> @ <N>k", Context that window. A model whose
  list has one size, or none, stays one model.
- grokSigned sends grok-4.7@500k as model grok-4.7, with
  x-grok-model-override: grok-4.7 and x-grok-context-window: 500000, the
  header the CLI 1.0.50 sends for /context-window 500k. The body is
  rewritten in the signer because Prepare runs before Sign, which reads
  the window from the prepared body.
- pricedNames prices grok-4.7@500k as grok-4.7 (grokWindow), as it
  already prices grok-4.7-xhigh; only Grok ids are read this way.

Not taking the largest window as context_window, as the issue suggests:
the CLI asks for 500K with the header, and the plain id keeps asking at
the default as before.

Run:
- HOME=<temp> go test -tags nogui ./internal/provider/: ok.
  go test -run 'Grok|Price' ./internal/gateway/: ok.
- Broken by hand: ignoring context_windows turns
  TestParseGrokModelsWindows red; not setting the header or rewriting
  the body turns TestGrokSignsWindow red; dropping grokWindow turns
  TestGrokEffortListPrice red.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/provider clean.
- The same wire request (body model grok-4.7, x-grok-context-window:
  500000) answered 200 on a real SuperGrok account through the plugin
  during plugins#83's review.
Not tried: the built-in itself against a real account; whether Grok
compacts any differently at 500K.
2026-10-11 20:06:04 +08:00
yetone 88519703cd provider: a magpie left running lists the plugins' models again every hour, and a model a plugin dropped leaves the picks (Jeremy.Zhou on Discord)
Jeremy.Zhou asked that the free-models plugin's dropped models go and new
ones come by themselves. A plugin's list was read on start, sign-in, a
plugin change or Refresh, never again while magpie ran; and Refetch skipped
dropGonePicks for plugin providers, so a dropped model stayed picked.

- KeepPluginsListed, started beside KeepRetiringMoved in the gateway's
  ListenAndServe, asks the plugins again a minute after start and then
  hourly (plugin.Providers, 2 min timeout). A failed ask logs and keeps the
  lists. A list that fell back (vendor unreadable) drops nothing, and the
  last read list stays the comparison for the next ask (keptListed).
- dropGonePluginPicks drops a pick the old list had and the new one lacks;
  a pick neither listed (typed by hand) stays. Refetch uses it for plugin
  providers too.

Run: TestPluginsListedAgainWhileRunning -race -count=5 green; red with the
drop removed, and red with keptListed replaced by before = now. internal/
plugin ok; gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui
./internal/provider ./internal/gateway ok. The full gateway package hit
the 10 min test timeout at load average ~150 (stacks in mcpauth sleeps), not
rerun before disk fell under 10G.
2026-10-10 23:22:01 +08:00
yetone e70e7ed46a routing: a routing group is made from a template in one click, of the user's own models: hard turns to the strongest and easy ones to a cheap one, cheap first, or never stuck
Making a group took the whole editor (owner, 10-10). Three templates are
made from the models the user has (provider.Templates, grouptemplate.go):

- smart (smart-split): an ordered group of the strongest model and a cheap
  one; a classifier sends a hard turn to the strong one and an easy turn or
  a compaction to the cheap one, images to a model that sees them. The
  classifier is the decision API when there is one, else the cheapest
  priced model that doesn't reason.
- thrifty (cheap-first): two cheap models of different providers, then the
  strongest, which also takes high reasoning.
- steady (never-stuck): the strongest model of up to three providers, each
  failing over to the next.

A model weighs by its maker's list price, else its provider's, else by its
id's size words; one over $100 a million output tokens is never picked. A
template that can't be made says what is missing. AddTemplate saves it
under a name and id no group has (freeGroupName, now shared with
CopyGroup), never over one.

GUI: before the user has a group of their own, the Routing page shows the
templates as cards (models, Add, Edit first); after, a Templates menu by
New group. CLI: `magpie group template [kind] [name]`, no args to list.
Pricing goes through priceOf with the served entry's provider, so
/api/groups pays ~75ms for templates on 203 models, not ~600ms.

Run, at this head rebased on origin/main 4e584faa: go test ./... green;
gofmt -l clean; go vet on darwin, GOOS=linux -tags nogui and GOOS=windows.
GUI: group-template.test.cjs and group-duplicate.test.cjs (Chromium and
WebKit, 5 languages, 420px) 30/30, the template test 3 runs in a row; it
skips WebKit's "ResizeObserver loop" notice as two other tests do. The
group-*/routing-* GUI tests ran before the rebase: 628/635, the 7 being
WebKit flights in routing-group-fold and routing-keys-fold, one Chromium
routing-proxy, and the ResizeObserver notice above; run alone at this head,
routing-proxy passes and the two fold files pass twice on WebKit, as on
origin/main. Real data in a sandbox HOME: `magpie web` on 3561, the
Templates menu added smart-split as GPT-6.1 Sol → GPT-6 Luna with 3 rules.
No real request was routed through the new group.
2026-10-10 19:46:58 +08:00
wei 5a27b924e2 providers, gateway: Google Vertex AI is a preset, Gemini in the user's own Google Cloud project, signed with their Google credentials rather than a key
Gemini on Vertex AI was reachable only through a proxy of the user's own
in front of Vertex AI's OpenAI-compatible endpoint, added as a custom
provider. The Google Vertex AI preset (google-vertex) asks Vertex AI
itself.

  * The provider holds a project, a location (global when none is given;
    us, eu or a region), an optional credentials file and an optional
    service account to go as (provider.Vertex). It has no key and no
    URL: Save refuses a key, normalize clears a key and the four URLs
    kept by hand, and its one address is
    https://<host>/v1/projects/<project>/locations/<location>, the host
    following the location (vertexHost). It is ready when it has a
    project, never for a key or an account, and an import link can't add
    it.
  * Each request is signed with a Google token (Sign), and the token goes
    to no other address. The credentials are found as Google's libraries
    find Application Default Credentials: the provider's file, else
    GOOGLE_APPLICATION_CREDENTIALS's, else gcloud's
    application_default_credentials.json. A GOOGLE_APPLICATION_CREDENTIALS
    that isn't a full path is an error, not unset, since gcloud's file
    read in its place may be another account's. authorized_user,
    service_account and gcloud's impersonated_service_account are read;
    external_account and another universe are refused by name. With a
    service account set, the token is traded at IAM Credentials'
    generateAccessToken for one of that account's, as gcloud's
    --impersonate-service-account does. Tokens are kept in memory per
    file and account, minted once for requests made together, again 5
    minutes before they expire or when the file changes (gcloud signed
    in again). A mint is given 30 seconds; one that fails fails the
    requests that waited through it too, and a request given up on
    stops waiting. A sign-in Google refuses says the command that makes
    that file again: gcloud's for its own files, impersonating as it
    did.
  * The gateway speaks Gemini to it alone. A Gemini client's request is
    relayed as it came, its thinkingConfig, safetySettings and schema
    with it: streamed to
    publishers/google/models/<model>:streamGenerateContent?alt=sse, or
    asked whole to :generateContent. Every other API's is translated
    (buildVertex), streamed, and read back with thoughts as reasoning,
    never as the answer. The path names a model by its upstream name
    when one is set, as the usage log's endpoint does. Gemini 3 is sent a thinkingLevel fitted to the
    model's levels, 2.5 a thinkingBudget in the model's range, off
    included (Pro's least, as Pro can't stop). A call's thought
    signature goes to the client in its id and comes back on the call;
    a 400 "Invalid thought signature." is asked again with every call
    waved through, for that request, and a 400 refusing minimal is asked
    again at the model's lowest level, kept until restart. Neither is
    tried for another provider.
  * Vertex AI has no list of the models a location serves, so each
    location has the ones it answered with on 2026-10-06: 12 at global,
    6 Flash at us and eu, the 2.5 trio at a region.
  * The preset offers Priority PayGo's and Flex PayGo's request headers
    (HeaderHints). GOOGLE_APPLICATION_CREDENTIALS and CLOUDSDK_CONFIG are
    in agentenv.Vars, so the desktop app takes them from the login shell
    and the tests clear them.

Not read: the metadata server of Compute Engine, Cloud Run and GKE;
workload identity federation; Vertex AI's express-mode API keys. No
quota project is sent.

Reference: docs/subsystems/providers-accounts.md (Google Vertex AI,
Vertex AI tokens, four constraints) and gateway-routing.md (Vertex AI).

Verified: go test ./... (nogui), -race -count=5 on the Vertex tests,
gofmt and vet. A fake Google (token endpoint, IAM Credentials, Vertex
AI) checks each credentials type, the mint shared, bounded and
re-minted, every refusal's advice and that no token reaches another
host. Each of 24 mutations made after review, of the mint, the key
rules, the advice, the upstream path and the retries, fails a test.
Live, against a real project through an impersonated service account,
with magpie in a sandboxed HOME: Chat, Anthropic Messages, Responses and
Gemini clients, streamed and whole, with thinking and with tool calls, a
whole Gemini call and its signature sent back streamed, at global, us
and us-central1, and with Flex PayGo's header. No token was found in its
files or logs afterwards.
2026-10-10 19:21:56 +08:00
yetone 66f920e3a3 provider: a Claude account whose user picked every model is served Haiku 5.5 once models.dev lists it, beside the picks (wakaka)
9b51428e put Haiku 5.5 in the Claude account's list (Available), but
agents are served the user's picks (Exposed) when there are any. A user
who had picked every model (Select all, or the TUI's toggles) kept the
list as it was then. The owner's providers.json holds exactly that: all
16 Claude models up to Sonnet 5.5, not Haiku 5.5, which never reached
an agent; wakaka's file wasn't seen, so this is the likely cause there.

Save now keeps, beside new picks, the models listed when they were made
(PickedFrom); the same picks saved again keep it. withNewlyListed serves
a model listed since first beside picks that held every model listed
then; one listed then and left unpicked stays out, and picks that left
any out take nothing new. Picks saved before PickedFrom existed count as
"every model" when they hold every one released up to the newest of
them (models.dev's release_date), which is the owner's saved state. The
editor (providerJSON.Chosen) and the TUI start from Picks, so a later
Save keeps the new model picked rather than dropping it.

Run: TestClaudePicksOfEveryModelTakeOnesListedSince with the reporter's
16 picks and models.dev's Haiku 5.5 row (red with Exposed using the
picks alone); go test -tags nogui ./... under a temp HOME, all ok;
gofmt -l; go vet -tags nogui on darwin, GOOS=linux and GOOS=windows for
internal/provider, internal/gui, internal/tui.
2026-10-10 19:01:10 +08:00
yetone fcae505ff7 gateway, codexcat: Codex is offered Fast on a remote magpie's model where that magpie offers its own Codex Fast, and the tier asked reaches it (#1234, PennyVibe)
remote-magpie/codex/gpt-6.1-sol had service_tiers [] in the local
/v1/codex/models while the remote's own codex/gpt-6.1-sol had Fast: the
local catalog only gave tiers to a provider added by its address
(OwnTier, Preset == ""), and the gateway sent service_tier only to one.

Now a remote magpie's /v1/models (asked with X-Magpie-Drawers) tells each
model's service_tiers as its own Codex catalog offers them
(codexcat.ServiceTiers over the same CodexCatalog/Entries as its
/v1/codex/models). The local keeps the ids (catalog.Model.Tiers ->
Entry.Tiers), codexListed hands them on for the remote's models, and
codexcat.Entries offers them with Codex's own names. The gateway sends the
tier Codex asked for to a remote magpie as it was asked (OwnTier, still
dropped and remembered if refused); the remote serves it as its own
Codex's turn. A remote from before this sends no tiers: unchanged.

Run:
- TestRemoteMagpieOffersItsTiers (gateway, the gateway as both computers
  over HTTP): fails without the codexListed change with
  `office/relay/gpt-6.1-sol offered "" ..., want "priority:Fast "`, and
  without the gateway change with `tier sent to the remote magpie [(none)],
  by it to its vendor [(none)]; want priority, priority`.
- TestServiceTiersGoOnToAnotherMagpie (codexcat): a ChatGPT account's
  model with Codex's own entry tells priority+ultrafast, a relay's GPT
  Fast, glm none; fails when either the own-entry branch of ServiceTiers
  or the namedTiers branch of Entries is taken out.
- gofmt -l clean; go vet -tags nogui for darwin, linux, windows on
  gateway, provider, codexcat, catalog, agent; go test -tags nogui of those
  five packages under a temp HOME: ok.
Not tried with a real ChatGPT account behind a real remote magpie.
2026-10-10 17:55:14 +08:00
yetone 4df1402d10 provider: Provider in model names Off names a remote magpie's models alone, not with the other magpie's provider or "routing group" after them (ARNO on Discord)
A remote magpie's list names each model by its label there (magpie_label),
which carries that magpie's provider, or "· routing group", by that
magpie's own setting. Here it was taken as the model's name, so turning
Provider in model names Off on this computer still left "DeepSeek Chat ·
Relay A" and "Fast · routing group" in every agent's list.

The list's display_name, the name there alone, is now kept beside it
(catalog.Model.Plain, Entry.Plain). provider.Labels names an entry by it
under Off, and under own for a name the user gave; two that would read the
same keep their labels as before. On is unchanged ("DeepSeek Chat · Relay A
· Remote magpie"). /v1/models' display_name is that name alone too, as it
is for every other model, so a magpie chained after this one gets it. The
provider editor's Names & levels line says the same ("plain" in the
provider's model JSON).

Reproduced in a sandbox: fake vendor on :3571, magpie A on :3572 with it
and a group, magpie B on :3573 with remote-magpie → A and `model suffix
off`: B's /v1/models said "DeepSeek Chat · Relay A", "Fast · routing
group". With the fix: "DeepSeek Chat", "Fast"; on: "DeepSeek Chat · Relay
A · Remote magpie".

Run:
- TestRemoteMagpieSuffixOff (internal/gateway, A's list bytes as served)
  fails on the old code (off: "DeepSeek Chat · Relay A", "Fast · routing
  group"), passes with the fix.
- name-suffix-remote.test.cjs, Chromium and WebKit, en/zh/zh-TW/ja/de at
  420px: 10/10; on the old app.js it fails ("… · Relay A"). Sibling
  name-suffix-*.test.cjs and names-fold: 86/86.
- go test -tags nogui ./internal/{catalog,provider,gui,agent,gateway}
  under a temp HOME with pinned caches: ok. gofmt -l clean; go vet
  darwin/linux/windows on the touched packages: ok. Full suite before push.
2026-10-10 15:08:14 +08:00
yetone 9b51428e16 provider: a Claude model models.dev lists after the Claude account's last fetch, Haiku 5.5 among them, is offered at once, not after the next Refresh (wakaka on Discord)
The Claude subscription's models are magpie's own list, the models.dev
catalog's anthropic rows. Its fetch kept a copy of that list in
models/claude.json, and available() served that copy over the catalog
from then on. FetchNew fetches an account only while it has no list, so
the copy was never taken again unless the user pressed Refresh: the
hourly models.dev sync brought Claude Haiku 5.5 (listed from 2026-10-07)
into the catalog, while the Claude account kept offering the list as it
was at its first fetch. The owner's own copy is from 2026-10-03 and has
no claude-haiku-5-5, though the synced catalog beside it has.

An account whose fetch asks no vendor (magpieList: Claude's, and
Factory's compiled-in droid list, which had the same hold-out after an
update) is now always served its list as it is now. A vendor's own list
(Codex, Copilot, Kiro, ...) is served as fetched, as before.

Haiku 5.5's facts come from the catalog: models.dev's row (1M context,
128K output, low..max efforts, $0.10/$0.50 with $0.50/$2.50 over 100K)
matches Claude Code 2.1.296's own model catalog (window 1e6, native 1M,
max_output 128000, effort/xhigh_effort/max_effort, default medium). So
no static table needed a row: claudeEffortsFor gives an unknown newer
Claude all five levels, and claudeTopEffort rightly leaves it out
(2.1.296 reads the top effortLevel only for the models up to Fable 5.1).
With the model listed, the haiku tier follows the newest Haiku
(claudeLight), as Claude Code's own default haiku on the Anthropic API
is claude-haiku-5-5 since 2.1.293.

Verified:
- TestClaudeAccountServesModelsListedSinceItsFetch (models.dev's real
  rows) fails without the models.go change: "Haiku 5.5 not served on the
  Claude account: [claude-opus-5-5]". TestFactoryServesModelsAddedSince
  ItsFetch fails without Factory's flag. Both pass with the change.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/provider; go build, GOOS=linux and windows build -tags nogui.
- go test -tags nogui ./internal/provider ./internal/agent
  ./internal/catalog ./internal/gateway ./internal/gui under a temp HOME:
  all ok.
- Not tried against a running magpie with a real Claude sign-in: the
  owner's gateway on 3425 wasn't running. The stale models/claude.json
  and synced models.json were read from the owner's cache (read only).
2026-10-10 07:37:24 +08:00
yetone c1c887798b provider, docs: a bare model id several providers serve goes by the Providers order, said and tested (MOMO on Discord)
MOMO's {"model":"glm-5.3"} was answered by opencode-go though a6api
serves glm-5.3 too, and they asked for a 409 or for the response to say
which provider was used. The pick was already deterministic, but
Resolve's comment said "exactly one provider" and no doc said what
happens.

Decision: keep serving bare ids, no 409. magpie writes only
provider/model ids into agents' configs (agent/route.go magpieModels),
so a bare id comes from a user's own config, and a 409 would break every
such client the day a second provider adds the model. The rule is now
written down and pinned:
- found groups on (the default): GroupFor takes the bare id to its found
  group auto-<slug>, members in the Providers order, smart routing and
  fail-over to the next provider; a conversation stays with the member
  that answered it while its cache is worth it (affinity).
- found groups off: Resolve takes the first provider in the Providers
  order that exposes it, alone.
- every reply already carries X-Magpie-Provider / X-Magpie-Model
  (member.go), and the usage log has the provider.

What changed: Resolve's comment; gateway-routing.md model resolution
row; reference.md, the ways a model is named and the headers;
bare_slug_test.go: two providers serving glm-5.3, both modes: the first
in the Providers order answers every new conversation, reordering moves
new ones, an answered one stays in the found group, and a 503 from the
first falls over only in the found group. It passes on the old code
too: it pins behaviour that was already there, now documented.

Run: gofmt -l; go vet -tags nogui on darwin, linux, windows for provider
and gateway; go test -tags nogui ./internal/gateway ./internal/provider
in a sandbox HOME.
2026-10-10 05:56:07 +08:00
yetone 0311c720c1 gateway, provider: a model its vendor answers is deprecated leaves that provider's lists until it is answered again, and the next member is asked (MOMO on Discord)
MOMO's /v1/models listed opencode-zen-free/exo-free, and a request for it
got 410 "Model exo-free has been deprecated.". OpenCode Zen's own
/zen/v1/models still lists exo-free (checked 2026-10-10), and models.dev
gives it no deprecated status, so the zen-free plugin's discovery keeps it
and a refresh of the list would bring it straight back. No preset
hardcodes it.

What changed:
- fallback.go: retiredWords / modelRetired: a 400, 404, 410 or 422 saying
  the model is deprecated/retired (Zen's "ModelDeprecated", OpenAI's
  "The model ... has been deprecated"), without quota words. It is
  retryable (410 wasn't), and modelRefused, so only that model rests.
- gateway.go: such an answer calls provider.Retire(provider, model);
  routing.go: servedCandidate calls Unretire.
- provider/retired.go: retired.json beside providers.json, re-read by
  mtime; Retire/Unretire touch the catalog so agents' lists are written
  again. buildEntries leaves a retired model out, for that provider only,
  for at most a week. provider/model requests are still sent.
- docs: gateway-routing.md failure handling, reference.md.

Tests: retired_test.go with Zen's literal 410 body: the model leaves
/v1/models while the provider's other model stays; a group falls over to
the next member and only the 410's provider is marked; modelRetired
cases. All three fail with the hooks reverted.

Run: gofmt -l; go vet -tags nogui on darwin, linux, windows for provider
and gateway; go test -tags nogui ./internal/provider ./internal/gateway
./internal/agent ./internal/catalog in a sandbox HOME.
2026-10-10 05:40:28 +08:00
a998a36367 provider, gateway: remote magpie serves decision and retrieval APIs (#1282)
* provider, gateway: remote magpie serves decision and retrieval APIs

Configure System One from the remote address and discover explicitly marked
decision models, including Clef and custom names. Keep exposed retrieval
models when importing the remote catalog, without treating decisions as
chat or image generators. Refresh removes stale decisions and the editor
receives an explicit empty decision list when none remain.

Forward caller/session attribution for decision, retrieval and media APIs.
Preserve TUI model-list errors for a remote that cannot be reached. Document
the HTTP API surface and old-peer compatibility.

Verified with the full nogui Go suite, focused race checks, go vet, native
macOS and Linux/Windows cross-builds, and the Remote magpie browser tests in
Chromium and WebKit in English and Chinese. The new System One integration
test fails on the old code with an empty model list, and the retrieval test
fails because the remote embedding model is filtered out. Integration tests
exercise two gateways and simulated upstreams; live vendor accounts were
not used.

* gateway, provider: remote forwards keep official client headers

Claude Code and Codex keep their User-Agent through both gateways, so a
relay behind the remote that admits only official clients accepts their
requests. Only decision, retrieval and media calls set magpie's User-Agent
at their own call sites. The two-hop test covers Messages, Responses, Chat
Completions and a Codex originator with another User-Agent.

Keep entryFor limited to remote decision providers. Test rejection of
unlisted remote decisions and remove the redundant resolveDecideModel
early return: the explicit model marker and list-only Jev already exclude
vendor aliases. Document retrieval entries remaining in the shared agent
catalog and TUI list errors being shown for other mixed providers too.

Verified with the Remote magpie provider/gateway tests. Before the fix,
TestRemoteMagpieClientHeaders fails all four cases with the relay receiving
magpie/dev and returning 403 official client required; all pass after it.
Follow-up to yetone's review of #1282.

* provider, gateway, gui: remote discovery reports only the decisions it lists (#1282)

Show CLI list failures and catalog counts for mixed providers. Derive the
remote decision endpoint from its one editable address, name custom decisions
by their ids, and reuse successful discovery in endpoint tests without an
empty decide OK row. Bare-provider decision selection is documented.

Simplify decision classification around the explicit remote list and reuse
model markers while building Available, Catalog and Deciders, avoiding a
whole-list copy and scan for every model. Other providers keep their rules.

The regression tests failed before the fixes on swallowed CLI errors, blank
labels, extra endpoint fields, empty decide results and repeated discovery.
Deliberately removing retrieval/video User-Agent or System One caller
attribution makes all three receiving-side tests fail with lost agent/via.

Verified with sandboxed Go tests, targeted race checks, Linux GUI/nogui and
Windows vet/build, Chromium/WebKit en/zh browser tests and zh-TW/ja/de checks.
The two-hop tests use real gateway handlers with simulated vendor replies;
real vendor accounts and native Windows/macOS runs were not used.

Co-authored-by: XYenon <register@xyenon.bid>
Amp-Thread-ID: https://ampcode.com/threads/T-01a11cd6-93aa-767c-9d6e-f0db2a9c5bab

* gui, gateway tests: remote decision refresh leaves only its current model choices (#1282)

The empty-decision browser fixture cleared deciders but kept decision
entries in models, so its screenshot still showed the same chips. Remove
those entries and assert the visible choices in both states. Check the
real providerInfo model list after refresh too, with Jev Router retained
as chat, and verify an unnamed remote decision reaches the local picker
with its id and provider label.

No production code changes. Verified all Remote magpie tests in root,
provider, gateway and gui under a sandbox HOME with -race; the new
assertions in gateway/gui pass. Chromium and WebKit pass all six browser
cases in English and Chinese; the corrected screenshot run passes 3/3.
Targeted Linux and Windows nogui vet and gofmt are clean.

Amp-Thread-ID: https://ampcode.com/threads/T-01a11cd6-93aa-767c-9d6e-f0db2a9c5bab
Co-authored-by: XYenon <register@xyenon.bid>

---------

Co-authored-by: Amp <amp@ampcode.com>
2026-10-10 03:55:45 +08:00
yetone 7f62dbf3ed gateway, agents, gui: a model's reply limit is published within the window beside it, on /v1/models, Cursor's and Muse's lists, the Gateway page and magpie model output (#1438, yhong91)
#1438 (yhong91): GET /v1/models listed grok/grok-4.7 with context_window
256000 (the Grok backend's own) and max_output_tokens 500000 (models.dev's
x-ai entry, which catalog.Decorate fills in when the backend gives no
output). A client that reads both sizes its replies past what the window
holds. The agents' files already kept output within the window (maxTokens,
#338/#347), but the gateway's lists, the GUI and the CLI did not.

What changed:
- provider.OutputWithin(window, output) and Entry.PublishedOutput(): the
  output is kept within the window; an unknown window or output (0) is left
  as it is.
- Every place that publishes the pair uses it: modelObject (/v1/models),
  cursorLocalModel (Cursor Private Inference), Muse Code's list, the
  Gateway page's models and groups (providerInfo, providersState), the
  agents' maxTokens, and `magpie model output` (which also says
  "500k, kept within its 200k window" when it lowers one).
- Entry.Output stays the model's own limit. The request-path cap
  (outputLimit/withMaxOutput) and the user's Max output setting are
  unchanged, so no request is lowered further than before. This is why the
  clamp is not in replyLimit/entryFor as the issue suggests, and why the
  commenter's patch (modelObject only) was not taken as is: it was right
  but missed Cursor, Muse, the GUI and the CLI.
- docs/subsystems/gateway-routing.md: the rule and its routes.

Tests (each fails without the change):
- gateway TestModelListsKeepOutputWithinTheWindow: models.dev 500000 over a
  backend 256000 window, plus output within the window, unknown window and
  unknown output, on /v1/models, Cursor's capabilities and Muse's limit; a
  group request with max_tokens 300000 still reaches upstream as 300000.
- provider TestOutputWithin, gui TestProviderModelOutputWithinTheWindow,
  TestModelOutputCmdWithinTheWindow.
Breaking it by hand: OutputWithin returning output unclamped turns all of
them red, plus agent TestMaxTokensWithinContextWindow; gateway sites back
on e.Output turn the gateway test red on all three lists; moving the clamp
into Entry.Output turns the fixture and the group-request guard red.

Real data: an offline dump of the owner's catalog (copies of
~/.config/magpie and its caches, 203 entries) has 3 models with output
over their window, grok/grok-4.5, 4.6 and 4.7 (256000 vs 500000), now
published as 256000; 0 are not Grok. The live gateway on 3425 was not
running, so /v1/models itself was not read, and no real Grok request was
made.

Run: gofmt -l; go vet -tags nogui ./... on darwin, linux and windows;
go test -tags nogui ./... -count=1: all green except
TestLoopEndsWorkBuddysReply/plugin/anthropic ("let go only after 3207
lines", bound 2000) at load average ~35 with other suites running; it
passes 5 of 5 alone and does not touch the output limit or request path.
2026-10-10 01:30:29 +08:00
yetone ee657c0969 usage: a Kimi Code membership's k3 is counted at Kimi's API price for kimi-k3, not ≈¥0.000, and kimi-for-coding is unpriced rather than free (#1370, maicent: Kimi Code 的模型计费都是 0)
Why it was 0: magpie already counts a subscription's calls at the API list
price (a Claude or Codex account at its maker's, cf6b82f7). A Kimi Code
provider is looked up in its own models.dev catalog first, and models.dev
lists every model of kimi-code-plan-global / kimi-code-plan-cn at $0 (what
the membership charges per token), so k3, k3-256k, kimi-for-coding and
kimi-for-coding-highspeed were all "priced" at $0. The same $0 catalogs
were also among the maker catalogs, so MakerPrice("k3") was $0 too.

What changed (internal/provider/models.go):
- membershipCatalogs (the two Kimi Code plan catalogs) are never read for a
  price: ListPrice, MakerPrice and PricedName skip them.
- A provider served at a Kimi Code catalog prices its model as the Kimi API
  model it is (kimiCodeAPI), per Kimi Code's docs
  (https://www.kimi.com/code/docs/en/, read 2026-10-09): k3 and k3-256k are
  K3 -> kimi-k3; kimi-for-coding-highspeed is K2.7 Code HighSpeed ->
  kimi-k2.7-code-highspeed. models.dev's canonical_model_id agrees. The
  prices come from moonshotai's catalog, which matches Kimi's pricing page
  (https://platform.kimi.ai/docs/pricing/chat: kimi-k3 $3 in, $15 out,
  $0.30 cached, $3 cache write; kimi-k2.7-code-highspeed $1.90/$8/$0.38).
- kimi-for-coding is K2.8 Preview, which the Kimi API doesn't sell: it has
  no API price, so it is now unpriced (the "—" / "no known price" the GUI
  already shows) instead of ¥0.000. The user can give it a price with
  `magpie model price kimi-code/kimi-for-coding …` or in Names & levels.
- The alias is scoped to Kimi Code providers: a relay's own "k3" keeps its
  own catalog price; Moonshot pay-as-you-go's kimi-k3, an OpenCode free
  model ($0) and Codex's maker price are unchanged.
- PricedNameFor(provider, model): the Requests list's "API price
  reference" names kimi-k3 for a Kimi Code k3 (internal/gui/usage.go).
Docs: reference.md (What a model costs) and providers-accounts.md.

Tests: TestKimiCodeListPrice (internal/provider; fixture
testdata/kimi_code_catalog.json is models.dev's own moonshotai and Kimi Code
plan entries) and TestKimiCodeCost (internal/usage; the reporter's k3 row,
240K in / 78.4K out / 10.0M cached, counted at $4.896 in the ledger and the
summary, kimi-for-coding unpriced, moonshot/kimi-k3 unchanged). Both fail on
the old models.go (every Kimi Code model priced at $0, MakerPrice(k3) $0,
k3 cost=0, unpriced 0); PricedNameFor's check fails with the alias turned
off ("k3-256k").

Run: gofmt -l (empty); go vet -tags nogui, GOOS=linux go vet -tags nogui,
GOOS=windows go vet -tags nogui on internal/provider, internal/usage,
internal/gui; go build, GOOS=linux go build -tags nogui, GOOS=windows go
build; go test -tags nogui -count=1 ./... under a temp HOME with pinned
caches: all ok; -race -count=3 on the new tests ok. No GUI asset changed,
so the Playwright suite wasn't run. Not tried with a real Kimi Code
account or the reporter's usage log.
2026-10-09 11:48:41 +08:00
yetone 58ba737811 remote magpie: a remote magpie's model prices are this magpie's list prices for its models, so both Usage pages count a call at one cost (Sorghum on Discord: 希望本地 magpie 可以自动集成 remote magpie 手动设置的模型价格)
What changed
- The local magpie asks a remote magpie's /v1/models with a new header,
  X-Magpie-Prices (provider.PricesHeader, beside the Drawers and
  Videomakers headers in listHeaders).
- The remote answers each model's "magpie_price": what its own Usage page
  counts the model at (provider.EntryPriceIn: the price its user set by
  hand, else its provider's list price at its price rate; a routing group
  only when every member costs the same). EntryPriceIn is agent/route.go's
  entryPrice moved into provider unchanged, so the agents' cost and the
  remote's price are one rule.
- It tells prices only to a request from its own computer or one let in
  with a gateway key (local || sharedWith), and only when asked: a machine
  let in without a key (MAGPIE_ADDR open, not shared) and an older magpie
  or an agent that sends no header get nothing new.
- The local keeps the price with the fetched list (catalog.Model.Price; read
  raw, so an odd value or a negative part drops the price and keeps the
  model and the list) and uses it as that provider's list price
  (ListPrice -> remotePrice). A price the local user set (provider/model,
  provider/*, */model) still comes first, and the local provider's own
  price rate still applies on top.
- Old remote <-> new local: no field, models priced as before.
  Old local <-> new remote: no header, nothing new sent (and an unknown
  field would be ignored by encoding/json anyway).
- The model editor's price tooltip and `magpie model price` say the greyed
  price is what the other magpie counts the model at (remoteList; new
  string in zh, zh-TW, ja, de).
- Side effect: smallModel/cheapest picks over a remote's models (image
  description, web search) now see these prices, where every remote model
  was unpriced before.
- docs/subsystems/providers-accounts.md: a row for it.

What was run
- New TestRemoteMagpiePrices (real gateway handler behind lanGuard as the
  remote, a local remote-magpie provider fetching it): the remote's hand-set
  price is the local's price; a real chat call through it costs $9 on both
  the local's and the remote's usage records; the local's own price wins
  and survives a refetch; an old remote's list leaves the model unpriced.
  New TestRemoteMagpiePricesTold: priced for loopback asking, not without
  the header, not for a keyless LAN caller with MAGPIE_ADDR open, priced
  with a gateway key. New TestLiveMagpiePrice in catalog.
- Broken by hand, each red: no remotePrice in ListPrice (FAIL: priced
  false); remote price over the user's (FAIL: remote's price won); the
  local/sharedWith gate removed (FAIL: keyless machine priced); the header
  gate removed (FAIL: told to a list that didn't ask); sane() always true
  (FAIL: a/negative priced). A string-typed magpie_price first failed the
  whole list ("not a model list"), hence the raw read.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean; go build, GOOS=linux -tags nogui and
  GOOS=windows builds OK; go test -tags nogui ./... green under a temp HOME
  with pinned caches.
- GUI: model-price-edit (new remote-title check), model-price-tiers,
  provider-price-rate, gui-ja, gui-de, gui-zh-tw, i18n-keys: 18/18 in
  Chromium and WebKit; the title check goes red with the remoteList branch
  removed.
- Not tried between two real magpie binaries on two computers, nor in the
  real window.
2026-10-09 09:43:54 +08:00
yetone 844b9ca3ac provider, gateway, gui: a custom provider's Base URL can be a Gemini API (generateContent): …/v1beta, its models listed from it, the key sent in x-goog-api-key (#1346, NagaseMinato)
The custom provider editor's Base URL has a fifth API, "Gemini compatible"
(Gemini 兼容 / Gemini 互換 / Gemini-kompatibel), beside OpenAI, Anthropic and
Responses; More endpoints has a Gemini URL; the CLI takes gemini=. A
Gemini URL is kept as its base (…/v1beta, a relay's path prefix kept, a
pasted models/…:generateContent cut off). Every client's request, Chat,
Messages, Responses or Gemini, streamed or not, goes upstream to
models/{model}:streamGenerateContent?alt=sse under it, with no model in
the body and the key in x-goog-api-key; models are listed from its
/models, a page at a time, keeping those that serve generateContent.
Detect doesn't ask a Gemini API and is hidden while it is picked.
Factory's Gemini route and Bearer token are unchanged.

With five APIs the pick no longer fits a 900px editor in English and
German, so it wraps to a second row, and its thumb now follows the
picked option onto that row.

Verified against fake httptest upstreams only; no real Gemini key or
relay was tried:
- TestCustomGeminiUpstream (gateway): chat, chat stream, messages, a
  Gemini client's stream and non-stream, behind /proxy/v1beta. Fails with
  "chat: 404" without the gateway.go change.
- TestCustomGeminiProvider, TestGeminiBase, TestFactoryGeminiUnchanged
  (provider).
- go vet, HOME=$(mktemp -d) go test -tags nogui ./... (44 packages ok),
  GOOS=linux and GOOS=windows go vet on the touched packages.
- provider-gemini.test.cjs (new, en/zh/ja/de, Chromium + WebKit, 8 pass;
  fails with "900px: the thumb is 22px off" without the slide() fix),
  and in both engines: provider-base-api, provider-detect,
  provider-detect-models, provider-add-models, provider-output-picks,
  provider-search, provider-url-each-api, seg-contrast, settings-groups,
  menu-scroll, click-scroll, ledger-hscroll, strip-scrollbar,
  view-scrollbar, usage-ledger-chart, system-one, gui-ja, gui-de,
  gui-zh-tw: all pass.
2026-10-09 01:10:25 +08:00
XYenon b66481a953 provider, gateway: Volcengine plans expose their own models by kind (#1265) 2026-10-08 18:15:54 +08:00
如是 1b8c33b5e2 provider: a routing group reasons when any member does, not only when all of them do (#950)
* provider: a routing group reasons when any member does, not only when all of them do

groupEntries started a group at Reasoning: true and intersected it with
each member's (e.Reasoning = e.Reasoning && thinks), so one member that
doesn't think made the whole group 不支持推理. Pi reads that off /v1/models
and turns /thinking off for the model: a routing group of
deepseek-v4-flash-0731-max (a Trae plugin model magpie read as one that
doesn't reason) with a DeepSeek that does lost reasoning for both.

The group now reasons when any member does. Images already worked this way
(#756: a text-only member doesn't turn every image away), and the gateway
fits a request's effort to the member that gets it (fitFor), failing over
when a member refuses the level (failEffort). What the group offers as
levels is not changed: a member known to take none still leaves the group
none (#597), so such a group is Levelless — a shape magpie serves — rather
than one that doesn't reason.

group_reasoning_test.go (6 tests) fails without the change:
TestGroupReasoningFromAMemberThatThinks, TestGroupReasoningLevels and
TestGroupReasoningQuietMemberKeepsTheRest report reasoning off.
TestModelsListReasoning, the /v1/models contract test, fails the same way
and is updated to the new semantics. go vet, go build, GOOS=linux
GOARCH=amd64 go build -tags nogui and GOOS=windows go build pass; go test
-tags nogui ./internal/provider ./internal/plugin pass under a temp HOME.
internal/gateway passes except TestPluginStreamStalledClientKeepsOther
RequestsMoving, which fails on this machine with and without the change.

* gateway, provider: a group's member that can't think is sent no reasoning, rather than a 400

A routing group reasons when any member does (#950, 533887c2), so an agent
asks a group for reasoning that a member of it may not think at all. The
effort reached every member, and some vendors turn a reasoning ask away
with a 400 on a model that can't think — the review's second point: the
comment said the gateway routes a reasoning request to the members that
take it, and nothing did.

The gateway now sends such a member no reasoning ask, in the agent's own
protocol: Chat's reasoning_effort and reasoning, Responses' reasoning (with
reasoning_effort, which some relays take), Anthropic's thinking when it
asks to think — thinking disabled is no ask and stays — and output_config's
effort alone, the rest kept. Everything else goes as the agent sent it, the
Responses effort-update history is skipped for it, and the trace's Effort is
"" (nothing was sent) with Fixed kept, so the user's own pin is still read.
Which member goes first is unchanged: the group routes as it did, and only
the body changes.

provider.Entry.Quiet is the judgment: magpie has a word on the model — its
vendor's or its maker's list, or its provider's own account list — and that
word says no reasoning. A model nothing speaks for isn't quiet: it is sent
the effort the agent asked for, as #597 leaves it. Nor is one that takes
levels, which includes a model the user gave levels of their own: those
take the effort the gateway fits to them. Direct requests outside a group
are untouched, as TestPluginThinkingOff pins.

TestModelsReasoningWithoutLevels (thinks_test.go) still expected
group/mixed false; the review's first point. It is updated with a comment
saying why the #402 expectation changes, and a group of two quiet members
keeps the "none of them thinks" case.

TestGroupNonThinkingMemberNoEffort (group_reasoning_test.go) fails without
the change: with the withoutReasoningAsk call disabled it reports "B: the
quiet member was sent map[... reasoning_effort:high]". TestEntryQuiet
(provider) pins the judgment, and TestWithoutReasoningAsk the field set per
protocol.

go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./... and
GOOS=windows go build ./... pass. go test ./internal/provider,
./internal/catalog and ./internal/plugin pass whole; internal/gateway
passes in three chunks covering every test (TestGroup|TestFixed|TestFast|
TestModels|TestPluginThink|TestWithout|TestMember, TestEffort|TestResponse|
TestReasoning|TestQuiet|TestTrace|TestRoute|TestRules|TestRule, and the
rest), 43s + 36s + 790s. The whole suite in one process times out on this
machine in an unrelated test (TestRuleDecidesAtTurnStartAndHolds here,
TestRequestBodyProgressRenewsIdleDeadline on another run) — the base commit
533887c2 times out the same way, at 800s — so the chunks are what was run.
The GUI is untouched, so no Playwright run.

* gateway, provider: a member the user fixed at an effort keeps it, quiet or not

The review's remaining point: Quiet() rests on magpie's catalog or an
account's own model list, and what this PR is about is that word being
wrong — the Trae plugin gave no capabilities, and magpie read a thinking
model as one that doesn't. A member the user fixed at an effort
("provider/model:high", #189) is the user saying this model does think, so
magpie's word doesn't override theirs: the gateway sends the fixed member
its effort and strips the reasoning ask from the others as before.

quiet := isGroup && c.effort == "" && quietTo(c.p.ID, c.model). c.effort is
only ever the member's own fixed effort (Member.Effort, planLevel), never
the agent's, a group's Group.Levels, the turn's pick or the Settings' — so
those are stripped as they were.

TestGroupNonThinkingMemberNoEffort's E is now the other way: the fixed quiet
member is sent reasoning_effort "high", and the trace's Effort is "high"
with Fixed "high". Dropping the c.effort == "" guard makes it fail with
"E: the fixed member was sent map[... model:plain]". quiet.go and
Entry.Quiet say why.

gofmt, go vet ./..., go build ./..., GOOS=linux go build -tags nogui ./...
and GOOS=windows go build ./... pass. The review's own set passes —
go test -count=1 -run 'TestGroup|TestWithoutReasoningAsk|TestEntryQuiet|
TestModelsReasoning|TestModelsListReasoning|Thinks|TestPluginThinking'
./internal/provider ./internal/gateway — and so does internal/provider whole
(208s). internal/gateway passes in chunks (Test[A-D] 340s, Test[S-Z] 216s,
Test[^A-DS-Z] split over TestEffort|TestResponse|TestReasoning|TestQuiet|
TestTrace|TestRoute|TestRules|TestRule|TestFixed|TestFast 38s and the rest
earlier): the whole suite in one process still hangs here on an unrelated
test (TestCodexBodyReadsPastOldLimit this time, TestRuleDecidesAtTurnStart
AndHolds and TestRequestBodyProgressRenewsIdleDeadline before), which the
base commit does too and which passes alone in 0.9s.
2026-10-08 13:47:13 +08:00
XYenonandAmp d1bbc5b65b provider: Volcengine plans use their preset models instead of /models (xyenon) (#1216)
Coding Plan's /models returns Ark's general catalog, while Agent Plan's
returns 404. Skip their model-list requests and ignore old fetched lists,
including their protocol and key restrictions. Pay-as-you-go and an
explicit list URL still fetch normally; saved model choices stay intact.

Both plan endpoints were checked with real keys. TestVolcengineModelLists
fails without the no-list behavior and passes with it. Vet (gtk3) and
Linux GUI/CLI and Windows builds pass under a temporary HOME. The full
nogui suite passes except TestCodexArchivedSameSizeRewriteInvalidatesDiscovery
in sessions, also reproduced separately with -race -count=20.

Amp-Thread-ID: https://ampcode.com/threads/T-01a11791-db8b-7229-ade8-5e3600b835fc

Co-authored-by: Amp <amp@ampcode.com>
2026-10-08 05:37:56 +08:00
yetone 9db5753ba3 providers: a provider's model list reads the settings once, not three times per model (lml on Discord, Windows: 每次至少都得等五六秒…供应商或者额度列表还在加载) — each model's row asked for its image answer twice (ApplyImage, ImageOverride) and its reply limit once (ReplyLimit), and each ask parsed settings.json again, even inside a GET's hold, since filememo keeps its bytes, not the parse. providerInfo now reads the settings once and uses provider.ImageOverrideIn and Provider.ReplyLimitIn. This removes redundant work found while measuring lml's report; it does not explain the whole 5-6s, which needs their setup (see below).
Measured with a copy of the owner's config (23 providers, ~1500 models) under a sandbox HOME and the real server (magpie web, dead proxy): GET /api/providers on the Windows box 497-558ms → 148-214ms, on the Mac 442-525ms → 174-191ms; the JSON answer is byte-for-byte the same apart from the gateway port. Everything else the window waits on at open answered locally in under 0.6s on Windows, so the rest of a 5-6s wait is network (the usage cards wait for every vendor on a cold start, and on Usage's own open), not this.

TestProviderListReadsSettingsOnce (300 models, a big settings file, held as a GET is) takes 5.3s without the change and 41ms with it, and checks an image answer and a reply limit the user set are still said. go vet, GOOS=windows go build, GOOS=linux go build -tags nogui and go test -tags nogui ./... under a temp HOME pass.
2026-10-07 01:58:10 +08:00
yetone 5361a2178e agent, gateway: Cursor Private Inference's row has an effort, which magpie's gateway asks its requests for (#1003, gjf7) — other agents' rows pick a reasoning effort that magpie writes into their config, but Cursor Private Inference reads only its base URL and key from the environment, and its app offers no Reasoning control for most of magpie's models, so there was no way to set one short of a routing group with a member fixed at a level, which the reporter used as a workaround. Its row now has an effort field like the others': the default (as Cursor asks) first, then every level the models it lists have (cursorLocalEfforts: their levels in MemberEfforts order, low/medium/high where a model reasons with levels unknown, none at all when nothing it lists reasons or it isn't connected). The pick is kept in magpie, settings' agentEfforts by agent (provider.AgentEffort / SetAgentEffort, a level of MemberEfforts or "" for none), and the gateway's candidate loop asks a cursor-local request for it with withFixedEffort, fitted to the model's levels and bounded by a group's, on a model that reasons (the new Provider.Thinks: levels, its list's Reasoning, or models.dev's). Precedence: a group member's fixed effort, then a :effort suffix, then a routing rule's turn pick, then the agent's pick, then the request's own; the pick wins over a level Cursor sent, as Cursor sends its own default as often as a choice, and Default hands the choice back to Cursor. A model that doesn't reason and every other agent's requests go as they came. The Settings page's save carries agentEfforts over as it does fastPicks (TestSettingsSaveKeepsWhatItDoesNotSend's fixture names it). In the window the field sits under "Settings" rather than "New sessions" for this agent alone, as it applies to every request from then on, not to what a session starts on; no new t() strings (Settings, effort and default are translated in zh, ja and de already). TestAgentEffortOnCursorLocal (Chat and Responses with and without a level of their own, Claude on Messages made to think, OpenCode's request untouched, a non-reasoning model untouched, a member fixed at low kept, the pick taken off) fails without the gateway change and passes; TestCursorLocalEffort covers the options (none with no reasoning model, the union of levels, the low/medium/high fallback, none while disconnected), Apply and a bad level refused; both pass -race (-count=20 gateway, -count=10 agent). cursor-local-effort.test.cjs (the window at 560px and the tray panel at 440px: the field under Settings, the slider's five stops with Default first, a pick posting the field, no sideways scroll) passes on Chromium and WebKit in en, zh, ja and de; claude-effort, subagent-effort, agent-field-names, agent-connect, agent-layout, agent-tweak-fold, agent-models, cursor-local-launch and i18n pass on both. go test -tags nogui ./internal/..., go vet, gofmt -l, linux (nogui) and windows builds pass. Not tried with the real Cursor Private Inference: whether it sends a reasoning level of its own on models it shows a Reasoning control for is unverified, which the precedence makes moot. docs/subsystems/gateway-routing.md and agent-wiring.md say it. 2026-10-06 17:29:28 +08:00
yetone e0bf3e61ed catalog: a model the provider's catalog doesn't list is named as the other providers name it (John on Discord #feedback: GLM Coding Plan and ZCode name the same models in different case, in the provider list and the group picker) — the Coding Plan's /models (open.bigmodel.cn and api.z.ai, read with a real key) gives ids alone, glm-5-turbo, glm-5.3-flashx …; catalog.Decorate names only those Zhipu's models.dev entry (zhipuai) lists, so glm-5-turbo kept its id as its name beside ZCode's GLM-5-Turbo. models.dev's load now keeps each model's name as most providers serving it give it (a name that is only the id casts no vote), catalog.NameOf reads it by bare id in any case, and catalog.Named fills it in for a model still named by its id: in Available's live list and for a pick the list doesn't have. Ids, and what is sent upstream, are unchanged; a name the user gave stays theirs (Catalog's Name, with the new one as Default); an Azure provider is left out, its deployments named as their owner named them. TestModelNamedAsElsewhere (the Coding Plan's real ids, a user name, an Azure deployment) fails without the provider change and passes; TestNameOf is new. TestSearcherChosen read whatever catalog an earlier test had left loaded, and now resets it: with none, its lists' models go by their ids, as it expects. go test ./internal/catalog/ ./internal/provider/ ./internal/gateway/ ./internal/gui/ . pass; -race -count=5 for the two new tests; go vet, linux(nogui)/windows builds pass. No GUI change (the GUI and the group picker show name || id). 2026-10-06 13:09:40 +08:00
yetone 6c13b00cd5 provider: a model its vendor lists with no name has one (#955) — Antigravity names none of its -tiered ids (gemini-3.6/3.7/3.8-flash-tiered: one id that thinks at the level the request asks, beside the -low/-medium/-high ids folded into gemini-3.x-flash), so the catalog carried them with an empty name: /v1beta/models gave displayName "" and agy's list and magpie's picker showed the bare magpie/antigravity/gemini-3.6-flash-tiered (EZN7L2C3). A -tiered id is now named for the model it is a tier of, "Gemini 3.6 Flash (Tiered)", and any model a vendor leaves unnamed is called by its id in the catalog (entryFor), so no agent's list is left with an empty name; a name the user gave still wins. TestAntigravityUnnamedModels and TestEntryForUnnamedModel fail without it; collapsing the real account's cached fetchAvailableModels list (27 models, three unnamed -tiered) names all three. go vet, go test -tags nogui -count=1 ./... under a temp HOME, GOOS=windows/linux builds pass. No GUI code changed. 2026-10-06 10:44:33 +08:00
yetone 3a30ac87c2 catalog, gui: a 1-hour cache write is 2× input for a Claude model only, any other's unset is its 5-minute price and isn't shown (PAMI on Discord)
v0.1.1032 counted a 1-hour cache write left out at 2× input for every
model, so gpt-6-astra priced 10,50,1,12.5 showed "$20 (1 hour) at 2×
input", a write OpenAI has no price for. OneHourFor gives a Claude model's
price, listed or given by the user, its 2× input; any other model's 1-hour
writes count at the 5-minute price, magpie model price shows only its cache
write, and the app shows the 1-hour box only for a Claude model or one
priced with one.
2026-10-05 22:55:30 +08:00
yetone 6fc0afe817 gui, provider: a model's price is set in the provider editor's Names & levels, beside its name, with its list price shown (ITea312, #819)
ITea312 couldn't find a way to price one model in the window. Only the provider's Price rate was there; a model's own price could be set only by `magpie model price` on the command line.

Each row of Names & levels now has Price, $ / 1M tokens, with four boxes:
- input, output, cache read and cache write;
- each shows the model's list price in grey (its vendor's on models.dev, else its maker's, before the price rate), so the official table is right there.

How a price is given:
- A part typed and the others left empty takes the list's for them.
- A model with no list price needs its input and output given.
- Every box emptied, or Restore default, gives it its list price again.

It is staged and made with the provider's Save, as names and levels are. Behind it:
- ModelPref gains Price and OwnPrice, set by SetModelPrice: the same check and store as the CLI, and the agents aren't told.
- modelJSON carries the price set and the list price.
- A price set here is counted as given, not multiplied by the price rate. The tooltip says so.
- zh, ja, de strings.

Two other changes:
- Names & levels drawn again keeps the place it was scrolled to: the taller rows had the list scroll, and Ask on one API jumped it back to the top.
- models.go: the Named field of bbb97297 is gofmt'd into the Entry block.

Tests:
- TestSetModelPrefsPrice; it doesn't build on the old code.
- model-price-edit.test.cjs (WebKit, en and zh) fails 2/2 on the old assets.
- provider-detect and provider-same-as read the Restore default tooltip's new words.
- model-*, models-*, provider-*, providers-*, name-suffix-where-named, gui-ja, gui-de and click-scroll pass on WebKit, except model-api-preset and provider-levels-scroll, which fail the same on origin/main.
- go vet passes. The darwin, GOOS=linux nogui and GOOS=windows builds pass. go test -tags nogui -count=1 ./... passes under a temp HOME.
2026-10-05 14:36:41 +08:00
yetone bbb9729748 gui, provider: where a model or routing group is named, it says what agents' lists will call it and offers dropping the suffix there; a group the user made counts as a name they set (#868)
The reporter's screenshot was Codex's model menu, where a long name plus " · Relay" or " · routing group" is cut off. Magpie can't widen an agent's menu. What it can do is shorten the label. Models can already be renamed (provider editor › Names & levels), groups have a Name, and Settings › Provider in model names (#335) can drop the suffix. The reporter found none of these.

Changes:
- The provider editor's Names & levels and a routing group's editor now each have the three choices: Off, Not on names I set, On.
- Each says what the agents' lists will show, e.g. "My Sol · Relay" or "Fast · routing group".
- The line follows the name as it is typed and the choice as it is picked.
- A pick posts settings/plain-names once and doesn't scroll.
- "Not on names I set" now covers routing groups the user made or changed (Entry.Named = !g.Auto) as well as renamed models, still only where the name is unique in the list. A group magpie found keeps its suffix.
- zh, ja, de strings.

Tests:
- TestPlainOwnNamesGroups fails on the old code.
- name-suffix-where-named.test.cjs (WebKit, en and zh) fails 4/4 on the old assets.
- group-fold.test.cjs: viewport raised to 1500 for the taller editor.
- Pass on WebKit: group-context, plain-names, provider-same-as, provider-levels-save, gui-ja, gui-de, click-scroll, agent-models, agent-model-groups, group-* and routing-*.
- Fail the same on origin/main: group-from-model-add at 600x420, provider-levels-scroll.
- go vet passes. The darwin, GOOS=linux nogui and GOOS=windows builds pass. go test -tags nogui -count=1 ./... passes under a temp HOME.
2026-10-05 14:03:51 +08:00
yetone 372316260d provider: OpenRouter's decision models are listed with their window and image input, on the built-in OpenRouter too (ARNO on Discord: 手动添加的 systemone provider 填 openrouter,模型列表没有图像和上下文信息;默认的 openrouter provider 列表里又没有全部的 decision 模型) — three causes. A System One provider at OpenRouter whose list was fetched before v0.1.895 kept that list, without windows or input, since lists are fetched again only on Save or Refresh: FetchNew now fetches such a list again (decideListDue: on, at OpenRouter, missing or with no model's facts), once. One added with no list URL got typesafe/jev-router only, which is OpenRouter's chat router named like Jev: it now fetches OpenRouter's /models?output_modalities=decisions. And the built-in OpenRouter had no decision API at all: its preset (and a saved one, in Normalize as Zen's) gets Decide at https://openrouter.ai/api/v1, its decision list is fetched beside its chat list (kept at <id>.decisions, renamed with it), shown in its model list with context and image input (/api/providers deciders), offered to routing groups' classifier picker and asked at /systemone with the same key; Jev Router stays a chat model for agents (DecidesModel, app.js decidesModel). With the owner's real OpenRouter key in a sandbox HOME, FetchNew listed all 13 decision models with their facts (pplx-decider 262144 + images, solar-decide 524288, …) and the gateway's POST /v1/systemone with openrouter/inception/mercury-decide:free answered 200 from Inception. TestOpenRouterListsDecisionModels and TestOpenRouterDecisionListRefreshed fail on the old code ("OpenRouter has no decision API", "decision models: [typesafe/jev-router]"). system-one, gateway-systemone, gateway-decide-info, group-found-off, routing-reset-deadline pass on WebKit; group-from-model-add fails 2 the same on origin/main. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 07:24:08 +08:00
yetone 4965117e78 gui: a provider's model says its reply limit in the Gateway's tooltip, the one agents are told (ARNO on Discord: some models' output tokens weren't in the tooltip, yet were in the config written for an agent) — the Gateway's model list took each provider model from /api/providers, whose models carried a context and no output, so its tooltip said Output only for routing groups, while agents were told the catalog's (the vendor's list's, else models.dev's, else the user's Max output, Command Code's within its 200000). Both now take provider.ReplyLimit, the one rule entryFor used; the Providers page's model JSON carries it as output and the tooltip says Output: up to N tokens. With it, trae 0.1.12 (magpie-community/plugins c172d93) no longer gives a made-up 32K for a model Trae names no max_tokens for, so models.dev's is told (DeepSeek V4.1 Flash 384K). WorkBuddy AI's glm-5.3-flash 32000 is WorkBuddy's own config's maxOutputTokens (asked with the owner's real workbuddy-ai account: glm-5.3-flash 32000, glm-5.3 48000, deepseek-v4.1-flash 128000), kept; Max output in the provider's editor sets another. TestProviderModelOutputSaid (the page's output equals Served()'s, models.dev's and the user's) fails on the old code; gateway-model-info.test.cjs asserts a model's Output line, failing on the old code; it and gateway-decide-info pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 04:33:36 +08:00
yetone 2a4042a94d perf: magpie opens and shows the Agents page in a fraction of the time it took (Junjie Zhou on Discord: 8 个 agent 30 个 provider … 每次我打开的时候都会很慢,要好几秒。setting 页面秒进后 我切换到 agent 就有问题) — at start, writing the agents' model lists (agent.SyncCatalog) built every provider's catalog thousands of times with nothing held, each build reading migrations.json, settings and groups again: 6000+ file reads and ~8.5s of CPU in the first 8s with the owner's 30-odd providers, all competing with the first /api/state and the Agents page. Now SyncCatalog, magpieModels and main's start-up moves run under provider.Hold, migrations, groups, settings and a provider's fetched models are held for a second like the rest, and filememo.Hold lets a GET /api/* not stat a file it confirmed unchanged within the last second (any magpie write, Changed() or a recent mtime still reads it again). A big ~/.codex/config.toml parsed in quadratic time (the TOML parser's Shape counts newlines from the start for every key): a 3 MB one took 5.4s, now 0.04s (tomlShaper). theInstalled reads through edit.Read's memo. Measured with a copy of the owner's magpie config and agent configs under a sandbox HOME, the real server in WebKit: CPU in the first 8s 8.59s → 0.39s, page up 475 → 75ms, Agents rows drawn 775 → 325ms after start; the agents' written model files are unchanged (pi byte for byte, opencode the same models). TestTOMLShaperMatchesParser, TestTOMLBigFileParsesInLinearTime (fails on the old code), TestHold (filememo), TestHoldReadsMigrationsOnce. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 03:02:40 +08:00
yetone 41ed1c95bc gui, provider: the request log scrolls sideways from a bar at the window's foot and a request's detail opens with its status, duration and a View routing link (mintonight, #799); a provider has a price rate its costs are counted at (ITea312, #819) — #799: the request table, wider than the window, could only be scrolled sideways from the scrollbar at its very end, below 40+ rows, so it looked like it had none; and the "status detail" the reply pointed to wasn't to be found in the row's detail. A bar (#ledHScroll) now sits at the window's foot while the table is wider than its box, scrolling with it both ways; a row's detail begins with Status (Succeeded for log rows), Duration and Routing: View routing, which opens the request's route. #819: costs were counted only at the official (list or maker) price, or a price set per model with magpie model price; a relay billing 0.8 of it had to have each model priced by hand. The provider editor (key and signed-in alike) has a Price rate field (empty for 1; 0–1000, three decimals), saved as priceRate; EffectivePrice multiplies the list/maker price by it, and a price set for a model stays as set. Usage caches key on the providers file, so the counts follow. zh, ja, de strings. ledger-hscroll.test.cjs (fails on the old code) and provider-price-rate.test.cjs (WebKit, en and zh); usage-ledger, usage-ledger-detail (updated for the new rows), usage-ledger-content, usage-ledger-chart, routing-failed-open, purpose-filter, provider-concurrency and provider-levels-save pass on WebKit. TestPriceRateScalesListPrice, TestPriceRateOK, TestPriceRateOf. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 02:03:10 +08:00
yetone d1c19131a6 provider: a decision model has its window and whether it takes images, and the Gateway list shows them with a tooltip saying what it is (ARNO on Discord: decision模型也是需要拉取正确的上下文长度以及是否支持视觉功能的,在网关的模型列表里也应该显示这些信息以及相关的tooltip) — a decision provider's list (OpenRouter's output_modalities=decisions, Vercel's) is now read for its context_length / context_window and its input modalities; a model the list says nothing of (TypeSafe's, OpenCode Zen's, Workers AI's and Bailian's presets) takes its vendor's documented values: Jev 32,000 and text, Clef and Clef Flash 65,536 and images, Bailian's decision-model-preview 65,536 and text. A gateway's Jev among its chat models has them too; its chat models are left as they were. The Gateway list's row of a decision model shows its context and image chips as other models' do, and its tooltip begins Decision model: routing groups ask it, agents never see it (zh, ja, de) in place of Reasoning levels: none known. /v1/models still leaves decision models out: agents can't use them. TestDecideModelsKnowWindowAndImages and gateway-decide-info.test.cjs (WebKit, en and zh) fail on the old code; gateway-model-info passes on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass (TestClientGoneRecordedAsCanceled, TestProvidersAnswerWhileListsComeIn and TestClaudeSignedOut flaked under load, pass alone). 2026-10-05 01:20:06 +08:00
yetone 80441c2c29 gui: a provider's editor has a Max output beside its Context window, so a model whose reply limit magpie has wrong can be set right there (ARNO on Discord: 上下文长度有问题还可以手动覆盖,maxtoken错了如何解决呢) — the reply limits the user sets (ModelOutputs, "provider/model" or "provider/*") could only be set with magpie model output; the editor now shows them in a Max output box written as the Context window box is (32k for all its models, or gpt-6=128k, comma separated), and a Save sends them: the limits not in the box are dropped, a model the provider doesn't list is refused, and the catalog is touched so /v1/models, the agents' max tokens and the gateway's per-member clamp take the new limit. zh and ja strings added. TestModelOutputsSetFromTheEditor, TestProviderSaveOutputs and provider-max-output.test.cjs (WebKit, en and zh) fail on the old code. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass (TestClientGoneRecordedAsCanceled flaked once under load, passes alone). 2026-10-04 23:37:35 +08:00
yetone 209dc69b59 providers: Tencent Cloud is one preset, its regions Plan · China, Pay as you go · China and Pay as you go · Global (Discord, Jorben: Tencent Cloud's Token Plan, TokenHub and TokenHub China were three tiles of one vendor) — tencent-token-plan, tencent-tokenhub-cn and tencent-tokenhub become tencent-cloud's regions plan, cn and intl, as Xiaomi MiMo's are, each made as its own preset made it: the plan's /plan endpoints with no Responses, its own models and no catalog; TokenHub's hosts with Responses, models.dev's tencent-tokenhub and its own keys page and docs. A region now carries its Website, Catalog and Models, and a saved provider's region is found by its endpoints (regionOf, by exact URL before path, since TokenHub China and global share their paths): normalize gives it that region's keys page, docs and catalog (a catalog the user picked is kept), and planModels its models. The old ids are aliases, as qianfan-token-plan is of baidu-qianfan: Preset and FromPreset take them, FromPreset builds at their region, normalize rewrites a saved provider's preset to tencent-cloud, and a provider's own id never changes, so its key, models, routing groups, usage and prices stay where they were; magpie://import links by an old id land at its region, and region= now also gives a region's docs and catalog. Imports from other apps match a region's endpoints. The editor's docs link follows the region picked with the segmented control, en and zh ("按量 · 中国", "按量 · 国际"); the add sheet has one Tencent Cloud tile; the site's import docs list tencent-cloud with its regions and import.html still names the old ids. TestTencentCloud (each region, old ids, FromPreset, imports, import links) and TestTencentCloudOldPresetsKeepWorking (a providers.json saved by an older magpie under all three old presets, with a routing group over them, read, re-saved as the editor saves and switched between regions) fail on the old code; TestTencentTokenHubRoutes routes through old ids and tencent-cloud alike. tencent-cloud.test.cjs (WebKit en and zh: one tile, the three regions, no select, the docs and Get a key links following the region, an old id's provider opening at its region and saved under its id) fails on the old app.js; add-sheet, zhipu-team, system-one, strip-scrollbar and click-scroll pass (Chromium doesn't launch in this sandbox). Not tried with a Tencent account. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-04 19:38:14 +08:00