From 919ee51dca25ba03f2d627eaabbe17b578dec45d Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Tue, 1 Oct 2024 13:58:50 +0800 Subject: [PATCH] hover show errorMsg when plugin run error --- app/components/chat.tsx | 1 + app/store/chat.ts | 1 + app/utils.ts | 6 ++++-- app/utils/chat.ts | 11 ++++++----- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 3d519dee7..b45d36f95 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1815,6 +1815,7 @@ function _Chat() { {message?.tools?.map((tool) => (
{tool.isError === false ? ( diff --git a/app/store/chat.ts b/app/store/chat.ts index 968d8cb64..931cad768 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -37,6 +37,7 @@ export type ChatMessageTool = { }; content?: string; isError?: boolean; + errorMsg?: string; }; export type ChatMessage = RequestMessage & { diff --git a/app/utils.ts b/app/utils.ts index 95880115a..83bcea5c0 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -322,8 +322,10 @@ export function adapter(config: Record) { : path; return fetch(fetchUrl as string, { ...rest, responseType: "text" }).then( (res) => { - const { status, headers } = res; - return res.text().then((data) => ({ status, headers, data })); + const { status, headers, statusText } = res; + return res + .text() + .then((data: string) => ({ status, statusText, headers, data })); }, ); } diff --git a/app/utils/chat.ts b/app/utils/chat.ts index 3d7960480..46f232638 100644 --- a/app/utils/chat.ts +++ b/app/utils/chat.ts @@ -222,10 +222,7 @@ export function stream( ), ) .then((res) => { - let content = res.data; - try { - content = JSON.stringify(res.data); - } catch (e) {} + let content = res.data || res?.statusText; if (res.status >= 300) { return Promise.reject(content); } @@ -240,7 +237,11 @@ export function stream( return content; }) .catch((e) => { - options?.onAfterTool?.({ ...tool, isError: true }); + options?.onAfterTool?.({ + ...tool, + isError: true, + errorMsg: e.toString(), + }); return e.toString(); }) .then((content) => ({