@deepseek-ai/dsh-subagent 0.0.1-rc.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/LICENSE +28 -0
- package/README.i18n.yaml +6 -0
- package/README.md +132 -0
- package/README.zh.md +132 -0
- package/lib/index.js +2392 -0
- package/lib/invariant.js +76 -0
- package/lib/types/activation-setup-registry.d.ts +57 -0
- package/lib/types/activation-setup-registry.js +148 -0
- package/lib/types/child-agent.d.ts +139 -0
- package/lib/types/child-agent.js +169 -0
- package/lib/types/client.d.ts +7 -0
- package/lib/types/client.js +7 -0
- package/lib/types/continuation.d.ts +375 -0
- package/lib/types/continuation.js +951 -0
- package/lib/types/depth.d.ts +31 -0
- package/lib/types/depth.js +39 -0
- package/lib/types/descriptor-seed.d.ts +21 -0
- package/lib/types/descriptor-seed.js +24 -0
- package/lib/types/descriptor.d.ts +139 -0
- package/lib/types/descriptor.js +189 -0
- package/lib/types/error.d.ts +11 -0
- package/lib/types/error.js +14 -0
- package/lib/types/index.d.ts +278 -0
- package/lib/types/index.js +338 -0
- package/lib/types/invariant.d.ts +13 -0
- package/lib/types/invariant.js +91 -0
- package/lib/types/lifecycle.d.ts +93 -0
- package/lib/types/lifecycle.js +169 -0
- package/lib/types/list-children.d.ts +112 -0
- package/lib/types/list-children.js +316 -0
- package/lib/types/out-of-process.d.ts +115 -0
- package/lib/types/out-of-process.js +181 -0
- package/lib/types/projection-types.d.ts +60 -0
- package/lib/types/projection-types.js +7 -0
- package/lib/types/projection.d.ts +48 -0
- package/lib/types/projection.js +135 -0
- package/lib/types/run-settlement.d.ts +17 -0
- package/lib/types/run-settlement.js +59 -0
- package/lib/types/types.d.ts +293 -0
- package/lib/types/types.js +19 -0
- package/package.json +106 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure session projections for subagent identity (mode/label) and active-turn
|
|
3
|
+
* duration.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent/projection
|
|
6
|
+
*/
|
|
7
|
+
import type { ProjectionDefinition } from '@deepseek-ai/dsh-session-projection';
|
|
8
|
+
import type { SubagentIdentityProjection } from './projection-types.ts';
|
|
9
|
+
interface TimingState {
|
|
10
|
+
/** Milliseconds accumulated across completed post-descriptor turns. */
|
|
11
|
+
settledMs: number;
|
|
12
|
+
/** Current open interval kept paired inside the fold. */
|
|
13
|
+
active?: {
|
|
14
|
+
since: number;
|
|
15
|
+
through: number;
|
|
16
|
+
};
|
|
17
|
+
/** Latest pre-descriptor turn start, promoted when the child's own descriptor arrives. */
|
|
18
|
+
pendingTurnStart?: number;
|
|
19
|
+
/** Whether the fold has crossed a descriptor in this logical log. */
|
|
20
|
+
descriptorSeen: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fold turn boundaries around the child's own durable descriptor.
|
|
24
|
+
*
|
|
25
|
+
* A fork seed may contain an ancestor descriptor and completed turns. Every
|
|
26
|
+
* descriptor therefore resets the accumulated state; the healthy catalog
|
|
27
|
+
* admits only a child with exactly one descriptor in its own suffix, making
|
|
28
|
+
* the final reset the child's authoritative timing origin.
|
|
29
|
+
*/
|
|
30
|
+
export declare const subagentTimingProjectionDefinition: ProjectionDefinition<'subagentTiming', TimingState>;
|
|
31
|
+
interface IdentityState {
|
|
32
|
+
/** Identity from the last valid descriptor; absent before one, and after an invalid one. */
|
|
33
|
+
identity?: SubagentIdentityProjection;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fold the durable mode/label identity from `subagent/descriptor` events,
|
|
37
|
+
* last-wins: a fork seed may replay an ancestor's descriptor, and the child's
|
|
38
|
+
* own descriptor must override it — the same reset discipline as
|
|
39
|
+
* {@link subagentTimingProjectionDefinition}. A malformed or unknown-version
|
|
40
|
+
* payload resets to the `null` sentinel instead of throwing, so a fork of a
|
|
41
|
+
* healthy ancestor never inherits an identity its own descriptor failed to
|
|
42
|
+
* establish — and the reset survives every JSON push frame, so a consumer
|
|
43
|
+
* holding the earlier identity replaces it instead of keeping it stale;
|
|
44
|
+
* `null` ⟺ no valid descriptor, with the causes deliberately undistinguished.
|
|
45
|
+
*/
|
|
46
|
+
export declare const subagentIdentityProjectionDefinition: ProjectionDefinition<'subagent', IdentityState>;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure session projections for subagent identity (mode/label) and active-turn
|
|
3
|
+
* duration.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent/projection
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { foldSubagentDescriptor } from "./descriptor.js";
|
|
9
|
+
// Zod's optional output includes explicit `undefined`; with
|
|
10
|
+
// exactOptionalPropertyTypes the public interface permits omission only.
|
|
11
|
+
const projectionSchema = z.object({
|
|
12
|
+
settledMs: z.number().int().nonnegative(),
|
|
13
|
+
active: z.object({
|
|
14
|
+
since: z.number().int().nonnegative(),
|
|
15
|
+
through: z.number().int().nonnegative(),
|
|
16
|
+
}).strict().optional(),
|
|
17
|
+
}).strict();
|
|
18
|
+
/**
|
|
19
|
+
* Fold turn boundaries around the child's own durable descriptor.
|
|
20
|
+
*
|
|
21
|
+
* A fork seed may contain an ancestor descriptor and completed turns. Every
|
|
22
|
+
* descriptor therefore resets the accumulated state; the healthy catalog
|
|
23
|
+
* admits only a child with exactly one descriptor in its own suffix, making
|
|
24
|
+
* the final reset the child's authoritative timing origin.
|
|
25
|
+
*/
|
|
26
|
+
export const subagentTimingProjectionDefinition = {
|
|
27
|
+
key: 'subagentTiming',
|
|
28
|
+
schema: projectionSchema,
|
|
29
|
+
init: () => ({ descriptorSeen: false, settledMs: 0 }),
|
|
30
|
+
apply: (state, event) => {
|
|
31
|
+
if (event.type === 'turn/start') {
|
|
32
|
+
return state.descriptorSeen
|
|
33
|
+
? { ...state, active: { since: event.time, through: event.time } }
|
|
34
|
+
: { ...state, pendingTurnStart: event.time };
|
|
35
|
+
}
|
|
36
|
+
if (event.type === 'subagent/descriptor') {
|
|
37
|
+
const activeSince = state.active?.since ?? state.pendingTurnStart;
|
|
38
|
+
return {
|
|
39
|
+
descriptorSeen: true,
|
|
40
|
+
settledMs: 0,
|
|
41
|
+
...(activeSince === undefined
|
|
42
|
+
? {}
|
|
43
|
+
: { active: { since: activeSince, through: event.time } }),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (event.type === 'turn/end') {
|
|
47
|
+
if (!state.descriptorSeen) {
|
|
48
|
+
if (state.pendingTurnStart === undefined)
|
|
49
|
+
return state;
|
|
50
|
+
const { pendingTurnStart: _closed, ...next } = state;
|
|
51
|
+
return next;
|
|
52
|
+
}
|
|
53
|
+
if (state.active === undefined)
|
|
54
|
+
return state;
|
|
55
|
+
const { active, ...rest } = state;
|
|
56
|
+
return {
|
|
57
|
+
...rest,
|
|
58
|
+
settledMs: state.settledMs + Math.max(0, event.time - active.since),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (state.active === undefined)
|
|
62
|
+
return state;
|
|
63
|
+
return { ...state, active: { ...state.active, through: event.time } };
|
|
64
|
+
},
|
|
65
|
+
view: state => ({
|
|
66
|
+
settledMs: state.settledMs,
|
|
67
|
+
...(state.active === undefined ? {} : { active: state.active }),
|
|
68
|
+
}),
|
|
69
|
+
stateVersion: 2,
|
|
70
|
+
};
|
|
71
|
+
// The cast bridges only the optional-label arm: Zod's optional output
|
|
72
|
+
// includes explicit `undefined`, which exactOptionalPropertyTypes excludes
|
|
73
|
+
// from the public interface. The no-value state itself is the serializable
|
|
74
|
+
// `null` arm — never `undefined` — so every registry read and push frame
|
|
75
|
+
// survives JSON.stringify losslessly.
|
|
76
|
+
const identitySchema = z.discriminatedUnion('mode', [
|
|
77
|
+
z.object({
|
|
78
|
+
mode: z.literal('one-shot'),
|
|
79
|
+
label: z.string().optional(),
|
|
80
|
+
seq: z.number().int().nonnegative(),
|
|
81
|
+
}).strict(),
|
|
82
|
+
z.object({
|
|
83
|
+
mode: z.literal('continuable'),
|
|
84
|
+
label: z.string(),
|
|
85
|
+
seq: z.number().int().nonnegative(),
|
|
86
|
+
}).strict(),
|
|
87
|
+
]).nullable();
|
|
88
|
+
/** Interpret one `subagent/descriptor` event's identity; no value when the payload cannot be trusted. */
|
|
89
|
+
function descriptorIdentity(event) {
|
|
90
|
+
let descriptor;
|
|
91
|
+
try {
|
|
92
|
+
descriptor = foldSubagentDescriptor([event]);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Only a malformed current-version payload throws in descriptor parsing;
|
|
96
|
+
// a projection fold must never throw, so damage folds to no value.
|
|
97
|
+
descriptor = undefined;
|
|
98
|
+
}
|
|
99
|
+
if (descriptor === undefined)
|
|
100
|
+
return undefined;
|
|
101
|
+
return descriptor.mode === 'one-shot'
|
|
102
|
+
? {
|
|
103
|
+
mode: 'one-shot',
|
|
104
|
+
...descriptor.label !== undefined ? { label: descriptor.label } : {},
|
|
105
|
+
seq: event.seq,
|
|
106
|
+
}
|
|
107
|
+
: { mode: 'continuable', label: descriptor.label, seq: event.seq };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Fold the durable mode/label identity from `subagent/descriptor` events,
|
|
111
|
+
* last-wins: a fork seed may replay an ancestor's descriptor, and the child's
|
|
112
|
+
* own descriptor must override it — the same reset discipline as
|
|
113
|
+
* {@link subagentTimingProjectionDefinition}. A malformed or unknown-version
|
|
114
|
+
* payload resets to the `null` sentinel instead of throwing, so a fork of a
|
|
115
|
+
* healthy ancestor never inherits an identity its own descriptor failed to
|
|
116
|
+
* establish — and the reset survives every JSON push frame, so a consumer
|
|
117
|
+
* holding the earlier identity replaces it instead of keeping it stale;
|
|
118
|
+
* `null` ⟺ no valid descriptor, with the causes deliberately undistinguished.
|
|
119
|
+
*/
|
|
120
|
+
export const subagentIdentityProjectionDefinition = {
|
|
121
|
+
key: 'subagent',
|
|
122
|
+
schema: identitySchema,
|
|
123
|
+
init: () => ({}),
|
|
124
|
+
apply: (state, event) => {
|
|
125
|
+
if (event.type !== 'subagent/descriptor')
|
|
126
|
+
return state;
|
|
127
|
+
const identity = descriptorIdentity(event);
|
|
128
|
+
return identity === undefined ? {} : { identity };
|
|
129
|
+
},
|
|
130
|
+
view: state => state.identity ?? null,
|
|
131
|
+
// Bumped when the identity gained its `seq` field: an older checkpoint row
|
|
132
|
+
// would replay into a value the schema rejects, so it must refold instead.
|
|
133
|
+
stateVersion: 2,
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settlement of one ONE-SHOT subagent run into a background-Task outcome. Only
|
|
3
|
+
* the one-shot background path uses Tasks; continuable children have no Task,
|
|
4
|
+
* no per-message result, and no Task cancellation.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/run-settlement
|
|
7
|
+
*/
|
|
8
|
+
import type { TaskOutcome } from '@deepseek-ai/dsh-tasks';
|
|
9
|
+
import type { SubagentRun } from './types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Await the child result, dispose the run, then return its task outcome. Result
|
|
12
|
+
* and disposal failures become `failed`; when both fail, both details survive.
|
|
13
|
+
* @param run - live run to settle and release.
|
|
14
|
+
* @returns outcome after child resources are released.
|
|
15
|
+
*/
|
|
16
|
+
export declare function settleRun(run: SubagentRun): Promise<TaskOutcome>;
|
|
17
|
+
//# sourceMappingURL=run-settlement.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settlement of one ONE-SHOT subagent run into a background-Task outcome. Only
|
|
3
|
+
* the one-shot background path uses Tasks; continuable children have no Task,
|
|
4
|
+
* no per-message result, and no Task cancellation.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/run-settlement
|
|
7
|
+
*/
|
|
8
|
+
/** Flatten a child's final output blocks to the task's final text. */
|
|
9
|
+
function finalText(blocks) {
|
|
10
|
+
return blocks
|
|
11
|
+
.filter((block) => block.type === 'text')
|
|
12
|
+
.map(block => block.text)
|
|
13
|
+
.join('');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Map a child result to the task outcome: completed carries final text,
|
|
17
|
+
* aborted is killed, and every other reason is failed without partial output.
|
|
18
|
+
* @param result - child terminal result.
|
|
19
|
+
* @returns outcome for the `ctx.tasks` registration.
|
|
20
|
+
*/
|
|
21
|
+
function runOutcome(result) {
|
|
22
|
+
switch (result.stopReason) {
|
|
23
|
+
case 'completed':
|
|
24
|
+
return { status: 'completed', output: finalText(result.output) };
|
|
25
|
+
case 'aborted':
|
|
26
|
+
return { status: 'killed' };
|
|
27
|
+
case 'error':
|
|
28
|
+
case 'max-tokens':
|
|
29
|
+
case 'refusal':
|
|
30
|
+
return { status: 'failed', detail: result.stopReason };
|
|
31
|
+
// Merge-extensible reasons remain failures with their raw detail.
|
|
32
|
+
default:
|
|
33
|
+
return { status: 'failed', detail: String(result.stopReason) };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Await the child result, dispose the run, then return its task outcome. Result
|
|
38
|
+
* and disposal failures become `failed`; when both fail, both details survive.
|
|
39
|
+
* @param run - live run to settle and release.
|
|
40
|
+
* @returns outcome after child resources are released.
|
|
41
|
+
*/
|
|
42
|
+
export async function settleRun(run) {
|
|
43
|
+
let outcome;
|
|
44
|
+
try {
|
|
45
|
+
outcome = runOutcome(await run.result);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
outcome = { status: 'failed', detail: String(error) };
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await run.dispose();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
const prefix = outcome.detail === undefined ? '' : `${outcome.detail}; `;
|
|
55
|
+
return { status: 'failed', detail: `${prefix}dispose failed: ${String(error)}` };
|
|
56
|
+
}
|
|
57
|
+
return outcome;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=run-settlement.js.map
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam's consumer-facing contracts: request, result, and capability types
|
|
3
|
+
* for {@link SubagentProvider}, plus the `subagent/start` and `subagent/end`
|
|
4
|
+
* payloads that plugins and hosts observe. Internal control interfaces belong
|
|
5
|
+
* with their implementation — the lifecycle observer in `./lifecycle.ts`, the
|
|
6
|
+
* continuation host in `./continuation.ts` — so this module stays the published
|
|
7
|
+
* surface rather than a bag of everything type-shaped.
|
|
8
|
+
*
|
|
9
|
+
* @module @deepseek-ai/dsh-subagent/types
|
|
10
|
+
*/
|
|
11
|
+
import type { Agent, AgentOptions } from '@deepseek-ai/dsh-agent';
|
|
12
|
+
import type { Branded } from '@deepseek-ai/dsh-brand';
|
|
13
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import type { SessionEvent, SessionId } from '@deepseek-ai/dsh-session';
|
|
15
|
+
import type { ObjectJsonSchema, ToolRestriction } from '@deepseek-ai/dsh-tools';
|
|
16
|
+
import type { SubagentDescriptorData } from './descriptor.ts';
|
|
17
|
+
/** Identifies one accepted subagent run across its lifecycle event pair. */
|
|
18
|
+
export type SubagentRunId = Branded<'SubagentRunId'>;
|
|
19
|
+
/**
|
|
20
|
+
* Brand a string as a {@link SubagentRunId}.
|
|
21
|
+
* @param id - the raw run id.
|
|
22
|
+
* @returns the same string, branded.
|
|
23
|
+
*/
|
|
24
|
+
export declare function SubagentRunId(id: string): SubagentRunId;
|
|
25
|
+
/**
|
|
26
|
+
* Observe-only identifying detail for a published subagent run, carried by
|
|
27
|
+
* `subagent/start`. One-shot runs and continuable Activation epochs share this
|
|
28
|
+
* payload, so an observer sees the same vocabulary for both.
|
|
29
|
+
*/
|
|
30
|
+
export interface SubagentRunInfo {
|
|
31
|
+
/** Unique identity shared with the paired terminal event. */
|
|
32
|
+
readonly runId: SubagentRunId;
|
|
33
|
+
/**
|
|
34
|
+
* Provider name recorded when the child was first created. The provider may
|
|
35
|
+
* be absent when an accepted one-shot run becomes ready or a persisted
|
|
36
|
+
* Activation cold-resumes, because neither lifecycle depends on continued
|
|
37
|
+
* registration.
|
|
38
|
+
*/
|
|
39
|
+
readonly provider: string;
|
|
40
|
+
/** The child agent's id. */
|
|
41
|
+
readonly id: SessionId;
|
|
42
|
+
/** Snapshot of whether `SubagentRun.localAgent` was present when start fulfilled. */
|
|
43
|
+
readonly local: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Observe-only outcome detail for a settled subagent run, carried by
|
|
47
|
+
* `subagent/end` and paired with one {@link SubagentRunInfo} by `runId`.
|
|
48
|
+
*/
|
|
49
|
+
export interface SubagentRunEndInfo {
|
|
50
|
+
/** Unique identity shared with the paired start event. */
|
|
51
|
+
readonly runId: SubagentRunId;
|
|
52
|
+
/** The same provider name carried by the paired start event. */
|
|
53
|
+
readonly provider: string;
|
|
54
|
+
/** The child agent's id. */
|
|
55
|
+
readonly id: SessionId;
|
|
56
|
+
/** Snapshot of whether `SubagentRun.localAgent` was present when start fulfilled. */
|
|
57
|
+
readonly local: boolean;
|
|
58
|
+
/** The terminal stop reason. */
|
|
59
|
+
readonly stopReason: SubagentResult['stopReason'];
|
|
60
|
+
/** The child's final assistant output, absent on infrastructure rejection. */
|
|
61
|
+
readonly lastAssistantMessage?: ContentBlock[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Which START-TIME features a provider supports. Checked by the service before delegating to
|
|
65
|
+
* {@link SubagentProvider.start}: a request that needs a capability the chosen provider lacks
|
|
66
|
+
* is rejected with a typed error rather than accepted-then-ignored (the "fail loud, no silent
|
|
67
|
+
* degradation" rule). These flags describe the ONE-SHOT
|
|
68
|
+
* {@link SubagentProvider.start} path, where the provider composes the child;
|
|
69
|
+
* continuable children are composed by the continuation manager itself and are
|
|
70
|
+
* gated by {@link SubagentProvider.prepareContinuable} instead. Each flag
|
|
71
|
+
* corresponds one-to-one to a {@link SubagentStartRequest} option: `depthLimit`
|
|
72
|
+
* to `maxDepth`; the other names match.
|
|
73
|
+
*/
|
|
74
|
+
export interface SubagentCapabilities {
|
|
75
|
+
readonly outputSchema: boolean;
|
|
76
|
+
readonly depthLimit: boolean;
|
|
77
|
+
readonly toolFilter: boolean;
|
|
78
|
+
readonly persona: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* What a caller asks for when starting a ONE-SHOT subagent. The tool layer
|
|
82
|
+
* builds this from the model's `{ description, prompt }` plus its own config;
|
|
83
|
+
* the service validates {@link SubagentCapabilities} against the named provider
|
|
84
|
+
* and resolves the durable descriptor before dispatching to
|
|
85
|
+
* {@link SubagentProvider.start}.
|
|
86
|
+
*/
|
|
87
|
+
export interface SubagentStartRequest {
|
|
88
|
+
/** Optional short display label persisted with a session-backed child. */
|
|
89
|
+
readonly label?: string;
|
|
90
|
+
/** Content delivered as the child's user message. */
|
|
91
|
+
readonly prompt: ContentBlock[];
|
|
92
|
+
/**
|
|
93
|
+
* The spawning agent. In-process providers derive workspace, lineage, and
|
|
94
|
+
* delegation depth from its durable session state. ACP reads only its cwd,
|
|
95
|
+
* and only when no deployment `cwd` override is configured.
|
|
96
|
+
*/
|
|
97
|
+
readonly parent: Agent;
|
|
98
|
+
/**
|
|
99
|
+
* Cancellation signal from the spawning context (the tool's `exec.signal`).
|
|
100
|
+
* This is the canonical cancellation channel both before and after startup:
|
|
101
|
+
* a provider rejects `start()` after cleaning partial resources when it
|
|
102
|
+
* fires before the run is published, and cancels the published run's
|
|
103
|
+
* remaining turn work when it fires afterward.
|
|
104
|
+
*/
|
|
105
|
+
readonly signal: AbortSignal;
|
|
106
|
+
readonly agentOptions?: AgentOptions;
|
|
107
|
+
/**
|
|
108
|
+
* Object-rooted JSON Schema within `assertObjectJsonSchema`'s enforced subset. Start rejects
|
|
109
|
+
* unsupported schemas or providers without the capability. Data must be plain host-realm JSON;
|
|
110
|
+
* a successful child returns the matching value as {@link SubagentResult.structured}.
|
|
111
|
+
*/
|
|
112
|
+
readonly outputSchema?: ObjectJsonSchema;
|
|
113
|
+
/**
|
|
114
|
+
* Optional absolute delegation-depth cap for the child being started: its
|
|
115
|
+
* computed depth must be less than or equal to this non-negative safe
|
|
116
|
+
* integer. Requires {@link SubagentCapabilities.depthLimit}; rejected at
|
|
117
|
+
* start otherwise.
|
|
118
|
+
*/
|
|
119
|
+
readonly maxDepth?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Optional child tool scoping. Requires {@link SubagentCapabilities.toolFilter};
|
|
122
|
+
* rejected at start otherwise. In-process backends apply it as a scoped
|
|
123
|
+
* `tools.restrict()` in the child's creation window: the named tools vanish
|
|
124
|
+
* from the child's prompt AND refuse to execute (one visibility), with loud
|
|
125
|
+
* unknown-name validation.
|
|
126
|
+
*/
|
|
127
|
+
readonly toolFilter?: ToolRestriction;
|
|
128
|
+
/**
|
|
129
|
+
* Optional per-child persona. Requires {@link SubagentCapabilities.persona};
|
|
130
|
+
* rejected at start otherwise. In-process backends register it as a scoped
|
|
131
|
+
* `deployment:persona` section on the child, SHADOWING the deployment's
|
|
132
|
+
* persona for this child alone — same template semantics as the deployment
|
|
133
|
+
* persona (strict `{{…}}` interpolation against the registered variables).
|
|
134
|
+
*/
|
|
135
|
+
readonly persona?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Provider-facing one-shot request after {@link SubagentService.start} resolves
|
|
139
|
+
* the durable child descriptor.
|
|
140
|
+
*/
|
|
141
|
+
export interface ResolvedSubagentStartRequest extends SubagentStartRequest {
|
|
142
|
+
/** Detached descriptor a session-backed provider persists in the child log. */
|
|
143
|
+
readonly descriptor: SubagentDescriptorData;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* What the continuation manager asks a provider for while materializing one
|
|
147
|
+
* continuable child's FIRST activation. The manager has already reserved the
|
|
148
|
+
* durable child identity and owns every later operation, so this request
|
|
149
|
+
* carries only what distinguishes a fresh child from one seeded with parent
|
|
150
|
+
* history.
|
|
151
|
+
*/
|
|
152
|
+
export interface ContinuableCreateRequest {
|
|
153
|
+
/** The reserved durable child session id, for provider diagnostics. */
|
|
154
|
+
readonly sessionId: SessionId;
|
|
155
|
+
/** The delegating parent agent whose history a seeding provider reads. */
|
|
156
|
+
readonly parent: Agent;
|
|
157
|
+
/**
|
|
158
|
+
* Caller cancellation, which owns preparation only until the manager accepts
|
|
159
|
+
* the initial prompt into the child's inbox.
|
|
160
|
+
*/
|
|
161
|
+
readonly signal: AbortSignal;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* A provider's detached contribution to one continuable child's creation. This
|
|
165
|
+
* is DATA, never a capability: it carries no Agent, `AgentHandle`, prompt
|
|
166
|
+
* delivery, result, disposal, or resume operation, because the continuation
|
|
167
|
+
* manager owns the child's whole lifecycle after preparation.
|
|
168
|
+
*/
|
|
169
|
+
export interface ContinuableCreateSpec {
|
|
170
|
+
/**
|
|
171
|
+
* Completed-turn prefix of the parent's log to seed the child session with,
|
|
172
|
+
* or absent for a fresh child. Same durable contract as
|
|
173
|
+
* `CreateAgentOptions.seed`: contiguous from seq 0, lossless JSON, balanced.
|
|
174
|
+
*/
|
|
175
|
+
readonly seed?: readonly SessionEvent[];
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Why a subagent run ended. Merge-extensible (a backend may add variants);
|
|
179
|
+
* consumers branch on the known cases and fall through `default`. The known
|
|
180
|
+
* cases mirror the harness turn-end vocabulary so the tool layer can map a
|
|
181
|
+
* non-`completed` result to an `isError` tool result.
|
|
182
|
+
*/
|
|
183
|
+
export interface SubagentStopReasonMap {
|
|
184
|
+
/** The child finished its turn normally. */
|
|
185
|
+
completed: 'completed';
|
|
186
|
+
/** Cancelled through the request signal or disposal. */
|
|
187
|
+
aborted: 'aborted';
|
|
188
|
+
/** Model or transport failure. */
|
|
189
|
+
error: 'error';
|
|
190
|
+
/** The child hit its token ceiling before finishing. */
|
|
191
|
+
'max-tokens': 'max-tokens';
|
|
192
|
+
/** The child declined the task. */
|
|
193
|
+
refusal: 'refusal';
|
|
194
|
+
}
|
|
195
|
+
/** The union over {@link SubagentStopReasonMap} — widens automatically as backends merge in variants. */
|
|
196
|
+
export type SubagentStopReason = SubagentStopReasonMap[keyof SubagentStopReasonMap];
|
|
197
|
+
/**
|
|
198
|
+
* The terminal outcome of a subagent run, resolved by {@link SubagentRun.result}.
|
|
199
|
+
*/
|
|
200
|
+
export interface SubagentResult {
|
|
201
|
+
/** The child's final assistant output (the last assistant message's content). */
|
|
202
|
+
readonly output: ContentBlock[];
|
|
203
|
+
/**
|
|
204
|
+
* The structured result after a requested `outputSchema` was successfully
|
|
205
|
+
* satisfied. Requesting a schema does not guarantee presence: a provider can
|
|
206
|
+
* end with `stopReason: 'error'` when the child fails or finishes without a
|
|
207
|
+
* valid capture. The structured value is validated against the requested
|
|
208
|
+
* output schema by the provider; `unknown` here because the seam is
|
|
209
|
+
* schema-agnostic.
|
|
210
|
+
*/
|
|
211
|
+
readonly structured?: unknown;
|
|
212
|
+
/** Why the run ended. A non-`completed` reason means `output` may be partial. */
|
|
213
|
+
readonly stopReason: SubagentStopReason;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* ONE-SHOT child handle returned after publication. Prompt submission, turn
|
|
217
|
+
* work, and infrastructure faults after that boundary belong to {@link result}.
|
|
218
|
+
* Consumers await that result and must always {@link dispose} to cancel
|
|
219
|
+
* remaining work and reach quiescence. A run is one disposable foreground
|
|
220
|
+
* delegation with one result; continuable conversations have no run — the
|
|
221
|
+
* continuation manager holds their `AgentHandle` directly and orders every
|
|
222
|
+
* turn through the child's own inbox.
|
|
223
|
+
*/
|
|
224
|
+
export interface SubagentRun {
|
|
225
|
+
/**
|
|
226
|
+
* Parent-scoped run id. For a local run, this MUST equal the published child
|
|
227
|
+
* session id, whose `parentSession` records `request.parent.session.id`; a
|
|
228
|
+
* remote provider mints an id unique in the parent namespace.
|
|
229
|
+
*/
|
|
230
|
+
readonly id: SessionId;
|
|
231
|
+
/**
|
|
232
|
+
* The exact published in-process child, or `undefined` for a remote run.
|
|
233
|
+
* When present, its id is {@link id}; the provider retains no ownership
|
|
234
|
+
* implication beyond the run's ordinary {@link dispose} contract.
|
|
235
|
+
*/
|
|
236
|
+
readonly localAgent: Agent | undefined;
|
|
237
|
+
/**
|
|
238
|
+
* Resolves with the child's terminal {@link SubagentResult} when the run
|
|
239
|
+
* settles. Does NOT reject on a child-level failure — a model/transport
|
|
240
|
+
* failure resolves with `stopReason: 'error'` so the consumer maps it to an
|
|
241
|
+
* `isError` tool result. Rejects on an infrastructure fault the seam cannot
|
|
242
|
+
* represent as a stop reason.
|
|
243
|
+
*/
|
|
244
|
+
readonly result: Promise<SubagentResult>;
|
|
245
|
+
/**
|
|
246
|
+
* Cancel remaining work, reach child quiescence, and release resources.
|
|
247
|
+
* Idempotent.
|
|
248
|
+
*/
|
|
249
|
+
dispose(): Promise<void>;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* One registered transport for running child agents. Providers are trusted
|
|
253
|
+
* same-process implementations; callers treat descriptors and returned values
|
|
254
|
+
* as borrowed immutable data.
|
|
255
|
+
*/
|
|
256
|
+
export interface SubagentProvider {
|
|
257
|
+
/** Unique registry name (e.g. `spawn`, `fork`, `acp`). */
|
|
258
|
+
readonly name: string;
|
|
259
|
+
/** The start-time features this provider supports (see {@link SubagentCapabilities}). */
|
|
260
|
+
readonly capabilities: SubagentCapabilities;
|
|
261
|
+
/**
|
|
262
|
+
* Whether the child sees the parent's completed-turn prefix. This is descriptive, not a
|
|
263
|
+
* service-validated start capability: the model-facing tool derives truthful wording from it.
|
|
264
|
+
* It says nothing about tool registration, injected services, or authority inheritance.
|
|
265
|
+
*/
|
|
266
|
+
readonly inheritsParentContext: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Establish a ONE-SHOT child and return its handle after publication.
|
|
269
|
+
* The service has already validated that every requested start-time
|
|
270
|
+
* capability is supported and resolved `request.descriptor`, so a
|
|
271
|
+
* session-backed implementation appends that descriptor inside the child's
|
|
272
|
+
* initial turn. Before fulfillment, the provider owns setup and cleans any
|
|
273
|
+
* unpublished partial resources before rejecting. Ownership transfers on
|
|
274
|
+
* fulfillment; subsequent turn or infrastructure failure settles through
|
|
275
|
+
* the returned run.
|
|
276
|
+
*/
|
|
277
|
+
start(request: ResolvedSubagentStartRequest): Promise<SubagentRun>;
|
|
278
|
+
/**
|
|
279
|
+
* OPTIONAL (continuable-creation capability): contribute the detached
|
|
280
|
+
* creation inputs that distinguish this provider's continuable children —
|
|
281
|
+
* only whether the child session is seeded with parent history. Method
|
|
282
|
+
* presence IS the capability: the service rejects continuable starts on
|
|
283
|
+
* providers without it, while a provider that has it may still serve
|
|
284
|
+
* ordinary one-shot delegations.
|
|
285
|
+
*
|
|
286
|
+
* This is the provider's ONLY participation in a continuable child. The
|
|
287
|
+
* continuation manager owns identity reservation, composition, Agent
|
|
288
|
+
* creation, prompt delivery, cold resume, ownership, and disposal, so a
|
|
289
|
+
* provider never sees the child's Agent, handle, turns, or teardown.
|
|
290
|
+
*/
|
|
291
|
+
prepareContinuable?(request: ContinuableCreateRequest): Promise<ContinuableCreateSpec>;
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam's consumer-facing contracts: request, result, and capability types
|
|
3
|
+
* for {@link SubagentProvider}, plus the `subagent/start` and `subagent/end`
|
|
4
|
+
* payloads that plugins and hosts observe. Internal control interfaces belong
|
|
5
|
+
* with their implementation — the lifecycle observer in `./lifecycle.ts`, the
|
|
6
|
+
* continuation host in `./continuation.ts` — so this module stays the published
|
|
7
|
+
* surface rather than a bag of everything type-shaped.
|
|
8
|
+
*
|
|
9
|
+
* @module @deepseek-ai/dsh-subagent/types
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Brand a string as a {@link SubagentRunId}.
|
|
13
|
+
* @param id - the raw run id.
|
|
14
|
+
* @returns the same string, branded.
|
|
15
|
+
*/
|
|
16
|
+
export function SubagentRunId(id) {
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.js.map
|