35 lines
1.4 KiB
Plaintext
35 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"}
|
|
|
|
# Use the function provided by the hermes-web-cli module
|
|
# This will call the remote hermes-service API
|
|
# Pass empty string as initial message since we don't collect it in the form
|
|
session_result = create_session(service_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)}"} |