@opengeni/contracts 0.18.0 → 0.19.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.
package/src/index.ts CHANGED
@@ -468,6 +468,8 @@ export const ErrorCode = z.enum([
468
468
  "conflict",
469
469
  "idempotency_conflict",
470
470
  "limit_exceeded",
471
+ "nested_agent_depth_exceeded",
472
+ "nested_agent_depth_override_forbidden",
471
473
  "provider_verification_failed",
472
474
  "upstream_unavailable",
473
475
  "internal_error",
@@ -484,6 +486,45 @@ export const ErrorEnvelope = z.object({
484
486
  });
485
487
  export type ErrorEnvelope = z.infer<typeof ErrorEnvelope>;
486
488
 
489
+ /** Physical ceiling of the PostgreSQL integer columns that persist depth policy. */
490
+ export const MAX_NESTED_AGENT_DEPTH = 2_147_483_647;
491
+ export const NestedAgentDepthValue = z.number().int().nonnegative().max(MAX_NESTED_AGENT_DEPTH);
492
+ export type NestedAgentDepthValue = z.infer<typeof NestedAgentDepthValue>;
493
+ /** A denied child can be one greater than the persisted PostgreSQL int ceiling. */
494
+ export const NestedAgentDepthAttemptValue = z
495
+ .number()
496
+ .int()
497
+ .nonnegative()
498
+ .max(MAX_NESTED_AGENT_DEPTH + 1);
499
+
500
+ export const NestedAgentDepthPolicySource = z.enum([
501
+ "session",
502
+ "workspace",
503
+ "deployment",
504
+ "default",
505
+ ]);
506
+ export type NestedAgentDepthPolicySource = z.infer<typeof NestedAgentDepthPolicySource>;
507
+
508
+ /** Durable evidence for a session-create denial at the database admission boundary. */
509
+ export const SessionSpawnDenial = z.object({
510
+ id: z.string().uuid(),
511
+ accountId: z.string().uuid(),
512
+ workspaceId: z.string().uuid(),
513
+ parentSessionId: z.string().uuid().nullable(),
514
+ rootSessionId: z.string().uuid().nullable(),
515
+ currentDepth: NestedAgentDepthValue,
516
+ attemptedDepth: NestedAgentDepthAttemptValue,
517
+ effectiveMaxNestedAgentDepth: NestedAgentDepthValue,
518
+ requestedMaxNestedAgentDepthOverride: NestedAgentDepthValue.nullable(),
519
+ policySource: NestedAgentDepthPolicySource,
520
+ policySessionId: z.string().uuid().nullable(),
521
+ subjectId: z.string().nullable(),
522
+ code: z.enum(["nested_agent_depth_exceeded", "nested_agent_depth_override_forbidden"]),
523
+ idempotencyKey: z.string().nullable(),
524
+ createdAt: z.string(),
525
+ });
526
+ export type SessionSpawnDenial = z.infer<typeof SessionSpawnDenial>;
527
+
487
528
  export const Permission = z.enum([
488
529
  "account:read",
489
530
  "account:admin",
@@ -934,6 +975,9 @@ export const WorkspaceSettingsSchema = z
934
975
  .object({
935
976
  memoryEnabled: z.boolean().optional(),
936
977
  transcription: WorkspaceTranscriptionPolicy.optional(),
978
+ // null clears the workspace override and falls back to the persisted
979
+ // deployment policy. The database boundary validates the same range.
980
+ maxNestedAgentDepth: NestedAgentDepthValue.nullable().optional(),
937
981
  })
938
982
  .passthrough();
939
983
  export type WorkspaceSettings = z.infer<typeof WorkspaceSettingsSchema>;
@@ -951,6 +995,7 @@ export const UpdateWorkspaceSettingsRequest = z
951
995
  .object({
952
996
  memoryEnabled: z.boolean().optional(),
953
997
  transcription: WorkspaceTranscriptionPolicy.optional(),
998
+ maxNestedAgentDepth: NestedAgentDepthValue.nullable().optional(),
954
999
  })
955
1000
  .passthrough();
956
1001
  export type UpdateWorkspaceSettingsRequest = z.infer<typeof UpdateWorkspaceSettingsRequest>;
@@ -3011,6 +3056,41 @@ export const SessionGoalPausedReason = z.enum([
3011
3056
  ]);
3012
3057
  export type SessionGoalPausedReason = z.infer<typeof SessionGoalPausedReason>;
3013
3058
 
3059
+ export const SessionGoalContinuationState = z.enum([
3060
+ "inactive",
3061
+ "scheduled",
3062
+ "running",
3063
+ "blocked",
3064
+ "invariant_broken",
3065
+ ]);
3066
+ export type SessionGoalContinuationState = z.infer<typeof SessionGoalContinuationState>;
3067
+
3068
+ export const SessionGoalContinuationReason = z.enum([
3069
+ "goal_inactive",
3070
+ "wake_pending",
3071
+ "continuation_pending",
3072
+ "human_work_pending",
3073
+ "goal_turn_running",
3074
+ "human_turn_running",
3075
+ "workstream_paused",
3076
+ "approval_required",
3077
+ "provider_backpressure",
3078
+ "session_cancelled",
3079
+ "system_work_pending",
3080
+ "missing_obligation",
3081
+ ]);
3082
+ export type SessionGoalContinuationReason = z.infer<typeof SessionGoalContinuationReason>;
3083
+
3084
+ export const SessionGoalContinuation = z.object({
3085
+ state: SessionGoalContinuationState,
3086
+ reason: SessionGoalContinuationReason,
3087
+ wakeRevision: z.number().int().nonnegative(),
3088
+ observedRevision: z.number().int().nonnegative(),
3089
+ nextAttemptAt: z.string().datetime({ offset: true }).nullable(),
3090
+ lastError: z.string().nullable(),
3091
+ });
3092
+ export type SessionGoalContinuation = z.infer<typeof SessionGoalContinuation>;
3093
+
3014
3094
  export const SessionGoal = z.object({
3015
3095
  id: z.string().uuid(),
3016
3096
  accountId: z.string().uuid(),
@@ -3028,6 +3108,9 @@ export const SessionGoal = z.object({
3028
3108
  noProgressStreak: z.number().int().nonnegative(),
3029
3109
  maxAutoContinuations: z.number().int().positive().nullable(),
3030
3110
  metadata: z.record(z.string(), z.unknown()),
3111
+ // Optional for source compatibility with older clients; the API always
3112
+ // supplies this authoritative continuation projection.
3113
+ continuation: SessionGoalContinuation.optional(),
3031
3114
  createdAt: z.string(),
3032
3115
  updatedAt: z.string(),
3033
3116
  });
@@ -3464,6 +3547,45 @@ export const SaveComposerDraftRequest = ComposerDraft.pick({
3464
3547
  }).extend({ expectedRevision: z.number().int().nonnegative() });
3465
3548
  export type SaveComposerDraftRequest = z.infer<typeof SaveComposerDraftRequest>;
3466
3549
 
3550
+ /**
3551
+ * Create-only options saved with an actor's private pre-session draft. This is
3552
+ * deliberately narrower than CreateSessionRequest: idempotency/event keys and
3553
+ * credential-bearing MCP server inputs are per-attempt data, never draft state.
3554
+ */
3555
+ export const NewSessionDraftOptions = z.object({
3556
+ sandboxBackend: SandboxBackend.optional(),
3557
+ targetSandboxId: z.string().uuid().optional(),
3558
+ workingDir: z.string().min(1).optional(),
3559
+ variableSetId: z.string().uuid().optional(),
3560
+ rigId: z.string().uuid().optional(),
3561
+ goal: GoalSpec.optional(),
3562
+ firstPartyMcpPermissions: z.array(Permission).optional(),
3563
+ });
3564
+ export type NewSessionDraftOptions = z.infer<typeof NewSessionDraftOptions>;
3565
+
3566
+ /** Actor-private, server-authoritative composer state before a session exists. */
3567
+ export const NewSessionDraft = z.object({
3568
+ revision: z.number().int().nonnegative(),
3569
+ text: z.string(),
3570
+ resources: z.array(ResourceRef),
3571
+ tools: z.array(ToolRef),
3572
+ model: z.string().min(1),
3573
+ reasoningEffort: ReasoningEffort,
3574
+ options: NewSessionDraftOptions,
3575
+ updatedAt: z.string().nullable(),
3576
+ });
3577
+ export type NewSessionDraft = z.infer<typeof NewSessionDraft>;
3578
+
3579
+ export const SaveNewSessionDraftRequest = NewSessionDraft.pick({
3580
+ text: true,
3581
+ resources: true,
3582
+ tools: true,
3583
+ model: true,
3584
+ reasoningEffort: true,
3585
+ options: true,
3586
+ }).extend({ expectedRevision: z.number().int().nonnegative() });
3587
+ export type SaveNewSessionDraftRequest = z.infer<typeof SaveNewSessionDraftRequest>;
3588
+
3467
3589
  export const WORKSPACE_CONTROL_REASON_MAX_BYTES = 8 * 1024;
3468
3590
  export const WORKSPACE_CONTROL_ACTOR_MAX_BYTES = 1024;
3469
3591
  export const WORKSPACE_CONTROL_EVENT_MAX_BYTES = 16 * 1024;
@@ -4037,6 +4159,9 @@ export const ScheduledTaskAgentConfig = z.object({
4037
4159
  reasoningEffort: ReasoningEffort.optional(),
4038
4160
  sandboxBackend: SandboxBackend.optional(),
4039
4161
  goal: GoalSpec.optional(),
4162
+ // Durable task override. Scheduled dispatch is trusted to preserve this
4163
+ // snapshot even if the workspace/deployment policy narrows later.
4164
+ maxNestedAgentDepth: NestedAgentDepthValue.optional(),
4040
4165
  });
4041
4166
  export type ScheduledTaskAgentConfig = z.infer<typeof ScheduledTaskAgentConfig>;
4042
4167
 
@@ -4772,6 +4897,14 @@ export const Session = z.object({
4772
4897
  // direct API creates and scheduled-task runs. When set, this session's
4773
4898
  // terminal-for-now transitions wake the parent.
4774
4899
  parentSessionId: z.string().uuid().nullable(),
4900
+ // Server-authored nested-agent lineage/policy. Root sessions are depth 0;
4901
+ // snapshots are immutable and govern only future descendant creation.
4902
+ rootSessionId: z.string().uuid(),
4903
+ nestedAgentDepth: NestedAgentDepthValue,
4904
+ maxNestedAgentDepthOverride: NestedAgentDepthValue.nullable(),
4905
+ effectiveMaxNestedAgentDepth: NestedAgentDepthValue,
4906
+ nestedAgentDepthPolicySource: NestedAgentDepthPolicySource,
4907
+ nestedAgentDepthPolicySessionId: z.string().uuid().nullable(),
4775
4908
  // Workspace-scoped CREATE idempotency key the session was created under (the
4776
4909
  // dedup target collapsing double-submit/retry races to one session); null
4777
4910
  // when the create carried no key.
@@ -4977,6 +5110,10 @@ export const SessionEventType = z.enum([
4977
5110
  // credential allocator per-turn selection audit. Payload is metadata only: credential row
4978
5111
  // id, bounded strategy/reason, and pool counts — never token material.
4979
5112
  "codex.credential.selected",
5113
+ // Adaptive fleet shadow decision record. Contains only bounded opaque candidate aliases,
5114
+ // normalized pressure/cache/confidence features, deterministic fingerprints,
5115
+ // the actual-vs-shadow comparison, and no credential/account identity.
5116
+ "codex.fleet.decision",
4980
5117
  // credential allocator durable zero-capacity wait lifecycle. Runtime/system events only;
4981
5118
  // no synthetic user message is created when capacity returns.
4982
5119
  "codex.capacity.waiting",
@@ -5446,7 +5583,7 @@ export type TerminalPtyOutputDeltaPayload = z.infer<typeof TerminalPtyOutputDelt
5446
5583
  export const TerminalPtyExitedPayload = z.object({
5447
5584
  ptyId: z.string().uuid(),
5448
5585
  exitCode: z.number().int().nullable(),
5449
- reason: z.enum(["exit", "killed", "owner_gone", "timeout"]),
5586
+ reason: z.enum(["exit", "killed", "owner_gone", "timeout", "lost"]),
5450
5587
  });
5451
5588
  export type TerminalPtyExitedPayload = z.infer<typeof TerminalPtyExitedPayload>;
5452
5589
 
@@ -5905,7 +6042,8 @@ export type GitShowResponse = z.infer<typeof GitShowResponse>;
5905
6042
  export const TerminalExecRequest = z.object({
5906
6043
  command: z.string().min(1),
5907
6044
  cwd: z.string().default(""), // workspace-relative
5908
- // Soft per-call wall-clock bound (the box yields output back when reached).
6045
+ // Hard wall-clock bound. A timeout response is returned only after the exact
6046
+ // provider process is physically absent and any retained admission settles.
5909
6047
  timeoutMs: z.number().int().positive().max(120_000).default(30_000),
5910
6048
  // Stream the deltas onto A1 as the agent firehose (so other viewers see it),
5911
6049
  // in addition to returning the buffered result inline.
@@ -5915,10 +6053,10 @@ export type TerminalExecRequest = z.infer<typeof TerminalExecRequest>;
5915
6053
  export const TerminalExecResponse = z.object({
5916
6054
  stdout: z.string(),
5917
6055
  stderr: z.string(),
5918
- exitCode: z.number().int().nullable(),
5919
- // True when the process was still running when the call yielded (a long
5920
- // command); the remaining output drains onto A1 if emitStream was set.
5921
- running: z.boolean(),
6056
+ exitCode: z.number().int(),
6057
+ // Retained for wire compatibility; synchronous exec never exposes a live
6058
+ // provider process. Interactive work uses the PTY API.
6059
+ running: z.literal(false),
5922
6060
  wallTimeSeconds: z.number().nonnegative(),
5923
6061
  });
5924
6062
  export type TerminalExecResponse = z.infer<typeof TerminalExecResponse>;
@@ -7015,6 +7153,14 @@ export const CreateSessionRequest = withVariableSetIdAlias({
7015
7153
  // creation of a brand-new session. Absent means no create-dedup (each call
7016
7154
  // is an independent create).
7017
7155
  idempotencyKey: z.string().min(1).max(200).optional(),
7156
+ // The exact actor-private pre-session draft revision represented by this
7157
+ // create. The durable initializer consumes only this revision. A newer draft
7158
+ // written by a sibling tab survives, while every failed pre-initialization
7159
+ // create leaves the submitted draft intact.
7160
+ expectedNewSessionDraftRevision: z.number().int().nonnegative().optional(),
7161
+ // A child may lower its inherited limit freely; an increase requires
7162
+ // workspace:admin and is checked again at the DB transaction boundary.
7163
+ maxNestedAgentDepth: NestedAgentDepthValue.optional(),
7018
7164
  // Permissions the session's first-party MCP token should carry. A top-level
7019
7165
  // omission uses the deployment's worker default; a child omission inherits
7020
7166
  // the creating session's effective grant. An explicit set is capped at
@@ -7397,6 +7543,9 @@ export const SessionCapabilities = z.object({
7397
7543
  liveness: z.enum(["cold", "warming", "warm", "draining"]),
7398
7544
  // Echoed on viewer heartbeats (the split-brain fence).
7399
7545
  leaseEpoch: z.number().int().nonnegative(),
7546
+ workspaceGeneration: z.number().int().nonnegative().nullable().default(null),
7547
+ archiveGeneration: z.number().int().nonnegative().nullable().default(null),
7548
+ archiveComplete: z.boolean().default(false),
7400
7549
  viewerHeartbeatIntervalMs: z.number().int().positive().default(30_000),
7401
7550
  FileSystem: z.object({
7402
7551
  available: z.boolean(),
@@ -7501,6 +7650,9 @@ export const ViewerHolder = z.object({
7501
7650
  liveness: z.enum(["cold", "warming", "warm", "draining"]),
7502
7651
  // The epoch the viewer is fenced on; echoed back on heartbeats.
7503
7652
  leaseEpoch: z.number().int().nonnegative(),
7653
+ workspaceGeneration: z.number().int().nonnegative().nullable(),
7654
+ archiveGeneration: z.number().int().nonnegative().nullable(),
7655
+ archiveComplete: z.boolean(),
7504
7656
  viewerHeartbeatIntervalMs: z.number().int().positive(),
7505
7657
  // The desktop pixel tunnel URL the viewer connects to directly; null until
7506
7658
  // a viewer grant is minted (gated until then).
@@ -7864,6 +8016,9 @@ export const MachineView = z.object({
7864
8016
  state: MachineState,
7865
8017
  active: z.boolean(),
7866
8018
  isSessionGroup: z.boolean(),
8019
+ workspaceGeneration: z.number().int().nonnegative().nullable(),
8020
+ archiveGeneration: z.number().int().nonnegative().nullable(),
8021
+ archiveComplete: z.boolean(),
7867
8022
  os: z.string(),
7868
8023
  arch: z.string(),
7869
8024
  hasDisplay: z.boolean(),
@@ -7923,6 +8078,9 @@ export const SwapActiveSandboxResponse = z.object({
7923
8078
  "unsupported_backend_context",
7924
8079
  "transient_establishment",
7925
8080
  "concurrent_swap",
8081
+ "recovery_in_progress",
8082
+ "recovery_degraded",
8083
+ "recovery_unrecoverable",
7926
8084
  ])
7927
8085
  .optional(),
7928
8086
  });
@@ -8434,3 +8592,5 @@ export function evaluateWorkspaceModelPolicy(
8434
8592
  }
8435
8593
  return { allowed: true };
8436
8594
  }
8595
+
8596
+ export * from "./codex-fleet-policy";