fix: 删除不必要的手动.dspy端点,修正new_session.ui使用标准CRUD端点和textField/valueField参数

This commit is contained in:
yumoqing 2026-04-22 13:20:47 +08:00
parent 51f9776f40
commit 7d55ef7548
16 changed files with 3 additions and 631 deletions

Binary file not shown.

View File

@ -1,20 +0,0 @@
# Get hermes_services list for code dropdown
# This .dspy file uses functions released by load_hermes_web_cli()
try:
# Use the function provided by hermes-web-cli module
services = get_all_services()
# Format for code component (value, text pairs)
result = []
for service in services:
result.append({
"value": str(service.get('id')),
"text": service.get('name', f"Service {service.get('id')}")
})
# Return array directly for code component
return result
except Exception as e:
# On error or no data, return empty array
return []

View File

@ -26,7 +26,9 @@
"label": "Service",
"uitype": "code",
"required": true,
"data_url": "/hermes-web-cli/hermes_services/list/"
"data_url": "/hermes-web-cli/hermes_services/",
"textField": "name",
"valueField": "id"
},
{
"name": "initial_message",

View File

@ -1,79 +0,0 @@
# hermes-web-cli renew.dspy
# Business logic for service renewal and management
import json
from datetime import datetime, timedelta
def get_service_info(service_id: str) -> dict:
"""Get detailed service information including status and usage stats"""
# This function will be called by the .ui files through data_url
from hermes_web_cli.init import get_service_by_id
service = get_service_by_id(service_id)
if not service:
return {"error": "Service not found"}
# Add additional info like usage stats, renewal date, etc.
service_info = service.copy()
service_info.update({
"renewal_date": (datetime.now() + timedelta(days=30)).isoformat(),
"usage_stats": {
"total_sessions": 150,
"active_sessions": 12,
"api_calls_today": 2340
}
})
return service_info
def renew_service(service_id: str, renewal_period: str = "monthly") -> dict:
"""Renew a Hermes service subscription"""
from hermes_web_cli.init import get_service_by_id
service = get_service_by_id(service_id)
if not service:
return {"success": False, "error": "Service not found"}
# Calculate new renewal date based on period
now = datetime.now()
if renewal_period == "monthly":
new_renewal = now + timedelta(days=30)
elif renewal_period == "yearly":
new_renewal = now + timedelta(days=365)
else:
new_renewal = now + timedelta(days=30)
# Update service in database (placeholder)
renewed_service = service.copy()
renewed_service.update({
"renewal_date": new_renewal.isoformat(),
"status": "active",
"last_renewed": now.isoformat()
})
return {"success": True, "service": renewed_service}
def get_renewal_options() -> list:
"""Get available renewal options"""
return [
{"id": "monthly", "name": "月度续费", "price": "¥299/月"},
{"id": "quarterly", "name": "季度续费", "price": "¥799/季"},
{"id": "yearly", "name": "年度续费", "price": "¥2899/年"}
]
def validate_renewal_request(service_id: str, payment_method: str) -> dict:
"""Validate renewal request before processing"""
from hermes_web_cli.init import get_service_by_id
service = get_service_by_id(service_id)
if not service:
return {"valid": False, "error": "Service not found"}
if payment_method not in ["credit_card", "alipay", "wechat_pay"]:
return {"valid": False, "error": "Invalid payment method"}
return {"valid": True, "service_name": service["name"]}
# Module exports for template access
__all__ = [
'get_service_info',
'renew_service',
'get_renewal_options',
'validate_renewal_request'
]

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))