Remove new-session.js: implement form handling inline using script actiontype, simplify model selection to text input
This commit is contained in:
parent
7daf801c99
commit
63a3d3be59
@ -1,73 +0,0 @@
|
|||||||
// Register function for creating new sessions
|
|
||||||
bricks.RF.register('create_session', async function(params) {
|
|
||||||
try {
|
|
||||||
// Get form data from the new session form using correct API
|
|
||||||
const formWidget = bricks.getWidgetById('app.new-session-form');
|
|
||||||
const formData = formWidget ? formWidget.getData() : {};
|
|
||||||
|
|
||||||
if (!formData['session-name']) {
|
|
||||||
bricks.showMessage('Please enter a session name', 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!formData['model-select']) {
|
|
||||||
bricks.showMessage('Please select an AI model', 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch('/hermes-web-cli/sessions/create/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
'session-name': formData['session-name'],
|
|
||||||
'model-select': formData['model-select'],
|
|
||||||
'initial-prompt': formData['initial-prompt'] || ''
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
bricks.showMessage('Session created successfully', 'success');
|
|
||||||
// Navigate back to sessions list
|
|
||||||
const mainContent = bricks.getWidgetById('app.main-content');
|
|
||||||
if (mainContent) {
|
|
||||||
mainContent.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');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load available models for the model select dropdown
|
|
||||||
async function loadModelsForNewSession() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/hermes-web-cli/models/list/');
|
|
||||||
const models = await response.json();
|
|
||||||
|
|
||||||
if (Array.isArray(models)) {
|
|
||||||
const modelSelect = bricks.getWidgetById('app.model-select');
|
|
||||||
if (modelSelect && modelSelect.options) {
|
|
||||||
// Format models as items for UiCode component
|
|
||||||
const modelItems = models.map(model => ({
|
|
||||||
label: model.name || model.model_name,
|
|
||||||
value: model.id || model.model_id
|
|
||||||
}));
|
|
||||||
modelSelect.options.items = modelItems;
|
|
||||||
modelSelect.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load models:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-load models when the new session form is loaded
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// Try to load models after a short delay to ensure widgets are ready
|
|
||||||
setTimeout(loadModelsForNewSession, 100);
|
|
||||||
});
|
|
||||||
@ -33,13 +33,12 @@
|
|||||||
"marginBottom": "16px"
|
"marginBottom": "16px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"widgettype": "UiCode",
|
"widgettype": "UiStr",
|
||||||
"name": "model-select",
|
"name": "model-select",
|
||||||
"label": "AI Model",
|
"label": "AI Model",
|
||||||
"placeholder": "Select model...",
|
"placeholder": "Enter model name or ID...",
|
||||||
"width": "100%",
|
"width": "100%",
|
||||||
"marginBottom": "16px",
|
"marginBottom": "16px"
|
||||||
"items": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"widgettype": "UiText",
|
"widgettype": "UiText",
|
||||||
@ -72,13 +71,11 @@
|
|||||||
"fontWeight": "600"
|
"fontWeight": "600"
|
||||||
},
|
},
|
||||||
"binds": [
|
"binds": [
|
||||||
{
|
{
|
||||||
"wid": "self",
|
"wid": "self",
|
||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "registerfunction",
|
"actiontype": "script",
|
||||||
"target": "app.new-session-container",
|
"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'); });"
|
||||||
"rfname": "create_session",
|
|
||||||
"params": {}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user