@omdp/dsh-key-fallback 1.0.2 → 1.0.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/lib/client.js +17 -8
- package/lib/index.js +23 -16
- package/package.json +1 -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,21 +52,22 @@ function readConfig() {
|
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
function apply(ctx) {
|
|
49
|
-
// 注册 settings
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
// 注册实际从未发生;这里用真实 require 修复。
|
|
54
|
-
if (zs) {
|
|
55
|
+
// 注册 settings 命名空间(官方助手 installSettingsSection,与 dshmarket 同款):
|
|
56
|
+
// 让客户端 Settings → 插件的 keyed slot(settings.plugin.item, key='key-fallback')
|
|
57
|
+
// 被 serve 并渲染状态卡。状态卡只读;轮换逻辑仍直接读 settings.yaml(原设计)。
|
|
58
|
+
if (dshSettings && zs) {
|
|
55
59
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const ns = dshSettings.settingsNamespace(SETTINGS_NS)
|
|
61
|
+
const schema = zs.object({
|
|
62
|
+
providers: zs.dict(zs.object({
|
|
63
|
+
env: zs.string(),
|
|
64
|
+
keys: zs.array(zs.string()),
|
|
65
|
+
cooldownMs: zs.natural(),
|
|
66
|
+
})),
|
|
67
|
+
})
|
|
68
|
+
dshSettings.installSettingsSection(ctx, ns, schema, {}, {
|
|
69
|
+
setSource: () => {},
|
|
70
|
+
onChange: () => {},
|
|
64
71
|
})
|
|
65
72
|
} catch (e) {
|
|
66
73
|
// 命名空间注册失败不影响核心轮换逻辑
|
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.3",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|