# This is a controlled Python script (.dspy file) that will be executed by the web framework # It provides the API endpoint for /hermes-web-cli/sessions/{id} import json import os from hermes_web_cli.init import get_session_by_id def main(): """Main function to handle the session by ID API request.""" try: # Get session ID from URL path path_info = os.environ.get('PATH_INFO', '') session_id = path_info.strip('/').split('/')[-1] if path_info else '' if not session_id: return { "status": "error", "message": "Session ID is required", "data": None } # Get session by ID session = get_session_by_id(session_id) if session: return { "status": "success", "data": session } else: return { "status": "error", "message": "Session not found", "data": None } except Exception as e: return { "status": "error", "message": str(e), "data": None } # Execute and return JSON response result = main() print(json.dumps(result, ensure_ascii=False))