app.routes
HTTP route layer for the AIFT Flask application.
This package contains all HTTP endpoint definitions, in-memory state management, evidence handling, artifact/profile logic, and background task runners for the AIFT forensic triage wizard.
Sub-modules:
state: Constants, global state dicts, SSE streaming, case management.evidence: Archive extraction, file upload, evidence resolution, CSV/hash.artifacts: Artifact option normalisation, profile CRUD, date validation.tasks: Background parse/analysis/chat runners and prompt helpers.handlers: Core blueprint (UI, cases, settings) and route registration.analysis: AI analysis routes.chat: Chat routes.
1"""HTTP route layer for the AIFT Flask application. 2 3This package contains all HTTP endpoint definitions, in-memory state 4management, evidence handling, artifact/profile logic, and background 5task runners for the AIFT forensic triage wizard. 6 7Sub-modules: 8 9- ``state``: Constants, global state dicts, SSE streaming, case management. 10- ``evidence``: Archive extraction, file upload, evidence resolution, CSV/hash. 11- ``artifacts``: Artifact option normalisation, profile CRUD, date validation. 12- ``tasks``: Background parse/analysis/chat runners and prompt helpers. 13- ``handlers``: Core blueprint (UI, cases, settings) and route registration. 14- ``analysis``: AI analysis routes. 15- ``chat``: Chat routes. 16""" 17 18from __future__ import annotations 19 20# Re-export the primary entry point used by app/__init__.py. 21from .handlers import register_routes 22 23# Re-export names that external code (tests, etc.) accesses via 24# ``import app.routes as routes; routes.SOME_NAME``. 25# 26# State, constants, and helpers: 27from .state import ( # noqa: F401 28 ANALYSIS_PROGRESS, 29 CASE_STATES, 30 CASE_TTL_SECONDS, 31 CASES_ROOT, 32 CHAT_HISTORY_MAX_PAIRS, 33 CHAT_PROGRESS, 34 CONNECTION_TEST_SYSTEM_PROMPT, 35 CONNECTION_TEST_USER_PROMPT, 36 DEFAULT_FORENSIC_SYSTEM_PROMPT, 37 DISSECT_EVIDENCE_EXTENSIONS, 38 IMAGES_ROOT, 39 MASKED, 40 MODE_PARSE_AND_AI, 41 MODE_PARSE_ONLY, 42 PARSE_PROGRESS, 43 PROJECT_ROOT, 44 SAFE_NAME_RE, 45 SENSITIVE_KEYS, 46 SSE_INITIAL_IDLE_GRACE_SECONDS, 47 SSE_POLL_INTERVAL_SECONDS, 48 STATE_LOCK, 49 TERMINAL_CASE_STATUSES, 50 audit_config_change, 51 cleanup_case_entries, 52 cleanup_terminal_cases, 53 deep_merge, 54 emit_progress, 55 error_response, 56 get_case, 57 mark_case_status, 58 mask_sensitive, 59 new_progress, 60 normalize_case_status, 61 now_iso, 62 resolve_logo_filename, 63 safe_int, 64 safe_name, 65 sanitize_changed_keys, 66 set_progress_status, 67 stream_sse, 68 success_response, 69) 70 71# Evidence helpers and blueprint: 72from .evidence import ( # noqa: F401 73 EWF_SEGMENT_RE, 74 SPLIT_RAW_SEGMENT_RE, 75 build_csv_map, 76 collect_case_csv_paths, 77 evidence_bp, 78 read_audit_entries, 79 resolve_case_csv_output_dir, 80 resolve_evidence_payload, 81 resolve_hash_verification_path, 82) 83 84# Artifact / profile helpers and blueprint: 85from .artifacts import ( # noqa: F401 86 BUILTIN_RECOMMENDED_PROFILE, 87 PROFILE_DIRNAME, 88 PROFILE_FILE_SUFFIX, 89 PROFILE_NAME_RE, 90 RECOMMENDED_PROFILE_EXCLUDED_ARTIFACTS, 91 artifact_bp, 92 artifact_options_to_lists, 93 compose_profile_response, 94 extract_parse_progress, 95 extract_parse_selection_payload, 96 load_profiles_from_directory, 97 normalize_artifact_mode, 98 normalize_artifact_options, 99 normalize_profile_name, 100 profile_path_for_new_name, 101 resolve_profiles_root, 102 sanitize_prompt, 103 validate_analysis_date_range, 104 write_profile_file, 105) 106 107# Background task runners: 108from .tasks import ( # noqa: F401 109 load_case_analysis_results, 110 resolve_case_investigation_context, 111 resolve_case_parsed_dir, 112 run_analysis, 113 run_chat, 114 run_parse, 115 run_task_with_case_log_context, 116) 117 118# Re-export names from handlers.py that tests patch directly on ``routes``. 119from .handlers import ( # noqa: F401 120 WINDOWS_ARTIFACT_REGISTRY, 121 ForensicAnalyzer, 122 ForensicParser, 123 ReportGenerator, 124 TOOL_VERSION, 125 case_log_context, 126 compute_hashes, 127 create_provider, 128 verify_hash, 129 AIProviderError, 130 routes_bp, 131 threading, 132) 133 134# Sub-blueprints (evidence_bp and artifact_bp already imported above): 135from .analysis import analysis_bp # noqa: F401 136from .chat import chat_bp # noqa: F401 137 138__all__ = [ 139 "register_routes", 140 "analysis", 141 "artifacts", 142 "chat", 143 "evidence", 144 "handlers", 145 "state", 146 "tasks", 147]
def
register_routes(app: flask.app.Flask) -> None:
402def register_routes(app: Flask) -> None: 403 """Register all HTTP route handlers with the Flask application. 404 405 Registers the core ``routes_bp`` blueprint plus sub-blueprints for 406 evidence, artifact, analysis, and chat routes. 407 408 Args: 409 app: The Flask application instance. 410 """ 411 app.register_blueprint(routes_bp) 412 app.register_blueprint(evidence_bp) 413 app.register_blueprint(artifact_bp) 414 app.register_blueprint(analysis_bp) 415 app.register_blueprint(chat_bp)
Register all HTTP route handlers with the Flask application.
Registers the core routes_bp blueprint plus sub-blueprints for
evidence, artifact, analysis, and chat routes.
Arguments:
- app: The Flask application instance.