@mofeng2223/dsh-claude-provider 0.4.6 → 0.5.0

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": "@mofeng2223/dsh-claude-provider",
3
- "version": "0.4.6",
4
- "description": "Custom Claude provider support for DeepSeek Harness 0.1.6-alpha.2",
3
+ "version": "0.5.0",
4
+ "description": "Custom Claude provider support for DeepSeek Harness 0.1.7-alpha.2",
5
5
  "author": "mofeng2223",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -24,7 +24,8 @@
24
24
  },
25
25
  "type": "module",
26
26
  "dependencies": {
27
- "@deepseek-ai/schemastery": "^3.18.2"
27
+ "@deepseek-ai/schemastery": "3.18.4",
28
+ "js-yaml": "^4.3.2"
28
29
  },
29
30
  "exports": {
30
31
  ".": "./src/index.js",
@@ -37,7 +38,8 @@
37
38
  "cordis.patch.yml",
38
39
  "README.md",
39
40
  "README.zh-CN.md",
40
- "LICENSE"
41
+ "LICENSE",
42
+ "scripts/migrate-legacy-types.mjs"
41
43
  ],
42
44
  "scripts": {
43
45
  "build": "node scripts/build-client.mjs",
@@ -60,6 +62,6 @@
60
62
  }
61
63
  },
62
64
  "devDependencies": {
63
- "@deepseek-ai/dsh-client-ui-settings-models": "0.1.6-alpha.2"
65
+ "@deepseek-ai/dsh-client-ui-settings-models": "0.1.7-alpha.2"
64
66
  }
65
67
  }
@@ -0,0 +1,42 @@
1
+ import { readFile, writeFile, copyFile } from 'node:fs/promises'
2
+ import { join, resolve } from 'node:path'
3
+ import { homedir } from 'node:os'
4
+ import { pathToFileURL } from 'node:url'
5
+ import yaml from 'js-yaml'
6
+
7
+ // Recover only UI type markers skipped when DSH was upgraded before this plugin.
8
+ // Model settings and credential references remain owned by llm-pi-ai.
9
+ export function recoverProviderTypes(legacy, current, providers) {
10
+ const result = { ...current }
11
+ for (const [id, type] of Object.entries(legacy ?? {})) {
12
+ if (type === 'claude-adaptive' && providers?.[id]?.api === 'anthropic-messages'
13
+ && !Object.hasOwn(result, id)) result[id] = type
14
+ }
15
+ return result
16
+ }
17
+
18
+ export async function migrateLegacyTypes(home, profile = 'web') {
19
+ const target = join(home, 'profiles', profile, 'cordis.patch.yml')
20
+ let legacy
21
+ try { legacy = yaml.load(await readFile(join(home, 'settings.yaml.imported'), 'utf8')) }
22
+ catch (error) { if (error.code === 'ENOENT') return { recovered: 0 }; throw error }
23
+ const text = await readFile(target, 'utf8')
24
+ const patches = yaml.load(text) ?? []
25
+ if (!Array.isArray(patches)) throw new Error('Expected a profile patch list')
26
+ const providerEntry = patches.find(entry => entry.id === 'llm-pi-ai')
27
+ const markerEntry = patches.find(entry => entry.id === 'dsh-claude-provider')
28
+ const current = markerEntry?.config?.providerTypes ?? {}
29
+ const merged = recoverProviderTypes(legacy?.['dsh-claude-provider']?.providerTypes, current, providerEntry?.config?.providers)
30
+ const recovered = Object.keys(merged).length - Object.keys(current).length
31
+ if (!recovered) return { recovered: 0 }
32
+ const backup = `${target}.before-claude-migration-${Date.now()}`
33
+ await copyFile(target, backup)
34
+ if (markerEntry) markerEntry.config = { ...markerEntry.config, providerTypes: merged }
35
+ else patches.push({ id: 'dsh-claude-provider', config: { providerTypes: merged } })
36
+ await writeFile(target, yaml.dump(patches, { lineWidth: -1, noRefs: true }), { mode: 0o600 })
37
+ return { recovered, backup }
38
+ }
39
+
40
+ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
41
+ console.log(JSON.stringify(await migrateLegacyTypes(process.env.DSH_HOME ?? join(homedir(), '.dsh'), process.argv[2] ?? 'web')))
42
+ }
package/src/index.js CHANGED
@@ -6,8 +6,8 @@ export const inject = ['llm', 'settings']
6
6
  export const CLAUDE_PROVIDER_TYPE = 'claude-adaptive'
7
7
  export const CLAUDE_PROVIDER_SETTINGS_NS = 'dsh-claude-provider'
8
8
 
9
- const ProviderTypeSettings = z.object({
10
- providerTypes: z.dict(z.const(CLAUDE_PROVIDER_TYPE)).default({}),
9
+ export const Config = z.object({
10
+ providerTypes: z.dict(z.const(CLAUDE_PROVIDER_TYPE)).default({}).volatile(),
11
11
  })
12
12
 
13
13
  export const CLAUDE_DISCOVERY_API = 'mofeng-anthropic-models'
@@ -207,7 +207,7 @@ export async function discoverAnthropicModels({ baseURL, apiKey, signal, fetchIm
207
207
 
208
208
  function configuredCredentialRef(ctx, provider) {
209
209
  if (typeof provider !== 'string' || provider.length === 0) return undefined
210
- const section = ctx.get('settings')?.get(PI_AI_SETTINGS_NS)
210
+ const section = ctx.get('settings')?.describe().find(entry => entry.ns === PI_AI_SETTINGS_NS)?.value
211
211
  const profile = section?.providers?.[provider]
212
212
  const ref = profile?.apiKeyEnv
213
213
  return typeof ref === 'string' && ref.length > 0 ? ref : undefined
@@ -260,10 +260,5 @@ function installClaudeModelDiscovery(ctx) {
260
260
  }
261
261
 
262
262
  export function apply(ctx) {
263
- ctx.settings.register(
264
- CLAUDE_PROVIDER_SETTINGS_NS,
265
- ProviderTypeSettings,
266
- { base: { providerTypes: {} } },
267
- )
268
263
  installClaudeModelDiscovery(ctx)
269
264
  }