@sorbetai/durable 0.0.0-stage → 0.1.0-alpha.17

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.
@@ -0,0 +1,847 @@
1
+ import { _ as WaitTargetSource } from "./contracts-ui4Wvp-X.js";
2
+ import * as s from "@earendil-works/pi-schema";
3
+ import * as _sorbetai_runtime18 from "@sorbetai/runtime";
4
+ import { ContextualTool, JournalCursor, JournalSubscription, JsonValue, RunCancellationReceipt, RunInspection, RunTerminalOutcome, RunView, SessionInspection, SessionInspectionOptions, SorbetRun, ToolInvocationContext, UnitReader, UnitRuntime, UnitTx } from "@sorbetai/runtime";
5
+ import * as _sorbetai_context0 from "@sorbetai/context";
6
+ import { NamedStateOwner } from "@sorbetai/context";
7
+
8
+ //#region src/children/contracts.d.ts
9
+ /** Named State for every child Session; parents use `ChildAgentManager.stateOwner` instead. */
10
+ declare const subagentIdentity: NamedStateOwner;
11
+ declare const ChildModelUsageSnapshotSchema: s.Schema<{
12
+ committedResponses: number;
13
+ activeRequests: number;
14
+ unknownRequests: number;
15
+ totalTokens: number;
16
+ costUsd: number;
17
+ models?: {
18
+ provider: string;
19
+ model: string;
20
+ usage: {
21
+ input: number;
22
+ output: number;
23
+ cacheRead: number;
24
+ cacheWrite: number;
25
+ totalTokens: number;
26
+ cost: {
27
+ input: number;
28
+ output: number;
29
+ cacheRead: number;
30
+ cacheWrite: number;
31
+ total: number;
32
+ totalFromProvider?: boolean | undefined;
33
+ };
34
+ cacheWrite1h?: number | undefined;
35
+ reasoning?: number | undefined;
36
+ };
37
+ }[] | undefined;
38
+ }>;
39
+ declare const ClosedChildUsageSchema: s.Schema<{
40
+ modelUsage: {
41
+ committedResponses: number;
42
+ activeRequests: number;
43
+ unknownRequests: number;
44
+ totalTokens: number;
45
+ costUsd: number;
46
+ models?: {
47
+ provider: string;
48
+ model: string;
49
+ usage: {
50
+ input: number;
51
+ output: number;
52
+ cacheRead: number;
53
+ cacheWrite: number;
54
+ totalTokens: number;
55
+ cost: {
56
+ input: number;
57
+ output: number;
58
+ cacheRead: number;
59
+ cacheWrite: number;
60
+ total: number;
61
+ totalFromProvider?: boolean | undefined;
62
+ };
63
+ cacheWrite1h?: number | undefined;
64
+ reasoning?: number | undefined;
65
+ };
66
+ }[] | undefined;
67
+ };
68
+ throughRunId?: string | undefined;
69
+ }>;
70
+ type ClosedChildUsage = Readonly<s.Static<typeof ClosedChildUsageSchema>>;
71
+ type ChildAgentState = 'starting' | 'running' | 'completed' | 'failed' | 'cancelled' | 'closed';
72
+ interface ChildAgentSnapshot {
73
+ readonly agentId: string;
74
+ readonly childSessionId: string;
75
+ /** Short display name chosen when this child was spawned. Older children may not have one. */
76
+ readonly name?: string;
77
+ /** Short description of the initial assignment. */
78
+ readonly description?: string;
79
+ readonly state: ChildAgentState;
80
+ /** Run of the parent that admitted this child. */
81
+ readonly parentRunId: string;
82
+ /** Parent Tool call that admitted this child; anchors the child in task projections. */
83
+ readonly spawnToolCallId: string;
84
+ readonly createdAt: string;
85
+ readonly modelUsage: ChildModelUsageSnapshot;
86
+ readonly runId?: string;
87
+ readonly outcome?: RunTerminalOutcome;
88
+ readonly response?: {
89
+ readonly text: string;
90
+ readonly truncated: boolean;
91
+ readonly offset?: number;
92
+ readonly nextOffset?: number;
93
+ };
94
+ }
95
+ interface SpawnAgentOptions {
96
+ readonly name?: string;
97
+ readonly description?: string;
98
+ readonly model?: string;
99
+ readonly isBackground?: boolean;
100
+ readonly completionDelivery?: 'auto' | 'manual';
101
+ }
102
+ type SpawnAgentRequest = {
103
+ readonly prompt: string;
104
+ } & SpawnAgentOptions;
105
+ interface SwarmAgentRequest {
106
+ readonly tasks: readonly {
107
+ readonly prompt: string;
108
+ readonly taskId: string;
109
+ readonly name?: string;
110
+ readonly description?: string;
111
+ }[];
112
+ readonly model?: string;
113
+ }
114
+ interface SendInputRequest {
115
+ readonly agentId: string;
116
+ readonly prompt: string;
117
+ readonly interrupt?: boolean;
118
+ }
119
+ interface SpawnAgentOutput {
120
+ readonly agent: ChildAgentSnapshot;
121
+ }
122
+ type SwarmTaskOutput = {
123
+ readonly taskId: string;
124
+ readonly status: 'completed';
125
+ readonly agent: ChildAgentSnapshot;
126
+ } | {
127
+ readonly taskId: string;
128
+ readonly status: 'failed';
129
+ readonly agent: ChildAgentSnapshot;
130
+ } | {
131
+ readonly taskId: string;
132
+ readonly status: 'failed';
133
+ readonly error: {
134
+ readonly code: string;
135
+ readonly message: string;
136
+ };
137
+ } | {
138
+ readonly taskId: string;
139
+ readonly status: 'cancelled';
140
+ readonly error: {
141
+ readonly code: string;
142
+ readonly message: string;
143
+ };
144
+ };
145
+ interface SwarmAgentOutput {
146
+ readonly tasks: readonly SwarmTaskOutput[];
147
+ }
148
+ /** Accepted input is durable; placement and the Run belong to the child. */
149
+ interface SendInputOutput {
150
+ readonly status: 'accepted';
151
+ readonly deliveryId: string;
152
+ readonly agent: ChildAgentSnapshot;
153
+ }
154
+ interface TeamPeerSnapshot {
155
+ readonly agentId: string;
156
+ readonly state: ChildAgentState;
157
+ }
158
+ interface ListTeamPeersOutput {
159
+ readonly peers: readonly TeamPeerSnapshot[];
160
+ }
161
+ interface SendTeamMessageRequest {
162
+ readonly agentId: string;
163
+ readonly prompt: string;
164
+ }
165
+ interface SendTeamMessageOutput {
166
+ /** The parent ledger owns delivery; the recipient may not have accepted the input yet. */
167
+ readonly status: 'queued';
168
+ readonly deliveryId: string;
169
+ readonly recipient: {
170
+ readonly agentId: string;
171
+ };
172
+ }
173
+ interface ListAgentsOutput {
174
+ readonly agents: readonly ChildAgentSnapshot[];
175
+ readonly modelUsage: ChildModelUsageSnapshot;
176
+ }
177
+ type ChildModelUsageSnapshot = Readonly<s.Static<typeof ChildModelUsageSnapshotSchema>>;
178
+ interface CloseAgentOutput {
179
+ readonly agent: ChildAgentSnapshot & {
180
+ readonly state: 'closed';
181
+ };
182
+ }
183
+ type ChildAgentFailureCode = 'model_unavailable' | 'child_not_found' | 'child_closed' | 'child_provision_failed' | 'child_depth_exceeded' | 'child_delivery_conflict' | 'child_input_interrupted' | 'child_input_pending' | 'child_run_not_found' | 'team_self_message' | 'child_manager_closed';
184
+ declare class ChildAgentError extends Error {
185
+ readonly code: ChildAgentFailureCode;
186
+ readonly name = "ChildAgentError";
187
+ constructor(code: ChildAgentFailureCode, message: string);
188
+ }
189
+ //#endregion
190
+ //#region src/children/telemetry-port.d.ts
191
+ interface ChildDeliveryBacklog {
192
+ readonly direction: 'to_child' | 'to_parent';
193
+ readonly pending: number;
194
+ readonly dispatching: number;
195
+ readonly awaitingInclusion: number;
196
+ /** Wall-clock bound; absent when no pending delivery has a recorded enqueue time. */
197
+ readonly oldestPendingEnqueuedAt?: string;
198
+ readonly unknownPendingAge: number;
199
+ }
200
+ /** The callback name is retained for compatibility; its data derives from committed Unit facts. */
201
+ interface ChildLedgerObservation {
202
+ readonly parentSessionId: string;
203
+ /** Children with a nonterminal Run, including interrupted or parked Runs; not a resource-usage gauge. */
204
+ readonly activeChildren: number;
205
+ readonly deliveries: readonly ChildDeliveryBacklog[];
206
+ }
207
+ interface ChildDeliveryObservation {
208
+ readonly parentSessionId: string;
209
+ readonly agentId: string;
210
+ readonly childSessionId?: string;
211
+ readonly deliveryId: string;
212
+ readonly orderingKey: number;
213
+ readonly sourceSessionId: string;
214
+ readonly sourceRunId: string;
215
+ readonly direction: 'to_child' | 'to_parent';
216
+ readonly state: 'pending' | 'dispatching' | 'complete' | 'cancelled';
217
+ readonly transition: 'enqueued' | 'dispatched' | 'accepted' | 'included' | 'completed' | 'cancelled';
218
+ /** Persisted wall times, never reconstructed as a continuous monotonic span. */
219
+ readonly enqueuedAt?: string;
220
+ readonly dispatchedAt?: string;
221
+ readonly acceptedAt?: string;
222
+ readonly acceptedRunId?: string;
223
+ readonly acceptedSessionId?: string;
224
+ readonly acceptedFactId?: string;
225
+ readonly acceptedCursor?: string;
226
+ readonly includedAt?: string;
227
+ readonly includedModelRequestId?: string;
228
+ readonly includedFactId?: string;
229
+ readonly includedCursor?: string;
230
+ readonly includedSessionId?: string;
231
+ }
232
+ interface ChildDeliveryPage {
233
+ readonly parentSessionId: string;
234
+ readonly deliveries: readonly Omit<ChildDeliveryObservation, 'transition'>[];
235
+ readonly nextOrderingKey?: number;
236
+ }
237
+ interface ChildSpawnObservation {
238
+ readonly parentSessionId: string;
239
+ readonly parentRunId: string;
240
+ readonly childSessionId: string;
241
+ readonly agentId: string;
242
+ readonly toolCallId: string;
243
+ readonly effectAttemptId: string;
244
+ }
245
+ /** Borrowed passive metadata callbacks. Durable transitions report only after an atomic
246
+ * Unit commit; reopening a Unit does not replay historical transition counters. Throws and
247
+ * accidental rejected promises cannot alter child admission, delivery, or cleanup. */
248
+ interface ChildAgentObservationPort {
249
+ childLedgerProjected?(data: ChildLedgerObservation): void;
250
+ childDeliveryCommitted?(data: ChildDeliveryObservation): void;
251
+ childSpawnCommitted?(data: ChildSpawnObservation): void;
252
+ childLedgerDetached?(data: {
253
+ readonly parentSessionId: string;
254
+ }): void;
255
+ }
256
+ //#endregion
257
+ //#region src/children/record.d.ts
258
+ /** Applied to the child's first Run. Open: hosts persist their own fields, such as a sandbox mode. */
259
+ declare const ChildExecutionPolicySchema: s.Schema<{
260
+ toolPermissions: {
261
+ fallback: {
262
+ access: "deny";
263
+ } | {
264
+ access: "allow";
265
+ approval: "not-required";
266
+ } | {
267
+ access: "allow";
268
+ approval: "required";
269
+ };
270
+ tools: Record<string, {
271
+ access: "deny";
272
+ } | {
273
+ access: "allow";
274
+ approval: "not-required";
275
+ } | {
276
+ access: "allow";
277
+ approval: "required";
278
+ }>;
279
+ rules: {
280
+ entry: {
281
+ access: "deny";
282
+ } | {
283
+ access: "allow";
284
+ approval: "not-required";
285
+ } | {
286
+ access: "allow";
287
+ approval: "required";
288
+ };
289
+ toolName: string;
290
+ parameter?: {
291
+ name: string;
292
+ value: string | number | boolean | null;
293
+ } | undefined;
294
+ }[];
295
+ };
296
+ approvalMode?: "human" | "auto" | undefined;
297
+ }>;
298
+ type ChildExecutionPolicy = Readonly<s.Static<typeof ChildExecutionPolicySchema>>;
299
+ declare const ChildTaskInputSchema: s.Schema<{
300
+ agentId: string;
301
+ childSessionId: string;
302
+ parentSessionId: string;
303
+ parentRunId: string;
304
+ spawnToolCallId: string;
305
+ spawnEffectAttemptId: string;
306
+ depth: 1;
307
+ providerId: string;
308
+ modelId: string;
309
+ executionPolicy: {
310
+ toolPermissions: {
311
+ fallback: {
312
+ access: "deny";
313
+ } | {
314
+ access: "allow";
315
+ approval: "not-required";
316
+ } | {
317
+ access: "allow";
318
+ approval: "required";
319
+ };
320
+ tools: Record<string, {
321
+ access: "deny";
322
+ } | {
323
+ access: "allow";
324
+ approval: "not-required";
325
+ } | {
326
+ access: "allow";
327
+ approval: "required";
328
+ }>;
329
+ rules: {
330
+ entry: {
331
+ access: "deny";
332
+ } | {
333
+ access: "allow";
334
+ approval: "not-required";
335
+ } | {
336
+ access: "allow";
337
+ approval: "required";
338
+ };
339
+ toolName: string;
340
+ parameter?: {
341
+ name: string;
342
+ value: string | number | boolean | null;
343
+ } | undefined;
344
+ }[];
345
+ };
346
+ approvalMode?: "human" | "auto" | undefined;
347
+ };
348
+ ordinaryToolNames: string[];
349
+ initialMode: "foreground" | "background";
350
+ initialCompletionDelivery: "auto" | "manual";
351
+ contextMode: "fresh" | "full";
352
+ createdAt: string;
353
+ name?: string | undefined;
354
+ description?: string | undefined;
355
+ initialSubmissionId?: string | undefined;
356
+ imported?: {
357
+ orderingKeyFloor: number;
358
+ deliveries: {
359
+ deliveryId: string;
360
+ orderingKey: number;
361
+ direction: "to_child" | "to_parent";
362
+ sourceSessionId: string;
363
+ sourceRunId: string;
364
+ state: "pending" | "cancelled" | "complete";
365
+ enqueuedAt?: string | undefined;
366
+ dispatchedAt?: string | undefined;
367
+ acceptedAt?: string | undefined;
368
+ acceptedRunId?: string | undefined;
369
+ acceptedSessionId?: string | undefined;
370
+ acceptedFactId?: string | undefined;
371
+ acceptedMessageId?: string | undefined;
372
+ acceptedCursor?: string | undefined;
373
+ includedAt?: string | undefined;
374
+ includedModelRequestId?: string | undefined;
375
+ includedSessionId?: string | undefined;
376
+ includedFactId?: string | undefined;
377
+ includedCursor?: string | undefined;
378
+ }[];
379
+ initialRunId?: string | undefined;
380
+ } | undefined;
381
+ }>;
382
+ type ChildTaskInput = s.Static<typeof ChildTaskInputSchema>;
383
+ //#endregion
384
+ //#region src/children/projection.d.ts
385
+ interface ChildAgentEntry extends ChildTaskInput {
386
+ readonly anchorId: string;
387
+ readonly initialRunId?: string;
388
+ readonly closing: boolean;
389
+ readonly closed: boolean;
390
+ readonly closedUsage?: ClosedChildUsage;
391
+ }
392
+ //#endregion
393
+ //#region src/children/catalog.d.ts
394
+ /** Cold reads pin a committed prefix; owned reads incrementally reuse that writer's index. */
395
+ declare class ChildAgentCatalog {
396
+ #private;
397
+ readonly openReader: (parentSessionId: string) => Promise<UnitReader>;
398
+ constructor(openReader: (parentSessionId: string) => Promise<UnitReader>);
399
+ track(unit: UnitRuntime, observe: boolean): void;
400
+ record(parentSessionId: string, agentId: string): Promise<ChildAgentEntry>;
401
+ read(parentSessionId: string, afterSequence?: number): Promise<{
402
+ children: ChildAgentEntry[];
403
+ observations: ({
404
+ kind: "spawn";
405
+ data: ChildSpawnObservation;
406
+ } | {
407
+ kind: "delivery";
408
+ data: ChildDeliveryObservation;
409
+ })[];
410
+ observedUnitSequence: number;
411
+ activeChildren: number;
412
+ completions: {
413
+ agentId: string;
414
+ runId: string;
415
+ cursor: number;
416
+ }[];
417
+ deliveries: Omit<ChildDeliveryObservation, "transition">[];
418
+ }>;
419
+ inspectDeliveries(parentSessionId: string, options?: {
420
+ readonly afterOrderingKey?: number;
421
+ readonly limit?: number;
422
+ }): Promise<ChildDeliveryPage>;
423
+ }
424
+ //#endregion
425
+ //#region src/children/models.d.ts
426
+ interface AvailableAgentModel {
427
+ readonly selector: string;
428
+ readonly providerId: string;
429
+ readonly modelId: string;
430
+ readonly displayName: string;
431
+ }
432
+ interface ModelSelector {
433
+ readonly providerId: string;
434
+ readonly modelId: string;
435
+ }
436
+ declare function encodeModelSelector(providerId: string, modelId: string): string;
437
+ declare function decodeModelSelector(selector: string): ModelSelector | undefined;
438
+ //#endregion
439
+ //#region src/children/host.d.ts
440
+ /** The part of an attached Session the child layer observes and aborts; `SorbetSession` satisfies it. */
441
+ interface ChildSessionRuntime {
442
+ getActiveRun(): Promise<SorbetRun | undefined>;
443
+ abortRun(runId: string, reason?: string): Promise<RunCancellationReceipt>;
444
+ snapshot(runId: string): Promise<RunView>;
445
+ runFacts(runId: string, options?: {
446
+ readonly after?: JournalCursor;
447
+ }): JournalSubscription;
448
+ inspect(options?: SessionInspectionOptions): Promise<SessionInspection>;
449
+ }
450
+ /** Spawn authority of an attached parent Session. */
451
+ interface ChildAgentParent {
452
+ /** Only depth 0 Sessions own children. */
453
+ readonly depth: number;
454
+ readonly providerId: string;
455
+ readonly modelId: string;
456
+ /** Frozen into the child record; the host may add fields such as a sandbox mode. */
457
+ executionPolicy(runId: string): ChildExecutionPolicy;
458
+ /** Tool names the child may use; frozen into the child record. */
459
+ ordinaryToolNames(): Promise<readonly string[]>;
460
+ }
461
+ /**
462
+ * Everything environment-specific about child Sessions: which models exist, how a
463
+ * child Session is attached with its model, Tools and permissions, and its metadata.
464
+ * Implementations must linearize attachment of committed children by
465
+ * `childSessionId`: concurrent `loadChild` calls return the same attached Session.
466
+ */
467
+ interface ChildAgentHost {
468
+ availableModels(): Promise<readonly AvailableAgentModel[]>;
469
+ unit(sessionId: string): UnitRuntime;
470
+ /** An attached parent; spawning from an unattached parent fails. */
471
+ parent(sessionId: string): ChildAgentParent | undefined;
472
+ /** `session.created` metadata for a new child. Not called when the child already exists. */
473
+ childMetadata(child: ChildTaskInput): Promise<JsonValue>;
474
+ /** The attached Session, if any. Unattached children have no execution in this process. */
475
+ loaded(sessionId: string): ChildSessionRuntime | undefined;
476
+ loadChild(record: ChildAgentEntry): Promise<ChildSessionRuntime>;
477
+ inspectChild(record: ChildAgentEntry): Promise<SessionInspection>;
478
+ /** Detach every attached child of the parent, preserving its Runs for recovery. */
479
+ releaseChildren(parentSessionId: string): Promise<void>;
480
+ }
481
+ //#endregion
482
+ //#region src/children/operations.d.ts
483
+ interface ChildOperation {
484
+ readonly parentSessionId: string;
485
+ readonly context: ToolInvocationContext;
486
+ }
487
+ interface SpawnOperation extends ChildOperation {
488
+ readonly request: SpawnAgentRequest;
489
+ }
490
+ interface SwarmOperation extends ChildOperation {
491
+ readonly request: SwarmAgentRequest;
492
+ }
493
+ //#endregion
494
+ //#region src/children/manager.d.ts
495
+ declare class ChildAgentManager {
496
+ #private;
497
+ constructor(options: {
498
+ readonly catalog: ChildAgentCatalog;
499
+ readonly host: ChildAgentHost;
500
+ /**
501
+ * Swarm admission concurrency, unbounded by default. Run placement is bounded
502
+ * separately by the Unit's `policies.concurrency.childRunsPerParent`.
503
+ */
504
+ readonly maxActiveChildrenPerParent?: number;
505
+ readonly createId: () => string;
506
+ readonly now: () => Date;
507
+ readonly observation?: ChildAgentObservationPort;
508
+ });
509
+ spawn(operation: SpawnOperation): Promise<SpawnAgentOutput>;
510
+ stateOwner(parentSessionId: string): _sorbetai_context0.NamedStateOwner<"child_runs", s.Schema<{
511
+ throughCompletion: number;
512
+ resultCount: number;
513
+ results: {
514
+ agentId: string;
515
+ runId: string;
516
+ cursor: number;
517
+ }[];
518
+ }>>;
519
+ getResult(operation: ChildOperation & {
520
+ readonly agentId: string;
521
+ readonly runId: string;
522
+ readonly offset?: number;
523
+ readonly limit?: number;
524
+ }): Promise<ChildAgentSnapshot>;
525
+ listResults(operation: ChildOperation & {
526
+ readonly after?: number;
527
+ readonly limit?: number;
528
+ }): Promise<{
529
+ results: {
530
+ agentId: string;
531
+ runId: string;
532
+ cursor: number;
533
+ }[];
534
+ nextCursor: number | undefined;
535
+ }>;
536
+ swarm(operation: SwarmOperation): Promise<SwarmAgentOutput>;
537
+ send(operation: ChildOperation & {
538
+ readonly request: SendInputRequest;
539
+ }): Promise<SendInputOutput>;
540
+ listTeamPeers(operation: ChildOperation & {
541
+ readonly senderAgentId: string;
542
+ }): Promise<ListTeamPeersOutput>;
543
+ sendTeamMessage(operation: ChildOperation & {
544
+ readonly senderAgentId: string;
545
+ readonly request: SendTeamMessageRequest;
546
+ }): Promise<SendTeamMessageOutput>;
547
+ listAgents(operation: ChildOperation & {
548
+ readonly request: {
549
+ readonly includeClosed?: boolean;
550
+ };
551
+ }): Promise<ListAgentsOutput>;
552
+ listAgentsForHost(parentSessionId: string, includeClosed?: boolean): Promise<ListAgentsOutput>;
553
+ closeChild(operation: ChildOperation & {
554
+ readonly agentId: string;
555
+ }): Promise<CloseAgentOutput>;
556
+ closeChildForHost(parentSessionId: string, agentId: string, signal?: AbortSignal, reason?: string): Promise<CloseAgentOutput>;
557
+ /** Lets the durable `wait` Tool wait for child Runs of the Session that owns them. */
558
+ waitTargets(): WaitTargetSource;
559
+ trackUnit(unit: UnitRuntime): void;
560
+ activateParent(parentSessionId: string): Promise<void>;
561
+ releaseParent(parentSessionId: string): Promise<void>;
562
+ closeBySession(parentSessionId: string, childSessionId: string): Promise<boolean>;
563
+ shutdown(parentSessionIds: readonly string[]): Promise<void>;
564
+ }
565
+ //#endregion
566
+ //#region src/children/tools.d.ts
567
+ declare const AgentActionSchema: s.Schema<{
568
+ action: "list_models";
569
+ } | {
570
+ action: "get_result";
571
+ agentId: string;
572
+ runId: string;
573
+ offset?: number | undefined;
574
+ limit?: number | undefined;
575
+ } | {
576
+ action: "list_results";
577
+ after?: number | undefined;
578
+ limit?: number | undefined;
579
+ } | {
580
+ action: "spawn";
581
+ prompt: string;
582
+ name?: string | undefined;
583
+ description?: string | undefined;
584
+ model?: string | undefined;
585
+ completionDelivery?: "auto" | "manual" | undefined;
586
+ } | {
587
+ action: "swarm";
588
+ tasks: {
589
+ taskId: string;
590
+ prompt: string;
591
+ name?: string | undefined;
592
+ description?: string | undefined;
593
+ }[];
594
+ model?: string | undefined;
595
+ } | {
596
+ action: "send_input";
597
+ agentId: string;
598
+ prompt: string;
599
+ interrupt?: boolean | undefined;
600
+ } | {
601
+ action: "list";
602
+ includeClosed?: boolean | undefined;
603
+ } | {
604
+ action: "close";
605
+ agentId: string;
606
+ }>;
607
+ type AgentAction = s.Static<typeof AgentActionSchema>;
608
+ declare const AgentToolParametersSchema: s.Schema<AgentAction>;
609
+ interface ListModelsOutput {
610
+ readonly inheritedModel: string;
611
+ readonly models: readonly AvailableAgentModel[];
612
+ }
613
+ type AgentToolDetails = ({
614
+ readonly action: 'get_result';
615
+ } & {
616
+ readonly agent: ChildAgentSnapshot;
617
+ }) | ({
618
+ readonly action: 'list_results';
619
+ } & Awaited<ReturnType<ChildAgentManager['listResults']>>) | ({
620
+ readonly action: 'list_models';
621
+ } & ListModelsOutput) | ({
622
+ readonly action: 'spawn';
623
+ } & SpawnAgentOutput) | ({
624
+ readonly action: 'swarm';
625
+ } & SwarmAgentOutput) | ({
626
+ readonly action: 'send_input';
627
+ } & SendInputOutput) | ({
628
+ readonly action: 'list';
629
+ } & ListAgentsOutput) | ({
630
+ readonly action: 'close';
631
+ } & CloseAgentOutput);
632
+ declare function createAgentTool(options: {
633
+ readonly parentSessionId: string;
634
+ readonly inheritedModel: string;
635
+ readonly listAvailableModels: () => Promise<readonly AvailableAgentModel[]>;
636
+ readonly manager: ChildAgentManager;
637
+ }): ContextualTool<typeof AgentToolParametersSchema, AgentToolDetails>;
638
+ //#endregion
639
+ //#region src/children/team-tools.d.ts
640
+ declare const TeamActionSchema: s.Schema<{
641
+ action: "list_peers";
642
+ } | {
643
+ action: "send_message";
644
+ agentId: string;
645
+ prompt: string;
646
+ }>;
647
+ type TeamAction = s.Static<typeof TeamActionSchema>;
648
+ declare const TeamToolParametersSchema: s.Schema<TeamAction>;
649
+ type TeamToolDetails = ({
650
+ readonly action: 'list_peers';
651
+ } & ListTeamPeersOutput) | ({
652
+ readonly action: 'send_message';
653
+ } & SendTeamMessageOutput);
654
+ declare function createTeamTool(options: {
655
+ readonly parentSessionId: string;
656
+ readonly senderAgentId: string;
657
+ readonly manager: ChildAgentManager;
658
+ }): ContextualTool<typeof TeamToolParametersSchema, TeamToolDetails>;
659
+ //#endregion
660
+ //#region src/children/close.d.ts
661
+ /** The Host handles close intent and confirms resource release; phases perform no resource I/O. */
662
+ declare const childTaskDefinition: _sorbetai_runtime18.TaskDefinition<{
663
+ agentId: string;
664
+ childSessionId: string;
665
+ parentSessionId: string;
666
+ parentRunId: string;
667
+ spawnToolCallId: string;
668
+ spawnEffectAttemptId: string;
669
+ depth: 1;
670
+ providerId: string;
671
+ modelId: string;
672
+ executionPolicy: {
673
+ toolPermissions: {
674
+ fallback: {
675
+ access: "deny";
676
+ } | {
677
+ access: "allow";
678
+ approval: "not-required";
679
+ } | {
680
+ access: "allow";
681
+ approval: "required";
682
+ };
683
+ tools: Record<string, {
684
+ access: "deny";
685
+ } | {
686
+ access: "allow";
687
+ approval: "not-required";
688
+ } | {
689
+ access: "allow";
690
+ approval: "required";
691
+ }>;
692
+ rules: {
693
+ entry: {
694
+ access: "deny";
695
+ } | {
696
+ access: "allow";
697
+ approval: "not-required";
698
+ } | {
699
+ access: "allow";
700
+ approval: "required";
701
+ };
702
+ toolName: string;
703
+ parameter?: {
704
+ name: string;
705
+ value: string | number | boolean | null;
706
+ } | undefined;
707
+ }[];
708
+ };
709
+ approvalMode?: "human" | "auto" | undefined;
710
+ };
711
+ ordinaryToolNames: string[];
712
+ initialMode: "foreground" | "background";
713
+ initialCompletionDelivery: "auto" | "manual";
714
+ contextMode: "fresh" | "full";
715
+ createdAt: string;
716
+ name?: string | undefined;
717
+ description?: string | undefined;
718
+ initialSubmissionId?: string | undefined;
719
+ imported?: {
720
+ orderingKeyFloor: number;
721
+ deliveries: {
722
+ deliveryId: string;
723
+ orderingKey: number;
724
+ direction: "to_child" | "to_parent";
725
+ sourceSessionId: string;
726
+ sourceRunId: string;
727
+ state: "pending" | "cancelled" | "complete";
728
+ enqueuedAt?: string | undefined;
729
+ dispatchedAt?: string | undefined;
730
+ acceptedAt?: string | undefined;
731
+ acceptedRunId?: string | undefined;
732
+ acceptedSessionId?: string | undefined;
733
+ acceptedFactId?: string | undefined;
734
+ acceptedMessageId?: string | undefined;
735
+ acceptedCursor?: string | undefined;
736
+ includedAt?: string | undefined;
737
+ includedModelRequestId?: string | undefined;
738
+ includedSessionId?: string | undefined;
739
+ includedFactId?: string | undefined;
740
+ includedCursor?: string | undefined;
741
+ }[];
742
+ initialRunId?: string | undefined;
743
+ } | undefined;
744
+ }, {
745
+ phase: "open";
746
+ } | {
747
+ phase: "closing";
748
+ close: string;
749
+ released: string;
750
+ }, {
751
+ modelUsage: {
752
+ committedResponses: number;
753
+ activeRequests: number;
754
+ unknownRequests: number;
755
+ totalTokens: number;
756
+ costUsd: number;
757
+ models?: {
758
+ provider: string;
759
+ model: string;
760
+ usage: {
761
+ input: number;
762
+ output: number;
763
+ cacheRead: number;
764
+ cacheWrite: number;
765
+ totalTokens: number;
766
+ cost: {
767
+ input: number;
768
+ output: number;
769
+ cacheRead: number;
770
+ cacheWrite: number;
771
+ total: number;
772
+ totalFromProvider?: boolean | undefined;
773
+ };
774
+ cacheWrite1h?: number | undefined;
775
+ reasoning?: number | undefined;
776
+ };
777
+ }[] | undefined;
778
+ };
779
+ throughRunId?: string | undefined;
780
+ }>;
781
+ /** Fence placement in the same commit as close intent; cleanup can continue after a crash. */
782
+ declare function stageChildClose(tx: UnitTx, anchorId: string, reason: string, commandId: string): void;
783
+ /** Also used by the offline importer for already-created Sessions; it never starts a Run. */
784
+ declare function stageChildAnchor(tx: UnitTx, child: ChildTaskInput): string;
785
+ /** Finish committed close intent without constructing a Session, Provider or Tool. */
786
+ declare function finishChildClose(unit: UnitRuntime, sessionId: string, release: () => Promise<void>, signal: AbortSignal): Promise<void>;
787
+ //#endregion
788
+ //#region src/children/completion.d.ts
789
+ declare const ReporterInput: s.Schema<{
790
+ submissionId: string;
791
+ agentId: string;
792
+ childSessionId: string;
793
+ parentSessionId: string;
794
+ kind?: "submission" | undefined;
795
+ } | {
796
+ kind: "legacy-run";
797
+ legacyRunId: string;
798
+ agentId: string;
799
+ childSessionId: string;
800
+ parentSessionId: string;
801
+ }>;
802
+ /** Submission settlement, completion acceptance and reporter settlement use durable identities. */
803
+ declare const childReporterDefinition: _sorbetai_runtime18.TaskDefinition<{
804
+ submissionId: string;
805
+ agentId: string;
806
+ childSessionId: string;
807
+ parentSessionId: string;
808
+ kind?: "submission" | undefined;
809
+ } | {
810
+ kind: "legacy-run";
811
+ legacyRunId: string;
812
+ agentId: string;
813
+ childSessionId: string;
814
+ parentSessionId: string;
815
+ }, {
816
+ phase: "report";
817
+ }, {
818
+ runId?: string | undefined;
819
+ deliveryId?: string | undefined;
820
+ }>;
821
+ /** Call in the same group that accepts the child input, when automatic delivery is enabled. */
822
+ declare function stageChildReporter(tx: UnitTx, anchorId: string, input: s.Static<typeof ReporterInput>): string;
823
+ /**
824
+ * Input acceptance and its completion reporter share one commit. Manual children
825
+ * never create reporters. Foreground children omit the initial reporter.
826
+ * Initial placement also records the child's execution policy.
827
+ */
828
+ declare function stageChildInput(tx: UnitTx, child: ChildTaskInput, anchorId: string, input: Parameters<UnitTx['submit']>[1], options?: {
829
+ readonly initial?: boolean;
830
+ }): void;
831
+ //#endregion
832
+ //#region src/children/lifecycle.d.ts
833
+ /** Commit before waiting for a child Run or Tool result. A failed receipt cannot undo admission. */
834
+ declare function stageChildAgent(tx: UnitTx, request: {
835
+ readonly child: ChildTaskInput & {
836
+ readonly initialSubmissionId: string;
837
+ };
838
+ readonly metadata: JsonValue;
839
+ readonly input: Parameters<UnitTx['submit']>[1];
840
+ }): string;
841
+ //#endregion
842
+ //#region src/children/usage.d.ts
843
+ /** Journal-authoritative per-model rows, so a Host can account child spend by model. */
844
+ declare function projectModelUsage(runs: readonly RunInspection[]): ChildModelUsageSnapshot;
845
+ //#endregion
846
+ export { type AgentToolDetails, type AvailableAgentModel, ChildAgentCatalog, type ChildAgentEntry, ChildAgentError, type ChildAgentFailureCode, type ChildAgentHost, ChildAgentManager, type ChildAgentObservationPort, type ChildAgentParent, type ChildAgentSnapshot, type ChildAgentState, type ChildDeliveryBacklog, type ChildDeliveryObservation, type ChildDeliveryPage, type ChildExecutionPolicy, ChildExecutionPolicySchema, type ChildLedgerObservation, type ChildModelUsageSnapshot, type ChildSessionRuntime, type ChildSpawnObservation, type ChildTaskInput, ChildTaskInputSchema, type CloseAgentOutput, type ClosedChildUsage, ClosedChildUsageSchema, type ListAgentsOutput, type ListTeamPeersOutput, type ModelSelector, type SendInputOutput, type SendTeamMessageOutput, type SpawnAgentOutput, type SwarmAgentOutput, type SwarmTaskOutput, type TeamPeerSnapshot, type TeamToolDetails, childReporterDefinition, childTaskDefinition, createAgentTool, createTeamTool, decodeModelSelector, encodeModelSelector, finishChildClose, projectModelUsage, stageChildAgent, stageChildAnchor, stageChildClose, stageChildInput, stageChildReporter, subagentIdentity };
847
+ //# sourceMappingURL=children.d.ts.map