@opengeni/db 0.14.0 → 0.16.2

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 (63) hide show
  1. package/dist/{chunk-ELMUCYZF.js → chunk-4RUK5CON.js} +183 -42
  2. package/dist/chunk-4RUK5CON.js.map +1 -0
  3. package/dist/chunk-HZD7KVAR.js +4648 -0
  4. package/dist/chunk-HZD7KVAR.js.map +1 -0
  5. package/dist/{chunk-Y5WZZVQK.js → chunk-SK7YYHBI.js} +5 -2
  6. package/dist/chunk-SK7YYHBI.js.map +1 -0
  7. package/dist/codex-token-resolver.d.ts +64 -0
  8. package/dist/connection-token-resolver.d.ts +90 -0
  9. package/dist/environment-crypto.d.ts +11 -0
  10. package/dist/event-payload-sanitizer.d.ts +32 -0
  11. package/dist/index.d.ts +6217 -10
  12. package/dist/index.js +6992 -2728
  13. package/dist/index.js.map +1 -1
  14. package/dist/insights.d.ts +157 -0
  15. package/dist/memory-domain.d.ts +44 -0
  16. package/dist/migrate.d.ts +5 -7
  17. package/dist/migrate.js +1 -1
  18. package/dist/new-session-drafts.d.ts +49 -0
  19. package/dist/persistence-errors.d.ts +69 -0
  20. package/dist/preference-registry-schema.d.ts +1147 -0
  21. package/dist/preference-registry.d.ts +878 -0
  22. package/dist/provision-roles.d.ts +4 -6478
  23. package/dist/provision-roles.js +1 -1
  24. package/dist/role-relationships.d.ts +35 -0
  25. package/dist/runtime-posture-cli.d.ts +1 -0
  26. package/dist/runtime-posture.d.ts +103 -0
  27. package/dist/schema.d.ts +23533 -3
  28. package/dist/schema.js +17 -1
  29. package/dist/session-control.d.ts +331 -0
  30. package/dist/session-queue-commands.d.ts +186 -0
  31. package/dist/session-tool-call-settlement.d.ts +32 -0
  32. package/dist/turn-initiator.d.ts +28 -0
  33. package/dist/workspace-instruction-policies-schema.d.ts +735 -0
  34. package/dist/workspace-instruction-policies.d.ts +64 -0
  35. package/drizzle/0136_unified_session_tool_policy.sql +109 -0
  36. package/drizzle/0137_preference_registry.sql +1347 -0
  37. package/drizzle/0138_sandbox_checkpoint_artifacts_and_deadlines.sql +1074 -0
  38. package/drizzle/0139_codex_provider_artifact_invalidations.sql +51 -0
  39. package/drizzle/0140_sandbox_restore_and_reaper_fences.sql +276 -0
  40. package/drizzle/0142_sandbox_archive_capture_gate.sql +80 -0
  41. package/drizzle/0143_session_codex_compaction_mode.sql +20 -0
  42. package/drizzle/0144_sandbox_viewer_force_drain_gate.sql +95 -0
  43. package/drizzle/0145_model_call_facts.sql +96 -0
  44. package/drizzle/0146_slack_bot_delete_idempotency.sql +105 -0
  45. package/drizzle/0147_draft_latency_mode.sql +12 -0
  46. package/drizzle/0148_session_turn_latency_mode.sql +12 -0
  47. package/package.json +6 -6
  48. package/src/index.ts +5095 -430
  49. package/src/insights.ts +837 -0
  50. package/src/migrate.ts +9 -1
  51. package/src/new-session-drafts.ts +4 -0
  52. package/src/preference-registry-schema.ts +170 -0
  53. package/src/preference-registry.ts +1220 -0
  54. package/src/provision-roles.ts +95 -22
  55. package/src/role-relationships.ts +132 -0
  56. package/src/runtime-posture.ts +28 -26
  57. package/src/schema.ts +484 -12
  58. package/src/session-queue-commands.ts +47 -46
  59. package/dist/chunk-ELMUCYZF.js.map +0 -1
  60. package/dist/chunk-PQKVUWQW.js +0 -4047
  61. package/dist/chunk-PQKVUWQW.js.map +0 -1
  62. package/dist/chunk-Y5WZZVQK.js.map +0 -1
  63. package/dist/schema-FoPub9yt.d.ts +0 -22666
package/src/migrate.ts CHANGED
@@ -173,7 +173,15 @@ async function executeMigrationFile(
173
173
  }
174
174
  const concurrentIndex = parseConcurrentIndexMigration(file, sqlText);
175
175
  if (!concurrentIndex) {
176
- await sql.unsafe(sqlText);
176
+ // Migration SQL is the only writer allowed to cross protocol generations.
177
+ // Keep the authority transaction-local and inside the same PostgreSQL simple
178
+ // query as the migration body: setting it in a prior statement would end
179
+ // that implicit transaction and silently lose the LOCAL value. This also
180
+ // makes a fresh database capable of applying maintenance migration 0138
181
+ // without a process-global PGOPTIONS escape hatch.
182
+ await sql.unsafe(
183
+ `SELECT pg_catalog.set_config('opengeni.sandbox_recovery_protocol_v2', '1', true);\n${sqlText}`,
184
+ );
177
185
  return;
178
186
  }
179
187
 
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  NewSessionDraftOptions,
3
+ LatencyMode,
3
4
  ReasoningEffort,
4
5
  RepositoryResourceRef,
5
6
  ResourceRef,
@@ -86,6 +87,7 @@ export async function saveNewSessionDraftInTransaction(
86
87
  toolsProvided: boolean;
87
88
  model: string;
88
89
  reasoningEffort: ReasoningEffort;
90
+ latencyMode?: LatencyMode;
89
91
  options: NewSessionDraftOptions;
90
92
  /** API-key and delegated service subjects have no workspace-membership row. */
91
93
  requireWorkspaceMembership?: boolean;
@@ -126,6 +128,7 @@ export async function saveNewSessionDraftInTransaction(
126
128
  tools: input.tools,
127
129
  model: input.model,
128
130
  reasoningEffort: input.reasoningEffort,
131
+ latencyMode: input.latencyMode ?? "standard",
129
132
  // Keep the explicit/omitted policy in the existing JSONB extension point;
130
133
  // adding a column here would turn a client preference into a migration.
131
134
  sessionOptions: storedOptions(input.options, input.toolsProvided),
@@ -248,6 +251,7 @@ export async function seedNewSessionDraftInTransaction(
248
251
  tools: newSessionDraftToolsProvided(current) ? current.tools : [],
249
252
  model: current.model,
250
253
  reasoningEffort: current.reasoningEffort,
254
+ latencyMode: current.latencyMode,
251
255
  sessionOptions: storedOptions(safeOptions, newSessionDraftToolsProvided(current)),
252
256
  updatedAt: new Date(),
253
257
  })
@@ -0,0 +1,170 @@
1
+ import { sql } from "drizzle-orm";
2
+ import {
3
+ bigint,
4
+ boolean,
5
+ check,
6
+ index,
7
+ integer,
8
+ jsonb,
9
+ pgTable,
10
+ text,
11
+ timestamp,
12
+ uniqueIndex,
13
+ uuid,
14
+ } from "drizzle-orm/pg-core";
15
+ import type { PreferenceRegistryDescriptor } from "@opengeni/contracts";
16
+
17
+ // Foreign keys and cross-row integrity triggers are migration-owned. This leaf
18
+ // stays cycle-free so schema.ts can expose the registry as one additive domain.
19
+ export const preferenceRegistryPreferences = pgTable(
20
+ "preference_registry_preferences",
21
+ {
22
+ id: uuid("id").primaryKey().defaultRandom(),
23
+ accountId: uuid("account_id").notNull(),
24
+ stableKey: text("stable_key").notNull(),
25
+ scope: text("scope").notNull(),
26
+ scopeWorkspaceId: uuid("scope_workspace_id"),
27
+ scopeSubjectId: text("scope_subject_id"),
28
+ status: text("status").notNull().default("proposed"),
29
+ scopeVersion: integer("scope_version").notNull().default(1),
30
+ activationVersion: integer("activation_version").notNull().default(0),
31
+ activeRevisionId: uuid("active_revision_id"),
32
+ activeRevision: bigint("active_revision", { mode: "number" }),
33
+ activeContentHash: text("active_content_hash"),
34
+ supersededByPreferenceId: uuid("superseded_by_preference_id"),
35
+ createdBySubjectId: text("created_by_subject_id").notNull(),
36
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
37
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
38
+ },
39
+ (table) => ({
40
+ organizationStableKey: uniqueIndex("preference_registry_preferences_organization_key_uq")
41
+ .on(table.accountId, table.stableKey)
42
+ .where(sql`${table.scope} = 'organization'`),
43
+ workspaceStableKey: uniqueIndex("preference_registry_preferences_workspace_key_uq")
44
+ .on(table.accountId, table.scopeWorkspaceId, table.stableKey)
45
+ .where(sql`${table.scope} = 'workspace'`),
46
+ userStableKey: uniqueIndex("preference_registry_preferences_user_key_uq")
47
+ .on(table.accountId, table.scopeSubjectId, table.stableKey)
48
+ .where(sql`${table.scope} = 'user'`),
49
+ applicable: index("preference_registry_preferences_applicable_idx").on(
50
+ table.accountId,
51
+ table.scope,
52
+ table.scopeWorkspaceId,
53
+ table.scopeSubjectId,
54
+ table.status,
55
+ table.stableKey,
56
+ ),
57
+ scopeShape: check(
58
+ "preference_registry_preferences_scope_shape_chk",
59
+ sql`(
60
+ (${table.scope} = 'organization' and ${table.scopeWorkspaceId} is null and ${table.scopeSubjectId} is null)
61
+ or (${table.scope} = 'workspace' and ${table.scopeWorkspaceId} is not null and ${table.scopeSubjectId} is null)
62
+ or (${table.scope} = 'user' and ${table.scopeWorkspaceId} is null and ${table.scopeSubjectId} is not null)
63
+ )`,
64
+ ),
65
+ }),
66
+ );
67
+
68
+ export const preferenceRegistryRevisions = pgTable(
69
+ "preference_registry_revisions",
70
+ {
71
+ id: uuid("id").primaryKey().defaultRandom(),
72
+ accountId: uuid("account_id").notNull(),
73
+ preferenceId: uuid("preference_id").notNull(),
74
+ revision: bigint("revision", { mode: "number" })
75
+ .notNull()
76
+ .default(sql`nextval('preference_registry_revision_seq')`),
77
+ title: text("title").notNull(),
78
+ description: text("description").notNull(),
79
+ content: text("content").notNull(),
80
+ contentHash: text("content_hash").notNull(),
81
+ precedenceRank: integer("precedence_rank").notNull().default(0),
82
+ conflictStrategy: text("conflict_strategy").notNull(),
83
+ conflictsWith: jsonb("conflicts_with").$type<string[]>().notNull().default([]),
84
+ provenanceSource: text("provenance_source").notNull(),
85
+ provenanceSourceId: text("provenance_source_id"),
86
+ trust: text("trust").notNull(),
87
+ expiresAt: timestamp("expires_at", { withTimezone: true }),
88
+ correctsRevisionId: uuid("corrects_revision_id"),
89
+ createdBySubjectId: text("created_by_subject_id").notNull(),
90
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
91
+ },
92
+ (table) => ({
93
+ preferenceRevision: uniqueIndex("preference_registry_revisions_preference_revision_uq").on(
94
+ table.preferenceId,
95
+ table.revision,
96
+ ),
97
+ history: index("preference_registry_revisions_history_idx").on(
98
+ table.preferenceId,
99
+ table.revision,
100
+ ),
101
+ }),
102
+ );
103
+
104
+ export const preferenceRegistryEvents = pgTable(
105
+ "preference_registry_events",
106
+ {
107
+ id: uuid("id").primaryKey().defaultRandom(),
108
+ accountId: uuid("account_id").notNull(),
109
+ preferenceId: uuid("preference_id").notNull(),
110
+ type: text("type").notNull(),
111
+ version: integer("version").notNull(),
112
+ oldRevisionId: uuid("old_revision_id"),
113
+ newRevisionId: uuid("new_revision_id"),
114
+ oldScope: text("old_scope"),
115
+ oldWorkspaceId: uuid("old_workspace_id"),
116
+ oldSubjectId: text("old_subject_id"),
117
+ newScope: text("new_scope"),
118
+ newWorkspaceId: uuid("new_workspace_id"),
119
+ newSubjectId: text("new_subject_id"),
120
+ relatedPreferenceId: uuid("related_preference_id"),
121
+ actorSubjectId: text("actor_subject_id").notNull(),
122
+ reason: text("reason").notNull(),
123
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
124
+ },
125
+ (table) => ({
126
+ preferenceVersion: uniqueIndex("preference_registry_events_preference_version_uq").on(
127
+ table.preferenceId,
128
+ table.version,
129
+ ),
130
+ timeline: index("preference_registry_events_timeline_idx").on(
131
+ table.preferenceId,
132
+ table.createdAt,
133
+ table.id,
134
+ ),
135
+ }),
136
+ );
137
+
138
+ export const preferenceRegistrySnapshots = pgTable(
139
+ "preference_registry_snapshots",
140
+ {
141
+ id: uuid("id").primaryKey().defaultRandom(),
142
+ accountId: uuid("account_id").notNull(),
143
+ workspaceId: uuid("workspace_id").notNull(),
144
+ sessionId: uuid("session_id").notNull(),
145
+ turnId: uuid("turn_id").notNull(),
146
+ attemptId: uuid("attempt_id").notNull(),
147
+ executionGeneration: integer("execution_generation").notNull(),
148
+ initiatingHumanSubjectId: text("initiating_human_subject_id").notNull(),
149
+ descriptors: jsonb("descriptors").$type<PreferenceRegistryDescriptor[]>().notNull(),
150
+ descriptorHash: text("descriptor_hash").notNull(),
151
+ truncated: boolean("truncated").notNull().default(false),
152
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
153
+ },
154
+ (table) => ({
155
+ attempt: uniqueIndex("preference_registry_snapshots_attempt_uq").on(
156
+ table.accountId,
157
+ table.workspaceId,
158
+ table.attemptId,
159
+ ),
160
+ humanTimeline: index("preference_registry_snapshots_human_timeline_idx").on(
161
+ table.workspaceId,
162
+ table.initiatingHumanSubjectId,
163
+ table.createdAt,
164
+ ),
165
+ descriptorBytes: check(
166
+ "preference_registry_snapshots_descriptor_bytes_chk",
167
+ sql`octet_length(convert_to(${table.descriptors}::text, 'UTF8')) <= 16384`,
168
+ ),
169
+ }),
170
+ );