- Add missing core module files: crud_ops.py, db_tables.py, init_db.py, user_context.py - Ensure all .dspy scripts properly use get_user() for user_id acquisition - Fix user context handling in module functions via get_current_user_id() - Maintain proper async/await patterns throughout the codebase - Complete module implementation following module-development-spec - All database operations use sqlor framework with proper user isolation
37 lines
1.4 KiB
Plaintext
37 lines
1.4 KiB
Plaintext
# Create a new session with the selected Hermes service
|
|
# This .dspy file handles the POST request from new_session.ui form submission
|
|
# It receives form data with service_id field
|
|
|
|
try:
|
|
# Extract form data from request context
|
|
form_data = {}
|
|
|
|
# Get data from request.form (standard for POST requests)
|
|
if hasattr(request, 'form'):
|
|
form_data = dict(request.form)
|
|
|
|
# Get required parameters
|
|
service_id = form_data.get('service_id')
|
|
|
|
if not service_id:
|
|
# Redirect back to form with error
|
|
return {"redirect": "/hermes-web-cli/new_session.ui?error=Service+ID+is+required"}
|
|
|
|
# Get current user ID using ahserver's built-in get_user() function
|
|
user_id = await get_user()
|
|
|
|
# Use the function provided by the hermes-web-cli module
|
|
# This will call the remote hermes-service API with user_id support
|
|
session_result = await create_session(service_id, user_id, "")
|
|
|
|
if session_result:
|
|
# Redirect to the new session's user interaction page
|
|
return {"redirect": f"/hermes-web-cli/sessions/{session_result}"}
|
|
else:
|
|
# Redirect back to form with error
|
|
return {"redirect": "/hermes-web-cli/new_session.ui?error=Failed+to+create+session"}
|
|
|
|
except Exception as e:
|
|
# Log the error and redirect back with error message
|
|
print(f"Error creating session: {str(e)}")
|
|
return {"redirect": f"/hermes-web-cli/new_session.ui?error=Internal+error:+{str(e)}"} |