dsh-sensenova-pool 0.1.1 → 0.1.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/README.md +39 -0
- package/lib/index.js +178 -9
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -179,6 +179,37 @@ sk-cccccccccccccccccccccccccccccc
|
|
|
179
179
|
|
|
180
180
|
在卡片上点某把 Key 的「测试」看真实原因。`403 model is not available in the current token plan` 表示该模型不在这个 Key 的套餐里 —— 换模型,而不是换 Key。
|
|
181
181
|
|
|
182
|
+
**DSH 弹「The application could not start or stopped unexpectedly」,完全起不来?**
|
|
183
|
+
|
|
184
|
+
先看崩溃日志里的失败插件名。如果 `Failed plugins` 指向 `credentials`,且错误是
|
|
185
|
+
`record "dsh-sensenova-pool/keys" ... has unknown field "payload"`,说明凭据库里那条记录
|
|
186
|
+
的标签写错了 —— DSH 的凭据库对记录做白名单校验,`api-key` 只认 `kind`/`key`/`env`,
|
|
187
|
+
`grant` 只认 `kind`/`payload`,**一条记录不合规就会让 `credentials` 插件激活失败,进而
|
|
188
|
+
中止整个应用启动**(0.1.1 及更早版本存在这个写入 bug,已修复)。
|
|
189
|
+
|
|
190
|
+
手工修复:编辑 `$DSH_HOME/.credentials.yaml`,把该记录的 `kind: api-key` 改成
|
|
191
|
+
`kind: grant`(`payload.keys` 里的 Key 原样保留),然后重启 DSH。
|
|
192
|
+
|
|
193
|
+
```yaml
|
|
194
|
+
records:
|
|
195
|
+
dsh-sensenova-pool/keys:
|
|
196
|
+
kind: grant # ← 必须是 grant;api-key 不接受 payload
|
|
197
|
+
payload:
|
|
198
|
+
keys:
|
|
199
|
+
- sk-…
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
崩溃日志位置:Windows 下为 `%APPDATA%\@deepseek-ai\dsh-desktop\logs\crash-*-host.log`。
|
|
203
|
+
|
|
204
|
+
**重启电脑后 Key 池空了(「忘记 Key」)?**
|
|
205
|
+
|
|
206
|
+
0.1.2 及更早版本存在一个**启动竞态**:插件启动时只读一次凭据库,而 DSH 的凭据快照
|
|
207
|
+
是异步读盘填充的,冷启动磁盘慢时就会读到空快照,于是池子变成 0 把 —— 且此后没有任何
|
|
208
|
+
补载机制,只能重新填 Key。**0.1.3 已修复**(改为等凭据服务真正就绪后再装载)。
|
|
209
|
+
|
|
210
|
+
如果你还在旧版本上遇到,升级即可,不需要重新填 Key(Key 一直好好地在
|
|
211
|
+
`$DSH_HOME/.credentials.yaml` 里)。临时办法是在插件卡片上点一次「刷新/重载」。
|
|
212
|
+
|
|
182
213
|
**Key 会泄漏吗?**
|
|
183
214
|
|
|
184
215
|
不会。界面只显示掩码;明文只存在 DSH 凭据库(`$DSH_HOME/.credentials.yaml`)中,不会写入任何配置文件,也不会出现在日志里。
|
|
@@ -235,6 +266,14 @@ Add `"dsh-sensenova-pool"` to `dsh.profile.bundles` in your profile `package.jso
|
|
|
235
266
|
|
|
236
267
|
Open **Plugins → dsh-sensenova-pool**, paste your keys, click **Add keys**, then pick any model under the "商汤日日新(Key 轮换池)" group in the model picker.
|
|
237
268
|
|
|
269
|
+
### Troubleshooting
|
|
270
|
+
|
|
271
|
+
**The key pool is empty after rebooting the machine ("it forgot my keys")?**
|
|
272
|
+
|
|
273
|
+
Versions 0.1.2 and earlier had a startup race: the plugin read the credential store once at startup, while DSH fills that store from disk asynchronously. On a slow cold boot the plugin read an empty snapshot, so the pool came up with zero keys — and nothing ever re-loaded it, forcing you to re-enter them. **Fixed in 0.1.3** (the plugin now waits until the credentials service is genuinely ready before loading).
|
|
274
|
+
|
|
275
|
+
Upgrade and your keys will be picked up again; they were never lost (they live in `$DSH_HOME/.credentials.yaml`). On an older version, clicking reload on the plugin card recovers them for the session.
|
|
276
|
+
|
|
238
277
|
### Acknowledgements
|
|
239
278
|
|
|
240
279
|
- [corrinehu/dsh-workbuddy-connect](https://github.com/corrinehu/dsh-workbuddy-connect) — the plugin pattern for bringing third-party models into DSH
|
package/lib/index.js
CHANGED
|
@@ -162,9 +162,72 @@ export function apply(ctx, config) {
|
|
|
162
162
|
*/
|
|
163
163
|
const RECORD_SCOPE = 'dsh-sensenova-pool';
|
|
164
164
|
const RECORD_ID = `${RECORD_SCOPE}/keys`;
|
|
165
|
+
/**
|
|
166
|
+
* 写入前等待首次权威装载的上限(毫秒)。
|
|
167
|
+
*
|
|
168
|
+
* 只作为兜底:正常路径下 `firstAuthoritativeLoad` 会在凭据服务就绪的那一刻兑现。
|
|
169
|
+
* 设上限是为了「宿主没有凭据服务」时不要永远挂住写入请求。
|
|
170
|
+
*/
|
|
171
|
+
const SAVE_LOAD_WAIT_MS = 10_000;
|
|
172
|
+
/** 严格读取:只返回**已就绪**(fiber ACTIVE)的凭据服务。 */
|
|
165
173
|
function credentialsService() {
|
|
166
174
|
return ctx.get?.('credentials');
|
|
167
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* 宽松读取:服务**已注册但可能仍在加载**时也能拿到实例。
|
|
178
|
+
*
|
|
179
|
+
* 用来区分两种「读不到凭据」:服务正在加载(应继续等),还是宿主压根没有这个
|
|
180
|
+
* 服务(应直接提示用户填 key)。
|
|
181
|
+
*/
|
|
182
|
+
function credentialsRegistered() {
|
|
183
|
+
try {
|
|
184
|
+
return ctx.get?.('credentials', false) !== undefined;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 「首次**权威**装载」完成信号。
|
|
192
|
+
*
|
|
193
|
+
* 权威 = 凭据服务**真正就绪**(fiber 已 ACTIVE、`.credentials.yaml` 已解析进内存
|
|
194
|
+
* 快照),而不是「服务对象已构造」。这两者的区别正是 issue #1:
|
|
195
|
+
*
|
|
196
|
+
* 1. **已构造** —— `Service` 在构造函数里就 `provide()`,服务已能被解析到,但
|
|
197
|
+
* 所属 fiber 还停在 PENDING/LOADING,`Service.init` 尚未跑完;
|
|
198
|
+
* 2. **已就绪** —— `Service.init` 已结束,credentials-local 的 `loadInitial()`
|
|
199
|
+
* 已把 `.credentials.yaml` 填进内存快照。
|
|
200
|
+
*
|
|
201
|
+
* 本插件只 `inject: ['llm']`,与 credentials 之间**没有顺序保证**。冷启动磁盘 IO
|
|
202
|
+
* 慢时 `loadKeys()` 会先于 `loadInitial()` 执行,`readRecord()` 读到空快照 → key
|
|
203
|
+
* 池为 0,且此后没有任何补载机制(`credentials/record-updated` 只在运行期写入时
|
|
204
|
+
* 触发,覆盖不到启动装载)—— 这就是「重启电脑后 Key 池为空」。
|
|
205
|
+
*
|
|
206
|
+
* 修复方式不是「轮询 + 超时」,而是用 cordis 自己的就绪通知:`ctx.inject` 的回调
|
|
207
|
+
* **只在服务所属 fiber 变为 ACTIVE 时才触发**(已用真实 cordis 验证)。它精确、
|
|
208
|
+
* 零延迟,也不会给「宿主根本没有凭据服务」的环境白等一段超时 —— 那种情况下回调
|
|
209
|
+
* 只是不触发,启动路径照常给出「请填入 key」的提示。
|
|
210
|
+
*
|
|
211
|
+
* 之所以要等它再允许写入:`saveKeys()` 是用 `pool.keys()` **整体覆盖**记录。若在
|
|
212
|
+
* 权威装载之前写入(启动还没完,用户就点了「添加 Key」),池子里只有刚加的那把,
|
|
213
|
+
* 磁盘上原有的 key 会被静默抹掉。
|
|
214
|
+
*/
|
|
215
|
+
let notifyKeysLoaded;
|
|
216
|
+
const firstAuthoritativeLoad = new Promise((resolve) => {
|
|
217
|
+
notifyKeysLoaded = resolve;
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* 装载 key,并在**凭据快照确实可读**时宣告首次权威装载完成。
|
|
221
|
+
*
|
|
222
|
+
* 只有凭据服务可见时才宣告:否则「池子为空」只代表「还没读到」,不代表「真的没有
|
|
223
|
+
* key」,提前宣告会让 `saveKeys()` 把空池覆盖写回记录。
|
|
224
|
+
*/
|
|
225
|
+
async function loadKeysAndNotify() {
|
|
226
|
+
const added = await loadKeys();
|
|
227
|
+
if (credentialsService() !== undefined)
|
|
228
|
+
notifyKeysLoaded?.();
|
|
229
|
+
return added;
|
|
230
|
+
}
|
|
168
231
|
async function loadKeys() {
|
|
169
232
|
const credentials = credentialsService();
|
|
170
233
|
if (credentials === undefined) {
|
|
@@ -189,13 +252,47 @@ export function apply(ctx, config) {
|
|
|
189
252
|
logger.info(`已装载 ${added} 把 key`);
|
|
190
253
|
return added;
|
|
191
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* 可被进程退出的定时器(`unref`)。
|
|
257
|
+
*
|
|
258
|
+
* 为什么不用裸 `setTimeout`:这里只拿它当「兜底超时」,正常路径下由 Promise 先行
|
|
259
|
+
* 兑现。裸定时器会一直挂在事件循环上,让 DSH 退出时多等一段、也让测试无谓变慢。
|
|
260
|
+
*/
|
|
261
|
+
function delay(ms) {
|
|
262
|
+
return new Promise((resolve) => {
|
|
263
|
+
const timer = setTimeout(resolve, ms);
|
|
264
|
+
timer?.unref?.();
|
|
265
|
+
});
|
|
266
|
+
}
|
|
192
267
|
async function saveKeys() {
|
|
268
|
+
// 写入前必须确保首次**权威**装载已完成:saveKeys 是整体覆盖写,若此时池子还是
|
|
269
|
+
// 空的(快照尚未读到),磁盘上原有的 key 会被这次写入静默抹掉。
|
|
270
|
+
//
|
|
271
|
+
// 只在凭据服务**确实存在**时才等:宿主压根没有该服务时,等它没有意义,直接让
|
|
272
|
+
// 下面给出明确错误,而不是让用户对着转圈的按钮等满超时。
|
|
273
|
+
if (credentialsRegistered()) {
|
|
274
|
+
await Promise.race([firstAuthoritativeLoad, delay(SAVE_LOAD_WAIT_MS)]);
|
|
275
|
+
}
|
|
193
276
|
const credentials = credentialsService();
|
|
194
277
|
if (credentials === undefined)
|
|
195
278
|
throw new Error('凭据服务不可用,无法保存 key');
|
|
196
279
|
const keys = pool.keys();
|
|
280
|
+
// 必须用 `grant`,不能用 `api-key`。
|
|
281
|
+
//
|
|
282
|
+
// credentials-local 对记录做白名单校验(`assertFields`),两种标签允许的字段
|
|
283
|
+
// 是互斥的:`api-key` 只认 `kind` / `key` / `env`,`grant` 只认 `kind` /
|
|
284
|
+
// `payload`。而 `api-key` 的 `key` 是**单值**字符串,根本表达不了 key 池,
|
|
285
|
+
// 所以池子只能落在 `grant` 的 `payload` 里(存储对 grant payload 逐字保留,
|
|
286
|
+
// 不做解释)。
|
|
287
|
+
//
|
|
288
|
+
// 踩过的坑:这里原先写的是 `kind: 'api-key'` + `payload`。写入路径的
|
|
289
|
+
// `assertStorableApiKey` 只校验 `key` 是否为空和 `env` 值,**不查未知字段**,
|
|
290
|
+
// 于是坏记录顺利落盘;下次启动时 credentials-local 在 loadInitial 阶段
|
|
291
|
+
// 解析失败 → credentials 插件激活失败 → 整个 dsh 启动中止(弹「could not
|
|
292
|
+
// start or stopped unexpectedly」)。一条记录写错就能锁死整个应用,所以这里
|
|
293
|
+
// 的标签必须与 schema 严格对齐。
|
|
197
294
|
await credentials.modifyRecord(RECORD_ID, async () => ({
|
|
198
|
-
kind: '
|
|
295
|
+
kind: 'grant',
|
|
199
296
|
payload: { keys },
|
|
200
297
|
}));
|
|
201
298
|
}
|
|
@@ -306,6 +403,8 @@ export function apply(ctx, config) {
|
|
|
306
403
|
}
|
|
307
404
|
catch (error) {
|
|
308
405
|
logger.error(`回环端点启动失败:${error instanceof Error ? error.message : String(error)}`);
|
|
406
|
+
// 监听失败时 server 可能已部分启动;显式关闭,避免留下半开的句柄。
|
|
407
|
+
await shim.close().catch(() => { });
|
|
309
408
|
return;
|
|
310
409
|
}
|
|
311
410
|
// ---- 端口就绪,此时才能安全构建模型描述符并注册 provider ----------------
|
|
@@ -313,29 +412,97 @@ export function apply(ctx, config) {
|
|
|
313
412
|
adapter = createAdapter();
|
|
314
413
|
registration = ctx.llm.registerAdapter([PROVIDER_ID], adapter);
|
|
315
414
|
ctx.effect?.(() => () => {
|
|
415
|
+
// 必须**返回** close() 的 Promise:cordis 的 disposer 可以是异步的,返回它
|
|
416
|
+
// 才会等回环服务真正关闭。原先写成 `void shim.close()`,卸载时 Promise 无人
|
|
417
|
+
// 等待,server 仍在监听的状态下进程就可能退出 —— 在 Windows 上表现为 libuv
|
|
418
|
+
// 断言(async.c: !(handle->flags & UV_HANDLE_CLOSING)),退出码 0xC0000409。
|
|
316
419
|
try {
|
|
317
420
|
registration?.();
|
|
318
421
|
}
|
|
319
422
|
finally {
|
|
320
|
-
|
|
423
|
+
return shim.close();
|
|
321
424
|
}
|
|
322
425
|
});
|
|
323
426
|
logger.info(`已注册 provider "${PROVIDER_ID}",模型分组「${PROVIDER_NAME}」`);
|
|
324
427
|
}
|
|
325
428
|
catch (error) {
|
|
326
429
|
logger.error(`注册 provider 失败:${error instanceof Error ? error.message : String(error)}`);
|
|
327
|
-
|
|
430
|
+
await shim.close();
|
|
328
431
|
return;
|
|
329
432
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
433
|
+
// ---- 装载 key(issue #1:等凭据快照真正就绪) --------------------------
|
|
434
|
+
//
|
|
435
|
+
// 这里不再「立刻读一次就算」,而是等凭据服务就绪的通知:`ctx.inject` 的回调
|
|
436
|
+
// 只在 credentials 所属 fiber 变为 ACTIVE(`loadInitial()` 已填充快照)时触发。
|
|
437
|
+
// 冷启动磁盘 IO 慢时,正是这一等把「读到空快照」变成了「读到真实的 key 列表」。
|
|
438
|
+
//
|
|
439
|
+
// 回调可能因服务重注册而多次触发;`pool.addKey()` 幂等,重复装载安全。
|
|
440
|
+
const onCredentialsReady = () => {
|
|
441
|
+
void loadKeysAndNotify()
|
|
442
|
+
.then((added) => {
|
|
443
|
+
if (added > 0) {
|
|
444
|
+
refreshCatalog();
|
|
445
|
+
void fetchCatalogFromUpstream();
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
logger.info('key 池为空 —— 请在「设置 → 插件 → 商汤日日新(Key 轮换池)」里填入 key');
|
|
449
|
+
}
|
|
450
|
+
})
|
|
451
|
+
.catch((error) => {
|
|
452
|
+
logger.warn(`装载 key 失败:${error instanceof Error ? error.message : String(error)}`);
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
if (typeof ctx.inject === 'function') {
|
|
456
|
+
try {
|
|
457
|
+
ctx.inject(['credentials'], onCredentialsReady);
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
// 注入注册失败(例如 ctx 形状不符):退化为「服务已就绪就直接装载一次」,
|
|
461
|
+
// 至少不比旧行为更差。
|
|
462
|
+
logger.warn(`等待凭据服务就绪失败,改为立即尝试装载:${error instanceof Error ? error.message : String(error)}`);
|
|
463
|
+
if (credentialsService() !== undefined)
|
|
464
|
+
onCredentialsReady();
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else if (credentialsService() !== undefined) {
|
|
468
|
+
// 极老的宿主没有 ctx.inject:退化为直接装载一次(此时服务已就绪)。
|
|
469
|
+
onCredentialsReady();
|
|
334
470
|
}
|
|
335
|
-
|
|
471
|
+
// 宿主没有凭据服务时,上面的回调永不触发 —— 仍需给出可操作的提示(与旧行为一致)。
|
|
472
|
+
// 但如果服务**已注册、只是在加载**(冷启动的竞态场景),就绝不能在这里报
|
|
473
|
+
// 「池为空」:那是还没读到,不是真的没有 key。此时静默等待即可。
|
|
474
|
+
await delay(0);
|
|
475
|
+
if (credentialsService() === undefined && !credentialsRegistered()) {
|
|
336
476
|
logger.info('key 池为空 —— 请在「设置 → 插件 → 商汤日日新(Key 轮换池)」里填入 key');
|
|
337
477
|
}
|
|
338
478
|
})();
|
|
479
|
+
/**
|
|
480
|
+
* 兜底补载:凭据记录被**本进程之外**改动时(手工编辑 `.credentials.yaml`、
|
|
481
|
+
* 另一次 boot 迁移了文档布局),credentials-local 的 watcher 会 emit
|
|
482
|
+
* `credentials/record-updated`。这里据此重载,使池子最终一致。
|
|
483
|
+
*
|
|
484
|
+
* 注意这不是启动竞态的修复手段 —— 那条路径由 `ctx.inject(['credentials'])` 负责,
|
|
485
|
+
* 因为启动装载**早于**任何事件发生,等事件是等不到的。这里只覆盖运行期变更。
|
|
486
|
+
*/
|
|
487
|
+
try {
|
|
488
|
+
ctx.on?.('credentials/record-updated', (key) => {
|
|
489
|
+
if (key !== RECORD_ID)
|
|
490
|
+
return;
|
|
491
|
+
void loadKeysAndNotify()
|
|
492
|
+
.then((added) => {
|
|
493
|
+
if (added > 0) {
|
|
494
|
+
refreshCatalog();
|
|
495
|
+
void fetchCatalogFromUpstream();
|
|
496
|
+
}
|
|
497
|
+
})
|
|
498
|
+
.catch((error) => {
|
|
499
|
+
logger.warn(`记录变更后重载失败:${error instanceof Error ? error.message : String(error)}`);
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
// 事件总线形状不符:不影响主路径。
|
|
505
|
+
}
|
|
339
506
|
/**
|
|
340
507
|
* 用池里的 key 拉取真实模型目录。
|
|
341
508
|
*
|
|
@@ -419,7 +586,9 @@ export function apply(ctx, config) {
|
|
|
419
586
|
void fetchCatalogFromUpstream();
|
|
420
587
|
},
|
|
421
588
|
reload: async () => {
|
|
422
|
-
|
|
589
|
+
// 手动重载:走同一套「装载并宣告」逻辑,因此在启动早期点它也不会把
|
|
590
|
+
// 「还没读到」误当成「真的没有 key」而清空权威装载信号。
|
|
591
|
+
await loadKeysAndNotify();
|
|
423
592
|
refreshCatalog();
|
|
424
593
|
},
|
|
425
594
|
fetchCatalog: fetchCatalogFromUpstream,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-sensenova-pool",
|
|
3
3
|
"displayName": "DSH SenseNova Key Pool",
|
|
4
4
|
"description": "商汤日日新(SenseNova)多 Key 轮换池 — 填入多把 Key 即可零配置接入 DeepSeek Harness,遇 429 限流自动切换下一把 Key。",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.3",
|
|
6
6
|
"author": "Phoeky",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"dsh-plugin",
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@deepseek-ai/cordis": "^4.0.4",
|
|
69
|
-
"@deepseek-ai/
|
|
70
|
-
"@deepseek-ai/dsh-llm
|
|
71
|
-
"@deepseek-ai/
|
|
72
|
-
"@earendil-works/pi-ai": "^0.87.1"
|
|
68
|
+
"@deepseek-ai/cordis": "^4.0.4 || >=4.0.4-0 <5.0.0-0",
|
|
69
|
+
"@deepseek-ai/schemastery": "~3.18.4 || >=3.18.4-0 <3.19.0-0",
|
|
70
|
+
"@deepseek-ai/dsh-llm": "0.2.0-rc.2 || >=0.2.0-rc.2 <0.3.0-0",
|
|
71
|
+
"@deepseek-ai/dsh-llm-pi-ai": "0.2.0-rc.2 || >=0.2.0-rc.2 <0.3.0-0",
|
|
72
|
+
"@earendil-works/pi-ai": "^0.87.1 || >=0.87.1-0 <0.88.0-0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/node": "22.19.19",
|