diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index 349b28da4..0272d068c 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -462,7 +462,7 @@ and `TestHistoricalWindowHoldsUsesEachWindowsOwnReading`. - A sub2api key's windows are fixed: each starts at the key's first request after it was empty, aligned to the relay's day, and a window not started yet says `used 0` with no `reset_at`, so it is taken to renew a span from now. They count this key's spend only, not the relay's accounts behind it. `ForgetBalances` (a key or Balance URL changed) has every key's windows read again at its next ask, a read begun before dropped; until then the last reading stands, fresher than the card's, which routing's reads never write. A key changed is another key (`keyID`), with windows of its own. - A Volcengine Ark provider's access key (`TakesVolcAccessKey`: any of its bases on `ark..volces.com`) is kept with its keys and never sent to the GUI: `/api/providers` tells the editor its ID and whether a Secret is saved (`accessKey`). A save that leaves the Secret blank keeps it, one that leaves the ID out or sends it blank keeps both (an editor opened before the key was given sends `""`, #1821), and `clearAccessKey` drops both. The ID and Secret go together everywhere the keys go: a copy takes them, also when its form sends the source's ID without the Secret (`AddCopy`), a backup or sync without keys has neither (`withoutKeys`), and a restore, mirror or sync keeps this machine's (`KeepSecrets` in `Restore`, `Mirror`, davsync's `take`) when it came without keys, or with the same key and no access key at all, as a magpie before v0.1.1142 or one the access key was never given on sends it (#1821); another key is another account and brings its own. A copy without keys keeps this machine's secret headers (`SecretHeader`) the same way. A plan endpoint with no provider on it holding the access key is a card that says which to give (`accessKeyCard`, `needsAccessKey`), with a button to the provider's settings, not a card left out. A `providers.json` saved with a UTF-8 BOM is read through it, not taken for a broken file whose `.bak` stands in. The plan read is the endpoint's: `/api/coding` asks `GetCodingPlanUsage`, `/api/plan` asks `GetAFPUsage`, pay-as-you-go (`/api/v3`) has no card; the region is the host's. One card is read for each access key and plan. `GetCodingPlanUsage`'s reply (`QuotaUsage[]` with `Level`, `Percent`, `ResetTimestamp` in seconds) is the one three tools built on it read; `GetAFPUsage`'s buckets are read in each form those tools read (`Used` of `Quota` or `Total`, or `Percent`; `ResetTime` or `ResetTimestamp`), none of them seen from a real account here. A reply none of that reads says so on the card with the reply's head. Changing the access key drops the cached cards (`ForgetPlanQuotas`). - A Tencent Cloud provider's SecretId and SecretKey are kept, listed and saved the same way, in the same fields (`AccessKeyVendor` tells the editor whose: `accessKey.vendor`, the preset's `accessKeyVendor`). Only the Token Plan's endpoints are read with them (`TakesTencentAccessKey`: `/plan` on `tokenhub.tencentmaas.com`, region `ap-guangzhou`, or `tokenhub-intl.tencentmaas.com`, `ap-singapore`). Since 10-22 Tencent serves 个人版 and 企业版 in China at the same `/plan` endpoints with the same `sk-tp-` keys (product/1823/130060, 130659), so they are one region, `plan` (a key saved on `enterprise` is on it, `regionAliases`/`RegionID`); 个人版 has no usage API, so a Guangzhou provider without a SecretId gets no card asking for one (`tcSharedRegion`), while Singapore's does. A Tencent Cloud provider saved at the old personal host `api.lkeap.cloud.tencent.com/plan/...` is moved to TokenHub's at load (`movedEndpoints`, `moveEndpoints` in `normalize`), with Responses added; one of no preset keeps the address its user typed, and an app imported at the old host lands on the plan. TokenHub's pay as you go has no plan and no card. A custom provider (no preset) at a Token Plan's or Ark plan's address is the user's own: its editor and Usage page ask it for no access key (`AsksAccessKey`) until one is saved on it, and its key goes as typed, `Authorization: Bearer` on chat and Responses (ysm119). The preset lists its regions that take one (`accessKeyRegions`, `presetAccessKey`), and the editor shows SecretId and SecretKey at those alone. `DescribeTokenPlanList` gives the account's team plans (a sub-user sees the ones it made); each is asked `DescribeTokenPlan` for its `PackageInfo` and `TokenSummary`, the list's kept for what the reply leaves out. The card's one window is `TotalUsed` of `CycleQuota` (else `TotalQuota`), resetting at `TokenSummary.CycleEndTime`, else counted in months from `StartTime` and never past `ExpireTime`. A plan not `enable` says its status beside the plan's name. Errors come back as 200 with `Response.Error`; an `AuthFailure…` or `UnauthorizedOperation` one says to check the key. Built from the API docs (api/1823/132270 and siblings) and the signing doc's worked example; never seen from a real account here. -- An Alibaba Cloud Token Plan provider's AccessKey ID and Secret are kept in the same fields (`AccessKeyVendor` "alibaba"). Only the plan's two hosts at `token-plan..maas.aliyuncs.com` take them (`TakesAlibabaAccessKey`, `aliPlanSite`: `cn-beijing` is `bailian-token-plan`, `ap-southeast-1` is `alibaba-token-plan`, #2940); Qwen Cloud's plan has no read here (its console takes a browser sign-in, #5829). The Qwen AI platform's plan (`qwen-token-plan`, `token-plan.maas.qianwenaiapi.com`) is read through a sign-in to the platform instead, as the QianWen CLI 1.10.0 reads it (`qianwen_plan.go`, @imthe99galaxy on X): a device sign-in with PKCE at `t.qianwenai.com/cli/device/code` and `/cli/device/token`, the editor's *Sign in to the Qwen AI platform* (`qianwenplan.js`, imported when such a provider's editor opens) opening the approval page and polling it; the session is the provider's own, kept by provider id in `qianwen-auth.json` (0600) and moved or dropped with the provider. From it `cli.qianwenai.com/data/v2/api.json` (`GenerateCLIAccessToken`) mints a console token, kept and minted once more when the gateway answers `NotLogined`; the usage is the same `BroadScopeAspnGateway` call at `cs-data.qianwenai.com` with consoleSite `QIANWENAI` and region `cn-beijing`, read by `aliAskUsage` and `aliReadWindows`. The plan key (`sk-sp-`) is never sent there. Not signed in, the card says so with *Open settings* (`NeedsAccessKey`); a session the platform refuses is signed out. `TestQianwenSignIn`, `TestQianwenPlanQuotas`, `TestQianwenFollowsProvider`, `TestQianwenSignInRoutes`, `qianwen-plan.test.cjs`. Built from the CLI's source and the device endpoint's live replies; never signed in with a real account here. The plan key only authorizes inference. The usage is on the console's gateway behind a console token, which `POST modelstudio..aliyuncs.com/modelstudio/cli/generateAccessToken` (ACS3-HMAC-SHA256, `aliACSSign`; Action `GenerateCLIAccessToken`, version `2026-02-10`; reply `cliAccessToken`) makes from the AccessKey, as Alibaba's own `bl` CLI does. The token is kept 20 minutes per AccessKey and region and made again once when the gateway answers `BailianGateway.Login.NotLogined`. The gateway call is `POST /cli/api.json?action=BroadScopeAspnGateway|IntlBroadScopeAspnGateway&product=sfm_bailian&api=zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage` with `Bearer` and a form `params`, `region`; the windows are the `perPercentage` (a share used, 0 to 1) and `ResetTime` (ms) fields of `data.DataV2.data.data`, so 5 hours, Weekly and Month show as the plan has them. A RAM user's key gets `BailianGateway.Team.NotAuthorised` until the main account grants what Alibaba's Token Plan docs ask for RAM users: the `AliyunTokenPlanReadOnlyAccess` and `AliyunBSSReadOnlyAccess` system policies (the `AliyunBailian*` and `AliyunModelStudio*` ones don't cover the Token Plan) and the Administrator or Subscribe Plan permission on Model Studio's Account Management page; the card and the editor's hint name all three (`aliRAMHint`, #6506). The same API serves the main account and RAM users; `bl` has no other route. Another refusal shows the console's `errorMsg`. Team plans (团队版) use other APIs and have no card. The gateway has no public doc: built from the official client's source; never seen from a real account here, and the international gateway host (`bailian-singapore-cs.alibabacloud.com`) is the least certain part. +- An Alibaba Cloud Token Plan provider's AccessKey ID and Secret are kept in the same fields (`AccessKeyVendor` "alibaba"). Only the plan's two hosts at `token-plan..maas.aliyuncs.com` take them (`TakesAlibabaAccessKey`, `aliPlanSite`: `cn-beijing` is `bailian-token-plan`, `ap-southeast-1` is `alibaba-token-plan`, #2940); Qwen Cloud's plan has no read here (its console takes a browser sign-in, #5829). The Qwen AI platform's plan (`qwen-token-plan`, `token-plan.maas.qianwenaiapi.com`) is read through a sign-in to the platform instead, as the QianWen CLI 1.10.0 reads it (`qianwen_plan.go`, @imthe99galaxy on X): a device sign-in with PKCE at `t.qianwenai.com/cli/device/code` and `/cli/device/token`, the editor's *Sign in to the Qwen AI platform* (`qianwenplan.js`, imported when such a provider's editor opens) opening the approval page and polling it; the session is the provider's own, kept by provider id in `qianwen-auth.json` (0600) and moved or dropped with the provider. From it `cli.qianwenai.com/data/v2/api.json` (`GenerateCLIAccessToken`) mints a console token, kept and minted once more when the gateway answers `NotLogined`; the usage is the same `BroadScopeAspnGateway` call at `cs-data.qianwenai.com` with consoleSite `QIANWENAI` and region `cn-beijing`, read by `aliAskUsage` and `aliReadWindows`. The plan key (`sk-sp-`) is never sent there. Not signed in, the card says so with *Open settings* (`NeedsAccessKey`); a session the platform refuses is signed out. `TestQianwenSignIn`, `TestQianwenPlanQuotas`, `TestQianwenFollowsProvider`, `TestQianwenSignInRoutes`, `qianwen-plan.test.cjs`. Built from the CLI's source and the device endpoint's live replies; never signed in with a real account here. The plan key only authorizes inference. The usage is on the console's gateway behind a console token, which `POST modelstudio..aliyuncs.com/modelstudio/cli/generateAccessToken` (ACS3-HMAC-SHA256, `aliACSSign`; Action `GenerateCLIAccessToken`, version `2026-02-10`; reply `cliAccessToken`) makes from the AccessKey, as Alibaba's own `bl` CLI does. The token is kept 20 minutes per AccessKey and region and made again once when the gateway answers `BailianGateway.Login.NotLogined`. The gateway call is `POST /cli/api.json?action=BroadScopeAspnGateway|IntlBroadScopeAspnGateway&product=sfm_bailian&api=zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage` with `Bearer` and a form `params`, `region`; the windows are the `perPercentage` (a share used, 0 to 1) and `ResetTime` (ms) fields of `data.DataV2.data.data`, so 5 hours, Weekly and Month show as the plan has them. A RAM user's key gets `BailianGateway.Team.NotAuthorised` until the main account grants what Alibaba's Token Plan docs ask for RAM users: the `AliyunTokenPlanReadOnlyAccess` and `AliyunBSSReadOnlyAccess` system policies (the `AliyunBailian*` and `AliyunModelStudio*` ones don't cover the Token Plan) and the Administrator or Subscription plan permission on Model Studio's Account Management page; the card names all three (`aliRAMHint`, #6506), and the GUI says them in the reader's language: under the editor's AccessKey ID and on a card whose error carries `aliRAMHint` (`ALI_RAM` in app.js, which `quotaError` matches on the hint's opening words). The same API serves the main account and RAM users; `bl` has no other route. Another refusal shows the console's `errorMsg`. Team plans (团队版) use other APIs and have no card. The gateway has no public doc: built from the official client's source; never seen from a real account here, and the international gateway host (`bailian-singapore-cs.alibabacloud.com`) is the least certain part. - Whether a Codex account spends its credits (`CodexNoCredits` in settings, opt-out, by lower-cased email) is the gateway's routing only. It never changes which account Codex is signed in to: `NextLogin` moves off an account at its routing's spent share, 100% at most, credits or not. - Whether a Claude account spends Anthropic's extra usage past its plan (`ClaudeNoExtraUsage` in settings, one switch for every Claude account, opt-out: Spend extra usage in the Claude editor's Advanced, or `magpie settings set claudeNoExtraUsage off`) is the gateway's routing and the warm-up only; a cap on an account's Usage credits window holds that account the same way once its extra usage reaches it (`provider/claude_extra.go`). magpie can't turn extra usage off at Anthropic: a Claude Code signed in on its own, not through magpie, still spends it. `NextLogin` already moves Claude Code off an account on overages, as the Extra usage row reads 100 (`claudeOveragesWindow`, `usedPast`). Claude Code's hidden `/limit-reset` is not driven: it spends or resets limits through a flow Anthropic hasn't made public, and calling its endpoints would be Claude Code's client imitated. - A Vertex AI provider's credentials are read only when a request is signed (`Sign`), so adding, listing and showing one ask Google nothing. With no `credentials` given and no file where Application Default Credentials are looked for, the request fails with `no Google credentials at `, naming `gcloud auth application-default login` and the provider's credentials file as the ways to give it some. A `credentials` file that isn't there fails with the same words, saying to correct it or clear it. When Google refuses a person's sign-in (revoked, or past the organization's session length), the error says how to sign in again for the file used (`signInAgain`): gcloud's Application Default Credentials with `gcloud auth application-default login`, adding `--impersonate-service-account=` when the file impersonates one; a file under gcloud's `legacy_credentials//` with `gcloud auth login `; any other file by writing it anew or giving the provider another. The new file is read at the next request, with no restart. diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 4b945bbda..40d35d7fe 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -10144,11 +10144,12 @@ function drawEditor(p, presetID) { pair.append(side); } const rows = [ - ...field(idName, ak, ""), + // what a RAM user's key needs (aliRAMHint, MetalHqa on X) + ...field(idName, ak, access.vendor === "alibaba" ? t(ALI_RAM) : ""), ...field(secretName, pair, tc ? t("Token Plan Enterprise's usage is told only to the Tencent Cloud account's API key (console → Access management → API keys), not to the plan's API key. Give its SecretId and SecretKey here for the Usage page to show it; a sub-user's key that may read TokenHub is enough. It is used for nothing else.") : access.vendor === "alibaba" - ? t("The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it; a RAM user that may use Model Studio is enough. It is used for nothing else.") + ? t("The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it. It is used for nothing else.") : t("The plan's 5-hour, weekly and monthly windows are told only to the account's access key (Volcengine console → API Access Keys), not to the plan's API key. Give it here for the Usage page to show them; it is used for nothing else.")), ]; ed.append(...rows); @@ -14056,6 +14057,8 @@ function redrawAccounts(agent) { // quotaError says why an allowance can't be read, the raw error in the tooltip. // SIGN_IN_GONE: a read saying the sign-in is gone (signInGone) const SIGN_IN_GONE = /sign-in has (expired|lapsed)|sign in again/i; +// the grants Alibaba's Token Plan asks of a RAM user's AccessKey (aliRAMHint): the editor's note and its card's refusal +const ALI_RAM = "A RAM user's AccessKey needs AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess, and Administrator or Subscription plan in Model Studio → Account Management; the main account's needs none"; function quotaError(err, q) { if (/^Claude Code: claude-tui: .{0,40}(stays on its first-run screens|shows its first-run notes)/.test(err)) return t("Finish Claude Code's first-run setup, then refresh. Run magpie claude-code to find its executable."); @@ -14075,6 +14078,7 @@ function quotaError(err, q) { // a Volcengine or Tencent plan with no access key (#1821) if (/^this plan's usage is read with the account's access key: give its SecretId/.test(err)) return t("This plan's usage needs the account's SecretId and SecretKey — give them in the provider's settings"); if (/^this plan's usage is read with the account's access key/.test(err)) return t("This plan's usage needs the account's AccessKey ID and Secret — give them in the provider's settings"); + if (/a RAM user's AccessKey needs/.test(err)) return t(ALI_RAM); // a Qwen AI platform plan (qianwen_plan.go) if (/^(this plan's usage is told only to a sign-in on|signed out of) the Qwen AI platform/.test(err)) return t("This plan's usage needs a sign-in to the Qwen AI platform — sign in in the provider's settings"); // a Baidu Qianfan Token Plan Personal (qianfan_plan.go) diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 9c7e26b18..0ca6ffcde 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -3946,7 +3946,8 @@ const I18N = { "SecretId": "SecretId", "SecretKey": "SecretKey", "Token Plan Enterprise's usage is told only to the Tencent Cloud account's API key (console → Access management → API keys), not to the plan's API key. Give its SecretId and SecretKey here for the Usage page to show it; a sub-user's key that may read TokenHub is enough. It is used for nothing else.": "Token Plan 企业版的用量只对腾讯云账号的 API 密钥开放(控制台 → 访问管理 → API 密钥管理),套餐的 API Key 查不到。在这里填入它的 SecretId 和 SecretKey,用量页就会显示;有 TokenHub 读权限的子用户密钥即可。仅用于查询用量。", - "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it; a RAM user that may use Model Studio is enough. It is used for nothing else.": "套餐的用量只对阿里云账号的 AccessKey 开放(控制台 → AccessKey 管理),套餐的 API Key 查不到。在这里填入它的 AccessKey ID 和 Secret,用量页就会显示;有百炼使用权限的 RAM 子账号即可。仅用于查询用量。", + "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it. It is used for nothing else.": "套餐的用量只对阿里云账号的 AccessKey 开放(控制台 → AccessKey 管理),套餐的 API Key 查不到。在这里填入它的 AccessKey ID 和 Secret,用量页就会显示。仅用于查询用量。", + "A RAM user's AccessKey needs AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess, and Administrator or Subscription plan in Model Studio → Account Management; the main account's needs none": "RAM 子账号的 AccessKey 需要 AliyunTokenPlanReadOnlyAccess 和 AliyunBSSReadOnlyAccess 两个系统策略,并在百炼控制台的账号管理页给它管理员或订阅套餐权限;主账号的 AccessKey 无需额外授权", "This plan's usage needs the account's AccessKey ID and Secret — give them in the provider's settings": "此套餐的用量需要账号的 AccessKey ID 和 Secret 才能读取,请在服务商设置里填写", "Open settings": "打开设置", "This plan's usage needs the account's SecretId and SecretKey — give them in the provider's settings": "此套餐的用量需要账号的 SecretId 和 SecretKey 才能读取,请在服务商设置里填写", @@ -9283,7 +9284,8 @@ const I18N = { "SecretId": "SecretId", "SecretKey": "SecretKey", "Token Plan Enterprise's usage is told only to the Tencent Cloud account's API key (console → Access management → API keys), not to the plan's API key. Give its SecretId and SecretKey here for the Usage page to show it; a sub-user's key that may read TokenHub is enough. It is used for nothing else.": "Token Plan 企業版的用量只對騰訊雲帳號的 API 金鑰開放(主控台 → 存取管理 → API 金鑰管理),套餐的 API Key 查不到。在這裡填入它的 SecretId 和 SecretKey,用量頁就會顯示;有 TokenHub 讀取權限的子使用者金鑰即可。僅用於查詢用量。", - "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it; a RAM user that may use Model Studio is enough. It is used for nothing else.": "套餐的用量只對阿里雲帳號的 AccessKey 開放(主控台 → AccessKey 管理),套餐的 API Key 查不到。在這裡填入它的 AccessKey ID 和 Secret,用量頁就會顯示;有百鍊使用權限的 RAM 子帳號即可。僅用於查詢用量。", + "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it. It is used for nothing else.": "套餐的用量只對阿里雲帳號的 AccessKey 開放(主控台 → AccessKey 管理),套餐的 API Key 查不到。在這裡填入它的 AccessKey ID 和 Secret,用量頁就會顯示。僅用於查詢用量。", + "A RAM user's AccessKey needs AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess, and Administrator or Subscription plan in Model Studio → Account Management; the main account's needs none": "RAM 子帳號的 AccessKey 需要 AliyunTokenPlanReadOnlyAccess 和 AliyunBSSReadOnlyAccess 兩個系統策略,並在百鍊主控台的帳號管理頁給它管理員或訂閱套餐權限;主帳號的 AccessKey 無需額外授權", "This plan's usage needs the account's AccessKey ID and Secret — give them in the provider's settings": "此方案的用量需要帳號的 AccessKey ID 和 Secret 才能讀取,請在服務商設定中填寫", "Open settings": "開啟設定", "This plan's usage needs the account's SecretId and SecretKey — give them in the provider's settings": "此方案的用量需要帳號的 SecretId 和 SecretKey 才能讀取,請在服務商設定中填寫", @@ -14628,7 +14630,8 @@ const I18N = { "SecretId": "SecretId", "SecretKey": "SecretKey", "Token Plan Enterprise's usage is told only to the Tencent Cloud account's API key (console → Access management → API keys), not to the plan's API key. Give its SecretId and SecretKey here for the Usage page to show it; a sub-user's key that may read TokenHub is enough. It is used for nothing else.": "Token Plan Enterprise の使用量は、Tencent Cloud アカウントの API キー(コンソール → アクセス管理 → API キー)にだけ返され、プランの API キーでは取得できません。ここに SecretId と SecretKey を入力すると使用量ページに表示されます。TokenHub を読み取れるサブユーザーのキーで十分です。それ以外には使いません。", - "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it; a RAM user that may use Model Studio is enough. It is used for nothing else.": "プランの使用量は、Alibaba Cloud アカウントの AccessKey(コンソール → AccessKey 管理)にだけ返され、プランの API キーでは取得できません。ここに AccessKey ID と Secret を入力すると使用量ページに表示されます。Model Studio を利用できる RAM ユーザーで十分です。それ以外には使いません。", + "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it. It is used for nothing else.": "プランの使用量は、Alibaba Cloud アカウントの AccessKey(コンソール → AccessKey 管理)にだけ返され、プランの API キーでは取得できません。ここに AccessKey ID と Secret を入力すると使用量ページに表示されます。それ以外には使いません。", + "A RAM user's AccessKey needs AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess, and Administrator or Subscription plan in Model Studio → Account Management; the main account's needs none": "RAM ユーザーの AccessKey には、AliyunTokenPlanReadOnlyAccess と AliyunBSSReadOnlyAccess のシステムポリシー、および Model Studio の Account Management ページでの Administrator または Subscription plan 権限が必要です。メインアカウントの AccessKey には追加の権限は要りません", "This plan's usage needs the account's AccessKey ID and Secret — give them in the provider's settings": "このプランの使用量を読むにはアカウントの AccessKey ID と Secret が必要です。プロバイダの設定で入力してください", "Open settings": "設定を開く", "This plan's usage needs the account's SecretId and SecretKey — give them in the provider's settings": "このプランの使用量を読むにはアカウントの SecretId と SecretKey が必要です。プロバイダの設定で入力してください", @@ -19982,7 +19985,8 @@ const I18N = { "SecretId": "SecretId", "SecretKey": "SecretKey", "Token Plan Enterprise's usage is told only to the Tencent Cloud account's API key (console → Access management → API keys), not to the plan's API key. Give its SecretId and SecretKey here for the Usage page to show it; a sub-user's key that may read TokenHub is enough. It is used for nothing else.": "Die Nutzung des Token Plan Enterprise gibt Tencent Cloud nur dem API-Schlüssel des Kontos (Konsole → Zugriffsverwaltung → API-Schlüssel), nicht dem API-Schlüssel des Plans. Geben Sie hier dessen SecretId und SecretKey an, damit die Seite „Nutzung“ sie zeigt; der Schlüssel eines Unterbenutzers, der TokenHub lesen darf, genügt. Er wird für nichts anderes verwendet.", - "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it; a RAM user that may use Model Studio is enough. It is used for nothing else.": "Die Nutzung des Plans gibt Alibaba Cloud nur dem AccessKey des Kontos (Konsole → AccessKey), nicht dem API-Schlüssel des Plans. Geben Sie hier dessen AccessKey ID und Secret an, damit die Seite „Nutzung“ sie zeigt; ein RAM-Benutzer, der Model Studio nutzen darf, genügt. Er wird für nichts anderes verwendet.", + "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it. It is used for nothing else.": "Die Nutzung des Plans gibt Alibaba Cloud nur dem AccessKey des Kontos (Konsole → AccessKey), nicht dem API-Schlüssel des Plans. Geben Sie hier dessen AccessKey ID und Secret an, damit die Seite „Nutzung“ sie zeigt. Er wird für nichts anderes verwendet.", + "A RAM user's AccessKey needs AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess, and Administrator or Subscription plan in Model Studio → Account Management; the main account's needs none": "Der AccessKey eines RAM-Benutzers braucht die Systemrichtlinien AliyunTokenPlanReadOnlyAccess und AliyunBSSReadOnlyAccess und in Model Studio unter Account Management die Berechtigung Administrator oder Subscription plan; der AccessKey des Hauptkontos braucht nichts weiter", "This plan's usage needs the account's AccessKey ID and Secret — give them in the provider's settings": "Die Nutzung dieses Tarifs wird mit der AccessKey ID und dem Secret des Kontos gelesen – geben Sie sie in den Einstellungen des Anbieters an", "Open settings": "Einstellungen öffnen", "This plan's usage needs the account's SecretId and SecretKey — give them in the provider's settings": "Die Nutzung dieses Tarifs wird mit der SecretId und dem SecretKey des Kontos gelesen – geben Sie sie in den Einstellungen des Anbieters an", diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index e0fb8b2bd..2bde6d71c 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -17,8 +17,8 @@ import ( // never what pays for a change (#5918); the history of each number is in // `git log -L` of this file. const ( - appScriptBudget = 1_086_971 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had; +123 for a sidebar list folded from its page's row (hkwok06 on X), its chevron and fold in navicons.js, imported with the first list; +57 for each account of a provider's Usage card in a card of its own (normalcoder_ on X), past the 24 of room left; +17 for an allowance card's wallet line under its rings (apple_test_src on X), the one filter shared with its text line; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to - coreScriptBudget = 1_271_061 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +168 for Discover's long lists drawn in part (the owner, 11-13), after the rest of its hook moved into plugingrid.js, imported when Plugins first draws; +296 for the cap toggle and Smart sentences that say what they do and the Sign in on another computer row (Wing8Aqua on X), packed to the shortest form, no page left to move them to; +333 for In turn's figure in a provider's editor and its words naming the message that goes round (Wing8Aqua on X), the figure itself in rotfig.js, imported when In turn is first shown, the hook packed to the shortest form; +236 for a lone capped Codex account's row saying its turns go to the fallbacks when Codex is connected (not_4O4 on X), the two helpers inlined, no page left to move it to; +717 for omp's advisor (Awad_Yoo on X, #6408): its three rows moved into ompadvisor.js, imported when an omp's settings show, and what is left is the import, the role's " · off" and the Settings line's name, packed to the shortest form; +468 for a plugin's own file import (auth.import) in the import sheet, in the plugin's words (marchen_cc on X), packed to one statement; importSay is read as the Providers rows draw, so it has no lazy page to go to, and nothing else was moved out; +180 for Claude Magpie's own Claude Code folder (xMopf7RF on X, #6459): its Advanced fold in claudemagpie.js, imported when it first shows, and what is left is the import and the fold's place in the Separate app line, 216 bytes packed to the shortest form, less the 36 of room there was; +81 for the Use Claude Magpie button on Claude Desktop's row (xMopf7RF on X), drawn by claudemagpie.js too, what is left the one line that places it (#2710); +225 for the Hermes row's Other profiles lines (Norethcy on X), which 1d60b165c took out while each profile had a row and c96f33d65 left with no place at all, packed to the shortest form; the dead hermes# Default note went with it, and the Agents rows draw it, so there is no page to move it to; +397 for a key's own price rate (tnt12231 on X): its lines, check and placeholder in keyrates.js, imported when a provider with two or more keys opens, and what is left is the import, the draft's copy, Advanced opening for it, the save's one line and proxyLines drawing another kind of line; +316 for an image or video model's chip saying what it makes from its right-click (iceloon on X): the chat chip's Makes… now shared with it, and the media chip's Copy model ID left out, packed to the shortest form; the provider's editor draws it, so there is no page to move it to; +67 for the Claude Code · Claude Magpie row saying it is on magpie through Claude Magpie (xMopf7RF on X), one line in connectLine with the shortest words that say it; the Agents rows draw it, so there is no page to move it to; +12 for AIGoCode's logo in pngIcons (MindfulReturn on X), the list every drawn icon is looked up in; +491 for each cost in the tray panel's and Requests' chart and ranking in its own provider's currency (onkashiko on X): ledProv and the provider passed through, packed to the shortest form; drawLedColumns and drawLedRank are shared by the panel, so there is no page to move it to; +326 for the Qwen AI platform's Token Plan sign-in (imthe99galaxy on X): its field, sign-in and wait in qianwenplan.js, imported when such a provider's editor opens, and what is left is the import and one quotaError line for its two refusals, packed to the shortest form; quotaError reads every card's error, so there is no page to move it to; +72 for Copy all keys (emilochen on X): its row in keyrates.js, imported when a provider with two or more keys opens through keyRateField, now told which of its parts to draw, and what is left is the one line that places it; +83 for the page saying it has gone from view, so what its Sessions and Usage pages keep goes in 30 s and not 7 minutes (P0 memory): folded into the visibilitychange listener every window has, packed to the shortest form, so there is no page to move it to; +270 for Providers' Select, to remove several at once (eiyuuzaki2333 on X): its rows, bar, removal and keys in pvpick.js, imported when Select is first clicked, and what is left is pvSel, the button's click and two lines in renderProviders, which draws the list, so there is no page to move it to; +81 for each account of a provider's Usage card in a card of its own (normalcoder_ on X): one line that makes the box, its brief look left to CSS, and renderQuotas, which draws every card, so there is no page to move it to; +17 for Kimi Code's booster balance under an allowance card's rings in the tray panel (apple_test_src on X): the card's text line and the wallet line share one filter, packed to the shortest form; panelQuotaCard draws every card, so there is no page to move it to; +51 for what a failed plugin install left in plugins/, listed under Installed with a Remove (CHENGJIAHEGOXIS on X): its section in plugininstalled.js as pmLeftovers, imported when Plugins first draws, and what is left is the one call after drawInstalled; draw is what draws the page, so there is no page to move it to; +123 for a sidebar list folded from its page's row (hkwok06 on X): the chevron, its click and the fold kept per page in navicons.js, imported with the first list, and what is left is the folded list read beside the hidden pages' (navList, which navMine now shares) and the two rows' clicks asking navFold first; navSubs draws every list, so there is no page to move it to; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to + appScriptBudget = 1_087_246 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had; +123 for a sidebar list folded from its page's row (hkwok06 on X), its chevron and fold in navicons.js, imported with the first list; +57 for each account of a provider's Usage card in a card of its own (normalcoder_ on X), past the 24 of room left; +17 for an allowance card's wallet line under its rings (apple_test_src on X), the one filter shared with its text line; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to; +275 for the grants Alibaba's Token Plan asks of a RAM user's AccessKey in the reader's language (MetalHqa on X): one string (ALI_RAM) shown under the editor's AccessKey ID and on the card that names them, less the 48 of the wrong "a RAM user that may use Model Studio is enough" it replaces; the editor and quotaError draw them on every window, so there is no page to move them to + coreScriptBudget = 1_271_336 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +168 for Discover's long lists drawn in part (the owner, 11-13), after the rest of its hook moved into plugingrid.js, imported when Plugins first draws; +296 for the cap toggle and Smart sentences that say what they do and the Sign in on another computer row (Wing8Aqua on X), packed to the shortest form, no page left to move them to; +333 for In turn's figure in a provider's editor and its words naming the message that goes round (Wing8Aqua on X), the figure itself in rotfig.js, imported when In turn is first shown, the hook packed to the shortest form; +236 for a lone capped Codex account's row saying its turns go to the fallbacks when Codex is connected (not_4O4 on X), the two helpers inlined, no page left to move it to; +717 for omp's advisor (Awad_Yoo on X, #6408): its three rows moved into ompadvisor.js, imported when an omp's settings show, and what is left is the import, the role's " · off" and the Settings line's name, packed to the shortest form; +468 for a plugin's own file import (auth.import) in the import sheet, in the plugin's words (marchen_cc on X), packed to one statement; importSay is read as the Providers rows draw, so it has no lazy page to go to, and nothing else was moved out; +180 for Claude Magpie's own Claude Code folder (xMopf7RF on X, #6459): its Advanced fold in claudemagpie.js, imported when it first shows, and what is left is the import and the fold's place in the Separate app line, 216 bytes packed to the shortest form, less the 36 of room there was; +81 for the Use Claude Magpie button on Claude Desktop's row (xMopf7RF on X), drawn by claudemagpie.js too, what is left the one line that places it (#2710); +225 for the Hermes row's Other profiles lines (Norethcy on X), which 1d60b165c took out while each profile had a row and c96f33d65 left with no place at all, packed to the shortest form; the dead hermes# Default note went with it, and the Agents rows draw it, so there is no page to move it to; +397 for a key's own price rate (tnt12231 on X): its lines, check and placeholder in keyrates.js, imported when a provider with two or more keys opens, and what is left is the import, the draft's copy, Advanced opening for it, the save's one line and proxyLines drawing another kind of line; +316 for an image or video model's chip saying what it makes from its right-click (iceloon on X): the chat chip's Makes… now shared with it, and the media chip's Copy model ID left out, packed to the shortest form; the provider's editor draws it, so there is no page to move it to; +67 for the Claude Code · Claude Magpie row saying it is on magpie through Claude Magpie (xMopf7RF on X), one line in connectLine with the shortest words that say it; the Agents rows draw it, so there is no page to move it to; +12 for AIGoCode's logo in pngIcons (MindfulReturn on X), the list every drawn icon is looked up in; +491 for each cost in the tray panel's and Requests' chart and ranking in its own provider's currency (onkashiko on X): ledProv and the provider passed through, packed to the shortest form; drawLedColumns and drawLedRank are shared by the panel, so there is no page to move it to; +326 for the Qwen AI platform's Token Plan sign-in (imthe99galaxy on X): its field, sign-in and wait in qianwenplan.js, imported when such a provider's editor opens, and what is left is the import and one quotaError line for its two refusals, packed to the shortest form; quotaError reads every card's error, so there is no page to move it to; +72 for Copy all keys (emilochen on X): its row in keyrates.js, imported when a provider with two or more keys opens through keyRateField, now told which of its parts to draw, and what is left is the one line that places it; +83 for the page saying it has gone from view, so what its Sessions and Usage pages keep goes in 30 s and not 7 minutes (P0 memory): folded into the visibilitychange listener every window has, packed to the shortest form, so there is no page to move it to; +270 for Providers' Select, to remove several at once (eiyuuzaki2333 on X): its rows, bar, removal and keys in pvpick.js, imported when Select is first clicked, and what is left is pvSel, the button's click and two lines in renderProviders, which draws the list, so there is no page to move it to; +81 for each account of a provider's Usage card in a card of its own (normalcoder_ on X): one line that makes the box, its brief look left to CSS, and renderQuotas, which draws every card, so there is no page to move it to; +17 for Kimi Code's booster balance under an allowance card's rings in the tray panel (apple_test_src on X): the card's text line and the wallet line share one filter, packed to the shortest form; panelQuotaCard draws every card, so there is no page to move it to; +51 for what a failed plugin install left in plugins/, listed under Installed with a Remove (CHENGJIAHEGOXIS on X): its section in plugininstalled.js as pmLeftovers, imported when Plugins first draws, and what is left is the one call after drawInstalled; draw is what draws the page, so there is no page to move it to; +123 for a sidebar list folded from its page's row (hkwok06 on X): the chevron, its click and the fold kept per page in navicons.js, imported with the first list, and what is left is the folded list read beside the hidden pages' (navList, which navMine now shares) and the two rows' clicks asking navFold first; navSubs draws every list, so there is no page to move it to; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to; +275 for the grants Alibaba's Token Plan asks of a RAM user's AccessKey in the reader's language (MetalHqa on X): one string (ALI_RAM) shown under the editor's AccessKey ID and on the card that names them, less the 48 of the wrong "a RAM user that may use Model Studio is enough" it replaces; the editor and quotaError draw them on every window, so there is no page to move them to ) // codeBytes is how many bytes of b are code: its blank lines, its lines diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index c75846f69..3abc2cece 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -2676,6 +2676,22 @@ node --test internal/gui/tests/tencent-access-key.test.cjs go test -tags nogui ./internal/gui -run TestProviderListTellsTencentAccessKey ``` +## Alibaba Cloud Token Plan AccessKey grants + +`alibaba-ram-grants.test.cjs` covers MetalHqa's report on X: what an +Alibaba Cloud Token Plan's AccessKey needs to read the plan's usage is said +under the editor's AccessKey ID (`ALI_RAM`), in the reader's language, and +the Secret's hint no longer says any Model Studio RAM user will do. A card +refused with `aliRAMHint`, read from `alibaba_usage.go` itself, says the +same grants in the reader's language with the raw refusal in its tooltip. +Volcengine's editor has no such note. 420px with no sideways scroll; all +five languages, Chromium and WebKit. + +```sh +node --test internal/gui/tests/alibaba-ram-grants.test.cjs +go test ./internal/provider -run TestAliGatewayRAMNotAuthorised +``` + `plugin-kernel.test.cjs` holds the window's plugin kernel (`kernel.js`) to its error boundary, with the Gateway page, the first page a plugin draws (`assets/plugins/gateway/`). With the page's drawing made to throw, the page diff --git a/internal/gui/tests/alibaba-ram-grants.test.cjs b/internal/gui/tests/alibaba-ram-grants.test.cjs new file mode 100644 index 000000000..9cc013bc3 --- /dev/null +++ b/internal/gui/tests/alibaba-ram-grants.test.cjs @@ -0,0 +1,129 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// MetalHqa on X: what an Alibaba Cloud Token Plan's AccessKey needs to read +// the plan's usage wasn't said where the key is given. The editor said "a +// RAM user that may use Model Studio is enough", which is wrong (#6506), +// and the grants Alibaba's docs list (aliRAMHint) were said only in +// English, on the card, after a refusal. Now the editor says them under +// the AccessKey ID, in the reader's language, and a card refused with +// aliRAMHint says them in the reader's language too, the raw error in its +// tooltip. The refusal is read from alibaba_usage.go itself, so a change of +// its words that quotaError no longer matches is red here. A 420px window, +// both engines, every language. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const GRANTS = "A RAM user's AccessKey needs AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess, and Administrator or Subscription plan in Model Studio → Account Management; the main account's needs none"; +const HINT = "The plan's usage is told only to the Alibaba Cloud account's AccessKey (console → AccessKey), not to the plan's API key. Give its AccessKey ID and Secret here for the Usage page to show it. It is used for nothing else."; +const plan = { chat: "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1", anthropic: "https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic" }; +const ali = { + id: "bailian-token-plan", name: "Bailian Token Plan", icon: "alibabacloud-color", preset: "bailian-token-plan", ...plan, responses: "", catalog: "", + models: [{ id: "qwen3.6-plus", name: "qwen3.6-plus", on: true }], agents: [], fallback: [], headers: {}, + key: { set: true, masked: "sk-sp-…ab12" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", + accessKey: { vendor: "alibaba", id: "LTAIsaved", secretSet: true }, +}; +const volc = { + id: "volcengine", name: "Volcengine Ark", icon: "volcengine", preset: "volcengine", chat: "https://ark.cn-beijing.volces.com/api/coding/v3", responses: "", anthropic: "", catalog: "", + models: [], agents: [], fallback: [], headers: {}, key: { set: true, masked: "ark-…key" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", + accessKey: { vendor: "volcengine", id: "", secretSet: false }, +}; + +// the card's error as aliAskUsage words it on BailianGateway.Team.NotAuthorised +async function refusal() { + const src = await fs.readFile(path.resolve(__dirname, "../../provider/alibaba_usage.go"), "utf8"); + const hint = /\baliRAMHint\s*=\s*"((?:[^"\\]|\\.)*)"/.exec(src); + assert.ok(hint, "aliRAMHint is in alibaba_usage.go"); + return `Alibaba Cloud's console: BailianGateway.Team.NotAuthorised: ${JSON.parse(`"${hint[1]}"`)}`; +} + +function serve(lang, quotas) { + const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" }; + const providers = { providers: [ali, volc], presets: [], excluded: [], gateway: { running: true, window: true } }; + return async (route) => { + const url = new URL(route.request().url()); + const json = (body) => route.fulfill({ json: body }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/providers") return json(providers); + if (url.pathname === "/api/usage/quotas") return json(quotas); + if (url.pathname === "/api/usage/quotas/history") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + const start = async (t, view, quotas) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width: 420, height: 760 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, quotas)); + await page.goto(`http://magpie.test/?view=${view}`); + const said = lang === "en" ? [GRANTS, HINT] : await page.evaluate(([l, keys]) => keys.map((k) => I18N[l][k]), [lang, [GRANTS, HINT]]); + return { page, errors, said }; + }; + const fits = async (page) => { + const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + assert(over <= 0, `the page scrolls sideways by ${over}px`); + }; + + test(`${engine} ${lang}: the editor says what an Alibaba Token Plan's AccessKey needs, under its AccessKey ID`, async (t) => { + const { page, errors, said: [grants, hint] } = await start(t, "providers", []); + if (lang !== "en") { + const missing = await page.evaluate(([l, keys]) => keys.filter((k) => !I18N[l][k]), [lang, [GRANTS, HINT]]); + assert.deepEqual(missing, [], "said in this language"); + } + assert.ok(grants && hint); + await page.locator(".row.provider", { hasText: "Bailian Token Plan" }).click(); + const ak = page.locator(".editor .volc-ak"); + await ak.waitFor(); + // the note sits right under the AccessKey ID, and its input reads it + const note = ak.locator("xpath=following-sibling::div[contains(@class,'hint')]"); + assert.equal((await note.textContent()).trim(), grants); + assert.equal(await ak.getAttribute("aria-describedby"), await note.getAttribute("id")); + for (const name of ["AliyunTokenPlanReadOnlyAccess", "AliyunBSSReadOnlyAccess"]) assert.ok(grants.includes(name), `${grants} names ${name}`); + const tips = await page.locator(".editor .hint").allTextContents(); + assert.ok(tips.includes(hint), tips.join(" | ")); + assert.ok(!tips.some((x) => /Model Studio is enough|百炼使用权限|百鍊使用權限|利用できる RAM|nutzen darf/.test(x)), "the wrong 'any Model Studio RAM user' is gone"); + await fits(page); + + // another vendor's access key has no such note + await page.keyboard.press("Escape"); + await page.locator(".row.provider", { hasText: "Volcengine Ark" }).click(); + const vak = page.locator(".editor .volc-ak"); + await vak.waitFor(); + assert.equal(await vak.locator("xpath=following-sibling::div[contains(@class,'hint')]").count(), 0); + assert.ok(!(await page.locator(".editor").textContent()).includes("AliyunTokenPlan")); + assert.deepEqual(errors, []); + }); + + test(`${engine} ${lang}: a card refused for a RAM user's grants says them in the reader's language`, async (t) => { + const raw = await refusal(); + const quotas = [ + { provider: "bailian-token-plan", name: "Bailian Token Plan", icon: "alibabacloud-color", plan: "Token Plan", error: raw, windows: [] }, + ]; + const { page, errors, said: [grants] } = await start(t, "usage", quotas); + const err = page.locator(".subscription-card", { hasText: "Bailian Token Plan" }).locator(".subscription-error"); + await err.waitFor(); + assert.equal(await err.getAttribute("title"), raw, "the raw refusal in the tooltip"); + assert.ok((await err.textContent()).includes(grants), await err.textContent()); + if (lang !== "en") assert.ok(!(await err.textContent()).includes("from the main account"), "not the English refusal"); + await fits(page); + assert.deepEqual(errors, []); + }); + } +} diff --git a/internal/provider/alibaba_usage.go b/internal/provider/alibaba_usage.go index 33bf9749f..3aba498d6 100644 --- a/internal/provider/alibaba_usage.go +++ b/internal/provider/alibaba_usage.go @@ -65,7 +65,7 @@ const ( // two system policies the Bailian and ModelStudio ones don't include, // and a permission given in Model Studio's own console. Without the // last the console answers BailianGateway.Team.NotAuthorised (#6506). - aliRAMHint = "a RAM user's AccessKey needs, from the main account: the AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess system policies in the RAM console (AliyunBailian* and AliyunModelStudio* policies don't cover the Token Plan), and the Administrator or Subscribe Plan permission for this RAM user on the Account Management page of the Model Studio (Bailian) console. Or use the main account's own AccessKey" + aliRAMHint = "a RAM user's AccessKey needs, from the main account: the AliyunTokenPlanReadOnlyAccess and AliyunBSSReadOnlyAccess system policies in the RAM console (AliyunBailian* and AliyunModelStudio* policies don't cover the Token Plan), and the Administrator or Subscription plan permission for this RAM user on the Account Management page of the Model Studio (Bailian) console. Or use the main account's own AccessKey" // aliTokenTTL is how long a console token is kept before a new one is // made; one the console refuses is made again at once aliTokenTTL = 20 * time.Minute diff --git a/internal/provider/alibaba_usage_test.go b/internal/provider/alibaba_usage_test.go index acc9506c8..520200502 100644 --- a/internal/provider/alibaba_usage_test.go +++ b/internal/provider/alibaba_usage_test.go @@ -213,7 +213,7 @@ func TestAliGatewayRAMNotAuthorised(t *testing.T) { if err == nil { t.Fatal("no error") } - for _, want := range []string{"BailianGateway.Team.NotAuthorised", "AliyunTokenPlanReadOnlyAccess", "AliyunBSSReadOnlyAccess", "Account Management", "Administrator or Subscribe Plan", "main account's own AccessKey"} { + for _, want := range []string{"BailianGateway.Team.NotAuthorised", "AliyunTokenPlanReadOnlyAccess", "AliyunBSSReadOnlyAccess", "Account Management", "Administrator or Subscription plan", "main account's own AccessKey"} { if !strings.Contains(err.Error(), want) { t.Errorf("%q doesn't say %q", err, want) }