Files
gott/wwwroot/js/commands-ui.js
T
Meleki 9abb5fd217 fix: esc() Quote-Escaping für Attribut-Kontexte + cache_control für Sub-Agents/Telegram
- esc() um "→" Escaping erweitert (Bug: Anführungszeichen in value="..."-Attributen brachen HTML)
- cache_control: ephemeral zu RunAgentChat() hinzugefügt (Preparer/Review/Finalizer hatten kein Prompt Caching)
- cache_control: ephemeral zu ChatNonStreaming() hinzugefügt (Telegram hatte kein Prompt Caching)
- Trailing-Leerzeile in commands-ui.js bereinigt
2026-03-07 22:42:20 +01:00

56 lines
2.2 KiB
JavaScript

// ── Custom Commands UI (shared between session-page and agent-page) ──
function createCommandRow(container, name, command, type) {
name = name || '';
command = command || '';
type = type || 'background';
const item = document.createElement('div');
item.className = 'custom-command-item';
item.innerHTML = `
<div class="custom-command-fields">
<select class="cmd-type">
<option value="background">Hintergrund</option>
<option value="foreground">Vordergrund</option>
<option value="message">Nachricht</option>
</select>
<input type="text" class="cmd-name" placeholder="Name (z.B. Deploy)" value="${esc(name)}">
<input type="text" class="cmd-command" placeholder="${type === 'message' ? 'Nachricht...' : 'Befehl (z.B. ./deploy.sh)'}" value="${esc(command)}">
</div>
<button type="button" class="remove-cmd-btn icon-btn"><i class="fa fa-times"></i></button>
`;
var typeSelect = item.querySelector('.cmd-type');
typeSelect.value = type;
typeSelect.addEventListener('change', function() {
var cmdInput = item.querySelector('.cmd-command');
cmdInput.placeholder = typeSelect.value === 'message' ? 'Nachricht...' : 'Befehl (z.B. ./deploy.sh)';
});
item.querySelector('.remove-cmd-btn').addEventListener('click', function() { item.remove(); });
container.appendChild(item);
}
function getCommandsFromUI(container) {
var items = container.querySelectorAll('.custom-command-item');
var commands = [];
for (var i = 0; i < items.length; i++) {
var item = items[i];
var name = item.querySelector('.cmd-name').value.trim();
var command = item.querySelector('.cmd-command').value.trim();
var type = item.querySelector('.cmd-type').value;
if (name || command) commands.push({ name: name, command: command, type: type });
}
return commands.length > 0 ? commands : null;
}
function loadCommandsIntoUI(container, customCommands) {
if (!customCommands) return;
try {
var cmds = typeof customCommands === 'string' ? JSON.parse(customCommands) : customCommands;
for (var i = 0; i < cmds.length; i++) {
var cmd = cmds[i];
createCommandRow(container, cmd.name || '', cmd.command || '', cmd.type || 'background');
}
} catch (e) { /* ignore parse errors */ }
}