ltcai 11.5.2 → 11.6.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/README.md +91 -148
- package/bin/ltcai.js +234 -24
- package/docs/CHANGELOG.md +75 -0
- package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
- package/docs/DEVELOPMENT.md +8 -6
- package/docs/ENTERPRISE.md +2 -1
- package/docs/MULTI_AGENT_RUNTIME.md +12 -5
- package/docs/ONBOARDING.md +1 -1
- package/docs/OPERATIONS.md +6 -3
- package/docs/REALTIME_COLLABORATION.md +1 -1
- package/docs/TRUST_MODEL.md +1 -1
- package/docs/WHY_LATTICE.md +1 -1
- package/docs/WORKFLOW_DESIGNER.md +3 -2
- package/docs/kg-schema.md +1 -1
- package/docs/v11.6.0_ONE_DOOR_PLAN.md +170 -0
- package/lattice_brain/__init__.py +42 -79
- package/lattice_brain/graph/__init__.py +9 -24
- package/lattice_brain/graph/_kg_common/__init__.py +13 -24
- package/lattice_brain/ingestion/__init__.py +19 -58
- package/lattice_brain/ingestion/pipeline.py +20 -398
- package/lattice_brain/multimodal/__init__.py +7 -18
- package/lattice_brain/multimodal/images.py +6 -264
- package/lattice_brain/multimodal/video.py +8 -247
- package/lattice_brain/runtime/__init__.py +8 -79
- package/lattice_brain/runtime/hooks.py +22 -584
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/agent_worker_seam.py +7 -80
- package/latticeai/api/health.py +6 -20
- package/latticeai/api/local_files.py +16 -613
- package/latticeai/api/models.py +12 -87
- package/latticeai/api/search.py +17 -255
- package/latticeai/api/tools.py +69 -750
- package/latticeai/api/voice_capture.py +8 -70
- package/latticeai/api/worker_compute.py +842 -0
- package/latticeai/api/worker_seams.py +216 -0
- package/latticeai/app_factory.py +23 -232
- package/latticeai/cli/entrypoint.py +36 -249
- package/latticeai/core/agent_permission.py +16 -91
- package/latticeai/core/messages.py +89 -531
- package/latticeai/runtime/access_runtime.py +0 -14
- package/latticeai/runtime/bootstrap.py +10 -21
- package/latticeai/runtime/brain_runtime.py +35 -43
- package/latticeai/runtime/build_phases/__init__.py +21 -37
- package/latticeai/runtime/build_phases/features.py +99 -389
- package/latticeai/runtime/build_phases/foundation.py +82 -392
- package/latticeai/runtime/build_phases/web.py +91 -408
- package/latticeai/runtime/build_phases/worker_profile.py +244 -0
- package/latticeai/runtime/lifespan_runtime.py +7 -16
- package/latticeai/runtime/platform_services_runtime.py +1 -15
- package/latticeai/runtime/runtime_context.py +13 -130
- package/latticeai/runtime/security_runtime.py +10 -103
- package/latticeai/services/architecture_readiness.py +82 -43
- package/latticeai/services/model_runtime/__init__.py +2 -11
- package/latticeai/services/model_runtime/service.py +4 -28
- package/latticeai/services/p_reinforce.py +10 -261
- package/latticeai/services/product_readiness.py +31 -38
- package/latticeai/services/search_service.py +37 -795
- package/latticeai/services/tool_dispatch.py +30 -386
- package/latticeai/services/voice_capture.py +13 -107
- package/latticeai/tools/__init__.py +22 -49
- package/latticeai/tools/commands.py +0 -163
- package/latticeai/tools/computer.py +0 -39
- package/latticeai/tools/documents.py +1 -134
- package/latticeai/tools/filesystem.py +1 -247
- package/latticeai/tools/knowledge.py +1 -52
- package/latticeai/tools/local_files.py +0 -20
- package/latticeai/worker_app.py +75 -0
- package/package.json +2 -3
- package/requirements.txt +0 -5
- package/scripts/agent_eval.py +16 -28
- package/scripts/brain_quality_eval.py +20 -183
- package/scripts/bump_version.py +5 -5
- package/scripts/check_current_release_docs.mjs +7 -4
- package/scripts/check_openapi_drift.mjs +10 -0
- package/scripts/check_server_i18n.mjs +2 -18
- package/scripts/compose_openapi.py +377 -0
- package/scripts/export_openapi.py +32 -4
- package/scripts/gen_messages_catalog_fixture.py +302 -0
- package/scripts/gen_openapi_fragments.py +365 -0
- package/scripts/gen_redact_fixture.py +196 -0
- package/scripts/gen_worker_allowlist_fixture.py +115 -0
- package/scripts/generate_agent_parity_fixtures.py +33 -14
- package/scripts/openapi_route_families.json +2161 -0
- package/scripts/release_screen_claims.json +21 -0
- package/scripts/run_integration_tests.mjs +134 -29
- package/scripts/run_sidecar_e2e.mjs +104 -11
- package/scripts/wheel_smoke.py +32 -22
- package/src-tauri/Cargo.lock +375 -9
- package/src-tauri/Cargo.toml +1 -1
- package/src-tauri/src/backend.rs +151 -45
- package/src-tauri/src/main.rs +18 -18
- package/src-tauri/src/topology.rs +58 -88
- package/src-tauri/tauri.conf.json +1 -2
- package/static/app/asset-manifest.json +41 -41
- package/static/app/assets/{Act-DcQizkl1.js → Act-CToZnOHz.js} +1 -1
- package/static/app/assets/{AdminConsole-cf4npybT.js → AdminConsole-D5kbrBu8.js} +1 -1
- package/static/app/assets/{Brain-3VCSHFcn.js → Brain-C6zCdv4S.js} +1 -1
- package/static/app/assets/{BrainHome-Qm8eaztx.js → BrainHome-D4n3EDUt.js} +1 -1
- package/static/app/assets/{BrainSignals-DS9BtKOW.js → BrainSignals-CzeZ-vQ9.js} +1 -1
- package/static/app/assets/{Capture-DiQ219jW.js → Capture-DPcyTczq.js} +1 -1
- package/static/app/assets/{Chronicle-BGvuAchH.js → Chronicle-D3Nx-oWS.js} +1 -1
- package/static/app/assets/{CommandPalette-Bqhm0Urn.js → CommandPalette-DPPvpp28.js} +1 -1
- package/static/app/assets/{Library-BV6NnF0a.js → Library-Co2qTu3I.js} +1 -1
- package/static/app/assets/{LivingBrain-GzenJchP.js → LivingBrain-Bsmzwy8_.js} +1 -1
- package/static/app/assets/{ProductFlow-DEP6-vML.js → ProductFlow-CBLdmesT.js} +1 -1
- package/static/app/assets/{ReviewCard-CNZ7XjWG.js → ReviewCard-CfR6DLs7.js} +1 -1
- package/static/app/assets/{System-CieofHQa.js → System-Ce-P2YL6.js} +1 -1
- package/static/app/assets/arrow-left-DD5jFGHV.js +1 -0
- package/static/app/assets/{bot-B_K1Tdmw.js → bot-C5-XIww2.js} +1 -1
- package/static/app/assets/{brain-DWyaV1L1.js → brain-CFRJUvdX.js} +1 -1
- package/static/app/assets/{button-aTn4s84A.js → button-DI1KcQP-.js} +1 -1
- package/static/app/assets/circle-check-CY20XMCh.js +1 -0
- package/static/app/assets/{circle-pause-xKgeGXkT.js → circle-pause-C8HHyood.js} +1 -1
- package/static/app/assets/{circle-play-DkT6tYPX.js → circle-play-Cufc235E.js} +1 -1
- package/static/app/assets/{cpu-85xYObUC.js → cpu-DW2_JVsv.js} +1 -1
- package/static/app/assets/{download-B5Fm7YXo.js → download-gbdKTBb8.js} +1 -1
- package/static/app/assets/{folder-open-kk2Xa52u.js → folder-open-C9ydyX33.js} +1 -1
- package/static/app/assets/{hard-drive-DkA3zBW_.js → hard-drive-BxNMzBM3.js} +1 -1
- package/static/app/assets/index-BovSWRmQ.css +2 -0
- package/static/app/assets/{index-BMPdTmlY.js → index-q9XyDY7A.js} +3 -3
- package/static/app/assets/{input-B0nRf2jO.js → input-GLD94Y_K.js} +1 -1
- package/static/app/assets/{link-2-Dwb4gnTc.js → link-2-B4Y0gz1S.js} +1 -1
- package/static/app/assets/{permissionCopy-CQDUBrOZ.js → permissionCopy-CxrV0fvU.js} +1 -1
- package/static/app/assets/{primitives-SNp0LRJz.js → primitives-2ANdAsu2.js} +1 -1
- package/static/app/assets/search-DTxtjQ07.js +1 -0
- package/static/app/assets/{share-2-BsrxFglO.js → share-2-DxArfiuI.js} +1 -1
- package/static/app/assets/{shield-alert-5BStfp2_.js → shield-alert-CgftuFFs.js} +1 -1
- package/static/app/assets/{textarea-Cg8IUA-k.js → textarea-BHVBAoCr.js} +1 -1
- package/static/app/assets/{useFocusTrap-CYKvE46M.js → useFocusTrap-Dzq2j_OG.js} +1 -1
- package/static/app/assets/{useMutation-CSn9t1op.js → useMutation-BcqfMLNq.js} +1 -1
- package/static/app/assets/{useQuery-CY2OI2uy.js → useQuery-DBzLKCOv.js} +1 -1
- package/static/app/assets/{utils-Ddol2RWD.js → utils-B-Aah1bO.js} +1 -1
- package/static/app/assets/{workspace-BqDwOz_p.js → workspace-B6fFhoko.js} +1 -1
- package/static/app/index.html +4 -4
- package/static/sw.js +1 -1
- package/lattice_brain/archive.py +0 -522
- package/lattice_brain/context.py +0 -325
- package/lattice_brain/conversations.py +0 -382
- package/lattice_brain/core.py +0 -82
- package/lattice_brain/graph/_kg_contract.py +0 -249
- package/lattice_brain/graph/curator.py +0 -676
- package/lattice_brain/graph/discovery.py +0 -595
- package/lattice_brain/graph/discovery_index/__init__.py +0 -35
- package/lattice_brain/graph/discovery_index/cleanup.py +0 -182
- package/lattice_brain/graph/discovery_index/extract.py +0 -137
- package/lattice_brain/graph/discovery_index/scan.py +0 -411
- package/lattice_brain/graph/discovery_index/upsert.py +0 -495
- package/lattice_brain/graph/documents.py +0 -380
- package/lattice_brain/graph/fusion.py +0 -395
- package/lattice_brain/graph/identity.py +0 -175
- package/lattice_brain/graph/image_vectors.py +0 -230
- package/lattice_brain/graph/ingest.py +0 -829
- package/lattice_brain/graph/network.py +0 -205
- package/lattice_brain/graph/proactive.py +0 -724
- package/lattice_brain/graph/projection/__init__.py +0 -42
- package/lattice_brain/graph/projection/curation.py +0 -500
- package/lattice_brain/graph/projection/v2_schema.py +0 -518
- package/lattice_brain/graph/provenance.py +0 -524
- package/lattice_brain/graph/rerank.py +0 -163
- package/lattice_brain/graph/retrieval/__init__.py +0 -54
- package/lattice_brain/graph/retrieval/context.py +0 -197
- package/lattice_brain/graph/retrieval/graph_view.py +0 -319
- package/lattice_brain/graph/retrieval/hybrid.py +0 -488
- package/lattice_brain/graph/retrieval/maintenance.py +0 -121
- package/lattice_brain/graph/retrieval/signals.py +0 -95
- package/lattice_brain/graph/retrieval_docgen.py +0 -253
- package/lattice_brain/graph/retrieval_policy.py +0 -180
- package/lattice_brain/graph/retrieval_reads.py +0 -769
- package/lattice_brain/graph/retrieval_vector/__init__.py +0 -42
- package/lattice_brain/graph/retrieval_vector/fingerprint.py +0 -97
- package/lattice_brain/graph/retrieval_vector/indexing.py +0 -347
- package/lattice_brain/graph/retrieval_vector/search.py +0 -560
- package/lattice_brain/graph/retrieval_vector/status.py +0 -374
- package/lattice_brain/graph/schema.py +0 -792
- package/lattice_brain/graph/store.py +0 -268
- package/lattice_brain/graph/vector_index/__init__.py +0 -85
- package/lattice_brain/graph/vector_index/base.py +0 -167
- package/lattice_brain/graph/vector_index/brute_force.py +0 -110
- package/lattice_brain/graph/vector_index/hnsw.py +0 -290
- package/lattice_brain/graph/vector_index/jobs.py +0 -287
- package/lattice_brain/graph/vector_index/quantized.py +0 -148
- package/lattice_brain/graph/vector_index/selector.py +0 -161
- package/lattice_brain/graph/write_master.py +0 -308
- package/lattice_brain/ingestion/_contract.py +0 -90
- package/lattice_brain/ingestion/folder_scan.py +0 -57
- package/lattice_brain/ingestion/folders.py +0 -258
- package/lattice_brain/ingestion/jobs_api.py +0 -107
- package/lattice_brain/ingestion/routing.py +0 -295
- package/lattice_brain/ingestion_jobs.py +0 -380
- package/lattice_brain/memory.py +0 -75
- package/lattice_brain/portability/__init__.py +0 -90
- package/lattice_brain/portability/_contract.py +0 -42
- package/lattice_brain/portability/backups.py +0 -338
- package/lattice_brain/portability/bundles.py +0 -136
- package/lattice_brain/portability/constants.py +0 -93
- package/lattice_brain/portability/fsops.py +0 -138
- package/lattice_brain/portability/service.py +0 -41
- package/lattice_brain/portability/sharing.py +0 -710
- package/lattice_brain/quality.py +0 -543
- package/lattice_brain/retrieval_benchmark_fixtures.py +0 -92
- package/lattice_brain/runtime/agent_runtime.py +0 -859
- package/lattice_brain/runtime/contracts.py +0 -460
- package/lattice_brain/runtime/multi_agent.py +0 -942
- package/lattice_brain/runtime/statuses.py +0 -10
- package/lattice_brain/sealed_box.py +0 -240
- package/lattice_brain/self_model.py +0 -675
- package/lattice_brain/sensitivity.py +0 -94
- package/lattice_brain/storage/__init__.py +0 -22
- package/lattice_brain/storage/base.py +0 -100
- package/lattice_brain/storage/docker.py +0 -105
- package/lattice_brain/storage/factory.py +0 -31
- package/lattice_brain/storage/migration.py +0 -191
- package/lattice_brain/storage/postgres.py +0 -123
- package/lattice_brain/storage/sqlite.py +0 -143
- package/lattice_brain/synthesis.py +0 -824
- package/lattice_brain/workflow.py +0 -497
- package/latticeai/api/admin.py +0 -471
- package/latticeai/api/agent_registry.py +0 -105
- package/latticeai/api/agents.py +0 -228
- package/latticeai/api/auth.py +0 -383
- package/latticeai/api/automation_intelligence.py +0 -401
- package/latticeai/api/brain_intelligence.py +0 -199
- package/latticeai/api/browser.py +0 -493
- package/latticeai/api/change_proposals.py +0 -89
- package/latticeai/api/chat.py +0 -572
- package/latticeai/api/chat_agent_http.py +0 -892
- package/latticeai/api/chat_contracts.py +0 -73
- package/latticeai/api/chat_documents.py +0 -276
- package/latticeai/api/chat_helpers.py +0 -460
- package/latticeai/api/chat_history.py +0 -101
- package/latticeai/api/chat_hybrid.py +0 -113
- package/latticeai/api/chat_intents.py +0 -646
- package/latticeai/api/chat_stream.py +0 -216
- package/latticeai/api/chronicle.py +0 -63
- package/latticeai/api/command_center.py +0 -51
- package/latticeai/api/computer_use.py +0 -474
- package/latticeai/api/evidence_actions.py +0 -48
- package/latticeai/api/features.py +0 -70
- package/latticeai/api/funnel_metrics.py +0 -31
- package/latticeai/api/garden.py +0 -34
- package/latticeai/api/hooks.py +0 -165
- package/latticeai/api/index_jobs.py +0 -145
- package/latticeai/api/invitations.py +0 -100
- package/latticeai/api/knowledge_graph.py +0 -536
- package/latticeai/api/marketplace.py +0 -105
- package/latticeai/api/mcp.py +0 -482
- package/latticeai/api/memory.py +0 -270
- package/latticeai/api/network.py +0 -81
- package/latticeai/api/network_boundary.py +0 -225
- package/latticeai/api/permission_mode.py +0 -61
- package/latticeai/api/permissions.py +0 -436
- package/latticeai/api/plugins.py +0 -126
- package/latticeai/api/portability.py +0 -391
- package/latticeai/api/project_sessions.py +0 -114
- package/latticeai/api/realtime.py +0 -118
- package/latticeai/api/review_queue.py +0 -364
- package/latticeai/api/security_dashboard.py +0 -604
- package/latticeai/api/setup.py +0 -319
- package/latticeai/api/static_routes.py +0 -354
- package/latticeai/api/ui_redirects.py +0 -26
- package/latticeai/api/workflow_designer.py +0 -394
- package/latticeai/api/workspace.py +0 -856
- package/latticeai/api/workspace_scope.py +0 -125
- package/latticeai/core/agent/__init__.py +0 -93
- package/latticeai/core/agent/_contract.py +0 -79
- package/latticeai/core/agent/context.py +0 -57
- package/latticeai/core/agent/deps.py +0 -125
- package/latticeai/core/agent/execution.py +0 -622
- package/latticeai/core/agent/planning.py +0 -145
- package/latticeai/core/agent/recovery.py +0 -157
- package/latticeai/core/agent/runtime.py +0 -210
- package/latticeai/core/agent/verification.py +0 -231
- package/latticeai/core/agent_eval.py +0 -739
- package/latticeai/core/agent_helpers.py +0 -493
- package/latticeai/core/agent_profiles.py +0 -110
- package/latticeai/core/agent_prompts.py +0 -171
- package/latticeai/core/agent_registry.py +0 -232
- package/latticeai/core/agent_state.py +0 -41
- package/latticeai/core/agent_trace.py +0 -104
- package/latticeai/core/artifact_ledger.py +0 -109
- package/latticeai/core/audit.py +0 -260
- package/latticeai/core/builtin_hooks.py +0 -105
- package/latticeai/core/context_builder.py +0 -394
- package/latticeai/core/document_generator.py +0 -103
- package/latticeai/core/enterprise.py +0 -154
- package/latticeai/core/enterprise_admin.py +0 -158
- package/latticeai/core/file_generation/__init__.py +0 -115
- package/latticeai/core/file_generation/bundles.py +0 -76
- package/latticeai/core/file_generation/extraction.py +0 -154
- package/latticeai/core/file_generation/inference.py +0 -235
- package/latticeai/core/file_generation/orchestration.py +0 -152
- package/latticeai/core/file_generation/prompting.py +0 -117
- package/latticeai/core/file_generation/repair.py +0 -114
- package/latticeai/core/file_generation/sanitize.py +0 -61
- package/latticeai/core/file_generation/validation.py +0 -201
- package/latticeai/core/invitations.py +0 -132
- package/latticeai/core/legacy_compatibility.py +0 -243
- package/latticeai/core/logging_safety.py +0 -46
- package/latticeai/core/marketplace.py +0 -293
- package/latticeai/core/mcp_catalog.py +0 -452
- package/latticeai/core/mcp_registry.py +0 -506
- package/latticeai/core/network_boundary.py +0 -168
- package/latticeai/core/oidc.py +0 -208
- package/latticeai/core/plugins.py +0 -432
- package/latticeai/core/product_hardening.py +0 -218
- package/latticeai/core/project_sessions.py +0 -337
- package/latticeai/core/realtime.py +0 -238
- package/latticeai/core/run_explain.py +0 -426
- package/latticeai/core/run_store.py +0 -252
- package/latticeai/core/timezones.py +0 -80
- package/latticeai/core/workspace_computer_memory.py +0 -84
- package/latticeai/core/workspace_graph_trace.py +0 -155
- package/latticeai/core/workspace_indexing.py +0 -102
- package/latticeai/core/workspace_memory.py +0 -77
- package/latticeai/core/workspace_onboarding.py +0 -104
- package/latticeai/core/workspace_os.py +0 -978
- package/latticeai/core/workspace_os_constants.py +0 -126
- package/latticeai/core/workspace_os_state.py +0 -180
- package/latticeai/core/workspace_os_utils.py +0 -103
- package/latticeai/core/workspace_permissions.py +0 -101
- package/latticeai/core/workspace_plugins.py +0 -97
- package/latticeai/core/workspace_relationships.py +0 -99
- package/latticeai/core/workspace_reorganization.py +0 -335
- package/latticeai/core/workspace_review_items.py +0 -112
- package/latticeai/core/workspace_runs.py +0 -726
- package/latticeai/core/workspace_skills.py +0 -109
- package/latticeai/core/workspace_snapshots.py +0 -198
- package/latticeai/core/workspace_timeline.py +0 -110
- package/latticeai/integrations/__init__.py +0 -0
- package/latticeai/integrations/telegram_bot/__init__.py +0 -123
- package/latticeai/integrations/telegram_bot/__main__.py +0 -17
- package/latticeai/integrations/telegram_bot/config.py +0 -86
- package/latticeai/integrations/telegram_bot/dispatch.py +0 -311
- package/latticeai/integrations/telegram_bot/flows.py +0 -478
- package/latticeai/integrations/telegram_bot/helpers.py +0 -322
- package/latticeai/integrations/telegram_bot/screens.py +0 -394
- package/latticeai/runtime/audit_runtime.py +0 -76
- package/latticeai/runtime/automation_runtime.py +0 -81
- package/latticeai/runtime/chat_wiring.py +0 -141
- package/latticeai/runtime/context_runtime.py +0 -66
- package/latticeai/runtime/feature_toggle_wiring.py +0 -157
- package/latticeai/runtime/history_runtime.py +0 -163
- package/latticeai/runtime/history_writer.py +0 -138
- package/latticeai/runtime/hooks_runtime.py +0 -77
- package/latticeai/runtime/model_wiring.py +0 -68
- package/latticeai/runtime/namespace_runtime.py +0 -163
- package/latticeai/runtime/network_boundary_wiring.py +0 -117
- package/latticeai/runtime/network_config_runtime.py +0 -56
- package/latticeai/runtime/permission_mode_wiring.py +0 -112
- package/latticeai/runtime/persistence_runtime.py +0 -159
- package/latticeai/runtime/platform_runtime_wiring.py +0 -89
- package/latticeai/runtime/review_wiring.py +0 -42
- package/latticeai/runtime/router_registration.py +0 -693
- package/latticeai/runtime/service_singletons.py +0 -55
- package/latticeai/runtime/sso_config_runtime.py +0 -128
- package/latticeai/runtime/user_key_runtime.py +0 -106
- package/latticeai/runtime/web_runtime.py +0 -92
- package/latticeai/server_app.py +0 -51
- package/latticeai/services/app_context.py +0 -130
- package/latticeai/services/automation_execution.py +0 -266
- package/latticeai/services/automation_intelligence.py +0 -614
- package/latticeai/services/brain_automation.py +0 -191
- package/latticeai/services/brain_intelligence/__init__.py +0 -58
- package/latticeai/services/brain_intelligence/_contract.py +0 -71
- package/latticeai/services/brain_intelligence/consistency.py +0 -193
- package/latticeai/services/brain_intelligence/constants.py +0 -47
- package/latticeai/services/brain_intelligence/digest.py +0 -258
- package/latticeai/services/brain_intelligence/health.py +0 -331
- package/latticeai/services/brain_intelligence/proposals.py +0 -259
- package/latticeai/services/brain_intelligence/sampling.py +0 -84
- package/latticeai/services/brain_intelligence/service.py +0 -48
- package/latticeai/services/change_proposals.py +0 -471
- package/latticeai/services/chat_service.py +0 -243
- package/latticeai/services/chronicle.py +0 -555
- package/latticeai/services/cloud_egress_audit.py +0 -85
- package/latticeai/services/cloud_extraction.py +0 -129
- package/latticeai/services/cloud_streaming.py +0 -268
- package/latticeai/services/cloud_token_guard.py +0 -84
- package/latticeai/services/command_center.py +0 -548
- package/latticeai/services/evidence_actions.py +0 -258
- package/latticeai/services/feature_toggles.py +0 -502
- package/latticeai/services/folder_watch.py +0 -520
- package/latticeai/services/funnel_metrics.py +0 -307
- package/latticeai/services/hybrid_chat.py +0 -316
- package/latticeai/services/hybrid_context.py +0 -228
- package/latticeai/services/hybrid_policy.py +0 -129
- package/latticeai/services/interop_bridges.py +0 -978
- package/latticeai/services/local_knowledge.py +0 -465
- package/latticeai/services/memory_service/__init__.py +0 -52
- package/latticeai/services/memory_service/_contract.py +0 -100
- package/latticeai/services/memory_service/brief.py +0 -431
- package/latticeai/services/memory_service/constants.py +0 -57
- package/latticeai/services/memory_service/maintenance.py +0 -138
- package/latticeai/services/memory_service/manager.py +0 -186
- package/latticeai/services/memory_service/proof.py +0 -136
- package/latticeai/services/memory_service/recall.py +0 -225
- package/latticeai/services/memory_service/service.py +0 -48
- package/latticeai/services/memory_service/stores.py +0 -110
- package/latticeai/services/mode_store.py +0 -132
- package/latticeai/services/model_recommendation.py +0 -224
- package/latticeai/services/model_runtime/cloud.py +0 -87
- package/latticeai/services/network_boundary_service.py +0 -117
- package/latticeai/services/obsidian_bridge.py +0 -609
- package/latticeai/services/openai_compatible_adapter.py +0 -101
- package/latticeai/services/permission_mode_service.py +0 -122
- package/latticeai/services/platform_runtime.py +0 -366
- package/latticeai/services/review_queue.py +0 -380
- package/latticeai/services/router_context.py +0 -59
- package/latticeai/services/run_executor.py +0 -387
- package/latticeai/services/self_model_service.py +0 -171
- package/latticeai/services/setup_detection.py +0 -147
- package/latticeai/services/triggers.py +0 -378
- package/latticeai/services/upload_service.py +0 -172
- package/latticeai/services/workspace_service.py +0 -165
- package/latticeai/setup/__init__.py +0 -25
- package/latticeai/setup/auto_setup.py +0 -846
- package/latticeai/setup/demo_corpus.py +0 -98
- package/latticeai/setup/wizard/__init__.py +0 -126
- package/latticeai/setup/wizard/catalog.py +0 -175
- package/latticeai/setup/wizard/detect.py +0 -302
- package/latticeai/setup/wizard/install.py +0 -348
- package/latticeai/setup/wizard/paths.py +0 -165
- package/latticeai/setup/wizard/plans.py +0 -74
- package/latticeai/setup/wizard/recommend.py +0 -320
- package/scripts/bench_agent_smoke.py +0 -409
- package/scripts/bench_models.py +0 -540
- package/scripts/bench_vector_index.py +0 -295
- package/scripts/funnel_soft_gate.py +0 -192
- package/scripts/generate_agent_loop_fixtures.py +0 -994
- package/scripts/generate_rust_parity_fixtures.py +0 -908
- package/scripts/migrate_brain_storage.py +0 -57
- package/scripts/parity_fixture_corpus_context.py +0 -162
- package/scripts/parity_fixture_corpus_docgen.py +0 -341
- package/scripts/profile_kg.py +0 -355
- package/server.py +0 -30
- package/static/app/assets/arrow-left-kfsrk0mv.js +0 -1
- package/static/app/assets/circle-check-qqLug9nU.js +0 -1
- package/static/app/assets/index-DxmOfNRi.css +0 -2
- package/static/app/assets/search-BcHqkjoy.js +0 -1
|
@@ -1,604 +0,0 @@
|
|
|
1
|
-
"""Lattice AI Admin Security & Audit Command Center.
|
|
2
|
-
|
|
3
|
-
피드백 #5 (lattice_ai_admin_security_dashboard_review.txt) 반영.
|
|
4
|
-
|
|
5
|
-
추가 엔드포인트:
|
|
6
|
-
GET /admin/security/overview
|
|
7
|
-
GET /admin/security/users
|
|
8
|
-
GET /admin/security/events
|
|
9
|
-
GET /admin/security/events/{event_id}
|
|
10
|
-
GET /admin/security/conversations/{conversation_id}
|
|
11
|
-
GET /admin/security/conversations/{conversation_id}/raw
|
|
12
|
-
GET /admin/security/files
|
|
13
|
-
GET /admin/security/files/{file_id}
|
|
14
|
-
GET /admin/security/files/{file_id}/content
|
|
15
|
-
GET /admin/security/raw
|
|
16
|
-
POST /admin/security/export
|
|
17
|
-
|
|
18
|
-
핵심 원칙:
|
|
19
|
-
- Secret/API key/token/password/private key는 관리자도 원문을 보면 안 됨.
|
|
20
|
-
- 원문 조회 자체를 admin_view_sensitive_raw 감사로그로 남김.
|
|
21
|
-
- 모든 응답은 마스킹된 preview를 기본으로, raw는 별도 권한 필요.
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
from __future__ import annotations
|
|
25
|
-
|
|
26
|
-
import io
|
|
27
|
-
import json
|
|
28
|
-
import logging
|
|
29
|
-
from collections import defaultdict
|
|
30
|
-
from datetime import datetime
|
|
31
|
-
from typing import Any, Callable, Dict, List, Optional
|
|
32
|
-
|
|
33
|
-
from fastapi import APIRouter, HTTPException, Query, Request
|
|
34
|
-
from fastapi.responses import Response
|
|
35
|
-
from pydantic import BaseModel
|
|
36
|
-
|
|
37
|
-
from ..core import timezones
|
|
38
|
-
from ..core.security import SECRET_TEXT_PATTERNS, redact_secret_text
|
|
39
|
-
|
|
40
|
-
logger = logging.getLogger(__name__)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
# ── Hard secret patterns ──────────────────────────────────────────────────────
|
|
44
|
-
# 이 값들은 관리자도 절대 원문으로 보면 안 된다.
|
|
45
|
-
|
|
46
|
-
HARD_SECRET_PATTERNS = SECRET_TEXT_PATTERNS
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def redact_hard_secrets(text: str) -> str:
|
|
50
|
-
return redact_secret_text(text)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def soft_mask(text: str, *, keep: int = 4) -> str:
|
|
54
|
-
if not text:
|
|
55
|
-
return ""
|
|
56
|
-
raw = redact_hard_secrets(text)
|
|
57
|
-
if len(raw) <= keep * 2:
|
|
58
|
-
return "*" * len(raw)
|
|
59
|
-
return raw[:keep] + "*" * min(len(raw) - keep * 2, 30) + raw[-keep:]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _redact_structure(value: Any) -> Any:
|
|
63
|
-
"""A copy of ``value`` with every string leaf redacted.
|
|
64
|
-
|
|
65
|
-
Redacting the *serialized* JSON instead only appeared to work: the secret
|
|
66
|
-
patterns end in an optional quote, so a secret that ran up to the closing
|
|
67
|
-
``"`` of a JSON string swallowed it and the response stopped being
|
|
68
|
-
parseable JSON. Walking the structure first keeps the document valid.
|
|
69
|
-
|
|
70
|
-
The walk copies rather than edits in place — the rows come straight from
|
|
71
|
-
the audit/upload seams and must not be masked in the caller's store.
|
|
72
|
-
|
|
73
|
-
Only *values* are redacted. Keys are field names the console renders by,
|
|
74
|
-
and blanking a whole field by its name (``core.security.redact_secrets``)
|
|
75
|
-
would drop honest data such as ``token_count`` from an export.
|
|
76
|
-
"""
|
|
77
|
-
if isinstance(value, str):
|
|
78
|
-
return redact_hard_secrets(value)
|
|
79
|
-
if isinstance(value, dict):
|
|
80
|
-
return {key: _redact_structure(item) for key, item in value.items()}
|
|
81
|
-
if isinstance(value, list):
|
|
82
|
-
return [_redact_structure(item) for item in value]
|
|
83
|
-
if isinstance(value, tuple):
|
|
84
|
-
return tuple(_redact_structure(item) for item in value)
|
|
85
|
-
return value
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
# ── Export models ─────────────────────────────────────────────────────────────
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
class ExportRequest(BaseModel):
|
|
92
|
-
scope: str = "events" # events | users | files | conversations | overview
|
|
93
|
-
format: str = "json" # json | csv | excel | pdf | txt
|
|
94
|
-
filters: Optional[Dict[str, Any]] = None
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
# ── Helpers ───────────────────────────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def _user_label(users: Dict[str, Dict[str, Any]], email: Optional[str]) -> str:
|
|
101
|
-
if not email:
|
|
102
|
-
return "Unknown"
|
|
103
|
-
u = users.get(email) or {}
|
|
104
|
-
return u.get("nickname") or u.get("name") or email
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _summarize_user_risk(
|
|
108
|
-
history: List[Dict[str, Any]],
|
|
109
|
-
file_events: List[Dict[str, Any]],
|
|
110
|
-
classify_sensitive_message: Callable[[Dict[str, Any], int], Dict[str, Any]],
|
|
111
|
-
) -> List[Dict[str, Any]]:
|
|
112
|
-
"""사용자별 준수 채팅/위험 채팅/준수 파일/위험 파일 카운트."""
|
|
113
|
-
buckets: Dict[str, Dict[str, Any]] = defaultdict(lambda: {
|
|
114
|
-
"user": "Unknown",
|
|
115
|
-
"total_chats": 0,
|
|
116
|
-
"compliant_chats": 0,
|
|
117
|
-
"risky_chats": 0,
|
|
118
|
-
"uploaded_files": 0,
|
|
119
|
-
"compliant_files": 0,
|
|
120
|
-
"risky_files": 0,
|
|
121
|
-
"high_risk_events": 0,
|
|
122
|
-
"last_activity_at": None,
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
for idx, item in enumerate(history):
|
|
126
|
-
role = item.get("role")
|
|
127
|
-
if role != "user":
|
|
128
|
-
continue
|
|
129
|
-
email = item.get("user_email") or item.get("user_nickname") or "Unknown"
|
|
130
|
-
nickname = item.get("user_nickname") or email
|
|
131
|
-
bucket = buckets[email]
|
|
132
|
-
bucket["user"] = nickname
|
|
133
|
-
bucket["total_chats"] += 1
|
|
134
|
-
try:
|
|
135
|
-
cls = classify_sensitive_message(item, idx)
|
|
136
|
-
except Exception:
|
|
137
|
-
cls = {"sensitivity": "none"}
|
|
138
|
-
if (cls.get("sensitivity") or "none") != "none":
|
|
139
|
-
bucket["risky_chats"] += 1
|
|
140
|
-
if cls.get("sensitivity") == "high":
|
|
141
|
-
bucket["high_risk_events"] += 1
|
|
142
|
-
else:
|
|
143
|
-
bucket["compliant_chats"] += 1
|
|
144
|
-
ts = item.get("timestamp")
|
|
145
|
-
if ts and (not bucket["last_activity_at"] or ts > bucket["last_activity_at"]):
|
|
146
|
-
bucket["last_activity_at"] = ts
|
|
147
|
-
|
|
148
|
-
for fe in file_events:
|
|
149
|
-
email = fe.get("user_email") or "Unknown"
|
|
150
|
-
bucket = buckets[email]
|
|
151
|
-
bucket["uploaded_files"] += 1
|
|
152
|
-
if (fe.get("sensitivity") or "none") != "none" or fe.get("sensitive_labels"):
|
|
153
|
-
bucket["risky_files"] += 1
|
|
154
|
-
if fe.get("sensitivity") == "high":
|
|
155
|
-
bucket["high_risk_events"] += 1
|
|
156
|
-
else:
|
|
157
|
-
bucket["compliant_files"] += 1
|
|
158
|
-
|
|
159
|
-
out: List[Dict[str, Any]] = []
|
|
160
|
-
for email, b in buckets.items():
|
|
161
|
-
total = b["total_chats"] + b["uploaded_files"]
|
|
162
|
-
risk = b["risky_chats"] + b["risky_files"]
|
|
163
|
-
b["email"] = email
|
|
164
|
-
b["risk_rate"] = round((risk / total) * 100, 1) if total else 0.0
|
|
165
|
-
out.append(b)
|
|
166
|
-
out.sort(key=lambda x: (x["high_risk_events"], x["risky_chats"] + x["risky_files"]), reverse=True)
|
|
167
|
-
return out
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def _csv_dump(rows: List[Dict[str, Any]]) -> bytes:
|
|
171
|
-
import csv
|
|
172
|
-
|
|
173
|
-
buf = io.StringIO()
|
|
174
|
-
if not rows:
|
|
175
|
-
return b""
|
|
176
|
-
keys: List[str] = []
|
|
177
|
-
seen: set = set()
|
|
178
|
-
for r in rows:
|
|
179
|
-
for k in r.keys():
|
|
180
|
-
if k not in seen:
|
|
181
|
-
seen.add(k)
|
|
182
|
-
keys.append(k)
|
|
183
|
-
writer = csv.DictWriter(buf, fieldnames=keys, extrasaction="ignore")
|
|
184
|
-
writer.writeheader()
|
|
185
|
-
for r in rows:
|
|
186
|
-
# per value, not per rendered line — and through the structure, because
|
|
187
|
-
# csv stringifies a list/dict cell after this point, which used to carry
|
|
188
|
-
# a nested secret into the file untouched.
|
|
189
|
-
sanitized = {k: _redact_structure(v) for k, v in r.items()}
|
|
190
|
-
writer.writerow(sanitized)
|
|
191
|
-
return buf.getvalue().encode("utf-8")
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def _excel_dump(rows: List[Dict[str, Any]]) -> bytes:
|
|
195
|
-
try:
|
|
196
|
-
from openpyxl import Workbook
|
|
197
|
-
except Exception: # pragma: no cover
|
|
198
|
-
return _csv_dump(rows)
|
|
199
|
-
wb = Workbook()
|
|
200
|
-
ws = wb.active
|
|
201
|
-
ws.title = "security_export"
|
|
202
|
-
headers: List[str] = []
|
|
203
|
-
if rows:
|
|
204
|
-
seen: set = set()
|
|
205
|
-
for r in rows:
|
|
206
|
-
for k in r.keys():
|
|
207
|
-
if k not in seen:
|
|
208
|
-
seen.add(k)
|
|
209
|
-
headers.append(k)
|
|
210
|
-
ws.append(headers)
|
|
211
|
-
for r in rows:
|
|
212
|
-
ws.append([
|
|
213
|
-
redact_hard_secrets(str(r.get(h))) if isinstance(r.get(h), str) else r.get(h)
|
|
214
|
-
for h in headers
|
|
215
|
-
])
|
|
216
|
-
else:
|
|
217
|
-
ws.append(["empty"])
|
|
218
|
-
buf = io.BytesIO()
|
|
219
|
-
wb.save(buf)
|
|
220
|
-
return buf.getvalue()
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def _pdf_report(title: str, rows: List[Dict[str, Any]], overview: Dict[str, Any]) -> bytes:
|
|
224
|
-
try:
|
|
225
|
-
from reportlab.lib.pagesizes import A4
|
|
226
|
-
from reportlab.lib.styles import getSampleStyleSheet
|
|
227
|
-
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Table
|
|
228
|
-
except Exception: # pragma: no cover
|
|
229
|
-
return ("PDF library not available\n" + json.dumps(overview, ensure_ascii=False, indent=2)).encode("utf-8")
|
|
230
|
-
|
|
231
|
-
buf = io.BytesIO()
|
|
232
|
-
doc = SimpleDocTemplate(buf, pagesize=A4, title=title)
|
|
233
|
-
styles = getSampleStyleSheet()
|
|
234
|
-
story: List[Any] = []
|
|
235
|
-
story.append(Paragraph(f"<b>{title}</b>", styles["Title"]))
|
|
236
|
-
story.append(Spacer(1, 12))
|
|
237
|
-
story.append(Paragraph(f"Generated: {datetime.utcnow().isoformat()}Z", styles["Normal"]))
|
|
238
|
-
story.append(Spacer(1, 12))
|
|
239
|
-
story.append(Paragraph("Overview", styles["Heading2"]))
|
|
240
|
-
for k, v in overview.items():
|
|
241
|
-
story.append(Paragraph(f"{k}: {redact_hard_secrets(str(v))}", styles["Normal"]))
|
|
242
|
-
story.append(Spacer(1, 12))
|
|
243
|
-
if rows:
|
|
244
|
-
story.append(Paragraph("Top entries", styles["Heading2"]))
|
|
245
|
-
headers = list(rows[0].keys())
|
|
246
|
-
table_data = [headers] + [
|
|
247
|
-
[redact_hard_secrets(str(r.get(h, ""))) for h in headers] for r in rows[:30]
|
|
248
|
-
]
|
|
249
|
-
story.append(Table(table_data))
|
|
250
|
-
doc.build(story)
|
|
251
|
-
return buf.getvalue()
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
# ── Router factory ────────────────────────────────────────────────────────────
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
def create_security_router(
|
|
258
|
-
*,
|
|
259
|
-
require_admin: Callable,
|
|
260
|
-
get_history: Callable,
|
|
261
|
-
get_audit_events: Callable,
|
|
262
|
-
classify_sensitive_message: Callable,
|
|
263
|
-
build_sensitivity_report: Callable,
|
|
264
|
-
list_uploaded_files: Optional[Callable] = None,
|
|
265
|
-
get_conversation: Optional[Callable] = None,
|
|
266
|
-
append_audit_event: Optional[Callable] = None,
|
|
267
|
-
) -> APIRouter:
|
|
268
|
-
"""관리자 보안/감사 Command Center API.
|
|
269
|
-
|
|
270
|
-
- require_admin(request) -> (admin_email, users)
|
|
271
|
-
- get_history() -> List[Dict]
|
|
272
|
-
- get_audit_events() -> List[Dict]
|
|
273
|
-
- classify_sensitive_message(item, index) -> Dict
|
|
274
|
-
- build_sensitivity_report(history) -> Dict
|
|
275
|
-
- list_uploaded_files() -> Optional[List[Dict]] (없으면 audit_events에서 추론)
|
|
276
|
-
- get_conversation(conversation_id) -> Optional[Dict]
|
|
277
|
-
- append_audit_event(event_type, **payload) -> None
|
|
278
|
-
"""
|
|
279
|
-
|
|
280
|
-
router = APIRouter()
|
|
281
|
-
|
|
282
|
-
# ── Common loaders ────────────────────────────────────────────────────
|
|
283
|
-
|
|
284
|
-
def _events() -> List[Dict[str, Any]]:
|
|
285
|
-
try:
|
|
286
|
-
return list(get_audit_events() or [])
|
|
287
|
-
except Exception as e:
|
|
288
|
-
logger.warning("get_audit_events failed: %s", e)
|
|
289
|
-
return []
|
|
290
|
-
|
|
291
|
-
def _file_events() -> List[Dict[str, Any]]:
|
|
292
|
-
if list_uploaded_files:
|
|
293
|
-
try:
|
|
294
|
-
items = list(list_uploaded_files() or [])
|
|
295
|
-
if items:
|
|
296
|
-
return items
|
|
297
|
-
except Exception:
|
|
298
|
-
logger.debug("list_uploaded_files failed", exc_info=True)
|
|
299
|
-
return [e for e in _events() if e.get("event_type") == "document_upload"]
|
|
300
|
-
|
|
301
|
-
def _log_view(admin_email: str, target_type: str, target_id: str, reason: str = "security_review") -> None:
|
|
302
|
-
if not append_audit_event:
|
|
303
|
-
return
|
|
304
|
-
try:
|
|
305
|
-
append_audit_event(
|
|
306
|
-
"admin_view_sensitive_raw",
|
|
307
|
-
admin_email=admin_email,
|
|
308
|
-
target_type=target_type,
|
|
309
|
-
target_id=target_id,
|
|
310
|
-
reason=reason,
|
|
311
|
-
)
|
|
312
|
-
except Exception:
|
|
313
|
-
logger.debug("append_audit_event for admin_view_sensitive_raw failed", exc_info=True)
|
|
314
|
-
|
|
315
|
-
# ── 1. Security Overview ──────────────────────────────────────────────
|
|
316
|
-
|
|
317
|
-
@router.get("/admin/security/overview")
|
|
318
|
-
async def security_overview(request: Request):
|
|
319
|
-
require_admin(request)
|
|
320
|
-
history = get_history() or []
|
|
321
|
-
events = _events()
|
|
322
|
-
report = build_sensitivity_report(history) or {}
|
|
323
|
-
summary = report.get("summary", {})
|
|
324
|
-
sev = summary.get("severity_counts", {}) or {}
|
|
325
|
-
# item 7: audit timestamp(로컬/설정 시간대)와 동일한 기준으로 "오늘"을 계산한다.
|
|
326
|
-
today = timezones.today_str()
|
|
327
|
-
today_events = [e for e in events if str(e.get("timestamp", ""))[:10] == today]
|
|
328
|
-
|
|
329
|
-
return {
|
|
330
|
-
"generated_at": timezones.now_iso(),
|
|
331
|
-
"timezone": timezones.tz_name(),
|
|
332
|
-
"cards": {
|
|
333
|
-
"events_today": len(today_events),
|
|
334
|
-
"high_risk_events": int(sev.get("high", 0)),
|
|
335
|
-
"risky_chats": int(summary.get("risky_messages", 0)),
|
|
336
|
-
"risky_files": sum(
|
|
337
|
-
1 for fe in _file_events()
|
|
338
|
-
if (fe.get("sensitivity") or "none") != "none" or fe.get("sensitive_labels")
|
|
339
|
-
),
|
|
340
|
-
"secret_blocks": sum(
|
|
341
|
-
1 for e in events
|
|
342
|
-
if (e.get("event_type") in {"secret_block", "external_send_block"})
|
|
343
|
-
or "secret" in (e.get("sensitive_labels") or [])
|
|
344
|
-
),
|
|
345
|
-
"external_blocks": sum(
|
|
346
|
-
1 for e in events
|
|
347
|
-
if e.get("event_type") == "external_send_block"
|
|
348
|
-
),
|
|
349
|
-
"admin_raw_views": sum(
|
|
350
|
-
1 for e in events
|
|
351
|
-
if e.get("event_type") == "admin_view_sensitive_raw"
|
|
352
|
-
),
|
|
353
|
-
"review_required": int(sev.get("high", 0)) + int(sev.get("medium", 0)),
|
|
354
|
-
},
|
|
355
|
-
"field_counts": summary.get("field_counts", {}),
|
|
356
|
-
"severity_counts": sev,
|
|
357
|
-
"risk_rate": summary.get("risk_rate", 0),
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
# ── 2. User Risk Matrix ───────────────────────────────────────────────
|
|
361
|
-
|
|
362
|
-
@router.get("/admin/security/users")
|
|
363
|
-
async def security_users(request: Request):
|
|
364
|
-
_, users = require_admin(request)
|
|
365
|
-
history = get_history() or []
|
|
366
|
-
per_user = _summarize_user_risk(history, _file_events(), classify_sensitive_message)
|
|
367
|
-
# 사용자 메타데이터 join
|
|
368
|
-
for row in per_user:
|
|
369
|
-
email = row.get("email")
|
|
370
|
-
meta = users.get(email or "") or {}
|
|
371
|
-
row["role"] = meta.get("role") or "user"
|
|
372
|
-
row["disabled"] = bool(meta.get("disabled"))
|
|
373
|
-
row["user"] = _user_label(users, email)
|
|
374
|
-
return {"users": per_user, "total": len(per_user)}
|
|
375
|
-
|
|
376
|
-
# ── 3. Events listing (with filters) ──────────────────────────────────
|
|
377
|
-
|
|
378
|
-
@router.get("/admin/security/events")
|
|
379
|
-
async def security_events(
|
|
380
|
-
request: Request,
|
|
381
|
-
user: Optional[str] = Query(None),
|
|
382
|
-
type: Optional[str] = Query(None),
|
|
383
|
-
severity: Optional[str] = Query(None),
|
|
384
|
-
date_from: Optional[str] = Query(None, alias="from"),
|
|
385
|
-
date_to: Optional[str] = Query(None, alias="to"),
|
|
386
|
-
limit: int = Query(200, ge=1, le=2000),
|
|
387
|
-
):
|
|
388
|
-
require_admin(request)
|
|
389
|
-
events = _events()
|
|
390
|
-
out: List[Dict[str, Any]] = []
|
|
391
|
-
for idx, e in enumerate(events):
|
|
392
|
-
ts = str(e.get("timestamp") or "")
|
|
393
|
-
if user and (e.get("user_email") != user and e.get("user_nickname") != user):
|
|
394
|
-
continue
|
|
395
|
-
if type and e.get("event_type") != type:
|
|
396
|
-
continue
|
|
397
|
-
if severity and (e.get("sensitivity") or "none") != severity:
|
|
398
|
-
continue
|
|
399
|
-
if date_from and ts < date_from:
|
|
400
|
-
continue
|
|
401
|
-
if date_to and ts > date_to:
|
|
402
|
-
continue
|
|
403
|
-
mc = dict(e)
|
|
404
|
-
mc["event_id"] = str(e.get("event_id") or idx)
|
|
405
|
-
if "content_preview" in mc:
|
|
406
|
-
mc["content_preview"] = redact_hard_secrets(str(mc.get("content_preview") or ""))
|
|
407
|
-
out.append(mc)
|
|
408
|
-
out.sort(key=lambda x: str(x.get("timestamp") or ""), reverse=True)
|
|
409
|
-
return {"events": out[:limit], "total": len(out)}
|
|
410
|
-
|
|
411
|
-
@router.get("/admin/security/events/{event_id}")
|
|
412
|
-
async def security_event_detail(event_id: str, request: Request):
|
|
413
|
-
admin_email, _ = require_admin(request)
|
|
414
|
-
events = _events()
|
|
415
|
-
idx_to_find: Optional[int] = None
|
|
416
|
-
try:
|
|
417
|
-
idx_to_find = int(event_id)
|
|
418
|
-
except Exception:
|
|
419
|
-
idx_to_find = None
|
|
420
|
-
|
|
421
|
-
target: Optional[Dict[str, Any]] = None
|
|
422
|
-
if idx_to_find is not None and 0 <= idx_to_find < len(events):
|
|
423
|
-
target = events[idx_to_find]
|
|
424
|
-
else:
|
|
425
|
-
for e in events:
|
|
426
|
-
if str(e.get("event_id") or "") == event_id:
|
|
427
|
-
target = e
|
|
428
|
-
break
|
|
429
|
-
if not target:
|
|
430
|
-
raise HTTPException(status_code=404, detail="이벤트를 찾을 수 없습니다.")
|
|
431
|
-
_log_view(admin_email, "event", str(event_id))
|
|
432
|
-
masked = dict(target)
|
|
433
|
-
if "content_preview" in masked:
|
|
434
|
-
masked["content_preview"] = redact_hard_secrets(str(masked.get("content_preview") or ""))
|
|
435
|
-
return {"event": masked, "raw_available": True}
|
|
436
|
-
|
|
437
|
-
# ── 4. Conversation drill-down ────────────────────────────────────────
|
|
438
|
-
|
|
439
|
-
@router.get("/admin/security/conversations/{conversation_id}")
|
|
440
|
-
async def security_conversation_summary(conversation_id: str, request: Request):
|
|
441
|
-
require_admin(request)
|
|
442
|
-
history = [h for h in (get_history() or []) if h.get("conversation_id") == conversation_id]
|
|
443
|
-
items = [classify_sensitive_message(h, i) for i, h in enumerate(history)]
|
|
444
|
-
return {
|
|
445
|
-
"conversation_id": conversation_id,
|
|
446
|
-
"messages_total": len(items),
|
|
447
|
-
"risky_messages": sum(1 for it in items if it.get("sensitivity") != "none"),
|
|
448
|
-
"items": items,
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
@router.get("/admin/security/conversations/{conversation_id}/raw")
|
|
452
|
-
async def security_conversation_raw(conversation_id: str, request: Request):
|
|
453
|
-
admin_email, _ = require_admin(request)
|
|
454
|
-
history = [h for h in (get_history() or []) if h.get("conversation_id") == conversation_id]
|
|
455
|
-
if not history:
|
|
456
|
-
raise HTTPException(status_code=404, detail="대화를 찾을 수 없습니다.")
|
|
457
|
-
_log_view(admin_email, "conversation", conversation_id)
|
|
458
|
-
# 원문 조회 — 단, hard secret은 항상 redact
|
|
459
|
-
masked = []
|
|
460
|
-
for h in history:
|
|
461
|
-
cleaned = dict(h)
|
|
462
|
-
if "content" in cleaned:
|
|
463
|
-
cleaned["content"] = redact_hard_secrets(str(cleaned.get("content") or ""))
|
|
464
|
-
masked.append(cleaned)
|
|
465
|
-
return {"conversation_id": conversation_id, "messages": masked}
|
|
466
|
-
|
|
467
|
-
# ── 5. File monitor ───────────────────────────────────────────────────
|
|
468
|
-
|
|
469
|
-
@router.get("/admin/security/files")
|
|
470
|
-
async def security_files(request: Request):
|
|
471
|
-
require_admin(request)
|
|
472
|
-
# Every string field is masked, not only the rendered preview:
|
|
473
|
-
# `extracted_text` carries the same document body the content route
|
|
474
|
-
# redacts, and a listing that leaked it would be the easier way in.
|
|
475
|
-
# Masking a copy leaves the upload/audit rows behind the seam intact.
|
|
476
|
-
files = [_redact_structure(f) for f in _file_events()]
|
|
477
|
-
return {"files": files, "total": len(files)}
|
|
478
|
-
|
|
479
|
-
@router.get("/admin/security/files/{file_id}")
|
|
480
|
-
async def security_file_detail(file_id: str, request: Request):
|
|
481
|
-
admin_email, _ = require_admin(request)
|
|
482
|
-
files = _file_events()
|
|
483
|
-
target = next(
|
|
484
|
-
(f for f in files if str(f.get("file_id") or f.get("filename") or "") == file_id),
|
|
485
|
-
None,
|
|
486
|
-
)
|
|
487
|
-
if not target:
|
|
488
|
-
raise HTTPException(status_code=404, detail="파일을 찾을 수 없습니다.")
|
|
489
|
-
_log_view(admin_email, "file", file_id)
|
|
490
|
-
# Same rule as the listing: every string field of the record is masked
|
|
491
|
-
# on a copy, so the detail view can never be the looser way to read
|
|
492
|
-
# `extracted_text`. The preview keeps its text coercion — the console
|
|
493
|
-
# renders it as a string and a missing one stays "".
|
|
494
|
-
cleaned = _redact_structure(target)
|
|
495
|
-
if "content_preview" in cleaned:
|
|
496
|
-
cleaned["content_preview"] = redact_hard_secrets(str(target.get("content_preview") or ""))
|
|
497
|
-
return {"file": cleaned}
|
|
498
|
-
|
|
499
|
-
@router.get("/admin/security/files/{file_id}/content")
|
|
500
|
-
async def security_file_content(file_id: str, request: Request):
|
|
501
|
-
admin_email, _ = require_admin(request)
|
|
502
|
-
files = _file_events()
|
|
503
|
-
target = next(
|
|
504
|
-
(f for f in files if str(f.get("file_id") or f.get("filename") or "") == file_id),
|
|
505
|
-
None,
|
|
506
|
-
)
|
|
507
|
-
if not target:
|
|
508
|
-
raise HTTPException(status_code=404, detail="파일을 찾을 수 없습니다.")
|
|
509
|
-
_log_view(admin_email, "file_content", file_id, reason="raw_content_review")
|
|
510
|
-
# raw text가 있더라도 hard secret은 redact
|
|
511
|
-
text = target.get("extracted_text") or target.get("content_preview") or ""
|
|
512
|
-
return {"file_id": file_id, "text": redact_hard_secrets(str(text))}
|
|
513
|
-
|
|
514
|
-
# ── 6. Raw data explorer ──────────────────────────────────────────────
|
|
515
|
-
|
|
516
|
-
@router.get("/admin/security/raw")
|
|
517
|
-
async def security_raw(request: Request, scope: str = Query("audit")):
|
|
518
|
-
admin_email, _ = require_admin(request)
|
|
519
|
-
_log_view(admin_email, "raw", scope, reason="raw_explorer")
|
|
520
|
-
if scope == "audit":
|
|
521
|
-
payload = _events()
|
|
522
|
-
elif scope == "history":
|
|
523
|
-
payload = get_history() or []
|
|
524
|
-
elif scope == "files":
|
|
525
|
-
payload = _file_events()
|
|
526
|
-
else:
|
|
527
|
-
raise HTTPException(status_code=400, detail="지원하지 않는 scope입니다.")
|
|
528
|
-
# JSON 전체에서 hard secret redact — 값을 먼저 마스킹한 뒤 직렬화해야
|
|
529
|
-
# 유효한 JSON이 나온다(직렬화 후 마스킹은 닫는 따옴표를 먹는다).
|
|
530
|
-
text = json.dumps(_redact_structure(payload), ensure_ascii=False)
|
|
531
|
-
return Response(content=text, media_type="application/json; charset=utf-8")
|
|
532
|
-
|
|
533
|
-
# ── 7. Export ─────────────────────────────────────────────────────────
|
|
534
|
-
|
|
535
|
-
@router.post("/admin/security/export")
|
|
536
|
-
async def security_export(req: ExportRequest, request: Request):
|
|
537
|
-
admin_email, users = require_admin(request)
|
|
538
|
-
scope = (req.scope or "events").lower()
|
|
539
|
-
fmt = (req.format or "json").lower()
|
|
540
|
-
if scope == "events":
|
|
541
|
-
rows = _events()
|
|
542
|
-
elif scope == "users":
|
|
543
|
-
rows = _summarize_user_risk(get_history() or [], _file_events(), classify_sensitive_message)
|
|
544
|
-
elif scope == "files":
|
|
545
|
-
rows = _file_events()
|
|
546
|
-
elif scope == "overview":
|
|
547
|
-
report = build_sensitivity_report(get_history() or []) or {}
|
|
548
|
-
rows = [report.get("summary", {})]
|
|
549
|
-
else:
|
|
550
|
-
raise HTTPException(status_code=400, detail="지원하지 않는 scope입니다.")
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
_log_view(admin_email, "export", f"{scope}:{fmt}", reason="export")
|
|
554
|
-
|
|
555
|
-
if fmt == "json":
|
|
556
|
-
# 마스킹은 직렬화 전에 — 다운로드된 파일은 언제나 파싱 가능해야 한다.
|
|
557
|
-
body = json.dumps(_redact_structure(rows), ensure_ascii=False, indent=2)
|
|
558
|
-
filename = f"security_{scope}.json"
|
|
559
|
-
return Response(
|
|
560
|
-
content=body,
|
|
561
|
-
media_type="application/json; charset=utf-8",
|
|
562
|
-
headers={"Content-Disposition": f"attachment; filename={filename}"},
|
|
563
|
-
)
|
|
564
|
-
if fmt == "csv":
|
|
565
|
-
body = _csv_dump(rows) # type: ignore[assignment]
|
|
566
|
-
filename = f"security_{scope}.csv"
|
|
567
|
-
return Response(
|
|
568
|
-
content=body,
|
|
569
|
-
media_type="text/csv; charset=utf-8",
|
|
570
|
-
headers={"Content-Disposition": f"attachment; filename={filename}"},
|
|
571
|
-
)
|
|
572
|
-
if fmt in {"excel", "xlsx"}:
|
|
573
|
-
body = _excel_dump(rows) # type: ignore[assignment]
|
|
574
|
-
filename = f"security_{scope}.xlsx"
|
|
575
|
-
return Response(
|
|
576
|
-
content=body,
|
|
577
|
-
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
578
|
-
headers={"Content-Disposition": f"attachment; filename={filename}"},
|
|
579
|
-
)
|
|
580
|
-
if fmt == "pdf":
|
|
581
|
-
overview = build_sensitivity_report(get_history() or []).get("summary", {}) or {}
|
|
582
|
-
body = _pdf_report("Lattice AI Security Report", rows, overview) # type: ignore[assignment]
|
|
583
|
-
filename = f"security_{scope}.pdf"
|
|
584
|
-
return Response(
|
|
585
|
-
content=body,
|
|
586
|
-
media_type="application/pdf",
|
|
587
|
-
headers={"Content-Disposition": f"attachment; filename={filename}"},
|
|
588
|
-
)
|
|
589
|
-
if fmt == "txt":
|
|
590
|
-
# 한 줄 = 한 행의 JSON. 여기서도 값 마스킹이 직렬화보다 앞선다.
|
|
591
|
-
body = "\n".join(
|
|
592
|
-
json.dumps(_redact_structure(r), ensure_ascii=False) for r in rows
|
|
593
|
-
)
|
|
594
|
-
return Response(
|
|
595
|
-
content=body,
|
|
596
|
-
media_type="text/plain; charset=utf-8",
|
|
597
|
-
headers={"Content-Disposition": f"attachment; filename=security_{scope}.txt"},
|
|
598
|
-
)
|
|
599
|
-
raise HTTPException(status_code=400, detail="지원하지 않는 포맷입니다.")
|
|
600
|
-
|
|
601
|
-
return router
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
__all__ = ["create_security_router", "redact_hard_secrets", "soft_mask"]
|