@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,588 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActivateGovernedLearningDecisionRequest,
|
|
3
|
+
ActivateHumanConfirmedLearningDecisionRequest,
|
|
4
|
+
ConfirmRememberKnowledgeClaimRequest,
|
|
5
|
+
GovernedLearningActivationCaller,
|
|
6
|
+
RememberKnowledgeConfirmationReceipt,
|
|
7
|
+
GovernedLearningActivationReceipt,
|
|
8
|
+
GovernedLearningActivationUndoReceipt,
|
|
9
|
+
UndoGovernedLearningActivationRequest,
|
|
10
|
+
type ActivateGovernedLearningDecisionRequest as ActivateRequest,
|
|
11
|
+
type ActivateHumanConfirmedLearningDecisionRequest as ActivateHumanConfirmedRequest,
|
|
12
|
+
type ConfirmRememberKnowledgeClaimRequest as ConfirmRememberKnowledgeClaimRequestType,
|
|
13
|
+
type RememberKnowledgeConfirmationReceipt as RememberKnowledgeConfirmationReceiptType,
|
|
14
|
+
type GovernedLearningActivationCaller as ActivationCaller,
|
|
15
|
+
type GovernedLearningActivationReceipt as ActivationReceipt,
|
|
16
|
+
type GovernedLearningActivationUndoReceipt as UndoReceipt,
|
|
17
|
+
type UndoGovernedLearningActivationRequest as UndoRequest,
|
|
18
|
+
} from "@opengeni/contracts";
|
|
19
|
+
import { sql } from "drizzle-orm";
|
|
20
|
+
import type { Database } from "./database";
|
|
21
|
+
import { rawRows, withWorkspaceRls, withWorkspaceSubjectRls } from "./database";
|
|
22
|
+
import { nestedPostgresSqlState } from "./persistence-errors";
|
|
23
|
+
|
|
24
|
+
export class GovernedLearningActivationAuthorityError extends Error {
|
|
25
|
+
readonly name = "GovernedLearningActivationAuthorityError";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class GovernedLearningActivationConflictError extends Error {
|
|
29
|
+
readonly name = "GovernedLearningActivationConflictError";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class GovernedLearningActivationInvalidOperationError extends Error {
|
|
33
|
+
readonly name = "GovernedLearningActivationInvalidOperationError";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ActivationRow = {
|
|
37
|
+
authority_kind?: string | null;
|
|
38
|
+
human_input_request_id?: string | null;
|
|
39
|
+
id: string;
|
|
40
|
+
operation_id: string;
|
|
41
|
+
input_hash: string;
|
|
42
|
+
account_id: string;
|
|
43
|
+
workspace_id: string;
|
|
44
|
+
decision_receipt_id: string;
|
|
45
|
+
initiating_human_subject_id: string;
|
|
46
|
+
service_actor_subject_id: string;
|
|
47
|
+
policy_revision_id: string;
|
|
48
|
+
policy_hash: string;
|
|
49
|
+
policy_activation_version: number | string;
|
|
50
|
+
source_kind: string;
|
|
51
|
+
source_id: string;
|
|
52
|
+
source_authority_hash: string;
|
|
53
|
+
proposal_id: string;
|
|
54
|
+
claim_id: string;
|
|
55
|
+
evidence_id: string;
|
|
56
|
+
knowledge_previous_review_id: string;
|
|
57
|
+
knowledge_previous_review_revision: number | string;
|
|
58
|
+
knowledge_approval_review_id: string;
|
|
59
|
+
knowledge_approval_review_revision: number | string;
|
|
60
|
+
knowledge_approval_input_hash: string;
|
|
61
|
+
destination: string;
|
|
62
|
+
destination_proposal_id: string;
|
|
63
|
+
destination_revision_id: string;
|
|
64
|
+
destination_old_revision_id: string | null;
|
|
65
|
+
destination_old_content_hash: string | null;
|
|
66
|
+
destination_old_version: number | string;
|
|
67
|
+
destination_new_content_hash: string;
|
|
68
|
+
destination_new_version: number | string;
|
|
69
|
+
destination_event_id: string;
|
|
70
|
+
effective_at: Date | string;
|
|
71
|
+
created_at: Date | string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
type UndoRow = {
|
|
75
|
+
id: string;
|
|
76
|
+
operation_id: string;
|
|
77
|
+
input_hash: string;
|
|
78
|
+
account_id: string;
|
|
79
|
+
workspace_id: string;
|
|
80
|
+
activation_receipt_id: string;
|
|
81
|
+
initiating_human_subject_id: string;
|
|
82
|
+
service_actor_subject_id: string;
|
|
83
|
+
destination: string;
|
|
84
|
+
knowledge_approval_review_id: string;
|
|
85
|
+
knowledge_revocation_review_id: string;
|
|
86
|
+
knowledge_revocation_review_revision: number | string;
|
|
87
|
+
knowledge_revocation_input_hash: string;
|
|
88
|
+
destination_activated_revision_id: string;
|
|
89
|
+
destination_restored_revision_id: string | null;
|
|
90
|
+
destination_activated_content_hash: string;
|
|
91
|
+
destination_restored_content_hash: string | null;
|
|
92
|
+
destination_old_version: number | string;
|
|
93
|
+
destination_new_version: number | string;
|
|
94
|
+
destination_event_id: string;
|
|
95
|
+
effective_at: Date | string;
|
|
96
|
+
created_at: Date | string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function iso(value: Date | string): string {
|
|
100
|
+
return (value instanceof Date ? value : new Date(value)).toISOString();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function activationFromRow(row: ActivationRow): ActivationReceipt {
|
|
104
|
+
return GovernedLearningActivationReceipt.parse({
|
|
105
|
+
id: row.id,
|
|
106
|
+
operationId: row.operation_id,
|
|
107
|
+
inputHash: row.input_hash,
|
|
108
|
+
accountId: row.account_id,
|
|
109
|
+
workspaceId: row.workspace_id,
|
|
110
|
+
decisionReceiptId: row.decision_receipt_id,
|
|
111
|
+
initiatingHumanSubjectId: row.initiating_human_subject_id,
|
|
112
|
+
serviceActorSubjectId: row.service_actor_subject_id,
|
|
113
|
+
policyRevisionId: row.policy_revision_id,
|
|
114
|
+
policyHash: row.policy_hash,
|
|
115
|
+
policyActivationVersion: Number(row.policy_activation_version),
|
|
116
|
+
sourceKind: row.source_kind,
|
|
117
|
+
sourceId: row.source_id,
|
|
118
|
+
sourceAuthorityHash: row.source_authority_hash,
|
|
119
|
+
proposalId: row.proposal_id,
|
|
120
|
+
claimId: row.claim_id,
|
|
121
|
+
evidenceId: row.evidence_id,
|
|
122
|
+
knowledgePreviousReviewId: row.knowledge_previous_review_id,
|
|
123
|
+
knowledgePreviousReviewRevision: Number(row.knowledge_previous_review_revision),
|
|
124
|
+
knowledgeApprovalReviewId: row.knowledge_approval_review_id,
|
|
125
|
+
knowledgeApprovalReviewRevision: Number(row.knowledge_approval_review_revision),
|
|
126
|
+
knowledgeApprovalInputHash: row.knowledge_approval_input_hash,
|
|
127
|
+
destination: row.destination,
|
|
128
|
+
destinationProposalId: row.destination_proposal_id,
|
|
129
|
+
destinationRevisionId: row.destination_revision_id,
|
|
130
|
+
destinationOldRevisionId: row.destination_old_revision_id,
|
|
131
|
+
destinationOldContentHash: row.destination_old_content_hash,
|
|
132
|
+
destinationOldVersion: Number(row.destination_old_version),
|
|
133
|
+
destinationNewContentHash: row.destination_new_content_hash,
|
|
134
|
+
destinationNewVersion: Number(row.destination_new_version),
|
|
135
|
+
destinationEventId: row.destination_event_id,
|
|
136
|
+
outcome: "activated",
|
|
137
|
+
effectiveAt: iso(row.effective_at),
|
|
138
|
+
authorityKind: row.authority_kind ?? "automatic",
|
|
139
|
+
humanInputRequestId: row.human_input_request_id ?? null,
|
|
140
|
+
rollback: { supported: true, mechanism: "exact_head_and_latest_review" },
|
|
141
|
+
createdAt: iso(row.created_at),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function undoFromRow(row: UndoRow): UndoReceipt {
|
|
146
|
+
return GovernedLearningActivationUndoReceipt.parse({
|
|
147
|
+
id: row.id,
|
|
148
|
+
operationId: row.operation_id,
|
|
149
|
+
inputHash: row.input_hash,
|
|
150
|
+
accountId: row.account_id,
|
|
151
|
+
workspaceId: row.workspace_id,
|
|
152
|
+
activationReceiptId: row.activation_receipt_id,
|
|
153
|
+
initiatingHumanSubjectId: row.initiating_human_subject_id,
|
|
154
|
+
serviceActorSubjectId: row.service_actor_subject_id,
|
|
155
|
+
destination: row.destination,
|
|
156
|
+
knowledgeApprovalReviewId: row.knowledge_approval_review_id,
|
|
157
|
+
knowledgeRevocationReviewId: row.knowledge_revocation_review_id,
|
|
158
|
+
knowledgeRevocationReviewRevision: Number(row.knowledge_revocation_review_revision),
|
|
159
|
+
knowledgeRevocationInputHash: row.knowledge_revocation_input_hash,
|
|
160
|
+
destinationActivatedRevisionId: row.destination_activated_revision_id,
|
|
161
|
+
destinationRestoredRevisionId: row.destination_restored_revision_id,
|
|
162
|
+
destinationActivatedContentHash: row.destination_activated_content_hash,
|
|
163
|
+
destinationRestoredContentHash: row.destination_restored_content_hash,
|
|
164
|
+
destinationOldVersion: Number(row.destination_old_version),
|
|
165
|
+
destinationNewVersion: Number(row.destination_new_version),
|
|
166
|
+
destinationEventId: row.destination_event_id,
|
|
167
|
+
outcome: "undone",
|
|
168
|
+
superseded: false,
|
|
169
|
+
effectiveAt: iso(row.effective_at),
|
|
170
|
+
createdAt: iso(row.created_at),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Subject-filtered activation and compensation history for Workspace State. */
|
|
175
|
+
export async function listGovernedLearningActivationHistory(
|
|
176
|
+
db: Database,
|
|
177
|
+
input: { workspaceId: string; subjectId: string; principalKind: string; limit: number },
|
|
178
|
+
): Promise<{ activations: ActivationReceipt[]; undos: UndoReceipt[]; truncated: boolean }> {
|
|
179
|
+
if (input.principalKind !== "human_session") {
|
|
180
|
+
throw new GovernedLearningActivationAuthorityError(
|
|
181
|
+
"Governed-learning history requires an exact authenticated human actor",
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const limit = Math.max(1, Math.min(input.limit, 100));
|
|
185
|
+
try {
|
|
186
|
+
return await withWorkspaceSubjectRls(db, input.workspaceId, input.subjectId, async (scoped) => {
|
|
187
|
+
await scoped.execute(
|
|
188
|
+
sql`select set_config('opengeni.principal_kind', ${input.principalKind}, true)`,
|
|
189
|
+
);
|
|
190
|
+
const [activationRows, undoRows] = await Promise.all([
|
|
191
|
+
rawRows<ActivationRow>(
|
|
192
|
+
scoped,
|
|
193
|
+
sql`SELECT * FROM inspect_governed_learning_activations(
|
|
194
|
+
current_setting('opengeni.account_id')::uuid,
|
|
195
|
+
${input.workspaceId}::uuid,
|
|
196
|
+
${input.subjectId},
|
|
197
|
+
${limit + 1}
|
|
198
|
+
)`,
|
|
199
|
+
),
|
|
200
|
+
rawRows<UndoRow>(
|
|
201
|
+
scoped,
|
|
202
|
+
sql`SELECT * FROM inspect_governed_learning_activation_undos(
|
|
203
|
+
current_setting('opengeni.account_id')::uuid,
|
|
204
|
+
${input.workspaceId}::uuid,
|
|
205
|
+
${input.subjectId},
|
|
206
|
+
${limit + 1}
|
|
207
|
+
)`,
|
|
208
|
+
),
|
|
209
|
+
]);
|
|
210
|
+
return {
|
|
211
|
+
activations: activationRows.slice(0, limit).map(activationFromRow),
|
|
212
|
+
undos: undoRows.slice(0, limit).map(undoFromRow),
|
|
213
|
+
truncated: activationRows.length > limit || undoRows.length > limit,
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (nestedPostgresSqlState(error) === "42501") {
|
|
218
|
+
throw new GovernedLearningActivationAuthorityError(
|
|
219
|
+
"Governed-learning history is unavailable",
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The translated errors keep the originating failure as `cause`. The SQLSTATE
|
|
227
|
+
// alone collapses distinguishable outcomes - a stale instruction-policy
|
|
228
|
+
// baseline and a duplicate-key conflict are both surfaced here - so callers
|
|
229
|
+
// that need to tell them apart can still reach the exact database diagnostic
|
|
230
|
+
// without re-running the operation.
|
|
231
|
+
function translate(error: unknown): never {
|
|
232
|
+
const state = nestedPostgresSqlState(error);
|
|
233
|
+
if (state === "42501") {
|
|
234
|
+
throw new GovernedLearningActivationAuthorityError(
|
|
235
|
+
"Governed-learning activation is unavailable",
|
|
236
|
+
{ cause: error },
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (state === "23505" || state === "40001") {
|
|
240
|
+
throw new GovernedLearningActivationConflictError(
|
|
241
|
+
"Governed-learning activation conflicted with current authority",
|
|
242
|
+
{ cause: error },
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (state === "23514" || state === "55000" || state === "22023") {
|
|
246
|
+
throw new GovernedLearningActivationInvalidOperationError(
|
|
247
|
+
"Governed-learning activation is no longer eligible",
|
|
248
|
+
{ cause: error },
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export async function activateGovernedLearningDecision(
|
|
255
|
+
db: Database,
|
|
256
|
+
raw: { caller: ActivationCaller; request: ActivateRequest },
|
|
257
|
+
): Promise<ActivationReceipt> {
|
|
258
|
+
const caller = GovernedLearningActivationCaller.parse(raw.caller);
|
|
259
|
+
const request = ActivateGovernedLearningDecisionRequest.parse(raw.request);
|
|
260
|
+
try {
|
|
261
|
+
return await withWorkspaceSubjectRls(
|
|
262
|
+
db,
|
|
263
|
+
caller.workspaceId,
|
|
264
|
+
caller.subjectId,
|
|
265
|
+
async (scoped) => {
|
|
266
|
+
const rows = await rawRows<ActivationRow>(
|
|
267
|
+
scoped,
|
|
268
|
+
sql`SELECT * FROM activate_governed_learning_decision(
|
|
269
|
+
current_setting('opengeni.account_id')::uuid,
|
|
270
|
+
${caller.workspaceId}::uuid,
|
|
271
|
+
${request.operationId}::uuid,
|
|
272
|
+
${request.decisionReceiptId}::uuid
|
|
273
|
+
)`,
|
|
274
|
+
);
|
|
275
|
+
if (rows.length !== 1 || !rows[0]) {
|
|
276
|
+
throw new Error("Governed-learning activation returned no unique receipt");
|
|
277
|
+
}
|
|
278
|
+
return activationFromRow(rows[0]);
|
|
279
|
+
},
|
|
280
|
+
);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
translate(error);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Activate one confirmable evaluator receipt (`suggest`, `automatic`, or
|
|
288
|
+
* `confidence`) because the exact initiating human answered the bound
|
|
289
|
+
* `remember:<proposalId>` structured human-input question with `save` on the
|
|
290
|
+
* same session/turn generation. The database capability revalidates the human
|
|
291
|
+
* answer, current policy (not `off`), evidence, and destination CAS.
|
|
292
|
+
*/
|
|
293
|
+
export async function activateHumanConfirmedLearningDecision(
|
|
294
|
+
db: Database,
|
|
295
|
+
raw: { caller: ActivationCaller; request: ActivateHumanConfirmedRequest },
|
|
296
|
+
): Promise<ActivationReceipt> {
|
|
297
|
+
const caller = GovernedLearningActivationCaller.parse(raw.caller);
|
|
298
|
+
const request = ActivateHumanConfirmedLearningDecisionRequest.parse(raw.request);
|
|
299
|
+
try {
|
|
300
|
+
return await withWorkspaceSubjectRls(
|
|
301
|
+
db,
|
|
302
|
+
caller.workspaceId,
|
|
303
|
+
caller.subjectId,
|
|
304
|
+
async (scoped) => {
|
|
305
|
+
const rows = await rawRows<ActivationRow>(
|
|
306
|
+
scoped,
|
|
307
|
+
sql`SELECT * FROM activate_human_confirmed_learning_decision(
|
|
308
|
+
current_setting('opengeni.account_id')::uuid,
|
|
309
|
+
${caller.workspaceId}::uuid,
|
|
310
|
+
${request.operationId}::uuid,
|
|
311
|
+
${request.decisionReceiptId}::uuid,
|
|
312
|
+
${request.humanInputRequestId}::uuid
|
|
313
|
+
)`,
|
|
314
|
+
);
|
|
315
|
+
if (rows.length !== 1 || !rows[0]) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
"Human-confirmed governed-learning activation returned no unique receipt",
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
return activationFromRow(rows[0]);
|
|
321
|
+
},
|
|
322
|
+
);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
translate(error);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export async function undoGovernedLearningActivation(
|
|
329
|
+
db: Database,
|
|
330
|
+
raw: { caller: ActivationCaller; request: UndoRequest },
|
|
331
|
+
): Promise<UndoReceipt> {
|
|
332
|
+
const caller = GovernedLearningActivationCaller.parse(raw.caller);
|
|
333
|
+
const request = UndoGovernedLearningActivationRequest.parse(raw.request);
|
|
334
|
+
try {
|
|
335
|
+
return await withWorkspaceSubjectRls(
|
|
336
|
+
db,
|
|
337
|
+
caller.workspaceId,
|
|
338
|
+
caller.subjectId,
|
|
339
|
+
async (scoped) => {
|
|
340
|
+
const rows = await rawRows<UndoRow>(
|
|
341
|
+
scoped,
|
|
342
|
+
sql`SELECT * FROM undo_governed_learning_activation(
|
|
343
|
+
current_setting('opengeni.account_id')::uuid,
|
|
344
|
+
${caller.workspaceId}::uuid,
|
|
345
|
+
${request.operationId}::uuid,
|
|
346
|
+
${request.activationReceiptId}::uuid
|
|
347
|
+
)`,
|
|
348
|
+
);
|
|
349
|
+
if (rows.length !== 1 || !rows[0]) {
|
|
350
|
+
throw new Error("Governed-learning activation undo returned no unique receipt");
|
|
351
|
+
}
|
|
352
|
+
return undoFromRow(rows[0]);
|
|
353
|
+
},
|
|
354
|
+
);
|
|
355
|
+
} catch (error) {
|
|
356
|
+
translate(error);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export type GovernedLearningEvidenceOrigin =
|
|
361
|
+
| { kind: "task-note" }
|
|
362
|
+
| { kind: "document"; providerKey: string | null };
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Resolve where the evidence behind a governed-learning receipt came from, so
|
|
366
|
+
* notification sinks can fail closed for evidence that originated in the same
|
|
367
|
+
* connector they publish to (loop prevention). Returns `null` when the exact
|
|
368
|
+
* evidence row is not visible under the workspace authority.
|
|
369
|
+
*/
|
|
370
|
+
export async function resolveGovernedLearningEvidenceOrigin(
|
|
371
|
+
db: Database,
|
|
372
|
+
input: { workspaceId: string; evidenceId: string },
|
|
373
|
+
): Promise<GovernedLearningEvidenceOrigin | null> {
|
|
374
|
+
return await withWorkspaceRls(db, input.workspaceId, async (scoped) => {
|
|
375
|
+
const rows = await rawRows<{
|
|
376
|
+
task_note_id: string | null;
|
|
377
|
+
provider_key: string | null;
|
|
378
|
+
}>(
|
|
379
|
+
scoped,
|
|
380
|
+
sql`SELECT evidence.task_note_id, provider.provider_key
|
|
381
|
+
FROM knowledge_claim_evidence evidence
|
|
382
|
+
LEFT JOIN knowledge_document_versions version
|
|
383
|
+
ON version.account_id = evidence.account_id
|
|
384
|
+
AND version.id = evidence.document_version_id
|
|
385
|
+
LEFT JOIN knowledge_sources source
|
|
386
|
+
ON source.account_id = version.account_id
|
|
387
|
+
AND source.id = version.source_id
|
|
388
|
+
LEFT JOIN knowledge_providers provider
|
|
389
|
+
ON provider.account_id = source.account_id
|
|
390
|
+
AND provider.id = source.provider_id
|
|
391
|
+
WHERE evidence.account_id = current_setting('opengeni.account_id')::uuid
|
|
392
|
+
AND evidence.scope_kind = 'workspace'
|
|
393
|
+
AND evidence.scope_workspace_id = ${input.workspaceId}::uuid
|
|
394
|
+
AND evidence.id = ${input.evidenceId}::uuid
|
|
395
|
+
LIMIT 1`,
|
|
396
|
+
);
|
|
397
|
+
const row = rows[0];
|
|
398
|
+
if (!row) return null;
|
|
399
|
+
if (row.task_note_id) return { kind: "task-note" };
|
|
400
|
+
return { kind: "document", providerKey: row.provider_key };
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export type GovernedLearningProposalSummary = {
|
|
405
|
+
id: string;
|
|
406
|
+
claimId: string;
|
|
407
|
+
evidenceId: string;
|
|
408
|
+
status: string;
|
|
409
|
+
targetKind: string;
|
|
410
|
+
initiatingHumanSubjectId: string | null;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Read one workspace-scoped `knowledge_change_proposals` row under workspace
|
|
415
|
+
* RLS. Used by `remember_confirm` to rebuild the evaluator request for the
|
|
416
|
+
* exact proposal the human confirmed; it exposes no content.
|
|
417
|
+
*/
|
|
418
|
+
export async function getWorkspaceKnowledgeChangeProposalSummary(
|
|
419
|
+
db: Database,
|
|
420
|
+
input: { workspaceId: string; proposalId: string },
|
|
421
|
+
): Promise<GovernedLearningProposalSummary | null> {
|
|
422
|
+
return await withWorkspaceRls(db, input.workspaceId, async (scoped) => {
|
|
423
|
+
const rows = await rawRows<{
|
|
424
|
+
id: string;
|
|
425
|
+
claim_id: string;
|
|
426
|
+
evidence_id: string;
|
|
427
|
+
status: string;
|
|
428
|
+
target_kind: string;
|
|
429
|
+
initiating_human_subject_id: string | null;
|
|
430
|
+
}>(
|
|
431
|
+
scoped,
|
|
432
|
+
sql`SELECT proposal.id, proposal.claim_id, proposal.evidence_id, proposal.status,
|
|
433
|
+
proposal.target_kind, proposal.initiating_human_subject_id
|
|
434
|
+
FROM knowledge_change_proposals proposal
|
|
435
|
+
WHERE proposal.account_id = current_setting('opengeni.account_id')::uuid
|
|
436
|
+
AND proposal.scope_kind = 'workspace'
|
|
437
|
+
AND proposal.scope_workspace_id = ${input.workspaceId}::uuid
|
|
438
|
+
AND proposal.scope_subject_id IS NULL
|
|
439
|
+
AND proposal.id = ${input.proposalId}::uuid
|
|
440
|
+
LIMIT 1`,
|
|
441
|
+
);
|
|
442
|
+
const row = rows[0];
|
|
443
|
+
if (!row) return null;
|
|
444
|
+
return {
|
|
445
|
+
id: row.id,
|
|
446
|
+
claimId: row.claim_id,
|
|
447
|
+
evidenceId: row.evidence_id,
|
|
448
|
+
status: row.status,
|
|
449
|
+
targetKind: row.target_kind,
|
|
450
|
+
initiatingHumanSubjectId: row.initiating_human_subject_id,
|
|
451
|
+
};
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
type KnowledgeConfirmationRow = {
|
|
456
|
+
id: string;
|
|
457
|
+
operation_id: string;
|
|
458
|
+
input_hash: string;
|
|
459
|
+
account_id: string;
|
|
460
|
+
workspace_id: string;
|
|
461
|
+
session_id: string;
|
|
462
|
+
turn_id: string;
|
|
463
|
+
execution_generation: number;
|
|
464
|
+
initiating_human_subject_id: string;
|
|
465
|
+
service_actor_subject_id: string;
|
|
466
|
+
claim_id: string;
|
|
467
|
+
evidence_id: string;
|
|
468
|
+
task_note_id: string;
|
|
469
|
+
task_note_text_hash: string;
|
|
470
|
+
human_input_request_id: string;
|
|
471
|
+
previous_review_id: string;
|
|
472
|
+
previous_review_revision: number | string;
|
|
473
|
+
approval_review_id: string;
|
|
474
|
+
approval_review_revision: number | string;
|
|
475
|
+
created_at: Date | string;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Approve one user-directed Knowledge claim after the exact initiating human
|
|
480
|
+
* answered the bound `remember:<claimId>` structured human-input question with
|
|
481
|
+
* `save` on the live turn. The database capability revalidates the claim,
|
|
482
|
+
* Task-note evidence, latest `proposed` review, and the canonical question
|
|
483
|
+
* before writing the approval through the guarded service-review path.
|
|
484
|
+
*/
|
|
485
|
+
export async function confirmRememberKnowledgeClaim(
|
|
486
|
+
db: Database,
|
|
487
|
+
raw: {
|
|
488
|
+
caller: ActivationCaller & {
|
|
489
|
+
sessionId: string;
|
|
490
|
+
turnId: string;
|
|
491
|
+
executionGeneration: number;
|
|
492
|
+
};
|
|
493
|
+
request: ConfirmRememberKnowledgeClaimRequestType;
|
|
494
|
+
},
|
|
495
|
+
): Promise<RememberKnowledgeConfirmationReceiptType> {
|
|
496
|
+
const caller = GovernedLearningActivationCaller.parse({
|
|
497
|
+
workspaceId: raw.caller.workspaceId,
|
|
498
|
+
subjectId: raw.caller.subjectId,
|
|
499
|
+
});
|
|
500
|
+
const request = ConfirmRememberKnowledgeClaimRequest.parse(raw.request);
|
|
501
|
+
const { sessionId, turnId, executionGeneration } = raw.caller;
|
|
502
|
+
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
503
|
+
if (
|
|
504
|
+
!uuidPattern.test(sessionId) ||
|
|
505
|
+
!uuidPattern.test(turnId) ||
|
|
506
|
+
!Number.isSafeInteger(executionGeneration) ||
|
|
507
|
+
executionGeneration <= 0
|
|
508
|
+
) {
|
|
509
|
+
throw new GovernedLearningActivationAuthorityError(
|
|
510
|
+
"remember Knowledge confirmation requires exact turn authority",
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
try {
|
|
514
|
+
return await withWorkspaceSubjectRls(
|
|
515
|
+
db,
|
|
516
|
+
caller.workspaceId,
|
|
517
|
+
caller.subjectId,
|
|
518
|
+
async (scoped) => {
|
|
519
|
+
const rows = await rawRows<KnowledgeConfirmationRow>(
|
|
520
|
+
scoped,
|
|
521
|
+
sql`SELECT * FROM confirm_remember_knowledge_claim(
|
|
522
|
+
current_setting('opengeni.account_id')::uuid,
|
|
523
|
+
${caller.workspaceId}::uuid,
|
|
524
|
+
${sessionId}::uuid,
|
|
525
|
+
${turnId}::uuid,
|
|
526
|
+
${executionGeneration}::integer,
|
|
527
|
+
${request.operationId}::uuid,
|
|
528
|
+
${request.claimId}::uuid,
|
|
529
|
+
${request.humanInputRequestId}::uuid
|
|
530
|
+
)`,
|
|
531
|
+
);
|
|
532
|
+
const row = rows[0];
|
|
533
|
+
if (rows.length !== 1 || !row) {
|
|
534
|
+
throw new Error("remember Knowledge confirmation returned no unique receipt");
|
|
535
|
+
}
|
|
536
|
+
return RememberKnowledgeConfirmationReceipt.parse({
|
|
537
|
+
id: row.id,
|
|
538
|
+
operationId: row.operation_id,
|
|
539
|
+
inputHash: row.input_hash,
|
|
540
|
+
accountId: row.account_id,
|
|
541
|
+
workspaceId: row.workspace_id,
|
|
542
|
+
sessionId: row.session_id,
|
|
543
|
+
turnId: row.turn_id,
|
|
544
|
+
executionGeneration: Number(row.execution_generation),
|
|
545
|
+
initiatingHumanSubjectId: row.initiating_human_subject_id,
|
|
546
|
+
serviceActorSubjectId: row.service_actor_subject_id,
|
|
547
|
+
claimId: row.claim_id,
|
|
548
|
+
evidenceId: row.evidence_id,
|
|
549
|
+
taskNoteId: row.task_note_id,
|
|
550
|
+
taskNoteTextHash: row.task_note_text_hash,
|
|
551
|
+
humanInputRequestId: row.human_input_request_id,
|
|
552
|
+
previousReviewId: row.previous_review_id,
|
|
553
|
+
previousReviewRevision: Number(row.previous_review_revision),
|
|
554
|
+
approvalReviewId: row.approval_review_id,
|
|
555
|
+
approvalReviewRevision: Number(row.approval_review_revision),
|
|
556
|
+
createdAt: iso(row.created_at),
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
);
|
|
560
|
+
} catch (error) {
|
|
561
|
+
translate(error);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Read the initiating human bound to one workspace-scoped Knowledge claim under
|
|
567
|
+
* workspace RLS. Used by `remember_confirm` for the Knowledge lane; exposes no
|
|
568
|
+
* content.
|
|
569
|
+
*/
|
|
570
|
+
export async function getWorkspaceKnowledgeClaimInitiatingHuman(
|
|
571
|
+
db: Database,
|
|
572
|
+
input: { workspaceId: string; claimId: string },
|
|
573
|
+
): Promise<string | null> {
|
|
574
|
+
return await withWorkspaceRls(db, input.workspaceId, async (scoped) => {
|
|
575
|
+
const rows = await rawRows<{ initiating_human_subject_id: string | null }>(
|
|
576
|
+
scoped,
|
|
577
|
+
sql`SELECT claim.initiating_human_subject_id
|
|
578
|
+
FROM knowledge_claims claim
|
|
579
|
+
WHERE claim.account_id = current_setting('opengeni.account_id')::uuid
|
|
580
|
+
AND claim.scope_kind = 'workspace'
|
|
581
|
+
AND claim.scope_workspace_id = ${input.workspaceId}::uuid
|
|
582
|
+
AND claim.scope_subject_id IS NULL
|
|
583
|
+
AND claim.id = ${input.claimId}::uuid
|
|
584
|
+
LIMIT 1`,
|
|
585
|
+
);
|
|
586
|
+
return rows[0]?.initiating_human_subject_id ?? null;
|
|
587
|
+
});
|
|
588
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { GovernedLearningDecisionReason } from "@opengeni/contracts";
|
|
2
|
+
import {
|
|
3
|
+
bigint,
|
|
4
|
+
boolean,
|
|
5
|
+
index,
|
|
6
|
+
integer,
|
|
7
|
+
pgTable,
|
|
8
|
+
text,
|
|
9
|
+
timestamp,
|
|
10
|
+
uniqueIndex,
|
|
11
|
+
uuid,
|
|
12
|
+
} from "drizzle-orm/pg-core";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Immutable, content-free evaluator evidence. Migration 0268 owns the exact
|
|
16
|
+
* foreign keys, checks, FORCE-RLS policies, trigger, and runtime privileges.
|
|
17
|
+
*/
|
|
18
|
+
export const governedLearningDecisionReceipts = pgTable(
|
|
19
|
+
"governed_learning_decision_receipts",
|
|
20
|
+
{
|
|
21
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
22
|
+
accountId: uuid("account_id").notNull(),
|
|
23
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
24
|
+
operationId: uuid("operation_id").notNull(),
|
|
25
|
+
inputHash: text("input_hash").notNull(),
|
|
26
|
+
sessionId: uuid("session_id").notNull(),
|
|
27
|
+
turnId: uuid("turn_id").notNull(),
|
|
28
|
+
attemptId: uuid("attempt_id").notNull(),
|
|
29
|
+
executionGeneration: integer("execution_generation").notNull(),
|
|
30
|
+
initiatingHumanSubjectId: text("initiating_human_subject_id").notNull(),
|
|
31
|
+
policySnapshotId: uuid("policy_snapshot_id").notNull(),
|
|
32
|
+
policySnapshotHash: text("policy_snapshot_hash").notNull(),
|
|
33
|
+
policyRevisionId: uuid("policy_revision_id"),
|
|
34
|
+
policyActivationVersion: bigint("policy_activation_version", { mode: "number" }).notNull(),
|
|
35
|
+
sourceKind: text("source_kind").notNull(),
|
|
36
|
+
sourceId: uuid("source_id").notNull(),
|
|
37
|
+
proposalId: uuid("proposal_id").notNull(),
|
|
38
|
+
proposalInputHash: text("proposal_input_hash").notNull(),
|
|
39
|
+
proposalContentHash: text("proposal_content_hash").notNull(),
|
|
40
|
+
claimId: uuid("claim_id").notNull(),
|
|
41
|
+
claimInputHash: text("claim_input_hash").notNull(),
|
|
42
|
+
evidenceId: uuid("evidence_id").notNull(),
|
|
43
|
+
evidenceInputHash: text("evidence_input_hash").notNull(),
|
|
44
|
+
evidenceContentHash: text("evidence_content_hash").notNull(),
|
|
45
|
+
evidenceAuthorityHash: text("evidence_authority_hash").notNull(),
|
|
46
|
+
reviewRevision: bigint("review_revision", { mode: "number" }).notNull(),
|
|
47
|
+
reviewState: text("review_state").notNull(),
|
|
48
|
+
effectiveMode: text("effective_mode").notNull(),
|
|
49
|
+
confidenceBps: integer("confidence_bps").notNull(),
|
|
50
|
+
conflictCount: integer("conflict_count").notNull(),
|
|
51
|
+
outcome: text("outcome").notNull(),
|
|
52
|
+
reasonCodes: text("reason_codes").array().$type<GovernedLearningDecisionReason[]>().notNull(),
|
|
53
|
+
automaticEligible: boolean("automatic_eligible").notNull(),
|
|
54
|
+
confidenceFloorBps: integer("confidence_floor_bps").notNull(),
|
|
55
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
56
|
+
},
|
|
57
|
+
(table) => ({
|
|
58
|
+
workspaceOperation: uniqueIndex("governed_learning_decision_receipts_operation_uq").on(
|
|
59
|
+
table.workspaceId,
|
|
60
|
+
table.operationId,
|
|
61
|
+
),
|
|
62
|
+
snapshotProposal: uniqueIndex("governed_learning_decision_receipts_snapshot_proposal_uq").on(
|
|
63
|
+
table.policySnapshotId,
|
|
64
|
+
table.proposalId,
|
|
65
|
+
),
|
|
66
|
+
workspaceTimeline: index("governed_learning_decision_receipts_workspace_time_idx").on(
|
|
67
|
+
table.workspaceId,
|
|
68
|
+
table.createdAt,
|
|
69
|
+
table.id,
|
|
70
|
+
),
|
|
71
|
+
}),
|
|
72
|
+
);
|