codearts 0.2.0: Huawei Cloud CodeArts (码道) coding plans, with Huawei Cloud OAuth sign-in (#284)

New package @magpie-community/opencode-codearts-auth 0.2.0 (Sakura-Natsu): Huawei Cloud CodeArts (码道) coding plans, with Huawei Cloud OAuth sign-in, request signing (SDK-HMAC-SHA256), a per-account cap of 3 in-flight sessions, per-account free/regular model lists, and requests signed only for https Huawei Cloud hosts.

Reviewed head 31099104 (two rounds; the first asked for changes at a793ca5, all fixed here). Run at the reviewed head, macOS, bun 1.4.2, with a preload that allows only loopback network:
- HOME=$(mktemp -d) bun test packages/codearts: 91 pass, 0 fail
- HOME=$(mktemp -d) bun test (whole repo): 2011 pass, 0 fail
- bun scripts/check.mjs: 21 ok
- 10 parallel bun test --rerun-each 40 in packages/codearts: 0 fail
- 22 hand breaks (signature, DPoP proof, 403 expired mark, session clamp, host check, per-account lists, callback server, refresh mark); 21 went red. The one green is the callback's prefix-path match (follow-up).

Not tried against Huawei's real API (no credentials); sign-in, signature acceptance, session counting and metering rest on the author's use on two accounts. Follow-ups: list the exact Huawei hosts instead of *.myhuaweicloud.com / *.huaweicloud.com; fail at once on a callback with no code; drop the unused ticketId; exact callback path match. This is a new npm name, so its first publish needs an owner.
This commit is contained in:
Rahayu Kertawiguna
2026-10-21 07:55:51 +08:00
committed by GitHub
parent b3afe11631
commit 6579f0682a
7 changed files with 4100 additions and 0 deletions
+1
View File
@@ -12,6 +12,7 @@ subscription and makes its requests. The packages work in OpenCode and in
| Package | Signs in to | Provider id |
|---|---|---|
| [cline](packages/cline) | Cline (cline.bot): usage-billed models, ClinePass's and Cline's free ones, with Cline's device sign-in or an API key | `cline` |
| [codearts](packages/codearts) | Huawei Cloud CodeArts (码道) coding plans (Trial, personal and enterprise credits), with Huawei Cloud OAuth sign-in (unofficial) | `codearts` |
| [commandcode](packages/commandcode) | Command Code plans (Pro, GOAT, Max, Ultra, Go, Teams Pro) | `commandcode-plan` |
| [cursor](packages/cursor) | Cursor subscriptions (Pro, Pro+, Ultra, Teams), on the API cursor-agent talks to | `cursor` |
| [devin](packages/devin) | Devin subscription (the devin CLI's account) | `devin` |
+22
View File
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2026 yuweihao17
Copyright (c) 2026 Sakura-Natsu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+121
View File
@@ -0,0 +1,121 @@
# @magpie-community/opencode-codearts-auth
Signs in to **Huawei Cloud CodeArts** (华为云码道, the CodeArts Agent coding plans: Trial,
personal and enterprise credit plans) and serves its models — GLM, DeepSeek, openPangu and
more — in OpenCode and magpie. Provider id: `codearts`.
> **Unofficial.** This package is not affiliated with, authorized or endorsed by Huawei,
> Huawei Cloud or CodeArts; their names and marks belong to their owners. It talks to the
> non-public APIs the CodeArts client uses and identifies itself the way that client does
> (including claiming the daily free benefit and check-in), which may not be allowed by Huawei
> Cloud's terms of service, and those APIs may change at any time. Use it at your own risk,
> including the risk of restrictions on your account.
## Install
```sh
magpie plugin add @magpie-community/opencode-codearts-auth
magpie plugin login codearts
```
or install it from magpie's Plugins tab and sign in there.
## Sign-in
**Sign in with Huawei Cloud** opens Huawei Cloud's consent page. The plugin listens on a
loopback port (`127.0.0.1`, ≥ 10000) for the redirect and exchanges the code at Huawei Cloud
STS — a PKCE flow whose token requests carry an ES256 DPoP proof, as the CodeArts client does.
STS answers with temporary AK/SK/security-token credentials and a refresh token.
**Where it is kept:** the whole credential (AK/SK/security token, expiry, refresh token, the
PKCE verifier and the DPoP private key) is a JSON string in the account's `access` field, in
magpie's (or OpenCode's) own account store. `auth.refresh` renews it 30 minutes before it
expires, reusing the same verifier and DPoP key; a stale credential met on a request
(`401`, `APIG.0602`) is renewed once and the request sent again. The account id is the signer
named in the refresh token, so signing in again replaces the account instead of adding one.
## Models
The account's live list: CodeArts' builtin models, plus the free models of its daily benefit
once today's benefit has been claimed (`POST /api/v1/benefit/claim`, once a Beijing day, as the
client does). Each model's credit rate (the client's 「消耗系数」) is reported as magpie's `rate`,
with its reasoning flag and limits, from the account's main agent (`build`) model list. Before
signing in, a short built-in catalog stands in.
## Requests
- Every request is signed with Huawei's SDK-HMAC-SHA256 using the temporary credentials.
- The gateway allows 3 concurrent sessions per account and tells them apart by
`x-ot-session-id`; the plugin sends one stable session id per account (and a fresh trace per
request) like the client, keeps at most 3 chats in flight per account, retries
`TM.00001041` with backoff, and waits in the gateway's own queue (`429` +
`queue-status: queued`) the way the client does. Only then does magpie get a `429`.
- Chats always go upstream as streams — CodeArts meters only streamed answers — and are folded
back into one `chat.completion` when the caller asked for JSON.
- `thinking: { type: "enabled" }` is sent unless the caller set it, so the reasoning lands in
`reasoning_content` and `content` is only the reply.
- Errors the gateway puts inside a `200` stream (spent quota, unknown model) come back as
`429` / `400` / `502` with the vendor's words. The `codearts/` prefix is stripped and output
budgets are clamped to 65536.
## Usage and check-in
- Usage: the credit buckets of `snap-manager/v1/statistics/plugin` (only the package total
pauses the account; the basic / on-demand / bonus buckets are shown aside) and the free daily
token pool.
- When each credit batch expires is read from the CodeArts console's own calls
(`snap-manager/v1/package/credit/page`, `v1/ops/credit/*`); when those can't be read, the
plugin falls back to a small ledger of the check-ins it claimed,
`~/.config/magpie/codearts-checkins.json` (or `MAGPIE_CODEARTS_LEDGER`). This part is still
being checked against more accounts — trust the CodeArts console where they differ.
- `auth.checkin`: the client's 「限时福利 → 每日领取」 — `GET /v1/ops/delivery?channel=IDE`,
`POST /v1/ops/claim`, then `POST /v1/ops/confirm` when the claim answers an id. Turn on
*Auto check-in* for CodeArts under **Settings → Usage → Plugins**.
## Options
| Option | Default | What it does |
|---|---|---|
| `maxInflight` | `3` | chats in flight per account; it can only lower the vendor's cap of 3 sessions |
| `retryBudgetMs` | `150000` | how long to retry `TM.00001041` before answering `429` |
| `retryDelays` | `[2000,4000,6000,8000,10000]` | retry waits in ms (the last repeats) |
| `queueBudgetMs` | `300000` | how long to wait in the gateway's queue |
| `thinking` | `true` | `false` stops adding `thinking: { type: "enabled" }` |
## Credits
First written by [yuweihao17](https://github.com/yuweihao17/codearts); this version carries the
fixes of [yuweihao17/codearts#8](https://github.com/yuweihao17/codearts/pull/8). It builds on the
measurements and code of [HuHong-Tao](https://github.com/yuweihao17/codearts/pull/6) and
[ReachForStar](https://github.com/ReachForStar/codearts), and on the CodeArts channel of
[Ebony-Vinyl/dsh-our-free-model](https://github.com/Ebony-Vinyl/dsh-our-free-model).
## 中文
接入**华为云码道(CodeArts Agent)**的编码套餐(体验版、个人与企业积分套餐),在 OpenCode 和
magpie 里使用其 GLM、DeepSeek、openPangu 等模型。provider id:`codearts`。
> **非官方插件**:与华为、华为云及 CodeArts(码道)没有任何关联,也未获其授权或认可。插件调用的是
> 码道客户端使用的非公开接口,并以与官方客户端相同的方式标识自己(含自动领取每日免费权益与签到),
> 这可能不符合华为云的服务条款,接口也可能随时变更。使用风险(包括账号受限)由使用者自行承担。
- **登录**:华为云 OAuth(PKCE + DPoP),本机 `127.0.0.1`(端口 ≥ 10000)接收回调,向 STS 换取临时
AK/SK/security-token。完整凭据(含 refresh_token、PKCE verifier、DPoP 私钥)以 JSON 存在账号的
`access` 字段里,保存在 magpie / OpenCode 自己的账号存储中;过期前 30 分钟自动续期,请求遇到临时凭据
过期时就地续期并重发一次;账号标识取自 refresh_token,重复登录不会多出账号。
- **模型**:账号实时的内置模型列表;领取当日免费权益成功后,再加上免费模型(每个北京自然日领一次,与
客户端一致)。每个模型的「消耗系数」作为 magpie 的倍率上报,来自账号主智能体(`build`)的模型列表。
- **请求**:SDK-HMAC-SHA256 签名;像客户端一样发送 `x-ot-session-id` 会话头(每账号一个会话),账号内
在途请求不超过 3 个,`TM.00001041` 退避重试,网关排队时按客户端的方式等待;总是以流式请求上游(码道
只对流式回答计量积分),调用方要非流式时折叠回 JSON;默认注入 `thinking: { type: "enabled" }`,思考与
正文分开;200 里内嵌的错误换算为 `429` / `400` / `502` 并带厂商原话。
- **用量与签到**:总积分决定账号是否可用,其余积分桶只做明细;另有每日免费额度窗口。各批积分的到期
时间读自码道控制台同一批接口,读不到时退回插件的签到账本 `~/.config/magpie/codearts-checkins.json`
(这部分仍在用更多账号验证,请以控制台为准)。`auth.checkin` 与客户端「限时福利 → 每日领取」一致,
在 **设置 → 用量 → Plugins** 打开「每日自动签到」即可。
- **致谢**:原作者 [yuweihao17](https://github.com/yuweihao17/codearts);HuHong-Tao、ReachForStar 的
实测与实现;[Ebony-Vinyl/dsh-our-free-model](https://github.com/Ebony-Vinyl/dsh-our-free-model)。
## License
MIT — see [LICENSE](./LICENSE).
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+34
View File
@@ -0,0 +1,34 @@
{
"name": "@magpie-community/opencode-codearts-auth",
"version": "0.2.0",
"description": "Huawei Cloud CodeArts (码道) in OpenCode and magpie: its models through Huawei Cloud OAuth sign-in, signed requests, credit usage and the daily check-in (unofficial)",
"type": "module",
"main": "./index.mjs",
"exports": "./index.mjs",
"files": [
"index.mjs",
"README.md",
"LICENSE"
],
"scripts": {
"test": "bun test"
},
"keywords": [
"opencode",
"opencode-plugin",
"magpie",
"codearts",
"huaweicloud",
"oauth"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/magpie-community/plugins.git",
"directory": "packages/codearts"
},
"magpie": {
"maxConcurrency": 3,
"icon": "data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjQ0YwQTJDIiByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+SHVhd2VpPC90aXRsZT48cGF0aCBkPSJNMy42NyA2LjE0UzEuODIgNy45MSAxLjcyIDkuNzh2LjM1Yy4wOCAxLjUxIDEuMjIgMi40IDEuMjIgMi40IDEuODMgMS43OSA2LjI2IDQuMDQgNy4zIDQuNTUgMCAwIC4wNi4wMy4xLS4wMWwuMDItLjA0di0uMDRDNy41MiAxMC44IDMuNjcgNi4xNCAzLjY3IDYuMTR6TTkuNjUgMTguNmMtLjAyLS4wOC0uMS0uMDgtLjEtLjA4bC03LjM4LjI2Yy44IDEuNDMgMi4xNSAyLjUzIDMuNTYgMi4yLjk2LS4yNSAzLjE2LTEuNzggMy44OC0yLjMuMDYtLjA1LjA0LS4wOS4wNC0uMDl6bS4wOC0uNzhDNi40OSAxNS42My4yMSAxMi4yOC4yMSAxMi4yOGMtLjE1LjQ2LS4yLjktLjIxIDEuM3YuMDdjMCAxLjA3LjQgMS44Mi40IDEuODIuOCAxLjY5IDIuMzQgMi4yIDIuMzQgMi4yLjcuMyAxLjQuMzEgMS40LjMxLjEyLjAyIDQuNCAwIDUuNTQgMCAuMDUgMCAuMDgtLjA1LjA4LS4wNXYtLjA2YzAtLjAzLS4wMy0uMDUtLjAzLS4wNXpNOS4wNiAzLjE5YTMuNDIgMy40MiAwIDAwLTIuNTcgMy4xNXYuNDFjLjAzLjYuMTYgMS4wNS4xNiAxLjA1LjY2IDIuOSAzLjg2IDcuNjUgNC41NSA4LjY1LjA1LjA1LjEuMDMuMS4wM2EuMS4xIDAgMDAuMDYtLjFjMS4wNi0xMC42LTEuMTEtMTMuNDItMS4xMS0xMy40Mi0uMzIuMDItMS4xOS4yMy0xLjE5LjIzem04LjI5OSAyLjI3cy0uNDktMS44LTIuNDQtMi4yOGMwIDAtLjU3LS4xNC0xLjE3LS4yMiAwIDAtMi4xOCAyLjgxLTEuMTIgMTMuNDMuMDEuMDcuMDYuMDguMDYuMDguMDcuMDMuMS0uMDMuMS0uMDMuNzItMS4wMyAzLjktNS43NiA0LjU1LTguNjQgMCAwIC4zNi0xLjQuMDItMi4zNHptLTIuOTIgMTMuMDdzLS4wNyAwLS4wOS4wNWMwIDAtLjAxLjA3LjAzLjEuNy41MSAyLjg1IDIgMy44OCAyLjMgMCAwIC4xNi4wNS40My4wNmguMTRjLjY5LS4wMiAxLjktLjM3IDMtMi4yNmwtNy40LS4yNXptNy44My04LjQxYy4xNC0yLjA2LTEuOTQtMy45Ny0xLjk0LTMuOTggMCAwLTMuODUgNC42Ni02LjY3IDEwLjggMCAwLS4wMy4wOC4wMi4xM2wuMDQuMDFoLjA2YzEuMDYtLjUzIDUuNDYtMi43NyA3LjI4LTQuNTQgMCAwIDEuMTUtLjkzIDEuMjEtMi40MnptMS41MiAyLjE0cy02LjI4IDMuMzctOS41MiA1LjU1YzAgMC0uMDUuMDQtLjAzLjExIDAgMCAuMDMuMDYuMDcuMDYgMS4xNiAwIDUuNTYgMCA1LjY3LS4wMiAwIDAgLjU3LS4wMiAxLjI3LS4yOSAwIDAgMS41Ni0uNSAyLjM3LTIuMjcgMCAwIC43My0xLjQ1LjE3LTMuMTR6Ii8+PC9zdmc+"
}
}
+2
View File
@@ -38,6 +38,8 @@
"summary": { "en": "SenseTime Raccoon (xiaohuanxiong.com) models, account credits and daily check-in, with browser sign-in or Raccoon desktop's live sign-in.", "zh": "商汤小浣熊(xiaohuanxiong.com)模型、积分余额与每日签到,支持浏览器登录或直接复用小浣熊桌面端登录态。" } },
{ "package": "@magpie-community/opencode-autoclaw-auth", "name": "AutoClaw", "providers": ["autoclaw", "autoclaw-cn"], "community": true,
"summary": { "en": "AutoClaw (Zhipu OpenClaw) cloud accounts: oversea web sign-in (Google/z.ai) or CN phone SMS, credit balance and daily check-in.", "zh": "AutoClaw(智谱澳龙/OpenClaw)云端账号:国际版网页登录(Google/z.ai)或国内手机验证码,积分余额与每日签到。" } },
{ "package": "@magpie-community/opencode-codearts-auth", "name": "CodeArts", "providers": ["codearts"], "community": true,
"summary": { "en": "Unofficial: Huawei Cloud CodeArts (码道) coding plans with Huawei Cloud OAuth sign-in — GLM, DeepSeek, openPangu, live models and credit rates, credit usage and daily check-in.", "zh": "非官方:华为云码道(CodeArts)编码套餐,华为云 OAuth 登录;GLM、DeepSeek、openPangu 等模型,实时模型与积分倍率、积分用量和每日签到。" } },
{ "package": "@magpie-community/middleware-param-override", "name": "Param Override", "kind": "middleware", "community": true,
"summary": { "en": "New API's parameter override: set, delete, move or rewrite fields of every request, by model or by condition.", "zh": "New API 的参数覆盖:按模型或条件设置、删除、移动或改写每个请求的字段。" } },
{ "package": "@magpie-community/middleware-model-map", "name": "Model Map", "kind": "middleware", "community": true,