dsh-plugin-subagent-director 0.1.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +135 -0
  4. package/lib/bridge-contract.d.ts +41 -0
  5. package/lib/bridge-contract.d.ts.map +1 -0
  6. package/lib/bridge-contract.js +7 -0
  7. package/lib/bridge-contract.js.map +1 -0
  8. package/lib/bridge-entry.d.ts +29 -0
  9. package/lib/bridge-entry.d.ts.map +1 -0
  10. package/lib/bridge-entry.js +10 -0
  11. package/lib/bridge-entry.js.map +1 -0
  12. package/lib/client/RoleCard.d.ts +23 -0
  13. package/lib/client/RoleCard.d.ts.map +1 -0
  14. package/lib/client/RoleCard.js +72 -0
  15. package/lib/client/RoleCard.js.map +1 -0
  16. package/lib/client/SubagentModelDock.d.ts +29 -0
  17. package/lib/client/SubagentModelDock.d.ts.map +1 -0
  18. package/lib/client/SubagentModelDock.js +32 -0
  19. package/lib/client/SubagentModelDock.js.map +1 -0
  20. package/lib/client/SubagentOptionsSection.d.ts +23 -0
  21. package/lib/client/SubagentOptionsSection.d.ts.map +1 -0
  22. package/lib/client/SubagentOptionsSection.js +164 -0
  23. package/lib/client/SubagentOptionsSection.js.map +1 -0
  24. package/lib/client/index.d.ts +44 -0
  25. package/lib/client/index.d.ts.map +1 -0
  26. package/lib/client/index.js +1541 -0
  27. package/lib/client/index.js.map +1 -0
  28. package/lib/client/locales.d.ts +13 -0
  29. package/lib/client/locales.d.ts.map +1 -0
  30. package/lib/client/locales.js +107 -0
  31. package/lib/client/locales.js.map +1 -0
  32. package/lib/client/store-logic.d.ts +105 -0
  33. package/lib/client/store-logic.d.ts.map +1 -0
  34. package/lib/client/store-logic.js +143 -0
  35. package/lib/client/store-logic.js.map +1 -0
  36. package/lib/client/store.d.ts +104 -0
  37. package/lib/client/store.d.ts.map +1 -0
  38. package/lib/client/store.js +223 -0
  39. package/lib/client/store.js.map +1 -0
  40. package/lib/client/subagent-model.d.ts +47 -0
  41. package/lib/client/subagent-model.d.ts.map +1 -0
  42. package/lib/client/subagent-model.js +81 -0
  43. package/lib/client/subagent-model.js.map +1 -0
  44. package/lib/client/ui.d.ts +26 -0
  45. package/lib/client/ui.d.ts.map +1 -0
  46. package/lib/client/ui.js +102 -0
  47. package/lib/client/ui.js.map +1 -0
  48. package/lib/config.d.ts +63 -0
  49. package/lib/config.d.ts.map +1 -0
  50. package/lib/config.js +26 -0
  51. package/lib/config.js.map +1 -0
  52. package/lib/delegation-tool.d.ts +169 -0
  53. package/lib/delegation-tool.d.ts.map +1 -0
  54. package/lib/delegation-tool.js +404 -0
  55. package/lib/delegation-tool.js.map +1 -0
  56. package/lib/envelope.d.ts +97 -0
  57. package/lib/envelope.d.ts.map +1 -0
  58. package/lib/envelope.js +136 -0
  59. package/lib/envelope.js.map +1 -0
  60. package/lib/guidance.d.ts +37 -0
  61. package/lib/guidance.d.ts.map +1 -0
  62. package/lib/guidance.js +46 -0
  63. package/lib/guidance.js.map +1 -0
  64. package/lib/index.d.ts +29 -0
  65. package/lib/index.d.ts.map +1 -0
  66. package/lib/index.js +63 -0
  67. package/lib/index.js.map +1 -0
  68. package/lib/remote.d.ts +102 -0
  69. package/lib/remote.d.ts.map +1 -0
  70. package/lib/remote.js +254 -0
  71. package/lib/remote.js.map +1 -0
  72. package/lib/route-resolver.d.ts +118 -0
  73. package/lib/route-resolver.d.ts.map +1 -0
  74. package/lib/route-resolver.js +71 -0
  75. package/lib/route-resolver.js.map +1 -0
  76. package/lib/settings.d.ts +157 -0
  77. package/lib/settings.d.ts.map +1 -0
  78. package/lib/settings.js +118 -0
  79. package/lib/settings.js.map +1 -0
  80. package/package.json +110 -0
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Delegation tool subagent_role (design section 7).
3
+ *
4
+ * A model-facing tool that lets the calling agent delegate to a subagent while
5
+ * selecting an LLM route and/or a named role template. It resolves the four-layer
6
+ * fallback chain via the pure resolveRoute (design section 6), validates the
7
+ * resolution against live runtime facts, and assembles a SubagentStartRequest
8
+ * on ctx.subagents.start(...) exactly like dsh-workflow-worker-thread's
9
+ * startChild and dsh-tool-subagent's one-shot path.
10
+ *
11
+ * Two provider namespaces coexist and MUST NOT be confused (design section 14, R2):
12
+ * - config.subagentProvider is the subagent TRANSPORT provider name handed
13
+ * to ctx.subagents.start(name, ...) (e.g. spawn).
14
+ * - the resolved agentOptions.provider is an LLM route served by an adapter
15
+ * (e.g. deepseek-official).
16
+ *
17
+ * Execution contract (schema/execute mirror dsh-tool-subagent):
18
+ * - foreground is the core path: await run.result, throw a stop-reason
19
+ * error for a non-completed child, dispose idempotently, return
20
+ * { kind: foreground, runId, output }.
21
+ * - one-shot background mirrors the official Task registration on
22
+ * ctx.jobs.start({ kind: subagent, ... }) returning { kind: background, jobId }.
23
+ * - continuable runs the child through ctx.subagents.startContinuable() and
24
+ * returns { kind: continuable, subagentId } (the durable child id), which the
25
+ * parent later follows up on with send_message (M3a / FR-5.3).
26
+ *
27
+ * reasoningEffort: the DSH AgentOptions and SubagentStartRequest shapes do
28
+ * not carry reasoning effort (dsh-agent runtime-types.d.ts, dsh-subagent
29
+ * types.d.ts), so it is surfaced and logged only, never injected (route-resolver
30
+ * already returns it separately for auditability).
31
+ */
32
+ import type { Context } from '@deepseek-ai/cordis';
33
+ import type { Agent, AgentOptions } from '@deepseek-ai/dsh-agent';
34
+ import { type JsonValue, type ParameterSchemaSpec, type ValueSchemaSpec } from '@deepseek-ai/dsh-tools';
35
+ import type { ContentBlock } from '@deepseek-ai/dsh-llm';
36
+ import type { SubagentProvider } from '@deepseek-ai/dsh-subagent';
37
+ import type { DirectorConfig } from './config.js';
38
+ import { type RouteToolFilter, type SubagentDirectorSettings } from './route-resolver.js';
39
+ /** Stable log namespace prefix for delegation/tool diagnostics (design section 10). */
40
+ export declare const DELEGATION_TOOL_PREFIX = "subagent-director";
41
+ /**
42
+ * Delegate a task to a role-bound subagent with an optional LLM route override.
43
+ * Resolves role/model/provider through the configure -> role -> default ->
44
+ * inherit chain; role persona and tool filtering are applied when the chosen
45
+ * subagent transport supports them.
46
+ */
47
+ export interface DelegationToolArgs {
48
+ /** A short (3-5 word) description of the delegated task, for display. */
49
+ description: string;
50
+ /** The complete, self-contained task for the subagent. */
51
+ prompt: string;
52
+ /** Role template id (optional). Falls back to the configured default role. */
53
+ role?: string;
54
+ /** LLM provider route override (optional). Wins over any role binding. */
55
+ provider?: string;
56
+ /** Model id override (optional). Wins over any role binding. */
57
+ model?: string;
58
+ /** Reasoning-effort override (optional; advisory — logged, not injected). */
59
+ reasoningEffort?: string;
60
+ /**
61
+ * Whether to run in the background. Defaults to false in one-shot mode; in
62
+ * continuable mode it defaults to true and returns the durable child id for
63
+ * later send_message follow-up.
64
+ */
65
+ run_in_background?: boolean;
66
+ }
67
+ /**
68
+ * Build the model-facing tool parameter schema given a config. Exposed as a
69
+ * pure function so unit tests can assert the model-visible shape without a live
70
+ * context: description/prompt are required; role/provider/model/reasoningEffort
71
+ * are optional; run_in_background appears only when enableRunInBackground is not
72
+ * false. In continuable mode its description notes the default of true and the
73
+ * durable-child-id return shape (mirrors dsh-tool-subagent's wording).
74
+ */
75
+ export declare function createDelegationParameters(config: Pick<DirectorConfig, 'enableRunInBackground' | 'backgroundMode'>): ParameterSchemaSpec;
76
+ /** The model-facing output schema: exactly one of background, continuable, or foreground. */
77
+ export declare function createDelegationOutputSchema(): ValueSchemaSpec;
78
+ /** The resolved execution route for one delegation call. */
79
+ export type DelegationRoute = 'foreground' | 'one-shot' | 'continuable';
80
+ /** The mode decision for one delegation: whether to run in the background, and which route to use. */
81
+ export interface DelegationModeDecision {
82
+ runInBackground: boolean;
83
+ route: DelegationRoute;
84
+ }
85
+ /**
86
+ * Pure mode decision (extracted for unit testing) mirroring dsh-tool-subagent's
87
+ * resolveDelegationRun: a forced background while the flag is disabled is
88
+ * rejected; otherwise background defaults to the configured mode's policy —
89
+ * false for one-shot, true for continuable.
90
+ */
91
+ export declare function resolveDelegationMode(request: Pick<DelegationToolArgs, 'run_in_background'>, options: {
92
+ backgroundEnabled: boolean;
93
+ continuable: boolean;
94
+ }): DelegationModeDecision;
95
+ /** The union of delegation result shapes produced by execute. */
96
+ export type DelegationResult = {
97
+ kind: 'background';
98
+ jobId: string;
99
+ } | {
100
+ kind: 'continuable';
101
+ subagentId: string;
102
+ } | {
103
+ kind: 'foreground';
104
+ runId: string;
105
+ output: JsonValue[];
106
+ };
107
+ /**
108
+ * Pure renderer for a delegation result (extracted for unit testing). Mirrors
109
+ * dsh-tool-subagent's output.render: a continuable child renders as
110
+ * "started subagent <id>"; a one-shot task keeps its tool-name-qualified text;
111
+ * a foreground result emits its joined text blocks.
112
+ */
113
+ export declare function renderDelegationResult(value: DelegationResult | {
114
+ kind: 'foreground';
115
+ output: object[];
116
+ }, toolName: string): string;
117
+ /**
118
+ * Pure capability gate (extracted from execute for unit testing, behavioral
119
+ * no-op): a resolved delegation feature demands a transport-provider capability,
120
+ * and its absence is a hard error (FR-8.1 / design 7.3). persona, toolFilter,
121
+ * and a numeric maxDepth each require the matching capability flag.
122
+ */
123
+ export declare function assertDelegationCapabilities(options: {
124
+ providerName: string;
125
+ persona?: string;
126
+ toolFilter?: RouteToolFilter;
127
+ capabilities: {
128
+ persona: boolean;
129
+ toolFilter: boolean;
130
+ depthLimit: boolean;
131
+ };
132
+ maxDepth?: number | 'provider-managed';
133
+ }): void;
134
+ /** The route-derived fields that flow into a SubagentStartRequest body. */
135
+ export interface SubagentRequestParts {
136
+ description: string;
137
+ prompt: ContentBlock[];
138
+ parent: Agent;
139
+ agentOptions?: Pick<AgentOptions, 'provider' | 'model'>;
140
+ persona?: string;
141
+ toolFilter?: RouteToolFilter;
142
+ maxDepth?: number;
143
+ }
144
+ /**
145
+ * Pure request-body assembly (extracted from execute for unit testing,
146
+ * behavioral no-op): persona and toolFilter propagate into the request only
147
+ * when the role resolved them, so a bare delegation stays zero-intrusion.
148
+ */
149
+ export declare function buildSubagentRequest<Parts extends SubagentRequestParts>(parts: Parts): {
150
+ label: string;
151
+ prompt: ContentBlock[];
152
+ parent: Agent;
153
+ agentOptions?: Pick<AgentOptions, "model" | "provider"> | undefined;
154
+ persona?: string | undefined;
155
+ toolFilter?: RouteToolFilter | undefined;
156
+ maxDepth?: number | undefined;
157
+ };
158
+ /**
159
+ * Create the subagent_role ToolDefinition for one mounted subagent transport
160
+ * provider. getSettings returns the current settings snapshot so execute reads
161
+ * live role/default layers.
162
+ */
163
+ export declare function createDelegationTool(options: {
164
+ ctx: Context;
165
+ config: DirectorConfig;
166
+ provider: SubagentProvider;
167
+ getSettings: () => SubagentDirectorSettings;
168
+ }): import("@deepseek-ai/dsh-tools").ToolDefinition;
169
+ //# sourceMappingURL=delegation-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation-tool.d.ts","sourceRoot":"","sources":["../src/delegation-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAc,KAAK,SAAS,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEpH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAA+B,MAAM,2BAA2B,CAAC;AAE/F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAExG,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAK1D;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;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ools';
2
+ import { settleRun } from '@deepseek-ai/dsh-subagent';
3
+ import { resolveRoute } from './route-resolver.js';
4
+ /** Stable log namespace prefix for delegation/tool diagnostics (design section 10). */
5
+ export const DELEGATION_TOOL_PREFIX = 'subagent-director';
6
+ /** The canonical error prefix used across all structured failures (FR-8.1 / design 7.3). */
7
+ const ERROR_PREFIX = 'subagent-director:';
8
+ /**
9
+ * Build the model-facing tool parameter schema given a config. Exposed as a
10
+ * pure function so unit tests can assert the model-visible shape without a live
11
+ * context: description/prompt are required; role/provider/model/reasoningEffort
12
+ * are optional; run_in_background appears only when enableRunInBackground is not
13
+ * false. In continuable mode its description notes the default of true and the
14
+ * durable-child-id return shape (mirrors dsh-tool-subagent's wording).
15
+ */
16
+ export function createDelegationParameters(config) {
17
+ const continuable = (config.backgroundMode ?? 'one-shot') === 'continuable';
18
+ const parameters = {
19
+ description: {
20
+ type: 'string',
21
+ required: true,
22
+ description: 'A short (3-5 word) description of the delegated task, for display.',
23
+ },
24
+ prompt: {
25
+ type: 'string',
26
+ required: true,
27
+ description: "The complete, self-contained task for the subagent. It does not share this conversation's context, so include everything it needs.",
28
+ },
29
+ role: {
30
+ type: 'string',
31
+ description: 'Role template id (optional). Falls back to the configured default role when unset.',
32
+ },
33
+ provider: {
34
+ type: 'string',
35
+ description: 'LLM provider route override (optional). Explicit provider/model win over a role binding. Must match a route with a registered adapter.',
36
+ },
37
+ model: { type: 'string', description: 'Model id override (optional). Explicit provider/model win over a role binding.' },
38
+ reasoningEffort: { type: 'string', description: 'Reasoning-effort override (optional). Adapter serving the route decides support.' },
39
+ };
40
+ if (config.enableRunInBackground !== false) {
41
+ parameters.run_in_background = {
42
+ type: 'boolean',
43
+ description: continuable
44
+ ? 'Whether to run in the background and return a durable subagent id immediately. Defaults to true. Set false to wait for the result when your next action depends on it.'
45
+ : 'Whether to run as a background job and return its id. Defaults to false; collect with job_output or stop with job_kill.',
46
+ };
47
+ }
48
+ return parameters;
49
+ }
50
+ /** The model-facing output schema: exactly one of background, continuable, or foreground. */
51
+ export function createDelegationOutputSchema() {
52
+ return {
53
+ oneOf: [
54
+ {
55
+ type: 'object',
56
+ additionalProperties: false,
57
+ properties: {
58
+ kind: { type: 'string', required: true, const: 'background' },
59
+ jobId: { type: 'string', required: true },
60
+ },
61
+ },
62
+ {
63
+ type: 'object',
64
+ additionalProperties: false,
65
+ properties: {
66
+ kind: { type: 'string', required: true, const: 'continuable' },
67
+ subagentId: { type: 'string', required: true },
68
+ },
69
+ },
70
+ {
71
+ type: 'object',
72
+ additionalProperties: false,
73
+ properties: {
74
+ kind: { type: 'string', required: true, const: 'foreground' },
75
+ runId: { type: 'string', required: true },
76
+ output: { type: 'array', required: true, items: { type: 'json' } },
77
+ },
78
+ },
79
+ ],
80
+ };
81
+ }
82
+ function isEmpty(value) {
83
+ return value === undefined || value === null || value === '';
84
+ }
85
+ /** A non-completed stop reason means the child did not finish cleanly. */
86
+ function stopReasonError(result) {
87
+ switch (result.stopReason) {
88
+ case 'completed':
89
+ return undefined;
90
+ case 'aborted':
91
+ return 'subagent run was cancelled';
92
+ case 'error':
93
+ return 'subagent run failed';
94
+ case 'max-tokens':
95
+ return 'subagent run hit its token limit before finishing';
96
+ case 'refusal':
97
+ return 'subagent declined the task';
98
+ default:
99
+ return `subagent run ended abnormally (${String(result.stopReason)})`;
100
+ }
101
+ }
102
+ /** Append the child's preserved partial answer to a stop-reason error. */
103
+ function withPartialText(error, output) {
104
+ const text = output
105
+ .filter((block) => block.type === 'text')
106
+ .map((block) => block.text)
107
+ .join('');
108
+ return text.length === 0 ? error : `${error}\nPartial output before the run ended:\n${text}`;
109
+ }
110
+ /**
111
+ * Collect and release one foreground run without letting disposal replace an
112
+ * independent result failure (mirrors dsh-tool-subagent settleForegroundRun).
113
+ */
114
+ async function settleForegroundRun(run) {
115
+ const [execution] = await Promise.allSettled([
116
+ run.result.then((result) => {
117
+ const error = stopReasonError(result);
118
+ if (error !== undefined)
119
+ throw new Error(withPartialText(error, result.output));
120
+ return { kind: 'foreground', runId: String(run.id), output: result.output };
121
+ }),
122
+ ]);
123
+ const [disposal] = await Promise.allSettled([Promise.resolve().then(() => run.dispose())]);
124
+ if (execution.status === 'rejected') {
125
+ if (disposal.status === 'rejected') {
126
+ throw new AggregateError([execution.reason, disposal.reason], `subagent run failed: ${String(execution.reason)}; dispose failed: ${String(disposal.reason)}`);
127
+ }
128
+ throw execution.reason;
129
+ }
130
+ if (disposal.status === 'rejected')
131
+ throw disposal.reason;
132
+ return execution.value;
133
+ }
134
+ /** Settle a background child without rejecting the Task producer contract. */
135
+ async function settleBackgroundRun(start, signal) {
136
+ try {
137
+ return await settleRun(await start);
138
+ }
139
+ catch (error) {
140
+ return signal.aborted ? { status: 'killed' } : { status: 'failed', detail: String(error) };
141
+ }
142
+ }
143
+ /** Check whether an LLM route has a registered adapter (routable = listed). */
144
+ function isProviderRoutable(ctx, provider) {
145
+ const llm = ctx.get('llm');
146
+ if (llm === undefined)
147
+ return true; // cannot validate without llm; assume routable
148
+ return llm.listProviders().some((entry) => entry.id === provider);
149
+ }
150
+ /** Format the structured FR-8.1 error with the available route list. */
151
+ function invalidProviderError(provider, available) {
152
+ const list = available.length > 0 ? available.join(', ') : '(none)';
153
+ return new Error(`${ERROR_PREFIX} LLM provider route ${provider} is not routable (no adapter serves it). Available providers: ${list}`);
154
+ }
155
+ /**
156
+ * Pure mode decision (extracted for unit testing) mirroring dsh-tool-subagent's
157
+ * resolveDelegationRun: a forced background while the flag is disabled is
158
+ * rejected; otherwise background defaults to the configured mode's policy —
159
+ * false for one-shot, true for continuable.
160
+ */
161
+ export function resolveDelegationMode(request, options) {
162
+ if (!options.backgroundEnabled) {
163
+ if (request.run_in_background === true) {
164
+ throw new Error(`${ERROR_PREFIX} run_in_background is disabled for this tool instance (enableRunInBackground: false)`);
165
+ }
166
+ return { runInBackground: false, route: 'foreground' };
167
+ }
168
+ const runInBackground = request.run_in_background ?? options.continuable;
169
+ return {
170
+ runInBackground,
171
+ route: runInBackground ? (options.continuable ? 'continuable' : 'one-shot') : 'foreground',
172
+ };
173
+ }
174
+ /**
175
+ * Pure renderer for a delegation result (extracted for unit testing). Mirrors
176
+ * dsh-tool-subagent's output.render: a continuable child renders as
177
+ * "started subagent <id>"; a one-shot task keeps its tool-name-qualified text;
178
+ * a foreground result emits its joined text blocks.
179
+ */
180
+ export function renderDelegationResult(value, toolName) {
181
+ if (value.kind === 'background')
182
+ return `started background ${toolName} task ${value.jobId}`;
183
+ if (value.kind === 'continuable')
184
+ return `started subagent ${value.subagentId}`;
185
+ const blocks = value.output;
186
+ return blocks
187
+ .filter((block) => typeof block === 'object' && block !== null && block.type === 'text' && typeof block.text === 'string')
188
+ .map((block) => block.text)
189
+ .join('');
190
+ }
191
+ /**
192
+ * Pure capability gate (extracted from execute for unit testing, behavioral
193
+ * no-op): a resolved delegation feature demands a transport-provider capability,
194
+ * and its absence is a hard error (FR-8.1 / design 7.3). persona, toolFilter,
195
+ * and a numeric maxDepth each require the matching capability flag.
196
+ */
197
+ export function assertDelegationCapabilities(options) {
198
+ const { providerName, persona, toolFilter, capabilities, maxDepth } = options;
199
+ if (persona !== undefined && !capabilities.persona) {
200
+ throw new Error(`${ERROR_PREFIX} role binds a persona but transport provider "${providerName}" does not support the persona capability — switch the subagent provider or drop the role persona`);
201
+ }
202
+ if (toolFilter !== undefined && !capabilities.toolFilter) {
203
+ throw new Error(`${ERROR_PREFIX} role binds a tool filter but transport provider "${providerName}" does not support the toolFilter capability — switch the subagent provider or drop the role filter`);
204
+ }
205
+ if (typeof maxDepth === 'number' && !capabilities.depthLimit) {
206
+ throw new Error(`${ERROR_PREFIX} transport provider "${providerName}" cannot enforce maxDepth (no depthLimit capability) — set maxDepth: 'provider-managed' to leave the recursion budget to the provider`);
207
+ }
208
+ }
209
+ /**
210
+ * Pure request-body assembly (extracted from execute for unit testing,
211
+ * behavioral no-op): persona and toolFilter propagate into the request only
212
+ * when the role resolved them, so a bare delegation stays zero-intrusion.
213
+ */
214
+ export function buildSubagentRequest(parts) {
215
+ return {
216
+ label: parts.description,
217
+ prompt: parts.prompt,
218
+ parent: parts.parent,
219
+ ...(parts.agentOptions !== undefined ? { agentOptions: parts.agentOptions } : {}),
220
+ ...(parts.persona !== undefined ? { persona: parts.persona } : {}),
221
+ ...(parts.toolFilter !== undefined ? { toolFilter: parts.toolFilter } : {}),
222
+ ...(parts.maxDepth !== undefined ? { maxDepth: parts.maxDepth } : {}),
223
+ };
224
+ }
225
+ /**
226
+ * Create the subagent_role ToolDefinition for one mounted subagent transport
227
+ * provider. getSettings returns the current settings snapshot so execute reads
228
+ * live role/default layers.
229
+ */
230
+ export function createDelegationTool(options) {
231
+ const { ctx, config, provider, getSettings } = options;
232
+ const backgroundEnabled = config.enableRunInBackground !== false;
233
+ const continuable = (config.backgroundMode ?? 'one-shot') === 'continuable';
234
+ const toolName = config.toolName ?? 'subagent_role';
235
+ const providerName = config.subagentProvider ?? 'spawn';
236
+ return defineTool({
237
+ name: toolName,
238
+ description: 'Delegate a self-contained task to a role-bound subagent with an optional LLM route (provider/model) override. ' +
239
+ 'Resolves the model through configure -> role -> default -> inherit; role persona and tool filtering are applied when supported. ' +
240
+ (backgroundEnabled
241
+ ? continuable
242
+ ? ' This tool runs in the background by default, immediately returns a durable subagent id, and keeps the child conversation available for later turns. When that run settles, the runtime sends the parent a notice containing its outcome and any final assistant message; `send_message` starts a later turn in the same child conversation. Set `run_in_background: false` only when your next action depends on receiving the result.'
243
+ : ' This call waits for the result by default. Set `run_in_background: true` to return a job id; collect with `job_output` and stop with `job_kill`.'
244
+ : ' This call waits for the subagent and returns its result.'),
245
+ parameters: {
246
+ description: {
247
+ type: 'string',
248
+ required: true,
249
+ description: 'A short (3-5 word) description of the delegated task, for display.',
250
+ },
251
+ prompt: {
252
+ type: 'string',
253
+ required: true,
254
+ description: "The complete, self-contained task for the subagent. It does not share this conversation's context, so include everything it needs.",
255
+ },
256
+ role: {
257
+ type: 'string',
258
+ description: 'Role template id (optional). Falls back to the configured default role when unset.',
259
+ },
260
+ provider: {
261
+ type: 'string',
262
+ description: 'LLM provider route override (optional). Explicit provider/model win over a role binding. Must match a route with a registered adapter.',
263
+ },
264
+ model: { type: 'string', description: 'Model id override (optional). Explicit provider/model win over a role binding.' },
265
+ reasoningEffort: { type: 'string', description: 'Reasoning-effort override (optional). Adapter serving the route decides support.' },
266
+ ...(backgroundEnabled
267
+ ? {
268
+ run_in_background: {
269
+ type: 'boolean',
270
+ description: continuable
271
+ ? 'Whether to run in the background and return a durable subagent id immediately. Defaults to true. Set false to wait for the result when your next action depends on it.'
272
+ : 'Whether to run as a background job and return its id. Defaults to false; collect with job_output or stop with job_kill.',
273
+ },
274
+ }
275
+ : {}),
276
+ },
277
+ output: {
278
+ schema: {
279
+ oneOf: [
280
+ {
281
+ type: 'object',
282
+ additionalProperties: false,
283
+ properties: {
284
+ kind: { type: 'string', required: true, const: 'background' },
285
+ jobId: { type: 'string', required: true },
286
+ },
287
+ },
288
+ {
289
+ type: 'object',
290
+ additionalProperties: false,
291
+ properties: {
292
+ kind: { type: 'string', required: true, const: 'continuable' },
293
+ subagentId: { type: 'string', required: true },
294
+ },
295
+ },
296
+ {
297
+ type: 'object',
298
+ additionalProperties: false,
299
+ properties: {
300
+ kind: { type: 'string', required: true, const: 'foreground' },
301
+ runId: { type: 'string', required: true },
302
+ output: { type: 'array', required: true, items: { type: 'json' } },
303
+ },
304
+ },
305
+ ],
306
+ },
307
+ render: (_args, value) => [{ type: 'text', text: renderDelegationResult(value, toolName) }],
308
+ },
309
+ isConcurrencySafe: () => true,
310
+ async execute(args, exec) {
311
+ const parent = exec.agent;
312
+ if (!parent)
313
+ throw new Error(`${ERROR_PREFIX} tool requires a calling agent (exec.agent was undefined)`);
314
+ const settings = getSettings();
315
+ const route = resolveRoute({ args, settings, parent: parent.options });
316
+ const warnings = [...route.warnings];
317
+ ctx.logger.info(`[${DELEGATION_TOOL_PREFIX}] delegate layer=${route.layer} mode=${continuable ? 'continuable' : 'one-shot'} transport=${providerName} route=${JSON.stringify(route.agentOptions ?? null)} persona=${route.persona ? 'yes' : 'no'} warnings=${JSON.stringify(warnings)}`);
318
+ // FR-8.1: an explicitly supplied provider must be routable — never silently swapped.
319
+ const explicitProvider = isEmpty(args.provider) ? undefined : args.provider;
320
+ if (explicitProvider !== undefined && !isProviderRoutable(ctx, explicitProvider)) {
321
+ const llm = ctx.get('llm');
322
+ const available = llm === undefined ? [] : llm.listProviders().map((entry) => entry.id);
323
+ throw invalidProviderError(explicitProvider, available);
324
+ }
325
+ // FR-8.2: role/default-bound provider not routable -> fallback (fallbackOnInvalid) or error.
326
+ let agentOptions = route.agentOptions;
327
+ const routeProvider = agentOptions?.provider;
328
+ if (routeProvider !== undefined && explicitProvider === undefined && !isProviderRoutable(ctx, routeProvider)) {
329
+ const fallBack = settings.fallbackOnInvalid !== false;
330
+ if (fallBack) {
331
+ // Drop the un-routable route fields so the seam inherits the parent model (AC-8.2).
332
+ agentOptions = undefined;
333
+ warnings.push(`${ERROR_PREFIX} role/default provider ${routeProvider} is not routable; fell back to the parent model (fallbackOnInvalid: true)`);
334
+ ctx.logger.warn(`[${DELEGATION_TOOL_PREFIX}] fell back to parent model for un-routable provider ${routeProvider}`);
335
+ }
336
+ else {
337
+ const llm = ctx.get('llm');
338
+ const available = llm === undefined ? [] : llm.listProviders().map((entry) => entry.id);
339
+ throw invalidProviderError(routeProvider, available);
340
+ }
341
+ }
342
+ // persona/toolFilter require the transport provider's capabilities.
343
+ const maxDepth = typeof config.maxDepth === 'number' ? config.maxDepth : undefined;
344
+ assertDelegationCapabilities({
345
+ providerName,
346
+ persona: route.persona,
347
+ toolFilter: route.toolFilter,
348
+ capabilities: provider.capabilities,
349
+ maxDepth,
350
+ });
351
+ // reasoningEffort is advisory and not part of AgentOptions/SubagentStartRequest.
352
+ if (route.reasoningEffort !== undefined) {
353
+ ctx.logger.info(`[${DELEGATION_TOOL_PREFIX}] reasoningEffort=${route.reasoningEffort} is advisory and logged only (not injectable via AgentOptions)`);
354
+ }
355
+ const request = buildSubagentRequest({
356
+ description: args.description,
357
+ prompt: [{ type: 'text', text: args.prompt }],
358
+ parent,
359
+ agentOptions,
360
+ persona: route.persona,
361
+ toolFilter: route.toolFilter,
362
+ maxDepth,
363
+ });
364
+ const decision = resolveDelegationMode(args, { backgroundEnabled, continuable });
365
+ // Continuable background runs the child through startContinuable and returns
366
+ // the durable child id for later send_message follow-up (FR-5.3 / F11).
367
+ if (decision.route === 'continuable') {
368
+ if (provider.prepareContinuable === undefined) {
369
+ throw new Error(`${ERROR_PREFIX} transport provider "${providerName}" does not support backgroundMode: continuable — switch the subagent provider or use backgroundMode: 'one-shot'`);
370
+ }
371
+ const start = await ctx.subagents.startContinuable({
372
+ provider: providerName,
373
+ label: args.description,
374
+ request,
375
+ signal: exec.signal,
376
+ });
377
+ return { kind: 'continuable', subagentId: start.childId };
378
+ }
379
+ if (decision.route === 'one-shot') {
380
+ const jobs = ctx.get('jobs');
381
+ if (jobs === undefined) {
382
+ throw new Error(`${ERROR_PREFIX} background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`);
383
+ }
384
+ return {
385
+ kind: 'background',
386
+ jobId: jobs.start({
387
+ kind: 'subagent',
388
+ label: args.description,
389
+ owner: parent,
390
+ run: () => {
391
+ const controller = new AbortController();
392
+ return {
393
+ cancel: (reason) => controller.abort(reason ?? 'background subagent task killed'),
394
+ done: settleBackgroundRun(ctx.subagents.start(providerName, { ...request, signal: controller.signal }), controller.signal),
395
+ };
396
+ },
397
+ }),
398
+ };
399
+ }
400
+ return settleForegroundRun(await ctx.subagents.start(providerName, { ...request, signal: exec.signal }));
401
+ },
402
+ });
403
+ }
404
+ //# sourceMappingURL=delegation-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation-tool.js","sourceRoot":"","sources":["../src/delegation-tool.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,UAAU,EAAkE,MAAM,wBAAwB,CAAC;AACpH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