@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.cjs CHANGED
@@ -164,11 +164,13 @@ function useChat({
164
164
  const reader = response.body?.getReader();
165
165
  const decoder = new TextDecoder();
166
166
  if (reader) {
167
+ let buffer = "";
167
168
  while (true) {
168
169
  const { done, value } = await reader.read();
169
170
  if (done) break;
170
- const chunk = decoder.decode(value);
171
- const lines = chunk.split("\n");
171
+ buffer += decoder.decode(value, { stream: true });
172
+ const lines = buffer.split("\n");
173
+ buffer = lines.pop() || "";
172
174
  for (const line of lines) {
173
175
  if (line.startsWith("data: ")) {
174
176
  const data = line.slice(6).trim();
@@ -517,11 +519,13 @@ function useChat({
517
519
  const decoder = new TextDecoder();
518
520
  let accumulatedText = "";
519
521
  if (reader) {
522
+ let buffer = "";
520
523
  while (true) {
521
524
  const { done, value } = await reader.read();
522
525
  if (done) break;
523
- const chunk = decoder.decode(value);
524
- const lines = chunk.split("\n");
526
+ buffer += decoder.decode(value, { stream: true });
527
+ const lines = buffer.split("\n");
528
+ buffer = lines.pop() || "";
525
529
  for (const line of lines) {
526
530
  if (line.startsWith("data: ")) {
527
531
  const data = line.slice(6).trim();