The scheduler AI dock read the poll envelope as the job, so every answer hung on thinking
This commit is contained in:
@@ -80,11 +80,15 @@
|
|||||||
// CSRF prepend never reaches here and a request that dies inside the include never reaches the
|
// CSRF prepend never reaches here and a request that dies inside the include never reaches the
|
||||||
// action log below, and those two look identical from outside — which is what made a POST that
|
// action log below, and those two look identical from outside — which is what made a POST that
|
||||||
// the browser demonstrably sent leave no trace anywhere on the server.
|
// the browser demonstrably sent leave no trace anywhere on the server.
|
||||||
@file_put_contents('/var/log/varaverk/ai.log',
|
// Polls are excluded here for the same reason they are excluded from the action log below: one
|
||||||
date('Y-m-d H:i:s') . ' ENTER ' . ($_SERVER['REQUEST_METHOD'] ?? '?')
|
// line per second per open tab buries every line worth reading.
|
||||||
. ' ' . ($_SERVER['REQUEST_URI'] ?? '?')
|
if (strpos($_SERVER['REQUEST_URI'] ?? '', 'action=poll') === false) {
|
||||||
. ' ct=' . substr($_SERVER['CONTENT_TYPE'] ?? '-', 0, 40)
|
@file_put_contents('/var/log/varaverk/ai.log',
|
||||||
. ' len=' . ($_SERVER['CONTENT_LENGTH'] ?? '-') . "\n", FILE_APPEND | LOCK_EX);
|
date('Y-m-d H:i:s') . ' ENTER ' . ($_SERVER['REQUEST_METHOD'] ?? '?')
|
||||||
|
. ' ' . ($_SERVER['REQUEST_URI'] ?? '?')
|
||||||
|
. ' ct=' . substr($_SERVER['CONTENT_TYPE'] ?? '-', 0, 40)
|
||||||
|
. ' len=' . ($_SERVER['CONTENT_LENGTH'] ?? '-') . "\n", FILE_APPEND | LOCK_EX);
|
||||||
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
header('Cache-Control: no-store, no-cache');
|
header('Cache-Control: no-store, no-cache');
|
||||||
|
|||||||
@@ -2429,11 +2429,15 @@ function vvAiDockSend() {
|
|||||||
}).catch(e => vvAiDockDone('Request failed: ' + e, true));
|
}).catch(e => vvAiDockDone('Request failed: ' + e, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
function vvAiDockPoll(token) {
|
function vvAiDockPoll(token, started) {
|
||||||
|
started = started || Date.now();
|
||||||
clearTimeout(vvAiPoll);
|
clearTimeout(vvAiPoll);
|
||||||
|
if (Date.now() - started > 300000) return vvAiDockDone('Timed out waiting for a response.', true);
|
||||||
vvAiPoll = setTimeout(() => {
|
vvAiPoll = setTimeout(() => {
|
||||||
fetch('/plugins/varaverk/api/ai.php?action=poll&token=' + encodeURIComponent(token))
|
fetch('/plugins/varaverk/api/ai.php?action=poll&token=' + encodeURIComponent(token))
|
||||||
.then(r => r.json()).then(j => {
|
.then(r => r.json()).then(d => {
|
||||||
|
if (!d.ok) return vvAiDockDone(d.error || 'Poll failed', true);
|
||||||
|
const j = d.job || {};
|
||||||
if (j.status === 'done') {
|
if (j.status === 'done') {
|
||||||
vvAiHist.push({ role: 'assistant', content: j.answer || '' });
|
vvAiHist.push({ role: 'assistant', content: j.answer || '' });
|
||||||
vvAiDockDone(j.answer || '(empty answer)', false, j.sources || []);
|
vvAiDockDone(j.answer || '(empty answer)', false, j.sources || []);
|
||||||
@@ -2443,7 +2447,7 @@ function vvAiDockPoll(token) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (j.status === 'error') return vvAiDockDone(j.error || 'Unknown error', true);
|
if (j.status === 'error') return vvAiDockDone(j.error || 'Unknown error', true);
|
||||||
vvAiDockPoll(token);
|
vvAiDockPoll(token, started);
|
||||||
}).catch(e => vvAiDockDone('Poll failed: ' + e, true));
|
}).catch(e => vvAiDockDone('Poll failed: ' + e, true));
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user