Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhance]: eliminate-overwriting code #2381

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
489e3d4
refactor(frontend) removed src/_app.tsx file
ashrafchowdury Dec 18, 2024
f88c8fa
refactor(frontend): removed observability index file from oss
ashrafchowdury Dec 18, 2024
bcc6973
Merge branch 'dev' of github.com:agenta-ai/agenta into enhance/eliman…
ashrafchowdury Dec 22, 2024
aed3775
refactor(frontend): moved auth init code from _app.tsx to a component
ashrafchowdury Dec 23, 2024
b8b5d29
enhance(frontend): conditionally rendering the OrgProvided
ashrafchowdury Dec 23, 2024
602c425
refactor(frontend): noved scripts from _app.tsx
ashrafchowdury Dec 23, 2024
785d4c1
fix(frontend): import cloud component error
ashrafchowdury Dec 23, 2024
27140a1
enhanc(frontend): updated _app.tsx file with new providers
ashrafchowdury Dec 23, 2024
2382279
fix(frontend): import cloud components error
ashrafchowdury Dec 23, 2024
05b3aa5
fix(frontend): auth condif error by adding ts-ignore
ashrafchowdury Dec 24, 2024
5fb8ac4
enhance(frontend): senntry initilization
ashrafchowdury Dec 24, 2024
4a99aab
fix(frontend): sentry initlization hook
ashrafchowdury Dec 24, 2024
f5e8696
refactor(frontend: moved posthog configs
ashrafchowdury Dec 24, 2024
eac97ac
enhance(frontend): .eslintrc.json file
ashrafchowdury Dec 24, 2024
5bb9475
enhance(frontend): avoid overwriting next.config.js file
ashrafchowdury Dec 24, 2024
13ab782
cleanup(frontend): fix types and made the code consistent
ashrafchowdury Dec 24, 2024
7c4477c
fix(frontend): failure cypress test
ashrafchowdury Dec 24, 2024
1fe6303
enhance(frontend): improve the code structure
ashrafchowdury Dec 24, 2024
e06a26e
Merge branch 'enhance/elimanate-overwritting-code' of github.com:agen…
ashrafchowdury Dec 24, 2024
c534d93
fix(frontend): improved the GlobalScript code
ashrafchowdury Dec 24, 2024
3fa3ede
refactor(frontend): removed isLoading to utilize the existing state
ashrafchowdury Dec 24, 2024
e30f384
Merge branch 'dev' into enhance/elimanate-overwritting-code
ardaerzin Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion agenta-web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": ["next/core-web-vitals"],
"rules": {
"react/no-unescaped-entities": 0,
"react/display-name": 0
"react/display-name": 0,
"@next/next/no-sync-scripts": 0,
"react/no-children-prop": 0
}
}
3 changes: 2 additions & 1 deletion agenta-web/cypress/support/commands/evaluations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Cypress.Commands.add("createVariantsAndTestsets", () => {
cy.wrap(testsetName).as("testsetName")

cy.get(".ag-row").should("have.length", 1)
cy.get('[data-cy="testset-header-column-edit-button"]').eq(0).click()
cy.wait(2000)
cy.get('[data-cy="testset-header-column-edit-button"]').eq(0).should("exist").click()
cy.get('[data-cy="testset-header-column-edit-input"]').clear()
cy.get('[data-cy="testset-header-column-edit-input"]').type("country")
cy.get('[data-cy="testset-header-column-save-button"]').click()
Expand Down
59 changes: 57 additions & 2 deletions agenta-web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
const nextConfig = {
output: "standalone",
reactStrictMode: true,
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
pageExtensions: ["ts", "tsx", "js", "jsx"],
productionBrowserSourceMaps: true,
transpilePackages: [
"@lobehub/ui",
Expand All @@ -26,6 +26,11 @@ const nextConfig = {
images: {
remotePatterns: [{hostname: "fps.cdnpk.net"}],
},
...(process.env.NEXT_PUBLIC_FF === "cloud" && {
experimental: {
instrumentationHook: true,
},
}),

async redirects() {
return [
Expand Down Expand Up @@ -54,8 +59,58 @@ const nextConfig = {
)
}

if (process.env.NEXT_PUBLIC_FF === "cloud") {
config.plugins.push(
new webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: true,
__RRWEB_EXCLUDE_IFRAME__: true,
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
}),
)
}

return config
},
}

module.exports = withBundleAnalyzer(nextConfig)
if (process.env.NEXT_PUBLIC_FF === "cloud") {
const {withSentryConfig} = require("@sentry/nextjs")

module.exports = withBundleAnalyzer(
withSentryConfig(
nextConfig,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

// Suppresses source map uploading logs during build
silent: true,
org: "agenta-ai",
project: "javascript-nextjs",
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: true,

// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: "/monitoring",

// Hides source maps from generated client bundles
hideSourceMaps: true,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
},
),
)
} else {
module.exports = withBundleAnalyzer(nextConfig)
}
14 changes: 0 additions & 14 deletions agenta-web/src/_app.tsx

This file was deleted.

29 changes: 29 additions & 0 deletions agenta-web/src/components/OrgWrapper/OrgWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {useState, useEffect, useCallback, ComponentType, FC} from "react"
import {isDemo} from "@/lib/helpers/utils"
import {dynamicContext} from "@/lib/helpers/dynamic"

type OrgWrapperProps = {children: React.ReactNode}

const OrgWrapper: FC<OrgWrapperProps> = ({children}) => {
const [OrgContextProvider, setOrgContextProvider] =
useState<ComponentType<OrgWrapperProps> | null>(null)

const initializeOrgProvider = useCallback(async () => {
const Provider = await dynamicContext("org.context")
setOrgContextProvider(() => Provider.default)
}, [])

useEffect(() => {
if (isDemo()) {
initializeOrgProvider()
}
}, [initializeOrgProvider])

if (isDemo() && OrgContextProvider) {
return <OrgContextProvider>{children}</OrgContextProvider>
}

return <>{children}</>
}

export default OrgWrapper
37 changes: 37 additions & 0 deletions agenta-web/src/components/Scripts/GlobalScripts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {useState, useEffect, useCallback, ComponentType} from "react"
import Head from "next/head"
import {isDemo} from "@/lib/helpers/utils"
import {dynamicComponent} from "@/lib/helpers/dynamic"

const GlobalScripts = () => {
const [CloudScripts, setCloudScripts] = useState<ComponentType | null>(null)
const [isLoading, setIsLoading] = useState(false)
ashrafchowdury marked this conversation as resolved.
Show resolved Hide resolved

const initializeScripts = useCallback(() => {
const Scripts = dynamicComponent("Scripts/assets/CloudScripts")
setCloudScripts((prev: any) => prev || Scripts)
ashrafchowdury marked this conversation as resolved.
Show resolved Hide resolved
}, [])

useEffect(() => {
ashrafchowdury marked this conversation as resolved.
Show resolved Hide resolved
if (!isLoading && isDemo()) {
ashrafchowdury marked this conversation as resolved.
Show resolved Hide resolved
setIsLoading(true)
ashrafchowdury marked this conversation as resolved.
Show resolved Hide resolved

initializeScripts()
}
}, [initializeScripts, isLoading])
ashrafchowdury marked this conversation as resolved.
Show resolved Hide resolved

if (isDemo() && CloudScripts) {
return <CloudScripts />
}

return (
<>
<Head>
<title>Agenta: The LLMOps platform.</title>
<link rel="shortcut icon" href="/assets/favicon.ico" />
</Head>
</>
)
}

export default GlobalScripts
8 changes: 5 additions & 3 deletions agenta-web/src/lib/helpers/analytics/AgPosthogProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {useRouter} from "next/router"
import {useAtom} from "jotai"
import {posthogAtom, type PostHogConfig} from "./store/atoms"
import {CustomPosthogProviderType} from "./types"
import {CLOUD_CONFIG, OSS_CONFIG} from "./assets/constants"
import {isDemo} from "../utils"

const CustomPosthogProvider: CustomPosthogProviderType = ({children, config}) => {
const CustomPosthogProvider: CustomPosthogProviderType = ({children}) => {
const router = useRouter()
const [loadingPosthog, setLoadingPosthog] = useState(false)
const [posthogClient, setPosthogClient] = useAtom(posthogAtom)
Expand All @@ -26,12 +28,12 @@ const CustomPosthogProvider: CustomPosthogProviderType = ({children, config}) =>
if (process.env.NODE_ENV === "development") posthog.debug()
},
capture_pageview: false,
...config,
...((isDemo() ? CLOUD_CONFIG : OSS_CONFIG) as Partial<PostHogConfig>),
})
} finally {
setLoadingPosthog(false)
}
}, [loadingPosthog, config, posthogClient, setPosthogClient])
}, [loadingPosthog, posthogClient, setPosthogClient])

useEffect(() => {
initPosthog()
Expand Down
12 changes: 12 additions & 0 deletions agenta-web/src/lib/helpers/analytics/assets/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const CLOUD_CONFIG = {
session_recording: {
maskAllInputs: false,
maskInputOptions: {
password: true,
email: true,
},
},
}
export const OSS_CONFIG = {
persistence: "localStorage+cookie",
}
1 change: 0 additions & 1 deletion agenta-web/src/lib/helpers/analytics/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import {type PostHogConfig} from "./store/atoms"
export interface CustomPosthogProviderType
extends React.FC<{
children: React.ReactNode
config: Partial<PostHogConfig>
}> {}
37 changes: 37 additions & 0 deletions agenta-web/src/lib/helpers/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {useEffect, useCallback} from "react"
import SuperTokensReact, {SuperTokensWrapper} from "supertokens-auth-react"
import {AuthProviderType} from "./types"
import {isDemo} from "../utils"
import {dynamicConfig} from "../dynamic"
;(async () => {
if (typeof window !== "undefined" && isDemo()) {
const {frontendConfig} = await dynamicConfig("frontendConfig")
SuperTokensReact.init(frontendConfig())
}
})()

const AuthProvider: AuthProviderType = ({children, pageProps}) => {
const doRefresh = useCallback(async () => {
if (isDemo() && pageProps.fromSupertokens === "needs-refresh") {
const session = await import("supertokens-auth-react/recipe/session")

if (await session.attemptRefreshingSession()) {
location.reload()
} else {
SuperTokensReact.redirectToAuth()
}
}
}, [pageProps.fromSupertokens])

useEffect(() => {
doRefresh()
}, [doRefresh])

if (isDemo() && pageProps.fromSupertokens === "needs-refresh") {
return null
}

return isDemo() ? <SuperTokensWrapper>{children}</SuperTokensWrapper> : <>{children}</>
}

export default AuthProvider
5 changes: 5 additions & 0 deletions agenta-web/src/lib/helpers/auth/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface AuthProviderType
extends React.FC<{
children: React.ReactNode
pageProps: any
}> {}
8 changes: 8 additions & 0 deletions agenta-web/src/lib/helpers/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ export async function dynamicLib(path: string, fallback?: any) {
return fallback
}
}

export async function dynamicConfig(path: string, fallback?: any) {
try {
return await import(`@/config/${path}`)
} catch (error) {
return fallback
}
}
20 changes: 20 additions & 0 deletions agenta-web/src/lib/helpers/sentry/hook/useSentryIntegrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {useCallback, useEffect, useRef} from "react"
import {dynamicLib} from "../../dynamic"
import {isDemo} from "../../utils"

export const useSentryIntegrations = () => {
const isLoading = useRef(false)

const initializeSentryIntegrations = useCallback(async () => {
const initSentry = await dynamicLib("helpers/sentry/lazyLoadSentryIntegrations")
initSentry?.lazyLoadSentryIntegrations()
}, [])

useEffect(() => {
if (!isLoading.current && isDemo()) {
isLoading.current = true

initializeSentryIntegrations()
}
}, [])
}
47 changes: 25 additions & 22 deletions agenta-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {AppProps} from "next/app"
import Head from "next/head"
import dynamic from "next/dynamic"

import "@/styles/globals.css"
Expand All @@ -9,8 +8,12 @@ import ThemeContextProvider from "@/components/Layout/ThemeContextProvider"
import AppContextProvider from "@/contexts/app.context"
import ProfileContextProvider from "@/contexts/profile.context"
import ProjectContextProvider from "@/contexts/project.context"
import AuthProvider from "@/lib/helpers/auth/AuthProvider"
import OrgWrapper from "@/components/OrgWrapper/OrgWrapper"
import GlobalScripts from "@/components/Scripts/GlobalScripts"
import {Inter} from "next/font/google"
import AgSWRConfig from "@/lib/api/SWRConfig"
import {useSentryIntegrations} from "@/lib/helpers/sentry/hook/useSentryIntegrations"

const NoMobilePageWrapper = dynamicComponent("NoMobilePageWrapper/NoMobilePageWrapper")
const CustomPosthogProvider = dynamic(() => import("@/lib/helpers/analytics/AgPosthogProvider"))
Expand All @@ -21,31 +24,31 @@ const inter = Inter({
})

export default function App({Component, pageProps}: AppProps) {
useSentryIntegrations()

return (
<>
<Head>
<title>Agenta: The LLMOps platform.</title>
<link rel="shortcut icon" href="/assets/favicon.ico" />
</Head>
<GlobalScripts />

<main className={`${inter.variable} font-sans`}>
<AgSWRConfig>
<CustomPosthogProvider
config={{
persistence: "localStorage+cookie",
}}
>
<ThemeContextProvider>
<ProfileContextProvider>
<ProjectContextProvider>
<AppContextProvider>
<Layout>
<Component {...pageProps} />
<NoMobilePageWrapper />
</Layout>
</AppContextProvider>
</ProjectContextProvider>
</ProfileContextProvider>
</ThemeContextProvider>
<CustomPosthogProvider>
<AuthProvider pageProps={pageProps}>
<ThemeContextProvider>
<ProfileContextProvider>
<OrgWrapper>
<ProjectContextProvider>
<AppContextProvider>
<Layout>
<Component {...pageProps} />
<NoMobilePageWrapper />
</Layout>
</AppContextProvider>
</ProjectContextProvider>
</OrgWrapper>
</ProfileContextProvider>
</ThemeContextProvider>
</AuthProvider>
</CustomPosthogProvider>
</AgSWRConfig>
</main>
Expand Down
6 changes: 0 additions & 6 deletions agenta-web/src/services/observability/api/index.ts

This file was deleted.

Loading