fix(hermes-web-cli): correct new_session.ui implementation

- Change service_id field uitype from 'select' to 'code' (bricks has no select type)
- Create hermes_services/list/index.dspy endpoint to provide service list data for code component
- Use Form's built-in submit/cancel buttons instead of manual Button widgets
- Add sessions.json CRUD definition for session management
- Ensure proper data format for code component: {"value": "id", "text": "name"}
This commit is contained in:
yumoqing 2026-04-22 13:13:36 +08:00
parent 450820d9ed
commit d6e7309e85
3 changed files with 66 additions and 54 deletions

23
json/sessions.json Normal file
View File

@ -0,0 +1,23 @@
{
"tblname": "sessions",
"title": "Sessions",
"params": {
"sortby": ["created_at desc"],
"confidential_fields": [],
"browserfields": {
"exclouded": ["id", "user_id", "session_data", "updated_at"],
"alters": {
"status": {
"uitype": "code",
"data": [
{"value": "active", "text": "Active"},
{"value": "closed", "text": "Closed"},
{"value": "expired", "text": "Expired"}
]
}
}
},
"editexclouded": ["id", "user_id", "message_count", "created_at", "updated_at", "closed_at"],
"subtables": []
}
}

View File

@ -0,0 +1,33 @@
# Get hermes_services list for code dropdown
# This .dspy file uses functions released by load_hermes_web_cli()
def main():
"""Get hermes_services records for code component dropdown."""
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 {
"status": "success",
"data": result,
"total": len(result)
}
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

@ -24,9 +24,9 @@
{ {
"name": "service_id", "name": "service_id",
"label": "Service", "label": "Service",
"uitype": "select", "uitype": "code",
"required": true, "required": true,
"data_url": "/hermes-web-cli/hermes_services/" "data_url": "/hermes-web-cli/hermes_services/list/"
}, },
{ {
"name": "initial_message", "name": "initial_message",
@ -35,60 +35,16 @@
"required": true, "required": true,
"placeholder": "Enter your initial message to start the conversation..." "placeholder": "Enter your initial message to start the conversation..."
} }
] ],
} "submit_url": "/hermes-web-cli/sessions/",
}, "method": "POST"
{
"widgettype": "HBox",
"options": {
"width": "100%",
"height": "auto",
"marginTop": "20px",
"gap": "10px"
},
"subwidgets": [
{
"widgettype": "Button",
"options": {
"icon": "fa fa-plus",
"backgroundColor": "#22C55E",
"color": "#FFFFFF",
"border": "none",
"borderRadius": "6px",
"padding": "10px 20px",
"label": "Create Session"
}, },
"binds": [ "binds": [
{ {
"wid": "self", "wid": "self",
"event": "click", "event": "submited",
"actiontype": "script", "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'); }); }" "script": "const data = event.params; if (data && data.session_id) { bricks.app.load_widget('{{entire_url(\"session_detail.ui\")}}?session_id=' + data.session_id, 'main-content', 'replace'); }"
}
]
},
{
"widgettype": "Button",
"options": {
"backgroundColor": "#64748B",
"color": "#FFFFFF",
"border": "none",
"borderRadius": "6px",
"padding": "10px 20px",
"label": "Cancel"
},
"binds": [
{
"wid": "self",
"event": "click",
"actiontype": "urlwidget",
"target": "main-content",
"options": {
"url": "{{entire_url('index.ui')}}"
},
"mode": "replace"
}
]
} }
] ]
} }