Commit 7bd1e40b by Michael Pastushkov

fix clear

parent efce9518
......@@ -10,7 +10,6 @@ const ConversationManager = require('./ConversationManager');
const MODEL = 'gpt-oss:20b'; // 'llama3:8b'; // 'gpt-oss:20b';
const EMBED_MODEL = 'nomic-embed-text';
const LABEL_MODEL = 'llama3:8b';
const COOKIE_TIMEOUT = 1 * 1 * 10 * 60 * 1000 // 10 minutes
const sessions = new Map(); // cookie -> ConversationManager
//const queues = new Map(); // cookie -> Promise (to serialize)
......@@ -21,12 +20,11 @@ async function run(req, res) {
let cookie = req.cookies?.session;
if (!cookie) {
cookie = uuidv4();
res.cookie('session', cookie, { maxAge: COOKIE_TIMEOUT });
res.cookie('session', cookie, { path: '/', sameSite: 'Lax', httpOnly: true });
utils.log(`[session] New cookie set: ${cookie}`, 5);
} else {
utils.log(`[session] Existing cookie: ${cookie}`, 5);
}
// Get conversation manager
let convman = sessions.get(cookie);
if (!convman) {
......@@ -46,8 +44,16 @@ async function run(req, res) {
async function stop(req, res) {
utils.log('stop');
res.send('Stop OK');
}
async function clear(req, res) {
res.clearCookie('session', { path: '/', sameSite: 'Lax', httpOnly: true });
utils.log('clear');
res.send('Clear OK');
}
module.exports = { run, stop };
/* Testing * /
......@@ -64,3 +70,5 @@ function log(data) {
/**/
module.exports.run = run;
module.exports.stop = stop;
module.exports.clear = clear;
......@@ -21,6 +21,7 @@ function init(app) {
// Misc
[POST, '/stream', './KotGPT'],
[GET, '/stop', './KotGPT', 'stop'],
[GET, '/clear', './KotGPT', 'clear'],
// Misc
[GET, '/info', '../common/info'],
[GET, '/logcat', '../utils/logcat'],
......
......@@ -178,6 +178,11 @@
let controller = null;
window.addEventListener('DOMContentLoaded', async () => {
try {
await fetch('/api/clear', { method: 'GET' });
} catch (err) {
// nothing to do
}
await loadLocale(CURRENT_LOCALE);
inputText.focus();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment