@deepseek-ai/dsh-subagent 0.1.2-alpha.5 → 0.1.3-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 +2 -2
- package/README.md +11 -7
- package/README.zh.md +11 -7
- package/lib/index.js +958 -914
- package/lib/typert.host.js +44 -11
- package/lib/typert.remote-client.js +3 -2
- package/lib/types/assistant-output.d.ts +3 -3
- package/lib/types/assistant-output.js +5 -4
- package/lib/types/child-agent.js +2 -2
- package/lib/types/continuation-activation.d.ts +251 -0
- package/lib/types/continuation-activation.js +663 -0
- package/lib/types/continuation-messages.d.ts +62 -0
- package/lib/types/continuation-messages.js +102 -0
- package/lib/types/continuation.d.ts +44 -358
- package/lib/types/continuation.js +135 -987
- package/lib/types/control-types.d.ts +2 -0
- package/lib/types/control.d.ts +4 -0
- package/lib/types/control.js +1 -0
- package/lib/types/inbox.d.ts +43 -0
- package/lib/types/inbox.js +61 -0
- package/lib/types/index.d.ts +11 -11
- package/lib/types/index.js +14 -12
- package/lib/types/internal.d.ts +17 -5
- package/lib/types/internal.js +16 -3
- package/lib/types/out-of-process.d.ts +1 -1
- package/lib/types/out-of-process.js +1 -1
- package/lib/types/types.d.ts +46 -2
- package/package.json +44 -44
- package/lib/types/descriptor-seed.d.ts +0 -21
- package/lib/types/descriptor-seed.js +0 -24
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-visible messages owned by continuable-subagent orchestration.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-subagent/continuation-messages
|
|
5
|
+
*/
|
|
6
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
7
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
9
|
+
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
10
|
+
import type { ActivationTerminal } from './lifecycle.ts';
|
|
11
|
+
/** Durable attribution for one model-authored message between adjacent Agents. */
|
|
12
|
+
export interface AgentMessageSource {
|
|
13
|
+
readonly kind: 'agent-message';
|
|
14
|
+
/** A message another agent addressed to this one (`relay` context form). */
|
|
15
|
+
readonly form: 'relay';
|
|
16
|
+
/** Session id of the Agent whose tool call produced the message. */
|
|
17
|
+
readonly senderSessionId: SessionId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Durable attribution for the runtime's own account of a continuable child
|
|
21
|
+
* settling. Deliberately a different kind from
|
|
22
|
+
* {@link AgentMessageSource}: an Agent message is content the sender chose,
|
|
23
|
+
* while this message is the manager stating what became of the child, and a
|
|
24
|
+
* transcript that merged them would credit the child with words it never wrote.
|
|
25
|
+
*/
|
|
26
|
+
export interface SubagentSettledMessageSource {
|
|
27
|
+
readonly kind: 'subagent-settled';
|
|
28
|
+
/** A runtime account shown without expanding the row (`notice` context form). */
|
|
29
|
+
readonly form: 'notice';
|
|
30
|
+
/** One-line account of how the child ended. */
|
|
31
|
+
readonly summary: string;
|
|
32
|
+
/** Session id of the child that settled. */
|
|
33
|
+
readonly senderSessionId: SessionId;
|
|
34
|
+
}
|
|
35
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
36
|
+
interface MessageSourceMap {
|
|
37
|
+
'agent-message': AgentMessageSource;
|
|
38
|
+
'subagent-settled': SubagentSettledMessageSource;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the model-visible and durable representation of one adjacent-Agent message.
|
|
43
|
+
* @param sender - exact live Agent that authored the message.
|
|
44
|
+
* @param content - model-visible message blocks supplied by the sender.
|
|
45
|
+
* @returns the durable user-message representation delivered to the recipient.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createAgentMessage(sender: Agent, content: ContentBlock[]): ReturnType<typeof createUserMessage>;
|
|
48
|
+
/**
|
|
49
|
+
* Append adjacent-Agent return guidance to a continuable child's initial task.
|
|
50
|
+
* @param parentId - durable parent session id named in the guidance.
|
|
51
|
+
* @param prompt - initial model-visible task blocks.
|
|
52
|
+
* @returns task blocks followed by the continuable return guidance.
|
|
53
|
+
*/
|
|
54
|
+
export declare function withContinuableReturnGuidance(parentId: SessionId, prompt: ContentBlock[]): ContentBlock[];
|
|
55
|
+
/**
|
|
56
|
+
* Build the runtime-owned settlement notice delivered to a child's parent.
|
|
57
|
+
* @param childId - durable child session id named in the notice.
|
|
58
|
+
* @param terminal - recorded terminal state for the settled Activation.
|
|
59
|
+
* @returns the durable user-message representation delivered to the parent.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createSettlementMessage(childId: SessionId, terminal: ActivationTerminal): ReturnType<typeof createUserMessage>;
|
|
62
|
+
//# sourceMappingURL=continuation-messages.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-visible messages owned by continuable-subagent orchestration.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-subagent/continuation-messages
|
|
5
|
+
*/
|
|
6
|
+
import { boundContextSummary, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
/** Build durable attribution for one adjacent-Agent message. */
|
|
8
|
+
function agentMessageSource(sender) {
|
|
9
|
+
return {
|
|
10
|
+
kind: 'agent-message',
|
|
11
|
+
form: 'relay',
|
|
12
|
+
senderSessionId: sender.id,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build the model-visible and durable representation of one adjacent-Agent message.
|
|
17
|
+
* @param sender - exact live Agent that authored the message.
|
|
18
|
+
* @param content - model-visible message blocks supplied by the sender.
|
|
19
|
+
* @returns the durable user-message representation delivered to the recipient.
|
|
20
|
+
*/
|
|
21
|
+
export function createAgentMessage(sender, content) {
|
|
22
|
+
return createUserMessage({
|
|
23
|
+
content: [
|
|
24
|
+
{ type: 'text', text: `Agent ${sender.id} sent a message: ` },
|
|
25
|
+
...content,
|
|
26
|
+
],
|
|
27
|
+
source: agentMessageSource(sender),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Append adjacent-Agent return guidance to a continuable child's initial task.
|
|
32
|
+
* @param parentId - durable parent session id named in the guidance.
|
|
33
|
+
* @param prompt - initial model-visible task blocks.
|
|
34
|
+
* @returns task blocks followed by the continuable return guidance.
|
|
35
|
+
*/
|
|
36
|
+
export function withContinuableReturnGuidance(parentId, prompt) {
|
|
37
|
+
const encodedParentId = JSON.stringify(parentId);
|
|
38
|
+
return [
|
|
39
|
+
...prompt,
|
|
40
|
+
{
|
|
41
|
+
type: 'text',
|
|
42
|
+
text: `Your parent agent id is ${encodedParentId}. Before you finish, send your result to that agent with `
|
|
43
|
+
+ `send_message({ agent_id: ${encodedParentId}, message: "<self-contained result>" }). The parent shares `
|
|
44
|
+
+ 'your workspace but does not automatically receive your transcript, tool output, or reasoning. Send '
|
|
45
|
+
+ 'earlier messages as well when a finding changes what the parent should do next; sending a message '
|
|
46
|
+
+ 'does not end your turn.',
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* One line telling a parent that a background child is finished and why, in
|
|
52
|
+
* the parent's own task vocabulary.
|
|
53
|
+
* @param childId - the durable child the parent knows by id.
|
|
54
|
+
* @param stopReason - how the child's last ordinary turn ended.
|
|
55
|
+
* @returns the model-facing opening line of the settlement notice.
|
|
56
|
+
*/
|
|
57
|
+
function settlementSummary(childId, stopReason) {
|
|
58
|
+
const subject = `Background subagent ${childId}`;
|
|
59
|
+
switch (stopReason) {
|
|
60
|
+
case 'completed':
|
|
61
|
+
return `${subject} finished and will do no further work unless you send it more.`;
|
|
62
|
+
case 'aborted':
|
|
63
|
+
return `${subject} was stopped before it finished.`;
|
|
64
|
+
case 'max-tokens':
|
|
65
|
+
return `${subject} ran out of room before it finished.`;
|
|
66
|
+
// A pre-step rejection — a hook deny, a policy plugin — discarded input
|
|
67
|
+
// the child had claimed, so the parent must not treat the task as done.
|
|
68
|
+
case 'refusal':
|
|
69
|
+
return `${subject} declined the task.`;
|
|
70
|
+
case 'error':
|
|
71
|
+
return `${subject} failed before it finished.`;
|
|
72
|
+
/* v8 ignore next 4 -- `SubagentResult['stopReason']` is merge-extensible, so this arm
|
|
73
|
+
* needs a backend that adds a variant; an unnameable ending is reported as unfinished
|
|
74
|
+
* rather than silently as success. */
|
|
75
|
+
default:
|
|
76
|
+
return `${subject} ended abnormally (${String(stopReason)}) before it finished.`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build the runtime-owned settlement notice delivered to a child's parent.
|
|
81
|
+
* @param childId - durable child session id named in the notice.
|
|
82
|
+
* @param terminal - recorded terminal state for the settled Activation.
|
|
83
|
+
* @returns the durable user-message representation delivered to the parent.
|
|
84
|
+
*/
|
|
85
|
+
export function createSettlementMessage(childId, terminal) {
|
|
86
|
+
const summary = settlementSummary(childId, terminal.stopReason);
|
|
87
|
+
return createUserMessage({
|
|
88
|
+
content: [
|
|
89
|
+
{ type: 'text', text: summary },
|
|
90
|
+
...terminal.output === undefined
|
|
91
|
+
? [{ type: 'text', text: 'It left no closing message.' }]
|
|
92
|
+
: [{ type: 'text', text: 'Its closing message:' }, ...terminal.output],
|
|
93
|
+
],
|
|
94
|
+
source: {
|
|
95
|
+
kind: 'subagent-settled',
|
|
96
|
+
form: 'notice',
|
|
97
|
+
summary: boundContextSummary(summary),
|
|
98
|
+
senderSessionId: childId,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=continuation-messages.js.map
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* persistence,
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Continuable-subagent orchestration behind `ctx.subagents`: stable child ids,
|
|
3
|
+
* descriptor persistence, provider preparation, cold resume, authorization,
|
|
4
|
+
* and message routing. {@link ContinuableActivationRegistry} owns the mutable
|
|
5
|
+
* process-local Activation graph and its settlement and disposal lifecycle.
|
|
6
6
|
*
|
|
7
7
|
* A continuable child has one durable Session and at most one process-local
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* residency while the Agent loop owns all turn ordering and execution. No
|
|
13
|
-
* continuable path creates a Task or an intermediate result-bearing wrapper.
|
|
14
|
-
*
|
|
15
|
-
* Because residency is this manager's alone to end, telling the parent that a
|
|
16
|
-
* child settled is its job too. An external `subagent/end` listener cannot do
|
|
17
|
-
* it correctly: that payload names no parent, the child handle is already
|
|
18
|
-
* disposed by then, and the release that wakes the parent's own settlement
|
|
19
|
-
* watcher has already run. See {@link SubagentContinuationManager.notifySettlement}.
|
|
8
|
+
* Activation. The Agent inbox is the only turn queue, so this manager owns
|
|
9
|
+
* durable orchestration while the Agent loop owns all turn ordering and
|
|
10
|
+
* execution. No continuable path creates a Task or an intermediate
|
|
11
|
+
* result-bearing wrapper.
|
|
20
12
|
*
|
|
21
13
|
* @module @deepseek-ai/dsh-subagent
|
|
22
14
|
*/
|
|
@@ -24,105 +16,13 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
24
16
|
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
25
17
|
import type { ContentBlock, MessageId, MessageSource } from '@deepseek-ai/dsh-llm';
|
|
26
18
|
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
27
|
-
import type { SubagentDescriptorData } from './descriptor.ts';
|
|
28
|
-
import type { ContinuableCreateRequest, ContinuableCreateSpec, SubagentStartRequest } from './types.ts';
|
|
29
19
|
import type { ActivationObserver } from './lifecycle.ts';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readonly kind: 'agent-message';
|
|
33
|
-
/** A message another agent addressed to this one (`relay` context form). */
|
|
34
|
-
readonly form: 'relay';
|
|
35
|
-
/** Session id of the Agent whose tool call produced the message. */
|
|
36
|
-
readonly senderSessionId: SessionId;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Durable attribution for the runtime's own account of a continuable child
|
|
40
|
-
* settling. Deliberately a different kind from
|
|
41
|
-
* {@link AgentMessageSource}: an Agent message is content the sender chose,
|
|
42
|
-
* while this message is the manager stating what became of the child, and a
|
|
43
|
-
* transcript that merged them would credit the child with words it never wrote.
|
|
44
|
-
*/
|
|
45
|
-
export interface SubagentSettledMessageSource {
|
|
46
|
-
readonly kind: 'subagent-settled';
|
|
47
|
-
/** A runtime account shown without expanding the row (`notice` context form). */
|
|
48
|
-
readonly form: 'notice';
|
|
49
|
-
/** One-line account of how the child ended. */
|
|
50
|
-
readonly summary: string;
|
|
51
|
-
/** Session id of the child that settled. */
|
|
52
|
-
readonly senderSessionId: SessionId;
|
|
53
|
-
}
|
|
54
|
-
declare module '@deepseek-ai/dsh-llm' {
|
|
55
|
-
interface MessageSourceMap {
|
|
56
|
-
'agent-message': AgentMessageSource;
|
|
57
|
-
'subagent-settled': SubagentSettledMessageSource;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/** What a caller asks for when starting a continuable background child. */
|
|
61
|
-
export interface ContinuableStartSpec {
|
|
62
|
-
/** The `ctx.subagents` provider whose continuable-creation capability establishes the child. */
|
|
63
|
-
readonly provider: string;
|
|
64
|
-
/** The initial delegation's short `description`, persisted as the child's creation label. */
|
|
65
|
-
readonly label: string;
|
|
66
|
-
/**
|
|
67
|
-
* Optional caller-reserved child identity. Omission preserves the manager's
|
|
68
|
-
* UUID allocation; supplying one lets a durable parent record provisioning
|
|
69
|
-
* before child materialization without a second identity handshake.
|
|
70
|
-
*/
|
|
71
|
-
readonly childId?: SessionId;
|
|
72
|
-
/**
|
|
73
|
-
* The delegation request. The manager reserves the stable child id, resolves
|
|
74
|
-
* the durable descriptor, and composes the child itself.
|
|
75
|
-
*/
|
|
76
|
-
readonly request: Omit<SubagentStartRequest, 'label' | 'signal' | 'outputSchema'>;
|
|
77
|
-
/** Caller cancellation, owning the operation only until inbox acceptance. */
|
|
78
|
-
readonly signal: AbortSignal;
|
|
79
|
-
}
|
|
80
|
-
/** Identities returned once a continuable child accepted its initial prompt. */
|
|
81
|
-
export interface ContinuableStart {
|
|
82
|
-
/** The durable child session id, stable across activations. */
|
|
83
|
-
readonly childId: SessionId;
|
|
84
|
-
/** The accepted initial prompt's inbox message id. */
|
|
85
|
-
readonly messageId: MessageId;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Authority under which one interrupt request is admitted. `user` carries the
|
|
89
|
-
* durable direct-parent address a human client presented; `ancestor` carries
|
|
90
|
-
* the exact live Agent object whose recorded lineage must contain the caller.
|
|
91
|
-
*/
|
|
92
|
-
export type SubagentInterruptAuthority = {
|
|
93
|
-
readonly kind: 'user';
|
|
94
|
-
readonly parentSessionId: SessionId;
|
|
95
|
-
} | {
|
|
96
|
-
readonly kind: 'ancestor';
|
|
97
|
-
readonly agent: Agent;
|
|
98
|
-
};
|
|
99
|
-
/** Options for one model-authored message between adjacent Agents. */
|
|
100
|
-
export interface SubagentSendMessageOptions {
|
|
101
|
-
/** Caller cancellation, owning the operation only until inbox acceptance. */
|
|
102
|
-
readonly signal: AbortSignal;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Hooks the manager needs from the owning service. Declared here, by the
|
|
106
|
-
* dependent, so the manager states exactly what it requires instead of
|
|
107
|
-
* depending back on the whole {@link SubagentRuntime}. Package-private: no
|
|
108
|
-
* consumer outside this package supplies a host.
|
|
109
|
-
*/
|
|
20
|
+
import type { ContinuableCreateRequest, ContinuableCreateSpec, ContinuableStart, ContinuableStartSpec, SubagentInterruptAuthority, SubagentSendMessageOptions } from './types.ts';
|
|
21
|
+
/** Package-private hooks supplied by the owning service. */
|
|
110
22
|
interface ContinuationHost {
|
|
111
|
-
/**
|
|
112
|
-
* Resolve one provider's continuable-creation contribution, or reject when
|
|
113
|
-
* the provider is unknown or lacks the capability.
|
|
114
|
-
* @param name - the configured provider name.
|
|
115
|
-
* @param request - the reserved identity, delegating parent, and cancellation.
|
|
116
|
-
* @returns the provider's detached creation spec.
|
|
117
|
-
*/
|
|
23
|
+
/** Resolve one provider's detached continuable-creation contribution. */
|
|
118
24
|
prepareContinuable(name: string, request: ContinuableCreateRequest): Promise<ContinuableCreateSpec>;
|
|
119
|
-
/**
|
|
120
|
-
* Build the lifecycle observer for one Activation's residency epoch.
|
|
121
|
-
* @param provider - the provider name recorded in the durable descriptor.
|
|
122
|
-
* @param childId - the durable child session id.
|
|
123
|
-
* @param parent - the exact live direct parent for scoped dispatch.
|
|
124
|
-
* @returns the observer whose edges this epoch publishes.
|
|
125
|
-
*/
|
|
25
|
+
/** Build the lifecycle observer for one Activation residency epoch. */
|
|
126
26
|
observeActivation(provider: string, childId: SessionId, parent: Agent): ActivationObserver;
|
|
127
27
|
}
|
|
128
28
|
/**
|
|
@@ -134,305 +34,91 @@ interface ContinuationHost {
|
|
|
134
34
|
export declare class SubagentContinuationManager {
|
|
135
35
|
private readonly ctx;
|
|
136
36
|
private readonly host;
|
|
137
|
-
|
|
138
|
-
private activations;
|
|
139
|
-
/** Materializations admitted before drain, tracked through publication or rollback. */
|
|
140
|
-
private readonly materializations;
|
|
141
|
-
private readonly locks;
|
|
142
|
-
/** Structural Cordis owner of every Activation handle. */
|
|
143
|
-
private readonly ownerCtx;
|
|
144
|
-
/**
|
|
145
|
-
* Exact roots whose host teardown has begun, with the live lineage members
|
|
146
|
-
* observed under each root. Entries remain until that exact root leaves the
|
|
147
|
-
* Agent registry, closing admission throughout its host's teardown without
|
|
148
|
-
* poisoning a later same-id replacement.
|
|
149
|
-
*/
|
|
150
|
-
private readonly closingScopes;
|
|
151
|
-
private draining;
|
|
37
|
+
private readonly activations;
|
|
152
38
|
constructor(ctx: Context, host: ContinuationHost);
|
|
153
39
|
/**
|
|
154
|
-
* Start one continuable background child
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* ownership, and submit the initial prompt. Resolves when inbox acceptance
|
|
158
|
-
* yields the message id — without waiting for the turn to start or for the
|
|
159
|
-
* message to reach the Session log.
|
|
160
|
-
*
|
|
161
|
-
* Every failure before that acceptance rejects without either id, disposing
|
|
162
|
-
* any created handle and rolling back the Activation and parent ownership.
|
|
163
|
-
* The caller signal owns lookup, materialization, and admission only until
|
|
164
|
-
* acceptance; afterwards the manager owns the Activation independently.
|
|
40
|
+
* Start one continuable background child and resolve at initial inbox acceptance.
|
|
41
|
+
* Every earlier failure disposes any created handle and rolls back Activation
|
|
42
|
+
* and parent ownership without returning either id.
|
|
165
43
|
* @param spec - provider, delegation request, and caller cancellation.
|
|
166
|
-
* @returns the durable child id and
|
|
44
|
+
* @returns the durable child id and accepted initial prompt message id.
|
|
167
45
|
*/
|
|
168
46
|
startContinuable(spec: ContinuableStartSpec): Promise<ContinuableStart>;
|
|
169
|
-
/** Reject one child identity already owned by a live Agent or Session. */
|
|
170
|
-
private assertChildIdAvailable;
|
|
171
47
|
/**
|
|
172
48
|
* Deliver one model-authored message to a direct continuable child or to the
|
|
173
|
-
* sender's direct parent.
|
|
174
|
-
*
|
|
175
|
-
* turn. A missing direct child cold-resumes through the ordinary continuation
|
|
176
|
-
* lifecycle. The caller signal owns the operation only until inbox acceptance.
|
|
49
|
+
* sender's direct parent. A missing direct child cold-resumes through the
|
|
50
|
+
* ordinary continuation lifecycle.
|
|
177
51
|
* @param sender - exact live Agent authorizing and originating the message.
|
|
178
52
|
* @param targetId - durable direct-parent or direct-child session id.
|
|
179
53
|
* @param content - model-authored content to deliver.
|
|
180
54
|
* @param options - caller cancellation before acceptance.
|
|
181
55
|
* @returns the accepted message's inbox id.
|
|
182
|
-
* @throws when adjacency, availability, or admission rejects delivery.
|
|
183
56
|
*/
|
|
184
57
|
sendMessage(sender: Agent, targetId: SessionId, content: ContentBlock[], options: SubagentSendMessageOptions): Promise<MessageId>;
|
|
185
58
|
/**
|
|
186
59
|
* Queue one human-authored prompt as a distinct direct-child turn.
|
|
187
60
|
* @param parent - exact live direct parent authorizing delivery.
|
|
188
61
|
* @param childId - durable direct-child session id.
|
|
189
|
-
* @param content -
|
|
190
|
-
* @param source - durable
|
|
62
|
+
* @param content - model-visible prompt blocks.
|
|
63
|
+
* @param source - durable attribution for the human prompt.
|
|
191
64
|
* @param signal - caller cancellation before inbox acceptance.
|
|
192
|
-
* @returns the accepted message
|
|
65
|
+
* @returns the accepted durable message id.
|
|
193
66
|
*/
|
|
194
67
|
queuePrompt(parent: Agent, childId: SessionId, content: ContentBlock[], source: MessageSource, signal: AbortSignal): Promise<MessageId>;
|
|
68
|
+
/**
|
|
69
|
+
* Steer one host-authored prompt to a direct continuable child.
|
|
70
|
+
* @param parent - exact live direct parent authorizing delivery.
|
|
71
|
+
* @param childId - durable direct-child session id.
|
|
72
|
+
* @param content - model-visible prompt blocks.
|
|
73
|
+
* @param source - durable attribution for the host prompt.
|
|
74
|
+
* @param signal - caller cancellation before inbox acceptance.
|
|
75
|
+
* @returns the accepted durable message id.
|
|
76
|
+
*/
|
|
77
|
+
steerPrompt(parent: Agent, childId: SessionId, content: ContentBlock[], source: MessageSource, signal: AbortSignal): Promise<MessageId>;
|
|
195
78
|
/** Route one parent-originated delivery through residency and cold resume. */
|
|
196
79
|
private deliverToChild;
|
|
80
|
+
/** The delivery loop behind {@link deliverToChild}, run under the parent hold. */
|
|
81
|
+
private deliverFollowup;
|
|
197
82
|
/**
|
|
198
83
|
* Interrupt one live continuable child's current turn. Admission is
|
|
199
|
-
* synchronous and the effect is asynchronous
|
|
200
|
-
*
|
|
201
|
-
* returns without waiting for the target to observe the signal or reach
|
|
202
|
-
* quiescence. The Activation, its handle, accepted unclaimed inbox work, and
|
|
203
|
-
* already-published descendants are untouched; work already claimed into the
|
|
204
|
-
* interrupted turn is not requeued. Once the interrupted driver is idle, a
|
|
205
|
-
* waking send resumes the parked queue.
|
|
206
|
-
*
|
|
207
|
-
* An absent target is an accepted no-op, which uniformly covers natural
|
|
208
|
-
* completion races, repeated requests, one-shot ids, and unknown ids without
|
|
209
|
-
* consulting the durable catalog. A target whose disposal transaction is
|
|
210
|
-
* already open is likewise an accepted no-op after authorization.
|
|
84
|
+
* synchronous and the cancellation effect is asynchronous. An absent or
|
|
85
|
+
* already-closing target is an accepted no-op after authority checks.
|
|
211
86
|
* @param targetSessionId - the durable child session id to interrupt.
|
|
212
87
|
* @param authority - the human parent address or exact live ancestor Agent.
|
|
213
|
-
* @throws {SubagentError} `UNAUTHORIZED` when the presented authority does
|
|
214
|
-
* not own the live target: a stale or self-targeting ancestor caller, a
|
|
215
|
-
* parent address that is not the live target's durable direct parent, or
|
|
216
|
-
* an ancestor outside the target's recorded live lineage.
|
|
217
88
|
*/
|
|
218
89
|
interrupt(targetSessionId: SessionId, authority: SubagentInterruptAuthority): void;
|
|
219
90
|
/** Deliver one resident continuable child's message to its live direct parent. */
|
|
220
91
|
private sendToParent;
|
|
221
|
-
/**
|
|
222
|
-
* Perform one waking send to a parent, accounted against that parent's own
|
|
223
|
-
* Activation when it has one. Registering the id before the send is what
|
|
224
|
-
* keeps a continuation-managed parent from being judged quiescent in the
|
|
225
|
-
* window between a waking send and the microtask that admits it.
|
|
226
|
-
* @param parent - the exact live parent receiving the waking message.
|
|
227
|
-
* @param message - the message whose id is accounted.
|
|
228
|
-
* @param send - the synchronous waking send to perform.
|
|
229
|
-
*/
|
|
230
|
-
private sendWaking;
|
|
231
92
|
/** Send one Agent message while translating only the target's own rejection. */
|
|
232
93
|
private sendAgentMessage;
|
|
233
|
-
/**
|
|
234
|
-
* Close admission, await every already-admitted materialization through
|
|
235
|
-
* publication or rollback, then dispose the stable live Activation forest
|
|
236
|
-
* child-first. Sibling branches drain independently: one failure is recorded
|
|
237
|
-
* but never prevents the remaining handles from being attempted, and the
|
|
238
|
-
* aggregate rejects only after every branch settles.
|
|
239
|
-
* @returns once materialization is quiescent and every live Activation released its handle.
|
|
240
|
-
* @throws an aggregate error when any branch failed to release.
|
|
241
|
-
*/
|
|
94
|
+
/** Close manager-wide admission and release every live Activation. */
|
|
242
95
|
drain(): Promise<void>;
|
|
243
96
|
/**
|
|
244
97
|
* Stop only the continuable descendants of exact live host-owned parents.
|
|
245
|
-
* Admission stays closed for those parent trees until each exact parent
|
|
246
|
-
* leaves the Agent registry; unrelated trees and manager-wide admission stay
|
|
247
|
-
* live.
|
|
248
98
|
* @param parents - exact live roots whose continuable descendants must stop.
|
|
249
|
-
* @returns once every retained descendant Activation released its handle.
|
|
250
|
-
* @throws an aggregate error after all scoped branches settle when any failed.
|
|
251
99
|
*/
|
|
252
100
|
drainDescendants(parents: readonly Agent[]): Promise<void>;
|
|
253
101
|
/**
|
|
254
|
-
* Release selected resident direct children of one exact live parent
|
|
255
|
-
* closing admission for the parent's other continuable children. Owned
|
|
256
|
-
* descendants are released recursively through the same lifecycle.
|
|
102
|
+
* Release selected resident direct children of one exact live parent.
|
|
257
103
|
* @param parent - exact live direct parent authorizing the selected release.
|
|
258
104
|
* @param childIds - durable direct-child ids to release when resident.
|
|
259
|
-
* @returns once every selected Activation released its handle.
|
|
260
|
-
* @throws {SubagentError} `UNAUTHORIZED` when a resident target is not the
|
|
261
|
-
* parent's direct continuable child or the parent identity is stale.
|
|
262
105
|
*/
|
|
263
106
|
drainChildren(parent: Agent, childIds: readonly SessionId[]): Promise<void>;
|
|
264
|
-
/** Dispose independent roots and report every branch failure after all settle. */
|
|
265
|
-
private disposeRoots;
|
|
266
|
-
/** Return the retained member set for one exact scoped-teardown root. */
|
|
267
|
-
private closingMembers;
|
|
268
|
-
/**
|
|
269
|
-
* Return the exact currently resolvable ancestry from `agent` upward. The
|
|
270
|
-
* first element is always the supplied identity, even when it is already
|
|
271
|
-
* stale; each ancestor after it must be the registry's current exact entry.
|
|
272
|
-
*/
|
|
273
|
-
private liveLineage;
|
|
274
107
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* whose forest is closing.
|
|
278
|
-
* @param agent - the agent whose lineage is tested.
|
|
279
|
-
* @returns the closing teardown, or `undefined` while admission is open.
|
|
280
|
-
*/
|
|
281
|
-
private closingTeardownFor;
|
|
282
|
-
/** Reject new admission once the manager or this exact parent tree began draining. */
|
|
283
|
-
private assertAdmitting;
|
|
284
|
-
/**
|
|
285
|
-
* Derive residency from Agent quiescence and the owned-child set. `running`
|
|
286
|
-
* covers an active admission, an open turn, or accepted waking inbox work.
|
|
287
|
-
*
|
|
288
|
-
* `Agent.status` alone is insufficient: it stays `idle` between an accepted
|
|
289
|
-
* waking send and the microtask that admits it, so a synchronous inbox
|
|
290
|
-
* observer would see `settled` while a turn is already queued. `accepted`
|
|
291
|
-
* holds the ids this manager admitted but has not yet seen drained.
|
|
292
|
-
*/
|
|
293
|
-
private stateOf;
|
|
294
|
-
/**
|
|
295
|
-
* Cold-resume a persisted child: retain and authorize its prepared Session, fold the
|
|
296
|
-
* generic descriptor, create the Activation through `ctx.agents.resume()`,
|
|
297
|
-
* and submit the waiting turn. This never dispatches through a subagent
|
|
298
|
-
* provider — the persisted Session already holds the initial prefix and the
|
|
299
|
-
* descriptor is the whole reconstruction input.
|
|
108
|
+
* Cold-resume a persisted child and submit the waiting turn. The descriptor
|
|
109
|
+
* supplies every reconstruction input; no subagent provider is dispatched.
|
|
300
110
|
*/
|
|
301
111
|
private coldResume;
|
|
302
|
-
/**
|
|
303
|
-
* Submit to a freshly materialized Activation or roll it back completely.
|
|
304
|
-
* @param activation - the just-published Activation to admit or release.
|
|
305
|
-
* @param content - the initial or resumed message content.
|
|
306
|
-
* @param options - durable source, scheduling, and pre-acceptance cancellation.
|
|
307
|
-
* @param parent - the live direct parent authorizing admission.
|
|
308
|
-
* @returns the accepted inbox message id.
|
|
309
|
-
*/
|
|
112
|
+
/** Submit to a freshly materialized Activation or roll it back completely. */
|
|
310
113
|
private submitMaterialized;
|
|
311
|
-
/**
|
|
312
|
-
* Refuse image content addressed to a child whose model accepts text only.
|
|
313
|
-
* Callers guard with `contentHasImage`, so text-only delivery never awaits.
|
|
314
|
-
* The check runs inside the per-child delivery lock, before the message
|
|
315
|
-
* exists, so a rejection leaves no partial user message. When the child's
|
|
316
|
-
* route is not fixed by its options (a request-waterfall listener owns it)
|
|
317
|
-
* or no LLM registry is composed, delivery proceeds and the LLM layer's
|
|
318
|
-
* text-only projection replaces each image with its stable placeholder.
|
|
319
|
-
* @param agent - the live or freshly materialized child agent.
|
|
320
|
-
* @param signal - caller cancellation bounding the model-info read.
|
|
321
|
-
* @throws {SubagentError} `MODEL_DOES_NOT_SUPPORT_IMAGES` when the child's resolved model declines image input.
|
|
322
|
-
*/
|
|
323
|
-
private assertImageCapable;
|
|
324
|
-
/**
|
|
325
|
-
* Create or resume the child Agent through the private activation-owner
|
|
326
|
-
* scope, install the handle in a fresh Activation, and register ownership on
|
|
327
|
-
* a continuation-managed parent. Rejection leaves no Activation, no handle,
|
|
328
|
-
* and no ownership membership.
|
|
329
|
-
*/
|
|
330
|
-
private materialize;
|
|
331
|
-
/**
|
|
332
|
-
* Perform one tracked materialization. The caller keeps the drain barrier
|
|
333
|
-
* registered until this either returns a resident Activation or finishes
|
|
334
|
-
* rollback.
|
|
335
|
-
*/
|
|
336
|
-
private materializeTracked;
|
|
337
|
-
/**
|
|
338
|
-
* Release an Activation whose start edge was not published. The memoized
|
|
339
|
-
* transaction remains in the live map until handle disposal settles, so a
|
|
340
|
-
* concurrent drain or delivery observes the same closing boundary.
|
|
341
|
-
*/
|
|
342
|
-
private rollbackUnpublished;
|
|
343
|
-
/**
|
|
344
|
-
* Register the child in a continuation-managed parent's owned set before the
|
|
345
|
-
* child can run, so that parent cannot settle while the child is live. A
|
|
346
|
-
* top-level or other non-continuation Agent has no Activation and stays
|
|
347
|
-
* outside the waiting graph.
|
|
348
|
-
*/
|
|
349
|
-
private acquireOwnership;
|
|
350
|
-
/** Remove one child from its live owner's set and let that owner re-check settlement. */
|
|
351
|
-
private releaseOwnership;
|
|
352
|
-
/** Let a settlement watcher re-observe quiescence after ownership or inbox changes. */
|
|
353
|
-
private wake;
|
|
354
|
-
/**
|
|
355
|
-
* Submit one message as the child's next FIFO turn and return its accepted
|
|
356
|
-
* inbox id. Acceptance is the operation's success boundary; the manager owns
|
|
357
|
-
* the Activation independently afterwards.
|
|
358
|
-
*/
|
|
359
|
-
private submit;
|
|
360
|
-
/**
|
|
361
|
-
* Account one waking send across a resident Activation's settlement window.
|
|
362
|
-
* @param activation - Activation receiving waking inbox work.
|
|
363
|
-
* @param messageId - stable identity of the message about to be sent.
|
|
364
|
-
* @param send - synchronous send that publishes one enqueue occurrence.
|
|
365
|
-
* @returns the accepted message id.
|
|
366
|
-
*/
|
|
367
|
-
private admitWaking;
|
|
368
|
-
/**
|
|
369
|
-
* Cross the final admission cutoff and submit without yielding. Signal abort,
|
|
370
|
-
* manager drain, or Activation disposal that wins before this synchronous
|
|
371
|
-
* span rejects without inbox acceptance.
|
|
372
|
-
*/
|
|
114
|
+
/** Build and submit one message across the final synchronous admission cutoff. */
|
|
373
115
|
private submitAdmitted;
|
|
374
|
-
/**
|
|
375
|
-
|
|
376
|
-
* agents, ancestors, teams, workflows, and hosts remain rejected until an
|
|
377
|
-
* explicit authority protocol has a production consumer.
|
|
378
|
-
*/
|
|
379
|
-
private authorizeLineage;
|
|
380
|
-
/**
|
|
381
|
-
* Follow one Activation to settlement: wait for Agent quiescence, then for
|
|
382
|
-
* every owned child to complete disposal, and dispose the handle once both
|
|
383
|
-
* hold. A `next-turn` delivered while `waiting` wakes the same Agent and
|
|
384
|
-
* returns it to `running`, so this re-observes rather than settling early.
|
|
385
|
-
*/
|
|
386
|
-
private watchSettlement;
|
|
387
|
-
/**
|
|
388
|
-
* Stop one Activation immediately, then release it child-first. The memoized
|
|
389
|
-
* transaction is installed before cancellation or recursive callbacks, so
|
|
390
|
-
* admission and reentrant teardown converge on the same owner.
|
|
391
|
-
*
|
|
392
|
-
* The final session flush is best effort and never prevents handle disposal
|
|
393
|
-
* or ownership release, because retaining a child would permanently pin its
|
|
394
|
-
* ancestors in `waiting`.
|
|
395
|
-
* @param activation - the residency epoch to stop and release.
|
|
396
|
-
* @returns the one disposal transaction owned by this Activation.
|
|
397
|
-
*/
|
|
398
|
-
private dispose;
|
|
399
|
-
/**
|
|
400
|
-
* Propagate stop synchronously, then finish the child-first release.
|
|
401
|
-
* @param activation - the Activation whose disposal transaction is installed.
|
|
402
|
-
* @returns once the handle and ownership edge are released.
|
|
403
|
-
*/
|
|
404
|
-
private finishDisposal;
|
|
405
|
-
/**
|
|
406
|
-
* Tell the durable direct parent that this child produced everything it is
|
|
407
|
-
* going to. Unconditional for every child the caller received an id for: it
|
|
408
|
-
* does not consider whether the child reported, because the cases that most
|
|
409
|
-
* need it — a token ceiling, a model failure, cancellation, teardown — are
|
|
410
|
-
* exactly the ones where the child never got to choose. A materialization
|
|
411
|
-
* rolled back before its first acceptance stays silent, since the caller was
|
|
412
|
-
* told that child was not established. A parent that is no longer live is not
|
|
413
|
-
* an error; the child's own Session remains the durable record either way.
|
|
414
|
-
* A parent whose own lineage is already closing receives the notice without a
|
|
415
|
-
* wake, because teardown is not a reason to start a turn.
|
|
416
|
-
*
|
|
417
|
-
* Never blocks disposal. A delivery failure is logged and dropped, because
|
|
418
|
-
* retaining a child to retry a notice would pin its whole ancestry in
|
|
419
|
-
* `waiting` forever.
|
|
420
|
-
* @param activation - the settling Activation, still owned by its parent.
|
|
421
|
-
* @param terminal - how this epoch ended, as the terminal edge will report it.
|
|
422
|
-
*/
|
|
423
|
-
private notifySettlement;
|
|
424
|
-
/**
|
|
425
|
-
* Request a best-effort final session flush after the child is quiescent.
|
|
426
|
-
* Listener failure is logged because flush participation cannot identify a
|
|
427
|
-
* particular persistence backend, and teardown must still release ownership.
|
|
428
|
-
* @param activation - the Activation whose final events should be flushed.
|
|
429
|
-
*/
|
|
430
|
-
private flushFinalState;
|
|
116
|
+
/** Refuse image content for a child whose fixed model accepts text only. */
|
|
117
|
+
private assertImageCapable;
|
|
431
118
|
/** Resolve the persistence service continuable children require, or fail loud. */
|
|
432
119
|
private requirePersistence;
|
|
433
120
|
/** Resolve the Session query service used for cold child observations. */
|
|
434
121
|
private requireSessionQuery;
|
|
435
122
|
}
|
|
436
|
-
export type { SubagentDescriptorData };
|
|
437
123
|
export default SubagentContinuationManager;
|
|
438
124
|
//# sourceMappingURL=continuation.d.ts.map
|