Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor(web): reroute leftover dual-use feature deep imports through server doors (#17770)

Nikita Kabardin181a6c871df7
diff --git a/web/src/__tests__/server/apiKeyCacheInvalidation.servertest.ts b/web/src/__tests__/server/apiKeyCacheInvalidation.servertest.ts
index 408b5643d6..c1f47a5f02 100644
--- a/web/src/__tests__/server/apiKeyCacheInvalidation.servertest.ts
+++ b/web/src/__tests__/server/apiKeyCacheInvalidation.servertest.ts
@@ -20,10 +20,16 @@ import {
// organizations.delete cancels Stripe before deleting; the test env has a cloud
// region but no Stripe, so force the self-hosted path to reach the eviction.
-vi.mock("@/src/ee/features/billing/utils/isCloudBilling", () => ({
+vi.mock("@/src/ee/features/billing/utils/isCloudBillingEnabled", () => ({
isCloudBillingEnabled: () => false,
- useIsCloudBillingAvailable: () => false,
}));
+vi.mock("@/src/ee/features/billing/server", async (importOriginal) => {
+ const actual = (await importOriginal()) as Record<string, unknown>;
+ return {
+ ...actual,
+ isCloudBillingEnabled: () => false,
+ };
+});
import { appRouter } from "@/src/server/api/root";
import { createInnerTRPCContext } from "@/src/server/api/trpc";
diff --git a/web/src/__tests__/server/unit/cloudBillingRouter.servertest.ts b/web/src/__tests__/server/unit/cloudBillingRouter.servertest.ts
index 5c22033a6b..7063e5e9b7 100644
--- a/web/src/__tests__/server/unit/cloudBillingRouter.servertest.ts
+++ b/web/src/__tests__/server/unit/cloudBillingRouter.servertest.ts
@@ -29,7 +29,7 @@ vi.mock("@/src/features/audit-logs/server", () => ({
auditLog: mocks.auditLog,
}));
-vi.mock("@/src/ee/features/billing/utils/isCloudBilling", () => ({
+vi.mock("@/src/ee/features/billing/utils/isCloudBillingEnabled", () => ({
isCloudBillingEnabled: mocks.isCloudBillingEnabled,
}));
diff --git a/web/src/ee/features/billing/index.ts b/web/src/ee/features/billing/index.ts
index 6693253e54..8a32993d6e 100644
--- a/web/src/ee/features/billing/index.ts
+++ b/web/src/ee/features/billing/index.ts
@@ -5,8 +5,9 @@
// BillingSettings stays off this door: OrganizationSettingsPage is the
// only consumer, and putting the settings page here would pull billing
// UI into every SupportOrUpgradePage importer. isCloudBillingEnabled
-// stays a deep import for server callers (rule 10) — it shares a module
-// with the client hook. stripeCatalogue, chbProjectEvents, and
-// resolveBillingService live on server/index.ts.
+// lives on server/index.ts so server callers do not load this hook.
+// stripeCatalogue stays deep so entitlements getPlan does not load the
+// billing service graph. chbProjectEvents and resolveBillingService
+// live on server/index.ts.
export { SupportOrUpgradePage } from "@/src/ee/features/billing/components/SupportOrUpgradePage";
export { useIsCloudBillingAvailable } from "@/src/ee/features/billing/utils/isCloudBilling";
diff --git a/web/src/ee/features/billing/server/cloudBillingRouter.ts b/web/src/ee/features/billing/server/cloudBillingRouter.ts
index 2d6da9a019..0fe4f19dcf 100644
--- a/web/src/ee/features/billing/server/cloudBillingRouter.ts
+++ b/web/src/ee/features/billing/server/cloudBillingRouter.ts
@@ -12,7 +12,7 @@ import { auditLog } from "@/src/features/audit-logs/server";
import { logger } from "@langfuse/shared/src/server";
import { type BillingProvider } from "@langfuse/shared";
import { resolveBillingService } from "./resolveBillingService";
-import { isCloudBillingEnabled } from "../utils/isCloudBilling";
+import { isCloudBillingEnabled } from "../utils/isCloudBillingEnabled";
const PROVIDER_LABEL: Record<BillingProvider, string> = {
stripe: "Stripe",
diff --git a/web/src/ee/features/billing/server/index.ts b/web/src/ee/features/billing/server/index.ts
index e3435ba575..c23dd061d7 100644
--- a/web/src/ee/features/billing/server/index.ts
+++ b/web/src/ee/features/billing/server/index.ts
@@ -7,4 +7,5 @@ export {
emitChbProjectEvent,
sendChbProjectEvent,
} from "@/src/ee/features/billing/server/chb/chbProjectEvents";
+export { isCloudBillingEnabled } from "@/src/ee/features/billing/utils/isCloudBillingEnabled";
export { resolveBillingService } from "@/src/ee/features/billing/server/resolveBillingService";
diff --git a/web/src/ee/features/billing/utils/isCloudBilling.ts b/web/src/ee/features/billing/utils/isCloudBilling.ts
index 1052cb0331..4b339b4947 100644
--- a/web/src/ee/features/billing/utils/isCloudBilling.ts
+++ b/web/src/ee/features/billing/utils/isCloudBilling.ts
@@ -1,19 +1,5 @@
-import { env } from "@/src/env.mjs";
import { useLangfuseCloudRegion } from "@/src/features/organizations";
-/**
- * Server-side check to determine if cloud billing is enabled.
- * Cloud billing requires NEXT_PUBLIC_LANGFUSE_CLOUD_REGION to be set.
- *
- * Use this in server-side code (tRPC routers, API routes).
- * For client-side components, use the hook useIsCloudBillingAvailable.
- *
- * @returns true if cloud billing should be active
- */
-export function isCloudBillingEnabled(): boolean {
- return Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
-}
-
/**
* Client-side hook to check if cloud billing features are available.
* Uses the NEXT_PUBLIC_LANGFUSE_CLOUD_REGION to determine availability.
diff --git a/web/src/ee/features/billing/utils/isCloudBillingEnabled.ts b/web/src/ee/features/billing/utils/isCloudBillingEnabled.ts
new file mode 100644
index 0000000000..58eee925f8
--- /dev/null
+++ b/web/src/ee/features/billing/utils/isCloudBillingEnabled.ts
@@ -0,0 +1,14 @@
+import { env } from "@/src/env.mjs";
+
+/**
+ * Server-side check to determine if cloud billing is enabled.
+ * Cloud billing requires NEXT_PUBLIC_LANGFUSE_CLOUD_REGION to be set.
+ *
+ * Use this in server-side code (tRPC routers, API routes).
+ * For client-side components, use the hook useIsCloudBillingAvailable.
+ *
+ * @returns true if cloud billing should be active
+ */
+export function isCloudBillingEnabled(): boolean {
+ return Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
+}
diff --git a/web/src/features/dashboard/index.ts b/web/src/features/dashboard/index.ts
index cbbff03f84..364a0cca16 100644
--- a/web/src/features/dashboard/index.ts
+++ b/web/src/features/dashboard/index.ts
@@ -6,8 +6,9 @@
// useDashboardQueryScheduler stay off this door: mapping helpers are
// imported by widgets/utils and scores adapters, and putting the dialog or
// home-chart registry here would load that UI into every mapping consumer.
-// dashboardUiTableToViewMapping stays a deep import for server callers
-// (rule 10). Pages and dashboardRouter stay off this door.
+// dashboardUiTableToViewMapping stays on this door for client callers
+// and on server/index.ts for server callers (rule 10). Pages and
+// dashboardRouter stay off this door.
export {
buildTableFilterHref,
buildViewAsTableHint,
diff --git a/web/src/features/dashboard/server/index.ts b/web/src/features/dashboard/server/index.ts
index 9fac7a9f82..9e04e0b184 100644
--- a/web/src/features/dashboard/server/index.ts
+++ b/web/src/features/dashboard/server/index.ts
@@ -1,5 +1,9 @@
// The dashboard feature's server surface (RFC rule 9, amended): the
// public dashboard services MCP tools already imported by file path.
+export {
+ getWidgetImportFilterConfig,
+ partitionStoredUiTableFiltersToView,
+} from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
export {
addPublicDashboardPlacement,
createPublicDashboard,
diff --git a/web/src/features/mcp/server/dashboardWidgets/tools/createDashboardWidget.ts b/web/src/features/mcp/server/dashboardWidgets/tools/createDashboardWidget.ts
index af8ce12fc9..28a85ff902 100644
--- a/web/src/features/mcp/server/dashboardWidgets/tools/createDashboardWidget.ts
+++ b/web/src/features/mcp/server/dashboardWidgets/tools/createDashboardWidget.ts
@@ -8,7 +8,7 @@ import { metricAggregations } from "@langfuse/shared/query";
import { defineTool } from "@/src/features/mcp/core/define-tool";
import { runMcpTool } from "@/src/features/mcp/core/run-mcp-tool";
import { createPublicDashboardWidget } from "@/src/features/widgets/server";
-import { getWidgetImportFilterConfig } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
+import { getWidgetImportFilterConfig } from "@/src/features/dashboard/server";
import { StructuredPublicApiError } from "@/src/features/public-api";
import {
PostUnstableDashboardWidgetBody,
diff --git a/web/src/features/organizations/server/organizationRouter.ts b/web/src/features/organizations/server/organizationRouter.ts
index 76569969bd..f1c1038def 100644
--- a/web/src/features/organizations/server/organizationRouter.ts
+++ b/web/src/features/organizations/server/organizationRouter.ts
@@ -17,8 +17,10 @@ import {
isLangfuseAITracingConfigured,
redis,
} from "@langfuse/shared/src/server";
-import { resolveBillingService } from "@/src/ee/features/billing/server";
-import { isCloudBillingEnabled } from "@/src/ee/features/billing/utils/isCloudBilling";
+import {
+ isCloudBillingEnabled,
+ resolveBillingService,
+} from "@/src/ee/features/billing/server";
import { shouldAutoEnableV4 } from "@/src/features/events/server";
import { buildAdminOrgContext } from "@/src/features/organizations/server/adminOrgContext";
import { getSfdcService } from "@/src/ee/features/sfdc-sync/server";
diff --git a/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsx b/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsx
index b48aa63f84..171a2f1a24 100644
--- a/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsx
+++ b/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsx
@@ -6,7 +6,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/src/components/ui/dialog";
-import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";
+import { useUiCustomization } from "@/src/ee/features/ui-customization";
import { CreateLLMApiKeyForm } from "@/src/features/public-api/components/CreateLLMApiKeyForm";
import { useHasProjectAccess } from "@/src/features/rbac";
diff --git a/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx b/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx
index 21fa612456..fde6c1dcdd 100644
--- a/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx
+++ b/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx
@@ -13,7 +13,7 @@ vi.mock("@/src/features/rbac", () => ({
vi.mock("@/src/features/posthog-analytics", () => ({
usePostHogClientCapture: () => vi.fn(),
}));
-vi.mock("@/src/ee/features/ui-customization/useUiCustomization", () => ({
+vi.mock("@/src/ee/features/ui-customization", () => ({
useUiCustomization: () => undefined,
}));
vi.mock("./CreateLLMApiKeyDialog", () => ({
diff --git a/web/src/features/widgets/server/public-dashboard-widget-service.ts b/web/src/features/widgets/server/public-dashboard-widget-service.ts
index 84a46748ab..7898923e1a 100644
--- a/web/src/features/widgets/server/public-dashboard-widget-service.ts
+++ b/web/src/features/widgets/server/public-dashboard-widget-service.ts
@@ -24,7 +24,7 @@ import { ChartConfigSchema, LangfuseNotFoundError } from "@langfuse/shared";
import {
getWidgetImportFilterConfig,
partitionStoredUiTableFiltersToView,
-} from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
+} from "@/src/features/dashboard/server";
import {
MAX_PIVOT_TABLE_DIMENSIONS,
MAX_PIVOT_TABLE_METRICS,