@opengeni/db 1.0.1 → 3.1.0-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.
- package/dist/attached-browser-devices.d.ts +7 -0
- package/dist/automations.d.ts +154 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-integrations.d.ts +13 -0
- package/dist/child-lifecycle-notices.d.ts +68 -0
- package/dist/{chunk-LTG3S6ZY.js → chunk-EULAN2NP.js} +2 -2
- package/dist/{chunk-CUPM3FGB.js → chunk-NJVZPWXY.js} +3 -3
- package/dist/{chunk-4SR4HKKA.js → chunk-NMUBV7Z5.js} +19 -11
- package/dist/chunk-NMUBV7Z5.js.map +1 -0
- package/dist/chunk-OF5OBB76.js +4457 -0
- package/dist/chunk-OF5OBB76.js.map +1 -0
- package/dist/{chunk-6ZYKCRFO.js → chunk-PR2WMLOQ.js} +7580 -4417
- package/dist/chunk-PR2WMLOQ.js.map +1 -0
- package/dist/{chunk-ZWREYEWA.js → chunk-SCPUJS53.js} +41 -4
- package/dist/chunk-SCPUJS53.js.map +1 -0
- package/dist/{chunk-SK7YYHBI.js → chunk-SIBYBA2D.js} +46 -1
- package/dist/chunk-SIBYBA2D.js.map +1 -0
- package/dist/chunk-TIKF3KTI.js +383 -0
- package/dist/chunk-TIKF3KTI.js.map +1 -0
- package/dist/chunk-ZZ5LJEFX.js +516 -0
- package/dist/chunk-ZZ5LJEFX.js.map +1 -0
- package/dist/codemode-operations.d.ts +1 -6
- package/dist/company-brain-context-selection-schema.d.ts +705 -0
- package/dist/company-brain-context-selection.d.ts +94 -0
- package/dist/company-brain-governed-writes.d.ts +24 -0
- package/dist/company-brain.d.ts +55 -0
- package/dist/company-profile-agent-admin.d.ts +15 -0
- package/dist/company-profile-schema.d.ts +619 -2
- package/dist/company-profile.d.ts +9 -4
- package/dist/connection-authority.d.ts +95 -0
- package/dist/connection-scopes.d.ts +8 -0
- package/dist/connection-tenancy-backfill.d.ts +41 -0
- package/dist/connection-token-resolver.d.ts +30 -1
- package/dist/database.d.ts +19 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.d.ts +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/governed-learning-activation-schema.d.ts +984 -0
- package/dist/governed-learning-activation.d.ts +98 -0
- package/dist/governed-learning-evaluator-schema.d.ts +633 -0
- package/dist/governed-learning-evaluator.d.ts +28 -0
- package/dist/index.d.ts +1595 -81
- package/dist/index.js +21571 -8126
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +18 -0
- package/dist/integration-bindings.d.ts +1 -0
- package/dist/integration-facets.d.ts +30 -0
- package/dist/interaction-placement-loss.d.ts +22 -0
- package/dist/managed-human-provisioning.d.ts +25 -0
- package/dist/memory-domain.d.ts +3 -3
- package/dist/migrate.d.ts +11 -1
- package/dist/migrate.js +1 -1
- package/dist/new-session-drafts.d.ts +43 -5
- package/dist/organization-membership-backfill.d.ts +174 -0
- package/dist/organization-membership-lifecycle.d.ts +162 -0
- package/dist/pr-review.d.ts +107 -0
- package/dist/preference-registry-schema.d.ts +2 -0
- package/dist/preference-registry.d.ts +2 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +22 -8
- package/dist/schema.d.ts +24914 -13703
- package/dist/schema.js +99 -1
- package/dist/scoped-knowledge-schema.d.ts +52 -1
- package/dist/session-background-commands.d.ts +125 -0
- package/dist/session-background-commands.js +34 -0
- package/dist/session-background-commands.js.map +1 -0
- package/dist/session-control.d.ts +156 -3
- package/dist/session-goal-pacing.d.ts +68 -0
- package/dist/session-queue-commands.d.ts +41 -4
- package/dist/session-realtime-ledger.d.ts +2 -0
- package/dist/session-tenancy.d.ts +71 -1
- package/dist/session-tenancy.js +25 -3
- package/dist/session-tool-call-settlement.d.ts +9 -4
- package/dist/slack-routing-personal-workspace.d.ts +23 -0
- package/dist/slack-routing.d.ts +153 -0
- package/dist/slack-task-policy-schema.d.ts +34 -0
- package/dist/slack-task-policy.d.ts +8 -0
- package/dist/slack-user-link-access.d.ts +1 -0
- package/dist/task-notes-schema.d.ts +594 -0
- package/dist/task-notes.d.ts +39 -0
- package/dist/turn-initiator.d.ts +2 -0
- package/dist/user-resource-authority.d.ts +109 -0
- package/dist/video-generation.js +3 -3
- package/dist/workspace-authority.d.ts +81 -0
- package/dist/workspace-instruction-policies-schema.d.ts +279 -0
- package/dist/workspace-instruction-policies.d.ts +62 -0
- package/dist/workspace-learning-policy.d.ts +1 -0
- package/dist/workspace-membership-permissions.d.ts +2 -0
- package/drizzle/0240_enrollment_connection_authority.sql +39 -0
- package/drizzle/0241_atomic_personal_resource_delegation.sql +1000 -0
- package/drizzle/0241_enrollment_agent_runtime.sql +70 -0
- package/drizzle/0244_slack_app_home_refresh_queue.sql +120 -0
- package/drizzle/0245_model_context_contribution_facts.sql +88 -0
- package/drizzle/0246_integration_personal_instance_authority.sql +70 -0
- package/drizzle/0247_terraform_stacks_provenance_repair.sql +428 -0
- package/drizzle/0248_terraform_stacks_component_resolution_fence.sql +83 -0
- package/drizzle/0249_personal_resource_delegation_authority_correction.sql +662 -0
- package/drizzle/0250_direct_retained_process_owner_liveness.sql +199 -0
- package/drizzle/0251_connected_machine_operation_policy.sql +45 -0
- package/drizzle/0252_scheduled_personal_resource_delegation.sql +1867 -0
- package/drizzle/0253_common_user_resource_authority_lifecycle.sql +1555 -0
- package/drizzle/0254_scoped_variable_set_authority.sql +1255 -0
- package/drizzle/0255_company_brain_governed_write_proposals.sql +524 -0
- package/drizzle/0256_connection_authority_delegation.sql +703 -0
- package/drizzle/0257_goal_revision_decisions_and_root_constraints.sql +436 -0
- package/drizzle/0258_three_scope_document_knowledge_authority.sql +1273 -0
- package/drizzle/0259_company_brain_context_selection_receipts.sql +869 -0
- package/drizzle/0260_task_note_knowledge_promotion.sql +820 -0
- package/drizzle/0261_preference_knowledge_proposal_actor_binding.sql +471 -0
- package/drizzle/0262_scoped_connected_machines_and_rigs.sql +1700 -0
- package/drizzle/0263_organization_membership_lifecycle.sql +3284 -0
- package/drizzle/0264_connection_authority_runtime_activation.sql +1084 -0
- package/drizzle/0266_company_brain_context_receipt_inspection.sql +156 -0
- package/drizzle/0268_governed_learning_decision_receipts.sql +825 -0
- package/drizzle/0269_governed_learning_activation_controller.sql +1874 -0
- package/drizzle/0270_governed_learning_history_inspection.sql +170 -0
- package/drizzle/0271_company_brain_retrieval_only_default.sql +524 -0
- package/drizzle/0272_human_confirmed_learning_activation.sql +591 -0
- package/drizzle/0273_scheduled_variable_set_materialization.sql +268 -0
- package/drizzle/0274_human_confirmed_knowledge_review.sql +310 -0
- package/drizzle/0275_scheduled_connection_authority.sql +5527 -0
- package/drizzle/0276_onboarding_proposal_initiating_human_guc.sql +198 -0
- package/drizzle/0277_workspace_writer_authority_attribution.sql +393 -0
- package/drizzle/0278_workspace_membership_removal_fencing.sql +1174 -0
- package/drizzle/0279_workspace_connection_use_lane.sql +343 -0
- package/drizzle/0280_connection_and_variable_set_audit_attribution.sql +773 -0
- package/drizzle/0281_viewer_holder_authority_claims.sql +52 -0
- package/drizzle/0282_variable_set_session_attach_attribution.sql +178 -0
- package/drizzle/0283_editable_spreadsheet_authored_state.sql +82 -0
- package/drizzle/0284_truthful_human_confirmed_review_reason.sql +930 -0
- package/drizzle/0285_organization_tenancy_inventory.sql +329 -0
- package/drizzle/0286_widen_task_note_expiry_ceiling.sql +391 -0
- package/drizzle/0287_open_suffix_pending_tool_calls.sql +18 -0
- package/drizzle/0288_attached_browser_reenrollment.sql +64 -0
- package/drizzle/0289_session_composer_policy_authority.sql +597 -0
- package/drizzle/0290_organization_membership_backfill.sql +268 -0
- package/drizzle/0291_resource_authority_classification_assertion.sql +371 -0
- package/drizzle/0292_truthful_tenancy_inventory_counters.sql +291 -0
- package/drizzle/0293_confirm_time_rule_rebaseline.sql +615 -0
- package/drizzle/0294_preference_activation_authority.sql +237 -0
- package/drizzle/0295_retire_legacy_standing_memory_mode.sql +476 -0
- package/drizzle/0296_force_rls_backfill_noop_repair.sql +215 -0
- package/drizzle/0297_session_ownership_classification_and_backfill.sql +752 -0
- package/drizzle/0298_organization_tenancy_parity.sql +609 -0
- package/drizzle/0299_organization_membership_lock_order.sql +291 -0
- package/drizzle/0300_tenancy_backfill_ledger.sql +459 -0
- package/drizzle/0301_session_snapshot_and_pin_visibility.sql +181 -0
- package/drizzle/0302_personal_workspace_session_ownership.sql +303 -0
- package/drizzle/0303_session_tenancy_product_activation.sql +919 -0
- package/drizzle/0304_personal_workspace_private_session_reads.sql +97 -0
- package/drizzle/0305_personal_resource_grant_management.sql +584 -0
- package/drizzle/0306_atomic_personal_resource_attachments.sql +1374 -0
- package/drizzle/0307_session_attention_state.sql +51 -0
- package/drizzle/0308_session_archives.sql +35 -0
- package/drizzle/0309_channel_project_pins.sql +6 -0
- package/drizzle/0310_channel_project_order.sql +27 -0
- package/drizzle/0311_company_scope_and_private_session_create.sql +656 -0
- package/drizzle/0312_quiescent_session_tree_deletion.sql +39 -0
- package/drizzle/0313_private_child_session_authority.sql +365 -0
- package/drizzle/0314_unregistered_organization_invitations.sql +606 -0
- package/drizzle/0315_personal_github_repository_selection.sql +624 -0
- package/drizzle/0316_human_confirmed_activation_resumed_generation.sql +869 -0
- package/drizzle/0317_session_goal_continuation_hold.sql +64 -0
- package/drizzle/0318_session_turn_startup_milestones.sql +115 -0
- package/drizzle/0319_event_triggered_automations.sql +254 -0
- package/drizzle/0320_pr_review_pack.sql +113 -0
- package/drizzle/0321_slack_bot_environment_display_name.sql +15 -0
- package/drizzle/0322_session_turns_unclaimed_prompt_trigger_index.sql +5 -0
- package/drizzle/0323_organization_private_session_enablement.sql +489 -0
- package/drizzle/0324_human_confirmed_company_profile_agent_admin.sql +856 -0
- package/drizzle/0325_child_lifecycle_notices.sql +44 -0
- package/drizzle/0326_interaction_operation_error_codes.sql +62 -0
- package/drizzle/0327_slack_first_task_hint.sql +29 -0
- package/drizzle/0328_session_background_commands.sql +590 -0
- package/drizzle/0329_slack_orchestration_delivery_events.sql +91 -0
- package/drizzle/0330_api_key_descriptions.sql +20 -0
- package/drizzle/0331_managed_organization_creation.sql +163 -0
- package/drizzle/0332_organization_shared_workspace_control_plane.sql +539 -0
- package/drizzle/0333_session_turn_prompt_routing.sql +45 -0
- package/drizzle/0334_connected_machine_workspace_root.sql +99 -0
- package/drizzle/0335_slack_workspace_routing.sql +460 -0
- package/drizzle/0336_atomic_session_fork_visibility.sql +667 -0
- package/drizzle/0337_slack_routed_action_handles.sql +189 -0
- package/drizzle/0338_atomic_connected_machine_attachments.sql +410 -0
- package/drizzle/0339_document_authority_reclassification.sql +1153 -0
- package/drizzle/0340_tenancy_backfill_activation_evidence.sql +1347 -0
- package/drizzle/0341_slack_routing_probe_organization_fence.sql +109 -0
- package/package.json +10 -6
- package/src/attached-browser-devices.ts +233 -5
- package/src/automations.ts +911 -0
- package/src/browser-sessions.ts +10 -0
- package/src/capability-integrations.ts +175 -1
- package/src/child-lifecycle-notices.ts +241 -0
- package/src/codemode-operations.ts +1 -35
- package/src/company-brain-context-selection-schema.ts +100 -0
- package/src/company-brain-context-selection.ts +359 -0
- package/src/company-brain-governed-writes.ts +1170 -0
- package/src/company-brain.ts +309 -0
- package/src/company-profile-agent-admin.ts +225 -0
- package/src/company-profile-schema.ts +121 -1
- package/src/company-profile.ts +21 -0
- package/src/computer-sessions.ts +10 -1
- package/src/connection-authority.ts +290 -0
- package/src/connection-scopes.ts +20 -0
- package/src/connection-tenancy-backfill.ts +81 -0
- package/src/connection-token-resolver.ts +263 -31
- package/src/database.ts +75 -2
- package/src/editable-artifacts-schema.ts +10 -5
- package/src/editable-artifacts.ts +21 -11
- package/src/governed-learning-activation-schema.ts +121 -0
- package/src/governed-learning-activation.ts +588 -0
- package/src/governed-learning-evaluator-schema.ts +72 -0
- package/src/governed-learning-evaluator.ts +217 -0
- package/src/index.ts +11651 -1548
- package/src/insights.ts +107 -0
- package/src/integration-bindings.ts +88 -6
- package/src/integration-facets.ts +287 -84
- package/src/interaction-placement-loss.ts +234 -0
- package/src/managed-human-provisioning.ts +116 -0
- package/src/memory-domain.ts +27 -32
- package/src/migrate.ts +77 -1
- package/src/new-session-drafts.ts +229 -35
- package/src/organization-membership-backfill.ts +735 -0
- package/src/organization-membership-lifecycle.ts +985 -0
- package/src/pr-review.ts +890 -0
- package/src/preference-registry.ts +31 -1
- package/src/provision-roles.ts +877 -6
- package/src/runtime-posture-cli.ts +2 -0
- package/src/runtime-posture.ts +1291 -76
- package/src/schema.ts +3303 -428
- package/src/scoped-knowledge-schema.ts +16 -8
- package/src/scoped-knowledge.ts +1 -1
- package/src/session-background-commands.ts +759 -0
- package/src/session-control.ts +640 -74
- package/src/session-goal-pacing.ts +126 -0
- package/src/session-queue-commands.ts +437 -84
- package/src/session-realtime-context.ts +3 -3
- package/src/session-realtime-ledger.ts +22 -11
- package/src/session-realtime-mirror.ts +1 -1
- package/src/session-tenancy.ts +403 -49
- package/src/session-tool-call-settlement.ts +38 -29
- package/src/slack-routing-personal-workspace.ts +67 -0
- package/src/slack-routing.ts +469 -0
- package/src/slack-task-policy-schema.ts +5 -0
- package/src/slack-task-policy.ts +18 -0
- package/src/slack-user-link-access.ts +17 -1
- package/src/task-notes-schema.ts +74 -0
- package/src/task-notes.ts +124 -2
- package/src/turn-initiator.ts +8 -0
- package/src/user-resource-authority.ts +377 -0
- package/src/workspace-authority.ts +160 -0
- package/src/workspace-instruction-policies-schema.ts +53 -1
- package/src/workspace-instruction-policies.ts +528 -77
- package/src/workspace-learning-policy.ts +21 -5
- package/src/workspace-membership-permissions.ts +9 -0
- package/dist/chunk-4SR4HKKA.js.map +0 -1
- package/dist/chunk-6ZYKCRFO.js.map +0 -1
- package/dist/chunk-NXAFLCQX.js +0 -2468
- package/dist/chunk-NXAFLCQX.js.map +0 -1
- package/dist/chunk-SK7YYHBI.js.map +0 -1
- package/dist/chunk-WD5ROSLL.js +0 -117
- package/dist/chunk-WD5ROSLL.js.map +0 -1
- package/dist/chunk-ZWREYEWA.js.map +0 -1
- /package/dist/{chunk-LTG3S6ZY.js.map → chunk-EULAN2NP.js.map} +0 -0
- /package/dist/{chunk-CUPM3FGB.js.map → chunk-NJVZPWXY.js.map} +0 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
SET lock_timeout = '5s';
|
|
3
|
+
SET statement_timeout = '10min';
|
|
4
|
+
|
|
5
|
+
-- Surface activation authority on preference descriptors.
|
|
6
|
+
--
|
|
7
|
+
-- `provenance.trust` is the frozen creation-time fact and stays exactly as it
|
|
8
|
+
-- is: a revision an agent proposed is `untrusted_proposal` forever, and both
|
|
9
|
+
-- activation adapters still require that value, so it cannot be repurposed to
|
|
10
|
+
-- mean "a human approved this". The separate question - did a human explicitly
|
|
11
|
+
-- confirm this activation, or did policy activate it automatically - already
|
|
12
|
+
-- has a durable answer in the governed-learning activation receipt. This
|
|
13
|
+
-- reads it at descriptor-build time rather than mutating any immutable row.
|
|
14
|
+
--
|
|
15
|
+
-- Snapshots written before this field existed keep their exact stored JSON and
|
|
16
|
+
-- their pinned descriptor hash; the contract parses their missing value as
|
|
17
|
+
-- null, which is the truthful reading.
|
|
18
|
+
|
|
19
|
+
CREATE OR REPLACE FUNCTION preference_registry_canonical_snapshot_at(p_account_id uuid, p_workspace_id uuid, p_initiating_human_subject_id text, p_accepted_at timestamp with time zone)
|
|
20
|
+
RETURNS TABLE(canonical_descriptors jsonb, canonical_truncated boolean)
|
|
21
|
+
LANGUAGE plpgsql
|
|
22
|
+
STABLE
|
|
23
|
+
AS $function$
|
|
24
|
+
DECLARE
|
|
25
|
+
canonical_descriptor jsonb;
|
|
26
|
+
candidate_descriptors jsonb;
|
|
27
|
+
BEGIN
|
|
28
|
+
canonical_descriptors := '[]'::jsonb;
|
|
29
|
+
canonical_truncated := false;
|
|
30
|
+
|
|
31
|
+
FOR canonical_descriptor IN
|
|
32
|
+
WITH state_event AS (
|
|
33
|
+
SELECT DISTINCT ON (event.preference_id)
|
|
34
|
+
event.preference_id,
|
|
35
|
+
event.type,
|
|
36
|
+
event.new_revision_id
|
|
37
|
+
FROM preference_registry_events event
|
|
38
|
+
WHERE event.account_id = p_account_id
|
|
39
|
+
AND event.created_at <= p_accepted_at
|
|
40
|
+
AND event.type IN (
|
|
41
|
+
'proposal_created',
|
|
42
|
+
'activated',
|
|
43
|
+
'corrected',
|
|
44
|
+
'rejected',
|
|
45
|
+
'deactivated',
|
|
46
|
+
'superseded'
|
|
47
|
+
)
|
|
48
|
+
ORDER BY
|
|
49
|
+
event.preference_id,
|
|
50
|
+
event.created_at DESC,
|
|
51
|
+
event.version DESC,
|
|
52
|
+
event.id DESC
|
|
53
|
+
), scope_event AS (
|
|
54
|
+
SELECT DISTINCT ON (event.preference_id)
|
|
55
|
+
event.preference_id,
|
|
56
|
+
event.new_scope AS scope,
|
|
57
|
+
event.new_workspace_id AS scope_workspace_id,
|
|
58
|
+
event.new_subject_id AS scope_subject_id
|
|
59
|
+
FROM preference_registry_events event
|
|
60
|
+
WHERE event.account_id = p_account_id
|
|
61
|
+
AND event.created_at <= p_accepted_at
|
|
62
|
+
AND event.new_scope IS NOT NULL
|
|
63
|
+
ORDER BY
|
|
64
|
+
event.preference_id,
|
|
65
|
+
event.created_at DESC,
|
|
66
|
+
event.version DESC,
|
|
67
|
+
event.id DESC
|
|
68
|
+
), activation_version AS (
|
|
69
|
+
SELECT
|
|
70
|
+
event.preference_id,
|
|
71
|
+
count(*)::integer AS value
|
|
72
|
+
FROM preference_registry_events event
|
|
73
|
+
WHERE event.account_id = p_account_id
|
|
74
|
+
AND event.created_at <= p_accepted_at
|
|
75
|
+
AND event.type IN ('activated', 'corrected', 'deactivated')
|
|
76
|
+
GROUP BY event.preference_id
|
|
77
|
+
)
|
|
78
|
+
SELECT jsonb_build_object(
|
|
79
|
+
'id', preference.id::text,
|
|
80
|
+
'stableKey', preference.stable_key,
|
|
81
|
+
'title', revision.title,
|
|
82
|
+
'description', revision.description,
|
|
83
|
+
'scope', scope.scope,
|
|
84
|
+
'activeVersion', coalesce(activation.value, 0),
|
|
85
|
+
'revisionId', revision.id::text,
|
|
86
|
+
'contentHash', revision.content_hash,
|
|
87
|
+
'precedence', jsonb_build_object(
|
|
88
|
+
'tier', scope.scope,
|
|
89
|
+
'rank', revision.precedence_rank,
|
|
90
|
+
'conflictStrategy', revision.conflict_strategy,
|
|
91
|
+
'conflictsWith', revision.conflicts_with
|
|
92
|
+
),
|
|
93
|
+
'provenance', jsonb_build_object(
|
|
94
|
+
'source', revision.provenance_source,
|
|
95
|
+
'sourceIdHash', CASE
|
|
96
|
+
WHEN revision.provenance_source_id IS NULL THEN NULL
|
|
97
|
+
ELSE encode(
|
|
98
|
+
sha256(convert_to(revision.provenance_source_id, 'UTF8')),
|
|
99
|
+
'hex'
|
|
100
|
+
)
|
|
101
|
+
END,
|
|
102
|
+
'trust', revision.trust
|
|
103
|
+
),
|
|
104
|
+
-- How this exact revision became active. `trust` above stays the frozen
|
|
105
|
+
-- creation-time fact; this is the separate activation question, read from
|
|
106
|
+
-- the governed-learning receipt that activated this revision. NULL when
|
|
107
|
+
-- the revision became active outside governed learning.
|
|
108
|
+
'activationAuthority', (
|
|
109
|
+
SELECT receipt.authority_kind
|
|
110
|
+
FROM governed_learning_activation_receipts receipt
|
|
111
|
+
WHERE receipt.account_id = p_account_id
|
|
112
|
+
AND receipt.workspace_id = p_workspace_id
|
|
113
|
+
AND receipt.destination = 'preference'
|
|
114
|
+
AND receipt.destination_revision_id = revision.id
|
|
115
|
+
AND NOT EXISTS (
|
|
116
|
+
SELECT 1 FROM governed_learning_activation_undo_receipts undo
|
|
117
|
+
WHERE undo.account_id = receipt.account_id
|
|
118
|
+
AND undo.activation_receipt_id = receipt.id
|
|
119
|
+
)
|
|
120
|
+
ORDER BY receipt.created_at DESC, receipt.id DESC
|
|
121
|
+
LIMIT 1
|
|
122
|
+
),
|
|
123
|
+
'expiresAt', CASE
|
|
124
|
+
WHEN revision.expires_at IS NULL THEN NULL
|
|
125
|
+
ELSE to_char(
|
|
126
|
+
revision.expires_at AT TIME ZONE 'UTC',
|
|
127
|
+
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
|
128
|
+
)
|
|
129
|
+
END,
|
|
130
|
+
'retrievalHandle',
|
|
131
|
+
'preference://' || preference.id::text || '/revisions/' || revision.id::text ||
|
|
132
|
+
'?sha256=' || revision.content_hash
|
|
133
|
+
)
|
|
134
|
+
FROM state_event state
|
|
135
|
+
JOIN scope_event scope ON scope.preference_id = state.preference_id
|
|
136
|
+
JOIN preference_registry_preferences preference
|
|
137
|
+
ON preference.account_id = p_account_id
|
|
138
|
+
AND preference.id = state.preference_id
|
|
139
|
+
JOIN preference_registry_revisions revision
|
|
140
|
+
ON revision.account_id = preference.account_id
|
|
141
|
+
AND revision.preference_id = preference.id
|
|
142
|
+
AND revision.id = state.new_revision_id
|
|
143
|
+
LEFT JOIN activation_version activation
|
|
144
|
+
ON activation.preference_id = preference.id
|
|
145
|
+
WHERE state.type IN ('activated', 'corrected')
|
|
146
|
+
AND (revision.expires_at IS NULL OR revision.expires_at > p_accepted_at)
|
|
147
|
+
AND (
|
|
148
|
+
scope.scope = 'organization'
|
|
149
|
+
OR (
|
|
150
|
+
scope.scope = 'workspace'
|
|
151
|
+
AND scope.scope_workspace_id = p_workspace_id
|
|
152
|
+
AND scope.scope_subject_id IS NULL
|
|
153
|
+
)
|
|
154
|
+
OR (
|
|
155
|
+
scope.scope = 'user'
|
|
156
|
+
AND scope.scope_workspace_id IS NULL
|
|
157
|
+
AND scope.scope_subject_id = p_initiating_human_subject_id
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
ORDER BY CASE scope.scope
|
|
161
|
+
WHEN 'organization' THEN 0
|
|
162
|
+
WHEN 'workspace' THEN 1
|
|
163
|
+
WHEN 'user' THEN 2
|
|
164
|
+
ELSE 3
|
|
165
|
+
END,
|
|
166
|
+
revision.precedence_rank DESC,
|
|
167
|
+
preference.stable_key,
|
|
168
|
+
preference.id
|
|
169
|
+
LOOP
|
|
170
|
+
IF jsonb_array_length(canonical_descriptors) >= 64 THEN
|
|
171
|
+
canonical_truncated := true;
|
|
172
|
+
EXIT;
|
|
173
|
+
END IF;
|
|
174
|
+
candidate_descriptors := canonical_descriptors || jsonb_build_array(canonical_descriptor);
|
|
175
|
+
IF octet_length(convert_to(candidate_descriptors::text, 'UTF8')) > 16384 THEN
|
|
176
|
+
canonical_truncated := true;
|
|
177
|
+
EXIT;
|
|
178
|
+
END IF;
|
|
179
|
+
canonical_descriptors := candidate_descriptors;
|
|
180
|
+
END LOOP;
|
|
181
|
+
|
|
182
|
+
RETURN NEXT;
|
|
183
|
+
END;
|
|
184
|
+
$function$;
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
-- The receipts table stays closed to the runtime role: reads go through a
|
|
188
|
+
-- definer accessor, exactly as the inspection surfaces in 0270 do. This one is
|
|
189
|
+
-- deliberately narrow - it answers only "how did these exact preference
|
|
190
|
+
-- revisions become active", never returning receipt bodies or any other
|
|
191
|
+
-- destination.
|
|
192
|
+
CREATE OR REPLACE FUNCTION preference_registry_activation_authority(
|
|
193
|
+
p_workspace_id uuid,
|
|
194
|
+
p_revision_ids uuid[]
|
|
195
|
+
) RETURNS TABLE (revision_id uuid, authority_kind text)
|
|
196
|
+
LANGUAGE sql
|
|
197
|
+
STABLE
|
|
198
|
+
SECURITY DEFINER
|
|
199
|
+
AS $$
|
|
200
|
+
SELECT DISTINCT ON (receipt.destination_revision_id)
|
|
201
|
+
receipt.destination_revision_id, receipt.authority_kind
|
|
202
|
+
FROM governed_learning_activation_receipts receipt
|
|
203
|
+
WHERE receipt.workspace_id = p_workspace_id
|
|
204
|
+
AND receipt.destination = 'preference'
|
|
205
|
+
AND receipt.destination_revision_id = ANY(p_revision_ids)
|
|
206
|
+
AND opengeni_private.workspace_rls_visible(receipt.account_id, receipt.workspace_id)
|
|
207
|
+
-- An activation that was undone no longer describes how the revision is
|
|
208
|
+
-- active now: a later ordinary activation of the same revision is not
|
|
209
|
+
-- governed learning's doing, and must not inherit its authority.
|
|
210
|
+
AND NOT EXISTS (
|
|
211
|
+
SELECT 1 FROM governed_learning_activation_undo_receipts undo
|
|
212
|
+
WHERE undo.account_id = receipt.account_id
|
|
213
|
+
AND undo.activation_receipt_id = receipt.id
|
|
214
|
+
)
|
|
215
|
+
ORDER BY receipt.destination_revision_id, receipt.created_at DESC, receipt.id DESC;
|
|
216
|
+
$$;
|
|
217
|
+
|
|
218
|
+
DO $preference_activation_authority_access$
|
|
219
|
+
DECLARE
|
|
220
|
+
data_schema text := current_schema();
|
|
221
|
+
signature text := 'preference_registry_activation_authority(uuid,uuid[])';
|
|
222
|
+
BEGIN
|
|
223
|
+
EXECUTE pg_catalog.format(
|
|
224
|
+
'ALTER FUNCTION %I.%s SET search_path = pg_catalog, %I, pg_temp',
|
|
225
|
+
data_schema, signature, data_schema
|
|
226
|
+
);
|
|
227
|
+
EXECUTE pg_catalog.format('REVOKE ALL ON FUNCTION %I.%s FROM PUBLIC', data_schema, signature);
|
|
228
|
+
IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
229
|
+
EXECUTE pg_catalog.format(
|
|
230
|
+
'GRANT EXECUTE ON FUNCTION %I.%s TO opengeni_app', data_schema, signature
|
|
231
|
+
);
|
|
232
|
+
END IF;
|
|
233
|
+
END
|
|
234
|
+
$preference_activation_authority_access$;
|
|
235
|
+
|
|
236
|
+
RESET statement_timeout;
|
|
237
|
+
RESET lock_timeout;
|