From 765c7fc6947720158d580725d7d838a384353087 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Thu, 26 Sep 2024 19:34:11 +0800 Subject: [PATCH] fix(agent): fix processing undefined read from readable stream. (#3206) --- clients/tabby-agent/src/chat/inlineEdit.ts | 4 ++-- clients/tabby-agent/src/utils/string.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clients/tabby-agent/src/chat/inlineEdit.ts b/clients/tabby-agent/src/chat/inlineEdit.ts index 485f7cac1767..4465f323ef91 100644 --- a/clients/tabby-agent/src/chat/inlineEdit.ts +++ b/clients/tabby-agent/src/chat/inlineEdit.ts @@ -436,11 +436,11 @@ export class ChatEditProvider implements Feature { // Insert the first line as early as possible so codelens can be shown await applyEdit(this.currentEdit, true, false); - for await (const delta of stream) { + for await (const item of stream) { if (!this.mutexAbortController || this.mutexAbortController.signal.aborted) { break; } - + const delta = typeof item === "string" ? item : ""; const edit = this.currentEdit; edit.buffer += delta; diff --git a/clients/tabby-agent/src/utils/string.ts b/clients/tabby-agent/src/utils/string.ts index 83b3547e1c73..3ac18d1193dc 100644 --- a/clients/tabby-agent/src/utils/string.ts +++ b/clients/tabby-agent/src/utils/string.ts @@ -276,7 +276,8 @@ import type { Readable } from "readable-stream"; export async function parseChatResponse(readableStream: Readable): Promise { let output = ""; try { - for await (const delta of readableStream) { + for await (const item of readableStream) { + const delta = typeof item === "string" ? item : ""; output += delta; } } catch (error) {