Files
magpie/docs
yetone 11ddf076b4 usage: a Qwen AI platform Token Plan is read through a sign-in to the platform (@imthe99galaxy on X, #5829)
On v0.1.4137 a provider on the Qwen AI platform's Token Plan
(qwen-token-plan, token-plan.maas.qianwenaiapi.com) had no quota card at
all. The plan key (sk-sp-) only authorizes inference; the platform tells
the plan's usage only to a sign-in on the platform, and magpie had none.

Now each such provider can sign in to the platform, as the QianWen CLI
1.10.0 does (qianwen_plan.go, UA qianwen-cli/1.10.0):
- a device sign-in with PKCE S256 at t.qianwenai.com/cli/device/code and
  /cli/device/token, approved in the user's browser; the editor's
  "Sign in to the Qwen AI platform" opens the page and waits for it;
- the session is the provider's own, kept by provider id in
  qianwen-auth.json (0600), moved on Rename and dropped on Delete;
- cli.qianwenai.com/data/v2/api.json (GenerateCLIAccessToken) mints a
  console token, kept and minted once more when the gateway answers
  NotLogined; ConsoleNeedLogin or a fresh token refused signs it out;
- the usage is the Alibaba Token Plan's BroadScopeAspnGateway call at
  cs-data.qianwenai.com with consoleSite QIANWENAI, region cn-beijing,
  read by the shared aliAskUsage/aliReadWindows (alibaba_usage.go now
  takes the console per call). The sk-sp- key is never sent there.
- Plan windows (planquota.go) and routing's key allowance
  (key_allowance.go, keyTag "qianwen") read it; not signed in, the card
  says so with Open settings (NeedsAccessKey).
- GUI routes /api/qianwen/{id}/signin (POST start, GET state),
  /signin/cancel, /signout; the editor's field lives in qianwenplan.js,
  imported when such a provider's editor opens. The core script budget
  is raised by 326 for the import and one quotaError line (its reason in
  core_budget_test.go). The routes are in the CLI parity's notYet, as
  StepFun's are.

Run, on mote at the base df2b819c6 (= origin/main then):
- gofmt -l: clean. go vet (darwin), GOOS=linux go vet -tags nogui,
  GOOS=windows go vet on internal/provider, internal/gui, internal/cli: ok.
- go test -count=1 -timeout 45m ./internal/provider ./internal/gui
  ./internal/cli: provider ok; gui and cli red on TestCoreScriptBudget
  and TestEveryRouteHasACommandOrIsNamed, both mine; fixed (code moved to
  qianwenplan.js, budget +326, routes named), then gui ok, cli ok.
- go test -race -run Qianwen ./internal/provider: ok.
- GUI (chromium + webkit, 900/420px, en zh zh-TW ja de where the file
  has them): qianwen-plan 20/20, stepfun-per-provider,
  usage-access-key-card, volc-access-key, quota-balance-error,
  i18n-en-no-cjk all ok; earlier also opencode-zen-balance,
  siliconflow-balance, usage-card-refresh, usage-remote-key-limits,
  usage-remote-cards ok. Reds not mine: i18n-keys "a plugin's words are
  its own" (#6619, fixed on main by ea6470cb7), old-webkit's
  headerpresets.js (#6030) and app.css :has() (#5919).
- Rebased on origin/main 79a30eb9c and run again at that tree on mote:
  go test -count=1 -timeout 45m ./internal/provider ./internal/gui
  ./internal/cli all ok; qianwen-plan + i18n-keys 24 pass, 0 fail. Rebased again onto
  fc75d90af before the push; b507b5f69 and fc75d90af touch only
  internal/sessions and third_party/yaml.v3, not run again.

Broken by hand, each red, then restored: the NotLogined retry, the
code_verifier, renameQianwen, the planquota channel, forgetQianwen on
Delete, the session expiry check, qianwenWatch not called, the sign-in
quotaError mapping.

Not tried: a real sign-in. No Qwen AI platform account is available here,
and approving the device sign-in grants an OAuth permission. Fixtures are
built from the QianWen CLI 1.10.0 source and the live device/code and
unauthenticated replies; the usage reply's shape is the Alibaba Token
Plan's, which the CLI reads with the same code.
2026-11-14 15:46:34 +08:00
..