feat(assistant): больше рабочей памяти (~14 сообщений) + оформление сноски
История разговора расширена с 6 до 14 сообщений (фронт _chat.slice и бэкенд история в ask/askStream). Сноска о памяти переоформлена: иконка-история + чище текст, акцент на количестве. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -707,7 +707,7 @@ async function ask(req, res) {
|
||||
const pageCtx = String((req.body && req.body.context) || '').slice(0, 4000);
|
||||
const mode = ['hint', 'check'].includes(req.body && req.body.mode) ? req.body.mode : 'answer';
|
||||
let history = (req.body && req.body.history);
|
||||
history = Array.isArray(history) ? history.slice(-6) : [];
|
||||
history = Array.isArray(history) ? history.slice(-14) : [];
|
||||
const hits = searchFaq(q, 3);
|
||||
const faqJson = hits.map(h => ({ id: h.id, q: h.q, a: h.a, url: h.url || null }));
|
||||
|
||||
@@ -769,7 +769,7 @@ async function askStream(req, res) {
|
||||
const pageCtx = String((req.body && req.body.context) || '').slice(0, 4000);
|
||||
const mode = ['hint', 'check'].includes(req.body && req.body.mode) ? req.body.mode : 'answer';
|
||||
let history = (req.body && req.body.history);
|
||||
history = Array.isArray(history) ? history.slice(-6) : [];
|
||||
history = Array.isArray(history) ? history.slice(-14) : [];
|
||||
const hits = searchFaq(q, 3);
|
||||
const faqJson = hits.map(h => ({ id: h.id, q: h.q, a: h.a, url: h.url || null }));
|
||||
sse('meta', { answers: faqJson });
|
||||
|
||||
@@ -301,7 +301,9 @@
|
||||
// плавное появление сообщений
|
||||
reduceMotion ? '' : '.asst-msg{animation:asstMsgIn .26s cubic-bezier(.4,0,.2,1);}',
|
||||
'@keyframes asstMsgIn{from{opacity:0;transform:translateY(7px);}to{opacity:1;transform:translateY(0);}}',
|
||||
'.asst-memnote{font-size:.66rem;color:#9aa5b4;margin-top:9px;line-height:1.45;border-top:1px solid rgba(15,23,42,.05);padding-top:8px;}',
|
||||
'.asst-memnote{display:flex;gap:7px;align-items:flex-start;font-size:.66rem;color:#9aa5b4;margin-top:9px;line-height:1.45;border-top:1px solid rgba(15,23,42,.05);padding-top:9px;}',
|
||||
'.asst-memnote .ic{width:13px;height:13px;flex:none;margin-top:1px;color:#b6abdd;}',
|
||||
'.asst-memnote b{color:#7e3eca;font-weight:700;}',
|
||||
'.asst-bubble.open{opacity:1;transform:translateY(0);pointer-events:auto;}',
|
||||
'.asst-x{position:absolute;top:12px;right:12px;width:28px;height:28px;border:none;background:transparent;color:#94a3b8;z-index:3;',
|
||||
' cursor:pointer;border-radius:8px;font-size:19px;line-height:1;transition:all .14s;}',
|
||||
@@ -590,7 +592,8 @@
|
||||
'<div class="asst-chat"></div>' + chips + modes +
|
||||
'<div class="asst-ask-row"><input class="asst-ask-in" type="text" placeholder="' + MODE_PH.answer + '" maxlength="500" />' +
|
||||
'<button class="asst-send" type="button" title="Отправить" aria-label="Отправить"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 2 11 13"/><path d="M22 2 15 22l-4-9-9-4 20-7z"/></svg></button></div>' +
|
||||
'<div class="asst-memnote">Я помню последние ~6 сообщений этого разговора — как рабочая память: что было раньше, понимаю; старое постепенно забывается. «Очистить» — начать с чистого листа.</div>', {});
|
||||
'<div class="asst-memnote">' + _svg('<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>') +
|
||||
'<span>Держу в голове ход беседы — последние <b>~14 сообщений</b>. Что обсуждали раньше — учту, давнее плавно забывается. «Очистить» — начать с чистого листа.</span></div>', {});
|
||||
var inp = bubble.querySelector('.asst-ask-in');
|
||||
var chatEl = bubble.querySelector('.asst-chat');
|
||||
var chipsEl = bubble.querySelector('.asst-chips');
|
||||
@@ -685,7 +688,7 @@
|
||||
// стриминг недоступен (старый кэш api.js / нет ReadableStream) — обычный путь
|
||||
if (!LS.assistantAskStream || typeof ReadableStream === 'undefined') return sendNonStream(q, context, chatEl, mode);
|
||||
|
||||
var history = _chat.slice(-6);
|
||||
var history = _chat.slice(-14);
|
||||
_chat.push({ role: 'user', content: q });
|
||||
var u = msgEl('user'); u.textContent = q; chatEl.appendChild(u);
|
||||
var ph = msgEl('assistant'); ph.className += ' asst-msg-ph'; ph.innerHTML = '<span class="asst-typing"><span></span><span></span><span></span></span>'; chatEl.appendChild(ph);
|
||||
@@ -759,7 +762,7 @@
|
||||
if (q.length < 2) return;
|
||||
if (mode === 'draw') return drawInChat(q, chatEl);
|
||||
if (mode === 'quiz') return makeQuiz(q, chatEl);
|
||||
var history = _chat.slice(-6);
|
||||
var history = _chat.slice(-14);
|
||||
_chat.push({ role: 'user', content: q });
|
||||
var u = msgEl('user'); u.textContent = q; chatEl.appendChild(u);
|
||||
var ph = msgEl('assistant'); ph.className += ' asst-msg-ph'; ph.innerHTML = '<span class="asst-typing"><span></span><span></span><span></span></span>'; chatEl.appendChild(ph);
|
||||
|
||||
Reference in New Issue
Block a user