@tangle-network/agent-interface 0.40.0 → 0.42.0

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.
@@ -1,6 +1,11 @@
1
+ import { z } from "zod";
1
2
  import type { AgentProfile, AgentProfileCapabilities, AgentProfileValidationResult } from "./agent-profile.js";
2
3
  import type { AgentCandidateTermination } from "./agent-candidate.js";
3
4
  import type { InputPart, StreamEvent, TokenUsage } from "./index.js";
5
+ import { type InteractionAcknowledgement, type InteractionCapabilities, type InteractionResponseCommand } from "./interaction.js";
6
+ import { type ContextTransferReceipt, type ContextTransferRequest, type NativeContextBoundaryProof, type NativeContextContinuationRequest, type NativeContextContinuationTurn } from "./portable-context.js";
7
+ import { type AgentRunControlRef } from "./runtime-control.js";
8
+ import type { AgentWorkspaceBranching } from "./workspace-branching.js";
4
9
  /** Portable profile reference: inline profile or provider catalog id. */
5
10
  export type AgentProfileRef = AgentProfile | string;
6
11
  export type AgentEnvironmentStatus = "pending" | "provisioning" | "running" | "stopped" | "failed" | "expired" | "unknown";
@@ -202,6 +207,12 @@ export interface AgentTurnInput {
202
207
  lastEventId?: string;
203
208
  turnId?: string;
204
209
  detach?: boolean;
210
+ /** Stable coordinates for a retained run when one already exists. */
211
+ controlRef?: AgentRunControlRef;
212
+ /** Approved portable history for a fresh provider session. */
213
+ contextTransfer?: ContextTransferRequest;
214
+ /** Verified same-session continuation; never carries duplicate history. */
215
+ nativeContinuation?: NativeContextContinuationRequest;
205
216
  context?: Record<string, unknown>;
206
217
  signal?: AbortSignal;
207
218
  providerOptions?: Record<string, unknown>;
@@ -214,10 +225,269 @@ export interface AgentTurnResult {
214
225
  usage?: TokenUsage;
215
226
  metadata?: Record<string, unknown>;
216
227
  events?: AgentEnvironmentEvent[];
228
+ contextTransferReceipt?: ContextTransferReceipt;
217
229
  }
230
+ /** Runtime validator for a provider turn returned from durable continuation. */
231
+ export declare const AgentTurnResultSchema: z.ZodObject<{
232
+ text: z.ZodString;
233
+ success: z.ZodBoolean;
234
+ error: z.ZodOptional<z.ZodString>;
235
+ sessionId: z.ZodOptional<z.ZodString>;
236
+ usage: z.ZodOptional<z.ZodObject<{
237
+ inputTokens: z.ZodNumber;
238
+ outputTokens: z.ZodNumber;
239
+ totalTokens: z.ZodOptional<z.ZodNumber>;
240
+ cacheReadInputTokens: z.ZodOptional<z.ZodNumber>;
241
+ cacheCreationInputTokens: z.ZodOptional<z.ZodNumber>;
242
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
243
+ cost: z.ZodOptional<z.ZodNumber>;
244
+ }, z.core.$strict>>;
245
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
246
+ events: z.ZodOptional<z.ZodArray<z.ZodObject<{
247
+ type: z.ZodString;
248
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
249
+ id: z.ZodOptional<z.ZodString>;
250
+ normalized: z.ZodOptional<z.ZodType<StreamEvent, unknown, z.core.$ZodTypeInternals<StreamEvent, unknown>>>;
251
+ usage: z.ZodOptional<z.ZodObject<{
252
+ inputTokens: z.ZodNumber;
253
+ outputTokens: z.ZodNumber;
254
+ totalTokens: z.ZodOptional<z.ZodNumber>;
255
+ cacheReadInputTokens: z.ZodOptional<z.ZodNumber>;
256
+ cacheCreationInputTokens: z.ZodOptional<z.ZodNumber>;
257
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
258
+ cost: z.ZodOptional<z.ZodNumber>;
259
+ }, z.core.$strict>>;
260
+ providerEvent: z.ZodOptional<z.ZodUnknown>;
261
+ }, z.core.$strict>>>;
262
+ contextTransferReceipt: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
263
+ status: z.ZodLiteral<"accepted" | "replayed">;
264
+ operationId: z.ZodString;
265
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
266
+ planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
267
+ contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
268
+ destination: z.ZodObject<{
269
+ runner: z.ZodString;
270
+ provider: z.ZodOptional<z.ZodString>;
271
+ model: z.ZodOptional<z.ZodString>;
272
+ profileDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
273
+ }, z.core.$strict>;
274
+ provider: z.ZodString;
275
+ environmentId: z.ZodString;
276
+ sessionId: z.ZodString;
277
+ sessionCreatedForOperationId: z.ZodString;
278
+ sessionCreatedAt: z.ZodISODateTime;
279
+ transferredMessageIds: z.ZodArray<z.ZodString>;
280
+ omittedMessageIds: z.ZodArray<z.ZodString>;
281
+ admittedAt: z.ZodISODateTime;
282
+ }, z.core.$strict>, z.ZodObject<{
283
+ status: z.ZodLiteral<"accepted" | "replayed">;
284
+ operationId: z.ZodString;
285
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
286
+ planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
287
+ contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
288
+ destination: z.ZodObject<{
289
+ runner: z.ZodString;
290
+ provider: z.ZodOptional<z.ZodString>;
291
+ model: z.ZodOptional<z.ZodString>;
292
+ profileDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
293
+ }, z.core.$strict>;
294
+ provider: z.ZodString;
295
+ environmentId: z.ZodString;
296
+ sessionId: z.ZodString;
297
+ sessionCreatedForOperationId: z.ZodString;
298
+ sessionCreatedAt: z.ZodISODateTime;
299
+ transferredMessageIds: z.ZodArray<z.ZodString>;
300
+ omittedMessageIds: z.ZodArray<z.ZodString>;
301
+ admittedAt: z.ZodISODateTime;
302
+ }, z.core.$strict>], "status">>;
303
+ }, z.core.$strict>;
304
+ /** Durable provider result for one digest-bound native continuation operation. */
305
+ export declare const AgentNativeContextContinuationResultSchema: z.ZodUnion<readonly [z.ZodObject<{
306
+ acknowledgement: z.ZodIntersection<z.ZodObject<{
307
+ operationId: z.ZodString;
308
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
309
+ status: z.ZodEnum<{
310
+ conflict: "conflict";
311
+ accepted: "accepted";
312
+ transport_failure: "transport_failure";
313
+ replayed: "replayed";
314
+ boundary_mismatch: "boundary_mismatch";
315
+ unverified: "unverified";
316
+ unknown_session: "unknown_session";
317
+ }>;
318
+ historyMessagesSent: z.ZodNumber;
319
+ existingRequestDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
320
+ actualBoundary: z.ZodOptional<z.ZodObject<{
321
+ runId: z.ZodString;
322
+ provider: z.ZodString;
323
+ environmentId: z.ZodString;
324
+ sessionId: z.ZodString;
325
+ boundary: z.ZodDiscriminatedUnion<[z.ZodObject<{
326
+ kind: z.ZodLiteral<"token">;
327
+ token: z.ZodString;
328
+ }, z.core.$strict>, z.ZodObject<{
329
+ kind: z.ZodLiteral<"revision">;
330
+ revision: z.ZodString;
331
+ }, z.core.$strict>, z.ZodObject<{
332
+ kind: z.ZodLiteral<"digest">;
333
+ digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
334
+ }, z.core.$strict>, z.ZodObject<{
335
+ kind: z.ZodLiteral<"messages">;
336
+ messageIds: z.ZodArray<z.ZodString>;
337
+ digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
338
+ }, z.core.$strict>], "kind">;
339
+ observedAt: z.ZodISODateTime;
340
+ }, z.core.$strict>>;
341
+ message: z.ZodOptional<z.ZodString>;
342
+ retryable: z.ZodOptional<z.ZodBoolean>;
343
+ }, z.core.$strict>, z.ZodObject<{
344
+ status: z.ZodEnum<{
345
+ accepted: "accepted";
346
+ replayed: "replayed";
347
+ }>;
348
+ }, z.core.$strip>>;
349
+ result: z.ZodObject<{
350
+ text: z.ZodString;
351
+ success: z.ZodBoolean;
352
+ error: z.ZodOptional<z.ZodString>;
353
+ sessionId: z.ZodOptional<z.ZodString>;
354
+ usage: z.ZodOptional<z.ZodObject<{
355
+ inputTokens: z.ZodNumber;
356
+ outputTokens: z.ZodNumber;
357
+ totalTokens: z.ZodOptional<z.ZodNumber>;
358
+ cacheReadInputTokens: z.ZodOptional<z.ZodNumber>;
359
+ cacheCreationInputTokens: z.ZodOptional<z.ZodNumber>;
360
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
361
+ cost: z.ZodOptional<z.ZodNumber>;
362
+ }, z.core.$strict>>;
363
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
364
+ events: z.ZodOptional<z.ZodArray<z.ZodObject<{
365
+ type: z.ZodString;
366
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
367
+ id: z.ZodOptional<z.ZodString>;
368
+ normalized: z.ZodOptional<z.ZodType<StreamEvent, unknown, z.core.$ZodTypeInternals<StreamEvent, unknown>>>;
369
+ usage: z.ZodOptional<z.ZodObject<{
370
+ inputTokens: z.ZodNumber;
371
+ outputTokens: z.ZodNumber;
372
+ totalTokens: z.ZodOptional<z.ZodNumber>;
373
+ cacheReadInputTokens: z.ZodOptional<z.ZodNumber>;
374
+ cacheCreationInputTokens: z.ZodOptional<z.ZodNumber>;
375
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
376
+ cost: z.ZodOptional<z.ZodNumber>;
377
+ }, z.core.$strict>>;
378
+ providerEvent: z.ZodOptional<z.ZodUnknown>;
379
+ }, z.core.$strict>>>;
380
+ contextTransferReceipt: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
381
+ status: z.ZodLiteral<"accepted" | "replayed">;
382
+ operationId: z.ZodString;
383
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
384
+ planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
385
+ contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
386
+ destination: z.ZodObject<{
387
+ runner: z.ZodString;
388
+ provider: z.ZodOptional<z.ZodString>;
389
+ model: z.ZodOptional<z.ZodString>;
390
+ profileDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
391
+ }, z.core.$strict>;
392
+ provider: z.ZodString;
393
+ environmentId: z.ZodString;
394
+ sessionId: z.ZodString;
395
+ sessionCreatedForOperationId: z.ZodString;
396
+ sessionCreatedAt: z.ZodISODateTime;
397
+ transferredMessageIds: z.ZodArray<z.ZodString>;
398
+ omittedMessageIds: z.ZodArray<z.ZodString>;
399
+ admittedAt: z.ZodISODateTime;
400
+ }, z.core.$strict>, z.ZodObject<{
401
+ status: z.ZodLiteral<"accepted" | "replayed">;
402
+ operationId: z.ZodString;
403
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
404
+ planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
405
+ contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
406
+ destination: z.ZodObject<{
407
+ runner: z.ZodString;
408
+ provider: z.ZodOptional<z.ZodString>;
409
+ model: z.ZodOptional<z.ZodString>;
410
+ profileDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
411
+ }, z.core.$strict>;
412
+ provider: z.ZodString;
413
+ environmentId: z.ZodString;
414
+ sessionId: z.ZodString;
415
+ sessionCreatedForOperationId: z.ZodString;
416
+ sessionCreatedAt: z.ZodISODateTime;
417
+ transferredMessageIds: z.ZodArray<z.ZodString>;
418
+ omittedMessageIds: z.ZodArray<z.ZodString>;
419
+ admittedAt: z.ZodISODateTime;
420
+ }, z.core.$strict>], "status">>;
421
+ }, z.core.$strict>;
422
+ controlRef: z.ZodObject<{
423
+ runId: z.ZodString;
424
+ provider: z.ZodString;
425
+ environmentId: z.ZodString;
426
+ sessionId: z.ZodOptional<z.ZodString>;
427
+ executionId: z.ZodOptional<z.ZodString>;
428
+ }, z.core.$strict>;
429
+ }, z.core.$strict>, z.ZodObject<{
430
+ acknowledgement: z.ZodIntersection<z.ZodObject<{
431
+ operationId: z.ZodString;
432
+ requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
433
+ status: z.ZodEnum<{
434
+ conflict: "conflict";
435
+ accepted: "accepted";
436
+ transport_failure: "transport_failure";
437
+ replayed: "replayed";
438
+ boundary_mismatch: "boundary_mismatch";
439
+ unverified: "unverified";
440
+ unknown_session: "unknown_session";
441
+ }>;
442
+ historyMessagesSent: z.ZodNumber;
443
+ existingRequestDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
444
+ actualBoundary: z.ZodOptional<z.ZodObject<{
445
+ runId: z.ZodString;
446
+ provider: z.ZodString;
447
+ environmentId: z.ZodString;
448
+ sessionId: z.ZodString;
449
+ boundary: z.ZodDiscriminatedUnion<[z.ZodObject<{
450
+ kind: z.ZodLiteral<"token">;
451
+ token: z.ZodString;
452
+ }, z.core.$strict>, z.ZodObject<{
453
+ kind: z.ZodLiteral<"revision">;
454
+ revision: z.ZodString;
455
+ }, z.core.$strict>, z.ZodObject<{
456
+ kind: z.ZodLiteral<"digest">;
457
+ digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
458
+ }, z.core.$strict>, z.ZodObject<{
459
+ kind: z.ZodLiteral<"messages">;
460
+ messageIds: z.ZodArray<z.ZodString>;
461
+ digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
462
+ }, z.core.$strict>], "kind">;
463
+ observedAt: z.ZodISODateTime;
464
+ }, z.core.$strict>>;
465
+ message: z.ZodOptional<z.ZodString>;
466
+ retryable: z.ZodOptional<z.ZodBoolean>;
467
+ }, z.core.$strict>, z.ZodObject<{
468
+ status: z.ZodEnum<{
469
+ conflict: "conflict";
470
+ transport_failure: "transport_failure";
471
+ boundary_mismatch: "boundary_mismatch";
472
+ unverified: "unverified";
473
+ unknown_session: "unknown_session";
474
+ }>;
475
+ }, z.core.$strip>>;
476
+ }, z.core.$strict>]>;
477
+ export type AgentNativeContextContinuationResult = z.infer<typeof AgentNativeContextContinuationResultSchema>;
478
+ /** Runtime-only controls kept outside the digest-bound user turn. */
479
+ export interface AgentNativeContextContinuationOptions {
480
+ turn: NativeContextContinuationTurn;
481
+ timeoutMs?: number;
482
+ signal?: AbortSignal;
483
+ }
484
+ /** Cross-check a successful result against its exact request and retained session. */
485
+ export declare function agentNativeContextContinuationResultMatchesRequest(request: NativeContextContinuationRequest, outcome: AgentNativeContextContinuationResult): boolean;
218
486
  export interface AgentSessionRef {
219
487
  id: string;
220
488
  provider?: string;
489
+ controlRef?: AgentRunControlRef;
490
+ contextTransferReceipt?: ContextTransferReceipt;
221
491
  metadata?: Record<string, unknown>;
222
492
  }
223
493
  export interface AgentEnvironmentEvent {
@@ -230,13 +500,29 @@ export interface AgentEnvironmentEvent {
230
500
  }
231
501
  export interface AgentSession {
232
502
  readonly id: string;
503
+ readonly controlRef?: AgentRunControlRef;
233
504
  status(): Promise<AgentSessionStatus | null>;
234
505
  events(options?: {
506
+ /** Exclusive stable event id previously emitted by this session. */
235
507
  since?: string;
508
+ /** Provider execution selected by the durable control reference, when required. */
509
+ executionId?: string;
236
510
  signal?: AbortSignal;
237
511
  }): AsyncIterable<AgentEnvironmentEvent>;
238
512
  result(): Promise<AgentTurnResult>;
239
513
  prompt(input: AgentTurnInput): Promise<AgentTurnResult>;
514
+ respondToInteraction?(command: InteractionResponseCommand, options?: {
515
+ signal?: AbortSignal;
516
+ }): Promise<InteractionAcknowledgement>;
517
+ contextBoundary?(options?: {
518
+ signal?: AbortSignal;
519
+ }): Promise<NativeContextBoundaryProof | null>;
520
+ /**
521
+ * Atomically verify the boundary and admit one digest-bound continuation.
522
+ * Repeating an operation id with the same request returns the original result;
523
+ * repeating it with a different request returns a conflict without dispatch.
524
+ */
525
+ continueNative?(request: NativeContextContinuationRequest, options: AgentNativeContextContinuationOptions): Promise<AgentNativeContextContinuationResult>;
240
526
  cancel(): Promise<void>;
241
527
  }
242
528
  export interface AgentEnvironment {
@@ -246,7 +532,12 @@ export interface AgentEnvironment {
246
532
  status(): Promise<AgentEnvironmentStatus>;
247
533
  stream(input: AgentTurnInput): AsyncIterable<AgentEnvironmentEvent>;
248
534
  dispatch?(input: AgentTurnInput): Promise<AgentSessionRef>;
249
- session?(id: string): AgentSession;
535
+ session?(id: string, options?: {
536
+ controlRef?: AgentRunControlRef;
537
+ }): AgentSession;
538
+ respondToInteraction?(command: InteractionResponseCommand, options?: {
539
+ signal?: AbortSignal;
540
+ }): Promise<InteractionAcknowledgement>;
250
541
  read?(path: string, options?: {
251
542
  sessionId?: string;
252
543
  }): Promise<string>;
@@ -256,6 +547,8 @@ export interface AgentEnvironment {
256
547
  exec?(command: string, options?: ExecRequest): Promise<ExecResult>;
257
548
  checkpoint?(options?: CheckpointRequest): Promise<CheckpointRef>;
258
549
  fork?(checkpoint: CheckpointRef, options?: ForkRequest): Promise<AgentEnvironment>;
550
+ /** Durable, retry-safe checkpoint and environment-fork operations. */
551
+ readonly workspaceBranching?: AgentWorkspaceBranching;
259
552
  placement?(): Promise<PlacementInfo>;
260
553
  refresh?(): Promise<void>;
261
554
  destroy?(): Promise<void>;
@@ -273,6 +566,15 @@ export interface AgentEnvironmentCapabilities {
273
566
  list: boolean;
274
567
  messages: boolean;
275
568
  };
569
+ /** Absent when verified, retry-safe same-session continuation is unsupported. */
570
+ nativeContinuation?: {
571
+ /** Boundary comparison and operation admission are one atomic provider action. */
572
+ atomicBoundary: boolean;
573
+ /** Operation id + request digest recover retries and reject changed input. */
574
+ requestIdempotency: boolean;
575
+ };
576
+ /** Absent when the provider cannot originate or answer interactions. */
577
+ interactions?: InteractionCapabilities;
276
578
  workspace: {
277
579
  read: boolean;
278
580
  write: boolean;
@@ -284,6 +586,12 @@ export interface AgentEnvironmentCapabilities {
284
586
  branching: {
285
587
  checkpoint: boolean;
286
588
  fork: boolean;
589
+ /** True only when key + canonical request digest semantics are implemented. */
590
+ retrySafe?: boolean;
591
+ /** True only when operations can be recovered by idempotency key. */
592
+ lookup?: boolean;
593
+ /** True only when checkpoints and forked environments have confirmed cleanup. */
594
+ cleanup?: boolean;
287
595
  };
288
596
  placement: boolean;
289
597
  usage: boolean;
@@ -293,6 +601,89 @@ export interface AgentEnvironmentCapabilities {
293
601
  egress: readonly AgentExactProcessEgressMode[];
294
602
  };
295
603
  }
604
+ /** Strict runtime validator for provider capability negotiation. */
605
+ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
606
+ profile: z.ZodObject<{
607
+ namedProfiles: z.ZodBoolean;
608
+ systemPrompt: z.ZodBoolean;
609
+ instructions: z.ZodBoolean;
610
+ tools: z.ZodBoolean;
611
+ permissions: z.ZodBoolean;
612
+ mcp: z.ZodBoolean;
613
+ subagents: z.ZodBoolean;
614
+ resources: z.ZodObject<{
615
+ files: z.ZodBoolean;
616
+ instructions: z.ZodBoolean;
617
+ tools: z.ZodOptional<z.ZodBoolean>;
618
+ skills: z.ZodOptional<z.ZodBoolean>;
619
+ agents: z.ZodOptional<z.ZodBoolean>;
620
+ commands: z.ZodOptional<z.ZodBoolean>;
621
+ }, z.core.$strict>;
622
+ hooks: z.ZodOptional<z.ZodBoolean>;
623
+ modes: z.ZodOptional<z.ZodBoolean>;
624
+ runtimeUpdate: z.ZodBoolean;
625
+ validation: z.ZodBoolean;
626
+ extensions: z.ZodOptional<z.ZodArray<z.ZodString>>;
627
+ }, z.core.$strict>;
628
+ streaming: z.ZodObject<{
629
+ live: z.ZodBoolean;
630
+ replay: z.ZodBoolean;
631
+ detach: z.ZodBoolean;
632
+ turnIdempotency: z.ZodBoolean;
633
+ }, z.core.$strict>;
634
+ sessions: z.ZodObject<{
635
+ continue: z.ZodBoolean;
636
+ list: z.ZodBoolean;
637
+ messages: z.ZodBoolean;
638
+ }, z.core.$strict>;
639
+ nativeContinuation: z.ZodOptional<z.ZodObject<{
640
+ atomicBoundary: z.ZodBoolean;
641
+ requestIdempotency: z.ZodBoolean;
642
+ }, z.core.$strict>>;
643
+ interactions: z.ZodOptional<z.ZodObject<{
644
+ kinds: z.ZodArray<z.ZodString>;
645
+ answerFieldTypes: z.ZodArray<z.ZodEnum<{
646
+ number: "number";
647
+ boolean: "boolean";
648
+ text: "text";
649
+ select: "select";
650
+ secret: "secret";
651
+ }>>;
652
+ responseScopes: z.ZodArray<z.ZodEnum<{
653
+ interaction: "interaction";
654
+ session: "session";
655
+ persistent: "persistent";
656
+ }>>;
657
+ secretAnswers: z.ZodBoolean;
658
+ concurrentRequests: z.ZodBoolean;
659
+ replay: z.ZodBoolean;
660
+ responseIdempotency: z.ZodBoolean;
661
+ }, z.core.$strict>>;
662
+ workspace: z.ZodObject<{
663
+ read: z.ZodBoolean;
664
+ write: z.ZodBoolean;
665
+ exec: z.ZodBoolean;
666
+ git: z.ZodBoolean;
667
+ upload: z.ZodBoolean;
668
+ download: z.ZodBoolean;
669
+ }, z.core.$strict>;
670
+ branching: z.ZodObject<{
671
+ checkpoint: z.ZodBoolean;
672
+ fork: z.ZodBoolean;
673
+ retrySafe: z.ZodOptional<z.ZodBoolean>;
674
+ lookup: z.ZodOptional<z.ZodBoolean>;
675
+ cleanup: z.ZodOptional<z.ZodBoolean>;
676
+ }, z.core.$strict>;
677
+ placement: z.ZodBoolean;
678
+ usage: z.ZodBoolean;
679
+ confidential: z.ZodBoolean;
680
+ exactProcess: z.ZodOptional<z.ZodObject<{
681
+ egress: z.ZodArray<z.ZodEnum<{
682
+ blocked: "blocked";
683
+ strict: "strict";
684
+ }>>;
685
+ }, z.core.$strict>>;
686
+ }, z.core.$strict>;
296
687
  export interface CreateAgentEnvironmentInput {
297
688
  profile: AgentProfileRef;
298
689
  /** Agent backend inside the provider, for example "opencode" or "codex". */
@@ -1 +1,214 @@
1
- export {};
1
+ import { z } from "zod";
2
+ import { InteractionCapabilitiesSchema, } from "./interaction.js";
3
+ /*
4
+ * Keep the provider contract runtime-validatable. Provider capability data is
5
+ * commonly read from a remote service or adapter configuration, so its static
6
+ * TypeScript type is not a trust boundary.
7
+ */
8
+ const AgentProfileCapabilitiesSchema = z.strictObject({
9
+ namedProfiles: z.boolean(),
10
+ systemPrompt: z.boolean(),
11
+ instructions: z.boolean(),
12
+ tools: z.boolean(),
13
+ permissions: z.boolean(),
14
+ mcp: z.boolean(),
15
+ subagents: z.boolean(),
16
+ resources: z.strictObject({
17
+ files: z.boolean(),
18
+ instructions: z.boolean(),
19
+ tools: z.boolean().optional(),
20
+ skills: z.boolean().optional(),
21
+ agents: z.boolean().optional(),
22
+ commands: z.boolean().optional(),
23
+ }),
24
+ hooks: z.boolean().optional(),
25
+ modes: z.boolean().optional(),
26
+ runtimeUpdate: z.boolean(),
27
+ validation: z.boolean(),
28
+ extensions: z.array(z.string().min(1)).optional(),
29
+ });
30
+ import { ContextTransferReceiptSchema, NativeContextContinuationAcknowledgementSchema, NativeContextContinuationRequestSchema, nativeContextContinuationAcknowledgementMatches, } from "./portable-context.js";
31
+ import { AgentRunControlRefSchema, CanonicalStreamEventSchema, } from "./runtime-control.js";
32
+ const TokenUsageSchema = z.strictObject({
33
+ inputTokens: z.number().int().nonnegative(),
34
+ outputTokens: z.number().int().nonnegative(),
35
+ totalTokens: z.number().int().nonnegative().optional(),
36
+ cacheReadInputTokens: z.number().int().nonnegative().optional(),
37
+ cacheCreationInputTokens: z.number().int().nonnegative().optional(),
38
+ reasoningTokens: z.number().int().nonnegative().optional(),
39
+ cost: z.number().finite().nonnegative().optional(),
40
+ });
41
+ const AgentEnvironmentEventSchema = z.strictObject({
42
+ type: z.string().min(1),
43
+ data: z.record(z.string(), z.unknown()),
44
+ id: z.string().min(1).optional(),
45
+ normalized: CanonicalStreamEventSchema.optional(),
46
+ usage: TokenUsageSchema.optional(),
47
+ providerEvent: z.unknown().optional(),
48
+ });
49
+ /** Runtime validator for a provider turn returned from durable continuation. */
50
+ export const AgentTurnResultSchema = z.strictObject({
51
+ text: z.string(),
52
+ success: z.boolean(),
53
+ error: z.string().optional(),
54
+ sessionId: z.string().min(1).optional(),
55
+ usage: TokenUsageSchema.optional(),
56
+ metadata: z.record(z.string(), z.unknown()).optional(),
57
+ events: z.array(AgentEnvironmentEventSchema).optional(),
58
+ contextTransferReceipt: ContextTransferReceiptSchema.optional(),
59
+ });
60
+ /** Durable provider result for one digest-bound native continuation operation. */
61
+ export const AgentNativeContextContinuationResultSchema = z.union([
62
+ z
63
+ .strictObject({
64
+ acknowledgement: NativeContextContinuationAcknowledgementSchema.and(z.object({ status: z.enum(["accepted", "replayed"]) })),
65
+ result: AgentTurnResultSchema,
66
+ /** Exact provider coordinates after the continuation completed. */
67
+ controlRef: AgentRunControlRefSchema,
68
+ })
69
+ .superRefine((outcome, refinement) => {
70
+ if (outcome.result.contextTransferReceipt !== undefined) {
71
+ refinement.addIssue({
72
+ code: "custom",
73
+ path: ["result", "contextTransferReceipt"],
74
+ message: "native continuation cannot return a context transfer receipt",
75
+ });
76
+ }
77
+ }),
78
+ z
79
+ .strictObject({
80
+ acknowledgement: NativeContextContinuationAcknowledgementSchema.and(z.object({
81
+ status: z.enum([
82
+ "conflict",
83
+ "boundary_mismatch",
84
+ "unverified",
85
+ "unknown_session",
86
+ "transport_failure",
87
+ ]),
88
+ })),
89
+ })
90
+ .superRefine((outcome, refinement) => {
91
+ if (outcome.acknowledgement.status === "transport_failure" &&
92
+ outcome.acknowledgement.retryable !== true) {
93
+ refinement.addIssue({
94
+ code: "custom",
95
+ path: ["acknowledgement", "retryable"],
96
+ message: "a durable native continuation transport failure must be retryable",
97
+ });
98
+ }
99
+ }),
100
+ ]);
101
+ /** Cross-check a successful result against its exact request and retained session. */
102
+ export function agentNativeContextContinuationResultMatchesRequest(request, outcome) {
103
+ const parsedRequest = NativeContextContinuationRequestSchema.safeParse(request);
104
+ const parsedOutcome = AgentNativeContextContinuationResultSchema.safeParse(outcome);
105
+ if (!parsedRequest.success || !parsedOutcome.success)
106
+ return false;
107
+ const exactOutcome = parsedOutcome.data;
108
+ if (exactOutcome.acknowledgement.status !== "accepted" &&
109
+ exactOutcome.acknowledgement.status !== "replayed") {
110
+ return false;
111
+ }
112
+ if (!("result" in exactOutcome) || !("controlRef" in exactOutcome)) {
113
+ return false;
114
+ }
115
+ if (!nativeContextContinuationAcknowledgementMatches(parsedRequest.data, exactOutcome.acknowledgement)) {
116
+ return false;
117
+ }
118
+ const source = parsedRequest.data.run;
119
+ const current = exactOutcome.controlRef;
120
+ return (current.provider === source.provider &&
121
+ current.environmentId === source.environmentId &&
122
+ current.sessionId === source.sessionId &&
123
+ (exactOutcome.result.sessionId === undefined ||
124
+ exactOutcome.result.sessionId === current.sessionId));
125
+ }
126
+ /** Strict runtime validator for provider capability negotiation. */
127
+ export const AgentEnvironmentCapabilitiesSchema = z
128
+ .strictObject({
129
+ profile: AgentProfileCapabilitiesSchema,
130
+ streaming: z.strictObject({
131
+ live: z.boolean(),
132
+ replay: z.boolean(),
133
+ detach: z.boolean(),
134
+ turnIdempotency: z.boolean(),
135
+ }),
136
+ sessions: z.strictObject({
137
+ continue: z.boolean(),
138
+ list: z.boolean(),
139
+ messages: z.boolean(),
140
+ }),
141
+ nativeContinuation: z
142
+ .strictObject({
143
+ atomicBoundary: z.boolean(),
144
+ requestIdempotency: z.boolean(),
145
+ })
146
+ .optional(),
147
+ interactions: InteractionCapabilitiesSchema.optional(),
148
+ workspace: z.strictObject({
149
+ read: z.boolean(),
150
+ write: z.boolean(),
151
+ exec: z.boolean(),
152
+ git: z.boolean(),
153
+ upload: z.boolean(),
154
+ download: z.boolean(),
155
+ }),
156
+ branching: z.strictObject({
157
+ checkpoint: z.boolean(),
158
+ fork: z.boolean(),
159
+ retrySafe: z.boolean().optional(),
160
+ lookup: z.boolean().optional(),
161
+ cleanup: z.boolean().optional(),
162
+ }),
163
+ placement: z.boolean(),
164
+ usage: z.boolean(),
165
+ confidential: z.boolean(),
166
+ exactProcess: z
167
+ .strictObject({
168
+ egress: z.array(z.enum(["blocked", "strict"])).min(1),
169
+ })
170
+ .optional(),
171
+ })
172
+ .superRefine((capabilities, refinement) => {
173
+ if (capabilities.nativeContinuation !== undefined &&
174
+ (!capabilities.nativeContinuation.atomicBoundary ||
175
+ !capabilities.nativeContinuation.requestIdempotency ||
176
+ !capabilities.sessions.continue)) {
177
+ refinement.addIssue({
178
+ code: "custom",
179
+ path: ["nativeContinuation"],
180
+ message: "native continuation requires session continuation, atomic boundary admission, and request idempotency together",
181
+ });
182
+ }
183
+ const durableBranching = [
184
+ capabilities.branching.retrySafe ?? false,
185
+ capabilities.branching.lookup ?? false,
186
+ capabilities.branching.cleanup ?? false,
187
+ ];
188
+ if (durableBranching.some(Boolean) &&
189
+ (!durableBranching.every(Boolean) ||
190
+ !capabilities.branching.checkpoint ||
191
+ !capabilities.branching.fork)) {
192
+ refinement.addIssue({
193
+ code: "custom",
194
+ path: ["branching"],
195
+ message: "retry-safe branching requires checkpoint, fork, lookup, and cleanup together",
196
+ });
197
+ }
198
+ const egress = capabilities.exactProcess?.egress;
199
+ if (egress && new Set(egress).size !== egress.length) {
200
+ refinement.addIssue({
201
+ code: "custom",
202
+ path: ["exactProcess", "egress"],
203
+ message: "exact process egress modes must be unique",
204
+ });
205
+ }
206
+ const extensions = capabilities.profile.extensions;
207
+ if (extensions && new Set(extensions).size !== extensions.length) {
208
+ refinement.addIssue({
209
+ code: "custom",
210
+ path: ["profile", "extensions"],
211
+ message: "profile extension namespaces must be unique",
212
+ });
213
+ }
214
+ });