incognitolm commited on
Commit
1ce36f5
Β·
1 Parent(s): 31f4a53
Files changed (2) hide show
  1. public/js/chat.js +2 -2
  2. server/wsHandler.js +4 -4
public/js/chat.js CHANGED
@@ -586,7 +586,7 @@ export function submitMessage(text, attachments = [], regenerate = false, editIn
586
 
587
  // Append optimistic user bubble
588
  const box = document.getElementById('chat-messages');
589
- if (box) {
590
  const wrap = makeWrap(-1);
591
  const bubble = document.createElement('div'); bubble.className = 'msg-user';
592
  bubble.innerHTML = renderMarkdown(fullText);
@@ -601,7 +601,7 @@ export function submitMessage(text, attachments = [], regenerate = false, editIn
601
  if (autoScroll) box.scrollTop = box.scrollHeight;
602
  }
603
 
604
- send({ type: 'chat:send', sessionId: activeSessionId, content, tools: getActiveTools(), clientId: localStorage.getItem('ipai_client_id') || '' });
605
  }
606
 
607
  // ── Utils ─────────────────────────────────────────────────────────────────
 
586
 
587
  // Append optimistic user bubble
588
  const box = document.getElementById('chat-messages');
589
+ if (box && !regenerate) {
590
  const wrap = makeWrap(-1);
591
  const bubble = document.createElement('div'); bubble.className = 'msg-user';
592
  bubble.innerHTML = renderMarkdown(fullText);
 
601
  if (autoScroll) box.scrollTop = box.scrollHeight;
602
  }
603
 
604
+ send({ type: 'chat:send', sessionId: activeSessionId, content, regenerate, tools: getActiveTools(), clientId: localStorage.getItem('ipai_client_id') || '' });
605
  }
606
 
607
  // ── Utils ─────────────────────────────────────────────────────────────────
server/wsHandler.js CHANGED
@@ -146,7 +146,7 @@ const handlers = {
146
  },
147
 
148
  'chat:send': async (ws, msg, client) => {
149
- const { sessionId, content, tools } = msg;
150
  if (!client.userId) {
151
  if (!sessionStore.tempCanSend(client.tempId)) return safeSend(ws, { type: 'chat:limitReached' });
152
  sessionStore.tempBump(client.tempId);
@@ -165,7 +165,7 @@ const handlers = {
165
  const assetsCollected = [], toolCallsCollected = [];
166
 
167
  await streamChat(ws, {
168
- history: session.history || [], userMessage: content, tools: tools || {},
169
  accessToken: client.accessToken, clientId: msg.clientId, abortSignal: abort.signal,
170
  onToken(t) { fullText += t; safeSend(ws, { type: 'chat:token', token: t, sessionId }); },
171
  onToolCall(call) {
@@ -215,8 +215,8 @@ const handlers = {
215
  const history = session.history || [];
216
  const m = history[messageIndex]; if (!m) return;
217
  if (!m.versions) m.versions = [{ content: m.content, tail: history.slice(messageIndex + 1), timestamp: m.timestamp || Date.now() }];
218
- m.versions.unshift({ content: newContent, tail: history.slice(messageIndex + 1), timestamp: Date.now() });
219
- m.currentVersionIdx = 0;
220
  m.content = newContent;
221
  const newHistory = history.slice(0, messageIndex + 1);
222
  if (client.userId) await sessionStore.updateUserSession(client.userId, client.accessToken, sessionId, { history: newHistory });
 
146
  },
147
 
148
  'chat:send': async (ws, msg, client) => {
149
+ const { sessionId, content, regenerate, tools } = msg;
150
  if (!client.userId) {
151
  if (!sessionStore.tempCanSend(client.tempId)) return safeSend(ws, { type: 'chat:limitReached' });
152
  sessionStore.tempBump(client.tempId);
 
165
  const assetsCollected = [], toolCallsCollected = [];
166
 
167
  await streamChat(ws, {
168
+ history: session.history || [], userMessage: regenerate ? undefined : content, tools: tools || {},
169
  accessToken: client.accessToken, clientId: msg.clientId, abortSignal: abort.signal,
170
  onToken(t) { fullText += t; safeSend(ws, { type: 'chat:token', token: t, sessionId }); },
171
  onToolCall(call) {
 
215
  const history = session.history || [];
216
  const m = history[messageIndex]; if (!m) return;
217
  if (!m.versions) m.versions = [{ content: m.content, tail: history.slice(messageIndex + 1), timestamp: m.timestamp || Date.now() }];
218
+ m.versions.push({ content: newContent, tail: history.slice(messageIndex + 1), timestamp: Date.now() });
219
+ m.currentVersionIdx = m.versions.length - 1;
220
  m.content = newContent;
221
  const newHistory = history.slice(0, messageIndex + 1);
222
  if (client.userId) await sessionStore.updateUserSession(client.userId, client.accessToken, sessionId, { history: newHistory });