@opengeni/db 0.23.0 → 0.26.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 (34) hide show
  1. package/dist/{chunk-3UCHDMKG.js → chunk-7WTDI7Y3.js} +109 -2
  2. package/dist/chunk-7WTDI7Y3.js.map +1 -0
  3. package/dist/{chunk-L6ADMZHE.js → chunk-KW6U54V2.js} +3 -1
  4. package/dist/chunk-KW6U54V2.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 +1168 -336
  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 +2 -2
  12. package/dist/schema.d.ts +262 -4
  13. package/dist/schema.js +3 -1
  14. package/dist/session-realtime-mirror.d.ts +22 -1
  15. package/dist/workspace-instruction-policies-schema.d.ts +68 -0
  16. package/dist/workspace-instruction-policies.d.ts +53 -7
  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/package.json +3 -3
  22. package/src/connection-token-resolver.ts +79 -16
  23. package/src/index.ts +419 -23
  24. package/src/preference-registry.ts +103 -0
  25. package/src/runtime-posture.ts +2 -0
  26. package/src/schema.ts +86 -0
  27. package/src/session-control.ts +48 -1
  28. package/src/session-queue-commands.ts +45 -11
  29. package/src/session-realtime-mirror.ts +117 -1
  30. package/src/session-realtime.ts +49 -1
  31. package/src/workspace-instruction-policies-schema.ts +30 -0
  32. package/src/workspace-instruction-policies.ts +438 -24
  33. package/dist/chunk-3UCHDMKG.js.map +0 -1
  34. 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,
@@ -180,6 +181,8 @@ var workspaceInstructionPolicyRevisions = pgTable(
180
181
  "workspace_instruction_policy_revisions",
181
182
  {
182
183
  id: uuid("id").primaryKey().defaultRandom(),
184
+ operationId: uuid("operation_id"),
185
+ requestFingerprint: text("request_fingerprint"),
183
186
  accountId: uuid("account_id").notNull(),
184
187
  workspaceId: uuid("workspace_id").notNull(),
185
188
  revision: bigint("revision", { mode: "number" }).notNull().default(sql`nextval('workspace_instruction_policy_revision_seq')`),
@@ -195,6 +198,17 @@ var workspaceInstructionPolicyRevisions = pgTable(
195
198
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
196
199
  },
197
200
  (table) => ({
201
+ workspaceOperation: uniqueIndex("workspace_instruction_policy_revisions_workspace_operation_uq").on(table.workspaceId, table.operationId).where(sql`${table.operationId} is not null`),
202
+ operationReceipt: check(
203
+ "workspace_instruction_policy_revisions_operation_receipt_chk",
204
+ sql`(
205
+ (${table.operationId} is null and ${table.requestFingerprint} is null)
206
+ or (
207
+ ${table.operationId} is not null
208
+ and ${table.requestFingerprint} ~ '^[0-9a-f]{64}$'
209
+ )
210
+ )`
211
+ ),
198
212
  workspaceRevision: uniqueIndex(
199
213
  "workspace_instruction_policy_revisions_workspace_revision_uq"
200
214
  ).on(table.workspaceId, table.revision),
@@ -248,6 +262,8 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
248
262
  "workspace_instruction_policy_activation_events",
249
263
  {
250
264
  id: uuid("id").primaryKey().defaultRandom(),
265
+ operationId: uuid("operation_id"),
266
+ requestFingerprint: text("request_fingerprint"),
251
267
  accountId: uuid("account_id").notNull(),
252
268
  workspaceId: uuid("workspace_id").notNull(),
253
269
  kind: text("kind").notNull(),
@@ -266,6 +282,17 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
266
282
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
267
283
  },
268
284
  (table) => ({
285
+ workspaceOperation: uniqueIndex("workspace_instruction_policy_events_workspace_operation_uq").on(table.workspaceId, table.operationId).where(sql`${table.operationId} is not null`),
286
+ operationReceipt: check(
287
+ "workspace_instruction_policy_events_operation_receipt_chk",
288
+ sql`(
289
+ (${table.operationId} is null and ${table.requestFingerprint} is null)
290
+ or (
291
+ ${table.operationId} is not null
292
+ and ${table.requestFingerprint} ~ '^[0-9a-f]{64}$'
293
+ )
294
+ )`
295
+ ),
269
296
  workspaceActivationVersion: uniqueIndex(
270
297
  "workspace_instruction_policy_events_target_version_uq"
271
298
  ).on(
@@ -1812,6 +1839,38 @@ var connections = pgTable5(
1812
1839
  )
1813
1840
  })
1814
1841
  );
1842
+ var connectionDisconnectOperations = pgTable5(
1843
+ "connection_disconnect_operations",
1844
+ {
1845
+ id: uuid5("id").primaryKey().defaultRandom(),
1846
+ accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1847
+ workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1848
+ connectionId: uuid5("connection_id").notNull().references(() => connections.id, { onDelete: "cascade" }),
1849
+ subjectId: text5("subject_id").notNull(),
1850
+ idempotencyKey: text5("idempotency_key").notNull(),
1851
+ expectedVersion: integer5("expected_version").notNull(),
1852
+ resultVersion: integer5("result_version").notNull(),
1853
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
1854
+ },
1855
+ (table) => ({
1856
+ workspaceSubjectKey: uniqueIndex5("connection_disconnect_operations_subject_key_uq").on(
1857
+ table.workspaceId,
1858
+ table.subjectId,
1859
+ table.idempotencyKey
1860
+ ),
1861
+ connectionGeneration: uniqueIndex5(
1862
+ "connection_disconnect_operations_connection_generation_uq"
1863
+ ).on(table.workspaceId, table.connectionId, table.expectedVersion),
1864
+ identityValid: check4(
1865
+ "connection_disconnect_operations_identity_check",
1866
+ sql5`length(${table.subjectId}) between 1 and 512
1867
+ and length(${table.idempotencyKey}) between 1 and 200
1868
+ and ${table.idempotencyKey} = btrim(${table.idempotencyKey})
1869
+ and ${table.expectedVersion} > 0
1870
+ and ${table.resultVersion} = ${table.expectedVersion} + 1`
1871
+ )
1872
+ })
1873
+ );
1815
1874
  var connectorActionPolicies = pgTable5(
1816
1875
  "connector_action_policies",
1817
1876
  {
@@ -3015,6 +3074,11 @@ var documents = pgTable5(
3015
3074
  sourceUpdatedAt: timestamp5("source_updated_at", { withTimezone: true }),
3016
3075
  sourceVersion: text5("source_version"),
3017
3076
  aclTags: jsonb5("acl_tags").$type().notNull().default([]),
3077
+ // Durable authorization tuple. The workspace_id above remains ingestion
3078
+ // provenance; organization authority deliberately has no workspace owner.
3079
+ authorityKind: text5("authority_kind").notNull().default("workspace"),
3080
+ authorityWorkspaceId: uuid5("authority_workspace_id"),
3081
+ authoritySubjectId: text5("authority_subject_id"),
3018
3082
  // Per-document access controls. visibility 'private' restricts human reads to
3019
3083
  // created_by (a grant subject id, not a uuid); agent_access=false hides the
3020
3084
  // document from agent retrieval surfaces (docs MCP) while humans keep REST.
@@ -3052,6 +3116,28 @@ var documents = pgTable5(
3052
3116
  table.workspaceId,
3053
3117
  table.curationStatus
3054
3118
  ),
3119
+ authority: index5("documents_authority_idx").on(
3120
+ table.accountId,
3121
+ table.authorityKind,
3122
+ table.authorityWorkspaceId,
3123
+ table.authoritySubjectId,
3124
+ table.status
3125
+ ),
3126
+ authorityWorkspaceAccount: foreignKey({
3127
+ name: "documents_authority_workspace_fk",
3128
+ columns: [table.authorityWorkspaceId, table.accountId],
3129
+ foreignColumns: [workspaces.id, workspaces.accountId]
3130
+ }).onDelete("restrict"),
3131
+ authorityState: check4(
3132
+ "documents_authority_chk",
3133
+ sql5`(${table.authorityKind} = 'organization' and ${table.authorityWorkspaceId} is null and ${table.authoritySubjectId} is null)
3134
+ or (${table.authorityKind} = 'workspace' and ${table.authorityWorkspaceId} = ${table.workspaceId} and ${table.authoritySubjectId} is null)
3135
+ 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})`
3136
+ ),
3137
+ authorityVisibility: check4(
3138
+ "documents_authority_visibility_chk",
3139
+ sql5`(${table.authorityKind} = 'personal') = (${table.visibility} = 'private')`
3140
+ ),
3055
3141
  visibilityState: check4(
3056
3142
  "documents_visibility_chk",
3057
3143
  sql5`${table.visibility} in ('workspace', 'private')`
@@ -3083,6 +3169,9 @@ var documentChunks = pgTable5(
3083
3169
  chunkIndex: integer5("chunk_index").notNull(),
3084
3170
  text: text5("text").notNull(),
3085
3171
  metadata: jsonb5("metadata").$type().notNull().default({}),
3172
+ authorityKind: text5("authority_kind").notNull().default("workspace"),
3173
+ authorityWorkspaceId: uuid5("authority_workspace_id"),
3174
+ authoritySubjectId: text5("authority_subject_id"),
3086
3175
  embedding: vector("embedding").notNull(),
3087
3176
  embeddingModel: text5("embedding_model").notNull(),
3088
3177
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
@@ -3093,7 +3182,24 @@ var documentChunks = pgTable5(
3093
3182
  table.documentId,
3094
3183
  table.chunkIndex
3095
3184
  ),
3096
- base: index5("document_chunks_workspace_base_idx").on(table.workspaceId, table.baseId)
3185
+ base: index5("document_chunks_workspace_base_idx").on(table.workspaceId, table.baseId),
3186
+ authority: index5("document_chunks_authority_idx").on(
3187
+ table.accountId,
3188
+ table.authorityKind,
3189
+ table.authorityWorkspaceId,
3190
+ table.authoritySubjectId
3191
+ ),
3192
+ authorityWorkspaceAccount: foreignKey({
3193
+ name: "document_chunks_authority_workspace_fk",
3194
+ columns: [table.authorityWorkspaceId, table.accountId],
3195
+ foreignColumns: [workspaces.id, workspaces.accountId]
3196
+ }).onDelete("restrict"),
3197
+ authorityState: check4(
3198
+ "document_chunks_authority_chk",
3199
+ sql5`(${table.authorityKind} = 'organization' and ${table.authorityWorkspaceId} is null and ${table.authoritySubjectId} is null)
3200
+ or (${table.authorityKind} = 'workspace' and ${table.authorityWorkspaceId} = ${table.workspaceId} and ${table.authoritySubjectId} is null)
3201
+ 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)`
3202
+ )
3097
3203
  })
3098
3204
  );
3099
3205
  var knowledgeMemories = pgTable5(
@@ -6243,6 +6349,7 @@ export {
6243
6349
  codexSubscriptionCredentials,
6244
6350
  codexResetRedemptionAttempts,
6245
6351
  connections,
6352
+ connectionDisconnectOperations,
6246
6353
  connectorActionPolicies,
6247
6354
  slackBotUserLinks,
6248
6355
  slackInteractionInbox,
@@ -6342,4 +6449,4 @@ export {
6342
6449
  rigChanges,
6343
6450
  schema_exports
6344
6451
  };
6345
- //# sourceMappingURL=chunk-3UCHDMKG.js.map
6452
+ //# sourceMappingURL=chunk-7WTDI7Y3.js.map