Remove the tool toggle: tools are always on, the agent turn is the only GUI path

This commit is contained in:
adm committed 2026-11-25 18:47:56 +01:00
1 parent 22967ef60e
commit f4f209d650
4 files changed
+6 -84

No files matched your search

+2 -2
View File
@@ -157,8 +157,8 @@ copied into `data/` once on first run (the original is left in place).
## Agent mode
The GUI model can **act**, not just chat. Tools are **on by default** (the 🤖 button
toggles them): the framework is meant to act, not just chat. The agent has a single
The GUI model can **act**, not just chat. Tools are **always on** — there is no
toggle, because the framework could not function without them. The agent has a single
universal tool, **`shell_exec`** (a shell is universal: file ops, programs, system
inspection, web via curl, git, …). A bounded server-side loop drives
`model → shell_exec → result → model → … → final answer`, persisting the whole
-1
View File
@@ -161,7 +161,6 @@ details.thinking .reasoning {
font-size: 0.82rem; background: var(--bg); border-radius: 8px; padding: 8px;
}
.tool-out:empty { display: none; }
#agent-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* ---- Composer ---- */
#composer {
+4 -80
View File
@@ -5,7 +5,7 @@
const $ = (sel) => document.querySelector(sel);
const state = { sessions: [], current: null, busy: false, agent: true, attachments: [] };
const state = { sessions: [], current: null, busy: false, attachments: [] };
// ---- i18n: new user-facing strings go through t(key, params) --------------
// Catalogs are served at /assets/locales/<lang>.json; language follows the
@@ -51,35 +51,6 @@ async function sendJSON(url, method, body) {
return r.status === 204 ? null : r.json();
}
// Stream a chat turn, invoking onDelta for each SSE chunk.
async function streamChat(id, content, attachments, onDelta) {
const r = await fetch(`/api/sessions/${id}/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content, stream: true, attachments }),
});
if (!r.ok) throw new Error(await r.text());
const reader = r.body.getReader();
const dec = new TextDecoder();
let buf = "";
for (;;) {
const { done, value } = await reader.read();
if (done) break;
buf += dec.decode(value, { stream: true });
let idx;
while ((idx = buf.indexOf("\n\n")) >= 0) {
const block = buf.slice(0, idx);
buf = buf.slice(idx + 2);
for (const line of block.split("\n")) {
if (!line.startsWith("data:")) continue;
const data = line.slice(5).trim();
if (data === "[DONE]") return;
try { onDelta(JSON.parse(data)); } catch { /* ignore partial */ }
}
}
}
}
// ---- DOM builders ---------------------------------------------------------
function el(tag, cls, text) {
const n = document.createElement(tag);
@@ -342,8 +313,7 @@ async function sendMessage() {
const ids = attachments.map((a) => a.id);
try {
if (state.agent) await agentTurn(content, t, ids);
else await chatTurn(content, t, ids);
await agentTurn(content, t, ids);
state.sessions = await getJSON("/api/sessions");
renderSessions();
} catch (e) {
@@ -356,44 +326,8 @@ async function sendMessage() {
}
}
// Plain chat: stream OpenAI chunks into a live assistant bubble.
async function chatTurn(content, t, attachments) {
const wrap = el("div", "msg assistant");
wrap.appendChild(el("div", "role", "Assistente"));
const bubble = el("div", "bubble");
const det = el("details", "thinking");
det.appendChild(el("summary", null, "Pensiero"));
const reasoningNode = el("div", "reasoning", "");
det.appendChild(reasoningNode);
det.hidden = true;
const contentNode = el("div", "content", "");
bubble.appendChild(det);
bubble.appendChild(contentNode);
wrap.appendChild(bubble);
t.appendChild(wrap);
scrollDown();
let reasoning = "", text = "", usage = null;
await streamChat(state.current, content, attachments, (chunk) => {
const d = chunk.choices && chunk.choices[0] && chunk.choices[0].delta;
if (d && d.reasoning_content) {
reasoning += d.reasoning_content;
reasoningNode.textContent = reasoning;
det.hidden = false;
det.open = true; // show the thinking live, so the wait is visible progress
}
if (d && d.content) {
if (!text) det.open = false; // fold the thinking once the answer starts
text += d.content;
contentNode.textContent = text;
}
if (chunk.usage) usage = chunk.usage;
scrollDown();
});
if (usage) bubble.appendChild(el("div", "usage", usageText(usage)));
}
// Agent mode: stream tool_call / tool_result / final events (observability, no gate).
// The only turn path: tools are always on (no user toggle). Stream tool_call /
// tool_result / final events (observability, no gate).
async function agentTurn(content, t, attachments) {
const r = await fetch(`/api/sessions/${state.current}/chat`, {
method: "POST",
@@ -858,16 +792,6 @@ function wire() {
e.target.value = "";
if (files.length) uploadFiles(files);
});
$("#agent-toggle").addEventListener("click", () => {
state.agent = !state.agent;
const b = $("#agent-toggle");
b.classList.toggle("active", state.agent);
b.setAttribute("aria-pressed", String(state.agent));
});
// Tools are on by default: the framework is meant to act, not just chat.
const ab = $("#agent-toggle");
ab.classList.toggle("active", state.agent);
ab.setAttribute("aria-pressed", String(state.agent));
$("#show-stats").addEventListener("click", showStats);
$("#close-stats").setAttribute("aria-label", t("stats.close"));
$("#close-stats").addEventListener("click", closeStats);
-1
View File
@@ -43,7 +43,6 @@
<footer id="composer">
<textarea id="input" rows="1" placeholder="Scrivi un messaggio…" autocomplete="off"></textarea>
<button id="attach" class="btn ghost" aria-label="Allega file o immagini" title="Allega file o immagini">&#128206;</button>
<button id="agent-toggle" class="btn ghost" aria-pressed="false" title="Modalità agent: il modello usa shell_exec sull'host">&#129302;</button>
<button id="send" class="btn primary" aria-label="Invia">&#10148;</button>
<input id="file-input" type="file" multiple hidden />
</footer>