Mishig commited on
Commit
f35e104
1 Parent(s): b1cf529

[Websearch] Fix UI flicker (#710)

Browse files

* [Wbesarch] Fix UI flicker

Co-authored-by: Michael Fried mikelfried@gmail.com

* format

src/routes/conversation/[id]/+page.svelte CHANGED
@@ -137,6 +137,7 @@
137
  const encoder = new TextDecoderStream();
138
  const reader = response?.body?.pipeThrough(encoder).getReader();
139
  let finalAnswer = "";
 
140
 
141
  // set str queue
142
  // ex) if the last response is => {"type": "stream", "token":
@@ -172,6 +173,10 @@
172
  try {
173
  const update = JSON.parse(el) as MessageUpdate;
174
 
 
 
 
 
175
  if (update.type === "finalAnswer") {
176
  finalAnswer = update.text;
177
  reader.cancel();
@@ -224,9 +229,11 @@
224
  });
225
  }
226
 
227
- // reset the websearchMessages
228
  webSearchMessages = [];
229
 
 
 
 
230
  await invalidate(UrlDependency.ConversationList);
231
  } catch (err) {
232
  if (err instanceof Error && err.message.includes("overloaded")) {
 
137
  const encoder = new TextDecoderStream();
138
  const reader = response?.body?.pipeThrough(encoder).getReader();
139
  let finalAnswer = "";
140
+ const messageUpdates: MessageUpdate[] = [];
141
 
142
  // set str queue
143
  // ex) if the last response is => {"type": "stream", "token":
 
173
  try {
174
  const update = JSON.parse(el) as MessageUpdate;
175
 
176
+ if (update.type !== "stream") {
177
+ messageUpdates.push(update);
178
+ }
179
+
180
  if (update.type === "finalAnswer") {
181
  finalAnswer = update.text;
182
  reader.cancel();
 
229
  });
230
  }
231
 
 
232
  webSearchMessages = [];
233
 
234
+ const lastMessage = messages[messages.length - 1];
235
+ lastMessage.updates = messageUpdates;
236
+
237
  await invalidate(UrlDependency.ConversationList);
238
  } catch (err) {
239
  if (err instanceof Error && err.message.includes("overloaded")) {