@opengeni/db 1.4.0 → 1.4.4

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 (69) hide show
  1. package/dist/canonical-human-identities.js +2 -2
  2. package/dist/capability-reconciliation.js +1 -1
  3. package/dist/{chunk-27T4AP25.js → chunk-45EMCVJC.js} +22 -6
  4. package/dist/{chunk-27T4AP25.js.map → chunk-45EMCVJC.js.map} +1 -1
  5. package/dist/{chunk-EMYA6XNE.js → chunk-4SUZSKKW.js} +2 -2
  6. package/dist/{chunk-VCHK4D6S.js → chunk-57FM4RG4.js} +2 -2
  7. package/dist/{chunk-7QWWTVYH.js → chunk-5ROHLEN6.js} +29 -4
  8. package/dist/chunk-5ROHLEN6.js.map +1 -0
  9. package/dist/{chunk-BA52ITIY.js → chunk-7HP5NCRN.js} +2 -2
  10. package/dist/{chunk-UQELJ6OM.js → chunk-A4LPJOKP.js} +2 -2
  11. package/dist/{chunk-CKDHKQS4.js → chunk-DEMX4GWU.js} +4 -4
  12. package/dist/{chunk-GC5GUTV3.js → chunk-ISNA4KUA.js} +2 -2
  13. package/dist/{chunk-3WUCM7YF.js → chunk-JYKUR5KT.js} +2 -2
  14. package/dist/{chunk-EFANLEWI.js → chunk-LGXWM3UJ.js} +2 -2
  15. package/dist/{chunk-T3CYF3DH.js → chunk-NI3WPW2L.js} +35 -17
  16. package/dist/{chunk-T3CYF3DH.js.map → chunk-NI3WPW2L.js.map} +1 -1
  17. package/dist/{chunk-TRUEH4I2.js → chunk-PUOQEL6A.js} +2 -2
  18. package/dist/{chunk-NT7OGKYX.js → chunk-SG5YDHSE.js} +3 -3
  19. package/dist/{chunk-AMK3FNOW.js → chunk-WAFY2TCB.js} +3 -3
  20. package/dist/codemode-approvals.d.ts +7 -1
  21. package/dist/connect-attempts.js +2 -2
  22. package/dist/credit-balances.d.ts +25 -4
  23. package/dist/database.d.ts +15 -3
  24. package/dist/editable-artifact-durable-export.js +1 -1
  25. package/dist/editable-artifacts.js +2 -2
  26. package/dist/index.d.ts +24 -2
  27. package/dist/index.js +2782 -2509
  28. package/dist/index.js.map +1 -1
  29. package/dist/interaction-schema.d.ts +2 -0
  30. package/dist/managed-auth-session-sets.js +2 -2
  31. package/dist/mcp-operations.js +1 -1
  32. package/dist/modal-native-live-origin.d.ts +75 -0
  33. package/dist/organization-integration-policy.js +2 -2
  34. package/dist/provision-roles.js +1 -1
  35. package/dist/retained-provider-commands.d.ts +21 -21
  36. package/dist/retained-provider-commands.js +5 -5
  37. package/dist/runtime-posture.d.ts +1 -1
  38. package/dist/sandbox-interaction-idle.d.ts +22 -0
  39. package/dist/session-background-commands.js +3 -3
  40. package/dist/session-command-output.js +4 -4
  41. package/dist/session-event-slices.js +2 -2
  42. package/dist/session-mcp-credential-rotation.js +4 -4
  43. package/dist/session-tenancy.js +2 -2
  44. package/dist/video-generation.js +2 -2
  45. package/dist/workspace-tool-defaults.js +3 -3
  46. package/drizzle/0632_modal_native_live_origin.sql +239 -0
  47. package/package.json +7 -7
  48. package/src/codemode-approvals.ts +52 -22
  49. package/src/codemode-operations.ts +198 -181
  50. package/src/credit-balances.ts +58 -17
  51. package/src/database.ts +47 -8
  52. package/src/index.ts +453 -255
  53. package/src/modal-native-live-origin.ts +148 -0
  54. package/src/provision-roles.ts +12 -0
  55. package/src/runtime-posture.ts +32 -3
  56. package/src/sandbox-interaction-idle.ts +91 -0
  57. package/src/transcription-recordings.ts +3 -1
  58. package/dist/chunk-7QWWTVYH.js.map +0 -1
  59. /package/dist/{chunk-EMYA6XNE.js.map → chunk-4SUZSKKW.js.map} +0 -0
  60. /package/dist/{chunk-VCHK4D6S.js.map → chunk-57FM4RG4.js.map} +0 -0
  61. /package/dist/{chunk-BA52ITIY.js.map → chunk-7HP5NCRN.js.map} +0 -0
  62. /package/dist/{chunk-UQELJ6OM.js.map → chunk-A4LPJOKP.js.map} +0 -0
  63. /package/dist/{chunk-CKDHKQS4.js.map → chunk-DEMX4GWU.js.map} +0 -0
  64. /package/dist/{chunk-GC5GUTV3.js.map → chunk-ISNA4KUA.js.map} +0 -0
  65. /package/dist/{chunk-3WUCM7YF.js.map → chunk-JYKUR5KT.js.map} +0 -0
  66. /package/dist/{chunk-EFANLEWI.js.map → chunk-LGXWM3UJ.js.map} +0 -0
  67. /package/dist/{chunk-TRUEH4I2.js.map → chunk-PUOQEL6A.js.map} +0 -0
  68. /package/dist/{chunk-NT7OGKYX.js.map → chunk-SG5YDHSE.js.map} +0 -0
  69. /package/dist/{chunk-AMK3FNOW.js.map → chunk-WAFY2TCB.js.map} +0 -0
package/src/database.ts CHANGED
@@ -864,17 +864,33 @@ export async function withSessionActivityRlsContext<T>(
864
864
  fn: (db: SessionActivityDatabase) => Promise<T>,
865
865
  transactionConfig?: PgTransactionConfig,
866
866
  fenceMode: "shared" | "none" = "shared",
867
- organizationMembershipFence = false,
867
+ organizationMembershipFence: OrganizationMembershipFenceMode = false,
868
868
  ): Promise<T> {
869
869
  await assertSessionActivityGateEntry(db);
870
870
  return await withRlsContext(
871
871
  db,
872
872
  context,
873
873
  async (scopedDb) => {
874
- if (organizationMembershipFence) {
875
- // Claim can inherit membership-fenced authority after locking sessions.
876
- // Acquire membership before even a shared tenancy fence: an exclusive
877
- // tenancy/control waiter can otherwise complete the same lock cycle.
874
+ if (organizationMembershipFence === "shared") {
875
+ // A pure reader of membership truth (the turn claim) only needs to
876
+ // exclude membership/tenancy mutators, which hold this key
877
+ // exclusively. Readers must not serialize each other: an exclusive
878
+ // claim fence made every turn claim in one organization queue behind
879
+ // every other one. Same position as the exclusive mode below, so the
880
+ // membership -> tenancy -> control prefix order is unchanged. A
881
+ // caller using this mode must never request the exclusive lock on the
882
+ // same key later in the transaction (no in-place escalation).
883
+ await scopedDb.execute(sql`select pg_advisory_xact_lock_shared(
884
+ hashtextextended(${`organization-membership:${context.accountId}`}, 0))`);
885
+ if (fenceMode === "shared") {
886
+ await scopedDb.execute(sql`select pg_advisory_xact_lock_shared(
887
+ hashtextextended(${`session-tenancy:${context.workspaceId}`}, 0))`);
888
+ }
889
+ } else if (organizationMembershipFence) {
890
+ // Callers that reauthorize or mutate under the membership lifecycle
891
+ // lock take it exclusively. Acquire membership before even a shared
892
+ // tenancy fence: an exclusive tenancy/control waiter can otherwise
893
+ // complete the same lock cycle.
878
894
  await scopedDb.execute(sql`select pg_advisory_xact_lock(
879
895
  hashtextextended(${`organization-membership:${context.accountId}`}, 0))`);
880
896
  if (fenceMode === "shared") {
@@ -894,21 +910,37 @@ export async function withSessionActivityRlsContext<T>(
894
910
  return value;
895
911
  },
896
912
  transactionConfig,
897
- organizationMembershipFence ? "none" : fenceMode,
913
+ organizationMembershipFence !== false ? "none" : fenceMode,
898
914
  );
899
915
  }
900
916
 
917
+ /**
918
+ * `true`/`"exclusive"`: the callback reauthorizes or mutates under the
919
+ * organization-membership lifecycle lock. `"shared"`: the callback only reads
920
+ * membership-fenced authority and must never escalate to exclusive.
921
+ */
922
+ export type OrganizationMembershipFenceMode = boolean | "exclusive" | "shared";
923
+
924
+ /**
925
+ * `organizationMembershipFence` is required when the callback takes the
926
+ * organization-membership lifecycle lock (for example external-actor
927
+ * reauthorization): that lock precedes the session-tenancy fence and the
928
+ * canonical control/workspace/session prefix, never follows it.
929
+ */
901
930
  export async function withWorkspaceSessionActivityRls<T>(
902
931
  db: Database,
903
932
  workspaceId: string,
904
933
  fn: (db: SessionActivityDatabase) => Promise<T>,
905
934
  transactionConfig?: PgTransactionConfig,
935
+ organizationMembershipFence = false,
906
936
  ): Promise<T> {
907
937
  return await withSessionActivityRlsContext(
908
938
  db,
909
939
  { ...(await rlsContextForWorkspace(db, workspaceId)), workspaceId },
910
940
  fn,
911
941
  transactionConfig,
942
+ "shared",
943
+ organizationMembershipFence,
912
944
  );
913
945
  }
914
946
 
@@ -972,14 +1004,21 @@ export async function retrySessionActivityRls<T>(
972
1004
  /** Claim can inherit membership-fenced causal authority after locking the
973
1005
  * session. Acquire that fence before tenancy/control/session instead. An
974
1006
  * enclosing transaction must preserve this same lock prefix. */
975
- organizationMembershipFence?: boolean;
1007
+ organizationMembershipFence?: OrganizationMembershipFenceMode;
976
1008
  },
977
1009
  fn: (db: SessionActivityDatabase) => Promise<T>,
978
1010
  ): Promise<T> {
979
1011
  return await runIdempotentPersistenceTransaction(options, async () => {
980
1012
  if (options.organizationMembershipFence) {
981
1013
  const context = { ...(await rlsContextForWorkspace(db, workspaceId)), workspaceId };
982
- return await withSessionActivityRlsContext(db, context, fn, undefined, "shared", true);
1014
+ return await withSessionActivityRlsContext(
1015
+ db,
1016
+ context,
1017
+ fn,
1018
+ undefined,
1019
+ "shared",
1020
+ options.organizationMembershipFence,
1021
+ );
983
1022
  }
984
1023
  return await withWorkspaceSessionActivityRls(db, workspaceId, fn);
985
1024
  });