@omdp/dsh-key-fallback 1.0.4 → 1.0.5
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/lib/index.js +30 -45
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
// @omdp/dsh-key-fallback — Host half
|
|
1
|
+
// @omdp/dsh-key-fallback — Host half (ESM)
|
|
3
2
|
// 极简 API Key 回退:请求报错 → 静默换下一个 key 重试同一请求。
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try { return require('@deepseek-ai/dsh-settings') } catch { return null }
|
|
16
|
-
})()
|
|
17
|
-
const zs = (() => {
|
|
18
|
-
try { return require('@deepseek-ai/schemastery') } catch { return null }
|
|
19
|
-
})()
|
|
3
|
+
//
|
|
4
|
+
// 注意:必须 ESM + 静态 import(与 dshmarket / vision-bridge 一致)。
|
|
5
|
+
// DSH 的 bundle loader 对 CommonJS 的 require() 是受限的(先前实测
|
|
6
|
+
// dshSettings=false zs=false),只有 ESM import 能解析 DSH 内部包
|
|
7
|
+
// (@deepseek-ai/dsh-settings / @deepseek-ai/schemastery)。
|
|
8
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
9
|
+
import { homedir } from 'node:os'
|
|
10
|
+
import { join } from 'node:path'
|
|
11
|
+
import { load as loadYaml } from 'js-yaml'
|
|
12
|
+
import * as dshSettings from '@deepseek-ai/dsh-settings'
|
|
13
|
+
import * as zs from '@deepseek-ai/schemastery'
|
|
20
14
|
|
|
21
|
-
const name = 'key-fallback'
|
|
22
|
-
const inject = ['llm', 'settings', 'webServer']
|
|
15
|
+
export const name = 'key-fallback'
|
|
16
|
+
export const inject = ['llm', 'settings', 'webServer']
|
|
23
17
|
const API_BASE = '/dsh-key-fallback'
|
|
24
18
|
const SETTINGS_FILE = join(homedir(), '.dsh', 'settings.yaml')
|
|
25
19
|
// 与客户端 slots.register key 保持一致的命名空间名。
|
|
@@ -51,32 +45,25 @@ function readConfig() {
|
|
|
51
45
|
} catch (e) { return {} }
|
|
52
46
|
}
|
|
53
47
|
|
|
54
|
-
function apply(ctx) {
|
|
48
|
+
export function apply(ctx) {
|
|
55
49
|
// 注册 settings 命名空间(官方助手 installSettingsSection,与 dshmarket 同款):
|
|
56
50
|
// 让客户端 Settings → 插件的 keyed slot(settings.plugin.item, key='key-fallback')
|
|
57
51
|
// 被 serve 并渲染状态卡。状态卡只读;轮换逻辑仍直接读 settings.yaml(原设计)。
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.log('[key-fallback] settings namespace registered: ' + SETTINGS_NS)
|
|
74
|
-
} catch (e) {
|
|
75
|
-
console.log('[key-fallback] settings register FAILED: ' + (e && e.message ? e.message : e))
|
|
76
|
-
// 命名空间注册失败不影响核心轮换逻辑
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
console.log('[key-fallback] settings register SKIPPED (dshSettings=' + (!!dshSettings) + ' zs=' + (!!zs) + ')')
|
|
52
|
+
try {
|
|
53
|
+
const ns = dshSettings.settingsNamespace(SETTINGS_NS)
|
|
54
|
+
const schema = zs.object({
|
|
55
|
+
providers: zs.dict(zs.object({
|
|
56
|
+
env: zs.string(),
|
|
57
|
+
keys: zs.array(zs.string()),
|
|
58
|
+
cooldownMs: zs.natural(),
|
|
59
|
+
})),
|
|
60
|
+
})
|
|
61
|
+
dshSettings.installSettingsSection(ctx, ns, schema, {}, {
|
|
62
|
+
setSource: () => {},
|
|
63
|
+
onChange: () => {},
|
|
64
|
+
})
|
|
65
|
+
} catch (e) {
|
|
66
|
+
// 命名空间注册失败不影响核心轮换逻辑
|
|
80
67
|
}
|
|
81
68
|
|
|
82
69
|
const pools = new Map()
|
|
@@ -205,5 +192,3 @@ function apply(ctx) {
|
|
|
205
192
|
|
|
206
193
|
ctx.effect(() => () => { lifetime.abort() })
|
|
207
194
|
}
|
|
208
|
-
|
|
209
|
-
module.exports = { name, inject, apply }
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omdp/dsh-key-fallback",
|
|
3
3
|
"description": "Minimal API key fallback for DeepSeek Harness: on a retryable request error, silently retry the same call with the next key in the pool.",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"type": "
|
|
4
|
+
"version": "1.0.5",
|
|
5
|
+
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": { "default": "./lib/index.js" },
|