hover show errorMsg when plugin run error

This commit is contained in:
lloydzhou 2024-10-01 13:58:50 +08:00
parent 9c577ad9d5
commit 919ee51dca
4 changed files with 12 additions and 7 deletions

View File

@ -1815,6 +1815,7 @@ function _Chat() {
{message?.tools?.map((tool) => (
<div
key={tool.id}
title={tool?.errorMsg}
className={styles["chat-message-tool"]}
>
{tool.isError === false ? (

View File

@ -37,6 +37,7 @@ export type ChatMessageTool = {
};
content?: string;
isError?: boolean;
errorMsg?: string;
};
export type ChatMessage = RequestMessage & {

View File

@ -322,8 +322,10 @@ export function adapter(config: Record<string, unknown>) {
: 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 }));
},
);
}

View File

@ -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) => ({