Files
magpie/internal
yetone b26f16ee24 agent: Alma has one magpie provider, whichever side turned it on
realLemonawa on X: Alma has its own Magpie preset, and magpie's Alma
agent adds a provider of its own, so turning on both left two.

Alma's preset card claims the provider whose id is "magpie" (Alma
origin/main: forPredef / getProviderForPredefined, provPredefBody in
desktop-native settings_providers_detail.go). magpie's provider is now
made under that id (with the preset's icon), so Alma's card shows it set
up and offers no second one. When a provider has that id already (a
user's own elsewhere), magpie makes one as before and leaves it alone.

almaMagpie already took a Magpie set up in Alma first (same gateway
host) as magpie's, so the row showed connected and nothing was added.
What was wrong was switching off: almaSet("") DELETEd whichever
provider it had matched, the user's own preset included. Now a provider
magpie didn't make (name not "magpie") is kept: only the default model
and image refs that point at it are taken back, as before, and it is
turned off again only if it was off when magpie turned it on
(alma.wasoff in the stash). Sync no longer rewrites its model list after
the switch-off.

Tests: TestAlmaOneMagpie (internal/agent/alma_test.go), against the
fake Alma, whose POST now honours an id and answers a taken id with
Alma's 500 "UNIQUE constraint failed":
- set up in Alma first: connected, no second provider, switch-off sends
  no DELETE, the preset stays on, sync after off writes nothing
- turned off in Alma: enabled on connect, disabled again on switch-off
- none in Alma: created under id "magpie", removed on switch-off
- preset id taken by another host: left alone, a new one made

Red on the old alma.go: "the user's own Magpie was removed:
[PUT /api/settings DELETE /api/providers/magpie]". Broken by hand:
without the id, "none in Alma" fails ("not under the preset's id");
without the Sync skip, "sync after off wrote [PUT
/api/providers/magpie/models]".

Real Alma (alma-server from /Applications/Alma.app, sandbox HOME and
ALMA_DATA_DIR, port 23917, never the live one): the preset's own POST
body creates id "magpie"; a second POST with that id is refused
500 UNIQUE constraint failed; PUT {"enabled":false} turns it off; DELETE
204; magpie's POST body with id "magpie" and type openai is kept as
sent.

Run at this tree (rebased on origin/main 0ffb21f83), on mica:
go test -tags nogui -count=1 ./internal/agent ok (199s); go vet -tags
nogui ./internal/agent for darwin, linux and windows ok; gofmt -l clean.
The full suite is queued on mote behind another session's run and was
not waited for; a red there gets its own issue.

Not tried: magpie's agent end to end against a running Alma (the calls
were replayed with curl). A user who already has both (magpie's old
random-id provider and Alma's preset) keeps both: threads name
"<id>:<model>", so neither is merged or removed for them, and magpie's
old provider keeps its id.
2026-11-16 00:23:37 +08:00
..
…
…
…
…
…
…
…
…
…
…