diff --git a/front/lib/api/assistant/jit_actions.ts b/front/lib/api/assistant/jit_actions.ts index 4c189126ec3e..010da3bccebc 100644 --- a/front/lib/api/assistant/jit_actions.ts +++ b/front/lib/api/assistant/jit_actions.ts @@ -48,7 +48,6 @@ import { } from "@app/lib/api/assistant/utils"; import type { Authenticator } from "@app/lib/auth"; import { getFeatureFlags } from "@app/lib/auth"; -import { canEnableJIT } from "@app/lib/development"; import { renderLightContentFragmentForModel } from "@app/lib/resources/content_fragment_resource"; import { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource"; import { generateRandomModelSId } from "@app/lib/resources/string_ids"; @@ -59,14 +58,14 @@ export async function isJITActionsEnabled( auth: Authenticator ): Promise { let use = false; - if (canEnableJIT(auth.getNonNullableWorkspace())) { - // For now we limit the feature flag to development and dust workspace only to not introduce an extraneous DB call - // on the critical path of conversations. - const flags = await getFeatureFlags(auth.getNonNullableWorkspace()); - if (flags.includes("conversations_jit_actions")) { - use = true; - } + + // For now we limit the feature flag to development and dust workspace only to not introduce an extraneous DB call + // on the critical path of conversations. + const flags = await getFeatureFlags(auth.getNonNullableWorkspace()); + if (flags.includes("conversations_jit_actions")) { + use = true; } + return use; } diff --git a/front/lib/auth.ts b/front/lib/auth.ts index 24ae1bde2d6b..1a3d39284602 100644 --- a/front/lib/auth.ts +++ b/front/lib/auth.ts @@ -23,6 +23,7 @@ import { Ok, WHITELISTABLE_FEATURES, } from "@dust-tt/types"; +import memoizer from "lru-memoizer"; import type { GetServerSidePropsContext, NextApiRequest, @@ -1006,15 +1007,21 @@ export async function prodAPICredentialsForOwner( }; } -export const getFeatureFlags = async ( - workspace: WorkspaceType -): Promise => { - if (ACTIVATE_ALL_FEATURES_DEV && isDevelopment()) { - return [...WHITELISTABLE_FEATURES]; - } else { - const res = await FeatureFlag.findAll({ - where: { workspaceId: workspace.id }, - }); - return res.map((flag) => flag.name); - } -}; +export const getFeatureFlags = memoizer.sync({ + load: async (workspace: WorkspaceType): Promise => { + if (ACTIVATE_ALL_FEATURES_DEV && isDevelopment()) { + return [...WHITELISTABLE_FEATURES]; + } else { + const res = await FeatureFlag.findAll({ + where: { workspaceId: workspace.id }, + }); + return res.map((flag) => flag.name); + } + }, + + hash: function (workspace: WorkspaceType) { + return `feature_flags_${workspace.id}`; + }, + + itemMaxAge: () => 3000, +}); diff --git a/front/lib/development.ts b/front/lib/development.ts index cef0f0926063..1c4be50732df 100644 --- a/front/lib/development.ts +++ b/front/lib/development.ts @@ -17,10 +17,6 @@ export function canForceUserRole(owner: LightWorkspaceType) { return isDevelopment() || isADustProdWorkspace(owner); } -export function canEnableJIT(owner: LightWorkspaceType) { - return isDevelopment() || isADustProdWorkspace(owner); -} - export async function forceUserRole( user: UserType, owner: LightWorkspaceType, diff --git a/front/package-lock.json b/front/package-lock.json index ea41ddfc1e75..e2b03265d0ec 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -66,6 +66,7 @@ "jszip": "^3.10.1", "jwks-rsa": "^3.1.0", "lodash": "^4.17.21", + "lru-memoizer": "^2.2.0", "lucide-react": "^0.363.0", "luxon": "^3.4.4", "marked": "^14.1.3", @@ -175,7 +176,7 @@ }, "../sdks/js": { "name": "@dust-tt/client", - "version": "1.0.6", + "version": "1.0.7", "license": "ISC", "dependencies": { "eventsource-parser": "^1.1.1", diff --git a/front/package.json b/front/package.json index 39c808eedec8..1908349907f0 100644 --- a/front/package.json +++ b/front/package.json @@ -81,6 +81,7 @@ "lodash": "^4.17.21", "lucide-react": "^0.363.0", "luxon": "^3.4.4", + "lru-memoizer": "^2.2.0", "marked": "^14.1.3", "mermaid": "^10.9.0", "minimist": "^1.2.8",