@driftgate/contracts 0.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts ADDED
@@ -0,0 +1,1408 @@
1
+ import { z } from "zod";
2
+
3
+ export const CONTRACT_VERSION = "1.9.0";
4
+
5
+ export const AuthSessionSchema = z.object({
6
+ sessionId: z.string(),
7
+ userId: z.string(),
8
+ tenantId: z.string(),
9
+ workspaceIds: z.array(z.string()),
10
+ roles: z.array(z.string()),
11
+ idpProvider: z.enum(["google", "github", "email", "saml"]),
12
+ mfaStatus: z.enum(["required", "passed", "not-required"])
13
+ });
14
+
15
+ export const WorkspaceRoleBindingSchema = z.object({
16
+ workspaceId: z.string(),
17
+ userId: z.string(),
18
+ role: z.enum(["owner", "admin", "editor", "viewer", "approver", "billing-admin"]),
19
+ grantedAt: z.string().datetime(),
20
+ grantedBy: z.string()
21
+ });
22
+
23
+ export const WorkflowVersionSchema = z.object({
24
+ workflowId: z.string(),
25
+ versionId: z.string(),
26
+ versionNumber: z.number().int().positive(),
27
+ state: z.enum(["draft", "published", "archived"]),
28
+ checksum: z.string(),
29
+ sourceType: z.enum(["ui_graph", "workflow_yaml", "api_plan"]).optional(),
30
+ compiledPlanJson: z.record(z.unknown()).optional(),
31
+ createdAt: z.string().datetime(),
32
+ publishedAt: z.string().datetime().optional()
33
+ });
34
+
35
+ export const WorkflowBuilderNodeSchema = z.object({
36
+ id: z.string().min(1),
37
+ type: z.string().min(1).optional(),
38
+ position: z.object({
39
+ x: z.number(),
40
+ y: z.number()
41
+ }),
42
+ data: z.record(z.unknown())
43
+ });
44
+
45
+ export const WorkflowBuilderEdgeSchema = z.object({
46
+ id: z.string().min(1),
47
+ source: z.string().min(1),
48
+ target: z.string().min(1),
49
+ type: z.string().min(1).optional(),
50
+ label: z.string().optional(),
51
+ data: z.record(z.unknown()).optional()
52
+ });
53
+
54
+ export const WorkflowBuilderViewportSchema = z.object({
55
+ x: z.number(),
56
+ y: z.number(),
57
+ zoom: z.number().positive()
58
+ });
59
+
60
+ export const WorkflowBuilderDocumentSchema = z.object({
61
+ workflowId: z.string(),
62
+ version: z.number().int().nonnegative(),
63
+ nodes: z.array(WorkflowBuilderNodeSchema),
64
+ edges: z.array(WorkflowBuilderEdgeSchema),
65
+ viewport: WorkflowBuilderViewportSchema,
66
+ updatedAt: z.string().datetime()
67
+ });
68
+
69
+ export const RunStateSchema = z.enum([
70
+ "queued",
71
+ "running",
72
+ "waiting_approval",
73
+ "approved",
74
+ "denied",
75
+ "succeeded",
76
+ "failed",
77
+ "aborted",
78
+ "timed_out",
79
+ "canceled"
80
+ ]);
81
+
82
+ export const RunTriggerSourceSchema = z.enum(["ui", "api", "sdk", "cli", "hosted", "webhook"]);
83
+
84
+ export const GovernedRunRequestSchema = z.object({
85
+ workspaceId: z.string().min(1),
86
+ workflowVersionId: z.string().min(1),
87
+ requiresApproval: z.boolean().default(false),
88
+ requiredRole: z.string().min(1).optional(),
89
+ slaPolicyId: z.string().min(1).optional(),
90
+ idempotencyKey: z.string().min(1).max(200).optional(),
91
+ correlationId: z.string().min(1).max(200).optional(),
92
+ triggerSource: RunTriggerSourceSchema.default("api")
93
+ });
94
+
95
+ export const HeadlessRunRequestSchema = GovernedRunRequestSchema.extend({
96
+ input: z.record(z.unknown()).optional()
97
+ });
98
+
99
+ export const StructuredErrorEnvelopeSchema = z.object({
100
+ code: z.string(),
101
+ message: z.string(),
102
+ correlation_id: z.string().optional(),
103
+ details: z.unknown().optional()
104
+ });
105
+
106
+ export const CanonicalPolicyRefSchema = z.object({
107
+ ref: z.string().min(1),
108
+ version: z.string().min(1)
109
+ });
110
+
111
+ export const CanonicalRouteRefSchema = z.object({
112
+ provider: z.string().min(1).optional(),
113
+ model: z.string().min(1).optional(),
114
+ region: z.string().min(1).optional()
115
+ });
116
+
117
+ export const CanonicalRiskMetaSchema = z.object({
118
+ score: z.number().optional(),
119
+ decision: z.enum(["allow", "deny", "review"]).optional()
120
+ });
121
+
122
+ export const CanonicalTimingMsSchema = z.object({
123
+ total: z.number().nonnegative(),
124
+ policy: z.number().nonnegative().optional(),
125
+ route: z.number().nonnegative().optional(),
126
+ tool: z.number().nonnegative().optional()
127
+ });
128
+
129
+ export const CanonicalResponseMetaSchema = z.object({
130
+ requestId: z.string().min(1),
131
+ sessionId: z.string().min(1).optional(),
132
+ executionId: z.string().min(1).optional(),
133
+ lineageId: z.string().min(1).optional(),
134
+ policy: CanonicalPolicyRefSchema.optional(),
135
+ route: CanonicalRouteRefSchema.optional(),
136
+ risk: CanonicalRiskMetaSchema.optional(),
137
+ timingMs: CanonicalTimingMsSchema
138
+ });
139
+
140
+ export const CanonicalErrorCodeSchema = z.enum([
141
+ "AUTH_INVALID",
142
+ "POLICY_DENIED",
143
+ "RISK_EXCEEDED",
144
+ "ROUTE_UNAVAILABLE",
145
+ "TOOL_BLOCKED",
146
+ "RATE_LIMITED",
147
+ "TIMEOUT",
148
+ "INTERNAL",
149
+ "INVALID_REQUEST"
150
+ ]);
151
+
152
+ export const CanonicalErrorSchema = z.object({
153
+ code: CanonicalErrorCodeSchema,
154
+ message: z.string().min(1),
155
+ status: z.number().int().min(100).max(599),
156
+ retryable: z.boolean(),
157
+ details: z.record(z.unknown()).optional()
158
+ });
159
+
160
+ export const CanonicalResponseEnvelopeSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>
161
+ z.object({
162
+ ok: z.boolean(),
163
+ data: dataSchema.nullable(),
164
+ meta: CanonicalResponseMetaSchema,
165
+ error: CanonicalErrorSchema.nullable()
166
+ });
167
+
168
+ export const V4SessionStartRequestSchema = z.object({
169
+ workspaceId: z.string().min(1).optional(),
170
+ agent: z.string().min(1),
171
+ subject: z.string().min(1).optional(),
172
+ metadata: z.record(z.unknown()).optional(),
173
+ policy: CanonicalPolicyRefSchema.optional(),
174
+ route: CanonicalRouteRefSchema.optional(),
175
+ risk: CanonicalRiskMetaSchema.optional(),
176
+ workflowVersionId: z.string().min(1).optional(),
177
+ expiresAt: z.string().datetime().optional()
178
+ });
179
+
180
+ export const V4SessionResourceSchema = z.object({
181
+ sessionId: z.string().min(1),
182
+ workspaceId: z.string().min(1),
183
+ agent: z.string().min(1),
184
+ subject: z.string().min(1).optional(),
185
+ metadata: z.record(z.unknown()).optional(),
186
+ policy: CanonicalPolicyRefSchema.optional(),
187
+ route: CanonicalRouteRefSchema.optional(),
188
+ risk: CanonicalRiskMetaSchema.optional(),
189
+ workflowVersionId: z.string().min(1).optional(),
190
+ createdAt: z.string().datetime(),
191
+ expiresAt: z.string().datetime().optional()
192
+ });
193
+
194
+ export const V4ExecutionRequestSchema = z.object({
195
+ input: z.record(z.unknown()),
196
+ policy: CanonicalPolicyRefSchema.optional(),
197
+ route: CanonicalRouteRefSchema.optional(),
198
+ risk: CanonicalRiskMetaSchema.optional(),
199
+ workflowVersionId: z.string().min(1).optional()
200
+ });
201
+
202
+ export const V4ExecutionResultSchema = z.object({
203
+ run: z.record(z.unknown()),
204
+ approval: z.record(z.unknown()).nullable().optional(),
205
+ blocked: z.boolean(),
206
+ policyDecisions: z.array(z.record(z.unknown())).default([]),
207
+ entitlementDecision: z.record(z.unknown()),
208
+ usageEntry: z.record(z.unknown()),
209
+ boundaryDecision: z.record(z.unknown()).nullable().optional(),
210
+ firewallDecision: z.record(z.unknown()).nullable().optional()
211
+ });
212
+
213
+ export const V4EphemeralExecuteRequestSchema = V4SessionStartRequestSchema.omit({
214
+ expiresAt: true
215
+ }).extend({
216
+ input: z.record(z.unknown())
217
+ });
218
+
219
+ export const RunStateTransitionSchema = z.object({
220
+ runId: z.string(),
221
+ from: RunStateSchema,
222
+ to: RunStateSchema,
223
+ occurredAt: z.string().datetime(),
224
+ actor: z.string().optional(),
225
+ reason: z.string().optional()
226
+ });
227
+
228
+ export const PolicyDecisionSchema = z.object({
229
+ mode: z.enum(["monitor", "enforce"]),
230
+ decision: z.enum(["allow", "deny"]),
231
+ policyId: z.string(),
232
+ ruleId: z.string(),
233
+ reasonCode: z.string(),
234
+ reasonText: z.string(),
235
+ correlationId: z.string(),
236
+ trace: z.record(z.unknown())
237
+ });
238
+
239
+ export const PolicyExitGateEvidenceSchema = z.object({
240
+ runId: z.string(),
241
+ runState: RunStateSchema,
242
+ blocked: z.boolean(),
243
+ traceComplete: z.boolean(),
244
+ decisionCount: z.number().int().nonnegative(),
245
+ blockingDecision: PolicyDecisionSchema.nullable(),
246
+ denialEvent: z
247
+ .object({
248
+ eventId: z.string(),
249
+ occurredAt: z.string().datetime(),
250
+ policyId: z.string(),
251
+ ruleId: z.string(),
252
+ reasonCode: z.string(),
253
+ reasonText: z.string(),
254
+ correlationId: z.string()
255
+ })
256
+ .nullable()
257
+ });
258
+
259
+ export const EntitlementDecisionSchema = z.object({
260
+ tenantId: z.string(),
261
+ plan: z.string(),
262
+ entitled: z.boolean(),
263
+ denialReason: z.string().optional()
264
+ });
265
+
266
+ export const ArtifactManifestItemSchema = z.object({
267
+ artifactId: z.string(),
268
+ runId: z.string(),
269
+ path: z.string(),
270
+ type: z.string(),
271
+ sha256: z.string(),
272
+ sizeBytes: z.number().int().nonnegative()
273
+ });
274
+
275
+ export const ControlFailureSchema = z.object({
276
+ jobId: z.string(),
277
+ failureCategory: z.enum([
278
+ "cursor-drift",
279
+ "missing-run-script",
280
+ "policy-deny",
281
+ "network",
282
+ "dependency-timeout",
283
+ "unknown"
284
+ ]),
285
+ firstFailure: z.string().datetime(),
286
+ blockedUntil: z.string().datetime().optional()
287
+ });
288
+
289
+ export const ControlJobStateSchema = z.enum([
290
+ "queued",
291
+ "running",
292
+ "succeeded",
293
+ "failed",
294
+ "blocked"
295
+ ]);
296
+
297
+ export const ControlJobSchema = z.object({
298
+ id: z.string(),
299
+ kind: z.string(),
300
+ dispatchKey: z.string(),
301
+ payload: z.record(z.unknown()),
302
+ state: ControlJobStateSchema,
303
+ createdAt: z.string().datetime(),
304
+ updatedAt: z.string().datetime(),
305
+ lastFailure: ControlFailureSchema.nullable()
306
+ });
307
+
308
+ export const ControlJobAttemptSchema = z.object({
309
+ id: z.string(),
310
+ jobId: z.string(),
311
+ attempt: z.number().int().positive(),
312
+ startedAt: z.string().datetime(),
313
+ finishedAt: z.string().datetime(),
314
+ outcome: z.enum(["succeeded", "failed", "blocked"])
315
+ });
316
+
317
+ export const ControlJobEventSchema = z.object({
318
+ id: z.string(),
319
+ jobId: z.string(),
320
+ type: z.enum([
321
+ "job.queued",
322
+ "job.suppressed",
323
+ "job.started",
324
+ "job.succeeded",
325
+ "job.failed",
326
+ "job.blocked",
327
+ "job.backoff_scheduled",
328
+ "job.retried"
329
+ ]),
330
+ payload: z.record(z.unknown()),
331
+ createdAt: z.string().datetime()
332
+ });
333
+
334
+ export const ControlBackoffStateSchema = z.object({
335
+ jobId: z.string(),
336
+ dispatchKey: z.string(),
337
+ rootCauseKey: z.string(),
338
+ consecutiveFailures: z.number().int().nonnegative(),
339
+ nextRetryAt: z.string().datetime().nullable(),
340
+ blockedUntil: z.string().datetime().nullable(),
341
+ updatedAt: z.string().datetime()
342
+ });
343
+
344
+ export const ControlSuppressionStateSchema = z.object({
345
+ dispatchKey: z.string(),
346
+ blockedUntil: z.string().datetime(),
347
+ reason: z.string(),
348
+ updatedAt: z.string().datetime()
349
+ });
350
+
351
+ export const ControlJobScheduleRequestSchema = z.object({
352
+ kind: z.string().min(1),
353
+ dedupeKey: z.string().min(1).optional(),
354
+ payload: z.record(z.unknown()).default({})
355
+ });
356
+
357
+ export const ControlJobBlockRequestSchema = z.object({
358
+ failureCategory: ControlFailureSchema.shape.failureCategory,
359
+ message: z.string().min(1),
360
+ blockedUntil: z.string().datetime().optional()
361
+ });
362
+
363
+ export const ControlJobRunNextResponseSchema = z.union([
364
+ z.object({
365
+ processed: z.literal(false),
366
+ reason: z.literal("queue_empty")
367
+ }),
368
+ z.object({
369
+ processed: z.literal(true),
370
+ job: ControlJobSchema,
371
+ attempt: ControlJobAttemptSchema
372
+ })
373
+ ]);
374
+
375
+ export const GitHubDispatchControlPayloadSchema = z.object({
376
+ owner: z.string().min(1),
377
+ repo: z.string().min(1),
378
+ eventType: z.string().min(1).default("control_job_requested"),
379
+ clientPayload: z.record(z.unknown()).default({})
380
+ });
381
+
382
+ export const SamlConnectionSchema = z.object({
383
+ workspaceId: z.string(),
384
+ connectionId: z.string(),
385
+ issuer: z.string().url(),
386
+ entryPoint: z.string().url(),
387
+ signInUrl: z.string().url(),
388
+ certificateFingerprint: z.string().min(1),
389
+ createdAt: z.string().datetime(),
390
+ createdBy: z.string(),
391
+ updatedAt: z.string().datetime(),
392
+ updatedBy: z.string()
393
+ });
394
+
395
+ export const ScimProvisioningTokenSchema = z.object({
396
+ workspaceId: z.string(),
397
+ tokenId: z.string(),
398
+ tokenPreview: z.string(),
399
+ status: z.enum(["active", "revoked"]),
400
+ createdAt: z.string().datetime(),
401
+ createdBy: z.string(),
402
+ revokedAt: z.string().datetime().optional(),
403
+ revokedBy: z.string().optional()
404
+ });
405
+
406
+ export const ComplianceFrameworkSchema = z.enum(["soc2", "iso27001", "gdpr", "ai_act"]);
407
+
408
+ export const ComplianceFrameworkControlMappingSchema = z.object({
409
+ framework: ComplianceFrameworkSchema,
410
+ controlIds: z.array(z.string().min(1)).min(1),
411
+ rationale: z.string().min(1).optional()
412
+ });
413
+
414
+ export const ComplianceExportFormatSchema = z.enum(["json", "csv", "api_feed"]);
415
+
416
+ export const CreateComplianceExportRequestSchema = z.object({
417
+ workspaceId: z.string().min(1),
418
+ bundleIds: z.array(z.string().min(1)).optional(),
419
+ frameworks: z.array(ComplianceFrameworkSchema).min(1).optional(),
420
+ format: ComplianceExportFormatSchema.optional()
421
+ });
422
+
423
+ export const ComplianceExportManifestItemSchema = z.object({
424
+ exportId: z.string(),
425
+ bundleId: z.string(),
426
+ runId: z.string(),
427
+ artifactId: z.string(),
428
+ path: z.string(),
429
+ type: z.string(),
430
+ sha256: z.string(),
431
+ sizeBytes: z.number().int().nonnegative(),
432
+ traceability: z
433
+ .object({
434
+ auditEventId: z.string().min(1).optional(),
435
+ usageEntryId: z.string().min(1).optional()
436
+ })
437
+ .optional(),
438
+ frameworkMappings: z.array(ComplianceFrameworkControlMappingSchema).optional()
439
+ });
440
+
441
+ export const ComplianceExportExitGateSchema = z.object({
442
+ workspaceId: z.string(),
443
+ passed: z.boolean(),
444
+ reasonCodes: z.array(z.string()),
445
+ evaluatedAt: z.string().datetime(),
446
+ latestExportId: z.string().optional(),
447
+ manifestHash: z.string().optional()
448
+ });
449
+
450
+ export const CapabilityStatusSchema = z.enum(["enabled", "disabled", "preview"]);
451
+
452
+ export const CapabilityDescriptorSchema = z.object({
453
+ key: z.string().min(1),
454
+ status: CapabilityStatusSchema,
455
+ version: z.string().min(1).optional(),
456
+ description: z.string().min(1).optional(),
457
+ config: z.record(z.unknown()).optional()
458
+ });
459
+
460
+ export const ApiSurfaceVersionSchema = z.object({
461
+ name: z.string().min(1),
462
+ version: z.string().min(1),
463
+ deprecated: z.boolean().optional()
464
+ });
465
+
466
+ export const CapabilityNegotiationSchema = z.object({
467
+ requestedSurface: z.string().min(1).optional(),
468
+ requestedVersion: z.string().min(1).optional(),
469
+ selectedSurface: z.string().min(1),
470
+ selectedVersion: z.string().min(1),
471
+ compatible: z.boolean()
472
+ });
473
+
474
+ export const CapabilitiesResponseSchema = z.object({
475
+ generatedAt: z.string().datetime(),
476
+ workspaceId: z.string().min(1).optional(),
477
+ apiSurfaces: z.array(ApiSurfaceVersionSchema).default([]),
478
+ capabilities: z.array(CapabilityDescriptorSchema).default([]),
479
+ negotiation: CapabilityNegotiationSchema.optional()
480
+ });
481
+
482
+ export const AccessPermissionKeySchema = z.enum([
483
+ "policy:read",
484
+ "policy:write",
485
+ "policy:publish",
486
+ "policy:simulate",
487
+ "execution:read",
488
+ "execution:export",
489
+ "approval:read",
490
+ "approval:decide",
491
+ "approval:configure",
492
+ "audit:read",
493
+ "audit:export",
494
+ "audit:retention:manage",
495
+ "connector:read",
496
+ "connector:connect",
497
+ "connector:disconnect",
498
+ "workspace:user:invite",
499
+ "workspace:user:role:set",
500
+ "workspace:delete",
501
+ "service-account:read",
502
+ "service-account:write",
503
+ "service-account:token:rotate"
504
+ ]);
505
+
506
+ export const AccessRoleScopeSchema = z.enum(["org", "workspace", "environment"]);
507
+
508
+ export const AccessRoleSchema = z.object({
509
+ id: z.string().min(1),
510
+ key: z.string().min(1),
511
+ name: z.string().min(1),
512
+ description: z.string().optional(),
513
+ scope: AccessRoleScopeSchema,
514
+ permissions: z.array(AccessPermissionKeySchema),
515
+ isBuiltIn: z.boolean(),
516
+ createdAt: z.string().datetime().optional(),
517
+ updatedAt: z.string().datetime().optional()
518
+ });
519
+
520
+ export const AccessSubjectTypeSchema = z.enum(["user", "group", "serviceAccount"]);
521
+
522
+ export const AccessRoleBindingSchema = z.object({
523
+ id: z.string().min(1),
524
+ scopeType: AccessRoleScopeSchema,
525
+ scopeId: z.string().min(1),
526
+ subjectType: AccessSubjectTypeSchema,
527
+ subjectId: z.string().min(1),
528
+ roleKey: z.string().min(1),
529
+ createdAt: z.string().datetime().optional(),
530
+ createdBy: z.string().optional()
531
+ });
532
+
533
+ export const ServiceAccountStatusSchema = z.enum(["active", "disabled"]);
534
+
535
+ export const ServiceAccountSchema = z.object({
536
+ id: z.string().min(1),
537
+ name: z.string().min(1),
538
+ description: z.string().optional(),
539
+ workspaceId: z.string().min(1),
540
+ environmentKey: z.string().min(1).nullable().optional(),
541
+ status: ServiceAccountStatusSchema,
542
+ createdAt: z.string().datetime(),
543
+ createdByUserId: z.string().min(1),
544
+ updatedAt: z.string().datetime().optional(),
545
+ disabledAt: z.string().datetime().nullable().optional()
546
+ });
547
+
548
+ export const AgentIdentityStatusSchema = z.enum(["active", "disabled"]);
549
+
550
+ export const AgentProfileSchema = z.object({
551
+ id: z.string().min(1),
552
+ workspaceId: z.string().min(1),
553
+ name: z.string().min(1),
554
+ description: z.string().optional(),
555
+ environmentKey: z.string().min(1).nullable().optional(),
556
+ status: AgentIdentityStatusSchema,
557
+ createdAt: z.string().datetime(),
558
+ updatedAt: z.string().datetime().optional(),
559
+ disabledAt: z.string().datetime().nullable().optional(),
560
+ createdByUserId: z.string().min(1)
561
+ });
562
+
563
+ export const AgentKeyStatusSchema = z.enum(["active", "revoked"]);
564
+
565
+ export const AgentKeyMetadataSchema = z.object({
566
+ keyId: z.string().min(1),
567
+ workspaceId: z.string().min(1),
568
+ agentId: z.string().min(1),
569
+ name: z.string().min(1),
570
+ keyPrefix: z.string().min(1),
571
+ scopes: z.array(z.string().min(1)).default([]),
572
+ rateLimitPerMinute: z.number().int().positive(),
573
+ status: AgentKeyStatusSchema,
574
+ createdAt: z.string().datetime(),
575
+ revokedAt: z.string().datetime().nullable().optional()
576
+ });
577
+
578
+ export const AgentTokenClaimsSchema = z.object({
579
+ tokenUse: z.literal("agent_execution"),
580
+ tokenVersion: z.string().min(1).default("v1"),
581
+ iss: z.string().min(1),
582
+ sub: z.string().min(1),
583
+ aud: z.string().min(1),
584
+ jti: z.string().min(1),
585
+ workspaceId: z.string().min(1),
586
+ agentId: z.string().min(1),
587
+ scopes: z.array(z.string().min(1)).default([]),
588
+ iat: z.string().datetime(),
589
+ exp: z.string().datetime().nullable().optional()
590
+ });
591
+
592
+ export const AgentExecutionTokenIssueRequestSchema = z.object({
593
+ scopes: z.array(z.string().min(1)).min(1),
594
+ ttlSeconds: z.number().int().min(1).max(3600).default(900)
595
+ });
596
+
597
+ export const AgentExecutionTokenIssueResponseSchema = z.object({
598
+ token: z.string().min(1),
599
+ expiresAt: z.string().datetime(),
600
+ claims: AgentTokenClaimsSchema
601
+ });
602
+
603
+ export const AgentCapabilitySourceSchema = z.enum(["manual", "role", "token"]);
604
+ export const AgentCapabilityStatusSchema = z.enum(["active", "disabled"]);
605
+
606
+ export const AgentCapabilitySchema = z.object({
607
+ id: z.string().min(1),
608
+ workspaceId: z.string().min(1),
609
+ agentId: z.string().min(1),
610
+ capability: z.string().min(1),
611
+ source: AgentCapabilitySourceSchema,
612
+ status: AgentCapabilityStatusSchema,
613
+ createdAt: z.string().datetime(),
614
+ updatedAt: z.string().datetime()
615
+ });
616
+
617
+ export const AgentDelegationTargetTypeSchema = z.enum(["agent", "tool", "runtime"]);
618
+ export const AgentDelegationEffectSchema = z.enum(["allow", "deny"]);
619
+ export const AgentDelegationStatusSchema = z.enum(["active", "disabled"]);
620
+
621
+ export const AgentDelegationRuleSchema = z.object({
622
+ id: z.string().min(1),
623
+ workspaceId: z.string().min(1),
624
+ sourceAgentId: z.string().min(1),
625
+ targetType: AgentDelegationTargetTypeSchema,
626
+ targetId: z.string().min(1),
627
+ capability: z.string().min(1),
628
+ effect: AgentDelegationEffectSchema,
629
+ status: AgentDelegationStatusSchema,
630
+ createdAt: z.string().datetime(),
631
+ updatedAt: z.string().datetime()
632
+ });
633
+
634
+ export const AgentRevocationEscalationLevelSchema = z.enum([
635
+ "none",
636
+ "low",
637
+ "medium",
638
+ "high",
639
+ "critical"
640
+ ]);
641
+
642
+ export const AgentRevocationEventSchema = z.object({
643
+ id: z.string().min(1),
644
+ workspaceId: z.string().min(1),
645
+ agentId: z.string().min(1),
646
+ reasonCode: z.string().min(1),
647
+ reasonText: z.string().min(1).nullable().optional(),
648
+ escalationLevel: AgentRevocationEscalationLevelSchema,
649
+ requestedByUserId: z.string().min(1),
650
+ correlationId: z.string().min(1).nullable().optional(),
651
+ tokenRevocationCount: z.number().int().nonnegative(),
652
+ previousStatus: AgentIdentityStatusSchema,
653
+ currentStatus: AgentIdentityStatusSchema,
654
+ effectiveAt: z.string().datetime(),
655
+ propagationWindowSeconds: z.number().int().nonnegative(),
656
+ createdAt: z.string().datetime()
657
+ });
658
+
659
+ export const AgentEscalationSourceSchema = z.enum(["manual", "runtime", "delegation", "revocation"]);
660
+ export const AgentEscalationSeveritySchema = z.enum(["low", "medium", "high", "critical"]);
661
+ export const AgentEscalationStatusSchema = z.enum(["open", "acknowledged", "resolved"]);
662
+
663
+ export const AgentEscalationEventSchema = z.object({
664
+ id: z.string().min(1),
665
+ workspaceId: z.string().min(1),
666
+ agentId: z.string().min(1),
667
+ source: AgentEscalationSourceSchema,
668
+ severity: AgentEscalationSeveritySchema,
669
+ status: AgentEscalationStatusSchema,
670
+ summary: z.string().min(1),
671
+ details: z.record(z.unknown()).optional(),
672
+ createdByUserId: z.string().min(1),
673
+ createdAt: z.string().datetime(),
674
+ updatedAt: z.string().datetime(),
675
+ resolvedAt: z.string().datetime().nullable().optional(),
676
+ resolutionNote: z.string().nullable().optional()
677
+ });
678
+
679
+ export const UsageTimeframeSchema = z.enum(["7d", "30d", "90d"]);
680
+ export const UsageBreakdownSchema = z.enum(["total", "allowed", "blocked", "pending"]);
681
+
682
+ export const UsageTimeseriesPointSchema = z.object({
683
+ ts: z.string().datetime(),
684
+ total: z.number().int().nonnegative(),
685
+ allowed: z.number().int().nonnegative(),
686
+ blocked: z.number().int().nonnegative(),
687
+ pending: z.number().int().nonnegative(),
688
+ environmentKey: z.string().min(1).optional()
689
+ });
690
+
691
+ export const UsageTimeseriesResponseSchema = z.object({
692
+ workspaceId: z.string().min(1),
693
+ timeframe: UsageTimeframeSchema,
694
+ breakdown: UsageBreakdownSchema,
695
+ points: z.array(UsageTimeseriesPointSchema)
696
+ });
697
+
698
+ export const TimelineEntityTypeSchema = z.enum(["route", "policy", "change-request"]);
699
+
700
+ export const TimelineEventSchema = z.object({
701
+ id: z.string().min(1),
702
+ entityType: TimelineEntityTypeSchema,
703
+ entityId: z.string().min(1),
704
+ action: z.string().min(1),
705
+ summary: z.string().min(1),
706
+ actor: z.string().min(1),
707
+ occurredAt: z.string().datetime(),
708
+ versionId: z.string().min(1).optional(),
709
+ versionNumber: z.number().int().positive().optional(),
710
+ environmentKey: z.string().min(1).optional(),
711
+ metadata: z.record(z.unknown()).optional()
712
+ });
713
+
714
+ export const RouteTimelineResponseSchema = z.object({
715
+ routeId: z.string().min(1),
716
+ events: z.array(TimelineEventSchema)
717
+ });
718
+
719
+ export const PolicyTimelineResponseSchema = z.object({
720
+ policyId: z.string().min(1),
721
+ events: z.array(TimelineEventSchema)
722
+ });
723
+
724
+ export const ChangeRequestTimelineResponseSchema = z.object({
725
+ changeRequestId: z.string().min(1),
726
+ events: z.array(TimelineEventSchema)
727
+ });
728
+
729
+ export const LineageNodeTypeSchema = z.enum([
730
+ "run",
731
+ "policyDecision",
732
+ "approval",
733
+ "artifact",
734
+ "export",
735
+ "changeRequest",
736
+ "route",
737
+ "policy",
738
+ "workflowVersion",
739
+ "riskScore",
740
+ "agent",
741
+ "prompt",
742
+ "model",
743
+ "tool",
744
+ "api",
745
+ "dataset",
746
+ "risk",
747
+ "outcome"
748
+ ]);
749
+
750
+ export const LineageNodeSchema = z.object({
751
+ id: z.string().min(1),
752
+ type: LineageNodeTypeSchema,
753
+ label: z.string().optional(),
754
+ occurredAt: z.string().datetime().optional(),
755
+ attributes: z.record(z.unknown()).optional()
756
+ });
757
+
758
+ export const LineageEdgeSchema = z.object({
759
+ id: z.string().min(1),
760
+ from: z.string().min(1),
761
+ to: z.string().min(1),
762
+ relation: z.string().min(1),
763
+ occurredAt: z.string().datetime().optional(),
764
+ attributes: z.record(z.unknown()).optional()
765
+ });
766
+
767
+ export const LineageQueryRequestSchema = z.object({
768
+ workspaceId: z.string().min(1),
769
+ rootNodeId: z.string().min(1),
770
+ maxDepth: z.number().int().min(1).max(8).default(3),
771
+ includeRelations: z.array(z.string().min(1)).optional(),
772
+ since: z.string().datetime().optional(),
773
+ until: z.string().datetime().optional()
774
+ });
775
+
776
+ export const LineageQueryResponseSchema = z.object({
777
+ workspaceId: z.string().min(1),
778
+ rootNodeId: z.string().min(1),
779
+ depth: z.number().int().min(1),
780
+ nodes: z.array(LineageNodeSchema),
781
+ edges: z.array(LineageEdgeSchema)
782
+ });
783
+
784
+ export const RiskTierSchema = z.enum(["low", "med", "high", "critical"]);
785
+ export const RiskSubjectTypeSchema = z.enum([
786
+ "run",
787
+ "changeRequest",
788
+ "route",
789
+ "policy",
790
+ "workspace"
791
+ ]);
792
+
793
+ export const RiskFactorSchema = z.object({
794
+ key: z.string().min(1),
795
+ weight: z.number(),
796
+ value: z.number(),
797
+ reason: z.string().optional()
798
+ });
799
+
800
+ export const RiskScoreCheckRequestSchema = z.object({
801
+ workspaceId: z.string().min(1),
802
+ subjectType: RiskSubjectTypeSchema,
803
+ subjectId: z.string().min(1),
804
+ context: z.record(z.unknown()).optional()
805
+ });
806
+
807
+ export const RiskScoreResultSchema = z.object({
808
+ score: z.number().min(0).max(100),
809
+ tier: RiskTierSchema,
810
+ evaluatedAt: z.string().datetime(),
811
+ factors: z.array(RiskFactorSchema).default([])
812
+ });
813
+
814
+ export const RiskScoreCheckResponseSchema = z.object({
815
+ workspaceId: z.string().min(1),
816
+ subjectType: RiskSubjectTypeSchema,
817
+ subjectId: z.string().min(1),
818
+ result: RiskScoreResultSchema
819
+ });
820
+
821
+ export const RiskTrendWindowSchema = z.enum(["24h", "7d", "30d", "90d"]);
822
+
823
+ export const RiskTrendPointSchema = z.object({
824
+ ts: z.string().datetime(),
825
+ avgScore: z.number().min(0).max(100),
826
+ p95Score: z.number().min(0).max(100),
827
+ highCount: z.number().int().nonnegative(),
828
+ criticalCount: z.number().int().nonnegative()
829
+ });
830
+
831
+ export const RiskTrendResponseSchema = z.object({
832
+ workspaceId: z.string().min(1),
833
+ window: RiskTrendWindowSchema,
834
+ points: z.array(RiskTrendPointSchema)
835
+ });
836
+
837
+ export const RiskBaselineWindowSchema = z.enum(["7d", "30d", "90d"]);
838
+
839
+ export const RiskBaselineSchema = z.object({
840
+ id: z.string().min(1),
841
+ workspaceId: z.string().min(1),
842
+ subjectType: RiskSubjectTypeSchema,
843
+ subjectId: z.string().min(1),
844
+ window: RiskBaselineWindowSchema,
845
+ sampleSize: z.number().int().nonnegative(),
846
+ avgScore: z.number().min(0).max(100),
847
+ p95Score: z.number().min(0).max(100),
848
+ highRate: z.number().min(0).max(1),
849
+ criticalRate: z.number().min(0).max(1),
850
+ capturedAt: z.string().datetime()
851
+ });
852
+
853
+ export const RiskBaselineCaptureRequestSchema = z.object({
854
+ workspaceId: z.string().min(1),
855
+ window: RiskBaselineWindowSchema.default("30d"),
856
+ subjectType: RiskSubjectTypeSchema.optional(),
857
+ subjectId: z.string().min(1).optional()
858
+ });
859
+
860
+ export const RiskBaselineCaptureResponseSchema = z.object({
861
+ workspaceId: z.string().min(1),
862
+ window: RiskBaselineWindowSchema,
863
+ capturedAt: z.string().datetime(),
864
+ baselines: z.array(RiskBaselineSchema).default([])
865
+ });
866
+
867
+ export const RiskSignalTypeSchema = z.enum([
868
+ "score_spike",
869
+ "tier_escalation",
870
+ "high_risk_density"
871
+ ]);
872
+
873
+ export const RiskSignalSeveritySchema = z.enum(["low", "med", "high", "critical"]);
874
+
875
+ export const RiskAnomalySignalSchema = z.object({
876
+ id: z.string().min(1),
877
+ workspaceId: z.string().min(1),
878
+ subjectType: RiskSubjectTypeSchema,
879
+ subjectId: z.string().min(1),
880
+ riskScoreId: z.string().min(1),
881
+ baselineId: z.string().min(1),
882
+ signalType: RiskSignalTypeSchema,
883
+ severity: RiskSignalSeveritySchema,
884
+ score: z.number().min(0).max(100),
885
+ baselineScore: z.number().min(0).max(100),
886
+ delta: z.number(),
887
+ details: z.record(z.unknown()).default({}),
888
+ detectedAt: z.string().datetime()
889
+ });
890
+
891
+ export const RiskSignalGenerateRequestSchema = z.object({
892
+ workspaceId: z.string().min(1),
893
+ lookbackHours: z.number().int().min(1).max(168).default(24),
894
+ subjectType: RiskSubjectTypeSchema.optional(),
895
+ subjectId: z.string().min(1).optional()
896
+ });
897
+
898
+ export const RiskSignalGenerateResponseSchema = z.object({
899
+ workspaceId: z.string().min(1),
900
+ lookbackHours: z.number().int().min(1).max(168),
901
+ generatedCount: z.number().int().nonnegative(),
902
+ signals: z.array(RiskAnomalySignalSchema).default([])
903
+ });
904
+
905
+ export const RiskSignalListResponseSchema = z.object({
906
+ workspaceId: z.string().min(1),
907
+ lookbackHours: z.number().int().min(1).max(168),
908
+ signals: z.array(RiskAnomalySignalSchema).default([])
909
+ });
910
+
911
+ export const DriftDimensionSchema = z.enum(["prompt", "tool", "model", "data", "risk"]);
912
+ export const DriftSignalSeveritySchema = z.enum(["low", "med", "high", "critical"]);
913
+ export const DriftMetricKeySchema = z.enum(["risk_score_avg"]);
914
+
915
+ export const DriftMetricBaselineSchema = z.object({
916
+ id: z.string().min(1),
917
+ workspaceId: z.string().min(1),
918
+ dimension: DriftDimensionSchema,
919
+ entityKey: z.string().min(1),
920
+ metricKey: DriftMetricKeySchema,
921
+ lookbackHours: z.number().int().min(1).max(168),
922
+ sampleSize: z.number().int().nonnegative(),
923
+ avgScore: z.number().min(0).max(100),
924
+ p95Score: z.number().min(0).max(100),
925
+ highRate: z.number().min(0).max(1),
926
+ criticalRate: z.number().min(0).max(1),
927
+ capturedAt: z.string().datetime()
928
+ });
929
+
930
+ export const DriftSignalSchema = z.object({
931
+ id: z.string().min(1),
932
+ workspaceId: z.string().min(1),
933
+ dimension: DriftDimensionSchema,
934
+ entityKey: z.string().min(1),
935
+ metricKey: DriftMetricKeySchema,
936
+ baselineId: z.string().min(1),
937
+ sampleSize: z.number().int().nonnegative(),
938
+ baselineSampleSize: z.number().int().nonnegative(),
939
+ score: z.number().min(0).max(100),
940
+ baselineScore: z.number().min(0).max(100),
941
+ delta: z.number(),
942
+ deltaRatio: z.number(),
943
+ severity: DriftSignalSeveritySchema,
944
+ details: z.record(z.unknown()).default({}),
945
+ detectedAt: z.string().datetime()
946
+ });
947
+
948
+ export const DriftSignalGenerateRequestSchema = z.object({
949
+ workspaceId: z.string().min(1),
950
+ lookbackHours: z.number().int().min(1).max(168).default(24),
951
+ dimension: DriftDimensionSchema.optional(),
952
+ entityKey: z.string().min(1).optional()
953
+ });
954
+
955
+ export const DriftSignalGenerateResponseSchema = z.object({
956
+ workspaceId: z.string().min(1),
957
+ lookbackHours: z.number().int().min(1).max(168),
958
+ generatedAt: z.string().datetime(),
959
+ generatedCount: z.number().int().nonnegative(),
960
+ signals: z.array(DriftSignalSchema).default([])
961
+ });
962
+
963
+ export const DriftSignalListResponseSchema = z.object({
964
+ workspaceId: z.string().min(1),
965
+ lookbackHours: z.number().int().min(1).max(168),
966
+ limit: z.number().int().min(1).max(500).optional(),
967
+ nextCursor: z.string().datetime().optional(),
968
+ signals: z.array(DriftSignalSchema).default([])
969
+ });
970
+
971
+ export const SandboxSimulationStatusSchema = z.enum([
972
+ "queued",
973
+ "running",
974
+ "succeeded",
975
+ "failed",
976
+ "canceled"
977
+ ]);
978
+
979
+ export const SandboxSimulationRequestSchema = z.object({
980
+ workspaceId: z.string().min(1),
981
+ scenarioKey: z.string().min(1),
982
+ input: z.record(z.unknown()).default({}),
983
+ initiatedBy: z.string().min(1).optional()
984
+ });
985
+
986
+ export const SandboxSimulationArtifactSchema = z.object({
987
+ id: z.string().min(1),
988
+ type: z.string().min(1),
989
+ path: z.string().min(1),
990
+ sha256: z.string().optional()
991
+ });
992
+
993
+ export const SandboxPolicyPreviewSchema = z.object({
994
+ blocked: z.boolean(),
995
+ decisionCount: z.number().int().nonnegative(),
996
+ denyCount: z.number().int().nonnegative(),
997
+ decisions: z.array(PolicyDecisionSchema).default([])
998
+ });
999
+
1000
+ export const SandboxRiskPreviewSchema = z.object({
1001
+ subjectType: RiskSubjectTypeSchema,
1002
+ subjectId: z.string().min(1),
1003
+ result: RiskScoreResultSchema
1004
+ });
1005
+
1006
+ export const SandboxSimulationResultSchema = z.object({
1007
+ decision: z.enum(["allow", "deny", "partial"]).optional(),
1008
+ summary: z.string().optional(),
1009
+ metrics: z.record(z.number()).optional(),
1010
+ artifacts: z.array(SandboxSimulationArtifactSchema).default([]),
1011
+ policyPreview: SandboxPolicyPreviewSchema.optional(),
1012
+ riskPreview: SandboxRiskPreviewSchema.optional()
1013
+ });
1014
+
1015
+ export const SandboxSimulationRunSchema = z.object({
1016
+ simulationId: z.string().min(1),
1017
+ workspaceId: z.string().min(1),
1018
+ scenarioKey: z.string().min(1),
1019
+ status: SandboxSimulationStatusSchema,
1020
+ createdAt: z.string().datetime(),
1021
+ startedAt: z.string().datetime().optional(),
1022
+ finishedAt: z.string().datetime().optional(),
1023
+ result: SandboxSimulationResultSchema.optional()
1024
+ });
1025
+
1026
+ export const SandboxSimulationListResponseSchema = z.object({
1027
+ workspaceId: z.string().min(1),
1028
+ limit: z.number().int().min(1).max(200),
1029
+ nextCursor: z.string().datetime().optional(),
1030
+ simulations: z.array(SandboxSimulationRunSchema).default([])
1031
+ });
1032
+
1033
+ export const SandboxSimulationReplayResponseSchema = z.object({
1034
+ workspaceId: z.string().min(1),
1035
+ sourceSimulationId: z.string().min(1),
1036
+ simulation: SandboxSimulationRunSchema
1037
+ });
1038
+
1039
+ export const DataBoundaryPolicyModeSchema = z.enum(["monitor", "enforce"]);
1040
+ export const DataBoundaryPolicyStatusSchema = z.enum(["draft", "active", "disabled"]);
1041
+ export const DataBoundaryDecisionActionSchema = z.enum([
1042
+ "allow",
1043
+ "block",
1044
+ "redact",
1045
+ "mask",
1046
+ "escalate"
1047
+ ]);
1048
+ export const DataBoundaryMaskingStrategySchema = z.enum(["full", "partial", "hash", "tokenize"]);
1049
+ export const DataBoundaryRuleTargetSchema = z.enum([
1050
+ "input",
1051
+ "output",
1052
+ "tool_call",
1053
+ "payload",
1054
+ "metadata"
1055
+ ]);
1056
+
1057
+ export const DataBoundaryRuleSchema = z.object({
1058
+ id: z.string().min(1),
1059
+ ruleKey: z.string().min(1),
1060
+ description: z.string().optional(),
1061
+ classification: z.string().min(1),
1062
+ tags: z.array(z.string().min(1)).default([]),
1063
+ target: DataBoundaryRuleTargetSchema,
1064
+ matchPattern: z.string().min(1),
1065
+ action: DataBoundaryDecisionActionSchema,
1066
+ maskingStrategy: DataBoundaryMaskingStrategySchema.optional(),
1067
+ enabled: z.boolean().default(true),
1068
+ createdAt: z.string().datetime().optional(),
1069
+ updatedAt: z.string().datetime().optional()
1070
+ });
1071
+
1072
+ export const DataBoundaryPolicySchema = z.object({
1073
+ id: z.string().min(1),
1074
+ workspaceId: z.string().min(1),
1075
+ name: z.string().min(1),
1076
+ description: z.string().optional(),
1077
+ mode: DataBoundaryPolicyModeSchema,
1078
+ status: DataBoundaryPolicyStatusSchema,
1079
+ defaultAction: DataBoundaryDecisionActionSchema,
1080
+ regionAllowlist: z.array(z.string().min(1)).default([]),
1081
+ modelAllowlist: z.array(z.string().min(1)).default([]),
1082
+ rules: z.array(DataBoundaryRuleSchema).default([]),
1083
+ createdBy: z.string().min(1),
1084
+ createdAt: z.string().datetime(),
1085
+ updatedAt: z.string().datetime()
1086
+ });
1087
+
1088
+ export const DataBoundaryRuleUpsertInputSchema = DataBoundaryRuleSchema.omit({
1089
+ id: true,
1090
+ createdAt: true,
1091
+ updatedAt: true
1092
+ });
1093
+
1094
+ export const DataBoundaryPolicyCreateRequestSchema = z.object({
1095
+ workspaceId: z.string().min(1),
1096
+ name: z.string().min(1),
1097
+ description: z.string().optional(),
1098
+ mode: DataBoundaryPolicyModeSchema.default("enforce"),
1099
+ status: DataBoundaryPolicyStatusSchema.default("active"),
1100
+ defaultAction: DataBoundaryDecisionActionSchema.default("allow"),
1101
+ regionAllowlist: z.array(z.string().min(1)).default([]),
1102
+ modelAllowlist: z.array(z.string().min(1)).default([]),
1103
+ rules: z.array(DataBoundaryRuleUpsertInputSchema).min(1)
1104
+ });
1105
+
1106
+ export const DataBoundaryPolicyUpdateRequestSchema = z
1107
+ .object({
1108
+ workspaceId: z.string().min(1),
1109
+ policyId: z.string().min(1),
1110
+ name: z.string().min(1).optional(),
1111
+ description: z.string().optional(),
1112
+ mode: DataBoundaryPolicyModeSchema.optional(),
1113
+ status: DataBoundaryPolicyStatusSchema.optional(),
1114
+ defaultAction: DataBoundaryDecisionActionSchema.optional(),
1115
+ regionAllowlist: z.array(z.string().min(1)).optional(),
1116
+ modelAllowlist: z.array(z.string().min(1)).optional(),
1117
+ rules: z.array(DataBoundaryRuleUpsertInputSchema).min(1).optional()
1118
+ })
1119
+ .refine(
1120
+ (value) =>
1121
+ value.name !== undefined ||
1122
+ value.description !== undefined ||
1123
+ value.mode !== undefined ||
1124
+ value.status !== undefined ||
1125
+ value.defaultAction !== undefined ||
1126
+ value.regionAllowlist !== undefined ||
1127
+ value.modelAllowlist !== undefined ||
1128
+ value.rules !== undefined,
1129
+ { message: "at least one update field is required", path: ["policyId"] }
1130
+ );
1131
+
1132
+ export const DataBoundaryPolicyListResponseSchema = z.object({
1133
+ workspaceId: z.string().min(1),
1134
+ policies: z.array(DataBoundaryPolicySchema).default([])
1135
+ });
1136
+
1137
+ export const DataBoundaryDecisionSchema = z.object({
1138
+ action: DataBoundaryDecisionActionSchema,
1139
+ reasonCode: z.string().min(1),
1140
+ reasonText: z.string().min(1),
1141
+ policyId: z.string().min(1).optional(),
1142
+ ruleId: z.string().min(1).optional(),
1143
+ classification: z.string().min(1).optional(),
1144
+ tags: z.array(z.string().min(1)).default([]),
1145
+ maskedFields: z.array(z.string().min(1)).default([])
1146
+ });
1147
+
1148
+ export const DataBoundaryEvaluateRequestSchema = z.object({
1149
+ workspaceId: z.string().min(1),
1150
+ payload: z.record(z.unknown()),
1151
+ context: z.record(z.unknown()).optional()
1152
+ });
1153
+
1154
+ export const DataBoundaryEvaluateResponseSchema = z.object({
1155
+ workspaceId: z.string().min(1),
1156
+ decision: DataBoundaryDecisionSchema,
1157
+ evaluatedAt: z.string().datetime()
1158
+ });
1159
+
1160
+ export const FirewallInspectionModeSchema = z.enum(["monitor", "enforce"]);
1161
+ export const FirewallInspectionTargetSchema = z.enum(["input", "output", "tool_call", "payload"]);
1162
+ export const FirewallDecisionActionSchema = z.enum(["allow", "sanitize", "deny"]);
1163
+ export const FirewallFindingSeveritySchema = z.enum(["low", "med", "high", "critical"]);
1164
+ export const FirewallFindingCategorySchema = z.enum([
1165
+ "prompt_injection",
1166
+ "secret",
1167
+ "pii",
1168
+ "malicious_payload"
1169
+ ]);
1170
+
1171
+ export const FirewallInspectFindingSchema = z.object({
1172
+ ruleKey: z.string().min(1),
1173
+ category: FirewallFindingCategorySchema,
1174
+ severity: FirewallFindingSeveritySchema,
1175
+ target: FirewallInspectionTargetSchema,
1176
+ fieldPath: z.string().min(1),
1177
+ matchPreview: z.string().min(1)
1178
+ });
1179
+
1180
+ export const FirewallInspectRequestSchema = z.object({
1181
+ workspaceId: z.string().min(1),
1182
+ payload: z.record(z.unknown()),
1183
+ target: FirewallInspectionTargetSchema.default("payload"),
1184
+ context: z.record(z.unknown()).optional(),
1185
+ mode: FirewallInspectionModeSchema.default("monitor")
1186
+ });
1187
+
1188
+ export const FirewallInspectResultSchema = z.object({
1189
+ action: FirewallDecisionActionSchema,
1190
+ reasonCode: z.string().min(1),
1191
+ reasonText: z.string().min(1),
1192
+ findings: z.array(FirewallInspectFindingSchema).default([]),
1193
+ redactions: z.array(z.string().min(1)).default([]),
1194
+ blockedTools: z.array(z.string().min(1)).default([]),
1195
+ blockedDomains: z.array(z.string().min(1)).default([]),
1196
+ sanitizedPayload: z.record(z.unknown()).optional(),
1197
+ score: z.number().int().nonnegative()
1198
+ });
1199
+
1200
+ export const FirewallInspectResponseSchema = z.object({
1201
+ workspaceId: z.string().min(1),
1202
+ inspectedAt: z.string().datetime(),
1203
+ result: FirewallInspectResultSchema,
1204
+ eventId: z.string().min(1).optional()
1205
+ });
1206
+
1207
+ export const FirewallEventSchema = z.object({
1208
+ eventId: z.string().min(1),
1209
+ workspaceId: z.string().min(1),
1210
+ actorId: z.string().min(1),
1211
+ action: z.string().min(1),
1212
+ resourceId: z.string().min(1),
1213
+ resultAction: FirewallDecisionActionSchema,
1214
+ findingsCount: z.number().int().nonnegative(),
1215
+ highestSeverity: FirewallFindingSeveritySchema.optional(),
1216
+ reasonCode: z.string().min(1).optional(),
1217
+ occurredAt: z.string().datetime()
1218
+ });
1219
+
1220
+ export const FirewallEventsResponseSchema = z.object({
1221
+ workspaceId: z.string().min(1),
1222
+ events: z.array(FirewallEventSchema).default([])
1223
+ });
1224
+
1225
+ export const EdgeInterceptorModeSchema = z.enum(["sdk", "sidecar", "proxy"]);
1226
+ export const EdgeInterceptorStatusSchema = z.enum(["active", "disabled"]);
1227
+
1228
+ export const EdgeInterceptorRegisterRequestSchema = z.object({
1229
+ workspaceId: z.string().min(1),
1230
+ mode: EdgeInterceptorModeSchema,
1231
+ deploymentId: z.string().min(1).optional(),
1232
+ sdkVersion: z.string().min(1).optional(),
1233
+ region: z.string().min(1).optional(),
1234
+ capabilities: z.array(z.string().min(1)).default([])
1235
+ });
1236
+
1237
+ export const EdgeInterceptorRegistrationSchema = z.object({
1238
+ registrationId: z.string().min(1),
1239
+ workspaceId: z.string().min(1),
1240
+ mode: EdgeInterceptorModeSchema,
1241
+ deploymentId: z.string().min(1).optional(),
1242
+ sdkVersion: z.string().min(1).optional(),
1243
+ region: z.string().min(1).optional(),
1244
+ capabilities: z.array(z.string().min(1)).default([]),
1245
+ status: EdgeInterceptorStatusSchema,
1246
+ createdAt: z.string().datetime(),
1247
+ updatedAt: z.string().datetime()
1248
+ });
1249
+
1250
+ export type AuthSession = z.infer<typeof AuthSessionSchema>;
1251
+ export type WorkspaceRoleBinding = z.infer<typeof WorkspaceRoleBindingSchema>;
1252
+ export type WorkflowVersion = z.infer<typeof WorkflowVersionSchema>;
1253
+ export type WorkflowBuilderNode = z.infer<typeof WorkflowBuilderNodeSchema>;
1254
+ export type WorkflowBuilderEdge = z.infer<typeof WorkflowBuilderEdgeSchema>;
1255
+ export type WorkflowBuilderViewport = z.infer<typeof WorkflowBuilderViewportSchema>;
1256
+ export type WorkflowBuilderDocument = z.infer<typeof WorkflowBuilderDocumentSchema>;
1257
+ export type PolicyDecision = z.infer<typeof PolicyDecisionSchema>;
1258
+ export type PolicyExitGateEvidence = z.infer<typeof PolicyExitGateEvidenceSchema>;
1259
+ export type RunState = z.infer<typeof RunStateSchema>;
1260
+ export type HeadlessRunRequest = z.infer<typeof HeadlessRunRequestSchema>;
1261
+ export type StructuredErrorEnvelope = z.infer<typeof StructuredErrorEnvelopeSchema>;
1262
+ export type CanonicalPolicyRef = z.infer<typeof CanonicalPolicyRefSchema>;
1263
+ export type CanonicalRouteRef = z.infer<typeof CanonicalRouteRefSchema>;
1264
+ export type CanonicalRiskMeta = z.infer<typeof CanonicalRiskMetaSchema>;
1265
+ export type CanonicalTimingMs = z.infer<typeof CanonicalTimingMsSchema>;
1266
+ export type CanonicalResponseMeta = z.infer<typeof CanonicalResponseMetaSchema>;
1267
+ export type CanonicalErrorCode = z.infer<typeof CanonicalErrorCodeSchema>;
1268
+ export type CanonicalError = z.infer<typeof CanonicalErrorSchema>;
1269
+ export type V4SessionStartRequest = z.infer<typeof V4SessionStartRequestSchema>;
1270
+ export type V4SessionResource = z.infer<typeof V4SessionResourceSchema>;
1271
+ export type V4ExecutionRequest = z.infer<typeof V4ExecutionRequestSchema>;
1272
+ export type V4ExecutionResult = z.infer<typeof V4ExecutionResultSchema>;
1273
+ export type V4EphemeralExecuteRequest = z.infer<typeof V4EphemeralExecuteRequestSchema>;
1274
+ export type RunStateTransition = z.infer<typeof RunStateTransitionSchema>;
1275
+ export type EntitlementDecision = z.infer<typeof EntitlementDecisionSchema>;
1276
+ export type ArtifactManifestItem = z.infer<typeof ArtifactManifestItemSchema>;
1277
+ export type ControlFailure = z.infer<typeof ControlFailureSchema>;
1278
+ export type ControlJobState = z.infer<typeof ControlJobStateSchema>;
1279
+ export type ControlJob = z.infer<typeof ControlJobSchema>;
1280
+ export type ControlJobAttempt = z.infer<typeof ControlJobAttemptSchema>;
1281
+ export type ControlJobEvent = z.infer<typeof ControlJobEventSchema>;
1282
+ export type ControlBackoffState = z.infer<typeof ControlBackoffStateSchema>;
1283
+ export type ControlSuppressionState = z.infer<typeof ControlSuppressionStateSchema>;
1284
+ export type ControlJobScheduleRequest = z.infer<typeof ControlJobScheduleRequestSchema>;
1285
+ export type ControlJobBlockRequest = z.infer<typeof ControlJobBlockRequestSchema>;
1286
+ export type ControlJobRunNextResponse = z.infer<typeof ControlJobRunNextResponseSchema>;
1287
+ export type GitHubDispatchControlPayload = z.infer<typeof GitHubDispatchControlPayloadSchema>;
1288
+ export type SamlConnection = z.infer<typeof SamlConnectionSchema>;
1289
+ export type ScimProvisioningToken = z.infer<typeof ScimProvisioningTokenSchema>;
1290
+ export type ComplianceFramework = z.infer<typeof ComplianceFrameworkSchema>;
1291
+ export type ComplianceFrameworkControlMapping = z.infer<
1292
+ typeof ComplianceFrameworkControlMappingSchema
1293
+ >;
1294
+ export type ComplianceExportFormat = z.infer<typeof ComplianceExportFormatSchema>;
1295
+ export type CreateComplianceExportRequest = z.infer<typeof CreateComplianceExportRequestSchema>;
1296
+ export type ComplianceExportManifestItem = z.infer<typeof ComplianceExportManifestItemSchema>;
1297
+ export type ComplianceExportExitGate = z.infer<typeof ComplianceExportExitGateSchema>;
1298
+ export type CapabilityStatus = z.infer<typeof CapabilityStatusSchema>;
1299
+ export type CapabilityDescriptor = z.infer<typeof CapabilityDescriptorSchema>;
1300
+ export type ApiSurfaceVersion = z.infer<typeof ApiSurfaceVersionSchema>;
1301
+ export type CapabilityNegotiation = z.infer<typeof CapabilityNegotiationSchema>;
1302
+ export type CapabilitiesResponse = z.infer<typeof CapabilitiesResponseSchema>;
1303
+ export type AccessPermissionKey = z.infer<typeof AccessPermissionKeySchema>;
1304
+ export type AccessRoleScope = z.infer<typeof AccessRoleScopeSchema>;
1305
+ export type AccessRole = z.infer<typeof AccessRoleSchema>;
1306
+ export type AccessSubjectType = z.infer<typeof AccessSubjectTypeSchema>;
1307
+ export type AccessRoleBinding = z.infer<typeof AccessRoleBindingSchema>;
1308
+ export type ServiceAccountStatus = z.infer<typeof ServiceAccountStatusSchema>;
1309
+ export type ServiceAccount = z.infer<typeof ServiceAccountSchema>;
1310
+ export type AgentIdentityStatus = z.infer<typeof AgentIdentityStatusSchema>;
1311
+ export type AgentProfile = z.infer<typeof AgentProfileSchema>;
1312
+ export type AgentKeyStatus = z.infer<typeof AgentKeyStatusSchema>;
1313
+ export type AgentKeyMetadata = z.infer<typeof AgentKeyMetadataSchema>;
1314
+ export type AgentTokenClaims = z.infer<typeof AgentTokenClaimsSchema>;
1315
+ export type AgentExecutionTokenIssueRequest = z.infer<typeof AgentExecutionTokenIssueRequestSchema>;
1316
+ export type AgentExecutionTokenIssueResponse = z.infer<typeof AgentExecutionTokenIssueResponseSchema>;
1317
+ export type AgentCapabilitySource = z.infer<typeof AgentCapabilitySourceSchema>;
1318
+ export type AgentCapabilityStatus = z.infer<typeof AgentCapabilityStatusSchema>;
1319
+ export type AgentCapability = z.infer<typeof AgentCapabilitySchema>;
1320
+ export type AgentDelegationTargetType = z.infer<typeof AgentDelegationTargetTypeSchema>;
1321
+ export type AgentDelegationEffect = z.infer<typeof AgentDelegationEffectSchema>;
1322
+ export type AgentDelegationStatus = z.infer<typeof AgentDelegationStatusSchema>;
1323
+ export type AgentDelegationRule = z.infer<typeof AgentDelegationRuleSchema>;
1324
+ export type AgentRevocationEscalationLevel = z.infer<typeof AgentRevocationEscalationLevelSchema>;
1325
+ export type AgentRevocationEvent = z.infer<typeof AgentRevocationEventSchema>;
1326
+ export type AgentEscalationSource = z.infer<typeof AgentEscalationSourceSchema>;
1327
+ export type AgentEscalationSeverity = z.infer<typeof AgentEscalationSeveritySchema>;
1328
+ export type AgentEscalationStatus = z.infer<typeof AgentEscalationStatusSchema>;
1329
+ export type AgentEscalationEvent = z.infer<typeof AgentEscalationEventSchema>;
1330
+ export type UsageTimeframe = z.infer<typeof UsageTimeframeSchema>;
1331
+ export type UsageBreakdown = z.infer<typeof UsageBreakdownSchema>;
1332
+ export type UsageTimeseriesPoint = z.infer<typeof UsageTimeseriesPointSchema>;
1333
+ export type UsageTimeseriesResponse = z.infer<typeof UsageTimeseriesResponseSchema>;
1334
+ export type TimelineEntityType = z.infer<typeof TimelineEntityTypeSchema>;
1335
+ export type TimelineEvent = z.infer<typeof TimelineEventSchema>;
1336
+ export type RouteTimelineResponse = z.infer<typeof RouteTimelineResponseSchema>;
1337
+ export type PolicyTimelineResponse = z.infer<typeof PolicyTimelineResponseSchema>;
1338
+ export type ChangeRequestTimelineResponse = z.infer<typeof ChangeRequestTimelineResponseSchema>;
1339
+ export type LineageNodeType = z.infer<typeof LineageNodeTypeSchema>;
1340
+ export type LineageNode = z.infer<typeof LineageNodeSchema>;
1341
+ export type LineageEdge = z.infer<typeof LineageEdgeSchema>;
1342
+ export type LineageQueryRequest = z.infer<typeof LineageQueryRequestSchema>;
1343
+ export type LineageQueryResponse = z.infer<typeof LineageQueryResponseSchema>;
1344
+ export type RiskTier = z.infer<typeof RiskTierSchema>;
1345
+ export type RiskSubjectType = z.infer<typeof RiskSubjectTypeSchema>;
1346
+ export type RiskFactor = z.infer<typeof RiskFactorSchema>;
1347
+ export type RiskScoreCheckRequest = z.infer<typeof RiskScoreCheckRequestSchema>;
1348
+ export type RiskScoreResult = z.infer<typeof RiskScoreResultSchema>;
1349
+ export type RiskScoreCheckResponse = z.infer<typeof RiskScoreCheckResponseSchema>;
1350
+ export type RiskTrendWindow = z.infer<typeof RiskTrendWindowSchema>;
1351
+ export type RiskTrendPoint = z.infer<typeof RiskTrendPointSchema>;
1352
+ export type RiskTrendResponse = z.infer<typeof RiskTrendResponseSchema>;
1353
+ export type RiskBaselineWindow = z.infer<typeof RiskBaselineWindowSchema>;
1354
+ export type RiskBaseline = z.infer<typeof RiskBaselineSchema>;
1355
+ export type RiskBaselineCaptureRequest = z.infer<typeof RiskBaselineCaptureRequestSchema>;
1356
+ export type RiskBaselineCaptureResponse = z.infer<typeof RiskBaselineCaptureResponseSchema>;
1357
+ export type RiskSignalType = z.infer<typeof RiskSignalTypeSchema>;
1358
+ export type RiskSignalSeverity = z.infer<typeof RiskSignalSeveritySchema>;
1359
+ export type RiskAnomalySignal = z.infer<typeof RiskAnomalySignalSchema>;
1360
+ export type RiskSignalGenerateRequest = z.infer<typeof RiskSignalGenerateRequestSchema>;
1361
+ export type RiskSignalGenerateResponse = z.infer<typeof RiskSignalGenerateResponseSchema>;
1362
+ export type RiskSignalListResponse = z.infer<typeof RiskSignalListResponseSchema>;
1363
+ export type DriftDimension = z.infer<typeof DriftDimensionSchema>;
1364
+ export type DriftSignalSeverity = z.infer<typeof DriftSignalSeveritySchema>;
1365
+ export type DriftMetricKey = z.infer<typeof DriftMetricKeySchema>;
1366
+ export type DriftMetricBaseline = z.infer<typeof DriftMetricBaselineSchema>;
1367
+ export type DriftSignal = z.infer<typeof DriftSignalSchema>;
1368
+ export type DriftSignalGenerateRequest = z.infer<typeof DriftSignalGenerateRequestSchema>;
1369
+ export type DriftSignalGenerateResponse = z.infer<typeof DriftSignalGenerateResponseSchema>;
1370
+ export type DriftSignalListResponse = z.infer<typeof DriftSignalListResponseSchema>;
1371
+ export type SandboxSimulationStatus = z.infer<typeof SandboxSimulationStatusSchema>;
1372
+ export type SandboxSimulationRequest = z.infer<typeof SandboxSimulationRequestSchema>;
1373
+ export type SandboxSimulationArtifact = z.infer<typeof SandboxSimulationArtifactSchema>;
1374
+ export type SandboxPolicyPreview = z.infer<typeof SandboxPolicyPreviewSchema>;
1375
+ export type SandboxRiskPreview = z.infer<typeof SandboxRiskPreviewSchema>;
1376
+ export type SandboxSimulationResult = z.infer<typeof SandboxSimulationResultSchema>;
1377
+ export type SandboxSimulationRun = z.infer<typeof SandboxSimulationRunSchema>;
1378
+ export type SandboxSimulationListResponse = z.infer<typeof SandboxSimulationListResponseSchema>;
1379
+ export type SandboxSimulationReplayResponse = z.infer<typeof SandboxSimulationReplayResponseSchema>;
1380
+ export type DataBoundaryPolicyMode = z.infer<typeof DataBoundaryPolicyModeSchema>;
1381
+ export type DataBoundaryPolicyStatus = z.infer<typeof DataBoundaryPolicyStatusSchema>;
1382
+ export type DataBoundaryDecisionAction = z.infer<typeof DataBoundaryDecisionActionSchema>;
1383
+ export type DataBoundaryMaskingStrategy = z.infer<typeof DataBoundaryMaskingStrategySchema>;
1384
+ export type DataBoundaryRuleTarget = z.infer<typeof DataBoundaryRuleTargetSchema>;
1385
+ export type DataBoundaryRule = z.infer<typeof DataBoundaryRuleSchema>;
1386
+ export type DataBoundaryPolicy = z.infer<typeof DataBoundaryPolicySchema>;
1387
+ export type DataBoundaryRuleUpsertInput = z.infer<typeof DataBoundaryRuleUpsertInputSchema>;
1388
+ export type DataBoundaryPolicyCreateRequest = z.infer<typeof DataBoundaryPolicyCreateRequestSchema>;
1389
+ export type DataBoundaryPolicyUpdateRequest = z.infer<typeof DataBoundaryPolicyUpdateRequestSchema>;
1390
+ export type DataBoundaryPolicyListResponse = z.infer<typeof DataBoundaryPolicyListResponseSchema>;
1391
+ export type DataBoundaryDecision = z.infer<typeof DataBoundaryDecisionSchema>;
1392
+ export type DataBoundaryEvaluateRequest = z.infer<typeof DataBoundaryEvaluateRequestSchema>;
1393
+ export type DataBoundaryEvaluateResponse = z.infer<typeof DataBoundaryEvaluateResponseSchema>;
1394
+ export type FirewallInspectionMode = z.infer<typeof FirewallInspectionModeSchema>;
1395
+ export type FirewallInspectionTarget = z.infer<typeof FirewallInspectionTargetSchema>;
1396
+ export type FirewallDecisionAction = z.infer<typeof FirewallDecisionActionSchema>;
1397
+ export type FirewallFindingSeverity = z.infer<typeof FirewallFindingSeveritySchema>;
1398
+ export type FirewallFindingCategory = z.infer<typeof FirewallFindingCategorySchema>;
1399
+ export type FirewallInspectFinding = z.infer<typeof FirewallInspectFindingSchema>;
1400
+ export type FirewallInspectRequest = z.infer<typeof FirewallInspectRequestSchema>;
1401
+ export type FirewallInspectResult = z.infer<typeof FirewallInspectResultSchema>;
1402
+ export type FirewallInspectResponse = z.infer<typeof FirewallInspectResponseSchema>;
1403
+ export type FirewallEvent = z.infer<typeof FirewallEventSchema>;
1404
+ export type FirewallEventsResponse = z.infer<typeof FirewallEventsResponseSchema>;
1405
+ export type EdgeInterceptorMode = z.infer<typeof EdgeInterceptorModeSchema>;
1406
+ export type EdgeInterceptorStatus = z.infer<typeof EdgeInterceptorStatusSchema>;
1407
+ export type EdgeInterceptorRegisterRequest = z.infer<typeof EdgeInterceptorRegisterRequestSchema>;
1408
+ export type EdgeInterceptorRegistration = z.infer<typeof EdgeInterceptorRegistrationSchema>;