mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Adds support for enterprise LLM gateways through TOML configuration files,
enabling OpenHands CLI usage in corporate environments with custom API
management solutions.
Features:
- Load gateway configuration from TOML file via --gateway-config flag
- Support for environment variable OPENHANDS_GATEWAY_CONFIG
- Environment variable expansion in config values (${ENV:VAR_NAME})
- Comprehensive example configuration file with documentation
- Clean separation from interactive setup flow
Implementation:
- Added gateway_config.py module for loading and parsing TOML configs
- Thread gateway config through CLI entry to agent initialization
- Apply gateway settings when creating LLM instance
- Update tests to handle new gateway_config_path parameter
- Remove interactive gateway setup to keep UI simple
This enables enterprise customers to configure:
- OAuth2/token authentication with identity providers
- Custom headers for routing and authorization
- Request body parameters for compliance/monitoring
- All without impacting the standard user experience
Note: Requires openhands-sdk>=1.0.0a6 once the SDK PR is merged.
Currently set to >=1.0.0a4 for compatibility.
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple main entry point for OpenHands CLI.
|
|
This is a simplified version that demonstrates the TUI functionality.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import sys
|
|
import warnings
|
|
|
|
debug_env = os.getenv('DEBUG', 'false').lower()
|
|
if debug_env != '1' and debug_env != 'true':
|
|
logging.disable(logging.WARNING)
|
|
warnings.filterwarnings('ignore')
|
|
|
|
from prompt_toolkit import print_formatted_text
|
|
from prompt_toolkit.formatted_text import HTML
|
|
|
|
from openhands_cli.argparsers.main_parser import create_main_parser
|
|
|
|
|
|
def main() -> None:
|
|
"""Main entry point for the OpenHands CLI.
|
|
|
|
Raises:
|
|
ImportError: If agent chat dependencies are missing
|
|
Exception: On other error conditions
|
|
"""
|
|
parser = create_main_parser()
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
if args.command == 'serve':
|
|
# Import gui_launcher only when needed
|
|
from openhands_cli.gui_launcher import launch_gui_server
|
|
|
|
launch_gui_server(mount_cwd=args.mount_cwd, gpu=args.gpu)
|
|
else:
|
|
# Default CLI behavior - no subcommand needed
|
|
# Import agent_chat only when needed
|
|
from openhands_cli.agent_chat import run_cli_entry
|
|
|
|
# Start agent chat
|
|
run_cli_entry(
|
|
resume_conversation_id=args.resume,
|
|
gateway_config_path=args.gateway_config
|
|
)
|
|
except KeyboardInterrupt:
|
|
print_formatted_text(HTML('\n<yellow>Goodbye! 👋</yellow>'))
|
|
except EOFError:
|
|
print_formatted_text(HTML('\n<yellow>Goodbye! 👋</yellow>'))
|
|
except Exception as e:
|
|
print_formatted_text(HTML(f'<red>Error: {e}</red>'))
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
raise
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|