@fishwithcat/dsh-subagent 0.0.0-stage → 0.2.2-alpha.2
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 +106 -0
- package/README.md +237 -2
- package/README.zh.md +238 -0
- package/lib/index.js +3364 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +1142 -0
- package/lib/typert.remote-client.d.ts +29 -0
- package/lib/typert.remote-client.js +168 -0
- package/lib/types/activation.d.ts +120 -0
- package/lib/types/activation.js +112 -0
- package/lib/types/archive-admission.d.ts +16 -0
- package/lib/types/archive-admission.js +151 -0
- package/lib/types/assistant-output.d.ts +48 -0
- package/lib/types/assistant-output.js +73 -0
- package/lib/types/catalog.d.ts +87 -0
- package/lib/types/catalog.js +113 -0
- package/lib/types/child-agent.d.ts +155 -0
- package/lib/types/child-agent.js +227 -0
- package/lib/types/client.d.ts +8 -0
- package/lib/types/client.js +7 -0
- package/lib/types/continuation-messages.d.ts +65 -0
- package/lib/types/continuation-messages.js +118 -0
- package/lib/types/control-types.d.ts +142 -0
- package/lib/types/control-types.js +8 -0
- package/lib/types/control.d.ts +45 -0
- package/lib/types/control.js +79 -0
- package/lib/types/depth.d.ts +31 -0
- package/lib/types/depth.js +39 -0
- package/lib/types/descriptor.d.ts +105 -0
- package/lib/types/descriptor.js +192 -0
- package/lib/types/error.d.ts +11 -0
- package/lib/types/error.js +14 -0
- package/lib/types/index.d.ts +331 -0
- package/lib/types/index.js +461 -0
- package/lib/types/internal.d.ts +58 -0
- package/lib/types/internal.js +58 -0
- package/lib/types/lifecycle.d.ts +83 -0
- package/lib/types/lifecycle.js +115 -0
- package/lib/types/list-children.d.ts +36 -0
- package/lib/types/list-children.js +166 -0
- package/lib/types/manager.d.ts +250 -0
- package/lib/types/manager.js +1345 -0
- package/lib/types/out-of-process.d.ts +92 -0
- package/lib/types/out-of-process.js +177 -0
- package/lib/types/projection-types.d.ts +85 -0
- package/lib/types/projection-types.js +7 -0
- package/lib/types/projection.d.ts +94 -0
- package/lib/types/projection.js +157 -0
- package/lib/types/structured.d.ts +49 -0
- package/lib/types/structured.js +130 -0
- package/lib/types/types.d.ts +343 -0
- package/lib/types/types.js +19 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +135 -4
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical selection of a child's final assistant output. Backend run results
|
|
3
|
+
* and `subagent/end.lastAssistantMessage` apply the same rule: select the last
|
|
4
|
+
* non-empty assistant message. An empty-content message records usage only
|
|
5
|
+
* when the loop appends it after a max-tokens step with no executable blocks,
|
|
6
|
+
* so it does not replace earlier output. If no non-empty message exists,
|
|
7
|
+
* select the accumulated assistant text. Selection is independent of the
|
|
8
|
+
* run's stop reason.
|
|
9
|
+
*
|
|
10
|
+
* @module @deepseek-ai/dsh-subagent/assistant-output
|
|
11
|
+
*/
|
|
12
|
+
import { joinAssistantStreamText } from '@deepseek-ai/dsh-llm';
|
|
13
|
+
/**
|
|
14
|
+
* Incremental fold of the selection rule, for backends that observe a child's
|
|
15
|
+
* output as it streams: session-event backends {@link push} each event, and
|
|
16
|
+
* transports without session events (ACP content chunks) {@link pushText} raw
|
|
17
|
+
* text into the same streamed fallback.
|
|
18
|
+
*/
|
|
19
|
+
export class AssistantOutputFold {
|
|
20
|
+
message;
|
|
21
|
+
partial = [];
|
|
22
|
+
/**
|
|
23
|
+
* Fold one session event: a non-empty assistant message becomes the
|
|
24
|
+
* candidate final answer, while its embedded stream and any log-only attempt
|
|
25
|
+
* extend the streamed fallback; every other event contributes nothing.
|
|
26
|
+
* @param event - the next observed session event.
|
|
27
|
+
*/
|
|
28
|
+
push(event) {
|
|
29
|
+
if (event.type === 'assistant/message') {
|
|
30
|
+
const content = event.data.message.content;
|
|
31
|
+
if (content.length > 0)
|
|
32
|
+
this.message = content;
|
|
33
|
+
}
|
|
34
|
+
if (event.type === 'assistant/message' || event.type === 'assistant/attempt') {
|
|
35
|
+
this.pushText(joinAssistantStreamText(event.data.stream));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extend the streamed fallback with text observed outside session events.
|
|
40
|
+
* @param text - the next streamed text piece (an empty piece is a no-op).
|
|
41
|
+
*/
|
|
42
|
+
pushText(text) {
|
|
43
|
+
if (text.length > 0)
|
|
44
|
+
this.partial.push(text);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Select the final output folded so far.
|
|
48
|
+
* @returns the last non-empty assistant message, else the accumulated
|
|
49
|
+
* streamed text, or `undefined` when the child produced neither.
|
|
50
|
+
*/
|
|
51
|
+
collect() {
|
|
52
|
+
if (this.message !== undefined)
|
|
53
|
+
return this.message;
|
|
54
|
+
const text = this.partial.join('');
|
|
55
|
+
return text.length > 0 ? [{ type: 'text', text }] : undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Apply the selection rule to one complete child-owned event suffix.
|
|
60
|
+
* @param events - the child-owned events (after any seed or epoch boundary).
|
|
61
|
+
* @returns the selected output, or `undefined` when the child produced none.
|
|
62
|
+
*/
|
|
63
|
+
export function finalAssistantOutput(events) {
|
|
64
|
+
// TODO: this folds the complete suffix once per run/epoch settlement. If a
|
|
65
|
+
// long continuable epoch ever profiles hot here, scan backward with early
|
|
66
|
+
// exit for the last non-empty message and fold text deltas only on the
|
|
67
|
+
// no-message fallback.
|
|
68
|
+
const fold = new AssistantOutputFold();
|
|
69
|
+
for (const event of events)
|
|
70
|
+
fold.push(event);
|
|
71
|
+
return fold.collect();
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=assistant-output.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent-owned durable subagent catalog events and their chunked projection.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-subagent/catalog
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import type { ChunkedList } from '@deepseek-ai/dsh-chunked-list';
|
|
8
|
+
import type { Session, SessionEvent, SessionHeader, SessionId, SessionLogOffset } from '@deepseek-ai/dsh-session';
|
|
9
|
+
import type { SubagentCatalogEntry } from './projection-types.ts';
|
|
10
|
+
/** Catalog payload version emitted by local child creation. */
|
|
11
|
+
export declare const SUBAGENT_CATALOG_VERSION = 0;
|
|
12
|
+
type KnownCatalogMode = {
|
|
13
|
+
readonly mode: 'one-shot';
|
|
14
|
+
readonly label?: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly mode: 'continuable';
|
|
17
|
+
readonly label: string;
|
|
18
|
+
};
|
|
19
|
+
/** Parent catalog v0 records local modes, v1 adds unknown children, and v2 records external executions. */
|
|
20
|
+
export type SubagentCatalogEvent = {
|
|
21
|
+
readonly childId: SessionId;
|
|
22
|
+
readonly childCreatedAt: number;
|
|
23
|
+
} & (({
|
|
24
|
+
readonly version: 0;
|
|
25
|
+
} & KnownCatalogMode) | ({
|
|
26
|
+
readonly version: 1;
|
|
27
|
+
} & (KnownCatalogMode | {
|
|
28
|
+
readonly mode: 'unknown';
|
|
29
|
+
readonly label?: string;
|
|
30
|
+
})) | {
|
|
31
|
+
readonly version: 2;
|
|
32
|
+
readonly mode: 'external';
|
|
33
|
+
readonly label?: string;
|
|
34
|
+
});
|
|
35
|
+
declare module '@deepseek-ai/dsh-session/types' {
|
|
36
|
+
interface SessionEventMap {
|
|
37
|
+
/**
|
|
38
|
+
* A direct child's identity and available discovery fields.
|
|
39
|
+
* @param data - versioned parent-owned catalog entry.
|
|
40
|
+
*/
|
|
41
|
+
'subagent/catalog': SubagentCatalogEvent;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Host fold state for one parent catalog. */
|
|
45
|
+
export interface SubagentCatalogState {
|
|
46
|
+
readonly inheritedEventCount: SessionLogOffset;
|
|
47
|
+
readonly head?: ChunkedList<SubagentCatalogEvent> | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Materialize complete and unknown-mode child identities from parent catalog events.
|
|
51
|
+
* @param state - parent catalog fold state.
|
|
52
|
+
* @returns current direct-child rows in parent catalog event order.
|
|
53
|
+
*/
|
|
54
|
+
declare function subagentCatalogEntries(state: SubagentCatalogState): SubagentCatalogEntry[];
|
|
55
|
+
/** Parent-owned direct-child catalog projection; invalid own facts reject restoration. */
|
|
56
|
+
export declare const subagentCatalogProjectionDefinition: {
|
|
57
|
+
key: "subagentCatalog";
|
|
58
|
+
stateSchema: z.ZodType<SubagentCatalogState, unknown, z.core.$ZodTypeInternals<SubagentCatalogState, unknown>>;
|
|
59
|
+
init: (_header: SessionHeader, inheritedEventCount: SessionLogOffset) => {
|
|
60
|
+
inheritedEventCount: SessionLogOffset;
|
|
61
|
+
};
|
|
62
|
+
apply: (state: NoInfer<SubagentCatalogState>, event: SessionEvent) => SubagentCatalogState;
|
|
63
|
+
stateVersion: number;
|
|
64
|
+
wire: {
|
|
65
|
+
viewSchema: z.ZodType<SubagentCatalogEntry[], unknown, z.core.$ZodTypeInternals<SubagentCatalogEntry[], unknown>>;
|
|
66
|
+
view: typeof subagentCatalogEntries;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Append a complete direct-child discovery fact to its parent Session.
|
|
71
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
72
|
+
* @param child - established child's immutable Session metadata.
|
|
73
|
+
* @param descriptor - mode-discriminated creation label frozen with the child.
|
|
74
|
+
*/
|
|
75
|
+
export declare function establishCatalogChild(parent: Session, child: SessionHeader, descriptor: {
|
|
76
|
+
readonly mode: 'continuable';
|
|
77
|
+
readonly label: string;
|
|
78
|
+
}): void;
|
|
79
|
+
/**
|
|
80
|
+
* Record an external execution without a local child Session.
|
|
81
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
82
|
+
* @param childId - identity returned by the external provider.
|
|
83
|
+
* @param label - display label assigned by the caller.
|
|
84
|
+
*/
|
|
85
|
+
export declare function establishExternalCatalogChild(parent: Session, childId: SessionId, label: string): void;
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent-owned durable subagent catalog events and their chunked projection.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-subagent/catalog
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { appendChunkedList, chunkedListSchema, iterateChunkedList } from '@deepseek-ai/dsh-chunked-list';
|
|
8
|
+
/** Catalog payload version emitted by local child creation. */
|
|
9
|
+
export const SUBAGENT_CATALOG_VERSION = 0;
|
|
10
|
+
const sessionIdSchema = z.string();
|
|
11
|
+
const oneShotCatalogSchema = z.object({
|
|
12
|
+
version: z.union([z.literal(0), z.literal(1)]),
|
|
13
|
+
childId: sessionIdSchema,
|
|
14
|
+
childCreatedAt: z.number().int().nonnegative(),
|
|
15
|
+
mode: z.literal('one-shot'),
|
|
16
|
+
label: z.string().optional(),
|
|
17
|
+
}).strict();
|
|
18
|
+
const continuableCatalogSchema = z.object({
|
|
19
|
+
version: z.union([z.literal(0), z.literal(1)]),
|
|
20
|
+
childId: sessionIdSchema,
|
|
21
|
+
childCreatedAt: z.number().int().nonnegative(),
|
|
22
|
+
mode: z.literal('continuable'),
|
|
23
|
+
label: z.string(),
|
|
24
|
+
}).strict();
|
|
25
|
+
const externalCatalogSchema = oneShotCatalogSchema.extend({ version: z.literal(2), mode: z.literal('external') });
|
|
26
|
+
const unknownCatalogSchema = oneShotCatalogSchema.extend({ version: z.literal(1), mode: z.literal('unknown') });
|
|
27
|
+
const eventDataSchema = z.union([
|
|
28
|
+
oneShotCatalogSchema,
|
|
29
|
+
externalCatalogSchema,
|
|
30
|
+
continuableCatalogSchema,
|
|
31
|
+
unknownCatalogSchema,
|
|
32
|
+
]);
|
|
33
|
+
const viewSchema = z.array(z.union([
|
|
34
|
+
oneShotCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
35
|
+
id: sessionIdSchema,
|
|
36
|
+
createdAt: oneShotCatalogSchema.shape.childCreatedAt,
|
|
37
|
+
}),
|
|
38
|
+
externalCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
39
|
+
id: sessionIdSchema,
|
|
40
|
+
createdAt: externalCatalogSchema.shape.childCreatedAt,
|
|
41
|
+
}),
|
|
42
|
+
continuableCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
43
|
+
id: sessionIdSchema,
|
|
44
|
+
createdAt: continuableCatalogSchema.shape.childCreatedAt,
|
|
45
|
+
}),
|
|
46
|
+
unknownCatalogSchema.omit({ version: true, childId: true, childCreatedAt: true }).extend({
|
|
47
|
+
id: sessionIdSchema,
|
|
48
|
+
createdAt: unknownCatalogSchema.shape.childCreatedAt,
|
|
49
|
+
}),
|
|
50
|
+
]));
|
|
51
|
+
const stateSchema = z.object({
|
|
52
|
+
inheritedEventCount: z.number().int().nonnegative(),
|
|
53
|
+
head: chunkedListSchema(eventDataSchema).optional(),
|
|
54
|
+
}).strict();
|
|
55
|
+
/**
|
|
56
|
+
* Materialize complete and unknown-mode child identities from parent catalog events.
|
|
57
|
+
* @param state - parent catalog fold state.
|
|
58
|
+
* @returns current direct-child rows in parent catalog event order.
|
|
59
|
+
*/
|
|
60
|
+
function subagentCatalogEntries(state) {
|
|
61
|
+
const entries = [];
|
|
62
|
+
for (const data of iterateChunkedList(state.head)) {
|
|
63
|
+
const { version: _version, childId, childCreatedAt, ...descriptor } = data;
|
|
64
|
+
entries.push({ id: childId, createdAt: childCreatedAt, ...descriptor });
|
|
65
|
+
}
|
|
66
|
+
return entries;
|
|
67
|
+
}
|
|
68
|
+
/** Parent-owned direct-child catalog projection; invalid own facts reject restoration. */
|
|
69
|
+
export const subagentCatalogProjectionDefinition = {
|
|
70
|
+
key: 'subagentCatalog',
|
|
71
|
+
stateSchema,
|
|
72
|
+
init: (_header, inheritedEventCount) => ({ inheritedEventCount }),
|
|
73
|
+
apply: (state, event) => {
|
|
74
|
+
if (event.type !== 'subagent/catalog' || event.seq < state.inheritedEventCount)
|
|
75
|
+
return state;
|
|
76
|
+
return { ...state, head: appendChunkedList(state.head, eventDataSchema.parse(event.data)) };
|
|
77
|
+
},
|
|
78
|
+
stateVersion: 6,
|
|
79
|
+
wire: { viewSchema, view: subagentCatalogEntries },
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Append a complete direct-child discovery fact to its parent Session.
|
|
83
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
84
|
+
* @param child - established child's immutable Session metadata.
|
|
85
|
+
* @param descriptor - mode-discriminated creation label frozen with the child.
|
|
86
|
+
*/
|
|
87
|
+
export function establishCatalogChild(parent, child, descriptor) {
|
|
88
|
+
parent.append('subagent/catalog', {
|
|
89
|
+
version: SUBAGENT_CATALOG_VERSION,
|
|
90
|
+
childId: child.id,
|
|
91
|
+
childCreatedAt: child.createdAt,
|
|
92
|
+
mode: descriptor.mode,
|
|
93
|
+
label: descriptor.label,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Catalog payload version emitted by external execution creation. */
|
|
97
|
+
const EXTERNAL_SUBAGENT_CATALOG_VERSION = 2;
|
|
98
|
+
/**
|
|
99
|
+
* Record an external execution without a local child Session.
|
|
100
|
+
* @param parent - durable direct parent receiving the discovery fact.
|
|
101
|
+
* @param childId - identity returned by the external provider.
|
|
102
|
+
* @param label - display label assigned by the caller.
|
|
103
|
+
*/
|
|
104
|
+
export function establishExternalCatalogChild(parent, childId, label) {
|
|
105
|
+
parent.append('subagent/catalog', {
|
|
106
|
+
version: EXTERNAL_SUBAGENT_CATALOG_VERSION,
|
|
107
|
+
childId,
|
|
108
|
+
childCreatedAt: Date.now(),
|
|
109
|
+
mode: 'external',
|
|
110
|
+
label,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared in-process child composition: the delegation-depth budget, the
|
|
3
|
+
* durable session metadata, the resolved child `AgentOptions`, the delegated
|
|
4
|
+
* policy seed, and the scoped setup used by local activations.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/child-agent
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { Agent, AgentOptions, CreateAgentOptions } from '@deepseek-ai/dsh-agent';
|
|
10
|
+
import type { SandboxMode } from '@deepseek-ai/dsh-sandbox';
|
|
11
|
+
import type { Session, SessionId } from '@deepseek-ai/dsh-session';
|
|
12
|
+
import type { ToolRestriction } from '@deepseek-ai/dsh-tools';
|
|
13
|
+
import type { ApprovalPolicy } from '@deepseek-ai/dsh-user-approval';
|
|
14
|
+
/** Thrown when starting a child would exceed the requested depth cap. */
|
|
15
|
+
export declare class SubagentDepthError extends Error {
|
|
16
|
+
readonly attemptedDepth: number;
|
|
17
|
+
readonly maxDepth: number;
|
|
18
|
+
constructor(attemptedDepth: number, maxDepth: number);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the child's delegation depth from its parent and enforce an optional
|
|
22
|
+
* cap. The persisted parent header is the monotone floor, so a resumed parent
|
|
23
|
+
* cannot delegate as if it were top-level.
|
|
24
|
+
* @param parent - the delegating parent agent.
|
|
25
|
+
* @param maxDepth - optional absolute cap the resolved depth must not exceed.
|
|
26
|
+
* @returns the child's non-negative safe-integer depth.
|
|
27
|
+
* @throws {SubagentDepthError} when the resolved depth exceeds `maxDepth`.
|
|
28
|
+
* @throws {RangeError} when the resolved depth leaves the safe-integer range.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveChildDepth(parent: Agent, maxDepth: number | undefined): number;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the parent values inherited by a child. The latest request header
|
|
33
|
+
* owns provider, model, and reasoning effort after request-time selection;
|
|
34
|
+
* creation options remain the fallback before the first request and retain
|
|
35
|
+
* the configured output-token limit.
|
|
36
|
+
* @param parent - delegating parent Agent.
|
|
37
|
+
* @returns detached Agent options for child-option merging.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parentAgentOptionsForDelegation(parent: Agent): AgentOptions;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the child's `AgentOptions`: the parent's provider/model,
|
|
42
|
+
* reasoning-effort, and maxTokens values unless the request overrides them,
|
|
43
|
+
* stamped with the child's own delegation depth. Changing the route without
|
|
44
|
+
* naming an effort clears the parent's route-owned effort so the selected
|
|
45
|
+
* model resolves its own default.
|
|
46
|
+
* @param parent - the delegating parent whose route the child inherits.
|
|
47
|
+
* @param requested - per-child overrides, if any.
|
|
48
|
+
* @param childDepth - the resolved delegation depth to stamp.
|
|
49
|
+
* @returns the resolved options for `ctx.agents.create()`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveChildAgentOptions(parent: Agent, requested: AgentOptions | undefined, childDepth: number): AgentOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Build the child session's durable creation metadata: the parent's workspace,
|
|
54
|
+
* its direct lineage, coarse product origin, the recursion budget that must
|
|
55
|
+
* survive persistence, the seed boundary that separates inherited parent
|
|
56
|
+
* history from child work, and the composition the child runs under.
|
|
57
|
+
*
|
|
58
|
+
* Omitted selection uses the parent's live composition, including any switch
|
|
59
|
+
* made while the parent was blank.
|
|
60
|
+
* @param parent - the delegating parent agent.
|
|
61
|
+
* @param childDepth - the resolved delegation depth to persist.
|
|
62
|
+
* @param isSeeded - whether this child inherits a parent-log prefix, including an explicitly empty one.
|
|
63
|
+
* @param selectedPreset - independent selection, or omission to inherit the parent.
|
|
64
|
+
* @returns the `meta` for `ctx.agents.create()`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function childSessionMeta(parent: Agent, childDepth: number, isSeeded: boolean, selectedPreset?: string): NonNullable<CreateAgentOptions['meta']>;
|
|
67
|
+
/** The scoped composition a child agent's creation window applies. */
|
|
68
|
+
export interface ChildComposition {
|
|
69
|
+
/** Independently mounted preset; omission shares the parent's standing generation. */
|
|
70
|
+
readonly agentPreset?: string | undefined;
|
|
71
|
+
/** Historical descriptor persona reapplied only during cold resume. */
|
|
72
|
+
readonly persona?: string | undefined;
|
|
73
|
+
/** Historical descriptor tool restriction reapplied only during cold resume. */
|
|
74
|
+
readonly toolFilter?: ToolRestriction | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Model-facing delegation-scope statement for an in-process child whose approval
|
|
78
|
+
* policy is `never`. A runtime-context contribution rather than a system-prompt
|
|
79
|
+
* section, so the deployment's system prompt stays uniform across parents and
|
|
80
|
+
* children.
|
|
81
|
+
*/
|
|
82
|
+
export declare const SUBAGENT_DELEGATION_CONTEXT: string;
|
|
83
|
+
/**
|
|
84
|
+
* Model-facing delegation-scope statement for an in-process child whose approval
|
|
85
|
+
* policy is `ask`: the scope stays fixed, but one operation may request a
|
|
86
|
+
* decision from the user who owns the answerers.
|
|
87
|
+
*/
|
|
88
|
+
export declare const SUBAGENT_DELEGATION_INTERACTIVE_CONTEXT: string;
|
|
89
|
+
/**
|
|
90
|
+
* Compose a child before publication and restore historical descriptor overrides.
|
|
91
|
+
* Explicit selection mounts the named preset; omission synchronously joins the
|
|
92
|
+
* parent's current generation. Registrations belong to the child's scope.
|
|
93
|
+
* @param childCtx - the child agent's scoped creation context.
|
|
94
|
+
* @param parent - the delegating parent used when no preset is selected.
|
|
95
|
+
* @param composition - independent preset and any overrides read from a historical descriptor.
|
|
96
|
+
* @param approvalPolicy - the child's effective approval policy, selecting its delegation statement.
|
|
97
|
+
* @returns A promise when mounting an independent preset; otherwise completes synchronously.
|
|
98
|
+
*/
|
|
99
|
+
export declare function applyChildComposition(childCtx: Context, parent: Agent, composition: ChildComposition, approvalPolicy: ApprovalPolicy | undefined): void | Promise<void>;
|
|
100
|
+
/** How a delegated child's approval policy is seeded at creation. */
|
|
101
|
+
export type DelegatedApprovalPolicy = 'never' | 'inherit';
|
|
102
|
+
/** Policy seeded onto a child session's log at the delegation boundary. */
|
|
103
|
+
export interface DelegatedPolicyOverrides {
|
|
104
|
+
/**
|
|
105
|
+
* The parent's current preset identity when it runs in Auto or Full access;
|
|
106
|
+
* the child keeps it under the delegated approval policy.
|
|
107
|
+
*/
|
|
108
|
+
readonly permissionPreset: 'auto' | 'danger-full-access' | undefined;
|
|
109
|
+
/** The parent session's explicit sandbox-mode override, or `undefined` without one. */
|
|
110
|
+
readonly sandboxMode: SandboxMode | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* The policy to append to the child's own log, or `undefined` without an
|
|
113
|
+
* approval capability. `'never'` keeps every ask deterministic; `'ask'`
|
|
114
|
+
* inherits an interactive parent's policy so a composed answerer may decide
|
|
115
|
+
* the child's requests.
|
|
116
|
+
*/
|
|
117
|
+
readonly approvalPolicy: ApprovalPolicy | undefined;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Capture the permission state to seed into one delegation. Call synchronously before
|
|
121
|
+
* the child start's first await: a later parent switch belongs to the
|
|
122
|
+
* parent's future, not to this child. Auto and Full access identities are
|
|
123
|
+
* inherited only through the in-process DSH path so either can replace a stale
|
|
124
|
+
* same-bundle fork value. Only the parent session's explicit sandbox override
|
|
125
|
+
* is captured — never deployment defaults or one-shot grants. Approval is
|
|
126
|
+
* pinned to `'never'` by default; `'inherit'` seeds the parent's current
|
|
127
|
+
* effective policy instead, which only a surface that also answers descendant
|
|
128
|
+
* Agents can turn into a prompt.
|
|
129
|
+
* @param parent - the delegating parent agent.
|
|
130
|
+
* @param delegatedApproval - `'never'` to pin rejection, `'inherit'` to seed the parent's effective policy.
|
|
131
|
+
* @returns the sandbox override (or `undefined` without one) and the approval policy seed.
|
|
132
|
+
*/
|
|
133
|
+
export declare function captureDelegatedPolicyOverrides(parent: Agent, delegatedApproval: DelegatedApprovalPolicy): DelegatedPolicyOverrides;
|
|
134
|
+
/**
|
|
135
|
+
* Append the captured delegation policy onto the child's own log as
|
|
136
|
+
* `source: 'delegation'` events after Session announcement and before Agent registration, so the
|
|
137
|
+
* child's effective policy is reconstructable from its log alone. Appends land
|
|
138
|
+
* after any fork seed, so fresh policy wins stale seed state; later child
|
|
139
|
+
* switches still win over these events.
|
|
140
|
+
* @param childSession - the child's announced, writable Session.
|
|
141
|
+
* @param overrides - the policy captured at delegation.
|
|
142
|
+
*/
|
|
143
|
+
export declare function appendDelegatedPolicyOverrides(childSession: Session, overrides: DelegatedPolicyOverrides): void;
|
|
144
|
+
/** Identity and lineage inputs shared by every in-process child creation. */
|
|
145
|
+
export interface ChildCreateInputs {
|
|
146
|
+
/** The child's reserved session id. */
|
|
147
|
+
readonly sessionId: SessionId;
|
|
148
|
+
/** The delegating parent agent. */
|
|
149
|
+
readonly parent: Agent;
|
|
150
|
+
/** The resolved delegation depth. */
|
|
151
|
+
readonly childDepth: number;
|
|
152
|
+
/** How many leading seed events came from the parent's log. */
|
|
153
|
+
readonly lineageSeedLength: number;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=child-agent.d.ts.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared in-process child composition: the delegation-depth budget, the
|
|
3
|
+
* durable session metadata, the resolved child `AgentOptions`, the delegated
|
|
4
|
+
* policy seed, and the scoped setup used by local activations.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/child-agent
|
|
7
|
+
*/
|
|
8
|
+
import { delegationDepthOf } from "./depth.js";
|
|
9
|
+
import { SubagentError } from "./error.js";
|
|
10
|
+
/** Thrown when starting a child would exceed the requested depth cap. */
|
|
11
|
+
export class SubagentDepthError extends Error {
|
|
12
|
+
attemptedDepth;
|
|
13
|
+
maxDepth;
|
|
14
|
+
constructor(attemptedDepth, maxDepth) {
|
|
15
|
+
super(`subagent depth ${attemptedDepth} exceeds maxDepth ${maxDepth}`);
|
|
16
|
+
this.attemptedDepth = attemptedDepth;
|
|
17
|
+
this.maxDepth = maxDepth;
|
|
18
|
+
this.name = 'SubagentDepthError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the child's delegation depth from its parent and enforce an optional
|
|
23
|
+
* cap. The persisted parent header is the monotone floor, so a resumed parent
|
|
24
|
+
* cannot delegate as if it were top-level.
|
|
25
|
+
* @param parent - the delegating parent agent.
|
|
26
|
+
* @param maxDepth - optional absolute cap the resolved depth must not exceed.
|
|
27
|
+
* @returns the child's non-negative safe-integer depth.
|
|
28
|
+
* @throws {SubagentDepthError} when the resolved depth exceeds `maxDepth`.
|
|
29
|
+
* @throws {RangeError} when the resolved depth leaves the safe-integer range.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveChildDepth(parent, maxDepth) {
|
|
32
|
+
const childDepth = delegationDepthOf(parent) + 1;
|
|
33
|
+
if (!Number.isSafeInteger(childDepth)) {
|
|
34
|
+
throw new RangeError('subagent child depth exceeds the safe-integer range');
|
|
35
|
+
}
|
|
36
|
+
if (maxDepth !== undefined && childDepth > maxDepth) {
|
|
37
|
+
throw new SubagentDepthError(childDepth, maxDepth);
|
|
38
|
+
}
|
|
39
|
+
return childDepth;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the parent values inherited by a child. The latest request header
|
|
43
|
+
* owns provider, model, and reasoning effort after request-time selection;
|
|
44
|
+
* creation options remain the fallback before the first request and retain
|
|
45
|
+
* the configured output-token limit.
|
|
46
|
+
* @param parent - delegating parent Agent.
|
|
47
|
+
* @returns detached Agent options for child-option merging.
|
|
48
|
+
*/
|
|
49
|
+
export function parentAgentOptionsForDelegation(parent) {
|
|
50
|
+
const requestConfig = parent.session.requestHeader()?.config;
|
|
51
|
+
if (requestConfig === undefined)
|
|
52
|
+
return { ...parent.options };
|
|
53
|
+
const { provider: _createdProvider, model: _createdModel, reasoningEffort: _createdReasoningEffort, ...createdOptions } = parent.options;
|
|
54
|
+
return {
|
|
55
|
+
...createdOptions,
|
|
56
|
+
provider: requestConfig.provider,
|
|
57
|
+
model: requestConfig.model,
|
|
58
|
+
...requestConfig.reasoningEffort === undefined
|
|
59
|
+
? {}
|
|
60
|
+
: { reasoningEffort: requestConfig.reasoningEffort },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the child's `AgentOptions`: the parent's provider/model,
|
|
65
|
+
* reasoning-effort, and maxTokens values unless the request overrides them,
|
|
66
|
+
* stamped with the child's own delegation depth. Changing the route without
|
|
67
|
+
* naming an effort clears the parent's route-owned effort so the selected
|
|
68
|
+
* model resolves its own default.
|
|
69
|
+
* @param parent - the delegating parent whose route the child inherits.
|
|
70
|
+
* @param requested - per-child overrides, if any.
|
|
71
|
+
* @param childDepth - the resolved delegation depth to stamp.
|
|
72
|
+
* @returns the resolved options for `ctx.agents.create()`.
|
|
73
|
+
*/
|
|
74
|
+
export function resolveChildAgentOptions(parent, requested, childDepth) {
|
|
75
|
+
const parentOptions = parentAgentOptionsForDelegation(parent);
|
|
76
|
+
const parentProvider = parentOptions.provider;
|
|
77
|
+
const parentModel = parentOptions.model;
|
|
78
|
+
const parentReasoningEffort = parentOptions.reasoningEffort;
|
|
79
|
+
const parentMaxTokens = parentOptions.maxTokens;
|
|
80
|
+
const resolved = {
|
|
81
|
+
...parentProvider !== undefined ? { provider: parentProvider } : {},
|
|
82
|
+
...parentModel !== undefined ? { model: parentModel } : {},
|
|
83
|
+
...parentReasoningEffort !== undefined ? { reasoningEffort: parentReasoningEffort } : {},
|
|
84
|
+
...parentMaxTokens !== undefined ? { maxTokens: parentMaxTokens } : {},
|
|
85
|
+
...requested,
|
|
86
|
+
subagentDepth: childDepth,
|
|
87
|
+
};
|
|
88
|
+
const routeChanged = resolved.provider !== parentProvider || resolved.model !== parentModel;
|
|
89
|
+
if (routeChanged && requested?.reasoningEffort === undefined)
|
|
90
|
+
delete resolved.reasoningEffort;
|
|
91
|
+
return resolved;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Build the child session's durable creation metadata: the parent's workspace,
|
|
95
|
+
* its direct lineage, coarse product origin, the recursion budget that must
|
|
96
|
+
* survive persistence, the seed boundary that separates inherited parent
|
|
97
|
+
* history from child work, and the composition the child runs under.
|
|
98
|
+
*
|
|
99
|
+
* Omitted selection uses the parent's live composition, including any switch
|
|
100
|
+
* made while the parent was blank.
|
|
101
|
+
* @param parent - the delegating parent agent.
|
|
102
|
+
* @param childDepth - the resolved delegation depth to persist.
|
|
103
|
+
* @param isSeeded - whether this child inherits a parent-log prefix, including an explicitly empty one.
|
|
104
|
+
* @param selectedPreset - independent selection, or omission to inherit the parent.
|
|
105
|
+
* @returns the `meta` for `ctx.agents.create()`.
|
|
106
|
+
*/
|
|
107
|
+
export function childSessionMeta(parent, childDepth, isSeeded, selectedPreset) {
|
|
108
|
+
const parentHeader = parent.session.header;
|
|
109
|
+
const agentPreset = selectedPreset ?? parent.ctx.get('agentPresets')?.composedPreset(parent.ctx);
|
|
110
|
+
return {
|
|
111
|
+
...parentHeader.cwd !== undefined ? { cwd: parentHeader.cwd } : {},
|
|
112
|
+
...agentPreset === undefined ? {} : { agentPreset },
|
|
113
|
+
parentSession: parentHeader.id,
|
|
114
|
+
isSeeded,
|
|
115
|
+
// Navigation classification only; the descriptor remains the authority
|
|
116
|
+
// for mode and continuation capability.
|
|
117
|
+
origin: 'subagent',
|
|
118
|
+
// Durable: the recursion budget must survive persistence and resume.
|
|
119
|
+
delegationDepth: childDepth,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Model-facing delegation-scope statement for an in-process child whose approval
|
|
124
|
+
* policy is `never`. A runtime-context contribution rather than a system-prompt
|
|
125
|
+
* section, so the deployment's system prompt stays uniform across parents and
|
|
126
|
+
* children.
|
|
127
|
+
*/
|
|
128
|
+
export const SUBAGENT_DELEGATION_CONTEXT = 'You are a delegated subagent: your permission scope was fixed when you were started and cannot be '
|
|
129
|
+
+ 'widened from inside this session — operations that require approval are rejected automatically. '
|
|
130
|
+
+ 'When the task needs access beyond that scope, do not retry the denied operation; state the '
|
|
131
|
+
+ 'limitation in your reply so the delegating agent can handle it.';
|
|
132
|
+
/**
|
|
133
|
+
* Model-facing delegation-scope statement for an in-process child whose approval
|
|
134
|
+
* policy is `ask`: the scope stays fixed, but one operation may request a
|
|
135
|
+
* decision from the user who owns the answerers.
|
|
136
|
+
*/
|
|
137
|
+
export const SUBAGENT_DELEGATION_INTERACTIVE_CONTEXT = 'You are a delegated subagent: your permission scope was fixed when you were started and cannot be '
|
|
138
|
+
+ 'widened from inside this session. An operation that needs access beyond that scope may request '
|
|
139
|
+
+ 'approval from the user, who can allow or reject it. Do not retry a rejected or denied operation; '
|
|
140
|
+
+ 'state the limitation in your reply so the delegating agent can handle it.';
|
|
141
|
+
/**
|
|
142
|
+
* Compose a child before publication and restore historical descriptor overrides.
|
|
143
|
+
* Explicit selection mounts the named preset; omission synchronously joins the
|
|
144
|
+
* parent's current generation. Registrations belong to the child's scope.
|
|
145
|
+
* @param childCtx - the child agent's scoped creation context.
|
|
146
|
+
* @param parent - the delegating parent used when no preset is selected.
|
|
147
|
+
* @param composition - independent preset and any overrides read from a historical descriptor.
|
|
148
|
+
* @param approvalPolicy - the child's effective approval policy, selecting its delegation statement.
|
|
149
|
+
* @returns A promise when mounting an independent preset; otherwise completes synchronously.
|
|
150
|
+
*/
|
|
151
|
+
export function applyChildComposition(childCtx, parent, composition, approvalPolicy) {
|
|
152
|
+
if (composition.agentPreset !== undefined) {
|
|
153
|
+
const presets = childCtx.get('agentPresets');
|
|
154
|
+
if (presets === undefined) {
|
|
155
|
+
throw new SubagentError('selecting a child agent preset requires the agent-presets service', 'PRESET_UNAVAILABLE');
|
|
156
|
+
}
|
|
157
|
+
return presets.mount(childCtx, composition.agentPreset).then(() => {
|
|
158
|
+
applyChildOverrides(childCtx, composition, approvalPolicy);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
childCtx.get('agentPresets')?.composeFrom(childCtx, parent.ctx);
|
|
162
|
+
applyChildOverrides(childCtx, composition, approvalPolicy);
|
|
163
|
+
}
|
|
164
|
+
function applyChildOverrides(childCtx, composition, approvalPolicy) {
|
|
165
|
+
childCtx.systemPrompt.context({
|
|
166
|
+
name: 'subagent:delegation',
|
|
167
|
+
order: childCtx.systemPrompt.getContextOrder('SUBAGENT_DELEGATION'),
|
|
168
|
+
text: approvalPolicy === 'ask'
|
|
169
|
+
? SUBAGENT_DELEGATION_INTERACTIVE_CONTEXT
|
|
170
|
+
: SUBAGENT_DELEGATION_CONTEXT,
|
|
171
|
+
});
|
|
172
|
+
if (composition.persona !== undefined) {
|
|
173
|
+
childCtx.systemPrompt.section({
|
|
174
|
+
name: 'deployment:persona-prefix',
|
|
175
|
+
order: childCtx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
|
|
176
|
+
text: composition.persona,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (composition.toolFilter !== undefined)
|
|
180
|
+
childCtx.tools.restrict(composition.toolFilter);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Capture the permission state to seed into one delegation. Call synchronously before
|
|
184
|
+
* the child start's first await: a later parent switch belongs to the
|
|
185
|
+
* parent's future, not to this child. Auto and Full access identities are
|
|
186
|
+
* inherited only through the in-process DSH path so either can replace a stale
|
|
187
|
+
* same-bundle fork value. Only the parent session's explicit sandbox override
|
|
188
|
+
* is captured — never deployment defaults or one-shot grants. Approval is
|
|
189
|
+
* pinned to `'never'` by default; `'inherit'` seeds the parent's current
|
|
190
|
+
* effective policy instead, which only a surface that also answers descendant
|
|
191
|
+
* Agents can turn into a prompt.
|
|
192
|
+
* @param parent - the delegating parent agent.
|
|
193
|
+
* @param delegatedApproval - `'never'` to pin rejection, `'inherit'` to seed the parent's effective policy.
|
|
194
|
+
* @returns the sandbox override (or `undefined` without one) and the approval policy seed.
|
|
195
|
+
*/
|
|
196
|
+
export function captureDelegatedPolicyOverrides(parent, delegatedApproval) {
|
|
197
|
+
const preset = parent.ctx.get('permissionPresets')?.current(parent.session);
|
|
198
|
+
const approval = parent.ctx.get('approval');
|
|
199
|
+
return {
|
|
200
|
+
permissionPreset: preset === 'auto' || preset === 'danger-full-access' ? preset : undefined,
|
|
201
|
+
sandboxMode: parent.ctx.get('sandboxPolicy')?.overrideOf(parent.session),
|
|
202
|
+
approvalPolicy: approval === undefined
|
|
203
|
+
? undefined
|
|
204
|
+
: delegatedApproval === 'inherit' ? approval.effectivePolicy(parent.session) : 'never',
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Append the captured delegation policy onto the child's own log as
|
|
209
|
+
* `source: 'delegation'` events after Session announcement and before Agent registration, so the
|
|
210
|
+
* child's effective policy is reconstructable from its log alone. Appends land
|
|
211
|
+
* after any fork seed, so fresh policy wins stale seed state; later child
|
|
212
|
+
* switches still win over these events.
|
|
213
|
+
* @param childSession - the child's announced, writable Session.
|
|
214
|
+
* @param overrides - the policy captured at delegation.
|
|
215
|
+
*/
|
|
216
|
+
export function appendDelegatedPolicyOverrides(childSession, overrides) {
|
|
217
|
+
if (overrides.sandboxMode !== undefined) {
|
|
218
|
+
childSession.append('sandbox/mode', { mode: overrides.sandboxMode, source: 'delegation' });
|
|
219
|
+
}
|
|
220
|
+
if (overrides.approvalPolicy !== undefined) {
|
|
221
|
+
childSession.append('approval/policy', { policy: overrides.approvalPolicy, source: 'delegation' });
|
|
222
|
+
}
|
|
223
|
+
if (overrides.permissionPreset !== undefined) {
|
|
224
|
+
childSession.append('permission/preset', { preset: overrides.permissionPreset });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=child-agent.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe subagent projection and control vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-subagent/client
|
|
5
|
+
*/
|
|
6
|
+
export type * from './control-types.ts';
|
|
7
|
+
export type { SubagentCatalogEntry, SubagentIdentityProjection, SubagentTimingProjection } from './projection-types.ts';
|
|
8
|
+
//# sourceMappingURL=client.d.ts.map
|