@mastra/mcp-apps-components 0.1.0-alpha.4 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/dashboard-views.d.ts +39 -0
- package/dist/dashboard-views.d.ts.map +1 -0
- package/dist/dashboards.cjs +60 -0
- package/dist/dashboards.cjs.map +1 -0
- package/dist/dashboards.d.ts +187 -0
- package/dist/dashboards.d.ts.map +1 -0
- package/dist/dashboards.js +52 -0
- package/dist/dashboards.js.map +1 -0
- package/dist/index.cjs +11 -1062
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1058
- package/dist/index.js.map +1 -1
- package/dist/observability-dashboard-B85sO-8E.cjs +1351 -0
- package/dist/observability-dashboard-B85sO-8E.cjs.map +1 -0
- package/dist/observability-dashboard-r5BPo6Aq.js +1286 -0
- package/dist/observability-dashboard-r5BPo6Aq.js.map +1 -0
- package/dist/observability-dashboard.d.ts +44 -1
- package/dist/observability-dashboard.d.ts.map +1 -1
- package/package.json +17 -6
package/README.md
CHANGED
|
@@ -197,6 +197,78 @@ const host = useMemo(
|
|
|
197
197
|
|
|
198
198
|
To let the user pin widgets too, add `pins: { pinnedIds, onPin, onUnpin }`. `observabilityWidgetPins` is the same helper with only pins.
|
|
199
199
|
|
|
200
|
+
### Validating stored dashboards
|
|
201
|
+
|
|
202
|
+
`dashboardDefinitionSchema` from `@mastra/core/storage/dashboards` checks a definition's structure and queries, but not what each widget kind needs. A definition can pass it and still show an error in place of a widget. To store only dashboards that draw, check every write with `strictDashboardDefinitionSchema` in the code that stores them:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { strictDashboardDefinitionSchema } from '@mastra/mcp-apps-components/dashboards';
|
|
206
|
+
import type { StrictDashboardDefinition } from '@mastra/mcp-apps-components/dashboards';
|
|
207
|
+
|
|
208
|
+
const result = strictDashboardDefinitionSchema.safeParse(body.definition);
|
|
209
|
+
if (!result.success) {
|
|
210
|
+
// Each issue has a path to the view, or into its options
|
|
211
|
+
throw new BadRequestError(result.error.issues);
|
|
212
|
+
}
|
|
213
|
+
const definition: StrictDashboardDefinition = result.data;
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
On top of core's checks, the schema:
|
|
217
|
+
|
|
218
|
+
- Rejects widget kinds other than `kpis`, `table`, `timeseries` and `scores`.
|
|
219
|
+
- Checks each view's `options`, and each table column's `options`, against the kind's own schema.
|
|
220
|
+
- Rejects `columns` on views of widgets that aren't tables. The renderer ignores them, but they usually mean the widget was written as another kind.
|
|
221
|
+
- Runs each kind's checks, such as a KPI reading a query its view has, or a chart's series all fitting its buckets.
|
|
222
|
+
- Checks the widget at both `org` and `project` scope, so a widget that only breaks on one kind of page is rejected too.
|
|
223
|
+
|
|
224
|
+
Problems in a view's options point into them, such as `rows.0.widgets.1.views.0.options.series.0.value`. Problems a kind finds, such as a KPI reading a query its view doesn't have or two views with one label, point at the view, such as `rows.0.widgets.1.views.0`, with a message saying what's wrong, such as `options: reads query 'nope', which the view doesn't have`. All of a definition's problems come back together, so one fix can address them all.
|
|
225
|
+
|
|
226
|
+
`result.data` is the definition you passed in, unchanged; store it as sent. A definition that passes still passes after core's `dashboardDefinitionSchema` has parsed it and filled in its defaults, so you can check what you store either way. Use `strictDashboardWidgetSchema` to check a single widget, such as one being added or pinned; its issue paths start at the widget. Checks across widgets, such as unique ids and the widget limit, need the full definition.
|
|
227
|
+
|
|
228
|
+
Don't use these schemas in a request-body schema. Their input type is `unknown` and their JSON schema is empty, so a request type built from them would type `definition` as `unknown`, and generated API docs would describe it as anything. Keep core's `dashboardDefinitionSchema` there, and check with the strict schemas in the service before storing. Use `StrictDashboardDefinition` to type what you store and return.
|
|
229
|
+
|
|
230
|
+
Dashboards with custom widget kinds should keep using core's `dashboardDefinitionSchema`.
|
|
231
|
+
|
|
232
|
+
### Saving dashboards a model writes
|
|
233
|
+
|
|
234
|
+
A model writes a widget more reliably from a schema that spells out each kind's options than from an open object. `createObservabilityDraftSchemas` returns the schemas the dashboard tool takes, for a single widget (`widget`) and a whole dashboard (`dashboard`), to use as the input of tools that save them. Convert what the model wrote with `toObservabilityWidget` or `toObservabilityDashboard`:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import { createTool } from '@mastra/core/tools';
|
|
238
|
+
import {
|
|
239
|
+
createObservabilityDraftSchemas,
|
|
240
|
+
toObservabilityDashboard,
|
|
241
|
+
toObservabilityWidget,
|
|
242
|
+
} from '@mastra/mcp-apps-components/dashboards';
|
|
243
|
+
|
|
244
|
+
const schemas = createObservabilityDraftSchemas(
|
|
245
|
+
{ metricNames: await listMetricNames() },
|
|
246
|
+
{ kinds: ['kpis', 'timeseries', 'table'], dashboardFilters: false },
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const addWidget = createTool({
|
|
250
|
+
id: 'addWidget',
|
|
251
|
+
description: 'Adds a widget to the dashboard',
|
|
252
|
+
inputSchema: schemas.widget,
|
|
253
|
+
execute: async widget => saveWidget(toObservabilityWidget(widget)),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const createDashboard = createTool({
|
|
257
|
+
id: 'createDashboard',
|
|
258
|
+
description: 'Creates a dashboard',
|
|
259
|
+
inputSchema: schemas.dashboard,
|
|
260
|
+
execute: async dashboard => saveDashboard(toObservabilityDashboard({ dashboard }).dashboard),
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
- **Options:** `kinds` lists the widget kinds a model can write, and `dashboardFilters: false` limits a dashboard's `defaults` to `datePreset`. What you leave out is missing from the JSON schema the model sees, and rejected when a model writes it anyway. Narrowing `kinds` doesn't narrow the TypeScript types.
|
|
265
|
+
- **One call per catalog:** Build both tools' schemas from one call. Building takes about a millisecond, so it's fine to build them per request.
|
|
266
|
+
- **Ids:** `toObservabilityWidget` keeps a widget's `id` when the model gives one, so a widget can be pinned or replaced by it, and assigns a fresh UUID otherwise. `toObservabilityDashboard` does the same for each widget.
|
|
267
|
+
- **Converting outside a tool:** `toObservabilityWidget` and `toObservabilityDashboard` check against the default schemas, which allow every kind and metric name. Inside a tool built as above, its input schema has already applied your catalog and options. Anywhere else, check the draft against your schemas first, such as with `schemas.widget.parse(draft)`.
|
|
268
|
+
- **Errors:** As tool input schemas, the schemas reject a draft before `execute` runs, with paths into what the model wrote, such as `timeseries.series.1.value` for a widget or `rows.0.widgets.0.timeseries.series.1.value` for a dashboard. Nested under a field of a larger input, paths start with that field's name. `toObservabilityWidget` throws an error whose `cause` is the `ZodError`, with the same paths. Checks across widgets, such as unique ids and the widget limit, need the whole dashboard.
|
|
269
|
+
|
|
270
|
+
A draft that passes converts to a widget that passes `strictDashboardWidgetSchema`. Keep checking with the strict schemas where you store dashboards, since they also cover writes that don't come from a draft.
|
|
271
|
+
|
|
200
272
|
## Documentation
|
|
201
273
|
|
|
202
274
|
- [MCP Apps in Mastra](https://mastra.ai/docs/connections/mcp)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { DashboardBuiltInWidgetKind, DashboardWidget, DashboardWidgetView } from '@mastra/core/storage/dashboards';
|
|
2
|
+
import type { z } from 'zod/v4';
|
|
3
|
+
export type DashboardScope = 'org' | 'project';
|
|
4
|
+
/** A view as a kind's checks read it: its options parsed, its columns those at the scope. */
|
|
5
|
+
type CheckedView = Omit<DashboardWidgetView, 'options'> & {
|
|
6
|
+
options: any;
|
|
7
|
+
};
|
|
8
|
+
export type KindCheck = {
|
|
9
|
+
optionsSchema: z.ZodType;
|
|
10
|
+
issues?: (view: CheckedView) => string[];
|
|
11
|
+
};
|
|
12
|
+
/** A problem with a widget, its path relative to the widget. */
|
|
13
|
+
export type WidgetIssue = {
|
|
14
|
+
path: PropertyKey[];
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
/** How each built-in kind checks a view: the options it accepts, then what it checks beyond them. */
|
|
18
|
+
export declare const KIND_CHECKS: Record<DashboardBuiltInWidgetKind, KindCheck>;
|
|
19
|
+
/** Whether a widget, view or column tagged with `scope` shows at the page's scope. */
|
|
20
|
+
export declare const inScope: (item: {
|
|
21
|
+
scope?: DashboardScope;
|
|
22
|
+
}, scope: DashboardScope) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* What the renderer rejects in the widget's views at `scope`, in the order it finds them: options
|
|
25
|
+
* parsed, then the kind's own issues, then labels unique. Takes a widget core's schema accepts.
|
|
26
|
+
* Views in `skipKindChecks` skip the kind's own issues, for callers that already report them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function viewIssues(widget: DashboardWidget, check: KindCheck, scope: DashboardScope, skipKindChecks?: ReadonlySet<number>): WidgetIssue[];
|
|
29
|
+
export declare const zodIssues: (error: z.ZodError, prefix: PropertyKey[]) => WidgetIssue[];
|
|
30
|
+
/**
|
|
31
|
+
* What the renderer would reject in a widget core accepts, paths relative to the widget. Every
|
|
32
|
+
* view's options and columns are parsed; the kind's own checks then run at each scope the widget
|
|
33
|
+
* shows at, as the renderer runs them there, skipping views whose options or columns don't parse.
|
|
34
|
+
* All problems come back together. It also rejects columns on views that aren't tables, which the
|
|
35
|
+
* renderer ignores.
|
|
36
|
+
*/
|
|
37
|
+
export declare function widgetIssues(widget: DashboardWidget): WidgetIssue[];
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=dashboard-views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboard-views.d.ts","sourceRoot":"","sources":["../src/dashboard-views.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAUxH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAOhC,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,SAAS,CAAC;AAE/C,6FAA6F;AAC7F,KAAK,WAAW,GAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,SAAS,GAAG;IAAE,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,EAAE,CAAA;CAAE,CAAC;AAE/F,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,qGAAqG;AACrG,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,0BAA0B,EAAE,SAAS,CAWrE,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,OAAO,SAAU;IAAE,KAAK,CAAC,EAAE,cAAc,CAAA;CAAE,SAAS,cAAc,YAC7B,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,cAAc,EACrB,cAAc,GAAE,WAAW,CAAC,MAAM,CAAa,GAC9C,WAAW,EAAE,CA8Bf;AAID,eAAO,MAAM,SAAS,UAAW,CAAC,CAAC,QAAQ,UAAU,WAAW,EAAE,KAAG,WAAW,EACW,CAAC;AAE5F;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,EAAE,CAuCnE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_observability_dashboard = require("./observability-dashboard-B85sO-8E.cjs");
|
|
3
|
+
let _mastra_core_storage_dashboards = require("@mastra/core/storage/dashboards");
|
|
4
|
+
let zod_v4 = require("zod/v4");
|
|
5
|
+
// src/dashboards.ts
|
|
6
|
+
const report = (ctx, issues, prefix = []) => {
|
|
7
|
+
for (const issue of issues) ctx.addIssue({
|
|
8
|
+
code: "custom",
|
|
9
|
+
path: [...prefix, ...issue.path],
|
|
10
|
+
message: issue.message
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* One widget as the dashboard renderer draws it: core's `dashboardWidgetSchema`, a built-in kind,
|
|
15
|
+
* options that kind accepts, and nothing else it would reject, at every scope the widget shows at.
|
|
16
|
+
* It also rejects columns on views that aren't tables: the renderer ignores them, but they usually
|
|
17
|
+
* mean the widget was written as another kind. Paths are relative to the widget. Unique widget ids, the widget count and the size limit are the
|
|
18
|
+
* definition's to check, so check the whole definition with `strictDashboardDefinitionSchema` too
|
|
19
|
+
* before storing it.
|
|
20
|
+
*
|
|
21
|
+
* Parsing returns the widget as given: no defaults are filled in. It's a validator, not a schema to
|
|
22
|
+
* show a model: its JSON schema is empty. Its input type is `unknown`, so check with it where you
|
|
23
|
+
* store, not in a request schema.
|
|
24
|
+
*/
|
|
25
|
+
const strictDashboardWidgetSchema = zod_v4.z.unknown().superRefine((value, ctx) => {
|
|
26
|
+
const core = _mastra_core_storage_dashboards.dashboardWidgetSchema.safeParse(value);
|
|
27
|
+
if (!core.success) return report(ctx, require_observability_dashboard.zodIssues(core.error, []));
|
|
28
|
+
report(ctx, require_observability_dashboard.widgetIssues(value));
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* A dashboard definition as the dashboard renderer draws it: core's `dashboardDefinitionSchema`,
|
|
32
|
+
* then every widget as `strictDashboardWidgetSchema` checks it, paths from the definition (e.g.
|
|
33
|
+
* `rows.0.widgets.1.views.0.options.series.0.value`; problems a kind finds point at the view).
|
|
34
|
+
* Check every definition with it before storing it, so each stored widget renders. Widgets of a
|
|
35
|
+
* host's own kinds are rejected: check those with core's schema.
|
|
36
|
+
*
|
|
37
|
+
* Parsing returns the definition as given: no defaults are filled in. It's a validator, not a
|
|
38
|
+
* schema to show a model: its JSON schema is empty. Its input type is `unknown`, so check with it
|
|
39
|
+
* where you store, not in a request schema.
|
|
40
|
+
*/
|
|
41
|
+
const strictDashboardDefinitionSchema = zod_v4.z.unknown().superRefine((value, ctx) => {
|
|
42
|
+
const core = _mastra_core_storage_dashboards.dashboardDefinitionSchema.safeParse(value);
|
|
43
|
+
if (!core.success) return report(ctx, require_observability_dashboard.zodIssues(core.error, []));
|
|
44
|
+
for (const [r, row] of value.rows.entries()) for (const [w, widget] of row.widgets.entries()) report(ctx, require_observability_dashboard.widgetIssues(widget), [
|
|
45
|
+
"rows",
|
|
46
|
+
r,
|
|
47
|
+
"widgets",
|
|
48
|
+
w
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
exports.OBSERVABILITY_CATALOG_MAX_METRIC_NAMES = require_observability_dashboard.OBSERVABILITY_CATALOG_MAX_METRIC_NAMES;
|
|
52
|
+
exports.createObservabilityDraftSchemas = require_observability_dashboard.createObservabilityDraftSchemas;
|
|
53
|
+
exports.createObservabilityWidgetInputSchema = require_observability_dashboard.createObservabilityWidgetInputSchema;
|
|
54
|
+
exports.observabilityWidgetInputSchema = require_observability_dashboard.observabilityWidgetInputSchema;
|
|
55
|
+
exports.strictDashboardDefinitionSchema = strictDashboardDefinitionSchema;
|
|
56
|
+
exports.strictDashboardWidgetSchema = strictDashboardWidgetSchema;
|
|
57
|
+
exports.toObservabilityDashboard = require_observability_dashboard.toObservabilityDashboard;
|
|
58
|
+
exports.toObservabilityWidget = require_observability_dashboard.toObservabilityWidget;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=dashboards.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboards.cjs","names":["z","dashboardWidgetSchema","zodIssues","widgetIssues","dashboardDefinitionSchema"],"sources":["../src/dashboards.ts"],"sourcesContent":["import { dashboardDefinitionSchema, dashboardWidgetSchema } from '@mastra/core/storage/dashboards';\nimport type {\n DashboardColumn,\n DashboardDefinition,\n DashboardWidget,\n DashboardWidgetView,\n} from '@mastra/core/storage/dashboards';\nimport { z } from 'zod/v4';\nimport { widgetIssues, zodIssues } from './dashboard-views';\nimport type { WidgetIssue } from './dashboard-views';\n\nexport {\n OBSERVABILITY_CATALOG_MAX_METRIC_NAMES,\n createObservabilityDraftSchemas,\n createObservabilityWidgetInputSchema,\n observabilityWidgetInputSchema,\n toObservabilityDashboard,\n toObservabilityWidget,\n} from './observability-dashboard';\nexport type {\n ObservabilityCatalog,\n ObservabilityDashboardDraft,\n ObservabilityDashboardInput,\n ObservabilityDashboardOpened,\n ObservabilityDraftOptions,\n ObservabilityDraftSchemas,\n ObservabilityWidgetDraft,\n} from './observability-dashboard';\n\n/*\n * Dashboards to store, and the drafts a model writes them as. The stored format is checked at least\n * as strictly as the dashboard renderer checks it: core's `dashboardDefinitionSchema`, then each\n * widget's kind, each view's options and each table column's options, then what each kind checks\n * beyond its schema (queries an option names, labels, ...). It also rejects columns on views that\n * aren't tables, which the renderer ignores. A draft (`createObservabilityDraftSchemas`) converts to\n * a widget or definition that passes those checks.\n *\n * The types are written out here rather than inferred, so this entry's declarations need nothing\n * beyond `@mastra/core` and `zod`; the package's tests check they match the kinds' own schemas.\n */\n\n/** A number read from one of the view's queries, named by its `id`. */\nexport type DashboardValueRef = {\n query: string;\n field?: 'value' | 'estimatedCost';\n measure?: string;\n percentile?: number;\n groups?: string[];\n notGroups?: string[];\n};\n\n/** A number a view shows: a query's value, or a fixed combination of several. */\nexport type DashboardValueExpr =\n | DashboardValueRef\n | { const: number }\n | { sum: DashboardValueExpr[] }\n | { minus: [DashboardValueExpr, DashboardValueExpr] }\n | { ratio: { of: DashboardValueExpr; over: DashboardValueExpr } }\n | { max: DashboardValueExpr[] }\n | { coalesce: DashboardValueExpr[] };\n\nexport type DashboardValueFormat = 'count' | 'usd' | 'duration' | 'percent' | 'score';\n\nexport type DashboardChartColor = 'green' | 'sky' | 'violet' | 'teal' | 'indigo' | 'warning' | 'error' | 'neutral';\n\n/** A `kpis` view's options: a row of headline numbers. */\nexport type DashboardKpisOptions = {\n items: {\n label: string;\n icon: 'bot' | 'coins' | 'hash' | 'threads';\n format: 'count' | 'usd';\n value: DashboardValueExpr;\n detail: string;\n lowerIsBetter?: boolean;\n }[];\n};\n\n/** A `table` column's options, told apart by `type`. */\nexport type DashboardTableColumnOptions =\n | {\n type: 'name';\n as?: 'project';\n unnamed?: string;\n mark?: { icon: 'agent' | 'workflow' | 'tool' } | { providerDimension: string };\n description?: string;\n width?: string;\n sortable?: boolean;\n }\n | {\n type: 'dimension';\n dimension: string;\n as?: 'project';\n query?: string;\n joinOn?: string;\n description?: string;\n width?: string;\n sortable?: boolean;\n }\n | {\n type: 'value';\n value: DashboardValueExpr;\n format: 'count' | 'usd' | 'duration' | 'percent';\n emphasis?: boolean;\n missing?: number;\n additive?: boolean;\n better?: 'higher' | 'lower';\n unpricedWhen?: string;\n description?: string;\n width?: string;\n sortable?: boolean;\n }\n | { type: 'change'; description?: string };\n\n/** A `table` view's options: one row per group. */\nexport type DashboardTableOptions = {\n groupBy: string[];\n defaultSort: { column: string; direction: 'asc' | 'desc' };\n pageSize?: number;\n emptyMessage: string;\n ariaLabel?: string;\n hideUnnamed?: boolean;\n dropped?: boolean;\n openWhen?: { minRows: number };\n rowDrilldown?: {\n fields: Record<\n string,\n | 'projectId'\n | 'entityName'\n | 'threadId'\n | 'resourceId'\n | 'environment'\n | 'sessionId'\n | 'userId'\n | 'model'\n | 'provider'\n >;\n spanTypes?: string[];\n keepEmpty?: boolean;\n };\n};\n\n/** A `timeseries` view's options: values per time bucket as stacked bars or lines. */\nexport type DashboardTimeseriesOptions = {\n chart: 'stackedBar' | 'line';\n format: DashboardValueFormat;\n axis?: boolean;\n series: {\n dataKey: string;\n label: string;\n color: DashboardChartColor;\n emphasis?: boolean;\n value: DashboardValueExpr;\n rangeTotal?: DashboardValueExpr;\n round?: boolean;\n }[];\n buckets?: 'chart' | 'api';\n totals?: string[];\n hideEmpty?: boolean;\n emphasizeFirst?: boolean;\n xLabels?: 'edges';\n flatYDomain?: [number, number];\n yDomain?: [number, number];\n total?: { value: 'total' | { peak: string } | DashboardValueExpr; format?: DashboardValueFormat };\n /** @deprecated Accepted so saved definitions still parse. */\n emptyMessage?: string;\n emptyWhenZero?: DashboardValueExpr;\n};\n\n/** A `scores` view's options: one line per scorer. */\nexport type DashboardScoresOptions = {\n average: string;\n series: string;\n /** @deprecated Accepted so saved definitions still parse. */\n emptyMessage?: string;\n};\n\n/** A table column whose options its kind accepts. */\nexport type StrictDashboardTableColumn = Omit<DashboardColumn, 'options'> & { options: DashboardTableColumnOptions };\n\n/** A view whose options its kind accepts. Only table views have columns. */\nexport type StrictDashboardWidgetView<Options, Column = never> = Omit<DashboardWidgetView, 'options' | 'columns'> & {\n options: Options;\n columns?: Column[];\n};\n\ntype WidgetOf<Kind extends string, Options, Column = never> = Omit<DashboardWidget, 'kind' | 'views'> & {\n kind: Kind;\n views: StrictDashboardWidgetView<Options, Column>[];\n};\n\n/** A widget of a built-in kind that the dashboard renderer can draw. */\nexport type StrictDashboardWidget =\n | WidgetOf<'kpis', DashboardKpisOptions>\n | WidgetOf<'table', DashboardTableOptions, StrictDashboardTableColumn>\n | WidgetOf<'timeseries', DashboardTimeseriesOptions>\n | WidgetOf<'scores', DashboardScoresOptions>;\n\n/** A dashboard definition whose every widget the dashboard renderer can draw. */\nexport type StrictDashboardDefinition = Omit<DashboardDefinition, 'rows'> & {\n rows: { widgets: StrictDashboardWidget[] }[];\n};\n\ntype Issue = WidgetIssue;\n\nconst report = (ctx: z.RefinementCtx, issues: Issue[], prefix: PropertyKey[] = []) => {\n for (const issue of issues) {\n ctx.addIssue({ code: 'custom', path: [...prefix, ...issue.path], message: issue.message });\n }\n};\n\n/**\n * One widget as the dashboard renderer draws it: core's `dashboardWidgetSchema`, a built-in kind,\n * options that kind accepts, and nothing else it would reject, at every scope the widget shows at.\n * It also rejects columns on views that aren't tables: the renderer ignores them, but they usually\n * mean the widget was written as another kind. Paths are relative to the widget. Unique widget ids, the widget count and the size limit are the\n * definition's to check, so check the whole definition with `strictDashboardDefinitionSchema` too\n * before storing it.\n *\n * Parsing returns the widget as given: no defaults are filled in. It's a validator, not a schema to\n * show a model: its JSON schema is empty. Its input type is `unknown`, so check with it where you\n * store, not in a request schema.\n */\nexport const strictDashboardWidgetSchema: z.ZodType<StrictDashboardWidget> = z.unknown().superRefine((value, ctx) => {\n const core = dashboardWidgetSchema.safeParse(value);\n if (!core.success) return report(ctx, zodIssues(core.error, []));\n report(ctx, widgetIssues(value as DashboardWidget));\n}) as z.ZodType<StrictDashboardWidget>;\n\n/**\n * A dashboard definition as the dashboard renderer draws it: core's `dashboardDefinitionSchema`,\n * then every widget as `strictDashboardWidgetSchema` checks it, paths from the definition (e.g.\n * `rows.0.widgets.1.views.0.options.series.0.value`; problems a kind finds point at the view).\n * Check every definition with it before storing it, so each stored widget renders. Widgets of a\n * host's own kinds are rejected: check those with core's schema.\n *\n * Parsing returns the definition as given: no defaults are filled in. It's a validator, not a\n * schema to show a model: its JSON schema is empty. Its input type is `unknown`, so check with it\n * where you store, not in a request schema.\n */\nexport const strictDashboardDefinitionSchema: z.ZodType<StrictDashboardDefinition> = z\n .unknown()\n .superRefine((value, ctx) => {\n const core = dashboardDefinitionSchema.safeParse(value);\n if (!core.success) return report(ctx, zodIssues(core.error, []));\n for (const [r, row] of (value as DashboardDefinition).rows.entries()) {\n for (const [w, widget] of row.widgets.entries()) {\n report(ctx, widgetIssues(widget), ['rows', r, 'widgets', w]);\n }\n }\n }) as z.ZodType<StrictDashboardDefinition>;\n"],"mappings":";;;;;AA4MA,MAAM,UAAU,KAAsB,QAAiB,SAAwB,CAAC,MAAM;CACpF,KAAK,MAAM,SAAS,QAClB,IAAI,SAAS;EAAE,MAAM;EAAU,MAAM,CAAC,GAAG,QAAQ,GAAG,MAAM,IAAI;EAAG,SAAS,MAAM;CAAQ,CAAC;AAE7F;;;;;;;;;;;;;AAcA,MAAa,8BAAgEA,OAAAA,EAAE,QAAQ,CAAC,CAAC,aAAa,OAAO,QAAQ;CACnH,MAAM,OAAOC,gCAAAA,sBAAsB,UAAU,KAAK;CAClD,IAAI,CAAC,KAAK,SAAS,OAAO,OAAO,KAAKC,gCAAAA,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC;CAC/D,OAAO,KAAKC,gCAAAA,aAAa,KAAwB,CAAC;AACpD,CAAC;;;;;;;;;;;;AAaD,MAAa,kCAAwEH,OAAAA,EAClF,QAAQ,CAAC,CACT,aAAa,OAAO,QAAQ;CAC3B,MAAM,OAAOI,gCAAAA,0BAA0B,UAAU,KAAK;CACtD,IAAI,CAAC,KAAK,SAAS,OAAO,OAAO,KAAKF,gCAAAA,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC;CAC/D,KAAK,MAAM,CAAC,GAAG,QAAS,MAA8B,KAAK,QAAQ,GACjE,KAAK,MAAM,CAAC,GAAG,WAAW,IAAI,QAAQ,QAAQ,GAC5C,OAAO,KAAKC,gCAAAA,aAAa,MAAM,GAAG;EAAC;EAAQ;EAAG;EAAW;CAAC,CAAC;AAGjE,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { DashboardColumn, DashboardDefinition, DashboardWidget, DashboardWidgetView } from '@mastra/core/storage/dashboards';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
export { OBSERVABILITY_CATALOG_MAX_METRIC_NAMES, createObservabilityDraftSchemas, createObservabilityWidgetInputSchema, observabilityWidgetInputSchema, toObservabilityDashboard, toObservabilityWidget, } from './observability-dashboard.js';
|
|
4
|
+
export type { ObservabilityCatalog, ObservabilityDashboardDraft, ObservabilityDashboardInput, ObservabilityDashboardOpened, ObservabilityDraftOptions, ObservabilityDraftSchemas, ObservabilityWidgetDraft, } from './observability-dashboard.js';
|
|
5
|
+
/** A number read from one of the view's queries, named by its `id`. */
|
|
6
|
+
export type DashboardValueRef = {
|
|
7
|
+
query: string;
|
|
8
|
+
field?: 'value' | 'estimatedCost';
|
|
9
|
+
measure?: string;
|
|
10
|
+
percentile?: number;
|
|
11
|
+
groups?: string[];
|
|
12
|
+
notGroups?: string[];
|
|
13
|
+
};
|
|
14
|
+
/** A number a view shows: a query's value, or a fixed combination of several. */
|
|
15
|
+
export type DashboardValueExpr = DashboardValueRef | {
|
|
16
|
+
const: number;
|
|
17
|
+
} | {
|
|
18
|
+
sum: DashboardValueExpr[];
|
|
19
|
+
} | {
|
|
20
|
+
minus: [DashboardValueExpr, DashboardValueExpr];
|
|
21
|
+
} | {
|
|
22
|
+
ratio: {
|
|
23
|
+
of: DashboardValueExpr;
|
|
24
|
+
over: DashboardValueExpr;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
max: DashboardValueExpr[];
|
|
28
|
+
} | {
|
|
29
|
+
coalesce: DashboardValueExpr[];
|
|
30
|
+
};
|
|
31
|
+
export type DashboardValueFormat = 'count' | 'usd' | 'duration' | 'percent' | 'score';
|
|
32
|
+
export type DashboardChartColor = 'green' | 'sky' | 'violet' | 'teal' | 'indigo' | 'warning' | 'error' | 'neutral';
|
|
33
|
+
/** A `kpis` view's options: a row of headline numbers. */
|
|
34
|
+
export type DashboardKpisOptions = {
|
|
35
|
+
items: {
|
|
36
|
+
label: string;
|
|
37
|
+
icon: 'bot' | 'coins' | 'hash' | 'threads';
|
|
38
|
+
format: 'count' | 'usd';
|
|
39
|
+
value: DashboardValueExpr;
|
|
40
|
+
detail: string;
|
|
41
|
+
lowerIsBetter?: boolean;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
/** A `table` column's options, told apart by `type`. */
|
|
45
|
+
export type DashboardTableColumnOptions = {
|
|
46
|
+
type: 'name';
|
|
47
|
+
as?: 'project';
|
|
48
|
+
unnamed?: string;
|
|
49
|
+
mark?: {
|
|
50
|
+
icon: 'agent' | 'workflow' | 'tool';
|
|
51
|
+
} | {
|
|
52
|
+
providerDimension: string;
|
|
53
|
+
};
|
|
54
|
+
description?: string;
|
|
55
|
+
width?: string;
|
|
56
|
+
sortable?: boolean;
|
|
57
|
+
} | {
|
|
58
|
+
type: 'dimension';
|
|
59
|
+
dimension: string;
|
|
60
|
+
as?: 'project';
|
|
61
|
+
query?: string;
|
|
62
|
+
joinOn?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
width?: string;
|
|
65
|
+
sortable?: boolean;
|
|
66
|
+
} | {
|
|
67
|
+
type: 'value';
|
|
68
|
+
value: DashboardValueExpr;
|
|
69
|
+
format: 'count' | 'usd' | 'duration' | 'percent';
|
|
70
|
+
emphasis?: boolean;
|
|
71
|
+
missing?: number;
|
|
72
|
+
additive?: boolean;
|
|
73
|
+
better?: 'higher' | 'lower';
|
|
74
|
+
unpricedWhen?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
width?: string;
|
|
77
|
+
sortable?: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'change';
|
|
80
|
+
description?: string;
|
|
81
|
+
};
|
|
82
|
+
/** A `table` view's options: one row per group. */
|
|
83
|
+
export type DashboardTableOptions = {
|
|
84
|
+
groupBy: string[];
|
|
85
|
+
defaultSort: {
|
|
86
|
+
column: string;
|
|
87
|
+
direction: 'asc' | 'desc';
|
|
88
|
+
};
|
|
89
|
+
pageSize?: number;
|
|
90
|
+
emptyMessage: string;
|
|
91
|
+
ariaLabel?: string;
|
|
92
|
+
hideUnnamed?: boolean;
|
|
93
|
+
dropped?: boolean;
|
|
94
|
+
openWhen?: {
|
|
95
|
+
minRows: number;
|
|
96
|
+
};
|
|
97
|
+
rowDrilldown?: {
|
|
98
|
+
fields: Record<string, 'projectId' | 'entityName' | 'threadId' | 'resourceId' | 'environment' | 'sessionId' | 'userId' | 'model' | 'provider'>;
|
|
99
|
+
spanTypes?: string[];
|
|
100
|
+
keepEmpty?: boolean;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/** A `timeseries` view's options: values per time bucket as stacked bars or lines. */
|
|
104
|
+
export type DashboardTimeseriesOptions = {
|
|
105
|
+
chart: 'stackedBar' | 'line';
|
|
106
|
+
format: DashboardValueFormat;
|
|
107
|
+
axis?: boolean;
|
|
108
|
+
series: {
|
|
109
|
+
dataKey: string;
|
|
110
|
+
label: string;
|
|
111
|
+
color: DashboardChartColor;
|
|
112
|
+
emphasis?: boolean;
|
|
113
|
+
value: DashboardValueExpr;
|
|
114
|
+
rangeTotal?: DashboardValueExpr;
|
|
115
|
+
round?: boolean;
|
|
116
|
+
}[];
|
|
117
|
+
buckets?: 'chart' | 'api';
|
|
118
|
+
totals?: string[];
|
|
119
|
+
hideEmpty?: boolean;
|
|
120
|
+
emphasizeFirst?: boolean;
|
|
121
|
+
xLabels?: 'edges';
|
|
122
|
+
flatYDomain?: [number, number];
|
|
123
|
+
yDomain?: [number, number];
|
|
124
|
+
total?: {
|
|
125
|
+
value: 'total' | {
|
|
126
|
+
peak: string;
|
|
127
|
+
} | DashboardValueExpr;
|
|
128
|
+
format?: DashboardValueFormat;
|
|
129
|
+
};
|
|
130
|
+
/** @deprecated Accepted so saved definitions still parse. */
|
|
131
|
+
emptyMessage?: string;
|
|
132
|
+
emptyWhenZero?: DashboardValueExpr;
|
|
133
|
+
};
|
|
134
|
+
/** A `scores` view's options: one line per scorer. */
|
|
135
|
+
export type DashboardScoresOptions = {
|
|
136
|
+
average: string;
|
|
137
|
+
series: string;
|
|
138
|
+
/** @deprecated Accepted so saved definitions still parse. */
|
|
139
|
+
emptyMessage?: string;
|
|
140
|
+
};
|
|
141
|
+
/** A table column whose options its kind accepts. */
|
|
142
|
+
export type StrictDashboardTableColumn = Omit<DashboardColumn, 'options'> & {
|
|
143
|
+
options: DashboardTableColumnOptions;
|
|
144
|
+
};
|
|
145
|
+
/** A view whose options its kind accepts. Only table views have columns. */
|
|
146
|
+
export type StrictDashboardWidgetView<Options, Column = never> = Omit<DashboardWidgetView, 'options' | 'columns'> & {
|
|
147
|
+
options: Options;
|
|
148
|
+
columns?: Column[];
|
|
149
|
+
};
|
|
150
|
+
type WidgetOf<Kind extends string, Options, Column = never> = Omit<DashboardWidget, 'kind' | 'views'> & {
|
|
151
|
+
kind: Kind;
|
|
152
|
+
views: StrictDashboardWidgetView<Options, Column>[];
|
|
153
|
+
};
|
|
154
|
+
/** A widget of a built-in kind that the dashboard renderer can draw. */
|
|
155
|
+
export type StrictDashboardWidget = WidgetOf<'kpis', DashboardKpisOptions> | WidgetOf<'table', DashboardTableOptions, StrictDashboardTableColumn> | WidgetOf<'timeseries', DashboardTimeseriesOptions> | WidgetOf<'scores', DashboardScoresOptions>;
|
|
156
|
+
/** A dashboard definition whose every widget the dashboard renderer can draw. */
|
|
157
|
+
export type StrictDashboardDefinition = Omit<DashboardDefinition, 'rows'> & {
|
|
158
|
+
rows: {
|
|
159
|
+
widgets: StrictDashboardWidget[];
|
|
160
|
+
}[];
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* One widget as the dashboard renderer draws it: core's `dashboardWidgetSchema`, a built-in kind,
|
|
164
|
+
* options that kind accepts, and nothing else it would reject, at every scope the widget shows at.
|
|
165
|
+
* It also rejects columns on views that aren't tables: the renderer ignores them, but they usually
|
|
166
|
+
* mean the widget was written as another kind. Paths are relative to the widget. Unique widget ids, the widget count and the size limit are the
|
|
167
|
+
* definition's to check, so check the whole definition with `strictDashboardDefinitionSchema` too
|
|
168
|
+
* before storing it.
|
|
169
|
+
*
|
|
170
|
+
* Parsing returns the widget as given: no defaults are filled in. It's a validator, not a schema to
|
|
171
|
+
* show a model: its JSON schema is empty. Its input type is `unknown`, so check with it where you
|
|
172
|
+
* store, not in a request schema.
|
|
173
|
+
*/
|
|
174
|
+
export declare const strictDashboardWidgetSchema: z.ZodType<StrictDashboardWidget>;
|
|
175
|
+
/**
|
|
176
|
+
* A dashboard definition as the dashboard renderer draws it: core's `dashboardDefinitionSchema`,
|
|
177
|
+
* then every widget as `strictDashboardWidgetSchema` checks it, paths from the definition (e.g.
|
|
178
|
+
* `rows.0.widgets.1.views.0.options.series.0.value`; problems a kind finds point at the view).
|
|
179
|
+
* Check every definition with it before storing it, so each stored widget renders. Widgets of a
|
|
180
|
+
* host's own kinds are rejected: check those with core's schema.
|
|
181
|
+
*
|
|
182
|
+
* Parsing returns the definition as given: no defaults are filled in. It's a validator, not a
|
|
183
|
+
* schema to show a model: its JSON schema is empty. Its input type is `unknown`, so check with it
|
|
184
|
+
* where you store, not in a request schema.
|
|
185
|
+
*/
|
|
186
|
+
export declare const strictDashboardDefinitionSchema: z.ZodType<StrictDashboardDefinition>;
|
|
187
|
+
//# sourceMappingURL=dashboards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboards.d.ts","sourceRoot":"","sources":["../src/dashboards.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAI3B,OAAO,EACL,sCAAsC,EACtC,+BAA+B,EAC/B,oCAAoC,EACpC,8BAA8B,EAC9B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,2BAA2B,EAC3B,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;AAcnC,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,iFAAiF;AACjF,MAAM,MAAM,kBAAkB,GAC1B,iBAAiB,GACjB;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,GAAG,EAAE,kBAAkB,EAAE,CAAA;C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O,EAAE,qBAAqB,EAAE,CAAA;KAAE,EAAE,CAAC;CAC9C,CAAC;AAUF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAInC,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAUrC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { c as toObservabilityDashboard, d as zodIssues, i as createObservabilityWidgetInputSchema, l as toObservabilityWidget, r as createObservabilityDraftSchemas, s as observabilityWidgetInputSchema, t as OBSERVABILITY_CATALOG_MAX_METRIC_NAMES, u as widgetIssues } from "./observability-dashboard-r5BPo6Aq.js";
|
|
2
|
+
import { dashboardDefinitionSchema, dashboardWidgetSchema } from "@mastra/core/storage/dashboards";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
// src/dashboards.ts
|
|
5
|
+
const report = (ctx, issues, prefix = []) => {
|
|
6
|
+
for (const issue of issues) ctx.addIssue({
|
|
7
|
+
code: "custom",
|
|
8
|
+
path: [...prefix, ...issue.path],
|
|
9
|
+
message: issue.message
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* One widget as the dashboard renderer draws it: core's `dashboardWidgetSchema`, a built-in kind,
|
|
14
|
+
* options that kind accepts, and nothing else it would reject, at every scope the widget shows at.
|
|
15
|
+
* It also rejects columns on views that aren't tables: the renderer ignores them, but they usually
|
|
16
|
+
* mean the widget was written as another kind. Paths are relative to the widget. Unique widget ids, the widget count and the size limit are the
|
|
17
|
+
* definition's to check, so check the whole definition with `strictDashboardDefinitionSchema` too
|
|
18
|
+
* before storing it.
|
|
19
|
+
*
|
|
20
|
+
* Parsing returns the widget as given: no defaults are filled in. It's a validator, not a schema to
|
|
21
|
+
* show a model: its JSON schema is empty. Its input type is `unknown`, so check with it where you
|
|
22
|
+
* store, not in a request schema.
|
|
23
|
+
*/
|
|
24
|
+
const strictDashboardWidgetSchema = z.unknown().superRefine((value, ctx) => {
|
|
25
|
+
const core = dashboardWidgetSchema.safeParse(value);
|
|
26
|
+
if (!core.success) return report(ctx, zodIssues(core.error, []));
|
|
27
|
+
report(ctx, widgetIssues(value));
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* A dashboard definition as the dashboard renderer draws it: core's `dashboardDefinitionSchema`,
|
|
31
|
+
* then every widget as `strictDashboardWidgetSchema` checks it, paths from the definition (e.g.
|
|
32
|
+
* `rows.0.widgets.1.views.0.options.series.0.value`; problems a kind finds point at the view).
|
|
33
|
+
* Check every definition with it before storing it, so each stored widget renders. Widgets of a
|
|
34
|
+
* host's own kinds are rejected: check those with core's schema.
|
|
35
|
+
*
|
|
36
|
+
* Parsing returns the definition as given: no defaults are filled in. It's a validator, not a
|
|
37
|
+
* schema to show a model: its JSON schema is empty. Its input type is `unknown`, so check with it
|
|
38
|
+
* where you store, not in a request schema.
|
|
39
|
+
*/
|
|
40
|
+
const strictDashboardDefinitionSchema = z.unknown().superRefine((value, ctx) => {
|
|
41
|
+
const core = dashboardDefinitionSchema.safeParse(value);
|
|
42
|
+
if (!core.success) return report(ctx, zodIssues(core.error, []));
|
|
43
|
+
for (const [r, row] of value.rows.entries()) for (const [w, widget] of row.widgets.entries()) report(ctx, widgetIssues(widget), [
|
|
44
|
+
"rows",
|
|
45
|
+
r,
|
|
46
|
+
"widgets",
|
|
47
|
+
w
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
export { OBSERVABILITY_CATALOG_MAX_METRIC_NAMES, createObservabilityDraftSchemas, createObservabilityWidgetInputSchema, observabilityWidgetInputSchema, strictDashboardDefinitionSchema, strictDashboardWidgetSchema, toObservabilityDashboard, toObservabilityWidget };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=dashboards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboards.js","names":[],"sources":["../src/dashboards.ts"],"sourcesContent":["import { dashboardDefinitionSchema, dashboardWidgetSchema } from '@mastra/core/storage/dashboards';\nimport type {\n DashboardColumn,\n DashboardDefinition,\n DashboardWidget,\n DashboardWidgetView,\n} from '@mastra/core/storage/dashboards';\nimport { z } from 'zod/v4';\nimport { widgetIssues, zodIssues } from './dashboard-views';\nimport type { WidgetIssue } from './dashboard-views';\n\nexport {\n OBSERVABILITY_CATALOG_MAX_METRIC_NAMES,\n createObservabilityDraftSchemas,\n createObservabilityWidgetInputSchema,\n observabilityWidgetInputSchema,\n toObservabilityDashboard,\n toObservabilityWidget,\n} from './observability-dashboard';\nexport type {\n ObservabilityCatalog,\n ObservabilityDashboardDraft,\n ObservabilityDashboardInput,\n ObservabilityDashboardOpened,\n ObservabilityDraftOptions,\n ObservabilityDraftSchemas,\n ObservabilityWidgetDraft,\n} from './observability-dashboard';\n\n/*\n * Dashboards to store, and the drafts a model writes them as. The stored format is checked at least\n * as strictly as the dashboard renderer checks it: core's `dashboardDefinitionSchema`, then each\n * widget's kind, each view's options and each table column's options, then what each kind checks\n * beyond its schema (queries an option names, labels, ...). It also rejects columns on views that\n * aren't tables, which the renderer ignores. A draft (`createObservabilityDraftSchemas`) converts to\n * a widget or definition that passes those checks.\n *\n * The types are written out here rather than inferred, so this entry's declarations need nothing\n * beyond `@mastra/core` and `zod`; the package's tests check they match the kinds' own schemas.\n */\n\n/** A number read from one of the view's queries, named by its `id`. */\nexport type DashboardValueRef = {\n query: string;\n field?: 'value' | 'estimatedCost';\n measure?: string;\n percentile?: number;\n groups?: string[];\n notGroups?: string[];\n};\n\n/** A number a view shows: a query's value, or a fixed combination of several. */\nexport type DashboardValueExpr =\n | DashboardValueRef\n | { const: number }\n | { sum: DashboardValueExpr[] }\n | { minus: [DashboardValueExpr, DashboardValueExpr] }\n | { ratio: { of: DashboardValueExpr; over: DashboardValueExpr } }\n | { max: DashboardValueExpr[] }\n | { coalesce: DashboardValueExpr[] };\n\nexport type DashboardValueFormat = 'count' | 'usd' | 'duration' | 'percent' | 'score';\n\nexport type DashboardChartColor = 'green' | 'sky' | 'violet' | 'teal' | 'indigo' | 'warning' | 'error' | 'neutral';\n\n/** A `kpis` view's options: a row of headline numbers. */\nexport type DashboardKpisOptions = {\n items: {\n label: string;\n icon: 'bot' | 'coins' | 'hash' | 'threads';\n format: 'count' | 'usd';\n value: DashboardValueExpr;\n detail: string;\n lowerIsBetter?: boolean;\n }[];\n};\n\n/** A `table` column's options, told apart by `type`. */\nexport type DashboardTableColumnOptions =\n | {\n type: 'name';\n as?: 'project';\n unnamed?: string;\n mark?: { icon: 'agent' | 'workflow' | 'tool' } | { providerDimension: string };\n description?: string;\n width?: string;\n sortable?: boolean;\n }\n | {\n type: 'dimension';\n dimension: string;\n as?: 'project';\n query?: string;\n joinOn?: string;\n description?: string;\n width?: string;\n sortable?: boolean;\n }\n | {\n type: 'value';\n value: DashboardValueExpr;\n format: 'count' | 'usd' | 'duration' | 'percent';\n emphasis?: boolean;\n missing?: number;\n additive?: boolean;\n better?: 'higher' | 'lower';\n unpricedWhen?: string;\n description?: string;\n width?: string;\n sortable?: boolean;\n }\n | { type: 'change'; description?: string };\n\n/** A `table` view's options: one row per group. */\nexport type DashboardTableOptions = {\n groupBy: string[];\n defaultSort: { column: string; direction: 'asc' | 'desc' };\n pageSize?: number;\n emptyMessage: string;\n ariaLabel?: string;\n hideUnnamed?: boolean;\n dropped?: boolean;\n openWhen?: { minRows: number };\n rowDrilldown?: {\n fields: Record<\n string,\n | 'projectId'\n | 'entityName'\n | 'threadId'\n | 'resourceId'\n | 'environment'\n | 'sessionId'\n | 'userId'\n | 'model'\n | 'provider'\n >;\n spanTypes?: string[];\n keepEmpty?: boolean;\n };\n};\n\n/** A `timeseries` view's options: values per time bucket as stacked bars or lines. */\nexport type DashboardTimeseriesOptions = {\n chart: 'stackedBar' | 'line';\n format: DashboardValueFormat;\n axis?: boolean;\n series: {\n dataKey: string;\n label: string;\n color: DashboardChartColor;\n emphasis?: boolean;\n value: DashboardValueExpr;\n rangeTotal?: DashboardValueExpr;\n round?: boolean;\n }[];\n buckets?: 'chart' | 'api';\n totals?: string[];\n hideEmpty?: boolean;\n emphasizeFirst?: boolean;\n xLabels?: 'edges';\n flatYDomain?: [number, number];\n yDomain?: [number, number];\n total?: { value: 'total' | { peak: string } | DashboardValueExpr; format?: DashboardValueFormat };\n /** @deprecated Accepted so saved definitions still parse. */\n emptyMessage?: string;\n emptyWhenZero?: DashboardValueExpr;\n};\n\n/** A `scores` view's options: one line per scorer. */\nexport type DashboardScoresOptions = {\n average: string;\n series: string;\n /** @deprecated Accepted so saved definitions still parse. */\n emptyMessage?: string;\n};\n\n/** A table column whose options its kind accepts. */\nexport type StrictDashboardTableColumn = Omit<DashboardColumn, 'options'> & { options: DashboardTableColumnOptions };\n\n/** A view whose options its kind accepts. Only table views have columns. */\nexport type StrictDashboardWidgetView<Options, Column = never> = Omit<DashboardWidgetView, 'options' | 'columns'> & {\n options: Options;\n columns?: Column[];\n};\n\ntype WidgetOf<Kind extends string, Options, Column = never> = Omit<DashboardWidget, 'kind' | 'views'> & {\n kind: Kind;\n views: StrictDashboardWidgetView<Options, Column>[];\n};\n\n/** A widget of a built-in kind that the dashboard renderer can draw. */\nexport type StrictDashboardWidget =\n | WidgetOf<'kpis', DashboardKpisOptions>\n | WidgetOf<'table', DashboardTableOptions, StrictDashboardTableColumn>\n | WidgetOf<'timeseries', DashboardTimeseriesOptions>\n | WidgetOf<'scores', DashboardScoresOptions>;\n\n/** A dashboard definition whose every widget the dashboard renderer can draw. */\nexport type StrictDashboardDefinition = Omit<DashboardDefinition, 'rows'> & {\n rows: { widgets: StrictDashboardWidget[] }[];\n};\n\ntype Issue = WidgetIssue;\n\nconst report = (ctx: z.RefinementCtx, issues: Issue[], prefix: PropertyKey[] = []) => {\n for (const issue of issues) {\n ctx.addIssue({ code: 'custom', path: [...prefix, ...issue.path], message: issue.message });\n }\n};\n\n/**\n * One widget as the dashboard renderer draws it: core's `dashboardWidgetSchema`, a built-in kind,\n * options that kind accepts, and nothing else it would reject, at every scope the widget shows at.\n * It also rejects columns on views that aren't tables: the renderer ignores them, but they usually\n * mean the widget was written as another kind. Paths are relative to the widget. Unique widget ids, the widget count and the size limit are the\n * definition's to check, so check the whole definition with `strictDashboardDefinitionSchema` too\n * before storing it.\n *\n * Parsing returns the widget as given: no defaults are filled in. It's a validator, not a schema to\n * show a model: its JSON schema is empty. Its input type is `unknown`, so check with it where you\n * store, not in a request schema.\n */\nexport const strictDashboardWidgetSchema: z.ZodType<StrictDashboardWidget> = z.unknown().superRefine((value, ctx) => {\n const core = dashboardWidgetSchema.safeParse(value);\n if (!core.success) return report(ctx, zodIssues(core.error, []));\n report(ctx, widgetIssues(value as DashboardWidget));\n}) as z.ZodType<StrictDashboardWidget>;\n\n/**\n * A dashboard definition as the dashboard renderer draws it: core's `dashboardDefinitionSchema`,\n * then every widget as `strictDashboardWidgetSchema` checks it, paths from the definition (e.g.\n * `rows.0.widgets.1.views.0.options.series.0.value`; problems a kind finds point at the view).\n * Check every definition with it before storing it, so each stored widget renders. Widgets of a\n * host's own kinds are rejected: check those with core's schema.\n *\n * Parsing returns the definition as given: no defaults are filled in. It's a validator, not a\n * schema to show a model: its JSON schema is empty. Its input type is `unknown`, so check with it\n * where you store, not in a request schema.\n */\nexport const strictDashboardDefinitionSchema: z.ZodType<StrictDashboardDefinition> = z\n .unknown()\n .superRefine((value, ctx) => {\n const core = dashboardDefinitionSchema.safeParse(value);\n if (!core.success) return report(ctx, zodIssues(core.error, []));\n for (const [r, row] of (value as DashboardDefinition).rows.entries()) {\n for (const [w, widget] of row.widgets.entries()) {\n report(ctx, widgetIssues(widget), ['rows', r, 'widgets', w]);\n }\n }\n }) as z.ZodType<StrictDashboardDefinition>;\n"],"mappings":";;;;AA4MA,MAAM,UAAU,KAAsB,QAAiB,SAAwB,CAAC,MAAM;CACpF,KAAK,MAAM,SAAS,QAClB,IAAI,SAAS;EAAE,MAAM;EAAU,MAAM,CAAC,GAAG,QAAQ,GAAG,MAAM,IAAI;EAAG,SAAS,MAAM;CAAQ,CAAC;AAE7F;;;;;;;;;;;;;AAcA,MAAa,8BAAgE,EAAE,QAAQ,CAAC,CAAC,aAAa,OAAO,QAAQ;CACnH,MAAM,OAAO,sBAAsB,UAAU,KAAK;CAClD,IAAI,CAAC,KAAK,SAAS,OAAO,OAAO,KAAK,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC;CAC/D,OAAO,KAAK,aAAa,KAAwB,CAAC;AACpD,CAAC;;;;;;;;;;;;AAaD,MAAa,kCAAwE,EAClF,QAAQ,CAAC,CACT,aAAa,OAAO,QAAQ;CAC3B,MAAM,OAAO,0BAA0B,UAAU,KAAK;CACtD,IAAI,CAAC,KAAK,SAAS,OAAO,OAAO,KAAK,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC;CAC/D,KAAK,MAAM,CAAC,GAAG,QAAS,MAA8B,KAAK,QAAQ,GACjE,KAAK,MAAM,CAAC,GAAG,WAAW,IAAI,QAAQ,QAAQ,GAC5C,OAAO,KAAK,aAAa,MAAM,GAAG;EAAC;EAAQ;EAAG;EAAW;CAAC,CAAC;AAGjE,CAAC"}
|