@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
@@ -1,10 +1,12 @@
1
1
  import { sql } from "drizzle-orm";
2
2
  import type {
3
3
  CompanyProfileAgentHumanInputPrompt,
4
+ CompanyProfileAgentPolicyMode,
4
5
  CompanyProfileSnapshotEntry,
5
6
  } from "@opengeni/contracts";
6
7
  import {
7
8
  bigint,
9
+ boolean,
8
10
  check,
9
11
  index,
10
12
  integer,
@@ -111,6 +113,57 @@ export const companyProfileActivationEvents = pgTable(
111
113
  }),
112
114
  );
113
115
 
116
+ export const organizationCompanyProfileAgentPolicies = pgTable(
117
+ "organization_company_profile_agent_policies",
118
+ {
119
+ accountId: uuid("account_id").primaryKey(),
120
+ mode: text("mode").$type<CompanyProfileAgentPolicyMode>().notNull().default("suggest"),
121
+ version: bigint("version", { mode: "number" }).notNull().default(0),
122
+ updatedByMembershipId: uuid("updated_by_membership_id"),
123
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
124
+ },
125
+ (table) => ({
126
+ mode: check(
127
+ "organization_company_profile_agent_policies_mode_check",
128
+ sql`${table.mode} in ('off', 'suggest', 'automatic')`,
129
+ ),
130
+ version: check(
131
+ "organization_company_profile_agent_policies_version_check",
132
+ sql`${table.version} >= 0`,
133
+ ),
134
+ }),
135
+ );
136
+
137
+ export const organizationCompanyProfileAgentPolicyEvents = pgTable(
138
+ "organization_company_profile_agent_policy_events",
139
+ {
140
+ id: uuid("id").primaryKey(),
141
+ accountId: uuid("account_id").notNull(),
142
+ actorMembershipId: uuid("actor_membership_id").notNull(),
143
+ requestedMode: text("requested_mode").$type<CompanyProfileAgentPolicyMode>().notNull(),
144
+ expectedVersion: bigint("expected_version", { mode: "number" }).notNull(),
145
+ resultMode: text("result_mode").$type<CompanyProfileAgentPolicyMode>().notNull(),
146
+ resultVersion: bigint("result_version", { mode: "number" }).notNull(),
147
+ resultUpdatedAt: timestamp("result_updated_at", { withTimezone: true }).notNull(),
148
+ changed: boolean("changed").notNull(),
149
+ },
150
+ (table) => ({
151
+ accountTimeline: index("organization_company_profile_agent_policy_events_account_idx").on(
152
+ table.accountId,
153
+ table.resultVersion,
154
+ ),
155
+ modes: check(
156
+ "organization_company_profile_agent_policy_events_mode_check",
157
+ sql`${table.requestedMode} in ('off', 'suggest', 'automatic')
158
+ and ${table.resultMode} in ('off', 'suggest', 'automatic')`,
159
+ ),
160
+ versions: check(
161
+ "organization_company_profile_agent_policy_events_version_check",
162
+ sql`${table.expectedVersion} >= 0 and ${table.resultVersion} > 0`,
163
+ ),
164
+ }),
165
+ );
166
+
114
167
  export const companyProfileSnapshots = pgTable(
115
168
  "company_profile_snapshots",
116
169
  {
@@ -164,6 +217,8 @@ export const companyProfileAgentProposalReceipts = pgTable(
164
217
  revisionId: uuid("revision_id").notNull(),
165
218
  expectedCurrentRevisionId: uuid("expected_current_revision_id"),
166
219
  expectedActivationVersion: bigint("expected_activation_version", { mode: "number" }).notNull(),
220
+ policyMode: text("policy_mode").$type<CompanyProfileAgentPolicyMode>().notNull(),
221
+ policyVersion: bigint("policy_version", { mode: "number" }).notNull(),
167
222
  reason: text("reason").notNull(),
168
223
  humanInput: jsonb("human_input").$type<CompanyProfileAgentHumanInputPrompt>().notNull(),
169
224
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -193,7 +248,9 @@ export const companyProfileAgentProposalReceipts = pgTable(
193
248
  ),
194
249
  generation: check(
195
250
  "company_profile_agent_proposals_generation_check",
196
- sql`${table.executionGeneration} > 0 and ${table.expectedActivationVersion} >= 0`,
251
+ sql`${table.executionGeneration} > 0
252
+ and ${table.expectedActivationVersion} >= 0
253
+ and ${table.policyVersion} >= 0`,
197
254
  ),
198
255
  subject: check(
199
256
  "company_profile_agent_proposals_subject_check",
@@ -204,6 +261,10 @@ export const companyProfileAgentProposalReceipts = pgTable(
204
261
  sql`char_length(btrim(${table.reason})) between 1 and 4096
205
262
  and octet_length(convert_to(btrim(${table.reason}), 'UTF8')) <= 16384`,
206
263
  ),
264
+ policyMode: check(
265
+ "company_profile_agent_proposals_policy_mode_check",
266
+ sql`${table.policyMode} in ('suggest', 'automatic')`,
267
+ ),
207
268
  humanInputShape: check(
208
269
  "company_profile_agent_proposals_human_input_check",
209
270
  sql`jsonb_typeof(${table.humanInput}) = 'object'
@@ -261,3 +322,56 @@ export const companyProfileAgentConfirmationReceipts = pgTable(
261
322
  ),
262
323
  }),
263
324
  );
325
+
326
+ export const companyProfileAgentAutomaticActivationReceipts = pgTable(
327
+ "company_profile_agent_automatic_activation_receipts",
328
+ {
329
+ id: uuid("id").primaryKey().defaultRandom(),
330
+ operationId: uuid("operation_id").notNull(),
331
+ inputHash: text("input_hash").notNull(),
332
+ accountId: uuid("account_id").notNull(),
333
+ workspaceId: uuid("workspace_id").notNull(),
334
+ sessionId: uuid("session_id").notNull(),
335
+ turnId: uuid("turn_id").notNull(),
336
+ activationAttemptId: uuid("activation_attempt_id").notNull(),
337
+ executionGeneration: integer("execution_generation").notNull(),
338
+ proposalReceiptId: uuid("proposal_receipt_id").notNull(),
339
+ proposalRevisionId: uuid("proposal_revision_id").notNull(),
340
+ initiatingHumanSubjectId: text("initiating_human_subject_id").notNull(),
341
+ initiatingMembershipId: uuid("initiating_membership_id").notNull(),
342
+ policyVersion: bigint("policy_version", { mode: "number" }).notNull(),
343
+ activationEventId: uuid("activation_event_id").notNull(),
344
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
345
+ },
346
+ (table) => ({
347
+ accountOperation: uniqueIndex(
348
+ "company_profile_agent_automatic_activations_account_operation_uq",
349
+ ).on(table.accountId, table.operationId),
350
+ proposal: uniqueIndex("company_profile_agent_automatic_activations_proposal_uq").on(
351
+ table.accountId,
352
+ table.proposalReceiptId,
353
+ ),
354
+ activationEvent: uniqueIndex("company_profile_agent_automatic_activations_event_uq").on(
355
+ table.accountId,
356
+ table.activationEventId,
357
+ ),
358
+ turn: index("company_profile_agent_automatic_activations_turn_idx").on(
359
+ table.workspaceId,
360
+ table.sessionId,
361
+ table.turnId,
362
+ table.executionGeneration,
363
+ ),
364
+ hash: check(
365
+ "company_profile_agent_automatic_activations_input_hash_check",
366
+ sql`${table.inputHash} ~ '^[0-9a-f]{64}$'`,
367
+ ),
368
+ generation: check(
369
+ "company_profile_agent_automatic_activations_generation_check",
370
+ sql`${table.executionGeneration} > 0 and ${table.policyVersion} >= 0`,
371
+ ),
372
+ subject: check(
373
+ "company_profile_agent_automatic_activations_subject_check",
374
+ sql`octet_length(btrim(${table.initiatingHumanSubjectId})) between 1 and 1024`,
375
+ ),
376
+ }),
377
+ );
package/src/database.ts CHANGED
@@ -374,16 +374,14 @@ export async function setRlsContext(db: Database, context: RlsContext): Promise<
374
374
  if (typeof context.accountId !== "string" || context.accountId.trim() === "") {
375
375
  throw new Error("setRlsContext: a non-empty accountId is required to establish an RLS context");
376
376
  }
377
- await db.execute(sql`select set_config('opengeni.account_id', ${context.accountId}, true)`);
378
- await db.execute(
379
- sql`select set_config('opengeni.workspace_id', ${context.workspaceId ?? ""}, true)`,
380
- );
381
377
  // Transaction-local writer identity covers supported injected/embedded
382
378
  // database handles whose connection-level application_name is host-owned.
383
379
  // Standalone createDb connections also carry version receipts in their exact
384
380
  // application_name, while old OpenGeni binaries set neither current receipt.
385
- await db.execute(sql`select set_config('opengeni.lossless_content_writer', '1', true)`);
386
381
  await db.execute(sql`select
382
+ set_config('opengeni.account_id', ${context.accountId}, true),
383
+ set_config('opengeni.workspace_id', ${context.workspaceId ?? ""}, true),
384
+ set_config('opengeni.lossless_content_writer', '1', true),
387
385
  set_config('opengeni.sandbox_recovery_protocol_v2', '1', true),
388
386
  set_config('opengeni.pending_tool_event_output_v1', '1', true),
389
387
  set_config('opengeni.session_variable_set_attachments_v1', '1', true)`);