@mofeng2223/dsh-claude-provider 0.3.0 → 0.4.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/README.md +3 -18
- package/README.zh-CN.md +3 -18
- package/lib/client.js +552 -446
- package/package.json +7 -9
- package/src/index.js +38 -25
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mofeng2223/dsh-claude-provider",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Custom Claude provider support for DeepSeek Harness",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Custom Claude provider support for DeepSeek Harness 0.1.2-alpha",
|
|
5
5
|
"author": "mofeng2223",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@deepseek-ai/
|
|
28
|
-
"@deepseek-ai/schemastery": "3.18.1"
|
|
27
|
+
"@deepseek-ai/schemastery": "^3.18.2"
|
|
29
28
|
},
|
|
30
29
|
"exports": {
|
|
31
30
|
".": "./src/index.js",
|
|
@@ -33,7 +32,7 @@
|
|
|
33
32
|
"./package.json": "./package.json"
|
|
34
33
|
},
|
|
35
34
|
"files": [
|
|
36
|
-
"src",
|
|
35
|
+
"src/index.js",
|
|
37
36
|
"lib/client.js",
|
|
38
37
|
"cordis.patch.yml",
|
|
39
38
|
"README.md",
|
|
@@ -47,9 +46,6 @@
|
|
|
47
46
|
"engines": {
|
|
48
47
|
"node": ">=22.19"
|
|
49
48
|
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@deepseek-ai/dsh-client-ui-settings-models": "0.1.0-rc.8"
|
|
52
|
-
},
|
|
53
49
|
"dsh": {
|
|
54
50
|
"bundle": {
|
|
55
51
|
"patch": "./cordis.patch.yml"
|
|
@@ -57,11 +53,13 @@
|
|
|
57
53
|
"client": {
|
|
58
54
|
"platform": "web",
|
|
59
55
|
"inject": [
|
|
60
|
-
"@deepseek-ai/dsh-client-runtime",
|
|
61
56
|
"@deepseek-ai/dsh-client-ui-settings",
|
|
62
57
|
"@deepseek-ai/dsh-client-locale",
|
|
63
58
|
"@deepseek-ai/dsh-api-remotes"
|
|
64
59
|
]
|
|
65
60
|
}
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@deepseek-ai/dsh-client-ui-settings-models": "0.1.2-alpha.3"
|
|
66
64
|
}
|
|
67
65
|
}
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery'
|
|
2
|
-
import { settingsNamespace } from '@deepseek-ai/dsh-settings'
|
|
3
2
|
|
|
4
3
|
export const name = 'claude-provider'
|
|
5
4
|
export const inject = ['llm', 'settings']
|
|
6
5
|
|
|
7
6
|
export const CLAUDE_PROVIDER_TYPE = 'claude-adaptive'
|
|
8
|
-
export const CLAUDE_PROVIDER_SETTINGS_NS =
|
|
9
|
-
export const CLAUDE_PROVIDER_DIRECTORY_SENTINEL = 'dsh-claude-provider-type'
|
|
7
|
+
export const CLAUDE_PROVIDER_SETTINGS_NS = 'dsh-claude-provider'
|
|
10
8
|
|
|
11
9
|
const ProviderTypeSettings = z.object({
|
|
12
10
|
providerTypes: z.dict(z.const(CLAUDE_PROVIDER_TYPE)).default({}),
|
|
@@ -18,6 +16,19 @@ const PI_AI_SETTINGS_NS = 'llm-pi-ai'
|
|
|
18
16
|
const MAX_DISCOVERY_RESPONSE_BYTES = 4 * 1024 * 1024
|
|
19
17
|
const MAX_DISCOVERY_PAGES = 100
|
|
20
18
|
|
|
19
|
+
/** Recorded capacities and thinking presets for known Claude model ids. */
|
|
20
|
+
export const CLAUDE_KNOWN_MODELS = Object.freeze({
|
|
21
|
+
'claude-fable-5': Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: 'five' }),
|
|
22
|
+
'claude-haiku-4-5-20251001': Object.freeze({ contextWindow: 200000, maxTokens: 64000, preset: 'toggle' }),
|
|
23
|
+
'claude-haiku-4-5': Object.freeze({ contextWindow: 200000, maxTokens: 64000, preset: 'toggle' }),
|
|
24
|
+
'claude-opus-4-6': Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: 'four' }),
|
|
25
|
+
'claude-opus-4-7': Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: 'five' }),
|
|
26
|
+
'claude-opus-4-8': Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: 'five' }),
|
|
27
|
+
'claude-opus-5': Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: 'five' }),
|
|
28
|
+
'claude-sonnet-4-6': Object.freeze({ contextWindow: 1000000, maxTokens: 64000, preset: 'four' }),
|
|
29
|
+
'claude-sonnet-5': Object.freeze({ contextWindow: 1000000, maxTokens: 128000, preset: 'five' }),
|
|
30
|
+
})
|
|
31
|
+
|
|
21
32
|
function requireNonEmptyString(value, field) {
|
|
22
33
|
if (typeof value !== 'string' || value.length === 0) {
|
|
23
34
|
throw new Error(`claude-provider: ${field} must be a non-empty string`)
|
|
@@ -118,6 +129,13 @@ export function readAnthropicModelPage(body) {
|
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
|
|
132
|
+
/** Fill a discovered row's capacities from the recorded Claude model table. */
|
|
133
|
+
export function withKnownModelMetadata(model) {
|
|
134
|
+
const known = CLAUDE_KNOWN_MODELS[model?.id]
|
|
135
|
+
if (known === undefined) return model
|
|
136
|
+
return { ...model, contextWindow: known.contextWindow, maxTokens: known.maxTokens }
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
function discoveryHeaders(apiKey) {
|
|
122
140
|
const value = requireNonEmptyString(apiKey, 'apiKey').trim()
|
|
123
141
|
if (value.length === 0) throw new Error('Claude 模型目录:请先填写 API 密钥')
|
|
@@ -175,7 +193,7 @@ export async function discoverAnthropicModels({ baseURL, apiKey, signal, fetchIm
|
|
|
175
193
|
for (const model of parsed.models) {
|
|
176
194
|
if (seen.has(model.id)) continue
|
|
177
195
|
seen.add(model.id)
|
|
178
|
-
models.push(model)
|
|
196
|
+
models.push(withKnownModelMetadata(model))
|
|
179
197
|
}
|
|
180
198
|
if (!parsed.hasMore) return models
|
|
181
199
|
if (parsed.lastId === undefined || parsed.lastId === afterId) {
|
|
@@ -205,27 +223,34 @@ async function discoveryApiKey(ctx, request) {
|
|
|
205
223
|
return value
|
|
206
224
|
}
|
|
207
225
|
|
|
226
|
+
/** Whether an explicitly registered provider belongs to this plugin's Claude type. */
|
|
227
|
+
export function isClaudeProviderType(settings, provider) {
|
|
228
|
+
if (typeof provider !== 'string' || provider.length === 0) return false
|
|
229
|
+
return settings?.providerTypes?.[provider] === CLAUDE_PROVIDER_TYPE
|
|
230
|
+
}
|
|
231
|
+
|
|
208
232
|
function installClaudeModelDiscovery(ctx) {
|
|
209
233
|
const llm = ctx.llm
|
|
210
234
|
const upstream = llm.discoverModels
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
235
|
+
// DSH 0.1.2-alpha moved caller cancellation to a third positional
|
|
236
|
+
// parameter; `request.signal` no longer exists. Forward it verbatim.
|
|
237
|
+
// Only the plugin's own Claude surfaces send CLAUDE_DISCOVERY_API, so every
|
|
238
|
+
// other provider — generic anthropic-messages routes included — keeps the
|
|
239
|
+
// stock discovery behavior.
|
|
240
|
+
const wrapped = async function (settingsNs, request, signal) {
|
|
241
|
+
if (settingsNs !== PI_AI_SETTINGS_NS || request?.api !== CLAUDE_DISCOVERY_API) {
|
|
242
|
+
return upstream.call(this, settingsNs, request, signal)
|
|
214
243
|
}
|
|
215
244
|
// The built-in Anthropic route already has pi-ai's catalog and should keep
|
|
216
245
|
// using it. The plugin extension is only for hand-declared Claude routes.
|
|
217
246
|
if (request.provider === 'anthropic') {
|
|
218
|
-
return upstream.call(this, settingsNs, { ...request, api: 'anthropic-messages' })
|
|
247
|
+
return upstream.call(this, settingsNs, { ...request, api: 'anthropic-messages' }, signal)
|
|
219
248
|
}
|
|
220
249
|
if (typeof request.baseURL !== 'string' || request.baseURL.length === 0) {
|
|
221
250
|
throw new Error('Claude 模型目录:请先填写 API 地址')
|
|
222
251
|
}
|
|
223
252
|
const apiKey = await discoveryApiKey(ctx, request)
|
|
224
|
-
return discoverAnthropicModels({
|
|
225
|
-
baseURL: request.baseURL,
|
|
226
|
-
apiKey,
|
|
227
|
-
signal: request.signal,
|
|
228
|
-
})
|
|
253
|
+
return discoverAnthropicModels({ baseURL: request.baseURL, apiKey, signal })
|
|
229
254
|
}
|
|
230
255
|
llm.discoverModels = wrapped
|
|
231
256
|
ctx.effect(() => () => {
|
|
@@ -233,23 +258,11 @@ function installClaudeModelDiscovery(ctx) {
|
|
|
233
258
|
})
|
|
234
259
|
}
|
|
235
260
|
|
|
236
|
-
/** Whether an explicitly registered provider belongs to this plugin's Claude type. */
|
|
237
|
-
export function isClaudeProviderType(settings, provider) {
|
|
238
|
-
if (typeof provider !== 'string' || provider.length === 0) return false
|
|
239
|
-
return settings?.providerTypes?.[provider] === CLAUDE_PROVIDER_TYPE
|
|
240
|
-
}
|
|
241
|
-
|
|
242
261
|
export function apply(ctx) {
|
|
243
262
|
ctx.settings.register(
|
|
244
263
|
CLAUDE_PROVIDER_SETTINGS_NS,
|
|
245
264
|
ProviderTypeSettings,
|
|
246
265
|
{ base: { providerTypes: {} } },
|
|
247
266
|
)
|
|
248
|
-
ctx.llm.registerConfigurableProviders([{
|
|
249
|
-
provider: CLAUDE_PROVIDER_DIRECTORY_SENTINEL,
|
|
250
|
-
displayName: 'Claude Provider Type',
|
|
251
|
-
settingsNs: CLAUDE_PROVIDER_SETTINGS_NS,
|
|
252
|
-
settingsPath: ['providerTypes'],
|
|
253
|
-
}])
|
|
254
267
|
installClaudeModelDiscovery(ctx)
|
|
255
268
|
}
|