Add an incident journal the troubleshooter reads back, and thinking for diagnosis
This commit is contained in:
@@ -1062,6 +1062,8 @@ Still the same two servers, two households, the same media stack running itself.
|
||||
placeholder="Ask about what is on screen…"
|
||||
onkeydown="if(event.key==='Enter'){event.preventDefault();vvAiDockSend();}">
|
||||
<button class="vv-btn-sm" id="vv-ai-dock-send" onclick="vvAiDockSend()">Ask</button>
|
||||
<button class="vv-btn-sm" id="vv-ai-dock-fix" onclick="vvAiFixStart()"
|
||||
style="display:none" title="Record what actually fixed this, against this script">Save fix</button>
|
||||
<button class="vv-btn-sm" id="vv-ai-dock-hide" onclick="vvAiDockCollapse()"
|
||||
style="display:none" title="Collapse — the conversation is kept">▾</button>
|
||||
</div>
|
||||
@@ -2351,11 +2353,55 @@ function vvAiDockCollapse() {
|
||||
requestAnimationFrame(vvFitRight);
|
||||
}
|
||||
|
||||
// ── Recording a fix ───────────────────────────────────────────────────────────
|
||||
// The symptom is taken from the question that was being asked; the fix is typed by the operator.
|
||||
// The model's diagnosis is deliberately not saved — it is a reading of evidence, and writing a
|
||||
// hypothesis into institutional memory as settled fact is how a wrong answer outlives the
|
||||
// incident it came from. What gets remembered is what actually worked.
|
||||
let vvAiFixMode = false;
|
||||
let vvAiLastQ = '';
|
||||
|
||||
function vvAiFixStart() {
|
||||
const input = document.getElementById('vv-ai-dock-input');
|
||||
vvAiFixMode = true;
|
||||
input.placeholder = 'What actually fixed it? (saved against ' + vvAiScope + ')';
|
||||
input.value = '';
|
||||
input.focus();
|
||||
document.getElementById('vv-ai-dock-send').textContent = 'Save';
|
||||
document.getElementById('vv-ai-dock-fix').style.display = 'none';
|
||||
}
|
||||
|
||||
function vvAiFixCancel() {
|
||||
vvAiFixMode = false;
|
||||
const input = document.getElementById('vv-ai-dock-input');
|
||||
input.placeholder = 'Ask about what is on screen…';
|
||||
document.getElementById('vv-ai-dock-send').textContent = 'Ask';
|
||||
if (vvAiLastQ) document.getElementById('vv-ai-dock-fix').style.display = '';
|
||||
}
|
||||
|
||||
function vvAiFixSave(text) {
|
||||
fetch('/plugins/varaverk/api/ai.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: new URLSearchParams({ action: 'incident_add', scope: vvAiScope,
|
||||
symptom: vvAiLastQ, fix: text }),
|
||||
}).then(r => r.json()).then(d => {
|
||||
vvAiDockAppend(d.ok
|
||||
? '<div class="vv-ai-dock-sep">saved against ' + vvEscHtml(vvAiScope)
|
||||
+ ' — it will be shown next time this is diagnosed</div>'
|
||||
: '<div class="vv-ai-dock-a vv-ai-dock-err">Could not save: '
|
||||
+ vvEscHtml(d.error || 'unknown') + '</div>');
|
||||
}).catch(e => vvAiDockAppend('<div class="vv-ai-dock-a vv-ai-dock-err">Save failed: '
|
||||
+ vvEscHtml(String(e)) + '</div>'));
|
||||
vvAiFixCancel();
|
||||
}
|
||||
|
||||
function vvAiDockSend() {
|
||||
if (vvAiBusy) return;
|
||||
const input = document.getElementById('vv-ai-dock-input');
|
||||
const q = input.value.trim();
|
||||
if (!q) return;
|
||||
if (vvAiFixMode) { input.value = ''; vvAiFixSave(q); return; }
|
||||
input.value = '';
|
||||
vvAiBusy = true;
|
||||
document.getElementById('vv-ai-dock-send').disabled = true;
|
||||
@@ -2369,11 +2415,16 @@ function vvAiDockSend() {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: new URLSearchParams({
|
||||
action: 'ask', question: q, profile: vvAiProfile, scope: vvAiScope,
|
||||
think: '0', history: JSON.stringify(vvAiHist),
|
||||
// Thinking on for diagnosis only. Working out what a log means is reasoning, and it is
|
||||
// the one thing here worth waiting ~15s for; a lookup like "what does this setting do"
|
||||
// is not, and inline answers that stall feel broken.
|
||||
think: vvAiProfile === 'troubleshoot' ? '1' : '0',
|
||||
history: JSON.stringify(vvAiHist),
|
||||
}),
|
||||
}).then(r => r.json()).then(d => {
|
||||
if (!d.ok || !d.token) return vvAiDockDone(d.error || 'Could not start.', true);
|
||||
vvAiHist.push({ role: 'user', content: q });
|
||||
vvAiLastQ = q;
|
||||
vvAiDockPoll(d.token);
|
||||
}).catch(e => vvAiDockDone('Request failed: ' + e, true));
|
||||
}
|
||||
@@ -2415,6 +2466,8 @@ function vvAiDockDone(text, isErr, sources) {
|
||||
}
|
||||
vvAiBusy = false;
|
||||
document.getElementById('vv-ai-dock-send').disabled = false;
|
||||
// Offered only once there is something to attach a fix to.
|
||||
if (!isErr && vvAiLastQ) document.getElementById('vv-ai-dock-fix').style.display = '';
|
||||
const body = document.getElementById('vv-ai-dock-body');
|
||||
body.scrollTop = body.scrollHeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user