@opengeni/db 0.28.9 → 0.31.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.
Files changed (163) hide show
  1. package/dist/attached-browser-devices.d.ts +42 -0
  2. package/dist/attempt-tool-catalogs.d.ts +16 -0
  3. package/dist/browser-auth.d.ts +91 -0
  4. package/dist/browser-identities.d.ts +128 -0
  5. package/dist/browser-sessions.d.ts +272 -0
  6. package/dist/browser-state-artifacts.d.ts +17 -0
  7. package/dist/capability-components.d.ts +37 -0
  8. package/dist/capability-integrations.d.ts +192 -0
  9. package/dist/chunk-F5FT7BEZ.js +3535 -0
  10. package/dist/chunk-F5FT7BEZ.js.map +1 -0
  11. package/dist/chunk-ISI2TIUG.js +639 -0
  12. package/dist/chunk-ISI2TIUG.js.map +1 -0
  13. package/dist/chunk-MWDVXQOL.js +11639 -0
  14. package/dist/chunk-MWDVXQOL.js.map +1 -0
  15. package/dist/chunk-NBE6CHRI.js +955 -0
  16. package/dist/chunk-NBE6CHRI.js.map +1 -0
  17. package/dist/{chunk-VHBFHMPC.js → chunk-YHZXQ7HP.js} +754 -11
  18. package/dist/chunk-YHZXQ7HP.js.map +1 -0
  19. package/dist/codemode-operations.d.ts +117 -0
  20. package/dist/codex-token-resolver.d.ts +2 -2
  21. package/dist/company-profile-schema.d.ts +798 -0
  22. package/dist/company-profile.d.ts +268 -0
  23. package/dist/computer-sessions.d.ts +109 -0
  24. package/dist/connection-token-resolver.d.ts +9 -4
  25. package/dist/database.d.ts +52 -3
  26. package/dist/editable-artifact-durable-export.d.ts +153 -0
  27. package/dist/editable-artifact-durable-export.js +788 -0
  28. package/dist/editable-artifact-durable-export.js.map +1 -0
  29. package/dist/editable-artifact-materialization.d.ts +123 -0
  30. package/dist/editable-artifacts-schema.d.ts +4152 -0
  31. package/dist/editable-artifacts.d.ts +610 -0
  32. package/dist/editable-artifacts.js +26 -0
  33. package/dist/editable-artifacts.js.map +1 -0
  34. package/dist/generated-images.d.ts +139 -0
  35. package/dist/index.d.ts +698 -111
  36. package/dist/index.js +27573 -10322
  37. package/dist/index.js.map +1 -1
  38. package/dist/insights.d.ts +51 -4
  39. package/dist/integration-bindings.d.ts +70 -0
  40. package/dist/integration-features.d.ts +99 -0
  41. package/dist/interaction-revisions.d.ts +3 -0
  42. package/dist/interaction-schema.d.ts +5372 -0
  43. package/dist/knowledge-source-sync-schema.d.ts +1679 -0
  44. package/dist/knowledge-source-sync.d.ts +274 -0
  45. package/dist/memory-governance.d.ts +2 -2
  46. package/dist/memory-slack-delivery.d.ts +101 -0
  47. package/dist/new-session-drafts.d.ts +2 -2
  48. package/dist/pack-components.d.ts +76 -0
  49. package/dist/pack-installations.d.ts +86 -0
  50. package/dist/persistence-errors.d.ts +3 -3
  51. package/dist/plugin-packages.d.ts +126 -0
  52. package/dist/preference-registry.d.ts +1 -1
  53. package/dist/provision-roles.d.ts +9 -1
  54. package/dist/provision-roles.js +1 -1
  55. package/dist/runtime-posture.d.ts +18 -6
  56. package/dist/schema.d.ts +18342 -9099
  57. package/dist/schema.js +165 -1
  58. package/dist/scoped-knowledge.d.ts +97 -1
  59. package/dist/session-control.d.ts +4 -4
  60. package/dist/session-queue-commands.d.ts +19 -11
  61. package/dist/session-realtime-context.d.ts +2 -2
  62. package/dist/session-realtime-ledger.d.ts +4 -4
  63. package/dist/session-realtime-mirror.d.ts +2 -2
  64. package/dist/session-realtime-state.d.ts +1 -1
  65. package/dist/session-realtime-terminal.d.ts +1 -1
  66. package/dist/session-realtime.d.ts +7 -7
  67. package/dist/session-tool-call-settlement.d.ts +1 -1
  68. package/dist/slack-user-link-access.d.ts +54 -0
  69. package/dist/transcription-recordings.d.ts +2 -2
  70. package/dist/turn-initiator.d.ts +2 -2
  71. package/dist/video-generation.d.ts +216 -0
  72. package/dist/video-generation.js +66 -0
  73. package/dist/video-generation.js.map +1 -0
  74. package/dist/workspace-artifacts.d.ts +1 -1
  75. package/dist/workspace-instruction-policies.d.ts +1 -1
  76. package/dist/workspace-learning-policy-schema.d.ts +932 -0
  77. package/dist/workspace-learning-policy.d.ts +161 -0
  78. package/drizzle/0183_model_call_provider_cost_estimates.sql +39 -0
  79. package/drizzle/0184_sandbox_drain_teardown_fence.sql +682 -0
  80. package/drizzle/0185_temporal_schedule_cleanup_outbox.sql +168 -0
  81. package/drizzle/0186_sandbox_capture_provider_contract.sql +400 -0
  82. package/drizzle/0187_generated_image_artifacts.sql +173 -0
  83. package/drizzle/0188_image_generation_retention_failure.sql +25 -0
  84. package/drizzle/0189_retained_session_image_formats.sql +13 -0
  85. package/drizzle/0190_timeline_annotations.sql +31 -0
  86. package/drizzle/0191_editable_artifact_engine.sql +3853 -0
  87. package/drizzle/0192_editable_artifact_live_tickets.sql +338 -0
  88. package/drizzle/0193_editable_artifact_authorization.sql +190 -0
  89. package/drizzle/0194_editable_artifact_durable_exports.sql +160 -0
  90. package/drizzle/0195_editable_artifact_import_authorization.sql +203 -0
  91. package/drizzle/0196_rig_provider_images.sql +152 -0
  92. package/drizzle/0197_knowledge_source_sync_schedules.sql +523 -0
  93. package/drizzle/0198_memory_slack_publication_delivery.sql +393 -0
  94. package/drizzle/0199_workspace_learning_policy.sql +980 -0
  95. package/drizzle/0201_company_profile_authority.sql +849 -0
  96. package/drizzle/0202_document_index_checkpoints.sql +85 -0
  97. package/drizzle/0203_durable_video_generation.sql +353 -0
  98. package/drizzle/0204_video_generation_funding.sql +44 -0
  99. package/drizzle/0205_attempt_tool_catalogs.sql +230 -0
  100. package/drizzle/0206_browser_sessions.sql +646 -0
  101. package/drizzle/0207_browser_identities.sql +379 -0
  102. package/drizzle/0208_attached_browser_devices.sql +165 -0
  103. package/drizzle/0209_computer_sessions.sql +575 -0
  104. package/drizzle/0210_browser_auth_network_interventions.sql +441 -0
  105. package/drizzle/0211_editable_artifact_session_links.sql +58 -0
  106. package/drizzle/0212_slack_installation_bindings.sql +348 -0
  107. package/drizzle/0213_slack_user_link_access_requests.sql +177 -0
  108. package/drizzle/0214_session_activity_commit_gate.sql +262 -0
  109. package/drizzle/0215_capabilities_platform.sql +980 -0
  110. package/drizzle/0216_pack_component_ownership.sql +235 -0
  111. package/drizzle/0217_capability_definition_delete_authority.sql +32 -0
  112. package/package.json +18 -5
  113. package/src/attached-browser-devices.ts +371 -0
  114. package/src/attempt-tool-catalogs.ts +131 -0
  115. package/src/browser-auth.ts +1896 -0
  116. package/src/browser-identities.ts +1168 -0
  117. package/src/browser-sessions.ts +2005 -0
  118. package/src/browser-state-artifacts.ts +59 -0
  119. package/src/capability-components.ts +166 -0
  120. package/src/capability-integrations.ts +1663 -0
  121. package/src/codemode-operations.ts +674 -0
  122. package/src/company-profile-schema.ts +143 -0
  123. package/src/company-profile.ts +968 -0
  124. package/src/computer-sessions.ts +1130 -0
  125. package/src/connection-token-resolver.ts +270 -25
  126. package/src/database.ts +427 -23
  127. package/src/editable-artifact-durable-export.ts +1201 -0
  128. package/src/editable-artifact-materialization.ts +893 -0
  129. package/src/editable-artifacts-schema.ts +879 -0
  130. package/src/editable-artifacts.ts +5404 -0
  131. package/src/generated-images.ts +740 -0
  132. package/src/index.ts +5917 -1182
  133. package/src/insights.ts +160 -13
  134. package/src/integration-bindings.ts +455 -0
  135. package/src/integration-features.ts +859 -0
  136. package/src/interaction-revisions.ts +40 -0
  137. package/src/interaction-schema.ts +1303 -0
  138. package/src/knowledge-source-sync-schema.ts +192 -0
  139. package/src/knowledge-source-sync.ts +1922 -0
  140. package/src/memory-slack-delivery.ts +801 -0
  141. package/src/pack-components.ts +954 -0
  142. package/src/pack-installations.ts +929 -0
  143. package/src/persistence-errors.ts +4 -7
  144. package/src/plugin-packages.ts +1186 -0
  145. package/src/provision-roles.ts +302 -1
  146. package/src/runtime-posture-cli.ts +9 -0
  147. package/src/runtime-posture.ts +508 -5
  148. package/src/schema.ts +5117 -3119
  149. package/src/scoped-knowledge-schema.ts +1 -1
  150. package/src/scoped-knowledge.ts +655 -3
  151. package/src/session-control.ts +8 -5
  152. package/src/session-queue-commands.ts +187 -14
  153. package/src/session-realtime-context.ts +2 -2
  154. package/src/session-realtime-ledger.ts +3 -3
  155. package/src/session-realtime.ts +7 -7
  156. package/src/session-tool-call-settlement.ts +9 -0
  157. package/src/slack-user-link-access.ts +702 -0
  158. package/src/video-generation.ts +1452 -0
  159. package/src/workspace-learning-policy-schema.ts +139 -0
  160. package/src/workspace-learning-policy.ts +595 -0
  161. package/dist/chunk-P6CUHXQZ.js +0 -7248
  162. package/dist/chunk-P6CUHXQZ.js.map +0 -1
  163. package/dist/chunk-VHBFHMPC.js.map +0 -1
@@ -0,0 +1,1303 @@
1
+ import type {
2
+ AttachedBrowserDeviceCapabilities,
3
+ AuthRunChoice,
4
+ AuthRunExternalAction,
5
+ AuthRunPendingField,
6
+ BrowserRevisionMaterialization,
7
+ BrowserSessionCapabilities,
8
+ ComputerSessionCapabilities,
9
+ InteractionPlacement,
10
+ NetworkRouteConfiguration,
11
+ NetworkRouteConsistency,
12
+ SiteAuthAuthority,
13
+ SiteAuthHealthPolicy,
14
+ SiteAuthMethod,
15
+ } from "@opengeni/contracts";
16
+ import { sql } from "drizzle-orm";
17
+ import {
18
+ bigint,
19
+ boolean,
20
+ check,
21
+ index,
22
+ integer,
23
+ jsonb,
24
+ pgTable,
25
+ primaryKey,
26
+ text,
27
+ timestamp,
28
+ uniqueIndex,
29
+ uuid,
30
+ } from "drizzle-orm/pg-core";
31
+
32
+ // Foreign keys into the older workspace/session/sandbox tables live in the SQL
33
+ // migration. Keeping this schema leaf independent avoids a cycle into schema.ts.
34
+
35
+ export const interactionLifecycleValues = [
36
+ "starting",
37
+ "active",
38
+ "suspending",
39
+ "suspended",
40
+ "restoring",
41
+ "repair_required",
42
+ "lost",
43
+ "ending",
44
+ "ended",
45
+ "failed",
46
+ ] as const;
47
+
48
+ export const interactionOperationStateValues = [
49
+ "prepared",
50
+ "dispatched",
51
+ "completed",
52
+ "failed",
53
+ "outcome_unknown",
54
+ ] as const;
55
+
56
+ export const interactionOperationKindValues = [
57
+ "create",
58
+ "resume",
59
+ "suspend",
60
+ "end",
61
+ "publish",
62
+ ] as const;
63
+
64
+ export const workspaceInteractionRevisions = pgTable(
65
+ "workspace_interaction_revisions",
66
+ {
67
+ workspaceId: uuid("workspace_id").primaryKey(),
68
+ accountId: uuid("account_id").notNull(),
69
+ revision: bigint("revision", { mode: "number" }).notNull().default(0),
70
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
71
+ },
72
+ (table) => ({
73
+ revisionValid: check(
74
+ "workspace_interaction_revisions_revision_check",
75
+ sql`${table.revision} >= 0`,
76
+ ),
77
+ }),
78
+ );
79
+
80
+ export const browserIdentities = pgTable(
81
+ "browser_identities",
82
+ {
83
+ id: uuid("id").primaryKey(),
84
+ accountId: uuid("account_id").notNull(),
85
+ workspaceId: uuid("workspace_id").notNull(),
86
+ name: text("name").notNull(),
87
+ status: text("status", { enum: ["active", "archived"] })
88
+ .notNull()
89
+ .default("active"),
90
+ defaultRevisionId: uuid("default_revision_id"),
91
+ headGeneration: bigint("head_generation", { mode: "number" }).notNull().default(0),
92
+ revisionCount: bigint("revision_count", { mode: "number" }).notNull().default(0),
93
+ createOperationId: uuid("create_operation_id").notNull(),
94
+ createdBySubjectId: text("created_by_subject_id").notNull(),
95
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
96
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
97
+ },
98
+ (table) => ({
99
+ workspaceIdentity: uniqueIndex("browser_identities_workspace_id_uq").on(
100
+ table.workspaceId,
101
+ table.id,
102
+ ),
103
+ createOperation: uniqueIndex("browser_identities_workspace_create_operation_uq").on(
104
+ table.workspaceId,
105
+ table.createOperationId,
106
+ ),
107
+ activeName: uniqueIndex("browser_identities_workspace_active_name_uq")
108
+ .on(table.workspaceId, sql`lower(${table.name})`)
109
+ .where(sql`${table.status} = 'active'`),
110
+ discovery: index("browser_identities_workspace_status_updated_idx").on(
111
+ table.workspaceId,
112
+ table.status,
113
+ table.updatedAt,
114
+ table.id,
115
+ ),
116
+ valuesValid: check(
117
+ "browser_identities_values_check",
118
+ sql`octet_length(${table.name}) between 1 and 200
119
+ and ${table.name} = btrim(${table.name})
120
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024
121
+ and ${table.headGeneration} >= 0
122
+ and ${table.revisionCount} >= 0
123
+ and ${table.headGeneration} <= ${table.revisionCount}
124
+ and (
125
+ (${table.headGeneration} = 0 and ${table.defaultRevisionId} is null)
126
+ or (${table.headGeneration} > 0 and ${table.defaultRevisionId} is not null)
127
+ )`,
128
+ ),
129
+ }),
130
+ );
131
+
132
+ export const browserRevisions = pgTable(
133
+ "browser_revisions",
134
+ {
135
+ id: uuid("id").primaryKey(),
136
+ accountId: uuid("account_id").notNull(),
137
+ workspaceId: uuid("workspace_id").notNull(),
138
+ identityId: uuid("identity_id").notNull(),
139
+ parentRevisionId: uuid("parent_revision_id"),
140
+ ordinal: bigint("ordinal", { mode: "number" }).notNull(),
141
+ sourceBrowserSessionId: uuid("source_browser_session_id").notNull(),
142
+ publicationOperationId: uuid("publication_operation_id").notNull(),
143
+ expectedHeadGeneration: bigint("expected_head_generation", {
144
+ mode: "number",
145
+ }).notNull(),
146
+ advanceDefaultRequested: boolean("advance_default_requested").notNull(),
147
+ defaultAdvanced: boolean("default_advanced").notNull(),
148
+ resultHeadGeneration: bigint("result_head_generation", {
149
+ mode: "number",
150
+ }).notNull(),
151
+ manifestDigest: text("manifest_digest").notNull(),
152
+ createdBySubjectId: text("created_by_subject_id").notNull(),
153
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
154
+ },
155
+ (table) => ({
156
+ workspaceRevision: uniqueIndex("browser_revisions_workspace_id_uq").on(
157
+ table.workspaceId,
158
+ table.id,
159
+ ),
160
+ identityRevision: uniqueIndex("browser_revisions_identity_id_uq").on(
161
+ table.identityId,
162
+ table.id,
163
+ ),
164
+ workspaceIdentityRevision: uniqueIndex("browser_revisions_workspace_identity_id_uq").on(
165
+ table.workspaceId,
166
+ table.identityId,
167
+ table.id,
168
+ ),
169
+ identityOrdinal: uniqueIndex("browser_revisions_identity_ordinal_uq").on(
170
+ table.identityId,
171
+ table.ordinal,
172
+ ),
173
+ publicationOperation: uniqueIndex("browser_revisions_workspace_publication_operation_uq").on(
174
+ table.workspaceId,
175
+ table.publicationOperationId,
176
+ ),
177
+ identityHistory: index("browser_revisions_identity_history_idx").on(
178
+ table.workspaceId,
179
+ table.identityId,
180
+ table.ordinal,
181
+ ),
182
+ valuesValid: check(
183
+ "browser_revisions_values_check",
184
+ sql`${table.ordinal} > 0
185
+ and ${table.expectedHeadGeneration} >= 0
186
+ and ${table.resultHeadGeneration} >= 0
187
+ and (not ${table.defaultAdvanced} or ${table.advanceDefaultRequested})
188
+ and (
189
+ not ${table.defaultAdvanced}
190
+ or ${table.resultHeadGeneration} = ${table.expectedHeadGeneration} + 1
191
+ )
192
+ and ${table.manifestDigest} ~ '^[0-9a-f]{64}$'
193
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024
194
+ and ${table.parentRevisionId} is distinct from ${table.id}`,
195
+ ),
196
+ }),
197
+ );
198
+
199
+ /** Internal encrypted object metadata. Public mappers expose only bounded
200
+ * integrity/compatibility fields through BrowserRevisionComponent. */
201
+ export const browserStateArtifacts = pgTable(
202
+ "browser_state_artifacts",
203
+ {
204
+ id: uuid("id").primaryKey(),
205
+ accountId: uuid("account_id").notNull(),
206
+ workspaceId: uuid("workspace_id").notNull(),
207
+ sourceBrowserSessionId: uuid("source_browser_session_id").notNull(),
208
+ purpose: text("purpose", {
209
+ enum: ["revision_component", "private_checkpoint"],
210
+ }).notNull(),
211
+ kind: text("kind", {
212
+ enum: ["chromium_profile", "normalized_web_state", "provider_snapshot"],
213
+ }).notNull(),
214
+ format: text("format").notNull(),
215
+ artifactDigest: text("artifact_digest").notNull(),
216
+ contentDigest: text("content_digest").notNull(),
217
+ manifestDigest: text("manifest_digest").notNull(),
218
+ objectKey: text("object_key").notNull(),
219
+ encryptedDataKey: text("encrypted_data_key").notNull(),
220
+ sizeBytes: bigint("size_bytes", { mode: "number" }).notNull(),
221
+ materialization: jsonb("materialization").$type<BrowserRevisionMaterialization>().notNull(),
222
+ state: text("state", { enum: ["available", "delete_pending", "deleted"] })
223
+ .notNull()
224
+ .default("available"),
225
+ retainedUntil: timestamp("retained_until", { withTimezone: true }),
226
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
227
+ deletedAt: timestamp("deleted_at", { withTimezone: true }),
228
+ },
229
+ (table) => ({
230
+ workspaceArtifact: uniqueIndex("browser_state_artifacts_workspace_id_uq").on(
231
+ table.workspaceId,
232
+ table.id,
233
+ ),
234
+ objectKey: uniqueIndex("browser_state_artifacts_object_key_uq").on(table.objectKey),
235
+ source: index("browser_state_artifacts_source_idx").on(
236
+ table.workspaceId,
237
+ table.sourceBrowserSessionId,
238
+ table.createdAt,
239
+ ),
240
+ gc: index("browser_state_artifacts_gc_idx").on(
241
+ table.state,
242
+ table.retainedUntil,
243
+ table.createdAt,
244
+ ),
245
+ valuesValid: check(
246
+ "browser_state_artifacts_values_check",
247
+ sql`octet_length(${table.format}) between 1 and 512
248
+ and ${table.format} = btrim(${table.format})
249
+ and ${table.artifactDigest} ~ '^[0-9a-f]{64}$'
250
+ and ${table.contentDigest} ~ '^[0-9a-f]{64}$'
251
+ and ${table.manifestDigest} ~ '^[0-9a-f]{64}$'
252
+ and octet_length(${table.objectKey}) between 1 and 2048
253
+ and ${table.objectKey} ~ ('^workspaces/' || ${table.workspaceId}::text || '/browser-state/[A-Za-z0-9._=-]+(/[A-Za-z0-9._=-]+)*$')
254
+ and octet_length(${table.encryptedDataKey}) between 16 and 8192
255
+ and ${table.sizeBytes} > 0
256
+ and jsonb_typeof(${table.materialization}) = 'object'
257
+ and octet_length(${table.materialization}::text) between 2 and 65536
258
+ and (
259
+ ${table.purpose} <> 'revision_component'
260
+ or (
261
+ ${table.state} = 'available'
262
+ and ${table.retainedUntil} is null
263
+ and ${table.deletedAt} is null
264
+ )
265
+ )`,
266
+ ),
267
+ lifecycleValid: check(
268
+ "browser_state_artifacts_lifecycle_check",
269
+ sql`(${table.state} = 'deleted' and ${table.deletedAt} is not null)
270
+ or (${table.state} <> 'deleted' and ${table.deletedAt} is null)`,
271
+ ),
272
+ }),
273
+ );
274
+
275
+ export const browserRevisionComponents = pgTable(
276
+ "browser_revision_components",
277
+ {
278
+ id: uuid("id").primaryKey(),
279
+ accountId: uuid("account_id").notNull(),
280
+ workspaceId: uuid("workspace_id").notNull(),
281
+ identityId: uuid("identity_id").notNull(),
282
+ revisionId: uuid("revision_id").notNull(),
283
+ artifactId: uuid("artifact_id").notNull(),
284
+ sourceBrowserSessionId: uuid("source_browser_session_id").notNull(),
285
+ artifactPurpose: text("artifact_purpose", { enum: ["revision_component"] })
286
+ .notNull()
287
+ .default("revision_component"),
288
+ kind: text("kind", {
289
+ enum: ["chromium_profile", "normalized_web_state", "provider_snapshot"],
290
+ }).notNull(),
291
+ position: integer("position").notNull(),
292
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
293
+ },
294
+ (table) => ({
295
+ workspaceComponent: uniqueIndex("browser_revision_components_workspace_id_uq").on(
296
+ table.workspaceId,
297
+ table.id,
298
+ ),
299
+ revisionPosition: uniqueIndex("browser_revision_components_revision_position_uq").on(
300
+ table.revisionId,
301
+ table.position,
302
+ ),
303
+ artifact: uniqueIndex("browser_revision_components_artifact_uq").on(table.artifactId),
304
+ revisionKind: uniqueIndex("browser_revision_components_revision_kind_uq").on(
305
+ table.revisionId,
306
+ table.kind,
307
+ ),
308
+ revision: index("browser_revision_components_revision_idx").on(
309
+ table.workspaceId,
310
+ table.revisionId,
311
+ table.position,
312
+ ),
313
+ valuesValid: check(
314
+ "browser_revision_components_values_check",
315
+ sql`${table.position} between 0 and 15
316
+ and ${table.artifactPurpose} = 'revision_component'`,
317
+ ),
318
+ }),
319
+ );
320
+
321
+ export const attachedBrowserDevices = pgTable(
322
+ "attached_browser_devices",
323
+ {
324
+ id: uuid("id").notNull(),
325
+ accountId: uuid("account_id").notNull(),
326
+ workspaceId: uuid("workspace_id").notNull(),
327
+ enrollmentId: uuid("enrollment_id").notNull(),
328
+ name: text("name").notNull(),
329
+ profileLabel: text("profile_label"),
330
+ browserName: text("browser_name").notNull(),
331
+ browserVersion: text("browser_version").notNull(),
332
+ extensionVersion: text("extension_version").notNull(),
333
+ platform: text("platform", {
334
+ enum: ["linux", "macos", "windows"],
335
+ }).notNull(),
336
+ architecture: text("architecture", { enum: ["x64", "arm64"] }).notNull(),
337
+ connectionGeneration: text("connection_generation").notNull(),
338
+ inventoryRevision: bigint("inventory_revision", {
339
+ mode: "number",
340
+ }).notNull(),
341
+ tabCount: integer("tab_count").notNull(),
342
+ capabilities: jsonb("capabilities").$type<AttachedBrowserDeviceCapabilities>().notNull(),
343
+ lastSeenAt: timestamp("last_seen_at", { withTimezone: true }).notNull(),
344
+ disconnectedAt: timestamp("disconnected_at", { withTimezone: true }),
345
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
346
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
347
+ },
348
+ (table) => ({
349
+ identity: primaryKey({
350
+ name: "attached_browser_devices_workspace_id_pk",
351
+ columns: [table.workspaceId, table.id],
352
+ }),
353
+ enrollment: index("attached_browser_devices_enrollment_idx").on(
354
+ table.workspaceId,
355
+ table.enrollmentId,
356
+ table.disconnectedAt,
357
+ table.updatedAt,
358
+ ),
359
+ discovery: index("attached_browser_devices_discovery_idx").on(
360
+ table.workspaceId,
361
+ table.disconnectedAt,
362
+ table.updatedAt,
363
+ table.id,
364
+ ),
365
+ valuesValid: check(
366
+ "attached_browser_devices_values_check",
367
+ sql`octet_length(${table.name}) between 1 and 200
368
+ and ${table.name} = btrim(${table.name})
369
+ and (${table.profileLabel} is null or (
370
+ octet_length(${table.profileLabel}) between 1 and 200
371
+ and ${table.profileLabel} = btrim(${table.profileLabel})
372
+ ))
373
+ and octet_length(${table.browserName}) between 1 and 100
374
+ and ${table.browserName} = btrim(${table.browserName})
375
+ and octet_length(${table.browserVersion}) between 1 and 256
376
+ and ${table.browserVersion} = btrim(${table.browserVersion})
377
+ and octet_length(${table.extensionVersion}) between 1 and 256
378
+ and ${table.extensionVersion} = btrim(${table.extensionVersion})
379
+ and octet_length(${table.connectionGeneration}) between 1 and 256
380
+ and ${table.connectionGeneration} ~ '^[A-Za-z0-9][A-Za-z0-9._:-]*$'
381
+ and ${table.inventoryRevision} >= 0
382
+ and ${table.tabCount} between 0 and 100000
383
+ and jsonb_typeof(${table.capabilities}) = 'object'
384
+ and octet_length(${table.capabilities}::text) between 2 and 65536`,
385
+ ),
386
+ }),
387
+ );
388
+
389
+ /** Accepted full-snapshot cursor for one connected agent's local browser bridge.
390
+ * This lets heartbeat replay refresh liveness without allowing an older
391
+ * inventory to disconnect a newly announced profile. */
392
+ export const attachedBrowserInventories = pgTable(
393
+ "attached_browser_inventories",
394
+ {
395
+ accountId: uuid("account_id").notNull(),
396
+ workspaceId: uuid("workspace_id").notNull(),
397
+ enrollmentId: uuid("enrollment_id").notNull(),
398
+ bridgeGeneration: text("bridge_generation").notNull(),
399
+ revision: bigint("revision", { mode: "number" }).notNull(),
400
+ observedAt: timestamp("observed_at", { withTimezone: true }).notNull(),
401
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
402
+ },
403
+ (table) => ({
404
+ identity: primaryKey({
405
+ name: "attached_browser_inventories_workspace_enrollment_pk",
406
+ columns: [table.workspaceId, table.enrollmentId],
407
+ }),
408
+ valuesValid: check(
409
+ "attached_browser_inventories_values_check",
410
+ sql`octet_length(${table.bridgeGeneration}) between 1 and 256
411
+ and ${table.bridgeGeneration} ~ '^[A-Za-z0-9][A-Za-z0-9._:-]*$'
412
+ and ${table.revision} >= 0`,
413
+ ),
414
+ }),
415
+ );
416
+
417
+ export const browserSessions = pgTable(
418
+ "browser_sessions",
419
+ {
420
+ id: uuid("id").primaryKey(),
421
+ accountId: uuid("account_id").notNull(),
422
+ workspaceId: uuid("workspace_id").notNull(),
423
+ name: text("name").notNull(),
424
+ lifecycle: text("lifecycle", { enum: interactionLifecycleValues })
425
+ .notNull()
426
+ .default("starting"),
427
+ placementKind: text("placement_kind", {
428
+ enum: ["sandbox_group", "connected_machine", "attached_device", "external_provider"],
429
+ }).notNull(),
430
+ sandboxGroupId: uuid("sandbox_group_id"),
431
+ connectedSandboxId: uuid("connected_sandbox_id"),
432
+ deviceId: uuid("device_id"),
433
+ externalProviderId: text("external_provider_id"),
434
+ externalPlacementId: text("external_placement_id"),
435
+ controllerId: text("controller_id"),
436
+ controllerGeneration: text("controller_generation"),
437
+ placementInstanceId: text("placement_instance_id"),
438
+ tokenGeneration: integer("token_generation").notNull().default(1),
439
+ driverId: text("driver_id").notNull(),
440
+ engine: text("engine", {
441
+ enum: ["chromium", "chrome", "firefox", "webkit", "lightpanda", "external"],
442
+ }).notNull(),
443
+ engineVersion: text("engine_version"),
444
+ headless: boolean("headless").notNull(),
445
+ identityId: uuid("identity_id"),
446
+ baseRevisionId: uuid("base_revision_id"),
447
+ linkedComputerSessionId: uuid("linked_computer_session_id"),
448
+ networkRouteId: uuid("network_route_id"),
449
+ privateCheckpointArtifactId: uuid("private_checkpoint_artifact_id"),
450
+ capabilities: jsonb("capabilities").$type<BrowserSessionCapabilities>().notNull(),
451
+ createOperationId: uuid("create_operation_id").notNull(),
452
+ createdBySubjectId: text("created_by_subject_id").notNull(),
453
+ failureCode: text("failure_code"),
454
+ controllerHeartbeatAt: timestamp("controller_heartbeat_at", {
455
+ withTimezone: true,
456
+ }),
457
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
458
+ lastUsedAt: timestamp("last_used_at", { withTimezone: true }).notNull().defaultNow(),
459
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
460
+ },
461
+ (table) => ({
462
+ workspaceIdentity: uniqueIndex("browser_sessions_workspace_id_uq").on(
463
+ table.workspaceId,
464
+ table.id,
465
+ ),
466
+ createOperation: uniqueIndex("browser_sessions_workspace_create_operation_uq").on(
467
+ table.workspaceId,
468
+ table.createOperationId,
469
+ ),
470
+ workspaceLifecycle: index("browser_sessions_workspace_lifecycle_idx").on(
471
+ table.workspaceId,
472
+ table.lifecycle,
473
+ table.lastUsedAt,
474
+ table.id,
475
+ ),
476
+ sandboxGroup: index("browser_sessions_sandbox_group_idx").on(
477
+ table.workspaceId,
478
+ table.sandboxGroupId,
479
+ table.lifecycle,
480
+ ),
481
+ valuesValid: check(
482
+ "browser_sessions_values_check",
483
+ sql`octet_length(${table.name}) between 1 and 200
484
+ and octet_length(${table.driverId}) between 1 and 512
485
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024
486
+ and ${table.tokenGeneration} > 0
487
+ and octet_length(${table.capabilities}::text) between 2 and 65536
488
+ and (${table.engineVersion} is null or octet_length(${table.engineVersion}) between 1 and 256)
489
+ and (${table.failureCode} is null or octet_length(${table.failureCode}) between 1 and 512)`,
490
+ ),
491
+ placementValid: check(
492
+ "browser_sessions_placement_check",
493
+ sql`(
494
+ ${table.placementKind} = 'sandbox_group'
495
+ and ${table.sandboxGroupId} is not null
496
+ and ${table.connectedSandboxId} is null
497
+ and ${table.deviceId} is null
498
+ and ${table.externalProviderId} is null
499
+ and ${table.externalPlacementId} is null
500
+ ) or (
501
+ ${table.placementKind} = 'connected_machine'
502
+ and ${table.sandboxGroupId} is null
503
+ and ${table.connectedSandboxId} is not null
504
+ and ${table.deviceId} is null
505
+ and ${table.externalProviderId} is null
506
+ and ${table.externalPlacementId} is null
507
+ ) or (
508
+ ${table.placementKind} = 'attached_device'
509
+ and ${table.sandboxGroupId} is null
510
+ and ${table.connectedSandboxId} is null
511
+ and ${table.deviceId} is not null
512
+ and ${table.externalProviderId} is null
513
+ and ${table.externalPlacementId} is null
514
+ ) or (
515
+ ${table.placementKind} = 'external_provider'
516
+ and ${table.sandboxGroupId} is null
517
+ and ${table.connectedSandboxId} is null
518
+ and ${table.deviceId} is null
519
+ and ${table.externalProviderId} is not null
520
+ and ${table.externalPlacementId} is not null
521
+ and octet_length(${table.externalProviderId}) between 1 and 512
522
+ and octet_length(${table.externalPlacementId}) between 1 and 512
523
+ )`,
524
+ ),
525
+ controllerValid: check(
526
+ "browser_sessions_controller_check",
527
+ sql`(
528
+ ${table.controllerId} is null
529
+ and ${table.controllerGeneration} is null
530
+ and ${table.placementInstanceId} is null
531
+ and ${table.controllerHeartbeatAt} is null
532
+ ) or (
533
+ ${table.controllerId} is not null
534
+ and octet_length(${table.controllerId}) between 1 and 512
535
+ and ${table.controllerGeneration} is not null
536
+ and octet_length(${table.controllerGeneration}) between 1 and 256
537
+ and ${table.placementInstanceId} is not null
538
+ and octet_length(${table.placementInstanceId}) between 1 and 512
539
+ and ${table.controllerHeartbeatAt} is not null
540
+ )`,
541
+ ),
542
+ identityRevisionValid: check(
543
+ "browser_sessions_identity_revision_check",
544
+ sql`${table.baseRevisionId} is null or ${table.identityId} is not null`,
545
+ ),
546
+ failureValid: check(
547
+ "browser_sessions_failure_check",
548
+ sql`(
549
+ ${table.lifecycle} in ('repair_required', 'lost', 'failed')
550
+ and ${table.failureCode} is not null
551
+ ) or (
552
+ ${table.lifecycle} not in ('repair_required', 'lost', 'failed')
553
+ and ${table.failureCode} is null
554
+ )`,
555
+ ),
556
+ }),
557
+ );
558
+
559
+ export const browserSessionAssociations = pgTable(
560
+ "browser_session_associations",
561
+ {
562
+ id: uuid("id").primaryKey().defaultRandom(),
563
+ accountId: uuid("account_id").notNull(),
564
+ workspaceId: uuid("workspace_id").notNull(),
565
+ browserSessionId: uuid("browser_session_id").notNull(),
566
+ sessionId: uuid("session_id").notNull(),
567
+ turnId: uuid("turn_id"),
568
+ attemptId: uuid("attempt_id"),
569
+ relationship: text("relationship", {
570
+ enum: ["created", "using", "observing", "related"],
571
+ }).notNull(),
572
+ actorSubjectId: text("actor_subject_id").notNull(),
573
+ lastUsedAt: timestamp("last_used_at", { withTimezone: true }).notNull().defaultNow(),
574
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
575
+ },
576
+ (table) => ({
577
+ resourceSessionRelationship: uniqueIndex(
578
+ "browser_session_associations_resource_session_relationship_uq",
579
+ ).on(table.browserSessionId, table.sessionId, table.relationship),
580
+ workspaceSession: index("browser_session_associations_workspace_session_idx").on(
581
+ table.workspaceId,
582
+ table.sessionId,
583
+ table.lastUsedAt,
584
+ ),
585
+ resource: index("browser_session_associations_resource_idx").on(
586
+ table.workspaceId,
587
+ table.browserSessionId,
588
+ table.lastUsedAt,
589
+ ),
590
+ valuesValid: check(
591
+ "browser_session_associations_values_check",
592
+ sql`octet_length(${table.actorSubjectId}) between 1 and 1024
593
+ and (${table.attemptId} is null or ${table.turnId} is not null)`,
594
+ ),
595
+ }),
596
+ );
597
+
598
+ export const computerSessions = pgTable(
599
+ "computer_sessions",
600
+ {
601
+ id: uuid("id").primaryKey(),
602
+ accountId: uuid("account_id").notNull(),
603
+ workspaceId: uuid("workspace_id").notNull(),
604
+ name: text("name").notNull(),
605
+ lifecycle: text("lifecycle", { enum: interactionLifecycleValues })
606
+ .notNull()
607
+ .default("starting"),
608
+ placementKind: text("placement_kind", {
609
+ enum: ["sandbox_group", "connected_machine", "attached_device", "external_provider"],
610
+ }).notNull(),
611
+ sandboxGroupId: uuid("sandbox_group_id"),
612
+ connectedSandboxId: uuid("connected_sandbox_id"),
613
+ deviceId: uuid("device_id"),
614
+ externalProviderId: text("external_provider_id"),
615
+ externalPlacementId: text("external_placement_id"),
616
+ controllerId: text("controller_id"),
617
+ controllerGeneration: text("controller_generation"),
618
+ placementInstanceId: text("placement_instance_id"),
619
+ tokenGeneration: integer("token_generation").notNull().default(1),
620
+ platform: text("platform", { enum: ["linux", "macos", "windows"] }),
621
+ adapter: text("adapter"),
622
+ seatId: text("seat_id"),
623
+ displayId: text("display_id"),
624
+ capabilities: jsonb("capabilities").$type<ComputerSessionCapabilities>(),
625
+ createOperationId: uuid("create_operation_id").notNull(),
626
+ createdBySubjectId: text("created_by_subject_id").notNull(),
627
+ failureCode: text("failure_code"),
628
+ controllerHeartbeatAt: timestamp("controller_heartbeat_at", {
629
+ withTimezone: true,
630
+ }),
631
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
632
+ lastUsedAt: timestamp("last_used_at", { withTimezone: true }).notNull().defaultNow(),
633
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
634
+ },
635
+ (table) => ({
636
+ workspaceIdentity: uniqueIndex("computer_sessions_workspace_id_uq").on(
637
+ table.workspaceId,
638
+ table.id,
639
+ ),
640
+ createOperation: uniqueIndex("computer_sessions_workspace_create_operation_uq").on(
641
+ table.workspaceId,
642
+ table.createOperationId,
643
+ ),
644
+ workspaceLifecycle: index("computer_sessions_workspace_lifecycle_idx").on(
645
+ table.workspaceId,
646
+ table.lifecycle,
647
+ table.lastUsedAt,
648
+ table.id,
649
+ ),
650
+ sandboxGroup: index("computer_sessions_sandbox_group_idx").on(
651
+ table.workspaceId,
652
+ table.sandboxGroupId,
653
+ table.lifecycle,
654
+ ),
655
+ valuesValid: check(
656
+ "computer_sessions_values_check",
657
+ sql`octet_length(${table.name}) between 1 and 200
658
+ and ${table.name} = btrim(${table.name})
659
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024
660
+ and ${table.tokenGeneration} > 0
661
+ and (${table.adapter} is null or octet_length(${table.adapter}) between 1 and 512)
662
+ and (${table.seatId} is null or octet_length(${table.seatId}) between 1 and 512)
663
+ and (${table.displayId} is null or octet_length(${table.displayId}) between 1 and 512)
664
+ and (${table.capabilities} is null or (
665
+ jsonb_typeof(${table.capabilities}) = 'object'
666
+ and octet_length(${table.capabilities}::text) between 2 and 65536
667
+ ))
668
+ and (${table.failureCode} is null or octet_length(${table.failureCode}) between 1 and 512)`,
669
+ ),
670
+ placementValid: check(
671
+ "computer_sessions_placement_check",
672
+ sql`(
673
+ ${table.placementKind} = 'sandbox_group'
674
+ and ${table.sandboxGroupId} is not null
675
+ and ${table.connectedSandboxId} is null
676
+ and ${table.deviceId} is null
677
+ and ${table.externalProviderId} is null
678
+ and ${table.externalPlacementId} is null
679
+ ) or (
680
+ ${table.placementKind} = 'connected_machine'
681
+ and ${table.sandboxGroupId} is null
682
+ and ${table.connectedSandboxId} is not null
683
+ and ${table.deviceId} is null
684
+ and ${table.externalProviderId} is null
685
+ and ${table.externalPlacementId} is null
686
+ ) or (
687
+ ${table.placementKind} = 'attached_device'
688
+ and ${table.sandboxGroupId} is null
689
+ and ${table.connectedSandboxId} is null
690
+ and ${table.deviceId} is not null
691
+ and ${table.externalProviderId} is null
692
+ and ${table.externalPlacementId} is null
693
+ ) or (
694
+ ${table.placementKind} = 'external_provider'
695
+ and ${table.sandboxGroupId} is null
696
+ and ${table.connectedSandboxId} is null
697
+ and ${table.deviceId} is null
698
+ and ${table.externalProviderId} is not null
699
+ and ${table.externalPlacementId} is not null
700
+ and octet_length(${table.externalProviderId}) between 1 and 512
701
+ and octet_length(${table.externalPlacementId}) between 1 and 512
702
+ )`,
703
+ ),
704
+ controllerValid: check(
705
+ "computer_sessions_controller_check",
706
+ sql`(
707
+ ${table.controllerId} is null
708
+ and ${table.controllerGeneration} is null
709
+ and ${table.placementInstanceId} is null
710
+ and ${table.controllerHeartbeatAt} is null
711
+ ) or (
712
+ ${table.controllerId} is not null
713
+ and octet_length(${table.controllerId}) between 1 and 512
714
+ and ${table.controllerGeneration} is not null
715
+ and octet_length(${table.controllerGeneration}) between 1 and 256
716
+ and ${table.placementInstanceId} is not null
717
+ and octet_length(${table.placementInstanceId}) between 1 and 512
718
+ and ${table.controllerHeartbeatAt} is not null
719
+ )`,
720
+ ),
721
+ nativeBindingValid: check(
722
+ "computer_sessions_native_binding_check",
723
+ sql`(
724
+ ${table.platform} is null
725
+ and ${table.adapter} is null
726
+ and ${table.seatId} is null
727
+ and ${table.displayId} is null
728
+ and ${table.capabilities} is null
729
+ ) or (
730
+ ${table.platform} is not null
731
+ and ${table.adapter} is not null
732
+ and ${table.seatId} is not null
733
+ and ${table.displayId} is not null
734
+ and ${table.capabilities} is not null
735
+ )`,
736
+ ),
737
+ activeValid: check(
738
+ "computer_sessions_active_binding_check",
739
+ sql`${table.lifecycle} <> 'active' or (
740
+ ${table.controllerId} is not null
741
+ and ${table.platform} is not null
742
+ and ${table.capabilities} is not null
743
+ )`,
744
+ ),
745
+ failureValid: check(
746
+ "computer_sessions_failure_check",
747
+ sql`(
748
+ ${table.lifecycle} in ('repair_required', 'lost', 'failed')
749
+ and ${table.failureCode} is not null
750
+ ) or (
751
+ ${table.lifecycle} not in ('repair_required', 'lost', 'failed')
752
+ and ${table.failureCode} is null
753
+ )`,
754
+ ),
755
+ }),
756
+ );
757
+
758
+ export const computerSessionAssociations = pgTable(
759
+ "computer_session_associations",
760
+ {
761
+ id: uuid("id").primaryKey().defaultRandom(),
762
+ accountId: uuid("account_id").notNull(),
763
+ workspaceId: uuid("workspace_id").notNull(),
764
+ computerSessionId: uuid("computer_session_id").notNull(),
765
+ sessionId: uuid("session_id").notNull(),
766
+ turnId: uuid("turn_id"),
767
+ attemptId: uuid("attempt_id"),
768
+ relationship: text("relationship", {
769
+ enum: ["created", "using", "observing", "related"],
770
+ }).notNull(),
771
+ actorSubjectId: text("actor_subject_id").notNull(),
772
+ lastUsedAt: timestamp("last_used_at", { withTimezone: true }).notNull().defaultNow(),
773
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
774
+ },
775
+ (table) => ({
776
+ resourceSessionRelationship: uniqueIndex(
777
+ "computer_session_associations_resource_session_relationship_uq",
778
+ ).on(table.computerSessionId, table.sessionId, table.relationship),
779
+ workspaceSession: index("computer_session_associations_workspace_session_idx").on(
780
+ table.workspaceId,
781
+ table.sessionId,
782
+ table.lastUsedAt,
783
+ ),
784
+ resource: index("computer_session_associations_resource_idx").on(
785
+ table.workspaceId,
786
+ table.computerSessionId,
787
+ table.lastUsedAt,
788
+ ),
789
+ valuesValid: check(
790
+ "computer_session_associations_values_check",
791
+ sql`octet_length(${table.actorSubjectId}) between 1 and 1024
792
+ and (${table.attemptId} is null or ${table.turnId} is not null)`,
793
+ ),
794
+ }),
795
+ );
796
+
797
+ export const networkRoutes = pgTable(
798
+ "network_routes",
799
+ {
800
+ id: uuid("id").primaryKey().defaultRandom(),
801
+ accountId: uuid("account_id").notNull(),
802
+ workspaceId: uuid("workspace_id").notNull(),
803
+ name: text("name").notNull(),
804
+ status: text("status", { enum: ["active", "archived"] })
805
+ .notNull()
806
+ .default("active"),
807
+ configuration: jsonb("configuration").$type<NetworkRouteConfiguration>().notNull(),
808
+ consistency: jsonb("consistency").$type<NetworkRouteConsistency>().notNull(),
809
+ version: bigint("version", { mode: "number" }).notNull().default(1),
810
+ createOperationId: uuid("create_operation_id").notNull(),
811
+ createdBySubjectId: text("created_by_subject_id").notNull(),
812
+ updatedBySubjectId: text("updated_by_subject_id").notNull(),
813
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
814
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
815
+ },
816
+ (table) => ({
817
+ workspaceIdentity: uniqueIndex("network_routes_workspace_id_uq").on(
818
+ table.workspaceId,
819
+ table.id,
820
+ ),
821
+ createOperation: uniqueIndex("network_routes_workspace_create_operation_uq").on(
822
+ table.workspaceId,
823
+ table.createOperationId,
824
+ ),
825
+ activeName: uniqueIndex("network_routes_workspace_active_name_uq")
826
+ .on(table.workspaceId, sql`lower(${table.name})`)
827
+ .where(sql`${table.status} = 'active'`),
828
+ discovery: index("network_routes_workspace_status_updated_idx").on(
829
+ table.workspaceId,
830
+ table.status,
831
+ table.updatedAt,
832
+ table.id,
833
+ ),
834
+ valuesValid: check(
835
+ "network_routes_values_check",
836
+ sql`octet_length(${table.name}) between 1 and 200
837
+ and ${table.name} = btrim(${table.name})
838
+ and jsonb_typeof(${table.configuration}) = 'object'
839
+ and octet_length(${table.configuration}::text) between 2 and 65536
840
+ and jsonb_typeof(${table.consistency}) = 'object'
841
+ and octet_length(${table.consistency}::text) between 2 and 65536
842
+ and ${table.version} > 0
843
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024
844
+ and octet_length(${table.updatedBySubjectId}) between 1 and 1024`,
845
+ ),
846
+ }),
847
+ );
848
+
849
+ export const siteAuthConnections = pgTable(
850
+ "site_auth_connections",
851
+ {
852
+ id: uuid("id").primaryKey().defaultRandom(),
853
+ accountId: uuid("account_id").notNull(),
854
+ workspaceId: uuid("workspace_id").notNull(),
855
+ name: text("name").notNull(),
856
+ accountLabel: text("account_label").notNull(),
857
+ status: text("status", { enum: ["active", "archived"] })
858
+ .notNull()
859
+ .default("active"),
860
+ origins: jsonb("origins").$type<string[]>().notNull(),
861
+ loginUrl: text("login_url"),
862
+ verificationUrlPrefixes: jsonb("verification_url_prefixes").$type<string[]>().notNull(),
863
+ authorities: jsonb("authorities").$type<SiteAuthAuthority[]>().notNull(),
864
+ methods: jsonb("methods").$type<SiteAuthMethod[]>().notNull(),
865
+ preferredIdentityId: uuid("preferred_identity_id"),
866
+ preferredPlacement: jsonb("preferred_placement").$type<InteractionPlacement>(),
867
+ preferredNetworkRouteId: uuid("preferred_network_route_id"),
868
+ healthPolicy: jsonb("health_policy").$type<SiteAuthHealthPolicy>().notNull(),
869
+ verificationState: text("verification_state", {
870
+ enum: ["unknown", "verified", "needs_repair", "failed"],
871
+ })
872
+ .notNull()
873
+ .default("unknown"),
874
+ lastVerifiedAt: timestamp("last_verified_at", { withTimezone: true }),
875
+ lastVerifiedUrl: text("last_verified_url"),
876
+ repairCode: text("repair_code"),
877
+ version: bigint("version", { mode: "number" }).notNull().default(1),
878
+ createOperationId: uuid("create_operation_id").notNull(),
879
+ createdBySubjectId: text("created_by_subject_id").notNull(),
880
+ updatedBySubjectId: text("updated_by_subject_id").notNull(),
881
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
882
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
883
+ },
884
+ (table) => ({
885
+ workspaceIdentity: uniqueIndex("site_auth_connections_workspace_id_uq").on(
886
+ table.workspaceId,
887
+ table.id,
888
+ ),
889
+ createOperation: uniqueIndex("site_auth_connections_workspace_create_operation_uq").on(
890
+ table.workspaceId,
891
+ table.createOperationId,
892
+ ),
893
+ activeName: uniqueIndex("site_auth_connections_workspace_active_name_uq")
894
+ .on(table.workspaceId, sql`lower(${table.name})`)
895
+ .where(sql`${table.status} = 'active'`),
896
+ discovery: index("site_auth_connections_workspace_status_updated_idx").on(
897
+ table.workspaceId,
898
+ table.status,
899
+ table.updatedAt,
900
+ table.id,
901
+ ),
902
+ valuesValid: check(
903
+ "site_auth_connections_values_check",
904
+ sql`octet_length(${table.name}) between 1 and 200
905
+ and ${table.name} = btrim(${table.name})
906
+ and octet_length(${table.accountLabel}) between 1 and 200
907
+ and ${table.accountLabel} = btrim(${table.accountLabel})
908
+ and jsonb_typeof(${table.origins}) = 'array'
909
+ and octet_length(${table.origins}::text) between 3 and 65536
910
+ and (${table.loginUrl} is null or octet_length(${table.loginUrl}) between 1 and 16384)
911
+ and jsonb_typeof(${table.verificationUrlPrefixes}) = 'array'
912
+ and octet_length(${table.verificationUrlPrefixes}::text) between 2 and 65536
913
+ and jsonb_typeof(${table.authorities}) = 'array'
914
+ and octet_length(${table.authorities}::text) between 3 and 65536
915
+ and jsonb_typeof(${table.methods}) = 'array'
916
+ and octet_length(${table.methods}::text) between 3 and 65536
917
+ and (${table.preferredPlacement} is null or (
918
+ jsonb_typeof(${table.preferredPlacement}) = 'object'
919
+ and octet_length(${table.preferredPlacement}::text) between 2 and 65536
920
+ ))
921
+ and jsonb_typeof(${table.healthPolicy}) = 'object'
922
+ and octet_length(${table.healthPolicy}::text) between 2 and 65536
923
+ and (${table.lastVerifiedUrl} is null or octet_length(${table.lastVerifiedUrl}) between 1 and 16384)
924
+ and (${table.repairCode} is null or octet_length(${table.repairCode}) between 1 and 512)
925
+ and ${table.version} > 0
926
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024
927
+ and octet_length(${table.updatedBySubjectId}) between 1 and 1024`,
928
+ ),
929
+ verificationValid: check(
930
+ "site_auth_connections_verification_check",
931
+ sql`(
932
+ ${table.verificationState} = 'verified'
933
+ and ${table.lastVerifiedAt} is not null
934
+ and ${table.lastVerifiedUrl} is not null
935
+ and ${table.repairCode} is null
936
+ ) or (
937
+ ${table.verificationState} = 'unknown'
938
+ and ${table.lastVerifiedAt} is null
939
+ and ${table.lastVerifiedUrl} is null
940
+ and ${table.repairCode} is null
941
+ ) or (
942
+ ${table.verificationState} in ('needs_repair', 'failed')
943
+ and ${table.repairCode} is not null
944
+ )`,
945
+ ),
946
+ }),
947
+ );
948
+
949
+ export const authRuns = pgTable(
950
+ "auth_runs",
951
+ {
952
+ id: uuid("id").primaryKey().defaultRandom(),
953
+ accountId: uuid("account_id").notNull(),
954
+ workspaceId: uuid("workspace_id").notNull(),
955
+ siteAuthConnectionId: uuid("site_auth_connection_id").notNull(),
956
+ browserSessionId: uuid("browser_session_id").notNull(),
957
+ targetId: text("target_id").notNull(),
958
+ controllerGeneration: text("controller_generation").notNull(),
959
+ targetGeneration: text("target_generation").notNull(),
960
+ documentGeneration: text("document_generation"),
961
+ methodId: text("method_id"),
962
+ authorityId: text("authority_id"),
963
+ state: text("state", {
964
+ enum: [
965
+ "discovering",
966
+ "awaiting_choice",
967
+ "awaiting_secret",
968
+ "awaiting_external_action",
969
+ "working",
970
+ "verified",
971
+ "failed",
972
+ "cancelled",
973
+ ],
974
+ })
975
+ .notNull()
976
+ .default("discovering"),
977
+ choices: jsonb("choices").$type<AuthRunChoice[]>().notNull().default([]),
978
+ pendingFields: jsonb("pending_fields").$type<AuthRunPendingField[]>().notNull().default([]),
979
+ externalAction: jsonb("external_action").$type<AuthRunExternalAction>(),
980
+ interventionId: uuid("intervention_id"),
981
+ verifiedUrl: text("verified_url"),
982
+ failureCode: text("failure_code"),
983
+ version: bigint("version", { mode: "number" }).notNull().default(1),
984
+ operationId: uuid("operation_id").notNull(),
985
+ createdBySubjectId: text("created_by_subject_id").notNull(),
986
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
987
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
988
+ settledAt: timestamp("settled_at", { withTimezone: true }),
989
+ },
990
+ (table) => ({
991
+ workspaceIdentity: uniqueIndex("auth_runs_workspace_id_uq").on(table.workspaceId, table.id),
992
+ operation: uniqueIndex("auth_runs_workspace_operation_uq").on(
993
+ table.workspaceId,
994
+ table.operationId,
995
+ ),
996
+ activeTarget: uniqueIndex("auth_runs_active_browser_target_uq")
997
+ .on(table.workspaceId, table.browserSessionId, table.targetId)
998
+ .where(sql`${table.settledAt} is null`),
999
+ browserHistory: index("auth_runs_browser_history_idx").on(
1000
+ table.workspaceId,
1001
+ table.browserSessionId,
1002
+ table.createdAt,
1003
+ ),
1004
+ siteHistory: index("auth_runs_site_history_idx").on(
1005
+ table.workspaceId,
1006
+ table.siteAuthConnectionId,
1007
+ table.createdAt,
1008
+ ),
1009
+ valuesValid: check(
1010
+ "auth_runs_values_check",
1011
+ sql`octet_length(${table.targetId}) between 1 and 512
1012
+ and octet_length(${table.controllerGeneration}) between 1 and 256
1013
+ and octet_length(${table.targetGeneration}) between 1 and 256
1014
+ and (${table.documentGeneration} is null or octet_length(${table.documentGeneration}) between 1 and 256)
1015
+ and (${table.methodId} is null or octet_length(${table.methodId}) between 1 and 512)
1016
+ and (${table.authorityId} is null or octet_length(${table.authorityId}) between 1 and 512)
1017
+ and jsonb_typeof(${table.choices}) = 'array'
1018
+ and octet_length(${table.choices}::text) between 2 and 65536
1019
+ and jsonb_typeof(${table.pendingFields}) = 'array'
1020
+ and octet_length(${table.pendingFields}::text) between 2 and 65536
1021
+ and (${table.externalAction} is null or (
1022
+ jsonb_typeof(${table.externalAction}) = 'object'
1023
+ and octet_length(${table.externalAction}::text) between 2 and 65536
1024
+ ))
1025
+ and (${table.verifiedUrl} is null or octet_length(${table.verifiedUrl}) between 1 and 16384)
1026
+ and (${table.failureCode} is null or octet_length(${table.failureCode}) between 1 and 512)
1027
+ and ${table.version} > 0
1028
+ and octet_length(${table.createdBySubjectId}) between 1 and 1024`,
1029
+ ),
1030
+ lifecycleValid: check(
1031
+ "auth_runs_lifecycle_check",
1032
+ sql`(
1033
+ ${table.state} = 'verified'
1034
+ and ${table.verifiedUrl} is not null
1035
+ and ${table.failureCode} is null
1036
+ and ${table.settledAt} is not null
1037
+ ) or (
1038
+ ${table.state} = 'failed'
1039
+ and ${table.verifiedUrl} is null
1040
+ and ${table.failureCode} is not null
1041
+ and ${table.settledAt} is not null
1042
+ ) or (
1043
+ ${table.state} = 'cancelled'
1044
+ and ${table.verifiedUrl} is null
1045
+ and ${table.settledAt} is not null
1046
+ ) or (
1047
+ ${table.state} not in ('verified', 'failed', 'cancelled')
1048
+ and ${table.verifiedUrl} is null
1049
+ and ${table.failureCode} is null
1050
+ and ${table.settledAt} is null
1051
+ )`,
1052
+ ),
1053
+ projectionValid: check(
1054
+ "auth_runs_projection_check",
1055
+ sql`(${table.state} = 'awaiting_choice') = (jsonb_array_length(${table.choices}) > 0)
1056
+ and (${table.state} = 'awaiting_secret') = (jsonb_array_length(${table.pendingFields}) > 0)
1057
+ and (${table.state} = 'awaiting_external_action') = (${table.externalAction} is not null)
1058
+ and (${table.state} = 'failed') = (${table.failureCode} is not null)`,
1059
+ ),
1060
+ }),
1061
+ );
1062
+
1063
+ export const interactionInterventions = pgTable(
1064
+ "interaction_interventions",
1065
+ {
1066
+ id: uuid("id").primaryKey().defaultRandom(),
1067
+ accountId: uuid("account_id").notNull(),
1068
+ workspaceId: uuid("workspace_id").notNull(),
1069
+ resourceKind: text("resource_kind", {
1070
+ enum: ["browser_session", "computer_session"],
1071
+ }).notNull(),
1072
+ resourceId: uuid("resource_id").notNull(),
1073
+ targetId: text("target_id").notNull(),
1074
+ controllerGeneration: text("controller_generation").notNull(),
1075
+ targetGeneration: text("target_generation").notNull(),
1076
+ documentGeneration: text("document_generation"),
1077
+ kind: text("kind", {
1078
+ enum: ["manual_login", "mfa", "external_action", "confirmation", "other"],
1079
+ }).notNull(),
1080
+ reason: text("reason").notNull(),
1081
+ status: text("status", {
1082
+ enum: ["open", "completed", "dismissed", "expired", "cancelled"],
1083
+ })
1084
+ .notNull()
1085
+ .default("open"),
1086
+ authRunId: uuid("auth_run_id"),
1087
+ originatingSessionId: uuid("originating_session_id").notNull(),
1088
+ originatingTurnId: uuid("originating_turn_id"),
1089
+ originatingAttemptId: uuid("originating_attempt_id"),
1090
+ originatingToolOperationId: uuid("originating_tool_operation_id"),
1091
+ responseActorSubjectId: text("response_actor_subject_id"),
1092
+ version: bigint("version", { mode: "number" }).notNull().default(1),
1093
+ operationId: uuid("operation_id").notNull(),
1094
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
1095
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1096
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
1097
+ settledAt: timestamp("settled_at", { withTimezone: true }),
1098
+ },
1099
+ (table) => ({
1100
+ workspaceIdentity: uniqueIndex("interaction_interventions_workspace_id_uq").on(
1101
+ table.workspaceId,
1102
+ table.id,
1103
+ ),
1104
+ operation: uniqueIndex("interaction_interventions_workspace_operation_uq").on(
1105
+ table.workspaceId,
1106
+ table.operationId,
1107
+ ),
1108
+ openResource: index("interaction_interventions_open_resource_idx").on(
1109
+ table.workspaceId,
1110
+ table.resourceKind,
1111
+ table.resourceId,
1112
+ table.status,
1113
+ table.createdAt,
1114
+ ),
1115
+ openTargetKind: uniqueIndex("interaction_interventions_open_target_kind_uq")
1116
+ .on(table.workspaceId, table.resourceKind, table.resourceId, table.targetId, table.kind)
1117
+ .where(sql`${table.status} = 'open'`),
1118
+ openAuthRun: uniqueIndex("interaction_interventions_open_auth_run_uq")
1119
+ .on(table.workspaceId, table.authRunId)
1120
+ .where(sql`${table.status} = 'open' and ${table.authRunId} is not null`),
1121
+ valuesValid: check(
1122
+ "interaction_interventions_values_check",
1123
+ sql`octet_length(${table.targetId}) between 1 and 512
1124
+ and octet_length(${table.controllerGeneration}) between 1 and 256
1125
+ and octet_length(${table.targetGeneration}) between 1 and 256
1126
+ and (${table.documentGeneration} is null or octet_length(${table.documentGeneration}) between 1 and 256)
1127
+ and octet_length(${table.reason}) between 1 and 2048
1128
+ and ${table.reason} = btrim(${table.reason})
1129
+ and (${table.originatingAttemptId} is null or ${table.originatingTurnId} is not null)
1130
+ and (${table.originatingToolOperationId} is null or ${table.originatingAttemptId} is not null)
1131
+ and (${table.responseActorSubjectId} is null or octet_length(${table.responseActorSubjectId}) between 1 and 1024)
1132
+ and ${table.version} > 0`,
1133
+ ),
1134
+ lifecycleValid: check(
1135
+ "interaction_interventions_lifecycle_check",
1136
+ sql`(
1137
+ ${table.status} = 'open'
1138
+ and ${table.responseActorSubjectId} is null
1139
+ and ${table.settledAt} is null
1140
+ ) or (
1141
+ ${table.status} <> 'open'
1142
+ and ${table.settledAt} is not null
1143
+ )`,
1144
+ ),
1145
+ }),
1146
+ );
1147
+
1148
+ export const interactionResourceOperations = pgTable(
1149
+ "interaction_resource_operations",
1150
+ {
1151
+ operationId: uuid("operation_id").primaryKey(),
1152
+ accountId: uuid("account_id").notNull(),
1153
+ workspaceId: uuid("workspace_id").notNull(),
1154
+ resourceKind: text("resource_kind", {
1155
+ enum: ["network_route", "site_auth_connection", "auth_run", "intervention"],
1156
+ }).notNull(),
1157
+ resourceId: uuid("resource_id").notNull(),
1158
+ kind: text("kind", {
1159
+ enum: ["create", "update", "start", "report", "protected_fill", "verify", "resolve"],
1160
+ }).notNull(),
1161
+ requestDigest: text("request_digest").notNull(),
1162
+ state: text("state", {
1163
+ enum: ["prepared", "dispatched", "completed", "failed", "outcome_unknown"],
1164
+ })
1165
+ .notNull()
1166
+ .default("completed"),
1167
+ resultVersion: bigint("result_version", { mode: "number" }),
1168
+ result: jsonb("result").$type<Record<string, unknown>>(),
1169
+ errorCode: text("error_code"),
1170
+ actorSubjectId: text("actor_subject_id").notNull(),
1171
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1172
+ settledAt: timestamp("settled_at", { withTimezone: true }),
1173
+ },
1174
+ (table) => ({
1175
+ workspaceOperation: uniqueIndex("interaction_resource_operations_workspace_operation_uq").on(
1176
+ table.workspaceId,
1177
+ table.operationId,
1178
+ ),
1179
+ resourceHistory: index("interaction_resource_operations_resource_history_idx").on(
1180
+ table.workspaceId,
1181
+ table.resourceKind,
1182
+ table.resourceId,
1183
+ table.createdAt,
1184
+ ),
1185
+ valuesValid: check(
1186
+ "interaction_resource_operations_values_check",
1187
+ sql`${table.requestDigest} ~ '^[0-9a-f]{64}$'
1188
+ and (${table.resultVersion} is null or ${table.resultVersion} > 0)
1189
+ and (${table.result} is null or (
1190
+ jsonb_typeof(${table.result}) = 'object'
1191
+ and octet_length(${table.result}::text) between 2 and 262144
1192
+ ))
1193
+ and (${table.errorCode} is null or octet_length(${table.errorCode}) between 1 and 512)
1194
+ and octet_length(${table.actorSubjectId}) between 1 and 1024`,
1195
+ ),
1196
+ lifecycleValid: check(
1197
+ "interaction_resource_operations_lifecycle_check",
1198
+ sql`(
1199
+ ${table.state} = 'completed'
1200
+ and ${table.resultVersion} is not null
1201
+ and ${table.result} is not null
1202
+ and ${table.errorCode} is null
1203
+ and ${table.settledAt} is not null
1204
+ ) or (
1205
+ ${table.state} in ('failed', 'outcome_unknown')
1206
+ and ${table.resultVersion} is null
1207
+ and ${table.result} is null
1208
+ and ${table.errorCode} is not null
1209
+ and ${table.settledAt} is not null
1210
+ ) or (
1211
+ ${table.state} in ('prepared', 'dispatched')
1212
+ and ${table.resultVersion} is null
1213
+ and ${table.result} is null
1214
+ and ${table.errorCode} is null
1215
+ and ${table.settledAt} is null
1216
+ )`,
1217
+ ),
1218
+ }),
1219
+ );
1220
+
1221
+ export const interactionOperations = pgTable(
1222
+ "interaction_operations",
1223
+ {
1224
+ operationId: uuid("operation_id").primaryKey(),
1225
+ accountId: uuid("account_id").notNull(),
1226
+ workspaceId: uuid("workspace_id").notNull(),
1227
+ resourceKind: text("resource_kind", {
1228
+ enum: ["browser_session", "computer_session"],
1229
+ }).notNull(),
1230
+ resourceId: uuid("resource_id").notNull(),
1231
+ kind: text("kind", { enum: interactionOperationKindValues }).notNull(),
1232
+ requestDigest: text("request_digest").notNull(),
1233
+ state: text("state", { enum: interactionOperationStateValues }).notNull().default("prepared"),
1234
+ controllerGeneration: text("controller_generation"),
1235
+ errorCode: text("error_code"),
1236
+ errorMessage: text("error_message"),
1237
+ errorRetryable: boolean("error_retryable"),
1238
+ errorDetails: jsonb("error_details").$type<Record<string, unknown>>(),
1239
+ actorSubjectId: text("actor_subject_id").notNull(),
1240
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1241
+ dispatchedAt: timestamp("dispatched_at", { withTimezone: true }),
1242
+ settledAt: timestamp("settled_at", { withTimezone: true }),
1243
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
1244
+ },
1245
+ (table) => ({
1246
+ workspaceOperation: uniqueIndex("interaction_operations_workspace_operation_uq").on(
1247
+ table.workspaceId,
1248
+ table.operationId,
1249
+ ),
1250
+ resourceHistory: index("interaction_operations_resource_history_idx").on(
1251
+ table.workspaceId,
1252
+ table.resourceKind,
1253
+ table.resourceId,
1254
+ table.createdAt,
1255
+ ),
1256
+ activeResource: uniqueIndex("interaction_operations_active_resource_uq")
1257
+ .on(table.workspaceId, table.resourceKind, table.resourceId)
1258
+ .where(sql`${table.state} in ('prepared', 'dispatched')`),
1259
+ valuesValid: check(
1260
+ "interaction_operations_values_check",
1261
+ sql`${table.requestDigest} ~ '^[0-9a-f]{64}$'
1262
+ and octet_length(${table.actorSubjectId}) between 1 and 1024
1263
+ and (${table.controllerGeneration} is null or octet_length(${table.controllerGeneration}) between 1 and 256)
1264
+ and (${table.errorCode} is null or octet_length(${table.errorCode}) between 1 and 512)
1265
+ and (${table.errorMessage} is null or octet_length(${table.errorMessage}) between 1 and 8192)
1266
+ and (${table.errorDetails} is null or octet_length(${table.errorDetails}::text) between 2 and 65536)`,
1267
+ ),
1268
+ lifecycleValid: check(
1269
+ "interaction_operations_lifecycle_check",
1270
+ sql`(
1271
+ ${table.state} = 'prepared'
1272
+ and ${table.dispatchedAt} is null
1273
+ and ${table.settledAt} is null
1274
+ and ${table.errorCode} is null
1275
+ and ${table.errorMessage} is null
1276
+ and ${table.errorRetryable} is null
1277
+ and ${table.errorDetails} is null
1278
+ ) or (
1279
+ ${table.state} = 'dispatched'
1280
+ and ${table.dispatchedAt} is not null
1281
+ and ${table.settledAt} is null
1282
+ and ${table.errorCode} is null
1283
+ and ${table.errorMessage} is null
1284
+ and ${table.errorRetryable} is null
1285
+ and ${table.errorDetails} is null
1286
+ ) or (
1287
+ ${table.state} = 'completed'
1288
+ and ${table.dispatchedAt} is not null
1289
+ and ${table.settledAt} is not null
1290
+ and ${table.errorCode} is null
1291
+ and ${table.errorMessage} is null
1292
+ and ${table.errorRetryable} is null
1293
+ and ${table.errorDetails} is null
1294
+ ) or (
1295
+ ${table.state} in ('failed', 'outcome_unknown')
1296
+ and ${table.settledAt} is not null
1297
+ and ${table.errorCode} is not null
1298
+ and ${table.errorMessage} is not null
1299
+ and ${table.errorRetryable} is not null
1300
+ )`,
1301
+ ),
1302
+ }),
1303
+ );