Просмотр исходного кода

hover show errorMsg when plugin run error

lloydzhou 1 год назад
Родитель
Сommit
919ee51dca
4 измененных файлов с 12 добавлено и 7 удалено
  1. 1 0
      app/components/chat.tsx
  2. 1 0
      app/store/chat.ts
  3. 4 2
      app/utils.ts
  4. 6 5
      app/utils/chat.ts

+ 1 - 0
app/components/chat.tsx

@@ -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 ? (

+ 1 - 0
app/store/chat.ts

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

+ 4 - 2
app/utils.ts

@@ -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 }));
     },
   );
 }

+ 6 - 5
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) => ({