@opengeni/contracts 0.32.0 → 0.35.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.
@@ -6,6 +6,10 @@ export declare const WORKSPACE_STATE_MAX_GAPS = 16;
6
6
  export declare const WORKSPACE_STATE_BASE_NAME_MAX_CHARS = 160;
7
7
  export declare const WORKSPACE_STATE_TOPIC_MAX_CHARS = 96;
8
8
  export declare const WORKSPACE_STATE_MEMORY_SAMPLE_LIMIT = 100;
9
+ export declare const WorkspaceStateQuery: z.ZodObject<{
10
+ attemptId: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strict>;
12
+ export type WorkspaceStateQuery = z.infer<typeof WorkspaceStateQuery>;
9
13
  export declare const WorkspaceStateDocumentStatusCounts: z.ZodObject<{
10
14
  queued: z.ZodNumber;
11
15
  indexing: z.ZodNumber;
@@ -364,6 +368,118 @@ export declare const WorkspaceStateKnowledge: z.ZodDiscriminatedUnion<[z.ZodObje
364
368
  requiredPermission: z.ZodLiteral<"documents:search">;
365
369
  }, z.core.$strict>], "availability">;
366
370
  export type WorkspaceStateKnowledge = z.infer<typeof WorkspaceStateKnowledge>;
371
+ export declare const WorkspaceStateGovernanceDriftStatus: z.ZodEnum<{
372
+ changed: "changed";
373
+ identical: "identical";
374
+ missing: "missing";
375
+ superseded: "superseded";
376
+ truncated: "truncated";
377
+ unavailable: "unavailable";
378
+ }>;
379
+ export type WorkspaceStateGovernanceDriftStatus = z.infer<typeof WorkspaceStateGovernanceDriftStatus>;
380
+ export declare const WorkspaceStateAttemptGovernance: z.ZodDiscriminatedUnion<[z.ZodObject<{
381
+ status: z.ZodLiteral<"not_requested">;
382
+ }, z.core.$strict>, z.ZodObject<{
383
+ status: z.ZodLiteral<"unavailable">;
384
+ reason: z.ZodLiteral<"attempt_not_found_or_not_authorized">;
385
+ driftStatus: z.ZodLiteral<"unavailable">;
386
+ }, z.core.$strict>, z.ZodObject<{
387
+ status: z.ZodLiteral<"available">;
388
+ attemptId: z.ZodString;
389
+ executionGeneration: z.ZodNumber;
390
+ acceptedAt: z.ZodString;
391
+ policySnapshot: z.ZodDiscriminatedUnion<[z.ZodObject<{
392
+ status: z.ZodLiteral<"available">;
393
+ id: z.ZodString;
394
+ createdAt: z.ZodString;
395
+ entryHash: z.ZodString;
396
+ policyRole: z.ZodNullable<z.ZodString>;
397
+ roleSource: z.ZodEnum<{
398
+ invalid_metadata_fallback: "invalid_metadata_fallback";
399
+ metadata_fallback: "metadata_fallback";
400
+ none: "none";
401
+ session_binding: "session_binding";
402
+ }>;
403
+ entries: z.ZodArray<z.ZodObject<{
404
+ kind: z.ZodEnum<{
405
+ charter: "charter";
406
+ policy: "policy";
407
+ }>;
408
+ scope: z.ZodEnum<{
409
+ global: "global";
410
+ role: "role";
411
+ }>;
412
+ roleKey: z.ZodNullable<z.ZodString>;
413
+ revisionId: z.ZodString;
414
+ revision: z.ZodNumber;
415
+ contentHash: z.ZodString;
416
+ activationVersion: z.ZodNumber;
417
+ activatedAt: z.ZodString;
418
+ provenance: z.ZodObject<{
419
+ source: z.ZodEnum<{
420
+ human: "human";
421
+ knowledge_proposal: "knowledge_proposal";
422
+ legacy_import: "legacy_import";
423
+ onboarding: "onboarding";
424
+ }>;
425
+ sourceIdHash: z.ZodNullable<z.ZodString>;
426
+ }, z.core.$strip>;
427
+ }, z.core.$strip>>;
428
+ }, z.core.$strict>, z.ZodObject<{
429
+ status: z.ZodLiteral<"missing">;
430
+ }, z.core.$strict>], "status">;
431
+ preferenceSnapshot: z.ZodDiscriminatedUnion<[z.ZodObject<{
432
+ status: z.ZodLiteral<"available">;
433
+ id: z.ZodString;
434
+ createdAt: z.ZodString;
435
+ descriptorHash: z.ZodString;
436
+ descriptorCount: z.ZodNumber;
437
+ truncated: z.ZodBoolean;
438
+ }, z.core.$strict>, z.ZodObject<{
439
+ status: z.ZodLiteral<"missing">;
440
+ }, z.core.$strict>], "status">;
441
+ drift: z.ZodObject<{
442
+ overall: z.ZodEnum<{
443
+ changed: "changed";
444
+ identical: "identical";
445
+ missing: "missing";
446
+ superseded: "superseded";
447
+ truncated: "truncated";
448
+ unavailable: "unavailable";
449
+ }>;
450
+ policy: z.ZodObject<{
451
+ status: z.ZodEnum<{
452
+ changed: "changed";
453
+ identical: "identical";
454
+ missing: "missing";
455
+ superseded: "superseded";
456
+ truncated: "truncated";
457
+ unavailable: "unavailable";
458
+ }>;
459
+ snapshotHash: z.ZodNullable<z.ZodString>;
460
+ currentHash: z.ZodNullable<z.ZodString>;
461
+ snapshotTargetCount: z.ZodNumber;
462
+ currentTargetCount: z.ZodNumber;
463
+ }, z.core.$strict>;
464
+ preferences: z.ZodObject<{
465
+ status: z.ZodEnum<{
466
+ changed: "changed";
467
+ identical: "identical";
468
+ missing: "missing";
469
+ superseded: "superseded";
470
+ truncated: "truncated";
471
+ unavailable: "unavailable";
472
+ }>;
473
+ snapshotHash: z.ZodNullable<z.ZodString>;
474
+ currentHash: z.ZodNullable<z.ZodString>;
475
+ snapshotDescriptorCount: z.ZodNumber;
476
+ currentDescriptorCount: z.ZodNumber;
477
+ snapshotTruncated: z.ZodBoolean;
478
+ currentTruncated: z.ZodBoolean;
479
+ }, z.core.$strict>;
480
+ }, z.core.$strict>;
481
+ }, z.core.$strict>], "status">;
482
+ export type WorkspaceStateAttemptGovernance = z.infer<typeof WorkspaceStateAttemptGovernance>;
367
483
  export declare const WorkspaceStateResponse: z.ZodObject<{
368
484
  workspaceId: z.ZodString;
369
485
  generatedAt: z.ZodString;
@@ -372,10 +488,108 @@ export declare const WorkspaceStateResponse: z.ZodObject<{
372
488
  source: z.ZodLiteral<"read_time_projection">;
373
489
  capturedAt: z.ZodString;
374
490
  }, z.core.$strict>;
375
- policySnapshot: z.ZodObject<{
376
- status: z.ZodLiteral<"not_captured">;
377
- reason: z.ZodLiteral<"workspace_instruction_policy_snapshot_not_implemented">;
378
- }, z.core.$strict>;
491
+ attemptGovernance: z.ZodDiscriminatedUnion<[z.ZodObject<{
492
+ status: z.ZodLiteral<"not_requested">;
493
+ }, z.core.$strict>, z.ZodObject<{
494
+ status: z.ZodLiteral<"unavailable">;
495
+ reason: z.ZodLiteral<"attempt_not_found_or_not_authorized">;
496
+ driftStatus: z.ZodLiteral<"unavailable">;
497
+ }, z.core.$strict>, z.ZodObject<{
498
+ status: z.ZodLiteral<"available">;
499
+ attemptId: z.ZodString;
500
+ executionGeneration: z.ZodNumber;
501
+ acceptedAt: z.ZodString;
502
+ policySnapshot: z.ZodDiscriminatedUnion<[z.ZodObject<{
503
+ status: z.ZodLiteral<"available">;
504
+ id: z.ZodString;
505
+ createdAt: z.ZodString;
506
+ entryHash: z.ZodString;
507
+ policyRole: z.ZodNullable<z.ZodString>;
508
+ roleSource: z.ZodEnum<{
509
+ invalid_metadata_fallback: "invalid_metadata_fallback";
510
+ metadata_fallback: "metadata_fallback";
511
+ none: "none";
512
+ session_binding: "session_binding";
513
+ }>;
514
+ entries: z.ZodArray<z.ZodObject<{
515
+ kind: z.ZodEnum<{
516
+ charter: "charter";
517
+ policy: "policy";
518
+ }>;
519
+ scope: z.ZodEnum<{
520
+ global: "global";
521
+ role: "role";
522
+ }>;
523
+ roleKey: z.ZodNullable<z.ZodString>;
524
+ revisionId: z.ZodString;
525
+ revision: z.ZodNumber;
526
+ contentHash: z.ZodString;
527
+ activationVersion: z.ZodNumber;
528
+ activatedAt: z.ZodString;
529
+ provenance: z.ZodObject<{
530
+ source: z.ZodEnum<{
531
+ human: "human";
532
+ knowledge_proposal: "knowledge_proposal";
533
+ legacy_import: "legacy_import";
534
+ onboarding: "onboarding";
535
+ }>;
536
+ sourceIdHash: z.ZodNullable<z.ZodString>;
537
+ }, z.core.$strip>;
538
+ }, z.core.$strip>>;
539
+ }, z.core.$strict>, z.ZodObject<{
540
+ status: z.ZodLiteral<"missing">;
541
+ }, z.core.$strict>], "status">;
542
+ preferenceSnapshot: z.ZodDiscriminatedUnion<[z.ZodObject<{
543
+ status: z.ZodLiteral<"available">;
544
+ id: z.ZodString;
545
+ createdAt: z.ZodString;
546
+ descriptorHash: z.ZodString;
547
+ descriptorCount: z.ZodNumber;
548
+ truncated: z.ZodBoolean;
549
+ }, z.core.$strict>, z.ZodObject<{
550
+ status: z.ZodLiteral<"missing">;
551
+ }, z.core.$strict>], "status">;
552
+ drift: z.ZodObject<{
553
+ overall: z.ZodEnum<{
554
+ changed: "changed";
555
+ identical: "identical";
556
+ missing: "missing";
557
+ superseded: "superseded";
558
+ truncated: "truncated";
559
+ unavailable: "unavailable";
560
+ }>;
561
+ policy: z.ZodObject<{
562
+ status: z.ZodEnum<{
563
+ changed: "changed";
564
+ identical: "identical";
565
+ missing: "missing";
566
+ superseded: "superseded";
567
+ truncated: "truncated";
568
+ unavailable: "unavailable";
569
+ }>;
570
+ snapshotHash: z.ZodNullable<z.ZodString>;
571
+ currentHash: z.ZodNullable<z.ZodString>;
572
+ snapshotTargetCount: z.ZodNumber;
573
+ currentTargetCount: z.ZodNumber;
574
+ }, z.core.$strict>;
575
+ preferences: z.ZodObject<{
576
+ status: z.ZodEnum<{
577
+ changed: "changed";
578
+ identical: "identical";
579
+ missing: "missing";
580
+ superseded: "superseded";
581
+ truncated: "truncated";
582
+ unavailable: "unavailable";
583
+ }>;
584
+ snapshotHash: z.ZodNullable<z.ZodString>;
585
+ currentHash: z.ZodNullable<z.ZodString>;
586
+ snapshotDescriptorCount: z.ZodNumber;
587
+ currentDescriptorCount: z.ZodNumber;
588
+ snapshotTruncated: z.ZodBoolean;
589
+ currentTruncated: z.ZodBoolean;
590
+ }, z.core.$strict>;
591
+ }, z.core.$strict>;
592
+ }, z.core.$strict>], "status">;
379
593
  }, z.core.$strict>;
380
594
  policy: z.ZodObject<{
381
595
  authority: z.ZodLiteral<"workspace_instruction_policy_heads">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/contracts",
3
- "version": "0.32.0",
3
+ "version": "0.35.0",
4
4
  "description": "Shared zod schemas and wire-contract types for the OpenGeni API.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -72,6 +72,59 @@ export type GoogleDriveSyncCadence = z.infer<typeof GoogleDriveSyncCadence>;
72
72
  export const GoogleDriveReadPolicy = z.enum(["allow", "ask", "block"]);
73
73
  export type GoogleDriveReadPolicy = z.infer<typeof GoogleDriveReadPolicy>;
74
74
 
75
+ export const GoogleDriveConnectionLifecycleState = z.enum([
76
+ "active",
77
+ "paused",
78
+ "token_revoked",
79
+ "app_removed",
80
+ "disconnected",
81
+ "reconnect_required",
82
+ "reconsent_required",
83
+ ]);
84
+ export type GoogleDriveConnectionLifecycleState = z.infer<
85
+ typeof GoogleDriveConnectionLifecycleState
86
+ >;
87
+
88
+ const GoogleDriveLifecycleObservedAt = z.string().datetime({ offset: true });
89
+ export const GoogleDriveConnectionLifecycle = z.discriminatedUnion("state", [
90
+ z.object({
91
+ state: z.literal("active"),
92
+ recoverable: z.literal(true),
93
+ observedAt: GoogleDriveLifecycleObservedAt,
94
+ }),
95
+ z.object({
96
+ state: z.literal("paused"),
97
+ recoverable: z.literal(true),
98
+ observedAt: GoogleDriveLifecycleObservedAt,
99
+ }),
100
+ z.object({
101
+ state: z.literal("token_revoked"),
102
+ recoverable: z.literal(true),
103
+ observedAt: GoogleDriveLifecycleObservedAt,
104
+ }),
105
+ z.object({
106
+ state: z.literal("app_removed"),
107
+ recoverable: z.literal(false),
108
+ observedAt: GoogleDriveLifecycleObservedAt,
109
+ }),
110
+ z.object({
111
+ state: z.literal("disconnected"),
112
+ recoverable: z.literal(true),
113
+ observedAt: GoogleDriveLifecycleObservedAt,
114
+ }),
115
+ z.object({
116
+ state: z.literal("reconnect_required"),
117
+ recoverable: z.literal(true),
118
+ observedAt: GoogleDriveLifecycleObservedAt,
119
+ }),
120
+ z.object({
121
+ state: z.literal("reconsent_required"),
122
+ recoverable: z.literal(true),
123
+ observedAt: GoogleDriveLifecycleObservedAt,
124
+ }),
125
+ ]);
126
+ export type GoogleDriveConnectionLifecycle = z.infer<typeof GoogleDriveConnectionLifecycle>;
127
+
75
128
  export const GoogleDriveSelectedSource = z.object({
76
129
  id: z.string().min(1).max(256),
77
130
  name: z.string().min(1).max(1024),
@@ -93,6 +146,7 @@ export const GoogleDriveConnectionMetadata = z
93
146
  googleDisplayName: z.string().min(1).max(512).nullable(),
94
147
  verifiedAt: z.string().datetime({ offset: true }),
95
148
  accessMode: z.enum(["metadata_readonly", "readonly"]),
149
+ lifecycle: GoogleDriveConnectionLifecycle.optional(),
96
150
  selectedSources: z.array(GoogleDriveSelectedSource).max(100).optional(),
97
151
  /** @deprecated Read `selectedSources`; retained while existing connections migrate. */
98
152
  selectedSource: GoogleDriveSelectedSource.nullable().optional(),
@@ -111,6 +165,18 @@ export const GoogleDriveOAuthStartResponse = z.object({
111
165
  });
112
166
  export type GoogleDriveOAuthStartResponse = z.infer<typeof GoogleDriveOAuthStartResponse>;
113
167
 
168
+ export const GoogleDriveLifecycleActionRequest = z.object({
169
+ action: z.enum(["pause", "resume"]),
170
+ expectedVersion: z.number().int().positive(),
171
+ });
172
+ export type GoogleDriveLifecycleActionRequest = z.infer<typeof GoogleDriveLifecycleActionRequest>;
173
+
174
+ export const GoogleDriveDisconnectRequest = z.object({
175
+ expectedVersion: z.number().int().positive(),
176
+ idempotencyKey: z.string().trim().min(1).max(200),
177
+ });
178
+ export type GoogleDriveDisconnectRequest = z.infer<typeof GoogleDriveDisconnectRequest>;
179
+
114
180
  export const GoogleDriveBrowseItem = z.object({
115
181
  id: z.string().min(1).max(256),
116
182
  name: z.string().min(1).max(1024),
package/src/index.ts CHANGED
@@ -2957,6 +2957,14 @@ export const FileResourceRef = z.object({
2957
2957
  });
2958
2958
  export type FileResourceRef = z.infer<typeof FileResourceRef>;
2959
2959
 
2960
+ /**
2961
+ * Private durable metadata carried on user history items. It contains only
2962
+ * stable file references, never file bytes, and is removed before model wire
2963
+ * serialization. Keeping the references beside the message lets a later turn
2964
+ * reconstruct the same typed attachment input after a model switch or retry.
2965
+ */
2966
+ export const MODEL_ATTACHMENT_REFS_FIELD = "opengeni_attachment_refs" as const;
2967
+
2960
2968
  export const ResourceRef = z.discriminatedUnion("kind", [RepositoryResourceRef, FileResourceRef]);
2961
2969
  export type ResourceRef = z.infer<typeof ResourceRef>;
2962
2970
 
@@ -3043,10 +3051,12 @@ export function defaultRepositoryMountPath(uri: string): string {
3043
3051
  }
3044
3052
 
3045
3053
  /** Resolve the exact mount used by API normalization, manifests, and clone hooks. */
3054
+ export const DEFAULT_FILE_RESOURCE_MOUNT_ROOT = ".opengeni/files" as const;
3055
+
3046
3056
  export function resourceMountPath(resource: ResourceRef): string {
3047
3057
  if (resource.mountPath) return normalizeResourceMountPath(resource.mountPath);
3048
3058
  return resource.kind === "file"
3049
- ? normalizeResourceMountPath(`files/${resource.fileId}`)
3059
+ ? normalizeResourceMountPath(`${DEFAULT_FILE_RESOURCE_MOUNT_ROOT}/${resource.fileId}`)
3050
3060
  : defaultRepositoryMountPath(resource.uri);
3051
3061
  }
3052
3062
 
@@ -3138,8 +3148,15 @@ export type KnowledgeSourceKind = z.infer<typeof KnowledgeSourceKind>;
3138
3148
  export const DocumentSearchMode = z.enum(["hybrid", "vector", "keyword"]);
3139
3149
  export type DocumentSearchMode = z.infer<typeof DocumentSearchMode>;
3140
3150
 
3151
+ // Durable document authority. Collections/bases are organizational metadata,
3152
+ // never an authorization boundary.
3153
+ export const DocumentAuthorityKind = z.enum(["organization", "workspace", "personal"]);
3154
+ export type DocumentAuthorityKind = z.infer<typeof DocumentAuthorityKind>;
3155
+
3141
3156
  // 'workspace' documents are readable by anyone with workspace access;
3142
3157
  // 'private' documents are readable only by the grant subject that created them.
3158
+ // Retained as a compatibility projection over authorityKind:
3159
+ // personal -> private; organization/workspace -> workspace.
3143
3160
  export const DocumentVisibility = z.enum(["workspace", "private"]);
3144
3161
  export type DocumentVisibility = z.infer<typeof DocumentVisibility>;
3145
3162
 
@@ -3198,6 +3215,9 @@ export const Document = z.object({
3198
3215
  sourceUpdatedAt: z.string().nullable(),
3199
3216
  sourceVersion: z.string().nullable(),
3200
3217
  aclTags: z.array(z.string()),
3218
+ authorityKind: DocumentAuthorityKind,
3219
+ authorityWorkspaceId: z.string().uuid().nullable(),
3220
+ authoritySubjectId: z.string().nullable(),
3201
3221
  visibility: DocumentVisibility,
3202
3222
  createdBy: z.string().nullable(),
3203
3223
  agentAccess: z.boolean(),
@@ -3212,6 +3232,9 @@ export type Document = z.infer<typeof Document>;
3212
3232
 
3213
3233
  export const DocumentSearchResult = z.object({
3214
3234
  chunkId: z.string().uuid(),
3235
+ // The workspace that ingested the document. Organization-authority results
3236
+ // may originate in another workspace in the same account; this identifier
3237
+ // is provenance and does not grant access to that workspace or its resources.
3215
3238
  workspaceId: z.string().uuid(),
3216
3239
  documentId: z.string().uuid(),
3217
3240
  baseId: z.string().uuid(),
@@ -3233,9 +3256,17 @@ export const DocumentSearchResult = z.object({
3233
3256
  sourceUpdatedAt: z.string().nullable(),
3234
3257
  sourceVersion: z.string().nullable(),
3235
3258
  aclTags: z.array(z.string()),
3259
+ authorityKind: DocumentAuthorityKind,
3260
+ authorityWorkspaceId: z.string().uuid().nullable(),
3261
+ authoritySubjectId: z.string().nullable(),
3236
3262
  });
3237
3263
  export type DocumentSearchResult = z.infer<typeof DocumentSearchResult>;
3238
3264
 
3265
+ export const DocumentSearchResponse = z.object({
3266
+ results: z.array(DocumentSearchResult),
3267
+ });
3268
+ export type DocumentSearchResponse = z.infer<typeof DocumentSearchResponse>;
3269
+
3239
3270
  export const CreateDocumentBaseRequest = z.object({
3240
3271
  name: z.string().min(1),
3241
3272
  description: z.string().optional(),
@@ -3254,6 +3285,7 @@ export const AddDocumentRequest = z.object({
3254
3285
  sourceUpdatedAt: z.string().datetime({ offset: true }).optional(),
3255
3286
  sourceVersion: z.string().min(1).optional(),
3256
3287
  aclTags: z.array(z.string().min(1)).optional(),
3288
+ authorityKind: DocumentAuthorityKind.optional(),
3257
3289
  visibility: DocumentVisibility.optional(),
3258
3290
  agentAccess: z.boolean().optional(),
3259
3291
  });
@@ -3270,6 +3302,7 @@ export const CreateKnowledgeDropRequest = z
3270
3302
  fileId: z.string().uuid().optional(),
3271
3303
  filename: z.string().min(1).optional(),
3272
3304
  title: z.string().min(1).optional(),
3305
+ authorityKind: DocumentAuthorityKind.optional(),
3273
3306
  visibility: DocumentVisibility.optional(),
3274
3307
  agentAccess: z.boolean().optional(),
3275
3308
  })
@@ -8579,10 +8612,10 @@ export const HumanInputQuestion = z
8579
8612
  options: z.array(HumanInputOption).max(20).default([]),
8580
8613
  required: z.boolean().default(true),
8581
8614
  allowOther: z.boolean().default(false),
8615
+ // Selection bounds only — agents invent useless text char mins/maxes.
8616
+ // Answer strings stay platform-capped on HumanInputAnswer (~8192).
8582
8617
  validation: z
8583
8618
  .object({
8584
- minLength: z.number().int().nonnegative().max(8192).nullable().optional(),
8585
- maxLength: z.number().int().positive().max(8192).nullable().optional(),
8586
8619
  minSelections: z.number().int().nonnegative().max(20).nullable().optional(),
8587
8620
  maxSelections: z.number().int().positive().max(20).nullable().optional(),
8588
8621
  })
@@ -8621,17 +8654,6 @@ export const HumanInputQuestion = z
8621
8654
  });
8622
8655
  }
8623
8656
  const validation = question.validation;
8624
- if (
8625
- validation?.minLength != null &&
8626
- validation?.maxLength != null &&
8627
- validation.minLength > validation.maxLength
8628
- ) {
8629
- ctx.addIssue({
8630
- code: "custom",
8631
- path: ["validation"],
8632
- message: "minLength exceeds maxLength",
8633
- });
8634
- }
8635
8657
  if (
8636
8658
  validation?.minSelections != null &&
8637
8659
  validation?.maxSelections != null &&
@@ -9507,6 +9529,7 @@ export const ModelCapabilitiesV1 = /* @__PURE__ */ defineModelContractSchema(()
9507
9529
  codeExecution: ModelCapabilityStateV1,
9508
9530
  }),
9509
9531
  inputModalities: z.array(z.enum(["text", "image", "audio"])),
9532
+ inputFileMediaTypes: z.array(z.string()).optional(),
9510
9533
  outputModalities: z.array(z.enum(["text", "image", "audio"])),
9511
9534
  transports: z.object({
9512
9535
  sse: ModelCapabilityStateV1,
@@ -130,6 +130,7 @@ export type WorkspaceInstructionPolicyRevisionIdentity = z.infer<
130
130
 
131
131
  export const WorkspaceInstructionPolicyRevision = z.object({
132
132
  ...revisionIdentityShape,
133
+ operationId: z.string().uuid(),
133
134
  accountId: z.string().uuid(),
134
135
  workspaceId: z.string().uuid(),
135
136
  ...targetShape,
@@ -212,6 +213,7 @@ export type ResolvedWorkspaceInstructionPolicySnapshot = z.infer<
212
213
 
213
214
  export const WorkspaceInstructionPolicyActivationEvent = z.object({
214
215
  id: z.string().uuid(),
216
+ operationId: z.string().uuid(),
215
217
  accountId: z.string().uuid(),
216
218
  workspaceId: z.string().uuid(),
217
219
  ...targetShape,
@@ -229,6 +231,7 @@ export type WorkspaceInstructionPolicyActivationEvent = z.infer<
229
231
 
230
232
  export const CreateWorkspaceInstructionPolicyDraftRequest = z
231
233
  .object({
234
+ operationId: z.string().uuid().optional(),
232
235
  kind: WorkspaceInstructionPolicyKind,
233
236
  scope: WorkspaceInstructionPolicyScope,
234
237
  roleKey: WorkspaceInstructionPolicyRoleKeyInput.nullable().default(null),
@@ -253,6 +256,7 @@ export type CreateWorkspaceInstructionPolicyDraftRequest = z.infer<
253
256
 
254
257
  export const ImportLegacyWorkspaceInstructionPolicyDraftRequest = z
255
258
  .object({
259
+ operationId: z.string().uuid().optional(),
256
260
  supersedesRevisionId: z.string().uuid().nullable().default(null),
257
261
  })
258
262
  .strict();
@@ -305,7 +309,9 @@ export type WorkspaceInstructionPolicyDiffResponse = z.infer<
305
309
  >;
306
310
 
307
311
  export const ActivateWorkspaceInstructionPolicyRequest = z.object({
312
+ operationId: z.string().uuid().optional(),
308
313
  expectedCurrentRevisionId: z.string().uuid().nullable(),
314
+ expectedActivationVersion: z.number().int().nonnegative().optional(),
309
315
  reason: z.string().trim().min(1).max(WORKSPACE_INSTRUCTION_POLICY_REASON_MAX_CHARS),
310
316
  });
311
317
  export type ActivateWorkspaceInstructionPolicyRequest = z.infer<
@@ -313,8 +319,10 @@ export type ActivateWorkspaceInstructionPolicyRequest = z.infer<
313
319
  >;
314
320
 
315
321
  export const RollbackWorkspaceInstructionPolicyRequest = z.object({
322
+ operationId: z.string().uuid().optional(),
316
323
  targetRevisionId: z.string().uuid(),
317
324
  expectedCurrentRevisionId: z.string().uuid(),
325
+ expectedActivationVersion: z.number().int().positive().optional(),
318
326
  reason: z.string().trim().min(1).max(WORKSPACE_INSTRUCTION_POLICY_REASON_MAX_CHARS),
319
327
  });
320
328
  export type RollbackWorkspaceInstructionPolicyRequest = z.infer<
@@ -337,3 +345,11 @@ export const WorkspaceInstructionPolicyConflictResponse = z.object({
337
345
  export type WorkspaceInstructionPolicyConflictResponse = z.infer<
338
346
  typeof WorkspaceInstructionPolicyConflictResponse
339
347
  >;
348
+
349
+ export const WorkspaceInstructionPolicyOperationReuseResponse = z.object({
350
+ code: z.literal("WORKSPACE_INSTRUCTION_POLICY_OPERATION_REUSED"),
351
+ message: z.string(),
352
+ });
353
+ export type WorkspaceInstructionPolicyOperationReuseResponse = z.infer<
354
+ typeof WorkspaceInstructionPolicyOperationReuseResponse
355
+ >;
@@ -4,7 +4,9 @@ import {
4
4
  WorkspaceInstructionPolicyKind,
5
5
  WorkspaceInstructionPolicyProvenanceSource,
6
6
  WorkspaceInstructionPolicyRoleKey,
7
+ WorkspaceInstructionPolicyRoleSource,
7
8
  WorkspaceInstructionPolicyScope,
9
+ WorkspaceInstructionPolicySnapshotEntry,
8
10
  } from "./workspace-instruction-policies";
9
11
 
10
12
  export const WORKSPACE_STATE_MAX_ACTIVE_POLICY_HEADS = 32;
@@ -17,6 +19,9 @@ export const WORKSPACE_STATE_MEMORY_SAMPLE_LIMIT = 100;
17
19
 
18
20
  const Count = z.number().int().nonnegative();
19
21
 
22
+ export const WorkspaceStateQuery = z.object({ attemptId: z.string().uuid().optional() }).strict();
23
+ export type WorkspaceStateQuery = z.infer<typeof WorkspaceStateQuery>;
24
+
20
25
  export const WorkspaceStateDocumentStatusCounts = z
21
26
  .object({
22
27
  queued: Count,
@@ -196,6 +201,112 @@ export const WorkspaceStateKnowledge = z.discriminatedUnion("availability", [
196
201
  ]);
197
202
  export type WorkspaceStateKnowledge = z.infer<typeof WorkspaceStateKnowledge>;
198
203
 
204
+ export const WorkspaceStateGovernanceDriftStatus = z.enum([
205
+ "identical",
206
+ "changed",
207
+ "superseded",
208
+ "missing",
209
+ "unavailable",
210
+ "truncated",
211
+ ]);
212
+ export type WorkspaceStateGovernanceDriftStatus = z.infer<
213
+ typeof WorkspaceStateGovernanceDriftStatus
214
+ >;
215
+
216
+ const WorkspaceStatePolicySnapshotAvailable = z
217
+ .object({
218
+ status: z.literal("available"),
219
+ id: z.string().uuid(),
220
+ createdAt: z.string().datetime(),
221
+ entryHash: z.string().regex(/^[0-9a-f]{64}$/),
222
+ policyRole: WorkspaceInstructionPolicyRoleKey.nullable(),
223
+ roleSource: WorkspaceInstructionPolicyRoleSource,
224
+ entries: z.array(WorkspaceInstructionPolicySnapshotEntry).max(3),
225
+ })
226
+ .strict();
227
+
228
+ const WorkspaceStatePolicySnapshotMissing = z.object({ status: z.literal("missing") }).strict();
229
+
230
+ const WorkspaceStatePreferenceSnapshotAvailable = z
231
+ .object({
232
+ status: z.literal("available"),
233
+ id: z.string().uuid(),
234
+ createdAt: z.string().datetime(),
235
+ descriptorHash: z.string().regex(/^[0-9a-f]{64}$/),
236
+ descriptorCount: Count.max(64),
237
+ truncated: z.boolean(),
238
+ })
239
+ .strict();
240
+
241
+ const WorkspaceStatePreferenceSnapshotMissing = z.object({ status: z.literal("missing") }).strict();
242
+
243
+ const WorkspaceStateGovernanceDrift = z
244
+ .object({
245
+ overall: WorkspaceStateGovernanceDriftStatus,
246
+ policy: z
247
+ .object({
248
+ status: WorkspaceStateGovernanceDriftStatus,
249
+ snapshotHash: z
250
+ .string()
251
+ .regex(/^[0-9a-f]{64}$/)
252
+ .nullable(),
253
+ currentHash: z
254
+ .string()
255
+ .regex(/^[0-9a-f]{64}$/)
256
+ .nullable(),
257
+ snapshotTargetCount: Count,
258
+ currentTargetCount: Count,
259
+ })
260
+ .strict(),
261
+ preferences: z
262
+ .object({
263
+ status: WorkspaceStateGovernanceDriftStatus,
264
+ snapshotHash: z
265
+ .string()
266
+ .regex(/^[0-9a-f]{64}$/)
267
+ .nullable(),
268
+ currentHash: z
269
+ .string()
270
+ .regex(/^[0-9a-f]{64}$/)
271
+ .nullable(),
272
+ snapshotDescriptorCount: Count,
273
+ currentDescriptorCount: Count,
274
+ snapshotTruncated: z.boolean(),
275
+ currentTruncated: z.boolean(),
276
+ })
277
+ .strict(),
278
+ })
279
+ .strict();
280
+
281
+ export const WorkspaceStateAttemptGovernance = z.discriminatedUnion("status", [
282
+ z.object({ status: z.literal("not_requested") }).strict(),
283
+ z
284
+ .object({
285
+ status: z.literal("unavailable"),
286
+ reason: z.literal("attempt_not_found_or_not_authorized"),
287
+ driftStatus: z.literal("unavailable"),
288
+ })
289
+ .strict(),
290
+ z
291
+ .object({
292
+ status: z.literal("available"),
293
+ attemptId: z.string().uuid(),
294
+ executionGeneration: z.number().int().positive(),
295
+ acceptedAt: z.string().datetime(),
296
+ policySnapshot: z.discriminatedUnion("status", [
297
+ WorkspaceStatePolicySnapshotAvailable,
298
+ WorkspaceStatePolicySnapshotMissing,
299
+ ]),
300
+ preferenceSnapshot: z.discriminatedUnion("status", [
301
+ WorkspaceStatePreferenceSnapshotAvailable,
302
+ WorkspaceStatePreferenceSnapshotMissing,
303
+ ]),
304
+ drift: WorkspaceStateGovernanceDrift,
305
+ })
306
+ .strict(),
307
+ ]);
308
+ export type WorkspaceStateAttemptGovernance = z.infer<typeof WorkspaceStateAttemptGovernance>;
309
+
199
310
  export const WorkspaceStateResponse = z
200
311
  .object({
201
312
  workspaceId: z.string().uuid(),
@@ -208,12 +319,7 @@ export const WorkspaceStateResponse = z
208
319
  capturedAt: z.string().datetime(),
209
320
  })
210
321
  .strict(),
211
- policySnapshot: z
212
- .object({
213
- status: z.literal("not_captured"),
214
- reason: z.literal("workspace_instruction_policy_snapshot_not_implemented"),
215
- })
216
- .strict(),
322
+ attemptGovernance: WorkspaceStateAttemptGovernance,
217
323
  })
218
324
  .strict(),
219
325
  policy: WorkspaceStatePolicy,