@mzzsfy/dsh-llm-pi-gateway 0.2.6 → 0.2.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mzzsfy/dsh-llm-pi-gateway",
3
3
  "description": "NewAPI 等 LLM 网关接入:跨协议会话粘性标记,提升网关侧 prompt 缓存命中,compat 全开放",
4
- "version": "0.2.6",
4
+ "version": "0.2.7",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "exports": {
@@ -37,6 +37,7 @@
37
37
  "@deepseek-ai/dsh-llm-pi-ai": ">=0.1.2-rc.1"
38
38
  },
39
39
  "devDependencies": {
40
+ "@deepseek-ai/cordis": "4.0.2",
40
41
  "@deepseek-ai/schemastery": "3.18.2",
41
42
  "@deepseek-ai/dsh-llm": "0.1.2-rc.1",
42
43
  "@deepseek-ai/dsh-settings": "0.1.2-rc.1",
package/src/index.js CHANGED
@@ -77,9 +77,17 @@ export function missingHostExports(dshLlm) {
77
77
  * 静态 import 命名导出缺失即加载崩溃,违反干净禁用规约)
78
78
  */
79
79
  export async function apply(ctx, config, importOfficial = () => import('@deepseek-ai/dsh-llm-pi-ai')) {
80
- // 宿主兼容探测:HOST_REQUIRED_EXPORTS 为 dsh 0.1.2 引入的 dsh-llm 导出,
81
- // 静态 import 命名导出缺失即加载崩溃,故动态探测;
82
- // 旧本体缺失时禁用插件,不注册 adapter 与 settings 节,boot 保持干净。
80
+ // 宿主兼容探测,两项独立:
81
+ // 1) settings 服务面:installSection 为 0.1.2-alpha.2+ 引入(与 peerDependencies
82
+ // 对齐);旧宿主缺失即禁用。此探测直接读运行宿主注入的服务对象,不受插件
83
+ // 解析链影响——import 解析链会命中 dev 工作副本仓库根的宿主包副本,与运行
84
+ // 宿主版本脱钩,不能作为旧宿主判据(rc.2 实测教训)。
85
+ // 2) dsh-llm 导出:HOST_REQUIRED_EXPORTS 为 dsh 0.1.2 引入,动态探测防静态
86
+ // import 命名导出缺失即加载崩溃;旧本体缺失时同样禁用,boot 保持干净。
87
+ if (typeof ctx.settings?.installSection !== 'function') {
88
+ ctx.logger.warn('llm-pi-gateway: 宿主 settings 服务缺少 installSection(需要 dsh 本体 0.1.2+),插件禁用')
89
+ return undefined
90
+ }
83
91
  const dshLlm = await import('@deepseek-ai/dsh-llm')
84
92
  const missing = missingHostExports(dshLlm)
85
93
  if (missing.length > 0) {
@@ -12,6 +12,15 @@ test('探测清单:宿主导出齐全返回空表', () => {
12
12
  assert.deepEqual(missingHostExports(realDshLlm), [])
13
13
  })
14
14
 
15
+ test('场景: 宿主 settings 服务面缺 installSection(rc.2 形态),apply 干净禁用不注册', async () => {
16
+ const { ctx, logs, llmCalls, installed } = makeCtx({ legacySettings: true })
17
+ await apply(ctx, undefined, OFFICIAL_MISSING)
18
+ assert.match(logs.warn.join('\n'), /settings 服务缺少 installSection/)
19
+ assert.deepEqual(installed, [], '禁用态不得安装任何 settings 节')
20
+ assert.deepEqual(llmCalls.adapters, [], '禁用态不得注册 adapter')
21
+ assert.deepEqual(llmCalls.discovery, [], '禁用态不得注册 discovery')
22
+ })
23
+
15
24
  test('探测清单:缺失任一必备导出即报告其名,双缺报告两名', () => {
16
25
  const partial = { ...realDshLlm, offloadedImageText: undefined }
17
26
  assert.deepEqual(missingHostExports(partial), ['offloadedImageText'])
@@ -22,7 +31,7 @@ test('探测清单:缺失任一必备导出即报告其名,双缺报告两名',
22
31
  // 假宿主:settings 安装记录可注入接管失败形态,llm 注册与 logger 全程 spy。
23
32
  const CONFLICT_MESSAGE_FORM = (ns) => `settings namespace "${ns}" is already registered`
24
33
 
25
- function makeCtx({ officialInstallFailure, officialDiscoveryPresent } = {}) {
34
+ function makeCtx({ officialInstallFailure, officialDiscoveryPresent, legacySettings = false } = {}) {
26
35
  const logs = { warn: [], error: [] }
27
36
  const installed = []
28
37
  const hooksByNs = {}
@@ -54,16 +63,18 @@ function makeCtx({ officialInstallFailure, officialDiscoveryPresent } = {}) {
54
63
  llmCalls.discovery.push(ns)
55
64
  },
56
65
  },
57
- settings: {
58
- installSection: (target, ns, schema, config, hooks) => {
59
- if (ns === OFFICIAL_SETTINGS_NS && officialInstallFailure !== undefined) {
60
- throw officialInstallFailure()
61
- }
62
- installed.push(ns)
63
- hooksByNs[ns] = hooks
64
- hooks.setSource(() => sectionValues[ns] ?? config)
65
- },
66
- },
66
+ settings: legacySettings
67
+ ? {}
68
+ : {
69
+ installSection: (target, ns, schema, config, hooks) => {
70
+ if (ns === OFFICIAL_SETTINGS_NS && officialInstallFailure !== undefined) {
71
+ throw officialInstallFailure()
72
+ }
73
+ installed.push(ns)
74
+ hooksByNs[ns] = hooks
75
+ hooks.setSource(() => sectionValues[ns] ?? config)
76
+ },
77
+ },
67
78
  }
68
79
  return { ctx, logs, installed, hooksByNs, llmCalls, sectionValues }
69
80
  }