diff --git a/README.md b/README.md index f0a3026..1e04373 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ LangMem uses a hybrid approach combining: - ๐Ÿ“Š **Rich Metadata**: Flexible memory attributes - ๐Ÿ”’ **Secure API**: Bearer token authentication - ๐Ÿณ **Docker Ready**: Containerized deployment +- ๐Ÿ“š **Protected Documentation**: Basic auth-protected docs - ๐Ÿงช **Comprehensive Tests**: Unit and integration tests ## Quick Start @@ -278,6 +279,44 @@ For production deployment: 4. Set up monitoring and logging 5. Configure backup procedures +## Documentation + +The LangMem project includes comprehensive documentation with authentication protection. + +### Accessing Documentation + +Start the authenticated documentation server: + +```bash +# Start documentation server on port 8080 (default) +./start-docs-server.sh + +# Or specify a custom port +./start-docs-server.sh 8090 +``` + +**Access Credentials:** +- **Username:** `langmem` +- **Password:** `langmem2025` + +**Available Documentation:** +- ๐Ÿ“– **Main Docs**: System overview and features +- ๐Ÿ—๏ธ **Architecture**: Detailed system architecture +- ๐Ÿ“ก **API Reference**: Complete API documentation +- ๐Ÿ› ๏ธ **Implementation**: Step-by-step setup guide + +### Direct Server Usage + +You can also run the documentation server directly: + +```bash +python3 docs_server.py [port] +``` + +Then visit: `http://localhost:8080` (or your specified port) + +Your browser will prompt for authentication credentials. + ## Contributing 1. Fork the repository diff --git a/docs_server.py b/docs_server.py new file mode 100755 index 0000000..cba47d4 --- /dev/null +++ b/docs_server.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +""" +Simple authenticated web server for LangMem documentation +""" + +import http.server +import socketserver +import base64 +import os +from urllib.parse import parse_qs + +# Authentication credentials +USERNAME = "langmem" +PASSWORD = "langmem2025" + +class AuthHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): + """HTTP handler with basic authentication""" + + def __init__(self, *args, **kwargs): + super().__init__(*args, directory="docs", **kwargs) + + def do_GET(self): + """Handle GET requests with authentication""" + if self.authenticate(): + super().do_GET() + else: + self.send_auth_request() + + def authenticate(self): + """Check if request has valid authentication""" + auth_header = self.headers.get('Authorization') + + if not auth_header: + return False + + try: + auth_type, credentials = auth_header.split(' ', 1) + if auth_type.lower() != 'basic': + return False + + decoded = base64.b64decode(credentials).decode('utf-8') + username, password = decoded.split(':', 1) + + return username == USERNAME and password == PASSWORD + + except Exception: + return False + + def send_auth_request(self): + """Send authentication request to client""" + self.send_response(401) + self.send_header('WWW-Authenticate', 'Basic realm="LangMem Documentation"') + self.send_header('Content-type', 'text/html') + self.end_headers() + + html = """ + + + + Authentication Required + + + +
+

๐Ÿ” LangMem Documentation

+

Authentication required to access documentation.

+

Username: langmem
+ Password: langmem2025

+

Please refresh the page and enter your credentials when prompted.

+
+ + + """ + self.wfile.write(html.encode()) + +def start_server(port=8080): + """Start the authenticated documentation server""" + try: + with socketserver.TCPServer(("", port), AuthHTTPRequestHandler) as httpd: + print(f"๐ŸŒ LangMem Documentation Server started!") + print(f"๐Ÿ“ URL: http://localhost:{port}") + print(f"๐Ÿ”‘ Username: {USERNAME}") + print(f"๐Ÿ”‘ Password: {PASSWORD}") + print(f"๐Ÿ›‘ Press Ctrl+C to stop the server") + print("=" * 50) + httpd.serve_forever() + except KeyboardInterrupt: + print("\n๐Ÿ›‘ Server stopped by user") + except Exception as e: + print(f"โŒ Error starting server: {e}") + +if __name__ == "__main__": + import sys + + port = 8080 + if len(sys.argv) > 1: + try: + port = int(sys.argv[1]) + except ValueError: + print("Invalid port number. Using default port 8080.") + + start_server(port) \ No newline at end of file diff --git a/start-docs-server.sh b/start-docs-server.sh new file mode 100755 index 0000000..ad6753a --- /dev/null +++ b/start-docs-server.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Start LangMem Documentation Server with Authentication + +echo "๐Ÿš€ Starting LangMem Documentation Server..." +echo "๐Ÿ” Authentication enabled with basic auth" +echo "" + +# Default port +PORT=${1:-8080} + +# Start the authenticated server +python3 docs_server.py $PORT \ No newline at end of file