dsh-plugin-doubao 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +457 -2
- package/bin/login.bat +27 -0
- package/bin/login.js +112 -0
- package/cordis.patch.yml +13 -0
- package/lib/adapter.js +851 -0
- package/lib/bridge.js +608 -0
- package/lib/client.js +171 -0
- package/lib/credits.js +143 -0
- package/lib/doubao.js +746 -0
- package/lib/identity.js +291 -0
- package/lib/index.js +290 -0
- package/lib/login.js +357 -0
- package/lib/rates.js +117 -0
- package/lib/risk-memory.js +84 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-plugin-doubao contributors
|
|
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,458 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-doubao
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use Doubao (豆包) models inside [DSH](https://github.com/deepseek-ai/deepseek-harness) as a normal
|
|
4
|
+
provider. Install the plugin, sign in once by scanning a QR code with the Douyin app, then pick a
|
|
5
|
+
`doubao/*` model in the picker.
|
|
6
|
+
|
|
7
|
+
There is no proxy to start and no browser to drive. The plugin speaks the same HTTP endpoints the
|
|
8
|
+
web client uses, from inside the harness process.
|
|
9
|
+
|
|
10
|
+
Every model the client can route to is exposed, with the same names the client shows:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
doubao Doubao
|
|
14
|
+
doubao-expert Doubao Expert
|
|
15
|
+
doubao-auto Doubao Auto
|
|
16
|
+
doubao-2.1-lite Doubao 2.1 Lite
|
|
17
|
+
doubao-2.1-pro Doubao 2.1 Pro
|
|
18
|
+
deepseek-v4.1-flash DeepSeek V4.1 Flash
|
|
19
|
+
deepseek-v4-pro DeepSeek V4 Pro
|
|
20
|
+
kimi-k3.1-pro Kimi K3.1 Pro
|
|
21
|
+
kimi-k3.1-pro-highspeed Kimi K3.1 Pro Highspeed
|
|
22
|
+
kimi-k3 Kimi K3
|
|
23
|
+
glm-5.3 GLM 5.3
|
|
24
|
+
glm-5.3-flash GLM 5.3 Flash
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Picking one is not just a name. The client sends a five-tuple — `model_item_key`, `mode_id`,
|
|
28
|
+
`agent_mode`, `conversation_mode`, `reasoning_effort` (plus a thinking-mode id) — and repeats it in
|
|
29
|
+
three places in the request body. The server reads whichever copy it wants, so a field left at the
|
|
30
|
+
default silently answers from the plain chat model instead of the one you picked. All twelve are
|
|
31
|
+
verified against a live account.
|
|
32
|
+
|
|
33
|
+
### Credit multipliers
|
|
34
|
+
|
|
35
|
+
Like the WorkBuddy provider, each model name carries its credit multiplier on the right, separated
|
|
36
|
+
by a middle dot — `Doubao 2.1 Pro · x0.65`, `Kimi K3.1 Pro Highspeed · x1.44`. Promo tags ride
|
|
37
|
+
along too (`x0.01 限时优惠`, `小额免费`). The suffix goes on `name` rather than `description`
|
|
38
|
+
because DSH's model seat and `/model` popup render only `name`; routing still uses `id`, so this is
|
|
39
|
+
display-only and cannot change which model answers.
|
|
40
|
+
|
|
41
|
+
The table is read live from the client's `action_bar_v3/brief_list` endpoint at most once every ten
|
|
42
|
+
minutes, with a snapshot from 2026-11-14 as the seed so the picker is informative even before the
|
|
43
|
+
first lookup (or if it fails). A failed lookup returns "nothing new" instead of restoring the seed,
|
|
44
|
+
so a fresher rate is never rolled back to an older one. `Doubao` and `Doubao Expert` have no tag in
|
|
45
|
+
the client's own list and are shown without a suffix.
|
|
46
|
+
|
|
47
|
+
## Prerequisites — read this first
|
|
48
|
+
|
|
49
|
+
The plugin is not standalone. All four must hold, or the install succeeds but
|
|
50
|
+
sign-in fails:
|
|
51
|
+
|
|
52
|
+
1. **DSH** — this is a DSH provider, not a standalone app.
|
|
53
|
+
2. **The Doubao desktop client, installed and signed in at least once on the same machine that runs DSH.** Doubao checks a device fingerprint on every request and only accepts one this account has used before. There is no API to get it: the plugin reads it from the client's `Local State`, and a freshly generated device id is always refused (`710022004`). Windows, macOS and Linux are supported, a non-default install path is fine, and the client does not need to stay running — it only has to have been signed in once.
|
|
54
|
+
3. **The Douyin app (抖音) on your phone** — sign-in is a QR scan and must be done with Douyin, not the Doubao app (which fails silently). Scan on the machine that runs DSH; signing in elsewhere does not carry over.
|
|
55
|
+
4. **A Doubao account with available credit** — a fresh free account starts with 9,000 monthly + 2,000 activity points.
|
|
56
|
+
|
|
57
|
+
Without #2, `node bin/login.js` prints `No Doubao desktop client identity found on this machine.` and exits. See [One thing you should know before installing](#one-thing-you-should-know-before-installing) for how the fingerprint is read and when the client is actually needed.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
### One line — paste this
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
dsh plugin --profile web add github:woc-jpg/dsh-plugin-doubao
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then restart DSH, pick a Doubao model, and (first time only) sign in with the helper
|
|
68
|
+
bundled inside the installed package:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
node "$(dsh plugin --profile web exec pwd)/node_modules/dsh-plugin-doubao/bin/login.js"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If that path lookup is awkward on your shell, the same helper is at
|
|
75
|
+
`~/.dsh/profiles/<profile>/node_modules/dsh-plugin-doubao/bin/login.js` — or just clone
|
|
76
|
+
the repo and run `node bin/login.js` from it.
|
|
77
|
+
|
|
78
|
+
**Use `github:woc-jpg/dsh-plugin-doubao` exactly as written.** Do not paste the browser
|
|
79
|
+
address `https://github.com/woc-jpg/dsh-plugin-doubao`: pnpm treats a bare `https://...`
|
|
80
|
+
as a git dependency and runs `git ls-remote`, which stalls or fails on many networks.
|
|
81
|
+
The `github:owner/repo` form downloads a codeload tarball instead and takes a few seconds.
|
|
82
|
+
`woc-jpg/dsh-plugin-doubao` also works. The bare name `dsh-plugin-doubao` does **not** work
|
|
83
|
+
yet — there is no npm release — so `npx dsh-plugin-doubao` is not a thing.
|
|
84
|
+
|
|
85
|
+
`dsh plugin add` installs the package and activates it as a profile bundle automatically
|
|
86
|
+
(the package declares `dsh.bundle.patch`). The session is cached in
|
|
87
|
+
`~/.dsh/doubao-local/credentials.json`; you sign in only once.
|
|
88
|
+
|
|
89
|
+
If your DSH profile is the desktop app's, `dsh plugin` refuses to touch it (the Electron app
|
|
90
|
+
owns that profile). Add the dependency to the profile's `package.json` by hand and run
|
|
91
|
+
`pnpm install` there instead:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
"dsh-plugin-doubao": "github:woc-jpg/dsh-plugin-doubao"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
and add `"dsh-plugin-doubao"` to `dsh.profile.bundles` in the same file.
|
|
98
|
+
|
|
99
|
+
## Sign in — no conversation needed
|
|
100
|
+
|
|
101
|
+
Signing in is a standalone step. You do **not** need to start DSH or chat with the agent first
|
|
102
|
+
(in fact you can't: until you sign in, every Doubao request fails with `AUTH_MISSING`). The
|
|
103
|
+
package ships a `dsh-plugin-doubao` command that opens a local sign-in page, shows a QR code,
|
|
104
|
+
and saves the session as soon as you scan it.
|
|
105
|
+
|
|
106
|
+
**Windows — double-click:** `bin/login.bat` in the cloned repo, or
|
|
107
|
+
`node_modules\dsh-plugin-doubao\bin\login.bat` inside your DSH profile directory. It finds
|
|
108
|
+
Node by itself, opens the browser, and waits for the scan.
|
|
109
|
+
|
|
110
|
+
**Any OS — terminal:**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
dsh-plugin-doubao # opens the browser at http://127.0.0.1:8899/
|
|
114
|
+
dsh-plugin-doubao --status # check whether you're signed in and when it expires
|
|
115
|
+
dsh-plugin-doubao --force # sign in again (the normal run is a no-op if already signed in)
|
|
116
|
+
dsh-plugin-doubao --port 9001 --no-open # custom port / don't launch a browser
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
From a checkout, `node bin/login.js` accepts the same flags. Once the page opens, **scan with
|
|
120
|
+
the Douyin app (抖音), not the Doubao app** — Doubao's own QR page says so, and scanning with
|
|
121
|
+
Doubao fails silently. The QR refreshes automatically every ~60 s, so take your time. When it
|
|
122
|
+
succeeds the page says `saved`, the command prints the credential path, and you can go straight
|
|
123
|
+
to DSH and pick a Doubao model. No restart, no chat, no agent round-trip.
|
|
124
|
+
|
|
125
|
+
The sign-in needs the device fingerprint from a Doubao desktop client that has been signed in
|
|
126
|
+
at least once on this machine — see [Prerequisites](#prerequisites--read-this-first). If that
|
|
127
|
+
client is missing, the command tells you exactly which paths it looked in and exits.
|
|
128
|
+
|
|
129
|
+
## One thing you should know before installing
|
|
130
|
+
|
|
131
|
+
Doubao checks a device fingerprint on every request, and it only accepts the fingerprint of a device
|
|
132
|
+
the account has already used. Two failure modes follow from that, and they look alike:
|
|
133
|
+
|
|
134
|
+
| What was sent | What comes back |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| a valid session, but a device id the account has never seen | `710022004` — "rate limited" (it is not a rate limit) |
|
|
137
|
+
| no session at all | `710012001` — login invalid |
|
|
138
|
+
|
|
139
|
+
A freshly generated device id is refused no matter how valid the session is. So the plugin reads the
|
|
140
|
+
device id out of the **installed Doubao desktop client's** `Local State` file, and pairs it with the
|
|
141
|
+
session from your scan. That means:
|
|
142
|
+
|
|
143
|
+
- **The Doubao desktop client must be installed and signed in at least once** on the same machine.
|
|
144
|
+
Without it there is no device id to use. The client is supported on Windows, macOS and Linux; the
|
|
145
|
+
plugin finds it from the running process, the OS install record (Windows registry / macOS Spotlight),
|
|
146
|
+
or the usual install locations, so a non-default install path is fine. Stopping a stale instance
|
|
147
|
+
uses `taskkill` on Windows and `pkill` on the other two.
|
|
148
|
+
- Signing in on a different machine than the one that runs DSH will not work; run `login` where DSH
|
|
149
|
+
runs.
|
|
150
|
+
|
|
151
|
+
Requests go out as plain HTTPS first — the same shape the current web client uses — so on a healthy
|
|
152
|
+
account the desktop client is never touched, and restarting DSH changes nothing. Only when Doubao
|
|
153
|
+
answers `710022004` does the plugin need a signature; it then remembers that state for a while and
|
|
154
|
+
routes subsequent turns through the client's page, whose own hook signs them. If no client with a
|
|
155
|
+
debugger port is running, it starts (or restarts) one with the flag — that is the only time it
|
|
156
|
+
launches an app on your behalf. Reading `Local State` is passive; the restart only happens after a
|
|
157
|
+
request has actually been refused. Set `allowBridge: false` if you would rather switch models than
|
|
158
|
+
ever have the client started.
|
|
159
|
+
|
|
160
|
+
`login` tells you straight away if no client identity is found, and lists the directories it looked in.
|
|
161
|
+
|
|
162
|
+
## Why not read the cookies from the client too?
|
|
163
|
+
|
|
164
|
+
Two reasons. The client's Cookies database is exclusively locked while it runs (SQLite cannot open it
|
|
165
|
+
even read-only), and it is encrypted with DPAPI. `Local State` and Local Storage, by contrast, are
|
|
166
|
+
plain files that stay readable — so only that half is read.
|
|
167
|
+
|
|
168
|
+
The leveldb directory is a *fallback*, not the primary source: leveldb blocks are prefix-compressed,
|
|
169
|
+
so once the client compacts its database `client_device_info` is no longer a contiguous byte run and
|
|
170
|
+
a scan finds nothing. `Local State` survives that compaction, so it wins when both are available.
|
|
171
|
+
|
|
172
|
+
## Configuration
|
|
173
|
+
|
|
174
|
+
All optional. Set them in the profile's `cordis.patch.yml` entry for `dsh-plugin-doubao`:
|
|
175
|
+
|
|
176
|
+
| Key | Default | What it does |
|
|
177
|
+
| --- | --- | --- |
|
|
178
|
+
| `providerId` | `doubao` | Provider id shown to the harness. Change it if another plugin already claims `doubao`. |
|
|
179
|
+
| `displayName` | `Doubao` | Name shown in the picker. |
|
|
180
|
+
| `minIntervalMs` | `1500` | Minimum gap between turns. Turns are serialized and spaced; see below. |
|
|
181
|
+
| `credentialsPath` | `~/.dsh/doubao-local/credentials.json` | Where the session is cached. |
|
|
182
|
+
| `loginPort` | `8899` | Port for the QR page served inside a session. |
|
|
183
|
+
| `bridgePort` | `9222` | DevTools port used for the fallback client bridge, including when starting the client. |
|
|
184
|
+
| `allowBridge` | `true` | Try plain HTTPS first and fall back to the signed client bridge on `710022004`. Set `false` for direct-only — the client is never probed or launched. |
|
|
185
|
+
| `riskTtlMs` | `1800000` | How long (ms) a `710022004` flag keeps routing through the bridge before the direct path is tried again. |
|
|
186
|
+
|
|
187
|
+
Environment: `DOUBAO_CREDENTIALS` overrides the credential path, `DOUBAO_LOGIN_PORT` the login port,
|
|
188
|
+
`DSH_HOME` the base directory.
|
|
189
|
+
|
|
190
|
+
## Rate limiting
|
|
191
|
+
|
|
192
|
+
Doubao's risk engine reacts to bursts, not volume. Five quick calls in a row were enough to earn a
|
|
193
|
+
cooldown that outlasted the run producing them. So the plugin holds an exclusive lock for the whole
|
|
194
|
+
turn — request *and* stream — and keeps at least `minIntervalMs` between turns. Releasing the lock
|
|
195
|
+
after the POST is not enough: overlapping streams are exactly the pattern that trips `710022004`.
|
|
196
|
+
|
|
197
|
+
When a refusal does arrive, the adapter backs off for a minute and reports it as an error finish with
|
|
198
|
+
code `RATE_LIMIT`. It deliberately does not throw: a thrown error makes the harness retry, and
|
|
199
|
+
retrying a rate limit only deepens it. The provider also ships its own retry policy
|
|
200
|
+
(`RETRY_POLICY`) with `RATE_LIMIT` removed from `retryableCodes` — the harness default *would* retry
|
|
201
|
+
it five times, which is the opposite of what a flagged account needs.
|
|
202
|
+
|
|
203
|
+
The gap used to default to six seconds, which is longer than a turn's own time-to-first-token and was
|
|
204
|
+
felt as lag rather than as caution — the lock already serialises turns, so a healthy account rarely
|
|
205
|
+
gets near it. It now defaults to 1.5s and the real protection moved to the `710022004` cooldown above.
|
|
206
|
+
|
|
207
|
+
Signing in does not clear a flag that is already set. If the account is flagged, the desktop client
|
|
208
|
+
shows a picture-selection captcha the next time you send a message from it, and solving it is what
|
|
209
|
+
restores access; the flag is account-wide, so the plugin recovers as soon as it is cleared. Note that
|
|
210
|
+
the captcha also expires quickly — a challenge that sits unsolved for a minute or two comes back as
|
|
211
|
+
`NotFoundChallengeId` and a fresh question, so the desktop client may need a restart before a slow
|
|
212
|
+
solve can succeed.
|
|
213
|
+
|
|
214
|
+
## Switching models mid-session
|
|
215
|
+
|
|
216
|
+
Switching the model used to leave the next turn hanging, for two reasons that only showed up when a
|
|
217
|
+
turn did not end the way the plugin assumed.
|
|
218
|
+
|
|
219
|
+
- **A turn that was abandoned kept the lock.** The pacer releases its turn lock in a `finally`, which
|
|
220
|
+
runs when a stream is closed — but not when the consumer simply drops the iterator. A cancelled
|
|
221
|
+
turn, or a host that stops reading on a switch, left `this.tail` pending forever and every later
|
|
222
|
+
turn waited on it, whichever model it asked for. The lock is now a lease: it is renewed on every
|
|
223
|
+
chunk that comes out of a stream, and it expires on its own when nothing has moved for `leaseMs`
|
|
224
|
+
(45s — longer than a healthy stream, short enough that a dead one is obvious). An abort signal also
|
|
225
|
+
releases it immediately, so a cancelled turn never holds the queue.
|
|
226
|
+
- **A cooldown was account-wide.** One model answering `710022004` set a one-minute penalty that every
|
|
227
|
+
other model had to sit through, which is exactly the "switched model, still nothing" feeling.
|
|
228
|
+
Penalties are now keyed by model. A response-filter refusal is a property of the *conversation*, not
|
|
229
|
+
of the model, so that one is still deliberately unscoped — `penalize(ms)` with no key keeps the old
|
|
230
|
+
account-wide meaning.
|
|
231
|
+
|
|
232
|
+
Both are covered by tests (`a stream dropped without return() stops blocking the next turn`,
|
|
233
|
+
`aborting a turn lets the next one start immediately`, `a cooldown belongs to the model that earned
|
|
234
|
+
it`) and were reproduced against the live endpoint before and after the fix.
|
|
235
|
+
|
|
236
|
+
## When the risk engine takes an interest
|
|
237
|
+
|
|
238
|
+
While an account is in good standing, a plain HTTPS request is enough and this plugin is as
|
|
239
|
+
self-contained as it looks — that is the path every turn takes first, and it needs no client at all.
|
|
240
|
+
Once the semantic risk model flags the account, that stops being true: every unsigned request comes
|
|
241
|
+
back as `710022004`, no matter how the payload is shaped. That was measured rather than assumed —
|
|
242
|
+
a client request was captured and then bisected field by field:
|
|
243
|
+
|
|
244
|
+
| Variation | Result |
|
|
245
|
+
| --- | --- |
|
|
246
|
+
| Vary the query string (versions, `web_id`, `device_platform`) | still `710022004` |
|
|
247
|
+
| Vary the session cookie (stored vs. the client's live jar) | still `710022004` |
|
|
248
|
+
| Vary the model or the wording | still `710022004` |
|
|
249
|
+
| Vary `client_meta` (conversation id, last section, message index) | no effect |
|
|
250
|
+
| Vary `option` | this is what the check reads |
|
|
251
|
+
| Reuse a `conversation_id` that already exists | accepted, but only replays history |
|
|
252
|
+
| Replay a captured signed URL | accepted, but only replays history |
|
|
253
|
+
|
|
254
|
+
The last two rows are the interesting ones. A captured request is signed with `a_bogus` plus an
|
|
255
|
+
`msToken`, and those are bound to the body: change one field and the signature stops matching, which
|
|
256
|
+
is why a replay only ever returns what the original call returned. New conversations are refused
|
|
257
|
+
outright, so no amount of shape-matching inside Node can make a fresh request pass — and the signer
|
|
258
|
+
is not reachable either, since `a_bogus` appears in none of the client's 26 loaded bundles and
|
|
259
|
+
`window.byted_acrawler` does not exist. The signing lives in the client's preload, wrapped around
|
|
260
|
+
`fetch` itself.
|
|
261
|
+
|
|
262
|
+
So the plugin borrows the signer instead of imitating it — but only when it must. The flow is:
|
|
263
|
+
|
|
264
|
+
1. **Healthy account:** the first request goes out as plain HTTPS. The client is never probed, let
|
|
265
|
+
alone launched, and a DSH restart makes no difference. This is the normal case.
|
|
266
|
+
2. **710022004 on the direct path:** no partial answer is leaked; the account is marked in a short-lived
|
|
267
|
+
`riskMemory` (see `lib/risk-memory.js`, default 30 minutes, persisted under
|
|
268
|
+
`~/.dsh/doubao-local/risk-flags.json`), and the same turn is retried through the signed bridge.
|
|
269
|
+
3. **Flagged on entry:** the doomed direct probe is skipped and the turn goes straight to the bridge.
|
|
270
|
+
The flag expires on its own, so an account that recovers (a completed slider, a different network)
|
|
271
|
+
drifts back to direct requests without any manual reset and without launching the client again.
|
|
272
|
+
|
|
273
|
+
`lib/bridge.js` connects to the client's chat page over the DevTools protocol and lets *the page*
|
|
274
|
+
perform the signed request: its own preload hook adds the signature, and each response chunk is
|
|
275
|
+
pushed back through a runtime binding as it arrives, so the plugin still streams rather than
|
|
276
|
+
buffering. The bridge uses port `9222` by default.
|
|
277
|
+
|
|
278
|
+
Getting there is automatic once needed. The debugger port only exists when the client was started
|
|
279
|
+
with `--remote-debugging-port`, which an ordinary launch does not pass — and a second launch against
|
|
280
|
+
a running client just joins it and drops the flag. So the plugin starts the client with the flag,
|
|
281
|
+
stopping and restarting an existing instance if one is in the way. The attempt is made once per port
|
|
282
|
+
per process and its result cached (success or failure), so a missing install is not retried on every
|
|
283
|
+
message. In practice a plain client is brought up to a working bridge in about five seconds, once.
|
|
284
|
+
|
|
285
|
+
The bridge is a transport, with a clear failure model:
|
|
286
|
+
|
|
287
|
+
- No client and no way to start one (the executable is not installed) → the direct request stands and
|
|
288
|
+
the `710022004` is reported. Nothing could sign it anyway, so this is honest, not degraded.
|
|
289
|
+
- A client reachable but the page dies mid-flight → the turn fails with code `BRIDGE`, mapped to
|
|
290
|
+
`TRANSPORT` so the harness may retry it. That is deliberately *not* reported as `RATE_LIMIT`:
|
|
291
|
+
retrying a rate limit deepens it, while retrying a dropped local connection is harmless.
|
|
292
|
+
- `allowBridge: false` (or `bridge: false` on a single call) forces direct-only: no memory, no
|
|
293
|
+
fallback, and the client is never probed or launched. `bridgePort` overrides the port.
|
|
294
|
+
|
|
295
|
+
What this does not do is make a flagged account work in general: the bridge satisfies the
|
|
296
|
+
*signature* check, so an account held only by that check recovers immediately, but an account under
|
|
297
|
+
an active semantic flag can still be refused, and only the captcha in the client clears that.
|
|
298
|
+
|
|
299
|
+
## Content moderation
|
|
300
|
+
|
|
301
|
+
Doubao's content filter does not return an error code. It answers with a canned notice as an ordinary
|
|
302
|
+
text stream and a `stop` finish:
|
|
303
|
+
|
|
304
|
+
> 该内容涉嫌违反[豆包使用规范](...),若有误判,请长按本条消息后点击"反馈与举报"进行反馈。
|
|
305
|
+
|
|
306
|
+
Left alone, the harness renders that as the model's reply — to the user it just looks like the model
|
|
307
|
+
"cannot chat". The plugin handles this in two layers:
|
|
308
|
+
|
|
309
|
+
- **It does not ship the host's own instructions.** DSH appends its operating-mode preamble,
|
|
310
|
+
`AGENTS.md`, and the project memory to the messages it hands an adapter (inside
|
|
311
|
+
`<system-reminder>` blocks, tens of thousands of characters). Those words are for *this* agent,
|
|
312
|
+
not conversation content, and phrases like "execute without refusal" are exactly what tripped the
|
|
313
|
+
consumer endpoint's moderation. `toPrompt` strips the reminder tags and drops long host preambles
|
|
314
|
+
while keeping short system hints and any long document the user actually pasted.
|
|
315
|
+
- **It never shows a canned refusal as an answer.** If a refusal still arrives (in one chunk or
|
|
316
|
+
split across several), the adapter catches it before a single character reaches the UI and emits a
|
|
317
|
+
plain explanation instead — "Doubao 内容审核拦截了本次请求(不是模型故障)…" — plus a short
|
|
318
|
+
cooling-off. It stays a `stop` finish rather than a thrown error, so the harness does not retry
|
|
319
|
+
into the same filter.
|
|
320
|
+
|
|
321
|
+
Normal replies are unaffected: the refusal check only buffers deltas while they are still a prefix
|
|
322
|
+
of the notice's lead, which is shorter than one chunk, so a real answer starts streaming on its very
|
|
323
|
+
first delta.
|
|
324
|
+
|
|
325
|
+
## Streaming: thinking and time-to-first-token
|
|
326
|
+
|
|
327
|
+
Doubao streams a deep-thinking model in two phases, and the wire format does not label them the way
|
|
328
|
+
you would hope. A `block_type: 10040` `thinking_block` carries only titles (`正在思考` / `已完成思考`)
|
|
329
|
+
— no body. The reasoning text itself is an ordinary `block_type: 10000` `text_block` whose
|
|
330
|
+
`parent_id` points at that 10040 block, followed by `CHUNK_DELTA` frames that carry `{"text": …}` and
|
|
331
|
+
nothing else. The final answer is another 10000 block with no thinking parent.
|
|
332
|
+
|
|
333
|
+
The adapter used to take every `CHUNK_DELTA` as answer text, so the reasoning was welded onto the
|
|
334
|
+
front of the reply (`"用户要解题,我先算出甲效率为1/6…\n\n3"`) and nothing appeared on screen until the
|
|
335
|
+
answer block began. `createTextTracker` now remembers which block ids were thinking parents, attributes
|
|
336
|
+
each `CHUNK_DELTA` to the most recently declared text block, and `stream()` maps the two kinds onto
|
|
337
|
+
separate DSH blocks: `block-start`+`reasoning-delta` for thinking, `block-start`+`text-delta` for the
|
|
338
|
+
answer. The client's `ReasoningRow` renders the first as a collapsible "thinking" strip, so the turn
|
|
339
|
+
starts moving as soon as the model starts thinking.
|
|
340
|
+
|
|
341
|
+
Two limits are worth knowing. Models that do not reason at all (`deepseek-v4.1-flash`, `doubao-2.1-*`
|
|
342
|
+
under a low effort) emit no reasoning stream, so there is nothing earlier to show; their
|
|
343
|
+
time-to-first-token is whatever the service gives (measured 2.3–7.0s for a one-line question, and the
|
|
344
|
+
surface tuple — `mode_id` / `agent_mode` / `conversation_mode` / `reasoning_effort` — moved it within
|
|
345
|
+
noise, 2.3–7.4s, so it is not worth retuning). The request also sits behind the turn lock, so the
|
|
346
|
+
first token of turn *N* cannot arrive before turn *N-1* finished plus `minIntervalMs`.
|
|
347
|
+
|
|
348
|
+
`prepareCall` no longer awaits the credit-rate fetch either: rates only decorate the model name shown
|
|
349
|
+
in the turn record, and blocking the first byte on a `brief_list` round trip was pure latency. The
|
|
350
|
+
picker still awaits them, where accuracy is what matters.
|
|
351
|
+
|
|
352
|
+
## Context budget / long sessions
|
|
353
|
+
|
|
354
|
+
The endpoint is stateless: DSH replays the whole visible conversation on every turn, and this adapter
|
|
355
|
+
has to flatten it into one `text_block.text`. A long session therefore used to produce a request body
|
|
356
|
+
of **2,253,285 characters** (1,497 blocks, including compressed summaries, tool results and injected
|
|
357
|
+
runtime notes). Doubao's gateway answers an oversized single text block with a plain
|
|
358
|
+
`common invalid param` SSE error — no error code, HTTP still 200 — so the UI just showed a failed
|
|
359
|
+
turn with no explanation. A fresh session (≈900 characters) worked, an old one always failed.
|
|
360
|
+
|
|
361
|
+
`toPrompt` now applies a `MAX_PROMPT_CHARS = 32_000` budget before the body is built, following the
|
|
362
|
+
same idea as workbuddy's `applyContextBudgets` / `keepPromptLast`:
|
|
363
|
+
|
|
364
|
+
- Runtime injections (`Time sampled while preparing turn …`, `Current runtime context`, ACP markers,
|
|
365
|
+
`[model changed: …]`, compressed-section headers) are not conversation and are dropped.
|
|
366
|
+
- Host-marked assistant/tool meta-discussion (`AGENTS.md`, operating-mode phrases) is dropped too;
|
|
367
|
+
a short user question mentioning those words is kept, and so is a long document the user pasted.
|
|
368
|
+
- If the remaining history still exceeds the budget, the adapter keeps the leading system hint, a
|
|
369
|
+
`[… earlier turns omitted …]` marker, and as many recent turns as fit. **The last user turn is
|
|
370
|
+
never dropped**; when a single turn is itself oversized, its tail is kept because that is where the
|
|
371
|
+
actual instruction lives.
|
|
372
|
+
|
|
373
|
+
If the gateway ever returns `invalid param` again, the error finish now carries the wire prompt size
|
|
374
|
+
and the budget, so a recurrence is self-diagnosing.
|
|
375
|
+
|
|
376
|
+
## Remaining credit
|
|
377
|
+
|
|
378
|
+
Beside the composer, next to the model seat, the plugin shows `积分 9,793` while a Doubao model is
|
|
379
|
+
selected — same place and same styling as the WorkBuddy plugin's credit readout. Hovering it breaks
|
|
380
|
+
the total down per quota window; clicking re-reads it. It refreshes once a minute.
|
|
381
|
+
|
|
382
|
+
The number comes from `POST /alice/commerce/sale/subscription/quota/summary/`, the endpoint the Doubao
|
|
383
|
+
web client itself calls, authorised by the same cookies the chat requests already use. Two quota
|
|
384
|
+
windows arrive (`活动赠送额度` and `月度额度`), each with a thousand-separated `total_amount` and
|
|
385
|
+
`used_amount`; there is no ready-made `remaining` field, so it is `total - used`, clamped at zero.
|
|
386
|
+
|
|
387
|
+
Three details are deliberate:
|
|
388
|
+
|
|
389
|
+
- **A read failure shows `—`, never `0`.** Not signed in, offline, or an upstream shape change all
|
|
390
|
+
mean "could not read it", which is a different fact from "you have none left". `creditsFromSummary`
|
|
391
|
+
returns `undefined` for a payload it cannot parse, and the route answers `{"credits": null}`.
|
|
392
|
+
- **The browser never talks to doubao.com.** The host reads the balance and serves it on
|
|
393
|
+
`GET /plugins/dsh-plugin-doubao/credits` (loopback-only, GET-only, `Cache-Control: no-store`); the
|
|
394
|
+
client bundle just fetches that same-origin path, so no cookie ever enters the page.
|
|
395
|
+
- **It renders for the Doubao provider only.** The slot is drawn for every provider, so the component
|
|
396
|
+
runs its hooks unconditionally and returns `null` afterwards — switching to a WorkBuddy model must
|
|
397
|
+
not leave a stale Doubao number sitting in the composer.
|
|
398
|
+
|
|
399
|
+
## Limitations
|
|
400
|
+
|
|
401
|
+
- **Text only.** Doubao's web endpoint accepts no images here, so nothing advertises image input.
|
|
402
|
+
- **Tool calling is a prompt bridge, not a native capability.** `www.doubao.com/chat/completion`
|
|
403
|
+
has no `tools`/`function_call` field (that lives on the paid Volcengine Ark API), so the plugin
|
|
404
|
+
serialises the harness tool schemas into the prompt and asks the model to answer with a strict
|
|
405
|
+
`[TOOL_CALL]{"name":…,"arguments":{…}}[/TOOL_CALL]` marker. Those markers are translated back into
|
|
406
|
+
the harness `tool-call` chunk protocol and the agent loop executes them locally — so Doubao models
|
|
407
|
+
can run terminal commands, read files and use the other harness tools. This is model-compliance
|
|
408
|
+
dependent: if the model ignores the marker or writes a malformed one, the turn is rendered as plain
|
|
409
|
+
text instead of a call. Turns with no tools configured are byte-for-byte unchanged.
|
|
410
|
+
- **Token counts are estimates.** The endpoint returns no usage block, so counts are derived from
|
|
411
|
+
character length (roughly two characters per token). Good enough for a meter, not for billing.
|
|
412
|
+
- **The thinking toggle only reaches the chat models.** `doubao` and `doubao-expert` take a
|
|
413
|
+
`need_deep_think` flag, so the harness reasoning setting applies to them and they expose Off/High.
|
|
414
|
+
For the routed models the thinking depth is part of the model definition — `GLM 5.3` is not `GLM 5.3`
|
|
415
|
+
with thinking off — so the flag is fixed. Those models advertise only the Off effort rather than a
|
|
416
|
+
High switch that would silently do nothing; a stale High request is rejected as unsupported instead
|
|
417
|
+
of being quietly ignored.
|
|
418
|
+
- **No conversation continuity.** Each turn is a fresh conversation on Doubao's side, because the
|
|
419
|
+
endpoint is stateless per request and passing a conversation id back would require server-side state
|
|
420
|
+
the harness does not give the adapter.
|
|
421
|
+
|
|
422
|
+
## Development
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
node --test test/plugin.test.mjs # protocol, framing, pacer, identity, credentials
|
|
426
|
+
node --test test/apply.test.mjs # wiring into a cordis context
|
|
427
|
+
node --test test/credits.test.mjs # quota parsing and the loopback credits route
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Pass the file, not the directory: `node --test test/` is treated as a module path and fails with
|
|
431
|
+
`Cannot find module`.
|
|
432
|
+
|
|
433
|
+
The identity reader can be checked against the real client on this machine:
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
node -e "import('./lib/identity.js').then(m => console.log(m.toIdentity(m.findClientIdentity({}).info)))"
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## Layout
|
|
440
|
+
|
|
441
|
+
| File | Role |
|
|
442
|
+
| --- | --- |
|
|
443
|
+
| `lib/doubao.js` | The wire protocol: query/body shaping, SSE framing, thinking/answer attribution, the turn pacer. |
|
|
444
|
+
| `lib/bridge.js` | The signed-request bridge: drives the running client over the DevTools protocol. |
|
|
445
|
+
| `lib/identity.js` | Reads `device_id` and friends out of the installed client's `Local State`. |
|
|
446
|
+
| `lib/adapter.js` | The LLM provider: model catalog, stream mapping, error mapping. |
|
|
447
|
+
| `lib/rates.js` | Reads the credit multipliers from Doubao's model-list endpoint. |
|
|
448
|
+
| `lib/credits.js` | Reads the remaining credit from Doubao's quota-summary endpoint. |
|
|
449
|
+
| `lib/client.js` | The browser half: the credit readout in `conversation.input.right`. |
|
|
450
|
+
| `lib/login.js` | QR sign-in page, cookie harvest, credential storage. |
|
|
451
|
+
| `lib/index.js` | `apply()`: registers the provider, the `doubao` service and the credits route. |
|
|
452
|
+
| `bin/login.js` | The `dsh-plugin-doubao` command. |
|
|
453
|
+
|
|
454
|
+
## Legal
|
|
455
|
+
|
|
456
|
+
This uses your own Doubao account through the same endpoints its web client calls. It is not
|
|
457
|
+
affiliated with ByteDance. Automating a consumer account may violate the service's terms, and the
|
|
458
|
+
account is yours to risk.
|
package/bin/login.bat
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
set "LOGINJS=%~dp0login.js"
|
|
4
|
+
|
|
5
|
+
set "NODEexe="
|
|
6
|
+
where node >nul 2>&1 && set "NODEexe=node"
|
|
7
|
+
if not defined NODEexe if exist "%ProgramFiles%\nodejs\node.exe" set "NODEexe=%ProgramFiles%\nodejs\node.exe"
|
|
8
|
+
if not defined NODEexe if exist "%LOCALAPPDATA%\Programs\nodejs\node.exe" set "NODEexe=%LOCALAPPDATA%\Programs\nodejs\node.exe"
|
|
9
|
+
if not defined NODEexe (
|
|
10
|
+
echo Node.js not found. Install it from https://nodejs.org ^(needs 22 or newer^).
|
|
11
|
+
pause
|
|
12
|
+
exit /b 1
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
if not exist "%LOGINJS%" (
|
|
16
|
+
echo login.js not found next to this file.
|
|
17
|
+
pause
|
|
18
|
+
exit /b 1
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
echo Opening the Doubao sign-in page...
|
|
22
|
+
echo Scan the QR with the DOUYIN app ^(not the Doubao app^).
|
|
23
|
+
echo.
|
|
24
|
+
"%NODEexe%" "%LOGINJS%" %*
|
|
25
|
+
echo.
|
|
26
|
+
pause
|
|
27
|
+
endlocal
|
package/bin/login.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `dsh-plugin-doubao` — sign in to Doubao without talking to the agent.
|
|
4
|
+
*
|
|
5
|
+
* The plugin can serve its sign-in page from inside a DSH session, but that is a
|
|
6
|
+
* chicken-and-egg problem: you install it, the model list appears, and every
|
|
7
|
+
* request fails with AUTH_MISSING until you sign in — which you were told to do
|
|
8
|
+
* by chatting with the very agent that cannot answer. This entry point breaks
|
|
9
|
+
* that loop: run it once after install, scan a QR, and the session is stored
|
|
10
|
+
* where the plugin reads it. No conversation, no harness, no restart needed.
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from 'node:child_process'
|
|
13
|
+
import { runLoginServer, readCredentials, credentialsPath } from '../lib/login.js'
|
|
14
|
+
import { findClientIdentity, toIdentity } from '../lib/identity.js'
|
|
15
|
+
|
|
16
|
+
const args = process.argv.slice(2)
|
|
17
|
+
const has = (...flags) => flags.some((f) => args.includes(f))
|
|
18
|
+
const force = has('--force', '-f')
|
|
19
|
+
const statusOnly = has('--status', '-s')
|
|
20
|
+
const noOpen = has('--no-open')
|
|
21
|
+
const portAt = args.indexOf('--port')
|
|
22
|
+
const port = portAt >= 0 ? Number(args[portAt + 1]) : Number(process.env.DOUBAO_LOGIN_PORT ?? 8899)
|
|
23
|
+
const store = { DSH_HOME: process.env.DSH_HOME }
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Read the expiry out of the sid_guard cookie when present. Its shape is
|
|
27
|
+
* `id|createdEpoch|durationSeconds|ExpiryDateGMT` — field[1] is the CREATION
|
|
28
|
+
* time, not the expiry, so prefer the explicit date in field[3] and fall back
|
|
29
|
+
* to created + duration.
|
|
30
|
+
*/
|
|
31
|
+
function expiryOf(cred) {
|
|
32
|
+
const match = /(?:^|;\s*)sid_guard=([^;]+)/.exec(cred?.cookies ?? '')
|
|
33
|
+
if (!match) return undefined
|
|
34
|
+
const parts = decodeURIComponent(match[1]).split('|')
|
|
35
|
+
if (parts[3]) {
|
|
36
|
+
const parsed = new Date(parts[3].replace(/\+/g, ' '))
|
|
37
|
+
if (!Number.isNaN(parsed.getTime())) return parsed
|
|
38
|
+
}
|
|
39
|
+
const seconds = Number(parts[1]) + Number(parts[2] || 0)
|
|
40
|
+
return Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1000) : undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function describe(cred) {
|
|
44
|
+
const path = credentialsPath(store)
|
|
45
|
+
const exp = expiryOf(cred)
|
|
46
|
+
const days = exp ? Math.ceil((exp.getTime() - Date.now()) / 86_400_000) : undefined
|
|
47
|
+
return [
|
|
48
|
+
`Signed in: ${path}`,
|
|
49
|
+
`Device: ${cred.identity?.deviceId ?? '?'}`,
|
|
50
|
+
exp ? `Expires: ${exp.toISOString()}${days > 0 ? ` (${days} days left)` : ' (EXPIRED — run with --force)'}` : null,
|
|
51
|
+
].filter(Boolean).join('\n')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function openBrowser(url) {
|
|
55
|
+
try {
|
|
56
|
+
const child = process.platform === 'win32'
|
|
57
|
+
? spawn('cmd', ['/c', 'start', '""', url], { detached: true, stdio: 'ignore' })
|
|
58
|
+
: process.platform === 'darwin'
|
|
59
|
+
? spawn('open', [url], { detached: true, stdio: 'ignore' })
|
|
60
|
+
: spawn('xdg-open', [url], { detached: true, stdio: 'ignore' })
|
|
61
|
+
child.unref()
|
|
62
|
+
return true
|
|
63
|
+
} catch {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const existing = readCredentials(store)
|
|
69
|
+
|
|
70
|
+
if (statusOnly) {
|
|
71
|
+
if (!existing) {
|
|
72
|
+
console.log('Not signed in. Run `dsh-plugin-doubao` (or double-click the login launcher).')
|
|
73
|
+
process.exit(0)
|
|
74
|
+
}
|
|
75
|
+
console.log(describe(existing))
|
|
76
|
+
process.exit(0)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (existing && !force) {
|
|
80
|
+
console.log(describe(existing))
|
|
81
|
+
console.log('Run with --force to scan again, or --status to check this any time.')
|
|
82
|
+
process.exit(0)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const found = findClientIdentity(store)
|
|
86
|
+
if (!found.found) {
|
|
87
|
+
console.error('No Doubao desktop client identity found on this machine.')
|
|
88
|
+
console.error('Doubao refuses requests from device ids the account has never seen (710022004),')
|
|
89
|
+
console.error('so the client must be installed and signed in at least once. Looked in:')
|
|
90
|
+
for (const dir of found.tried) console.error(` ${dir}`)
|
|
91
|
+
process.exit(1)
|
|
92
|
+
}
|
|
93
|
+
console.log(`Device identity: ${toIdentity(found.info).deviceId} (from the installed client)`)
|
|
94
|
+
|
|
95
|
+
const server = await runLoginServer({
|
|
96
|
+
port,
|
|
97
|
+
logger: console,
|
|
98
|
+
onCredentials() {
|
|
99
|
+
console.log('Saved. You can use Doubao models in DSH now — no restart, no chat needed.')
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
server.close()
|
|
102
|
+
process.exit(0)
|
|
103
|
+
}, 1800)
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
console.log(`\nOpen ${server.url} and scan with the Douyin app (not Doubao).`)
|
|
108
|
+
if (!noOpen && openBrowser(server.url)) {
|
|
109
|
+
console.log('Browser opened for you. If it did not appear, copy the URL above.')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Keep the process alive; runLoginServer owns the event loop.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# dsh-plugin-doubao bundle patch.
|
|
2
|
+
#
|
|
3
|
+
# Mounts one entry. It registers itself as an LLM provider ("doubao" by default),
|
|
4
|
+
# so it owns its own model list — there is nothing to declare in the profile and no
|
|
5
|
+
# local server to start.
|
|
6
|
+
#
|
|
7
|
+
# If something else already claims the "doubao" provider id, change it here:
|
|
8
|
+
# config:
|
|
9
|
+
# providerId: doubao-personal
|
|
10
|
+
- insert:
|
|
11
|
+
- id: doubao
|
|
12
|
+
name: dsh-plugin-doubao
|
|
13
|
+
config: {}
|