@deepseek-ai/dsh-subagent 0.2.0-rc.2 → 0.2.1-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 +36 -36
- package/README.md +33 -27
- package/README.zh.md +33 -27
- package/lib/index.js +1436 -1304
- package/lib/typert.host.js +73 -60
- package/lib/typert.remote-client.js +2 -2
- package/lib/types/activation.d.ts +114 -0
- package/lib/types/activation.js +112 -0
- package/lib/types/catalog.d.ts +14 -6
- package/lib/types/catalog.js +34 -30
- package/lib/types/child-agent.d.ts +1 -3
- package/lib/types/child-agent.js +1 -3
- package/lib/types/continuation-messages.d.ts +4 -3
- package/lib/types/continuation-messages.js +13 -5
- package/lib/types/control-types.d.ts +7 -0
- package/lib/types/descriptor.d.ts +7 -46
- package/lib/types/descriptor.js +20 -21
- package/lib/types/index.d.ts +52 -53
- package/lib/types/index.js +75 -95
- package/lib/types/internal.d.ts +1 -1
- package/lib/types/lifecycle.d.ts +28 -58
- package/lib/types/lifecycle.js +9 -74
- package/lib/types/list-children.js +1 -1
- package/lib/types/manager.d.ts +247 -0
- package/lib/types/manager.js +1294 -0
- package/lib/types/out-of-process.d.ts +2 -28
- package/lib/types/out-of-process.js +3 -44
- package/lib/types/projection-types.d.ts +3 -0
- package/lib/types/structured.d.ts +49 -0
- package/lib/types/structured.js +130 -0
- package/lib/types/types.d.ts +57 -81
- package/lib/types/types.js +1 -1
- package/package.json +53 -63
- package/lib/invariant.js +0 -76
- package/lib/types/continuation-activation.d.ts +0 -267
- package/lib/types/continuation-activation.js +0 -700
- package/lib/types/continuation.d.ts +0 -124
- package/lib/types/continuation.js +0 -455
- package/lib/types/inbox.d.ts +0 -43
- package/lib/types/inbox.js +0 -61
- package/lib/types/invariant.d.ts +0 -13
- package/lib/types/invariant.js +0 -91
- package/lib/types/run-settlement.d.ts +0 -17
- package/lib/types/run-settlement.js +0 -70
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owns subagent startup, message admission, cold resume, and execution lifetimes.
|
|
3
|
+
* One child lock orders input acceptance and closure; one activation map owns
|
|
4
|
+
* capacity, parent relationships, and resource release across all providers.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/manager
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
10
|
+
import type { ContentBlock, MessageId, MessageSource } from '@deepseek-ai/dsh-llm';
|
|
11
|
+
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
12
|
+
import type { ActivationObserver } from './lifecycle.ts';
|
|
13
|
+
import type { ContinuableCreateRequest, ContinuableCreateSpec, SubagentInterruptAuthority, SubagentActivationSpec, SubagentActivation, SubagentRun, SubagentSendMessageOptions, ResolvedSubagentStartRequest } from './types.ts';
|
|
14
|
+
/** Package-private hooks supplied by the owning service. */
|
|
15
|
+
interface SubagentHost {
|
|
16
|
+
startExternal(name: string, request: ResolvedSubagentStartRequest): Promise<SubagentRun>;
|
|
17
|
+
/** Resolve one provider's detached continuable-creation contribution. */
|
|
18
|
+
prepareContinuable(name: string, request: ContinuableCreateRequest): Promise<ContinuableCreateSpec>;
|
|
19
|
+
/** Build the lifecycle observer for one Activation residency epoch. */
|
|
20
|
+
observeActivation(provider: string, childId: SessionId, parent: Agent): ActivationObserver;
|
|
21
|
+
}
|
|
22
|
+
/** Own subagent requests and the resources of every live activation. */
|
|
23
|
+
export declare class SubagentManager {
|
|
24
|
+
private readonly ctx;
|
|
25
|
+
private readonly host;
|
|
26
|
+
private readonly maxActiveSubagents;
|
|
27
|
+
/** Child session id → its live Activation. Process-local, never durable. */
|
|
28
|
+
private readonly resident;
|
|
29
|
+
/** Root identities retain their pool across child settlement without retaining dead roots. */
|
|
30
|
+
private readonly rootPools;
|
|
31
|
+
/** Materializations admitted before drain, tracked through publication or rollback. */
|
|
32
|
+
private readonly materializations;
|
|
33
|
+
/** Per-child serializer shared by delivery, release, and disposal. */
|
|
34
|
+
private readonly locks;
|
|
35
|
+
/** Structural Cordis owner of every Activation handle. */
|
|
36
|
+
private readonly ownerCtx;
|
|
37
|
+
/**
|
|
38
|
+
* Exact roots whose host teardown has begun, with the live lineage members
|
|
39
|
+
* observed under each root. Entries remain until that exact root leaves the
|
|
40
|
+
* Agent registry, closing admission throughout its host's teardown without
|
|
41
|
+
* poisoning a later same-id replacement.
|
|
42
|
+
*/
|
|
43
|
+
private readonly closingScopes;
|
|
44
|
+
private draining;
|
|
45
|
+
/**
|
|
46
|
+
* Build one manager inside the service's Agent-injected context.
|
|
47
|
+
* @param ctx - context providing Agents, Sessions, and teardown ownership.
|
|
48
|
+
* @param host - provider dispatch and lifecycle observation owned by the service.
|
|
49
|
+
* @param maxActiveSubagents - the current configured child capacity.
|
|
50
|
+
*/
|
|
51
|
+
constructor(ctx: Context, host: SubagentHost, maxActiveSubagents: () => number);
|
|
52
|
+
/**
|
|
53
|
+
* Interrupt one live continuable child's current turn under the supplied authority.
|
|
54
|
+
* @param targetSessionId - the durable child session id to interrupt.
|
|
55
|
+
* @param authority - the human parent address or exact live ancestor Agent.
|
|
56
|
+
*/
|
|
57
|
+
interrupt(targetSessionId: SessionId, authority: SubagentInterruptAuthority): void;
|
|
58
|
+
/**
|
|
59
|
+
* Close admission, await every already-admitted materialization through
|
|
60
|
+
* publication or rollback, then dispose the stable live Activation graph
|
|
61
|
+
* child-first.
|
|
62
|
+
*/
|
|
63
|
+
drain(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Join progressing child work, leaving idle parked inboxes resident.
|
|
66
|
+
* @param parent - exact live parent whose descendants are observed.
|
|
67
|
+
* @returns whether work was joined and the host must recheck parent completion.
|
|
68
|
+
*/
|
|
69
|
+
waitForChildren(parent: Agent): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Stop the managed descendants of exact live host-owned parents.
|
|
72
|
+
* @param parents - exact live roots whose managed descendants must stop.
|
|
73
|
+
*/
|
|
74
|
+
drainDescendants(parents: readonly Agent[]): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Release selected resident direct children of one exact live parent.
|
|
77
|
+
* @param parent - exact live direct parent authorizing the selected release.
|
|
78
|
+
* @param childIds - durable direct-child ids to release when resident.
|
|
79
|
+
*/
|
|
80
|
+
drainChildren(parent: Agent, childIds: readonly SessionId[]): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Start one continuable background child and resolve at initial inbox acceptance.
|
|
83
|
+
* Every earlier failure disposes any created handle and rolls back Activation
|
|
84
|
+
* and parent ownership without returning either id.
|
|
85
|
+
* @param spec - provider, delegation request, and caller cancellation.
|
|
86
|
+
* @returns the durable child id and accepted initial prompt message id.
|
|
87
|
+
*/
|
|
88
|
+
startLocal(spec: SubagentActivationSpec): Promise<SubagentActivation & {
|
|
89
|
+
messageId: MessageId;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Start an external backend under activation ownership.
|
|
93
|
+
* @param spec - task, provider, cancellation, and delivery policy.
|
|
94
|
+
* @returns the accepted activation and its result/disposal capabilities.
|
|
95
|
+
*/
|
|
96
|
+
startExternal(spec: SubagentActivationSpec): Promise<SubagentActivation>;
|
|
97
|
+
/** Capture the explicit or inherited directory while the parent still owns startup. */
|
|
98
|
+
private resolveDirectory;
|
|
99
|
+
/**
|
|
100
|
+
* Deliver one model-authored message to a direct continuable child or to the
|
|
101
|
+
* sender's direct parent. A missing direct child cold-resumes through the
|
|
102
|
+
* ordinary continuation lifecycle.
|
|
103
|
+
* @param sender - exact live Agent authorizing and originating the message.
|
|
104
|
+
* @param targetId - durable direct-parent or direct-child session id.
|
|
105
|
+
* @param content - model-authored content to deliver.
|
|
106
|
+
* @param options - caller cancellation before acceptance.
|
|
107
|
+
* @returns the accepted message's inbox id.
|
|
108
|
+
*/
|
|
109
|
+
sendMessage(sender: Agent, targetId: SessionId, content: ContentBlock[], options: SubagentSendMessageOptions): Promise<MessageId>;
|
|
110
|
+
/**
|
|
111
|
+
* Queue one human-authored prompt as a distinct direct-child turn.
|
|
112
|
+
* @param parent - exact live direct parent authorizing delivery.
|
|
113
|
+
* @param childId - durable direct-child session id.
|
|
114
|
+
* @param content - model-visible prompt blocks.
|
|
115
|
+
* @param source - durable attribution for the human prompt.
|
|
116
|
+
* @param signal - caller cancellation before inbox acceptance.
|
|
117
|
+
* @returns the accepted durable message id.
|
|
118
|
+
*/
|
|
119
|
+
queuePrompt(parent: Agent, childId: SessionId, content: ContentBlock[], source: MessageSource, signal: AbortSignal): Promise<MessageId>;
|
|
120
|
+
/**
|
|
121
|
+
* Steer one host-authored prompt to a direct continuable child.
|
|
122
|
+
* @param parent - exact live direct parent authorizing delivery.
|
|
123
|
+
* @param childId - durable direct-child session id.
|
|
124
|
+
* @param content - model-visible prompt blocks.
|
|
125
|
+
* @param source - durable attribution for the host prompt.
|
|
126
|
+
* @param signal - caller cancellation before inbox acceptance.
|
|
127
|
+
* @returns the accepted durable message id.
|
|
128
|
+
*/
|
|
129
|
+
steerPrompt(parent: Agent, childId: SessionId, content: ContentBlock[], source: MessageSource, signal: AbortSignal): Promise<MessageId>;
|
|
130
|
+
/** Admit local input synchronously before any teardown can begin. */
|
|
131
|
+
private deliver;
|
|
132
|
+
/**
|
|
133
|
+
* Reject one child identity already owned by a live Agent or Session.
|
|
134
|
+
* @param childId - proposed durable child session id.
|
|
135
|
+
*/
|
|
136
|
+
private assertChildIdAvailable;
|
|
137
|
+
/**
|
|
138
|
+
* Pre-register `childId` in a continuation-managed parent's owned set so the
|
|
139
|
+
* parent cannot settle while a caller is still establishing or resuming that
|
|
140
|
+
* child. Returns a releaser for the failure path; it removes only a hold
|
|
141
|
+
* this call added, and leaves ownership in place once a live Activation for
|
|
142
|
+
* the child exists.
|
|
143
|
+
* @param parent - the live direct parent the operation is admitted under.
|
|
144
|
+
* @param childId - the durable child the operation addresses.
|
|
145
|
+
* @returns the failure-path releaser; a no-op when nothing was added.
|
|
146
|
+
*/
|
|
147
|
+
private holdOwnership;
|
|
148
|
+
/**
|
|
149
|
+
* Apply activation admission to a resident parent before delivering input.
|
|
150
|
+
* @param parent - exact live Agent receiving the message.
|
|
151
|
+
* @param message - durable user message to deliver.
|
|
152
|
+
* @param delivery - receiving inbox destination.
|
|
153
|
+
*/
|
|
154
|
+
private sendWaking;
|
|
155
|
+
/**
|
|
156
|
+
* Reject new admission once the manager or this exact parent tree began draining.
|
|
157
|
+
* @param agent - exact live Agent whose lineage determines admission.
|
|
158
|
+
*/
|
|
159
|
+
private assertAdmitting;
|
|
160
|
+
/**
|
|
161
|
+
* Authorize one operation against the durable direct-parent lineage.
|
|
162
|
+
* @param parent - exact live Agent claiming direct-parent authority.
|
|
163
|
+
* @param childId - durable child session id addressed by the operation.
|
|
164
|
+
* @param parentSession - durable direct-parent id recorded by the child.
|
|
165
|
+
*/
|
|
166
|
+
private authorizeLineage;
|
|
167
|
+
/** Reject parent authority after the live registry entry changes. */
|
|
168
|
+
private assertLiveParent;
|
|
169
|
+
/**
|
|
170
|
+
* Create or resume one child Agent and publish its Activation.
|
|
171
|
+
* @param inputs - reconstruction and admission inputs for the residency epoch.
|
|
172
|
+
* @returns the published process-local Activation.
|
|
173
|
+
*/
|
|
174
|
+
private materialize;
|
|
175
|
+
/**
|
|
176
|
+
* Stop and release one Activation through its memoized close transaction.
|
|
177
|
+
* @param activation - exact residency epoch to close.
|
|
178
|
+
* @returns the shared close transaction.
|
|
179
|
+
*/
|
|
180
|
+
private dispose;
|
|
181
|
+
/** Close admission synchronously and share one release, including startup rollback. */
|
|
182
|
+
private close;
|
|
183
|
+
/** Dispose independent roots and report every branch failure after all settle. */
|
|
184
|
+
private disposeRoots;
|
|
185
|
+
/** Return the retained member set for one exact scoped-teardown root. */
|
|
186
|
+
private closingMembers;
|
|
187
|
+
/** Return the exact currently resolvable ancestry from `agent` upward. */
|
|
188
|
+
private liveLineage;
|
|
189
|
+
/** Return the teardown that closed continuable admission for this agent's lineage. */
|
|
190
|
+
private closingTeardownFor;
|
|
191
|
+
/** Resolve a root's pool once; descendants inherit their resident parent's pool directly. */
|
|
192
|
+
private rootPool;
|
|
193
|
+
/** Perform one tracked materialization through publication or rollback. */
|
|
194
|
+
private materializeTracked;
|
|
195
|
+
/**
|
|
196
|
+
* Begin settlement observation after initial acceptance is recorded.
|
|
197
|
+
* @param activation - accepted activation to observe.
|
|
198
|
+
*/
|
|
199
|
+
private announce;
|
|
200
|
+
/** Release an Activation whose start edge was not published. */
|
|
201
|
+
private rollbackUnpublished;
|
|
202
|
+
/** Register the child in a continuation-managed parent's owned set. */
|
|
203
|
+
private acquireOwnership;
|
|
204
|
+
/** Remove one child from its live owner's set and let that owner re-check settlement. */
|
|
205
|
+
private releaseOwnership;
|
|
206
|
+
/** Let a settlement watcher re-check residency after relevant state changes. */
|
|
207
|
+
private wake;
|
|
208
|
+
/** Follow one Activation to natural settlement. */
|
|
209
|
+
private watchLocalSettlement;
|
|
210
|
+
/** Report disposal failure once after the natural settlement observer finishes. */
|
|
211
|
+
private reportTeardownFailure;
|
|
212
|
+
/** Check pending input and owned children before closing admission. */
|
|
213
|
+
private settlementState;
|
|
214
|
+
/** Propagate stop synchronously and await descendant startup rollback before release. */
|
|
215
|
+
private finishDisposal;
|
|
216
|
+
/** Deliver the captured execution result to the durable direct parent after cleanup. */
|
|
217
|
+
private notifySettlement;
|
|
218
|
+
/** Request a best-effort final session flush before closing natural-settlement admission. */
|
|
219
|
+
private flushFinalState;
|
|
220
|
+
/** Return capabilities bound to an exact activation instead of a future same-id instance. */
|
|
221
|
+
private receipt;
|
|
222
|
+
/** Route one parent-originated delivery through residency and cold resume. */
|
|
223
|
+
private deliverToChild;
|
|
224
|
+
/** The delivery loop behind {@link deliverToChild}, run under the parent hold. */
|
|
225
|
+
private deliverFollowup;
|
|
226
|
+
/** Deliver one resident continuable child's message to its live direct parent. */
|
|
227
|
+
private sendToParent;
|
|
228
|
+
/** Send one Agent message while translating only the target's own rejection. */
|
|
229
|
+
private sendAgentMessage;
|
|
230
|
+
/**
|
|
231
|
+
* Cold-resume a persisted child and submit the waiting turn. The descriptor
|
|
232
|
+
* supplies every reconstruction input; no subagent provider is dispatched.
|
|
233
|
+
*/
|
|
234
|
+
private coldResume;
|
|
235
|
+
/** Admit a materialized child, commit its creation fact, and release it on failure. */
|
|
236
|
+
private submitMaterialized;
|
|
237
|
+
/** Build and submit one message across the final synchronous admission cutoff. */
|
|
238
|
+
private submitAdmitted;
|
|
239
|
+
/** Refuse image content for a child whose fixed model accepts text only. */
|
|
240
|
+
private assertImageCapable;
|
|
241
|
+
/** Resolve the persistence service continuable children require, or fail loud. */
|
|
242
|
+
private requirePersistence;
|
|
243
|
+
/** Resolve the Session query service used for cold child observations. */
|
|
244
|
+
private requireSessionQuery;
|
|
245
|
+
}
|
|
246
|
+
export default SubagentManager;
|
|
247
|
+
//# sourceMappingURL=manager.d.ts.map
|