@opengeni/db 3.6.0 → 3.7.4-canary.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 (92) hide show
  1. package/dist/automations.d.ts +4 -0
  2. package/dist/canonical-human-identities.js +3 -3
  3. package/dist/{chunk-UGDVSQ6U.js → chunk-3ZMN4EXC.js} +2 -2
  4. package/dist/{chunk-744DFC65.js → chunk-6FIVOJ3V.js} +96 -6
  5. package/dist/chunk-6FIVOJ3V.js.map +1 -0
  6. package/dist/{chunk-UJ2EW3QI.js → chunk-DXJ2WY6W.js} +427 -85
  7. package/dist/chunk-DXJ2WY6W.js.map +1 -0
  8. package/dist/{chunk-CDMMSUWJ.js → chunk-JP6IYGYI.js} +3 -3
  9. package/dist/{chunk-Q5YUGQVK.js → chunk-JS3AWDKZ.js} +3 -3
  10. package/dist/{chunk-G3732M3T.js → chunk-LHKB62GC.js} +2 -2
  11. package/dist/{chunk-2NT476HD.js → chunk-QL4AHBYD.js} +2 -2
  12. package/dist/{chunk-IW6O6G7R.js → chunk-VDXHLVDE.js} +2 -2
  13. package/dist/{chunk-WW7AJ5IC.js → chunk-ZTSJPFDH.js} +5 -7
  14. package/dist/chunk-ZTSJPFDH.js.map +1 -0
  15. package/dist/codex-token-resolver.d.ts +12 -1
  16. package/dist/company-profile-agent-admin.d.ts +4 -2
  17. package/dist/company-profile-agent-policy.d.ts +20 -0
  18. package/dist/company-profile-schema.d.ts +573 -0
  19. package/dist/editable-artifact-durable-export.js +2 -2
  20. package/dist/editable-artifacts.js +3 -3
  21. package/dist/index.d.ts +487 -20
  22. package/dist/index.js +9489 -6041
  23. package/dist/index.js.map +1 -1
  24. package/dist/managed-auth-session-sets.js +3 -3
  25. package/dist/managed-human-provisioning.d.ts +3 -3
  26. package/dist/memory-domain.d.ts +5 -3
  27. package/dist/model-catalog.d.ts +153 -0
  28. package/dist/pr-review.d.ts +9 -0
  29. package/dist/provision-roles.js +1 -1
  30. package/dist/runtime-posture.d.ts +7 -7
  31. package/dist/schema.d.ts +1069 -6
  32. package/dist/schema.js +17 -1
  33. package/dist/session-background-commands.js +3 -3
  34. package/dist/session-control.d.ts +75 -5
  35. package/dist/session-queue-commands.d.ts +19 -0
  36. package/dist/session-tenancy.js +3 -3
  37. package/dist/user-resource-authority.d.ts +8 -0
  38. package/dist/video-generation.js +3 -3
  39. package/dist/xai-subscription.d.ts +8 -0
  40. package/drizzle/0369_local_human_personal_authority.sql +350 -0
  41. package/drizzle/0370_workspace_member_management_scope.sql +98 -0
  42. package/drizzle/0371_workspace_member_candidate_inventory.sql +128 -0
  43. package/drizzle/0372_ordered_variable_set_runtime_authority.sql +287 -0
  44. package/drizzle/0373_sandbox_shared_preparation.sql +59 -0
  45. package/drizzle/0374_session_event_cursors.sql +315 -0
  46. package/drizzle/0375_session_recovery_observability.sql +73 -0
  47. package/drizzle/0376_organization_workspace_inventory.sql +88 -0
  48. package/drizzle/0377_scoped_rig_health_projection.sql +80 -0
  49. package/drizzle/0378_scoped_rig_health_audit_timestamp.sql +77 -0
  50. package/drizzle/0379_session_event_raw_lane_activation.sql +518 -0
  51. package/drizzle/0380_autonomous_company_profile_agent_policy.sql +829 -0
  52. package/drizzle/0381_organization_codex_subscription_inheritance.sql +720 -0
  53. package/drizzle/0382_organization_api_key_provenance.sql +91 -0
  54. package/drizzle/0383_codex_cooldown_reconciliation.sql +51 -0
  55. package/drizzle/0384_codex_cooldown_revision_guard_privileges.sql +6 -0
  56. package/drizzle/0385_connected_machine_legacy_tilde_workdirs.sql +25 -0
  57. package/drizzle/0386_local_organization_administration.sql +157 -0
  58. package/drizzle/0387_bound_host_export_session_payloads.sql +165 -0
  59. package/drizzle/0388_sandbox_provider_deadline_interactions.sql +491 -0
  60. package/drizzle/0389_model_catalog_and_gateway_custom_models.sql +241 -0
  61. package/package.json +6 -6
  62. package/src/automations.ts +9 -1
  63. package/src/codex-token-resolver.ts +26 -1
  64. package/src/company-brain-governed-writes.ts +30 -1
  65. package/src/company-profile-agent-admin.ts +68 -1
  66. package/src/company-profile-agent-policy.ts +126 -0
  67. package/src/company-profile-schema.ts +115 -1
  68. package/src/database.ts +3 -5
  69. package/src/index.ts +4473 -570
  70. package/src/insights.ts +21 -7
  71. package/src/managed-human-provisioning.ts +3 -3
  72. package/src/memory-domain.ts +9 -4
  73. package/src/model-catalog.ts +682 -0
  74. package/src/organization-membership-lifecycle.ts +0 -1
  75. package/src/pr-review.ts +19 -0
  76. package/src/provision-roles.ts +83 -4
  77. package/src/runtime-posture.ts +26 -0
  78. package/src/schema.ts +259 -10
  79. package/src/session-control.ts +347 -59
  80. package/src/session-queue-commands.ts +303 -122
  81. package/src/session-tool-call-settlement.ts +34 -7
  82. package/src/user-resource-authority.ts +56 -0
  83. package/src/xai-subscription.ts +66 -14
  84. package/dist/chunk-744DFC65.js.map +0 -1
  85. package/dist/chunk-UJ2EW3QI.js.map +0 -1
  86. package/dist/chunk-WW7AJ5IC.js.map +0 -1
  87. /package/dist/{chunk-UGDVSQ6U.js.map → chunk-3ZMN4EXC.js.map} +0 -0
  88. /package/dist/{chunk-CDMMSUWJ.js.map → chunk-JP6IYGYI.js.map} +0 -0
  89. /package/dist/{chunk-Q5YUGQVK.js.map → chunk-JS3AWDKZ.js.map} +0 -0
  90. /package/dist/{chunk-G3732M3T.js.map → chunk-LHKB62GC.js.map} +0 -0
  91. /package/dist/{chunk-2NT476HD.js.map → chunk-QL4AHBYD.js.map} +0 -0
  92. /package/dist/{chunk-IW6O6G7R.js.map → chunk-VDXHLVDE.js.map} +0 -0
@@ -19,9 +19,16 @@ export function historyCallId(item: Record<string, unknown>): string | null {
19
19
  item.providerData && typeof item.providerData === "object" && !Array.isArray(item.providerData)
20
20
  ? (item.providerData as Record<string, unknown>)
21
21
  : null;
22
- const value =
23
- item.callId ?? item.call_id ?? providerData?.callId ?? providerData?.call_id ?? item.id;
24
- return typeof value === "string" && value.length > 0 ? value : null;
22
+ // Native tool-search `id` is the provider item id, not the call correlation
23
+ // id. Validate direct and provider identities before the item-id fallback.
24
+ const value = [
25
+ item.callId,
26
+ item.call_id,
27
+ providerData?.callId,
28
+ providerData?.call_id,
29
+ item.id,
30
+ ].find((candidate): candidate is string => typeof candidate === "string" && candidate.length > 0);
31
+ return value ?? null;
25
32
  }
26
33
 
27
34
  export function historyItemType(item: Record<string, unknown>): string | null {
@@ -68,13 +75,33 @@ export function interruptedToolCallResult(input: {
68
75
  }
69
76
  if (input.callType === "computer_call") return null;
70
77
  if (input.callType === "tool_search_call") {
78
+ const providerData =
79
+ input.callItem.providerData &&
80
+ typeof input.callItem.providerData === "object" &&
81
+ !Array.isArray(input.callItem.providerData)
82
+ ? (input.callItem.providerData as Record<string, unknown>)
83
+ : null;
84
+ const execution =
85
+ input.callItem.execution === "client" || input.callItem.execution === "server"
86
+ ? input.callItem.execution
87
+ : providerData?.execution === "client" || providerData?.execution === "server"
88
+ ? providerData.execution
89
+ : null;
90
+ const providerIdentity =
91
+ typeof providerData?.call_id === "string" || typeof providerData?.callId === "string";
71
92
  const snakeId = typeof input.callItem.call_id === "string";
72
93
  return {
73
94
  type: "tool_search_output",
74
- ...(snakeId ? { call_id: input.callId } : { callId: input.callId }),
75
- ...(input.callItem.execution === "client" || input.callItem.execution === "server"
76
- ? { execution: input.callItem.execution }
77
- : {}),
95
+ ...(providerIdentity
96
+ ? {
97
+ providerData: {
98
+ call_id: input.callId,
99
+ ...(execution ? { execution } : {}),
100
+ },
101
+ }
102
+ : snakeId
103
+ ? { call_id: input.callId, ...(execution ? { execution } : {}) }
104
+ : { callId: input.callId, ...(execution ? { execution } : {}) }),
78
105
  status: "incomplete",
79
106
  tools: [],
80
107
  };
@@ -301,6 +301,62 @@ export async function issueSelfUserResourceGrant(
301
301
  });
302
302
  }
303
303
 
304
+ export async function issueSelfLocalConnectionUseGrant(
305
+ db: Database,
306
+ input: {
307
+ accountId: string;
308
+ workspaceId: string;
309
+ subjectId: string;
310
+ authorityId: string;
311
+ context: "user_private" | "workspace_shared";
312
+ workspaceSharedAcknowledged: boolean;
313
+ },
314
+ ): Promise<UserResourceAuthorityGrant> {
315
+ return await withOwnerContext(db, input, async (scopedDb) => {
316
+ const [row] = await rawRows<
317
+ Omit<UserResourceAuthorityGrant, "delegation"> & {
318
+ organizationId: string;
319
+ authorityGeneration: number;
320
+ }
321
+ >(
322
+ scopedDb,
323
+ sql`
324
+ select grant_id as "grantId", organization_id as "organizationId",
325
+ authority_generation::int as "authorityGeneration",
326
+ target_workspace_id as "targetWorkspaceId",
327
+ target_session_id as "targetSessionId", action, grant_mode as mode,
328
+ grant_context as context, authority_epoch::int as "authorityEpoch",
329
+ grant_generation::int as generation, grant_status as status,
330
+ expires_at::text as "expiresAt"
331
+ from issue_self_local_connection_use_grant(
332
+ ${input.accountId}::uuid, ${input.authorityId}::uuid,
333
+ ${input.workspaceId}::uuid, ${input.context},
334
+ ${input.workspaceSharedAcknowledged}
335
+ )
336
+ `,
337
+ );
338
+ if (!row) throw new Error("local connection grant was not returned");
339
+ const { organizationId, authorityGeneration, ...grant } = row;
340
+ return {
341
+ ...grant,
342
+ expiresAt: rfc3339(grant.expiresAt),
343
+ delegation: {
344
+ authorityId: input.authorityId,
345
+ grantId: grant.grantId,
346
+ organizationId,
347
+ workspaceId: grant.targetWorkspaceId,
348
+ sessionId: grant.targetSessionId,
349
+ action: grant.action,
350
+ mode: grant.mode,
351
+ context: grant.context,
352
+ authorityEpoch: grant.authorityEpoch,
353
+ authorityGeneration,
354
+ grantGeneration: grant.generation,
355
+ },
356
+ };
357
+ });
358
+ }
359
+
304
360
  export async function revokeSelfUserResourceGrant(
305
361
  db: Database,
306
362
  input: { accountId: string; workspaceId: string; subjectId: string; grantId: string },
@@ -472,20 +472,72 @@ export async function workspaceXaiSubscriptionActive(
472
472
  workspaceId,
473
473
  subjectId,
474
474
  });
475
- const [accounts, rotation] = await Promise.all([
476
- listXaiSubscriptionAccountsMetadata(db, { workspaceId, subjectId }),
477
- getXaiRotationSettings(db, { workspaceId, subjectId, authoritySnapshot }),
478
- ]);
479
- const activeCredentialId = rotation?.activeCredentialId ?? null;
480
- const now = new Date();
481
- const eligible = (account: XaiSubscriptionAccountMetadata) =>
482
- account.status === "active" &&
483
- account.allocatorEnabled &&
484
- (!account.exhaustedUntil || account.exhaustedUntil <= now);
485
- if (rotation?.rotationEnabled !== false) {
486
- return accounts.some(eligible);
487
- }
488
- return accounts.some((account) => account.id === activeCredentialId && eligible(account));
475
+ return await workspaceXaiSubscriptionActiveForAuthority(db, settings, {
476
+ workspaceId,
477
+ subjectId,
478
+ authoritySnapshot,
479
+ });
480
+ }
481
+
482
+ /** Metadata-only readiness for the exact provider-account authority frozen on a turn. */
483
+ export async function workspaceXaiSubscriptionActiveForAuthority(
484
+ db: Database,
485
+ settings: { readonly supergrokSubscriptionEnabled: boolean },
486
+ input: {
487
+ workspaceId: string;
488
+ subjectId: string;
489
+ authoritySnapshot: XaiAuthoritySnapshot;
490
+ },
491
+ ): Promise<boolean> {
492
+ if (!settings.supergrokSubscriptionEnabled) return false;
493
+ const snapshot = XaiProviderAccountAuthoritySnapshotV1.parse(input.authoritySnapshot);
494
+ return await withWorkspaceSubjectRls(db, input.workspaceId, input.subjectId, async (scopedDb) => {
495
+ const ownerMembershipId = await resolveXaiPoolOwnerMembershipId(scopedDb, {
496
+ workspaceId: input.workspaceId,
497
+ subjectId: input.subjectId,
498
+ authoritySnapshot: snapshot,
499
+ });
500
+ const ownerPredicate =
501
+ ownerMembershipId === null
502
+ ? isNull(schema.xaiSubscriptionCredentials.ownerOrganizationMembershipId)
503
+ : eq(schema.xaiSubscriptionCredentials.ownerOrganizationMembershipId, ownerMembershipId);
504
+ const [accounts, rotation] = await Promise.all([
505
+ scopedDb
506
+ .select(xaiCredentialMetadataColumns)
507
+ .from(schema.xaiSubscriptionCredentials)
508
+ .where(
509
+ and(
510
+ eq(schema.xaiSubscriptionCredentials.workspaceId, input.workspaceId),
511
+ eq(schema.xaiSubscriptionCredentials.authorityScope, snapshot.scope),
512
+ ownerPredicate,
513
+ ),
514
+ ),
515
+ scopedDb
516
+ .select()
517
+ .from(schema.xaiRotationSettings)
518
+ .where(
519
+ and(
520
+ eq(schema.xaiRotationSettings.workspaceId, input.workspaceId),
521
+ eq(schema.xaiRotationSettings.authorityScope, snapshot.scope),
522
+ ownerMembershipId === null
523
+ ? isNull(schema.xaiRotationSettings.ownerOrganizationMembershipId)
524
+ : eq(schema.xaiRotationSettings.ownerOrganizationMembershipId, ownerMembershipId),
525
+ ),
526
+ )
527
+ .limit(1)
528
+ .then((rows) => rows[0] ?? null),
529
+ ]);
530
+ const activeCredentialId = rotation?.activeCredentialId ?? null;
531
+ const now = new Date();
532
+ const eligible = (account: XaiCredentialMetadataRow) =>
533
+ account.status === "active" &&
534
+ account.allocatorEnabled &&
535
+ (!account.exhaustedUntil || account.exhaustedUntil <= now);
536
+ if (rotation?.rotationEnabled !== false) {
537
+ return accounts.some(eligible);
538
+ }
539
+ return accounts.some((account) => account.id === activeCredentialId && eligible(account));
540
+ });
489
541
  }
490
542
 
491
543
  export async function getXaiSubscriptionAccountMetadata(