@omdp/dsh-key-fallback 1.0.2 → 1.0.4
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/client.js +17 -8
- package/lib/index.js +28 -16
- package/package.json +2 -1
package/lib/client.js
CHANGED
|
@@ -122,15 +122,24 @@ window.__ModuleLoader__.load({
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
function apply(ctx) {
|
|
125
|
-
var slots = ctx.get('slots')
|
|
126
|
-
if (slots === undefined) return
|
|
127
125
|
// settings.plugin.item 是 root-scope 的 keyed slot,按 settings 命名空间
|
|
128
|
-
// 分发:host 端
|
|
129
|
-
// served
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
// 分发:host 端 installSettingsSection 注册 key-fallback 命名空间,使它
|
|
127
|
+
// 进入 served 集合后,本卡片才会被 ConfigurablePluginsTab 渲染。
|
|
128
|
+
// 参考 dshmarket:注册通过嵌套 settingsScope inject(保持模块级无
|
|
129
|
+
// settingsScope 硬依赖——旧宿主没有该服务时不至于拖垮整个插件)。
|
|
130
|
+
var scopedInject = ctx.inject
|
|
131
|
+
if (typeof scopedInject === 'function') {
|
|
132
|
+
scopedInject(['settingsScope'], function (scoped) {
|
|
133
|
+
var scopedSlots = scoped.slots
|
|
134
|
+
if (!scopedSlots) return
|
|
135
|
+
scopedSlots.inject('settings.plugin.item', function () {
|
|
136
|
+
return scopedSlots.register({
|
|
137
|
+
name: 'settings.plugin.item',
|
|
138
|
+
key: 'key-fallback',
|
|
139
|
+
}, KeyFallbackCard)
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
}
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
exports.apply = apply
|
package/lib/index.js
CHANGED
|
@@ -8,8 +8,12 @@ const { load: loadYaml } = (() => {
|
|
|
8
8
|
try { return require('js-yaml') }
|
|
9
9
|
catch { return { load: (s) => { try { return JSON.parse(s) } catch { return {} } } } }
|
|
10
10
|
})()
|
|
11
|
-
//
|
|
12
|
-
//
|
|
11
|
+
// dsh-settings 官方助手:installSettingsSection 挂在 scoped fiber 上,注册命名空间
|
|
12
|
+
// 后 client 的 settings.plugin.item 键槽才能把它 serve 并渲染状态卡。
|
|
13
|
+
// 参考 dshmarket(同款姿势,实证可显示)。schemastery 用于构造命名空间 schema。
|
|
14
|
+
const dshSettings = (() => {
|
|
15
|
+
try { return require('@deepseek-ai/dsh-settings') } catch { return null }
|
|
16
|
+
})()
|
|
13
17
|
const zs = (() => {
|
|
14
18
|
try { return require('@deepseek-ai/schemastery') } catch { return null }
|
|
15
19
|
})()
|
|
@@ -18,6 +22,8 @@ const name = 'key-fallback'
|
|
|
18
22
|
const inject = ['llm', 'settings', 'webServer']
|
|
19
23
|
const API_BASE = '/dsh-key-fallback'
|
|
20
24
|
const SETTINGS_FILE = join(homedir(), '.dsh', 'settings.yaml')
|
|
25
|
+
// 与客户端 slots.register key 保持一致的命名空间名。
|
|
26
|
+
const SETTINGS_NS = 'key-fallback'
|
|
21
27
|
|
|
22
28
|
function mask(key) {
|
|
23
29
|
if (!key) return ''
|
|
@@ -46,25 +52,31 @@ function readConfig() {
|
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
function apply(ctx) {
|
|
49
|
-
// 注册 settings
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
if (zs) {
|
|
55
|
+
// 注册 settings 命名空间(官方助手 installSettingsSection,与 dshmarket 同款):
|
|
56
|
+
// 让客户端 Settings → 插件的 keyed slot(settings.plugin.item, key='key-fallback')
|
|
57
|
+
// 被 serve 并渲染状态卡。状态卡只读;轮换逻辑仍直接读 settings.yaml(原设计)。
|
|
58
|
+
// 诊断日志:确认注册链路是否真的执行(dsh-err.log 可查)。
|
|
59
|
+
if (dshSettings && zs) {
|
|
55
60
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const ns = dshSettings.settingsNamespace(SETTINGS_NS)
|
|
62
|
+
const schema = zs.object({
|
|
63
|
+
providers: zs.dict(zs.object({
|
|
64
|
+
env: zs.string(),
|
|
65
|
+
keys: zs.array(zs.string()),
|
|
66
|
+
cooldownMs: zs.natural(),
|
|
67
|
+
})),
|
|
68
|
+
})
|
|
69
|
+
dshSettings.installSettingsSection(ctx, ns, schema, {}, {
|
|
70
|
+
setSource: () => {},
|
|
71
|
+
onChange: () => {},
|
|
64
72
|
})
|
|
73
|
+
console.log('[key-fallback] settings namespace registered: ' + SETTINGS_NS)
|
|
65
74
|
} catch (e) {
|
|
75
|
+
console.log('[key-fallback] settings register FAILED: ' + (e && e.message ? e.message : e))
|
|
66
76
|
// 命名空间注册失败不影响核心轮换逻辑
|
|
67
77
|
}
|
|
78
|
+
} else {
|
|
79
|
+
console.log('[key-fallback] settings register SKIPPED (dshSettings=' + (!!dshSettings) + ' zs=' + (!!zs) + ')')
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
const pools = new Map()
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
34
34
|
"@deepseek-ai/dsh-llm": "^0.1.0-rc.6",
|
|
35
|
+
"@deepseek-ai/dsh-settings": "^0.1.0-rc.7 || ^0.1.1-rc.2",
|
|
35
36
|
"@deepseek-ai/schemastery": "^3.18.1"
|
|
36
37
|
}
|
|
37
38
|
}
|