dsh-unthrottle 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +635 -2
  3. package/bin/entry-point.mjs +19 -0
  4. package/bin/login.mjs +570 -0
  5. package/bin/providers.mjs +413 -0
  6. package/bin/smoke.mjs +146 -0
  7. package/bin/store.mjs +62 -0
  8. package/bin/unthrottle.mjs +90 -0
  9. package/client.js +1598 -0
  10. package/cordis.patch.yml +18 -0
  11. package/docs/DETAIL.de.md +1 -0
  12. package/docs/DETAIL.md +76 -0
  13. package/docs/preview.svg +50 -0
  14. package/icon.svg +7 -0
  15. package/index.js +743 -0
  16. package/lib/accounts.js +176 -0
  17. package/lib/adapter.js +515 -0
  18. package/lib/antigravity-auth.js +151 -0
  19. package/lib/catalog.js +210 -0
  20. package/lib/cockpit/host.js +151 -0
  21. package/lib/cockpit/live.js +124 -0
  22. package/lib/cockpit/prices.js +91 -0
  23. package/lib/cockpit/providers.js +194 -0
  24. package/lib/cockpit/reports.js +84 -0
  25. package/lib/cockpit/roi.js +219 -0
  26. package/lib/cockpit/signin.js +359 -0
  27. package/lib/cockpit/status.js +330 -0
  28. package/lib/cockpit/tool.js +138 -0
  29. package/lib/cockpit/turns.js +87 -0
  30. package/lib/credentials.js +785 -0
  31. package/lib/edition.js +41 -0
  32. package/lib/effort.js +47 -0
  33. package/lib/errors.js +141 -0
  34. package/lib/http.js +72 -0
  35. package/lib/hub/adapter.js +958 -0
  36. package/lib/hub/descriptor.js +519 -0
  37. package/lib/hub/keys.js +99 -0
  38. package/lib/hub/policy.js +72 -0
  39. package/lib/hub/pool-status.js +115 -0
  40. package/lib/hub/pool.js +1034 -0
  41. package/lib/hub/protocols/anthropic-messages.js +545 -0
  42. package/lib/hub/protocols/common.js +87 -0
  43. package/lib/hub/protocols/gemini.js +498 -0
  44. package/lib/hub/protocols/index.js +41 -0
  45. package/lib/hub/protocols/openai-chat.js +525 -0
  46. package/lib/hub/protocols/openai-responses.js +307 -0
  47. package/lib/hub/registry.js +137 -0
  48. package/lib/hub/yaml.js +430 -0
  49. package/lib/latency.js +97 -0
  50. package/lib/oauth.js +337 -0
  51. package/lib/openai-auth.js +354 -0
  52. package/lib/probe.js +147 -0
  53. package/lib/provider-auth.js +183 -0
  54. package/lib/providers/anthropic.js +1099 -0
  55. package/lib/providers/antigravity.js +871 -0
  56. package/lib/providers/openai.js +361 -0
  57. package/lib/providers/xai.js +318 -0
  58. package/lib/record-file.js +198 -0
  59. package/lib/responses.js +546 -0
  60. package/lib/sse.js +172 -0
  61. package/lib/tools.js +191 -0
  62. package/lib/unicode.js +32 -0
  63. package/lib/usage.js +230 -0
  64. package/lib/vendor/dsh-atomic-write.js +247 -0
  65. package/locale/de.json +7 -0
  66. package/locale/en.json +7 -0
  67. package/package.json +99 -4
  68. package/providers.d/abliteratedllm.yml +45 -0
  69. package/providers.d/anthropic.yml +16 -0
  70. package/providers.d/antigravity.yml +14 -0
  71. package/providers.d/cerebras.yml +13 -0
  72. package/providers.d/deepseek.yml +15 -0
  73. package/providers.d/fireworks.yml +12 -0
  74. package/providers.d/google.yml +11 -0
  75. package/providers.d/groq.yml +11 -0
  76. package/providers.d/kimi-code.yml +20 -0
  77. package/providers.d/lmstudio.yml +10 -0
  78. package/providers.d/minimax-coding.yml +19 -0
  79. package/providers.d/mistral.yml +12 -0
  80. package/providers.d/ollama.yml +10 -0
  81. package/providers.d/openai.yml +15 -0
  82. package/providers.d/openrouter.yml +12 -0
  83. package/providers.d/perplexity.yml +19 -0
  84. package/providers.d/together.yml +11 -0
  85. package/providers.d/xai.yml +15 -0
  86. package/providers.d/yeta.yml +24 -0
  87. package/providers.d/zai-coding.yml +28 -0
  88. package/providers.d/zhipu-coding.yml +27 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Leon Koopmann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,636 @@
1
- # Temporary Holding Version
1
+ > **Public edition.** This build has no Claude subscription sign-in and sends no
2
+ > Claude-Code identity. Use an Anthropic API key for Claude models; commands for
3
+ > anthropic logins or probes do not apply here.
4
+ >
5
+ > Install it with `dsh plugin --profile <profile> add dsh-unthrottle`.
6
+ # Unthrottle
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ > Formerly `dsh-abo-providers`. Since 0.9.0 the package is `dsh-unthrottle`, the plugin entry id is `unthrottle` and grants live under `unthrottle/<provider>`. The first start moves `abo-providers/<provider>` grant records to `unthrottle/<provider>` and removes the old copies; `abo-providers-pool.json` and `abo-providers-client.json` stay where they are and are read only as a fallback until the new name exists. `node bin/login.mjs migrate` moves the records too with DSH closed.
9
+
10
+ Subscription-plan LLM providers for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
11
+ SuperGrok / X Premium and Google Antigravity become ordinary DSH
12
+ model routes, paid for by the plan you already have, without an API key and
13
+ without a second subscription client per account.
14
+
15
+ Status: `1.1.0`, public edition. It ships the BYOK hub, the pool route and the
16
+ Grok, ChatGPT-plan and Antigravity subscription routes. The Claude subscription
17
+ route and its Claude Code identity are not part of this build: Claude models run
18
+ through the `anthropic` descriptor with an `ANTHROPIC_API_KEY`. The full edition
19
+ adds the Claude subscription route and documents its live checks.
20
+
21
+ How the pieces fit: every grant is one record in the harness credential store,
22
+ refreshed under the store's cross-process lock, and the CLI writes through the
23
+ same lock. The provider hub is the declarative registry plus four protocol
24
+ families (`openai-chat`, `openai-responses`, `anthropic-messages`, `gemini`)
25
+ and an OAuth-preset layer that carries the subscription routes themselves. A
26
+ preset with `transport: subscription` reuses the provider modules that were
27
+ checked against the vendor endpoints, so the Cloud Code envelope and the
28
+ ChatGPT-plan preview contract stay where they were tested; `routes: legacy`
29
+ keeps the direct subscription routes as an escape hatch. API keys come from the
30
+ harness credential store (then the environment), routes appear and disappear
31
+ live, coding plans and local servers ship as descriptors, and the `pool` route
32
+ fails over between members when one is rate limited, out of quota or down.
33
+ 21 descriptors ship, including two uncensored BYOK routes (`yeta`,
34
+ `abliteratedllm`). The Anthropic route takes an API key in every edition; the
35
+ plan sign-in for Claude exists in the full edition only.
36
+
37
+ ## Quickstart
38
+
39
+ 1. **Install.** Pick one way from [Install](#install). The shortest is the
40
+ npm package, which puts the `dsh-unthrottle` command on the PATH, plus the
41
+ plugin line that adds it to a DSH profile:
42
+
43
+ ```powershell
44
+ npm install -g dsh-unthrottle
45
+ dsh-unthrottle --help
46
+ dsh plugin --profile <profile> add dsh-unthrottle
47
+ ```
48
+
49
+ 2. **Sign in or store a key.** A subscription provider signs in through the
50
+ browser or a device code; an API-key provider takes its key without echo.
51
+ The CLI writes into the DSH credential store, never into a file in this
52
+ package:
53
+
54
+ ```powershell
55
+ dsh-unthrottle login xai
56
+ dsh-unthrottle providers key set <provider>
57
+ dsh-unthrottle status
58
+ ```
59
+
60
+ 3. **Restart DSH and choose a model.** The plugin loads when DSH starts. After
61
+ that, a sign-in or key set from the CLI registers its route without another
62
+ restart. Pick the route in the model picker, for example
63
+ `xai/grok-4.7`, or `pool/auto` to let the failover pool choose.
64
+
65
+ ## Features
66
+
67
+ - **Failover pool.** The `pool` route holds ordered members (`provider/model`)
68
+ and hands a request to the next member when one is rate limited, out of
69
+ quota, unauthorised, down, silent for 60 s or empty before its first chunk.
70
+ A pool sets `routing` to `balanced` (default), `fastest`, `cheapest` or
71
+ `quota`; `cheapest` has no cost signal yet. A conversation sticks to the
72
+ member that served it last (60 min, at most 500 sessions) unless that member
73
+ is cooling or its plan is nearly spent. See [Pool (failover)](#pool-failover).
74
+ - **Multi-account.** `login <provider> --account <name>` stores another grant
75
+ per provider; `accounts` lists them and `switch` activates one. The cockpit
76
+ shows the same list and the pool uses each provider's active account.
77
+ - **Cockpit.** The plugin page in DSH shows one tile per provider (live,
78
+ signed in, sign in, blocked, key), the pool chain with its last attempt order,
79
+ and an ROI card: calls, tokens and priced value per provider and month, prompt
80
+ cache hit rate (this month and over the last 50 calls, warning below 70 %),
81
+ time to first token p50 and p95 over the last 100 calls, and health per tile
82
+ (p95, failure rate, plan share) once data exists. See [Cockpit](#cockpit).
83
+ - **Quota windows.** Plan windows come from the vendor's rate-limit headers
84
+ (five-hour and seven-day windows for the Anthropic plan route, standard
85
+ rate-limit headers for xAI and the ChatGPT plan). A window at 90 % or more
86
+ logs a warning, the cockpit forecasts "full in ~n min" from the last 12
87
+ readings, and a spent window moves a pool member to the back.
88
+ - **Provider hub.** 21 declarative descriptors across four protocol families;
89
+ a user descriptor in `$DSH_HOME/providers.d` replaces a bundled one.
90
+ See [Provider hub (BYOK)](#provider-hub-byok).
91
+ - **Zero dependencies.** `package.json` declares no runtime `dependencies`,
92
+ only the harness peer dependencies. The YAML reader is a small subset
93
+ reader in `lib/hub/yaml.js`, and the lock-and-replace file write is a
94
+ verbatim copy of `@deepseek-ai/dsh-atomic-write` 0.2.2-rc.5 (MIT) under
95
+ `lib/vendor/`.
96
+
97
+ ## What it is
98
+
99
+ One Cordis plugin that registers an LLM adapter on the harness seam:
100
+
101
+ ```js
102
+ ctx.llm.registerAdapter(['anthropic', 'xai', 'openai', 'antigravity'], adapter)
103
+ ```
104
+
105
+ Exactly one tool is registered on `ctx.tools`: `unthrottle_status`, which reads the
106
+ same snapshot and runs the same repairs as the cockpit page and keeps its schema
107
+ small, because that schema rides along with every request. Once a route is
108
+ registered, the provider
109
+ behaves like any other: selectable per session, per agent, and per subagent, and
110
+ visible in the model picker with its own context window, image policy, retry
111
+ policy, and reasoning levels.
112
+
113
+ ## Status
114
+
115
+ | Provider | Route | Protocol | Live catalog (checked 2026-11-29) | Multi-turn + tools | Images |
116
+ |---|---|---|---|---|---|
117
+ | SuperGrok / X Premium | `xai` | Responses API (`/v1/responses`) | live, 7 chat models (filters `imagine-*`) | **verified** (`encrypted_content` replay) | `input_image` |
118
+ | ChatGPT plan | `openai` | Responses API via Sign in with ChatGPT | implemented (`/v1/models`, not live-tested) | offline-verified (stream contract) | `input_image` |
119
+ | Google Antigravity | `antigravity` | Cloud Code Assist (Gemini-only) | implemented (`fetchAvailableModels`) | offline-verified (`thoughtSignature`) | `inlineData` |
120
+
121
+ Claude models are BYOK in this build: the `anthropic` descriptor sends the
122
+ documented Messages API request with `x-api-key` and `anthropic-version`, native
123
+ image blocks and the thinking settings its catalog entry names, without a Claude
124
+ Code identity block and without subscription OAuth. The subscription route, its
125
+ adaptive-thinking replay and its cache behaviour belong to the full edition.
126
+ Grok runs on xAI's primary **Responses API** (`/v1/responses`), preserving
127
+ `reasoning.encrypted_content` across multi-turn agent loops, supporting `xhigh`
128
+ effort on Grok 4.5–4.7, filtering image/video generators out of the chat picker,
129
+ enriching catalog metadata from `cli-chat-proxy.grok.com`, and routing with a
130
+ stable `prompt_cache_key`.
131
+
132
+ ChatGPT plan usage is the one subscription route a vendor documents for
133
+ open-source and locally hosted apps. `login openai` registers this host as an
134
+ agent through the browser: the authorize request carries `client_id=
135
+ dynamic_agent_client`, this host's opaque `ext_agent_host_id` (a UUIDv5 of the
136
+ machine id, never a user identity) and the plan scope
137
+ `chatgpt.tokens.use.direct`; the loopback callback returns the **issued** client
138
+ id, which the grant keeps for every later sign-in and refresh. The ID token is
139
+ verified against OpenAI's published JWKS (RS256, issuer, audience, nonce, expiry)
140
+ before anything is stored, and a grant without the plan scope is refused. The
141
+ route posts to `POST /v1/responses` with the preview contract the docs require —
142
+ `store: false`, `stream: true`, system text through `instructions`, no sampler
143
+ fields, no `max_output_tokens`, no `previous_response_id` — sends tools as
144
+ function tools and falls back once to `additional_tools` input items if the
145
+ route rejects them, and maps the `subscription_sharing_*` error vocabulary onto
146
+ harness codes (usage limit → `QUOTA`, unavailable → retryable `SERVER`,
147
+ unsupported capability → `MALFORMED_RESPONSE`).
148
+
149
+ ## Install
150
+
151
+ ```powershell
152
+ # Quit DSH Desktop from the tray, then add the package to a profile:
153
+ dsh plugin --profile <profile> add dsh-unthrottle
154
+ ```
155
+
156
+ The bundle patch inserts one row (`xai` and `openai` enabled, `antigravity`
157
+ disabled by default).
158
+ ## Grants & CLI
159
+
160
+ A grant is the record `unthrottle/<provider>` in `$DSH_HOME/.credentials.yaml`
161
+ (`{ kind: grant, payload: { type: oauth, access, refresh, expires, … } }`).
162
+ The running harness and the CLI both write it only under the document's writer
163
+ lock (`.credentials.yaml.lock`), re-read it inside the lock, and refresh a token
164
+ there: whoever comes second finds the renewed grant and uses it instead of
165
+ spending the rotated refresh token again. A CLI sign-in reaches the running app
166
+ on its next request; a provider that was missing gets its route without a
167
+ restart.
168
+
169
+ The `bin` entry installs one dispatcher command, `dsh-unthrottle`
170
+ (`bin/unthrottle.mjs`), which forwards to these scripts with the same arguments
171
+ and exit code: `dsh-unthrottle <login|providers|smoke|status>` means
172
+ `login.mjs login <provider>`, `providers.mjs`, `smoke.mjs` and
173
+ `login.mjs status`; an unknown subcommand prints the usage and exits 2.
174
+
175
+ ```powershell
176
+ node bin/login.mjs status # records, expiry, blocks, leftover 0.2–0.4 copies
177
+ node bin/login.mjs login xai # xAI RFC 8628 device-code login
178
+ node bin/login.mjs login openai # Sign in with ChatGPT (loopback + dynamic client)
179
+ node bin/login.mjs login antigravity # loopback OAuth + PKCE + CSRF state check
180
+ node bin/login.mjs doctor # per provider: token state, refresh, live catalog
181
+ node bin/login.mjs usage # plan windows (5h/7d) from the rate-limit headers
182
+ node bin/login.mjs migrate # move 0.2–0.4 copies into records (DSH closed)
183
+ node bin/smoke.mjs xai grok-4.7
184
+ ```
185
+
186
+ On startup the plugin moves grants that 0.2–0.4 kept in the `ABO_PROVIDERS_*`
187
+ refs or in `$DSH_HOME/abo-providers.json` into records, without overwriting an
188
+ existing record, and then removes those copies. A refresh token the provider
189
+ rejects ends in an `AUTH` error naming the login command and leaves the record
190
+ untouched; a transient refresh failure keeps a still valid access token and
191
+ waits 30 s before the next attempt. A refresh that gets no complete token
192
+ response within 25 s counts as transient and frees the lock. A `403
193
+ TOS_VIOLATION` from Antigravity blocks the provider in its record until the next
194
+ `login antigravity`.
195
+
196
+ Antigravity sign-in needs an OAuth client pair, resolved in order:
197
+ `DSH_ABO_ANTIGRAVITY_CLIENT_ID` / `DSH_ABO_ANTIGRAVITY_CLIENT_SECRET`,
198
+ `clientId`/`clientSecret` in the stored grant, or `$DSH_HOME/unthrottle-client.json`
199
+ (`{"antigravity": {"clientId": "…", "clientSecret": "…"}}`, never inside the
200
+ repository). The plugin only reads this file and does not set its permissions;
201
+ on Windows restrict it yourself, for example
202
+ `icacls "$env:USERPROFILE\.dsh\unthrottle-client.json" /inheritance:r /grant:r "$($env:USERNAME):F"`. Set `DSH_ABO_OAUTH_TIMEOUT_MS` to change the
203
+ 5-minute callback timeout.
204
+
205
+ second grant at `unthrottle/anthropic-work`; `node bin/login.mjs accounts`
206
+ lists the accounts and `node bin/login.mjs switch anthropic work` makes one
207
+ active. The cockpit shows the same list on the provider tile and can switch
208
+ without the CLI. The pool always uses the active account of a provider.
209
+
210
+ **One client per account.** A refresh token rotates when it is used. Do not run
211
+ this plugin and another subscription client on the same grant at the same time.
212
+
213
+ ## Configuration
214
+
215
+ Exported as a `@deepseek-ai/schemastery` `Config` schema:
216
+
217
+ ```yaml
218
+ - id: unthrottle
219
+ name: dsh-unthrottle
220
+ config:
221
+ routes: hub # hub (default) | legacy direct routes
222
+ providers: # legacy-mode toggles, also policy hints
223
+ anthropic: { enabled: true }
224
+ xai: { enabled: true }
225
+ openai: { enabled: true }
226
+ antigravity: { enabled: false }
227
+ hub:
228
+ enabled: true
229
+ providers: [] # optional allowlist of descriptor ids
230
+ presets: true # false turns every OAuth preset off
231
+ optIn: [] # tos-risk/manual key plans and native ids, e.g. [zai-coding]
232
+ dirs: [] # extra descriptor dirs; $DSH_HOME/providers.d is always read
233
+ localProbe: true # register Ollama / LM Studio only while they answer
234
+ pool:
235
+ enabled: true
236
+ pools: # failover pools under the "pool" route
237
+ - id: auto
238
+ name: Auto (Claude, Grok, Kimi, GLM)
239
+ members: [anthropic/claude-opus-5-5, xai/grok-4.7, kimi-code/kimi-for-coding, zai-coding/glm-5.4]
240
+ - id: fast
241
+ name: Fast (Claude Haiku, Grok, Kimi)
242
+ members: [anthropic/claude-haiku-5-5, xai/grok-4.7, kimi-code/kimi-for-coding]
243
+ presets: # per-provider preset override; absent = policy default
244
+ anthropic: true
245
+ xai: true
246
+ openai: true
247
+ antigravity: false
248
+ claudeThinkingDisplay: summarized # summarized | omitted
249
+ claudeCacheTtl: auto # auto | 5m | 1h
250
+ ```
251
+
252
+ A pool may set `routing` to `balanced` (default), `fastest`, `cheapest` or
253
+ `quota`: once health, latency or forecast data exists, the listed policy orders
254
+ the members; without data the configured order stays. `cheapest` has no cost
255
+ signal wired yet. Accounts are per provider, and the pool uses the active
256
+ account of each provider.
257
+
258
+ With `routes: hub` a descriptor registers when its key resolves (harness
259
+ credential store first, then the environment), when a keyless loopback server
260
+ answers, or when its policy-enabled preset has a grant record. `presets`
261
+ overrides the preset policy default (`standard` on, `tos-risk` and `manual`
262
+ off). A key-based plan whose descriptor policy is not `standard`, and a
263
+ descriptor marked `native` (the harness serves that id itself, e.g.
264
+ `deepseek`), registers only when listed in `hub.optIn`. An id that another
265
+ adapter already owns is never claimed.
266
+
267
+ ### Keys
268
+
269
+ ```powershell
270
+ node bin/providers.mjs key set kimi-code # prompts without echo, or reads stdin
271
+ opa read "op://Vault/Item/credential" | node bin/providers.mjs key set kimi-code
272
+ node bin/providers.mjs key unset kimi-code
273
+ node bin/providers.mjs list # store | env | local | oauth grant | missing
274
+ ```
275
+
276
+ `key set` writes the descriptor's `auth.env` ref into
277
+ `$DSH_HOME/.credentials.yaml` under the store's lock and never prints the key.
278
+ The running harness reports the change as `credentials/reference-updated`;
279
+ the plugin then re-selects its routes, so a new key registers its route and a
280
+ removed one unregisters it without a restart.
281
+
282
+ ### Pool (failover)
283
+
284
+ The `pool` route exposes one model per configured pool. A call goes to the
285
+ first available member; members are `provider/model` and may name any
286
+ registered harness route, including routes of other adapters (for example the
287
+ native DeepSeek route). Members without a credential or route are skipped, and
288
+ a pool without any available member is not listed.
289
+
290
+ Chunks are held back until the first text, reasoning or tool delta. A member
291
+ that fails before that with a rate limit, exhausted quota, auth error, server
292
+ error, timeout, transport error, empty response, a missing route or HTTP 404
293
+ hands the same request to the next member; a malformed request (for example
294
+ HTTP 400) returns at once. After output has started a failure is the call's
295
+ failure. A failed member cools down: the provider's `Retry-After` when given
296
+ (capped at 6 h), otherwise 60 s for rate limits, 15 min for quota, 5 min for
297
+ auth, 1 h for an unknown model and 30 s for transient errors; account-level
298
+ failures cool the whole provider. When every member is cooling, the one that
299
+ recovers first is tried. The pool's model metadata is the conservative merge of
300
+ its members (smallest context window and output limit). Hub members receive
301
+ the nearest reasoning effort they support and image placeholders when they are
302
+ text-only; members on other harness routes run with their route's default
303
+ effort, and the harness projects images for them from that route's metadata. Failovers are logged as
304
+ `[unthrottle] pool auto: <member> <code>, cooling <n> s; trying <next>`.
305
+
306
+ Use it anywhere a model is chosen, for example as the subagent model
307
+ `pool/auto`, so a rate-limited plan does not stop a running agent.
308
+
309
+ The harness logger keeps its lines in memory, so the running plugin also writes
310
+ `$DSH_HOME/unthrottle-pool.json`: the member that served each pool last,
311
+ the number of calls since start and the last 20 failovers (ids, codes and times
312
+ only, never a key or a message body). A change of serving member is written at
313
+ once and logged as `[unthrottle] pool auto: served by <member>`.
314
+
315
+ ```powershell
316
+ node bin/providers.mjs pool # pool/auto: served by anthropic/claude-opus-5-5 at …
317
+ node bin/providers.mjs pool --json
318
+ ```
319
+
320
+ ## Provider hub (BYOK)
321
+
322
+ `providers.d/*.yml` is the declarative registry for ordinary API-key
323
+ providers. A descriptor names the provider, one of four protocol families
324
+ (`openai-chat`, `openai-responses`, `anthropic-messages`, `gemini`), the base
325
+ URL, where the key comes from, and the endpoint's chat-completions quirks.
326
+ Descriptors are data only: no secret, no code. 21 ship: fourteen BYOK
327
+ providers (OpenAI, xAI, Anthropic, Google Gemini, DeepSeek, Mistral, Groq,
328
+ OpenRouter, Together, Fireworks, Perplexity, Cerebras, plus the uncensored
329
+ `yeta` and `abliteratedllm` endpoints), four coding plans
330
+ (`kimi-code`, `zai-coding`, `zhipu-coding`, `minimax-coding`), two local
331
+ servers (`ollama`, `lmstudio`, `auth.type: none`, loopback only) and the
332
+ OAuth-only Antigravity descriptor. Coding-plan model ids come from vendor docs
333
+ and are not checked against a live endpoint here; a user descriptor in
334
+ `$DSH_HOME/providers.d` with the same id replaces the bundled one (for example
335
+ to add a header).
336
+
337
+ All 21 descriptors, with the key variable each one reads. The last column says
338
+ whether the route answered a live request in the maintainer's checkout (state
339
+ of 2026-11-29): four routes did (`anthropic`, `xai`, `yeta`, `abliteratedllm`),
340
+ the other 17 have no live check on record.
341
+
342
+ | Id | Provider | Protocol | Key variable | Notes | Live in this checkout |
343
+ |---|---|---|---|---|---|
344
+ | `anthropic` | Anthropic | `anthropic-messages` | `ANTHROPIC_API_KEY` | OAuth plan preset in the full edition; see [Limits](#limits) | **yes** (through the plan sign-in; the API-key path is not live-tested) |
345
+ | `xai` | xAI | `openai-responses` | `XAI_API_KEY` | OAuth plan preset (SuperGrok / X Premium) | **yes** (plan sign-in, `/v1/responses`) |
346
+ | `openai` | OpenAI | `openai-responses` | `OPENAI_API_KEY` | OAuth plan preset (Sign in with ChatGPT, preview) | no, no live evidence |
347
+ | `antigravity` | Google Antigravity | `gemini` | none (OAuth only) | policy `tos-risk`, off by default | no |
348
+ | `yeta` | Yeta | `openai-chat` | `YETA_API_KEY` | **uncensored**, text only, one model | **yes** (6 models listed, streamed a reply) |
349
+ | `abliteratedllm` | AbliteratedLLM | `openai-chat` | `ABLITERATEDLLM_API_KEY` | **uncensored**, GLM 5.3 Flash/Cyber and Kimi K3.1 Pro | **partly**: key, route and catalog work; inference answered HTTP 503 at check time (provider outage) |
350
+ | `google` | Google Gemini | `gemini` | `GEMINI_API_KEY` | `x-goog-api-key` header | no |
351
+ | `deepseek` | DeepSeek | `openai-chat` | `DEEPSEEK_API_KEY` | `native`: the harness serves this id itself, opt in with `hub.optIn` | no |
352
+ | `mistral` | Mistral AI | `openai-chat` | `MISTRAL_API_KEY` | | no |
353
+ | `groq` | Groq | `openai-chat` | `GROQ_API_KEY` | | no |
354
+ | `openrouter` | OpenRouter | `openai-chat` | `OPENROUTER_API_KEY` | | no |
355
+ | `together` | Together AI | `openai-chat` | `TOGETHER_API_KEY` | | no |
356
+ | `fireworks` | Fireworks AI | `openai-chat` | `FIREWORKS_API_KEY` | | no |
357
+ | `perplexity` | Perplexity | `openai-chat` | `PERPLEXITY_API_KEY` | static model list, text only | no |
358
+ | `cerebras` | Cerebras | `openai-chat` | `CEREBRAS_API_KEY` | text only | no |
359
+ | `kimi-code` | Kimi Code | `anthropic-messages` | `KIMI_API_KEY` | coding plan, static model list | no |
360
+ | `zai-coding` | Z.ai GLM Coding Plan | `openai-chat` | `ZAI_API_KEY` | coding plan, policy `tos-risk`, needs `hub.optIn` | no |
361
+ | `zhipu-coding` | Zhipu GLM Coding Plan (CN) | `openai-chat` | `ZHIPU_API_KEY` | coding plan, policy `tos-risk`, needs `hub.optIn` | no |
362
+ | `minimax-coding` | MiniMax Coding Plan | `anthropic-messages` | `MINIMAX_API_KEY` | coding plan, static model list | no |
363
+ | `ollama` | Ollama (local) | `openai-chat` | none | loopback, registers while the server answers | no |
364
+ | `lmstudio` | LM Studio (local) | `openai-chat` | none | loopback, registers while the server answers | no |
365
+
366
+ The two **uncensored** routes (`yeta`, `abliteratedllm`) are plain API-key
367
+ endpoints. The plugin adds no filter of its own; the provider's terms and the
368
+ law of your jurisdiction apply.
369
+
370
+ ```yaml
371
+ id: acme
372
+ name: Acme
373
+ protocol: openai-chat
374
+ baseUrl: https://api.acme.test/v1
375
+ auth:
376
+ type: api-key
377
+ env: ACME_API_KEY
378
+ chat:
379
+ maxTokensField: max_completion_tokens
380
+ streamUsage: false
381
+ reasoningEffort: true
382
+ temperature: false
383
+ images: false
384
+ models:
385
+ - acme-1
386
+ - acme-2
387
+ ```
388
+
389
+ Validation is strict: unknown fields, duplicate ids, a file name that does not
390
+ match the id, remote plain HTTP, URL credentials, a bad environment-variable
391
+ name and credential-looking static headers are refused with the file and the
392
+ field. One broken file never hides the valid ones.
393
+
394
+ ```powershell
395
+ node bin/providers.mjs list
396
+ node bin/providers.mjs list --json
397
+ node bin/providers.mjs test openai # GET /models with $env:OPENAI_API_KEY
398
+ ```
399
+
400
+ `list` never reaches the network and never prints a key, only whether the
401
+ descriptor's environment variable is set. `test` exits 3 when that variable is
402
+ missing, 2 when the provider or the protocol is unknown, and 1 when the
403
+ provider rejects the request.
404
+
405
+ The four protocol modules share the request/stream mechanics but keep their
406
+ wire rules local. `openai-chat` sends system text as the first message, image
407
+ data URIs as `image_url` parts, tools as function declarations, and answers
408
+ every assistant tool call before the next turn. `openai-responses` sends
409
+ `store: false`, flat function tools and encrypted reasoning when an effort is
410
+ set, and reuses the harness Responses item translation. `anthropic-messages`
411
+ sends the documented developer request without the subscription identity:
412
+ `x-api-key` plus `anthropic-version`, native image blocks, and a `tool_result`
413
+ at the start of the user turn that answers a `tool_use`, with an interrupted
414
+ result filling a gap in the history. `gemini` sends `contents` with `parts`
415
+ (`inlineData` for images, `functionCall` / `functionResponse` matched by
416
+ function name), maps thought parts to reasoning blocks and synthesises stable
417
+ call ids. All four translate text, reasoning, tool arguments, usage and finish
418
+ reasons onto harness stream chunks. A 400 that names a lower `max_tokens`
419
+ ceiling gets one retry with that ceiling. These are the BYOK request shapes; a
420
+ preset with `transport: subscription` hands the call to the verified module
421
+ instead, which adds the vendor's OAuth context.
422
+
423
+ Registration: with `routes: hub` (the default) `index.js` reads the registry at
424
+ startup and registers one hub route per available descriptor — a BYOK route
425
+ when the environment key is set, otherwise a policy-enabled preset with a
426
+ stored grant. The preset keeps the provider id (`anthropic`, `xai`, `openai`,
427
+ `antigravity`), so the model picker and existing sessions are unchanged. A
428
+ grant written later by the CLI registers its route without a restart.
429
+ `hub.providers` restricts the hub to an allowlist and `hub.presets: false`
430
+ disables every preset. `routes: legacy` restores the direct subscription
431
+ routes and leaves the hub with BYOK only. The key is read on every call, so
432
+ rotating it needs no restart; adding a key for a descriptor that had none needs
433
+ one.
434
+
435
+ ### OAuth presets
436
+
437
+ A descriptor may carry an OAuth preset next to its BYOK auth:
438
+
439
+ ```yaml
440
+ preset:
441
+ type: oauth
442
+ provider: anthropic # GrantStore record id (abo-providers/<provider>)
443
+ policy: standard # standard | tos-risk | manual
444
+ transport: subscription # hub (generic protocol) | subscription (verified module)
445
+ ```
446
+
447
+ `transport: subscription` is what makes H4 a migration rather than a rewrite:
448
+ the hub route resolves the grant and then calls the same verified provider
449
+ module the direct route used (`lib/providers/anthropic.js`, `xai.js`,
450
+ `openai.js`, `antigravity.js`), including Claude Code's identity block and beta
451
+ headers, the ChatGPT-plan preview body rules and the Cloud Code envelope. A
452
+ subscription preset may omit `auth` entirely (Antigravity does), because no
453
+ BYOK key exists for it. The default transport, `hub`, uses the generic protocol
454
+ modules and is the right choice for an OAuth endpoint that follows its
455
+ documented wire format.
456
+
457
+ Activation follows the policy class: `standard` presets register by default,
458
+ `tos-risk` (account-level block risk, for example Antigravity) and `manual`
459
+ never do. `presets.<id>: false` turns one off, `presets.<id>: true` forces one
460
+ on, and `hub.presets: false` turns every preset off. Credentials are resolved
461
+ BYOK-first: an environment key wins; otherwise the adapter reads the grant's
462
+ access token. Missing grants and refresh failures become `AUTH` errors that
463
+ name `node bin/login.mjs login <provider>`; a 401 retries once with a forced
464
+ refresh, and a block reason from the vendor is recorded through the store.
465
+
466
+ ```yaml
467
+ routes: hub
468
+ hub: { enabled: true, presets: true }
469
+ presets:
470
+ anthropic: true
471
+ xai: true
472
+ openai: true
473
+ antigravity: false
474
+ ```
475
+
476
+ The subscription transports are the modules from 0.6.0. The hub wrapper is
477
+ verified offline (bridge dispatch, 401 refresh, block recording, catalog
478
+ metadata). `routes: legacy` is the escape hatch if the direct registration path
479
+ is needed.
480
+ ## Architecture
481
+
482
+ ```
483
+ index.js Config schema, record backend over ctx.credentials, migration, hub/legacy route registration
484
+ lib/adapter.js LlmAdapter factory, retryPolicy, imageRequestTarget, 401 retry, TOS block, cache TTL, rate-limit warning
485
+ lib/credentials.js GrantStore over records: refresh under the record lock, backoff, block, legacy migration
486
+ lib/record-file.js CLI record backend: .credentials.yaml under the harness writer lock
487
+ lib/vendor/dsh-atomic-write.js verbatim @deepseek-ai/dsh-atomic-write 0.2.2-rc.5 (MIT): lock + atomic replace
488
+ lib/catalog.js context windows, output ceilings, reasoning defaults, systemPromptUpdate
489
+ lib/errors.js typed error taxonomy, secret sanitization, request-id & Retry-After parsing
490
+ lib/http.js bounded fetch timeouts distinguishing TimeoutError from AbortError
491
+ lib/sse.js SSE framing with per-chunk idle timeout and abort handling
492
+ lib/tools.js MCP/tool name sanitization (<=64 chars) + JSON Schema hygiene + reverse map
493
+ lib/unicode.js lone-surrogate removal for outgoing text
494
+ lib/oauth.js PKCE, random CSRF state, loopback server, form/JSON exchange, device flow
495
+ lib/openai-auth.js Sign in with ChatGPT: host id, dynamic client, loopback callback, JWKS-verified ID token
496
+ lib/provider-auth.js standalone Claude PKCE and xAI device-code CLI sign-in flows
497
+ lib/antigravity-auth.js Antigravity loopback consent with CSRF verification & client resolution
498
+ lib/responses.js shared Responses API translation (items, streaming blocks, usage, replay state)
499
+ lib/probe.js harness-shaped Claude request probe (plan vs third-party classification)
500
+ lib/usage.js Claude plan windows from anthropic-ratelimit-unified-* headers
501
+ lib/hub/yaml.js dependency-free YAML subset reader for provider descriptors
502
+ lib/hub/descriptor.js strict descriptor schema, defaults and validation
503
+ lib/hub/registry.js providers.d loader with per-file error reporting
504
+ lib/hub/policy.js preset policy classes: risk, default activation, explicit override
505
+ lib/hub/adapter.js hub adapter: route selection, BYOK/OAuth credentials, subscription transport, catalog, model metadata, error translation
506
+ lib/hub/protocols/common.js shared auth headers, HTTP errors and catalog parsing
507
+ lib/hub/protocols/openai-chat.js OpenAI-compatible chat completions (request, SSE, catalog)
508
+ lib/hub/protocols/openai-responses.js Responses API for BYOK (stateless request, shared translation)
509
+ lib/hub/protocols/anthropic-messages.js Messages API for BYOK (tool_result ordering, thinking, cache usage)
510
+ lib/hub/protocols/gemini.js Gemini contents/parts, function calls by name, thought parts, catalog limits
511
+ providers.d/ BYOK, coding-plan, local and OAuth-only descriptors (21)
512
+ lib/hub/keys.js key source: harness credential store first, then the environment
513
+ lib/hub/pool.js pool route: member parsing, failover rules, cooldowns, metadata merge
514
+ lib/providers/anthropic.js Messages API (OAuth identity, adaptive thinking, prefix-bound replay, in-history system, cache TTL)
515
+ lib/providers/xai.js Responses API (/v1/responses, encrypted_content replay, cli-chat-proxy enrich)
516
+ lib/providers/openai.js Responses API via ChatGPT plan (preview contract, subscription_sharing_* mapping)
517
+ lib/providers/antigravity.js Cloud Code Assist (Gemini-only, thoughtSignature replay, parallel tool merge, TOS block flag)
518
+ bin/ status, sign-in, live catalog test, doctor, migrate, smoke probes, provider registry
519
+ ```
520
+
521
+ ## Tests
522
+
523
+ ```powershell
524
+ npm test
525
+ ```
526
+
527
+ Offline suites cover SSE framing, idle/fetch timeouts, secret redaction, tool
528
+ name/schema sanitization, all three provider protocols, prefix-bound thinking
529
+ replay, mid-conversation system messages, cache TTL, surrogate removal, the
530
+ record backend under the harness lock (including a second process), grant
531
+ refresh races, legacy migration and the exact harness `LlmError`/`retryPolicy`
532
+ contracts. The ChatGPT-plan suite covers the authorize request, the host id, a
533
+ real RS256 ID-token check against a generated JWKS, the code exchange with the
534
+ issued client id and resource, the preview request body, the `subscription_sharing_*`
535
+ mapping, the `additional_tools` fallback and the refresh that keeps the id token.
536
+ The hub suite covers the YAML subset reader, descriptor and registry validation,
537
+ the four protocol modules (request shaping, tool-result ordering, images, SSE
538
+ translation, usage, finish reasons and catalog fallbacks), the hub adapter
539
+ (route selection, BYOK/OAuth credential resolution, the subscription-transport
540
+ bridge with 401 refresh and block recording, model metadata, LlmError
541
+ translation), the preset policy classes and the `providers.mjs` exit codes. No
542
+ network; `yaml` is resolved from the installed DSH profile for the record-file
543
+ tests and they skip without it.
544
+
545
+ ## Limits
546
+
547
+ - **Claude models are BYOK in this build.** The `anthropic` descriptor takes an
548
+ `ANTHROPIC_API_KEY` and sends no Claude Code identity. The subscription route
549
+ and its terms analysis belong to the full edition.
550
+ - Antigravity carries an account-level `403 TOS_VIOLATION` risk on third-party
551
+ clients, Google staff advised against DSH plugins on consumer sign-in
552
+ (2026-11-11), and the route stays disabled by default.
553
+ - The ChatGPT-plan route is a **preview** capability with documented limits:
554
+ `store: false` and `stream: true` are mandatory, `previous_response_id` does
555
+ not work over HTTP (history is sent in `input`), image generation, file search,
556
+ Code Interpreter, hosted MCP and `tool_search` are unsupported, and a Plus
557
+ five-hour limit is shared across every app that uses the plan. Limits are set
558
+ per app in ChatGPT settings → Usage. Nothing is stored server-side, so a
559
+ context that does not fit the model's window fails rather than truncating.
560
+ - **The OpenAI routes have no live evidence.** Neither the `openai` API-key
561
+ descriptor nor the ChatGPT-plan preset has answered a live request here; the
562
+ plan route is checked offline against OpenAI's documented preview contract
563
+ (authorize request, ID-token check, request body, error mapping), and the
564
+ `/v1/models` catalog call is not live-tested.
565
+ - **`abliteratedllm` currently answers 503.** At the last check (2026-11-29)
566
+ the key authenticated and the catalog listed 17 models, but inference
567
+ returned HTTP 503 `safety_unavailable` on every model tried, including the
568
+ control model. That is an outage on the provider's side, not a plugin fault,
569
+ and it has not been re-tested since. `yeta` is the uncensored route that
570
+ streamed a reply.
571
+ - **Uncensored routes carry no filter from this plugin.** `yeta` and
572
+ `abliteratedllm` are plain API-key endpoints; the provider's terms and your
573
+ jurisdiction decide what is allowed.
574
+ - Coding-plan descriptors (`kimi-code`, `zai-coding`, `zhipu-coding`,
575
+ `minimax-coding`) use model ids from vendor documentation and are not
576
+ checked against a live endpoint. The Z.ai and Zhipu plans restrict use to
577
+ tools they list, so they stay off until you opt in with `hub.optIn`.
578
+ - Local routes (`ollama`, `lmstudio`) register only while their server answers
579
+ on loopback.
580
+
581
+ ## Troubleshooting
582
+
583
+ | Symptom | Likely cause | What to do |
584
+ |---|---|---|
585
+ | Error `<id> has no API key; set <ENV> …` or the route is missing from the picker | No key in the DSH credential store or the environment | `dsh-unthrottle providers key set <id>` (reads stdin or prompts without echo), then `dsh-unthrottle providers list`: it shows `store`, `env`, `local`, `oauth grant` or `missing` and never the key. A new key registers its route without a restart |
586
+ | `AUTH` error naming a login command, or HTTP 401 | A subscription grant is missing or its refresh token was rejected; for a key route, the provider refused the key | The adapter retries a 401 once with a forced refresh. If it persists, run `dsh-unthrottle login <provider>` for a plan route, or set the key again and check it with `dsh-unthrottle providers test <id>` (exit 1 means the provider rejected it, 3 means no key). `dsh-unthrottle doctor` shows token state, refresh and live catalog per provider. Never run two clients on the same grant: a refresh token rotates on use |
587
+ | HTTP 429 or a spent plan window | Rate limit or plan window used up | A `pool` route moves to the next member and cools the failed one (the provider's `Retry-After`, else 60 s for a rate limit and 15 min for exhausted quota). Check windows with `dsh-unthrottle usage`; wait for the reset or add a member to the pool |
588
+ | HTTP 503 or other 5xx | Provider outage or overload (`abliteratedllm` is the known case) | Nothing to fix locally. A `pool` route treats it as a server error and tries the next member (30 s cooldown for transient errors); a direct route fails the call. Retry later, or switch route |
589
+ | Antigravity `403 TOS_VIOLATION` | Google blocked third-party use of the account | The provider is blocked in its record until the next `login antigravity`; see [Limits](#limits) before signing in again |
590
+ | `dsh-unthrottle doctor` warns that `.credentials.yaml` is readable by Everyone or Users (Windows) | The credential file inherited a broad ACL; the plugin does not set an ACL itself | Run the `fix:` line `doctor` prints, for example `icacls "%USERPROFILE%\.dsh\.credentials.yaml" /inheritance:r /grant:r "%USERNAME%:F"` |
591
+ | Routes missing after install | DSH loads the plugin at start | Restart DSH; for a CLI-only change use **Recheck** in the cockpit |
592
+
593
+ ## Cockpit
594
+
595
+ The bundle's page in the Plugins view carries a cockpit: one card per provider
596
+ (five states — live, signed in, sign in, blocked, key), the pool chain with each
597
+ member's pause, the last switches, and the plan windows of the subscription
598
+ routes. Two buttons repair without a restart: **Recheck** re-reads routes, keys
599
+ and local endpoints, **Clear pauses** drops the in-memory cooldowns.
600
+
601
+ Everything the page and the tiles show comes from six owner-only host routes,
602
+ all registered through `ctx.connection.fetch.register` — the route kind DSH
603
+ serves to owner peers only, so an agent or a foreign page cannot call them:
604
+ `GET /api/unthrottle/status` (the snapshot), `POST /api/unthrottle/action`
605
+ (`recheck`, `reset-cooldowns`), `GET`/`POST /api/unthrottle/client-report` (slot
606
+ reports), `POST /api/unthrottle/provider` (test, save or remove a key, opt in),
607
+ `POST /api/unthrottle/signin` (in-app sign-in) and `GET /api/unthrottle/turns`
608
+ (the turn ledger). The snapshot carries route ids, state names, expiries, counts
609
+ and plan utilizations; never a token, a key or an upstream body.
610
+
611
+ `docs/preview.svg` is the picture the plugin list may show.
612
+
613
+ ### Provider tiles
614
+
615
+ Every tile on the cockpit is a button. A click opens the provider's panel right
616
+ below its row (Escape or × closes it and gives focus back to the tile):
617
+
618
+ - **API-key providers:** where the key comes from (DSH store or an environment
619
+ variable), a password field, *Test and save*, *Remove key*. A key is first
620
+ shown to the provider's model list; only a key the provider accepts is stored,
621
+ unless you choose *Save anyway*. Providers without a live model list save the
622
+ key marked as untested. *Remove key* only removes a key the DSH store holds.
623
+ - **Opt-in routes** (coding plans with a ToS note, routes DSH ships itself): a
624
+ switch that writes `hub.optIn` through DSH's profile editor; the plugin reloads.
625
+ - **Subscriptions without a grant:** the exact sign-in command with a copy button.
626
+ - **Every provider:** *Test connection* reloads the live catalog and lists the first
627
+ models, or shows why it failed.
628
+
629
+ All of this goes through `POST /api/unthrottle/provider`, an owner-only route. A
630
+ key never comes back in an answer, a log line or the status snapshot; upstream
631
+ error text has the key cut out by value before it is shortened. The agent tool
632
+ cannot store, remove or approve anything.
633
+
634
+ ## License
635
+
636
+ MIT, see [LICENSE](LICENSE).