@omdp/dsh-key-fallback 1.0.3 → 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.
Files changed (2) hide show
  1. package/lib/index.js +30 -40
  2. package/package.json +3 -2
package/lib/index.js CHANGED
@@ -1,25 +1,19 @@
1
- 'use strict'
2
- // @omdp/dsh-key-fallback — Host half
1
+ // @omdp/dsh-key-fallback — Host half (ESM)
3
2
  // 极简 API Key 回退:请求报错 → 静默换下一个 key 重试同一请求。
4
- const { readFileSync, existsSync } = require('node:fs')
5
- const { homedir } = require('node:os')
6
- const { join } = require('node:path')
7
- const { load: loadYaml } = (() => {
8
- try { return require('js-yaml') }
9
- catch { return { load: (s) => { try { return JSON.parse(s) } catch { return {} } } } }
10
- })()
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
- })()
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,27 +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
- if (dshSettings && zs) {
59
- try {
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: () => {},
71
- })
72
- } catch (e) {
73
- // 命名空间注册失败不影响核心轮换逻辑
74
- }
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
+ // 命名空间注册失败不影响核心轮换逻辑
75
67
  }
76
68
 
77
69
  const pools = new Map()
@@ -200,5 +192,3 @@ function apply(ctx) {
200
192
 
201
193
  ctx.effect(() => () => { lifetime.abort() })
202
194
  }
203
-
204
- 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.3",
5
- "type": "commonjs",
4
+ "version": "1.0.5",
5
+ "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
8
8
  ".": { "default": "./lib/index.js" },
@@ -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
  }