Commit Graph
5 Commits
Author SHA1 Message Date
yetone d35509b65b agents: a custom provider's picked API is the one its models are asked on, and a model named like a routing group stays plain (nb5p)
nb5p on Discord: (1) a custom provider set to Responses had its models
wired into dsh on magpie's Chat Completions route (`magpie`), so dsh sent
Chat and magpie translated; (2) in dsh's models, mygateway/gpt-6.1-sol was
"GPT-6.1 Sol" while mygateway/gpt-6.1-terra was "GPT-6.1 Terra · MyGateway".

Cause 1: Provider.Native never read BaseAPI, the API the user gave the
Base URL as. Detect fills in every API that answers, so a relay picked as
Responses also had a Chat URL, and Native returned Chat (out[0]). Native
now takes BaseAPI after the vendor rules (ResponsesFirst, MessagesFirst),
when the provider serves it. dsh supports it: dsh 0.2.1-rc.2 bundles
@earendil-works/pi-ai, whose KnownApi includes "openai-responses", and
magpie already has the `magpie-responses` route (dshKinds). Siblings
reading m.APIs from magpieModels move with it: dsh, Pi, omp, droid,
Grok Build.

Cause 2: provider.Labels counted collisions over models and routing
groups together. A model two providers serve gets an auto group with the
model's name, so the shown model collided with its own group and kept
"· Provider" (terra: served by a second provider too, hidden for dsh;
sol: one provider). Models and groups are counted apart now: a model
keeps its suffix only when another model reads the same, and a group
named like anything else keeps "· routing group". Labels feeds every
agent's list, so this holds for all of them.

Not changed: the gateway's usable() still orders a translated request
Chat first and doesn't read BaseAPI (#4508).

Tests (each red on the old code, broken by hand in a worktree on
origin/main: all new cases red; reverting only Native red on the route,
reverting only Labels red on terra's name; the old dsh output reproduced
the report exactly):
- internal/agent TestDshCustomResponsesProvider (new): both models on
  magpie-responses, none on magpie, named "GPT-6.1 Sol"/"GPT-6.1 Terra".
- internal/provider native_test: Responses picked beside Chat, Chat
  picked, Responses picked for a Claude where Messages is served, and
  Responses picked with no Responses URL.
- plainnames/plainown_groups/suffix_mode expectations updated to the rule.

Run on mote, at this change on 7fe191cec (the pushed head is the same
change rebased on a newer origin/main, 6f435677c; not re-run there):
go test -tags nogui -count=1 -timeout 45m ./internal/provider
./internal/agent ./internal/gateway ./internal/cli ./internal/gui:
provider ok 170s, agent ok 303s, gateway ok 797s, cli ok 53s; gui FAIL
TestColdTurnsTaken only (0.00s, a test race untouched by this change,
filed #4510). gofmt -l clean. Still running at push: TestColdTurnsTaken
-count=20 and GOOS=linux/windows go vet ./... on mote, and the test on
origin/main alone.

Not tried: a real dsh session against a real Responses relay; nb5p's
own providers.json (the second provider serving terra is inferred from
the suffix); the GUI suite (no GUI file changed); the full ./... suite.
2026-10-31 10:08:40 +08:00
yetone e405315d79 provider: Cursor's built-in is retired; its plugin serves it
"cursor" joins retiredBuiltins (migrate.go), so PluginServes("cursor")
holds moved or not, and the built-in's code goes, as Zed's did in
c0605abc2 and Kiro's in the commit before this.

Removed:
- gateway/cursor.go (the Connect/protobuf translator) and its tests
  (cursor_test, cursor_conversation_test, cursor_maxmode_test,
  cursor_precision_test, cursor_stepusage_test), and gateway.go's
  Account.Agent == "cursor" dispatch to serveCursor;
- provider/cursor_usage.go (the usage card, cursorToken, cursorKeychain)
  and provider/cursor_picker.go, with their tests;
- from cursor.go: the built-in account (cursorAccount), its model list
  through `cursor-agent models` (cursorModels, parseCursorModels,
  cursorModelL), its sign-in (startCursorSignIn, cursorLinkWhole,
  cursorLoginUUID), the API client version (CursorClientVersion,
  cursorVersionFallback, cursorVersionRe) and the token refresh
  (CursorToken, cursorRefresh, tokenExpiry);
- StartSignIn's "cursor" case (signin.go), the usage fetch
  (subscription_usage.go), the login-list case and quota (login_usage.go)
  and the account (account.go);
- "cursor" from Native (provider.go) and asksOwnBackend (modelprefs.go).

Kept, because the mover, the plugin paths or other code need them:
- cursor.go's PLUGIN-SERVED notice (TestMovedBuiltinsSayTheirPlugin);
  cursorIdentity, cursorStatus, parseCursorAbout, readCursorToken,
  cursorTokenOf, cursorKeychainToken and cursorAuthFile: migrate_side.go
  and plugin_accounts.go ask whose account the agent is through them;
- cursorLoginURL (grok.go and claude_signin.go use it), cursorContext and
  withCursorContexts (the plugin's model contexts), CursorExecutable and
  isCursorAgent (the Cursor agent itself);
- cursor_models.go whole: CursorBase (agent/legacy.go), CursorVariants
  (groupfast.go, the plugin's fast pick), cursorPicks and the collapse
  (provider.go, models.go);
- accountIDs, builtinOrder, models.go's "cursor" live branch and
  servedByCursor, as Zed's and Kiro's commits left theirs. The live
  collapse and cursorPicks now only ever meet a built-in list, which a
  retired Cursor never has; they are left for a cleanup of their own.
- gateway/cursor_local_models_test.go (the Cursor agent, not the
  built-in) and the gateway's plugin_*_test.go parity tests.

Tests changed in meaning:
- cursor_signin_test.go became cli_signin_test.go: its two generic
  runCLISignIn tests stay (grok's), TestCursorSignInJoinsAWrappedLink
  goes with cursorLinkWhole.
- cursor_test.go keeps parseCursorModels as a test helper (the old
  parser, for the collapse tests' fixtures); TestParseCursorModels,
  TestCursorClientVersion, TestTokenExpiry and TestCursorLegacyPicks go,
  and cursor_names_test.go's TestCursorAvailableNames: they tested the
  built-in account's list and picks. Cursor's plugin lists its own
  picker models with their efforts (index.mjs), so magpie's collapse
  never runs for it; moving the two tests onto the plugin showed that.
- TestFetchNewWaitsForASlowSignIn (#1789) and
  TestFetchNewListsAgainForAnAnswerWhileListing (#1147) are gone: both
  were about a CLI account whose models `cursor-agent models` lists,
  and no built-in left lists its models through its CLI.
- internal/gui/providers_fetching_unix_test.go
  (TestProvidersAnswerWhileListsComeIn, #541) is gone: its slow vendor
  was the built-in's `cursor-agent models`. The guarantee (the
  Providers page answers while an account's list comes in) has no test
  now; re-homing it onto an HTTP-listed account (Antigravity, Copilot)
  needs exported test hooks and is left as a follow-up.
- TestNative drops its Cursor case; TestLeftAloneRunsNoCLI fakes and
  expects claude and devin only; isolate() and
  TestAccountDiscoveryOffReadsNoSignIn no longer set cursorKeychain
  (cursorTokenOf reads the Keychain on macOS only, as before).
- Dropped as built-in only: the Cursor case of the required-tools test,
  TestCodexToolImageCursor, TestCursorSplitParallelCallsKeepTheirResults.

Run at this tree (load ~300, so narrow runs only):
- gofmt -l internal: clean
- go vet -tags nogui ./... ; GOOS=linux and GOOS=windows the same: ok
- staticcheck -tags nogui -checks U1000 ./internal/provider/: clean;
  with -tests=false over provider and gateway: nothing Cursor or Kiro
- go test -tags nogui -count=1 -run 'Cursor|Kiro|Migrat|Mov|Retired|
  SignIn|AsksOwnBackend|Plugin|HandOver|NoWayBack|Adopt|Hide|
  RequiredTools|ToolImage|Split|Discovery|Account|Isolat' over
  provider, gateway, cli, gui: gateway ok 446s, cli ok 67s, gui ok 51s;
  provider failed TestCursorAvailableNames, TestCursorLegacyPicks,
  TestFetchNewWaitsForASlowSignIn (above) and
  TestSetUpstreamNameRefusesAnAccountBackend (Kiro's, fixed in that
  commit)
- every other test naming "cursor" or cursor-agent, by name, over the
  same four packages: gateway and cli ok; TestNative,
  TestLeftAloneRunsNoCLI, TestFetchNewListsAgainForAnAnswerWhileListing
  and TestProvidersAnswerWhileListsComeIn failed (above)
- after the changes: gofmt clean, vet ok on all three; -run 'Cursor|
  Kiro|Migrat|Mov|Retired|SignIn|AsksOwnBackend|Plugin|HandOver|
  NoWayBack|Adopt|Hide|Discovery|Account|Native|LeftAlone|SetUpstream|
  FetchNew|Hold|DailyCredits|NotSignedIn|ModelTest|Providers': provider
  ok 141s, gui ok 21s, cli ok 22s (gateway untouched since its ok run)
Not run: the whole packages, the full suite, the GUI node suite.
2026-10-17 23:11:00 +08:00
yetone 050e629b0a gateway, provider: a Claude model is asked on Anthropic's Messages where its provider has an Anthropic URL, not Chat (#997, wlj521: 自动好像只会走chat; ReturnTrue on Discord: a relay with an OpenAI and an Anthropic URL had 0% cache hits from Claude models until the OpenAI URL was left empty) — every API's order was Chat first. A request on an API the provider serves was already relayed as it is (a fake relay recording each path: Messages → /v1/messages, Responses → /v1/responses, Chat → /v1/chat/completions, for GLM, GPT and Claude alike, with one URL for three APIs and with an OpenAI URL plus an Anthropic one), but two places fell back to Chat for Claude: usable(), which a request on an API the provider lacks is translated to (Codex's Responses for a Claude model at a Chat+Anthropic relay went to /v1/chat/completions, losing the cache breakpoints the translation to Messages adds), and Provider.Native, the API Pi, omp and droid are wired to ask each model on (route.go's magpieModels), which named Chat for every Claude model at such a relay, so those agents spoke Chat and their cache_control never reached the relay. MessagesFirst (a Claude model by name, where the provider has an Anthropic URL) now puts Messages first in both, beside ResponsesFirst for OpenAI's models. A model the user set "Asked on" for, or one the vendor's list names its APIs for, is as before; GPT and other models keep Chat first; Copilot's Claude, which its list serves on Chat and Messages, is now native on Messages (TestNative updated), the API Claude Code already reaches it on. Not reproduced: a Claude Code /v1/messages request translated to Chat — with either relay layout, a list as new-api answers it, and a key per protocol, it went to /v1/messages with cache_control kept; ReturnTrue is asked for the request's Protocol row. TestClaudeGoesOnMessagesWhereTheRelayHasThem and TestNativeClaudeIsMessagesWhereServed fail without the change and pass; TestAutoRelaysOnTheClientsOwnAPI guards the pass-through for the three APIs; -race -count=5 on them. go test ./internal/gateway ./internal/provider ./internal/catalog ./internal/agent, go vet, darwin, linux (nogui) and windows builds pass. docs/subsystems/gateway-routing.md says the order. 2026-10-06 15:33:16 +08:00
yetone a2714f7506 claude: a Claude account's usage resets are read in the zone /usage names on Windows too, and the provider tests pass whole on Windows (goal: 插件订阅 provider 跟内置的所有逻辑都要一模一样, run on Windows and Linux) — Windows has no time zone database, so "resets Oct 1 at 3:30pm (Asia/Shanghai)" was read in the machine's own zone, hours off for anyone not in that zone; magpie now carries the database (time/tzdata). The provider tests set HOME but not USERPROFILE, which Windows takes the home from, so on Windows they read the test box's own agent sign-ins (Gemini models in a list, an extra provider, a Cursor version); every test home sets both now. Tests whose fake CLI is a shell script (Claude Code's auth status, codex --version, macOS's security) skip on Windows, as the fake devin did, and file mode bits go unchecked there. TestParseClaudeUsage fails on Windows without the change. On Windows and on Linux (WSL) the provider package passes whole, three times on Windows (15 failed before), the plugin package and the move/plugin/Grok/Devin/usage tests five times over on Linux. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-10-01 13:51:24 +08:00
yetone 761156a816 agent: Pi asks a Responses-native model on Responses (Leo: 同协议优先) — every magpie model in Pi's models.json went out as openai-completions, so a ChatGPT sign-in's models, a Responses-only provider's, and GPT on OpenAI's API or Copilot's were asked on Chat and translated to Responses by the gateway. Now each such model carries "api": "openai-responses" (Pi takes a model's own api over its provider's, and posts it to baseUrl/responses), so the gateway relays what Pi sent as it is: reasoning effort and summary, its encrypted reasoning, images, tools, prompt_cache_key; a ChatGPT sign-in's still made into Codex CLI's request. Which API is a model's is provider.Native — what the provider serves it on itself, Responses first for an OpenAI model where the gateway already put it first (ResponsesFirst, moved from the gateway). Chat providers, groups, Cursor/Devin/Kiro/Claude Code sign-ins and Anthropic-API models stay on openai-completions: Pi's anthropic-messages picks thinking by the Claude ids it knows and asks a newer Claude for a thinking budget it refuses, which magpie's translation doesn't. Tested with Pi 0.73.1 and @earendil-works/pi-coding-agent 0.87.1 against a sandbox gateway and a fake Responses upstream: /v1/responses relayed with effort high, xhigh, none (thinking off); a Chat model still on /v1/chat/completions 2026-09-28 20:18:37 +08:00