@opengeni/db 0.23.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/{chunk-3UCHDMKG.js → chunk-EX7CDSGH.js} +196 -2
  2. package/dist/chunk-EX7CDSGH.js.map +1 -0
  3. package/dist/{chunk-L6ADMZHE.js → chunk-IHPCI4GV.js} +5 -1
  4. package/dist/chunk-IHPCI4GV.js.map +1 -0
  5. package/dist/connection-token-resolver.d.ts +24 -2
  6. package/dist/index.d.ts +68 -2
  7. package/dist/index.js +1457 -338
  8. package/dist/index.js.map +1 -1
  9. package/dist/preference-registry.d.ts +14 -0
  10. package/dist/provision-roles.js +1 -1
  11. package/dist/runtime-posture.d.ts +3 -3
  12. package/dist/schema.d.ts +262 -4
  13. package/dist/schema.js +5 -1
  14. package/dist/session-realtime-mirror.d.ts +22 -1
  15. package/dist/workspace-instruction-policies-schema.d.ts +449 -0
  16. package/dist/workspace-instruction-policies.d.ts +88 -8
  17. package/drizzle/0165_document_authority_foundation.sql +259 -0
  18. package/drizzle/0166_connection_disconnect_idempotency.sql +49 -0
  19. package/drizzle/0167_document_index_replay_authority.sql +61 -0
  20. package/drizzle/0168_workspace_instruction_policy_operation_receipts.sql +44 -0
  21. package/drizzle/0169_workspace_instruction_policy_onboarding_proposals.sql +202 -0
  22. package/package.json +3 -3
  23. package/src/connection-token-resolver.ts +79 -16
  24. package/src/index.ts +419 -23
  25. package/src/preference-registry.ts +103 -0
  26. package/src/runtime-posture.ts +4 -0
  27. package/src/schema.ts +86 -0
  28. package/src/session-control.ts +48 -1
  29. package/src/session-queue-commands.ts +45 -11
  30. package/src/session-realtime-mirror.ts +117 -1
  31. package/src/session-realtime.ts +49 -1
  32. package/src/workspace-instruction-policies-schema.ts +116 -0
  33. package/src/workspace-instruction-policies.ts +819 -25
  34. package/dist/chunk-3UCHDMKG.js.map +0 -1
  35. package/dist/chunk-L6ADMZHE.js.map +0 -1
@@ -17,6 +17,7 @@ __export(schema_exports, {
17
17
  codexRotationSettings: () => codexRotationSettings,
18
18
  codexSubscriptionCredentials: () => codexSubscriptionCredentials,
19
19
  composerDrafts: () => composerDrafts,
20
+ connectionDisconnectOperations: () => connectionDisconnectOperations,
20
21
  connections: () => connections,
21
22
  connectorActionPolicies: () => connectorActionPolicies,
22
23
  connectorActionRequests: () => connectorActionRequests,
@@ -134,6 +135,7 @@ __export(schema_exports, {
134
135
  workspaceInferenceControls: () => workspaceInferenceControls,
135
136
  workspaceInstructionPolicyActivationEvents: () => workspaceInstructionPolicyActivationEvents,
136
137
  workspaceInstructionPolicyHeads: () => workspaceInstructionPolicyHeads,
138
+ workspaceInstructionPolicyOnboardingProposals: () => workspaceInstructionPolicyOnboardingProposals,
137
139
  workspaceInstructionPolicyRevisions: () => workspaceInstructionPolicyRevisions,
138
140
  workspaceInstructionPolicySnapshots: () => workspaceInstructionPolicySnapshots,
139
141
  workspaceMemberships: () => workspaceMemberships,
@@ -180,6 +182,8 @@ var workspaceInstructionPolicyRevisions = pgTable(
180
182
  "workspace_instruction_policy_revisions",
181
183
  {
182
184
  id: uuid("id").primaryKey().defaultRandom(),
185
+ operationId: uuid("operation_id"),
186
+ requestFingerprint: text("request_fingerprint"),
183
187
  accountId: uuid("account_id").notNull(),
184
188
  workspaceId: uuid("workspace_id").notNull(),
185
189
  revision: bigint("revision", { mode: "number" }).notNull().default(sql`nextval('workspace_instruction_policy_revision_seq')`),
@@ -195,6 +199,17 @@ var workspaceInstructionPolicyRevisions = pgTable(
195
199
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
196
200
  },
197
201
  (table) => ({
202
+ workspaceOperation: uniqueIndex("workspace_instruction_policy_revisions_workspace_operation_uq").on(table.workspaceId, table.operationId).where(sql`${table.operationId} is not null`),
203
+ operationReceipt: check(
204
+ "workspace_instruction_policy_revisions_operation_receipt_chk",
205
+ sql`(
206
+ (${table.operationId} is null and ${table.requestFingerprint} is null)
207
+ or (
208
+ ${table.operationId} is not null
209
+ and ${table.requestFingerprint} ~ '^[0-9a-f]{64}$'
210
+ )
211
+ )`
212
+ ),
198
213
  workspaceRevision: uniqueIndex(
199
214
  "workspace_instruction_policy_revisions_workspace_revision_uq"
200
215
  ).on(table.workspaceId, table.revision),
@@ -248,6 +263,8 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
248
263
  "workspace_instruction_policy_activation_events",
249
264
  {
250
265
  id: uuid("id").primaryKey().defaultRandom(),
266
+ operationId: uuid("operation_id"),
267
+ requestFingerprint: text("request_fingerprint"),
251
268
  accountId: uuid("account_id").notNull(),
252
269
  workspaceId: uuid("workspace_id").notNull(),
253
270
  kind: text("kind").notNull(),
@@ -266,6 +283,17 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
266
283
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
267
284
  },
268
285
  (table) => ({
286
+ workspaceOperation: uniqueIndex("workspace_instruction_policy_events_workspace_operation_uq").on(table.workspaceId, table.operationId).where(sql`${table.operationId} is not null`),
287
+ operationReceipt: check(
288
+ "workspace_instruction_policy_events_operation_receipt_chk",
289
+ sql`(
290
+ (${table.operationId} is null and ${table.requestFingerprint} is null)
291
+ or (
292
+ ${table.operationId} is not null
293
+ and ${table.requestFingerprint} ~ '^[0-9a-f]{64}$'
294
+ )
295
+ )`
296
+ ),
269
297
  workspaceActivationVersion: uniqueIndex(
270
298
  "workspace_instruction_policy_events_target_version_uq"
271
299
  ).on(
@@ -290,6 +318,91 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
290
318
  )
291
319
  })
292
320
  );
321
+ var workspaceInstructionPolicyOnboardingProposals = pgTable(
322
+ "workspace_instruction_policy_onboarding_proposals",
323
+ {
324
+ id: uuid("id").primaryKey().defaultRandom(),
325
+ operationId: uuid("operation_id").notNull(),
326
+ requestFingerprint: text("request_fingerprint").notNull(),
327
+ accountId: uuid("account_id").notNull(),
328
+ workspaceId: uuid("workspace_id").notNull(),
329
+ kind: text("kind").notNull(),
330
+ scope: text("scope").notNull(),
331
+ roleKey: text("role_key"),
332
+ sourceId: text("source_id").notNull(),
333
+ sourceVersion: text("source_version").notNull(),
334
+ confidenceBps: integer("confidence_bps").notNull(),
335
+ baselineRevisionId: uuid("baseline_revision_id"),
336
+ baselineRevision: bigint("baseline_revision", { mode: "number" }),
337
+ baselineContentHash: text("baseline_content_hash"),
338
+ baselineActivationVersion: bigint("baseline_activation_version", { mode: "number" }).notNull(),
339
+ baselineActivatedAt: timestamp("baseline_activated_at", { withTimezone: true }),
340
+ draftRevisionId: uuid("draft_revision_id").notNull(),
341
+ draftRevision: bigint("draft_revision", { mode: "number" }).notNull(),
342
+ draftContentHash: text("draft_content_hash").notNull(),
343
+ status: text("status").notNull().default("proposed"),
344
+ createdBySubjectId: text("created_by_subject_id").notNull(),
345
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
346
+ },
347
+ (table) => ({
348
+ workspaceOperation: uniqueIndex(
349
+ "workspace_instruction_policy_onboarding_proposals_workspace_operation_uq"
350
+ ).on(table.workspaceId, table.operationId),
351
+ sourceVersionTarget: uniqueIndex(
352
+ "workspace_instruction_policy_onboarding_proposals_source_version_target_uq"
353
+ ).on(
354
+ table.workspaceId,
355
+ table.kind,
356
+ table.scope,
357
+ sql`coalesce(${table.roleKey}, '')`,
358
+ table.sourceId,
359
+ table.sourceVersion
360
+ ),
361
+ workspaceTimeline: index(
362
+ "workspace_instruction_policy_onboarding_proposals_workspace_time_idx"
363
+ ).on(table.workspaceId, table.createdAt, table.id),
364
+ operationReceipt: check(
365
+ "workspace_instruction_policy_onboarding_proposals_operation_receipt_chk",
366
+ sql`${table.requestFingerprint} ~ '^[0-9a-f]{64}$'`
367
+ ),
368
+ target: check(
369
+ "workspace_instruction_policy_onboarding_proposals_target_chk",
370
+ sql`(
371
+ (${table.kind} = 'charter' and ${table.scope} = 'global' and ${table.roleKey} is null)
372
+ or (${table.kind} = 'policy' and ${table.scope} = 'global' and ${table.roleKey} is null)
373
+ or (${table.kind} = 'policy' and ${table.scope} = 'role' and ${table.roleKey} is not null)
374
+ )`
375
+ ),
376
+ source: check(
377
+ "workspace_instruction_policy_onboarding_proposals_source_chk",
378
+ sql`length(btrim(${table.sourceId})) between 1 and 512
379
+ and length(btrim(${table.sourceVersion})) between 1 and 256
380
+ and ${table.confidenceBps} between 0 and 10000`
381
+ ),
382
+ baseline: check(
383
+ "workspace_instruction_policy_onboarding_proposals_baseline_chk",
384
+ sql`(
385
+ ${table.baselineRevisionId} is null
386
+ and ${table.baselineRevision} is null
387
+ and ${table.baselineContentHash} is null
388
+ and ${table.baselineActivationVersion} = 0
389
+ and ${table.baselineActivatedAt} is null
390
+ ) or (
391
+ ${table.baselineRevisionId} is not null
392
+ and ${table.baselineRevision} > 0
393
+ and ${table.baselineContentHash} ~ '^[0-9a-f]{64}$'
394
+ and ${table.baselineActivationVersion} > 0
395
+ and ${table.baselineActivatedAt} is not null
396
+ )`
397
+ ),
398
+ draft: check(
399
+ "workspace_instruction_policy_onboarding_proposals_draft_chk",
400
+ sql`${table.draftRevision} > 0
401
+ and ${table.draftContentHash} ~ '^[0-9a-f]{64}$'
402
+ and ${table.status} = 'proposed'`
403
+ )
404
+ })
405
+ );
293
406
  var workspaceInstructionPolicySnapshots = pgTable(
294
407
  "workspace_instruction_policy_snapshots",
295
408
  {
@@ -1812,6 +1925,38 @@ var connections = pgTable5(
1812
1925
  )
1813
1926
  })
1814
1927
  );
1928
+ var connectionDisconnectOperations = pgTable5(
1929
+ "connection_disconnect_operations",
1930
+ {
1931
+ id: uuid5("id").primaryKey().defaultRandom(),
1932
+ accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1933
+ workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1934
+ connectionId: uuid5("connection_id").notNull().references(() => connections.id, { onDelete: "cascade" }),
1935
+ subjectId: text5("subject_id").notNull(),
1936
+ idempotencyKey: text5("idempotency_key").notNull(),
1937
+ expectedVersion: integer5("expected_version").notNull(),
1938
+ resultVersion: integer5("result_version").notNull(),
1939
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
1940
+ },
1941
+ (table) => ({
1942
+ workspaceSubjectKey: uniqueIndex5("connection_disconnect_operations_subject_key_uq").on(
1943
+ table.workspaceId,
1944
+ table.subjectId,
1945
+ table.idempotencyKey
1946
+ ),
1947
+ connectionGeneration: uniqueIndex5(
1948
+ "connection_disconnect_operations_connection_generation_uq"
1949
+ ).on(table.workspaceId, table.connectionId, table.expectedVersion),
1950
+ identityValid: check4(
1951
+ "connection_disconnect_operations_identity_check",
1952
+ sql5`length(${table.subjectId}) between 1 and 512
1953
+ and length(${table.idempotencyKey}) between 1 and 200
1954
+ and ${table.idempotencyKey} = btrim(${table.idempotencyKey})
1955
+ and ${table.expectedVersion} > 0
1956
+ and ${table.resultVersion} = ${table.expectedVersion} + 1`
1957
+ )
1958
+ })
1959
+ );
1815
1960
  var connectorActionPolicies = pgTable5(
1816
1961
  "connector_action_policies",
1817
1962
  {
@@ -3015,6 +3160,11 @@ var documents = pgTable5(
3015
3160
  sourceUpdatedAt: timestamp5("source_updated_at", { withTimezone: true }),
3016
3161
  sourceVersion: text5("source_version"),
3017
3162
  aclTags: jsonb5("acl_tags").$type().notNull().default([]),
3163
+ // Durable authorization tuple. The workspace_id above remains ingestion
3164
+ // provenance; organization authority deliberately has no workspace owner.
3165
+ authorityKind: text5("authority_kind").notNull().default("workspace"),
3166
+ authorityWorkspaceId: uuid5("authority_workspace_id"),
3167
+ authoritySubjectId: text5("authority_subject_id"),
3018
3168
  // Per-document access controls. visibility 'private' restricts human reads to
3019
3169
  // created_by (a grant subject id, not a uuid); agent_access=false hides the
3020
3170
  // document from agent retrieval surfaces (docs MCP) while humans keep REST.
@@ -3052,6 +3202,28 @@ var documents = pgTable5(
3052
3202
  table.workspaceId,
3053
3203
  table.curationStatus
3054
3204
  ),
3205
+ authority: index5("documents_authority_idx").on(
3206
+ table.accountId,
3207
+ table.authorityKind,
3208
+ table.authorityWorkspaceId,
3209
+ table.authoritySubjectId,
3210
+ table.status
3211
+ ),
3212
+ authorityWorkspaceAccount: foreignKey({
3213
+ name: "documents_authority_workspace_fk",
3214
+ columns: [table.authorityWorkspaceId, table.accountId],
3215
+ foreignColumns: [workspaces.id, workspaces.accountId]
3216
+ }).onDelete("restrict"),
3217
+ authorityState: check4(
3218
+ "documents_authority_chk",
3219
+ sql5`(${table.authorityKind} = 'organization' and ${table.authorityWorkspaceId} is null and ${table.authoritySubjectId} is null)
3220
+ or (${table.authorityKind} = 'workspace' and ${table.authorityWorkspaceId} = ${table.workspaceId} and ${table.authoritySubjectId} is null)
3221
+ or (${table.authorityKind} = 'personal' and ${table.authorityWorkspaceId} = ${table.workspaceId} and nullif(btrim(${table.authoritySubjectId}), '') is not null and octet_length(convert_to(${table.authoritySubjectId}, 'UTF8')) <= 1024 and ${table.authoritySubjectId} = ${table.createdBy})`
3222
+ ),
3223
+ authorityVisibility: check4(
3224
+ "documents_authority_visibility_chk",
3225
+ sql5`(${table.authorityKind} = 'personal') = (${table.visibility} = 'private')`
3226
+ ),
3055
3227
  visibilityState: check4(
3056
3228
  "documents_visibility_chk",
3057
3229
  sql5`${table.visibility} in ('workspace', 'private')`
@@ -3083,6 +3255,9 @@ var documentChunks = pgTable5(
3083
3255
  chunkIndex: integer5("chunk_index").notNull(),
3084
3256
  text: text5("text").notNull(),
3085
3257
  metadata: jsonb5("metadata").$type().notNull().default({}),
3258
+ authorityKind: text5("authority_kind").notNull().default("workspace"),
3259
+ authorityWorkspaceId: uuid5("authority_workspace_id"),
3260
+ authoritySubjectId: text5("authority_subject_id"),
3086
3261
  embedding: vector("embedding").notNull(),
3087
3262
  embeddingModel: text5("embedding_model").notNull(),
3088
3263
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
@@ -3093,7 +3268,24 @@ var documentChunks = pgTable5(
3093
3268
  table.documentId,
3094
3269
  table.chunkIndex
3095
3270
  ),
3096
- base: index5("document_chunks_workspace_base_idx").on(table.workspaceId, table.baseId)
3271
+ base: index5("document_chunks_workspace_base_idx").on(table.workspaceId, table.baseId),
3272
+ authority: index5("document_chunks_authority_idx").on(
3273
+ table.accountId,
3274
+ table.authorityKind,
3275
+ table.authorityWorkspaceId,
3276
+ table.authoritySubjectId
3277
+ ),
3278
+ authorityWorkspaceAccount: foreignKey({
3279
+ name: "document_chunks_authority_workspace_fk",
3280
+ columns: [table.authorityWorkspaceId, table.accountId],
3281
+ foreignColumns: [workspaces.id, workspaces.accountId]
3282
+ }).onDelete("restrict"),
3283
+ authorityState: check4(
3284
+ "document_chunks_authority_chk",
3285
+ sql5`(${table.authorityKind} = 'organization' and ${table.authorityWorkspaceId} is null and ${table.authoritySubjectId} is null)
3286
+ or (${table.authorityKind} = 'workspace' and ${table.authorityWorkspaceId} = ${table.workspaceId} and ${table.authoritySubjectId} is null)
3287
+ or (${table.authorityKind} = 'personal' and ${table.authorityWorkspaceId} = ${table.workspaceId} and nullif(btrim(${table.authoritySubjectId}), '') is not null and octet_length(convert_to(${table.authoritySubjectId}, 'UTF8')) <= 1024)`
3288
+ )
3097
3289
  })
3098
3290
  );
3099
3291
  var knowledgeMemories = pgTable5(
@@ -6205,6 +6397,7 @@ export {
6205
6397
  workspaceInstructionPolicyRevisions,
6206
6398
  workspaceInstructionPolicyHeads,
6207
6399
  workspaceInstructionPolicyActivationEvents,
6400
+ workspaceInstructionPolicyOnboardingProposals,
6208
6401
  workspaceInstructionPolicySnapshots,
6209
6402
  preferenceRegistryPreferences,
6210
6403
  preferenceRegistryRevisions,
@@ -6243,6 +6436,7 @@ export {
6243
6436
  codexSubscriptionCredentials,
6244
6437
  codexResetRedemptionAttempts,
6245
6438
  connections,
6439
+ connectionDisconnectOperations,
6246
6440
  connectorActionPolicies,
6247
6441
  slackBotUserLinks,
6248
6442
  slackInteractionInbox,
@@ -6342,4 +6536,4 @@ export {
6342
6536
  rigChanges,
6343
6537
  schema_exports
6344
6538
  };
6345
- //# sourceMappingURL=chunk-3UCHDMKG.js.map
6539
+ //# sourceMappingURL=chunk-EX7CDSGH.js.map