fix: custom command execution via systemd-run für prozessunabhängigkeit

This commit is contained in:
Meleki committed 2026-02-27 13:34:14 +01:00
1 parent 2b8749ee3a
commit 73c6d38254
11 files changed
+242 -12

No files matched your search

+8
View File
@@ -103,3 +103,11 @@ async function apiUpdateSession(sessionId, data) {
});
return resp.json();
}
async function apiExecCommand(sessionId, command) {
return fetch(`/api/sessions/${sessionId}/exec`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command })
});
}
+29
View File
@@ -21,6 +21,35 @@ registerPage('chat', {
titleEl.textContent = session.name || 'Unbenannt';
}
// Custom Command Buttons
const cmdBar = document.getElementById('customCmdBar');
if (cmdBar) {
cmdBar.innerHTML = '';
let cmds = [];
try { cmds = JSON.parse(session.customCommands || '[]') || []; } catch(e) {}
cmds.forEach(cmd => {
if (!cmd.name || !cmd.command) return;
const btn = document.createElement('button');
btn.className = 'custom-cmd-btn';
btn.textContent = cmd.name;
btn.title = cmd.command;
btn.addEventListener('click', async () => {
btn.disabled = true;
btn.classList.add('running');
try {
await apiExecCommand(sessionId, cmd.command);
} catch(e) {
console.error('Exec failed:', e);
}
setTimeout(() => {
btn.disabled = false;
btn.classList.remove('running');
}, 1000);
});
cmdBar.appendChild(btn);
});
}
// Zurück zur Session-Edit-Seite
const backBtn = document.getElementById('chatBackBtn');
if (backBtn) {
+49 -1
View File
@@ -2,6 +2,35 @@
let _sessionImageData = null;
function _createCommandRow(container, name = '', command = '') {
const item = document.createElement('div');
item.className = 'custom-command-item';
item.innerHTML = `
<div class="custom-command-fields">
<input type="text" class="cmd-name" placeholder="Name (z.B. Deploy)" value="${_escAttr(name)}">
<input type="text" class="cmd-command" placeholder="Befehl (z.B. ./deploy.sh)" value="${_escAttr(command)}">
</div>
<button type="button" class="remove-cmd-btn">✕</button>
`;
item.querySelector('.remove-cmd-btn').addEventListener('click', () => item.remove());
container.appendChild(item);
}
function _escAttr(str) {
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function _getCommandsFromUI(container) {
const items = container.querySelectorAll('.custom-command-item');
const commands = [];
for (const item of items) {
const name = item.querySelector('.cmd-name').value.trim();
const command = item.querySelector('.cmd-command').value.trim();
if (name || command) commands.push({ name, command });
}
return commands.length > 0 ? commands : null;
}
registerPage('session', {
async init(params) {
const sessionId = params.id;
@@ -27,6 +56,8 @@ registerPage('session', {
const cancelBtn = document.getElementById('sessionCancelBtn');
const deleteBtn = document.getElementById('sessionDeleteBtn');
const openChatBtn = document.getElementById('openChatBtn');
const commandsList = document.getElementById('customCommandsList');
const addCommandBtn = document.getElementById('addCommandBtn');
_sessionImageData = null;
@@ -43,12 +74,27 @@ registerPage('session', {
if (session.image) {
imagePreview.innerHTML = `<img src="${session.image}" alt="">`;
}
// Custom Commands laden
if (session.customCommands) {
try {
const cmds = typeof session.customCommands === 'string'
? JSON.parse(session.customCommands)
: session.customCommands;
for (const cmd of cmds) {
_createCommandRow(commandsList, cmd.name || '', cmd.command || '');
}
} catch (e) { /* ignore parse errors */ }
}
} else {
titleEl.textContent = 'Neue Session';
deleteBtn.hidden = true;
openChatBtn.disabled = true;
}
// Befehl hinzufügen
addCommandBtn.addEventListener('click', () => _createCommandRow(commandsList));
// Agents laden
const agents = await apiGetAgents();
agentSelect.innerHTML = '<option value="">-- Kein Agent --</option>';
@@ -94,13 +140,15 @@ registerPage('session', {
// Speichern
saveBtn.addEventListener('click', async () => {
const commands = _getCommandsFromUI(commandsList);
const data = {
name: nameEl.value.trim() || 'Unbenannt',
description: descEl.value.trim(),
image: _sessionImageData,
agentId: agentSelect.value || null,
context: contextEl.value || null,
workspace: workspaceEl.value.trim() || null
workspace: workspaceEl.value.trim() || null,
customCommands: commands
};
if (isNew) {