Fix new_session.ui: Use uitype instead of widgettype in Form fields, and implement proper Form toolbar actions

This commit is contained in:
yumoqing 2026-04-22 17:49:07 +08:00
parent 14ed67907a
commit c898c9eef1

View File

@ -25,7 +25,7 @@
"maxWidth": "600px", "maxWidth": "600px",
"fields": [ "fields": [
{ {
"widgettype": "UiStr", "uitype": "str",
"name": "session-name", "name": "session-name",
"label": "Session Name", "label": "Session Name",
"placeholder": "Enter session name...", "placeholder": "Enter session name...",
@ -33,7 +33,7 @@
"marginBottom": "16px" "marginBottom": "16px"
}, },
{ {
"widgettype": "UiStr", "uitype": "str",
"name": "model-select", "name": "model-select",
"label": "AI Model", "label": "AI Model",
"placeholder": "Enter model name or ID...", "placeholder": "Enter model name or ID...",
@ -41,7 +41,7 @@
"marginBottom": "16px" "marginBottom": "16px"
}, },
{ {
"widgettype": "UiText", "uitype": "text",
"name": "initial-prompt", "name": "initial-prompt",
"label": "Initial Prompt (Optional)", "label": "Initial Prompt (Optional)",
"placeholder": "Enter initial context or instructions...", "placeholder": "Enter initial context or instructions...",
@ -49,59 +49,52 @@
"height": "100px", "height": "100px",
"marginBottom": "24px" "marginBottom": "24px"
} }
] ],
} "toolbar": {
}, "tools": [
{
"widgettype": "HBox",
"options": {
"width": "100%",
"gap": "12px"
},
"subwidgets": [
{
"widgettype": "Button",
"options": {
"label": "Create Session",
"bgcolor": "#22C55E",
"color": "#FFFFFF",
"border": "none",
"borderRadius": "6px",
"padding": "10px 20px",
"fontWeight": "600"
},
"binds": [
{
"wid": "self",
"event": "click",
"actiontype": "script",
"script": "const formData = bricks.getWidgetById('app.new-session-form').getData(); if (!formData['session-name']) { bricks.showMessage('Please enter a session name', 'error'); return; } if (!formData['model-select']) { bricks.showMessage('Please enter an AI model', 'error'); return; } fetch('/hermes-web-cli/sessions/create/', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(response => response.json()).then(result => { if (result.success) { bricks.showMessage('Session created successfully', 'success'); bricks.getWidgetById('app.main-content').loadURL(bricks.entire_url('sessions.ui')); } else { bricks.showMessage(result.error || 'Failed to create session', 'error'); } }).catch(error => { bricks.showMessage('Network error: ' + error.message, 'error'); });"
}
]
},
{
"widgettype": "Button",
"options": {
"label": "Cancel",
"bgcolor": "#64748B",
"color": "#FFFFFF",
"border": "none",
"borderRadius": "6px",
"padding": "10px 20px"
},
"binds": [
{ {
"wid": "self", "label": "Create Session",
"event": "click", "bgcolor": "#22C55E",
"actiontype": "urlwidget", "color": "#FFFFFF",
"target": "app.main-content", "border": "none",
"options": { "borderRadius": "6px",
"url": "{{entire_url('index.ui')}}" "padding": "10px 20px",
}, "fontWeight": "600",
"mode": "replace" "action": "create_session"
},
{
"label": "Cancel",
"bgcolor": "#64748B",
"color": "#FFFFFF",
"border": "none",
"borderRadius": "6px",
"padding": "10px 20px",
"action": "cancel"
} }
] ]
} }
},
"binds": [
{
"wid": "self",
"event": "create_session",
"actiontype": "registerfunction",
"target": "app.new-session-container",
"rfname": "create_session",
"params": {
"form_data": "{{ 'new-session-form'.data }}"
}
},
{
"wid": "self",
"event": "cancel",
"actiontype": "urlwidget",
"target": "app.main-content",
"options": {
"url": "{{entire_url('index.ui')}}"
},
"mode": "replace"
}
] ]
} }
] ]