Commit Graph
4 Commits
Author SHA1 Message Date
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
claude-switch-only set page.setDefaultTimeout(5000) and then called
page.goto with no timeout of its own, so Playwright held the first load
of app.js, i18n.js and the plugins to the 5s bar meant for clicks. On a
busy box (a whole-suite run at load 130-160) that load took longer and
goto timed out. The same pattern is in 988 GUI test files (1174 pages):
every one of them now also sets setDefaultNavigationTimeout(60000) on
the same page, right after its default, so goto, reload and waitForURL
wait on the load itself with room, while clicks and waits keep their
short bar. group-from-model-add's own 20s navigation bar is raised to the
same minute. claude-switch-only also gives its first provider row (drawn
from the page's first reads) a minute before clicking it.

nav-timeout.test.cjs (no browser) reads every GUI test file and names
each page given a default under a minute without a navigation timeout of
at least a minute, so a new file can't bring the pattern back.

What was run (WSL magpie-desktop, Playwright 1.62.0, load 70-260 from
other sessions):
- node --check on every file in internal/gui/tests: all parse.
- nav-timeout.test.cjs against origin/main's test files: red (names the
  1174 pages); against this tree: its only reds were my own probe copies
  of the old files, since removed.
- By hand: claude-switch-only with app.js served 7s late (a busy box's
  first load), --test-name-pattern "1100 en": origin/main's file 4 of 4
  red with "page.goto: Timeout 5000ms exceeded"; this file 4 of 4 green.
- claude-switch-only.test.cjs, both engines, en/zh/ja/de, 1100 and 420:
  32 of 32. group-from-model-add, usage-access-key-card and i18n-keys:
  green. agent-plugin-agents: Chromium green; WebKit's de 420 subtest red
  on a 5s waitForFunction at line 115 (a wait after load, not the
  navigation), at load ~230.

Not tried: the whole GUI suite (about 1000 files; the change is one
mechanical line per page), Windows or mote (mote's browsers, #4125).
2026-10-31 02:09:18 +08:00
yetone c5f15cae7c provider: Amazon Bedrock's Mantle endpoint (@marktoown on X)
"添加 AmazonBedrock 的时候,API 还是旧的 Bedrock-runtime 节点,不支持最新的
Bedrock-mantle 节点". The reporter wanted to add Amazon Bedrock at its
Mantle endpoint, but magpie only offered bedrock-runtime.

What it does:
- A new vendor preset, bedrock-mantle ("Amazon Bedrock (Mantle)"), takes
  the same Bedrock API key as the runtime.
  - It has 17 regions of its own (mantleRegions): the
    bedrock-mantle.{region}.api.aws hosts that answered on 2026-10-16.
    The runtime's eu-west-3 has no Mantle host.
  - Chat completions and Responses go to /v1, and Messages to
    /anthropic.
  - Unlike the runtime, its models are listed from GET /v1/models.
    NoList stays on the runtime preset only.
- Mantle serves each OpenAI-style model under one prefix.
  - OpenAI's closed GPTs and xAI's Grok are under /openai/v1. Every
    other model is under /v1. Asking at the wrong prefix gets "model `x`
    isn't supported on this route".
  - provider.MantleBase picks the prefix from the model id. The
    gateway's forwardOnce and the provider test's tinyBody both use it.
  - For a model whose maker the rule doesn't know, the gateway asks
    again once at the other prefix when Mantle refuses it for its route
    (internal/gateway/mantle.go).
  - When the second prefix takes it, the gateway remembers that prefix
    in unfit. When both refuse, the client gets the first refusal and
    nothing is remembered.
- IsBedrockMantle is true for the preset and for any provider added at a
  Mantle host. IsBedrock includes it, so the shared Bedrock rules apply
  to Mantle too:
  - Claude goes on Messages only.
  - The key is sent as x-api-key alone, which is what Mantle's own
    examples send.
  - max_completion_tokens is used, and metadata is stripped.
  - Beta renames and refusals apply.
  - There is no Priority.
  - GPTs go to Responses first.
- I checked every other IsBedrock caller. None is runtime-only except
  the legacy /openai/v1 -> Responses migration in normalize, which is
  harmless for Mantle.
- A provider added by its Mantle address gets the APIs it wasn't given
  (mantleEndpoints, in normalize). A chat or Responses URL given at
  /openai/v1 is moved to /v1, because /openai/v1/models is a 404 and the
  list lives at /v1/models.
- GUI: the editor's Key header row is hidden for a Mantle Anthropic
  address, as it already was for the runtime's.
- Docs: README (en, zh) preset lists, docs/reference.md,
  providers-accounts.md (a new row) and gateway-routing.md (a new row,
  plus a test command).

What was run, in the worktree at e72b6a332 (origin/main):
- New tests: TestBedrockMantlePreset, TestBedrockMantleByAddress,
  TestMantleBase (internal/provider) and TestBedrockMantleRoutes
  (internal/gateway, against a fake Mantle that serves each model at
  one prefix only and refuses the other with Mantle's words). All pass.
- Each was broken by hand and went red:
  - The reroute call removed: newmaker got a 400.
  - The prefix pick turned off: gpt-5.5 got a 400.
  - mantleEndpoints made a no-op: the endpoints were not filled in.
  - mantleHost made false: the provider was not taken for Mantle.
  - On the old source, the gateway test fails with 'no preset
    "bedrock-mantle"' and the provider tests don't compile.
- GUI: I added a Mantle case to provider-auth-header.test.cjs.
  - It passes 20/20 in chromium and webkit, en and zh.
  - Against the old app.js, chromium fails 2 of 10 on the new
    assertion.
  - add-sheet 6/6, tencent-cloud 12/12, strip-scrollbar 2/2,
    zhipu-team 12/12 and volc-access-key 12/12 pass in both engines.
- gofmt -l prints nothing.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  -tags nogui ./... and GOOS=windows go vet ./... all exit 0.
- go build, GOOS=linux go build -tags nogui and GOOS=windows go build
  all exit 0.
- Full suite: go test -p 2 -tags nogui -count=1 -timeout 45m ./...
  (sandbox HOME).
  - 64 packages ok.
  - internal/agent and internal/gateway hit the 45m timeout with no
    test failing. Load average was 260-380 from other sessions, with
    about 68 other test binaries running.
  - A second 45m run of those two timed out the same way, again with no
    test failing, and different tests were running at the timeout each
    time.
  - The two were run again with -timeout 150m (-p 2, the same load):
    internal/agent ok in 2988.8s and internal/gateway ok in 2972.4s,
    both just past 45 minutes.

What was not tried:
- The real Mantle API. The owner has no Bedrock key (no Bedrock
  provider in providers.json, and AWS_BEARER_TOKEN_BEDROCK is unset).
  The only real-API evidence is unauthenticated probes of the hosts and
  the routes they answer on.
- The per-model prefix rule, /v1/models, Messages with x-api-key, and
  the "isn't supported on this route" refusal come from AWS's docs and
  model cards, not from a signed request.
- The Mantle Anthropic base's own model list (/anthropic/v1/models) was
  not checked. The list is taken from /v1/models.
- The GUI was not tried in the real desktop app.
- The gui-zh-tw, gui-ja and gui-de suites were not run, since no string
  was added.

Rebased onto origin/main e243937ca (no conflicts). At the rebased head:
go test -run 'Mantle|Bedrock' ./internal/provider ./internal/gateway ok,
gofmt -l of the changed files empty, GOOS=linux and GOOS=windows go vet
-tags nogui of both packages exit 0. The full suite above ran at
e72b6a332, not again at the rebased head.
2026-10-16 19:30:42 +08:00
yetone 0cad76cd99 gui: the provider editor folds rarely used fields under Advanced
The owner: "Provider表单太复杂了…有一些可以折叠在高级里面". Headers,
proxy, concurrency and RPM limits, prices, context and output windows,
native compaction and fallback now sit in an "Advanced" fold beside the
key and models. It opens on its own when any of them is set, keeps the
state it was left in across the editor's redraws (keyed by the provider
being edited), and a Save refused on a field inside it opens it and
focuses that field. A signed-in account's editor folds the same.
Strings in zh, zh-TW, ja and de.

Motion ("整个弹窗高度的改变也应该是丝滑的动画"): the fold grows and
shrinks on one spring-like curve, its rows fading in, its arrow turning,
and the dialog's height follows on the same curve both ways; clicked
again mid-way it turns back from where it is. Reduce motion: at once.

Every dialog holds its place: the element last pressed or focused stays
where it was while the dialog grows or shrinks (a relative top plus a
max-height cap), so the button under the pointer doesn't run away. Where
there is no room above, only a pressed button below the fields shortens
them through the cap; nothing a click does scrolls the fields
(models-fold, names-fold). An element mid-scale (a Copy button's pop) is
measured by its parent (key-copy). The names list holds its height while
drawNames rebuilds it, so WebKit doesn't clamp the editor's scroll mid
rebuild (provider-detect, "Ask on one API moved" 64→190).

Tests: provider-advanced-fold (new, 5 languages × 2 engines, 420px);
about 21 editor tests open Advanced before reaching a folded field;
balance-method and plugin-move find the fold by its class; detect-draft
allows 0.5px. appScriptBudget 1,250,000 and coreScriptBudget 1,426,000
(1,232,466 and 1,405,937 with this).

Run: go test ./internal/gui/ ok. Every GUI file (771) in a full run,
4 at a time; its reds, rerun alone at this head, both engines:
key-copy 8/0, models-fold 4/0, names-fold 8/0, balance-method 42/0,
provider-detect 4/0, plus provider-remove 16/0, plugin-move 8/0,
provider-detect-draft 20/0, provider-advanced-fold 50/0,
provider-add-models 4/0. Red on origin/main as well, filed: #2435
(agent-connect-no-models, fixed in cf21b71ff), #2439 (fonts), #2443
(key-balance-card), #2228 (quota-count-wrap, quota-name-translated),
#1905 (routing-wb-restricted), #2448 (s3-sync); mobile-web and
library-workbuddy-trust red only under load, noted on #1544;
readable-focus and text-size fixed on main in 1a16fc0b5 and d3ca90afc.
2026-10-16 04:08:02 +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