Compare commits
No commits in common. "5d4e70da8e42d476a3f2235257764285310002ec" and "526151b901bb1576aa7793c0b9f1ed7e66f27aa4" have entirely different histories.
5d4e70da8e
...
526151b901
@ -149,81 +149,6 @@ def get_session_messages(session_id: str) -> List[Dict]:
|
||||
print(f"Error getting session messages: {e}")
|
||||
return []
|
||||
|
||||
# Active sessions management
|
||||
def get_active_sessions() -> List[Dict]:
|
||||
"""Get all active sessions from database."""
|
||||
try:
|
||||
# This will be implemented using sqlor-database-module
|
||||
# Query the sessions table for active sessions
|
||||
# For now, return mock data structure that matches the UI expectations
|
||||
return [
|
||||
{
|
||||
"session_id": "sess-123456789",
|
||||
"session_name": "Customer Support Chat",
|
||||
"service_name": "Hermes Service 1",
|
||||
"message_count": 15,
|
||||
"created_at": datetime.now().isoformat(),
|
||||
"status": "active"
|
||||
},
|
||||
{
|
||||
"session_id": "sess-987654321",
|
||||
"session_name": "Technical Inquiry",
|
||||
"service_name": "Hermes Service 1",
|
||||
"message_count": 8,
|
||||
"created_at": datetime.now().isoformat(),
|
||||
"status": "active"
|
||||
}
|
||||
]
|
||||
except Exception as e:
|
||||
print(f"Error getting active sessions: {e}")
|
||||
return []
|
||||
|
||||
def get_recent_sessions(limit: int = 5) -> List[Dict]:
|
||||
"""Get recent sessions from database, ordered by creation time (most recent first)."""
|
||||
try:
|
||||
# This will be implemented using sqlor-database-module
|
||||
# Query the sessions table for recent sessions, ordered by created_at DESC
|
||||
# For now, return mock data structure that matches the UI expectations
|
||||
# The UI expects fields: session_id, service_name, last_message, created_at
|
||||
recent_sessions = [
|
||||
{
|
||||
"session_id": "sess-123456789",
|
||||
"service_name": "Hermes Service 1",
|
||||
"last_message": "How can I help you today?",
|
||||
"created_at": datetime.now().isoformat()
|
||||
},
|
||||
{
|
||||
"session_id": "sess-987654321",
|
||||
"service_name": "Hermes Service 1",
|
||||
"last_message": "Thanks for your assistance!",
|
||||
"created_at": datetime.now().isoformat()
|
||||
},
|
||||
{
|
||||
"session_id": "sess-456789123",
|
||||
"service_name": "Hermes Service 2",
|
||||
"last_message": "What's the status of my request?",
|
||||
"created_at": datetime.now().isoformat()
|
||||
}
|
||||
]
|
||||
# Return only the requested number of sessions
|
||||
return recent_sessions[:limit]
|
||||
except Exception as e:
|
||||
print(f"Error getting recent sessions: {e}")
|
||||
return []
|
||||
|
||||
def get_session_by_id(session_id: str) -> Optional[Dict]:
|
||||
"""Get session details by session ID."""
|
||||
try:
|
||||
# Query database for specific session
|
||||
sessions = get_active_sessions()
|
||||
for session in sessions:
|
||||
if session.get("session_id") == session_id:
|
||||
return session
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Error getting session by ID: {e}")
|
||||
return None
|
||||
|
||||
# Utility functions for validation
|
||||
def validate_service_url(url: str) -> bool:
|
||||
"""Validate if a URL is a valid Hermes service endpoint."""
|
||||
@ -252,9 +177,6 @@ __all__ = [
|
||||
'create_session',
|
||||
'send_message_to_service',
|
||||
'get_session_messages',
|
||||
'get_active_sessions',
|
||||
'get_recent_sessions',
|
||||
'get_session_by_id',
|
||||
'validate_service_url',
|
||||
'generate_session_id',
|
||||
'MODULE_NAME',
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
{
|
||||
"tblname": "sessions",
|
||||
"alias": "active_sessions",
|
||||
"title": "Active Sessions",
|
||||
"params": {
|
||||
"sortby": ["created_at desc"],
|
||||
"confidential_fields": [],
|
||||
"browserfields": {
|
||||
"exclouded": ["id", "user_id", "updated_at"]
|
||||
},
|
||||
"editexclouded": ["id", "session_id", "service_id", "message_count", "created_at", "updated_at", "user_id"],
|
||||
"subtables": []
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
{
|
||||
"summary": [
|
||||
{
|
||||
"name": "sessions",
|
||||
"title": "Active Sessions",
|
||||
"primary": "id",
|
||||
"catelog": "entity"
|
||||
}
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"name": "id",
|
||||
"title": "Session ID",
|
||||
"type": "str",
|
||||
"length": 32,
|
||||
"nullable": "no",
|
||||
"comments": "Primary key - UUID format"
|
||||
},
|
||||
{
|
||||
"name": "session_id",
|
||||
"title": "Session ID (External)",
|
||||
"type": "str",
|
||||
"length": 64,
|
||||
"nullable": "no",
|
||||
"comments": "External session identifier from Hermes service"
|
||||
},
|
||||
{
|
||||
"name": "session_name",
|
||||
"title": "Session Name",
|
||||
"type": "str",
|
||||
"length": 255,
|
||||
"nullable": "yes",
|
||||
"comments": "User-friendly session name"
|
||||
},
|
||||
{
|
||||
"name": "service_id",
|
||||
"title": "Service ID",
|
||||
"type": "str",
|
||||
"length": 32,
|
||||
"nullable": "no",
|
||||
"comments": "Reference to hermes_services table"
|
||||
},
|
||||
{
|
||||
"name": "service_name",
|
||||
"title": "Service Name",
|
||||
"type": "str",
|
||||
"length": 255,
|
||||
"nullable": "no",
|
||||
"comments": "Name of the Hermes service"
|
||||
},
|
||||
{
|
||||
"name": "message_count",
|
||||
"title": "Message Count",
|
||||
"type": "long",
|
||||
"nullable": "no",
|
||||
"default": "0",
|
||||
"comments": "Number of messages in the session"
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"title": "Created At",
|
||||
"type": "timestamp",
|
||||
"nullable": "no",
|
||||
"comments": "Session creation timestamp"
|
||||
},
|
||||
{
|
||||
"name": "updated_at",
|
||||
"title": "Updated At",
|
||||
"type": "timestamp",
|
||||
"nullable": "no",
|
||||
"comments": "Last update timestamp"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"title": "Status",
|
||||
"type": "str",
|
||||
"length": 32,
|
||||
"nullable": "no",
|
||||
"default": "active",
|
||||
"comments": "Session status: active, inactive, archived"
|
||||
},
|
||||
{
|
||||
"name": "user_id",
|
||||
"title": "User ID",
|
||||
"type": "str",
|
||||
"length": 32,
|
||||
"nullable": "yes",
|
||||
"comments": "Associated user ID for RBAC"
|
||||
}
|
||||
],
|
||||
"indexes": [
|
||||
{
|
||||
"name": "idx_sessions_service_id",
|
||||
"idxtype": "index",
|
||||
"idxfields": ["service_id"]
|
||||
},
|
||||
{
|
||||
"name": "idx_sessions_status",
|
||||
"idxtype": "index",
|
||||
"idxfields": ["status"]
|
||||
},
|
||||
{
|
||||
"name": "idx_sessions_user_id",
|
||||
"idxtype": "index",
|
||||
"idxfields": ["user_id"]
|
||||
},
|
||||
{
|
||||
"name": "idx_sessions_created_at",
|
||||
"idxtype": "index",
|
||||
"idxfields": ["created_at"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script for hermes-web-cli recent sessions functionality.
|
||||
This script simulates the .dspy file execution to verify it works correctly.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
# Add the module directory to Python path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'hermes_web_cli'))
|
||||
|
||||
try:
|
||||
from hermes_web_cli.init import get_recent_sessions
|
||||
|
||||
def test_recent_sessions():
|
||||
"""Test the get_recent_sessions function."""
|
||||
print("Testing get_recent_sessions function...")
|
||||
sessions = get_recent_sessions(limit=5)
|
||||
print(f"Retrieved {len(sessions)} recent sessions:")
|
||||
for i, session in enumerate(sessions, 1):
|
||||
print(f" {i}. Session ID: {session.get('session_id')}")
|
||||
print(f" Service: {session.get('service_name')}")
|
||||
print(f" Last Message: {session.get('last_message')[:50]}...")
|
||||
print(f" Created: {session.get('created_at')[:19]}")
|
||||
print()
|
||||
|
||||
# Test the .dspy file output format
|
||||
result = {
|
||||
"status": "success",
|
||||
"data": sessions,
|
||||
"total": len(sessions)
|
||||
}
|
||||
print("Expected .dspy output format:")
|
||||
print(json.dumps(result, indent=2, ensure_ascii=False))
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error during testing: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_recent_sessions()
|
||||
sys.exit(0 if success else 1)
|
||||
@ -1,102 +0,0 @@
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"padding": "20px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "Add New Service",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "add-service-form",
|
||||
"options": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "name",
|
||||
"label": "Service Name",
|
||||
"uitype": "str",
|
||||
"required": true,
|
||||
"placeholder": "Enter service name"
|
||||
},
|
||||
{
|
||||
"name": "url",
|
||||
"label": "Service URL",
|
||||
"uitype": "str",
|
||||
"required": true,
|
||||
"placeholder": "http://localhost:8080"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"label": "Description",
|
||||
"uitype": "str",
|
||||
"placeholder": "Optional description"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "auto",
|
||||
"marginTop": "20px",
|
||||
"gap": "10px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Add Service",
|
||||
"icon": "fa fa-plus",
|
||||
"backgroundColor": "#22C55E",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "const formData = bricks.app.get_widget('add-service-form').get_data(); if (formData.name && formData.url) { fetch('/hermes-web-cli/services', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(response => response.json()).then(data => { bricks.app.load_widget('{{entire_url(\"services.ui\")}}', 'main-content', 'replace'); }); }"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Cancel",
|
||||
"backgroundColor": "#64748B",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "urlwidget",
|
||||
"target": "main-content",
|
||||
"options": {
|
||||
"url": "{{entire_url('services.ui')}}"
|
||||
},
|
||||
"mode": "replace"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"style": {
|
||||
"padding": "20px"
|
||||
}
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "Edit Service",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"style": {
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "edit-service-form",
|
||||
"options": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "name",
|
||||
"label": "Service Name",
|
||||
"uitype": "str",
|
||||
"required": true,
|
||||
"placeholder": "Enter service name"
|
||||
},
|
||||
{
|
||||
"name": "url",
|
||||
"label": "Service URL",
|
||||
"uitype": "str",
|
||||
"required": true,
|
||||
"placeholder": "http://localhost:8080"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"label": "Description",
|
||||
"uitype": "str",
|
||||
"placeholder": "Optional description"
|
||||
}
|
||||
],
|
||||
"data_url": "/hermes-web-cli/services/{{query.service_id}}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "auto",
|
||||
"style": {
|
||||
"marginTop": "20px",
|
||||
"gap": "10px"
|
||||
}
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Update Service",
|
||||
"icon": "fa fa-save",
|
||||
"style": {
|
||||
"backgroundColor": "#3B82F6",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
}
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "const formData = bricks.app.get_widget('edit-service-form').get_data(); const serviceId = '{{query.service_id}}'; if (formData.name && formData.url) { fetch(`/hermes-web-cli/services/${serviceId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(() => { bricks.app.load_widget('{{entire_url(\"services.ui\")}}', 'main-content', 'replace'); }); }"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Cancel",
|
||||
"style": {
|
||||
"backgroundColor": "#64748B",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
}
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "urlwidget",
|
||||
"target": "main-content",
|
||||
"options": {
|
||||
"url": "{{entire_url('services.ui')}}"
|
||||
},
|
||||
"mode": "replace"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -3,92 +3,59 @@
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"padding": "20px"
|
||||
"style": {
|
||||
"padding": "20px"
|
||||
}
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "Create New Session",
|
||||
"text": "New Session",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
"style": {
|
||||
"marginBottom": "24px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "new-session-form",
|
||||
"options": {
|
||||
"title": "Create New AI Session",
|
||||
"description": "Start a new conversation with your Hermes AI agent by selecting a service and providing an initial message.",
|
||||
"fields": [
|
||||
{
|
||||
"name": "service_id",
|
||||
"label": "Service",
|
||||
"label": "Hermes Service",
|
||||
"uitype": "select",
|
||||
"required": true,
|
||||
"data_url": "/hermes-web-cli/services/list"
|
||||
"options_url": "/hermes-web-cli/services/list"
|
||||
},
|
||||
{
|
||||
"name": "initial_message",
|
||||
"label": "Initial Message",
|
||||
"uitype": "textarea",
|
||||
"uitype": "text",
|
||||
"required": true,
|
||||
"placeholder": "Enter your initial message to start the conversation..."
|
||||
"placeholder": "Enter your first message to the AI agent..."
|
||||
},
|
||||
{
|
||||
"name": "session_name",
|
||||
"label": "Session Name (Optional)",
|
||||
"uitype": "str",
|
||||
"placeholder": "Give your session a name for easy reference"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "auto",
|
||||
"marginTop": "20px",
|
||||
"gap": "10px"
|
||||
],
|
||||
"submit_url": "/hermes-web-cli/sessions",
|
||||
"method": "POST"
|
||||
},
|
||||
"subwidgets": [
|
||||
"binds": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Create Session",
|
||||
"icon": "fa fa-plus",
|
||||
"backgroundColor": "#22C55E",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "const formData = bricks.app.get_widget('new-session-form').get_data(); if (formData.service_id && formData.initial_message) { fetch('/hermes-web-cli/sessions', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(response => response.json()).then(data => { bricks.app.load_widget('{{entire_url(\"session_detail.ui\")}}?session_id=' + data.session_id, 'main-content', 'replace'); }); }"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Cancel",
|
||||
"backgroundColor": "#64748B",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "urlwidget",
|
||||
"target": "main-content",
|
||||
"options": {
|
||||
"url": "{{entire_url('index.ui')}}"
|
||||
},
|
||||
"mode": "replace"
|
||||
}
|
||||
]
|
||||
"wid": "self",
|
||||
"event": "submited",
|
||||
"actiontype": "script",
|
||||
"script": "bricks.show_resp_message_or_error(event.params).then(() => { bricks.app.load_widget('{{entire_url('index.ui')}}', 'root', 'replace'); });"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"padding": "20px"
|
||||
"style": {
|
||||
"padding": "20px"
|
||||
}
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
@ -12,55 +14,27 @@
|
||||
"text": "Hermes Services",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Add New Service",
|
||||
"icon": "fa fa-plus",
|
||||
"backgroundColor": "#22C55E",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px",
|
||||
"marginBottom": "20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "urlwidget",
|
||||
"target": "main-content",
|
||||
"options": {
|
||||
"url": "{{entire_url('add_service.ui')}}"
|
||||
},
|
||||
"mode": "replace"
|
||||
"style": {
|
||||
"marginBottom": "24px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "DataViewer",
|
||||
"options": {
|
||||
"data_url": "/hermes-web-cli/services",
|
||||
"page_rows": 10,
|
||||
"page_rows": 20,
|
||||
"row_options": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "id",
|
||||
"label": "Service ID",
|
||||
"uitype": "str"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"label": "Name",
|
||||
"label": "Service Name",
|
||||
"uitype": "str"
|
||||
},
|
||||
{
|
||||
"name": "service_url",
|
||||
"label": "URL",
|
||||
"label": "Service URL",
|
||||
"uitype": "str"
|
||||
},
|
||||
{
|
||||
@ -75,11 +49,19 @@
|
||||
},
|
||||
{
|
||||
"name": "created_at",
|
||||
"label": "Created",
|
||||
"label": "Created At",
|
||||
"uitype": "date"
|
||||
}
|
||||
]
|
||||
},
|
||||
"editable": {
|
||||
"add_icon": "fa fa-plus",
|
||||
"update_icon": "fa fa-edit",
|
||||
"delete_icon": "fa fa-trash",
|
||||
"new_data_url": "/hermes-web-cli/services",
|
||||
"update_data_url": "/hermes-web-cli/services/{id}",
|
||||
"delete_data_url": "/hermes-web-cli/services/{id}"
|
||||
},
|
||||
"toolbar": {
|
||||
"tools": [
|
||||
{
|
||||
@ -88,14 +70,9 @@
|
||||
"icon": "fa fa-plug"
|
||||
},
|
||||
{
|
||||
"name": "edit_service",
|
||||
"text": "Edit",
|
||||
"icon": "fa fa-edit"
|
||||
},
|
||||
{
|
||||
"name": "delete_service",
|
||||
"text": "Delete",
|
||||
"icon": "fa fa-trash"
|
||||
"name": "view_sessions",
|
||||
"text": "View Sessions",
|
||||
"icon": "fa fa-list"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -105,19 +82,13 @@
|
||||
"wid": "self",
|
||||
"event": "test_connection",
|
||||
"actiontype": "script",
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { fetch(`/hermes-web-cli/services/test?id=${selectedRow.id}`).then(response => response.json()).then(data => { alert(`Connection test: ${data.status_message}`); }); }"
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { fetch(`/hermes-web-cli/services/${selectedRow.id}/test`).then(resp => resp.json()).then(data => { if (data.success) { bricks.show_message({title: 'Connection Test', message: 'Service is reachable and responding.'}); } else { bricks.show_error({title: 'Connection Failed', message: data.message || 'Unable to connect to service.'}); } }); }"
|
||||
},
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "edit_service",
|
||||
"event": "view_sessions",
|
||||
"actiontype": "script",
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { const url = `{{entire_url('edit_service.ui')}}?service_id=${selectedRow.id}`; bricks.app.load_widget(url, 'main-content', 'replace'); }"
|
||||
},
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "delete_service",
|
||||
"actiontype": "script",
|
||||
"script": "const selectedRow = event.params; if (selectedRow && confirm('Are you sure you want to delete this service?')) { fetch(`/hermes-web-cli/services/${selectedRow.id}`, { method: 'DELETE' }).then(() => { this.refresh(); }); }"
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { const url = `{{entire_url('service_sessions.ui')}}?service_id=${selectedRow.id}`; bricks.app.load_widget(url, 'main-content', 'replace'); }"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/services/{id}
|
||||
|
||||
import json
|
||||
import os
|
||||
from hermes_web_cli.init import get_service_by_id
|
||||
|
||||
def main():
|
||||
"""Main function to handle the service by ID API request."""
|
||||
try:
|
||||
# Get service ID from URL path
|
||||
path_info = os.environ.get('PATH_INFO', '')
|
||||
service_id = path_info.strip('/').split('/')[-1] if path_info else ''
|
||||
|
||||
if not service_id:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Service ID is required",
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Get service by ID
|
||||
service = get_service_by_id(service_id)
|
||||
|
||||
if service:
|
||||
return {
|
||||
"status": "success",
|
||||
"data": service
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Service not found",
|
||||
"data": None
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,29 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/services
|
||||
|
||||
import json
|
||||
from hermes_web_cli.init import get_all_services
|
||||
|
||||
def main():
|
||||
"""Main function to handle the services API request."""
|
||||
try:
|
||||
# Get all services from the module
|
||||
services = get_all_services()
|
||||
|
||||
# Return as JSON response
|
||||
return {
|
||||
"status": "success",
|
||||
"data": services,
|
||||
"total": len(services)
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": [],
|
||||
"total": 0
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,37 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/services/list
|
||||
|
||||
import json
|
||||
from hermes_web_cli.init import get_all_services
|
||||
|
||||
def main():
|
||||
"""Main function to handle the services list API request for select dropdowns."""
|
||||
try:
|
||||
# Get all services from the module
|
||||
services = get_all_services()
|
||||
|
||||
# Format for select dropdown (value, label pairs)
|
||||
service_options = []
|
||||
for service in services:
|
||||
service_options.append({
|
||||
"value": service.get("id"),
|
||||
"label": service.get("name", f"Service {service.get('id')}")
|
||||
})
|
||||
|
||||
# Return as JSON response
|
||||
return {
|
||||
"status": "success",
|
||||
"data": service_options,
|
||||
"total": len(service_options)
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": [],
|
||||
"total": 0
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,56 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/services/test?id={service_id}
|
||||
|
||||
import json
|
||||
import os
|
||||
from hermes_web_cli.init import get_service_by_id, test_service_connection
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
def main():
|
||||
"""Main function to handle the service connection test API request with query parameter."""
|
||||
try:
|
||||
# Get service ID from query string
|
||||
query_string = os.environ.get('QUERY_STRING', '')
|
||||
if query_string:
|
||||
query_params = parse_qs(query_string)
|
||||
service_id = query_params.get('id', [None])[0]
|
||||
else:
|
||||
service_id = None
|
||||
|
||||
if not service_id:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Service ID is required (use ?id= parameter)",
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Get service by ID
|
||||
service = get_service_by_id(service_id)
|
||||
if not service:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Service not found",
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Test connection
|
||||
is_connected, status_message = test_service_connection(service.get("service_url", ""))
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"data": {
|
||||
"is_connected": is_connected,
|
||||
"status_message": status_message,
|
||||
"service_id": service_id
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,116 +0,0 @@
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"padding": "20px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Text",
|
||||
"options": {
|
||||
"text": "Session Details",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "DataViewer",
|
||||
"id": "session-messages",
|
||||
"options": {
|
||||
"data_url": "/hermes-web-cli/sessions/messages?session_id={{query.session_id}}",
|
||||
"page_rows": 50,
|
||||
"row_options": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "role",
|
||||
"label": "Role",
|
||||
"uitype": "str"
|
||||
},
|
||||
{
|
||||
"name": "content",
|
||||
"label": "Message",
|
||||
"uitype": "str"
|
||||
},
|
||||
{
|
||||
"name": "timestamp",
|
||||
"label": "Time",
|
||||
"uitype": "date"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "message-form",
|
||||
"options": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "message",
|
||||
"label": "Send Message",
|
||||
"uitype": "textarea",
|
||||
"placeholder": "Type your message here..."
|
||||
}
|
||||
],
|
||||
"marginTop": "20px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "auto",
|
||||
"marginTop": "10px",
|
||||
"gap": "10px"
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Send",
|
||||
"icon": "fa fa-paper-plane",
|
||||
"backgroundColor": "#22C55E",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "const formData = bricks.app.get_widget('message-form').get_data(); const sessionId = '{{query.session_id}}'; if (formData.message) { fetch(`/hermes-web-cli/sessions/messages?session_id=${sessionId}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: formData.message }) }).then(() => { bricks.app.get_widget('session-messages').refresh(); bricks.app.get_widget('message-form').clear(); }); }"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Back to Sessions",
|
||||
"backgroundColor": "#64748B",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "urlwidget",
|
||||
"target": "main-content",
|
||||
"options": {
|
||||
"url": "{{entire_url('sessions.ui')}}"
|
||||
},
|
||||
"mode": "replace"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -3,7 +3,9 @@
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"padding": "20px"
|
||||
"style": {
|
||||
"padding": "20px"
|
||||
}
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
@ -12,15 +14,17 @@
|
||||
"text": "Active Sessions",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
"style": {
|
||||
"marginBottom": "24px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "DataViewer",
|
||||
"options": {
|
||||
"data_url": "/hermes-web-cli/sessions/active",
|
||||
"page_rows": 10,
|
||||
"page_rows": 20,
|
||||
"row_options": {
|
||||
"fields": [
|
||||
{
|
||||
@ -55,17 +59,25 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"editable": {
|
||||
"add_icon": "fa fa-plus",
|
||||
"update_icon": "fa fa-edit",
|
||||
"delete_icon": "fa fa-trash",
|
||||
"new_data_url": "/hermes-web-cli/sessions",
|
||||
"update_data_url": "/hermes-web-cli/sessions/{id}",
|
||||
"delete_data_url": "/hermes-web-cli/sessions/{id}"
|
||||
},
|
||||
"toolbar": {
|
||||
"tools": [
|
||||
{
|
||||
"name": "open_session",
|
||||
"text": "Open",
|
||||
"icon": "fa fa-folder-open"
|
||||
"text": "Open Chat",
|
||||
"icon": "fa fa-comments"
|
||||
},
|
||||
{
|
||||
"name": "delete_session",
|
||||
"text": "Delete",
|
||||
"icon": "fa fa-trash"
|
||||
"name": "export_session",
|
||||
"text": "Export",
|
||||
"icon": "fa fa-download"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -75,13 +87,13 @@
|
||||
"wid": "self",
|
||||
"event": "open_session",
|
||||
"actiontype": "script",
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { const url = `{{entire_url('session_detail.ui')}}?session_id=${selectedRow.session_id}`; bricks.app.load_widget(url, 'main-content', 'replace'); }"
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { const url = `{{entire_url('session_chat.ui')}}?session_id=${selectedRow.session_id}`; bricks.app.load_widget(url, 'main-content', 'replace'); }"
|
||||
},
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "delete_session",
|
||||
"event": "export_session",
|
||||
"actiontype": "script",
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { fetch(`/hermes-web-cli/sessions/${selectedRow.session_id}`, { method: 'DELETE' }).then(() => { this.refresh(); }); }"
|
||||
"script": "const selectedRow = event.params; if (selectedRow) { window.location.href = `/hermes-web-cli/sessions/${selectedRow.session_id}/export`; }"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/sessions/active
|
||||
|
||||
import json
|
||||
from hermes_web_cli.init import get_active_sessions
|
||||
|
||||
def main():
|
||||
"""Main function to handle the active sessions API request."""
|
||||
try:
|
||||
# Get active sessions from the module
|
||||
sessions = get_active_sessions()
|
||||
|
||||
# Return as JSON response
|
||||
return {
|
||||
"status": "success",
|
||||
"data": sessions,
|
||||
"total": len(sessions)
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": [],
|
||||
"total": 0
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,45 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/sessions/{id}
|
||||
|
||||
import json
|
||||
import os
|
||||
from hermes_web_cli.init import get_session_by_id
|
||||
|
||||
def main():
|
||||
"""Main function to handle the session by ID API request."""
|
||||
try:
|
||||
# Get session ID from URL path
|
||||
path_info = os.environ.get('PATH_INFO', '')
|
||||
session_id = path_info.strip('/').split('/')[-1] if path_info else ''
|
||||
|
||||
if not session_id:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Session ID is required",
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Get session by ID
|
||||
session = get_session_by_id(session_id)
|
||||
|
||||
if session:
|
||||
return {
|
||||
"status": "success",
|
||||
"data": session
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Session not found",
|
||||
"data": None
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,60 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/sessions (POST to create)
|
||||
|
||||
import json
|
||||
import os
|
||||
from hermes_web_cli.init import create_session
|
||||
|
||||
def main():
|
||||
"""Main function to handle the create session API request."""
|
||||
try:
|
||||
# Get request method
|
||||
request_method = os.environ.get('REQUEST_METHOD', 'GET')
|
||||
|
||||
if request_method == 'POST':
|
||||
# Read POST data from stdin
|
||||
content_length = int(os.environ.get('CONTENT_LENGTH', 0))
|
||||
if content_length > 0:
|
||||
post_data = json.loads(os.read(0, content_length).decode('utf-8'))
|
||||
service_id = post_data.get('service_id')
|
||||
initial_message = post_data.get('initial_message')
|
||||
|
||||
if not service_id or not initial_message:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "service_id and initial_message are required",
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Create session
|
||||
session_id = create_session(service_id, initial_message)
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"data": {
|
||||
"session_id": session_id,
|
||||
"service_id": service_id
|
||||
}
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "No POST data provided",
|
||||
"data": None
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Method not allowed",
|
||||
"data": None
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,79 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/sessions/messages?session_id={session_id}
|
||||
|
||||
import json
|
||||
import os
|
||||
from hermes_web_cli.init import get_session_messages, send_message_to_service
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
def main():
|
||||
"""Main function to handle the session messages API request with query parameter."""
|
||||
try:
|
||||
# Get session ID from query string
|
||||
query_string = os.environ.get('QUERY_STRING', '')
|
||||
if query_string:
|
||||
query_params = parse_qs(query_string)
|
||||
session_id = query_params.get('session_id', [None])[0]
|
||||
else:
|
||||
session_id = None
|
||||
|
||||
if not session_id:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Session ID is required (use ?session_id= parameter)",
|
||||
"data": None
|
||||
}
|
||||
|
||||
request_method = os.environ.get('REQUEST_METHOD', 'GET')
|
||||
|
||||
if request_method == 'GET':
|
||||
# Get session messages
|
||||
messages = get_session_messages(session_id)
|
||||
return {
|
||||
"status": "success",
|
||||
"data": messages,
|
||||
"total": len(messages)
|
||||
}
|
||||
|
||||
elif request_method == 'POST':
|
||||
# Send new message
|
||||
content_length = int(os.environ.get('CONTENT_LENGTH', 0))
|
||||
if content_length > 0:
|
||||
post_data = json.loads(os.read(0, content_length).decode('utf-8'))
|
||||
message = post_data.get('message')
|
||||
|
||||
if not message:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Message content is required",
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Here you would get the service_id from the session and send the message
|
||||
# For now, just return success (in real implementation, call send_message_to_service)
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Message sent successfully"
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "No message data provided"
|
||||
}
|
||||
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Method not allowed"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,29 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/sessions/recent
|
||||
|
||||
import json
|
||||
from hermes_web_cli.init import get_recent_sessions
|
||||
|
||||
def main():
|
||||
"""Main function to handle the recent sessions API request."""
|
||||
try:
|
||||
# Get recent sessions from the module
|
||||
sessions = get_recent_sessions(limit=5)
|
||||
|
||||
# Return as JSON response
|
||||
return {
|
||||
"status": "success",
|
||||
"data": sessions,
|
||||
"total": len(sessions)
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": [],
|
||||
"total": 0
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,29 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/sessions/recent
|
||||
|
||||
import json
|
||||
from hermes_web_cli.init import get_recent_sessions
|
||||
|
||||
def main():
|
||||
"""Main function to handle the recent sessions API request."""
|
||||
try:
|
||||
# Get recent sessions from the module (limit to 5 as expected by the UI)
|
||||
sessions = get_recent_sessions(limit=5)
|
||||
|
||||
# Return as JSON response
|
||||
return {
|
||||
"status": "success",
|
||||
"data": sessions,
|
||||
"total": len(sessions)
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": [],
|
||||
"total": 0
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -3,7 +3,9 @@
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"padding": "20px"
|
||||
"style": {
|
||||
"padding": "20px"
|
||||
}
|
||||
},
|
||||
"subwidgets": [
|
||||
{
|
||||
@ -12,89 +14,56 @@
|
||||
"text": "Settings",
|
||||
"fontSize": "24px",
|
||||
"fontWeight": "bold",
|
||||
"marginBottom": "20px",
|
||||
"color": "#F8FAFC"
|
||||
"style": {
|
||||
"marginBottom": "24px",
|
||||
"color": "#F8FAFC"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "Form",
|
||||
"id": "settings-form",
|
||||
"options": {
|
||||
"title": "Hermes Web CLI Configuration",
|
||||
"description": "Configure your Hermes Web CLI preferences and default settings.",
|
||||
"fields": [
|
||||
{
|
||||
"name": "default_service",
|
||||
"label": "Default Service",
|
||||
"uitype": "select",
|
||||
"data_url": "/hermes-web-cli/services/list"
|
||||
"options_url": "/hermes-web-cli/services/list"
|
||||
},
|
||||
{
|
||||
"name": "auto_save_sessions",
|
||||
"label": "Auto-save Sessions",
|
||||
"uitype": "bool",
|
||||
"uitype": "check",
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "session_timeout_minutes",
|
||||
"label": "Session Timeout (minutes)",
|
||||
"name": "max_session_history",
|
||||
"label": "Max Session History Days",
|
||||
"uitype": "int",
|
||||
"default": 60
|
||||
"default": 30
|
||||
},
|
||||
{
|
||||
"name": "max_concurrent_sessions",
|
||||
"label": "Max Concurrent Sessions",
|
||||
"uitype": "int",
|
||||
"default": 10
|
||||
"name": "theme",
|
||||
"label": "Theme",
|
||||
"uitype": "select",
|
||||
"options": [
|
||||
{"value": "dark", "text": "Dark"},
|
||||
{"value": "light", "text": "Light"}
|
||||
],
|
||||
"default": "dark"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"widgettype": "HBox",
|
||||
"options": {
|
||||
"width": "100%",
|
||||
"height": "auto",
|
||||
"marginTop": "20px",
|
||||
"gap": "10px"
|
||||
],
|
||||
"submit_url": "/hermes-web-cli/settings",
|
||||
"method": "POST"
|
||||
},
|
||||
"subwidgets": [
|
||||
"binds": [
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Save Settings",
|
||||
"icon": "fa fa-save",
|
||||
"backgroundColor": "#3B82F6",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "const formData = bricks.app.get_widget('settings-form').get_data(); fetch('/hermes-web-cli/settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(() => { alert('Settings saved successfully!'); });"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {
|
||||
"text": "Reset to Defaults",
|
||||
"backgroundColor": "#EF4444",
|
||||
"color": "#FFFFFF",
|
||||
"border": "none",
|
||||
"borderRadius": "6px",
|
||||
"padding": "10px 20px"
|
||||
},
|
||||
"binds": [
|
||||
{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "if (confirm('Are you sure you want to reset all settings to defaults?')) { fetch('/hermes-web-cli/settings/reset', { method: 'POST' }).then(() => { bricks.app.get_widget('settings-form').load_data(); alert('Settings reset to defaults!'); }); }"
|
||||
}
|
||||
]
|
||||
"wid": "self",
|
||||
"event": "submited",
|
||||
"actiontype": "script",
|
||||
"script": "bricks.show_resp_message_or_error(event.params);"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/settings
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
def main():
|
||||
"""Main function to handle the settings API request."""
|
||||
try:
|
||||
request_method = os.environ.get('REQUEST_METHOD', 'GET')
|
||||
|
||||
if request_method == 'GET':
|
||||
# Return current settings (mock data for now)
|
||||
settings = {
|
||||
"default_service": "service-1",
|
||||
"auto_save_sessions": True,
|
||||
"session_timeout_minutes": 60,
|
||||
"max_concurrent_sessions": 10
|
||||
}
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"data": settings
|
||||
}
|
||||
|
||||
elif request_method == 'POST':
|
||||
# Update settings
|
||||
content_length = int(os.environ.get('CONTENT_LENGTH', 0))
|
||||
if content_length > 0:
|
||||
post_data = json.loads(os.read(0, content_length).decode('utf-8'))
|
||||
# Here you would save the settings to database or config file
|
||||
# For now, just return success
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Settings updated successfully"
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "No settings data provided"
|
||||
}
|
||||
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Method not allowed"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
@ -1,35 +0,0 @@
|
||||
# This is a controlled Python script (.dspy file) that will be executed by the web framework
|
||||
# It provides the API endpoint for /hermes-web-cli/settings/reset
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
def main():
|
||||
"""Main function to handle the reset settings API request."""
|
||||
try:
|
||||
request_method = os.environ.get('REQUEST_METHOD', 'GET')
|
||||
|
||||
if request_method == 'POST':
|
||||
# Reset settings to defaults
|
||||
# Here you would reset settings in database or config file
|
||||
# For now, just return success
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Settings reset to defaults successfully"
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "Method not allowed"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": str(e),
|
||||
"data": None
|
||||
}
|
||||
|
||||
# Execute and return JSON response
|
||||
result = main()
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
Loading…
x
Reference in New Issue
Block a user