Fix new_session.ui: correct URL reference and implement create_session functionality with proper registerfunction binding
This commit is contained in:
parent
73b833c1c3
commit
82a58be972
72
wwwroot/new-session.js
Normal file
72
wwwroot/new-session.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// Register function for creating new sessions
|
||||||
|
bricks.RF.register('create_session', async function(params) {
|
||||||
|
try {
|
||||||
|
// Get form data from the new session form
|
||||||
|
const sessionName = bricks.getWidget('session-name').value;
|
||||||
|
const modelSelect = bricks.getWidget('model-select').value;
|
||||||
|
const initialPrompt = bricks.getWidget('initial-prompt').value;
|
||||||
|
|
||||||
|
if (!sessionName) {
|
||||||
|
bricks.showMessage('Please enter a session name', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modelSelect) {
|
||||||
|
bricks.showMessage('Please select an AI model', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('session-name', sessionName);
|
||||||
|
formData.append('model-select', modelSelect);
|
||||||
|
formData.append('initial-prompt', initialPrompt || '');
|
||||||
|
|
||||||
|
const response = await fetch('/hermes-web-cli/sessions/create/', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
bricks.showMessage('Session created successfully', 'success');
|
||||||
|
// Navigate back to sessions list
|
||||||
|
const mainContent = bricks.getWidget('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.getWidget('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);
|
||||||
|
});
|
||||||
@ -81,9 +81,10 @@
|
|||||||
{
|
{
|
||||||
"wid": "self",
|
"wid": "self",
|
||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "script",
|
"actiontype": "registerfunction",
|
||||||
"target": "app.create_session",
|
"target": "self",
|
||||||
"mode": "call"
|
"rfname": "create_session",
|
||||||
|
"params": {}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user