Introduction¶
DeepSeek Harness (DSH) extends its functionality through plugins. ikoude/dsh-cnb2api is a connectivity tool plugin that lets you use your own CNB workspace’s cnb2api gateway within DSH. The real problem is singular: workspace addresses change, and workspaces get shut down. Every time the platform restarts a workspace, it assigns a new random subdomain (<random>-<port>.cnb.run). Once stopped, it stops responding and no one is notified. The plugin therefore provides two things: background monitoring of these two changes, and a stable local gateway (http://127.0.0.1:41729/v1) whose address never changes. You configure it once in DSH’s official provider, and from then on—address drift, account switching, quota exhaustion—all happen behind the gateway. No more config changes.
What It Does¶
The plugin provides the following capabilities:
- Provider: Automatically writes CNB2API (route
cnb-gateway) into “Settings → Models”—select it and start chatting - Gateway: Fixed base URL
http://127.0.0.1:41729/v1(configurable); hides address drift and account switching - Tools:
cnb2api_statusfor status ·cnb2api_startto start ·cnb2api_quotato check quota - Routes:
GET /cnb2api/status·POST /cnb2api/start(requiresContent-Type: application/json) - Login routes:
POST /cnb2api/login/{token,orgs,repos,proxy-key}— exchanges a token for dropdown options, validates PROXY_KEY - Backup routes:
POST /cnb2api/backup/{export,import,webdav}— export/import accounts and settings, save locally or to WebDAV - UI: Floating orb (draggable, dismissible) + plugin detail page with a status panel (including quota progress bars) and configuration forms
The UI doesn’t occupy the chat area: the floating orb sits in a window corner, while the detailed status panel lives in Settings → Plugins → CNB2API. Workspace status is something you check “when needed,” not something that should take up a line in every conversation.
The Floating Orb¶
A 44px orb in the window corner, using color to answer “can I use it right now.” The face is a ring progress bar showing the total quota consumption ratio (0–100%, integer); hover the mouse for details.
| Ring color | Meaning |
|---|---|
| Green | Available |
| Yellow | Quota exhausted / starting up |
| Red | Configuration issue (token, permissions, repository) |
| Gray | Not configured / quota unreadable (no arc drawn, doesn’t falsely report 0%) |
Percentage = (used + frozen) as a proportion of total. Frozen is a pre-deduction (see Section 4); at that moment the quota is already unavailable. Counting only used would severely underestimate consumption.
- Click to expand a card: one row per account (dot + name + badge + quota bar) + start button + “Open plugin page.” The card header (refresh/close) and footer buttons stay fixed; only the middle account list scrolls.
- Drag to reposition (displacement under 4px counts as a click); position is stored in the browser.
- Attached to
shell.overlay—the full-window overlay is inherently click-through, so the orb only occupies its own 44px. - Toggle is in the global settings section of the config form (“Show floating orb”). This is a browser preference; it takes effect immediately.
The orb can only stay within the window: DSH client plugins run inside the page and the plugin API has no capability to create desktop windows. To truly float on the desktop, you’d need to modify the DSH desktop app itself.
It does not do three things: doesn’t restart workspaces (restart takes 30–90s and changes the address), doesn’t pick repositories for you, doesn’t merge org quotas (CNB doesn’t support it).
Why Not Just Fill in the Workspace Address Directly¶
Because both ends are moving:
- The workspace address changes every restart (
<random>-<port>.cnb.run); - DSH’s own web port also changes every startup.
So “fill once, works forever” requires a fixed entry point. The gateway is that entry point. It also solves two other things:
| Need | How the gateway handles it |
|---|---|
| Address drift | Fetches the current address per request; no config changes needed |
| Multiple accounts | Picks an available one; on upstream 402/5xx, within the same request switches to the next |
| Quota exhaustion | Failed accounts get a 60s cooldown, during which they’re deprioritized (demoted, not excluded) |
Configuration¶
Configure in Settings → Plugins → CNB2API → Detail Page. Each account follows four steps:
① CNB Access Token Paste, then click "Verify & Login"
② Organization Dropdown, from the list this token can actually access
③ Repository Dropdown, from the selected org; marks "Running" existing workspaces
④ PROXY_KEY The env value in that repository's .cnb.yml
Why verify first: You can’t remember org names or repo names, and a typo won’t produce an error—the plugin would silently connect to a different repository’s workspace. So step ① uses the token to retrieve identity and the org list; steps ② and ③ are both selected from real data.
- The org list merges three sources (
/user/repos,/user,/user/groups); looking at any single source would miss entries. - The repo list marks “Running,” because an org may have several repositories and only the running one is what you need.
- If the token starts with
sk-, it immediately flags “This is a PROXY_KEY, not an access token”—no need to wait for a 401 from CNB. - Changing the token resets to unverified state: the old org and repo lists are no longer trustworthy.
- PROXY_KEY is hidden by default; click “Show” to verify—a 40-character key isn’t realistic to eyeball-compare.
The three credential types differ:
| Credential | Purpose | Where to find |
|---|---|---|
| CNB Access Token | Call CNB OpenAPI: list workspaces, read logs, start | CNB avatar → Access Tokens |
| Organization/Repository | Determines both the address and the account | Steps ② and ③ |
| PROXY_KEY | Used as upstream Authorization when the gateway forwards |
That repository’s .cnb.yml under env |
Token Permissions¶
| Scope | Purpose | What happens without it |
|---|---|---|
repo-cnb-trigger:r |
Read startup logs to get address | Unusable: can’t retrieve address |
account-engage:r |
List workspaces | Unusable: can’t find workspaces |
repo-cnb-trigger:rw |
Start a stopped workspace | Address still follows, but won’t auto-restart when stopped |
group-resource:r |
Display AI credits and compute hours | No quota display; no pre-start blocking |
repo-cnb-detail:r |
Prefer detail endpoint for address | Falls back to reading logs, slightly slower |
Minimum viable combination: repo-cnb-trigger:rw + account-engage:r.
Other Settings¶
| Field | Default | Description |
|---|---|---|
models |
deepseek-v4.1-flash |
Model list (comma-separated), written to the provider for selection |
checkSeconds |
120 (min 30) | Health-check interval |
autoStart |
true |
Whether to auto-restart after workspace stops |
branch |
main |
Branch used for startup |
port |
9001 | cnb2api port inside the workspace |
gatewayHost |
0.0.0.0 |
Gateway listen address; 127.0.0.1 for local only |
gatewayPort |
41729 | Gateway listen port; auto-increments if occupied |
gatewayKey |
Auto-generated | Key for clients calling the gateway; empty means auto-generate |
autoPublish |
true |
Auto-write base URL/key into “Settings → Models” |
lowCreditPercent |
5 | Balance warning threshold (%); prompts below this value, account still usable |
creditFloorPercent |
1 | Balance floor threshold (%); stops using that account below this; 0 means no floor |
lowCreditMessage |
Empty | Notice message template; empty uses default sentence |
locale |
auto |
UI language (auto follows browser); tool output auto uses Chinese, explicit en uses English |
webdavUrl |
Empty | WebDAV backup target (directory or full path); directory-only auto-appends cnb2api-backup.json |
webdavUser / webdavPassword |
Empty | WebDAV credentials; stored in local profile only, not exported in backup |
autoBackup |
false |
Auto-upload backup to WebDAV after saving config (restore still manual) |
apiBase |
https://api.cnb.cool |
CNB OpenAPI base URL (rarely changed; only in cordis.patch.yml) |
Warning Threshold vs. Floor Threshold (Two Distinct Things)¶
Warning threshold lowCreditPercent |
Floor threshold creditFloorPercent |
|
|---|---|---|
| Effect | Notice | Hard stop |
| Below it | Still accepts work; UI shows a notice | Completely excluded: gateway rejects, no auto-start |
| Default | 5% | 1% |
| To disable | —(always shows notice) | Set to 0 |
The floor threshold’s purpose is to leave yourself a safety margin: a task might blow through quota in its final step; keeping 1% lets you stop before overage. The cost is that the last task might get blocked.
The availability check is consistent: reachable && !flagged-faulty && available ≥ floor. When quota is unreadable, it doesn’t block—asserting “insufficient” without a number would lock out accounts that might work.
Customizable Low-Balance Notice (Under Warning Threshold)¶
When below the warning threshold, you can write your own sentence in “Config → Global → Low-balance notice message,” using variables to insert real numbers:
{account} quota alert: {consumed}/{total} {unit} used ({percent}%), only {remain} {unit} left
→ qdirs/cnb2api quota alert: 1157.7/1166 cr used (99.29%), only 8.3 cr left
| Variable | Meaning |
|---|---|
{account} |
Account (org/repo) |
{used} |
Settled consumption |
{frozen} |
Pre-deduction (frozen) |
{consumed} |
{used} + {frozen}, actual consumption |
{remain} |
Book-available (after deducting frozen) |
{total} |
Total (including bonus) |
{percent} |
Consumption percentage, two decimal places |
{threshold} |
Current warning threshold |
{unit} |
Unit (cr) |
All numbers are computed by the plugin—do not assemble them yourself in the template: the difference between used and consumed, and between remain and total − used, is easy to mix up. Incorrect placeholders are left as-is, so you can spot them. In the same sentence, {consumed} + {remain} equals {total} (self-consistent under display precision).
The config page shows a description next to each variable, plus a live example—rendered with your in-progress text and a set of realistic numbers, so you can see the effect without saving. The default short sentence is “Quota nearly exhausted · Please top up.”
The same message is also written into the gateway response header x-cnb2api-credit-notice (percent-encoded, since HTTP headers must be ASCII), for non-DSH clients to read.
Account Backup & Restore¶
At the bottom of the config page there’s a “Backup & Restore” section that packages accounts and/or settings into a single JSON file, savable locally or to WebDAV.
- Backup content is optional: accounts only, settings only, or both. Accounts include
token/repo/proxyKey/branch/port; settings include health check, gateway, warning/floor thresholds, model list, etc. The gateway access keygatewayKeyis excluded from backup (local credential; should be regenerated on a new machine). - Password-encrypted by default (AES-256-GCM, key derived via scrypt). Leave the password empty to export plaintext JSON—contains full tokens; mind file storage. A wrong password produces a clear error; no partial data is leaked.
- Restore is a merge: aligned by repository; same repo uses the backup’s values, new repos are appended, other existing accounts are preserved.
- Local: Export downloads a
.json; import selects a file. - WebDAV: Fill in URL/account/password to upload or download-and-import; requests are proxied through the Host (WebDAV generally lacks CORS headers; direct browser connections get blocked). Checking “Auto-upload after save” silently pushes a backup after each successful config save. Restore is always manual—it will never auto-overwrite local accounts.
Config Page Organization¶
With many accounts and many settings, the page gets long. Two things were done:
- Account cards are collapsible: each card has a collapse arrow in the top-left; when there’s more than one account, the section header also has “Collapse All / Expand All” to compress the page to one line per account.
- Global settings are grouped: Health check / Gateway / Balance & notices / Other—four subsections with sub-headers, no longer one long homogeneous list.
Gateway Security Boundary¶
Listening on 0.0.0.0 means opening “spend your quota” to the entire LAN, so:
- Without an access key, listening on non-loopback addresses is refused (not a warning—startup fails);
- Every request validates
Authorization: Bearer <key>using constant-time comparison; - The client’s key is only for accessing this gateway; upstream always uses the workspace’s own
PROXY_KEY; - The key is auto-generated on first run and written back to config; unchanged across restarts.
LAN devices can connect using the http://<LAN IP>:41729/v1 + access key shown on the plugin page.
How to Read Status¶
Two things per account: the dot answers “can it handle requests,” the badge answers “where is it stuck.”
| Status | Meaning | Start button? |
|---|---|---|
| Ready | Running, address reachable, quota sufficient | No |
| Quota exhausted | Org AI credits at zero: both start and requests will fail | No (reason explained) |
| Unreachable | Running, but gateway can’t connect | No |
| Stopped | Workspace instance exists, not running | Yes |
| No workspace | Never created for this repo | Yes |
| Starting | Just submitted, waiting for ready | No |
| Config issue | Hard failure: token, permissions, repository | No |
Quota exhausted overrides “Stopped”: when stopped, quota is also zero. Just saying “stopped” would make people think starting an instance would fix it.
Only four color rules, all converging on “normal state doesn’t alarm”:
| Semantics | Color | Where used |
|---|---|---|
| Normal consumption | Business blue | Quota progress bar |
| Used up | Neutral gray | Empty slot in progress bar, exhausted-row text |
| Needs your attention | Orange | Only the “balance below warning threshold” message |
| Real fault | Red | Only “config issue” |
Address is masked by default (860l****-9001.cnb.run) because status is often shared in screenshots; set CNB2API_SHOW_FULL_HOST=1 to see the full address.
How Quota Is Calculated (Including “Frozen”)¶
CNB’s quota endpoint has three fields with different scopes; together they add up to a complete picture:
| Field | Meaning |
|---|---|
total |
Total, including bonus quota |
used |
Settled consumption |
frozen |
Pre-deduction: quota occupied while workspace is running |
remain |
total − used − frozen |
Frozen Is Not a Deposit, It’s a Pre-Deduction¶
Measured (before vs. after stopping the workspace):
| Before stop | After stop | |
|---|---|---|
| used | 477.94 | 1124.33 |
| frozen | 642.71 | 0 |
| remain | 45.35 | 41.67 |
When frozen drops to zero, used jumps by 646—it’s not a refund, it’s a transfer. The quota was already deducted at the moment of freezing; stopping just changes the ledger label. So:
- The progress bar uses
used + frozen; counting onlyusedseverely underestimates (at the above moment: 41% vs. actual 96%); remainis the only number you can trust for “how much is left”—it already deducts frozen;- The UI labels frozen as “pre-deducted,” with a hover tooltip: “Already deducted from quota; counted as used after workspace stops; not refunded.”
quota.total includes bonus quota; subtract it when calculating the base, otherwise the same bonus is counted twice.
Not Wasting Compute Hours for Nothing¶
cnb2api is an AI gateway: when an org’s AI credits are exhausted, it returns 402 [EXCEEDING_LIMIT] AI credits exhausted for every request. Starting a workspace at that point just wastes 30–90s and consumes compute hours. So quota is checked before starting:
| Situation | Behavior |
|---|---|
| Quota exhausted | Don’t submit start; log once; auto-starts on next check once quota recovers |
| Quota unreadable | Start as normal: blocking a working account is worse than letting one through that will 402 |
| Balance low but > 0 | Start as normal, no pre-blocking (but UI shows warning per threshold) |
Connecting to DSH’s Model Provider¶
The plugin does not implement the LLM protocol layer—that’s handled by DSH’s official OpenAI-compatible provider (@deepseek-ai/dsh-llm-pi-ai), which already includes request/stream translation, image encoding, usage tracking, retries, and context budget. Rewriting it yourself means doing the same thing twice, and each implicit requirement in DSH that’s missed becomes a user-visible bug.
So the plugin does one thing: write “fixed base URL + key + model list” into the official config entry.
Plugin (follow address / switch account / check quota)
↓
Gateway http://127.0.0.1:41729/v1
↓
CNB2API in Settings → Models (route cnb-gateway)
- Writes to
llm-pi-ai’sproviders.cnb-gateway, by path, without touching your own configured providers. - Key stored in the credential store (reference name
CNB2API_GATEWAY_KEY); config file only has the reference name. - Turning off the “Auto-connect” toggle retracts this route.
- Model list comes from the
modelsconfig (comma-separated, defaultdeepseek-v4.1-flash).
Installation & Activation¶
Install from the plugin directory or GitHub repository (official channels preferred):
- Directory: https://www.skillhub.cn/plugins/ikoude/dsh-cnb2api
- GitHub: https://github.com/ikoude/dsh-cnb2api
After enabling, go to “Settings → Plugins → CNB2API → Detail Page” and follow the steps to configure CNB access token, organization, repository, and PROXY_KEY, then turn on “Auto-connect.”
Use Cases & Notes¶
Suited for developers who need to use CNB workspaces as a long-term AI gateway and don’t want to repeatedly modify configuration. The plugin runs with the current DSH process permissions; review the source code and license (MIT) before installing.
In Short¶
dsh-cnb2api shields you from workspace address drift and downtime through a local gateway, so you maintain a single configuration in DSH. It provides a floating orb, status panel, quota calculation, and backup/restore—confining the tedious ops details within the gateway and plugin internals. If you need a stable, long-term connection to a CNB workspace as an AI gateway, this is a solution worth considering.
Directory: https://www.skillhub.cn/plugins/ikoude/dsh-cnb2api
GitHub: https://github.com/ikoude/dsh-cnb2api