dsh-xdpool 2.7.2 → 2.7.3
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/CHANGELOG.md +62 -0
- package/lib/bin.js +1 -1
- package/lib/client.js +85 -11
- package/lib/index.js +290 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
本项目的所有重要变更都会记录在此文件。
|
|
3
3
|
版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
|
+
## 2.7.3 — 豆包进模型选择器,开关能记住了
|
|
5
|
+
|
|
6
|
+
> 两个问题:豆包的模型在选择器里完全看不到;勾选和全开全关关掉面板就失效。
|
|
7
|
+
|
|
8
|
+
### 豆包为什么不在模型选择器里
|
|
9
|
+
|
|
10
|
+
模型选择器读的是**宿主的 adapter 注册表**(`ctx.llm.registerAdapter`),而豆包只走了
|
|
11
|
+
channelLane 的 HTTP 路由 —— 那条路让模型可用,但不会让它们出现在列表里。所以一个已登录、
|
|
12
|
+
十个模型全勾的账号,在选择器里一片空白。
|
|
13
|
+
|
|
14
|
+
现在按其他渠道的方式注册:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
ctx.llm.registerAdapter([DOUBAO_PROVIDER_ID], new DoubaoHostAdapter({ ... }))
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
实现了 `LlmAdapter` 要求的五个方法(`providerInfo` / `listModels` / `resolveModel` /
|
|
21
|
+
`prepareCall` / `stream`),请求细节仍由 `doubao-upstream.ts` 决定。
|
|
22
|
+
|
|
23
|
+
### 模型参数、倍率、免费标注
|
|
24
|
+
|
|
25
|
+
`brief_list` 接口只返回功能入口,**不含**任何模型字段。倍率和上下文在**桌面客户端的
|
|
26
|
+
IndexedDB 记录里**:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
model_item_key: person-kimi-k3-261111
|
|
30
|
+
name: Kimi K3
|
|
31
|
+
total_window_size: 300000
|
|
32
|
+
tag.text: "1.48x"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
解析后卡片和选择器都能显示:
|
|
36
|
+
|
|
37
|
+
| 模型 | 倍率 |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| Kimi K3 | `1.48x` |
|
|
40
|
+
| GLM 5.3 | `0.80x` |
|
|
41
|
+
| Kimi K3.1 Pro 高速 | `1.44x` |
|
|
42
|
+
|
|
43
|
+
上下文窗口 256k,推理三档(低/中/高)。倍率写成字符串而不是数字 —— `1.48x` 是费率、
|
|
44
|
+
`免费` 根本不是倍率、`x0.12→x0.06` 是进行中的促销,压平成数字就等于替厂商改口径。
|
|
45
|
+
没有倍率数据的模型(例如某些套餐下的 DeepSeek)就不显示,不编造。
|
|
46
|
+
|
|
47
|
+
### 模型开关为什么记不住
|
|
48
|
+
|
|
49
|
+
`model.setDisabled` 和 `model.setAllDisabled` 都是 pack 的 RPC,指向 pack 自己的模型记录。
|
|
50
|
+
豆包在那里没有条目,所以两个调用都回答 `unknown provider`,接着 catch 回滚本地状态:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
setEnabled(previous => { const restored = new Map(previous); restored.delete(provider); return restored })
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
于是「全关 → 重新打开面板 → 又是全开」。
|
|
57
|
+
|
|
58
|
+
现在豆包自己存(其他渠道由 pack 存,因为 pack 拥有它们的目录):
|
|
59
|
+
|
|
60
|
+
- 单个开关:`saveDoubaoSkipped(modelId, disabled)`
|
|
61
|
+
- 全开全关:一次写入整个名单
|
|
62
|
+
|
|
63
|
+
读取端区分两种状态:`undefined` 是「从未配置」(全开),`[]` 是「配置为全关」。
|
|
64
|
+
混在一起会让新账号看起来像已经被配置过。
|
|
65
|
+
|
|
4
66
|
## 2.7.2 — 一个账号池,一组模型
|
|
5
67
|
|
|
6
68
|
> 模型选择器里同一个账号池出现了四个分组(XD Pool 国内版/国际版 + WorkBuddy 国内版/国际版)。
|
package/lib/bin.js
CHANGED
|
@@ -4,11 +4,11 @@ import { chmod, copyFile, mkdir, readFile, readdir, rename, rm, unlink, writeFil
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { basename, dirname, join, resolve } from "node:path";
|
|
6
6
|
import { execFile, execFileSync } from "node:child_process";
|
|
7
|
+
import "@deepseek-ai/dsh-llm";
|
|
7
8
|
import z from "@deepseek-ai/schemastery";
|
|
8
9
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
10
|
import "@earendil-works/pi-ai";
|
|
10
11
|
import "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
11
|
-
import "@deepseek-ai/dsh-llm";
|
|
12
12
|
import "@deepseek-ai/dsh-llm-pi-ai";
|
|
13
13
|
//#region src/badges.ts
|
|
14
14
|
/**
|
package/lib/client.js
CHANGED
|
@@ -12599,6 +12599,34 @@ window.__ModuleLoader__.load({
|
|
|
12599
12599
|
* Versioned, because the shape will change and a stale blob must not be fed to new code.
|
|
12600
12600
|
*/
|
|
12601
12601
|
const COUNTS_STORE_KEY = "dsh-xdpool.channel-counts.v1";
|
|
12602
|
+
/** Where Doubao's own model selection lives. Versioned for the same reason as the counts. */
|
|
12603
|
+
const DOUBAO_SKIP_KEY = "dsh-xdpool.doubao-skipped-models.v1";
|
|
12604
|
+
/**
|
|
12605
|
+
* The Doubao models the user switched off.
|
|
12606
|
+
*
|
|
12607
|
+
* `undefined` means "never configured", which is different from "none switched off": the first
|
|
12608
|
+
* shows everything, the second shows nothing. Collapsing them would make a fresh account look
|
|
12609
|
+
* as though the user had already made choices.
|
|
12610
|
+
*/
|
|
12611
|
+
function readDoubaoSkipped() {
|
|
12612
|
+
try {
|
|
12613
|
+
const raw = globalThis.localStorage?.getItem(DOUBAO_SKIP_KEY);
|
|
12614
|
+
if (raw === null || raw === void 0) return void 0;
|
|
12615
|
+
const parsed = JSON.parse(raw);
|
|
12616
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
12617
|
+
return new Set(parsed.filter((id) => typeof id === "string"));
|
|
12618
|
+
} catch {
|
|
12619
|
+
return;
|
|
12620
|
+
}
|
|
12621
|
+
}
|
|
12622
|
+
/** Record one model as switched off, or back on. */
|
|
12623
|
+
async function saveDoubaoSkipped(modelId, disabled) {
|
|
12624
|
+
const current = readDoubaoSkipped() ?? /* @__PURE__ */ new Set();
|
|
12625
|
+
const next = new Set(current);
|
|
12626
|
+
if (disabled) next.add(modelId);
|
|
12627
|
+
else next.delete(modelId);
|
|
12628
|
+
globalThis.localStorage?.setItem(DOUBAO_SKIP_KEY, JSON.stringify([...next]));
|
|
12629
|
+
}
|
|
12602
12630
|
/** Read the stored counts, or undefined when there is nothing usable. */
|
|
12603
12631
|
function readStoredCounts() {
|
|
12604
12632
|
try {
|
|
@@ -12761,8 +12789,15 @@ window.__ModuleLoader__.load({
|
|
|
12761
12789
|
const body = await (await fetch(POOL_DOUBAO_MODELS_PATH, { credentials: "same-origin" })).json().catch(() => void 0);
|
|
12762
12790
|
return (Array.isArray(body?.models) ? body.models : []).filter((model) => typeof model.id === "string" && typeof model.name === "string").map((model) => ({
|
|
12763
12791
|
id: model.id,
|
|
12764
|
-
|
|
12765
|
-
|
|
12792
|
+
/**
|
|
12793
|
+
* The multiplier is joined onto the name because that is the shape the card already
|
|
12794
|
+
* understands — every other channel writes it there (`DeepSeek-V4.1-Flash · x0.11`), and
|
|
12795
|
+
* `multiplierOf` splits it back out into its own badge. Doing it here keeps ONE rule for
|
|
12796
|
+
* every vendor instead of a Doubao-shaped exception in the renderer.
|
|
12797
|
+
*/
|
|
12798
|
+
name: typeof model.rate === "string" && model.rate !== "" ? `${model.name} · ${model.rate}` : model.name,
|
|
12799
|
+
...typeof model.badge === "string" && model.badge !== "" ? { description: model.badge } : {},
|
|
12800
|
+
...typeof model.contextWindow === "number" ? { contextWindow: model.contextWindow } : {}
|
|
12766
12801
|
}));
|
|
12767
12802
|
} catch {
|
|
12768
12803
|
return doubaoListing();
|
|
@@ -13147,7 +13182,23 @@ window.__ModuleLoader__.load({
|
|
|
13147
13182
|
return next;
|
|
13148
13183
|
});
|
|
13149
13184
|
};
|
|
13150
|
-
const enabledFor = (provider, models) =>
|
|
13185
|
+
const enabledFor = (provider, models) => {
|
|
13186
|
+
const live = enabled.get(provider);
|
|
13187
|
+
if (live !== void 0) return live;
|
|
13188
|
+
/**
|
|
13189
|
+
* Doubao remembers its own selection.
|
|
13190
|
+
*
|
|
13191
|
+
* The pack keeps every other channel's disabled list; this lane has no entry there, so its
|
|
13192
|
+
* choice is stored beside the counts it already keeps. `undefined` means "never touched" and
|
|
13193
|
+
* the default (all enabled) applies — a channel the user has not configured must not look
|
|
13194
|
+
* half-configured.
|
|
13195
|
+
*/
|
|
13196
|
+
if (provider === "doubao") {
|
|
13197
|
+
const saved = readDoubaoSkipped();
|
|
13198
|
+
if (saved !== void 0) return new Set(models.filter((model) => !saved.has(model.id)).map((model) => model.id));
|
|
13199
|
+
}
|
|
13200
|
+
return new Set(models.filter((model) => model.disabled !== true).map((model) => model.id));
|
|
13201
|
+
};
|
|
13151
13202
|
const queryFor = (provider) => queries.get(provider) ?? "";
|
|
13152
13203
|
const setQuery = (provider, query) => {
|
|
13153
13204
|
setQueries((previous) => {
|
|
@@ -13196,12 +13247,24 @@ window.__ModuleLoader__.load({
|
|
|
13196
13247
|
setEnabled((previous) => new Map(previous).set(provider, next));
|
|
13197
13248
|
markBusy(provider, true);
|
|
13198
13249
|
try {
|
|
13199
|
-
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13250
|
+
/**
|
|
13251
|
+
* Doubao's selection is saved HERE, not through the pack.
|
|
13252
|
+
*
|
|
13253
|
+
* `model.setDisabled` is a pack RPC addressed to the pack's own model record, and Doubao
|
|
13254
|
+
* has no entry there — so the call answered "unknown provider", the catch below rolled the
|
|
13255
|
+
* local state back, and the checkbox snapped to its old value the moment the panel was
|
|
13256
|
+
* reopened. Every other channel persists through the pack because the pack owns its
|
|
13257
|
+
* catalogue; this lane owns its own, so it persists its own.
|
|
13258
|
+
*/
|
|
13259
|
+
if (provider === "doubao") await saveDoubaoSkipped(modelId, !on);
|
|
13260
|
+
else {
|
|
13261
|
+
const envelope = await callPack("model.setDisabled", {
|
|
13262
|
+
provider,
|
|
13263
|
+
modelId,
|
|
13264
|
+
disabled: !on
|
|
13265
|
+
});
|
|
13266
|
+
if (!envelope.ok) throw new Error(envelope.error?.message ?? "model.setDisabled refused");
|
|
13267
|
+
}
|
|
13205
13268
|
} catch (cause) {
|
|
13206
13269
|
setNotice(t?.("channelpool.saveError", { message: cause instanceof Error ? cause.message : String(cause) }) ?? `Could not save: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
13207
13270
|
setEnabled((previous) => {
|
|
@@ -13254,7 +13317,18 @@ window.__ModuleLoader__.load({
|
|
|
13254
13317
|
setEnabled((previous) => new Map(previous).set(provider, new Set(on ? entry.models.map((model) => model.id) : [])));
|
|
13255
13318
|
markBusy(provider, true);
|
|
13256
13319
|
try {
|
|
13257
|
-
|
|
13320
|
+
/**
|
|
13321
|
+
* Doubao persists its own all-on / all-off.
|
|
13322
|
+
*
|
|
13323
|
+
* Same reason as the single toggle: `model.setAllDisabled` is a pack RPC and Doubao has no
|
|
13324
|
+
* entry in the pack's model record. Calling it answered "unknown provider", the catch
|
|
13325
|
+
* rolled the state back — which is exactly the "I turned them all off, reopened the panel,
|
|
13326
|
+
* they were all on again" report.
|
|
13327
|
+
*/
|
|
13328
|
+
if (provider === "doubao") {
|
|
13329
|
+
const skipped = on ? [] : entry.models.map((model) => model.id);
|
|
13330
|
+
globalThis.localStorage?.setItem(DOUBAO_SKIP_KEY, JSON.stringify(skipped));
|
|
13331
|
+
} else await callPack("model.setAllDisabled", {
|
|
13258
13332
|
provider,
|
|
13259
13333
|
disabled: !on
|
|
13260
13334
|
});
|
|
@@ -14403,7 +14477,7 @@ window.__ModuleLoader__.load({
|
|
|
14403
14477
|
*
|
|
14404
14478
|
* @module dsh-xdpool/version
|
|
14405
14479
|
*/
|
|
14406
|
-
const POOL_VERSION = "2.7.
|
|
14480
|
+
const POOL_VERSION = "2.7.3";
|
|
14407
14481
|
//#endregion
|
|
14408
14482
|
//#region src/client/PoolCard.tsx
|
|
14409
14483
|
/**
|
package/lib/index.js
CHANGED
|
@@ -4,12 +4,12 @@ import { appendFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSyn
|
|
|
4
4
|
import { homedir, hostname, tmpdir } from "node:os";
|
|
5
5
|
import { basename, dirname, join, resolve } from "node:path";
|
|
6
6
|
import crypto$1, { createDecipheriv, createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
7
|
+
import { LlmAdapter, LlmError, ReasoningEffortId, resolveImageAttachmentAccess, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
7
8
|
import { chmod, mkdir, readFile, readdir, rename, rm, unlink, writeFile } from "node:fs/promises";
|
|
8
9
|
import z from "@deepseek-ai/schemastery";
|
|
9
10
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
11
|
import { createProvider } from "@earendil-works/pi-ai";
|
|
11
12
|
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
12
|
-
import { resolveImageAttachmentAccess, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
13
13
|
import { PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
14
14
|
import { env } from "node:process";
|
|
15
15
|
import http, { createServer, request } from "node:http";
|
|
@@ -791,11 +791,22 @@ function parseCacheBuffer(buf) {
|
|
|
791
791
|
if (!/^person-[a-z0-9-]+-\d{6}$/u.test(slug)) continue;
|
|
792
792
|
if (out.has(slug)) continue;
|
|
793
793
|
const name = nameForSlug(buf, slug);
|
|
794
|
+
/**
|
|
795
|
+
* The window and the multiplier travel WITH the model in this cache.
|
|
796
|
+
*
|
|
797
|
+
* Measured on a real record: `total_window_size: 300000` and a `tag.text` of `"1.48x"` sit
|
|
798
|
+
* beside `model_item_key` and `name`. Neither is on any HTTP endpoint this lane can call —
|
|
799
|
+
* `brief_list` returns feature entries and no model fields at all — so the cache is the only
|
|
800
|
+
* source for the two numbers the picker wants to print.
|
|
801
|
+
*/
|
|
802
|
+
const meta = metaNear(buf, slug);
|
|
794
803
|
out.set(slug, {
|
|
795
804
|
id: slug,
|
|
796
805
|
name: name ?? nameFromSlug(slug),
|
|
797
806
|
badge: "工作任务",
|
|
798
|
-
reasoning: true
|
|
807
|
+
reasoning: true,
|
|
808
|
+
...meta.contextWindow === void 0 ? {} : { contextWindow: meta.contextWindow },
|
|
809
|
+
...meta.rate === void 0 ? {} : { rate: meta.rate }
|
|
799
810
|
});
|
|
800
811
|
}
|
|
801
812
|
const KEY = Buffer.from("model_item_key");
|
|
@@ -856,6 +867,32 @@ function nameForSlug(buf, slug) {
|
|
|
856
867
|
}
|
|
857
868
|
}
|
|
858
869
|
/**
|
|
870
|
+
* The window and multiplier recorded beside a model key.
|
|
871
|
+
*
|
|
872
|
+
* Both live in the same V8 record as the key, a few hundred bytes after it, so they are read
|
|
873
|
+
* from the same window the name is: `total_window_size` (or `context_window`) as a number, and
|
|
874
|
+
* the first `tag.text` that reads like a multiplier. Either may be absent — a model on a plan
|
|
875
|
+
* that publishes no figure simply has neither, and printing an invented one would be worse than
|
|
876
|
+
* printing nothing.
|
|
877
|
+
*/
|
|
878
|
+
function metaNear(buf, slug) {
|
|
879
|
+
const at = buf.indexOf(Buffer.from(slug, "latin1"));
|
|
880
|
+
if (at < 0) return {};
|
|
881
|
+
const text = buf.subarray(at, Math.min(buf.length, at + 1200)).toString("latin1");
|
|
882
|
+
const out = {};
|
|
883
|
+
const rate = /(\d+(?:\.\d+)?x|免费|限时免费)/iu.exec(text);
|
|
884
|
+
if (rate?.[1] !== void 0) out.rate = rate[1].trim();
|
|
885
|
+
/**
|
|
886
|
+
* A context window: `total_window_size` followed by its digits.
|
|
887
|
+
*
|
|
888
|
+
* Matched loosely on the boundary between the name and the number because the serialised form
|
|
889
|
+
* has no separator to anchor on — any non-digit run of up to 24 bytes is allowed between them.
|
|
890
|
+
*/
|
|
891
|
+
const size = /total_window_size[^0-9]{1,24}(\d{4,7})/u.exec(text) ?? /context_window[^0-9]{1,24}(\d{4,7})/u.exec(text) ?? /(\d{3})k_\d{3}/u.exec(text);
|
|
892
|
+
if (size?.[1] !== void 0) out.contextWindow = size[0].includes("k_") ? Number(size[1]) * 1e3 : Number(size[1]);
|
|
893
|
+
return out;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
859
896
|
* A presentable name derived from a model slug.
|
|
860
897
|
*
|
|
861
898
|
* `person-kimi-k3-1-pro-highspeed` reads as "Kimi K3.1 Pro Highspeed": the vendor prefix and
|
|
@@ -3517,6 +3554,246 @@ function createDoubaoAutomation(options) {
|
|
|
3517
3554
|
};
|
|
3518
3555
|
}
|
|
3519
3556
|
//#endregion
|
|
3557
|
+
//#region src/doubao-host-adapter.ts
|
|
3558
|
+
/**
|
|
3559
|
+
* Doubao as a host adapter.
|
|
3560
|
+
*
|
|
3561
|
+
* WHY THIS IS NEEDED
|
|
3562
|
+
*
|
|
3563
|
+
* `channel-lane.ts` serves `<channel>:<model>` ids for a gateway route, but the model PICKER
|
|
3564
|
+
* reads the host's adapter registry — `ctx.llm.registerAdapter([id], adapter)`. Every channel in
|
|
3565
|
+
* the pack registers one; Doubao did not, so a signed-in account with ten models enabled showed
|
|
3566
|
+
* nothing in the picker at all. The lane made the models reachable over HTTP; this makes them
|
|
3567
|
+
* visible in the list.
|
|
3568
|
+
*
|
|
3569
|
+
* WHAT IT IMPLEMENTS
|
|
3570
|
+
*
|
|
3571
|
+
* The five methods `LlmAdapter` requires, in the shape the pack's own adapters use:
|
|
3572
|
+
* `providerInfo`, `listModels`, `resolveModel`, `prepareCall`, `stream`. The wire stays in
|
|
3573
|
+
* `doubao-upstream.ts` — the module ported from a working implementation — so nothing here
|
|
3574
|
+
* invents request details.
|
|
3575
|
+
*
|
|
3576
|
+
* WHAT IT REPORTS ABOUT A MODEL
|
|
3577
|
+
*
|
|
3578
|
+
* The picker shows what these fields say, so they carry the same facts the other channels do:
|
|
3579
|
+
* context window, output ceiling, whether the model reasons, and the multiplier as a tag. A
|
|
3580
|
+
* model with no published figure says nothing rather than inventing one.
|
|
3581
|
+
*
|
|
3582
|
+
* @module dsh-xdpool/doubao-host-adapter
|
|
3583
|
+
*/
|
|
3584
|
+
/** The provider id the picker groups by. */
|
|
3585
|
+
const DOUBAO_PROVIDER_ID = "doubao";
|
|
3586
|
+
/** The name the picker shows for the group. */
|
|
3587
|
+
const DOUBAO_PROVIDER_NAME = "豆包";
|
|
3588
|
+
/**
|
|
3589
|
+
* The context window this lane reports.
|
|
3590
|
+
*
|
|
3591
|
+
* Doubao does not publish a per-model window on the endpoints this lane calls, and the chat
|
|
3592
|
+
* itself accepts far more than the client advertises. 256k is what the reference implementation
|
|
3593
|
+
* settled on after measuring; reporting nothing would make the picker show "—" beside every
|
|
3594
|
+
* model, which reads as a broken channel.
|
|
3595
|
+
*/
|
|
3596
|
+
const CONTEXT_WINDOW = 256e3;
|
|
3597
|
+
/** The output ceiling the lane requests. */
|
|
3598
|
+
const MAX_OUTPUT_TOKENS = 65536;
|
|
3599
|
+
/**
|
|
3600
|
+
* The multiplier, when the name carries one.
|
|
3601
|
+
*
|
|
3602
|
+
* Every vendor in this plugin writes the price into the model name; Doubao's own models are
|
|
3603
|
+
* included in the promotion programme, so the same shape appears (`… · x0.00`, `… · 免费`). The
|
|
3604
|
+
* split is done here rather than in the card so the PICKER sees it too.
|
|
3605
|
+
*/
|
|
3606
|
+
function rateOf(name) {
|
|
3607
|
+
return /[·・]\s*(x\s*[\d.]+(?:\s*→\s*x?[\d.]+)?|免费|限时免费)/iu.exec(name)?.[1]?.trim();
|
|
3608
|
+
}
|
|
3609
|
+
/** The name without its trailing price. */
|
|
3610
|
+
function bareName(name) {
|
|
3611
|
+
return name.replace(/\s*[·・]\s*(?:x\s*[\d.]+(?:\s*→\s*x?[\d.]+)?|免费|限时免费|正式版.*)$/iu, "").trim();
|
|
3612
|
+
}
|
|
3613
|
+
/**
|
|
3614
|
+
* The adapter.
|
|
3615
|
+
*
|
|
3616
|
+
* `listModels` reads the account's live roster through `fetchLiveModels`, which merges the
|
|
3617
|
+
* measured six with whatever `brief_list` returns and whatever the desktop client's cache holds —
|
|
3618
|
+
* that is where the `person-*` models (DeepSeek, Kimi, GLM) come from.
|
|
3619
|
+
*/
|
|
3620
|
+
var DoubaoHostAdapter = class extends LlmAdapter {
|
|
3621
|
+
options;
|
|
3622
|
+
/** The last roster read, so a picker redraw does not re-fetch. */
|
|
3623
|
+
cached;
|
|
3624
|
+
constructor(options) {
|
|
3625
|
+
super();
|
|
3626
|
+
this.options = options;
|
|
3627
|
+
}
|
|
3628
|
+
providerInfo(_provider) {
|
|
3629
|
+
return {
|
|
3630
|
+
id: DOUBAO_PROVIDER_ID,
|
|
3631
|
+
name: DOUBAO_PROVIDER_NAME
|
|
3632
|
+
};
|
|
3633
|
+
}
|
|
3634
|
+
async listModels(_provider) {
|
|
3635
|
+
const models = await fetchLiveModels(this.options.session());
|
|
3636
|
+
this.cached = {
|
|
3637
|
+
at: Date.now(),
|
|
3638
|
+
models
|
|
3639
|
+
};
|
|
3640
|
+
return models.map((model) => this.describe(model));
|
|
3641
|
+
}
|
|
3642
|
+
async resolveModel(provider, model, _signal) {
|
|
3643
|
+
const known = this.cached?.models.find((entry) => entry.id === model) ?? DOUBAO_MODELS.find((entry) => entry.id === model);
|
|
3644
|
+
if (known === void 0) return this.describe({
|
|
3645
|
+
id: model,
|
|
3646
|
+
name: model,
|
|
3647
|
+
reasoning: true
|
|
3648
|
+
});
|
|
3649
|
+
return this.describe(known);
|
|
3650
|
+
}
|
|
3651
|
+
async prepareCall(provider, model, signal) {
|
|
3652
|
+
return {
|
|
3653
|
+
model: await this.resolveModel(provider, model, signal),
|
|
3654
|
+
stream: (streamOptions) => this.stream(streamOptions)
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
/**
|
|
3658
|
+
* One turn.
|
|
3659
|
+
*
|
|
3660
|
+
* Text and reasoning are queued separately and drained as they arrive, so a long answer
|
|
3661
|
+
* appears progressively instead of landing whole. An image answer is appended as markdown —
|
|
3662
|
+
* the client renders it without knowing about Doubao's own image blocks.
|
|
3663
|
+
*/
|
|
3664
|
+
async *stream(options) {
|
|
3665
|
+
const session = this.options.session();
|
|
3666
|
+
if (session === void 0 || !sessionUsable(session)) throw new LlmError("还没有浏览器登录态。请在豆包卡片里点「重新登录」扫码一次。", "auth");
|
|
3667
|
+
const modelId = typeof options["model"] === "string" ? options["model"] : "";
|
|
3668
|
+
if (modelId === "") throw new LlmError("这条请求没有指定模型", "invalid");
|
|
3669
|
+
const messages = Array.isArray(options["messages"]) ? options["messages"] : [];
|
|
3670
|
+
const system = typeof options["system"] === "string" ? options["system"] : "";
|
|
3671
|
+
const body = promptOf(messages);
|
|
3672
|
+
const prompt = system === "" ? body : `${system}\n\n${body}`;
|
|
3673
|
+
if (prompt === "") throw new LlmError("这条请求没有可发送的文字", "invalid");
|
|
3674
|
+
const requested = options["reasoningEffort"];
|
|
3675
|
+
const level = typeof requested === "string" && [
|
|
3676
|
+
"low",
|
|
3677
|
+
"mid",
|
|
3678
|
+
"high"
|
|
3679
|
+
].includes(requested) ? requested : "mid";
|
|
3680
|
+
const signal = options["signal"] instanceof AbortSignal ? options["signal"] : new AbortController().signal;
|
|
3681
|
+
const textQueue = [];
|
|
3682
|
+
const reasoningQueue = [];
|
|
3683
|
+
let done = false;
|
|
3684
|
+
let failure;
|
|
3685
|
+
let images = [];
|
|
3686
|
+
const turn = chat(prompt, {
|
|
3687
|
+
modelKey: modelId,
|
|
3688
|
+
reasoningLevel: level,
|
|
3689
|
+
signal,
|
|
3690
|
+
callbacks: {
|
|
3691
|
+
onText: (chunk) => {
|
|
3692
|
+
if (chunk !== "") textQueue.push(chunk);
|
|
3693
|
+
},
|
|
3694
|
+
onThinking: (chunk) => {
|
|
3695
|
+
if (chunk !== "") reasoningQueue.push(chunk);
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
}).then((result) => {
|
|
3699
|
+
if (typeof result.conversationId === "string" && result.conversationId !== "") this.options.onConversationId?.(result.conversationId);
|
|
3700
|
+
if (Array.isArray(result.images)) images = result.images;
|
|
3701
|
+
}).catch((error) => {
|
|
3702
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
3703
|
+
}).finally(() => {
|
|
3704
|
+
done = true;
|
|
3705
|
+
});
|
|
3706
|
+
while (!done || textQueue.length > 0 || reasoningQueue.length > 0) {
|
|
3707
|
+
const thinking = reasoningQueue.shift();
|
|
3708
|
+
if (thinking !== void 0) {
|
|
3709
|
+
yield {
|
|
3710
|
+
type: "reasoning-delta",
|
|
3711
|
+
index: 0,
|
|
3712
|
+
text: thinking
|
|
3713
|
+
};
|
|
3714
|
+
continue;
|
|
3715
|
+
}
|
|
3716
|
+
const text = textQueue.shift();
|
|
3717
|
+
if (text !== void 0) {
|
|
3718
|
+
yield {
|
|
3719
|
+
type: "text-delta",
|
|
3720
|
+
index: 0,
|
|
3721
|
+
text
|
|
3722
|
+
};
|
|
3723
|
+
continue;
|
|
3724
|
+
}
|
|
3725
|
+
if (done) break;
|
|
3726
|
+
await Promise.race([turn, new Promise((resolve) => setTimeout(resolve, 20))]);
|
|
3727
|
+
}
|
|
3728
|
+
await turn;
|
|
3729
|
+
if (failure !== void 0) throw failure;
|
|
3730
|
+
for (const image of images) if (typeof image.url === "string" && image.url !== "") yield {
|
|
3731
|
+
type: "text-delta",
|
|
3732
|
+
index: 0,
|
|
3733
|
+
text: `\n\n\n`
|
|
3734
|
+
};
|
|
3735
|
+
}
|
|
3736
|
+
/** Everything the picker shows for one model. */
|
|
3737
|
+
describe(model) {
|
|
3738
|
+
const rate = rateOf(model.name);
|
|
3739
|
+
const free = rate !== void 0 && (/免费/u.test(rate) || /^x\s*0*\.?0+$/iu.test(rate));
|
|
3740
|
+
return {
|
|
3741
|
+
provider: DOUBAO_PROVIDER_ID,
|
|
3742
|
+
id: model.id,
|
|
3743
|
+
name: bareName(model.name),
|
|
3744
|
+
inputModalities: ["text", "image"],
|
|
3745
|
+
defaultMaxTokens: MAX_OUTPUT_TOKENS,
|
|
3746
|
+
context: { contextWindow: CONTEXT_WINDOW },
|
|
3747
|
+
reasoning: {
|
|
3748
|
+
efforts: [
|
|
3749
|
+
{
|
|
3750
|
+
id: ReasoningEffortId("low"),
|
|
3751
|
+
name: "低"
|
|
3752
|
+
},
|
|
3753
|
+
{
|
|
3754
|
+
id: ReasoningEffortId("mid"),
|
|
3755
|
+
name: "中"
|
|
3756
|
+
},
|
|
3757
|
+
{
|
|
3758
|
+
id: ReasoningEffortId("high"),
|
|
3759
|
+
name: "高"
|
|
3760
|
+
}
|
|
3761
|
+
],
|
|
3762
|
+
defaultEffort: ReasoningEffortId("mid")
|
|
3763
|
+
},
|
|
3764
|
+
...rate === void 0 ? {} : { tags: [{
|
|
3765
|
+
text: rate,
|
|
3766
|
+
tone: free ? "free" : "price"
|
|
3767
|
+
}] }
|
|
3768
|
+
};
|
|
3769
|
+
}
|
|
3770
|
+
};
|
|
3771
|
+
/** The readable text of the host's message list. */
|
|
3772
|
+
function promptOf(messages) {
|
|
3773
|
+
const parts = [];
|
|
3774
|
+
for (const message of messages) {
|
|
3775
|
+
if (typeof message !== "object" || message === null) continue;
|
|
3776
|
+
const content = message["content"];
|
|
3777
|
+
if (typeof content === "string") {
|
|
3778
|
+
if (content !== "") parts.push(content);
|
|
3779
|
+
continue;
|
|
3780
|
+
}
|
|
3781
|
+
if (!Array.isArray(content)) continue;
|
|
3782
|
+
const texts = [];
|
|
3783
|
+
for (const block of content) {
|
|
3784
|
+
if (typeof block === "string") {
|
|
3785
|
+
texts.push(block);
|
|
3786
|
+
continue;
|
|
3787
|
+
}
|
|
3788
|
+
if (typeof block !== "object" || block === null) continue;
|
|
3789
|
+
const text = block["text"];
|
|
3790
|
+
if (typeof text === "string") texts.push(text);
|
|
3791
|
+
}
|
|
3792
|
+
if (texts.length > 0) parts.push(texts.join("\n"));
|
|
3793
|
+
}
|
|
3794
|
+
return parts.join("\n\n");
|
|
3795
|
+
}
|
|
3796
|
+
//#endregion
|
|
3520
3797
|
//#region src/file-perms.ts
|
|
3521
3798
|
/**
|
|
3522
3799
|
* Write a file that holds credentials, without leaving it world-readable.
|
|
@@ -27627,6 +27904,7 @@ function apply(ctx, config = {}) {
|
|
|
27627
27904
|
let releaseAdapterGlobal;
|
|
27628
27905
|
let releaseAdapterAggregate;
|
|
27629
27906
|
let releaseAdapterFree;
|
|
27907
|
+
let releaseAdapterDoubao;
|
|
27630
27908
|
let releaseDirectory;
|
|
27631
27909
|
try {
|
|
27632
27910
|
/**
|
|
@@ -27657,6 +27935,14 @@ function apply(ctx, config = {}) {
|
|
|
27657
27935
|
releaseAdapterGlobal = detached;
|
|
27658
27936
|
releaseAdapterAggregate = ctx.llm.registerAdapter([XDPOOL_AGGREGATE_PROVIDER], adaptersByRegion.aggregate.adapter);
|
|
27659
27937
|
releaseAdapterFree = ctx.llm.registerAdapter([XDPOOL_FREE_PROVIDER], adaptersByRegion.free.adapter);
|
|
27938
|
+
/**
|
|
27939
|
+
* Doubao, registered the same way every other channel is.
|
|
27940
|
+
*
|
|
27941
|
+
* The lane over HTTP is not enough: the model PICKER reads the host's adapter
|
|
27942
|
+
* registry, so a signed-in Doubao account with ten models enabled appeared nowhere in
|
|
27943
|
+
* the list. This is the registration the pack performs for each of its own channels.
|
|
27944
|
+
*/
|
|
27945
|
+
releaseAdapterDoubao = ctx.llm.registerAdapter([DOUBAO_PROVIDER_ID], new DoubaoHostAdapter({ session: () => doubaoSession }));
|
|
27660
27946
|
} catch (error) {
|
|
27661
27947
|
ctx.logger.error("dsh-xdpool: adapter registration failed", error);
|
|
27662
27948
|
recordStartupNote(`adapters REJECTED: ${describeError(error)}`);
|
|
@@ -27664,6 +27950,7 @@ function apply(ctx, config = {}) {
|
|
|
27664
27950
|
releaseAdapterGlobal?.();
|
|
27665
27951
|
releaseAdapterAggregate?.();
|
|
27666
27952
|
releaseAdapterFree?.();
|
|
27953
|
+
releaseAdapterDoubao?.();
|
|
27667
27954
|
return;
|
|
27668
27955
|
}
|
|
27669
27956
|
try {
|
|
@@ -27734,6 +28021,7 @@ function apply(ctx, config = {}) {
|
|
|
27734
28021
|
releaseAdapterGlobal?.();
|
|
27735
28022
|
releaseAdapterAggregate?.();
|
|
27736
28023
|
releaseAdapterFree?.();
|
|
28024
|
+
releaseAdapterDoubao?.();
|
|
27737
28025
|
releaseDirectory?.();
|
|
27738
28026
|
};
|
|
27739
28027
|
try {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-xdpool",
|
|
3
3
|
"displayName": "DSH XD Pool",
|
|
4
4
|
"description": "One DSH model pool for every free quota you have: merge all locally signed-in WorkBuddy accounts with auto-failover, sign in to 13 vendors by QR/web, aggregate 76 vendors' free tiers, plus a usage dashboard, model routing, a local OpenAI-compatible gateway and a points-automation suite.",
|
|
5
|
-
"version": "2.7.
|
|
5
|
+
"version": "2.7.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "XDTrees",
|
|
8
8
|
"homepage": "https://github.com/XDTrees/dsh-xdpool#readme",
|