From 360264737b55cde4bd33db3357a9b861b8f764fb Mon Sep 17 00:00:00 2001 From: adolphzhang Date: Fri, 29 Nov 2024 00:58:40 +0800 Subject: [PATCH] fix: fix tool response being read repeatedly. --- src/tools/tool.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/tools/tool.ts b/src/tools/tool.ts index 69b03ed9..a51ae9df 100644 --- a/src/tools/tool.ts +++ b/src/tools/tool.ts @@ -52,15 +52,10 @@ export function executeTool(toolName: string) { if (!result.ok) { throw new Error(`Tool call error: ${result.statusText}}`); } - const contentType = await result.headers.get('content-type'); - if (contentType?.includes('json')) { - result = await result.json(); - } else { - try { - result = await result.json(); - } catch (e) { - result = await result.text(); - } + try { + result = await result.clone().json(); + } catch (e) { + result = await result.text(); } const middleHandler = async (data: any) => {