diff --git a/agenta-web/package-lock.json b/agenta-web/package-lock.json index f976553ed22..8bed4f1b79b 100644 --- a/agenta-web/package-lock.json +++ b/agenta-web/package-lock.json @@ -14,10 +14,10 @@ "@mdx-js/loader": "^2.3.0", "@mdx-js/react": "^2.3.0", "@next/mdx": "^13.4.13", + "@types/js-beautify": "^1.14.0", "@types/mdx": "^2.0.6", - "@types/node": "18.16.3", - "@types/react": "18.2.0", "@types/react-dom": "18.2.1", + "@types/react-syntax-highlighter": "^15.5.7", "ag-grid-community": "^30.0.6", "ag-grid-react": "^30.0.3", "antd": "^5.4.7", @@ -33,6 +33,7 @@ "posthog-js": "^1.77.2", "react": "18.2.0", "react-dom": "18.2.0", + "react-error-boundary": "^4.0.11", "react-jss": "^10.10.0", "react-markdown": "^8.0.7", "react-syntax-highlighter": "^15.5.0", @@ -44,8 +45,6 @@ "usehooks-ts": "^2.9.1" }, "devDependencies": { - "@types/js-beautify": "^1.14.0", - "@types/react-syntax-highlighter": "^15.5.7", "cypress": "^12.11.0", "eslint-config-prettier": "^8.8.0", "node-mocks-http": "^1.12.2", @@ -734,8 +733,7 @@ "node_modules/@types/js-beautify": { "version": "1.14.0", "resolved": "https://registry.npmjs.org/@types/js-beautify/-/js-beautify-1.14.0.tgz", - "integrity": "sha512-OrJo4dEKd/8YKwGWuRP7qC/NoxNQCVsjAT7aHhgoIrNJaaDudLwX8husFrklktmXKIFbXevxzrLyEhB1842zjg==", - "dev": true + "integrity": "sha512-OrJo4dEKd/8YKwGWuRP7qC/NoxNQCVsjAT7aHhgoIrNJaaDudLwX8husFrklktmXKIFbXevxzrLyEhB1842zjg==" }, "node_modules/@types/json-schema": { "version": "7.0.12", @@ -798,7 +796,6 @@ "version": "15.5.7", "resolved": "https://registry.npmjs.org/@types/react-syntax-highlighter/-/react-syntax-highlighter-15.5.7.tgz", "integrity": "sha512-bo5fEO5toQeyCp0zVHBeggclqf5SQ/Z5blfFmjwO5dkMVGPgmiwZsJh9nu/Bo5L7IHTuGWrja6LxJVE2uB5ZrQ==", - "dev": true, "dependencies": { "@types/react": "*" } @@ -7482,6 +7479,17 @@ "react": "^18.2.0" } }, + "node_modules/react-error-boundary": { + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-4.0.11.tgz", + "integrity": "sha512-U13ul67aP5DOSPNSCWQ/eO0AQEYzEFkVljULQIjMV0KlffTAhxuDoBKdO0pb/JZ8mDhMKFZ9NZi0BmLGUiNphw==", + "dependencies": { + "@babel/runtime": "^7.12.5" + }, + "peerDependencies": { + "react": ">=16.13.1" + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", diff --git a/agenta-web/package.json b/agenta-web/package.json index c723992875a..c1b6383d3b2 100644 --- a/agenta-web/package.json +++ b/agenta-web/package.json @@ -24,8 +24,6 @@ "@next/mdx": "^13.4.13", "@types/js-beautify": "^1.14.0", "@types/mdx": "^2.0.6", - "@types/node": "18.16.3", - "@types/react": "18.2.0", "@types/react-dom": "18.2.1", "@types/react-syntax-highlighter": "^15.5.7", "ag-grid-community": "^30.0.6", @@ -43,6 +41,7 @@ "posthog-js": "^1.77.2", "react": "18.2.0", "react-dom": "18.2.0", + "react-error-boundary": "^4.0.11", "react-jss": "^10.10.0", "react-markdown": "^8.0.7", "react-syntax-highlighter": "^15.5.0", diff --git a/agenta-web/src/components/AppSelector/AppCard.tsx b/agenta-web/src/components/AppSelector/AppCard.tsx index 8936ba5a89d..f0e3eb86345 100644 --- a/agenta-web/src/components/AppSelector/AppCard.tsx +++ b/agenta-web/src/components/AppSelector/AppCard.tsx @@ -69,8 +69,6 @@ const AppCard: React.FC<{ await removeApp(appName) // Refresh the data (if you're using SWR or a similar library) mutate(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/app_variant/list_apps/`) - } catch (error: any) { - message.error(`Failed to remove app: ${error?.message}`) } finally { setVisibleDelete(false) setConfirmLoading(false) diff --git a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx index bf1b9d242c3..0966a2d0cff 100644 --- a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx @@ -176,9 +176,6 @@ const ABTestingEvaluationTable: React.FC = ({ } } catch (e) { setRowValue(rowIndex, columnName, "") - if (rowIndex === rows.length - 1) { - message.error("Oops! Something went wrong") - } } }) } diff --git a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx index ab3fddf3618..5ca292f7e58 100644 --- a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx @@ -213,25 +213,19 @@ Answer ONLY with one of the given grading or evaluation options. const columnsDataNames = ["columnData0"] let idx = 0 for (const columnName of columnsDataNames) { - try { - setRowValue(rowIndex, "evaluationFlow", EvaluationFlow.COMPARISON_RUN_STARTED) + setRowValue(rowIndex, "evaluationFlow", EvaluationFlow.COMPARISON_RUN_STARTED) - let result = await callVariant( - inputParamsDict, - variantData[idx].inputParams!, - variantData[idx].optParams!, - variantData[idx].URIPath!, - ) - setRowValue(rowIndex, columnName as any, result) - await evaluate(rowIndex) - setShouldFetchResults(true) - if (rowIndex === rows.length - 1) { - message.success("Evaluation Results Saved") - } - } catch (e) { - if (rowIndex === rows.length - 1) { - message.error("Oops! Something went wrong") - } + let result = await callVariant( + inputParamsDict, + variantData[idx].inputParams!, + variantData[idx].optParams!, + variantData[idx].URIPath!, + ) + setRowValue(rowIndex, columnName as any, result) + await evaluate(rowIndex) + setShouldFetchResults(true) + if (rowIndex === rows.length - 1) { + message.success("Evaluation Results Saved") } idx++ } diff --git a/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx index 33659147fb9..ab6011b7acb 100644 --- a/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx @@ -180,11 +180,8 @@ const ExactMatchEvaluationTable: React.FC = ({ if (rowIndex === rows.length - 1) { message.success("Evaluation Results Saved") } - } catch (e) { + } catch { setRowValue(rowIndex, columnName, "") - if (rowIndex === rows.length - 1) { - message.error("Oops! Something went wrong") - } } }) } diff --git a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx index e115d3f7ce6..b6cff3def2b 100644 --- a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx @@ -175,12 +175,11 @@ const SimilarityMatchEvaluationTable: React.FC { const postData = async (url = "", data = {}) => { - const response = await fetch(url, { - method: "POST", - cache: "no-cache", - credentials: "same-origin", - headers: { - "Content-Type": "application/json", - }, - redirect: "follow", - referrerPolicy: "no-referrer", - body: JSON.stringify(data), - }) - - if (!response.ok) { - throw new Error((await response.json())?.detail ?? "Failed to create evaluation") - } - - return response.json() + const response = await axios.post(url, data) + return response.data } const data = { diff --git a/agenta-web/src/components/Layout/ErrorFallback.tsx b/agenta-web/src/components/Layout/ErrorFallback.tsx new file mode 100644 index 00000000000..a5c87cc993e --- /dev/null +++ b/agenta-web/src/components/Layout/ErrorFallback.tsx @@ -0,0 +1,23 @@ +import {getErrorMessage} from "@/lib/helpers/errorHandler" +import {Button, Result} from "antd" + +interface Props { + error: any +} + +const ErrorFallback: React.FC = ({error}) => { + return ( + + Go to home screen + , + ]} + /> + ) +} + +export default ErrorFallback diff --git a/agenta-web/src/components/Layout/Layout.tsx b/agenta-web/src/components/Layout/Layout.tsx index f71e10eeff6..b16cda4344c 100644 --- a/agenta-web/src/components/Layout/Layout.tsx +++ b/agenta-web/src/components/Layout/Layout.tsx @@ -9,6 +9,8 @@ import {useAppTheme} from "./ThemeContextProvider" import {useElementSize} from "usehooks-ts" import {createUseStyles} from "react-jss" import NoSSRWrapper from "../NoSSRWrapper/NoSSRWrapper" +import {ErrorBoundary} from "react-error-boundary" +import ErrorFallback from "./ErrorFallback" const {Content, Footer} = Layout @@ -86,7 +88,9 @@ const App: React.FC = ({children}) => { {title: capitalizedAppName}, ]} /> - {children} + + {children} +