@usecrow/ui 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -138,11 +138,13 @@ function useChat({
138
138
  const reader = response.body?.getReader();
139
139
  const decoder = new TextDecoder();
140
140
  if (reader) {
141
+ let buffer = "";
141
142
  while (true) {
142
143
  const { done, value } = await reader.read();
143
144
  if (done) break;
144
- const chunk = decoder.decode(value);
145
- const lines = chunk.split("\n");
145
+ buffer += decoder.decode(value, { stream: true });
146
+ const lines = buffer.split("\n");
147
+ buffer = lines.pop() || "";
146
148
  for (const line of lines) {
147
149
  if (line.startsWith("data: ")) {
148
150
  const data = line.slice(6).trim();
@@ -491,11 +493,13 @@ function useChat({
491
493
  const decoder = new TextDecoder();
492
494
  let accumulatedText = "";
493
495
  if (reader) {
496
+ let buffer = "";
494
497
  while (true) {
495
498
  const { done, value } = await reader.read();
496
499
  if (done) break;
497
- const chunk = decoder.decode(value);
498
- const lines = chunk.split("\n");
500
+ buffer += decoder.decode(value, { stream: true });
501
+ const lines = buffer.split("\n");
502
+ buffer = lines.pop() || "";
499
503
  for (const line of lines) {
500
504
  if (line.startsWith("data: ")) {
501
505
  const data = line.slice(6).trim();