@opengeni/db 0.19.0 → 0.21.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.
@@ -469,6 +469,54 @@ BEGIN
469
469
  ${literal(role)}
470
470
  );
471
471
  END IF;
472
+ IF to_regprocedure(
473
+ format(
474
+ '%I.scoped_knowledge_apply_lifecycle(uuid,text,uuid,text,bigint,text,text,text,text,text,text)',
475
+ ${literal(schema)}
476
+ )
477
+ ) IS NOT NULL THEN
478
+ EXECUTE format(
479
+ 'GRANT EXECUTE ON FUNCTION %I.scoped_knowledge_apply_lifecycle(uuid, text, uuid, text, bigint, text, text, text, text, text, text) TO %I',
480
+ ${literal(schema)},
481
+ ${literal(role)}
482
+ );
483
+ END IF;
484
+ IF to_regprocedure(
485
+ format(
486
+ '%I.scoped_knowledge_advance_source_acl(uuid,uuid,bigint,bigint,uuid,text,text,text,text,text,text)',
487
+ ${literal(schema)}
488
+ )
489
+ ) IS NOT NULL THEN
490
+ EXECUTE format(
491
+ 'GRANT EXECUTE ON FUNCTION %I.scoped_knowledge_advance_source_acl(uuid, uuid, bigint, bigint, uuid, text, text, text, text, text, text) TO %I',
492
+ ${literal(schema)},
493
+ ${literal(role)}
494
+ );
495
+ END IF;
496
+ IF to_regprocedure(
497
+ format(
498
+ '%I.scoped_knowledge_complete_sync(uuid,uuid,text,text,timestamptz,jsonb,text,text,text)',
499
+ ${literal(schema)}
500
+ )
501
+ ) IS NOT NULL THEN
502
+ EXECUTE format(
503
+ 'GRANT EXECUTE ON FUNCTION %I.scoped_knowledge_complete_sync(uuid, uuid, text, text, timestamptz, jsonb, text, text, text) TO %I',
504
+ ${literal(schema)},
505
+ ${literal(role)}
506
+ );
507
+ END IF;
508
+ IF to_regprocedure(
509
+ format(
510
+ '%I.scoped_knowledge_advance_object_version(uuid,uuid,bigint,bigint,uuid,text,text,text,text,text,text)',
511
+ ${literal(schema)}
512
+ )
513
+ ) IS NOT NULL THEN
514
+ EXECUTE format(
515
+ 'GRANT EXECUTE ON FUNCTION %I.scoped_knowledge_advance_object_version(uuid, uuid, bigint, bigint, uuid, text, text, text, text, text, text) TO %I',
516
+ ${literal(schema)},
517
+ ${literal(role)}
518
+ );
519
+ END IF;
472
520
  EXECUTE format('GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA %I TO %I', ${literal(schema)}, ${literal(role)});
473
521
  EXECUTE format(
474
522
  'ALTER DEFAULT PRIVILEGES FOR ROLE %I IN SCHEMA %I REVOKE ALL PRIVILEGES ON TABLES FROM %I',
@@ -42,9 +42,25 @@ export const FORCE_RLS_TABLES = [
42
42
  "host_export_outbox",
43
43
  "import_batches",
44
44
  "integration_oauth_state_nonces",
45
+ "knowledge_change_proposals",
46
+ "knowledge_claim_evidence",
47
+ "knowledge_claim_relations",
48
+ "knowledge_claim_reviews",
49
+ "knowledge_claims",
50
+ "knowledge_document_versions",
51
+ "knowledge_entities",
52
+ "knowledge_entity_aliases",
53
+ "knowledge_facts",
54
+ "knowledge_lifecycle_events",
45
55
  "knowledge_memories",
46
56
  "knowledge_memory_lifecycle_events",
47
57
  "knowledge_memory_relationships",
58
+ "knowledge_operation_receipts",
59
+ "knowledge_providers",
60
+ "knowledge_source_acl_versions",
61
+ "knowledge_source_objects",
62
+ "knowledge_sources",
63
+ "knowledge_sync_runs",
48
64
  "machine_metrics_latest",
49
65
  "machine_metrics_series",
50
66
  "model_call_facts",
@@ -231,6 +247,7 @@ export const RUNTIME_FULL_DML_TABLES = [
231
247
 
232
248
  /** Configuration and lifecycle-owned audit rows are read-only at runtime. */
233
249
  export const RUNTIME_READ_ONLY_TABLES = [
250
+ "knowledge_lifecycle_events",
234
251
  "knowledge_memory_lifecycle_events",
235
252
  "knowledge_memory_relationships",
236
253
  "nested_agent_depth_configuration",
@@ -240,6 +257,21 @@ export const RUNTIME_READ_ONLY_TABLES = [
240
257
 
241
258
  /** Append-only evidence/revision tables are insertable and queryable, never mutable. */
242
259
  export const RUNTIME_READ_INSERT_TABLES = [
260
+ "knowledge_change_proposals",
261
+ "knowledge_claim_evidence",
262
+ "knowledge_claim_relations",
263
+ "knowledge_claim_reviews",
264
+ "knowledge_claims",
265
+ "knowledge_document_versions",
266
+ "knowledge_entities",
267
+ "knowledge_entity_aliases",
268
+ "knowledge_facts",
269
+ "knowledge_operation_receipts",
270
+ "knowledge_providers",
271
+ "knowledge_source_acl_versions",
272
+ "knowledge_source_objects",
273
+ "knowledge_sources",
274
+ "knowledge_sync_runs",
243
275
  "preference_registry_preferences",
244
276
  "preference_registry_revisions",
245
277
  "session_spawn_denials",
package/src/schema.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  FirstPartyMcpToolName,
3
+ McpPersonalConnectionDelegation,
3
4
  McpServerConnectionRef,
4
5
  SessionMcpApprovalPolicy,
5
6
  } from "@opengeni/contracts";
@@ -1316,6 +1317,14 @@ export const sessions = pgTable(
1316
1317
  // Exact model-visible first-party tool selection. All catalogued tools are
1317
1318
  // selected by default; [] intentionally selects no broad-server tools.
1318
1319
  firstPartyMcpTools: jsonb("first_party_mcp_tools").$type<FirstPartyMcpToolName[]>().notNull(),
1320
+ // Initial-command staging only. initializeSessionStartAtomically copies
1321
+ // this immutable snapshot onto the first turn so create repair survives a
1322
+ // crash between the session insert and first-turn transaction. Runtime
1323
+ // credential authority must never read this session field.
1324
+ initialPersonalConnectionDelegations: jsonb("initial_personal_connection_delegations")
1325
+ .$type<McpPersonalConnectionDelegation[]>()
1326
+ .notNull()
1327
+ .default([]),
1319
1328
  // Durable tool-policy origin. Migration 0136 removes the old null/legacy
1320
1329
  // representation so every session has one explicit policy mode.
1321
1330
  toolPolicy: jsonb("tool_policy").$type<SessionToolPolicy>().notNull(),
@@ -1325,9 +1334,15 @@ export const sessions = pgTable(
1325
1334
  // when the creating grant carried a worker-signed sessionId claim (a session
1326
1335
  // spawning a worker); null for direct API creates and scheduled-task runs.
1327
1336
  // When set, this worker's terminal-for-now transitions wake the parent so a
1328
- // manager can orchestrate workers without busy-polling. Self-referencing FK,
1329
- // ON DELETE SET NULL so deleting a manager never cascades into its workers.
1337
+ // manager can orchestrate workers without busy-polling. The migration-owned
1338
+ // self-reference uses ON DELETE RESTRICT so immutable hierarchy and
1339
+ // authority lineage cannot be silently orphaned by a parent hard delete.
1330
1340
  parentSessionId: uuid("parent_session_id"),
1341
+ // Exact parent turn whose worker-signed attempt created this child. This is
1342
+ // private immutable authority lineage: child completion copies personal MCP
1343
+ // authority from that turn, never from whichever parent turn ran most
1344
+ // recently. Null for top-level and legacy child sessions.
1345
+ parentTurnId: uuid("parent_turn_id"),
1331
1346
  // Workspace-scoped CREATE idempotency key. NULL means the create carried no
1332
1347
  // key (each such create is independent). When set, the partial unique index
1333
1348
  // below collapses concurrent/retried creates with the same key in the same
@@ -2008,6 +2023,13 @@ export const sessionTurns = pgTable(
2008
2023
  .$type<Record<string, unknown>>()
2009
2024
  .notNull()
2010
2025
  .default({ backfill: true }),
2026
+ // Immutable exact personal MCP authority for this logical turn. Recovery,
2027
+ // approval, retries, and Toolspace reuse this row; no runtime may infer
2028
+ // broader authority from the session creator or mutable session state.
2029
+ personalConnectionDelegations: jsonb("personal_connection_delegations")
2030
+ .$type<McpPersonalConnectionDelegation[]>()
2031
+ .notNull()
2032
+ .default([]),
2011
2033
  cancelledBy: text("cancelled_by"),
2012
2034
  cancelReason: text("cancel_reason"),
2013
2035
  // Atomic per-turn toolspace call budget counter (migration 0043). Incremented
@@ -2447,6 +2469,12 @@ export const sessionSystemUpdates = pgTable(
2447
2469
  summary: text("summary").notNull(),
2448
2470
  payload: jsonb("payload").$type<Record<string, unknown>>().notNull().default({}),
2449
2471
  lineage: jsonb("lineage").$type<Record<string, unknown>>().notNull().default({}),
2472
+ // Private immutable authority frozen when this machine input is accepted.
2473
+ // Public projections intentionally omit connection ids and owner subjects.
2474
+ personalConnectionDelegations: jsonb("personal_connection_delegations")
2475
+ .$type<McpPersonalConnectionDelegation[]>()
2476
+ .notNull()
2477
+ .default([]),
2450
2478
  // pending is visible queue truth; delivered means its exact model-memory
2451
2479
  // batch was durably claimed. Terminal cancellation/supersession is explicit.
2452
2480
  state: text("state").notNull().default("pending"),
@@ -2526,6 +2554,12 @@ export const sessionSystemUpdateOutbox = pgTable(
2526
2554
  summary: text("summary").notNull(),
2527
2555
  payload: jsonb("payload").$type<Record<string, unknown>>().notNull().default({}),
2528
2556
  lineage: jsonb("lineage").$type<Record<string, unknown>>().notNull().default({}),
2557
+ // Exact private authority copied from the causal parent turn in the source
2558
+ // terminal transaction. Delivery retries cannot replace this snapshot.
2559
+ personalConnectionDelegations: jsonb("personal_connection_delegations")
2560
+ .$type<McpPersonalConnectionDelegation[]>()
2561
+ .notNull()
2562
+ .default([]),
2529
2563
  status: text("status").notNull().default("pending"),
2530
2564
  attempts: integer("attempts").notNull().default(0),
2531
2565
  updateId: uuid("update_id"),
@@ -4325,6 +4359,16 @@ export const scheduledTasks = pgTable(
4325
4359
  runMode: text("run_mode").notNull().default("new_session_per_run"),
4326
4360
  overlapPolicy: text("overlap_policy").notNull().default("allow_concurrent"),
4327
4361
  agentConfig: jsonb("agent_config").$type<unknown>().notNull(),
4362
+ createdByKind: text("created_by_kind").notNull().default("service"),
4363
+ createdBySubjectId: text("created_by_subject_id").notNull().default("unattributed-legacy"),
4364
+ createdByContext: jsonb("created_by_context")
4365
+ .$type<Record<string, unknown>>()
4366
+ .notNull()
4367
+ .default({ backfill: true }),
4368
+ personalConnectionDelegations: jsonb("personal_connection_delegations")
4369
+ .$type<McpPersonalConnectionDelegation[]>()
4370
+ .notNull()
4371
+ .default([]),
4328
4372
  reusableSessionId: uuid("reusable_session_id").references(() => sessions.id, {
4329
4373
  onDelete: "set null",
4330
4374
  }),
@@ -5343,3 +5387,4 @@ export const rigChanges = pgTable(
5343
5387
  export * from "./workspace-instruction-policies-schema";
5344
5388
  export * from "./preference-registry-schema";
5345
5389
  export * from "./memory-governance-schema";
5390
+ export * from "./scoped-knowledge-schema";