fix: Simplify init.py according to correct module development rules
- Update init.py to only expose variables/functions for web scripts (no routing) - Remove api.py (routing is automatic for wwwroot files) - Add MODULE_DEVELOPMENT_SPEC_UPDATE.md with clarified rules - Follow proper module development specification
This commit is contained in:
parent
b150399cc4
commit
9a5158d09a
47
MODULE_DEVELOPMENT_SPEC_UPDATE.md
Normal file
47
MODULE_DEVELOPMENT_SPEC_UPDATE.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Module Development Specification (Updated)
|
||||
|
||||
## Directory Structure
|
||||
```
|
||||
module-name/
|
||||
├── module_name/ # Python package (underscore format)
|
||||
│ ├── __init__.py # Required for Python package
|
||||
│ └── init.py # Exposes variables/functions for web scripts
|
||||
├── wwwroot/ # Web resources (auto-routed)
|
||||
│ ├── *.ui # Bricks framework UI files
|
||||
│ └── *.dspy # DSPy workflow files
|
||||
├── models/ # Database table definitions (JSON)
|
||||
├── json/ # CRUD operation definitions (JSON)
|
||||
├── init/ # Initial data (JSON)
|
||||
├── pyproject.toml # Package configuration for pip install
|
||||
└── build.sh # Build script (optional)
|
||||
```
|
||||
|
||||
## Key Rules
|
||||
|
||||
### 1. Automatic Routing
|
||||
- Files in `wwwroot/` are automatically accessible via `/{module_name}/filename.ext`
|
||||
- No need to register routes manually with ServerEnv
|
||||
- Supported extensions: `.ui`, `.dspy`
|
||||
|
||||
### 2. init.py Purpose
|
||||
- **Primary role**: Expose variables and functions for use by other modules and web scripts
|
||||
- **Not for**: Route registration, ServerEnv configuration, complex initialization
|
||||
- **Should contain**:
|
||||
- Module constants and configuration
|
||||
- Helper functions callable from .ui/.dspy scripts
|
||||
- Variables needed by other Python modules
|
||||
|
||||
### 3. Python Package Naming
|
||||
- Directory: `module-name/` (hyphen format for repository)
|
||||
- Python package: `module_name/` (underscore format for import)
|
||||
- PyPI package name: `module-name` (hyphen format)
|
||||
|
||||
### 4. Installation
|
||||
- Must include `pyproject.toml` or `setup.py`
|
||||
- Must be installable via `pip install .`
|
||||
- Should declare dependencies properly
|
||||
|
||||
### 5. Web Script Integration
|
||||
- .ui and .dspy files can import/use functions from init.py
|
||||
- Use standard Python import syntax in web scripts
|
||||
- Keep init.py lightweight and focused on exposure
|
||||
10
UNKNOWN.egg-info/PKG-INFO
Normal file
10
UNKNOWN.egg-info/PKG-INFO
Normal file
@ -0,0 +1,10 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: UNKNOWN
|
||||
Version: 0.0.0
|
||||
Summary: UNKNOWN
|
||||
Home-page: UNKNOWN
|
||||
License: UNKNOWN
|
||||
Platform: UNKNOWN
|
||||
|
||||
UNKNOWN
|
||||
|
||||
5
UNKNOWN.egg-info/SOURCES.txt
Normal file
5
UNKNOWN.egg-info/SOURCES.txt
Normal file
@ -0,0 +1,5 @@
|
||||
pyproject.toml
|
||||
UNKNOWN.egg-info/PKG-INFO
|
||||
UNKNOWN.egg-info/SOURCES.txt
|
||||
UNKNOWN.egg-info/dependency_links.txt
|
||||
UNKNOWN.egg-info/top_level.txt
|
||||
1
UNKNOWN.egg-info/dependency_links.txt
Normal file
1
UNKNOWN.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
||||
|
||||
1
UNKNOWN.egg-info/top_level.txt
Normal file
1
UNKNOWN.egg-info/top_level.txt
Normal file
@ -0,0 +1 @@
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from appPublic.worker import awaitify
|
||||
|
||||
def load_hermes_web_cli():
|
||||
"""Load hermes web cli module"""
|
||||
env = Server...[truncated]
|
||||
@ -1,58 +0,0 @@
|
||||
from ahserver.serverenv import ServerEnv
|
||||
|
||||
def register_routes(env: ServerEnv):
|
||||
"""Register API routes for hermes-web-cli module"""
|
||||
|
||||
@env.route('/api/hermes-web-cli/services', methods=['GET', 'POST'])
|
||||
async def handle_services(request):
|
||||
# Handle service registration and listing
|
||||
if request.method == 'GET':
|
||||
return await get_services(request)
|
||||
elif request.method == 'POST':
|
||||
return await create_service(request)
|
||||
|
||||
@env.route('/api/hermes-web-cli/services/<service_id>', methods=['GET', 'PUT', 'DELETE'])
|
||||
async def handle_service_detail(request, service_id):
|
||||
# Handle individual service operations
|
||||
if request.method == 'GET':
|
||||
return await get_service(request, service_id)
|
||||
elif request.method == 'PUT':
|
||||
return await update_service(request, service_id)
|
||||
elif request.method == 'DELETE':
|
||||
return await delete_service(request, service_id)
|
||||
|
||||
@env.route('/api/hermes-web-cli/sessions', methods=['POST'])
|
||||
async def create_session(request):
|
||||
# Create new session on remote service
|
||||
return await create_remote_session(request)
|
||||
|
||||
@env.route('/api/hermes-web-cli/sessions/<session_id>/messages', methods=['POST'])
|
||||
async def send_message(request, session_id):
|
||||
# Send message to remote session
|
||||
return await send_remote_message(request, session_id)
|
||||
|
||||
@env.route('/api/hermes-web-cli/health', methods=['GET'])
|
||||
async def health_check(request):
|
||||
return {'status': 'healthy', 'module': 'hermes-web-cli'}
|
||||
|
||||
# Placeholder functions - these would be implemented with actual database and HTTP client logic
|
||||
async def get_services(request):
|
||||
return []
|
||||
|
||||
async def create_service(request):
|
||||
return {}
|
||||
|
||||
async def get_service(request, service_id):
|
||||
return {}
|
||||
|
||||
async def update_service(request, service_id):
|
||||
return {}
|
||||
|
||||
async def delete_service(request, service_id):
|
||||
return {}
|
||||
|
||||
async def create_remote_session(request):
|
||||
return {}
|
||||
|
||||
async def send_remote_message(request, session_id):
|
||||
return {}
|
||||
@ -1,13 +1,27 @@
|
||||
from ahserver.serverenv import ServerEnv
|
||||
# hermes-web-cli module initialization
|
||||
# This file exposes variables and functions for use by other modules and web scripts (.ui, .dspy)
|
||||
|
||||
def load_hermes_web_cli():
|
||||
"""Load hermes web cli module"""
|
||||
env = ServerEnv()
|
||||
# Register static file serving for hermes-web-cli
|
||||
env.register_static_path('/hermes-web-cli', 'wwwroot/hermes-web-cli')
|
||||
# Module metadata
|
||||
MODULE_NAME = "hermes-web-cli"
|
||||
MODULE_VERSION = "0.1.0"
|
||||
|
||||
# Register API endpoints
|
||||
from hermes_web_cli.api import register_routes
|
||||
register_routes(env)
|
||||
# Configuration constants
|
||||
DEFAULT_SERVICE_URL = "http://localhost:9120"
|
||||
SUPPORTED_SERVICE_STATUS = ["active", "inactive", "disconnected"]
|
||||
|
||||
return True
|
||||
# Helper functions that can be used by .ui or .dspy scripts
|
||||
def get_service_config(service_id):
|
||||
"""Get service configuration by ID - can be called from .ui scripts"""
|
||||
# This would typically query the database
|
||||
pass
|
||||
|
||||
def validate_service_url(url):
|
||||
"""Validate service URL format - can be called from .ui scripts"""
|
||||
return url.startswith(('http://', 'https://'))
|
||||
|
||||
def create_session_id():
|
||||
"""Generate a new session ID - can be called from .ui scripts"""
|
||||
import uuid
|
||||
return str(uuid.uuid4())
|
||||
|
||||
# Any other variables or functions needed by web scripts
|
||||
Loading…
x
Reference in New Issue
Block a user