@qlzt/dsh-subagent 0.0.0-stage → 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/LICENSE +21 -0
- package/README.i18n.yaml +94 -0
- package/README.md +215 -2
- package/README.zh.md +216 -0
- package/lib/index.js +3333 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +991 -0
- package/lib/typert.remote-client.d.ts +25 -0
- package/lib/typert.remote-client.js +114 -0
- package/lib/types/activation.d.ts +114 -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 +92 -0
- package/lib/types/catalog.js +113 -0
- package/lib/types/child-agent.d.ts +154 -0
- package/lib/types/child-agent.js +211 -0
- package/lib/types/client.d.ts +8 -0
- package/lib/types/client.js +7 -0
- package/lib/types/continuation-messages.d.ts +63 -0
- package/lib/types/continuation-messages.js +114 -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 +319 -0
- package/lib/types/index.js +455 -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 +247 -0
- package/lib/types/manager.js +1294 -0
- package/lib/types/out-of-process.d.ts +92 -0
- package/lib/types/out-of-process.js +178 -0
- package/lib/types/projection-types.d.ts +85 -0
- package/lib/types/projection-types.js +7 -0
- package/lib/types/projection.d.ts +100 -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 +353 -0
- package/lib/types/types.js +19 -0
- package/package.json +136 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle-edge publication for managed subagent activations.
|
|
3
|
+
*
|
|
4
|
+
* Public event payloads live in `./types.ts`; the package-private observer
|
|
5
|
+
* retains only the identity shared by each start/end pair.
|
|
6
|
+
*
|
|
7
|
+
* @module @qlzt/dsh-subagent/lifecycle
|
|
8
|
+
*/
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { foldConsumedWork } from '@qlzt/dsh-agent';
|
|
11
|
+
import { SubagentRunId } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Build the contained lifecycle emitter this seam publishes every edge through.
|
|
14
|
+
* Every listener is independently contained: a synchronous throw or a rejected
|
|
15
|
+
* returned promise is logged without starving peer listeners, changing the run,
|
|
16
|
+
* or — for provider removal, which fires from a disposer — breaking teardown.
|
|
17
|
+
* @param ctx - the service's own context, owning dispatch and the logger.
|
|
18
|
+
* @param carrier - resolve the scoped dispatch carrier for one delegating parent.
|
|
19
|
+
* @returns the emitter both observers and the provider registry publish through.
|
|
20
|
+
*/
|
|
21
|
+
export function createLifecycleEmitter(ctx, carrier) {
|
|
22
|
+
return (name, info, parent) => {
|
|
23
|
+
const dispatchArgs = parent === undefined
|
|
24
|
+
? [name, info]
|
|
25
|
+
: [carrier(parent), name, info];
|
|
26
|
+
for (const callback of ctx.events.dispatch('emit', dispatchArgs)) {
|
|
27
|
+
try {
|
|
28
|
+
const returned = callback(info);
|
|
29
|
+
void Promise.resolve(returned).catch((error) => {
|
|
30
|
+
ctx.logger.warn(`subagent: ${name} listener rejected: ${renderThrown(error)}`);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
ctx.logger.warn(`subagent: ${name} listener threw: ${renderThrown(error)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build the observer for one local or external activation's residency epoch. Creation failure before residency emits no lifecycle edge.
|
|
41
|
+
* @param emit - the contained lifecycle emitter.
|
|
42
|
+
* @param provider - the provider name recorded in the durable descriptor.
|
|
43
|
+
* @param childId - the durable child session id.
|
|
44
|
+
* @param parent - the exact live direct parent keying scoped dispatch.
|
|
45
|
+
* @returns the observer whose edges this epoch publishes.
|
|
46
|
+
*/
|
|
47
|
+
export function createActivationObserver(emit, provider, childId, parent) {
|
|
48
|
+
const identity = { runId: SubagentRunId(randomUUID()), provider, id: childId, local: false };
|
|
49
|
+
return {
|
|
50
|
+
start: (child) => {
|
|
51
|
+
identity.local = child !== undefined;
|
|
52
|
+
emit('subagent/start', identity, parent);
|
|
53
|
+
},
|
|
54
|
+
settle: ({ stopReason, output }) => {
|
|
55
|
+
emit('subagent/end', {
|
|
56
|
+
...identity,
|
|
57
|
+
stopReason,
|
|
58
|
+
...output.length === 0 ? {} : { lastAssistantMessage: output },
|
|
59
|
+
}, parent);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Why this child's epoch ended, for the terminal lifecycle edge and the
|
|
65
|
+
* manager's own parent delivery. The child's own log is authoritative:
|
|
66
|
+
* teardown succeeding says nothing about whether the model errored, hit its
|
|
67
|
+
* token ceiling, or was cancelled, so deriving the reason from disposal would
|
|
68
|
+
* report failed work as completed.
|
|
69
|
+
*
|
|
70
|
+
* {@link foldConsumedWork} supplies both halves the raw turn sequence cannot:
|
|
71
|
+
* which turn accounts for the work this epoch consumed, and whether accepted
|
|
72
|
+
* work was cancelled after it without any turn opening over it. A recorded
|
|
73
|
+
* failure still wins over a cancellation — stopping a child that had already
|
|
74
|
+
* failed does not turn its failure into a cancellation.
|
|
75
|
+
* @param events - this epoch's own event suffix.
|
|
76
|
+
* @returns its terminal stop reason; `completed` only for an epoch that both
|
|
77
|
+
* closed cleanly and had nothing left to run.
|
|
78
|
+
*/
|
|
79
|
+
export function epochStopReason(events) {
|
|
80
|
+
const { end, droppedUnrun } = foldConsumedWork(events);
|
|
81
|
+
switch (end?.data.reason.kind) {
|
|
82
|
+
case 'max-tokens':
|
|
83
|
+
return 'max-tokens';
|
|
84
|
+
case 'aborted':
|
|
85
|
+
case 'interrupted':
|
|
86
|
+
return 'aborted';
|
|
87
|
+
case 'error':
|
|
88
|
+
return 'error';
|
|
89
|
+
// A pre-step rejection — a hook deny, a policy plugin — discarded input
|
|
90
|
+
// this epoch had claimed: the work was declined, not done.
|
|
91
|
+
case 'blocked':
|
|
92
|
+
return 'refusal';
|
|
93
|
+
// A clean ending and no accounting turn at all share one rule: the epoch
|
|
94
|
+
// finished what it was given unless a cancelled queue says otherwise.
|
|
95
|
+
case undefined:
|
|
96
|
+
case 'completed':
|
|
97
|
+
return droppedUnrun ? 'aborted' : 'completed';
|
|
98
|
+
/* v8 ignore next 4 -- `forked` appears only in constructor seed history, while
|
|
99
|
+
* this function reads an epoch-owned suffix. `TurnEndReason` is merge-extensible,
|
|
100
|
+
* so a backend-added variant cannot be listed; treating an unnameable reason as
|
|
101
|
+
* success would report failed work as completed. */
|
|
102
|
+
default:
|
|
103
|
+
return 'error';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Render any listener-thrown value without letting coercion escape containment. */
|
|
107
|
+
function renderThrown(value) {
|
|
108
|
+
try {
|
|
109
|
+
return value instanceof Error ? `${value.name}: ${value.message}` : String(value);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return '<unrenderable thrown value>';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct-child and recursive descendant discovery from parent-owned catalogs.
|
|
3
|
+
* Each catalog read releases its Session observation before the next branch.
|
|
4
|
+
* @module @qlzt/dsh-subagent
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import type { SessionId } from '@qlzt/dsh-session';
|
|
8
|
+
import type { SubagentListEntry } from './control-types.ts';
|
|
9
|
+
import type { SubagentCatalogEntry } from './projection-types.ts';
|
|
10
|
+
export type { SubagentListEntry } from './control-types.ts';
|
|
11
|
+
/** One catalog descendant with its direct parent and edge distance from the requested root. */
|
|
12
|
+
export type SubagentDescendantListEntry = SubagentListEntry & {
|
|
13
|
+
/** Parent whose catalog contains this child. */
|
|
14
|
+
readonly parentId: SessionId;
|
|
15
|
+
/** Edge distance from the requested root; direct children are `1`. */
|
|
16
|
+
readonly depth: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Read one parent's durable catalog through a live-preferred Session observation.
|
|
20
|
+
* @param ctx - context carrying the Session query service.
|
|
21
|
+
* @param parentSessionId - parent whose direct children are requested.
|
|
22
|
+
* @param signal - cancellation forwarded to the Session observation.
|
|
23
|
+
* @returns direct-child rows in parent catalog event order.
|
|
24
|
+
* @throws {@link SubagentError} when query or catalog projection is unavailable.
|
|
25
|
+
*/
|
|
26
|
+
export declare function listChildren(ctx: Context, parentSessionId: SessionId, signal?: AbortSignal): Promise<SubagentCatalogEntry[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Walk reachable parent catalogs in stable pre-order without loading Agents.
|
|
29
|
+
* @see SubagentRuntime.listDescendants for failure and cancellation semantics.
|
|
30
|
+
* @param ctx - context carrying the Session store and query service.
|
|
31
|
+
* @param rootSessionId - parent whose catalog starts the traversal.
|
|
32
|
+
* @param signal - cancellation checked around each catalog read.
|
|
33
|
+
* @returns children and branch diagnostics with catalog parent and depth.
|
|
34
|
+
*/
|
|
35
|
+
export declare function listDescendants(ctx: Context, rootSessionId: SessionId, signal?: AbortSignal): Promise<SubagentDescendantListEntry[]>;
|
|
36
|
+
//# sourceMappingURL=list-children.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct-child and recursive descendant discovery from parent-owned catalogs.
|
|
3
|
+
* Each catalog read releases its Session observation before the next branch.
|
|
4
|
+
* @module @qlzt/dsh-subagent
|
|
5
|
+
*/
|
|
6
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
7
|
+
if (value !== null && value !== void 0) {
|
|
8
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
9
|
+
var dispose, inner;
|
|
10
|
+
if (async) {
|
|
11
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.asyncDispose];
|
|
13
|
+
}
|
|
14
|
+
if (dispose === void 0) {
|
|
15
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
16
|
+
dispose = value[Symbol.dispose];
|
|
17
|
+
if (async) inner = dispose;
|
|
18
|
+
}
|
|
19
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
20
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
21
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
22
|
+
}
|
|
23
|
+
else if (async) {
|
|
24
|
+
env.stack.push({ async: true });
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
29
|
+
return function (env) {
|
|
30
|
+
function fail(e) {
|
|
31
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
32
|
+
env.hasError = true;
|
|
33
|
+
}
|
|
34
|
+
var r, s = 0;
|
|
35
|
+
function next() {
|
|
36
|
+
while (r = env.stack.pop()) {
|
|
37
|
+
try {
|
|
38
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
39
|
+
if (r.dispose) {
|
|
40
|
+
var result = r.dispose.call(r.value);
|
|
41
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
42
|
+
}
|
|
43
|
+
else s |= 1;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
fail(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
50
|
+
if (env.hasError) throw env.error;
|
|
51
|
+
}
|
|
52
|
+
return next();
|
|
53
|
+
};
|
|
54
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
55
|
+
var e = new Error(message);
|
|
56
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
|
+
});
|
|
58
|
+
import { SubagentError } from "./error.js";
|
|
59
|
+
/**
|
|
60
|
+
* Read one parent's durable catalog through a live-preferred Session observation.
|
|
61
|
+
* @param ctx - context carrying the Session query service.
|
|
62
|
+
* @param parentSessionId - parent whose direct children are requested.
|
|
63
|
+
* @param signal - cancellation forwarded to the Session observation.
|
|
64
|
+
* @returns direct-child rows in parent catalog event order.
|
|
65
|
+
* @throws {@link SubagentError} when query or catalog projection is unavailable.
|
|
66
|
+
*/
|
|
67
|
+
export async function listChildren(ctx, parentSessionId, signal) {
|
|
68
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
69
|
+
try {
|
|
70
|
+
const query = ctx.get('sessionQuery');
|
|
71
|
+
if (query === undefined) {
|
|
72
|
+
throw new SubagentError('listing subagents requires the sessionQuery service (load @qlzt/dsh-session-query)', 'SUBAGENT_CONTROL_QUERY_UNAVAILABLE');
|
|
73
|
+
}
|
|
74
|
+
const parent = __addDisposableResource(env_1, await query.observeSession(parentSessionId, {
|
|
75
|
+
...signal === undefined ? {} : { signal },
|
|
76
|
+
}), false);
|
|
77
|
+
const entries = parent.projections?.values.subagentCatalog;
|
|
78
|
+
if (entries === undefined) {
|
|
79
|
+
throw new SubagentError('listing subagents requires the registered subagentCatalog projection', 'SUBAGENT_CONTROL_PROJECTIONS_UNAVAILABLE');
|
|
80
|
+
}
|
|
81
|
+
return entries;
|
|
82
|
+
}
|
|
83
|
+
catch (e_1) {
|
|
84
|
+
env_1.error = e_1;
|
|
85
|
+
env_1.hasError = true;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
__disposeResources(env_1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Walk reachable parent catalogs in stable pre-order without loading Agents.
|
|
93
|
+
* @see SubagentRuntime.listDescendants for failure and cancellation semantics.
|
|
94
|
+
* @param ctx - context carrying the Session store and query service.
|
|
95
|
+
* @param rootSessionId - parent whose catalog starts the traversal.
|
|
96
|
+
* @param signal - cancellation checked around each catalog read.
|
|
97
|
+
* @returns children and branch diagnostics with catalog parent and depth.
|
|
98
|
+
*/
|
|
99
|
+
export async function listDescendants(ctx, rootSessionId, signal) {
|
|
100
|
+
const sessions = ctx.get('sessions');
|
|
101
|
+
if (sessions === undefined) {
|
|
102
|
+
throw new SubagentError('listing subagents requires the session store (load @qlzt/dsh-session)', 'SUBAGENT_CONTROL_SESSION_STORE_UNAVAILABLE');
|
|
103
|
+
}
|
|
104
|
+
const readChildren = async (id) => {
|
|
105
|
+
assertListingNotCancelled(signal);
|
|
106
|
+
let children;
|
|
107
|
+
try {
|
|
108
|
+
children = await listChildren(ctx, id, signal);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
assertListingNotCancelled(signal);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
assertListingNotCancelled(signal);
|
|
115
|
+
return children;
|
|
116
|
+
};
|
|
117
|
+
const stack = (await readChildren(rootSessionId))
|
|
118
|
+
.map(entry => ({ entry, parentId: rootSessionId, depth: 1 }))
|
|
119
|
+
.reverse();
|
|
120
|
+
const visited = new Set([rootSessionId]);
|
|
121
|
+
const result = [];
|
|
122
|
+
for (let position = stack.pop(); position !== undefined; position = stack.pop()) {
|
|
123
|
+
const { entry, parentId, depth } = position;
|
|
124
|
+
if (visited.has(entry.id))
|
|
125
|
+
continue;
|
|
126
|
+
visited.add(entry.id);
|
|
127
|
+
let children;
|
|
128
|
+
try {
|
|
129
|
+
children = entry.mode === 'external' ? [] : await readChildren(entry.id);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (error instanceof SubagentError)
|
|
133
|
+
throw error;
|
|
134
|
+
const code = error instanceof Error && 'code' in error ? error.code : undefined;
|
|
135
|
+
result.push({
|
|
136
|
+
kind: 'diagnostic', id: entry.id, parentId, depth,
|
|
137
|
+
reason: code === 'SESSION_QUERY_CORRUPT_SESSION' || code === 'SESSION_QUERY_SOURCE_CONFLICT'
|
|
138
|
+
? 'corrupt' : 'unavailable',
|
|
139
|
+
});
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (entry.mode === 'unknown') {
|
|
143
|
+
result.push({ kind: 'diagnostic', id: entry.id, parentId, depth, reason: 'unsupported' });
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const { createdAt: _createdAt, ...identity } = entry;
|
|
147
|
+
result.push({
|
|
148
|
+
...identity, kind: 'child', parentId, depth,
|
|
149
|
+
activity: sessions.get(entry.id) === undefined ? 'inactive' : 'running',
|
|
150
|
+
hasChildren: children.length > 0,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Catalog event order defines siblings; the stack visits the first one next.
|
|
154
|
+
for (const child of [...children].reverse()) {
|
|
155
|
+
stack.push({ entry: child, parentId: entry.id, depth: depth + 1 });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
/** Stop the complete traversal when its caller cancels. */
|
|
161
|
+
function assertListingNotCancelled(signal) {
|
|
162
|
+
if (signal?.aborted) {
|
|
163
|
+
throw new SubagentError('subagent listing was cancelled', 'CANCELLED');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=list-children.js.map
|
|
@@ -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 @qlzt/dsh-subagent/manager
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { Agent } from '@qlzt/dsh-agent';
|
|
10
|
+
import type { ContentBlock, MessageId, MessageSource } from '@qlzt/dsh-llm';
|
|
11
|
+
import type { SessionId } from '@qlzt/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
|