@xneog/dsh-subagent 0.1.0 → 0.1.3-alpha.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.
Files changed (41) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +108 -76
  3. package/README.zh.md +112 -80
  4. package/lib/index.js +1258 -718
  5. package/lib/typert.host.d.ts +3 -0
  6. package/lib/typert.host.js +923 -0
  7. package/lib/typert.remote-client.d.ts +27 -0
  8. package/lib/typert.remote-client.js +159 -0
  9. package/lib/types/assistant-output.d.ts +3 -3
  10. package/lib/types/assistant-output.js +8 -4
  11. package/lib/types/child-agent.d.ts +16 -5
  12. package/lib/types/child-agent.js +51 -13
  13. package/lib/types/client.d.ts +2 -1
  14. package/lib/types/client.js +1 -1
  15. package/lib/types/continuation.d.ts +100 -72
  16. package/lib/types/continuation.js +439 -169
  17. package/lib/types/control-types.d.ts +144 -0
  18. package/lib/types/control-types.js +9 -0
  19. package/lib/types/control.d.ts +67 -0
  20. package/lib/types/control.js +115 -0
  21. package/lib/types/descriptor-seed.d.ts +1 -1
  22. package/lib/types/descriptor-seed.js +1 -1
  23. package/lib/types/descriptor.d.ts +6 -1
  24. package/lib/types/descriptor.js +6 -2
  25. package/lib/types/index.d.ts +103 -69
  26. package/lib/types/index.js +436 -287
  27. package/lib/types/internal.d.ts +59 -0
  28. package/lib/types/internal.js +58 -0
  29. package/lib/types/lifecycle.js +4 -3
  30. package/lib/types/list-children.d.ts +12 -59
  31. package/lib/types/list-children.js +166 -101
  32. package/lib/types/out-of-process.d.ts +5 -2
  33. package/lib/types/out-of-process.js +42 -4
  34. package/lib/types/projection-types.d.ts +4 -3
  35. package/lib/types/projection.d.ts +55 -8
  36. package/lib/types/projection.js +33 -17
  37. package/lib/types/run-settlement.js +17 -6
  38. package/lib/types/types.d.ts +25 -0
  39. package/package.json +67 -37
  40. package/lib/types/activation-setup-registry.d.ts +0 -57
  41. package/lib/types/activation-setup-registry.js +0 -148
@@ -4,10 +4,8 @@
4
4
  * child before returning its run, so fulfillment is the single publication and
5
5
  * ownership-transfer boundary.
6
6
  *
7
- * Unlike the bash seam (one executor per context, second load throws), MULTIPLE
8
- * providers coexist here: each registers under a unique name and a caller picks
9
- * one by name. The shape mirrors the LLM adapter registry
10
- * (`LlmRuntime.registerAdapter`), not the single-service bash executor.
7
+ * Multiple providers coexist: each registers under a unique name and callers
8
+ * select one by name.
11
9
  *
12
10
  * This package owns the Service Definition role of the capability seam. Service Providers
13
11
  * (`@xneog/dsh-subagent-spawn-in-process`, `-fork`, `-acp`) and the model-facing
@@ -15,8 +13,8 @@
15
13
  *
16
14
  * Public operations express caller intent: `start` returns one published owned
17
15
  * one-shot run, `startContinuable` establishes a durable continuable child, and
18
- * `followup` delivers later content without exposing whether the child is
19
- * resident. Continuable children never become a {@link SubagentRun}: the
16
+ * `sendMessage` steers between adjacent Agents without exposing whether a child
17
+ * is resident. Continuable children never become a {@link SubagentRun}: the
20
18
  * continuation manager holds their `AgentHandle` directly and orders every turn
21
19
  * through the child's own inbox, so providers contribute only the detached
22
20
  * creation spec and see no handle, turn, or teardown. Child and descendant
@@ -30,30 +28,31 @@
30
28
  *
31
29
  * @module @xneog/dsh-subagent
32
30
  */
33
- import { Context, Service } from '@xneog/cordis';
31
+ import { Context } from '@xneog/cordis';
34
32
  import type { Scoped } from '@xneog/dsh-scope';
35
33
  import type { ContentBlock, MessageId } from '@xneog/dsh-llm';
36
34
  import type { Agent } from '@xneog/dsh-agent';
37
35
  import type { SessionId } from '@xneog/dsh-session';
36
+ import { TypertRemoteService } from '@xneog/dsh-typert-protocol';
37
+ import type { SubagentCatalog, SubagentInterruptReceipt, SubagentPromptReceipt, SubagentPromptRequest } from './control-types.ts';
38
38
  import type { SubagentProvider, SubagentRun, SubagentRunEndInfo, SubagentRunInfo, SubagentStartRequest } from './types.ts';
39
- import type { ContinuableStart, ContinuableStartSpec, SubagentFollowupOptions, SubagentInterruptAuthority, SubagentReportOptions } from './continuation.ts';
40
- import type { ContinuableSetupContribution } from './activation-setup-registry.ts';
39
+ import type { ContinuableStart, ContinuableStartSpec, SubagentInterruptAuthority, SubagentSendMessageOptions } from './continuation.ts';
41
40
  import type { SubagentDescendantListEntry, SubagentListEntry } from './list-children.ts';
41
+ import { deliverSubagentPrompt } from './internal.ts';
42
42
  export * from './out-of-process.ts';
43
43
  export { AssistantOutputFold, finalAssistantOutput } from './assistant-output.ts';
44
44
  export { SubagentRunId } from './types.ts';
45
45
  export type { ContinuableCreateRequest, ContinuableCreateSpec, ResolvedSubagentStartRequest, SubagentCapabilities, SubagentProvider, SubagentResult, SubagentRun, SubagentStartRequest, SubagentStopReason, SubagentStopReasonMap, } from './types.ts';
46
46
  export { foldSubagentDescriptor, snapshotSubagentDescriptor, SUBAGENT_DESCRIPTOR_VERSION, } from './descriptor.ts';
47
47
  export type { ContinuableSubagentDescriptorData, ContinuableSubagentDescriptorInput, OneShotSubagentDescriptorData, OneShotSubagentDescriptorInput, SubagentDescriptorData, SubagentDescriptorInput, } from './descriptor.ts';
48
- export { seedDescriptorTurn } from './descriptor-seed.ts';
49
48
  export { SubagentError } from './error.ts';
50
49
  export { settleRun } from './run-settlement.ts';
51
50
  export { assertSubagentMaxDepth, delegationDepthOf } from './depth.ts';
52
- export { appendDelegatedPolicyOverrides, applyChildComposition, captureDelegatedPolicyOverrides, childSessionMeta, resolveChildAgentOptions, resolveChildDepth, SubagentDepthError, } from './child-agent.ts';
51
+ export { appendDelegatedPolicyOverrides, applyChildComposition, captureDelegatedPolicyOverrides, childSessionMeta, parentAgentOptionsForDelegation, resolveChildAgentOptions, resolveChildDepth, SubagentDepthError, } from './child-agent.ts';
53
52
  export type { ChildComposition, DelegatedPolicyOverrides } from './child-agent.ts';
54
- export type { ContinuableStart, ContinuableStartSpec, CoordinatorMessageSource, SubagentFollowupOptions, SubagentInterruptAuthority, SubagentReportDelivery, SubagentReportMessageSource, SubagentReportOptions, SubagentSettledMessageSource, } from './continuation.ts';
55
- export type { ContinuableSetupContribution } from './activation-setup-registry.ts';
56
- export type { SubagentDescendantListEntry, SubagentListEntry } from './list-children.ts';
53
+ export type { AgentMessageSource, ContinuableStart, ContinuableStartSpec, SubagentInterruptAuthority, SubagentSendMessageOptions, SubagentSettledMessageSource, } from './continuation.ts';
54
+ export type * from './control-types.ts';
55
+ export type { SubagentDescendantListEntry } from './list-children.ts';
57
56
  export type { SubagentRunEndInfo, SubagentRunInfo } from './types.ts';
58
57
  export type { SubagentIdentityProjection, SubagentTimingProjection } from './projection-types.ts';
59
58
  declare module '@xneog/cordis' {
@@ -96,11 +95,9 @@ declare module '@xneog/cordis' {
96
95
  }
97
96
  }
98
97
  /** Named provider registry with one-shot runs, durable discovery, and continuable-child operations. */
99
- export declare class SubagentRuntime extends Service {
98
+ export declare class SubagentRuntime extends TypertRemoteService {
100
99
  private providers;
101
100
  private continuations;
102
- /** Deployment contributions composed into unpublished continuable children. */
103
- private readonly setupRegistry;
104
101
  /**
105
102
  * The contained lifecycle-edge publisher. Built here because scoped dispatch
106
103
  * keys its carrier by this exact service instance, whose own context filter
@@ -119,21 +116,33 @@ export declare class SubagentRuntime extends Service {
119
116
  */
120
117
  startContinuable(spec: ContinuableStartSpec): Promise<ContinuableStart>;
121
118
  /**
122
- * Deliver one later message to a continuable child as its next FIFO turn. A
123
- * resident child's Agent inbox accepts it directly (waking a `waiting`
124
- * Activation), while an absent one is cold-resumed from its persisted
125
- * Session. The Agent inbox is the only queue, so every accepted message has
126
- * one observable order.
127
- * @param parent - the exact live direct parent authorizing this delivery.
128
- * @param childId - durable child session id.
129
- * @param content - user-role content to deliver.
130
- * @param options - the message source fields and caller cancellation, which stops the
131
- * operation only before inbox acceptance.
119
+ * Steer one model-authored message to the sender's direct parent or direct
120
+ * continuable child. A running target admits it at the nearest step boundary;
121
+ * an idle target starts a turn, and an absent direct child cold-resumes from
122
+ * persistence. The service derives durable sender attribution from the exact
123
+ * live sender. Caller cancellation stops only pre-acceptance work.
124
+ * @param sender - exact live Agent authorizing and originating the message.
125
+ * @param targetId - durable direct-parent or direct-child session id.
126
+ * @param content - model-authored content to deliver.
127
+ * @param options - caller cancellation before inbox acceptance.
132
128
  * @returns the accepted message's inbox id.
133
- * @throws when continuation services are unavailable, parent authority is
134
- * rejected, or the message was not admitted.
129
+ * @throws when continuation services are unavailable, adjacency is rejected,
130
+ * or the message was not admitted.
135
131
  */
136
- followup(parent: Agent, childId: SessionId, content: ContentBlock[], options: SubagentFollowupOptions): Promise<MessageId>;
132
+ sendMessage(sender: Agent, targetId: SessionId, content: ContentBlock[], options: SubagentSendMessageOptions): Promise<MessageId>;
133
+ /**
134
+ * Deliver one host-protocol message to a direct continuable child.
135
+ * Symbol-keyed so host adapters can preserve their own provenance without
136
+ * widening the public Service Definition or impersonating an Agent sender.
137
+ * @param parent - exact live direct parent authorizing delivery.
138
+ * @param childId - durable direct-child session id.
139
+ * @param content - host-authored content to deliver.
140
+ * @param source - durable host-protocol provenance.
141
+ * @param signal - caller cancellation before inbox acceptance.
142
+ * @param delivery - Queue as a distinct turn or Steer at the nearest step.
143
+ * @returns the accepted message's inbox id.
144
+ */
145
+ private [deliverSubagentPrompt];
137
146
  /**
138
147
  * Interrupt one live continuable child's current turn under a human parent
139
148
  * address or an exact live ancestor Agent. Fire-and-return: the cancel
@@ -150,27 +159,6 @@ export declare class SubagentRuntime extends Service {
150
159
  * live target.
151
160
  */
152
161
  interrupt(targetSessionId: SessionId, authority: SubagentInterruptAuthority): void;
153
- /**
154
- * Deliver selected content from one live continuable child to its durable
155
- * direct parent. The child is the authority credential; callers cannot name a
156
- * recipient. Reporting does not conclude the child's turn or Activation.
157
- * @param child - exact live reporting child.
158
- * @param content - selected model-facing content.
159
- * @param options - parent scheduling and pre-acceptance cancellation.
160
- * @returns the stable identity of the parent-accepted message.
161
- * @throws when continuation services are unavailable, sender authorization
162
- * fails, or the direct parent is not live.
163
- */
164
- reportFrom(child: Agent, content: ContentBlock[], options: SubagentReportOptions): Promise<MessageId>;
165
- /**
166
- * Compose one deployment capability into every continuable child's
167
- * unpublished creation context on fresh creation and cold resume. Grants wait
168
- * for the next Activation; removing the contribution revokes every resident
169
- * installation immediately.
170
- * @param contribution - synchronous child-scope installer.
171
- * @returns the exact Cordis effect disposer.
172
- */
173
- registerContinuableSetup(contribution: ContinuableSetupContribution): () => void;
174
162
  /**
175
163
  * Close continuable admission below exact live parent Agents, stop only their
176
164
  * visible descendant Activations synchronously, then await admitted scoped
@@ -182,29 +170,29 @@ export declare class SubagentRuntime extends Service {
182
170
  * @throws an aggregate error after all branches settle when any failed.
183
171
  */
184
172
  drainContinuableDescendants(parents: readonly Agent[]): Promise<void>;
173
+ /**
174
+ * Release selected resident continuable direct children of one exact live
175
+ * parent. Other children of the same parent remain admitted and resident.
176
+ * Absent targets and a manager-less composition are accepted no-ops.
177
+ * @param parent - exact live direct parent authorizing the selected release.
178
+ * @param childIds - durable direct-child ids to release when resident.
179
+ * @returns once every selected Activation released its `AgentHandle`.
180
+ * @throws {SubagentError} `UNAUTHORIZED` when a resident target belongs to a
181
+ * different parent or the supplied parent identity is stale.
182
+ */
183
+ drainContinuableChildren(parent: Agent, childIds: readonly SessionId[]): Promise<void>;
185
184
  /**
186
185
  * Enumerate the parent's direct session-backed subagents without loading or
187
- * resuming an Agent and without any query service: the listing merges the live
188
- * session store with optional session persistence (live-preferred) and
189
- * serves each child's durable mode/label from the registered `subagent`
190
- * projection unit down a three-rung ladder — the registry's watermark
191
- * snapshot for a live child; for a cold one, a durable projection-cache
192
- * row when the optional cache serves an own-suffix identity (its `seq`
193
- * gate proves the value postdates the fork seed, where a child's own
194
- * descriptor is immutable once appended), else one persistence inspection
195
- * folded through the registry. The
196
- * projection fold is the single classification authority; per-child
197
- * diagnostics relay a fold that served no identity or a failed inspection,
198
- * never a list-time descriptor parse. Absent persistence, enumeration is
199
- * live-only (a cold child cannot be resumed then either, so its absence is
200
- * capability absence, not an error). This service consults no Agent
201
- * registrations, Activations, or providers.
186
+ * resuming an Agent. The Session query service supplies one live-preferred
187
+ * corpus and shared point observations; the projection cache supplies
188
+ * immutable descriptor hits without opening cold logs. The registered
189
+ * `subagent` projection remains the sole mode/label classifier.
202
190
  *
203
- * Every persistence read receives `signal`, and the listing rechecks
204
- * cancellation around each of those awaits. Read rejections that settle
191
+ * Every query receives `signal`, and the listing rechecks cancellation
192
+ * around each await. Read rejections that settle
205
193
  * after an abort become a stable `SubagentError` with code `CANCELLED`.
206
194
  * @param parentSessionId - parent session whose direct children are listed.
207
- * @param signal - caller-owned cancellation forwarded to persistence reads
195
+ * @param signal - caller-owned cancellation forwarded to Session queries
208
196
  * and observed around every read await.
209
197
  * @returns children and per-child diagnostics ordered by `createdAt`, then id.
210
198
  * @throws {@link SubagentError} when the projection registry or the session
@@ -227,6 +215,52 @@ export declare class SubagentRuntime extends Service {
227
215
  * @throws {@link SubagentError} under the same conditions as {@link listChildren}.
228
216
  */
229
217
  listDescendants(rootSessionId: SessionId, signal?: AbortSignal): Promise<SubagentDescendantListEntry[]>;
218
+ /**
219
+ * Remote face of {@link listChildren} for one browser: the durable listing
220
+ * plus live Agent activity and the delivery-time parent availability hint.
221
+ * Parent availability is a hint; {@link prompt} performs the authoritative
222
+ * check. Named apart from the provider-name {@link list}, which owns the
223
+ * member.
224
+ * @param parentSessionId - parent session whose direct children are listed.
225
+ * @param signal - carrier cancellation forwarded to Session queries.
226
+ * @returns the catalog view for that parent.
227
+ * @throws {RemoteError} `gateway/bad-request` for an empty parent id,
228
+ * `gateway/cancelled` for an aborted read, `subagent/projections-unavailable` when
229
+ * the deployment has no projection registry, otherwise `gateway/internal`.
230
+ */
231
+ remoteExportList(parentSessionId: SessionId, signal: AbortSignal): Promise<SubagentCatalog>;
232
+ /**
233
+ * Deliver one browser-authored message to a continuable child through the
234
+ * exact live direct parent, retaining the caller-minted request identity and
235
+ * validated browser zone on the accepted message. Success identifies the
236
+ * message the child's FIFO inbox accepted; later execution is independent of
237
+ * this call.
238
+ * Image parts are admitted and persisted through the attachment store
239
+ * before delivery, and the child's model must accept image input.
240
+ * @param request - durable address, minted identity, content, and optional browser zone.
241
+ * @param signal - carrier cancellation, owning the call until inbox acceptance.
242
+ * @returns the accepted message's inbox identity.
243
+ * @throws {RemoteError} `gateway/bad-request`, `subagent/attachment-invalid`,
244
+ * `subagent/invalid-time-zone`, `subagent/parent-unavailable`,
245
+ * `subagent/not-resumable`, `subagent/unauthorized`,
246
+ * `subagent/delivery-unavailable`, `gateway/cancelled`, or `gateway/internal`.
247
+ */
248
+ prompt(request: SubagentPromptRequest, signal: AbortSignal): Promise<SubagentPromptReceipt>;
249
+ /**
250
+ * Remote face of {@link interrupt} under one durable parent address. No
251
+ * catalog, history, persistence, or parent Agent lookup runs: the core
252
+ * primitive alone authorizes the address against the live Activation, which
253
+ * is what keeps a live child interruptible while its parent Agent is offline.
254
+ * Absent, idle, and already-completed targets are accepted no-ops there.
255
+ * @param childSessionId - durable child session id to interrupt.
256
+ * @param parentSessionId - durable direct parent whose authority is claimed.
257
+ * @param mode - required continuable-address discriminator.
258
+ * @returns acknowledgement that the cancel signal was admitted, not that the target is quiescent.
259
+ * @throws {RemoteError} `gateway/bad-request` for an empty id,
260
+ * `subagent/unauthorized` when the address does not own the live target,
261
+ * otherwise `gateway/internal`.
262
+ */
263
+ interruptByParent(childSessionId: SessionId, parentSessionId: SessionId, mode: 'continuable'): SubagentInterruptReceipt;
230
264
  /**
231
265
  * Register a provider under its name. Registration is effect-scoped and HMR
232
266
  * safe; removing a provider blocks new starts but does not revoke runs that