Skip to content

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

refactor(shared): promote query feature to @langfuse/shared (LFE-9806) (#13678)

Mark Salpeterd14d67cbc59d
diff --git a/.gitignore b/.gitignore
index 98dee645c7..83fb55f812 100644
--- a/.gitignore
+++ b/.gitignore
@@ -79,6 +79,7 @@ web/test-results/*
.mcp.json
.claude/settings.json
.claude/skills/
+.claude/launch.json
.cursor/mcp.json
.cursor/environment.json
.vscode/mcp.json
diff --git a/packages/shared/AGENTS.md b/packages/shared/AGENTS.md
index 6c56c604e6..b3d35cb945 100644
--- a/packages/shared/AGENTS.md
+++ b/packages/shared/AGENTS.md
@@ -30,6 +30,7 @@ Use root [AGENTS.md](../../AGENTS.md) for monorepo-level rules.
- Repository layer: `src/server/repositories/*`
- Queue payload schemas: `src/server/queues.ts`
- Queue helpers: `src/server/redis/*`
+- Dashboard/monitor query feature (data model + server-only builder/executor): `src/features/query/*`
- Postgres schema: `prisma/schema.prisma`
- For unstable public eval APIs, the public `evaluatorId` is currently the
exact `EvalTemplate.id`. Latest-version family grouping is derived from
@@ -54,6 +55,7 @@ Use root [AGENTS.md](../../AGENTS.md) for monorepo-level rules.
schema/accessors used by backend runtimes and scripts.
- `@langfuse/shared/encryption` via `src/encryption/index.ts`: encryption and
signature helpers for secrets and signed payloads.
+- `@langfuse/shared/query` via `src/features/query/index.ts`: dashboard query feature.
- Narrower exported subpaths also exist for targeted imports:
`@langfuse/shared/src/server/auth/apiKeys`,
`@langfuse/shared/src/server/ee/ingestionMasking`, and
@@ -108,8 +110,8 @@ the same PR.
set), fetch the latest published docs and check for discrepancies:
- https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage
- https://langfuse.com/docs/api-and-data-platform/features/blob-storage-export-fields
- Surface any mismatches in field names, types, nullability, or filter
- descriptions so they can be addressed in the docs repo.
+ Surface any mismatches in field names, types, nullability, or filter
+ descriptions so they can be addressed in the docs repo.
### Queue payload contract change
diff --git a/packages/shared/package.json b/packages/shared/package.json
index 043a08fd4d..61934914a3 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -46,6 +46,14 @@
"./src/server/ee/ingestionMasking": {
"import": "./dist/src/server/ee/ingestionMasking/index.js",
"require": "./dist/src/server/ee/ingestionMasking/index.js"
+ },
+ "./query": {
+ "import": "./dist/src/features/query/index.js",
+ "require": "./dist/src/features/query/index.js"
+ },
+ "./query/server": {
+ "import": "./dist/src/features/query/server/index.js",
+ "require": "./dist/src/features/query/server/index.js"
}
},
"scripts": {
diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.ts
index b74f29b883..96ea12fee6 100644
--- a/packages/shared/src/env.ts
+++ b/packages/shared/src/env.ts
@@ -105,7 +105,20 @@ const EnvSchema = z.object({
CLICKHOUSE_DISABLE_LAZY_MATERIALIZATION: z
.enum(["true", "false"])
.default("false"),
-
+ CLICKHOUSE_MAX_BYTES_BEFORE_EXTERNAL_GROUP_BY: z.coerce
+ .number()
+ .default(32_000_000_000), // ~32GB
+ CLICKHOUSE_USE_QUERY_CONDITION_CACHE: z
+ .enum(["true", "false"])
+ .default("false"),
+ LANGFUSE_ENABLE_SINGLE_LEVEL_QUERY_OPTIMIZATION: z
+ .enum(["true", "false"])
+ .default("false"),
+ LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS: z.coerce
+ .number()
+ .int()
+ .nonnegative()
+ .default(168), // 7 days
LANGFUSE_INGESTION_QUEUE_DELAY_MS: z.coerce
.number()
.nonnegative()
diff --git a/web/src/features/query/dataModel.ts b/packages/shared/src/features/query/dataModel.ts
similarity index 98%
rename from web/src/features/query/dataModel.ts
rename to packages/shared/src/features/query/dataModel.ts
index 35304a6781..b3bbd07a87 100644
--- a/web/src/features/query/dataModel.ts
+++ b/packages/shared/src/features/query/dataModel.ts
@@ -1,14 +1,14 @@
-import type z from "zod";
-import type {
- ViewVersion,
- ViewDeclarationType,
- DimensionsDeclarationType,
- views,
-} from "@/src/features/query/types";
-import { InvalidRequestError } from "@langfuse/shared";
+import { z } from "zod";
+import {
+ type ViewVersion,
+ type ViewDeclarationType,
+ type DimensionsDeclarationType,
+ type views,
+} from "./types";
+import { InvalidRequestError } from "../../errors";
// The data model defines all available dimensions, measures, and the timeDimension for a given view.
-// Make sure to update ./dashboardUiTableToViewMapping.ts if you make changes
+// Make sure to update web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts if you make changes
export const traceView: ViewDeclarationType = {
name: "traces",
@@ -1437,3 +1437,15 @@ export function getResultUnit(
if (aggregation === "count" || aggregation === "uniq") return "integer";
return getMeasureUnit(viewName, measureName, version);
}
+
+const measureNamesSet = new Set<string>();
+for (const versionViews of Object.values(viewDeclarations)) {
+ for (const view of Object.values(versionViews)) {
+ Object.keys(view.measures).forEach((m) => measureNamesSet.add(m));
+ }
+}
+const measureNames = Array.from(measureNamesSet).sort() as [
+ string,
+ ...string[],
+];
+export const measures = z.enum(measureNames);
diff --git a/web/src/features/query/index.ts b/packages/shared/src/features/query/index.ts
similarity index 52%
rename from web/src/features/query/index.ts
rename to packages/shared/src/features/query/index.ts
index 5555f1f257..4a023437cf 100644
--- a/web/src/features/query/index.ts
+++ b/packages/shared/src/features/query/index.ts
@@ -1,3 +1,3 @@
export * from "./dataModel";
-export * from "./dashboardUiTableToViewMapping";
export * from "./types";
+export * from "./validateQuery";
diff --git a/packages/shared/src/features/query/server/index.ts b/packages/shared/src/features/query/server/index.ts
new file mode 100644
index 0000000000..dea245f0e8
--- /dev/null
+++ b/packages/shared/src/features/query/server/index.ts
@@ -0,0 +1,3 @@
+export * from "./nullIfEmptyFilter";
+export * from "./queryBuilder";
+export * from "./queryExecutor";
diff --git a/web/src/features/query/server/nullIfEmptyFilter.ts b/packages/shared/src/features/query/server/nullIfEmptyFilter.ts
similarity index 100%
rename from web/src/features/query/server/nullIfEmptyFilter.ts
rename to packages/shared/src/features/query/server/nullIfEmptyFilter.ts
diff --git a/web/src/features/query/server/queryBuilder.ts b/packages/shared/src/features/query/server/queryBuilder.ts
similarity index 97%
rename from web/src/features/query/server/queryBuilder.ts
rename to packages/shared/src/features/query/server/queryBuilder.ts
index eeb208ee11..76103ed237 100644
--- a/web/src/features/query/server/queryBuilder.ts
+++ b/packages/shared/src/features/query/server/queryBuilder.ts
@@ -1,8 +1,12 @@
+import { randomUUID } from "crypto";
import { type z } from "zod";
+import { convertDateToClickhouseDateTime } from "../../../server/clickhouse/client";
+import { shouldSkipObservationsFinal } from "../../../server/queries/clickhouse-sql/query-options";
import {
- convertDateToClickhouseDateTime,
- shouldSkipObservationsFinal,
-} from "@langfuse/shared/src/server";
+ FilterList,
+ type Filter,
+} from "../../../server/queries/clickhouse-sql/clickhouse-filter";
+import { createFilterFromFilterState } from "../../../server/queries/clickhouse-sql/factory";
import type {
QueryType,
ViewDeclarationType,
@@ -15,14 +19,9 @@ import {
query as queryModel,
getValidAggregationsForMeasureType,
} from "../types";
-import { getViewDeclaration } from "@/src/features/query/dataModel";
-import {
- FilterList,
- createFilterFromFilterState,
- type Filter,
-} from "@langfuse/shared/src/server";
-import { InvalidRequestError } from "@langfuse/shared";
-import { env } from "@/src/env.mjs";
+import { getViewDeclaration } from "../dataModel";
+import { InvalidRequestError } from "../../../errors";
+import { env } from "../../../env";
import { NULL_IF_EMPTY_RE } from "./nullIfEmptyFilter";
type AppliedDimensionType = {
@@ -55,6 +54,8 @@ type MappedFilters = {
export class QueryBuilder {
private chartConfig?: { bins?: number; row_limit?: number };
private version: ViewVersion;
+ private rootEventConditionMaxWindowHours: number =
+ env.LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS;
constructor(
chartConfig?: { bins?: number; row_limit?: number },
@@ -64,6 +65,10 @@ export class QueryBuilder {
this.version = version;
}
+ setRootEventConditionMaxWindowHours(hours: number): void {
+ this.rootEventConditionMaxWindowHours = hours;
+ }
+
private translateAggregation(metric: AppliedMetricType): string {
switch (metric.aggregation) {
case "sum":
@@ -86,18 +91,20 @@ export class QueryBuilder {
return `quantile(0.95)(${metric.alias || metric.sql})`;
case "p99":
return `quantile(0.99)(${metric.alias || metric.sql})`;
- case "histogram":
+ case "histogram": {
// Get histogram bins from chart config, fallback to 10
const bins = this.chartConfig?.bins ?? 10;
return `histogram(${bins})(toFloat64(${metric.alias || metric.sql}))`;
+ }
case "uniq":
return `uniq(${metric.alias || metric.sql})`;
- default:
+ default: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const exhaustiveCheck: never = metric.aggregation;
throw new InvalidRequestError(
- `Invalid aggregation: ${metric.aggregation}`,
+ `Invalid aggregation: ${metric.aggregation satisfies never}`,
);
+ }
}
}
@@ -717,12 +724,13 @@ export class QueryBuilder {
throw new Error(
`Granularity 'auto' is not supported for getTimeDimensionSql`,
);
- default:
+ default: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const exhaustiveCheck: never = granularity;
throw new InvalidRequestError(
`Invalid time granularity: ${granularity}. Must be one of minute, hour, day, week, month`,
);
+ }
}
}
@@ -1351,12 +1359,12 @@ export class QueryBuilder {
new Date(query.toTimestamp).getTime() -
new Date(query.fromTimestamp).getTime();
const windowHours = windowMs / (1000 * 60 * 60);
- const thresholdHours = env.LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS;
+ const thresholdHours = this.rootEventConditionMaxWindowHours;
if (thresholdHours === 0 || windowHours <= thresholdHours) {
// Falls back gracefully: if no root events exist in the window at all
// (e.g. parent_span_id is never populated), the filter is skipped via NOT EXISTS.
- const uid = crypto.randomUUID().replace(/-/g, "").slice(0, 8);
+ const uid = randomUUID().replace(/-/g, "").slice(0, 8);
const fromP = `subFrom${uid}`;
const toP = `subTo${uid}`;
const projP = `subProj${uid}`;
diff --git a/web/src/features/query/server/queryExecutor.ts b/packages/shared/src/features/query/server/queryExecutor.ts
similarity index 86%
rename from web/src/features/query/server/queryExecutor.ts
rename to packages/shared/src/features/query/server/queryExecutor.ts
index 1a09787570..01e10d59bd 100644
--- a/web/src/features/query/server/queryExecutor.ts
+++ b/packages/shared/src/features/query/server/queryExecutor.ts
@@ -1,19 +1,13 @@
import {
queryClickhouse,
- measureAndReturn,
type ClickhouseQueryOpts,
- type PreferredClickhouseService,
-} from "@langfuse/shared/src/server";
-import { QueryBuilder } from "@/src/features/query/server/queryBuilder";
-import { type QueryType, type ViewVersion } from "@/src/features/query/types";
-import { getViewDeclaration } from "@/src/features/query/dataModel";
-import { env } from "@/src/env.mjs";
-
-// Re-export validation logic (shared between server and client)
-export {
- validateQuery,
- type QueryValidationResult,
-} from "@/src/features/query/validateQuery";
+} from "../../../server/repositories/clickhouse";
+import { measureAndReturn } from "../../../server/clickhouse/measureAndReturn";
+import { type PreferredClickhouseService } from "../../../server/clickhouse/client";
+import { QueryBuilder } from "./queryBuilder";
+import { type QueryType, type ViewVersion } from "../types";
+import { getViewDeclaration } from "../dataModel";
+import { env } from "../../../env";
export type PreparedQuery = {
compiledQuery: string;
diff --git a/web/src/features/query/types.ts b/packages/shared/src/features/query/types.ts
similarity index 98%
rename from web/src/features/query/types.ts
rename to packages/shared/src/features/query/types.ts
index d52252be79..2919d32129 100644
--- a/web/src/features/query/types.ts
+++ b/packages/shared/src/features/query/types.ts
@@ -1,5 +1,5 @@
import { z } from "zod";
-import { singleFilter } from "@langfuse/shared";
+import { singleFilter } from "../../interfaces/filters";
export type ViewDeclarationType = z.infer<typeof viewDeclaration>;
export type DimensionsDeclarationType = z.infer<
@@ -80,7 +80,7 @@ export const viewDeclaration = z.object({
.optional(),
});
-export const stringDateTime = z.iso.datetime({ offset: true });
+const stringDateTime = z.iso.datetime({ offset: true });
export const views = z.enum([
"traces",
diff --git a/web/src/features/query/validateQuery.ts b/packages/shared/src/features/query/validateQuery.ts
similarity index 97%
rename from web/src/features/query/validateQuery.ts
rename to packages/shared/src/features/query/validateQuery.ts
index be3630f5e8..449dc3626d 100644
--- a/web/src/features/query/validateQuery.ts
+++ b/packages/shared/src/features/query/validateQuery.ts
@@ -1,5 +1,5 @@
-import { type QueryType, type ViewVersion } from "@/src/features/query/types";
-import { getViewDeclaration } from "@/src/features/query/dataModel";
+import { type QueryType, type ViewVersion } from "./types";
+import { getViewDeclaration } from "./dataModel";
/**
* Result of query validation.
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index 18006c6f2a..62a3f4ee17 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -99,3 +99,8 @@ export * from "./utils/IORepresentation";
// analytics integrations (client-safe)
export * from "./features/analytics-integrations";
+
+// query (dashboard / monitor data model)
+export * from "./features/query/types";
+export * from "./features/query/dataModel";
+export * from "./features/query/validateQuery";
diff --git a/packages/shared/src/tableDefinitions/mapDashboards.ts b/packages/shared/src/tableDefinitions/mapDashboards.ts
index 29351c8721..4af9f7eea6 100644
--- a/packages/shared/src/tableDefinitions/mapDashboards.ts
+++ b/packages/shared/src/tableDefinitions/mapDashboards.ts
@@ -1,6 +1,6 @@
import { UiColumnMappings } from "./types";
-// Make sure to update web/src/features/query/dashboardUiTableToViewMapping.ts if you make changes
+// Make sure to update web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts if you make changes
export const dashboardColumnDefinitions: UiColumnMappings = [
{
diff --git a/web/src/__tests__/server/dashboard-router-pivot-table.servertest.ts b/web/src/__tests__/server/dashboard-router-pivot-table.servertest.ts
index 23e6e46a70..862d135df8 100644
--- a/web/src/__tests__/server/dashboard-router-pivot-table.servertest.ts
+++ b/web/src/__tests__/server/dashboard-router-pivot-table.servertest.ts
@@ -23,14 +23,12 @@ import {
createObservation,
createObservationsCh,
} from "@langfuse/shared/src/server";
-import { type QueryType } from "@/src/features/query/types";
+import { QueryBuilder, executeQuery } from "@langfuse/shared/query/server";
+import { type QueryType } from "@langfuse/shared/query";
import {
transformToPivotTable,
type DatabaseRow,
} from "@/src/features/widgets/utils/pivot-table-utils";
-import { QueryBuilder } from "@/src/features/query/server/queryBuilder";
-import { executeQuery } from "@/src/features/query/server/queryExecutor";
-
describe("Dashboard Router - Pivot Table Integration", () => {
// Single project ID for all tests
const projectId = randomUUID();
diff --git a/web/src/__tests__/server/dashboard-v1-v2-consistency.servertest.ts b/web/src/__tests__/server/dashboard-v1-v2-consistency.servertest.ts
index 8826788232..f37c25bf48 100644
--- a/web/src/__tests__/server/dashboard-v1-v2-consistency.servertest.ts
+++ b/web/src/__tests__/server/dashboard-v1-v2-consistency.servertest.ts
@@ -1,6 +1,6 @@
import { v4 } from "uuid";
-import { type QueryType } from "@/src/features/query/types";
-import { executeQuery } from "@/src/features/query/server/queryExecutor";
+import { executeQuery } from "@langfuse/shared/query/server";
+import { type QueryType } from "@langfuse/shared/query";
import {
createOrgProjectAndApiKey,
createTrace,
diff --git a/web/src/__tests__/server/dashboard-widget-version.servertest.ts b/web/src/__tests__/server/dashboard-widget-version.servertest.ts
index b7261c10ce..99e2766f5c 100644
--- a/web/src/__tests__/server/dashboard-widget-version.servertest.ts
+++ b/web/src/__tests__/server/dashboard-widget-version.servertest.ts
@@ -6,11 +6,11 @@ import { prisma } from "@langfuse/shared/src/db";
import { appRouter } from "@/src/server/api/root";
import { createInnerTRPCContext } from "@/src/server/api/trpc";
import type { Session } from "next-auth";
-import { requiresV2 } from "@/src/features/query/dataModel";
+import { requiresV2 } from "@langfuse/shared/query";
import {
mapLegacyUiTableFilterToView,
mapWidgetUiTableFilterToView,
-} from "@/src/features/query";
+} from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
describe("dashboard widget minVersion", () => {
let projectId: string;
diff --git a/web/src/__tests__/server/metrics-api.servertest.ts b/web/src/__tests__/server/metrics-api.servertest.ts
index 46ce1cf5cb..4effe9cbbe 100644
--- a/web/src/__tests__/server/metrics-api.servertest.ts
+++ b/web/src/__tests__/server/metrics-api.servertest.ts
@@ -6,7 +6,7 @@ import {
} from "@/src/__tests__/test-utils";
import { GetMetricsV1Response } from "@/src/features/public-api/types/metrics";
import { createBasicAuthHeader } from "@langfuse/shared/src/server";
-import { type QueryType } from "@/src/features/query/types";
+import { type QueryType } from "@langfuse/shared/query";
import {
createTrace,
createObservation,
diff --git a/web/src/__tests__/server/nullIfEmptyFilter.servertest.ts b/web/src/__tests__/server/nullIfEmptyFilter.servertest.ts
index 454df34b20..2e49a55bd5 100644
--- a/web/src/__tests__/server/nullIfEmptyFilter.servertest.ts
+++ b/web/src/__tests__/server/nullIfEmptyFilter.servertest.ts
@@ -1,4 +1,4 @@
-import { NULL_IF_EMPTY_RE } from "@/src/features/query/server/nullIfEmptyFilter";
+import { NULL_IF_EMPTY_RE } from "@langfuse/shared/query/server";
import {
StringFilter,
StringOptionsFilter,
diff --git a/web/src/__tests__/server/queryBuilder.servertest.ts b/web/src/__tests__/server/queryBuilder.servertest.ts
index 6df7cd6bae..6c4b255d25 100644
--- a/web/src/__tests__/server/queryBuilder.servertest.ts
+++ b/web/src/__tests__/server/queryBuilder.servertest.ts
@@ -1,13 +1,10 @@
-import { QueryBuilder } from "@/src/features/query/server/queryBuilder";
+import { QueryBuilder, executeQuery } from "@langfuse/shared/query/server";
import {
- type QueryType,
getValidAggregationsForMeasureType,
metricAggregations,
-} from "@/src/features/query/types";
-import {
- executeQuery,
validateQuery,
-} from "@/src/features/query/server/queryExecutor";
+ type QueryType,
+} from "@langfuse/shared/query";
import { env } from "@/src/env.mjs";
import {
createTrace,
@@ -4811,52 +4808,34 @@ describe("query builder measure-aggregation validation", () => {
};
it("should include rootEventCondition subquery when window is within threshold", async () => {
- const originalValue = env.LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS;
- try {
- // 168 hours (7 days) threshold, 72-hour window → should include subquery
- (env as any).LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS = 168;
- const builder = new QueryBuilder(undefined, "v2");
- const { query: sql } = await builder.build(tracesV2Query, randomUUID());
- expect(sql).toContain("IN (SELECT trace_id");
- } finally {
- (env as any).LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS =
- originalValue;
- }
+ // 168 hours (7 days) threshold, 72-hour window → should include subquery
+ const builder = new QueryBuilder(undefined, "v2");
+ builder.setRootEventConditionMaxWindowHours(168);
+ const { query: sql } = await builder.build(tracesV2Query, randomUUID());
+ expect(sql).toContain("IN (SELECT trace_id");
});
it("should skip rootEventCondition subquery when window exceeds threshold", async () => {
- const originalValue = env.LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS;
- try {
- // 24-hour threshold, 72-hour window → should skip subquery
- (env as any).LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS = 24;
- const builder = new QueryBuilder(undefined, "v2");
- const { query: sql } = await builder.build(tracesV2Query, randomUUID());
- expect(sql).not.toContain("IN (SELECT trace_id");
- } finally {
- (env as any).LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS =
- originalValue;
- }
+ // 24-hour threshold, 72-hour window → should skip subquery
+ const builder = new QueryBuilder(undefined, "v2");
+ builder.setRootEventConditionMaxWindowHours(24);
+ const { query: sql } = await builder.build(tracesV2Query, randomUUID());
+ expect(sql).not.toContain("IN (SELECT trace_id");
});
it("should always include rootEventCondition subquery when threshold is 0", async () => {
- const originalValue = env.LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS;
- try {
- // 0 = always apply, even for a very wide window
- (env as any).LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS = 0;
- const builder = new QueryBuilder(undefined, "v2");
- const { query: sql } = await builder.build(
- {
- ...tracesV2Query,
- fromTimestamp: "2024-01-01T00:00:00.000Z",
- toTimestamp: "2025-01-01T00:00:00.000Z", // 1-year window
- },
- randomUUID(),
- );
- expect(sql).toContain("IN (SELECT trace_id");
- } finally {
- (env as any).LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS =
- originalValue;
- }
+ // 0 = always apply, even for a very wide window
+ const builder = new QueryBuilder(undefined, "v2");
+ builder.setRootEventConditionMaxWindowHours(0);
+ const { query: sql } = await builder.build(
+ {
+ ...tracesV2Query,
+ fromTimestamp: "2024-01-01T00:00:00.000Z",
+ toTimestamp: "2025-01-01T00:00:00.000Z", // 1-year window
+ },
+ randomUUID(),
+ );
+ expect(sql).toContain("IN (SELECT trace_id");
});
});
});
diff --git a/web/src/__tests__/server/queryBuilderDashboards.servertest.ts b/web/src/__tests__/server/queryBuilderDashboards.servertest.ts
index a253959180..c2cf9a7619 100644
--- a/web/src/__tests__/server/queryBuilderDashboards.servertest.ts
+++ b/web/src/__tests__/server/queryBuilderDashboards.servertest.ts
@@ -5,9 +5,9 @@ import {
createObservation,
createObservationsCh,
} from "@langfuse/shared/src/server";
-import { type QueryType } from "@/src/features/query/types";
-import { executeQuery } from "@/src/features/query/server/queryExecutor";
-import { mapLegacyUiTableFilterToView } from "@/src/features/query";
+import { executeQuery } from "@langfuse/shared/query/server";
+import { type QueryType } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
describe("selfServeDashboards", () => {
// Single project ID for all tests
diff --git a/web/src/__tests__/server/queryBuilderSQLI.servertest.ts b/web/src/__tests__/server/queryBuilderSQLI.servertest.ts
index 8e712ea789..20327655fc 100644
--- a/web/src/__tests__/server/queryBuilderSQLI.servertest.ts
+++ b/web/src/__tests__/server/queryBuilderSQLI.servertest.ts
@@ -1,7 +1,6 @@
import { randomUUID } from "crypto";
-import { QueryBuilder } from "@/src/features/query/server/queryBuilder";
-import { type QueryType } from "@/src/features/query/types";
-import { executeQuery } from "@/src/features/query/server/queryExecutor";
+import { QueryBuilder, executeQuery } from "@langfuse/shared/query/server";
+import { type QueryType } from "@langfuse/shared/query";
import { InvalidRequestError } from "@langfuse/shared";
/**
diff --git a/web/src/env.mjs b/web/src/env.mjs
index eb028e59de..3d7edcef0b 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -283,20 +283,6 @@ export const env = createEnv({
CLICKHOUSE_USER: z.string(),
CLICKHOUSE_PASSWORD: z.string(),
CLICKHOUSE_CLUSTER_ENABLED: z.enum(["true", "false"]).default("true"),
- CLICKHOUSE_MAX_BYTES_BEFORE_EXTERNAL_GROUP_BY: z.coerce
- .number()
- .default(32_000_000_000), // ~32GB
- CLICKHOUSE_USE_QUERY_CONDITION_CACHE: z
- .enum(["true", "false"])
- .default("false"),
- LANGFUSE_ENABLE_SINGLE_LEVEL_QUERY_OPTIMIZATION: z
- .enum(["true", "false"])
- .default("false"),
- LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS: z.coerce
- .number()
- .int()
- .nonnegative()
- .default(168), // 7 days
// EE ui customization
LANGFUSE_UI_API_HOST: z.string().optional(),
@@ -760,14 +746,6 @@ export const env = createEnv({
CLICKHOUSE_USER: process.env.CLICKHOUSE_USER,
CLICKHOUSE_PASSWORD: process.env.CLICKHOUSE_PASSWORD,
CLICKHOUSE_CLUSTER_ENABLED: process.env.CLICKHOUSE_CLUSTER_ENABLED,
- CLICKHOUSE_MAX_BYTES_BEFORE_EXTERNAL_GROUP_BY:
- process.env.CLICKHOUSE_MAX_BYTES_BEFORE_EXTERNAL_GROUP_BY,
- CLICKHOUSE_USE_QUERY_CONDITION_CACHE:
- process.env.CLICKHOUSE_USE_QUERY_CONDITION_CACHE,
- LANGFUSE_ENABLE_SINGLE_LEVEL_QUERY_OPTIMIZATION:
- process.env.LANGFUSE_ENABLE_SINGLE_LEVEL_QUERY_OPTIMIZATION,
- LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS:
- process.env.LANGFUSE_ROOT_EVENT_CONDITION_MAX_WINDOW_HOURS,
// EE ui customization
LANGFUSE_UI_API_HOST: process.env.LANGFUSE_UI_API_HOST,
LANGFUSE_UI_DOCUMENTATION_HREF: process.env.LANGFUSE_UI_DOCUMENTATION_HREF,
diff --git a/web/src/features/dashboard/components/ChartScores.tsx b/web/src/features/dashboard/components/ChartScores.tsx
index 70801afd1c..0334286eaa 100644
--- a/web/src/features/dashboard/components/ChartScores.tsx
+++ b/web/src/features/dashboard/components/ChartScores.tsx
@@ -11,11 +11,8 @@ import {
} from "@/src/utils/date-range-utils";
import { getScoreDataTypeIcon } from "@/src/features/scores/lib/scoreColumns";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
diff --git a/web/src/features/dashboard/components/LatencyChart.tsx b/web/src/features/dashboard/components/LatencyChart.tsx
index 119aee3449..c90580a1fe 100644
--- a/web/src/features/dashboard/components/LatencyChart.tsx
+++ b/web/src/features/dashboard/components/LatencyChart.tsx
@@ -15,11 +15,8 @@ import {
ModelSelectorPopover,
useModelSelection,
} from "@/src/features/dashboard/components/ModelSelector";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import type { DatabaseRow } from "@/src/server/api/services/sqlInterface";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
diff --git a/web/src/features/dashboard/components/LatencyTables.tsx b/web/src/features/dashboard/components/LatencyTables.tsx
index c6e29a8482..da3919d4e7 100644
--- a/web/src/features/dashboard/components/LatencyTables.tsx
+++ b/web/src/features/dashboard/components/LatencyTables.tsx
@@ -10,11 +10,8 @@ import {
import { formatIntervalSeconds } from "@/src/utils/dates";
import { truncate } from "@/src/utils/string";
import { Popup } from "@/src/components/layouts/doc-popup";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
export const LatencyTables = ({
diff --git a/web/src/features/dashboard/components/ModelCostTable.tsx b/web/src/features/dashboard/components/ModelCostTable.tsx
index fb34f2d2aa..30536fde6e 100644
--- a/web/src/features/dashboard/components/ModelCostTable.tsx
+++ b/web/src/features/dashboard/components/ModelCostTable.tsx
@@ -8,11 +8,8 @@ import { compactNumberFormatter } from "@/src/utils/numbers";
import { TotalMetric } from "./TotalMetric";
import { costFormatter } from "@/src/utils/numbers";
import { truncate } from "@/src/utils/string";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
export const ModelCostTable = ({
diff --git a/web/src/features/dashboard/components/ModelSelector.tsx b/web/src/features/dashboard/components/ModelSelector.tsx
index 0a712b958d..d625e9cd60 100644
--- a/web/src/features/dashboard/components/ModelSelector.tsx
+++ b/web/src/features/dashboard/components/ModelSelector.tsx
@@ -16,7 +16,7 @@ import {
import { useAllModels } from "@/src/features/dashboard/components/hooks";
import { cn } from "@/src/utils/tailwind";
import { type FilterState } from "@langfuse/shared";
-import { type ViewVersion } from "@/src/features/query";
+import { type ViewVersion } from "@langfuse/shared/query";
import { Check, ChevronsUpDown } from "lucide-react";
import { useEffect, useState } from "react";
diff --git a/web/src/features/dashboard/components/ModelUsageChart.tsx b/web/src/features/dashboard/components/ModelUsageChart.tsx
index bef5bb6d0e..38dc99ea3a 100644
--- a/web/src/features/dashboard/components/ModelUsageChart.tsx
+++ b/web/src/features/dashboard/components/ModelUsageChart.tsx
@@ -19,11 +19,8 @@ import {
ModelSelectorPopover,
useModelSelection,
} from "@/src/features/dashboard/components/ModelSelector";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
diff --git a/web/src/features/dashboard/components/ScoresTable.tsx b/web/src/features/dashboard/components/ScoresTable.tsx
index a3f384a799..f5986f85fe 100644
--- a/web/src/features/dashboard/components/ScoresTable.tsx
+++ b/web/src/features/dashboard/components/ScoresTable.tsx
@@ -5,7 +5,7 @@ import {
type ScoreSourceType,
type FilterState,
} from "@langfuse/shared";
-import { type ViewVersion } from "@/src/features/query";
+import { type ViewVersion } from "@langfuse/shared/query";
import { api } from "@/src/utils/api";
import { compactNumberFormatter } from "@/src/utils/numbers";
import { RightAlignedCell } from "./RightAlignedCell";
diff --git a/web/src/features/dashboard/components/TracesBarListChart.tsx b/web/src/features/dashboard/components/TracesBarListChart.tsx
index 951dd4e8fc..267a35ee93 100644
--- a/web/src/features/dashboard/components/TracesBarListChart.tsx
+++ b/web/src/features/dashboard/components/TracesBarListChart.tsx
@@ -5,7 +5,7 @@ import { DashboardCard } from "@/src/features/dashboard/components/cards/Dashboa
import { TotalMetric } from "@/src/features/dashboard/components/TotalMetric";
import { compactNumberFormatter } from "@/src/utils/numbers";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
-import { type QueryType, type ViewVersion } from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { formatMetric } from "@/src/features/widgets/chart-library/utils";
import { barListToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
diff --git a/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx b/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx
index b3c5bcf5b4..ec337ed5c3 100644
--- a/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx
+++ b/web/src/features/dashboard/components/TracesTimeSeriesChart.tsx
@@ -9,11 +9,8 @@ import {
} from "@/src/utils/date-range-utils";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
import { TabComponent } from "@/src/features/dashboard/components/TabsComponent";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
diff --git a/web/src/features/dashboard/components/UserChart.tsx b/web/src/features/dashboard/components/UserChart.tsx
index 5810ee4395..00c59a7a8d 100644
--- a/web/src/features/dashboard/components/UserChart.tsx
+++ b/web/src/features/dashboard/components/UserChart.tsx
@@ -7,11 +7,8 @@ import { ExpandListButton } from "@/src/features/dashboard/components/cards/Chev
import { useState } from "react";
import { costFormatter } from "@/src/utils/numbers";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { barListToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
import { traceViewQuery } from "@/src/features/dashboard/lib/dashboard-utils";
diff --git a/web/src/features/dashboard/components/hooks.ts b/web/src/features/dashboard/components/hooks.ts
index ff0f0d7d7e..96456f5450 100644
--- a/web/src/features/dashboard/components/hooks.ts
+++ b/web/src/features/dashboard/components/hooks.ts
@@ -5,10 +5,8 @@ export type TimeSeriesChartDataPoint = {
values: { label: string; value?: number }[];
};
import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";
-import {
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
type UseAllModelsOptions = {
diff --git a/web/src/features/dashboard/components/score-analytics/CategoricalScoreChart.tsx b/web/src/features/dashboard/components/score-analytics/CategoricalScoreChart.tsx
index e8a3813047..12daf5c90f 100644
--- a/web/src/features/dashboard/components/score-analytics/CategoricalScoreChart.tsx
+++ b/web/src/features/dashboard/components/score-analytics/CategoricalScoreChart.tsx
@@ -7,11 +7,8 @@ import {
import React, { useMemo } from "react";
import { DashboardCategoricalScoreAdapter } from "@/src/features/scores/adapters";
import { type ScoreData } from "@/src/features/scores/types";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { scoreChartDataToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
diff --git a/web/src/features/dashboard/components/score-analytics/NumericScoreHistogram.tsx b/web/src/features/dashboard/components/score-analytics/NumericScoreHistogram.tsx
index 96ff090508..bbb142b823 100644
--- a/web/src/features/dashboard/components/score-analytics/NumericScoreHistogram.tsx
+++ b/web/src/features/dashboard/components/score-analytics/NumericScoreHistogram.tsx
@@ -4,7 +4,7 @@ import {
type FilterState,
type ScoreDataTypeType,
} from "@langfuse/shared";
-import { type ViewVersion } from "@/src/features/query";
+import { type ViewVersion } from "@langfuse/shared/query";
import { createTracesTimeFilter } from "@/src/features/dashboard/lib/dashboard-utils";
import React from "react";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
diff --git a/web/src/features/dashboard/components/score-analytics/NumericScoreTimeSeriesChart.tsx b/web/src/features/dashboard/components/score-analytics/NumericScoreTimeSeriesChart.tsx
index e78c10eb17..4203fedcd3 100644
--- a/web/src/features/dashboard/components/score-analytics/NumericScoreTimeSeriesChart.tsx
+++ b/web/src/features/dashboard/components/score-analytics/NumericScoreTimeSeriesChart.tsx
@@ -15,11 +15,8 @@ import {
} from "@/src/utils/date-range-utils";
import React, { useMemo } from "react";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { timeSeriesToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
diff --git a/web/src/features/dashboard/components/score-analytics/ScoreAnalytics.tsx b/web/src/features/dashboard/components/score-analytics/ScoreAnalytics.tsx
index e9860d6603..cae1822da5 100644
--- a/web/src/features/dashboard/components/score-analytics/ScoreAnalytics.tsx
+++ b/web/src/features/dashboard/components/score-analytics/ScoreAnalytics.tsx
@@ -16,7 +16,7 @@ import { NumericScoreHistogram } from "@/src/features/dashboard/components/score
import DocPopup from "@/src/components/layouts/doc-popup";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
import useLocalStorage from "@/src/components/useLocalStorage";
-import { type ViewVersion } from "@/src/features/query";
+import { type ViewVersion } from "@langfuse/shared/query";
import {
convertScoreColumnsToAnalyticsData,
getScoreDataTypeIcon,
diff --git a/web/src/features/dashboard/lib/dashboard-utils.ts b/web/src/features/dashboard/lib/dashboard-utils.ts
index 4326b2a133..2a73e2dc8d 100644
--- a/web/src/features/dashboard/lib/dashboard-utils.ts
+++ b/web/src/features/dashboard/lib/dashboard-utils.ts
@@ -1,10 +1,7 @@
import { type z } from "zod";
import { type FilterState, type singleFilter } from "@langfuse/shared";
-import {
- type QueryType,
- type ViewVersion,
- mapLegacyUiTableFilterToView,
-} from "@/src/features/query";
+import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
// traces do not have a startTime or endTime column, so we need to map these to the timestamp column
export const createTracesTimeFilter = (
diff --git a/web/src/features/query/dashboardUiTableToViewMapping.ts b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts
similarity index 99%
rename from web/src/features/query/dashboardUiTableToViewMapping.ts
rename to web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts
index 5390ad65f8..d0ebee8ab5 100644
--- a/web/src/features/query/dashboardUiTableToViewMapping.ts
+++ b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts
@@ -1,6 +1,6 @@
import { z } from "zod";
import { singleFilter } from "@langfuse/shared";
-import { type views } from "@/src/features/query/types";
+import { type views } from "@langfuse/shared/query";
// Exported to silence @typescript-eslint/no-unused-vars v8 warning
// (used for type extraction via typeof, which is a legitimate pattern)
diff --git a/web/src/features/dashboard/server/dashboard-router.ts b/web/src/features/dashboard/server/dashboard-router.ts
index c41c44ec7c..4791a3498b 100644
--- a/web/src/features/dashboard/server/dashboard-router.ts
+++ b/web/src/features/dashboard/server/dashboard-router.ts
@@ -20,12 +20,14 @@ import {
DashboardDefinitionSchema,
} from "@langfuse/shared/src/server";
import { type DatabaseRow } from "@/src/server/api/services/sqlInterface";
+import { executeQuery } from "@langfuse/shared/query/server";
import {
- type QueryType,
query as customQuery,
+ validateQuery,
viewVersions,
-} from "@/src/features/query/types";
-import { mapLegacyUiTableFilterToView } from "@/src/features/query/dashboardUiTableToViewMapping";
+ type QueryType,
+} from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import {
paginationZod,
orderBy,
@@ -35,10 +37,6 @@ import {
type FilterState,
} from "@langfuse/shared";
import { throwIfNoProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import {
- executeQuery,
- validateQuery,
-} from "@/src/features/query/server/queryExecutor";
// Define the dashboard list input schema
const ListDashboardsInput = z.object({
diff --git a/web/src/features/public-api/types/metrics.ts b/web/src/features/public-api/types/metrics.ts
index b83077b3e5..dff05fa0f7 100644
--- a/web/src/features/public-api/types/metrics.ts
+++ b/web/src/features/public-api/types/metrics.ts
@@ -12,7 +12,7 @@ import {
metric,
views,
viewsV2,
-} from "@/src/features/query";
+} from "@langfuse/shared/query";
/**
* Query Object Structure
diff --git a/web/src/features/public-api/types/observations.ts b/web/src/features/public-api/types/observations.ts
index fc1e1196da..72c257e212 100644
--- a/web/src/features/public-api/types/observations.ts
+++ b/web/src/features/public-api/types/observations.ts
@@ -7,7 +7,6 @@ import {
singleFilter,
InvalidRequestError,
} from "@langfuse/shared";
-
import {
reduceUsageOrCostDetails,
stringDateTime,
@@ -18,7 +17,7 @@ import {
type ObservationFieldGroupPublicApi,
} from "@langfuse/shared";
import { z } from "zod";
-import { useEventsTableSchema } from "../../query/types";
+import { useEventsTableSchema } from "@langfuse/shared/query";
// Re-export for convenience
export {
diff --git a/web/src/features/public-api/types/traces.ts b/web/src/features/public-api/types/traces.ts
index c84c1a69df..01864475f8 100644
--- a/web/src/features/public-api/types/traces.ts
+++ b/web/src/features/public-api/types/traces.ts
@@ -9,7 +9,7 @@ import {
} from "@langfuse/shared";
import { stringDateTime, TraceBody } from "@langfuse/shared/src/server";
import { z } from "zod";
-import { useEventsTableSchema } from "../../query";
+import { useEventsTableSchema } from "@langfuse/shared/query";
/**
* Field groups for selective field fetching
diff --git a/web/src/features/widgets/components/DashboardWidget.tsx b/web/src/features/widgets/components/DashboardWidget.tsx
index 550197b656..c708919881 100644
--- a/web/src/features/widgets/components/DashboardWidget.tsx
+++ b/web/src/features/widgets/components/DashboardWidget.tsx
@@ -1,12 +1,18 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { api } from "@/src/utils/api";
import {
- type views,
- type metricAggregations,
- type QueryType,
- mapLegacyUiTableFilterToView,
+ buildWidgetOrderBy,
getResultUnit,
-} from "@/src/features/query";
+ isV2BreakdownChart,
+ requiresV2,
+ toQueryChartConfig,
+ validateQuery,
+ type QueryType,
+ type ViewVersion,
+ type metricAggregations,
+ type views,
+} from "@langfuse/shared/query";
+import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import { type z } from "zod";
import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { type FilterState, type OrderByState } from "@langfuse/shared";
@@ -33,15 +39,7 @@ import {
getChartLoadingStateProps,
} from "@/src/features/widgets/chart-library/chartLoadingStateUtils";
import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
-import { type ViewVersion } from "@/src/features/query";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
-import {
- validateQuery,
- toQueryChartConfig,
- isV2BreakdownChart,
- buildWidgetOrderBy,
-} from "@/src/features/query/validateQuery";
-import { requiresV2 } from "@/src/features/query/dataModel";
export interface WidgetPlacement {
id: string;
diff --git a/web/src/features/widgets/components/WidgetForm.tsx b/web/src/features/widgets/components/WidgetForm.tsx
index f0edb1d219..baee6c52c2 100644
--- a/web/src/features/widgets/components/WidgetForm.tsx
+++ b/web/src/features/widgets/components/WidgetForm.tsx
@@ -8,14 +8,24 @@ import {
} from "@/src/components/ui/card";
import { api } from "@/src/utils/api";
import {
- type metricAggregations,
+ buildWidgetOrderBy,
+ getResultUnit,
getValidAggregationsForMeasureType,
+ isV2BreakdownChart,
+ requiresV2,
+ validateQuery,
+ viewDeclarations,
+ views,
+ viewsV2,
type QueryType,
- getResultUnit,
+ type ViewVersion,
+ type metricAggregations,
+} from "@langfuse/shared/query";
+import {
mapWidgetUiTableFilterToView,
normalizeStoredWidgetFiltersForEditor,
partitionWidgetUiTableFiltersToView,
-} from "@/src/features/query";
+} from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
import React, { useState, useMemo, useEffect, useRef } from "react";
import {
Select,
@@ -29,10 +39,9 @@ import {
import { WidgetPropertySelectItem } from "@/src/features/widgets/components/WidgetPropertySelectItem";
import { Label } from "@/src/components/ui/label";
import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
-import { viewDeclarations, requiresV2 } from "@/src/features/query/dataModel";
+
import { type z } from "zod";
-import { views, viewsV2 } from "@/src/features/query/types";
-import { type ViewVersion } from "@/src/features/query";
+
import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
import { Input } from "@/src/components/ui/input";
import startCase from "lodash/startCase";
@@ -55,11 +64,6 @@ import {
ObservationTypeDomain,
} from "@langfuse/shared";
import { isTimeSeriesChart } from "@/src/features/widgets/chart-library/utils";
-import {
- validateQuery,
- isV2BreakdownChart,
- buildWidgetOrderBy,
-} from "@/src/features/query/validateQuery";
import {
BarChart,
PieChart,
@@ -78,6 +82,7 @@ import {
formatMetricName,
getWidgetMetricPresentation,
sanitizePivotTableDefaultSort,
+ type WidgetChartConfig,
} from "@/src/features/widgets/utils";
import {
MAX_PIVOT_TABLE_DIMENSIONS,
@@ -101,8 +106,6 @@ type ChartType = {
supportsBreakdown: boolean;
};
-import { type WidgetChartConfig } from "@/src/features/widgets/utils";
-
type ChartConfig = WidgetChartConfig;
const chartTypes: ChartType[] = [
diff --git a/web/src/features/widgets/components/widgetFilterColumns.ts b/web/src/features/widgets/components/widgetFilterColumns.ts
index 78462bd728..e5f3c3adcd 100644
--- a/web/src/features/widgets/components/widgetFilterColumns.ts
+++ b/web/src/features/widgets/components/widgetFilterColumns.ts
@@ -2,8 +2,8 @@ import {
type ColumnDefinition,
type SingleValueOption,
} from "@langfuse/shared";
-import { type views } from "@/src/features/query/types";
-import { type ViewVersion } from "@/src/features/query";
+import { type ViewVersion, type views } from "@langfuse/shared/query";
+
import { type z } from "zod";
type GetWidgetFilterColumnsParams = {
diff --git a/web/src/features/widgets/utils.ts b/web/src/features/widgets/utils.ts
index 148265c5fc..cc4831c80a 100644
--- a/web/src/features/widgets/utils.ts
+++ b/web/src/features/widgets/utils.ts
@@ -2,10 +2,10 @@ import startCase from "lodash/startCase";
import { type FilterState } from "@langfuse/shared";
import { type DashboardWidgetChartType } from "@langfuse/shared/src/db";
import {
- type ViewVersion,
- views,
getViewDeclaration,
-} from "@/src/features/query";
+ views,
+ type ViewVersion,
+} from "@langfuse/shared/query";
import { formatMetric } from "@/src/features/widgets/chart-library/utils";
import { type MetricFormatterFunction } from "@/src/features/widgets/chart-library/chart-props";
diff --git a/web/src/pages/api/dashboard/execute-query-stream.ts b/web/src/pages/api/dashboard/execute-query-stream.ts
index 5dc4930f22..f9c88c1979 100644
--- a/web/src/pages/api/dashboard/execute-query-stream.ts
+++ b/web/src/pages/api/dashboard/execute-query-stream.ts
@@ -13,13 +13,15 @@ import { logger } from "@langfuse/shared/src/server";
import { getServerAuthSession } from "@/src/server/auth";
import { sendAdminAccessWebhook } from "@/src/server/adminAccessWebhook";
import { prisma } from "@langfuse/shared/src/db";
-import { query as customQuery, viewVersions } from "@/src/features/query/types";
import {
prepareExecuteQuery,
toClickhouseQueryOpts,
+} from "@langfuse/shared/query/server";
+import {
+ query as customQuery,
validateQuery,
-} from "@/src/features/query/server/queryExecutor";
-
+ viewVersions,
+} from "@langfuse/shared/query";
export type SSEEvent =
| { type: "progress"; progress: object }
| { type: "row"; row: Record<string, unknown> }
diff --git a/web/src/pages/api/public/metrics/index.ts b/web/src/pages/api/public/metrics/index.ts
index 1ecf63dd91..eb08bbef7d 100644
--- a/web/src/pages/api/public/metrics/index.ts
+++ b/web/src/pages/api/public/metrics/index.ts
@@ -8,8 +8,7 @@ import {
GetMetricsV1Query,
GetMetricsV1Response,
} from "@/src/features/public-api/types/metrics";
-import { executeQuery } from "@/src/features/query/server/queryExecutor";
-
+import { executeQuery } from "@langfuse/shared/query/server";
export default withMiddlewares(
{
GET: createAuthedProjectAPIRoute({
diff --git a/web/src/pages/api/public/v2/metrics.ts b/web/src/pages/api/public/v2/metrics.ts
index 54e20d0ca3..d2fb00bbb7 100644
--- a/web/src/pages/api/public/v2/metrics.ts
+++ b/web/src/pages/api/public/v2/metrics.ts
@@ -7,11 +7,8 @@ import {
GetMetricsV2Response,
} from "@/src/features/public-api/types/metrics";
import { InvalidRequestError, LangfuseNotFoundError } from "@langfuse/shared";
-import {
- executeQuery,
- validateQuery,
-} from "@/src/features/query/server/queryExecutor";
-
+import { executeQuery } from "@langfuse/shared/query/server";
+import { validateQuery } from "@langfuse/shared/query";
const DEFAULT_ROW_LIMIT = 100;
export default withMiddlewares({
diff --git a/web/src/pages/project/[projectId]/index.tsx b/web/src/pages/project/[projectId]/index.tsx
index 9cb7d4c5ff..00e5f63abc 100644
--- a/web/src/pages/project/[projectId]/index.tsx
+++ b/web/src/pages/project/[projectId]/index.tsx
@@ -32,7 +32,7 @@ import {
useEnvironmentFilter,
} from "@/src/hooks/useEnvironmentFilter";
import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
-import { type ViewVersion } from "@/src/features/query";
+import { type ViewVersion } from "@langfuse/shared/query";
import { useEnvironmentFilterOptionsCache } from "@/src/hooks/use-environment-filter-options-cache";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
import {
diff --git a/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx b/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx
index 859a8cc9b0..b2e8eec0ec 100644
--- a/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx
+++ b/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx
@@ -5,7 +5,7 @@ import { WidgetForm } from "@/src/features/widgets/components/WidgetForm";
import { showErrorToast } from "@/src/features/notifications/showErrorToast";
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
import { type DashboardWidgetChartType } from "@langfuse/shared/src/db";
-import { type views, type metricAggregations } from "@/src/features/query";
+import { type metricAggregations, type views } from "@langfuse/shared/query";
import { type z } from "zod";
import { type WidgetChartConfig } from "@/src/features/widgets/utils";
diff --git a/web/src/pages/project/[projectId]/widgets/new.tsx b/web/src/pages/project/[projectId]/widgets/new.tsx
index 370e4e575f..56b89011da 100644
--- a/web/src/pages/project/[projectId]/widgets/new.tsx
+++ b/web/src/pages/project/[projectId]/widgets/new.tsx
@@ -5,10 +5,7 @@ import { type WidgetChartConfig, WidgetForm } from "@/src/features/widgets";
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
import { showErrorToast } from "@/src/features/notifications/showErrorToast";
import { type DashboardWidgetChartType } from "@langfuse/shared/src/db";
-import {
- type views,
- type metricAggregations,
-} from "@/src/features/query/types";
+import { type metricAggregations, type views } from "@langfuse/shared/query";
import { type z } from "zod";
import { SelectDashboardDialog } from "@/src/features/dashboard/components/SelectDashboardDialog";
import { useState } from "react";
diff --git a/web/src/server/api/routers/dashboardWidgets.ts b/web/src/server/api/routers/dashboardWidgets.ts
index fea174fad0..2a32f14fa4 100644
--- a/web/src/server/api/routers/dashboardWidgets.ts
+++ b/web/src/server/api/routers/dashboardWidgets.ts
@@ -16,12 +16,12 @@ import {
ChartConfigSchema,
} from "@langfuse/shared/src/server";
import {
- views,
getValidAggregationsForMeasureType,
-} from "@/src/features/query";
-import { getViewDeclaration } from "@/src/features/query/dataModel";
+ getViewDeclaration,
+ views,
+ type ViewVersion,
+} from "@langfuse/shared/query";
import { TRPCError } from "@trpc/server";
-import type { ViewVersion } from "@/src/features/query";
import { LangfuseConflictError } from "@langfuse/shared";
const CreateDashboardWidgetInput = z.object({