Commit Graph
2 Commits
Author SHA1 Message Date
yetone fc78eb5f6b gateway: ClinePass's upstream is read from provider_metadata.gateway.routing.finalProvider (#2847, smart-lty)
ClinePass (api.cline.bot) names the provider that answered only in a
Chat choice's provider_metadata.gateway.routing.finalProvider: under
delta in a stream chunk, and under message in a single body. upstreamOf
read only a top-level provider, message.provider and response.provider,
so the Routing page's 上游 column, the request log and the usage ledger
showed nothing for ClinePass.

upstreamOf now also reads finalProvider at those two places, and nowhere
else. A choice's content belongs to the model. providerAttempts inside
routing lists every provider that was tried, not the one that answered.
The cheap pre-check now passes a chunk that carries only
"finalProvider".

Tests:
- TestUpstreamOfClinePass checks:
  - the real chunk gives deepseek;
  - the same chunk as one body (message) gives deepseek;
  - content, tool_call arguments, providerAttempts alone and an
    object-valued finalProvider give "";
  - a top-level provider still wins.
- TestClinePassUpstreamRecorded serves the real stream through the
  Handler on /v1/chat/completions and on /v1/messages (translated). It
  checks that the route, the try, Recent() and the usage ledger all say
  deepseek.

The fixture testdata/clinepass_stream.sse is a real ClinePass stream:
api.cline.bot, deepseek/deepseek-v4.1-flash, captured 2026-10-02 in the
MIT-licensed wkeking/clinepass-channel-monitor
(internal/channellog/testdata/plain_success.log). It is not the
reporter's own bytes; #2847 has none.

What was run at 1a3b92688 + this change, on macOS (Go 1.26.8):
- gofmt -l: clean.
- go vet: darwin, linux (-tags nogui) and windows.
- Builds: darwin, linux (nogui) and windows.
- go test -run 'TestUpstream|TestClinePass|TestServed' ./internal/gateway: ok.
- Broken by hand: with the old upstream.go put back, both new tests go
  red ("real ClinePass chunk: upstreamOf = \"\"; want deepseek", plus the
  route, request-log and usage assertions on both paths).
- go test -timeout 45m ./... at load average 420-460 (several sessions'
  suites at once). agent, davsync, gateway, library, plugin and provider
  ran past the 45m timeout. gui was red on load reds that are already
  filed:
  - TestSetAnswersWhileDevinAndProvidersHang: #1375.
  - TestTrayCellClickReleasedPanel: #2645.
  - TestClaudeAccountsSpentFallBackToCodex: #2859, also #2858.
  - TestHostOnBunLackingLibsSaysWhich and TestGatewayHookMixedPiPackage:
    #2865.
  - The package timeouts: #2869.
  Every other package was ok.

Not tried: a live ClinePass account in the real app.
2026-10-19 07:38:46 +08:00
yetone e5981040dc gateway, gui: a request an aggregator passed on says which provider answered it behind it, "Upstream: DeepInfra" (leslie_luo on Discord: 像 CPA 那样指出实际供应商) — through OpenRouter a request was only "OpenRouter · deepseek/deepseek-chat", with no word of the provider (DeepInfra, StreamLake, Novita…) OpenRouter had sent it on to. OpenRouter names it in its replies, as tried with the owner's real key: Chat's body and every chunk of its stream have a top-level "provider", Messages' body has one and its stream's message_start a message.provider; its Responses replies and every reply's headers name none. The gateway now reads it (upstreamOf) from a body relayed as it came and from each event of one it translated, Chat, Messages or Responses, streamed or not, and keeps it on the request's try and route (upstream) and in the usage ledger (Record.Upstream; the CSV export's last column, searched as the rest). The Routing page's Requests list says Upstream: DeepInfra beside where it went, giving way after the provider's name when short of room, with its story saying the aggregator passed it on; a request's details on the Usage page have Upstream provider. A reply naming none says nothing. zh, ja, de strings. ClinePass and Cline weren't tried (no account); Vercel's gateway documents no such field in its replies, and a vendor whose reply has a top-level "provider" string is read the same way. In a sandbox magpie with the owner's real OpenRouter key: Chat, Messages and Responses (translated to Chat), streamed and not, all six said StreamLake in the trace, the ledger and on the Routing page. TestUpstreamRecorded (6 paths × streamed or not: the route, its try, Recent and the ledger) fails on the old code, TestUpstreamOf; routing-upstream.test.cjs (Chromium and WebKit, en and zh: the tag inside its row, the story, the Usage details, a click moves nothing, no left-border accent) fails on the old assets. ledger-hscroll, request-archive-usage, usage-ledger and usage-ledger-detail pass on WebKit; routing-served fails the same on origin/main (its swap wording). go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass but for TestTranslatedStreamKeepsClientAlive, which passes alone 5 times here and on origin/main. 2026-10-05 14:08:08 +08:00