Skip to content

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

chore(shared): Move web utils needed by in-app-agent runtime to shared (#15428)

Lysander Kiesel271f755bc1ef
diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.ts
index b5b844889c..31d9040eac 100644
--- a/packages/shared/src/env.ts
+++ b/packages/shared/src/env.ts
@@ -39,6 +39,9 @@ const EnvSchema = z.object({
.enum(["development", "test", "production"])
.default("development"),
NEXTAUTH_URL: z.url().optional(),
+ // NextAuth.js falls back to VERCEL_URL when NEXTAUTH_URL is unset; the
+ // shared base-URL helper mirrors that (see web/src/env.mjs preprocess).
+ VERCEL_URL: z.string().optional(),
EMAIL_FROM_ADDRESS: z.string().optional(),
// Standard SMTP URL (`smtp://`, `smtps://`) or `ses://<region>` to send via
// AWS SES using the default AWS credential chain (IAM role, SSO, env vars).
@@ -484,6 +487,7 @@ const EnvSchema = z.object({
.default(120_000), // 2 minutes
LANGFUSE_AWS_BEDROCK_REGION: z.string().optional(),
+ LANGFUSE_AWS_BEDROCK_MODEL: z.string().optional(),
LANGFUSE_AWS_BEDROCK_SMALL_MODEL: z.string().optional(),
LANGFUSE_IN_APP_AGENT_AWS_PROFILE: z.string().optional(),
diff --git a/web/src/features/filters/lib/filter-query-encoding.ts b/packages/shared/src/features/filters/filterQueryEncoding.ts
similarity index 96%
rename from web/src/features/filters/lib/filter-query-encoding.ts
rename to packages/shared/src/features/filters/filterQueryEncoding.ts
index 5e4924021c..a9ae14b938 100644
--- a/web/src/features/filters/lib/filter-query-encoding.ts
+++ b/packages/shared/src/features/filters/filterQueryEncoding.ts
@@ -1,9 +1,7 @@
-import {
- type FilterState,
- singleFilter,
- type SingleValueOption,
-} from "@langfuse/shared";
-import { normalizeLegacySessionPositionInTraceKey } from "@/src/components/session/session-position-in-trace";
+import { type FilterState } from "../../types";
+import { singleFilter } from "../../interfaces/filters";
+import { type SingleValueOption } from "../../tableDefinitions/types";
+import { normalizeLegacySessionPositionInTraceKey } from "./sessionPositionInTrace";
const encodeDelimitedArray = (values: string[], delimiter: string): string =>
values.join(delimiter);
diff --git a/web/src/features/filters/constants/internal-environments.ts b/packages/shared/src/features/filters/internalEnvironments.ts
similarity index 85%
rename from web/src/features/filters/constants/internal-environments.ts
rename to packages/shared/src/features/filters/internalEnvironments.ts
index e7b9008c1e..8157a97d4d 100644
--- a/web/src/features/filters/constants/internal-environments.ts
+++ b/packages/shared/src/features/filters/internalEnvironments.ts
@@ -1,4 +1,4 @@
-import { LangfuseInternalTraceEnvironment } from "@langfuse/shared";
+import { LangfuseInternalTraceEnvironment } from "../../server/llm/types";
export const DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS = [
LangfuseInternalTraceEnvironment.PromptExperiments,
diff --git a/web/src/components/session/session-position-in-trace.ts b/packages/shared/src/features/filters/sessionPositionInTrace.ts
similarity index 96%
rename from web/src/components/session/session-position-in-trace.ts
rename to packages/shared/src/features/filters/sessionPositionInTrace.ts
index 4f1f14d4ec..f49ad215bd 100644
--- a/web/src/components/session/session-position-in-trace.ts
+++ b/packages/shared/src/features/filters/sessionPositionInTrace.ts
@@ -1,4 +1,4 @@
-import { type FilterState } from "@langfuse/shared";
+import { type FilterState } from "../../types";
type PositionInTraceFilter = Extract<
FilterState[number],
diff --git a/web/src/features/rbac/constants/projectAccessRights.ts b/packages/shared/src/features/rbac/projectAccessRights.ts
similarity index 92%
rename from web/src/features/rbac/constants/projectAccessRights.ts
rename to packages/shared/src/features/rbac/projectAccessRights.ts
index c0390cd342..5c8721c0a7 100644
--- a/web/src/features/rbac/constants/projectAccessRights.ts
+++ b/packages/shared/src/features/rbac/projectAccessRights.ts
@@ -1,4 +1,4 @@
-import { type Role } from "@langfuse/shared/src/db";
+import { type Role } from "../../db";
// Exported to silence @typescript-eslint/no-unused-vars v8 warning
// (used for type extraction via typeof, which is a legitimate pattern)
@@ -273,3 +273,17 @@ export const projectRoleAccessRights: Record<Role, ProjectScope[]> = {
export const projectNoneRoleComment =
"Do not override the organization role for this project.";
+
+/**
+ * Pure role-based access check (no session), for callers that already
+ * resolved the caller's project role — e.g. the in-app agent runtime.
+ * Mirrors the role branch of web's `hasProjectAccess`.
+ */
+export function hasProjectAccessByRole(p: {
+ role: Role;
+ scope: ProjectScope;
+ admin?: boolean;
+}): boolean {
+ if (p.admin) return true;
+ return projectRoleAccessRights[p.role].includes(p.scope);
+}
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index 77e1c87526..130868ea1d 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -49,6 +49,17 @@ export { BatchTableNames } from "./interfaces/tableNames";
// in-app agent
export * from "./features/inAppAgent/types";
+// rbac
+export * from "./features/rbac/projectAccessRights";
+
+// filters
+export * from "./features/filters/internalEnvironments";
+export * from "./features/filters/filterQueryEncoding";
+export * from "./features/filters/sessionPositionInTrace";
+
+// date ranges
+export * from "./utils/dateRanges";
+
// annotation
export * from "./features/annotation/types";
diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.ts
index 1d69c59392..fe588d7e7e 100644
--- a/packages/shared/src/server/index.ts
+++ b/packages/shared/src/server/index.ts
@@ -50,6 +50,9 @@ export * from "./llm/utils";
export * from "./llm/types";
export * from "./llm/promptToolConfig";
export * from "./llm/internalTraceEvents";
+export * from "./llm/langfuseAiCompletion";
+export * from "./utils/baseUrl";
+export * from "./utils/productUrl";
export * from "./llm/compileChatMessages";
export * from "./llm/testModelCall";
export * from "./llm/baseUrlValidation";
diff --git a/web/src/features/ai-features/server/bedrockCompletion.ts b/packages/shared/src/server/llm/langfuseAiCompletion.ts
similarity index 85%
rename from web/src/features/ai-features/server/bedrockCompletion.ts
rename to packages/shared/src/server/llm/langfuseAiCompletion.ts
index 9d61500764..8b754659e1 100644
--- a/web/src/features/ai-features/server/bedrockCompletion.ts
+++ b/packages/shared/src/server/llm/langfuseAiCompletion.ts
@@ -1,16 +1,10 @@
-import { BEDROCK_USE_DEFAULT_CREDENTIALS } from "@langfuse/shared";
-import { encrypt } from "@langfuse/shared/encryption";
-import {
- type ChatMessage,
- generateLLMText,
- LLMAdapter,
- mapLegacyLLMCompletionParams,
- type TraceSinkParams,
-} from "@langfuse/shared/src/server";
+import { BEDROCK_USE_DEFAULT_CREDENTIALS } from "../../interfaces/customLLMProviderConfigSchemas";
+import { encrypt } from "../../encryption";
+import { env } from "../../env";
+import { type ChatMessage, LLMAdapter, type TraceSinkParams } from "./types";
+import { generateLLMText, mapLegacyLLMCompletionParams } from "./llmText";
import { randomBytes } from "crypto";
-import { env } from "@/src/env.mjs";
-
export function isLangfuseAITracingConfigured() {
return Boolean(env.LANGFUSE_AI_FEATURES_PROJECT_ID);
}
diff --git a/packages/shared/src/server/utils/baseUrl.ts b/packages/shared/src/server/utils/baseUrl.ts
new file mode 100644
index 0000000000..0e9311e46f
--- /dev/null
+++ b/packages/shared/src/server/utils/baseUrl.ts
@@ -0,0 +1,35 @@
+import { env } from "../../env";
+
+const LOCALHOST_HOST_PATTERN = /^(localhost|127\.0\.0\.1|\[::1\])(?::|\/|$)/i;
+
+export const getBaseUrl = () => {
+ // NextAuth.js falls back to VERCEL_URL when NEXTAUTH_URL is unset (mirrors
+ // the preprocess in web/src/env.mjs).
+ const rawBaseUrl = env.NEXTAUTH_URL || env.VERCEL_URL;
+
+ if (!rawBaseUrl) {
+ throw new Error(
+ "NEXTAUTH_URL must be set to derive the Langfuse base URL.",
+ );
+ }
+
+ return new URL(
+ /^https?:\/\//i.test(rawBaseUrl)
+ ? rawBaseUrl
+ : `${LOCALHOST_HOST_PATTERN.test(rawBaseUrl) ? "http" : "https"}://${rawBaseUrl}`,
+ );
+};
+
+export const getProductBaseUrl = () => {
+ const baseUrl = getBaseUrl();
+
+ baseUrl.pathname = baseUrl.pathname.replace(/\/api\/auth\/?$/, "/");
+ baseUrl.search = "";
+ baseUrl.hash = "";
+
+ if (!baseUrl.pathname.endsWith("/")) {
+ baseUrl.pathname = `${baseUrl.pathname}/`;
+ }
+
+ return baseUrl;
+};
diff --git a/web/src/utils/product-url.ts b/packages/shared/src/server/utils/productUrl.ts
similarity index 97%
rename from web/src/utils/product-url.ts
rename to packages/shared/src/server/utils/productUrl.ts
index 94dfdc5870..7601b314bc 100644
--- a/web/src/utils/product-url.ts
+++ b/packages/shared/src/server/utils/productUrl.ts
@@ -1,14 +1,12 @@
-import {
- TableViewPresetTableName,
- type APIScoreV3,
- type FilterState,
-} from "@langfuse/shared";
-import { encodeFiltersGeneric } from "@/src/features/filters/lib/filter-query-encoding";
-import { getProductBaseUrl } from "@/src/utils/base-url";
+import { TableViewPresetTableName } from "../../domain/table-view-presets";
+import { type APIScoreV3 } from "../../features/scores/interfaces/api/v3/schemas";
+import { type FilterState } from "../../types";
+import { encodeFiltersGeneric } from "../../features/filters/filterQueryEncoding";
+import { getProductBaseUrl } from "./baseUrl";
import {
rangeToString,
type TABLE_AGGREGATION_OPTIONS,
-} from "@/src/utils/date-range-utils";
+} from "../../utils/dateRanges";
type ProductPathQuery = Record<string, string | string[] | null | undefined>;
diff --git a/packages/shared/src/utils/dateRanges.ts b/packages/shared/src/utils/dateRanges.ts
new file mode 100644
index 0000000000..6d964f5094
--- /dev/null
+++ b/packages/shared/src/utils/dateRanges.ts
@@ -0,0 +1,141 @@
+import { type DateTrunc } from "../server/repositories/dashboards";
+
+export interface TimeRangeDefinition {
+ label: string;
+ abbreviation: string;
+ minutes: number | null;
+ dateTrunc: DateTrunc | null;
+}
+
+export const TIME_RANGES = {
+ last5Minutes: {
+ label: "Past 5 min",
+ abbreviation: "5m",
+ minutes: 5,
+ dateTrunc: "minute",
+ },
+ last30Minutes: {
+ label: "Past 30 min",
+ abbreviation: "30m",
+ minutes: 30,
+ dateTrunc: "minute",
+ },
+ last1Hour: {
+ label: "Past 1 hour",
+ abbreviation: "1h",
+ minutes: 60,
+ dateTrunc: "minute",
+ },
+ last3Hours: {
+ label: "Past 3 hours",
+ abbreviation: "3h",
+ minutes: 3 * 60,
+ dateTrunc: "minute",
+ },
+ last6Hours: {
+ label: "Past 6 hours",
+ abbreviation: "6h",
+ minutes: 6 * 60,
+ dateTrunc: "minute",
+ },
+ last1Day: {
+ label: "Past 1 day",
+ abbreviation: "1d",
+ minutes: 24 * 60,
+ dateTrunc: "hour",
+ },
+ last3Days: {
+ label: "Past 3 days",
+ abbreviation: "3d",
+ minutes: 3 * 24 * 60,
+ dateTrunc: "hour",
+ },
+ last7Days: {
+ label: "Past 7 days",
+ abbreviation: "7d",
+ minutes: 7 * 24 * 60,
+ dateTrunc: "hour",
+ },
+ last14Days: {
+ label: "Past 14 days",
+ abbreviation: "14d",
+ minutes: 14 * 24 * 60,
+ dateTrunc: "day",
+ },
+ last30Days: {
+ label: "Past 30 days",
+ abbreviation: "30d",
+ minutes: 30 * 24 * 60,
+ dateTrunc: "day",
+ },
+ last90Days: {
+ label: "Past 90 days",
+ abbreviation: "90d",
+ minutes: 90 * 24 * 60,
+ dateTrunc: "week",
+ },
+ last1Year: {
+ label: "Past 1 year",
+ abbreviation: "1y",
+ minutes: 365 * 24 * 60,
+ dateTrunc: "month",
+ },
+ allTime: {
+ label: "All time",
+ abbreviation: "All",
+ minutes: null,
+ dateTrunc: null,
+ },
+ custom: {
+ label: "Custom",
+ abbreviation: "Custom",
+ minutes: null,
+ dateTrunc: null,
+ },
+} satisfies Record<string, TimeRangeDefinition>;
+
+export type TimeRangePresets = Exclude<keyof typeof TIME_RANGES, "custom">;
+
+export const TABLE_AGGREGATION_OPTIONS = [
+ "last30Minutes",
+ "last1Hour",
+ "last6Hours",
+ "last1Day",
+ "last3Days",
+ "last7Days",
+ "last14Days",
+ "last30Days",
+ "last90Days",
+] as const;
+
+export type TableDateRangeAggregationOption =
+ (typeof TABLE_AGGREGATION_OPTIONS)[number];
+
+export type RelativeTimeRange = {
+ range: string;
+};
+
+export type AbsoluteTimeRange = {
+ from: Date;
+ to: Date;
+};
+
+export type TimeRange = RelativeTimeRange | AbsoluteTimeRange;
+
+export function getAbbreviatedTimeRange(option: string): string {
+ return (
+ TIME_RANGES[option as keyof typeof TIME_RANGES]?.abbreviation || option
+ );
+}
+
+/**
+ * Converts a range object to a string for URL serialization
+ * - Named ranges: "last7Days" -> "7d" (abbreviated)
+ * - Custom ranges: {from, to} -> "1693872000000-1694131199999"
+ */
+export function rangeToString(range: TimeRange): string {
+ if ("range" in range) {
+ return getAbbreviatedTimeRange(range.range);
+ }
+ return `${range.from.getTime()}-${range.to.getTime()}`;
+}
diff --git a/packages/shared/src/utils/json.ts b/packages/shared/src/utils/json.ts
index f6c12aa574..5746feab12 100644
--- a/packages/shared/src/utils/json.ts
+++ b/packages/shared/src/utils/json.ts
@@ -473,3 +473,31 @@ export const parseJsonPrioritised = (
*/
export const parseJsonIfString = (value: unknown): unknown =>
typeof value === "string" ? parseJsonPrioritised(value) : value;
+
+export function safeJsonParse(value: string): unknown {
+ try {
+ return JSON.parse(value);
+ } catch {
+ return undefined;
+ }
+}
+
+export function stableJsonStringify(value: unknown): string {
+ return JSON.stringify(sortJsonValue(value)) ?? "undefined";
+}
+
+function sortJsonValue(value: unknown): unknown {
+ if (Array.isArray(value)) {
+ return value.map(sortJsonValue);
+ }
+
+ if (value && typeof value === "object") {
+ return Object.fromEntries(
+ Object.entries(value)
+ .sort(([left], [right]) => left.localeCompare(right))
+ .map(([key, nestedValue]) => [key, sortJsonValue(nestedValue)]),
+ );
+ }
+
+ return value;
+}
diff --git a/packages/shared/src/utils/stringChecks.ts b/packages/shared/src/utils/stringChecks.ts
index d1fc8ebd80..6484c70ec6 100644
--- a/packages/shared/src/utils/stringChecks.ts
+++ b/packages/shared/src/utils/stringChecks.ts
@@ -41,3 +41,11 @@ export function stringifyValue(value: unknown) {
return JSON.stringify(value);
}
}
+
+export function truncate(str: string, n = 16) {
+ // '...' suffix if the string is longer than n
+ if (str.length > n) {
+ return str.substring(0, n) + "...";
+ }
+ return str;
+}
diff --git a/packages/shared/src/utils/typeChecks.ts b/packages/shared/src/utils/typeChecks.ts
index 81331f818a..529683ead6 100644
--- a/packages/shared/src/utils/typeChecks.ts
+++ b/packages/shared/src/utils/typeChecks.ts
@@ -3,4 +3,8 @@ import { z } from "zod";
export const isPresent = <T>(value: T | null | undefined): value is T =>
value !== null && value !== undefined && value !== "";
+export function assertUnreachable(_x: never): never {
+ throw new Error("Didn't expect to get here");
+}
+
export const stringDateTime = z.iso.datetime({ offset: true }).nullish();
diff --git a/web/src/__tests__/server/in-app-agent-stream.servertest.ts b/web/src/__tests__/server/in-app-agent-stream.servertest.ts
index e411f94371..f7f138320f 100644
--- a/web/src/__tests__/server/in-app-agent-stream.servertest.ts
+++ b/web/src/__tests__/server/in-app-agent-stream.servertest.ts
@@ -18,8 +18,10 @@ import {
type SandboxSession,
} from "@/src/features/in-app-agent/server/sandbox";
import { IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES } from "@/src/features/in-app-agent/server/tools";
-import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@/src/features/filters/constants/internal-environments";
-import { decodeFiltersGeneric } from "@/src/features/filters/lib/filter-query-encoding";
+import {
+ DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS,
+ decodeFiltersGeneric,
+} from "@langfuse/shared";
import "@/src/features/mcp/server/bootstrap";
import { toolRegistry } from "@/src/features/mcp/server/registry";
import type { MastraAgent } from "@ag-ui/mastra";
diff --git a/web/src/__tests__/server/mcp-tools-read.servertest.ts b/web/src/__tests__/server/mcp-tools-read.servertest.ts
index f4e78cdb4d..de79056c3c 100644
--- a/web/src/__tests__/server/mcp-tools-read.servertest.ts
+++ b/web/src/__tests__/server/mcp-tools-read.servertest.ts
@@ -44,6 +44,15 @@ import {
createScoresCh,
createSessionScore,
createTraceScore,
+ buildDashboardUrl,
+ buildDashboardWidgetUrl,
+ buildEvaluatorUrl,
+ buildMonitorUrl,
+ buildExperimentUrl,
+ buildObservationUrl,
+ buildPromptUrl,
+ buildSessionUrl,
+ buildTraceUrl,
} from "@langfuse/shared/src/server";
import { ScoreConfigDataType } from "@langfuse/shared";
import { MonitorService } from "@langfuse/shared/monitors/server";
@@ -58,17 +67,6 @@ import {
import { env } from "@/src/env.mjs";
import "@/src/features/mcp/server/bootstrap";
import { toolRegistry } from "@/src/features/mcp/server/registry";
-import {
- buildDashboardUrl,
- buildDashboardWidgetUrl,
- buildEvaluatorUrl,
- buildMonitorUrl,
- buildExperimentUrl,
- buildObservationUrl,
- buildPromptUrl,
- buildSessionUrl,
- buildTraceUrl,
-} from "@/src/utils/product-url";
import { handleCreateDashboardWidget } from "@/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget";
import {
getDashboardTool,
diff --git a/web/src/components/deleteButton.tsx b/web/src/components/deleteButton.tsx
index 38e85f426d..1277f2f430 100644
--- a/web/src/components/deleteButton.tsx
+++ b/web/src/components/deleteButton.tsx
@@ -10,7 +10,7 @@ import { Button, type ButtonProps } from "@/src/components/ui/button";
import { LockIcon, TrashIcon } from "lucide-react";
import { IconOnlyButton } from "@/src/components/IconOnlyButton";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import { type ProjectScope } from "@/src/features/rbac/constants/projectAccessRights";
+import { type ProjectScope } from "@langfuse/shared";
import { api } from "@/src/utils/api";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { Input } from "@/src/components/ui/input";
diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsx
index 1dbd46b86b..94bb098571 100644
--- a/web/src/components/layouts/routes.tsx
+++ b/web/src/components/layouts/routes.tsx
@@ -1,5 +1,5 @@
import { type Flag } from "@/src/features/feature-flags/types";
-import { type ProjectScope } from "@/src/features/rbac/constants/projectAccessRights";
+import { type ProjectScope } from "@langfuse/shared";
import {
BellRing,
Database,
diff --git a/web/src/components/session/index.tsx b/web/src/components/session/index.tsx
index 537d6dda1b..f3f96e099e 100644
--- a/web/src/components/session/index.tsx
+++ b/web/src/components/session/index.tsx
@@ -43,6 +43,7 @@ import {
type FilterState,
type ScoreDomain,
TableViewPresetTableName,
+ normalizeLegacySessionPositionInTraceFilters,
} from "@langfuse/shared";
import { CreateNewAnnotationQueueItem } from "@/src/features/annotation-queues/components/CreateNewAnnotationQueueItem";
import { WebCalloutButton } from "@/src/features/web-callouts/components/WebCalloutMenuItem";
@@ -56,7 +57,6 @@ import { Switch } from "@/src/components/design-system/Switch/Switch";
import { LazySessionTraceEventsRow } from "@/src/components/session/LazySessionTraceEventsRow";
import { observationEventsFilterConfig } from "@/src/features/events/config/filter-config";
import { useEventsFilterOptions } from "@/src/features/events/hooks/useEventsFilterOptions";
-import { normalizeLegacySessionPositionInTraceFilters } from "@/src/components/session/session-position-in-trace";
import {
decodeAndNormalizeFilters,
useSidebarFilterState,
diff --git a/web/src/components/table/table-view-presets/lib/viewPreview.ts b/web/src/components/table/table-view-presets/lib/viewPreview.ts
index 8a833620f4..1a0db16a65 100644
--- a/web/src/components/table/table-view-presets/lib/viewPreview.ts
+++ b/web/src/components/table/table-view-presets/lib/viewPreview.ts
@@ -1,5 +1,8 @@
-import { type FilterState, type TableViewPresetState } from "@langfuse/shared";
-import { formatSessionPositionInTraceFilterValue } from "@/src/components/session/session-position-in-trace";
+import {
+ type FilterState,
+ type TableViewPresetState,
+ formatSessionPositionInTraceFilterValue,
+} from "@langfuse/shared";
function formatFilterLabel(filter: FilterState[number]) {
return "key" in filter && filter.key
diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsx
index 7d5daed653..a87834cabd 100644
--- a/web/src/components/table/use-cases/observations.tsx
+++ b/web/src/components/table/use-cases/observations.tsx
@@ -26,17 +26,8 @@ import {
OBSERVATION_COLUMN_TO_BACKEND_KEY,
type ObservationsOmittableFilterColumn,
} from "@/src/features/filters/config/observations-config";
-import { DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG } from "@/src/features/filters/constants/internal-environments";
-import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";
-import { formatIntervalSeconds } from "@/src/utils/dates";
-import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
-import {
- TableBadgeLoadingCell,
- TableIconBadgeLoadingCell,
- TableTextLoadingCell,
-} from "@/src/components/table/loading-cells";
-import { type LangfuseColumnDef } from "@/src/components/table/types";
import {
+ DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,
type ObservationLevelType,
type FilterState,
BatchExportTableName,
@@ -48,7 +39,17 @@ import {
type TimeFilter,
type OrderByState,
type TracingSearchType,
+ type ScoreAggregate,
} from "@langfuse/shared";
+import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";
+import { formatIntervalSeconds } from "@/src/utils/dates";
+import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
+import {
+ TableBadgeLoadingCell,
+ TableIconBadgeLoadingCell,
+ TableTextLoadingCell,
+} from "@/src/components/table/loading-cells";
+import { type LangfuseColumnDef } from "@/src/components/table/types";
import { cn } from "@/src/utils/tailwind";
import { LevelColors } from "@/src/components/level-colors";
import { numberFormatter, usdFormatter } from "@/src/utils/numbers";
@@ -62,7 +63,6 @@ import {
type TableDateRange,
} from "@/src/utils/date-range-utils";
import { TableHeaderControls } from "@/src/components/table/table-header-controls";
-import { type ScoreAggregate } from "@langfuse/shared";
import TagList from "@/src/features/tag/components/TagList";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
import { BatchExportTableButton } from "@/src/components/BatchExportTableButton";
diff --git a/web/src/components/table/use-cases/scores.tsx b/web/src/components/table/use-cases/scores.tsx
index 026da15c04..5a4adbd7d8 100644
--- a/web/src/components/table/use-cases/scores.tsx
+++ b/web/src/components/table/use-cases/scores.tsx
@@ -25,17 +25,8 @@ import {
SCORE_COLUMN_TO_BACKEND_KEY,
type ScoresTableHiddenColumn,
} from "@/src/features/filters/config/scores-config";
-import { DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG } from "@/src/features/filters/constants/internal-environments";
-import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";
-import { isNumericDataType } from "@/src/features/scores/lib/helpers";
-import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
-import { useTableDateRange } from "@/src/hooks/useTableDateRange";
-import { toAbsoluteTimeRange } from "@/src/utils/date-range-utils";
-import { api } from "@/src/utils/api";
-import { TableHeaderControls } from "@/src/components/table/table-header-controls";
-
-import type { RouterOutput } from "@/src/utils/types";
import {
+ DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,
isPresent,
type FilterState,
type ScoreDataTypeType,
@@ -45,6 +36,15 @@ import {
TableViewPresetTableName,
type TimeFilter,
} from "@langfuse/shared";
+import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";
+import { isNumericDataType } from "@/src/features/scores/lib/helpers";
+import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
+import { useTableDateRange } from "@/src/hooks/useTableDateRange";
+import { toAbsoluteTimeRange } from "@/src/utils/date-range-utils";
+import { api } from "@/src/utils/api";
+import { TableHeaderControls } from "@/src/components/table/table-header-controls";
+
+import type { RouterOutput } from "@/src/utils/types";
import TagList from "@/src/features/tag/components/TagList";
import { cn } from "@/src/utils/tailwind";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsx
index 57d0614b87..eaa1c35d9c 100644
--- a/web/src/components/table/use-cases/sessions.tsx
+++ b/web/src/components/table/use-cases/sessions.tsx
@@ -24,9 +24,8 @@ import {
SESSION_COLUMN_TO_BACKEND_KEY,
type SessionOmittableFilterColumn,
} from "@/src/features/filters/config/sessions-config";
-import { DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG } from "@/src/features/filters/constants/internal-environments";
-import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";
import {
+ DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,
type FilterState,
BatchExportTableName,
TableViewPresetTableName,
@@ -34,7 +33,9 @@ import {
BatchActionType,
ActionId,
type TimeFilter,
+ type ScoreAggregate,
} from "@langfuse/shared";
+import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";
import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context";
import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
import { api } from "@/src/utils/api";
@@ -55,7 +56,6 @@ import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrde
import { LocalIsoDate } from "@/src/components/LocalIsoDate";
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
import { Badge } from "@/src/components/ui/badge";
-import { type ScoreAggregate } from "@langfuse/shared";
import { useSelectAll } from "@/src/features/table/hooks/useSelectAll";
import { type TableAction } from "@/src/features/table/types";
import { TableActionMenu } from "@/src/features/table/components/TableActionMenu";
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index 2b51a1fab8..7b5dddbd48 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -48,12 +48,13 @@ import {
ActionId,
TableViewPresetTableName,
type TimeFilter,
+ type ScoreAggregate,
+ DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,
} from "@langfuse/shared";
import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";
import { MemoizedIOTableCell } from "../../ui/IOTableCell";
import { useTableDateRange } from "@/src/hooks/useTableDateRange";
import { toAbsoluteTimeRange } from "@/src/utils/date-range-utils";
-import { type ScoreAggregate } from "@langfuse/shared";
import { joinTableCoreAndMetrics } from "@/src/components/table/utils/joinTableCoreAndMetrics";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
import { BatchExportTableButton } from "@/src/components/BatchExportTableButton";
@@ -87,7 +88,6 @@ import {
getTraceFilterConfig,
type TraceOmittableFilterColumn,
} from "@/src/features/filters/config/traces-config";
-import { DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG } from "@/src/features/filters/constants/internal-environments";
import { TablePeekViewTraceDetail } from "@/src/components/table/peek/peek-trace-detail";
import { usePeekNavigation } from "@/src/components/table/peek/hooks/usePeekNavigation";
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
diff --git a/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts b/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts
index 71b4250851..49040f2a86 100644
--- a/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts
+++ b/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts
@@ -8,7 +8,7 @@ import { shouldAutoEnableV4 } from "@/src/features/events/lib/v4Rollout";
import { getSfdcService } from "@/src/ee/features/sfdc-sync/server";
import { canCreateOrganizations } from "@/src/features/organizations/server/canCreateOrganizations";
import { provisionStarterOrganizationForNewUser } from "@/src/features/onboarding/server/onboardingService";
-import { projectRoleAccessRights } from "@/src/features/rbac/constants/projectAccessRights";
+import { projectRoleAccessRights } from "@langfuse/shared";
export async function createProjectMembershipsOnSignup(
user: {
diff --git a/web/src/features/dashboard/lib/buildTableFilterHref.clienttest.ts b/web/src/features/dashboard/lib/buildTableFilterHref.clienttest.ts
index 553c249fc7..d13c267942 100644
--- a/web/src/features/dashboard/lib/buildTableFilterHref.clienttest.ts
+++ b/web/src/features/dashboard/lib/buildTableFilterHref.clienttest.ts
@@ -2,15 +2,13 @@ import {
type FilterState,
observationsTableCols,
tracesTableCols,
+ decodeFiltersGeneric,
+ MAX_URL_FILTER_QUERY_LENGTH,
} from "@langfuse/shared";
import {
buildTableFilterHref,
buildViewAsTableHint,
} from "./buildTableFilterHref";
-import {
- decodeFiltersGeneric,
- MAX_URL_FILTER_QUERY_LENGTH,
-} from "@/src/features/filters/lib/filter-query-encoding";
const DATE_RANGE = {
from: new Date("2026-07-01T00:00:00.000Z"),
diff --git a/web/src/features/dashboard/lib/buildTableFilterHref.ts b/web/src/features/dashboard/lib/buildTableFilterHref.ts
index 0ecaab9c9f..22225ea617 100644
--- a/web/src/features/dashboard/lib/buildTableFilterHref.ts
+++ b/web/src/features/dashboard/lib/buildTableFilterHref.ts
@@ -1,4 +1,8 @@
-import { type FilterState } from "@langfuse/shared";
+import {
+ type FilterState,
+ encodeFiltersGeneric,
+ MAX_URL_FILTER_QUERY_LENGTH,
+} from "@langfuse/shared";
import { type views } from "@langfuse/shared/query";
import { type z } from "zod";
import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
@@ -6,10 +10,6 @@ import {
classifyViewFiltersForTable,
tableTargetForView,
} from "@/src/features/dashboard/lib/viewFilterToTableFilter";
-import {
- encodeFiltersGeneric,
- MAX_URL_FILTER_QUERY_LENGTH,
-} from "@/src/features/filters/lib/filter-query-encoding";
import { rangeToString } from "@/src/utils/date-range-utils";
type ViewName = z.infer<typeof views>;
diff --git a/web/src/features/events/components/EventsTable.tsx b/web/src/features/events/components/EventsTable.tsx
index dc07d745f4..3b37cf1fb1 100644
--- a/web/src/features/events/components/EventsTable.tsx
+++ b/web/src/features/events/components/EventsTable.tsx
@@ -17,15 +17,8 @@ import {
getObservationEventsFilterConfig,
type ObservationEventsOmittableFilterColumn,
} from "../config/filter-config";
-import { DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG } from "@/src/features/filters/constants/internal-environments";
-import { formatIntervalSeconds } from "@/src/utils/dates";
-import {
- TableBadgeLoadingCell,
- TableIconBadgeLoadingCell,
- TableTextLoadingCell,
-} from "@/src/components/table/loading-cells";
-import { type LangfuseColumnDef } from "@/src/components/table/types";
import {
+ DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,
type ObservationLevelType,
type FilterState,
BatchExportTableName,
@@ -36,7 +29,15 @@ import {
ActionId,
RESOURCE_LIMIT_ERROR_MESSAGE,
type TracingSearchType,
+ type ScoreAggregate,
} from "@langfuse/shared";
+import { formatIntervalSeconds } from "@/src/utils/dates";
+import {
+ TableBadgeLoadingCell,
+ TableIconBadgeLoadingCell,
+ TableTextLoadingCell,
+} from "@/src/components/table/loading-cells";
+import { type LangfuseColumnDef } from "@/src/components/table/types";
import { filterStateToQueryText } from "@/src/features/search-bar/lib/filter-state-to-query";
import { cn } from "@/src/utils/tailwind";
import { LevelColors } from "@/src/components/level-colors";
@@ -58,7 +59,6 @@ import { TimeRangePicker } from "@/src/components/date-picker";
import { DataTableRefreshButton } from "@/src/components/table/data-table-refresh-button";
import { MobileFiltersSheet } from "@/src/features/events/components/MobileFiltersSheet";
import { useIsMobile } from "@/src/hooks/use-mobile";
-import { type ScoreAggregate } from "@langfuse/shared";
import TagList from "@/src/features/tag/components/TagList";
import { usePeekTableState } from "@/src/components/table/peek/contexts/PeekTableStateContext";
import useColumnOrder from "@/src/features/column-visibility/hooks/useColumnOrder";
diff --git a/web/src/features/events/lib/eventsTablePaths.clienttest.ts b/web/src/features/events/lib/eventsTablePaths.clienttest.ts
index 2fb261b687..e55567bea8 100644
--- a/web/src/features/events/lib/eventsTablePaths.clienttest.ts
+++ b/web/src/features/events/lib/eventsTablePaths.clienttest.ts
@@ -1,9 +1,9 @@
import { describe, expect, it } from "vitest";
-import { type FilterState } from "@langfuse/shared";
import {
+ type FilterState,
decodeFiltersGeneric,
encodeFiltersGeneric,
-} from "@/src/features/filters/lib/filter-query-encoding";
+} from "@langfuse/shared";
import { buildEventsTablePathForMetadataFilter } from "./eventsTablePaths";
const PROJECT = "p1";
diff --git a/web/src/features/events/lib/eventsTablePaths.ts b/web/src/features/events/lib/eventsTablePaths.ts
index da352a3d5b..6a5b7dce69 100644
--- a/web/src/features/events/lib/eventsTablePaths.ts
+++ b/web/src/features/events/lib/eventsTablePaths.ts
@@ -1,8 +1,8 @@
-import { type FilterState } from "@langfuse/shared";
import {
+ type FilterState,
decodeFiltersGeneric,
encodeFiltersGeneric,
-} from "@/src/features/filters/lib/filter-query-encoding";
+} from "@langfuse/shared";
type BuildEventsTablePathForSpanNameParams = {
currentPath: string;
diff --git a/web/src/features/filters/components/filter-builder.tsx b/web/src/features/filters/components/filter-builder.tsx
index 352e982134..d973628dc0 100644
--- a/web/src/features/filters/components/filter-builder.tsx
+++ b/web/src/features/filters/components/filter-builder.tsx
@@ -47,14 +47,12 @@ import {
type ColumnDefinition,
filterOperators,
singleFilter,
+ NonEmptyString,
+ formatSessionPositionInTraceFilterValue,
+ getSessionPositionInTraceFilterMode,
} from "@langfuse/shared";
-import { NonEmptyString } from "@langfuse/shared";
import { cn } from "@/src/utils/tailwind";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
-import {
- formatSessionPositionInTraceFilterValue,
- getSessionPositionInTraceFilterMode,
-} from "@/src/components/session/session-position-in-trace";
import {
InputCommand,
InputCommandEmpty,
diff --git a/web/src/features/filters/filter-integration.clienttest.ts b/web/src/features/filters/filter-integration.clienttest.ts
index d06e96e76c..f8b41a08cd 100644
--- a/web/src/features/filters/filter-integration.clienttest.ts
+++ b/web/src/features/filters/filter-integration.clienttest.ts
@@ -9,12 +9,11 @@ import {
type ColumnDefinition,
tracesTableCols,
observationsTableCols,
-} from "@langfuse/shared";
-import {
encodeFiltersGeneric,
decodeFiltersGeneric,
computeSelectedValues,
-} from "./lib/filter-query-encoding";
+ DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS,
+} from "@langfuse/shared";
import { validateFilters } from "@/src/components/table/table-view-presets/validation";
import { traceFilterConfig } from "./config/traces-config";
import { observationFilterConfig } from "./config/observations-config";
@@ -38,7 +37,6 @@ import {
buildEffectiveEnvironmentFilter,
stripImplicitEnvironmentFilterFromExplicitState,
} from "./lib/managedEnvironmentPolicy";
-import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "./constants/internal-environments";
// Helper to simulate complete URL flow
function simulateUrlFlow(filters: FilterState): FilterState {
diff --git a/web/src/features/filters/hooks/useFilterState.ts b/web/src/features/filters/hooks/useFilterState.ts
index 8e944ef925..788a781cf9 100644
--- a/web/src/features/filters/hooks/useFilterState.ts
+++ b/web/src/features/filters/hooks/useFilterState.ts
@@ -10,6 +10,10 @@ import {
datasetItemFilterColumns,
datasetRunItemsTableCols,
usersTableCols,
+ escapePipeInValue,
+ splitOnUnescapedPipe,
+ unescapePipeInValue,
+ normalizeLegacySessionPositionInTraceKey,
} from "@langfuse/shared";
import { scoresTableCols } from "@/src/server/api/definitions/scoresTable";
import {
@@ -23,12 +27,6 @@ import { evalConfigFilterColumns } from "@/src/server/api/definitions/evalConfig
import { evalExecutionsFilterCols } from "@/src/server/api/definitions/evalExecutionsTable";
import { experimentsTableCols } from "@/src/features/experiments/components/table/filter-config";
import { experimentItemsTableCols } from "@/src/features/experiments/config/experiment-items-filter-config";
-import {
- escapePipeInValue,
- splitOnUnescapedPipe,
- unescapePipeInValue,
-} from "../lib/filter-query-encoding";
-import { normalizeLegacySessionPositionInTraceKey } from "@/src/components/session/session-position-in-trace";
import { usePeekTableState } from "@/src/components/table/peek/contexts/PeekTableStateContext";
const DEBUG_QUERY_STATE = false;
diff --git a/web/src/features/filters/hooks/useSidebarFilterState.tsx b/web/src/features/filters/hooks/useSidebarFilterState.tsx
index d172e60207..0056f0e9e9 100644
--- a/web/src/features/filters/hooks/useSidebarFilterState.tsx
+++ b/web/src/features/filters/hooks/useSidebarFilterState.tsx
@@ -10,13 +10,11 @@ import {
singleFilter,
type SingleValueOption,
type ColumnDefinition,
-} from "@langfuse/shared";
-import {
computeSelectedValues,
encodeFiltersGeneric,
decodeFiltersGeneric,
MAX_URL_FILTER_QUERY_LENGTH,
-} from "../lib/filter-query-encoding";
+} from "@langfuse/shared";
import {
buildSidebarFilterQueryStorageKey,
createPersistedSidebarFilterQueryState,
diff --git a/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts b/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
index 07db6d05aa..0c4f61d9d8 100644
--- a/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
+++ b/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
@@ -1,8 +1,8 @@
import {
encodeFiltersGeneric,
decodeFiltersGeneric,
-} from "@/src/features/filters/lib/filter-query-encoding";
-import type { FilterState } from "@langfuse/shared";
+ type FilterState,
+} from "@langfuse/shared";
// Wrapper functions for tests
const encodeFilters = (filters: FilterState) => encodeFiltersGeneric(filters);
diff --git a/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx b/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx
index 26891da895..05dbafed05 100644
--- a/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx
+++ b/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx
@@ -5,13 +5,16 @@ import {
screen,
waitFor,
} from "@testing-library/react";
-import { TableViewPresetTableName, type FilterState } from "@langfuse/shared";
+import {
+ TableViewPresetTableName,
+ type FilterState,
+ DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS,
+ encodeFiltersGeneric,
+} from "@langfuse/shared";
import { useState } from "react";
import { useSidebarFilterState } from "./hooks/useSidebarFilterState";
-import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "./constants/internal-environments";
import type { FilterConfig } from "./lib/filter-config";
import { useTableViewManager } from "../../components/table/table-view-presets/hooks/useTableViewManager";
-import { encodeFiltersGeneric } from "./lib/filter-query-encoding";
const mockUseRouter = vi.fn();
const mockCapture = vi.fn();
diff --git a/web/src/features/filters/sidebarFilterSessionPersistence.clienttest.tsx b/web/src/features/filters/sidebarFilterSessionPersistence.clienttest.tsx
index 8d519badc5..02b30df8d5 100644
--- a/web/src/features/filters/sidebarFilterSessionPersistence.clienttest.tsx
+++ b/web/src/features/filters/sidebarFilterSessionPersistence.clienttest.tsx
@@ -1,8 +1,7 @@
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
-import type { FilterState } from "@langfuse/shared";
+import { type FilterState, encodeFiltersGeneric } from "@langfuse/shared";
import { useSidebarFilterState } from "./hooks/useSidebarFilterState";
import type { FilterConfig } from "./lib/filter-config";
-import { encodeFiltersGeneric } from "./lib/filter-query-encoding";
import { buildSidebarFilterQueryStorageKey } from "./lib/persistedSidebarFilterQuery";
const queryParamStore = new Map<string, unknown>();
diff --git a/web/src/features/filters/viewStateHistoryWrites.clienttest.tsx b/web/src/features/filters/viewStateHistoryWrites.clienttest.tsx
index d3e5e34552..d6e73e6271 100644
--- a/web/src/features/filters/viewStateHistoryWrites.clienttest.tsx
+++ b/web/src/features/filters/viewStateHistoryWrites.clienttest.tsx
@@ -291,8 +291,7 @@ describe("view-state URL writes and browser history (LFE-10715)", () => {
// sanitize effect rewrites the URL on mount — a programmatic correction
// that must not mint a history entry, or Back bounces off it re-firing
// the sanitize (same LFE-10715 class as the viewId writes).
- const { encodeFiltersGeneric } =
- await import("./lib/filter-query-encoding");
+ const { encodeFiltersGeneric } = await import("@langfuse/shared");
const canonical = encodeFiltersGeneric(TEST_FILTERS);
expect(canonical.startsWith("name;")).toBe(true);
const nonCanonical = canonical.replace(/^name;/, "Name;");
diff --git a/web/src/features/in-app-agent/components/utils/utils.ts b/web/src/features/in-app-agent/components/utils/utils.ts
index d341f359cd..1d0f31a581 100644
--- a/web/src/features/in-app-agent/components/utils/utils.ts
+++ b/web/src/features/in-app-agent/components/utils/utils.ts
@@ -3,7 +3,7 @@ import type { InAppAgentWindowMessage } from "../InAppAgentWindow";
import type { InAppAgentPendingToolApproval } from "../InAppAiAgentProvider";
import type { InAppAgentMessageContent } from "../InAppAgentMessage";
import { deduplicateBy } from "@/src/utils/arrays";
-import { safeJsonParse, stableJsonStringify } from "@/src/utils/json";
+import { safeJsonParse, stableJsonStringify } from "@langfuse/shared";
import {
IN_APP_AGENT_REDIRECT_TOOL_NAME,
IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE,
diff --git a/web/src/features/in-app-agent/server/agent.ts b/web/src/features/in-app-agent/server/agent.ts
index f8a2462dd2..f2ffc8998a 100644
--- a/web/src/features/in-app-agent/server/agent.ts
+++ b/web/src/features/in-app-agent/server/agent.ts
@@ -30,7 +30,7 @@ import {
} from "@/src/features/in-app-agent/server/tools";
import { LANGFUSE_IN_APP_AGENT_SKILLS } from "@/src/features/in-app-agent/server/skills";
import type { InAppAgentSandbox } from "@/src/features/in-app-agent/server/sandbox";
-import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@/src/features/filters/constants/internal-environments";
+import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@langfuse/shared";
import { logger } from "@langfuse/shared/src/server";
import {
IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER,
diff --git a/web/src/features/in-app-agent/server/handler.ts b/web/src/features/in-app-agent/server/handler.ts
index 181bdd8430..58e3ffa5a2 100644
--- a/web/src/features/in-app-agent/server/handler.ts
+++ b/web/src/features/in-app-agent/server/handler.ts
@@ -61,10 +61,17 @@ import {
createHttpHeaderFromRateLimit,
RateLimitService,
} from "@/src/features/public-api/server/RateLimitService";
-import { getLangfuseAITraceSinkParams } from "@/src/features/ai-features/server/bedrockCompletion";
+import {
+ getLangfuseAITraceSinkParams,
+ parseSavedViewFromURL,
+ addUserToSpan,
+ logger,
+ redis,
+ TableViewService,
+ type ApiAccessScope,
+} from "@langfuse/shared/src/server";
import { isProjectMemberOrAdmin } from "@/src/server/utils/checkProjectMembershipOrAdmin";
import { getProductBaseUrl } from "@/src/utils/base-url";
-import { parseSavedViewFromURL } from "@/src/utils/product-url";
import { assertUnreachable } from "@/src/utils/types";
import {
BaseError,
@@ -79,13 +86,6 @@ import {
CloudConfigSchema,
} from "@langfuse/shared";
import { prisma } from "@langfuse/shared/src/db";
-import {
- addUserToSpan,
- logger,
- redis,
- TableViewService,
- type ApiAccessScope,
-} from "@langfuse/shared/src/server";
import {
createAndAddApiKeysToDb,
deleteApiKeyFromDb,
diff --git a/web/src/features/in-app-agent/server/human-in-the-loop.ts b/web/src/features/in-app-agent/server/human-in-the-loop.ts
index 76f35cff7a..074a84de90 100644
--- a/web/src/features/in-app-agent/server/human-in-the-loop.ts
+++ b/web/src/features/in-app-agent/server/human-in-the-loop.ts
@@ -1,12 +1,15 @@
import { EventType } from "@ag-ui/core";
import { z } from "zod";
-import { InvalidRequestError } from "@langfuse/shared";
+import {
+ InvalidRequestError,
+ safeJsonParse,
+ stableJsonStringify,
+} from "@langfuse/shared";
import { prisma } from "@langfuse/shared/src/db";
import type { McpToolName } from "@/src/features/mcp/server/bootstrap";
import { IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE } from "@/src/features/in-app-agent/constants";
import { IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES } from "@/src/features/in-app-agent/server/tools";
-import { safeJsonParse, stableJsonStringify } from "@/src/utils/json";
import {
type AgUiEvent,
type AgUiMessage,
diff --git a/web/src/features/in-app-agent/server/persistence.ts b/web/src/features/in-app-agent/server/persistence.ts
index 866deb2f52..dd1df5f392 100644
--- a/web/src/features/in-app-agent/server/persistence.ts
+++ b/web/src/features/in-app-agent/server/persistence.ts
@@ -6,12 +6,15 @@ import {
InAppAgentRunStatus,
LangfuseConflictError,
LangfuseNotFoundError,
+ safeJsonParse,
} from "@langfuse/shared";
import {
ChatMessageRole,
ChatMessageType,
LangfuseInternalTraceEnvironment,
logger,
+ generateLangfuseAIText,
+ getLangfuseAITraceSinkParams,
} from "@langfuse/shared/src/server";
import { Prisma } from "@langfuse/shared/src/db";
import type {
@@ -20,10 +23,6 @@ import type {
} from "@langfuse/shared/src/db";
import { env } from "@/src/env.mjs";
-import {
- generateLangfuseAIText,
- getLangfuseAITraceSinkParams,
-} from "@/src/features/ai-features/server/bedrockCompletion";
import { getProductBaseUrl } from "@/src/utils/base-url";
import { truncate } from "@/src/utils/string";
import { assertUnreachable } from "@/src/utils/types";
@@ -35,7 +34,6 @@ import {
} from "@/src/features/in-app-agent/schema";
import { compactPersistedEventDeltas } from "@/src/features/in-app-agent/server/eventCompaction";
import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@/src/features/in-app-agent/constants";
-import { safeJsonParse } from "@/src/utils/json";
import { IN_APP_AGENT_SANDBOX_TOOL_NAMES } from "@/src/features/in-app-agent/server/tools";
// Keep this close to the route maxDuration (120s) so a killed foreground stream
diff --git a/web/src/features/in-app-agent/server/tools.ts b/web/src/features/in-app-agent/server/tools.ts
index fab515c77d..92e09a7caa 100644
--- a/web/src/features/in-app-agent/server/tools.ts
+++ b/web/src/features/in-app-agent/server/tools.ts
@@ -1,6 +1,10 @@
import { createTool } from "@mastra/core/tools";
import type { InAppAgentSandbox } from "@/src/features/in-app-agent/server/sandbox";
-import type { ProjectScope } from "@/src/features/rbac/constants/projectAccessRights";
+import {
+ type ProjectScope,
+ ObservationLevelDomain,
+ TracingSearchType,
+} from "@langfuse/shared";
import { hasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { assertUnreachable } from "@/src/utils/types";
import {
@@ -20,10 +24,9 @@ import {
buildSessionsPath,
buildTracePath,
buildTracesPath,
-} from "@/src/utils/product-url";
+} from "@langfuse/shared/src/server";
import z from "zod";
import { TABLE_AGGREGATION_OPTIONS } from "@/src/utils/date-range-utils";
-import { ObservationLevelDomain, TracingSearchType } from "@langfuse/shared";
import { Role } from "@langfuse/shared/src/db";
import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@/src/features/in-app-agent/constants";
import type { McpToolName } from "@/src/features/mcp/server/bootstrap";
diff --git a/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueue.ts b/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueue.ts
index 50121a76f4..50dc45e942 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueue.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueue.ts
@@ -4,7 +4,7 @@ import {
CreateAnnotationQueueResponse,
} from "@/src/features/public-api/types/annotation-queues";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { getMcpPublicApiAuth } from "../../publicApi";
import { z } from "zod";
diff --git a/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueueItem.ts b/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueueItem.ts
index 3e3339aa0b..add58fe539 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueueItem.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/createAnnotationQueueItem.ts
@@ -1,7 +1,7 @@
import { createAnnotationQueueItemForApi } from "@/src/features/annotation-queues/server/publicAnnotationQueueService";
import { CreateAnnotationQueueItemResponse } from "@/src/features/public-api/types/annotation-queues";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueItemUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { CreateAnnotationQueueItemToolSchema } from "../schema";
diff --git a/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueue.ts b/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueue.ts
index 1117f3440f..2fbd47b482 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueue.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueue.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/annotation-queues";
import { getAnnotationQueueForApi } from "@/src/features/annotation-queues/server/publicAnnotationQueueService";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [getAnnotationQueueTool, handleGetAnnotationQueue] = defineTool({
diff --git a/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueueItem.ts b/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueueItem.ts
index f47184951e..64353f82c8 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueueItem.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/getAnnotationQueueItem.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/annotation-queues";
import { getAnnotationQueueItemForApi } from "@/src/features/annotation-queues/server/publicAnnotationQueueService";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueItemUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [getAnnotationQueueItemTool, handleGetAnnotationQueueItem] =
diff --git a/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueueItems.ts b/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueueItems.ts
index 9f53fca01b..d57baffac7 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueueItems.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueueItems.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/annotation-queues";
import { listAnnotationQueueItemsForApi } from "@/src/features/annotation-queues/server/publicAnnotationQueueService";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueItemUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [listAnnotationQueueItemsTool, handleListAnnotationQueueItems] =
diff --git a/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueues.ts b/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueues.ts
index 61bfb0934e..dfc51c577c 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueues.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/listAnnotationQueues.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/annotation-queues";
import { listAnnotationQueuesForApi } from "@/src/features/annotation-queues/server/publicAnnotationQueueService";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [listAnnotationQueuesTool, handleListAnnotationQueues] =
diff --git a/web/src/features/mcp/features/annotationQueues/tools/updateAnnotationQueueItem.ts b/web/src/features/mcp/features/annotationQueues/tools/updateAnnotationQueueItem.ts
index 07aa1a7bed..996eb89d78 100644
--- a/web/src/features/mcp/features/annotationQueues/tools/updateAnnotationQueueItem.ts
+++ b/web/src/features/mcp/features/annotationQueues/tools/updateAnnotationQueueItem.ts
@@ -1,7 +1,7 @@
import { updateAnnotationQueueItemForApi } from "@/src/features/annotation-queues/server/publicAnnotationQueueService";
import { UpdateAnnotationQueueItemResponse } from "@/src/features/public-api/types/annotation-queues";
import { defineTool } from "../../../core/define-tool";
-import { buildAnnotationQueueItemUrl } from "@/src/utils/product-url";
+import { buildAnnotationQueueItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { UpdateAnnotationQueueItemToolSchema } from "../schema";
diff --git a/web/src/features/mcp/features/comments/tools/createComment.ts b/web/src/features/mcp/features/comments/tools/createComment.ts
index d4755604fa..45eee2148b 100644
--- a/web/src/features/mcp/features/comments/tools/createComment.ts
+++ b/web/src/features/mcp/features/comments/tools/createComment.ts
@@ -6,7 +6,7 @@ import {
PostCommentsV1Response,
} from "@/src/features/public-api/types/comments";
import { defineTool } from "../../../core/define-tool";
-import { buildCommentObjectUrl } from "@/src/utils/product-url";
+import { buildCommentObjectUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
const CreateCommentToolBaseSchema = z
diff --git a/web/src/features/mcp/features/comments/tools/getComment.ts b/web/src/features/mcp/features/comments/tools/getComment.ts
index 0ab5ecd8ab..1ea416fb87 100644
--- a/web/src/features/mcp/features/comments/tools/getComment.ts
+++ b/web/src/features/mcp/features/comments/tools/getComment.ts
@@ -4,7 +4,7 @@ import {
GetCommentV1Response,
} from "@/src/features/public-api/types/comments";
import { defineTool } from "../../../core/define-tool";
-import { buildCommentObjectUrl } from "@/src/utils/product-url";
+import { buildCommentObjectUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [getCommentTool, handleGetComment] = defineTool({
diff --git a/web/src/features/mcp/features/comments/tools/listComments.ts b/web/src/features/mcp/features/comments/tools/listComments.ts
index 0881c3e147..988153f71a 100644
--- a/web/src/features/mcp/features/comments/tools/listComments.ts
+++ b/web/src/features/mcp/features/comments/tools/listComments.ts
@@ -6,7 +6,7 @@ import {
GetCommentsV1Response,
} from "@/src/features/public-api/types/comments";
import { defineTool } from "../../../core/define-tool";
-import { buildCommentObjectUrl } from "@/src/utils/product-url";
+import { buildCommentObjectUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
const ListCommentsBaseSchema = z
diff --git a/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts b/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts
index 8982c9e368..019ddad397 100644
--- a/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts
+++ b/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts
@@ -8,7 +8,7 @@ import {
PostUnstableDashboardWidgetBody,
PostUnstableDashboardWidgetView,
} from "@/src/features/public-api/types/unstable-dashboard-widgets";
-import { buildDashboardWidgetUrl } from "@/src/utils/product-url";
+import { buildDashboardWidgetUrl } from "@langfuse/shared/src/server";
export const DashboardWidgetFilterBaseSchema = z
.object({
diff --git a/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts b/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
index 70d1575663..0caf1f64b1 100644
--- a/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
+++ b/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
@@ -10,7 +10,7 @@ import {
import {
buildDashboardUrl,
buildDashboardWidgetUrl,
-} from "@/src/utils/product-url";
+} from "@langfuse/shared/src/server";
import {
GetUnstableDashboardWidgetsQuery,
DashboardWidgetIdQuery,
diff --git a/web/src/features/mcp/features/datasets/tools/getDataset.ts b/web/src/features/mcp/features/datasets/tools/getDataset.ts
index b1b4e74076..16070ce51a 100644
--- a/web/src/features/mcp/features/datasets/tools/getDataset.ts
+++ b/web/src/features/mcp/features/datasets/tools/getDataset.ts
@@ -1,6 +1,6 @@
import { GetDatasetV2Response } from "@/src/features/public-api/types/datasets";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetUrl } from "@/src/utils/product-url";
+import { buildDatasetUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { getDatasetByIdForApi } from "@/src/features/datasets/server/publicDatasetService";
import { GetDatasetMcpInput } from "../schema";
diff --git a/web/src/features/mcp/features/datasets/tools/getDatasetItem.ts b/web/src/features/mcp/features/datasets/tools/getDatasetItem.ts
index b2c15540f9..7ed6a8625d 100644
--- a/web/src/features/mcp/features/datasets/tools/getDatasetItem.ts
+++ b/web/src/features/mcp/features/datasets/tools/getDatasetItem.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/datasets";
import { getDatasetItemForApi } from "@/src/features/datasets/server/publicDatasetService";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetItemUrl } from "@/src/utils/product-url";
+import { buildDatasetItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [getDatasetItemTool, handleGetDatasetItem] = defineTool({
diff --git a/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts b/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts
index 8740bea8d6..4e65e2019b 100644
--- a/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts
+++ b/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts
@@ -1,7 +1,7 @@
import { GetDatasetRunV1Response } from "@/src/features/public-api/types/datasets";
import { getDatasetRunByIdForApi } from "@/src/features/datasets/server/publicDatasetService";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetRunUrl } from "@/src/utils/product-url";
+import { buildDatasetRunUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
import { GetDatasetRunMcpInput } from "../schema";
diff --git a/web/src/features/mcp/features/datasets/tools/listDatasetItems.ts b/web/src/features/mcp/features/datasets/tools/listDatasetItems.ts
index 9cc8e1354a..4b1532aba5 100644
--- a/web/src/features/mcp/features/datasets/tools/listDatasetItems.ts
+++ b/web/src/features/mcp/features/datasets/tools/listDatasetItems.ts
@@ -1,7 +1,7 @@
import { GetDatasetItemsV1Response } from "@/src/features/public-api/types/datasets";
import { listDatasetItemsForApi } from "@/src/features/datasets/server/publicDatasetService";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetItemUrl } from "@/src/utils/product-url";
+import { buildDatasetItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import {
GetDatasetItemsMcpBaseSchema,
diff --git a/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts b/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts
index 8e77835d9a..394ceb1206 100644
--- a/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts
+++ b/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts
@@ -1,7 +1,7 @@
import { listDatasetRunItemsByRunIdForApi } from "@/src/features/datasets/server/publicDatasetService";
import { GetDatasetRunItemsV1Response } from "@/src/features/public-api/types/datasets";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetRunUrl } from "@/src/utils/product-url";
+import { buildDatasetRunUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { paginationMeta } from "../../publicApi";
import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
diff --git a/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts b/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts
index 72c69065d5..5e6f3a171f 100644
--- a/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts
+++ b/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts
@@ -1,7 +1,7 @@
import { GetDatasetRunsV1Response } from "@/src/features/public-api/types/datasets";
import { listDatasetRunsByDatasetIdForApi } from "@/src/features/datasets/server/publicDatasetService";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetRunUrl } from "@/src/utils/product-url";
+import { buildDatasetRunUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
import { GetDatasetRunsMcpInput } from "../schema";
diff --git a/web/src/features/mcp/features/datasets/tools/listDatasets.ts b/web/src/features/mcp/features/datasets/tools/listDatasets.ts
index 98231e4fa6..ef02b2272a 100644
--- a/web/src/features/mcp/features/datasets/tools/listDatasets.ts
+++ b/web/src/features/mcp/features/datasets/tools/listDatasets.ts
@@ -1,6 +1,6 @@
import { GetDatasetsV2Response } from "@/src/features/public-api/types/datasets";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetUrl } from "@/src/utils/product-url";
+import { buildDatasetUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { listDatasetsForApi } from "@/src/features/datasets/server/publicDatasetService";
import { GetDatasetsMcpInput } from "../schema";
diff --git a/web/src/features/mcp/features/datasets/tools/upsertDataset.ts b/web/src/features/mcp/features/datasets/tools/upsertDataset.ts
index 3dc419958a..d705b96cba 100644
--- a/web/src/features/mcp/features/datasets/tools/upsertDataset.ts
+++ b/web/src/features/mcp/features/datasets/tools/upsertDataset.ts
@@ -4,9 +4,11 @@ import {
PostDatasetsV2Body,
PostDatasetsV2Response,
} from "@/src/features/public-api/types/datasets";
-import { DatasetJSONSchema } from "@langfuse/shared/src/server";
+import {
+ DatasetJSONSchema,
+ buildDatasetUrl,
+} from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
const idField = z.string().min(1).optional();
diff --git a/web/src/features/mcp/features/datasets/tools/upsertDatasetItem.ts b/web/src/features/mcp/features/datasets/tools/upsertDatasetItem.ts
index 91c479dde5..3d44eef040 100644
--- a/web/src/features/mcp/features/datasets/tools/upsertDatasetItem.ts
+++ b/web/src/features/mcp/features/datasets/tools/upsertDatasetItem.ts
@@ -1,7 +1,7 @@
import { createDatasetItemForApi } from "@/src/features/datasets/server/publicDatasetService";
import { PostDatasetItemsV1Response } from "@/src/features/public-api/types/datasets";
import { defineTool } from "../../../core/define-tool";
-import { buildDatasetItemUrl } from "@/src/utils/product-url";
+import { buildDatasetItemUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { PostDatasetItemMcpInput } from "../schema";
diff --git a/web/src/features/mcp/features/evals/tools/getEvaluator.ts b/web/src/features/mcp/features/evals/tools/getEvaluator.ts
index 8e438336cb..f86c753e0f 100644
--- a/web/src/features/mcp/features/evals/tools/getEvaluator.ts
+++ b/web/src/features/mcp/features/evals/tools/getEvaluator.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/unstable-evaluators";
import { getPublicEvaluator } from "@/src/features/evals/server/unstable-public-api";
import { defineTool } from "../../../core/define-tool";
-import { buildEvaluatorUrl } from "@/src/utils/product-url";
+import { buildEvaluatorUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [getEvaluatorTool, handleGetEvaluator] = defineTool({
diff --git a/web/src/features/mcp/features/evals/tools/listEvaluators.ts b/web/src/features/mcp/features/evals/tools/listEvaluators.ts
index 941c687f9c..eb7c7dca98 100644
--- a/web/src/features/mcp/features/evals/tools/listEvaluators.ts
+++ b/web/src/features/mcp/features/evals/tools/listEvaluators.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/unstable-evaluators";
import { listPublicEvaluators } from "@/src/features/evals/server/unstable-public-api";
import { defineTool } from "../../../core/define-tool";
-import { buildEvaluatorUrl } from "@/src/utils/product-url";
+import { buildEvaluatorUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [listEvaluatorsTool, handleListEvaluators] = defineTool({
diff --git a/web/src/features/mcp/features/evals/tools/upsertEvaluator.ts b/web/src/features/mcp/features/evals/tools/upsertEvaluator.ts
index d4a127174b..b3a26a5320 100644
--- a/web/src/features/mcp/features/evals/tools/upsertEvaluator.ts
+++ b/web/src/features/mcp/features/evals/tools/upsertEvaluator.ts
@@ -11,7 +11,7 @@ import {
} from "@/src/features/public-api/types/unstable-public-evals-contract";
import { createPublicEvaluator } from "@/src/features/evals/server/unstable-public-api";
import { defineTool } from "../../../core/define-tool";
-import { buildEvaluatorUrl } from "@/src/utils/product-url";
+import { buildEvaluatorUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import {
EvaluatorModelConfigBaseSchema,
diff --git a/web/src/features/mcp/features/experiments/tools/listExperimentItems.ts b/web/src/features/mcp/features/experiments/tools/listExperimentItems.ts
index 775cee3b92..2a62d46d09 100644
--- a/web/src/features/mcp/features/experiments/tools/listExperimentItems.ts
+++ b/web/src/features/mcp/features/experiments/tools/listExperimentItems.ts
@@ -1,6 +1,6 @@
import { listExperimentItemsForPublicApi } from "@/src/features/experiments/server/public/service";
import { GetExperimentItemsV1Response } from "@/src/features/public-api/types/experiments";
-import { buildObservationUrl } from "@/src/utils/product-url";
+import { buildObservationUrl } from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
import {
diff --git a/web/src/features/mcp/features/experiments/tools/listExperiments.ts b/web/src/features/mcp/features/experiments/tools/listExperiments.ts
index 0d37a7b29d..7b14825cd7 100644
--- a/web/src/features/mcp/features/experiments/tools/listExperiments.ts
+++ b/web/src/features/mcp/features/experiments/tools/listExperiments.ts
@@ -1,6 +1,6 @@
import { listExperimentsForPublicApi } from "@/src/features/experiments/server/public/service";
import { GetExperimentsV1Response } from "@/src/features/public-api/types/experiments";
-import { buildExperimentUrl } from "@/src/utils/product-url";
+import { buildExperimentUrl } from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
import {
diff --git a/web/src/features/mcp/features/models/tools/createModel.ts b/web/src/features/mcp/features/models/tools/createModel.ts
index 2bc3a3784a..2a72ce22bf 100644
--- a/web/src/features/mcp/features/models/tools/createModel.ts
+++ b/web/src/features/mcp/features/models/tools/createModel.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/models";
import { createModelForApi } from "@/src/features/models/server/publicApiModelService";
import { defineTool } from "../../../core/define-tool";
-import { buildModelUrl } from "@/src/utils/product-url";
+import { buildModelUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { z } from "zod";
diff --git a/web/src/features/mcp/features/models/tools/getModel.ts b/web/src/features/mcp/features/models/tools/getModel.ts
index 18fe772b1c..8a5bb4893d 100644
--- a/web/src/features/mcp/features/models/tools/getModel.ts
+++ b/web/src/features/mcp/features/models/tools/getModel.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/models";
import { getModelForApi } from "@/src/features/models/server/publicApiModelService";
import { defineTool } from "../../../core/define-tool";
-import { buildModelUrl } from "@/src/utils/product-url";
+import { buildModelUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [getModelTool, handleGetModel] = defineTool({
diff --git a/web/src/features/mcp/features/models/tools/listModels.ts b/web/src/features/mcp/features/models/tools/listModels.ts
index 80053aa89e..1cea8c147a 100644
--- a/web/src/features/mcp/features/models/tools/listModels.ts
+++ b/web/src/features/mcp/features/models/tools/listModels.ts
@@ -4,7 +4,7 @@ import {
} from "@/src/features/public-api/types/models";
import { listModelsForApi } from "@/src/features/models/server/publicApiModelService";
import { defineTool } from "../../../core/define-tool";
-import { buildModelUrl } from "@/src/utils/product-url";
+import { buildModelUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
export const [listModelsTool, handleListModels] = defineTool({
diff --git a/web/src/features/mcp/features/monitors/tools/getMonitor.ts b/web/src/features/mcp/features/monitors/tools/getMonitor.ts
index 03c2ea6c75..7efb3572d6 100644
--- a/web/src/features/mcp/features/monitors/tools/getMonitor.ts
+++ b/web/src/features/mcp/features/monitors/tools/getMonitor.ts
@@ -1,7 +1,7 @@
import { MonitorService } from "@langfuse/shared/monitors/server";
import { z } from "zod";
-import { buildMonitorUrl } from "@/src/utils/product-url";
+import { buildMonitorUrl } from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
diff --git a/web/src/features/mcp/features/monitors/tools/listMonitors.ts b/web/src/features/mcp/features/monitors/tools/listMonitors.ts
index 53b233bb01..6673d2e50c 100644
--- a/web/src/features/mcp/features/monitors/tools/listMonitors.ts
+++ b/web/src/features/mcp/features/monitors/tools/listMonitors.ts
@@ -4,7 +4,7 @@ import {
} from "@langfuse/shared/monitors/server";
import { z } from "zod";
-import { buildMonitorUrl } from "@/src/utils/product-url";
+import { buildMonitorUrl } from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
import { McpAdvancedFilterBaseSchema } from "../../../core/filter-schema";
diff --git a/web/src/features/mcp/features/observations/tools/getObservation.ts b/web/src/features/mcp/features/observations/tools/getObservation.ts
index 639d969234..27bdb2b640 100644
--- a/web/src/features/mcp/features/observations/tools/getObservation.ts
+++ b/web/src/features/mcp/features/observations/tools/getObservation.ts
@@ -1,8 +1,10 @@
import { LangfuseNotFoundError } from "@langfuse/shared";
import { z } from "zod";
-import { getObservationsV2FromEventsTableForPublicApi } from "@langfuse/shared/src/server";
+import {
+ getObservationsV2FromEventsTableForPublicApi,
+ buildObservationUrl,
+} from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
-import { buildObservationUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
import {
ExpandMetadataKeysSchema,
diff --git a/web/src/features/mcp/features/observations/tools/listObservations.ts b/web/src/features/mcp/features/observations/tools/listObservations.ts
index 1eb4d80575..7e795b4453 100644
--- a/web/src/features/mcp/features/observations/tools/listObservations.ts
+++ b/web/src/features/mcp/features/observations/tools/listObservations.ts
@@ -14,7 +14,10 @@ import {
timeFilter,
type ColumnDefinition,
} from "@langfuse/shared";
-import { getObservationsV2FromEventsTableForPublicApi } from "@langfuse/shared/src/server";
+import {
+ getObservationsV2FromEventsTableForPublicApi,
+ buildObservationUrl,
+} from "@langfuse/shared/src/server";
import { z } from "zod";
import {
EncodedObservationsCursorV2,
@@ -22,7 +25,6 @@ import {
encodeCursor,
} from "@/src/features/public-api/types/observations";
import { defineTool } from "../../../core/define-tool";
-import { buildObservationUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
import {
ExpandMetadataKeysSchema,
diff --git a/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts b/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts
index 45773f6254..29c1018f9e 100644
--- a/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts
+++ b/web/src/features/mcp/features/prompts/tools/createChatPrompt.ts
@@ -14,7 +14,7 @@ import {
PROMPT_NAME_MAX_LENGTH,
} from "@langfuse/shared";
import { createPromptForApi } from "@/src/features/prompts/server/prompt-api-service";
-import { buildPromptUrl } from "@/src/utils/product-url";
+import { buildPromptUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { ParamCreatePromptLabels } from "../validation";
diff --git a/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts b/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts
index f9db15ed5a..9ba82b41bb 100644
--- a/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts
+++ b/web/src/features/mcp/features/prompts/tools/createTextPrompt.ts
@@ -14,7 +14,7 @@ import {
PROMPT_NAME_MAX_LENGTH,
} from "@langfuse/shared";
import { createPromptForApi } from "@/src/features/prompts/server/prompt-api-service";
-import { buildPromptUrl } from "@/src/utils/product-url";
+import { buildPromptUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { ParamCreatePromptLabels } from "../validation";
diff --git a/web/src/features/mcp/features/prompts/tools/listPrompts.ts b/web/src/features/mcp/features/prompts/tools/listPrompts.ts
index ff606f1232..dfb51cceb0 100644
--- a/web/src/features/mcp/features/prompts/tools/listPrompts.ts
+++ b/web/src/features/mcp/features/prompts/tools/listPrompts.ts
@@ -14,7 +14,7 @@ import {
} from "../validation";
import { ParamLimit, ParamPage } from "../../../core/validation";
import { listPromptsForApi } from "@/src/features/prompts/server/prompt-api-service";
-import { buildPromptUrl } from "@/src/utils/product-url";
+import { buildPromptUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { paginationMeta } from "../../publicApi";
diff --git a/web/src/features/mcp/features/prompts/tools/promptReadToolFactory.ts b/web/src/features/mcp/features/prompts/tools/promptReadToolFactory.ts
index f7586ee483..d7f53dcf69 100644
--- a/web/src/features/mcp/features/prompts/tools/promptReadToolFactory.ts
+++ b/web/src/features/mcp/features/prompts/tools/promptReadToolFactory.ts
@@ -4,7 +4,7 @@ import { LATEST_PROMPT_LABEL, type Prompt } from "@langfuse/shared";
import { getPromptForApi } from "@/src/features/prompts/server/prompt-api-service";
import { defineTool } from "../../../core/define-tool";
-import { buildPromptUrl } from "@/src/utils/product-url";
+import { buildPromptUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { UserInputError } from "../../../core/errors";
import {
diff --git a/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts b/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts
index 70b7032d04..6c8d930196 100644
--- a/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts
+++ b/web/src/features/mcp/features/prompts/tools/updatePromptLabels.ts
@@ -10,7 +10,7 @@ import { z } from "zod";
import { defineTool } from "../../../core/define-tool";
import { ParamPromptName, ParamNewLabels } from "../validation";
import { updatePromptLabelsForApi } from "@/src/features/prompts/server/prompt-api-service";
-import { buildPromptUrl } from "@/src/utils/product-url";
+import { buildPromptUrl } from "@langfuse/shared/src/server";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { PROMPT_NAME_MAX_LENGTH } from "@langfuse/shared";
diff --git a/web/src/features/mcp/features/scores/tools/createScore.ts b/web/src/features/mcp/features/scores/tools/createScore.ts
index 40701c0c54..26f414e7bb 100644
--- a/web/src/features/mcp/features/scores/tools/createScore.ts
+++ b/web/src/features/mcp/features/scores/tools/createScore.ts
@@ -7,9 +7,11 @@ import {
UnauthorizedError,
} from "@langfuse/shared";
import { ScoresApiService } from "@/src/features/public-api/server/scores-api-service";
-import { createUnknownSdkIngestionAttribution } from "@langfuse/shared/src/server";
+import {
+ createUnknownSdkIngestionAttribution,
+ buildScoreTargetUrl,
+} from "@langfuse/shared/src/server";
import { defineTool } from "../../../core/define-tool";
-import { buildScoreTargetUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { ApiServerError } from "../../../core/errors";
import { z } from "zod";
diff --git a/web/src/features/mcp/features/scores/tools/getScore.ts b/web/src/features/mcp/features/scores/tools/getScore.ts
index b0ccee099d..c79f0191f9 100644
--- a/web/src/features/mcp/features/scores/tools/getScore.ts
+++ b/web/src/features/mcp/features/scores/tools/getScore.ts
@@ -3,7 +3,7 @@ import { z } from "zod";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { listScoresV3ForPublicApi } from "@/src/features/public-api/server/scores-api-v3";
-import { buildScoreSubjectUrl } from "@/src/utils/product-url";
+import { buildScoreSubjectUrl } from "@langfuse/shared/src/server";
const GetScoreInputSchema = z.object({ scoreId: z.string() }).strict();
diff --git a/web/src/features/mcp/features/scores/tools/listScores.ts b/web/src/features/mcp/features/scores/tools/listScores.ts
index f334074d1a..e2b6aed40a 100644
--- a/web/src/features/mcp/features/scores/tools/listScores.ts
+++ b/web/src/features/mcp/features/scores/tools/listScores.ts
@@ -9,7 +9,7 @@ import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { listScoresV3ForPublicApi } from "@/src/features/public-api/server/scores-api-v3";
import { EncodedScoresCursorV3 } from "@/src/features/public-api/types/scores";
-import { buildScoreSubjectUrl } from "@/src/utils/product-url";
+import { buildScoreSubjectUrl } from "@langfuse/shared/src/server";
const ListScoresBaseSchema = z
.object({
diff --git a/web/src/features/natural-language-filters/server/router.ts b/web/src/features/natural-language-filters/server/router.ts
index 9b5643d704..0abc2166b9 100644
--- a/web/src/features/natural-language-filters/server/router.ts
+++ b/web/src/features/natural-language-filters/server/router.ts
@@ -8,16 +8,14 @@ import {
ChatMessageType,
LangfuseInternalTraceEnvironment,
logger,
+ generateLangfuseAIText,
+ getLangfuseAITraceSinkParams,
+ isLangfuseAITracingConfigured,
} from "@langfuse/shared/src/server";
import { env } from "@/src/env.mjs";
import { CreateNaturalLanguageFilterCompletion } from "./validation";
import { parseFiltersFromCompletion, getLangfuseClient } from "./utils";
import { throwIfNoProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import {
- generateLangfuseAIText,
- getLangfuseAITraceSinkParams,
- isLangfuseAITracingConfigured,
-} from "@/src/features/ai-features/server/bedrockCompletion";
export const naturalLanguageFilterRouter = createTRPCRouter({
createCompletion: protectedProjectProcedure
diff --git a/web/src/features/onboarding/server/onboardingService.ts b/web/src/features/onboarding/server/onboardingService.ts
index 517bba8173..05b997a64d 100644
--- a/web/src/features/onboarding/server/onboardingService.ts
+++ b/web/src/features/onboarding/server/onboardingService.ts
@@ -11,7 +11,7 @@ import {
organizationRoleAccessRights,
type OrganizationScope,
} from "@/src/features/rbac/constants/organizationAccessRights";
-import { projectRoleAccessRights } from "@/src/features/rbac/constants/projectAccessRights";
+import { projectRoleAccessRights } from "@langfuse/shared";
import { createProjectRoute } from "@/src/features/setup/setupRoutes";
const DEFAULT_STARTER_PROJECT_NAME = "My Project";
diff --git a/web/src/features/rbac/components/RoleSelectItem.tsx b/web/src/features/rbac/components/RoleSelectItem.tsx
index 372786afc0..ecf2966e30 100644
--- a/web/src/features/rbac/components/RoleSelectItem.tsx
+++ b/web/src/features/rbac/components/RoleSelectItem.tsx
@@ -5,15 +5,15 @@ import {
HoverCardPortal,
} from "@/src/components/ui/hover-card";
import { SelectItem } from "@/src/components/ui/select";
-import { Role } from "@langfuse/shared";
+import {
+ Role,
+ projectNoneRoleComment,
+ projectRoleAccessRights,
+} from "@langfuse/shared";
import {
organizationRoleAccessRights,
orgNoneRoleComment,
} from "@/src/features/rbac/constants/organizationAccessRights";
-import {
- projectNoneRoleComment,
- projectRoleAccessRights,
-} from "@/src/features/rbac/constants/projectAccessRights";
import { orderedRoles } from "@/src/features/rbac/constants/orderedRoles";
export const RoleSelectItem = ({
diff --git a/web/src/features/rbac/utils/checkProjectAccess.ts b/web/src/features/rbac/utils/checkProjectAccess.ts
index 31e23d3ffe..c4968bd0c9 100644
--- a/web/src/features/rbac/utils/checkProjectAccess.ts
+++ b/web/src/features/rbac/utils/checkProjectAccess.ts
@@ -1,7 +1,4 @@
-import {
- projectRoleAccessRights,
- type ProjectScope,
-} from "@/src/features/rbac/constants/projectAccessRights";
+import { projectRoleAccessRights, type ProjectScope } from "@langfuse/shared";
import { type Role } from "@langfuse/shared/src/db";
import { TRPCError } from "@trpc/server";
import { type Session } from "next-auth";
diff --git a/web/src/features/search-bar/server/router.ts b/web/src/features/search-bar/server/router.ts
index 23e535f0f6..d4e4fd4c21 100644
--- a/web/src/features/search-bar/server/router.ts
+++ b/web/src/features/search-bar/server/router.ts
@@ -24,6 +24,9 @@ import {
ChatMessageType,
LangfuseInternalTraceEnvironment,
logger,
+ generateLangfuseAIText,
+ getLangfuseAITraceSinkParams,
+ isLangfuseAITracingConfigured,
} from "@langfuse/shared/src/server";
import { env } from "@/src/env.mjs";
import { randomBytes } from "crypto";
@@ -40,11 +43,6 @@ import {
deriveParseOutcomeScores,
recordParseOutcomeScores,
} from "./parseOutcomeScoring";
-import {
- generateLangfuseAIText,
- getLangfuseAITraceSinkParams,
- isLangfuseAITracingConfigured,
-} from "@/src/features/ai-features/server/bedrockCompletion";
import { getProductBaseUrl } from "@/src/utils/base-url";
// Caps shared with `observedScoreNamesFromOptions` (the client-side builder),
diff --git a/web/src/features/table/types.ts b/web/src/features/table/types.ts
index 556859ab63..1077728598 100644
--- a/web/src/features/table/types.ts
+++ b/web/src/features/table/types.ts
@@ -1,6 +1,6 @@
import { type Entitlement } from "@/src/features/entitlements/constants/entitlements";
-import { type ProjectScope } from "@/src/features/rbac/constants/projectAccessRights";
import {
+ type ProjectScope,
type BatchActionType,
type ActionId,
type BatchExportTableName,
diff --git a/web/src/pages/api/public/mcp/index.ts b/web/src/pages/api/public/mcp/index.ts
index 35115f2966..fcdfdce4e0 100644
--- a/web/src/pages/api/public/mcp/index.ts
+++ b/web/src/pages/api/public/mcp/index.ts
@@ -37,12 +37,16 @@ import { addUserToSpan, logger, redis } from "@langfuse/shared/src/server";
import { ApiAuthService } from "@/src/features/public-api/server/apiAuth";
import { RateLimitService } from "@/src/features/public-api/server/RateLimitService";
import { prisma } from "@langfuse/shared/src/db";
-import { BaseError, UnauthorizedError, ForbiddenError } from "@langfuse/shared";
+import {
+ BaseError,
+ UnauthorizedError,
+ ForbiddenError,
+ safeJsonParse,
+} from "@langfuse/shared";
import { ZodError } from "zod";
import { isUserInputError } from "@/src/features/mcp/core/errors";
import { IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER } from "@/src/features/in-app-agent/constants";
import { InAppAgentMcpRunOverrideSchema } from "@/src/features/in-app-agent/server/human-in-the-loop";
-import { safeJsonParse } from "@/src/utils/json";
// Bootstrap MCP features - registers all tools at module load time
import "@/src/features/mcp/server/bootstrap";
diff --git a/web/src/server/auth.ts b/web/src/server/auth.ts
index 9cc8ac92bb..77b94d188b 100644
--- a/web/src/server/auth.ts
+++ b/web/src/server/auth.ts
@@ -45,7 +45,7 @@ import {
} from "@/src/ee/features/multi-tenant-sso/utils";
import { ENTERPRISE_SSO_REQUIRED_MESSAGE } from "@/src/features/auth/constants";
import { z } from "zod";
-import { CloudConfigSchema } from "@langfuse/shared";
+import { CloudConfigSchema, projectRoleAccessRights } from "@langfuse/shared";
import {
CustomSSOProvider,
GitHubEnterpriseProvider,
@@ -60,7 +60,6 @@ import {
getOrganizationPlanServerSide,
getSelfHostedInstancePlanServerSide,
} from "@/src/features/entitlements/server/getPlan";
-import { projectRoleAccessRights } from "@/src/features/rbac/constants/projectAccessRights";
import { getSSOBlockedDomains } from "@/src/features/auth-credentials/server/signupApiHandler";
import { createSupportEmailHash } from "@/src/features/support-chat/createSupportEmailHash";
import { canToggleV4 } from "@/src/features/events/lib/v4Rollout";
diff --git a/web/src/utils/base-url.ts b/web/src/utils/base-url.ts
index f3556f864e..2491f5ea7f 100644
--- a/web/src/utils/base-url.ts
+++ b/web/src/utils/base-url.ts
@@ -1,5 +1,9 @@
import { env } from "@/src/env.mjs";
+// Mirrors getBaseUrl/getProductBaseUrl in @langfuse/shared
+// (src/server/utils/baseUrl.ts), which shared server code such as productUrl
+// uses. Web keeps its own copy so callers read the validated web env (and
+// tests can mock @/src/env.mjs as the seam).
const LOCALHOST_HOST_PATTERN = /^(localhost|127\.0\.0\.1|\[::1\])(?::|\/|$)/i;
export const getBaseUrl = () => {
diff --git a/web/src/utils/date-range-utils.ts b/web/src/utils/date-range-utils.ts
index b76ddbd76a..b6f552347b 100644
--- a/web/src/utils/date-range-utils.ts
+++ b/web/src/utils/date-range-utils.ts
@@ -1,102 +1,28 @@
import { z } from "zod";
import { addMinutes, format } from "date-fns";
-import { type DateTrunc } from "@langfuse/shared/src/server";
-interface TimeRangeDefinition {
- label: string;
- abbreviation: string;
- minutes: number | null;
- dateTrunc: DateTrunc | null;
-}
-
-export const TIME_RANGES = {
- last5Minutes: {
- label: "Past 5 min",
- abbreviation: "5m",
- minutes: 5,
- dateTrunc: "minute",
- },
- last30Minutes: {
- label: "Past 30 min",
- abbreviation: "30m",
- minutes: 30,
- dateTrunc: "minute",
- },
- last1Hour: {
- label: "Past 1 hour",
- abbreviation: "1h",
- minutes: 60,
- dateTrunc: "minute",
- },
- last3Hours: {
- label: "Past 3 hours",
- abbreviation: "3h",
- minutes: 3 * 60,
- dateTrunc: "minute",
- },
- last6Hours: {
- label: "Past 6 hours",
- abbreviation: "6h",
- minutes: 6 * 60,
- dateTrunc: "minute",
- },
- last1Day: {
- label: "Past 1 day",
- abbreviation: "1d",
- minutes: 24 * 60,
- dateTrunc: "hour",
- },
- last3Days: {
- label: "Past 3 days",
- abbreviation: "3d",
- minutes: 3 * 24 * 60,
- dateTrunc: "hour",
- },
- last7Days: {
- label: "Past 7 days",
- abbreviation: "7d",
- minutes: 7 * 24 * 60,
- dateTrunc: "hour",
- },
- last14Days: {
- label: "Past 14 days",
- abbreviation: "14d",
- minutes: 14 * 24 * 60,
- dateTrunc: "day",
- },
- last30Days: {
- label: "Past 30 days",
- abbreviation: "30d",
- minutes: 30 * 24 * 60,
- dateTrunc: "day",
- },
- last90Days: {
- label: "Past 90 days",
- abbreviation: "90d",
- minutes: 90 * 24 * 60,
- dateTrunc: "week",
- },
- last1Year: {
- label: "Past 1 year",
- abbreviation: "1y",
- minutes: 365 * 24 * 60,
- dateTrunc: "month",
- },
- allTime: {
- label: "All time",
- abbreviation: "All",
- minutes: null,
- dateTrunc: null,
- },
- custom: {
- label: "Custom",
- abbreviation: "Custom",
- minutes: null,
- dateTrunc: null,
- },
-} satisfies Record<string, TimeRangeDefinition>;
-
-export type TimeRangePresets = Exclude<keyof typeof TIME_RANGES, "custom">;
+// Time-range presets, table aggregation options, and the TimeRange type
+// moved to @langfuse/shared (utils/dateRanges); re-exported here for the
+// existing web import surface.
+export {
+ TIME_RANGES,
+ type TimeRangePresets,
+ TABLE_AGGREGATION_OPTIONS,
+ type TableDateRangeAggregationOption,
+ type RelativeTimeRange,
+ type AbsoluteTimeRange,
+ type TimeRange,
+ getAbbreviatedTimeRange,
+ rangeToString,
+} from "@langfuse/shared";
+import {
+ TIME_RANGES,
+ TABLE_AGGREGATION_OPTIONS,
+ type TableDateRangeAggregationOption,
+ type TimeRange,
+ type TimeRangeDefinition,
+ type AbsoluteTimeRange,
+} from "@langfuse/shared";
const ABBREVIATION_TO_KEY = new Map(
Object.entries(TIME_RANGES).map(([key, def]) => [def.abbreviation, key]),
@@ -118,18 +44,6 @@ export const DASHBOARD_AGGREGATION_OPTIONS = [
"last1Year",
] as const;
-export const TABLE_AGGREGATION_OPTIONS = [
- "last30Minutes",
- "last1Hour",
- "last6Hours",
- "last1Day",
- "last3Days",
- "last7Days",
- "last14Days",
- "last30Days",
- "last90Days",
-] as const;
-
export type DashboardDateRangeAggregationOption =
(typeof DASHBOARD_AGGREGATION_OPTIONS)[number];
@@ -138,9 +52,6 @@ export type TableDateRange = {
to?: Date;
};
-export type TableDateRangeAggregationOption =
- (typeof TABLE_AGGREGATION_OPTIONS)[number];
-
export type DashboardDateRange = {
from: Date;
to: Date;
@@ -267,12 +178,6 @@ export function isValidTableDateRangeAggregationOption(
return (TABLE_AGGREGATION_OPTIONS as readonly string[]).includes(value);
}
-export function getAbbreviatedTimeRange(option: string): string {
- return (
- TIME_RANGES[option as keyof typeof TIME_RANGES]?.abbreviation || option
- );
-}
-
export function getFullTimeRangeFromAbbreviated(
abbreviated: string,
): DateRangeAggregationOption | null {
@@ -342,17 +247,6 @@ export const formatDateRange = (from: Date, to: Date) => {
return `${format(from, fromPattern)} - ${format(to, toPattern)}`;
};
-export type RelativeTimeRange = {
- range: string;
-};
-
-export type AbsoluteTimeRange = {
- from: Date;
- to: Date;
-};
-
-export type TimeRange = RelativeTimeRange | AbsoluteTimeRange;
-
/**
* =======================
* Interval Configuration
@@ -589,18 +483,6 @@ export function getScoreAnalyticsInterval(
return "month";
}
-/**
- * Converts a range object to a string for URL serialization
- * - Named ranges: "last7Days" -> "7d" (abbreviated)
- * - Custom ranges: {from, to} -> "1693872000000-1694131199999"
- */
-export function rangeToString(range: TimeRange): string {
- if ("range" in range) {
- return getAbbreviatedTimeRange(range.range);
- }
- return `${range.from.getTime()}-${range.to.getTime()}`;
-}
-
/**
* Parses a string back to a range object with validation
* - Handles both abbreviated ("7d") and full ("last7Days") named ranges
diff --git a/web/src/utils/json.ts b/web/src/utils/json.ts
deleted file mode 100644
index cbb109e79e..0000000000
--- a/web/src/utils/json.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-export function safeJsonParse(value: string): unknown {
- try {
- return JSON.parse(value);
- } catch {
- return undefined;
- }
-}
-
-export function stableJsonStringify(value: unknown): string {
- return JSON.stringify(sortJsonValue(value)) ?? "undefined";
-}
-
-function sortJsonValue(value: unknown): unknown {
- if (Array.isArray(value)) {
- return value.map(sortJsonValue);
- }
-
- if (value && typeof value === "object") {
- return Object.fromEntries(
- Object.entries(value)
- .sort(([left], [right]) => left.localeCompare(right))
- .map(([key, nestedValue]) => [key, sortJsonValue(nestedValue)]),
- );
- }
-
- return value;
-}
diff --git a/web/src/utils/string.ts b/web/src/utils/string.ts
index fc383bdb48..e7d0fe6ab0 100644
--- a/web/src/utils/string.ts
+++ b/web/src/utils/string.ts
@@ -1,11 +1,5 @@
+export { truncate } from "@langfuse/shared";
+
export function lastCharacters(str: string, n: number) {
return str.substring(str.length - n);
}
-
-export function truncate(str: string, n = 16) {
- // '...' suffix if the string is longer than n
- if (str.length > n) {
- return str.substring(0, n) + "...";
- }
- return str;
-}
diff --git a/web/src/utils/types.ts b/web/src/utils/types.ts
index b49a5960b1..b96d888aaa 100644
--- a/web/src/utils/types.ts
+++ b/web/src/utils/types.ts
@@ -5,9 +5,7 @@ import { type ObservationReturnType } from "@/src/server/api/routers/traces";
// unreachable code check
-export function assertUnreachable(_x: never): never {
- throw new Error("Didn't expect to get here");
-}
+export { assertUnreachable } from "@langfuse/shared";
// primitive type checks