@opengeni/db 1.0.1 → 3.2.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-4SR4HKKA.js → chunk-2EH4WRHL.js} +19 -11
- package/dist/chunk-2EH4WRHL.js.map +1 -0
- package/dist/{chunk-CUPM3FGB.js → chunk-2PRS4J5Q.js} +3 -3
- package/dist/chunk-6HMM2R5T.js +390 -0
- package/dist/chunk-6HMM2R5T.js.map +1 -0
- package/dist/{chunk-ZWREYEWA.js → chunk-AZHW7R5V.js} +56 -11
- package/dist/chunk-AZHW7R5V.js.map +1 -0
- package/dist/{chunk-LTG3S6ZY.js → chunk-E6CLMKEE.js} +2 -2
- package/dist/{chunk-6ZYKCRFO.js → chunk-KRLPEMLH.js} +7591 -4417
- package/dist/chunk-KRLPEMLH.js.map +1 -0
- package/dist/chunk-NAB6FKFN.js +516 -0
- package/dist/chunk-NAB6FKFN.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-UZNXG44K.js +4508 -0
- package/dist/chunk-UZNXG44K.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 +85 -0
- package/dist/connection-token-resolver.d.ts +30 -1
- package/dist/database.d.ts +23 -4
- 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 +1606 -81
- package/dist/index.js +21898 -8147
- 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 +29 -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 +43 -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 +268 -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 +28 -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/drizzle/0342_slack_route_prompt_single_pending.sql +32 -0
- package/drizzle/0343_personal_document_force_rls_lock_repair.sql +146 -0
- package/drizzle/0344_private_session_visibility_transition_gate.sql +85 -0
- package/drizzle/0345_tenant_scoped_session_tenancy_fence.sql +2839 -0
- package/drizzle/0346_document_migration_audit_surface.sql +454 -0
- package/drizzle/0347_connection_authority_convergence_evidence.sql +396 -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 +167 -0
- package/src/connection-token-resolver.ts +263 -31
- package/src/database.ts +87 -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 +11676 -1550
- 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 +995 -0
- package/src/pr-review.ts +890 -0
- package/src/preference-registry.ts +31 -1
- package/src/provision-roles.ts +905 -6
- package/src/runtime-posture-cli.ts +2 -0
- package/src/runtime-posture.ts +1317 -72
- package/src/schema.ts +3316 -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 +441 -85
- package/src/session-realtime-context.ts +4 -6
- package/src/session-realtime-ledger.ts +28 -14
- package/src/session-realtime-mirror.ts +1 -1
- package/src/session-tenancy.ts +410 -49
- package/src/session-tool-call-settlement.ts +38 -29
- package/src/slack-routing-personal-workspace.ts +67 -0
- package/src/slack-routing.ts +867 -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 +138 -11
- 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-CUPM3FGB.js.map → chunk-2PRS4J5Q.js.map} +0 -0
- /package/dist/{chunk-LTG3S6ZY.js.map → chunk-E6CLMKEE.js.map} +0 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import type { KnowledgeMemoryKind, HistoricalMemoryPromptMode } from "@opengeni/contracts";
|
|
2
|
+
import { sql } from "drizzle-orm";
|
|
3
|
+
import type { Database } from "./database";
|
|
4
|
+
import { rawRows, withRlsContext, withWorkspaceSubjectRls } from "./database";
|
|
5
|
+
import { fromPostgresLosslessText } from "./lossless-json";
|
|
6
|
+
import { selectWorkspaceMemoryBlockRecords, type MemoryBlockRecord } from "./memory-domain";
|
|
7
|
+
|
|
8
|
+
export type CompanyBrainContextAttemptClaims = Readonly<{
|
|
9
|
+
accountId: string;
|
|
10
|
+
workspaceId: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
turnId: string;
|
|
13
|
+
attemptId: string;
|
|
14
|
+
executionGeneration: number;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export type CompanyBrainMemorySelectionReference = Readonly<{
|
|
18
|
+
id: string;
|
|
19
|
+
kind: KnowledgeMemoryKind;
|
|
20
|
+
textHash: string;
|
|
21
|
+
contentHash: string;
|
|
22
|
+
textCodecVersion: number | null;
|
|
23
|
+
memoryVersion: number;
|
|
24
|
+
pinned: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
export type CompanyBrainContextSelectionReceipt = Readonly<{
|
|
28
|
+
id: string;
|
|
29
|
+
rootSessionId: string;
|
|
30
|
+
acceptedAt: string;
|
|
31
|
+
sessionRole: "root" | "child";
|
|
32
|
+
memoryEnabled: boolean;
|
|
33
|
+
memoryPromptMode: HistoricalMemoryPromptMode;
|
|
34
|
+
companyProfileIncluded: boolean;
|
|
35
|
+
instructionPolicyEntryHash: string;
|
|
36
|
+
preferenceDescriptorHash: string | null;
|
|
37
|
+
companyProfileSnapshotHash: string;
|
|
38
|
+
turnContextSnapshotId: string;
|
|
39
|
+
turnContextSnapshotHash: string;
|
|
40
|
+
turnContextSnapshotSource: "accepted_turn" | "legacy_first_claim";
|
|
41
|
+
legacyWorkspaceInstructionsOriginalUtf8Bytes: number | null;
|
|
42
|
+
legacyWorkspaceInstructionsTruncated: boolean;
|
|
43
|
+
selectionHash: string;
|
|
44
|
+
selectedMemoryCount: number;
|
|
45
|
+
renderedMemoryCount: number;
|
|
46
|
+
visibleMemoryCount: number;
|
|
47
|
+
budgetOmittedMemoryCount: number;
|
|
48
|
+
authorizationOmittedMemoryCount: number;
|
|
49
|
+
omittedMemoryCount: number;
|
|
50
|
+
}>;
|
|
51
|
+
|
|
52
|
+
export type ResolvedCompanyBrainContextSelection = Readonly<{
|
|
53
|
+
receipt: CompanyBrainContextSelectionReceipt;
|
|
54
|
+
legacyWorkspaceInstructions: string | null;
|
|
55
|
+
workspaceMemory: string | null;
|
|
56
|
+
}>;
|
|
57
|
+
|
|
58
|
+
export type CompanyBrainContextReceiptInspection = Readonly<{
|
|
59
|
+
id: string;
|
|
60
|
+
sessionId: string;
|
|
61
|
+
rootSessionId: string;
|
|
62
|
+
turnId: string;
|
|
63
|
+
acceptedAt: string;
|
|
64
|
+
createdAt: string;
|
|
65
|
+
sessionRole: "root" | "child";
|
|
66
|
+
memoryEnabled: boolean;
|
|
67
|
+
memoryPromptMode: HistoricalMemoryPromptMode;
|
|
68
|
+
companyProfileIncluded: boolean;
|
|
69
|
+
instructionPolicyEntryHash: string;
|
|
70
|
+
preferenceDescriptorHash: string | null;
|
|
71
|
+
companyProfileSnapshotHash: string;
|
|
72
|
+
turnContextSnapshotId: string;
|
|
73
|
+
turnContextSnapshotHash: string;
|
|
74
|
+
turnContextSnapshotSource: "accepted_turn" | "legacy_first_claim";
|
|
75
|
+
selectionHash: string;
|
|
76
|
+
selectedMemoryCount: number;
|
|
77
|
+
renderedMemoryCount: number;
|
|
78
|
+
budgetOmittedMemoryCount: number;
|
|
79
|
+
}>;
|
|
80
|
+
|
|
81
|
+
export type CompanyBrainContextReceiptInspectionCursor = Readonly<{
|
|
82
|
+
createdAt: string;
|
|
83
|
+
id: string;
|
|
84
|
+
}>;
|
|
85
|
+
|
|
86
|
+
export type InspectCompanyBrainContextReceiptsInput = Readonly<{
|
|
87
|
+
workspaceId: string;
|
|
88
|
+
subjectId: string;
|
|
89
|
+
attemptId?: string;
|
|
90
|
+
before?: CompanyBrainContextReceiptInspectionCursor;
|
|
91
|
+
limit?: number;
|
|
92
|
+
}>;
|
|
93
|
+
|
|
94
|
+
type SelectionRow = {
|
|
95
|
+
receipt_id: string;
|
|
96
|
+
root_session_id: string;
|
|
97
|
+
accepted_at: Date | string;
|
|
98
|
+
session_role: string;
|
|
99
|
+
memory_enabled: boolean;
|
|
100
|
+
memory_prompt_mode: string;
|
|
101
|
+
company_profile_included: boolean;
|
|
102
|
+
instruction_policy_entry_hash: string;
|
|
103
|
+
preference_descriptor_hash: string | null;
|
|
104
|
+
company_profile_snapshot_hash: string;
|
|
105
|
+
turn_context_snapshot_id: string;
|
|
106
|
+
turn_context_snapshot_hash: string;
|
|
107
|
+
turn_context_snapshot_source: string;
|
|
108
|
+
legacy_workspace_instructions: string | null;
|
|
109
|
+
legacy_workspace_instructions_original_utf8_bytes: number | null;
|
|
110
|
+
legacy_workspace_instructions_truncated: boolean;
|
|
111
|
+
selection_hash: string;
|
|
112
|
+
selected_memory_count: number;
|
|
113
|
+
rendered_memory_count: number;
|
|
114
|
+
visible_memory_count: number;
|
|
115
|
+
memory_id: string | null;
|
|
116
|
+
memory_kind: string | null;
|
|
117
|
+
memory_text: string | null;
|
|
118
|
+
memory_text_codec_version: number | null;
|
|
119
|
+
memory_pinned: boolean | null;
|
|
120
|
+
selection_ordinal: number | null;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type InspectionRow = {
|
|
124
|
+
receipt_id: string;
|
|
125
|
+
session_id: string;
|
|
126
|
+
root_session_id: string;
|
|
127
|
+
turn_id: string;
|
|
128
|
+
accepted_at: Date | string;
|
|
129
|
+
created_at: Date | string;
|
|
130
|
+
session_role: string;
|
|
131
|
+
memory_enabled: boolean;
|
|
132
|
+
memory_prompt_mode: string;
|
|
133
|
+
company_profile_included: boolean;
|
|
134
|
+
instruction_policy_entry_hash: string;
|
|
135
|
+
preference_descriptor_hash: string | null;
|
|
136
|
+
company_profile_snapshot_hash: string;
|
|
137
|
+
turn_context_snapshot_id: string;
|
|
138
|
+
turn_context_snapshot_hash: string;
|
|
139
|
+
turn_context_snapshot_source: string;
|
|
140
|
+
selection_hash: string;
|
|
141
|
+
selected_memory_count: number;
|
|
142
|
+
rendered_memory_count: number;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
function iso(value: Date | string): string {
|
|
146
|
+
return (value instanceof Date ? value : new Date(value)).toISOString();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function positiveGeneration(value: number): void {
|
|
150
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
151
|
+
throw new Error("Company Brain context selection requires a positive execution generation");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function inspectionLimit(value: number | undefined): number {
|
|
156
|
+
const resolved = value ?? 20;
|
|
157
|
+
if (!Number.isSafeInteger(resolved) || resolved < 1 || resolved > 51) {
|
|
158
|
+
throw new Error("Company Brain context receipt inspection limit must be between 1 and 51");
|
|
159
|
+
}
|
|
160
|
+
return resolved;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function inspectionReceipt(row: InspectionRow): CompanyBrainContextReceiptInspection {
|
|
164
|
+
if (row.session_role !== "root" && row.session_role !== "child") {
|
|
165
|
+
throw new Error("Company Brain receipt inspection returned an invalid session role");
|
|
166
|
+
}
|
|
167
|
+
if (row.memory_prompt_mode !== "legacy_standing" && row.memory_prompt_mode !== "retrieval_only") {
|
|
168
|
+
throw new Error("Company Brain receipt inspection returned an invalid memory prompt mode");
|
|
169
|
+
}
|
|
170
|
+
if (
|
|
171
|
+
row.turn_context_snapshot_source !== "accepted_turn" &&
|
|
172
|
+
row.turn_context_snapshot_source !== "legacy_first_claim"
|
|
173
|
+
) {
|
|
174
|
+
throw new Error("Company Brain receipt inspection returned an invalid snapshot source");
|
|
175
|
+
}
|
|
176
|
+
if (
|
|
177
|
+
!Number.isSafeInteger(row.selected_memory_count) ||
|
|
178
|
+
row.selected_memory_count < 0 ||
|
|
179
|
+
!Number.isSafeInteger(row.rendered_memory_count) ||
|
|
180
|
+
row.rendered_memory_count < 0 ||
|
|
181
|
+
row.rendered_memory_count > row.selected_memory_count
|
|
182
|
+
) {
|
|
183
|
+
throw new Error("Company Brain receipt inspection returned invalid selection counts");
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
id: row.receipt_id,
|
|
187
|
+
sessionId: row.session_id,
|
|
188
|
+
rootSessionId: row.root_session_id,
|
|
189
|
+
turnId: row.turn_id,
|
|
190
|
+
acceptedAt: iso(row.accepted_at),
|
|
191
|
+
createdAt: iso(row.created_at),
|
|
192
|
+
sessionRole: row.session_role,
|
|
193
|
+
memoryEnabled: row.memory_enabled,
|
|
194
|
+
memoryPromptMode: row.memory_prompt_mode,
|
|
195
|
+
companyProfileIncluded: row.company_profile_included,
|
|
196
|
+
instructionPolicyEntryHash: row.instruction_policy_entry_hash,
|
|
197
|
+
preferenceDescriptorHash: row.preference_descriptor_hash,
|
|
198
|
+
companyProfileSnapshotHash: row.company_profile_snapshot_hash,
|
|
199
|
+
turnContextSnapshotId: row.turn_context_snapshot_id,
|
|
200
|
+
turnContextSnapshotHash: row.turn_context_snapshot_hash,
|
|
201
|
+
turnContextSnapshotSource: row.turn_context_snapshot_source,
|
|
202
|
+
selectionHash: row.selection_hash,
|
|
203
|
+
selectedMemoryCount: row.selected_memory_count,
|
|
204
|
+
renderedMemoryCount: row.rendered_memory_count,
|
|
205
|
+
budgetOmittedMemoryCount: row.selected_memory_count - row.rendered_memory_count,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Read a bounded, content-free projection of existing accepted-turn receipts.
|
|
211
|
+
* The SQL capability independently proves the exact human and both session
|
|
212
|
+
* references; this adapter never calls the receipt-creating worker function.
|
|
213
|
+
*/
|
|
214
|
+
export async function inspectCompanyBrainContextReceipts(
|
|
215
|
+
db: Database,
|
|
216
|
+
input: InspectCompanyBrainContextReceiptsInput,
|
|
217
|
+
): Promise<readonly CompanyBrainContextReceiptInspection[]> {
|
|
218
|
+
const limit = inspectionLimit(input.limit);
|
|
219
|
+
return await withWorkspaceSubjectRls(db, input.workspaceId, input.subjectId, async (tx) => {
|
|
220
|
+
const rows = await rawRows<InspectionRow>(
|
|
221
|
+
tx,
|
|
222
|
+
sql`SELECT * FROM company_brain_inspect_context_receipts(
|
|
223
|
+
current_setting('opengeni.account_id')::uuid,
|
|
224
|
+
${input.workspaceId}::uuid,
|
|
225
|
+
${input.subjectId}::text,
|
|
226
|
+
${input.attemptId ?? null}::uuid,
|
|
227
|
+
${input.before?.createdAt ?? null}::timestamptz,
|
|
228
|
+
${input.before?.id ?? null}::uuid,
|
|
229
|
+
${limit}::integer
|
|
230
|
+
)`,
|
|
231
|
+
);
|
|
232
|
+
return rows.map(inspectionReceipt);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Freeze the broad legacy workspace-Memory candidate set once per accepted
|
|
238
|
+
* logical turn. Recovery gets the original candidate identities and may only
|
|
239
|
+
* lose rows that no longer pass current lifecycle/hash authorization. The
|
|
240
|
+
* durable receipt contains references and hashes, never memory text.
|
|
241
|
+
*/
|
|
242
|
+
export async function resolveCompanyBrainContextSelection(
|
|
243
|
+
db: Database,
|
|
244
|
+
claims: CompanyBrainContextAttemptClaims,
|
|
245
|
+
): Promise<ResolvedCompanyBrainContextSelection> {
|
|
246
|
+
positiveGeneration(claims.executionGeneration);
|
|
247
|
+
const rows = await withRlsContext(
|
|
248
|
+
db,
|
|
249
|
+
{ accountId: claims.accountId, workspaceId: claims.workspaceId },
|
|
250
|
+
async (tx) =>
|
|
251
|
+
await rawRows<SelectionRow>(
|
|
252
|
+
tx,
|
|
253
|
+
sql`SELECT * FROM company_brain_context_get_or_create_selection(
|
|
254
|
+
${claims.accountId}::uuid,
|
|
255
|
+
${claims.workspaceId}::uuid,
|
|
256
|
+
${claims.sessionId}::uuid,
|
|
257
|
+
${claims.turnId}::uuid,
|
|
258
|
+
${claims.attemptId}::uuid,
|
|
259
|
+
${claims.executionGeneration}::integer
|
|
260
|
+
)`,
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
const first = rows[0];
|
|
264
|
+
if (!first) throw new Error("Company Brain context selection returned no durable receipt");
|
|
265
|
+
if (!Number.isSafeInteger(first.selected_memory_count) || first.selected_memory_count < 0) {
|
|
266
|
+
throw new Error("Company Brain context selection returned an invalid selected count");
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
!Number.isSafeInteger(first.rendered_memory_count) ||
|
|
270
|
+
first.rendered_memory_count < 0 ||
|
|
271
|
+
first.rendered_memory_count > first.selected_memory_count
|
|
272
|
+
) {
|
|
273
|
+
throw new Error("Company Brain context selection returned an invalid rendered count");
|
|
274
|
+
}
|
|
275
|
+
if (
|
|
276
|
+
!Number.isSafeInteger(first.visible_memory_count) ||
|
|
277
|
+
first.visible_memory_count < 0 ||
|
|
278
|
+
first.visible_memory_count > first.rendered_memory_count
|
|
279
|
+
) {
|
|
280
|
+
throw new Error("Company Brain context selection returned an invalid visible count");
|
|
281
|
+
}
|
|
282
|
+
if (first.session_role !== "root" && first.session_role !== "child") {
|
|
283
|
+
throw new Error("Company Brain context selection returned an invalid session role");
|
|
284
|
+
}
|
|
285
|
+
if (
|
|
286
|
+
first.memory_prompt_mode !== "legacy_standing" &&
|
|
287
|
+
first.memory_prompt_mode !== "retrieval_only"
|
|
288
|
+
) {
|
|
289
|
+
throw new Error("Company Brain context selection returned an invalid memory prompt mode");
|
|
290
|
+
}
|
|
291
|
+
if (
|
|
292
|
+
first.turn_context_snapshot_source !== "accepted_turn" &&
|
|
293
|
+
first.turn_context_snapshot_source !== "legacy_first_claim"
|
|
294
|
+
) {
|
|
295
|
+
throw new Error("Company Brain context selection returned an invalid turn snapshot source");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const memoryRecords: MemoryBlockRecord[] = rows.flatMap((row) => {
|
|
299
|
+
if (
|
|
300
|
+
row.memory_id === null ||
|
|
301
|
+
row.memory_kind === null ||
|
|
302
|
+
row.memory_text === null ||
|
|
303
|
+
row.memory_pinned === null ||
|
|
304
|
+
row.selection_ordinal === null
|
|
305
|
+
) {
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
return [
|
|
309
|
+
{
|
|
310
|
+
id: row.memory_id,
|
|
311
|
+
kind: row.memory_kind as KnowledgeMemoryKind,
|
|
312
|
+
text: fromPostgresLosslessText(row.memory_text, row.memory_text_codec_version),
|
|
313
|
+
pinned: row.memory_pinned,
|
|
314
|
+
},
|
|
315
|
+
];
|
|
316
|
+
});
|
|
317
|
+
if (memoryRecords.length !== first.visible_memory_count) {
|
|
318
|
+
throw new Error("Company Brain context selection returned an incomplete visible projection");
|
|
319
|
+
}
|
|
320
|
+
if (selectWorkspaceMemoryBlockRecords(memoryRecords).length !== memoryRecords.length) {
|
|
321
|
+
throw new Error("Company Brain context selection exceeded its frozen prompt budget");
|
|
322
|
+
}
|
|
323
|
+
// Memory V1's standing block is retired. Retrieval-only composition is the
|
|
324
|
+
// only mode, so nothing is injected into the prompt: an agent reads the
|
|
325
|
+
// workspace's records through `memory_search` when it needs them, rather
|
|
326
|
+
// than receiving them unbidden on every turn. Historical receipts keep the
|
|
327
|
+
// mode they recorded; this is about what gets composed now.
|
|
328
|
+
const workspaceMemory = null;
|
|
329
|
+
|
|
330
|
+
return {
|
|
331
|
+
receipt: {
|
|
332
|
+
id: first.receipt_id,
|
|
333
|
+
rootSessionId: first.root_session_id,
|
|
334
|
+
acceptedAt: iso(first.accepted_at),
|
|
335
|
+
sessionRole: first.session_role,
|
|
336
|
+
memoryEnabled: first.memory_enabled,
|
|
337
|
+
memoryPromptMode: first.memory_prompt_mode,
|
|
338
|
+
companyProfileIncluded: first.company_profile_included,
|
|
339
|
+
instructionPolicyEntryHash: first.instruction_policy_entry_hash,
|
|
340
|
+
preferenceDescriptorHash: first.preference_descriptor_hash,
|
|
341
|
+
companyProfileSnapshotHash: first.company_profile_snapshot_hash,
|
|
342
|
+
turnContextSnapshotId: first.turn_context_snapshot_id,
|
|
343
|
+
turnContextSnapshotHash: first.turn_context_snapshot_hash,
|
|
344
|
+
turnContextSnapshotSource: first.turn_context_snapshot_source,
|
|
345
|
+
legacyWorkspaceInstructionsOriginalUtf8Bytes:
|
|
346
|
+
first.legacy_workspace_instructions_original_utf8_bytes,
|
|
347
|
+
legacyWorkspaceInstructionsTruncated: first.legacy_workspace_instructions_truncated,
|
|
348
|
+
selectionHash: first.selection_hash,
|
|
349
|
+
selectedMemoryCount: first.selected_memory_count,
|
|
350
|
+
renderedMemoryCount: first.rendered_memory_count,
|
|
351
|
+
visibleMemoryCount: first.visible_memory_count,
|
|
352
|
+
budgetOmittedMemoryCount: first.selected_memory_count - first.rendered_memory_count,
|
|
353
|
+
authorizationOmittedMemoryCount: first.rendered_memory_count - first.visible_memory_count,
|
|
354
|
+
omittedMemoryCount: first.selected_memory_count - first.visible_memory_count,
|
|
355
|
+
},
|
|
356
|
+
legacyWorkspaceInstructions: first.legacy_workspace_instructions,
|
|
357
|
+
workspaceMemory,
|
|
358
|
+
};
|
|
359
|
+
}
|