@opengeni/db 5.0.1 → 6.0.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 (212) hide show
  1. package/dist/automations.d.ts +0 -2
  2. package/dist/canonical-human-identities.d.ts +4 -0
  3. package/dist/canonical-human-identities.js +3 -3
  4. package/dist/capability-components.d.ts +5 -13
  5. package/dist/capability-integrations.d.ts +23 -8
  6. package/dist/capability-reconciliation.d.ts +5 -0
  7. package/dist/capability-reconciliation.js +21 -0
  8. package/dist/capability-reconciliation.js.map +1 -0
  9. package/dist/{chunk-6T2GGYWE.js → chunk-4UJCXBR2.js} +4 -5800
  10. package/dist/chunk-4UJCXBR2.js.map +1 -0
  11. package/dist/{chunk-MWMXWHJD.js → chunk-7JCDSMX2.js} +2 -2
  12. package/dist/chunk-AJA2ZIUW.js +219 -0
  13. package/dist/chunk-AJA2ZIUW.js.map +1 -0
  14. package/dist/chunk-CDAT6EKW.js +247 -0
  15. package/dist/chunk-CDAT6EKW.js.map +1 -0
  16. package/dist/{chunk-DPONPYJD.js → chunk-CJI6G254.js} +70 -18
  17. package/dist/chunk-CJI6G254.js.map +1 -0
  18. package/dist/chunk-G32NVMRJ.js +276 -0
  19. package/dist/chunk-G32NVMRJ.js.map +1 -0
  20. package/dist/chunk-GABXCG3N.js +5811 -0
  21. package/dist/chunk-GABXCG3N.js.map +1 -0
  22. package/dist/{chunk-ERKVSPDX.js → chunk-LVY33EWL.js} +3 -3
  23. package/dist/{chunk-45CP2YKY.js → chunk-MAMBI2HR.js} +9 -3
  24. package/dist/{chunk-45CP2YKY.js.map → chunk-MAMBI2HR.js.map} +1 -1
  25. package/dist/{chunk-F73UKJY6.js → chunk-MN5PZMEK.js} +91 -108
  26. package/dist/chunk-MN5PZMEK.js.map +1 -0
  27. package/dist/chunk-PJI4MUZ7.js +131 -0
  28. package/dist/chunk-PJI4MUZ7.js.map +1 -0
  29. package/dist/{chunk-T6BWIGWJ.js → chunk-RIYHP2WU.js} +2 -2
  30. package/dist/{chunk-7HMK3B45.js → chunk-RL2MUXM3.js} +16 -7
  31. package/dist/chunk-RL2MUXM3.js.map +1 -0
  32. package/dist/{chunk-HQDVI2DB.js → chunk-SYKHLPTK.js} +4 -3
  33. package/dist/{chunk-HQDVI2DB.js.map → chunk-SYKHLPTK.js.map} +1 -1
  34. package/dist/{chunk-T6YLHJLS.js → chunk-XIXVVBW2.js} +198 -51
  35. package/dist/chunk-XIXVVBW2.js.map +1 -0
  36. package/dist/chunk-ZPJ6V2VG.js +156 -0
  37. package/dist/chunk-ZPJ6V2VG.js.map +1 -0
  38. package/dist/codex-capacity-recovery.d.ts +12 -0
  39. package/dist/codex-failure-eligibility.d.ts +9 -0
  40. package/dist/company-profile-schema.d.ts +4 -2
  41. package/dist/connect-attempts.d.ts +15 -0
  42. package/dist/connect-attempts.js +25 -0
  43. package/dist/connect-attempts.js.map +1 -0
  44. package/dist/connection-authority.d.ts +7 -63
  45. package/dist/connection-refresh-lock.d.ts +4 -0
  46. package/dist/connection-token-resolver.d.ts +8 -43
  47. package/dist/database-timing.d.ts +10 -0
  48. package/dist/database.d.ts +4 -0
  49. package/dist/editable-artifact-durable-export.js +2 -2
  50. package/dist/editable-artifacts.d.ts +9 -0
  51. package/dist/editable-artifacts.js +7 -5
  52. package/dist/index.d.ts +447 -78
  53. package/dist/index.js +12705 -12872
  54. package/dist/index.js.map +1 -1
  55. package/dist/insights-usage-bundle.d.ts +3 -0
  56. package/dist/integration-bindings.d.ts +1 -1
  57. package/dist/integration-facets.d.ts +18 -1
  58. package/dist/knowledge-entries-schema.d.ts +2 -0
  59. package/dist/knowledge-entries.d.ts +1 -0
  60. package/dist/knowledge-indexing.d.ts +1 -0
  61. package/dist/live-session-attempt.d.ts +35 -137
  62. package/dist/managed-auth-session-sets.js +3 -3
  63. package/dist/mcp-account-bindings.d.ts +4 -0
  64. package/dist/mcp-oauth.d.ts +11 -0
  65. package/dist/mcp-operations.js +2 -2
  66. package/dist/migrate.js +1 -1
  67. package/dist/organization-integration-policy.d.ts +51 -0
  68. package/dist/organization-integration-policy.js +18 -0
  69. package/dist/organization-integration-policy.js.map +1 -0
  70. package/dist/organization-usage.d.ts +20 -0
  71. package/dist/plugin-packages.d.ts +9 -12
  72. package/dist/pr-review.d.ts +0 -11
  73. package/dist/preference-registry-schema.d.ts +17 -0
  74. package/dist/provision-roles.js +1 -1
  75. package/dist/retained-provider-commands.d.ts +124 -6
  76. package/dist/retained-provider-commands.js +29 -97
  77. package/dist/retained-provider-commands.js.map +1 -1
  78. package/dist/retired-session-create-metadata.d.ts +4 -0
  79. package/dist/runtime-posture.d.ts +7 -5
  80. package/dist/schema.d.ts +876 -656
  81. package/dist/schema.js +5 -7
  82. package/dist/session-admission-block.d.ts +32 -0
  83. package/dist/session-attempt-writers.d.ts +4 -0
  84. package/dist/session-background-commands.js +5 -4
  85. package/dist/session-command-output.js +8 -126
  86. package/dist/session-command-output.js.map +1 -1
  87. package/dist/session-control.d.ts +5 -1
  88. package/dist/session-event-slices.d.ts +10 -0
  89. package/dist/session-event-slices.js +8 -222
  90. package/dist/session-event-slices.js.map +1 -1
  91. package/dist/session-file-attachments.d.ts +28 -0
  92. package/dist/session-goal-reports.d.ts +43 -0
  93. package/dist/session-mcp-approval.d.ts +4 -0
  94. package/dist/session-mcp-credential-rotation.js +5 -4
  95. package/dist/session-mcp-credential-rotation.js.map +1 -1
  96. package/dist/session-message-search.d.ts +22 -0
  97. package/dist/session-queue-commands.d.ts +2 -6
  98. package/dist/session-retry.d.ts +36 -0
  99. package/dist/session-tenancy.js +3 -3
  100. package/dist/skill-source-release-impact.d.ts +18 -0
  101. package/dist/skill-source-release.d.ts +9 -0
  102. package/dist/skills.d.ts +7 -1
  103. package/dist/user-resource-authority.d.ts +0 -8
  104. package/dist/video-generation.js +3 -3
  105. package/dist/workspace-tool-defaults.js +5 -4
  106. package/dist/workspace-tool-defaults.js.map +1 -1
  107. package/drizzle/0468_knowledge_relationship_projection.sql +30 -0
  108. package/drizzle/0469_knowledge_source_discovery.sql +85 -0
  109. package/drizzle/0470_organization_integration_policy.sql +151 -0
  110. package/drizzle/0471_usage_events_account_recent_index.sql +4 -0
  111. package/drizzle/0472_usage_events_workspace_recent_index.sql +4 -0
  112. package/drizzle/0473_organization_usage_analytical_capability.sql +237 -0
  113. package/drizzle/0474_goal_report_requirements.sql +156 -0
  114. package/drizzle/0475_session_event_history_statistics.sql +15 -0
  115. package/drizzle/0476_session_event_history_policy_planning.sql +29 -0
  116. package/drizzle/0477_managed_sign_in_methods.sql +303 -0
  117. package/drizzle/0478_sender_owned_connections.sql +2772 -0
  118. package/drizzle/0479_connection_create_idempotency.sql +16 -0
  119. package/drizzle/0480_private_session_organization_key_administration.sql +154 -0
  120. package/drizzle/0481_personal_connection_visibility_cleanup.sql +45 -0
  121. package/drizzle/0482_remove_packs.sql +417 -0
  122. package/drizzle/0483_preclaim_admission_block.sql +85 -0
  123. package/drizzle/0484_insights_usage_projection.sql +211 -0
  124. package/drizzle/0485_inherited_mcp_approval_policies.sql +6 -0
  125. package/drizzle/0486_reasoning_configuration_message_forks.sql +35 -0
  126. package/drizzle/0487_skill_catalog_message_forks.sql +26 -0
  127. package/drizzle/0488_permanent_skill_removal.sql +207 -0
  128. package/drizzle/0489_modal_command_byte_offsets.sql +17 -0
  129. package/drizzle/0490_periodic_capture_attempt_cadence.sql +6 -0
  130. package/drizzle/0491_warm_capture_holder_reclamation.sql +57 -0
  131. package/drizzle/0492_codex_accepted_source_authority.sql +249 -0
  132. package/drizzle/0493_stopping_command_error_containment.sql +58 -0
  133. package/drizzle/0494_mcp_account_bindings.sql +334 -0
  134. package/drizzle/0495_consented_sandbox_recovery.sql +220 -0
  135. package/drizzle/0496_supervised_command_settlement.sql +386 -0
  136. package/drizzle/0497_modal_inventory_owner_read_capability.sql +112 -0
  137. package/drizzle/0498_enrollment_membership_fence.sql +87 -0
  138. package/drizzle/0499_session_attachment_access.sql +224 -0
  139. package/drizzle/0500_session_execution_epoch.sql +37 -0
  140. package/drizzle/0501_session_sharing_execution.sql +591 -0
  141. package/drizzle/0502_active_message_boundary_forks.sql +30 -0
  142. package/package.json +17 -5
  143. package/src/automations.ts +17 -73
  144. package/src/canonical-human-identities.ts +17 -5
  145. package/src/capability-components.ts +7 -24
  146. package/src/capability-integrations.ts +301 -21
  147. package/src/capability-reconciliation.ts +19 -0
  148. package/src/codex-capacity-recovery.ts +47 -0
  149. package/src/codex-failure-eligibility.ts +93 -0
  150. package/src/connect-attempts.ts +49 -18
  151. package/src/connection-authority.ts +12 -158
  152. package/src/connection-refresh-lock.ts +22 -0
  153. package/src/connection-token-resolver.ts +58 -530
  154. package/src/database-timing.ts +43 -0
  155. package/src/database.ts +61 -26
  156. package/src/editable-artifacts.ts +1 -1
  157. package/src/index.ts +3578 -1273
  158. package/src/insights-model-bundle.ts +19 -7
  159. package/src/insights-usage-bundle.ts +16 -19
  160. package/src/integration-bindings.ts +2 -7
  161. package/src/integration-facets.ts +73 -6
  162. package/src/knowledge-entries.ts +8 -1
  163. package/src/live-session-attempt.ts +0 -22
  164. package/src/mcp-account-bindings.ts +12 -0
  165. package/src/mcp-oauth.ts +26 -0
  166. package/src/organization-integration-policy.ts +235 -0
  167. package/src/organization-usage.ts +83 -0
  168. package/src/plugin-packages.ts +226 -42
  169. package/src/pr-review.ts +7 -69
  170. package/src/preference-registry-schema.ts +1 -0
  171. package/src/provision-roles.ts +50 -37
  172. package/src/retained-provider-commands.ts +286 -9
  173. package/src/retired-session-create-metadata.ts +16 -0
  174. package/src/runtime-posture.ts +217 -13
  175. package/src/schema.ts +104 -120
  176. package/src/session-admission-block.ts +29 -0
  177. package/src/session-attempt-writers.ts +48 -0
  178. package/src/session-control.ts +21 -5
  179. package/src/session-event-slices.ts +76 -26
  180. package/src/session-file-attachments.ts +66 -0
  181. package/src/session-goal-reports.ts +255 -0
  182. package/src/session-mcp-approval.ts +30 -0
  183. package/src/session-message-search.ts +348 -0
  184. package/src/session-queue-commands.ts +60 -36
  185. package/src/session-retry.ts +319 -0
  186. package/src/skill-config-migration.ts +11 -2
  187. package/src/skill-source-release-impact.ts +33 -0
  188. package/src/skill-source-release.ts +67 -26
  189. package/src/skills.ts +44 -6
  190. package/src/user-resource-authority.ts +0 -56
  191. package/dist/chunk-6T2GGYWE.js.map +0 -1
  192. package/dist/chunk-7HMK3B45.js.map +0 -1
  193. package/dist/chunk-DPONPYJD.js.map +0 -1
  194. package/dist/chunk-F73UKJY6.js.map +0 -1
  195. package/dist/chunk-T6YLHJLS.js.map +0 -1
  196. package/dist/host-mcp-binding-match.d.ts +0 -5
  197. package/dist/host-mcp-bindings.d.ts +0 -79
  198. package/dist/host-mcp-resolvers.d.ts +0 -47
  199. package/dist/host-mcp-task-authority.d.ts +0 -43
  200. package/dist/host-selection-identity.d.ts +0 -6
  201. package/dist/pack-components.d.ts +0 -83
  202. package/dist/pack-installations.d.ts +0 -86
  203. package/src/host-mcp-binding-match.ts +0 -34
  204. package/src/host-mcp-bindings.ts +0 -777
  205. package/src/host-mcp-resolvers.ts +0 -266
  206. package/src/host-mcp-task-authority.ts +0 -384
  207. package/src/host-selection-identity.ts +0 -29
  208. package/src/pack-components.ts +0 -980
  209. package/src/pack-installations.ts +0 -950
  210. /package/dist/{chunk-MWMXWHJD.js.map → chunk-7JCDSMX2.js.map} +0 -0
  211. /package/dist/{chunk-ERKVSPDX.js.map → chunk-LVY33EWL.js.map} +0 -0
  212. /package/dist/{chunk-T6BWIGWJ.js.map → chunk-RIYHP2WU.js.map} +0 -0
@@ -0,0 +1,43 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+
3
+ export type DatabaseTimingStage =
4
+ | "transaction_admission"
5
+ | "savepoint_admission"
6
+ | "rls_setup"
7
+ | "scoped_callback";
8
+ export type DatabaseTimingObservation = {
9
+ stage: DatabaseTimingStage;
10
+ outcome: "completed" | "failed";
11
+ durationMs: number;
12
+ };
13
+ export type DatabaseTimingObserver = (observation: DatabaseTimingObservation) => void;
14
+
15
+ const timingObserver = new AsyncLocalStorage<DatabaseTimingObserver>();
16
+
17
+ /** Opt-in, async-local diagnostics only; no identity or query payload is retained. */
18
+ export function withDatabaseTimingObserver<T>(
19
+ observer: DatabaseTimingObserver,
20
+ work: () => Promise<T>,
21
+ ): Promise<T> {
22
+ return timingObserver.run(observer, work);
23
+ }
24
+
25
+ export function startDatabaseTiming(
26
+ stage: DatabaseTimingStage,
27
+ ): (outcome: DatabaseTimingObservation["outcome"]) => void {
28
+ const observer = timingObserver.getStore();
29
+ if (!observer) return () => undefined;
30
+ const started = performance.now();
31
+ let finished = false;
32
+ return (outcome) => {
33
+ if (finished) return;
34
+ finished = true;
35
+ try {
36
+ // Do not await observers or let rejected async observers escape either.
37
+ const result = observer({ stage, outcome, durationMs: performance.now() - started });
38
+ void Promise.resolve(result).catch(() => undefined);
39
+ } catch {
40
+ // Diagnostics must not replace database results or the original error.
41
+ }
42
+ };
43
+ }
package/src/database.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { SessionAttachmentReadAccess } from "./session-file-attachments";
1
2
  import { AsyncLocalStorage } from "node:async_hooks";
2
3
  import { eq, sql, type SQL } from "drizzle-orm";
3
4
  import type { PgDatabase, PgTransactionConfig } from "drizzle-orm/pg-core";
@@ -10,6 +11,7 @@ import {
10
11
  } from "./persistence-errors";
11
12
  import { LOSSLESS_CONTENT_WRITER_APPLICATION_NAME } from "./lossless-json";
12
13
  import * as schema from "./schema";
14
+ import { startDatabaseTiming } from "./database-timing";
13
15
 
14
16
  // §7.7 driver widening (Step I). `Database` is the structural, cross-driver
15
17
  // query-layer port: every helper in this file accepts `db: Database` and uses
@@ -52,6 +54,8 @@ export type RlsContext = {
52
54
  };
53
55
 
54
56
  export type SessionRlsActorContext = {
57
+ /** Server-authorized session attachment scope; never taken from request JSON. */
58
+ sessionAttachmentReadAccess?: SessionAttachmentReadAccess;
55
59
  subjectId: string;
56
60
  /** Host-verified personal file ownership, never a request-supplied subject. */
57
61
  privateFileOwnerSubjectId?: string | null;
@@ -59,6 +63,9 @@ export type SessionRlsActorContext = {
59
63
  };
60
64
 
61
65
  const sessionRlsActorContext = new AsyncLocalStorage<SessionRlsActorContext>();
66
+ export function currentSessionAttachmentReadAccess(): SessionAttachmentReadAccess | undefined {
67
+ return sessionRlsActorContext.getStore()?.sessionAttachmentReadAccess;
68
+ }
62
69
 
63
70
  export async function withSessionRlsActorContext<T>(
64
71
  actor: SessionRlsActorContext,
@@ -469,32 +476,60 @@ export async function withRlsContext<T>(
469
476
  sessionTenancyFence: "shared" | "none" = "shared",
470
477
  ): Promise<T> {
471
478
  const restoreParentScope = isTransactionHandle(db);
472
- return await db.transaction(async (tx) => {
473
- const scoped = tx as unknown as Database;
474
- const parentScope = restoreParentScope ? await readRlsContextSettings(scoped) : null;
475
- await setRlsContext(scoped, context);
476
- if (context.workspaceId && sessionTenancyFence === "shared") {
477
- await scoped.execute(
478
- sql`select pg_advisory_xact_lock_shared(hashtextextended(${`session-tenancy:${context.workspaceId}`}, 0))`,
479
- );
480
- }
481
- // Defense-in-depth: read the LOCAL GUC back on THIS backend BEFORE running
482
- // the scoped query. The set_config and this read share one db.transaction,
483
- // which a transaction pooler pins to a single backend — so a mismatch here
484
- // means the context was genuinely lost (a torn transaction / pooler backend
485
- // swap), not normal operation. Without this guard such an event runs the
486
- // scoped read with an empty account_id and returns zero RLS-visible rows,
487
- // manufacturing a phantom "no active subscription" from a credential that is
488
- // in fact active. Convert that silent false into a loud, root-cause-bearing
489
- // error so the caller can retry rather than permanently mis-decide.
490
- await assertRlsContextApplied(scoped, context);
491
- const value = await fn(scoped);
492
- // A nested transaction is a savepoint, and SET LOCAL survives successful
493
- // savepoint release. Restore only the tenant scope the nested helper owns;
494
- // writer/protocol capabilities intentionally remain transaction-wide.
495
- if (parentScope) await restoreRlsContextSettings(scoped, parentScope);
496
- return value;
497
- }, transactionConfig);
479
+ // Callback entry includes connection admission AND BEGIN/SAVEPOINT round-trip.
480
+ // This is deliberately not advertised as pure pool wait.
481
+ const admission = startDatabaseTiming(
482
+ restoreParentScope ? "savepoint_admission" : "transaction_admission",
483
+ );
484
+ try {
485
+ return await db.transaction(async (tx) => {
486
+ admission("completed");
487
+ const setup = startDatabaseTiming("rls_setup");
488
+ const scoped = tx as unknown as Database;
489
+ let parentScope: RlsContextSettings | null;
490
+ try {
491
+ parentScope = restoreParentScope ? await readRlsContextSettings(scoped) : null;
492
+ await setRlsContext(scoped, context);
493
+ if (context.workspaceId && sessionTenancyFence === "shared") {
494
+ await scoped.execute(
495
+ sql`select pg_advisory_xact_lock_shared(hashtextextended(${`session-tenancy:${context.workspaceId}`}, 0))`,
496
+ );
497
+ }
498
+ // Defense-in-depth: read the LOCAL GUC back on THIS backend BEFORE running
499
+ // the scoped query. The set_config and this read share one db.transaction,
500
+ // which a transaction pooler pins to a single backend — so a mismatch here
501
+ // means the context was genuinely lost (a torn transaction / pooler backend
502
+ // swap), not normal operation. Without this guard such an event runs the
503
+ // scoped read with an empty account_id and returns zero RLS-visible rows,
504
+ // manufacturing a phantom "no active subscription" from a credential that is
505
+ // in fact active. Convert that silent false into a loud, root-cause-bearing
506
+ // error so the caller can retry rather than permanently mis-decide.
507
+ await assertRlsContextApplied(scoped, context);
508
+ setup("completed");
509
+ } catch (error) {
510
+ setup("failed");
511
+ throw error;
512
+ }
513
+ const callback = startDatabaseTiming("scoped_callback");
514
+ let value: T;
515
+ try {
516
+ value = await fn(scoped);
517
+ callback("completed");
518
+ } catch (error) {
519
+ callback("failed");
520
+ throw error;
521
+ }
522
+ // A nested transaction is a savepoint, and SET LOCAL survives successful
523
+ // savepoint release. Restore only the tenant scope the nested helper owns;
524
+ // writer/protocol capabilities intentionally remain transaction-wide.
525
+ if (parentScope) await restoreRlsContextSettings(scoped, parentScope);
526
+ return value;
527
+ }, transactionConfig);
528
+ } catch (error) {
529
+ // No-op after callback entry; only admission failures are counted here.
530
+ admission("failed");
531
+ throw error;
532
+ }
498
533
  }
499
534
 
500
535
  /**
@@ -4760,7 +4760,7 @@ function persistedEditableArtifactActorKey(actor: PersistedEditableArtifactActor
4760
4760
  }
4761
4761
  }
4762
4762
 
4763
- async function transactionallyAuthorizeEditableArtifactActor(
4763
+ export async function transactionallyAuthorizeEditableArtifactActor(
4764
4764
  tx: Database,
4765
4765
  input: Readonly<{
4766
4766
  scope: PersistedEditableArtifactScope;