From d6e7309e857e637090755d59398a7a462fc5916f Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 22 Apr 2026 13:13:36 +0800 Subject: [PATCH] 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"} --- json/sessions.json | 23 +++++++++ wwwroot/hermes_services/list/index.dspy | 33 +++++++++++++ wwwroot/new_session.ui | 64 ++++--------------------- 3 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 json/sessions.json create mode 100644 wwwroot/hermes_services/list/index.dspy diff --git a/json/sessions.json b/json/sessions.json new file mode 100644 index 0000000..7b3c33e --- /dev/null +++ b/json/sessions.json @@ -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": [] + } +} \ No newline at end of file diff --git a/wwwroot/hermes_services/list/index.dspy b/wwwroot/hermes_services/list/index.dspy new file mode 100644 index 0000000..734df8c --- /dev/null +++ b/wwwroot/hermes_services/list/index.dspy @@ -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)) \ No newline at end of file diff --git a/wwwroot/new_session.ui b/wwwroot/new_session.ui index 6c46e39..7452d30 100644 --- a/wwwroot/new_session.ui +++ b/wwwroot/new_session.ui @@ -24,9 +24,9 @@ { "name": "service_id", "label": "Service", - "uitype": "select", + "uitype": "code", "required": true, - "data_url": "/hermes-web-cli/hermes_services/" + "data_url": "/hermes-web-cli/hermes_services/list/" }, { "name": "initial_message", @@ -35,60 +35,16 @@ "required": true, "placeholder": "Enter your initial message to start the conversation..." } - ] - } - }, - { - "widgettype": "HBox", - "options": { - "width": "100%", - "height": "auto", - "marginTop": "20px", - "gap": "10px" + ], + "submit_url": "/hermes-web-cli/sessions/", + "method": "POST" }, - "subwidgets": [ + "binds": [ { - "widgettype": "Button", - "options": { - "icon": "fa fa-plus", - "backgroundColor": "#22C55E", - "color": "#FFFFFF", - "border": "none", - "borderRadius": "6px", - "padding": "10px 20px", - "label": "Create Session" - }, - "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": { - "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" - } - ] + "wid": "self", + "event": "submited", + "actiontype": "script", + "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'); }" } ] }