dsh-sensenova-pool 0.1.2 → 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 +17 -0
- package/lib/index.js +163 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -201,6 +201,15 @@ records:
|
|
|
201
201
|
|
|
202
202
|
崩溃日志位置:Windows 下为 `%APPDATA%\@deepseek-ai\dsh-desktop\logs\crash-*-host.log`。
|
|
203
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
|
+
|
|
204
213
|
**Key 会泄漏吗?**
|
|
205
214
|
|
|
206
215
|
不会。界面只显示掩码;明文只存在 DSH 凭据库(`$DSH_HOME/.credentials.yaml`)中,不会写入任何配置文件,也不会出现在日志里。
|
|
@@ -257,6 +266,14 @@ Add `"dsh-sensenova-pool"` to `dsh.profile.bundles` in your profile `package.jso
|
|
|
257
266
|
|
|
258
267
|
Open **Plugins → dsh-sensenova-pool**, paste your keys, click **Add keys**, then pick any model under the "商汤日日新(Key 轮换池)" group in the model picker.
|
|
259
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
|
+
|
|
260
277
|
### Acknowledgements
|
|
261
278
|
|
|
262
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,7 +252,27 @@ 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');
|
|
@@ -320,6 +403,8 @@ export function apply(ctx, config) {
|
|
|
320
403
|
}
|
|
321
404
|
catch (error) {
|
|
322
405
|
logger.error(`回环端点启动失败:${error instanceof Error ? error.message : String(error)}`);
|
|
406
|
+
// 监听失败时 server 可能已部分启动;显式关闭,避免留下半开的句柄。
|
|
407
|
+
await shim.close().catch(() => { });
|
|
323
408
|
return;
|
|
324
409
|
}
|
|
325
410
|
// ---- 端口就绪,此时才能安全构建模型描述符并注册 provider ----------------
|
|
@@ -327,29 +412,97 @@ export function apply(ctx, config) {
|
|
|
327
412
|
adapter = createAdapter();
|
|
328
413
|
registration = ctx.llm.registerAdapter([PROVIDER_ID], adapter);
|
|
329
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。
|
|
330
419
|
try {
|
|
331
420
|
registration?.();
|
|
332
421
|
}
|
|
333
422
|
finally {
|
|
334
|
-
|
|
423
|
+
return shim.close();
|
|
335
424
|
}
|
|
336
425
|
});
|
|
337
426
|
logger.info(`已注册 provider "${PROVIDER_ID}",模型分组「${PROVIDER_NAME}」`);
|
|
338
427
|
}
|
|
339
428
|
catch (error) {
|
|
340
429
|
logger.error(`注册 provider 失败:${error instanceof Error ? error.message : String(error)}`);
|
|
341
|
-
|
|
430
|
+
await shim.close();
|
|
342
431
|
return;
|
|
343
432
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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();
|
|
348
470
|
}
|
|
349
|
-
|
|
471
|
+
// 宿主没有凭据服务时,上面的回调永不触发 —— 仍需给出可操作的提示(与旧行为一致)。
|
|
472
|
+
// 但如果服务**已注册、只是在加载**(冷启动的竞态场景),就绝不能在这里报
|
|
473
|
+
// 「池为空」:那是还没读到,不是真的没有 key。此时静默等待即可。
|
|
474
|
+
await delay(0);
|
|
475
|
+
if (credentialsService() === undefined && !credentialsRegistered()) {
|
|
350
476
|
logger.info('key 池为空 —— 请在「设置 → 插件 → 商汤日日新(Key 轮换池)」里填入 key');
|
|
351
477
|
}
|
|
352
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
|
+
}
|
|
353
506
|
/**
|
|
354
507
|
* 用池里的 key 拉取真实模型目录。
|
|
355
508
|
*
|
|
@@ -433,7 +586,9 @@ export function apply(ctx, config) {
|
|
|
433
586
|
void fetchCatalogFromUpstream();
|
|
434
587
|
},
|
|
435
588
|
reload: async () => {
|
|
436
|
-
|
|
589
|
+
// 手动重载:走同一套「装载并宣告」逻辑,因此在启动早期点它也不会把
|
|
590
|
+
// 「还没读到」误当成「真的没有 key」而清空权威装载信号。
|
|
591
|
+
await loadKeysAndNotify();
|
|
437
592
|
refreshCatalog();
|
|
438
593
|
},
|
|
439
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",
|