@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
@@ -0,0 +1,73 @@
1
+ -- deployment-mode: rolling
2
+ -- Expose one content-free, bounded-cardinality aggregate for durable recovery
3
+ -- states that process-local turn gauges cannot see.
4
+
5
+ CREATE OR REPLACE FUNCTION opengeni_private.count_session_recovery_backlog()
6
+ RETURNS TABLE (state text, count bigint)
7
+ LANGUAGE sql
8
+ STABLE
9
+ SECURITY DEFINER
10
+ SET search_path FROM CURRENT
11
+ AS $count_session_recovery_backlog$
12
+ WITH recovery_states(state) AS (
13
+ VALUES ('quiescence_missing'::text), ('projection_stale'::text)
14
+ ), candidates AS (
15
+ SELECT CASE
16
+ WHEN attempt.quiesced_at IS NULL THEN 'quiescence_missing'::text
17
+ ELSE 'projection_stale'::text
18
+ END AS state
19
+ FROM sessions session
20
+ JOIN session_turns turn
21
+ ON turn.workspace_id = session.workspace_id
22
+ AND turn.session_id = session.id
23
+ AND turn.id = session.active_turn_id
24
+ JOIN LATERAL (
25
+ SELECT candidate.id, candidate.state, candidate.outcome, candidate.quiesced_at
26
+ FROM session_turn_attempts candidate
27
+ WHERE candidate.workspace_id = turn.workspace_id
28
+ AND candidate.session_id = turn.session_id
29
+ AND candidate.turn_id = turn.id
30
+ ORDER BY candidate.execution_generation DESC, candidate.updated_at DESC, candidate.id DESC
31
+ LIMIT 1
32
+ ) attempt ON true
33
+ WHERE session.status = 'recovering'
34
+ AND turn.status = 'recovering'
35
+ AND turn.active_attempt_id IS NULL
36
+ AND attempt.state = 'closed'
37
+ AND attempt.outcome = 'interrupted_recoverable'
38
+ AND (
39
+ EXISTS (
40
+ SELECT 1
41
+ FROM session_attempt_interruptions interruption
42
+ WHERE interruption.workspace_id = session.workspace_id
43
+ AND interruption.session_id = session.id
44
+ AND interruption.attempt_id = attempt.id
45
+ AND interruption.state IN ('settled', 'rejected_stale')
46
+ )
47
+ OR EXISTS (
48
+ SELECT 1
49
+ FROM session_events event
50
+ WHERE event.workspace_id = session.workspace_id
51
+ AND event.session_id = session.id
52
+ AND event.turn_id = turn.id
53
+ AND event.turn_attempt_id = attempt.id
54
+ AND event.type = 'turn.recovery.requested'
55
+ )
56
+ )
57
+ )
58
+ SELECT recovery_states.state, count(candidates.state)::bigint
59
+ FROM recovery_states
60
+ LEFT JOIN candidates USING (state)
61
+ GROUP BY recovery_states.state
62
+ ORDER BY recovery_states.state;
63
+ $count_session_recovery_backlog$;
64
+
65
+ REVOKE ALL ON FUNCTION opengeni_private.count_session_recovery_backlog() FROM PUBLIC;
66
+
67
+ DO $session_recovery_observability_grants$
68
+ BEGIN
69
+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
70
+ GRANT EXECUTE ON FUNCTION opengeni_private.count_session_recovery_backlog() TO opengeni_app;
71
+ END IF;
72
+ END
73
+ $session_recovery_observability_grants$;
@@ -0,0 +1,88 @@
1
+ -- deployment-mode: rolling
2
+ -- Account-scoped organization API keys need one complete shared-workspace
3
+ -- inventory without direct runtime access to organization membership rows.
4
+
5
+ SET LOCAL lock_timeout = '5s';
6
+ SET LOCAL statement_timeout = '5min';
7
+
8
+ CREATE FUNCTION list_organization_workspace_ids(p_account_id uuid)
9
+ RETURNS TABLE (workspace_id uuid)
10
+ LANGUAGE plpgsql SECURITY DEFINER
11
+ SET search_path FROM CURRENT
12
+ AS $body$
13
+ DECLARE
14
+ previous_lifecycle text := current_setting('opengeni.organization_tenancy_lifecycle', true);
15
+ BEGIN
16
+ IF p_account_id IS NULL
17
+ OR p_account_id IS DISTINCT FROM opengeni_private.current_account_id()
18
+ OR opengeni_private.current_workspace_id() IS NOT NULL
19
+ THEN
20
+ RAISE EXCEPTION 'organization workspace inventory authority required'
21
+ USING ERRCODE = '42501';
22
+ END IF;
23
+
24
+ PERFORM pg_catalog.set_config(
25
+ 'opengeni.organization_tenancy_lifecycle',
26
+ 'organization_membership_lifecycle', true
27
+ );
28
+
29
+ RETURN QUERY
30
+ SELECT workspace.id
31
+ FROM workspaces workspace
32
+ WHERE workspace.account_id = p_account_id
33
+ AND NOT EXISTS (
34
+ SELECT 1
35
+ FROM organization_memberships membership
36
+ WHERE membership.account_id = p_account_id
37
+ AND membership.personal_workspace_id = workspace.id
38
+ );
39
+
40
+ PERFORM pg_catalog.set_config(
41
+ 'opengeni.organization_tenancy_lifecycle', coalesce(previous_lifecycle, ''), true
42
+ );
43
+ RETURN;
44
+ EXCEPTION WHEN OTHERS THEN
45
+ PERFORM pg_catalog.set_config(
46
+ 'opengeni.organization_tenancy_lifecycle', coalesce(previous_lifecycle, ''), true
47
+ );
48
+ RAISE;
49
+ END
50
+ $body$;
51
+
52
+ REVOKE ALL ON FUNCTION list_organization_workspace_ids(uuid) FROM PUBLIC;
53
+
54
+ DO $pin_and_grant_organization_workspace_inventory$
55
+ DECLARE
56
+ data_schema text := current_schema();
57
+ application_role text;
58
+ BEGIN
59
+ EXECUTE format(
60
+ 'ALTER FUNCTION %I.list_organization_workspace_ids(uuid) '
61
+ 'SET search_path = pg_catalog, %I, pg_temp',
62
+ data_schema, data_schema
63
+ );
64
+
65
+ FOR application_role IN
66
+ SELECT role_value.rolname
67
+ FROM pg_catalog.jsonb_array_elements_text(
68
+ coalesce(
69
+ nullif(current_setting('opengeni.migration_application_roles', true), ''),
70
+ '[]'
71
+ )::jsonb
72
+ ) configured(value)
73
+ JOIN pg_catalog.pg_roles role_value
74
+ ON role_value.rolname = configured.value
75
+ UNION
76
+ SELECT 'opengeni_app'
77
+ WHERE EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'opengeni_app')
78
+ LOOP
79
+ EXECUTE format(
80
+ 'GRANT EXECUTE ON FUNCTION %I.list_organization_workspace_ids(uuid) TO %I',
81
+ data_schema, application_role
82
+ );
83
+ END LOOP;
84
+ END
85
+ $pin_and_grant_organization_workspace_inventory$;
86
+
87
+ COMMENT ON FUNCTION list_organization_workspace_ids(uuid) IS
88
+ 'Complete content-free organization workspace inventory. Canonical personal-workspace pointers are excluded under exact account scope.';
@@ -0,0 +1,80 @@
1
+ -- deployment-mode: rolling
2
+ -- Keep the access-controlled Rig projection in parity with the ordinary
3
+ -- workspace query: terminal verification evidence for the active version must
4
+ -- be visible to REST and first-party MCP callers instead of staying unknown.
5
+
6
+ SET LOCAL lock_timeout = '5s';
7
+ SET LOCAL statement_timeout = '5min';
8
+
9
+ CREATE OR REPLACE FUNCTION scoped_rig_json(p_rig_id uuid) RETURNS jsonb
10
+ LANGUAGE sql STABLE SECURITY DEFINER SET search_path FROM CURRENT AS $$
11
+ SELECT pg_catalog.jsonb_build_object(
12
+ 'id', rig.id, 'accountId', rig.account_id, 'workspaceId', rig.workspace_id,
13
+ 'scope', rig.authority_scope, 'generation', rig.generation, 'status', rig.status,
14
+ 'name', rig.name, 'description', rig.description, 'createdBy', rig.created_by,
15
+ 'activeVersion', (
16
+ SELECT pg_catalog.jsonb_build_object(
17
+ 'id', version.id, 'rigId', version.rig_id, 'version', version.version,
18
+ 'image', version.image, 'setupScript', version.setup_script,
19
+ 'checks', version.checks, 'credentialHooks', version.credential_hooks,
20
+ 'defaultVariableSetIds', version.default_variable_set_ids,
21
+ 'changelog', version.changelog, 'providerImages', version.provider_images,
22
+ 'createdBy', version.created_by, 'active', version.active,
23
+ 'createdAt', version.created_at
24
+ ) FROM rig_versions version
25
+ WHERE version.rig_id = rig.id AND version.account_id = rig.account_id
26
+ AND version.active = true LIMIT 1
27
+ ),
28
+ 'activeVersionHealth', (
29
+ SELECT pg_catalog.jsonb_build_object(
30
+ 'checkHealth', coalesce(health.check_health, 'unknown'),
31
+ 'lastVerifiedAt', health.verified_at
32
+ )
33
+ FROM rig_versions active_version
34
+ LEFT JOIN LATERAL (
35
+ SELECT candidate.check_health, candidate.verified_at
36
+ FROM (
37
+ SELECT CASE change.verification ->> 'passed'
38
+ WHEN 'true' THEN 'passing' WHEN 'false' THEN 'failing' END AS check_health,
39
+ coalesce(
40
+ nullif(change.verification ->> 'finishedAt', '')::timestamptz,
41
+ change.updated_at
42
+ ) AS verified_at
43
+ FROM rig_changes change
44
+ WHERE change.account_id = active_version.account_id
45
+ AND change.workspace_id = active_version.workspace_id
46
+ AND change.result_version_id = active_version.id
47
+ AND change.verification ->> 'passed' IN ('true', 'false')
48
+ UNION ALL
49
+ SELECT CASE event.action WHEN 'rig.verification.passed' THEN 'passing'
50
+ ELSE 'failing' END,
51
+ coalesce(
52
+ nullif(event.metadata ->> 'finishedAt', '')::timestamptz,
53
+ event.occurred_at
54
+ )
55
+ FROM audit_events event
56
+ WHERE event.account_id = active_version.account_id
57
+ AND event.workspace_id = active_version.workspace_id
58
+ AND event.target_type = 'rig'
59
+ AND event.target_id = rig.id::text
60
+ AND event.action IN ('rig.verification.passed', 'rig.verification.failed')
61
+ AND event.metadata ->> 'versionId' = active_version.id::text
62
+ ) candidate
63
+ ORDER BY candidate.verified_at DESC
64
+ LIMIT 1
65
+ ) health ON true
66
+ WHERE active_version.rig_id = rig.id
67
+ AND active_version.account_id = rig.account_id
68
+ AND active_version.active = true
69
+ LIMIT 1
70
+ ),
71
+ 'versionCount', (SELECT count(*)::integer FROM rig_versions version
72
+ WHERE version.rig_id = rig.id AND version.account_id = rig.account_id),
73
+ 'createdAt', rig.created_at, 'updatedAt', rig.updated_at
74
+ ) FROM rigs rig WHERE rig.id = p_rig_id
75
+ $$;
76
+
77
+ REVOKE ALL ON FUNCTION scoped_rig_json(uuid) FROM PUBLIC;
78
+
79
+ COMMENT ON FUNCTION scoped_rig_json(uuid) IS
80
+ 'Access-controlled Rig projection with active-version health from the latest terminal change or audit verification evidence.';
@@ -0,0 +1,77 @@
1
+ -- deployment-mode: rolling
2
+ -- Repair the already-ledgered scoped Rig health projection so generic audit
3
+ -- metadata can never abort a SECURITY DEFINER read. Audit occurrence time is
4
+ -- the trusted ordering and display timestamp for audit-backed evidence.
5
+
6
+ SET LOCAL lock_timeout = '5s';
7
+ SET LOCAL statement_timeout = '5min';
8
+
9
+ CREATE OR REPLACE FUNCTION scoped_rig_json(p_rig_id uuid) RETURNS jsonb
10
+ LANGUAGE sql STABLE SECURITY DEFINER SET search_path FROM CURRENT AS $$
11
+ SELECT pg_catalog.jsonb_build_object(
12
+ 'id', rig.id, 'accountId', rig.account_id, 'workspaceId', rig.workspace_id,
13
+ 'scope', rig.authority_scope, 'generation', rig.generation, 'status', rig.status,
14
+ 'name', rig.name, 'description', rig.description, 'createdBy', rig.created_by,
15
+ 'activeVersion', (
16
+ SELECT pg_catalog.jsonb_build_object(
17
+ 'id', version.id, 'rigId', version.rig_id, 'version', version.version,
18
+ 'image', version.image, 'setupScript', version.setup_script,
19
+ 'checks', version.checks, 'credentialHooks', version.credential_hooks,
20
+ 'defaultVariableSetIds', version.default_variable_set_ids,
21
+ 'changelog', version.changelog, 'providerImages', version.provider_images,
22
+ 'createdBy', version.created_by, 'active', version.active,
23
+ 'createdAt', version.created_at
24
+ ) FROM rig_versions version
25
+ WHERE version.rig_id = rig.id AND version.account_id = rig.account_id
26
+ AND version.active = true LIMIT 1
27
+ ),
28
+ 'activeVersionHealth', (
29
+ SELECT pg_catalog.jsonb_build_object(
30
+ 'checkHealth', coalesce(health.check_health, 'unknown'),
31
+ 'lastVerifiedAt', health.verified_at
32
+ )
33
+ FROM rig_versions active_version
34
+ LEFT JOIN LATERAL (
35
+ SELECT candidate.check_health, candidate.verified_at
36
+ FROM (
37
+ SELECT CASE change.verification ->> 'passed'
38
+ WHEN 'true' THEN 'passing' WHEN 'false' THEN 'failing' END AS check_health,
39
+ coalesce(
40
+ nullif(change.verification ->> 'finishedAt', '')::timestamptz,
41
+ change.updated_at
42
+ ) AS verified_at
43
+ FROM rig_changes change
44
+ WHERE change.account_id = active_version.account_id
45
+ AND change.workspace_id = active_version.workspace_id
46
+ AND change.result_version_id = active_version.id
47
+ AND change.verification ->> 'passed' IN ('true', 'false')
48
+ UNION ALL
49
+ SELECT CASE event.action WHEN 'rig.verification.passed' THEN 'passing'
50
+ ELSE 'failing' END,
51
+ event.occurred_at
52
+ FROM audit_events event
53
+ WHERE event.account_id = active_version.account_id
54
+ AND event.workspace_id = active_version.workspace_id
55
+ AND event.target_type = 'rig'
56
+ AND event.target_id = rig.id::text
57
+ AND event.action IN ('rig.verification.passed', 'rig.verification.failed')
58
+ AND event.metadata ->> 'versionId' = active_version.id::text
59
+ ) candidate
60
+ ORDER BY candidate.verified_at DESC
61
+ LIMIT 1
62
+ ) health ON true
63
+ WHERE active_version.rig_id = rig.id
64
+ AND active_version.account_id = rig.account_id
65
+ AND active_version.active = true
66
+ LIMIT 1
67
+ ),
68
+ 'versionCount', (SELECT count(*)::integer FROM rig_versions version
69
+ WHERE version.rig_id = rig.id AND version.account_id = rig.account_id),
70
+ 'createdAt', rig.created_at, 'updatedAt', rig.updated_at
71
+ ) FROM rigs rig WHERE rig.id = p_rig_id
72
+ $$;
73
+
74
+ REVOKE ALL ON FUNCTION scoped_rig_json(uuid) FROM PUBLIC;
75
+
76
+ COMMENT ON FUNCTION scoped_rig_json(uuid) IS
77
+ 'Access-controlled Rig projection with active-version health from terminal evidence and trusted audit occurrence timestamps.';