dsh-agent-router 1.9.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/LICENSE +21 -0
- package/README.en.md +304 -0
- package/README.md +304 -0
- package/client.js +3061 -0
- package/cordis.patch.yml +20 -0
- package/docs/ARCHITECTURE_DIAGNOSIS_AND_PLAN.md +414 -0
- package/docs/DETAIL.ja.md +1 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/IMPLEMENTATION_PLAN.md +99 -0
- package/docs/ITERATION_PLAN_2026-11.md +377 -0
- package/docs/RELEASE.md +133 -0
- package/docs/RELEASE_CHECKLIST.md +88 -0
- package/docs/preview.svg +69 -0
- package/docs/preview.zh.svg +63 -0
- package/icon.svg +16 -0
- package/index.js +24 -0
- package/lib/classifier.js +405 -0
- package/lib/cli/discover.js +187 -0
- package/lib/cli/invoke.js +294 -0
- package/lib/cli/parsers.js +234 -0
- package/lib/cli/shared.js +145 -0
- package/lib/cli-runners.js +39 -0
- package/lib/config-limits.js +67 -0
- package/lib/config-normalize.js +147 -0
- package/lib/config-presets.js +89 -0
- package/lib/config-schema.js +347 -0
- package/lib/defaults.js +117 -0
- package/lib/diagnose-fallback.js +96 -0
- package/lib/error-classify.js +160 -0
- package/lib/eval-routing.js +96 -0
- package/lib/guardrails.js +70 -0
- package/lib/integrations.js +173 -0
- package/lib/job-runner.js +287 -0
- package/lib/ledger.js +360 -0
- package/lib/legacy-config.js +34 -0
- package/lib/model-capabilities.js +135 -0
- package/lib/model-score.js +65 -0
- package/lib/plugin.js +184 -0
- package/lib/profile-mount.js +524 -0
- package/lib/route-edit.js +82 -0
- package/lib/router/candidates.js +194 -0
- package/lib/router/catalog.js +121 -0
- package/lib/router/cli-select.js +84 -0
- package/lib/router/config-manager.js +122 -0
- package/lib/router/doctor.js +159 -0
- package/lib/router/local-models.js +126 -0
- package/lib/router/policy.js +61 -0
- package/lib/router/rpc.js +263 -0
- package/lib/router/system-prompt.js +29 -0
- package/lib/router/tools.js +1028 -0
- package/lib/router/util.js +99 -0
- package/lib/rpc-contract.js +46 -0
- package/lib/sessions.js +59 -0
- package/lib/task-queue.js +201 -0
- package/lib/tier-presets.js +595 -0
- package/lib/typert.host.js +79 -0
- package/lib/update-check.js +205 -0
- package/lib/worktree-lock.js +86 -0
- package/lib/worktree.js +268 -0
- package/locale/en.json +7 -0
- package/locale/ja.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +136 -0
- package/scripts/profile-maintenance.mjs +287 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config presets and JSON import/export helpers.
|
|
3
|
+
*
|
|
4
|
+
* Presets only adjust global scalar policy; tier chains are left untouched so a
|
|
5
|
+
* preset never silently rewrites routes the user explicitly configured.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-agent-router/lib/config-presets
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { migrateConfig } from './config-normalize.js'
|
|
11
|
+
import { CONFIG_VERSION } from './defaults.js'
|
|
12
|
+
|
|
13
|
+
export const PRESET_NAMES = Object.freeze(['safe', 'cost', 'quality'])
|
|
14
|
+
|
|
15
|
+
const PRESETS = Object.freeze({
|
|
16
|
+
safe: Object.freeze({
|
|
17
|
+
preferBackend: 'dsh',
|
|
18
|
+
autoEscalate: true,
|
|
19
|
+
budgetGuard: true,
|
|
20
|
+
peakAvoidance: false,
|
|
21
|
+
adaptiveRanking: false,
|
|
22
|
+
cliSelection: 'static',
|
|
23
|
+
defaultBackground: false,
|
|
24
|
+
allowLocalModels: false,
|
|
25
|
+
}),
|
|
26
|
+
cost: Object.freeze({
|
|
27
|
+
preferBackend: 'cli',
|
|
28
|
+
autoEscalate: true,
|
|
29
|
+
budgetGuard: true,
|
|
30
|
+
peakAvoidance: true,
|
|
31
|
+
adaptiveRanking: true,
|
|
32
|
+
cliSelection: 'adaptive',
|
|
33
|
+
defaultBackground: true,
|
|
34
|
+
allowLocalModels: true,
|
|
35
|
+
}),
|
|
36
|
+
quality: Object.freeze({
|
|
37
|
+
preferBackend: 'auto',
|
|
38
|
+
autoEscalate: true,
|
|
39
|
+
budgetGuard: false,
|
|
40
|
+
peakAvoidance: false,
|
|
41
|
+
adaptiveRanking: true,
|
|
42
|
+
cliSelection: 'adaptive',
|
|
43
|
+
defaultBackground: false,
|
|
44
|
+
allowLocalModels: false,
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export function isPresetName(name) {
|
|
49
|
+
return PRESET_NAMES.includes(name)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {Record<string, any>} baseConfig
|
|
54
|
+
* @param {string} name
|
|
55
|
+
*/
|
|
56
|
+
export function buildPresetConfig(baseConfig, name) {
|
|
57
|
+
if (!isPresetName(name)) {
|
|
58
|
+
throw new Error(`Unknown preset "${name}"; choose one of ${PRESET_NAMES.join(', ')}`)
|
|
59
|
+
}
|
|
60
|
+
const next = JSON.parse(JSON.stringify(baseConfig ?? {}))
|
|
61
|
+
Object.assign(next, PRESETS[name], { configVersion: CONFIG_VERSION })
|
|
62
|
+
return next
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {Record<string, any>} config
|
|
67
|
+
*/
|
|
68
|
+
export function buildExportPayload(config) {
|
|
69
|
+
return {
|
|
70
|
+
format: 'dsh-agent-router/config',
|
|
71
|
+
configVersion: CONFIG_VERSION,
|
|
72
|
+
exportedAt: new Date().toISOString(),
|
|
73
|
+
config: JSON.parse(JSON.stringify(config ?? {})),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Accept either a full export payload or a bare config object and migrate it.
|
|
79
|
+
* @param {unknown} payload
|
|
80
|
+
*/
|
|
81
|
+
export function parseImportPayload(payload) {
|
|
82
|
+
const raw = payload && typeof payload === 'object' && !Array.isArray(payload) && payload.config
|
|
83
|
+
? payload.config
|
|
84
|
+
: payload
|
|
85
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
86
|
+
throw new Error('importConfig requires a config object or an exported { config } payload')
|
|
87
|
+
}
|
|
88
|
+
return migrateConfig(raw)
|
|
89
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency Schemastery + Standard Schema v1 compatible Config definition
|
|
3
|
+
* for `dsh-agent-router`.
|
|
4
|
+
*
|
|
5
|
+
* Allows DSH's `Config.listConfigs` (`status: "schema"`), `configEditor.edit()`,
|
|
6
|
+
* and Cordis `Entry._commitVolatile()` hot config updates to work without adding
|
|
7
|
+
* any external npm runtime dependency.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-agent-router/lib/config-schema
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { CLI_SELECTION_MODES, CONFIG_LIMITS, normalizeProviderIds } from './config-limits.js'
|
|
13
|
+
import { CONFIG_VERSION, DEFAULT_ROUTING_CONFIG, DEFAULT_TIER_LAYOUT, DEFAULT_TIER_POLICIES } from './defaults.js'
|
|
14
|
+
import {
|
|
15
|
+
PREFER_BACKENDS,
|
|
16
|
+
normalizeTierEntries,
|
|
17
|
+
validateTierEntries,
|
|
18
|
+
} from './tier-presets.js'
|
|
19
|
+
|
|
20
|
+
const SCHEMASTERY_SYM = Symbol.for('schemastery')
|
|
21
|
+
const VOLATILE_WRITE_SYM = Symbol.for('cosmokit.volatile.write')
|
|
22
|
+
|
|
23
|
+
export class VolatileRef {
|
|
24
|
+
#value
|
|
25
|
+
#listeners = new Set()
|
|
26
|
+
|
|
27
|
+
constructor(initial) {
|
|
28
|
+
this.#value = initial
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get() {
|
|
32
|
+
return this.#value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[VOLATILE_WRITE_SYM](next) {
|
|
36
|
+
this.#value = next
|
|
37
|
+
for (const fn of this.#listeners) {
|
|
38
|
+
try {
|
|
39
|
+
fn(next)
|
|
40
|
+
} catch {
|
|
41
|
+
// Listener errors should not abort Cordis volatile update
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
subscribe(fn) {
|
|
47
|
+
this.#listeners.add(fn)
|
|
48
|
+
return () => this.#listeners.delete(fn)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isVolatileRef(value) {
|
|
53
|
+
return typeof value === 'object' && value !== null && VOLATILE_WRITE_SYM in value && typeof value.get === 'function'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function readConfigValue(value, fallback = undefined) {
|
|
57
|
+
if (isVolatileRef(value)) return value.get()
|
|
58
|
+
return value === undefined ? fallback : value
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function unwrapConfigObject(raw) {
|
|
62
|
+
if (!raw || typeof raw !== 'object') return {}
|
|
63
|
+
const out = {}
|
|
64
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
65
|
+
out[k] = readConfigValue(v)
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function attachMetaMethods(node) {
|
|
71
|
+
node[SCHEMASTERY_SYM] = true
|
|
72
|
+
node.default = (val) => {
|
|
73
|
+
node.meta = { ...node.meta, default: val }
|
|
74
|
+
return node
|
|
75
|
+
}
|
|
76
|
+
node.description = (text) => {
|
|
77
|
+
node.meta = { ...node.meta, description: text }
|
|
78
|
+
return node
|
|
79
|
+
}
|
|
80
|
+
node.volatile = () => {
|
|
81
|
+
node.meta = { ...node.meta, volatile: true }
|
|
82
|
+
return node
|
|
83
|
+
}
|
|
84
|
+
node.required = () => {
|
|
85
|
+
node.meta = { ...node.meta, required: true }
|
|
86
|
+
return node
|
|
87
|
+
}
|
|
88
|
+
node.min = (n) => {
|
|
89
|
+
node.meta = { ...node.meta, min: n }
|
|
90
|
+
return node
|
|
91
|
+
}
|
|
92
|
+
node.max = (n) => {
|
|
93
|
+
node.meta = { ...node.meta, max: n }
|
|
94
|
+
return node
|
|
95
|
+
}
|
|
96
|
+
node.step = (n) => {
|
|
97
|
+
node.meta = { ...node.meta, step: n }
|
|
98
|
+
return node
|
|
99
|
+
}
|
|
100
|
+
node.toJSON = () => {
|
|
101
|
+
const out = { type: node.type, meta: { ...node.meta } }
|
|
102
|
+
if (node.value !== undefined) out.value = node.value
|
|
103
|
+
if (node.inner) out.inner = node.inner.toJSON()
|
|
104
|
+
if (node.list) out.list = node.list.map(x => x.toJSON())
|
|
105
|
+
if (node.dict) {
|
|
106
|
+
out.dict = Object.fromEntries(
|
|
107
|
+
Object.entries(node.dict).map(([k, v]) => [k, v.toJSON()]),
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
return out
|
|
111
|
+
}
|
|
112
|
+
return node
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const s = {
|
|
116
|
+
boolean: () => attachMetaMethods({ type: 'boolean', meta: {} }),
|
|
117
|
+
string: () => attachMetaMethods({ type: 'string', meta: {} }),
|
|
118
|
+
number: () => attachMetaMethods({ type: 'number', meta: {} }),
|
|
119
|
+
const: (value) => attachMetaMethods({ type: 'const', value, meta: {} }),
|
|
120
|
+
union: (list) => attachMetaMethods({ type: 'union', list, meta: {} }),
|
|
121
|
+
array: (inner) => attachMetaMethods({ type: 'array', inner, meta: {} }),
|
|
122
|
+
object: (dict) => attachMetaMethods({ type: 'object', dict, meta: {} }),
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const BACKENDS = PREFER_BACKENDS
|
|
126
|
+
|
|
127
|
+
const tiersSchema = s.object({})
|
|
128
|
+
.description('Configurable difficulty tiers keyed by id. Each entry holds name, description, role, score range, routing chains, and escalation target.')
|
|
129
|
+
|
|
130
|
+
const rootSchema = s.object({
|
|
131
|
+
configVersion: s.number()
|
|
132
|
+
.step(1).min(1)
|
|
133
|
+
.default(CONFIG_VERSION)
|
|
134
|
+
.volatile()
|
|
135
|
+
.description('Persisted routing config schema version used for migrations.'),
|
|
136
|
+
preferBackend: s.union(BACKENDS.map(b => s.const(b)))
|
|
137
|
+
.default(DEFAULT_ROUTING_CONFIG.preferBackend)
|
|
138
|
+
.volatile()
|
|
139
|
+
.description('Default execution backend preference across tiers.'),
|
|
140
|
+
autoEscalate: s.boolean()
|
|
141
|
+
.default(DEFAULT_ROUTING_CONFIG.autoEscalate)
|
|
142
|
+
.volatile()
|
|
143
|
+
.description('Automatically escalate to the next tier when all candidates fail.'),
|
|
144
|
+
budgetGuard: s.boolean()
|
|
145
|
+
.default(DEFAULT_ROUTING_CONFIG.budgetGuard)
|
|
146
|
+
.volatile()
|
|
147
|
+
.description('Prefer low-cost or local CLI routes when dsh-cost-meter reports budget near/at limit.'),
|
|
148
|
+
peakAvoidance: s.boolean()
|
|
149
|
+
.default(DEFAULT_ROUTING_CONFIG.peakAvoidance)
|
|
150
|
+
.volatile()
|
|
151
|
+
.description('Deprioritize DeepSeek-family routes during 2x peak pricing windows.'),
|
|
152
|
+
adaptiveRanking: s.boolean()
|
|
153
|
+
.default(DEFAULT_ROUTING_CONFIG.adaptiveRanking)
|
|
154
|
+
.volatile()
|
|
155
|
+
.description('Adjust candidate ordering dynamically using EWMA latency and recent success rates.'),
|
|
156
|
+
defaultBackground: s.boolean()
|
|
157
|
+
.default(DEFAULT_ROUTING_CONFIG.defaultBackground)
|
|
158
|
+
.volatile()
|
|
159
|
+
.description('Run CLI dispatches asynchronously in the background queue by default.'),
|
|
160
|
+
useNativeJobs: s.boolean()
|
|
161
|
+
.default(DEFAULT_ROUTING_CONFIG.useNativeJobs)
|
|
162
|
+
.volatile()
|
|
163
|
+
.description('Use the DSH native job registry (ctx.jobs) for background CLI runs when available; falls back to the built-in queue otherwise.'),
|
|
164
|
+
cliSelection: s.union(CLI_SELECTION_MODES.map(m => s.const(m)))
|
|
165
|
+
.default(DEFAULT_ROUTING_CONFIG.cliSelection)
|
|
166
|
+
.volatile()
|
|
167
|
+
.description('CLI candidate selection: static keeps the configured tier order, adaptive also adds installed CLIs and re-ranks by recent metrics.'),
|
|
168
|
+
allowLocalModels: s.boolean()
|
|
169
|
+
.default(DEFAULT_ROUTING_CONFIG.allowLocalModels)
|
|
170
|
+
.volatile()
|
|
171
|
+
.description('Opt in to local/self-hosted DSH providers (Ollama, LM Studio, vLLM, …) as routing candidates. Disabled by default.'),
|
|
172
|
+
localProviders: s.array(s.string().min(1))
|
|
173
|
+
.default([])
|
|
174
|
+
.volatile()
|
|
175
|
+
.description('Explicit provider ids treated as local models; empty means auto-detect by provider id/name/baseURL.'),
|
|
176
|
+
maxConcurrentCli: s.number()
|
|
177
|
+
.step(1).min(CONFIG_LIMITS.maxConcurrentCli.min).max(CONFIG_LIMITS.maxConcurrentCli.max)
|
|
178
|
+
.default(CONFIG_LIMITS.maxConcurrentCli.default)
|
|
179
|
+
.volatile()
|
|
180
|
+
.description('Maximum concurrent background CLI tasks.'),
|
|
181
|
+
cooldownMs: s.number()
|
|
182
|
+
.step(1).min(CONFIG_LIMITS.cooldownMs.min).max(CONFIG_LIMITS.cooldownMs.max)
|
|
183
|
+
.default(CONFIG_LIMITS.cooldownMs.default)
|
|
184
|
+
.volatile()
|
|
185
|
+
.description('Base circuit-breaker cooldown duration in milliseconds after a route failure.'),
|
|
186
|
+
defaultTimeoutMs: s.number()
|
|
187
|
+
.step(1).min(CONFIG_LIMITS.defaultTimeoutMs.min).max(CONFIG_LIMITS.defaultTimeoutMs.max)
|
|
188
|
+
.default(CONFIG_LIMITS.defaultTimeoutMs.default)
|
|
189
|
+
.volatile()
|
|
190
|
+
.description('Default CLI execution timeout in milliseconds.'),
|
|
191
|
+
maxRuns: s.number()
|
|
192
|
+
.step(1).min(CONFIG_LIMITS.maxRuns.min).max(CONFIG_LIMITS.maxRuns.max)
|
|
193
|
+
.default(CONFIG_LIMITS.maxRuns.default)
|
|
194
|
+
.volatile()
|
|
195
|
+
.description('Maximum recent run records retained in the persistent ledger.'),
|
|
196
|
+
ledgerFile: s.string()
|
|
197
|
+
.volatile()
|
|
198
|
+
.description('Optional custom path for the persistent routing ledger JSON file.'),
|
|
199
|
+
tierLayout: s.union([s.const('default'), s.const('custom')])
|
|
200
|
+
.default(DEFAULT_TIER_LAYOUT)
|
|
201
|
+
.volatile()
|
|
202
|
+
.description('Whether tiers merge over the built-in four-tier layout (default) or are authoritative (custom).'),
|
|
203
|
+
tiers: tiersSchema
|
|
204
|
+
.volatile()
|
|
205
|
+
.description('Configurable difficulty tiers keyed by id (T1-T4 by default).'),
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
export function validateRouterConfig(input) {
|
|
209
|
+
if (input !== undefined && input !== null && (typeof input !== 'object' || Array.isArray(input))) {
|
|
210
|
+
return { issues: [{ message: 'dsh-agent-router config must be a plain object' }] }
|
|
211
|
+
}
|
|
212
|
+
const src = input ?? {}
|
|
213
|
+
const issues = []
|
|
214
|
+
|
|
215
|
+
let configVersion = CONFIG_VERSION
|
|
216
|
+
if (src.configVersion !== undefined) {
|
|
217
|
+
if (!Number.isInteger(src.configVersion) || src.configVersion < 1) {
|
|
218
|
+
issues.push({ message: 'configVersion must be a positive integer' })
|
|
219
|
+
} else if (src.configVersion > CONFIG_VERSION) {
|
|
220
|
+
issues.push({ message: `configVersion ${src.configVersion} is newer than supported ${CONFIG_VERSION}; upgrade the plugin` })
|
|
221
|
+
} else {
|
|
222
|
+
configVersion = src.configVersion
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const preferBackend = src.preferBackend === undefined ? DEFAULT_ROUTING_CONFIG.preferBackend : src.preferBackend
|
|
227
|
+
if (!BACKENDS.includes(preferBackend)) {
|
|
228
|
+
issues.push({ message: `preferBackend must be one of ${BACKENDS.join(', ')}` })
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const checkBool = (key, def) => {
|
|
232
|
+
const v = src[key]
|
|
233
|
+
if (v === undefined) return def
|
|
234
|
+
if (typeof v !== 'boolean') {
|
|
235
|
+
issues.push({ message: `${key} must be a boolean` })
|
|
236
|
+
return def
|
|
237
|
+
}
|
|
238
|
+
return v
|
|
239
|
+
}
|
|
240
|
+
const checkInt = (key, def, min, max) => {
|
|
241
|
+
const v = src[key]
|
|
242
|
+
if (v === undefined) return def
|
|
243
|
+
if (typeof v !== 'number' || !Number.isInteger(v) || v < min || v > max) {
|
|
244
|
+
issues.push({ message: `${key} must be an integer between ${min} and ${max}` })
|
|
245
|
+
return def
|
|
246
|
+
}
|
|
247
|
+
return v
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const autoEscalate = checkBool('autoEscalate', DEFAULT_ROUTING_CONFIG.autoEscalate)
|
|
251
|
+
const budgetGuard = checkBool('budgetGuard', DEFAULT_ROUTING_CONFIG.budgetGuard)
|
|
252
|
+
const peakAvoidance = checkBool('peakAvoidance', DEFAULT_ROUTING_CONFIG.peakAvoidance)
|
|
253
|
+
const adaptiveRanking = checkBool('adaptiveRanking', DEFAULT_ROUTING_CONFIG.adaptiveRanking)
|
|
254
|
+
const defaultBackground = checkBool('defaultBackground', DEFAULT_ROUTING_CONFIG.defaultBackground)
|
|
255
|
+
const useNativeJobs = checkBool('useNativeJobs', DEFAULT_ROUTING_CONFIG.useNativeJobs)
|
|
256
|
+
const allowLocalModels = checkBool('allowLocalModels', DEFAULT_ROUTING_CONFIG.allowLocalModels)
|
|
257
|
+
|
|
258
|
+
let cliSelection = DEFAULT_ROUTING_CONFIG.cliSelection
|
|
259
|
+
if (src.cliSelection !== undefined) {
|
|
260
|
+
if (!CLI_SELECTION_MODES.includes(src.cliSelection)) {
|
|
261
|
+
issues.push({ message: `cliSelection must be one of ${CLI_SELECTION_MODES.join(', ')}` })
|
|
262
|
+
} else {
|
|
263
|
+
cliSelection = src.cliSelection
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
let localProviders = []
|
|
268
|
+
if (src.localProviders !== undefined) {
|
|
269
|
+
if (!Array.isArray(src.localProviders)) {
|
|
270
|
+
issues.push({ message: 'localProviders must be an array of provider ids' })
|
|
271
|
+
} else if (src.localProviders.some(v => typeof v !== 'string' || !v.trim())) {
|
|
272
|
+
issues.push({ message: 'localProviders entries must be non-empty strings' })
|
|
273
|
+
} else {
|
|
274
|
+
localProviders = normalizeProviderIds(src.localProviders)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const maxConcurrentCli = checkInt('maxConcurrentCli', CONFIG_LIMITS.maxConcurrentCli.default, CONFIG_LIMITS.maxConcurrentCli.min, CONFIG_LIMITS.maxConcurrentCli.max)
|
|
278
|
+
const cooldownMs = checkInt('cooldownMs', CONFIG_LIMITS.cooldownMs.default, CONFIG_LIMITS.cooldownMs.min, CONFIG_LIMITS.cooldownMs.max)
|
|
279
|
+
const defaultTimeoutMs = checkInt('defaultTimeoutMs', CONFIG_LIMITS.defaultTimeoutMs.default, CONFIG_LIMITS.defaultTimeoutMs.min, CONFIG_LIMITS.defaultTimeoutMs.max)
|
|
280
|
+
const maxRuns = checkInt('maxRuns', CONFIG_LIMITS.maxRuns.default, CONFIG_LIMITS.maxRuns.min, CONFIG_LIMITS.maxRuns.max)
|
|
281
|
+
|
|
282
|
+
let ledgerFile
|
|
283
|
+
if (src.ledgerFile !== undefined) {
|
|
284
|
+
if (typeof src.ledgerFile !== 'string') issues.push({ message: 'ledgerFile must be a string' })
|
|
285
|
+
else ledgerFile = src.ledgerFile
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let tierLayout = DEFAULT_TIER_LAYOUT
|
|
289
|
+
if (src.tierLayout !== undefined) {
|
|
290
|
+
if (src.tierLayout !== 'custom' && src.tierLayout !== DEFAULT_TIER_LAYOUT) {
|
|
291
|
+
issues.push({ message: 'tierLayout 只能是 default 或 custom' })
|
|
292
|
+
} else {
|
|
293
|
+
tierLayout = src.tierLayout
|
|
294
|
+
}
|
|
295
|
+
} else if (src.tiers !== undefined && Number(src.configVersion) >= CONFIG_VERSION) {
|
|
296
|
+
tierLayout = 'custom'
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let tiers = {}
|
|
300
|
+
if (src.tiers !== undefined && (!src.tiers || typeof src.tiers !== 'object' || Array.isArray(src.tiers))) {
|
|
301
|
+
issues.push({ message: 'tiers 必须是对象(键为档位 id)' })
|
|
302
|
+
} else {
|
|
303
|
+
const normalized = normalizeTierEntries(src.tiers, {
|
|
304
|
+
authoritative: tierLayout === 'custom',
|
|
305
|
+
baseTiers: DEFAULT_TIER_POLICIES,
|
|
306
|
+
})
|
|
307
|
+
for (const message of [...normalized.issues, ...validateTierEntries(normalized.tiers)]) {
|
|
308
|
+
issues.push({ message })
|
|
309
|
+
}
|
|
310
|
+
tiers = normalized.tiers
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (issues.length > 0) return { issues }
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
value: {
|
|
317
|
+
configVersion: new VolatileRef(configVersion),
|
|
318
|
+
preferBackend: new VolatileRef(preferBackend),
|
|
319
|
+
autoEscalate: new VolatileRef(autoEscalate),
|
|
320
|
+
budgetGuard: new VolatileRef(budgetGuard),
|
|
321
|
+
peakAvoidance: new VolatileRef(peakAvoidance),
|
|
322
|
+
adaptiveRanking: new VolatileRef(adaptiveRanking),
|
|
323
|
+
defaultBackground: new VolatileRef(defaultBackground),
|
|
324
|
+
useNativeJobs: new VolatileRef(useNativeJobs),
|
|
325
|
+
cliSelection: new VolatileRef(cliSelection),
|
|
326
|
+
allowLocalModels: new VolatileRef(allowLocalModels),
|
|
327
|
+
localProviders: new VolatileRef(localProviders),
|
|
328
|
+
maxConcurrentCli: new VolatileRef(maxConcurrentCli),
|
|
329
|
+
cooldownMs: new VolatileRef(cooldownMs),
|
|
330
|
+
defaultTimeoutMs: new VolatileRef(defaultTimeoutMs),
|
|
331
|
+
maxRuns: new VolatileRef(maxRuns),
|
|
332
|
+
ledgerFile: new VolatileRef(ledgerFile),
|
|
333
|
+
tierLayout: new VolatileRef(tierLayout),
|
|
334
|
+
tiers: new VolatileRef(tiers),
|
|
335
|
+
},
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export const Config = Object.assign(rootSchema, {
|
|
340
|
+
'~standard': {
|
|
341
|
+
version: 1,
|
|
342
|
+
vendor: 'dsh-agent-router',
|
|
343
|
+
validate: validateRouterConfig,
|
|
344
|
+
},
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
export default Config
|
package/lib/defaults.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for default routing policies.
|
|
3
|
+
* Imported by the classifier, Config schema, and runtime normalizer.
|
|
4
|
+
* Pure data plus tier skeleton imports, so any layer can depend on it safely.
|
|
5
|
+
* @module dsh-agent-router/lib/defaults
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DEFAULT_TIER_SKELETON, DEFAULT_TIER_LAYOUT } from './tier-presets.js'
|
|
9
|
+
|
|
10
|
+
/** Current persisted config schema version (bump when a migration is required). */
|
|
11
|
+
export const CONFIG_VERSION = 2
|
|
12
|
+
|
|
13
|
+
/** Default tier layout marker (merge overrides over built-in tiers). */
|
|
14
|
+
export { DEFAULT_TIER_LAYOUT }
|
|
15
|
+
|
|
16
|
+
/** Default scalar routing policy values. */
|
|
17
|
+
export const DEFAULT_ROUTING_CONFIG = Object.freeze({
|
|
18
|
+
configVersion: CONFIG_VERSION,
|
|
19
|
+
preferBackend: 'auto',
|
|
20
|
+
autoEscalate: true,
|
|
21
|
+
budgetGuard: true,
|
|
22
|
+
peakAvoidance: false,
|
|
23
|
+
adaptiveRanking: true,
|
|
24
|
+
defaultBackground: false,
|
|
25
|
+
useNativeJobs: true,
|
|
26
|
+
cliSelection: 'static',
|
|
27
|
+
allowLocalModels: false,
|
|
28
|
+
localProviders: Object.freeze([]),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
/** Route chains keyed by the built-in tier ids. */
|
|
32
|
+
const DEFAULT_TIER_ROUTES = {
|
|
33
|
+
T1: {
|
|
34
|
+
preferBackend: 'dsh',
|
|
35
|
+
escalateTo: 'T2',
|
|
36
|
+
dsh: [
|
|
37
|
+
{ provider: 'deepseek-account', model: 'deepseek-chat', note: 'Official DeepSeek fast chat model' },
|
|
38
|
+
{ provider: 'deepseek', model: 'deepseek-chat', note: 'DeepSeek API chat model' },
|
|
39
|
+
{ provider: 'open-design', model: 'deepseek-v4.1-flash-eco', reasoningEffort: 'low', note: 'Lowest cost fast eco model' },
|
|
40
|
+
{ provider: 'open-design', model: 'glm-5.3-flash', note: 'Fast general flash model' },
|
|
41
|
+
{ provider: 'open-design', model: 'mimo-v2.6-flash', note: 'Alternative flash executor' },
|
|
42
|
+
{ provider: 'gemini', model: 'gemini-3.5-flash-lite', note: 'Fast Gemini flash lite' },
|
|
43
|
+
{ provider: 'gemini', model: 'gemini-3.8-flash-low', note: 'Fast Gemini flash low' },
|
|
44
|
+
],
|
|
45
|
+
cli: [
|
|
46
|
+
{ backend: 'gemini', model: 'flash', note: 'Fast Gemini CLI flash' },
|
|
47
|
+
{ backend: 'antigravity', note: 'Antigravity CLI quick task' },
|
|
48
|
+
{ backend: 'claude', model: 'haiku', effort: 'low', note: 'Fast Claude Haiku' },
|
|
49
|
+
{ backend: 'opencode', note: 'OpenCode default lightweight run' },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
T2: {
|
|
53
|
+
preferBackend: 'dsh',
|
|
54
|
+
escalateTo: 'T3',
|
|
55
|
+
dsh: [
|
|
56
|
+
{ provider: 'deepseek-account', model: 'deepseek-chat', note: 'Official DeepSeek standard executor' },
|
|
57
|
+
{ provider: 'deepseek', model: 'deepseek-chat', note: 'DeepSeek API standard executor' },
|
|
58
|
+
{ provider: 'open-design', model: 'kimi-k2.7-code', note: 'Coding-specialized standard model' },
|
|
59
|
+
{ provider: 'open-design', model: 'deepseek-v4.1-flash', reasoningEffort: 'high', note: 'Balanced reasoning flash' },
|
|
60
|
+
{ provider: 'gemini', model: 'gemini-3.8-flash-high', note: 'Balanced Gemini flash high' },
|
|
61
|
+
{ provider: 'gemini', model: 'claude-sonnet-4-6', note: 'Claude Sonnet standard coding' },
|
|
62
|
+
],
|
|
63
|
+
cli: [
|
|
64
|
+
{ backend: 'codex', note: 'Codex CLI autonomous coding' },
|
|
65
|
+
{ backend: 'antigravity', note: 'Antigravity CLI coding' },
|
|
66
|
+
{ backend: 'opencode', note: 'OpenCode CLI coding' },
|
|
67
|
+
{ backend: 'claude', model: 'sonnet', effort: 'medium', note: 'Claude Sonnet standard' },
|
|
68
|
+
{ backend: 'gemini', model: 'pro', note: 'Gemini Pro CLI' },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
T3: {
|
|
72
|
+
preferBackend: 'auto',
|
|
73
|
+
escalateTo: null,
|
|
74
|
+
dsh: [
|
|
75
|
+
{ provider: 'deepseek-account', model: 'deepseek-reasoner', note: 'Official DeepSeek flagship reasoner' },
|
|
76
|
+
{ provider: 'deepseek', model: 'deepseek-reasoner', note: 'DeepSeek API flagship reasoner' },
|
|
77
|
+
{ provider: 'gemini', model: 'gemini-4-hydrogen-high', note: 'Frontier reasoning & coding' },
|
|
78
|
+
{ provider: 'open-design', model: 'deepseek-v4-pro', reasoningEffort: 'high', note: 'DeepSeek flagship Pro' },
|
|
79
|
+
{ provider: 'open-design-2', model: 'mimo-v2.6-pro', note: 'Pro fallback' },
|
|
80
|
+
],
|
|
81
|
+
cli: [
|
|
82
|
+
{ backend: 'claude', model: 'opus', effort: 'high', note: 'Claude Opus deep reasoning' },
|
|
83
|
+
{ backend: 'antigravity', note: 'Antigravity CLI deep execution' },
|
|
84
|
+
{ backend: 'codex', note: 'Codex CLI deep execution' },
|
|
85
|
+
{ backend: 'gemini', model: 'pro', note: 'Gemini Pro CLI' },
|
|
86
|
+
{ backend: 'opencode', note: 'OpenCode CLI' },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
T4: {
|
|
90
|
+
preferBackend: 'cli',
|
|
91
|
+
escalateTo: null,
|
|
92
|
+
dsh: [
|
|
93
|
+
{ provider: 'deepseek-account', model: 'deepseek-reasoner', note: 'DeepSeek independent reviewer' },
|
|
94
|
+
{ provider: 'deepseek', model: 'deepseek-reasoner', note: 'DeepSeek API reviewer' },
|
|
95
|
+
{ provider: 'gemini', model: 'gemini-4-hydrogen-high', note: 'Heterogeneous frontier reviewer' },
|
|
96
|
+
{ provider: 'open-design', model: 'deepseek-v4-pro', reasoningEffort: 'high', note: 'Flagship reviewer' },
|
|
97
|
+
],
|
|
98
|
+
cli: [
|
|
99
|
+
{ backend: 'claude', model: 'opus', effort: 'high', note: 'Claude Opus independent review' },
|
|
100
|
+
{ backend: 'antigravity', note: 'Antigravity CLI independent review' },
|
|
101
|
+
{ backend: 'codex', note: 'Codex CLI read-only review' },
|
|
102
|
+
{ backend: 'gemini', model: 'pro', note: 'Gemini Pro cross-family review' },
|
|
103
|
+
{ backend: 'opencode', note: 'OpenCode independent review' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Default difficulty tiers (routes + display metadata). The four built-in tiers
|
|
110
|
+
* remain the out-of-box layout; users may add, remove, or rename entries.
|
|
111
|
+
*/
|
|
112
|
+
export const DEFAULT_TIER_POLICIES = Object.fromEntries(
|
|
113
|
+
DEFAULT_TIER_SKELETON.map((tier) => {
|
|
114
|
+
const routes = DEFAULT_TIER_ROUTES[tier.id] || { preferBackend: 'auto', escalateTo: null, dsh: [], cli: [] }
|
|
115
|
+
return [tier.id, { ...tier, ...routes }]
|
|
116
|
+
}),
|
|
117
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Limited diagnostics built from the older `getState` endpoint.
|
|
3
|
+
*
|
|
4
|
+
* A link-installed plugin can ship a newer browser bundle while the DSH Host
|
|
5
|
+
* process still runs an older RPC contract. Instead of surfacing a raw
|
|
6
|
+
* `HTTP 404` for `diagnose`, the UI shows this degraded report plus a clear
|
|
7
|
+
* "restart DSH" instruction.
|
|
8
|
+
* @module dsh-agent-router/lib/diagnose-fallback
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function check(id, status, message, hint) {
|
|
12
|
+
return { id, status, message, ...(hint ? { hint } : {}) }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Record<string, any>} state Result of the legacy `getState` RPC.
|
|
17
|
+
* @returns {{
|
|
18
|
+
* ok: boolean,
|
|
19
|
+
* status: 'warn',
|
|
20
|
+
* checks: Array<{ id: string, status: 'ok'|'warn'|'fail', message: string, hint?: string }>,
|
|
21
|
+
* summary: { ok: number, warn: number, fail: number },
|
|
22
|
+
* suggestions: string[],
|
|
23
|
+
* degraded: true,
|
|
24
|
+
* }}
|
|
25
|
+
*/
|
|
26
|
+
export function buildLegacyDoctorReport(state) {
|
|
27
|
+
const checks = []
|
|
28
|
+
const catalog = Array.isArray(state?.catalog) ? state.catalog : []
|
|
29
|
+
const config = state?.config || {}
|
|
30
|
+
const subagent = state?.subagentModelSelection || {}
|
|
31
|
+
const localClis = state?.localClis && typeof state.localClis === 'object' ? state.localClis : {}
|
|
32
|
+
|
|
33
|
+
checks.push(check(
|
|
34
|
+
'host-rpc',
|
|
35
|
+
'warn',
|
|
36
|
+
'The running Host has not loaded the diagnose endpoint (HTTP 404).',
|
|
37
|
+
'Fully quit and relaunch DSH so the Host loads the current RPC contract, then run diagnostics again.',
|
|
38
|
+
))
|
|
39
|
+
|
|
40
|
+
checks.push(check(
|
|
41
|
+
'dsh-catalog',
|
|
42
|
+
catalog.length > 0 ? 'ok' : 'fail',
|
|
43
|
+
catalog.length > 0 ? `${catalog.length} DSH provider(s) reachable.` : 'No DSH LLM providers are registered.',
|
|
44
|
+
catalog.length > 0 ? undefined : 'Register at least one provider in DSH, or use local CLI routes only.',
|
|
45
|
+
))
|
|
46
|
+
|
|
47
|
+
if (subagent.available === false) {
|
|
48
|
+
checks.push(check('subagent-model-selection', 'warn', 'DSH subagent-model-selection is not exposed in this build.'))
|
|
49
|
+
} else if (subagent.enabled === false) {
|
|
50
|
+
checks.push(check('subagent-model-selection', 'warn', 'subagent-model-selection-settings is disabled.', 'Enable it and add tier models to allowedModels.'))
|
|
51
|
+
} else {
|
|
52
|
+
const allowed = Array.isArray(subagent.allowedModels) ? subagent.allowedModels.length : 0
|
|
53
|
+
checks.push(check('subagent-model-selection', 'ok', `Enabled with ${allowed} allowed model(s).`))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const installed = Object.keys(localClis).filter(name => localClis[name]?.installed)
|
|
57
|
+
checks.push(check(
|
|
58
|
+
'local-clis',
|
|
59
|
+
installed.length > 0 ? 'ok' : 'warn',
|
|
60
|
+
installed.length > 0 ? `Installed: ${installed.join(', ')}.` : 'No supported local agent CLI was found on PATH.',
|
|
61
|
+
installed.length > 0 ? undefined : 'Install claude, codex, gemini, opencode, or antigravity (agy), or keep DSH routes in each tier.',
|
|
62
|
+
))
|
|
63
|
+
|
|
64
|
+
checks.push(check(
|
|
65
|
+
'cli-selection',
|
|
66
|
+
'ok',
|
|
67
|
+
config.cliSelection === 'adaptive'
|
|
68
|
+
? 'CLI selection is adaptive.'
|
|
69
|
+
: 'CLI selection is static.',
|
|
70
|
+
))
|
|
71
|
+
|
|
72
|
+
checks.push(check(
|
|
73
|
+
'local-models',
|
|
74
|
+
'ok',
|
|
75
|
+
config.allowLocalModels === true
|
|
76
|
+
? 'Local models are enabled; route details need the full diagnose endpoint.'
|
|
77
|
+
: 'Local/self-hosted models are disabled (default).',
|
|
78
|
+
))
|
|
79
|
+
|
|
80
|
+
checks.push(check(
|
|
81
|
+
'cost-meter',
|
|
82
|
+
'ok',
|
|
83
|
+
state?.costMeter?.available ? 'dsh-cost-meter linked.' : 'dsh-cost-meter is not installed (optional).',
|
|
84
|
+
))
|
|
85
|
+
|
|
86
|
+
const summary = { ok: 0, warn: 0, fail: 0 }
|
|
87
|
+
for (const item of checks) summary[item.status] = (summary[item.status] ?? 0) + 1
|
|
88
|
+
return {
|
|
89
|
+
ok: summary.fail === 0,
|
|
90
|
+
status: 'warn',
|
|
91
|
+
checks,
|
|
92
|
+
summary,
|
|
93
|
+
suggestions: checks.filter(item => item.hint && item.status !== 'ok').map(item => item.hint),
|
|
94
|
+
degraded: true,
|
|
95
|
+
}
|
|
96
|
+
}
|