@opengeni/db 6.0.1 → 6.0.3

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 (87) hide show
  1. package/dist/browser-sessions.d.ts +26 -0
  2. package/dist/canonical-human-identities.js +3 -3
  3. package/dist/capability-reconciliation.js +2 -2
  4. package/dist/{chunk-4RDUZ5UV.js → chunk-4ZQFT5II.js} +2 -2
  5. package/dist/{chunk-6ORJPCYW.js → chunk-5UOWNKPP.js} +2 -2
  6. package/dist/{chunk-4CCFFLDZ.js → chunk-BG46J5HF.js} +13 -2
  7. package/dist/chunk-BG46J5HF.js.map +1 -0
  8. package/dist/{chunk-CSVHCF3R.js → chunk-IB3SW3JW.js} +11 -4
  9. package/dist/{chunk-CSVHCF3R.js.map → chunk-IB3SW3JW.js.map} +1 -1
  10. package/dist/{chunk-GSB4ISHE.js → chunk-IIPWNNVR.js} +4 -1
  11. package/dist/chunk-IIPWNNVR.js.map +1 -0
  12. package/dist/{chunk-MAMBI2HR.js → chunk-JPYN5XKV.js} +39 -3
  13. package/dist/chunk-JPYN5XKV.js.map +1 -0
  14. package/dist/{chunk-LSLNMENV.js → chunk-KZXWUXWV.js} +4 -4
  15. package/dist/{chunk-LO6BVXXH.js → chunk-LD52IFS3.js} +2 -2
  16. package/dist/{chunk-JILAWE26.js → chunk-M5Z6II2P.js} +2 -2
  17. package/dist/{chunk-PGIFHEBA.js → chunk-RVEOGRMF.js} +2 -2
  18. package/dist/{chunk-H7BC444C.js → chunk-SRAMNVHT.js} +17 -1
  19. package/dist/chunk-SRAMNVHT.js.map +1 -0
  20. package/dist/{chunk-XK6HXON2.js → chunk-UXFBXCHM.js} +2 -2
  21. package/dist/{chunk-RXH5CFG3.js → chunk-VE2XK2KD.js} +12 -8
  22. package/dist/{chunk-RXH5CFG3.js.map → chunk-VE2XK2KD.js.map} +1 -1
  23. package/dist/{chunk-FULLE5CF.js → chunk-WT7HG43Y.js} +3 -3
  24. package/dist/{chunk-I7HQL6FK.js → chunk-ZM5BA3TD.js} +3 -3
  25. package/dist/connect-attempts.js +3 -3
  26. package/dist/database.d.ts +8 -0
  27. package/dist/editable-artifact-durable-export.js +2 -2
  28. package/dist/editable-artifacts.js +3 -3
  29. package/dist/index.d.ts +69 -20
  30. package/dist/index.js +633 -202
  31. package/dist/index.js.map +1 -1
  32. package/dist/knowledge-entries.d.ts +2 -0
  33. package/dist/knowledge-indexing.d.ts +17 -0
  34. package/dist/managed-auth-session-sets.js +3 -3
  35. package/dist/managed-user-setup.d.ts +1 -0
  36. package/dist/mcp-operations.js +2 -2
  37. package/dist/migrate.d.ts +10 -1
  38. package/dist/migrate.js +3 -1
  39. package/dist/organization-integration-policy.js +3 -3
  40. package/dist/organization-membership-lifecycle.d.ts +1 -0
  41. package/dist/provision-roles.js +1 -1
  42. package/dist/retained-provider-commands.d.ts +4 -2
  43. package/dist/retained-provider-commands.js +6 -6
  44. package/dist/runtime-posture.d.ts +1 -1
  45. package/dist/schema.d.ts +25 -8
  46. package/dist/schema.js +1 -1
  47. package/dist/session-background-commands.js +4 -4
  48. package/dist/session-command-output.js +5 -5
  49. package/dist/session-event-slices.js +3 -3
  50. package/dist/session-mcp-credential-rotation.js +4 -4
  51. package/dist/session-tenancy.js +3 -3
  52. package/dist/video-generation.js +3 -3
  53. package/dist/workspace-tool-defaults.js +4 -4
  54. package/drizzle/0508_deadline_command_workspace_capture.sql +75 -0
  55. package/drizzle/0509_verified_signup_trial_credits.sql +76 -0
  56. package/drizzle/0510_knowledge_index_funding_wait.sql +174 -0
  57. package/drizzle/0511_knowledge_visible_index_status.sql +56 -0
  58. package/drizzle/0512_insights_fact_reads_hash_join.sql +31 -0
  59. package/drizzle/0513_message_fork_prefix_compaction.sql +85 -0
  60. package/drizzle/0514_failed_session_variable_set_attach.sql +25 -0
  61. package/package.json +5 -5
  62. package/src/browser-sessions.ts +71 -1
  63. package/src/database.ts +18 -0
  64. package/src/index.ts +706 -252
  65. package/src/insights.ts +44 -36
  66. package/src/knowledge-entries.ts +43 -2
  67. package/src/knowledge-indexing.ts +79 -1
  68. package/src/managed-user-setup.ts +18 -1
  69. package/src/migrate.ts +58 -1
  70. package/src/organization-membership-lifecycle.ts +11 -0
  71. package/src/provision-roles.ts +12 -0
  72. package/src/retained-provider-commands.ts +16 -6
  73. package/src/runtime-posture.ts +4 -0
  74. package/src/schema.ts +3 -0
  75. package/dist/chunk-4CCFFLDZ.js.map +0 -1
  76. package/dist/chunk-GSB4ISHE.js.map +0 -1
  77. package/dist/chunk-H7BC444C.js.map +0 -1
  78. package/dist/chunk-MAMBI2HR.js.map +0 -1
  79. /package/dist/{chunk-4RDUZ5UV.js.map → chunk-4ZQFT5II.js.map} +0 -0
  80. /package/dist/{chunk-6ORJPCYW.js.map → chunk-5UOWNKPP.js.map} +0 -0
  81. /package/dist/{chunk-LSLNMENV.js.map → chunk-KZXWUXWV.js.map} +0 -0
  82. /package/dist/{chunk-LO6BVXXH.js.map → chunk-LD52IFS3.js.map} +0 -0
  83. /package/dist/{chunk-JILAWE26.js.map → chunk-M5Z6II2P.js.map} +0 -0
  84. /package/dist/{chunk-PGIFHEBA.js.map → chunk-RVEOGRMF.js.map} +0 -0
  85. /package/dist/{chunk-XK6HXON2.js.map → chunk-UXFBXCHM.js.map} +0 -0
  86. /package/dist/{chunk-FULLE5CF.js.map → chunk-WT7HG43Y.js.map} +0 -0
  87. /package/dist/{chunk-I7HQL6FK.js.map → chunk-ZM5BA3TD.js.map} +0 -0
@@ -266,6 +266,11 @@ function associationFromRow(row: BrowserAssociationRow) {
266
266
  } as const;
267
267
  }
268
268
 
269
+ /** Legacy resources predate permission control; absence must never advertise support. */
270
+ export function readStoredBrowserCapabilities(value: Record<string, unknown>) {
271
+ return BrowserSessionCapabilities.parse({ permissions: false, ...value });
272
+ }
273
+
269
274
  function browserSessionFromRows(
270
275
  row: BrowserSessionRow,
271
276
  associations: readonly BrowserAssociationRow[],
@@ -286,7 +291,7 @@ function browserSessionFromRows(
286
291
  baseRevisionId: row.baseRevisionId,
287
292
  networkRouteId: row.networkRouteId,
288
293
  linkedComputerSessionId: row.linkedComputerSessionId,
289
- capabilities: row.capabilities,
294
+ capabilities: readStoredBrowserCapabilities(row.capabilities),
290
295
  associations: associations.map(associationFromRow),
291
296
  createdBySubjectId: row.createdBySubjectId,
292
297
  createdAt: iso(row.createdAt),
@@ -1463,6 +1468,71 @@ export async function prepareBrowserSessionSuspend(
1463
1468
  });
1464
1469
  }
1465
1470
 
1471
+ /** Restore the active controller when placement fails before a suspend was dispatched. */
1472
+ export async function failPreparedBrowserSessionSuspend(
1473
+ db: Database,
1474
+ input: {
1475
+ accountId: string;
1476
+ workspaceId: string;
1477
+ operationId: string;
1478
+ browserSessionId: string;
1479
+ error: InteractionErrorValue;
1480
+ },
1481
+ ): Promise<BrowserSessionMutationResponseValue | null> {
1482
+ const error = InteractionError.parse(input.error);
1483
+ return await withRlsContext(
1484
+ db,
1485
+ input,
1486
+ async (scopedDb) =>
1487
+ await scopedDb.transaction(async (txRaw) => {
1488
+ const tx = txRaw as unknown as Database;
1489
+ await lockOperation(tx, input.workspaceId, input.operationId);
1490
+ const operation = await loadOperation(tx, input.workspaceId, input.operationId);
1491
+ assertOperationResource(operation, input.browserSessionId, "suspend");
1492
+ if (operation.state !== "prepared" || operation.dispatchedAt) return null;
1493
+
1494
+ await lockBrowserSession(tx, input.workspaceId, input.browserSessionId);
1495
+ const now = new Date();
1496
+ const [sessionRow] = await tx
1497
+ .update(schema.browserSessions)
1498
+ .set({ lifecycle: "active", failureCode: null, updatedAt: now })
1499
+ .where(
1500
+ and(
1501
+ eq(schema.browserSessions.workspaceId, input.workspaceId),
1502
+ eq(schema.browserSessions.id, input.browserSessionId),
1503
+ eq(schema.browserSessions.lifecycle, "suspending"),
1504
+ ),
1505
+ )
1506
+ .returning();
1507
+ if (!sessionRow) {
1508
+ throw new BrowserSessionStateError("Prepared BrowserSession suspension changed state");
1509
+ }
1510
+ const [operationRow] = await tx
1511
+ .update(schema.interactionOperations)
1512
+ .set({
1513
+ state: "failed",
1514
+ errorCode: error.code,
1515
+ errorMessage: error.message,
1516
+ errorRetryable: error.retryable,
1517
+ errorDetails: error.details ?? null,
1518
+ settledAt: now,
1519
+ updatedAt: now,
1520
+ })
1521
+ .where(eq(schema.interactionOperations.operationId, input.operationId))
1522
+ .returning();
1523
+ if (!operationRow) throw new Error("BrowserSession failure receipt was lost");
1524
+ const associations = await loadAssociations(tx, input.workspaceId, [
1525
+ input.browserSessionId,
1526
+ ]);
1527
+ await advanceWorkspaceInteractionRevision(tx, input.accountId, input.workspaceId);
1528
+ return BrowserSessionMutationResponse.parse({
1529
+ session: browserSessionFromRows(sessionRow, associations),
1530
+ operation: operationReceipt(operationRow, false),
1531
+ });
1532
+ }),
1533
+ );
1534
+ }
1535
+
1466
1536
  export async function prepareBrowserSessionResume(
1467
1537
  db: Database,
1468
1538
  input: PrepareBrowserSessionLifecycleInput,
package/src/database.ts CHANGED
@@ -67,6 +67,24 @@ export function currentSessionAttachmentReadAccess(): SessionAttachmentReadAcces
67
67
  return sessionRlsActorContext.getStore()?.sessionAttachmentReadAccess;
68
68
  }
69
69
 
70
+ /**
71
+ * Stable identity of the ambient session RLS actor: every field that
72
+ * `setRlsContext` turns into database-visible GUCs or that scoped reads
73
+ * consult. Two callers with equal keys see exactly the same rows, so the key
74
+ * is safe for sharing a read result between them; `null` means no actor, in
75
+ * which case the subject GUC stays empty for every such caller.
76
+ */
77
+ export function currentSessionRlsActorIdentityKey(): string | null {
78
+ const actor = sessionRlsActorContext.getStore();
79
+ if (!actor) return null;
80
+ return JSON.stringify([
81
+ actor.subjectId,
82
+ actor.initiatingHumanSubjectId ?? null,
83
+ actor.privateFileOwnerSubjectId ?? null,
84
+ actor.sessionAttachmentReadAccess ?? null,
85
+ ]);
86
+ }
87
+
70
88
  export async function withSessionRlsActorContext<T>(
71
89
  actor: SessionRlsActorContext,
72
90
  fn: () => Promise<T>,