@deepseek-ai/dsh-tool-subagent 0.2.2-rc.5 → 0.2.3-alpha.1
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.i18n.yaml +22 -22
- package/README.md +14 -14
- package/README.zh.md +14 -14
- package/lib/index.js +83 -122
- package/lib/model-selection-settings.js +17 -67
- package/lib/types/index.d.ts +4 -4
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/list-models.d.ts +3 -6
- package/lib/types/list-models.d.ts.map +1 -1
- package/lib/types/list-models.js.map +1 -1
- package/lib/types/model-selection-settings.d.ts +11 -16
- package/lib/types/model-selection-settings.d.ts.map +1 -1
- package/lib/types/model-selection-settings.js.map +1 -1
- package/lib/types/model-selection-state.d.ts +6 -28
- package/lib/types/model-selection-state.d.ts.map +1 -1
- package/lib/types/model-selection-state.js.map +1 -1
- package/lib/types/model-selection.d.ts +31 -11
- package/lib/types/model-selection.d.ts.map +1 -1
- package/lib/types/model-selection.js.map +1 -1
- package/lib/types/preset-selection.d.ts +2 -1
- package/lib/types/preset-selection.d.ts.map +1 -1
- package/lib/types/preset-selection.js.map +1 -1
- package/package.json +23 -24
- package/src/index.ts +36 -33
- package/src/list-models.ts +22 -28
- package/src/model-selection-settings.ts +17 -52
- package/src/model-selection-state.ts +6 -49
- package/src/model-selection.ts +62 -32
- package/src/preset-selection.ts +7 -2
package/src/index.ts
CHANGED
|
@@ -9,18 +9,20 @@
|
|
|
9
9
|
import type { Context } from '@deepseek-ai/cordis'
|
|
10
10
|
import z from '@deepseek-ai/schemastery'
|
|
11
11
|
import type {} from '@deepseek-ai/dsh-agent-preset-registry'
|
|
12
|
-
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
12
|
+
import { defineTool, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools'
|
|
13
13
|
import type { ToolDefinition } from '@deepseek-ai/dsh-tools'
|
|
14
14
|
import type { AgentOptions } from '@deepseek-ai/dsh-agent'
|
|
15
|
-
import { ReasoningEffortId } from '@deepseek-ai/dsh-llm'
|
|
15
|
+
import type { ReasoningEffortId } from '@deepseek-ai/dsh-llm/types'
|
|
16
16
|
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
17
17
|
import {
|
|
18
18
|
assertSubagentMaxDepth,
|
|
19
19
|
delegationDepthOf,
|
|
20
20
|
parentAgentOptionsForDelegation,
|
|
21
|
+
SubagentError,
|
|
21
22
|
} from '@deepseek-ai/dsh-subagent'
|
|
22
23
|
import type { SubagentProvider } from '@deepseek-ai/dsh-subagent'
|
|
23
24
|
import {
|
|
25
|
+
delegationModelRequest,
|
|
24
26
|
hasConfiguredLlmSelection,
|
|
25
27
|
hasDelegationModelRequest,
|
|
26
28
|
preflightChildLlmRoute,
|
|
@@ -29,13 +31,12 @@ import {
|
|
|
29
31
|
import type { DelegationModelRequest } from './model-selection.ts'
|
|
30
32
|
import { registerListSubagentModels } from './list-models.ts'
|
|
31
33
|
import { SubagentPresetSelection, type PresetSelectionConfig, type PresetSelectionRequest } from './preset-selection.ts'
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from './model-selection-state.ts'
|
|
34
|
+
// Retains the released Session event declaration in emitted declarations.
|
|
35
|
+
import './model-selection-state.ts'
|
|
36
|
+
import type {} from './model-selection-settings.ts'
|
|
36
37
|
|
|
37
38
|
export const name = 'tool-subagent'
|
|
38
|
-
export const inject = ['tools', 'subagents', 'systemPrompt'
|
|
39
|
+
export const inject = ['tools', 'subagents', 'systemPrompt']
|
|
39
40
|
|
|
40
41
|
// Definition identity keeps shared guidance scoped to the actual visible tools,
|
|
41
42
|
// including scoped overrides and independently loaded tool registries.
|
|
@@ -52,8 +53,8 @@ export interface Config extends PresetSelectionConfig {
|
|
|
52
53
|
toolName?: string
|
|
53
54
|
/**
|
|
54
55
|
* Expose optional child `provider`, `model`, and `reasoning_effort` fields.
|
|
55
|
-
* Requires provider `agentOptions` support.
|
|
56
|
-
*
|
|
56
|
+
* Requires provider `agentOptions` support. Each call enforces the current
|
|
57
|
+
* Host setting, or restricts explicit selection to the current parent route.
|
|
57
58
|
*/
|
|
58
59
|
modelSelection?: boolean
|
|
59
60
|
/**
|
|
@@ -88,12 +89,12 @@ export const Config: z<Config> = z.object({
|
|
|
88
89
|
agentOptions: z.object({
|
|
89
90
|
provider: z.string(),
|
|
90
91
|
model: z.string(),
|
|
91
|
-
reasoningEffort: z.string().min(1) as z<
|
|
92
|
+
reasoningEffort: z.string().min(1) as z<ReasoningEffortId | undefined>,
|
|
92
93
|
maxTokens: z.number().step(1).min(1).max(Number.MAX_SAFE_INTEGER),
|
|
93
94
|
}).default(undefined as unknown as {
|
|
94
95
|
provider: string
|
|
95
96
|
model: string
|
|
96
|
-
reasoningEffort:
|
|
97
|
+
reasoningEffort: ReasoningEffortId
|
|
97
98
|
maxTokens: number
|
|
98
99
|
}),
|
|
99
100
|
agentPreset: z.string().min(1),
|
|
@@ -144,9 +145,8 @@ function providerWording(inheritsConversation: boolean): { description: string;
|
|
|
144
145
|
* The owning composition shares its registrations across Agents; child startup resolves the selected preset.
|
|
145
146
|
* @param ctx - Context that owns the registrations.
|
|
146
147
|
* @param config - delegation-tool configuration.
|
|
147
|
-
* @returns when the plugin is ready.
|
|
148
148
|
*/
|
|
149
|
-
export
|
|
149
|
+
export function apply(ctx: Context, config: Config): void {
|
|
150
150
|
for (const field of ['persona', 'toolFilter']) {
|
|
151
151
|
if (Object.hasOwn(config, field)) {
|
|
152
152
|
throw new Error(`tool-subagent: ${field} is no longer supported; configure persona and tool plugins in an Agent Preset and select it with agentPreset (spawn only)`)
|
|
@@ -162,7 +162,6 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
162
162
|
const toolName = config.toolName ?? 'subagent'
|
|
163
163
|
|
|
164
164
|
const modelSelectionEnabled = config.modelSelection === true
|
|
165
|
-
const subagentModelSelectionProjectionHandle = await ctx.sessionProjections.register(subagentModelSelectionProjectionDefinition)
|
|
166
165
|
|
|
167
166
|
const assertSubagentProviderConfiguration = (subagentProvider: SubagentProvider): void => {
|
|
168
167
|
presets.assertProvider(subagentProvider)
|
|
@@ -192,7 +191,7 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
192
191
|
const initialProvider = ctx.subagents.getProvider(config.provider)
|
|
193
192
|
if (initialProvider !== undefined) assertSubagentProviderConfiguration(initialProvider)
|
|
194
193
|
|
|
195
|
-
if (config.modelDiscovery === true) registerListSubagentModels(ctx
|
|
194
|
+
if (config.modelDiscovery === true) registerListSubagentModels(ctx)
|
|
196
195
|
|
|
197
196
|
// Load order and HMR replacement can change provider availability while
|
|
198
197
|
// this fiber remains active.
|
|
@@ -201,9 +200,11 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
201
200
|
assertSubagentProviderConfiguration(subagentProvider)
|
|
202
201
|
const wording = providerWording(subagentProvider.inheritsParentContext)
|
|
203
202
|
const providerRouteDefaults = subagentProvider.agentRouteDefaults
|
|
204
|
-
const
|
|
205
|
-
? '
|
|
206
|
-
: '
|
|
203
|
+
const defaultRoute = providerRouteDefaults !== undefined || hasConfiguredLlmSelection(config.agentOptions)
|
|
204
|
+
? 'the default model configured for this tool'
|
|
205
|
+
: 'your current model and reasoning effort'
|
|
206
|
+
// Discovery visibility is per Agent; only a same-instance owner is known to exist at mount.
|
|
207
|
+
const providerSource = config.modelDiscovery === true ? ' Use a provider id listed by `list_subagent_models`.' : ''
|
|
207
208
|
const definition = defineTool({
|
|
208
209
|
name: toolName,
|
|
209
210
|
description: wording.description
|
|
@@ -211,15 +212,10 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
211
212
|
+ (subagentProvider.prepareContinuable !== undefined
|
|
212
213
|
? ' Use `send_message` to steer it while running or continue its conversation after it finishes.'
|
|
213
214
|
: ' This backend does not accept follow-up messages.')
|
|
214
|
-
+ (modelSelectionEnabled ? selectionDescription : '')
|
|
215
215
|
+ (modelSelectionEnabled && subagentProvider.inheritsParentContext
|
|
216
216
|
? ' Changing the route can prevent provider-side reuse of the inherited conversation prefix.'
|
|
217
217
|
: ''),
|
|
218
218
|
parameters: {
|
|
219
|
-
cwd: {
|
|
220
|
-
type: 'string',
|
|
221
|
-
description: 'Initial child working directory. Relative paths use your current directory; omitted inherits it. Later directory changes in either agent are independent.',
|
|
222
|
-
},
|
|
223
219
|
description: {
|
|
224
220
|
type: 'string',
|
|
225
221
|
required: true,
|
|
@@ -246,7 +242,8 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
246
242
|
...modelSelectionEnabled ? {
|
|
247
243
|
provider: {
|
|
248
244
|
type: 'string' as const,
|
|
249
|
-
description: '
|
|
245
|
+
description: 'LLM provider id for the subagent; requires `model`. Set only when the task needs a different model; '
|
|
246
|
+
+ `omit \`provider\`, \`model\`, and \`reasoning_effort\` to run the subagent on ${defaultRoute}.${providerSource}`,
|
|
250
247
|
},
|
|
251
248
|
model: {
|
|
252
249
|
type: 'string' as const,
|
|
@@ -254,7 +251,7 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
254
251
|
},
|
|
255
252
|
reasoning_effort: {
|
|
256
253
|
type: 'string' as const,
|
|
257
|
-
description: 'Reasoning effort id; requires `provider` and `model`. Omit to use
|
|
254
|
+
description: 'Reasoning effort id; requires `provider` and `model`. Omit to use that model\'s default effort.',
|
|
258
255
|
},
|
|
259
256
|
} : {},
|
|
260
257
|
},
|
|
@@ -275,13 +272,15 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
275
272
|
const parent = exec.agent
|
|
276
273
|
if (!parent) {
|
|
277
274
|
// Non-agent callers provide no parent for delegation ownership.
|
|
278
|
-
throw new
|
|
275
|
+
throw new ToolContextUnavailableError('subagent tool requires a calling agent (exec.agent was undefined)')
|
|
279
276
|
}
|
|
280
277
|
|
|
281
|
-
const routes = subagentModelSelectionPolicy(subagentModelSelectionProjectionHandle, parent.session)
|
|
282
|
-
const modelSelectionPolicy = routes === undefined ? undefined : { routes }
|
|
283
278
|
const agentPreset = presets.resolve(args as PresetSelectionRequest)
|
|
284
|
-
const modelRequest = args as DelegationModelRequest
|
|
279
|
+
const modelRequest = delegationModelRequest(args as DelegationModelRequest)
|
|
280
|
+
const routes = modelSelectionEnabled && hasDelegationModelRequest(modelRequest)
|
|
281
|
+
? ctx.get('subagentModelSelection')?.allowedRoutes()
|
|
282
|
+
: undefined
|
|
283
|
+
const modelSelectionPolicy = routes === undefined ? undefined : { routes }
|
|
285
284
|
const parentOptions = parentAgentOptionsForDelegation(parent)
|
|
286
285
|
const requiresRoutePreflight = hasDelegationModelRequest(modelRequest)
|
|
287
286
|
|| hasConfiguredLlmSelection(config.agentOptions)
|
|
@@ -294,11 +293,12 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
294
293
|
modelSelectionEnabled,
|
|
295
294
|
modelSelectionPolicy,
|
|
296
295
|
parentOptions,
|
|
296
|
+
ctx.tools.get('list_subagent_models', parent, exec.toolSet) !== undefined,
|
|
297
297
|
)
|
|
298
298
|
if (requiresRoutePreflight) {
|
|
299
299
|
const llm = ctx.get('llm')
|
|
300
300
|
if (llm === undefined) {
|
|
301
|
-
throw new
|
|
301
|
+
throw new ToolContextUnavailableError('cannot resolve the selected child LLM route because the `llm` service is unavailable')
|
|
302
302
|
}
|
|
303
303
|
const inheritParentReasoningEffort = providerRouteDefaults === undefined && !hasDelegationModelRequest(modelRequest)
|
|
304
304
|
await preflightChildLlmRoute(
|
|
@@ -309,13 +309,15 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
309
309
|
inheritParentReasoningEffort,
|
|
310
310
|
)
|
|
311
311
|
if (ctx.subagents.getProvider(config.provider) !== subagentProvider) {
|
|
312
|
-
throw new
|
|
312
|
+
throw new SubagentError(
|
|
313
|
+
`subagent provider "${config.provider}" changed while resolving the child LLM route; retry the delegation`,
|
|
314
|
+
'PROVIDER_CHANGED',
|
|
315
|
+
)
|
|
313
316
|
}
|
|
314
317
|
}
|
|
315
318
|
exec.signal.throwIfAborted()
|
|
316
319
|
const maxDepth = ctx.subagents.resolveMaxDepth(config.maxDepth)
|
|
317
320
|
const request = {
|
|
318
|
-
...args.cwd === undefined ? {} : { cwd: args.cwd },
|
|
319
321
|
prompt: [{ type: 'text', text: args.prompt }] as ContentBlock[],
|
|
320
322
|
parent,
|
|
321
323
|
...agentPreset === undefined ? {} : { agentPreset },
|
|
@@ -365,6 +367,7 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
365
367
|
ctx.systemPrompt.section({
|
|
366
368
|
name: `tool:${toolName}`,
|
|
367
369
|
order: ctx.systemPrompt.getSectionOrder('TOOL_SUBAGENT'),
|
|
370
|
+
retirement: `The ${toolName} tool is no longer available. Its instructions no longer apply.`,
|
|
368
371
|
text: (context) => {
|
|
369
372
|
if (mounted === undefined) return ''
|
|
370
373
|
const visible = [...delegationTools]
|
|
@@ -373,7 +376,7 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
|
|
|
373
376
|
.sort()
|
|
374
377
|
if (visible[0] !== toolName) return ''
|
|
375
378
|
const names = visible.map(name => `\`${name}\``).join(' or ')
|
|
376
|
-
return `Start independent delegations with ${names} together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn. Collect the subagent results required to complete the task before giving the user a final answer.\n\nBash, formatters, code generators, and scripts can overwrite concurrent edits without conflict detection; coordinate their changes explicitly. The agent integrating the work must review the final diff and run relevant tests.`
|
|
379
|
+
return `Start independent delegations with ${names} together in one assistant message and continue useful work while they run. The concurrency limit of all the subagents is ${ctx.subagents.maxActiveSubagents}. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn. Collect the subagent results required to complete the task before giving the user a final answer.\n\nBash, formatters, code generators, and scripts can overwrite concurrent edits without conflict detection; coordinate their changes explicitly. The agent integrating the work must review the final diff and run relevant tests.`
|
|
377
380
|
},
|
|
378
381
|
})
|
|
379
382
|
ctx.systemPrompt.context({
|
package/src/list-models.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
import type { Context } from '@deepseek-ai/cordis'
|
|
4
4
|
import type LlmRuntime from '@deepseek-ai/dsh-llm'
|
|
5
5
|
import type { LlmProviderInfo } from '@deepseek-ai/dsh-llm'
|
|
6
|
-
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
7
|
-
import { parentAgentOptionsForDelegation } from '@deepseek-ai/dsh-subagent'
|
|
6
|
+
import { defineTool, ToolArgsError, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools'
|
|
7
|
+
import { parentAgentOptionsForDelegation, SubagentError } from '@deepseek-ai/dsh-subagent'
|
|
8
8
|
import type { ToolRunContext } from '@deepseek-ai/dsh-tools'
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import {
|
|
9
|
+
import type { ModelSelectionPolicy } from './model-selection.ts'
|
|
10
|
+
import type {} from './model-selection-settings.ts'
|
|
11
|
+
import { hasText } from './model-selection.ts'
|
|
12
12
|
|
|
13
13
|
interface ListSubagentModelsRequest {
|
|
14
14
|
readonly provider?: string
|
|
@@ -28,7 +28,7 @@ function registeredProvider(
|
|
|
28
28
|
.filter(candidate => policy.routes.some(route => route.provider === candidate.id))
|
|
29
29
|
.map(candidate => candidate.id)
|
|
30
30
|
.join(', ') || '(none)'
|
|
31
|
-
throw new
|
|
31
|
+
throw new SubagentError(`LLM provider "${providerId}" is not registered; available providers: ${available}`, 'LLM_PROVIDER_NOT_FOUND')
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** Render one advertised or resolved model. */
|
|
@@ -39,28 +39,27 @@ function modelLine(provider: string, model: { id: string; name: string; descript
|
|
|
39
39
|
/** Read the requested provider, allowed models, or exact-model efforts. */
|
|
40
40
|
async function listSubagentModels(
|
|
41
41
|
ctx: Context,
|
|
42
|
-
policyHandle: ProjectionHandle<AllowedModelRoute[] | null>,
|
|
43
42
|
request: ListSubagentModelsRequest,
|
|
44
43
|
exec: ToolRunContext,
|
|
45
44
|
): Promise<string> {
|
|
46
|
-
if (exec.agent === undefined) throw new
|
|
47
|
-
const routes =
|
|
45
|
+
if (exec.agent === undefined) throw new ToolContextUnavailableError('list_subagent_models requires a calling agent')
|
|
46
|
+
const routes = ctx.get('subagentModelSelection')?.allowedRoutes()
|
|
48
47
|
let policy = routes === undefined ? undefined : { routes }
|
|
49
48
|
const selectionEnabled = policy !== undefined
|
|
50
49
|
if (policy === undefined) {
|
|
51
50
|
const { provider, model } = parentAgentOptionsForDelegation(exec.agent)
|
|
52
51
|
if (provider === undefined || model === undefined) {
|
|
53
|
-
throw new
|
|
52
|
+
throw new ToolContextUnavailableError('cannot discover child LLM routes without a parent provider and model')
|
|
54
53
|
}
|
|
55
54
|
policy = { routes: [{ provider, model }] }
|
|
56
55
|
}
|
|
57
56
|
const { signal } = exec
|
|
58
57
|
const llm = ctx.get('llm')
|
|
59
58
|
if (llm === undefined) {
|
|
60
|
-
throw new
|
|
59
|
+
throw new ToolContextUnavailableError('cannot discover child LLM routes because the `llm` service is unavailable')
|
|
61
60
|
}
|
|
62
61
|
if (request.model !== undefined && request.provider === undefined) {
|
|
63
|
-
throw new
|
|
62
|
+
throw new ToolArgsError(['`model` requires `provider`'])
|
|
64
63
|
}
|
|
65
64
|
if (request.provider === undefined) {
|
|
66
65
|
const providers = llm.listProviders()
|
|
@@ -69,11 +68,10 @@ async function listSubagentModels(
|
|
|
69
68
|
? '(no LLM providers)'
|
|
70
69
|
: providers.map(provider => `${provider.id} — ${provider.name}`).join('\n')
|
|
71
70
|
}
|
|
72
|
-
if (request.provider.length === 0) throw new Error('`provider` must be non-empty')
|
|
73
71
|
const allowedRoutes = policy.routes.filter(route => route.provider === request.provider)
|
|
74
72
|
const [firstRoute] = allowedRoutes
|
|
75
73
|
if (firstRoute === undefined) {
|
|
76
|
-
throw new
|
|
74
|
+
throw new SubagentError(`LLM provider "${request.provider}" is not allowed by the current subagent model selection setting`, 'MODEL_ROUTE_NOT_ALLOWED')
|
|
77
75
|
}
|
|
78
76
|
const provider = registeredProvider(llm, policy, request.provider)
|
|
79
77
|
if (request.model === undefined) {
|
|
@@ -85,9 +83,8 @@ async function listSubagentModels(
|
|
|
85
83
|
? `(no advertised models for ${provider.id})`
|
|
86
84
|
: models.map(model => modelLine(provider.id, model)).join('\n')
|
|
87
85
|
}
|
|
88
|
-
if (request.model.length === 0) throw new Error('`model` must be non-empty')
|
|
89
86
|
if (!allowedRoutes.some(route => route.model === request.model)) {
|
|
90
|
-
throw new
|
|
87
|
+
throw new SubagentError(`child LLM route "${provider.id}/${request.model}" is not allowed by the current subagent model selection setting`, 'MODEL_ROUTE_NOT_ALLOWED')
|
|
91
88
|
}
|
|
92
89
|
const model = await llm.resolveModelInfo(provider.id, request.model, signal)
|
|
93
90
|
const efforts = model.reasoning?.efforts.map(effort => (
|
|
@@ -98,25 +95,19 @@ async function listSubagentModels(
|
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
/**
|
|
101
|
-
* Register discovery of the
|
|
102
|
-
* @param ctx - Context carrying the tool registry and
|
|
103
|
-
* @param policyHandle - retained reader for the Session’s authorized child routes.
|
|
98
|
+
* Register discovery of the child models the Host setting authorizes.
|
|
99
|
+
* @param ctx - Context carrying the tool registry, LLM service, and optional Host model-selection setting.
|
|
104
100
|
*/
|
|
105
|
-
export function registerListSubagentModels(
|
|
106
|
-
ctx: Context,
|
|
107
|
-
policyHandle: ProjectionHandle<AllowedModelRoute[] | null>,
|
|
108
|
-
): void {
|
|
101
|
+
export function registerListSubagentModels(ctx: Context): void {
|
|
109
102
|
ctx.tools.register(defineTool({
|
|
110
103
|
name: 'list_subagent_models',
|
|
111
104
|
description:
|
|
112
105
|
'Inspect the routes available for explicit subagent model selection. No arguments: authorized providers. '
|
|
113
|
-
+ '`provider`: that provider\'s authorized models. `provider` + `model`: that model and its reasoning efforts.
|
|
114
|
-
+ 'Query when choosing an explicit child route or reasoning effort. '
|
|
115
|
-
+ 'Omit optional fields rather than sending empty strings.',
|
|
106
|
+
+ '`provider`: that provider\'s authorized models. `provider` + `model`: that model and its reasoning efforts.',
|
|
116
107
|
parameters: {
|
|
117
108
|
provider: {
|
|
118
109
|
type: 'string',
|
|
119
|
-
description: '
|
|
110
|
+
description: 'Provider id from the no-argument listing.',
|
|
120
111
|
},
|
|
121
112
|
model: {
|
|
122
113
|
type: 'string',
|
|
@@ -130,7 +121,10 @@ export function registerListSubagentModels(
|
|
|
130
121
|
// Route and model metadata reads do not mutate parent-agent state.
|
|
131
122
|
isConcurrencySafe: () => true,
|
|
132
123
|
execute(args, exec) {
|
|
133
|
-
return listSubagentModels(ctx,
|
|
124
|
+
return listSubagentModels(ctx, {
|
|
125
|
+
...hasText(args.provider) ? { provider: args.provider } : {},
|
|
126
|
+
...hasText(args.model) ? { model: args.model } : {},
|
|
127
|
+
}, exec)
|
|
134
128
|
},
|
|
135
129
|
}))
|
|
136
130
|
}
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
import type { Volatile } from '@deepseek-ai/cordis'
|
|
3
3
|
|
|
4
4
|
import { Context, Service } from '@deepseek-ai/cordis'
|
|
5
|
+
import { SubagentError } from '@deepseek-ai/dsh-subagent'
|
|
5
6
|
import z from '@deepseek-ai/schemastery'
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
subagentModelSelectionPolicy,
|
|
10
|
-
subagentModelSelectionProjectionDefinition,
|
|
11
|
-
} from './model-selection-state.ts'
|
|
7
|
+
// Retains the released Session event declaration in emitted declarations.
|
|
8
|
+
import './model-selection-state.ts'
|
|
12
9
|
import {
|
|
13
10
|
AllowedModelRouteSchema,
|
|
14
11
|
assertAllowedModelRoutes,
|
|
@@ -17,31 +14,21 @@ import {
|
|
|
17
14
|
|
|
18
15
|
declare module '@deepseek-ai/cordis' {
|
|
19
16
|
interface Context {
|
|
20
|
-
/** User preference
|
|
17
|
+
/** User preference read for explicit child route selection and route discovery. */
|
|
21
18
|
subagentModelSelection: SubagentModelSelectionConfig
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
/**
|
|
26
|
-
export interface SubagentModelSelectionSettings {
|
|
27
|
-
/** Whether new top-level Sessions receive model selection. */
|
|
28
|
-
enabled: boolean
|
|
29
|
-
/** Exact child LLM routes offered to new top-level Sessions. */
|
|
30
|
-
allowedModels: AllowedModelRoute[]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Optional deployment base for the preference. */
|
|
22
|
+
/** Optional deployment base for the preference; the shipped composition defaults it off. */
|
|
34
23
|
export interface Config {
|
|
35
|
-
/**
|
|
24
|
+
/** Whether Agents may select a child route from `allowedModels`; inherited when the user document does not override it. */
|
|
36
25
|
enabled: Volatile<boolean>
|
|
37
26
|
/** Initial route list inherited when the user document does not override it. */
|
|
38
27
|
allowedModels: Volatile<AllowedModelRoute[]>
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
/** Host settings owner
|
|
30
|
+
/** Host settings owner whose current value authorizes explicit child routes in every Session. */
|
|
42
31
|
export class SubagentModelSelectionConfig extends Service {
|
|
43
|
-
static inject = ['sessionProjections', 'sessions']
|
|
44
|
-
|
|
45
32
|
static Config = z.object({
|
|
46
33
|
enabled: z.boolean().default(false).volatile(),
|
|
47
34
|
allowedModels: z.array(AllowedModelRouteSchema).default([]).volatile(),
|
|
@@ -51,44 +38,22 @@ export class SubagentModelSelectionConfig extends Service {
|
|
|
51
38
|
super(ctx, 'subagentModelSelection')
|
|
52
39
|
}
|
|
53
40
|
|
|
54
|
-
protected async [Service.init](): Promise<void> {
|
|
55
|
-
const ctx = this.ctx
|
|
56
|
-
const policyReady = ctx.sessionProjections.register(subagentModelSelectionProjectionDefinition)
|
|
57
|
-
ctx.on('agent/created', async ({ agent }) => {
|
|
58
|
-
const policy = await policyReady
|
|
59
|
-
ctx.fiber.assertActive()
|
|
60
|
-
const target = agent.session
|
|
61
|
-
if (subagentModelSelectionPolicy(policy, target) !== undefined) return
|
|
62
|
-
let allowedModels: AllowedModelRoute[] | undefined
|
|
63
|
-
const parentId = target.header.origin === 'subagent' ? target.header.parentSession : undefined
|
|
64
|
-
if (parentId !== undefined) {
|
|
65
|
-
const parent = ctx.sessions.get(parentId)
|
|
66
|
-
if (parent !== undefined) allowedModels = subagentModelSelectionPolicy(policy, parent)
|
|
67
|
-
} else if (target.firstLiveSeq === 0
|
|
68
|
-
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
|
|
69
|
-
&& target.eventAt(SessionSeq(0))?.type !== 'session/end-seed') {
|
|
70
|
-
const current = this.current()
|
|
71
|
-
allowedModels = current.enabled ? current.allowedModels : undefined
|
|
72
|
-
}
|
|
73
|
-
if (allowedModels !== undefined) target.append('subagent/model-selection-policy', { allowedModels })
|
|
74
|
-
})
|
|
75
|
-
await policyReady
|
|
76
|
-
}
|
|
77
|
-
|
|
78
41
|
/**
|
|
79
|
-
* Read
|
|
80
|
-
*
|
|
42
|
+
* Read the routes the setting currently authorizes. Each call samples the
|
|
43
|
+
* live setting, so an edit applies to the next delegation in every Session.
|
|
44
|
+
* @returns a detached route list, or undefined when the setting is disabled.
|
|
45
|
+
* @throws {SubagentError} `INVALID_MODEL_SELECTION_SETTINGS` when the enabled setting has no route,
|
|
46
|
+
* or its routes are malformed or repeated. Disabled settings do not read or validate routes.
|
|
81
47
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
48
|
+
allowedRoutes(): AllowedModelRoute[] | undefined {
|
|
49
|
+
if (!this.config.enabled.get()) return undefined
|
|
84
50
|
const allowedModels = this.config.allowedModels.get()
|
|
85
51
|
assertAllowedModelRoutes(allowedModels)
|
|
86
|
-
if (
|
|
87
|
-
throw new
|
|
52
|
+
if (allowedModels.length === 0) {
|
|
53
|
+
throw new SubagentError('enabled subagent model selection requires at least one allowed model', 'INVALID_MODEL_SELECTION_SETTINGS')
|
|
88
54
|
}
|
|
89
|
-
return
|
|
55
|
+
return allowedModels.map(route => ({ ...route }))
|
|
90
56
|
}
|
|
91
|
-
|
|
92
57
|
}
|
|
93
58
|
|
|
94
59
|
export const name = 'subagent-model-selection-settings'
|
|
@@ -1,60 +1,17 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Session event type retained from the earlier durable model-selection policy. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import type { Session } from '@deepseek-ai/dsh-session'
|
|
5
|
-
import type { ProjectionHandle } from '@deepseek-ai/dsh-session-projection'
|
|
6
|
-
import type { ProjectionDefinition } from '@deepseek-ai/dsh-session-projection'
|
|
7
|
-
import { assertAllowedModelRoutes, type AllowedModelRoute } from './model-selection.ts'
|
|
3
|
+
import type { AllowedModelRoute } from './model-selection.ts'
|
|
8
4
|
|
|
9
5
|
declare module '@deepseek-ai/dsh-session/types' {
|
|
10
6
|
interface SessionEventMap {
|
|
11
7
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* no `surfaceOp` and never enters model history.
|
|
8
|
+
* Child provider/model routes recorded by earlier releases. Current
|
|
9
|
+
* releases neither append nor read it: delegation reads the Host setting
|
|
10
|
+
* at each call. Log-only: it carries no `surfaceOp` and never enters model history.
|
|
16
11
|
*/
|
|
17
12
|
'subagent/model-selection-policy': {
|
|
18
|
-
/** Exact routes
|
|
13
|
+
/** Exact routes the Session could select explicitly for a child. */
|
|
19
14
|
allowedModels: AllowedModelRoute[]
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
17
|
}
|
|
23
|
-
|
|
24
|
-
const modelSelectionPolicySchema: zod.ZodType<AllowedModelRoute[] | null> = zod.array(zod.object({
|
|
25
|
-
provider: zod.string().min(1),
|
|
26
|
-
model: zod.string().min(1),
|
|
27
|
-
}).strict()).min(1).nullable()
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Host-only projection of the durable model-selection policy.
|
|
31
|
-
* Each independently mounted consumer registers this shared definition; the registry reference-counts it.
|
|
32
|
-
*/
|
|
33
|
-
export const subagentModelSelectionProjectionDefinition = {
|
|
34
|
-
key: 'subagentModelSelectionPolicy',
|
|
35
|
-
stateVersion: 1,
|
|
36
|
-
stateSchema: modelSelectionPolicySchema,
|
|
37
|
-
init: () => null,
|
|
38
|
-
apply: (policy, event) => {
|
|
39
|
-
if (policy !== null || event.type !== 'subagent/model-selection-policy') return policy
|
|
40
|
-
const { allowedModels } = event.data
|
|
41
|
-
assertAllowedModelRoutes(allowedModels)
|
|
42
|
-
if (allowedModels.length === 0) {
|
|
43
|
-
throw new Error('subagent/model-selection-policy requires at least one route')
|
|
44
|
-
}
|
|
45
|
-
return allowedModels
|
|
46
|
-
},
|
|
47
|
-
} satisfies ProjectionDefinition<'subagentModelSelectionPolicy', AllowedModelRoute[] | null>
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Read the exact route list authorized for a Session.
|
|
51
|
-
* @param subagentModelSelectionProjectionHandle - registered policy state reader.
|
|
52
|
-
* @param session - session whose durable decision is read.
|
|
53
|
-
* @returns a detached route list, or undefined to restrict selection to the parent route.
|
|
54
|
-
*/
|
|
55
|
-
export function subagentModelSelectionPolicy(
|
|
56
|
-
subagentModelSelectionProjectionHandle: Pick<ProjectionHandle<AllowedModelRoute[] | null>, 'stateOf'>,
|
|
57
|
-
session: Session,
|
|
58
|
-
): AllowedModelRoute[] | undefined {
|
|
59
|
-
return subagentModelSelectionProjectionHandle.stateOf(session)?.map(route => ({ ...route }))
|
|
60
|
-
}
|