diff --git a/agenta-web/src/components/HumanEvaluationModal/HumanEvaluationModal.tsx b/agenta-web/src/components/HumanEvaluationModal/HumanEvaluationModal.tsx index 2383cac732..65ad58c868 100644 --- a/agenta-web/src/components/HumanEvaluationModal/HumanEvaluationModal.tsx +++ b/agenta-web/src/components/HumanEvaluationModal/HumanEvaluationModal.tsx @@ -6,7 +6,7 @@ import {isDemo} from "@/lib/helpers/utils" import {Button, Col, Dropdown, MenuProps, Modal, ModalProps, Row, Spin, message} from "antd" import {getErrorMessage} from "@/lib/helpers/errorHandler" import {EvaluationType} from "@/lib/enums" -import {PERMISSION_ERR_MSG} from "@/lib/helpers/axiosConfig" +import {PERMISSION_ERR_MSG} from "@/lib/api/assets/axiosConfig" import {getAllVariantParameters} from "@/lib/helpers/variantHelper" import {useRouter} from "next/router" import {useAppTheme} from "../Layout/ThemeContextProvider" diff --git a/agenta-web/src/contexts/app.context.tsx b/agenta-web/src/contexts/app.context.tsx index 548aa34f39..e0e6768dc7 100644 --- a/agenta-web/src/contexts/app.context.tsx +++ b/agenta-web/src/contexts/app.context.tsx @@ -45,12 +45,9 @@ const useApps = () => { const isMockProjectId = projectId === DEFAULT_UUID const {selectedOrg, loading} = useOrgData() + const shouldFetch = !!user && (!isDemo() || !!selectedOrg?.id) const {data, error, isLoading, mutate} = useSWR( - !!user - ? `${getAgentaApiUrl()}/api/apps?` + - (!isMockProjectId ? `project_id=${projectId}&` : "") - : null, - !!user ? (isDemo() ? (selectedOrg?.id ? axiosFetcher : () => {}) : axiosFetcher) : null, + shouldFetch ? `/api/apps?` + (!isMockProjectId ? `project_id=${projectId}&` : "") : null, { shouldRetryOnError: false, }, diff --git a/agenta-web/src/lib/api/SWRConfig.tsx b/agenta-web/src/lib/api/SWRConfig.tsx new file mode 100644 index 0000000000..b393aedbdf --- /dev/null +++ b/agenta-web/src/lib/api/SWRConfig.tsx @@ -0,0 +1,19 @@ +import {SWRConfig, type SWRConfiguration} from "swr" +import axios from "@/lib/api/assets/axiosConfig" + +const config: SWRConfiguration = { + fetcher: (url: string) => axios.get(url).then((res) => res.data), +} + +const AgSWRConfig = ({ + children, + config: passedConfig = {}, +}: { + children: React.ReactNode + config?: Partial +}) => { + const mergedConfig = {...config, ...passedConfig} + return {children} +} + +export default AgSWRConfig diff --git a/agenta-web/src/lib/helpers/axiosConfig.ts b/agenta-web/src/lib/api/assets/axiosConfig.ts similarity index 94% rename from agenta-web/src/lib/helpers/axiosConfig.ts rename to agenta-web/src/lib/api/assets/axiosConfig.ts index 0961ebe87c..3da6bbe2a5 100644 --- a/agenta-web/src/lib/helpers/axiosConfig.ts +++ b/agenta-web/src/lib/api/assets/axiosConfig.ts @@ -1,8 +1,8 @@ import axiosApi from "axios" -import {getErrorMessage, globalErrorHandler} from "./errorHandler" +import {getErrorMessage, globalErrorHandler} from "../../helpers/errorHandler" import {signOut} from "supertokens-auth-react/recipe/session" import router from "next/router" -import {getAgentaApiUrl} from "./utils" +import {getAgentaApiUrl} from "../../helpers/utils" import isObject from "lodash/isObject" import AlertPopup from "@/components/AlertPopup/AlertPopup" diff --git a/agenta-web/src/lib/hooks/useVariant.ts b/agenta-web/src/lib/hooks/useVariant.ts index 676fa64899..525f54d6bd 100644 --- a/agenta-web/src/lib/hooks/useVariant.ts +++ b/agenta-web/src/lib/hooks/useVariant.ts @@ -1,7 +1,7 @@ import {useState, useEffect, useRef} from "react" import {Variant, Parameter} from "@/lib/Types" import {getAllVariantParameters, updateInputParams} from "@/lib/helpers/variantHelper" -import {PERMISSION_ERR_MSG} from "../helpers/axiosConfig" +import {PERMISSION_ERR_MSG} from "../api/assets/axiosConfig" import {createNewVariant, fetchVariantLogs, updateVariantParams} from "@/services/playground/api" /** diff --git a/agenta-web/src/pages/_app.tsx b/agenta-web/src/pages/_app.tsx index 8866c081f8..b24e72a3a0 100644 --- a/agenta-web/src/pages/_app.tsx +++ b/agenta-web/src/pages/_app.tsx @@ -12,6 +12,7 @@ import ProjectContextProvider from "@/contexts/project.context" import "ag-grid-community/styles/ag-grid.css" import "ag-grid-community/styles/ag-theme-alpine.css" import {Inter} from "next/font/google" +import AgSWRConfig from "@/lib/api/SWRConfig" const NoMobilePageWrapper = dynamicComponent("NoMobilePageWrapper/NoMobilePageWrapper") const CustomPosthogProvider = dynamic(() => import("@/lib/helpers/analytics/AgPosthogProvider")) @@ -29,24 +30,26 @@ export default function App({Component, pageProps}: AppProps) {
- - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
) diff --git a/agenta-web/src/services/api.ts b/agenta-web/src/services/api.ts index 4031e76103..acbf35af51 100644 --- a/agenta-web/src/services/api.ts +++ b/agenta-web/src/services/api.ts @@ -1,5 +1,5 @@ import {getCurrentProject} from "@/contexts/project.context" -import axios from "@/lib//helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import Session from "supertokens-auth-react/recipe/session" import {formatDay} from "@/lib/helpers/dateTimeHelper" import { diff --git a/agenta-web/src/services/app-selector/api/index.ts b/agenta-web/src/services/app-selector/api/index.ts index f7aa7b63d2..fe28fd4550 100644 --- a/agenta-web/src/services/app-selector/api/index.ts +++ b/agenta-web/src/services/app-selector/api/index.ts @@ -1,6 +1,6 @@ import {getCurrentProject} from "@/contexts/project.context" import {AppTemplate} from "@/lib/Types" -import axios from "@/lib/helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import {dynamicContext} from "@/lib/helpers/dynamic" import {LlmProvider} from "@/lib/helpers/llmProviders" import {getAgentaApiUrl} from "@/lib/helpers/utils" diff --git a/agenta-web/src/services/deployment/api/index.ts b/agenta-web/src/services/deployment/api/index.ts index 6a7153c883..97ac167543 100644 --- a/agenta-web/src/services/deployment/api/index.ts +++ b/agenta-web/src/services/deployment/api/index.ts @@ -1,6 +1,6 @@ import {getCurrentProject} from "@/contexts/project.context" import {Environment} from "@/lib/Types" -import axios from "@/lib/helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import {getAgentaApiUrl} from "@/lib/helpers/utils" //Prefix convention: diff --git a/agenta-web/src/services/evaluations/api/index.ts b/agenta-web/src/services/evaluations/api/index.ts index e747856832..13981ae6bb 100644 --- a/agenta-web/src/services/evaluations/api/index.ts +++ b/agenta-web/src/services/evaluations/api/index.ts @@ -1,4 +1,4 @@ -import axios from "@/lib//helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import { ComparisonResultRow, Evaluator, diff --git a/agenta-web/src/services/human-evaluations/api/index.ts b/agenta-web/src/services/human-evaluations/api/index.ts index c4a8cb0e03..1c3e647ed8 100644 --- a/agenta-web/src/services/human-evaluations/api/index.ts +++ b/agenta-web/src/services/human-evaluations/api/index.ts @@ -1,4 +1,4 @@ -import axios from "@/lib//helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import { EvaluationResponseType, Evaluation, diff --git a/agenta-web/src/services/observability/core/index.ts b/agenta-web/src/services/observability/core/index.ts index 40bd3f77c5..714fed4c16 100644 --- a/agenta-web/src/services/observability/core/index.ts +++ b/agenta-web/src/services/observability/core/index.ts @@ -1,6 +1,6 @@ import {getAgentaApiUrl} from "@/lib/helpers/utils" import {_AgentaRootsResponse} from "../types" -import axios from "@/lib/helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import {getCurrentProject} from "@/contexts/project.context" //Prefix convention: diff --git a/agenta-web/src/services/playground/api/index.ts b/agenta-web/src/services/playground/api/index.ts index f04fc7aefb..404392eb4b 100644 --- a/agenta-web/src/services/playground/api/index.ts +++ b/agenta-web/src/services/playground/api/index.ts @@ -1,6 +1,6 @@ import {getCurrentProject} from "@/contexts/project.context" import {Parameter} from "@/lib/Types" -import axios from "@/lib/helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import {getAgentaApiUrl} from "@/lib/helpers/utils" //Prefix convention: diff --git a/agenta-web/src/services/project/index.ts b/agenta-web/src/services/project/index.ts index 95d629d118..cad28a54be 100644 --- a/agenta-web/src/services/project/index.ts +++ b/agenta-web/src/services/project/index.ts @@ -1,4 +1,4 @@ -import axios from "@/lib/helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import {getAgentaApiUrl} from "@/lib/helpers/utils" import {ProjectsResponse} from "./types" diff --git a/agenta-web/src/services/testsets/api/index.ts b/agenta-web/src/services/testsets/api/index.ts index e6fb42f774..8527bd46a3 100644 --- a/agenta-web/src/services/testsets/api/index.ts +++ b/agenta-web/src/services/testsets/api/index.ts @@ -1,5 +1,5 @@ import useSWR from "swr" -import axios from "@/lib/helpers/axiosConfig" +import axios from "@/lib/api/assets/axiosConfig" import {getAgentaApiUrl} from "@/lib/helpers/utils" import {axiosFetcher} from "@/services/api" import {getCurrentProject} from "@/contexts/project.context" @@ -14,11 +14,10 @@ import {getCurrentProject} from "@/contexts/project.context" export const useLoadTestsetsList = () => { const {projectId} = getCurrentProject() - const {data, error, mutate, isLoading} = useSWR( - `${getAgentaApiUrl()}/api/testsets?project_id=${projectId}`, - axiosFetcher, - {revalidateOnFocus: false, shouldRetryOnError: false}, - ) + const {data, error, mutate, isLoading} = useSWR(`/api/testsets?project_id=${projectId}`, { + revalidateOnFocus: false, + shouldRetryOnError: false, + }) return { testsets: data || [],