Commit Graph
15 Commits
Author SHA1 Message Date
yetone 3b2794cadd provider: a relay's 403 in markup says its words, not a bare "403 Forbidden"
maralica (Discord #help) sent WorkBuddy through a custom Chat relay,
"magpie-grok", that serves only some agents' clients, and WorkBuddy was
told only "magpie-grok: 403 Forbidden". apiError dropped any body that
starts with "<" and isn't a whole web page (a page's fragment such as
"<h1>Forbidden</h1><p>…</p>", an XML error), and WebPage said a page
with no <title> as "a web page, not an API reply" alone, so a relay's
reason in either never reached the agent.

Now such markup is said by its words (provider.MarkupText: scripts,
styles, comments and declarations out, tags out, entities read,
whitespace folded, 300 runes), and a page with no title by its words
(120 runes, as a title). Markup with no words still says the status
alone. JSON, plain text and empty bodies read as before. Every APIError
caller and WebPage's (Unsaid, errorSaid, vendorMessage, vendorSaid) get
it.

Checked on the way, unchanged: the relay is asked for "grok-4.7" by
model "magpie-grok/grok-4.7" and by a group of it, never a magpie-named
id; with "Send the agent's own User-Agent" on, it gets WorkBuddy's
User-Agent as sent, and none of the agent's X-Agent-*, Acp-Connection-Id
or Traceparent headers (only Codex's and Claude Code's own identity
headers are passed on to a relay).

Tests: TestChatRelayRefusalSaysWhy (custom Chat provider, WorkBuddy's
User-Agent, by provider/model and by group, streaming: the model and
User-Agent the relay got, and the message for plain text, JSON, an
untitled page, a fragment, XML and an empty body); TestAPIErrorShapes
updated (untitled page, script-only page, XML, a bare XML tag).

Broken by hand: MarkupText made to return "": TestAPIErrorShapes red,
and TestChatRelayRefusalSaysWhy red in untitled page, fragment and xml
(said "magpie-grok: 403 Forbidden", the reporter's words). Restored,
green.

Run (mote, go1.26.8, tree at origin/main ee6f8866f plus this change):
go test -run 'TestAPIError|TestChatRelayRefusalSaysWhy|
TestRelayRefusalSaysWhatItWas|Unsaid|WebPage|EdgeBlocked|NotAnAPIReply'
./internal/provider ./internal/gateway: ok. A probe (not kept) of
chat/responses/messages, streaming and not, with ten 403 bodies: every
JSON and plain-text reason already reached the agent.

Not run: the full suite (go test ./..., and the whole provider and
gateway packages), shipped before it at the coordinator's word; the reporter's relay itself (its reply body is not known; no
network in tests); the GUI (no GUI file changed); Windows/Linux runs
(no OS-specific code).
2026-10-28 15:46:26 +08:00
yetone 4ed6b42f6b provider: an upstream refusal with an empty body or a web page says what it was
maralica's custom Responses relay answered 403, and Codex was told only
"<provider>: 403 Forbidden": apiError dropped any body starting with "<"
and said nothing of an empty one, so a Cloudflare block page, a proxy's
nginx page and a firewall's empty refusal all read the same.

apiError now says a web page by its <title> (provider.WebPage: markup
and entities taken out, whitespace folded, 120 runes at most), and an
empty body, when the fallback is an HTTP status ("403 Forbidden" or
"Forbidden", statusLine), as refused with no details, often a firewall
or proxy in front of the API (NoDetails). An empty body under any other
fallback stays bare: sniff's response.failed with no error still reads
"upstream stream failed" (TestNativeStreamFailureAccounting). Every
caller of APIError (passthrough, translated tries, routing, search,
decide, the built-in clients) says the same. edgeBlocked now also knows
Cloudflare's block pages ("Sorry, you have been blocked", "used
Cloudflare to restrict access", plain "error code: 1005-1012/1020"), and
APIError puts the page's title before BlockedHint. JSON errors read as
their message, as before; other markup (XML) still says nothing.

Siblings: planquota's vendorSaid and the gateway's HTTP error sites for
drawing, embeddings, video and WorkBuddy's config said a bare status or
dumped raw HTML; they use provider.Unsaid (empty or page) now, through
errorSaid in draw.go, and vendorMessage names a page by its title.
notAnAPIReply's webPage and codexSaidNothing kept their own title regex;
both read provider.PageTitle now.

Routing effect: a 4xx Cloudflare block page now counts as EdgeBlocked,
so retryable() lets a 400/405 one fail over as Alibaba's does (a 403 was
retryable already).

Tests: TestAPIErrorUnsaid (Cloudflare WAF page, plain-text 1020, nginx
page with markup and an entity in its title, a 200-rune title cut,
empty and whitespace bodies under "403 Forbidden", "Forbidden" and
"502", nil under a non-status fallback left bare, JSON unchanged,
vendorSaid);
TestRelayRefusalSaysWhatItWas (a custom Responses provider answering 403
with each through /v1/responses; message has no markup);
TestAPIErrorShapes updated for the page case.

Broken by hand: the page branch and the NoDetails line in apiError off:
TestAPIErrorShapes and TestAPIErrorUnsaid red ("403 Forbidden"), and
TestRelayRefusalSaysWhatItWas red in cloudflare, page and empty
("Relay: 403 Forbidden"). Restored, green.

Earlier, the Cloudflare words out of edgeBlocked turned TestAPIErrorUnsaid
red too.

Run (worktree, go1.26.8, rebased on origin/main 6afbe3f30): at this
commit, TestAPIError*, TestRelayRefusalSaysWhatItWas,
TestNativeStreamFailureAccounting, TestEdgeBlocked* and the draw,
embeddings and video tests ok; at the pushed head (this plus the
as-sent commit, which touches neither file nor test) go test
internal/gateway, whole package, -timeout 45m: ok (464s); internal/provider whole package
crashes in TestUnreadLoginsWriteErrorsKeepCredentials ("close of synctest
channel from outside bubble"), alone too, the open red on main #3632, not
touched here; the rest with it skipped: ok (99s). gofmt -l clean; go vet
gateway+provider darwin/linux/windows clean; go build . darwin and
GOOS=windows, GOOS=windows ./internal/..., GOOS=linux gateway+provider
(GOOS=linux of the app stops in wails' cgo files, as on main).
Not run: the full ./... suite (machine load ~30-60, other sessions'
suites). Not tried: maralica's real relay.
2026-10-27 03:30:57 +08:00
yetone b1396d2360 gateway, provider, gui: a routing group of decision models answers /v1/systemone, failing over between them (ARNO on Discord)
ARNO asked for decision models to get the group feature too: /v1/systemone
took only "<provider>/<model>" (xxx/jev-latest), so one refusing key or
vendor failed the call with nothing to fall back on.

A routing group may now be of decision models alone (provider.Group.Decides,
provider/decide_group.go). SaveGroup refuses one mixed with models that hold
a conversation, a decision group inside a chat group, and patterns, rules,
classifier, effort, levels, fast mode or a member effort on it. It is kept
out of the agents' catalog (groupEntries), and a chat request to it gets a
400 pointing at /v1/systemone.

POST /v1/systemone with "model":"group/<id>" (or the group's id or name, as
GroupFor reads them) goes to serveDecisionGroup (gateway/decide_group.go):
- the members' keys and accounts are planned with planGroup in the group's
  routing order, resting ones last; perKeyBarred no longer drops a
  decision-only provider's keys (it speaks no chat protocol), so each key
  is a try of its own;
- a gateway key's model and account limits and pause rules hold as for chat;
- a retryable failure that isn't the request's own (shape/prompt/protection)
  rests the candidate via restAfter and the next is asked; a transport error
  rests it as a 502; the last one's answer and Retry-After are passed on;
- every try is a Try of one route in the routing log; one usage row for the
  answer.
A group classifier naming a decision group fails over the same way
(askDecisionGroup; systemOne now returns decideRefused with the vendor's
status, headers and body, and postDecide returns the headers).

The GUI group editor offers a group of decision models only decision models
(groups.deciders), a chat group no decision model or decision group, a new
one both, and a decision model's row has no reasoning picker (groupJSON
.decides). The TUI member picker and `magpie group add` follow the same rule.
#1514's plugin_decide_test and TestMixedDecisionProvider now assert a mixed group is refused and a group
of decision models saves. Docs: reference.md (routing groups),
gateway-routing.md, provider-plugins.md.

Run:
- go test -tags nogui -timeout 40m . ./internal/provider ./internal/gateway
  ./internal/gui ./internal/tui: ok
- new: TestSystemOneDecisionGroupFailsOver (httptest System One fakes: a
  provider with two keys answering 429 and 503, then a second provider
  answering 200: tries ka1,ka2,kb, both failures rested and ask by name
  goes to kb first; all failing passes the last answer on; chat to the
  group is 400), TestDecisionGroupClassifierFailsOver, TestDecisionGroup,
  TestGroupAddDecisionModels, TestMemberOptionsDecisionGroup,
  group-decide-members.test.cjs (Chromium and WebKit, en and zh; no new
  strings)
- each broken by hand and seen red: no dispatch (404), no perKeyBarred
  change (ka2 skipped), no classifier failover, no rest, decision group in
  the catalog, CLI resolver, TUI and GUI picker filters
- GUI: group-*, routing-effort*, routing-levels, routing-save*,
  routing-intent-entry, routing-manual, i18n-keys in both engines: 169 pass
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on the
  touched packages
- after rebasing on bc2496dca, the five packages again: ok. The first run
  had TestMaxRPMWaitsForRoomInTheMinute red once under load; it passed
  -count=3 alone and in the rerun, and nothing here touches rpm.go.
Not tried against a real TypeSafe or Bailian account.
2026-10-11 01:37:18 +08:00
yetone 963a8d8f59 provider: Command Code's refusal of a Go plan's key says where the key works (#969, pan17) — a Go key added as the Command Code API-key provider (the preset, on api.commandcode.ai/provider) can never be served: Command Code's Provider API answers every request "Your Go plan doesn't include API access. Upgrade to Provider or higher …". APIError now adds that a Go key works through the Command Code plugin (Plugins › Command Code, signed in with the key), which asks as Command Code's CLI does. TestAPIErrorShapes and the new TestCommandCodeGoKeySaysWhereItWorks (chat, messages and responses through the gateway) fail without it and pass; go test provider/gateway/plugin/gui, vet, linux/windows builds pass. 2026-10-06 12:44:17 +08:00
yetone ee3fca6375 decide: Cloudflare's Clef and Clef Flash are offered on Workers AI beside Jev (ARNO on Discord: cloudflare workers-ai 现在有了新的 decision 模型) — Workers AI now serves Cloudflare's own decision models, @cf/cloudflare/clef (27B) and @cf/cloudflare/clef-flash, which answer System One's questions as Jev does. The cloudflare-jev provider (now named Cloudflare Workers AI · Jev, Clef) lists them beside typesafe/jev, so a routing group can pick either as its classifier (cloudflare-jev/@cf/cloudflare/clef), and magpie's System One API routes to them by name. Each is asked at its own run (…/ai/run/@cf/cloudflare/clef), with the request as it is and its model named clef or clef-flash, as Cloudflare's docs give it; Jev is still a run of typesafe/jev with the questions as its input, and stays the default. TestCloudflareClef (offered, routed, each one's URL, a Clef id outside Workers AI no decider) and TestClefOnCloudflare (a group classified by Clef Flash through Workers AI) 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. Not tried against Cloudflare: no Workers AI key in the owner's config. 2026-10-04 21:52:11 +08:00
yetone 71d96e28e8 system one: a decision provider's own models-list URL is asked as given, and its models can each be tested (Discord, ARNO: OpenRouter added as a System One provider with the list https://openrouter.ai/api/v1/models?limit=500&output_modalities=decisions didn't get its models, and a model typed in by hand couldn't be tested from its right-click) — a System One-only provider went to fetchDecide before its ModelsURL was read, so magpie asked …/models, which at OpenRouter lists the 466 chat models, and kept only Jev's ids of those: typesafe/jev-router alone. With a ModelsURL, fetchDecide now asks it as written, query included, and keeps every id in it, since that list is of decision models already (OpenRouter's answers 13: pplx-decider, liquid/d1, cloudflare/clef, respan/span-01, typesafe/jev-1.13 …). Without one nothing changes, Bailian included. Testing a decision model was refused outright (the chip's Test this model off, Test models leaving them out); where the API takes System One's own body (System One, TypeSafe, OpenRouter, Vercel's TypeSafe API) each model is now sent AskSystemOne's yes-or-no question, the one Detect already asks, and the editor offers Test for it (providerJSON.decideTest); Vercel's evaluation models and Workers AI, which wrap it their own way, still say why not. TestDecideModelsURLAndModelTest (a fake OpenRouter: the plain list, the decisions list, a hand-added model through /systemone, an unknown one failing) and TestModelTest's Workers AI case fail on the old code; model-test-why.test.cjs gains a hand-added System One model tested from its chip and Test models, and a Workers AI one still off (WebKit en and zh pass, with model-test-one and model-copy-id; Chromium doesn't launch in this sandbox). OpenRouter's live decisions list returns the 13 models. Not tried with an OpenRouter key: the /systemone question itself. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-04 18:40:13 +08:00
XYenonandAmp 564f8782c7 provider: keep conversation models on mixed decision providers (#609)
Distinguish decision-only providers from gateways that also serve conversations. Only Jev models use the decision API; ordinary models remain in the catalog, automatic groups and conversation routes. Keep the full model cache when probing a mixed provider’s decision endpoint, and allow conversation model tests in its editor.

Verified with go vet -tags gtk3 ./..., go test -tags gtk3 ./..., node --check internal/gui/assets/app.js, and an isolated browser fixture.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0fe05-afd7-70df-97cf-fdb69c4f4680

Co-authored-by: Amp <amp@ampcode.com>
2026-10-03 04:06:02 +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
drunkduckdrown ae9b3ecdcf decide: send a gateway's own Jev name; ambiguous unfetched is 400 (#207)
Vercel and Cloudflare each serve one Jev, as typesafe-ai/jev and
typesafe/jev. jev-latest is that model, rewritten to the name the
channel lists; jev-preview is not on the channel and is 400.

A bare jev-latest with two providers that have not fetched a list
used to 404 (listed empty, then no single provider to alias). Both
would take it, so it is 400 "more than one" as when the lists are in.

usage.Append still fills Requested and Served on systemOne and
serveSystemOne.

Tested with TestRouteDeciderVercelAlias (preview refused, own name
kept), TestRouteDeciderCloudflareAlias, TestRouteDeciderUnfetchedAmbiguous.
2026-09-29 23:26:25 +08:00
yetone 93d74d2b81 workbuddy: requests are streamed to it, Test's too (#124: 测试 400 · Non-stream chat request is currently not supported, 对话正常的) — WorkBuddy refuses any request that doesn't stream, so its Test, a small non-streaming request, failed with 400 while agents, which stream, answered. A WorkBuddy account is now a backend that only streams: Test sends it stream:true, and the gateway streams it a client's non-streaming request and gives the client one answer, as it does Codex's and Google's. Tested: Test's request to such a backend streams on each endpoint, and a non-streaming chat request through the gateway to a fake upstream that refuses one comes back as one chat.completion 2026-09-29 10:01:21 +08:00
yetone 35ced89666 provider: a vendor's refusal is shown in its own words, not a bare 400 Bad Request (Mrhe525 on #124: WorkBuddy 和 WorkBuddy AI 测试都 400 错误,积分都是有的) — an error body was read only for an OpenAI/Anthropic-style error or message, or shown as it was when under 200 bytes; Tencent's {code, msg} (WorkBuddy's endpoints) and any longer body were dropped, so the provider editor's Test and the error an agent got said only "400 Bad Request", nothing of why. msg is now read too, and a body in no known shape is shown collapsed to one line and cut at 300 characters; an HTML page still says nothing. Tested: {code, msg}, a long JSON body, an HTML page and an empty body 2026-09-29 09:38:33 +08:00
yetone 571766e6ff provider: Jev on Vercel is asked at its TypeSafe API, and on Workers AI at the account the endpoint names (ARNO: Vercel Jev 的默认端点为什么不是 https://ai-gateway.vercel.sh/typesafe;Cloudflare 官方写的是 …/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run,当前默认端点好像没起作用) — Vercel's preset now points at https://ai-gateway.vercel.sh/typesafe, its documented TypeSafe-compatible API: System One's own request and answer at /v1/systemone with typesafe-ai/jev, the key checked by /v1/models; …/typesafe/v1, …/v1/systemone and the bare host are taken for it, and a saved /v4/ai base keeps the AI SDK evaluation-model protocol it used (ViaVercelEval). Workers AI takes the address Cloudflare's docs give — an endpoint with /accounts/<id> in it, /ai/run after it or not, is asked there as it is and its key checked by that account's /ai/models/search, since a token made for Workers AI alone may not list /accounts; a placeholder ($CLOUDFLARE_ACCOUNT_ID) is looked up as before, and a token /accounts refuses is told to put its account ID in the endpoint 2026-09-28 19:14:49 +08:00
yetone de59782fba providers: Jev through Vercel's AI Gateway and Cloudflare's Workers AI — two presets, Jev · Vercel AI Gateway and Jev · Cloudflare Workers AI, route groups and pick their effort as TypeSafe's own does, each asked its own way: Vercel's evaluation-model with the model in a header, a noul asked as a boolean and a confidence taken from the probabilities; Workers AI's run of typesafe/jev at the account its API token works in, found once, out of Cloudflare's envelope. A key is checked by the gateway's free call (Vercel's credits, Cloudflare's accounts) 2026-09-28 01:43:09 +08:00
yetone 154d071699 routing: a group's effort can be picked per turn by any classifier, not only TypeSafe's Jev — a model that isn't a decision API (Jev Router on OpenRouter, Jev on OpenCode Zen, or any small fast model) is asked in words which of low, medium, high or xhigh the turn needs, in a call of its own beside the intent's, and told what the turn before needed; the routing editor offers every model for it 2026-09-27 16:11:23 +08:00
yetone 6fd85894ea routing: Jev (TypeSafe's System One) as a group's classifier — asked once as a turn begins which of the rules' intents the message is, with how sure it is, and, for a group with effort auto, how hard the turn is to think about; the turn's requests then ask their model for that reasoning, where the agent asked for any. TypeSafe is a decision provider: it serves no conversation and is no group's member 2026-09-27 01:53:04 +08:00