Skip to content

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

feat(api, mcp): Add dashboard & widget CRUD to Public API & MCP (unstable) (#15080)

Lysander Kiesel5633a79df1e5
diff --git a/fern/apis/server/definition/unstable/dashboard-widgets.yml b/fern/apis/server/definition/unstable/dashboard-widgets.yml
index 8a175b257d..d1e5b1cda7 100644
--- a/fern/apis/server/definition/unstable/dashboard-widgets.yml
+++ b/fern/apis/server/definition/unstable/dashboard-widgets.yml
@@ -1,19 +1,50 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
imports:
errors: ./errors.yml
+ pagination: ../utils/pagination.yml
service:
auth: true
base-path: /api/public/unstable
endpoints:
+ list:
+ docs: |
+ List dashboard widgets in the project, ordered by most recently
+ updated first.
+ method: GET
+ path: /dashboard-widgets
+ request:
+ name: ListDashboardWidgetsRequest
+ query-parameters:
+ page:
+ type: optional<integer>
+ docs: 1-based page number. Defaults to `1`.
+ limit:
+ type: optional<integer>
+ docs: Maximum number of items per page. Defaults to `50`.
+ response: DashboardWidgetList
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
create:
docs: |
- Create a reusable dashboard widget.
+ Create a dashboard widget (a standalone chart definition you place on
+ any dashboard).
- This endpoint creates the widget. It does not place the widget on a dashboard grid, this has to be done in the UI.
+ This endpoint creates the widget only; place it on a dashboard via
+ `POST /dashboards/{dashboardId}/placements`.
Supported views are `observations`, `scores-numeric`, and `scores-categorical`.
- The legacy `traces` view is not supported by this unstable API, `minVersion` defaults to `2`; values below `2` are rejected.
+ The legacy `traces` view is not supported by this unstable API.
+ Widgets are created as v2 internally.
+
+ `chartConfig` is optional and defaults to the plain config for
+ `chartType`; when `chartConfig.type` is given it must match
+ `chartType`.
Unstable API note:
- This surface may evolve while dashboard/widget APIs are being finalized.
@@ -42,9 +73,7 @@ service:
filters: []
chartType: HORIZONTAL_BAR
chartConfig:
- type: HORIZONTAL_BAR
row_limit: 10
- minVersion: 2
response:
body:
id: cm_dashboard_widget_123
@@ -63,7 +92,63 @@ service:
chartConfig:
type: HORIZONTAL_BAR
row_limit: 10
- minVersion: 2
+ get:
+ docs: Get a dashboard widget by id.
+ method: GET
+ path: /dashboard-widgets/{widgetId}
+ path-parameters:
+ widgetId: string
+ response: DashboardWidget
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ update:
+ docs: |
+ Update a dashboard widget.
+
+ All fields are optional; at least one field is required.
+ Changing `chartType` without sending `chartConfig` resets the config
+ to the new chart type's defaults. When `chartConfig.type` is given
+ it must match the widget's (possibly updated) `chartType`.
+ method: PATCH
+ path: /dashboard-widgets/{widgetId}
+ path-parameters:
+ widgetId: string
+ request: UpdateDashboardWidgetRequest
+ response: DashboardWidget
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ delete:
+ docs: |
+ Delete a dashboard widget.
+
+ The API returns `409` while the widget is still placed on a dashboard.
+ Remove those placements first.
+ method: DELETE
+ path: /dashboard-widgets/{widgetId}
+ path-parameters:
+ widgetId: string
+ response: DeleteDashboardWidgetResponse
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.ConflictError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
types:
DashboardWidgetView:
@@ -115,10 +200,22 @@ types:
DashboardWidgetFilter:
docs: |
- A dashboard widget filter in Langfuse filter-state shape.
+ A filter in Langfuse filter-state shape. The `value` shape and the
+ allowed operators depend on `type`:
- Filter shapes depend on `type`, for example string filters use a string `value`,
- option filters use a list of strings, and object filters include `key`.
+ | `type` | `value` | operators |
+ |---|---|---|
+ | `string` | string | `=`, `contains`, `does not contain`, `starts with`, `ends with` |
+ | `number` | number | `=`, `>`, `<`, `>=`, `<=` |
+ | `datetime` | ISO datetime string | `>`, `<`, `>=`, `<=` |
+ | `boolean` | boolean | `=`, `<>` |
+ | `null` | `""` | `is null`, `is not null` |
+ | `stringOptions` | list of strings | `any of`, `none of` |
+ | `arrayOptions` | list of strings | `any of`, `none of`, `all of` |
+ | `categoryOptions` | list of strings (requires `key`) | `any of`, `none of` |
+ | `stringObject` | string (requires `key`, e.g. a metadata key) | same as `string` |
+ | `numberObject` | number (requires `key`, e.g. a score name) | same as `number` |
+ | `booleanObject` | boolean (requires `key`) | `=`, `<>` |
properties:
column:
type: string
@@ -163,12 +260,29 @@ types:
- ASC
- DESC
+ DashboardWidgetChartConfigInput:
+ docs: |
+ Input-side chart config. `type` is optional and defaults to the
+ widget's `chartType`; when given it must match.
+ properties:
+ type:
+ type: optional<DashboardWidgetChartType>
+ row_limit:
+ type: optional<integer>
+ show_value_labels:
+ type: optional<boolean>
+ bins:
+ type: optional<integer>
+ defaultSort:
+ type: optional<DashboardWidgetDefaultSort>
+
CreateDashboardWidgetRequest:
properties:
name:
type: string
description:
- type: string
+ type: optional<string>
+ docs: Defaults to an empty string.
view:
type: DashboardWidgetView
dimensions:
@@ -180,9 +294,39 @@ types:
chartType:
type: DashboardWidgetChartType
chartConfig:
- type: DashboardWidgetChartConfig
- minVersion:
- type: optional<integer>
+ type: optional<DashboardWidgetChartConfigInput>
+ docs: Defaults to the plain config for `chartType`.
+
+ UpdateDashboardWidgetRequest:
+ properties:
+ name:
+ type: optional<string>
+ description:
+ type: optional<string>
+ view:
+ type: optional<DashboardWidgetView>
+ dimensions:
+ type: optional<list<DashboardWidgetDimension>>
+ metrics:
+ type: optional<list<DashboardWidgetMetric>>
+ filters:
+ type: optional<list<DashboardWidgetFilter>>
+ chartType:
+ type: optional<DashboardWidgetChartType>
+ chartConfig:
+ type: optional<DashboardWidgetChartConfigInput>
+
+ DashboardWidgetList:
+ properties:
+ data:
+ type: list<DashboardWidget>
+ meta:
+ type: pagination.MetaResponse
+
+ DeleteDashboardWidgetResponse:
+ properties:
+ message:
+ type: string
DashboardWidget:
properties:
@@ -208,5 +352,3 @@ types:
type: DashboardWidgetChartType
chartConfig:
type: DashboardWidgetChartConfig
- minVersion:
- type: integer
diff --git a/fern/apis/server/definition/unstable/dashboards.yml b/fern/apis/server/definition/unstable/dashboards.yml
new file mode 100644
index 0000000000..e244d6cff5
--- /dev/null
+++ b/fern/apis/server/definition/unstable/dashboards.yml
@@ -0,0 +1,281 @@
+# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
+imports:
+ errors: ./errors.yml
+ pagination: ../utils/pagination.yml
+ dashboardWidgets: ./dashboard-widgets.yml
+
+service:
+ auth: true
+ base-path: /api/public/unstable
+ endpoints:
+ list:
+ docs: |
+ List dashboards in the project, ordered by most recently updated
+ first.
+ method: GET
+ path: /dashboards
+ request:
+ name: ListDashboardsRequest
+ query-parameters:
+ page:
+ type: optional<integer>
+ docs: 1-based page number. Defaults to `1`.
+ limit:
+ type: optional<integer>
+ docs: Maximum number of items per page. Defaults to `50`.
+ response: DashboardList
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ create:
+ docs: Create a dashboard.
+ method: POST
+ path: /dashboards
+ request: CreateDashboardRequest
+ response: Dashboard
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ get:
+ docs: Get a dashboard by id.
+ method: GET
+ path: /dashboards/{dashboardId}
+ path-parameters:
+ dashboardId: string
+ response: Dashboard
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ update:
+ docs: Update a dashboard's name, description, definition, or filters.
+ method: PATCH
+ path: /dashboards/{dashboardId}
+ path-parameters:
+ dashboardId: string
+ request: UpdateDashboardRequest
+ response: Dashboard
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ delete:
+ docs: Delete a dashboard.
+ method: DELETE
+ path: /dashboards/{dashboardId}
+ path-parameters:
+ dashboardId: string
+ response: DeleteDashboardResponse
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ addPlacement:
+ docs: |
+ Add a placement to a dashboard grid (see `DashboardPlacement` for
+ grid semantics).
+
+ `id` and the position fields are optional: when omitted, the
+ placement gets a server-generated id and is appended below all
+ existing tiles as a 6x6 tile. Returns the created placement.
+
+ The referenced widget must exist in the same project or be a
+ Langfuse-managed widget. The API returns `409` if a placement with
+ the same `id` already exists on the dashboard.
+ method: POST
+ path: /dashboards/{dashboardId}/placements
+ path-parameters:
+ dashboardId: string
+ request: CreateDashboardPlacementRequest
+ response: DashboardPlacement
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.ConflictError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ updatePlacement:
+ docs: |
+ Move or resize a placement. All fields are optional; at least one is
+ required. Omitted fields keep their current value. The placement's
+ content (widget/preset reference) and id cannot change — delete and
+ re-add the placement to swap content. Returns the updated placement.
+ method: PATCH
+ path: /dashboards/{dashboardId}/placements/{placementId}
+ path-parameters:
+ dashboardId: string
+ placementId: string
+ request: UpdateDashboardPlacementRequest
+ response: DashboardPlacement
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+ deletePlacement:
+ docs: Remove a placement from a dashboard grid without deleting the referenced widget.
+ method: DELETE
+ path: /dashboards/{dashboardId}/placements/{placementId}
+ path-parameters:
+ dashboardId: string
+ placementId: string
+ response: DeleteDashboardPlacementResponse
+ errors:
+ - errors.BadRequestError
+ - errors.UnauthorizedError
+ - errors.AccessDeniedError
+ - errors.NotFoundError
+ - errors.MethodNotAllowedError
+ - errors.TooManyRequestsError
+ - errors.InternalServerError
+
+types:
+ DashboardPlacement:
+ docs: |
+ A tile on the dashboard's 12-column grid. `x`/`y` are the tile's
+ top-left cell (0-based; `y` grows downward), `width`/`height` its size
+ in cells. The UI default tile is 6x6 (half width). Overlapping tiles
+ are not rejected; prefer appending below existing tiles (or omit the
+ position on create to let the server do it).
+ discriminant: type
+ union:
+ widget:
+ type: WidgetPlacement
+ preset:
+ type: PresetPlacement
+ WidgetPlacement:
+ properties:
+ id: string
+ widgetId: string
+ x: integer
+ y: integer
+ width: integer
+ height: integer
+ PresetPlacement:
+ properties:
+ id: string
+ presetId: string
+ x: integer
+ y: integer
+ width: integer
+ height: integer
+ CreateDashboardPlacementRequest:
+ discriminant: type
+ union:
+ widget:
+ type: CreateWidgetPlacement
+ preset:
+ type: CreatePresetPlacement
+ CreateWidgetPlacement:
+ properties:
+ id:
+ type: optional<string>
+ docs: Server-generated when omitted.
+ widgetId: string
+ x:
+ type: optional<integer>
+ docs: Grid column (12-column grid). Defaults to `0`.
+ y:
+ type: optional<integer>
+ docs: Grid row. Defaults to the first row below all existing tiles.
+ width:
+ type: optional<integer>
+ docs: Width in grid columns. Defaults to `6`.
+ height:
+ type: optional<integer>
+ docs: Height in grid rows. Defaults to `6`.
+ CreatePresetPlacement:
+ properties:
+ id:
+ type: optional<string>
+ docs: Server-generated when omitted.
+ presetId: string
+ x:
+ type: optional<integer>
+ docs: Grid column (12-column grid). Defaults to `0`.
+ y:
+ type: optional<integer>
+ docs: Grid row. Defaults to the first row below all existing tiles.
+ width:
+ type: optional<integer>
+ docs: Width in grid columns. Defaults to `6`.
+ height:
+ type: optional<integer>
+ docs: Height in grid rows. Defaults to `6`.
+ UpdateDashboardPlacementRequest:
+ properties:
+ x:
+ type: optional<integer>
+ docs: Grid column (12-column grid).
+ y:
+ type: optional<integer>
+ docs: Grid row.
+ width:
+ type: optional<integer>
+ docs: Width in grid columns.
+ height:
+ type: optional<integer>
+ docs: Height in grid rows.
+ DeleteDashboardPlacementResponse:
+ properties:
+ message: string
+ DashboardDefinition:
+ properties:
+ widgets: list<DashboardPlacement>
+ Dashboard:
+ properties:
+ id: string
+ createdAt: datetime
+ updatedAt: datetime
+ name: string
+ description: string
+ definition: DashboardDefinition
+ filters:
+ type: list<dashboardWidgets.DashboardWidgetFilter>
+ docs: Dashboard-level filters applied to all widgets on the dashboard.
+ DashboardList:
+ properties:
+ data: list<Dashboard>
+ meta: pagination.MetaResponse
+ CreateDashboardRequest:
+ properties:
+ name: string
+ description: optional<string>
+ definition: optional<DashboardDefinition>
+ filters: optional<list<dashboardWidgets.DashboardWidgetFilter>>
+ UpdateDashboardRequest:
+ properties:
+ name: optional<string>
+ description: optional<string>
+ definition: optional<DashboardDefinition>
+ filters: optional<list<dashboardWidgets.DashboardWidgetFilter>>
+ DeleteDashboardResponse:
+ properties:
+ message: string
diff --git a/packages/shared/src/server/services/DashboardService/DashboardService.ts b/packages/shared/src/server/services/DashboardService/DashboardService.ts
index 7f4e1d214c..558e35c62e 100644
--- a/packages/shared/src/server/services/DashboardService/DashboardService.ts
+++ b/packages/shared/src/server/services/DashboardService/DashboardService.ts
@@ -26,17 +26,27 @@ export class DashboardService {
limit?: number;
page?: number;
orderBy?: OrderByState;
+ /** Include Langfuse-managed dashboards (projectId null). Defaults to true. */
+ includeLangfuseOwned?: boolean;
}): Promise<DashboardListResponse> {
- const { projectId, limit, page, orderBy } = props;
+ const {
+ projectId,
+ limit,
+ page,
+ orderBy,
+ includeLangfuseOwned = true,
+ } = props;
const skip = page && limit ? (page - 1) * limit : undefined;
const take = limit;
+ const where = includeLangfuseOwned
+ ? { OR: [{ projectId }, { projectId: null }] }
+ : { projectId };
+
const [dashboards, totalCount] = await Promise.all([
prisma.dashboard.findMany({
- where: {
- OR: [{ projectId }, { projectId: null }],
- },
+ where,
orderBy: orderBy
? [{ [orderBy.column]: orderBy.order.toLowerCase() }]
: [{ updatedAt: "desc" }],
@@ -44,9 +54,7 @@ export class DashboardService {
take,
}),
prisma.dashboard.count({
- where: {
- OR: [{ projectId }, { projectId: null }],
- },
+ where,
}),
]);
@@ -74,6 +82,7 @@ export class DashboardService {
initialDefinition: z.infer<typeof DashboardDefinitionSchema> = {
widgets: [],
},
+ filters?: z.infer<typeof singleFilter>[],
): Promise<DashboardDomain> {
const newDashboard = await prisma.dashboard.create({
data: {
@@ -83,6 +92,7 @@ export class DashboardService {
createdBy: userId,
updatedBy: userId,
definition: initialDefinition,
+ ...(filters !== undefined && { filters }),
},
});
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index 96da15dbfe..b0f05c7da0 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -6288,7 +6288,7 @@ paths:
[
{
- "type": string, // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
+ "type": string, // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "booleanObject", "boolean", "null"
"column": string, // Required. Column to filter on (see available columns below)
"operator": string, // Required. Operator based on type:
// - datetime: ">", "<", ">=", "<="
@@ -6299,10 +6299,11 @@ paths:
// - number: "=", ">", "<", ">=", "<="
// - stringObject: "=", "contains", "does not contain", "starts with", "ends with"
// - numberObject: "=", ">", "<", ">=", "<="
+ // - booleanObject: "=", "<>"
// - boolean: "=", "<>"
// - null: "is null", "is not null"
"value": any, // Required (except for null type). Value to compare against. Type depends on filter type
- "key": string // Required only for stringObject, numberObject, and categoryOptions types when filtering on nested fields like metadata
+ "key": string // Required only for stringObject, numberObject, booleanObject, and categoryOptions types when filtering on nested fields like metadata or score names
}
]
@@ -6387,6 +6388,12 @@ paths:
- `score_categories` (categoryOptions) - Categorical score values
+ - `score_booleans` (booleanObject) - Boolean score values. Use `key`
+ for the score name and a boolean `value`, e.g. `{"type":
+ "booleanObject", "column": "score_booleans", "key": "is_correct",
+ "operator": "=", "value": true}`. The `<>` operator also matches
+ traces without a score of that name.
+
## Filter Examples
@@ -6527,37 +6534,35 @@ paths:
required:
- traceIds
/api/public/unstable/dashboard-widgets:
- post:
- description: >-
- Create a reusable dashboard widget.
-
-
- This endpoint creates the widget. It does not place the widget on a
- dashboard grid, this has to be done in the UI.
-
-
- Supported views are `observations`, `scores-numeric`, and
- `scores-categorical`.
-
- The legacy `traces` view is not supported by this unstable API,
- `minVersion` defaults to `2`; values below `2` are rejected.
-
-
- Unstable API note:
-
- - This surface may evolve while dashboard/widget APIs are being
- finalized.
- operationId: unstable_dashboardWidgets_create
+ get:
+ description: |-
+ List dashboard widgets in the project, ordered by most recently
+ updated first.
+ operationId: unstable_dashboardWidgets_list
tags:
- UnstableDashboardWidgets
- parameters: []
+ parameters:
+ - name: page
+ in: query
+ description: 1-based page number. Defaults to `1`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ - name: limit
+ in: query
+ description: Maximum number of items per page. Defaults to `50`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
responses:
'200':
description: ''
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableDashboardWidget'
+ $ref: '#/components/schemas/unstableDashboardWidgetList'
'400':
description: ''
content:
@@ -6596,106 +6601,40 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- requestBody:
- required: true
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/unstableCreateDashboardWidgetRequest'
- /api/public/unstable/evaluation-rules:
post:
description: >-
- Create an evaluation rule.
-
-
- An evaluation rule defines **what** incoming data should be evaluated
- and **how prompt variables should be populated** from that data.
-
-
- Use this resource after choosing an evaluator from the evaluator
- endpoints.
-
-
- Key rules:
-
- - `name` must be unique within the project for public evaluation rules
-
- - `target` must be `observation` or `experiment`
-
- - `evaluator.name` + `evaluator.scope` must identify an existing
- evaluator family returned by the evaluator endpoints
+ Create a dashboard widget (a standalone chart definition you place on
- - Langfuse resolves that family to its latest version before saving the
- evaluation rule
-
- - for `target=experiment`, use dataset `id` values from `GET
- /api/public/v2/datasets` when filtering by `datasetId`
-
- - for `llm_as_judge` evaluators, every evaluator prompt variable must be
- mapped exactly once
-
- - for `code` evaluators, Langfuse uses the fixed code runtime mapping;
- omit `mapping` in create and update requests
-
- - for user-provided `llm_as_judge` mappings, `expected_output` and
- `experiment_item_metadata` are only valid for `target=experiment`
-
- - if `enabled=true`, Langfuse validates that the referenced evaluator
- can currently run
-
- - at most 50 evaluation rules can be effectively active in one project
- at the same time
-
-
- If an evaluation rule with the same `name` already exists in the
- project, the API returns `409`.
-
- In that case, update the existing resource with `PATCH
- /api/public/unstable/evaluation-rules/{evaluationRuleId}` instead of
- creating a second one.
-
-
- If enabling this resource would exceed the 50-active limit, the API also
- returns `409`.
+ any dashboard).
- In that case, disable or pause another active evaluation rule before
- enabling a new one.
+ This endpoint creates the widget only; place it on a dashboard via
- Current scope:
+ `POST /dashboards/{dashboardId}/placements`.
- - evaluation rules are live-ingestion rules only
- - they do not trigger historical backfills
+ Supported views are `observations`, `scores-numeric`, and
+ `scores-categorical`.
+ The legacy `traces` view is not supported by this unstable API.
- Recovery guidance:
+ Widgets are created as v2 internally.
- - `400 invalid_filter_value`: fix the filter `column` or `value` using
- `details.column`, `details.invalidValues`, and `details.allowedValues`
- - `400 invalid_filter_value` with `details.column=datasetId`: call `GET
- /api/public/v2/datasets`, then retry with dataset `id` values from that
- response
+ `chartConfig` is optional and defaults to the plain config for
- - `400 missing_variable_mapping`: for `llm_as_judge` evaluators, fetch
- the evaluator again and make sure every variable in `variables` appears
- exactly once in `mapping`
+ `chartType`; when `chartConfig.type` is given it must match
- - `400 duplicate_variable_mapping`: remove repeated mappings for the
- same variable
+ `chartType`.
- - `400 invalid_variable_mapping`: for `llm_as_judge`, switch to a valid
- `source` for the selected `target`, or fix the variable name
- - `400 invalid_json_path`: remove or correct the `jsonPath`
+ Unstable API note:
- - `422 evaluator_preflight_failed`: the selected evaluator cannot run
- with the resolved model configuration. Fix the evaluator/default model
- setup, then retry the create request.
- operationId: unstable_evaluationRules_create
+ - This surface may evolve while dashboard/widget APIs are being
+ finalized.
+ operationId: unstable_dashboardWidgets_create
tags:
- - UnstableEvaluationRules
+ - UnstableDashboardWidgets
parameters: []
responses:
'200':
@@ -6703,7 +6642,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluationRule'
+ $ref: '#/components/schemas/unstableDashboardWidget'
'400':
description: ''
content:
@@ -6729,18 +6668,6 @@ paths:
content:
application/json:
schema: {}
- '409':
- description: ''
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/unstablePublicApiError'
- '422':
- description: ''
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/unstablePublicApiError'
'429':
description: ''
content:
@@ -6759,39 +6686,26 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableCreateEvaluationRuleRequest'
+ $ref: '#/components/schemas/unstableCreateDashboardWidgetRequest'
+ /api/public/unstable/dashboard-widgets/{widgetId}:
get:
- description: >-
- List evaluation rules in the authenticated project.
-
-
- Each item describes one live evaluation rule and its effective runtime
- status.
- operationId: unstable_evaluationRules_list
+ description: Get a dashboard widget by id.
+ operationId: unstable_dashboardWidgets_get
tags:
- - UnstableEvaluationRules
+ - UnstableDashboardWidgets
parameters:
- - name: page
- in: query
- description: 1-based page number. Defaults to `1`.
- required: false
- schema:
- type: integer
- nullable: true
- - name: limit
- in: query
- description: Maximum number of items per page. Defaults to `50`.
- required: false
+ - name: widgetId
+ in: path
+ required: true
schema:
- type: integer
- nullable: true
+ type: string
responses:
'200':
description: ''
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluationRules'
+ $ref: '#/components/schemas/unstableDashboardWidget'
'400':
description: ''
content:
@@ -6830,23 +6744,20 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- /api/public/unstable/evaluation-rules/{evaluationRuleId}:
- get:
- description: >-
- Get one evaluation rule by its identifier.
-
+ patch:
+ description: |-
+ Update a dashboard widget.
- Use this endpoint to inspect the current evaluator, target, mapping,
- filters, and effective runtime status.
- operationId: unstable_evaluationRules_get
+ All fields are optional; at least one field is required.
+ Changing `chartType` without sending `chartConfig` resets the config
+ to the new chart type's defaults. When `chartConfig.type` is given
+ it must match the widget's (possibly updated) `chartType`.
+ operationId: unstable_dashboardWidgets_update
tags:
- - UnstableEvaluationRules
+ - UnstableDashboardWidgets
parameters:
- - name: evaluationRuleId
+ - name: widgetId
in: path
- description: >-
- Evaluation rule identifier returned by the evaluation rule
- endpoints.
required: true
schema:
type: string
@@ -6856,7 +6767,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluationRule'
+ $ref: '#/components/schemas/unstableDashboardWidget'
'400':
description: ''
content:
@@ -6895,64 +6806,24 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- patch:
- description: >-
- Update an evaluation rule.
-
-
- Typical uses:
-
- - enable or disable live execution
-
- - switch to another evaluator
-
- - adjust sampling
-
- - change filters
-
- - update LLM-as-judge variable mappings
-
-
- Important behavior:
-
- - provide only the fields you want to change
-
- - if you provide `evaluator`, Langfuse resolves that evaluator family to
- its latest version before saving
-
- - changing `target`, `filter`, or an LLM-as-judge `mapping` must still
- produce a valid target-specific configuration
-
- - if you change `target` for an LLM-as-judge rule, also send a
- compatible `filter` and `mapping` in the same request unless the
- existing ones are still valid for the new target
-
- - for `code` evaluator rules, omit `mapping`; Langfuse stores the fixed
- code runtime mapping automatically
-
- - if the resulting config is enabled, Langfuse re-validates that the
- selected evaluator can run
-
- - if the update would move a non-active evaluation rule into the active
- state and the project already has 50 active evaluation rules, the API
- returns `409`
-
-
- Recovery guidance:
-
- - if an LLM-as-judge update fails with `missing_variable_mapping` or
- `invalid_variable_mapping` after changing `evaluator` or `target`,
- resend the request with a complete new `mapping`
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableUpdateDashboardWidgetRequest'
+ delete:
+ description: |-
+ Delete a dashboard widget.
- - if the update fails with `invalid_filter_value` after changing
- `target`, resend the request with a target-compatible `filter`
- operationId: unstable_evaluationRules_update
+ The API returns `409` while the widget is still placed on a dashboard.
+ Remove those placements first.
+ operationId: unstable_dashboardWidgets_delete
tags:
- - UnstableEvaluationRules
+ - UnstableDashboardWidgets
parameters:
- - name: evaluationRuleId
+ - name: widgetId
in: path
- description: Evaluation rule identifier.
required: true
schema:
type: string
@@ -6962,7 +6833,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluationRule'
+ $ref: '#/components/schemas/unstableDeleteDashboardWidgetResponse'
'400':
description: ''
content:
@@ -6988,7 +6859,7 @@ paths:
content:
application/json:
schema: {}
- '422':
+ '409':
description: ''
content:
application/json:
@@ -7007,36 +6878,36 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- requestBody:
- required: true
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/unstableUpdateEvaluationRuleRequest'
- delete:
- description: >-
- Delete an evaluation rule.
-
-
- This removes the live-ingestion rule only. It does not delete the
- referenced evaluator.
- operationId: unstable_evaluationRules_delete
+ /api/public/unstable/dashboards:
+ get:
+ description: |-
+ List dashboards in the project, ordered by most recently updated
+ first.
+ operationId: unstable_dashboards_list
tags:
- - UnstableEvaluationRules
+ - UnstableDashboards
parameters:
- - name: evaluationRuleId
- in: path
- description: Evaluation rule identifier.
- required: true
+ - name: page
+ in: query
+ description: 1-based page number. Defaults to `1`.
+ required: false
schema:
- type: string
+ type: integer
+ nullable: true
+ - name: limit
+ in: query
+ description: Maximum number of items per page. Defaults to `50`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
responses:
'200':
description: ''
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableDeleteEvaluationRuleResponse'
+ $ref: '#/components/schemas/unstableDashboardList'
'400':
description: ''
content:
@@ -7075,84 +6946,11 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- /api/public/unstable/evaluators:
post:
- description: >-
- Create an evaluator in the authenticated project.
-
-
- Use evaluators to define **how** Langfuse should score data.
-
- LLM-as-a-judge evaluators define a prompt, expected structured output,
- and optional model configuration.
-
- Code evaluators define source code and a runtime language.
-
-
- Naming behavior:
-
- - If this is a new evaluator name in your project, Langfuse creates
- version `1`.
-
- - If the name already exists in your project, Langfuse creates the next
- version and returns it.
-
- - When a new project version is created, existing evaluation rules in
- that project automatically move to the newest version for that evaluator
- name.
-
-
- Recommended workflow:
-
- 1. Create the evaluator.
-
- 2. Read the returned `variables` array.
-
- 3. Read the returned `outputDefinition.dataType` so the client knows
- whether future scores will be numeric, boolean, or categorical.
-
- 4. Create one or more evaluation rules that reference the returned
- evaluator family using `name` and `scope`.
-
-
- Code evaluator validation:
-
- - At creation, Langfuse only validates the request shape
-
- - The `sourceCode` itself is not executed here. It is first run
- (preflight-tested against a sample observation) when you link the
- evaluator to an evaluation rule, so runtime errors in the code surface
- at evaluation-rule creation, not at evaluator creation.
-
-
- Recovery guidance:
-
- - `422` with `code=evaluator_preflight_failed`: the evaluator cannot run
- with the resolved model configuration. Add a valid explicit
- `modelConfig`, or configure the project's default evaluation model, then
- retry the same request.
-
- - `400` with `code=invalid_body`: the request shape is malformed. Use
- the structured `details.issues` array to fix the specific fields and
- retry.
-
- - `400` with `code=invalid_body` on `outputDefinition`: for
- `type=llm_as_judge`, send `dataType`, `reasoning.description`, and
- `score.description`. Do not send `version`; it is not part of the public
- request shape.
-
- - If `type` is omitted, Langfuse treats the request as
- `type=llm_as_judge` for backwards compatibility. New clients should send
- `type` explicitly.
-
-
- Unstable API note:
-
- - This surface may evolve while the underlying evaluation data model is
- being redesigned.
- operationId: unstable_evaluators_create
+ description: Create a dashboard.
+ operationId: unstable_dashboards_create
tags:
- - UnstableEvaluators
+ - UnstableDashboards
parameters: []
responses:
'200':
@@ -7160,7 +6958,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluator'
+ $ref: '#/components/schemas/unstableDashboard'
'400':
description: ''
content:
@@ -7186,18 +6984,69 @@ paths:
content:
application/json:
schema: {}
- '409':
+ '429':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
- '422':
+ '500':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableCreateDashboardRequest'
+ /api/public/unstable/dashboards/{dashboardId}:
+ get:
+ description: Get a dashboard by id.
+ operationId: unstable_dashboards_get
+ tags:
+ - UnstableDashboards
+ parameters:
+ - name: dashboardId
+ in: path
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableDashboard'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
'429':
description: ''
content:
@@ -7211,51 +7060,24 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- requestBody:
- required: true
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/unstableCreateEvaluatorRequest'
- get:
- description: >-
- List the evaluators available to the authenticated project.
-
-
- Important behavior:
-
- - This endpoint returns the latest version of each available evaluator.
-
- - Results can include evaluators from your project and Langfuse-managed
- evaluators.
-
- - If the same evaluator name exists in both places, both are returned as
- separate items with different `scope` values.
- operationId: unstable_evaluators_list
+ patch:
+ description: Update a dashboard's name, description, definition, or filters.
+ operationId: unstable_dashboards_update
tags:
- - UnstableEvaluators
+ - UnstableDashboards
parameters:
- - name: page
- in: query
- description: 1-based page number. Defaults to `1`.
- required: false
- schema:
- type: integer
- nullable: true
- - name: limit
- in: query
- description: Maximum number of items per page. Defaults to `50`.
- required: false
+ - name: dashboardId
+ in: path
+ required: true
schema:
- type: integer
- nullable: true
+ type: string
responses:
'200':
description: ''
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluators'
+ $ref: '#/components/schemas/unstableDashboard'
'400':
description: ''
content:
@@ -7294,22 +7116,20 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- /api/public/unstable/evaluators/{evaluatorId}:
- get:
- description: >-
- Get one evaluator by `id`.
-
-
- Use this endpoint when you want the prompt, output definition, model
- configuration, and derived variables for the evaluator you plan to use
- in an evaluation rule.
- operationId: unstable_evaluators_get
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableUpdateDashboardRequest'
+ delete:
+ description: Delete a dashboard.
+ operationId: unstable_dashboards_delete
tags:
- - UnstableEvaluators
+ - UnstableDashboards
parameters:
- - name: evaluatorId
+ - name: dashboardId
in: path
- description: Evaluator identifier returned by the evaluator endpoints.
required: true
schema:
type: string
@@ -7319,7 +7139,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableEvaluator'
+ $ref: '#/components/schemas/unstableDeleteDashboardResponse'
'400':
description: ''
content:
@@ -7358,30 +7178,25 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
- delete:
- description: >-
- Delete an evaluator.
-
-
- Important behavior:
-
- - This deletes the evaluator including all of its stored versions;
- `evaluatorId` may reference any version.
-
- - The API returns `409` while evaluation rules still reference the
- evaluator. Delete those evaluation rules first.
+ /api/public/unstable/dashboards/{dashboardId}/placements:
+ post:
+ description: |-
+ Add a placement to a dashboard grid (see `DashboardPlacement` for
+ grid semantics).
- - Langfuse-managed evaluators (`scope=managed`) cannot be deleted; the
- API returns `403`.
+ `id` and the position fields are optional: when omitted, the
+ placement gets a server-generated id and is appended below all
+ existing tiles as a 6x6 tile. Returns the created placement.
- - Scores already produced by the evaluator are not deleted.
- operationId: unstable_evaluators_delete
+ The referenced widget must exist in the same project or be a
+ Langfuse-managed widget. The API returns `409` if a placement with
+ the same `id` already exists on the dashboard.
+ operationId: unstable_dashboards_addPlacement
tags:
- - UnstableEvaluators
+ - UnstableDashboards
parameters:
- - name: evaluatorId
+ - name: dashboardId
in: path
- description: Evaluator identifier returned by the evaluator endpoints.
required: true
schema:
type: string
@@ -7391,7 +7206,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/unstableDeleteEvaluatorResponse'
+ $ref: '#/components/schemas/unstableDashboardPlacement'
'400':
description: ''
content:
@@ -7436,22 +7251,997 @@ paths:
schema:
$ref: '#/components/schemas/unstablePublicApiError'
security: *ref_0
-components:
- schemas:
- AnnotationQueueStatus:
- title: AnnotationQueueStatus
- type: string
- enum:
- - PENDING
- - COMPLETED
- AnnotationQueueObjectType:
- title: AnnotationQueueObjectType
- type: string
- enum:
- - TRACE
- - OBSERVATION
- - SESSION
- AnnotationQueue:
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableCreateDashboardPlacementRequest'
+ /api/public/unstable/dashboards/{dashboardId}/placements/{placementId}:
+ patch:
+ description: |-
+ Move or resize a placement. All fields are optional; at least one is
+ required. Omitted fields keep their current value. The placement's
+ content (widget/preset reference) and id cannot change — delete and
+ re-add the placement to swap content. Returns the updated placement.
+ operationId: unstable_dashboards_updatePlacement
+ tags:
+ - UnstableDashboards
+ parameters:
+ - name: dashboardId
+ in: path
+ required: true
+ schema:
+ type: string
+ - name: placementId
+ in: path
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableDashboardPlacement'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableUpdateDashboardPlacementRequest'
+ delete:
+ description: >-
+ Remove a placement from a dashboard grid without deleting the referenced
+ widget.
+ operationId: unstable_dashboards_deletePlacement
+ tags:
+ - UnstableDashboards
+ parameters:
+ - name: dashboardId
+ in: path
+ required: true
+ schema:
+ type: string
+ - name: placementId
+ in: path
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableDeleteDashboardPlacementResponse'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ /api/public/unstable/evaluation-rules:
+ post:
+ description: >-
+ Create an evaluation rule.
+
+
+ An evaluation rule defines **what** incoming data should be evaluated
+ and **how prompt variables should be populated** from that data.
+
+
+ Use this resource after choosing an evaluator from the evaluator
+ endpoints.
+
+
+ Key rules:
+
+ - `name` must be unique within the project for public evaluation rules
+
+ - `target` must be `observation` or `experiment`
+
+ - `evaluator.name` + `evaluator.scope` must identify an existing
+ evaluator family returned by the evaluator endpoints
+
+ - Langfuse resolves that family to its latest version before saving the
+ evaluation rule
+
+ - for `target=experiment`, use dataset `id` values from `GET
+ /api/public/v2/datasets` when filtering by `datasetId`
+
+ - for `llm_as_judge` evaluators, every evaluator prompt variable must be
+ mapped exactly once
+
+ - for `code` evaluators, Langfuse uses the fixed code runtime mapping;
+ omit `mapping` in create and update requests
+
+ - for user-provided `llm_as_judge` mappings, `expected_output` and
+ `experiment_item_metadata` are only valid for `target=experiment`
+
+ - if `enabled=true`, Langfuse validates that the referenced evaluator
+ can currently run
+
+ - at most 50 evaluation rules can be effectively active in one project
+ at the same time
+
+
+ If an evaluation rule with the same `name` already exists in the
+ project, the API returns `409`.
+
+ In that case, update the existing resource with `PATCH
+ /api/public/unstable/evaluation-rules/{evaluationRuleId}` instead of
+ creating a second one.
+
+
+ If enabling this resource would exceed the 50-active limit, the API also
+ returns `409`.
+
+ In that case, disable or pause another active evaluation rule before
+ enabling a new one.
+
+
+ Current scope:
+
+ - evaluation rules are live-ingestion rules only
+
+ - they do not trigger historical backfills
+
+
+ Recovery guidance:
+
+ - `400 invalid_filter_value`: fix the filter `column` or `value` using
+ `details.column`, `details.invalidValues`, and `details.allowedValues`
+
+ - `400 invalid_filter_value` with `details.column=datasetId`: call `GET
+ /api/public/v2/datasets`, then retry with dataset `id` values from that
+ response
+
+ - `400 missing_variable_mapping`: for `llm_as_judge` evaluators, fetch
+ the evaluator again and make sure every variable in `variables` appears
+ exactly once in `mapping`
+
+ - `400 duplicate_variable_mapping`: remove repeated mappings for the
+ same variable
+
+ - `400 invalid_variable_mapping`: for `llm_as_judge`, switch to a valid
+ `source` for the selected `target`, or fix the variable name
+
+ - `400 invalid_json_path`: remove or correct the `jsonPath`
+
+ - `422 evaluator_preflight_failed`: the selected evaluator cannot run
+ with the resolved model configuration. Fix the evaluator/default model
+ setup, then retry the create request.
+ operationId: unstable_evaluationRules_create
+ tags:
+ - UnstableEvaluationRules
+ parameters: []
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluationRule'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '409':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '422':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableCreateEvaluationRuleRequest'
+ get:
+ description: >-
+ List evaluation rules in the authenticated project.
+
+
+ Each item describes one live evaluation rule and its effective runtime
+ status.
+ operationId: unstable_evaluationRules_list
+ tags:
+ - UnstableEvaluationRules
+ parameters:
+ - name: page
+ in: query
+ description: 1-based page number. Defaults to `1`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ - name: limit
+ in: query
+ description: Maximum number of items per page. Defaults to `50`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluationRules'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ /api/public/unstable/evaluation-rules/{evaluationRuleId}:
+ get:
+ description: >-
+ Get one evaluation rule by its identifier.
+
+
+ Use this endpoint to inspect the current evaluator, target, mapping,
+ filters, and effective runtime status.
+ operationId: unstable_evaluationRules_get
+ tags:
+ - UnstableEvaluationRules
+ parameters:
+ - name: evaluationRuleId
+ in: path
+ description: >-
+ Evaluation rule identifier returned by the evaluation rule
+ endpoints.
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluationRule'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ patch:
+ description: >-
+ Update an evaluation rule.
+
+
+ Typical uses:
+
+ - enable or disable live execution
+
+ - switch to another evaluator
+
+ - adjust sampling
+
+ - change filters
+
+ - update LLM-as-judge variable mappings
+
+
+ Important behavior:
+
+ - provide only the fields you want to change
+
+ - if you provide `evaluator`, Langfuse resolves that evaluator family to
+ its latest version before saving
+
+ - changing `target`, `filter`, or an LLM-as-judge `mapping` must still
+ produce a valid target-specific configuration
+
+ - if you change `target` for an LLM-as-judge rule, also send a
+ compatible `filter` and `mapping` in the same request unless the
+ existing ones are still valid for the new target
+
+ - for `code` evaluator rules, omit `mapping`; Langfuse stores the fixed
+ code runtime mapping automatically
+
+ - if the resulting config is enabled, Langfuse re-validates that the
+ selected evaluator can run
+
+ - if the update would move a non-active evaluation rule into the active
+ state and the project already has 50 active evaluation rules, the API
+ returns `409`
+
+
+ Recovery guidance:
+
+ - if an LLM-as-judge update fails with `missing_variable_mapping` or
+ `invalid_variable_mapping` after changing `evaluator` or `target`,
+ resend the request with a complete new `mapping`
+
+ - if the update fails with `invalid_filter_value` after changing
+ `target`, resend the request with a target-compatible `filter`
+ operationId: unstable_evaluationRules_update
+ tags:
+ - UnstableEvaluationRules
+ parameters:
+ - name: evaluationRuleId
+ in: path
+ description: Evaluation rule identifier.
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluationRule'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '422':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableUpdateEvaluationRuleRequest'
+ delete:
+ description: >-
+ Delete an evaluation rule.
+
+
+ This removes the live-ingestion rule only. It does not delete the
+ referenced evaluator.
+ operationId: unstable_evaluationRules_delete
+ tags:
+ - UnstableEvaluationRules
+ parameters:
+ - name: evaluationRuleId
+ in: path
+ description: Evaluation rule identifier.
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableDeleteEvaluationRuleResponse'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ /api/public/unstable/evaluators:
+ post:
+ description: >-
+ Create an evaluator in the authenticated project.
+
+
+ Use evaluators to define **how** Langfuse should score data.
+
+ LLM-as-a-judge evaluators define a prompt, expected structured output,
+ and optional model configuration.
+
+ Code evaluators define source code and a runtime language.
+
+
+ Naming behavior:
+
+ - If this is a new evaluator name in your project, Langfuse creates
+ version `1`.
+
+ - If the name already exists in your project, Langfuse creates the next
+ version and returns it.
+
+ - When a new project version is created, existing evaluation rules in
+ that project automatically move to the newest version for that evaluator
+ name.
+
+
+ Recommended workflow:
+
+ 1. Create the evaluator.
+
+ 2. Read the returned `variables` array.
+
+ 3. Read the returned `outputDefinition.dataType` so the client knows
+ whether future scores will be numeric, boolean, or categorical.
+
+ 4. Create one or more evaluation rules that reference the returned
+ evaluator family using `name` and `scope`.
+
+
+ Code evaluator validation:
+
+ - At creation, Langfuse only validates the request shape
+
+ - The `sourceCode` itself is not executed here. It is first run
+ (preflight-tested against a sample observation) when you link the
+ evaluator to an evaluation rule, so runtime errors in the code surface
+ at evaluation-rule creation, not at evaluator creation.
+
+
+ Recovery guidance:
+
+ - `422` with `code=evaluator_preflight_failed`: the evaluator cannot run
+ with the resolved model configuration. Add a valid explicit
+ `modelConfig`, or configure the project's default evaluation model, then
+ retry the same request.
+
+ - `400` with `code=invalid_body`: the request shape is malformed. Use
+ the structured `details.issues` array to fix the specific fields and
+ retry.
+
+ - `400` with `code=invalid_body` on `outputDefinition`: for
+ `type=llm_as_judge`, send `dataType`, `reasoning.description`, and
+ `score.description`. Do not send `version`; it is not part of the public
+ request shape.
+
+ - If `type` is omitted, Langfuse treats the request as
+ `type=llm_as_judge` for backwards compatibility. New clients should send
+ `type` explicitly.
+
+
+ Unstable API note:
+
+ - This surface may evolve while the underlying evaluation data model is
+ being redesigned.
+ operationId: unstable_evaluators_create
+ tags:
+ - UnstableEvaluators
+ parameters: []
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluator'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '409':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '422':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableCreateEvaluatorRequest'
+ get:
+ description: >-
+ List the evaluators available to the authenticated project.
+
+
+ Important behavior:
+
+ - This endpoint returns the latest version of each available evaluator.
+
+ - Results can include evaluators from your project and Langfuse-managed
+ evaluators.
+
+ - If the same evaluator name exists in both places, both are returned as
+ separate items with different `scope` values.
+ operationId: unstable_evaluators_list
+ tags:
+ - UnstableEvaluators
+ parameters:
+ - name: page
+ in: query
+ description: 1-based page number. Defaults to `1`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ - name: limit
+ in: query
+ description: Maximum number of items per page. Defaults to `50`.
+ required: false
+ schema:
+ type: integer
+ nullable: true
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluators'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ /api/public/unstable/evaluators/{evaluatorId}:
+ get:
+ description: >-
+ Get one evaluator by `id`.
+
+
+ Use this endpoint when you want the prompt, output definition, model
+ configuration, and derived variables for the evaluator you plan to use
+ in an evaluation rule.
+ operationId: unstable_evaluators_get
+ tags:
+ - UnstableEvaluators
+ parameters:
+ - name: evaluatorId
+ in: path
+ description: Evaluator identifier returned by the evaluator endpoints.
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableEvaluator'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+ delete:
+ description: >-
+ Delete an evaluator.
+
+
+ Important behavior:
+
+ - This deletes the evaluator including all of its stored versions;
+ `evaluatorId` may reference any version.
+
+ - The API returns `409` while evaluation rules still reference the
+ evaluator. Delete those evaluation rules first.
+
+ - Langfuse-managed evaluators (`scope=managed`) cannot be deleted; the
+ API returns `403`.
+
+ - Scores already produced by the evaluator are not deleted.
+ operationId: unstable_evaluators_delete
+ tags:
+ - UnstableEvaluators
+ parameters:
+ - name: evaluatorId
+ in: path
+ description: Evaluator identifier returned by the evaluator endpoints.
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstableDeleteEvaluatorResponse'
+ '400':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '401':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '403':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '404':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '405':
+ description: ''
+ content:
+ application/json:
+ schema: {}
+ '409':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '429':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ '500':
+ description: ''
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/unstablePublicApiError'
+ security: *ref_0
+components:
+ schemas:
+ AnnotationQueueStatus:
+ title: AnnotationQueueStatus
+ type: string
+ enum:
+ - PENDING
+ - COMPLETED
+ AnnotationQueueObjectType:
+ title: AnnotationQueueObjectType
+ type: string
+ enum:
+ - TRACE
+ - OBSERVATION
+ - SESSION
+ AnnotationQueue:
title: AnnotationQueue
type: object
properties:
@@ -14073,13 +14863,40 @@ components:
title: unstableDashboardWidgetFilter
type: object
description: >-
- A dashboard widget filter in Langfuse filter-state shape.
+ A filter in Langfuse filter-state shape. The `value` shape and the
+
+ allowed operators depend on `type`:
+
+
+ | `type` | `value` | operators |
+
+ |---|---|---|
+
+ | `string` | string | `=`, `contains`, `does not contain`, `starts
+ with`, `ends with` |
+
+ | `number` | number | `=`, `>`, `<`, `>=`, `<=` |
+
+ | `datetime` | ISO datetime string | `>`, `<`, `>=`, `<=` |
+
+ | `boolean` | boolean | `=`, `<>` |
+
+ | `null` | `""` | `is null`, `is not null` |
+ | `stringOptions` | list of strings | `any of`, `none of` |
- Filter shapes depend on `type`, for example string filters use a string
- `value`,
+ | `arrayOptions` | list of strings | `any of`, `none of`, `all of` |
- option filters use a list of strings, and object filters include `key`.
+ | `categoryOptions` | list of strings (requires `key`) | `any of`, `none
+ of` |
+
+ | `stringObject` | string (requires `key`, e.g. a metadata key) | same
+ as `string` |
+
+ | `numberObject` | number (requires `key`, e.g. a score name) | same as
+ `number` |
+
+ | `booleanObject` | boolean (requires `key`) | `=`, `<>` |
properties:
column:
type: string
@@ -14140,6 +14957,28 @@ components:
enum:
- ASC
- DESC
+ unstableDashboardWidgetChartConfigInput:
+ title: unstableDashboardWidgetChartConfigInput
+ type: object
+ description: |-
+ Input-side chart config. `type` is optional and defaults to the
+ widget's `chartType`; when given it must match.
+ properties:
+ type:
+ $ref: '#/components/schemas/unstableDashboardWidgetChartType'
+ nullable: true
+ row_limit:
+ type: integer
+ nullable: true
+ show_value_labels:
+ type: boolean
+ nullable: true
+ bins:
+ type: integer
+ nullable: true
+ defaultSort:
+ $ref: '#/components/schemas/unstableDashboardWidgetDefaultSort'
+ nullable: true
unstableCreateDashboardWidgetRequest:
title: unstableCreateDashboardWidgetRequest
type: object
@@ -14148,6 +14987,8 @@ components:
type: string
description:
type: string
+ nullable: true
+ description: Defaults to an empty string.
view:
$ref: '#/components/schemas/unstableDashboardWidgetView'
dimensions:
@@ -14165,19 +15006,71 @@ components:
chartType:
$ref: '#/components/schemas/unstableDashboardWidgetChartType'
chartConfig:
- $ref: '#/components/schemas/unstableDashboardWidgetChartConfig'
- minVersion:
- type: integer
+ $ref: '#/components/schemas/unstableDashboardWidgetChartConfigInput'
nullable: true
+ description: Defaults to the plain config for `chartType`.
required:
- name
- - description
- view
- dimensions
- metrics
- filters
- chartType
- - chartConfig
+ unstableUpdateDashboardWidgetRequest:
+ title: unstableUpdateDashboardWidgetRequest
+ type: object
+ properties:
+ name:
+ type: string
+ nullable: true
+ description:
+ type: string
+ nullable: true
+ view:
+ $ref: '#/components/schemas/unstableDashboardWidgetView'
+ nullable: true
+ dimensions:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidgetDimension'
+ nullable: true
+ metrics:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidgetMetric'
+ nullable: true
+ filters:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidgetFilter'
+ nullable: true
+ chartType:
+ $ref: '#/components/schemas/unstableDashboardWidgetChartType'
+ nullable: true
+ chartConfig:
+ $ref: '#/components/schemas/unstableDashboardWidgetChartConfigInput'
+ nullable: true
+ unstableDashboardWidgetList:
+ title: unstableDashboardWidgetList
+ type: object
+ properties:
+ data:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidget'
+ meta:
+ $ref: '#/components/schemas/utilsMetaResponse'
+ required:
+ - data
+ - meta
+ unstableDeleteDashboardWidgetResponse:
+ title: unstableDeleteDashboardWidgetResponse
+ type: object
+ properties:
+ message:
+ type: string
+ required:
+ - message
unstableDashboardWidget:
title: unstableDashboardWidget
type: object
@@ -14212,8 +15105,6 @@ components:
$ref: '#/components/schemas/unstableDashboardWidgetChartType'
chartConfig:
$ref: '#/components/schemas/unstableDashboardWidgetChartConfig'
- minVersion:
- type: integer
required:
- id
- createdAt
@@ -14226,7 +15117,291 @@ components:
- filters
- chartType
- chartConfig
- - minVersion
+ unstableDashboardPlacement:
+ title: unstableDashboardPlacement
+ oneOf:
+ - type: object
+ allOf:
+ - type: object
+ properties:
+ type:
+ type: string
+ enum:
+ - widget
+ - $ref: '#/components/schemas/unstableWidgetPlacement'
+ required:
+ - type
+ - type: object
+ allOf:
+ - type: object
+ properties:
+ type:
+ type: string
+ enum:
+ - preset
+ - $ref: '#/components/schemas/unstablePresetPlacement'
+ required:
+ - type
+ description: |-
+ A tile on the dashboard's 12-column grid. `x`/`y` are the tile's
+ top-left cell (0-based; `y` grows downward), `width`/`height` its size
+ in cells. The UI default tile is 6x6 (half width). Overlapping tiles
+ are not rejected; prefer appending below existing tiles (or omit the
+ position on create to let the server do it).
+ unstableWidgetPlacement:
+ title: unstableWidgetPlacement
+ type: object
+ properties:
+ id:
+ type: string
+ widgetId:
+ type: string
+ x:
+ type: integer
+ 'y':
+ type: integer
+ width:
+ type: integer
+ height:
+ type: integer
+ required:
+ - id
+ - widgetId
+ - x
+ - 'y'
+ - width
+ - height
+ unstablePresetPlacement:
+ title: unstablePresetPlacement
+ type: object
+ properties:
+ id:
+ type: string
+ presetId:
+ type: string
+ x:
+ type: integer
+ 'y':
+ type: integer
+ width:
+ type: integer
+ height:
+ type: integer
+ required:
+ - id
+ - presetId
+ - x
+ - 'y'
+ - width
+ - height
+ unstableCreateDashboardPlacementRequest:
+ title: unstableCreateDashboardPlacementRequest
+ oneOf:
+ - type: object
+ allOf:
+ - type: object
+ properties:
+ type:
+ type: string
+ enum:
+ - widget
+ - $ref: '#/components/schemas/unstableCreateWidgetPlacement'
+ required:
+ - type
+ - type: object
+ allOf:
+ - type: object
+ properties:
+ type:
+ type: string
+ enum:
+ - preset
+ - $ref: '#/components/schemas/unstableCreatePresetPlacement'
+ required:
+ - type
+ unstableCreateWidgetPlacement:
+ title: unstableCreateWidgetPlacement
+ type: object
+ properties:
+ id:
+ type: string
+ nullable: true
+ description: Server-generated when omitted.
+ widgetId:
+ type: string
+ x:
+ type: integer
+ nullable: true
+ description: Grid column (12-column grid). Defaults to `0`.
+ 'y':
+ type: integer
+ nullable: true
+ description: Grid row. Defaults to the first row below all existing tiles.
+ width:
+ type: integer
+ nullable: true
+ description: Width in grid columns. Defaults to `6`.
+ height:
+ type: integer
+ nullable: true
+ description: Height in grid rows. Defaults to `6`.
+ required:
+ - widgetId
+ unstableCreatePresetPlacement:
+ title: unstableCreatePresetPlacement
+ type: object
+ properties:
+ id:
+ type: string
+ nullable: true
+ description: Server-generated when omitted.
+ presetId:
+ type: string
+ x:
+ type: integer
+ nullable: true
+ description: Grid column (12-column grid). Defaults to `0`.
+ 'y':
+ type: integer
+ nullable: true
+ description: Grid row. Defaults to the first row below all existing tiles.
+ width:
+ type: integer
+ nullable: true
+ description: Width in grid columns. Defaults to `6`.
+ height:
+ type: integer
+ nullable: true
+ description: Height in grid rows. Defaults to `6`.
+ required:
+ - presetId
+ unstableUpdateDashboardPlacementRequest:
+ title: unstableUpdateDashboardPlacementRequest
+ type: object
+ properties:
+ x:
+ type: integer
+ nullable: true
+ description: Grid column (12-column grid).
+ 'y':
+ type: integer
+ nullable: true
+ description: Grid row.
+ width:
+ type: integer
+ nullable: true
+ description: Width in grid columns.
+ height:
+ type: integer
+ nullable: true
+ description: Height in grid rows.
+ unstableDeleteDashboardPlacementResponse:
+ title: unstableDeleteDashboardPlacementResponse
+ type: object
+ properties:
+ message:
+ type: string
+ required:
+ - message
+ unstableDashboardDefinition:
+ title: unstableDashboardDefinition
+ type: object
+ properties:
+ widgets:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardPlacement'
+ required:
+ - widgets
+ unstableDashboard:
+ title: unstableDashboard
+ type: object
+ properties:
+ id:
+ type: string
+ createdAt:
+ type: string
+ format: date-time
+ updatedAt:
+ type: string
+ format: date-time
+ name:
+ type: string
+ description:
+ type: string
+ definition:
+ $ref: '#/components/schemas/unstableDashboardDefinition'
+ filters:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidgetFilter'
+ description: Dashboard-level filters applied to all widgets on the dashboard.
+ required:
+ - id
+ - createdAt
+ - updatedAt
+ - name
+ - description
+ - definition
+ - filters
+ unstableDashboardList:
+ title: unstableDashboardList
+ type: object
+ properties:
+ data:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboard'
+ meta:
+ $ref: '#/components/schemas/utilsMetaResponse'
+ required:
+ - data
+ - meta
+ unstableCreateDashboardRequest:
+ title: unstableCreateDashboardRequest
+ type: object
+ properties:
+ name:
+ type: string
+ description:
+ type: string
+ nullable: true
+ definition:
+ $ref: '#/components/schemas/unstableDashboardDefinition'
+ nullable: true
+ filters:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidgetFilter'
+ nullable: true
+ required:
+ - name
+ unstableUpdateDashboardRequest:
+ title: unstableUpdateDashboardRequest
+ type: object
+ properties:
+ name:
+ type: string
+ nullable: true
+ description:
+ type: string
+ nullable: true
+ definition:
+ $ref: '#/components/schemas/unstableDashboardDefinition'
+ nullable: true
+ filters:
+ type: array
+ items:
+ $ref: '#/components/schemas/unstableDashboardWidgetFilter'
+ nullable: true
+ unstableDeleteDashboardResponse:
+ title: unstableDeleteDashboardResponse
+ type: object
+ properties:
+ message:
+ type: string
+ required:
+ - message
unstablePublicApiErrorCode:
title: unstablePublicApiErrorCode
type: string
diff --git a/web/src/__tests__/server/mcp-public-api-tools.servertest.ts b/web/src/__tests__/server/mcp-public-api-tools.servertest.ts
index db593437fc..a8a59b1037 100644
--- a/web/src/__tests__/server/mcp-public-api-tools.servertest.ts
+++ b/web/src/__tests__/server/mcp-public-api-tools.servertest.ts
@@ -248,7 +248,9 @@ describe("MCP public API tools", () => {
.sort();
expect(destructiveToolNames).toEqual(
[
+ "addDashboardPlacement",
"createChatPrompt",
+ "createDashboard",
"createDashboardWidget",
"createEvaluationRule",
"upsertEvaluator",
@@ -257,6 +259,9 @@ describe("MCP public API tools", () => {
"createTextPrompt",
"deleteAnnotationQueueAssignment",
"deleteAnnotationQueueItem",
+ "deleteDashboard",
+ "deleteDashboardPlacement",
+ "deleteDashboardWidget",
"deleteDatasetItem",
"deleteDatasetRun",
"deleteEvaluationRule",
@@ -264,6 +269,9 @@ describe("MCP public API tools", () => {
"deleteModel",
"deleteScoreConfig",
"updateAnnotationQueueItem",
+ "updateDashboard",
+ "updateDashboardPlacement",
+ "updateDashboardWidget",
"updateEvaluationRule",
"updatePromptLabels",
"updateScoreConfig",
diff --git a/web/src/__tests__/server/mcp-tools-read.servertest.ts b/web/src/__tests__/server/mcp-tools-read.servertest.ts
index 86ff22f228..561dc23d67 100644
--- a/web/src/__tests__/server/mcp-tools-read.servertest.ts
+++ b/web/src/__tests__/server/mcp-tools-read.servertest.ts
@@ -57,12 +57,26 @@ 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,
buildObservationUrl,
buildPromptUrl,
buildTraceUrl,
} from "@/src/utils/product-url";
+import { handleCreateDashboardWidget } from "@/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget";
+import {
+ getDashboardTool,
+ getDashboardWidgetTool,
+ handleCreateDashboard,
+ handleGetDashboard,
+ handleGetDashboardWidget,
+ handleListDashboards,
+ handleListDashboardWidgets,
+ listDashboardsTool,
+ listDashboardWidgetsTool,
+} from "@/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud";
// Import MCP tool handlers directly
import {
@@ -3676,4 +3690,78 @@ describe("MCP Read Tools", () => {
);
});
});
+
+ describe("dashboard read tools", () => {
+ const dashboardReadTools = [
+ listDashboardsTool,
+ getDashboardTool,
+ listDashboardWidgetsTool,
+ getDashboardWidgetTool,
+ ];
+
+ it("should have readOnlyHint annotations", () => {
+ for (const tool of dashboardReadTools) {
+ verifyToolAnnotations(tool, { readOnlyHint: true });
+ }
+ });
+
+ it("should list and get dashboards and widgets with product URLs", async () => {
+ const setup = await createMcpTestSetup();
+ const dashboard = (await handleCreateDashboard(
+ { name: `mcp-dashboard-${nanoid()}`, description: "" },
+ setup.context,
+ )) as { id: string };
+ const widget = (await handleCreateDashboardWidget(
+ {
+ name: `mcp-widget-${nanoid()}`,
+ description: "Created by MCP",
+ view: "observations",
+ dimensions: [],
+ metrics: [{ measure: "count", agg: "count" }],
+ filters: [],
+ chartType: "NUMBER",
+ chartConfig: { type: "NUMBER" },
+ },
+ setup.context,
+ )) as { id: string };
+
+ const listedDashboards = (await handleListDashboards(
+ { page: 1, limit: 50 },
+ setup.context,
+ )) as { data: Array<{ id: string; url: string }> };
+ expect(listedDashboards.data.map((item) => item.id)).toContain(
+ dashboard.id,
+ );
+
+ const fetchedDashboard = (await handleGetDashboard(
+ { dashboardId: dashboard.id },
+ setup.context,
+ )) as { id: string; url: string };
+ expect(fetchedDashboard).toMatchObject({
+ id: dashboard.id,
+ url: buildDashboardUrl({
+ projectId: setup.projectId,
+ dashboardId: dashboard.id,
+ }),
+ });
+
+ const listedWidgets = (await handleListDashboardWidgets(
+ { page: 1, limit: 50 },
+ setup.context,
+ )) as { data: Array<{ id: string; url: string }> };
+ expect(listedWidgets.data.map((item) => item.id)).toContain(widget.id);
+
+ const fetchedWidget = (await handleGetDashboardWidget(
+ { widgetId: widget.id },
+ setup.context,
+ )) as { id: string; url: string };
+ expect(fetchedWidget).toMatchObject({
+ id: widget.id,
+ url: buildDashboardWidgetUrl({
+ projectId: setup.projectId,
+ widgetId: widget.id,
+ }),
+ });
+ });
+ });
});
diff --git a/web/src/__tests__/server/mcp-tools-write.servertest.ts b/web/src/__tests__/server/mcp-tools-write.servertest.ts
index 7c98b07470..afe8f54432 100644
--- a/web/src/__tests__/server/mcp-tools-write.servertest.ts
+++ b/web/src/__tests__/server/mcp-tools-write.servertest.ts
@@ -85,6 +85,18 @@ import {
createDashboardWidgetTool,
handleCreateDashboardWidget,
} from "@/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget";
+import {
+ handleAddDashboardPlacement,
+ handleCreateDashboard,
+ handleDeleteDashboard,
+ handleDeleteDashboardPlacement,
+ handleDeleteDashboardWidget,
+ handleGetDashboard,
+ handleGetDashboardWidget,
+ handleUpdateDashboardPlacement,
+ handleUpdateDashboard,
+ handleUpdateDashboardWidget,
+} from "@/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud";
const createScoreConfig = async (projectId: string) =>
prisma.scoreConfig.create({
@@ -441,7 +453,6 @@ describe("MCP Write Tools", () => {
filters: [],
chartType: "NUMBER",
chartConfig: { type: "NUMBER" },
- minVersion: 2,
},
setup.context,
)) as { id: string; name: string; url: string };
@@ -474,6 +485,179 @@ describe("MCP Write Tools", () => {
});
});
+ describe("dashboard CRUD tools", () => {
+ const createWidgetForTest = async (
+ setup: Awaited<ReturnType<typeof createMcpTestSetup>>,
+ ) =>
+ (await handleCreateDashboardWidget(
+ {
+ name: `mcp-widget-${nanoid()}`,
+ description: "Created by MCP",
+ view: "observations",
+ dimensions: [],
+ metrics: [{ measure: "count", agg: "count" }],
+ filters: [],
+ chartType: "NUMBER",
+ chartConfig: { type: "NUMBER" },
+ },
+ setup.context,
+ )) as { id: string };
+
+ it("runs the dashboard and placement write lifecycle", async () => {
+ const setup = await createMcpTestSetup();
+ const created = await createWidgetForTest(setup);
+ const newName = `mcp-widget-renamed-${nanoid()}`;
+
+ await expect(
+ handleUpdateDashboardWidget(
+ { widgetId: created.id, name: newName },
+ setup.context,
+ ),
+ ).resolves.toMatchObject({ id: created.id, name: newName });
+
+ const dashboard = (await handleCreateDashboard(
+ { name: `mcp-dashboard-${nanoid()}`, description: "" },
+ setup.context,
+ )) as { id: string };
+
+ await expect(
+ handleUpdateDashboard(
+ { dashboardId: dashboard.id, name: "MCP dashboard updated" },
+ setup.context,
+ ),
+ ).resolves.toMatchObject({
+ id: dashboard.id,
+ name: "MCP dashboard updated",
+ });
+
+ const added = (await handleAddDashboardPlacement(
+ { dashboardId: dashboard.id, type: "widget", widgetId: created.id },
+ setup.context,
+ )) as { id: string } & Record<string, unknown>;
+
+ expect(added).toEqual({
+ type: "widget",
+ id: expect.any(String),
+ widgetId: created.id,
+ x: 0,
+ y: 0,
+ width: 6,
+ height: 6,
+ });
+
+ await expect(
+ handleUpdateDashboardPlacement(
+ {
+ dashboardId: dashboard.id,
+ placementId: added.id,
+ x: 4,
+ width: 4,
+ },
+ setup.context,
+ ),
+ ).resolves.toMatchObject({ id: added.id, x: 4, width: 4 });
+ await expect(
+ handleDeleteDashboardPlacement(
+ { dashboardId: dashboard.id, placementId: added.id },
+ setup.context,
+ ),
+ ).resolves.toEqual({ message: "Placement successfully deleted" });
+ await expect(
+ handleDeleteDashboardWidget({ widgetId: created.id }, setup.context),
+ ).resolves.toEqual({
+ message: "Dashboard widget successfully deleted",
+ });
+ await expect(
+ handleDeleteDashboard({ dashboardId: dashboard.id }, setup.context),
+ ).resolves.toEqual({ message: "Dashboard successfully deleted" });
+ await expect(
+ prisma.dashboardWidget.findUnique({ where: { id: created.id } }),
+ ).resolves.toBeNull();
+ await expect(
+ prisma.dashboard.findUnique({ where: { id: dashboard.id } }),
+ ).resolves.toBeNull();
+ });
+
+ it("uses context.projectId for dashboard write isolation", async () => {
+ const owner = await createMcpTestSetup();
+ const other = await createMcpTestSetup();
+ const created = await createWidgetForTest(owner);
+ const dashboard = (await handleCreateDashboard(
+ { name: `private-mcp-dashboard-${nanoid()}`, description: "" },
+ owner.context,
+ )) as { id: string };
+ const placement = (await handleAddDashboardPlacement(
+ { dashboardId: dashboard.id, type: "widget", widgetId: created.id },
+ owner.context,
+ )) as { id: string };
+
+ await expect(
+ handleUpdateDashboard(
+ { dashboardId: dashboard.id, name: "Cross-project rename" },
+ other.context,
+ ),
+ ).rejects.toThrow(/not found/i);
+ await expect(
+ handleUpdateDashboardWidget(
+ { widgetId: created.id, name: "Cross-project widget rename" },
+ other.context,
+ ),
+ ).rejects.toThrow(/not found/i);
+ await expect(
+ handleUpdateDashboardPlacement(
+ {
+ dashboardId: dashboard.id,
+ placementId: placement.id,
+ x: 4,
+ },
+ other.context,
+ ),
+ ).rejects.toThrow(/not found/i);
+
+ await expect(
+ handleGetDashboard({ dashboardId: dashboard.id }, owner.context),
+ ).resolves.toMatchObject({
+ name: expect.stringContaining("private-mcp-dashboard-"),
+ definition: {
+ widgets: [expect.objectContaining({ id: placement.id, x: 0 })],
+ },
+ });
+ await expect(
+ handleGetDashboardWidget({ widgetId: created.id }, owner.context),
+ ).resolves.toMatchObject({
+ id: created.id,
+ name: expect.stringContaining("mcp-widget-"),
+ });
+ });
+
+ it("rejects widget placements without a widgetId", async () => {
+ const setup = await createMcpTestSetup();
+ const dashboard = (await handleCreateDashboard(
+ { name: `mcp-dashboard-${nanoid()}`, description: "" },
+ setup.context,
+ )) as { id: string };
+
+ await expect(
+ handleAddDashboardPlacement(
+ { dashboardId: dashboard.id, type: "widget", id: "placement-1" },
+ setup.context,
+ ),
+ ).rejects.toThrow(/widgetId is required/);
+ });
+
+ it("rejects dashboard updates without any patch field", async () => {
+ const setup = await createMcpTestSetup();
+ const dashboard = (await handleCreateDashboard(
+ { name: `mcp-dashboard-${nanoid()}`, description: "" },
+ setup.context,
+ )) as { id: string };
+
+ await expect(
+ handleUpdateDashboard({ dashboardId: dashboard.id }, setup.context),
+ ).rejects.toThrow(/at least one field/i);
+ });
+ });
+
describe("createTextPrompt tool", () => {
it("should create a simple text prompt", async () => {
const { context } = await createMcpTestSetup();
diff --git a/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts b/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts
index cf6ece15b4..a68366f474 100644
--- a/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts
+++ b/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts
@@ -16,8 +16,6 @@ const baseWidgetBody = {
metrics: [{ measure: "count", agg: "count" as const }],
filters: [],
chartType: "NUMBER" as const,
- chartConfig: { type: "NUMBER" as const },
- minVersion: 2,
};
const expectUnstableError = (
@@ -50,7 +48,8 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
name: "API widget",
view: "observations",
chartType: "NUMBER",
- minVersion: 2,
+ // chartConfig is derived from chartType when omitted
+ chartConfig: { type: "NUMBER" },
});
await expect(
@@ -62,6 +61,8 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
projectId,
name: "API widget",
view: "OBSERVATIONS",
+ // widgets created via the public API are always v2 internally
+ minVersion: 2,
});
await expect(
@@ -79,22 +80,6 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
});
});
- it("defaults supported views to minVersion 2", async () => {
- const { auth } = await createOrgProjectAndApiKey();
- const { minVersion: _minVersion, ...bodyWithoutMinVersion } =
- baseWidgetBody;
-
- const response = await makeZodVerifiedAPICall(
- PostUnstableDashboardWidgetResponse,
- "POST",
- "/api/public/unstable/dashboard-widgets",
- bodyWithoutMinVersion,
- auth,
- );
-
- expect(response.body.minVersion).toBe(2);
- });
-
it("rejects traces widgets", async () => {
const { auth } = await createOrgProjectAndApiKey();
@@ -104,26 +89,6 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
{
...baseWidgetBody,
view: "traces",
- minVersion: 2,
- },
- auth,
- );
-
- expectUnstableError(response, {
- status: 400,
- code: "invalid_body",
- });
- });
-
- it("rejects legacy minVersion values", async () => {
- const { auth } = await createOrgProjectAndApiKey();
-
- const response = await makeAPICall(
- "POST",
- "/api/public/unstable/dashboard-widgets",
- {
- ...baseWidgetBody,
- minVersion: 1,
},
auth,
);
@@ -134,7 +99,7 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
});
});
- it("returns unstable invalid_body errors for malformed widget JSON", async () => {
+ it("rejects a chartConfig.type that contradicts chartType", async () => {
const { auth } = await createOrgProjectAndApiKey();
const response = await makeAPICall(
@@ -149,7 +114,7 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
expectUnstableError(response, {
status: 400,
- code: "invalid_body",
+ code: "invalid_request",
});
});
diff --git a/web/src/__tests__/server/unstable-dashboards-api.servertest.ts b/web/src/__tests__/server/unstable-dashboards-api.servertest.ts
new file mode 100644
index 0000000000..1dedeb6ad9
--- /dev/null
+++ b/web/src/__tests__/server/unstable-dashboards-api.servertest.ts
@@ -0,0 +1,744 @@
+import {
+ makeAPICall,
+ makeZodVerifiedAPICall,
+} from "@/src/__tests__/test-utils";
+import {
+ DeleteUnstableDashboardWidgetResponse,
+ GetUnstableDashboardWidgetResponse,
+ GetUnstableDashboardWidgetsResponse,
+ PatchUnstableDashboardWidgetResponse,
+ PostUnstableDashboardWidgetResponse,
+} from "@/src/features/public-api/types/unstable-dashboard-widgets";
+import {
+ DeleteDashboardPlacementResponse,
+ DeleteUnstableDashboardResponse,
+ GetUnstableDashboardResponse,
+ GetUnstableDashboardsResponse,
+ PatchDashboardPlacementResponse,
+ PatchUnstableDashboardResponse,
+ PostDashboardPlacementResponse,
+ PostUnstableDashboardResponse,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import { UnstablePublicApiErrorResponse } from "@/src/features/public-api/types/unstable-public-evals-contract";
+import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";
+import { prisma } from "@langfuse/shared/src/db";
+import { nanoid } from "nanoid";
+
+const widget = {
+ name: "API widget",
+ description: "Created via unstable API",
+ view: "observations" as const,
+ dimensions: [],
+ metrics: [{ measure: "count", agg: "count" as const }],
+ filters: [],
+ chartType: "NUMBER" as const,
+};
+
+describe("unstable dashboard API", () => {
+ it("manages dashboards, widgets, and placements without leaving broken references", async () => {
+ const { auth, projectId, publicKey } = await createOrgProjectAndApiKey();
+ const createdWidget = await makeZodVerifiedAPICall(
+ PostUnstableDashboardWidgetResponse,
+ "POST",
+ "/api/public/unstable/dashboard-widgets",
+ widget,
+ auth,
+ );
+ const listedWidgets = await makeZodVerifiedAPICall(
+ GetUnstableDashboardWidgetsResponse,
+ "GET",
+ "/api/public/unstable/dashboard-widgets?page=1&limit=50",
+ undefined,
+ auth,
+ );
+ expect(listedWidgets.body.data.map(({ id }) => id)).toContain(
+ createdWidget.body.id,
+ );
+ await expect(
+ makeZodVerifiedAPICall(
+ GetUnstableDashboardWidgetResponse,
+ "GET",
+ `/api/public/unstable/dashboard-widgets/${createdWidget.body.id}`,
+ undefined,
+ auth,
+ ),
+ ).resolves.toMatchObject({ body: { id: createdWidget.body.id } });
+
+ const updatedWidget = await makeZodVerifiedAPICall(
+ PatchUnstableDashboardWidgetResponse,
+ "PATCH",
+ `/api/public/unstable/dashboard-widgets/${createdWidget.body.id}`,
+ { name: "Updated API widget" },
+ auth,
+ );
+ expect(updatedWidget.body.name).toBe("Updated API widget");
+
+ const dashboardFilters = [
+ {
+ column: "environment",
+ type: "string" as const,
+ operator: "=" as const,
+ value: "production",
+ },
+ ];
+ const createdDashboard = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ {
+ name: "API dashboard",
+ description: "Created via unstable API",
+ filters: dashboardFilters,
+ },
+ auth,
+ );
+ expect(createdDashboard.body.filters).toEqual(dashboardFilters);
+
+ await expect(
+ makeZodVerifiedAPICall(
+ GetUnstableDashboardResponse,
+ "GET",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}`,
+ undefined,
+ auth,
+ ),
+ ).resolves.toMatchObject({ body: { id: createdDashboard.body.id } });
+
+ const updatedFilters = [
+ {
+ column: "environment",
+ type: "string" as const,
+ operator: "=" as const,
+ value: "staging",
+ },
+ ];
+ const updatedDashboard = await makeZodVerifiedAPICall(
+ PatchUnstableDashboardResponse,
+ "PATCH",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}`,
+ {
+ name: "Updated API dashboard",
+ description: "Updated via unstable API",
+ filters: updatedFilters,
+ definition: {
+ widgets: [
+ {
+ type: "preset",
+ id: "preset-placement",
+ presetId: "home-score-analytics",
+ x: 0,
+ y: 0,
+ width: 6,
+ height: 4,
+ },
+ ],
+ },
+ },
+ auth,
+ );
+ expect(updatedDashboard.body).toMatchObject({
+ name: "Updated API dashboard",
+ description: "Updated via unstable API",
+ filters: updatedFilters,
+ definition: {
+ widgets: [
+ expect.objectContaining({
+ id: "preset-placement",
+ presetId: "home-score-analytics",
+ }),
+ ],
+ },
+ });
+
+ await makeZodVerifiedAPICall(
+ PostDashboardPlacementResponse,
+ "POST",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}/placements`,
+ {
+ type: "widget",
+ id: "placement-1",
+ widgetId: createdWidget.body.id,
+ x: 0,
+ y: 0,
+ width: 4,
+ height: 3,
+ },
+ auth,
+ );
+
+ const duplicatePlacement = await makeAPICall(
+ "POST",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}/placements`,
+ {
+ type: "widget",
+ id: "placement-1",
+ widgetId: createdWidget.body.id,
+ },
+ auth,
+ );
+ expect(duplicatePlacement.status).toBe(409);
+ expect(
+ UnstablePublicApiErrorResponse.parse(duplicatePlacement.body).code,
+ ).toBe("conflict");
+
+ const blockedDelete = await makeAPICall(
+ "DELETE",
+ `/api/public/unstable/dashboard-widgets/${createdWidget.body.id}`,
+ undefined,
+ auth,
+ );
+ expect(blockedDelete.status).toBe(409);
+ expect(UnstablePublicApiErrorResponse.parse(blockedDelete.body).code).toBe(
+ "conflict",
+ );
+
+ const moved = await makeZodVerifiedAPICall(
+ PatchDashboardPlacementResponse,
+ "PATCH",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}/placements/placement-1`,
+ { x: 4 },
+ auth,
+ );
+ // Partial move: omitted fields keep their current values.
+ expect(moved.body).toMatchObject({
+ id: "placement-1",
+ x: 4,
+ y: 0,
+ width: 4,
+ height: 3,
+ });
+
+ await makeZodVerifiedAPICall(
+ DeleteDashboardPlacementResponse,
+ "DELETE",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}/placements/placement-1`,
+ undefined,
+ auth,
+ );
+ await makeZodVerifiedAPICall(
+ DeleteDashboardPlacementResponse,
+ "DELETE",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}/placements/preset-placement`,
+ undefined,
+ auth,
+ );
+ await makeZodVerifiedAPICall(
+ DeleteUnstableDashboardWidgetResponse,
+ "DELETE",
+ `/api/public/unstable/dashboard-widgets/${createdWidget.body.id}`,
+ undefined,
+ auth,
+ );
+ await makeZodVerifiedAPICall(
+ DeleteUnstableDashboardResponse,
+ "DELETE",
+ `/api/public/unstable/dashboards/${createdDashboard.body.id}`,
+ undefined,
+ auth,
+ );
+
+ await expect(
+ prisma.dashboardWidget.findUnique({
+ where: { id: createdWidget.body.id },
+ }),
+ ).resolves.toBeNull();
+ await expect(
+ prisma.dashboard.findUnique({
+ where: { id: createdDashboard.body.id },
+ }),
+ ).resolves.toBeNull();
+
+ const apiKey = await prisma.apiKey.findFirstOrThrow({
+ where: { projectId, publicKey },
+ select: { id: true },
+ });
+ const auditLogs = await prisma.auditLog.findMany({
+ where: {
+ projectId,
+ apiKeyId: apiKey.id,
+ resourceId: {
+ in: [createdDashboard.body.id, createdWidget.body.id],
+ },
+ },
+ });
+ const dashboardAuditLogs = auditLogs.filter(
+ ({ resourceId }) => resourceId === createdDashboard.body.id,
+ );
+ const widgetAuditLogs = auditLogs.filter(
+ ({ resourceId }) => resourceId === createdWidget.body.id,
+ );
+ expect(dashboardAuditLogs.map(({ action }) => action).sort()).toEqual(
+ [
+ "create",
+ "update",
+ "update",
+ "update",
+ "update",
+ "update",
+ "delete",
+ ].sort(),
+ );
+ expect(widgetAuditLogs.map(({ action }) => action).sort()).toEqual(
+ ["create", "update", "delete"].sort(),
+ );
+ for (const auditLog of auditLogs) {
+ expect(auditLog).toMatchObject({
+ projectId,
+ apiKeyId: apiKey.id,
+ type: "API_KEY",
+ });
+ if (auditLog.action === "create") {
+ expect(auditLog.before).toBeNull();
+ expect(auditLog.after).not.toBeNull();
+ } else if (auditLog.action === "update") {
+ expect(auditLog.before).not.toBeNull();
+ expect(auditLog.after).not.toBeNull();
+ } else if (auditLog.action === "delete") {
+ expect(auditLog.before).not.toBeNull();
+ expect(auditLog.after).toBeNull();
+ }
+ }
+ });
+
+ it("paginates project dashboards with correct totals and excludes Langfuse-managed dashboards", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const first = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Dashboard A", description: "" },
+ auth,
+ );
+ const second = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Dashboard B", description: "" },
+ auth,
+ );
+ // Langfuse-managed dashboards (projectId null) sort first by updatedAt
+ // and must be neither returned nor counted by the public API.
+ const langfuseManaged = await prisma.dashboard.create({
+ data: {
+ id: `langfuse-managed-${nanoid()}`,
+ projectId: null,
+ name: "Langfuse managed",
+ description: "",
+ definition: { widgets: [] },
+ },
+ });
+ try {
+ const page1 = await makeZodVerifiedAPICall(
+ GetUnstableDashboardsResponse,
+ "GET",
+ "/api/public/unstable/dashboards?page=1&limit=1",
+ undefined,
+ auth,
+ );
+ expect(page1.body.data).toHaveLength(1);
+ expect([first.body.id, second.body.id]).toContain(page1.body.data[0].id);
+ expect(page1.body.meta).toMatchObject({
+ page: 1,
+ limit: 1,
+ totalItems: 2,
+ totalPages: 2,
+ });
+ const managedRead = await makeAPICall(
+ "GET",
+ `/api/public/unstable/dashboards/${langfuseManaged.id}`,
+ undefined,
+ auth,
+ );
+ expect(managedRead.status).toBe(404);
+ } finally {
+ await prisma.dashboard.delete({ where: { id: langfuseManaged.id } });
+ }
+ });
+
+ it("rejects creating a dashboard whose definition references a missing widget", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const response = await makeAPICall(
+ "POST",
+ "/api/public/unstable/dashboards",
+ {
+ name: "Broken dashboard",
+ description: "",
+ definition: {
+ widgets: [
+ {
+ type: "widget",
+ id: "placement-1",
+ widgetId: "does-not-exist",
+ x: 0,
+ y: 0,
+ width: 4,
+ height: 3,
+ },
+ ],
+ },
+ },
+ auth,
+ );
+ expect(response.status).toBe(404);
+ });
+
+ it("rejects definitions with duplicate placement ids", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const createdWidget = await makeZodVerifiedAPICall(
+ PostUnstableDashboardWidgetResponse,
+ "POST",
+ "/api/public/unstable/dashboard-widgets",
+ widget,
+ auth,
+ );
+ const placement = {
+ type: "widget",
+ id: "placement-1",
+ widgetId: createdWidget.body.id,
+ x: 0,
+ y: 0,
+ width: 4,
+ height: 3,
+ };
+ const response = await makeAPICall(
+ "POST",
+ "/api/public/unstable/dashboards",
+ {
+ name: "Duplicate placement ids",
+ description: "",
+ definition: { widgets: [placement, { ...placement, y: 3 }] },
+ },
+ auth,
+ );
+ expect(response.status).toBe(400);
+ });
+
+ it("allows placing Langfuse-managed widgets on a project dashboard", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const langfuseWidget = await prisma.dashboardWidget.create({
+ data: {
+ id: `langfuse-widget-${nanoid()}`,
+ projectId: null,
+ name: "Langfuse managed widget",
+ description: "",
+ view: "OBSERVATIONS",
+ dimensions: [],
+ metrics: [{ measure: "count", agg: "count" }],
+ filters: [],
+ chartType: "NUMBER",
+ chartConfig: { type: "NUMBER" },
+ minVersion: 2,
+ },
+ });
+ try {
+ const dashboard = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Dashboard with managed widget", description: "" },
+ auth,
+ );
+ const placed = await makeZodVerifiedAPICall(
+ PostDashboardPlacementResponse,
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ { type: "widget", widgetId: langfuseWidget.id },
+ auth,
+ );
+ expect(placed.body).toMatchObject({
+ type: "widget",
+ widgetId: langfuseWidget.id,
+ });
+
+ const listed = await makeZodVerifiedAPICall(
+ GetUnstableDashboardWidgetsResponse,
+ "GET",
+ "/api/public/unstable/dashboard-widgets?page=1&limit=50",
+ undefined,
+ auth,
+ );
+ expect(listed.body.data.map(({ id }) => id)).not.toContain(
+ langfuseWidget.id,
+ );
+ for (const [method, body] of [
+ ["GET", undefined],
+ ["PATCH", { name: "Cannot rename managed widget" }],
+ ["DELETE", undefined],
+ ] as const) {
+ const response = await makeAPICall(
+ method,
+ `/api/public/unstable/dashboard-widgets/${langfuseWidget.id}`,
+ body,
+ auth,
+ );
+ expect(response.status).toBe(404);
+ }
+ await expect(
+ prisma.dashboardWidget.findUnique({
+ where: { id: langfuseWidget.id },
+ }),
+ ).resolves.toMatchObject({
+ projectId: null,
+ name: "Langfuse managed widget",
+ });
+ } finally {
+ await prisma.dashboardWidget.delete({
+ where: { id: langfuseWidget.id },
+ });
+ }
+ });
+
+ it("validates preset placements against the preset registry", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const dashboard = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Preset dashboard", description: "" },
+ auth,
+ );
+
+ const unknownPreset = await makeAPICall(
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ { type: "preset", presetId: "does-not-exist" },
+ auth,
+ );
+ expect(unknownPreset.status).toBe(404);
+
+ const placed = await makeZodVerifiedAPICall(
+ PostDashboardPlacementResponse,
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ { type: "preset", presetId: "home-score-analytics" },
+ auth,
+ );
+ expect(placed.body).toMatchObject({
+ type: "preset",
+ presetId: "home-score-analytics",
+ });
+ });
+
+ it("appends placements with server defaults when id and position are omitted", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const createdWidget = await makeZodVerifiedAPICall(
+ PostUnstableDashboardWidgetResponse,
+ "POST",
+ "/api/public/unstable/dashboard-widgets",
+ widget,
+ auth,
+ );
+ const dashboard = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Auto-append dashboard", description: "" },
+ auth,
+ );
+ await makeZodVerifiedAPICall(
+ PostDashboardPlacementResponse,
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ {
+ type: "widget",
+ id: "placement-1",
+ widgetId: createdWidget.body.id,
+ x: 0,
+ y: 0,
+ width: 4,
+ height: 3,
+ },
+ auth,
+ );
+
+ const appended = await makeZodVerifiedAPICall(
+ PostDashboardPlacementResponse,
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ { type: "widget", widgetId: createdWidget.body.id },
+ auth,
+ );
+ // Appended below the existing 3-row tile with the UI's 6x6 default size.
+ expect(appended.body).toMatchObject({
+ type: "widget",
+ id: expect.any(String),
+ widgetId: createdWidget.body.id,
+ x: 0,
+ y: 3,
+ width: 6,
+ height: 6,
+ });
+ });
+
+ it("does not expose or mutate dashboards and widgets across projects", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const { auth: otherAuth } = await createOrgProjectAndApiKey();
+ const ownerWidget = await makeZodVerifiedAPICall(
+ PostUnstableDashboardWidgetResponse,
+ "POST",
+ "/api/public/unstable/dashboard-widgets",
+ { ...widget, name: "Private widget" },
+ auth,
+ );
+ const dashboard = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Private dashboard", description: "" },
+ auth,
+ );
+ await makeZodVerifiedAPICall(
+ PostDashboardPlacementResponse,
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ {
+ type: "widget",
+ id: "private-placement",
+ widgetId: ownerWidget.body.id,
+ },
+ auth,
+ );
+ const otherDashboard = await makeZodVerifiedAPICall(
+ PostUnstableDashboardResponse,
+ "POST",
+ "/api/public/unstable/dashboards",
+ { name: "Other dashboard", description: "" },
+ otherAuth,
+ );
+
+ const [otherDashboards, otherWidgets] = await Promise.all([
+ makeZodVerifiedAPICall(
+ GetUnstableDashboardsResponse,
+ "GET",
+ "/api/public/unstable/dashboards?page=1&limit=50",
+ undefined,
+ otherAuth,
+ ),
+ makeZodVerifiedAPICall(
+ GetUnstableDashboardWidgetsResponse,
+ "GET",
+ "/api/public/unstable/dashboard-widgets?page=1&limit=50",
+ undefined,
+ otherAuth,
+ ),
+ ]);
+ expect(otherDashboards.body.data.map(({ id }) => id)).not.toContain(
+ dashboard.body.id,
+ );
+ expect(otherWidgets.body.data.map(({ id }) => id)).not.toContain(
+ ownerWidget.body.id,
+ );
+
+ const forbiddenRequests = [
+ [
+ "GET",
+ `/api/public/unstable/dashboards/${dashboard.body.id}`,
+ undefined,
+ ],
+ [
+ "PATCH",
+ `/api/public/unstable/dashboards/${dashboard.body.id}`,
+ { name: "Cross-project rename" },
+ ],
+ [
+ "DELETE",
+ `/api/public/unstable/dashboards/${dashboard.body.id}`,
+ undefined,
+ ],
+ [
+ "POST",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements`,
+ { type: "preset", presetId: "home-score-analytics" },
+ ],
+ [
+ "PATCH",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements/private-placement`,
+ { x: 3 },
+ ],
+ [
+ "DELETE",
+ `/api/public/unstable/dashboards/${dashboard.body.id}/placements/private-placement`,
+ undefined,
+ ],
+ [
+ "GET",
+ `/api/public/unstable/dashboard-widgets/${ownerWidget.body.id}`,
+ undefined,
+ ],
+ [
+ "PATCH",
+ `/api/public/unstable/dashboard-widgets/${ownerWidget.body.id}`,
+ { name: "Cross-project widget rename" },
+ ],
+ [
+ "DELETE",
+ `/api/public/unstable/dashboard-widgets/${ownerWidget.body.id}`,
+ undefined,
+ ],
+ ] as const;
+ for (const [method, path, body] of forbiddenRequests) {
+ const response = await makeAPICall(method, path, body, otherAuth);
+ expect(response.status).toBe(404);
+ }
+
+ const foreignReference = await makeAPICall(
+ "POST",
+ `/api/public/unstable/dashboards/${otherDashboard.body.id}/placements`,
+ { type: "widget", widgetId: ownerWidget.body.id },
+ otherAuth,
+ );
+ expect(foreignReference.status).toBe(404);
+
+ const ownerDashboard = await makeZodVerifiedAPICall(
+ GetUnstableDashboardResponse,
+ "GET",
+ `/api/public/unstable/dashboards/${dashboard.body.id}`,
+ undefined,
+ auth,
+ );
+ expect(ownerDashboard.body).toMatchObject({
+ name: "Private dashboard",
+ definition: {
+ widgets: [expect.objectContaining({ id: "private-placement", x: 0 })],
+ },
+ });
+ const ownerWidgetRead = await makeZodVerifiedAPICall(
+ GetUnstableDashboardWidgetResponse,
+ "GET",
+ `/api/public/unstable/dashboard-widgets/${ownerWidget.body.id}`,
+ undefined,
+ auth,
+ );
+ expect(ownerWidgetRead.body.name).toBe("Private widget");
+ });
+
+ it("derives chartConfig on chartType changes and rejects contradictions", async () => {
+ const { auth } = await createOrgProjectAndApiKey();
+ const createdWidget = await makeZodVerifiedAPICall(
+ PostUnstableDashboardWidgetResponse,
+ "POST",
+ "/api/public/unstable/dashboard-widgets",
+ widget,
+ auth,
+ );
+
+ const contradiction = await makeAPICall(
+ "PATCH",
+ `/api/public/unstable/dashboard-widgets/${createdWidget.body.id}`,
+ { chartType: "PIE", chartConfig: { type: "NUMBER" } },
+ auth,
+ );
+ expect(contradiction.status).toBe(400);
+
+ // A bare chartType change resets the chartConfig to the new type.
+ const changed = await makeZodVerifiedAPICall(
+ PatchUnstableDashboardWidgetResponse,
+ "PATCH",
+ `/api/public/unstable/dashboard-widgets/${createdWidget.body.id}`,
+ { chartType: "PIE" },
+ auth,
+ );
+ expect(changed.body.chartType).toBe("PIE");
+ expect(changed.body.chartConfig).toEqual({ type: "PIE" });
+ });
+});
diff --git a/web/src/ee/features/in-app-agent/server/tools.ts b/web/src/ee/features/in-app-agent/server/tools.ts
index 83599ae2c9..69321e4062 100644
--- a/web/src/ee/features/in-app-agent/server/tools.ts
+++ b/web/src/ee/features/in-app-agent/server/tools.ts
@@ -314,6 +314,54 @@ export const IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES: Record<
approval: "approval",
availability: { scope: "dashboards:CUD" },
},
+ listDashboardWidgets: {
+ approval: "auto",
+ availability: { scope: "dashboards:read" },
+ },
+ getDashboardWidget: {
+ approval: "auto",
+ availability: { scope: "dashboards:read" },
+ },
+ updateDashboardWidget: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ deleteDashboardWidget: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ listDashboards: {
+ approval: "auto",
+ availability: { scope: "dashboards:read" },
+ },
+ getDashboard: {
+ approval: "auto",
+ availability: { scope: "dashboards:read" },
+ },
+ createDashboard: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ updateDashboard: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ deleteDashboard: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ addDashboardPlacement: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ updateDashboardPlacement: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
+ deleteDashboardPlacement: {
+ approval: "approval",
+ availability: { scope: "dashboards:CUD" },
+ },
};
export const IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES = new Set<McpToolName>(
diff --git a/web/src/features/audit-logs/auditLog.ts b/web/src/features/audit-logs/auditLog.ts
index 64a13aa895..97a85151a3 100644
--- a/web/src/features/audit-logs/auditLog.ts
+++ b/web/src/features/audit-logs/auditLog.ts
@@ -43,6 +43,7 @@ export type AuditableResource =
| "automation"
| "action"
| "dashboardWidget"
+ | "dashboard"
| "slackIntegration"
| "cloudSpendAlert"
| "verifiedDomain"
diff --git a/web/src/features/dashboard/server/public-dashboard-service.ts b/web/src/features/dashboard/server/public-dashboard-service.ts
new file mode 100644
index 0000000000..f09bd1b353
--- /dev/null
+++ b/web/src/features/dashboard/server/public-dashboard-service.ts
@@ -0,0 +1,414 @@
+import {
+ DashboardService,
+ type ApiAccessScope,
+ type DashboardDomain,
+} from "@langfuse/shared/src/server";
+import {
+ HOME_DASHBOARD_PRESET_IDS,
+ LangfuseConflictError,
+ LangfuseNotFoundError,
+} from "@langfuse/shared";
+import { auditLog } from "@/src/features/audit-logs/auditLog";
+import { DashboardSchema } from "@/src/features/public-api/types/unstable-dashboards";
+import type {
+ DashboardPlacementSchema,
+ PatchDashboardPlacementBody,
+ PatchUnstableDashboardBody,
+ PostDashboardPlacementBody,
+ PostUnstableDashboardBody,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import type { z } from "zod";
+import { randomUUID } from "crypto";
+
+type DashboardInput = z.infer<typeof PostUnstableDashboardBody>;
+type DashboardPatch = z.infer<typeof PatchUnstableDashboardBody>;
+type PublicPlacement = z.infer<typeof DashboardPlacementSchema>;
+type PlacementCreate = z.infer<typeof PostDashboardPlacementBody>;
+type PlacementPatch = z.infer<typeof PatchDashboardPlacementBody>;
+type InternalPlacement = DashboardDomain["definition"]["widgets"][number];
+
+// Matches the UI's add-widget default: a half-width (12-column grid) 6x6
+// tile appended below all existing tiles.
+const PLACEMENT_DEFAULT_SIZE = 6;
+
+// The public contract exposes placement sizes as width/height; storage and
+// the UI keep x_size/y_size.
+const toPublicPlacement = (placement: InternalPlacement): PublicPlacement =>
+ placement.type === "widget"
+ ? {
+ type: "widget",
+ id: placement.id,
+ widgetId: placement.widgetId,
+ x: placement.x,
+ y: placement.y,
+ width: placement.x_size,
+ height: placement.y_size,
+ }
+ : {
+ type: "preset",
+ id: placement.id,
+ presetId: placement.presetId,
+ x: placement.x,
+ y: placement.y,
+ width: placement.x_size,
+ height: placement.y_size,
+ };
+
+const toInternalPlacement = (placement: PublicPlacement): InternalPlacement =>
+ placement.type === "widget"
+ ? {
+ type: "widget",
+ id: placement.id,
+ widgetId: placement.widgetId,
+ x: placement.x,
+ y: placement.y,
+ x_size: placement.width,
+ y_size: placement.height,
+ }
+ : {
+ type: "preset",
+ id: placement.id,
+ presetId: placement.presetId,
+ x: placement.x,
+ y: placement.y,
+ x_size: placement.width,
+ y_size: placement.height,
+ };
+
+const toApiDashboard = (dashboard: DashboardDomain) =>
+ DashboardSchema.parse({
+ id: dashboard.id,
+ createdAt: dashboard.createdAt,
+ updatedAt: dashboard.updatedAt,
+ name: dashboard.name,
+ description: dashboard.description,
+ definition: {
+ widgets: dashboard.definition.widgets.map(toPublicPlacement),
+ },
+ filters: dashboard.filters,
+ });
+
+async function getProjectDashboardOrThrow(
+ projectId: string,
+ dashboardId: string,
+) {
+ const dashboard = await DashboardService.getDashboard(dashboardId, projectId);
+ if (!dashboard || dashboard.projectId !== projectId) {
+ throw new LangfuseNotFoundError(`Dashboard ${dashboardId} not found`);
+ }
+ return dashboard;
+}
+
+async function assertPlacementReferences(params: {
+ projectId: string;
+ placements: InternalPlacement[];
+}) {
+ await Promise.all(
+ params.placements.map(async (placement) => {
+ if (placement.type === "preset") {
+ if (
+ !(HOME_DASHBOARD_PRESET_IDS as readonly string[]).includes(
+ placement.presetId,
+ )
+ ) {
+ throw new LangfuseNotFoundError(
+ `Dashboard preset ${placement.presetId} not found`,
+ );
+ }
+ return;
+ }
+ // getWidget resolves project-owned and Langfuse-managed (projectId
+ // null) widgets; both are placeable, matching the UI.
+ const widget = await DashboardService.getWidget(
+ placement.widgetId,
+ params.projectId,
+ );
+ if (!widget) {
+ throw new LangfuseNotFoundError(
+ `Dashboard widget ${placement.widgetId} not found`,
+ );
+ }
+ }),
+ );
+}
+
+export async function listPublicDashboards(params: {
+ projectId: string;
+ page: number;
+ limit: number;
+}) {
+ const result = await DashboardService.listDashboards({
+ ...params,
+ includeLangfuseOwned: false,
+ });
+ return {
+ data: result.dashboards.map(toApiDashboard),
+ meta: {
+ page: params.page,
+ limit: params.limit,
+ totalItems: result.totalCount,
+ totalPages: Math.ceil(result.totalCount / params.limit),
+ },
+ };
+}
+
+export async function getPublicDashboard(params: {
+ projectId: string;
+ dashboardId: string;
+}) {
+ return toApiDashboard(
+ await getProjectDashboardOrThrow(params.projectId, params.dashboardId),
+ );
+}
+
+export async function createPublicDashboard(params: {
+ projectId: string;
+ input: DashboardInput;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const definition = params.input.definition
+ ? { widgets: params.input.definition.widgets.map(toInternalPlacement) }
+ : undefined;
+ if (definition) {
+ await assertPlacementReferences({
+ projectId: params.projectId,
+ placements: definition.widgets,
+ });
+ }
+ const dashboard = await DashboardService.createDashboard(
+ params.projectId,
+ params.input.name,
+ params.input.description,
+ undefined,
+ definition,
+ params.input.filters,
+ );
+ const result = toApiDashboard(dashboard);
+ await auditLog({
+ action: "create",
+ resourceType: "dashboard",
+ resourceId: dashboard.id,
+ projectId: params.projectId,
+ orgId: params.auditScope.orgId,
+ apiKeyId: params.auditScope.apiKeyId,
+ after: result,
+ });
+ return result;
+}
+
+export async function updatePublicDashboard(params: {
+ projectId: string;
+ dashboardId: string;
+ input: DashboardPatch;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectDashboardOrThrow(
+ params.projectId,
+ params.dashboardId,
+ );
+ const definition = params.input.definition
+ ? { widgets: params.input.definition.widgets.map(toInternalPlacement) }
+ : undefined;
+ if (definition) {
+ await assertPlacementReferences({
+ projectId: params.projectId,
+ placements: definition.widgets,
+ });
+ }
+ let dashboard = current;
+ if (
+ params.input.name !== undefined ||
+ params.input.description !== undefined
+ ) {
+ dashboard = await DashboardService.updateDashboard(
+ dashboard.id,
+ params.projectId,
+ params.input.name ?? dashboard.name,
+ params.input.description ?? dashboard.description,
+ );
+ }
+ if (definition !== undefined)
+ dashboard = await DashboardService.updateDashboardDefinition(
+ dashboard.id,
+ params.projectId,
+ definition,
+ );
+ if (params.input.filters !== undefined)
+ dashboard = await DashboardService.updateDashboardFilters(
+ dashboard.id,
+ params.projectId,
+ params.input.filters,
+ );
+ const result = toApiDashboard(dashboard);
+ await auditLog({
+ action: "update",
+ resourceType: "dashboard",
+ resourceId: dashboard.id,
+ projectId: params.projectId,
+ orgId: params.auditScope.orgId,
+ apiKeyId: params.auditScope.apiKeyId,
+ before: toApiDashboard(current),
+ after: result,
+ });
+ return result;
+}
+
+export async function deletePublicDashboard(params: {
+ projectId: string;
+ dashboardId: string;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectDashboardOrThrow(
+ params.projectId,
+ params.dashboardId,
+ );
+ await DashboardService.deleteDashboard(params.dashboardId, params.projectId);
+ await auditLog({
+ action: "delete",
+ resourceType: "dashboard",
+ resourceId: current.id,
+ projectId: params.projectId,
+ orgId: params.auditScope.orgId,
+ apiKeyId: params.auditScope.apiKeyId,
+ before: toApiDashboard(current),
+ });
+}
+
+// Shared write path for single-placement mutations. Unlike the full-definition
+// PATCH, callers validate only the placements they actually add or change.
+async function writeDashboardDefinition(params: {
+ projectId: string;
+ current: DashboardDomain;
+ widgets: InternalPlacement[];
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const dashboard = await DashboardService.updateDashboardDefinition(
+ params.current.id,
+ params.projectId,
+ { widgets: params.widgets },
+ );
+ await auditLog({
+ action: "update",
+ resourceType: "dashboard",
+ resourceId: dashboard.id,
+ projectId: params.projectId,
+ orgId: params.auditScope.orgId,
+ apiKeyId: params.auditScope.apiKeyId,
+ before: toApiDashboard(params.current),
+ after: toApiDashboard(dashboard),
+ });
+ return dashboard;
+}
+
+export async function addPublicDashboardPlacement(params: {
+ projectId: string;
+ dashboardId: string;
+ placement: PlacementCreate;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectDashboardOrThrow(
+ params.projectId,
+ params.dashboardId,
+ );
+ const maxY =
+ current.definition.widgets.length > 0
+ ? Math.max(
+ ...current.definition.widgets.map(
+ (placement) => placement.y + placement.y_size,
+ ),
+ )
+ : 0;
+ const placement: PublicPlacement = {
+ ...params.placement,
+ id: params.placement.id ?? randomUUID(),
+ x: params.placement.x ?? 0,
+ y: params.placement.y ?? maxY,
+ width: params.placement.width ?? PLACEMENT_DEFAULT_SIZE,
+ height: params.placement.height ?? PLACEMENT_DEFAULT_SIZE,
+ };
+ if (
+ current.definition.widgets.some((existing) => existing.id === placement.id)
+ )
+ throw new LangfuseConflictError(`Placement ${placement.id} already exists`);
+ const internalPlacement = toInternalPlacement(placement);
+ // Existing placements were validated when they were added; only the new
+ // placement's reference needs checking.
+ await assertPlacementReferences({
+ projectId: params.projectId,
+ placements: [internalPlacement],
+ });
+ await writeDashboardDefinition({
+ projectId: params.projectId,
+ current,
+ widgets: [...current.definition.widgets, internalPlacement],
+ auditScope: params.auditScope,
+ });
+ return placement;
+}
+
+export async function updatePublicDashboardPlacement(params: {
+ projectId: string;
+ dashboardId: string;
+ placementId: string;
+ placement: PlacementPatch;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectDashboardOrThrow(
+ params.projectId,
+ params.dashboardId,
+ );
+ const existing = current.definition.widgets.find(
+ (placement) => placement.id === params.placementId,
+ );
+ if (!existing)
+ throw new LangfuseNotFoundError(
+ `Placement ${params.placementId} not found`,
+ );
+ // Pure move/resize: the placement's content is immutable, so no reference
+ // re-validation is needed.
+ const updated: InternalPlacement = {
+ ...existing,
+ x: params.placement.x ?? existing.x,
+ y: params.placement.y ?? existing.y,
+ x_size: params.placement.width ?? existing.x_size,
+ y_size: params.placement.height ?? existing.y_size,
+ };
+ await writeDashboardDefinition({
+ projectId: params.projectId,
+ current,
+ widgets: current.definition.widgets.map((placement) =>
+ placement.id === params.placementId ? updated : placement,
+ ),
+ auditScope: params.auditScope,
+ });
+ return toPublicPlacement(updated);
+}
+
+export async function deletePublicDashboardPlacement(params: {
+ projectId: string;
+ dashboardId: string;
+ placementId: string;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectDashboardOrThrow(
+ params.projectId,
+ params.dashboardId,
+ );
+ if (
+ !current.definition.widgets.some(
+ (placement) => placement.id === params.placementId,
+ )
+ )
+ throw new LangfuseNotFoundError(
+ `Placement ${params.placementId} not found`,
+ );
+ await writeDashboardDefinition({
+ projectId: params.projectId,
+ current,
+ widgets: current.definition.widgets.filter(
+ (placement) => placement.id !== params.placementId,
+ ),
+ auditScope: params.auditScope,
+ });
+ return { message: "Placement successfully deleted" as const };
+}
diff --git a/web/src/features/mcp/features/dashboardWidgets/index.ts b/web/src/features/mcp/features/dashboardWidgets/index.ts
index 47f2ba0ca3..aa70c5ac0d 100644
--- a/web/src/features/mcp/features/dashboardWidgets/index.ts
+++ b/web/src/features/mcp/features/dashboardWidgets/index.ts
@@ -3,14 +3,63 @@ import {
createDashboardWidgetTool,
handleCreateDashboardWidget,
} from "./tools/createDashboardWidget";
+import * as dashboardCrud from "./tools/dashboardCrud";
export const dashboardWidgetsFeature = {
name: "dashboardWidgets",
description: "Manage dashboard widgets in the current Langfuse project",
tools: [
+ {
+ definition: dashboardCrud.listDashboardWidgetsTool,
+ handler: dashboardCrud.handleListDashboardWidgets,
+ },
{
definition: createDashboardWidgetTool,
handler: handleCreateDashboardWidget,
},
+ {
+ definition: dashboardCrud.getDashboardWidgetTool,
+ handler: dashboardCrud.handleGetDashboardWidget,
+ },
+ {
+ definition: dashboardCrud.updateDashboardWidgetTool,
+ handler: dashboardCrud.handleUpdateDashboardWidget,
+ },
+ {
+ definition: dashboardCrud.deleteDashboardWidgetTool,
+ handler: dashboardCrud.handleDeleteDashboardWidget,
+ },
+ {
+ definition: dashboardCrud.listDashboardsTool,
+ handler: dashboardCrud.handleListDashboards,
+ },
+ {
+ definition: dashboardCrud.getDashboardTool,
+ handler: dashboardCrud.handleGetDashboard,
+ },
+ {
+ definition: dashboardCrud.createDashboardTool,
+ handler: dashboardCrud.handleCreateDashboard,
+ },
+ {
+ definition: dashboardCrud.updateDashboardTool,
+ handler: dashboardCrud.handleUpdateDashboard,
+ },
+ {
+ definition: dashboardCrud.deleteDashboardTool,
+ handler: dashboardCrud.handleDeleteDashboard,
+ },
+ {
+ definition: dashboardCrud.addDashboardPlacementTool,
+ handler: dashboardCrud.handleAddDashboardPlacement,
+ },
+ {
+ definition: dashboardCrud.updateDashboardPlacementTool,
+ handler: dashboardCrud.handleUpdateDashboardPlacement,
+ },
+ {
+ definition: dashboardCrud.deleteDashboardPlacementTool,
+ handler: dashboardCrud.handleDeleteDashboardPlacement,
+ },
],
} as const satisfies McpFeatureModule;
diff --git a/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts b/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts
index b1bf4979f1..8982c9e368 100644
--- a/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts
+++ b/web/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget.ts
@@ -10,7 +10,7 @@ import {
} from "@/src/features/public-api/types/unstable-dashboard-widgets";
import { buildDashboardWidgetUrl } from "@/src/utils/product-url";
-const DashboardWidgetFilterBaseSchema = z
+export const DashboardWidgetFilterBaseSchema = z
.object({
column: z.string(),
operator: z.string(),
@@ -20,8 +20,8 @@ const DashboardWidgetFilterBaseSchema = z
})
.loose();
-const DashboardWidgetChartConfigBaseSchema = z.object({
- type: z.enum(DashboardWidgetChartType),
+export const DashboardWidgetChartConfigBaseSchema = z.object({
+ type: z.enum(DashboardWidgetChartType).optional(),
row_limit: z.number().int().positive().max(1000).optional(),
show_value_labels: z.boolean().optional(),
bins: z.number().int().min(1).max(100).optional(),
@@ -35,7 +35,10 @@ const DashboardWidgetChartConfigBaseSchema = z.object({
const CreateDashboardWidgetBaseSchema = z.object({
name: z.string().min(1).describe("Human-readable widget name."),
- description: z.string().describe("Human-readable widget description."),
+ description: z
+ .string()
+ .optional()
+ .describe("Human-readable widget description. Defaults to empty."),
view: PostUnstableDashboardWidgetView.describe(
"Data view for the widget. Traces widgets are not supported by this unstable API.",
),
@@ -59,24 +62,18 @@ const CreateDashboardWidgetBaseSchema = z.object({
"Widget filters in the same shape as exported dashboard widget JSON.",
),
chartType: z.enum(DashboardWidgetChartType),
- chartConfig: DashboardWidgetChartConfigBaseSchema.describe(
- "Chart-specific config. chartConfig.type must match chartType.",
+ chartConfig: DashboardWidgetChartConfigBaseSchema.optional().describe(
+ "Chart-specific config. Optional; type defaults to chartType and must match it when given.",
),
- minVersion: z
- .number()
- .int()
- .min(2)
- .optional()
- .describe("Widget data-model version. Defaults to 2."),
});
export const [createDashboardWidgetTool, handleCreateDashboardWidget] =
defineTool({
name: "createDashboardWidget",
description: [
- "Create a reusable dashboard widget.",
+ "Create a dashboard widget (a standalone chart definition you place on any dashboard).",
"Widgets are useful to visualize Langfuse project data and give informative breakdowns to the user.",
- "This creates the widget only; placing it on a dashboard requires updating that dashboard's definition in the Langfuse UI.",
+ "This creates the widget only; place it on a dashboard with the addDashboardPlacement tool.",
"The result includes a url field; use it to link to the created widget.",
].join(" "),
baseSchema: CreateDashboardWidgetBaseSchema,
diff --git a/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts b/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
new file mode 100644
index 0000000000..e76f28ffe8
--- /dev/null
+++ b/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
@@ -0,0 +1,438 @@
+import { z } from "zod";
+import { DashboardWidgetChartType } from "@langfuse/shared";
+import { metricAggregations } from "@langfuse/shared/query";
+import { defineTool } from "@/src/features/mcp/core/define-tool";
+import { runMcpTool } from "@/src/features/mcp/core/run-mcp-tool";
+import {
+ DashboardWidgetChartConfigBaseSchema,
+ DashboardWidgetFilterBaseSchema,
+} from "@/src/features/mcp/features/dashboardWidgets/tools/createDashboardWidget";
+import {
+ buildDashboardUrl,
+ buildDashboardWidgetUrl,
+} from "@/src/utils/product-url";
+import {
+ GetUnstableDashboardWidgetsQuery,
+ DashboardWidgetIdQuery,
+ PatchUnstableDashboardWidgetBody,
+} from "@/src/features/public-api/types/unstable-dashboard-widgets";
+import {
+ deletePublicDashboardWidget,
+ getPublicDashboardWidget,
+ listPublicDashboardWidgets,
+ updatePublicDashboardWidget,
+} from "@/src/features/widgets/server/public-dashboard-widget-service";
+import {
+ DashboardIdQuery,
+ GetUnstableDashboardsQuery,
+ PatchUnstableDashboardBody,
+ PostUnstableDashboardBody,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import {
+ addPublicDashboardPlacement,
+ createPublicDashboard,
+ deletePublicDashboard,
+ deletePublicDashboardPlacement,
+ getPublicDashboard,
+ listPublicDashboards,
+ updatePublicDashboard,
+ updatePublicDashboardPlacement,
+} from "@/src/features/dashboard/server/public-dashboard-service";
+
+const auditScope = (context: { orgId: string; apiKeyId: string }) => ({
+ orgId: context.orgId,
+ apiKeyId: context.apiKeyId,
+});
+// On add, id and position are optional: the service generates an id and
+// appends below existing tiles with the UI's default 6x6 size.
+const placementCreateBaseSchema = z.object({
+ type: z.enum(["widget", "preset"]),
+ id: z.string().optional(),
+ widgetId: z.string().optional(),
+ presetId: z.string().optional(),
+ x: z.number().int().gte(0).optional(),
+ y: z.number().int().gte(0).optional(),
+ width: z.number().int().positive().optional(),
+ height: z.number().int().positive().optional(),
+});
+// Placements are moved/resized in place; content and id are immutable.
+const placementPatchBaseSchema = z.object({
+ x: z.number().int().gte(0).optional(),
+ y: z.number().int().gte(0).optional(),
+ width: z.number().int().positive().optional(),
+ height: z.number().int().positive().optional(),
+});
+const dashboardWidgetPatchBaseSchema = z.object({
+ widgetId: z.string(),
+ name: z.string().min(1).optional(),
+ description: z.string().optional(),
+ view: z
+ .enum(["observations", "scores-numeric", "scores-categorical"])
+ .optional(),
+ dimensions: z.array(z.object({ field: z.string() })).optional(),
+ metrics: z
+ .array(z.object({ measure: z.string(), agg: metricAggregations }))
+ .optional(),
+ filters: z.array(DashboardWidgetFilterBaseSchema).optional(),
+ chartType: z.enum(DashboardWidgetChartType).optional(),
+ chartConfig: DashboardWidgetChartConfigBaseSchema.optional(),
+});
+const dashboardPatchBaseSchema = z.object({
+ dashboardId: z.string(),
+ name: z.string().min(1).optional(),
+ description: z.string().optional(),
+ filters: z.array(z.object({}).loose()).optional(),
+ definition: z.object({ widgets: z.array(z.object({}).loose()) }).optional(),
+});
+const dashboardCreateBaseSchema = z.object({
+ name: z.string().min(1),
+ description: z.string().optional(),
+ filters: z.array(z.object({}).loose()).optional(),
+ definition: z.object({ widgets: z.array(z.object({}).loose()) }).optional(),
+});
+// NOTE: object-level refinements do not survive `.shape` spreads, so every
+// schema built via `.extend(x.shape)` below must re-apply them explicitly.
+const requirePlacementIds = (
+ placement: z.infer<typeof placementCreateBaseSchema>,
+ ctx: z.RefinementCtx,
+) => {
+ if (placement.type === "widget" && !placement.widgetId)
+ ctx.addIssue({
+ code: "custom",
+ path: ["widgetId"],
+ message: "widgetId is required for widget placements",
+ });
+ if (placement.type === "preset" && !placement.presetId)
+ ctx.addIssue({
+ code: "custom",
+ path: ["presetId"],
+ message: "presetId is required for preset placements",
+ });
+};
+const requirePatchField =
+ (idKeys: string[]) =>
+ (value: Record<string, unknown>, ctx: z.RefinementCtx) => {
+ const patchKeys = Object.keys(value).filter(
+ (key) => !idKeys.includes(key) && value[key] !== undefined,
+ );
+ if (patchKeys.length === 0)
+ ctx.addIssue({
+ code: "custom",
+ message: "At least one field is required",
+ });
+ };
+// Extract the placement fields from an MCP add-placement input (which also
+// carries dashboardId).
+const toPlacementCreate = (
+ placement: z.infer<typeof placementCreateBaseSchema>,
+) =>
+ placement.type === "widget"
+ ? {
+ type: "widget" as const,
+ id: placement.id,
+ widgetId: placement.widgetId!,
+ x: placement.x,
+ y: placement.y,
+ width: placement.width,
+ height: placement.height,
+ }
+ : {
+ type: "preset" as const,
+ id: placement.id,
+ presetId: placement.presetId!,
+ x: placement.x,
+ y: placement.y,
+ width: placement.width,
+ height: placement.height,
+ };
+
+export const [listDashboardWidgetsTool, handleListDashboardWidgets] =
+ defineTool({
+ name: "listDashboardWidgets",
+ description: "List dashboard widgets in the current project.",
+ baseSchema: GetUnstableDashboardWidgetsQuery,
+ inputSchema: GetUnstableDashboardWidgetsQuery,
+ readOnlyHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboard_widgets.list",
+ context,
+ fn: async () => {
+ const result = await listPublicDashboardWidgets({
+ projectId: context.projectId,
+ ...input,
+ });
+ return {
+ ...result,
+ data: result.data.map((widget) => ({
+ ...widget,
+ url: buildDashboardWidgetUrl({
+ projectId: context.projectId,
+ widgetId: widget.id,
+ }),
+ })),
+ };
+ },
+ }),
+ });
+export const [getDashboardWidgetTool, handleGetDashboardWidget] = defineTool({
+ name: "getDashboardWidget",
+ description: "Get a dashboard widget by ID.",
+ baseSchema: DashboardWidgetIdQuery,
+ inputSchema: DashboardWidgetIdQuery,
+ readOnlyHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboard_widgets.get",
+ context,
+ fn: async () => ({
+ ...(await getPublicDashboardWidget({
+ projectId: context.projectId,
+ widgetId: input.widgetId,
+ })),
+ url: buildDashboardWidgetUrl({
+ projectId: context.projectId,
+ widgetId: input.widgetId,
+ }),
+ }),
+ }),
+});
+export const [updateDashboardWidgetTool, handleUpdateDashboardWidget] =
+ defineTool({
+ name: "updateDashboardWidget",
+ description: "Partially update a dashboard widget.",
+ baseSchema: dashboardWidgetPatchBaseSchema,
+ inputSchema: DashboardWidgetIdQuery.extend(
+ PatchUnstableDashboardWidgetBody.shape,
+ ).superRefine(requirePatchField(["widgetId"])),
+ destructiveHint: true,
+ handler: ({ widgetId, ...patch }, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboard_widgets.update",
+ context,
+ fn: async () =>
+ updatePublicDashboardWidget({
+ projectId: context.projectId,
+ widgetId,
+ input: patch,
+ auditScope: auditScope(context),
+ }),
+ }),
+ });
+export const [deleteDashboardWidgetTool, handleDeleteDashboardWidget] =
+ defineTool({
+ name: "deleteDashboardWidget",
+ description:
+ "Delete a dashboard widget. It must first be removed from every dashboard placement.",
+ baseSchema: DashboardWidgetIdQuery,
+ inputSchema: DashboardWidgetIdQuery,
+ destructiveHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboard_widgets.delete",
+ context,
+ fn: async () => {
+ await deletePublicDashboardWidget({
+ projectId: context.projectId,
+ widgetId: input.widgetId,
+ auditScope: auditScope(context),
+ });
+ return { message: "Dashboard widget successfully deleted" };
+ },
+ }),
+ });
+
+export const [listDashboardsTool, handleListDashboards] = defineTool({
+ name: "listDashboards",
+ description: "List editable dashboards in the current project.",
+ baseSchema: GetUnstableDashboardsQuery,
+ inputSchema: GetUnstableDashboardsQuery,
+ readOnlyHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.list",
+ context,
+ fn: async () => {
+ const result = await listPublicDashboards({
+ projectId: context.projectId,
+ ...input,
+ });
+ return {
+ ...result,
+ data: result.data.map((dashboard) => ({
+ ...dashboard,
+ url: buildDashboardUrl({
+ projectId: context.projectId,
+ dashboardId: dashboard.id,
+ }),
+ })),
+ };
+ },
+ }),
+});
+export const [getDashboardTool, handleGetDashboard] = defineTool({
+ name: "getDashboard",
+ description:
+ "Get an editable dashboard by ID, including its current layout: " +
+ "definition.widgets lists every placement with 12-column-grid " +
+ "coordinates (x/y top-left cell, width/height in cells).",
+ baseSchema: DashboardIdQuery,
+ inputSchema: DashboardIdQuery,
+ readOnlyHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.get",
+ context,
+ fn: async () => ({
+ ...(await getPublicDashboard({
+ projectId: context.projectId,
+ dashboardId: input.dashboardId,
+ })),
+ url: buildDashboardUrl({
+ projectId: context.projectId,
+ dashboardId: input.dashboardId,
+ }),
+ }),
+ }),
+});
+export const [createDashboardTool, handleCreateDashboard] = defineTool({
+ name: "createDashboard",
+ description: "Create an editable dashboard.",
+ baseSchema: dashboardCreateBaseSchema,
+ inputSchema: PostUnstableDashboardBody,
+ destructiveHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.create",
+ context,
+ fn: () =>
+ createPublicDashboard({
+ projectId: context.projectId,
+ input,
+ auditScope: auditScope(context),
+ }),
+ }),
+});
+export const [updateDashboardTool, handleUpdateDashboard] = defineTool({
+ name: "updateDashboard",
+ description:
+ "Partially update dashboard metadata, filters, or its complete definition.",
+ baseSchema: dashboardPatchBaseSchema,
+ inputSchema: DashboardIdQuery.extend(
+ PatchUnstableDashboardBody.shape,
+ ).superRefine(requirePatchField(["dashboardId"])),
+ destructiveHint: true,
+ handler: ({ dashboardId, ...patch }, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.update",
+ context,
+ fn: () =>
+ updatePublicDashboard({
+ projectId: context.projectId,
+ dashboardId,
+ input: patch,
+ auditScope: auditScope(context),
+ }),
+ }),
+});
+export const [deleteDashboardTool, handleDeleteDashboard] = defineTool({
+ name: "deleteDashboard",
+ description: "Delete an editable dashboard.",
+ baseSchema: DashboardIdQuery,
+ inputSchema: DashboardIdQuery,
+ destructiveHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.delete",
+ context,
+ fn: async () => {
+ await deletePublicDashboard({
+ projectId: context.projectId,
+ dashboardId: input.dashboardId,
+ auditScope: auditScope(context),
+ });
+ return { message: "Dashboard successfully deleted" };
+ },
+ }),
+});
+
+const placementQuery = DashboardIdQuery.extend({ placementId: z.string() });
+export const [addDashboardPlacementTool, handleAddDashboardPlacement] =
+ defineTool({
+ name: "addDashboardPlacement",
+ description:
+ "Add a widget or preset placement to a dashboard's 12-column grid. " +
+ "Prefer omitting id and position: the server generates an id and " +
+ "appends the tile below existing ones at the default 6x6 size. Explicit " +
+ "positions are not checked for overlap. After adding, call getDashboard " +
+ "to verify the full grid arrangement; use updateDashboardPlacement to " +
+ "move or resize the new tile when needed. Returns the created placement. " +
+ "If the user has the dashboard open, remind them to refresh the page to " +
+ "see the new widget.",
+ baseSchema: DashboardIdQuery.extend(placementCreateBaseSchema.shape),
+ inputSchema: DashboardIdQuery.extend(
+ placementCreateBaseSchema.shape,
+ ).superRefine(requirePlacementIds),
+ destructiveHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.placements.add",
+ context,
+ fn: () =>
+ addPublicDashboardPlacement({
+ projectId: context.projectId,
+ dashboardId: input.dashboardId,
+ placement: toPlacementCreate(input),
+ auditScope: auditScope(context),
+ }),
+ }),
+ });
+export const [updateDashboardPlacementTool, handleUpdateDashboardPlacement] =
+ defineTool({
+ name: "updateDashboardPlacement",
+ description:
+ "Move or resize an existing dashboard placement on the 12-column " +
+ "grid. Pass any of x, y (top-left cell), width, height (in cells); " +
+ "omitted fields keep their current value. The placement's content " +
+ "and id cannot change. Use getDashboard to read the current layout " +
+ "first. Overlaps are not checked. Returns the updated placement.",
+ baseSchema: placementQuery.extend(placementPatchBaseSchema.shape),
+ inputSchema: placementQuery
+ .extend(placementPatchBaseSchema.shape)
+ .superRefine(requirePatchField(["dashboardId", "placementId"])),
+ destructiveHint: true,
+ handler: ({ dashboardId, placementId, ...patch }, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.placements.update",
+ context,
+ fn: () =>
+ updatePublicDashboardPlacement({
+ projectId: context.projectId,
+ dashboardId,
+ placementId,
+ placement: patch,
+ auditScope: auditScope(context),
+ }),
+ }),
+ });
+export const [deleteDashboardPlacementTool, handleDeleteDashboardPlacement] =
+ defineTool({
+ name: "deleteDashboardPlacement",
+ description:
+ "Remove a placement from a dashboard without deleting the underlying widget.",
+ baseSchema: placementQuery,
+ inputSchema: placementQuery,
+ destructiveHint: true,
+ handler: (input, context) =>
+ runMcpTool({
+ spanName: "mcp.dashboards.placements.delete",
+ context,
+ fn: () =>
+ deletePublicDashboardPlacement({
+ projectId: context.projectId,
+ dashboardId: input.dashboardId,
+ placementId: input.placementId,
+ auditScope: auditScope(context),
+ }),
+ }),
+ });
diff --git a/web/src/features/public-api/types/unstable-dashboard-widgets.ts b/web/src/features/public-api/types/unstable-dashboard-widgets.ts
index eeaeaea696..7230fe8d2f 100644
--- a/web/src/features/public-api/types/unstable-dashboard-widgets.ts
+++ b/web/src/features/public-api/types/unstable-dashboard-widgets.ts
@@ -23,26 +23,29 @@ const DashboardWidgetDimensionSchema = DimensionSchema.extend({
field: z.string().min(1),
});
-export const PostUnstableDashboardWidgetBody = z
+// Input-side chart config: `type` is optional and defaults to the widget's
+// chartType; per-type option validation happens in the service after the
+// type is resolved.
+const DashboardWidgetChartConfigInput = z
.object({
- name: z.string().min(1, "Widget name is required"),
- description: z.string(),
- view: PostUnstableDashboardWidgetView,
- dimensions: z.array(DashboardWidgetDimensionSchema),
- metrics: z.array(DashboardWidgetMetricSchema).min(1),
- filters: z.array(singleFilter),
- chartType: z.enum(DashboardWidgetChartType),
- chartConfig: ChartConfigSchema,
- minVersion: z.number().int().min(2).optional(),
+ type: z.enum(DashboardWidgetChartType).optional(),
})
- .superRefine((widget, ctx) => {
- if (widget.chartConfig.type !== widget.chartType) {
- ctx.addIssue({
- code: "custom",
- path: ["chartConfig", "type"],
- message: "chartConfig.type must match chartType",
- });
- }
+ .loose();
+
+const UnstableDashboardWidgetBody = z.object({
+ name: z.string().min(1, "Widget name is required"),
+ description: z.string(),
+ view: PostUnstableDashboardWidgetView,
+ dimensions: z.array(DashboardWidgetDimensionSchema),
+ metrics: z.array(DashboardWidgetMetricSchema).min(1),
+ filters: z.array(singleFilter),
+ chartType: z.enum(DashboardWidgetChartType),
+ chartConfig: DashboardWidgetChartConfigInput.optional(),
+});
+
+export const PostUnstableDashboardWidgetBody =
+ UnstableDashboardWidgetBody.extend({
+ description: z.string().default(""),
});
export const PublicDashboardWidget = z
@@ -58,12 +61,36 @@ export const PublicDashboardWidget = z
filters: z.array(singleFilter),
chartType: z.enum(DashboardWidgetChartType),
chartConfig: ChartConfigSchema,
- minVersion: z.number().int().min(2),
})
.strict();
export const PostUnstableDashboardWidgetResponse = PublicDashboardWidget;
+export const GetUnstableDashboardWidgetsQuery = z.object({
+ page: z.coerce.number().int().positive().default(1),
+ limit: z.coerce.number().int().positive().max(100).default(50),
+});
+export const GetUnstableDashboardWidgetsResponse = z.object({
+ data: z.array(PublicDashboardWidget),
+ meta: z.object({
+ page: z.number(),
+ limit: z.number(),
+ totalItems: z.number(),
+ totalPages: z.number(),
+ }),
+});
+export const DashboardWidgetIdQuery = z.object({ widgetId: z.string() });
+export const GetUnstableDashboardWidgetResponse = PublicDashboardWidget;
+export const PatchUnstableDashboardWidgetBody =
+ UnstableDashboardWidgetBody.partial().refine(
+ (value) => Object.keys(value).length > 0,
+ "At least one field is required",
+ );
+export const PatchUnstableDashboardWidgetResponse = PublicDashboardWidget;
+export const DeleteUnstableDashboardWidgetResponse = z.object({
+ message: z.literal("Dashboard widget successfully deleted"),
+});
+
export type PostUnstableDashboardWidgetBodyType = z.infer<
typeof PostUnstableDashboardWidgetBody
>;
diff --git a/web/src/features/public-api/types/unstable-dashboards.ts b/web/src/features/public-api/types/unstable-dashboards.ts
new file mode 100644
index 0000000000..eecdd27915
--- /dev/null
+++ b/web/src/features/public-api/types/unstable-dashboards.ts
@@ -0,0 +1,128 @@
+import { z } from "zod";
+import { singleFilter } from "@langfuse/shared";
+
+const pagination = z.object({
+ page: z.coerce.number().int().positive().default(1),
+ limit: z.coerce.number().int().positive().max(100).default(50),
+});
+
+// Public placement shape. Sizes are exposed as width/height in grid cells;
+// storage and the UI keep x_size/y_size — the public-dashboard-service maps
+// between the two.
+const placementPosition = {
+ x: z.number().int().gte(0),
+ y: z.number().int().gte(0),
+ width: z.number().int().positive(),
+ height: z.number().int().positive(),
+};
+export const PublicWidgetPlacementSchema = z
+ .object({
+ type: z.literal("widget"),
+ id: z.string(),
+ widgetId: z.string(),
+ ...placementPosition,
+ })
+ .strict();
+export const PublicPresetPlacementSchema = z
+ .object({
+ type: z.literal("preset"),
+ id: z.string(),
+ presetId: z.string(),
+ ...placementPosition,
+ })
+ .strict();
+export const DashboardPlacementSchema = z.discriminatedUnion("type", [
+ PublicWidgetPlacementSchema,
+ PublicPresetPlacementSchema,
+]);
+export const PublicDashboardDefinitionSchema = z
+ .object({
+ widgets: z.array(DashboardPlacementSchema),
+ })
+ .refine(
+ (definition) =>
+ new Set(definition.widgets.map((placement) => placement.id)).size ===
+ definition.widgets.length,
+ "Placement ids must be unique",
+ );
+
+export const DashboardSchema = z
+ .object({
+ id: z.string(),
+ createdAt: z.coerce.date(),
+ updatedAt: z.coerce.date(),
+ name: z.string(),
+ description: z.string(),
+ definition: PublicDashboardDefinitionSchema,
+ filters: z.array(singleFilter),
+ })
+ .strict();
+
+export const GetUnstableDashboardsQuery = pagination;
+export const GetUnstableDashboardsResponse = z.object({
+ data: z.array(DashboardSchema),
+ meta: z.object({
+ page: z.number(),
+ limit: z.number(),
+ totalItems: z.number(),
+ totalPages: z.number(),
+ }),
+});
+
+export const PostUnstableDashboardBody = z.object({
+ name: z.string().min(1),
+ description: z.string().default(""),
+ definition: PublicDashboardDefinitionSchema.optional(),
+ filters: z.array(singleFilter).optional(),
+});
+export const PostUnstableDashboardResponse = DashboardSchema;
+
+export const DashboardIdQuery = z.object({ dashboardId: z.string() });
+export const GetUnstableDashboardResponse = DashboardSchema;
+export const PatchUnstableDashboardBody = z
+ .object({
+ name: z.string().min(1).optional(),
+ description: z.string().optional(),
+ definition: PublicDashboardDefinitionSchema.optional(),
+ filters: z.array(singleFilter).optional(),
+ })
+ .refine(
+ (value) => Object.keys(value).length > 0,
+ "At least one field is required",
+ );
+export const PatchUnstableDashboardResponse = DashboardSchema;
+export const DeleteUnstableDashboardResponse = z.object({
+ message: z.literal("Dashboard successfully deleted"),
+});
+
+export const DashboardPlacementQuery = z.object({
+ dashboardId: z.string(),
+ placementId: z.string(),
+});
+// On create, id and grid position are optional: the server generates an id
+// and appends the placement below existing tiles with the UI's default size.
+const placementCreateOptionalFields = {
+ id: true,
+ x: true,
+ y: true,
+ width: true,
+ height: true,
+} as const;
+export const PostDashboardPlacementBody = z.discriminatedUnion("type", [
+ PublicWidgetPlacementSchema.partial(placementCreateOptionalFields),
+ PublicPresetPlacementSchema.partial(placementCreateOptionalFields),
+]);
+export const PostDashboardPlacementResponse = DashboardPlacementSchema;
+// Placements are moved/resized in place; the widget/preset reference and the
+// id are immutable (delete + add to swap content).
+export const PatchDashboardPlacementBody = z
+ .object(placementPosition)
+ .partial()
+ .refine(
+ (value) => Object.keys(value).length > 0,
+ "At least one field is required",
+ );
+export const PatchDashboardPlacementResponse = DashboardPlacementSchema;
+export const DeleteDashboardPlacementResponse = z.object({
+ message: z.literal("Placement successfully deleted"),
+});
diff --git a/web/src/features/widgets/server/public-dashboard-widget-service.ts b/web/src/features/widgets/server/public-dashboard-widget-service.ts
index 690d24c966..c5c30e5068 100644
--- a/web/src/features/widgets/server/public-dashboard-widget-service.ts
+++ b/web/src/features/widgets/server/public-dashboard-widget-service.ts
@@ -20,6 +20,7 @@ import {
PostUnstableDashboardWidgetResponse,
type PostUnstableDashboardWidgetBodyType,
} from "@/src/features/public-api/types/unstable-dashboard-widgets";
+import { ChartConfigSchema, LangfuseNotFoundError } from "@langfuse/shared";
import {
getWidgetImportFilterConfig,
partitionStoredUiTableFiltersToView,
@@ -29,6 +30,13 @@ import {
MAX_PIVOT_TABLE_METRICS,
} from "@/src/features/widgets/utils/pivot-table-utils";
+// The widget shape used internally after input normalization: the public
+// body with chartConfig fully resolved plus the internal minVersion.
+type NormalizedWidgetInput = Omit<
+ z.infer<typeof PostUnstableDashboardWidgetResponse>,
+ "id" | "createdAt" | "updatedAt"
+> & { minVersion: number };
+
const viewMapping: Record<
PostUnstableDashboardWidgetBodyType["view"],
DashboardWidgetViews
@@ -67,14 +75,12 @@ const throwInvalidWidget = (params: {
});
};
-function getWidgetViewVersion(
- widget: PostUnstableDashboardWidgetBodyType,
-): ViewVersion {
- return (widget.minVersion ?? 2) >= 2 ? "v2" : "v1";
+function getWidgetViewVersion(widget: { minVersion: number }): ViewVersion {
+ return widget.minVersion >= 2 ? "v2" : "v1";
}
function getPublicDashboardWidgetViewDeclaration(
- widget: PostUnstableDashboardWidgetBodyType,
+ widget: NormalizedWidgetInput,
): ReturnType<typeof getViewDeclaration> {
const viewVersion = getWidgetViewVersion(widget);
@@ -90,7 +96,8 @@ function getPublicDashboardWidgetViewDeclaration(
export function normalizePublicDashboardWidgetInput(
input: PostUnstableDashboardWidgetBodyType,
-): PostUnstableDashboardWidgetBodyType {
+ minVersion = 2,
+): NormalizedWidgetInput {
const { mappedFilters, unsupportedFilters } =
partitionStoredUiTableFiltersToView(input.view, input.filters);
const { allowedColumns, columnAliases } = getWidgetImportFilterConfig(
@@ -116,18 +123,41 @@ export function normalizePublicDashboardWidgetInput(
});
}
+ // chartConfig.type defaults to chartType; when given explicitly it must
+ // match. Per-type option validation happens after the type is resolved.
+ const chartConfigType = input.chartConfig?.type ?? input.chartType;
+ if (chartConfigType !== input.chartType) {
+ throwInvalidWidget({
+ message: "chartConfig.type must match chartType",
+ field: "chartConfig.type",
+ });
+ }
+ const chartConfig = ChartConfigSchema.safeParse({
+ ...input.chartConfig,
+ type: chartConfigType,
+ });
+ if (!chartConfig.success) {
+ return throwInvalidWidget({
+ message: `Invalid chartConfig: ${chartConfig.error.issues
+ .map((issue) => `${issue.path.join(".")}: ${issue.message}`)
+ .join(", ")}`,
+ field: "chartConfig",
+ });
+ }
+
return {
...input,
filters: mappedFilters.map((filter) => ({
...filter,
column: columnAliases[filter.column] ?? filter.column,
})),
- minVersion: input.minVersion ?? 2,
+ chartConfig: chartConfig.data,
+ minVersion,
};
}
export function validatePublicDashboardWidgetInput(
- widget: PostUnstableDashboardWidgetBodyType,
+ widget: NormalizedWidgetInput,
): void {
const viewVersion = getWidgetViewVersion(widget);
const viewDeclaration = getPublicDashboardWidgetViewDeclaration(widget);
@@ -219,7 +249,6 @@ export function toApiDashboardWidget(widget: WidgetDomain) {
filters: widget.filters,
chartType: widget.chartType,
chartConfig: widget.chartConfig,
- minVersion: widget.minVersion,
});
}
@@ -248,3 +277,117 @@ export async function createPublicDashboardWidget(params: {
return toApiDashboardWidget(widget);
}
+
+function toPublicWidgetInput(widget: WidgetDomain) {
+ const {
+ id: _id,
+ createdAt: _createdAt,
+ updatedAt: _updatedAt,
+ ...input
+ } = toApiDashboardWidget(widget);
+ return input;
+}
+
+async function getProjectWidgetOrThrow(projectId: string, widgetId: string) {
+ const widget = await DashboardService.getWidget(widgetId, projectId);
+ if (!widget || widget.projectId !== projectId) {
+ throw new LangfuseNotFoundError(`Dashboard widget ${widgetId} not found`);
+ }
+ return widget;
+}
+
+export async function listPublicDashboardWidgets(params: {
+ projectId: string;
+ page: number;
+ limit: number;
+}) {
+ const result = await DashboardService.listWidgets(params);
+ return {
+ data: result.widgets.map(toApiDashboardWidget),
+ meta: {
+ page: params.page,
+ limit: params.limit,
+ totalItems: result.totalCount,
+ totalPages: Math.ceil(result.totalCount / params.limit),
+ },
+ };
+}
+
+export async function getPublicDashboardWidget(params: {
+ projectId: string;
+ widgetId: string;
+}) {
+ return toApiDashboardWidget(
+ await getProjectWidgetOrThrow(params.projectId, params.widgetId),
+ );
+}
+
+export async function updatePublicDashboardWidget(params: {
+ projectId: string;
+ widgetId: string;
+ input: Partial<PostUnstableDashboardWidgetBodyType>;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectWidgetOrThrow(
+ params.projectId,
+ params.widgetId,
+ );
+ const currentPublic = toPublicWidgetInput(current);
+ const chartTypeChanged =
+ params.input.chartType !== undefined &&
+ params.input.chartType !== currentPublic.chartType;
+ const input = normalizePublicDashboardWidgetInput(
+ {
+ ...currentPublic,
+ ...params.input,
+ // A chartType change without an explicit chartConfig resets the config
+ // to the new type; carrying the stale config type over would always
+ // fail validation.
+ chartConfig:
+ params.input.chartConfig ??
+ (chartTypeChanged
+ ? { type: params.input.chartType }
+ : currentPublic.chartConfig),
+ },
+ current.minVersion,
+ );
+ validatePublicDashboardWidgetInput(input);
+ const updated = await DashboardService.updateWidget(
+ params.projectId,
+ params.widgetId,
+ { ...input, view: viewMapping[input.view] },
+ );
+ const result = toApiDashboardWidget(updated);
+ await auditLog({
+ action: "update",
+ resourceType: "dashboardWidget",
+ resourceId: updated.id,
+ projectId: params.projectId,
+ orgId: params.auditScope.orgId,
+ apiKeyId: params.auditScope.apiKeyId,
+ before: toApiDashboardWidget(current),
+ after: result,
+ });
+ return result;
+}
+
+export async function deletePublicDashboardWidget(params: {
+ projectId: string;
+ widgetId: string;
+ auditScope: Pick<ApiAccessScope, "orgId" | "apiKeyId">;
+}) {
+ const current = await getProjectWidgetOrThrow(
+ params.projectId,
+ params.widgetId,
+ );
+ await DashboardService.deleteWidget(params.widgetId, params.projectId);
+ await auditLog({
+ action: "delete",
+ resourceType: "dashboardWidget",
+ resourceId: current.id,
+ projectId: params.projectId,
+ orgId: params.auditScope.orgId,
+ apiKeyId: params.auditScope.apiKeyId,
+ before: toApiDashboardWidget(current),
+ });
+}
diff --git a/web/src/pages/api/public/unstable/dashboard-widgets/[widgetId].ts b/web/src/pages/api/public/unstable/dashboard-widgets/[widgetId].ts
new file mode 100644
index 0000000000..4d5a0a245e
--- /dev/null
+++ b/web/src/pages/api/public/unstable/dashboard-widgets/[widgetId].ts
@@ -0,0 +1,55 @@
+import {
+ createUnstablePublicApiRoute,
+ withUnstablePublicApiMiddlewares,
+} from "@/src/features/public-api/server/unstable-public-api-route";
+import {
+ DashboardWidgetIdQuery,
+ DeleteUnstableDashboardWidgetResponse,
+ GetUnstableDashboardWidgetResponse,
+ PatchUnstableDashboardWidgetBody,
+ PatchUnstableDashboardWidgetResponse,
+} from "@/src/features/public-api/types/unstable-dashboard-widgets";
+import {
+ deletePublicDashboardWidget,
+ getPublicDashboardWidget,
+ updatePublicDashboardWidget,
+} from "@/src/features/widgets/server/public-dashboard-widget-service";
+
+export default withUnstablePublicApiMiddlewares({
+ GET: createUnstablePublicApiRoute({
+ name: "Get Unstable Dashboard Widget",
+ querySchema: DashboardWidgetIdQuery,
+ responseSchema: GetUnstableDashboardWidgetResponse,
+ fn: ({ query, auth }) =>
+ getPublicDashboardWidget({
+ projectId: auth.scope.projectId,
+ widgetId: query.widgetId,
+ }),
+ }),
+ PATCH: createUnstablePublicApiRoute({
+ name: "Update Unstable Dashboard Widget",
+ querySchema: DashboardWidgetIdQuery,
+ bodySchema: PatchUnstableDashboardWidgetBody,
+ responseSchema: PatchUnstableDashboardWidgetResponse,
+ fn: ({ query, body, auth }) =>
+ updatePublicDashboardWidget({
+ projectId: auth.scope.projectId,
+ widgetId: query.widgetId,
+ input: body,
+ auditScope: auth.scope,
+ }),
+ }),
+ DELETE: createUnstablePublicApiRoute({
+ name: "Delete Unstable Dashboard Widget",
+ querySchema: DashboardWidgetIdQuery,
+ responseSchema: DeleteUnstableDashboardWidgetResponse,
+ fn: async ({ query, auth }) => {
+ await deletePublicDashboardWidget({
+ projectId: auth.scope.projectId,
+ widgetId: query.widgetId,
+ auditScope: auth.scope,
+ });
+ return { message: "Dashboard widget successfully deleted" as const };
+ },
+ }),
+});
diff --git a/web/src/pages/api/public/unstable/dashboard-widgets/index.ts b/web/src/pages/api/public/unstable/dashboard-widgets/index.ts
index 4d9b887aa7..a7aaf39c2a 100644
--- a/web/src/pages/api/public/unstable/dashboard-widgets/index.ts
+++ b/web/src/pages/api/public/unstable/dashboard-widgets/index.ts
@@ -3,12 +3,24 @@ import {
withUnstablePublicApiMiddlewares,
} from "@/src/features/public-api/server/unstable-public-api-route";
import {
+ GetUnstableDashboardWidgetsQuery,
+ GetUnstableDashboardWidgetsResponse,
PostUnstableDashboardWidgetBody,
PostUnstableDashboardWidgetResponse,
} from "@/src/features/public-api/types/unstable-dashboard-widgets";
-import { createPublicDashboardWidget } from "@/src/features/widgets/server/public-dashboard-widget-service";
+import {
+ createPublicDashboardWidget,
+ listPublicDashboardWidgets,
+} from "@/src/features/widgets/server/public-dashboard-widget-service";
export default withUnstablePublicApiMiddlewares({
+ GET: createUnstablePublicApiRoute({
+ name: "List Unstable Dashboard Widgets",
+ querySchema: GetUnstableDashboardWidgetsQuery,
+ responseSchema: GetUnstableDashboardWidgetsResponse,
+ fn: ({ query, auth }) =>
+ listPublicDashboardWidgets({ projectId: auth.scope.projectId, ...query }),
+ }),
POST: createUnstablePublicApiRoute({
name: "Create Unstable Dashboard Widget",
bodySchema: PostUnstableDashboardWidgetBody,
diff --git a/web/src/pages/api/public/unstable/dashboards/[dashboardId].ts b/web/src/pages/api/public/unstable/dashboards/[dashboardId].ts
new file mode 100644
index 0000000000..7154e403a9
--- /dev/null
+++ b/web/src/pages/api/public/unstable/dashboards/[dashboardId].ts
@@ -0,0 +1,55 @@
+import {
+ createUnstablePublicApiRoute,
+ withUnstablePublicApiMiddlewares,
+} from "@/src/features/public-api/server/unstable-public-api-route";
+import {
+ DashboardIdQuery,
+ DeleteUnstableDashboardResponse,
+ GetUnstableDashboardResponse,
+ PatchUnstableDashboardBody,
+ PatchUnstableDashboardResponse,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import {
+ deletePublicDashboard,
+ getPublicDashboard,
+ updatePublicDashboard,
+} from "@/src/features/dashboard/server/public-dashboard-service";
+
+export default withUnstablePublicApiMiddlewares({
+ GET: createUnstablePublicApiRoute({
+ name: "Get Unstable Dashboard",
+ querySchema: DashboardIdQuery,
+ responseSchema: GetUnstableDashboardResponse,
+ fn: ({ query, auth }) =>
+ getPublicDashboard({
+ projectId: auth.scope.projectId,
+ dashboardId: query.dashboardId,
+ }),
+ }),
+ PATCH: createUnstablePublicApiRoute({
+ name: "Update Unstable Dashboard",
+ querySchema: DashboardIdQuery,
+ bodySchema: PatchUnstableDashboardBody,
+ responseSchema: PatchUnstableDashboardResponse,
+ fn: ({ query, body, auth }) =>
+ updatePublicDashboard({
+ projectId: auth.scope.projectId,
+ dashboardId: query.dashboardId,
+ input: body,
+ auditScope: auth.scope,
+ }),
+ }),
+ DELETE: createUnstablePublicApiRoute({
+ name: "Delete Unstable Dashboard",
+ querySchema: DashboardIdQuery,
+ responseSchema: DeleteUnstableDashboardResponse,
+ fn: async ({ query, auth }) => {
+ await deletePublicDashboard({
+ projectId: auth.scope.projectId,
+ dashboardId: query.dashboardId,
+ auditScope: auth.scope,
+ });
+ return { message: "Dashboard successfully deleted" as const };
+ },
+ }),
+});
diff --git a/web/src/pages/api/public/unstable/dashboards/[dashboardId]/placements/[placementId].ts b/web/src/pages/api/public/unstable/dashboards/[dashboardId]/placements/[placementId].ts
new file mode 100644
index 0000000000..c409a86bab
--- /dev/null
+++ b/web/src/pages/api/public/unstable/dashboards/[dashboardId]/placements/[placementId].ts
@@ -0,0 +1,41 @@
+import {
+ createUnstablePublicApiRoute,
+ withUnstablePublicApiMiddlewares,
+} from "@/src/features/public-api/server/unstable-public-api-route";
+import {
+ DashboardPlacementQuery,
+ DeleteDashboardPlacementResponse,
+ PatchDashboardPlacementBody,
+ PatchDashboardPlacementResponse,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import {
+ deletePublicDashboardPlacement,
+ updatePublicDashboardPlacement,
+} from "@/src/features/dashboard/server/public-dashboard-service";
+
+export default withUnstablePublicApiMiddlewares({
+ PATCH: createUnstablePublicApiRoute({
+ name: "Update Unstable Dashboard Placement",
+ querySchema: DashboardPlacementQuery,
+ bodySchema: PatchDashboardPlacementBody,
+ responseSchema: PatchDashboardPlacementResponse,
+ fn: ({ query, body, auth }) =>
+ updatePublicDashboardPlacement({
+ projectId: auth.scope.projectId,
+ ...query,
+ placement: body,
+ auditScope: auth.scope,
+ }),
+ }),
+ DELETE: createUnstablePublicApiRoute({
+ name: "Delete Unstable Dashboard Placement",
+ querySchema: DashboardPlacementQuery,
+ responseSchema: DeleteDashboardPlacementResponse,
+ fn: ({ query, auth }) =>
+ deletePublicDashboardPlacement({
+ projectId: auth.scope.projectId,
+ ...query,
+ auditScope: auth.scope,
+ }),
+ }),
+});
diff --git a/web/src/pages/api/public/unstable/dashboards/[dashboardId]/placements/index.ts b/web/src/pages/api/public/unstable/dashboards/[dashboardId]/placements/index.ts
new file mode 100644
index 0000000000..e8198be2fd
--- /dev/null
+++ b/web/src/pages/api/public/unstable/dashboards/[dashboardId]/placements/index.ts
@@ -0,0 +1,26 @@
+import {
+ createUnstablePublicApiRoute,
+ withUnstablePublicApiMiddlewares,
+} from "@/src/features/public-api/server/unstable-public-api-route";
+import {
+ DashboardIdQuery,
+ PostDashboardPlacementBody,
+ PostDashboardPlacementResponse,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import { addPublicDashboardPlacement } from "@/src/features/dashboard/server/public-dashboard-service";
+
+export default withUnstablePublicApiMiddlewares({
+ POST: createUnstablePublicApiRoute({
+ name: "Add Unstable Dashboard Placement",
+ querySchema: DashboardIdQuery,
+ bodySchema: PostDashboardPlacementBody,
+ responseSchema: PostDashboardPlacementResponse,
+ fn: ({ query, body, auth }) =>
+ addPublicDashboardPlacement({
+ projectId: auth.scope.projectId,
+ dashboardId: query.dashboardId,
+ placement: body,
+ auditScope: auth.scope,
+ }),
+ }),
+});
diff --git a/web/src/pages/api/public/unstable/dashboards/index.ts b/web/src/pages/api/public/unstable/dashboards/index.ts
new file mode 100644
index 0000000000..f03808f646
--- /dev/null
+++ b/web/src/pages/api/public/unstable/dashboards/index.ts
@@ -0,0 +1,35 @@
+import {
+ createUnstablePublicApiRoute,
+ withUnstablePublicApiMiddlewares,
+} from "@/src/features/public-api/server/unstable-public-api-route";
+import {
+ GetUnstableDashboardsQuery,
+ GetUnstableDashboardsResponse,
+ PostUnstableDashboardBody,
+ PostUnstableDashboardResponse,
+} from "@/src/features/public-api/types/unstable-dashboards";
+import {
+ createPublicDashboard,
+ listPublicDashboards,
+} from "@/src/features/dashboard/server/public-dashboard-service";
+
+export default withUnstablePublicApiMiddlewares({
+ GET: createUnstablePublicApiRoute({
+ name: "List Unstable Dashboards",
+ querySchema: GetUnstableDashboardsQuery,
+ responseSchema: GetUnstableDashboardsResponse,
+ fn: ({ query, auth }) =>
+ listPublicDashboards({ projectId: auth.scope.projectId, ...query }),
+ }),
+ POST: createUnstablePublicApiRoute({
+ name: "Create Unstable Dashboard",
+ bodySchema: PostUnstableDashboardBody,
+ responseSchema: PostUnstableDashboardResponse,
+ fn: ({ body, auth }) =>
+ createPublicDashboard({
+ projectId: auth.scope.projectId,
+ input: body,
+ auditScope: auth.scope,
+ }),
+ }),
+});
diff --git a/web/src/utils/product-url.ts b/web/src/utils/product-url.ts
index f9ea717d53..766750e52a 100644
--- a/web/src/utils/product-url.ts
+++ b/web/src/utils/product-url.ts
@@ -488,6 +488,14 @@ export const buildDashboardWidgetUrl = (params: {
widgetId: string;
}) => buildProductUrl(buildDashboardWidgetPath(params));
+export const buildDashboardUrl = (params: {
+ projectId: string;
+ dashboardId: string;
+}) =>
+ buildProductUrl(
+ `${buildDashboardsPath(params)}/${encodeURIComponent(params.dashboardId)}`,
+ );
+
export const buildEvaluatorUrl = (params: {
projectId: string;
evaluatorId: string;