@mastra/mcp-apps-components 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +18 -0
- package/dist/apps/observability-widget/tool.d.ts +9 -0
- package/dist/apps/observability-widget/tool.d.ts.map +1 -1
- package/dist/dashboards.cjs +1 -1
- package/dist/dashboards.cjs.map +1 -1
- package/dist/dashboards.d.ts +6 -6
- package/dist/dashboards.d.ts.map +1 -1
- package/dist/dashboards.js +1 -1
- package/dist/dashboards.js.map +1 -1
- package/dist/host.cjs +31 -17
- package/dist/host.cjs.map +1 -1
- package/dist/host.d.ts +12 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +30 -18
- package/dist/host.js.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{observability-dashboard-r5BPo6Aq.js → observability-dashboard-BsPT3Mon.js} +94 -46
- package/dist/observability-dashboard-BsPT3Mon.js.map +1 -0
- package/dist/{observability-dashboard-B85sO-8E.cjs → observability-dashboard-CUTNAsy0.cjs} +94 -46
- package/dist/observability-dashboard-CUTNAsy0.cjs.map +1 -0
- package/dist/observability-dashboard.d.ts +6 -0
- package/dist/observability-dashboard.d.ts.map +1 -1
- package/dist/{tool-B9qpVU16.cjs → tool--nuX8qzb.cjs} +20 -1
- package/dist/tool--nuX8qzb.cjs.map +1 -0
- package/dist/{tool-HqUC6iks.js → tool-CKJgZfHk.js} +9 -2
- package/dist/tool-CKJgZfHk.js.map +1 -0
- package/package.json +7 -7
- package/dist/observability-dashboard-B85sO-8E.cjs.map +0 -1
- package/dist/observability-dashboard-r5BPo6Aq.js.map +0 -1
- package/dist/tool-B9qpVU16.cjs.map +0 -1
- package/dist/tool-HqUC6iks.js.map +0 -1
package/README.md
CHANGED
|
@@ -197,6 +197,24 @@ 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
|
+
#### Configuring a widget
|
|
201
|
+
|
|
202
|
+
Pass `onConfigure` to `observabilityWidgetHost` to show a settings button on each widget, for example to open your own dialog for it:
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
const host = useMemo(
|
|
206
|
+
() =>
|
|
207
|
+
observabilityWidgetHost({
|
|
208
|
+
resourceUri: 'ui://mastra/observability-widget',
|
|
209
|
+
onConfigure: ({ widget, datePreset, customRange, filters }) =>
|
|
210
|
+
openWidgetSettings(widget, { datePreset, customRange, filters }),
|
|
211
|
+
}),
|
|
212
|
+
[],
|
|
213
|
+
);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The callback gets the widget as the opening tool returned it, with the date preset (and `customRange` when `custom`) and the filters it is drawn with, like a pin. The button only shows when the host passes `onConfigure` and accepts structured model context. It sits before the pin button and appears on the card's hover or keyboard focus, and always shows on touch screens.
|
|
217
|
+
|
|
200
218
|
### Validating stored dashboards
|
|
201
219
|
|
|
202
220
|
`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:
|
|
@@ -17,6 +17,13 @@ export type ObservabilityDatePreset = (typeof OBSERVABILITY_DATE_PRESETS)[number
|
|
|
17
17
|
export declare const OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = "mastra.ai/observability-widget-pinned";
|
|
18
18
|
/** `structuredContent` key of the model context update the app sends when the user (un)pins. */
|
|
19
19
|
export declare const OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = "mastra.ai/observability-widget-pin";
|
|
20
|
+
/**
|
|
21
|
+
* Host context key the host sets to `true` when it can configure a widget. The settings button only
|
|
22
|
+
* shows when the host sends it and supports `updateModelContext.structuredContent`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY = "mastra.ai/observability-widget-configurable";
|
|
25
|
+
/** `structuredContent` key of the model context update the app sends when the user opens a widget's settings. */
|
|
26
|
+
export declare const OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY = "mastra.ai/observability-widget-configure";
|
|
20
27
|
/** Host context key holding what the host's page draws the widgets over (`ObservabilityWidgetView`). */
|
|
21
28
|
export declare const OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY = "mastra.ai/observability-widget-view";
|
|
22
29
|
/** A custom window, as ISO date strings. A missing `from` is 24h before `to`; a missing `to` is now. */
|
|
@@ -52,4 +59,6 @@ export type ObservabilityWidgetPin = {
|
|
|
52
59
|
/** The filters the widget was drawn under (the host's, else the dashboard's `defaults.filters`), when any. */
|
|
53
60
|
filters?: unknown[];
|
|
54
61
|
};
|
|
62
|
+
/** What the app sends under `OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY`: the widget as the user sees it. */
|
|
63
|
+
export type ObservabilityWidgetConfigure = Omit<ObservabilityWidgetPin, 'pinned'>;
|
|
55
64
|
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/apps/observability-widget/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,sGAAsG;AACtG,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,YACrC,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,CACJ,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,0BAA0B,CAAC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AC,EAAE,UAAU,EAAE,CAAC;IACvB,0FAA0F;IAC1F,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qGAAqG;AACrG,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,oEAAoE;IACpE,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,8GAA8G;IAC9G,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF,6GAA6G;AAC7G,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC"}
|
package/dist/dashboards.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_observability_dashboard = require("./observability-dashboard-
|
|
2
|
+
const require_observability_dashboard = require("./observability-dashboard-CUTNAsy0.cjs");
|
|
3
3
|
let _mastra_core_storage_dashboards = require("@mastra/core/storage/dashboards");
|
|
4
4
|
let zod_v4 = require("zod/v4");
|
|
5
5
|
// src/dashboards.ts
|
package/dist/dashboards.cjs.map
CHANGED
|
@@ -1 +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"}
|
|
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 =\n | 'green'\n | 'sky'\n | 'violet'\n | 'teal'\n | 'indigo'\n | 'warning'\n | 'error'\n | 'neutral'\n | 'blue'\n | 'orange'\n | 'pink'\n | 'yellow'\n | 'red'\n | 'purple';\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: DashboardValueFormat;\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":";;;;;AA0NA,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"}
|
package/dist/dashboards.d.ts
CHANGED
|
@@ -29,15 +29,15 @@ export type DashboardValueExpr = DashboardValueRef | {
|
|
|
29
29
|
coalesce: DashboardValueExpr[];
|
|
30
30
|
};
|
|
31
31
|
export type DashboardValueFormat = 'count' | 'usd' | 'duration' | 'percent' | 'score';
|
|
32
|
-
export type DashboardChartColor = 'green' | 'sky' | 'violet' | 'teal' | 'indigo' | 'warning' | 'error' | 'neutral';
|
|
32
|
+
export type DashboardChartColor = 'green' | 'sky' | 'violet' | 'teal' | 'indigo' | 'warning' | 'error' | 'neutral' | 'blue' | 'orange' | 'pink' | 'yellow' | 'red' | 'purple';
|
|
33
33
|
/** A `kpis` view's options: a row of headline numbers. */
|
|
34
34
|
export type DashboardKpisOptions = {
|
|
35
35
|
items: {
|
|
36
36
|
label: string;
|
|
37
|
-
icon
|
|
38
|
-
format:
|
|
37
|
+
icon?: 'bot' | 'coins' | 'hash' | 'threads';
|
|
38
|
+
format: DashboardValueFormat;
|
|
39
39
|
value: DashboardValueExpr;
|
|
40
|
-
detail
|
|
40
|
+
detail?: string;
|
|
41
41
|
lowerIsBetter?: boolean;
|
|
42
42
|
}[];
|
|
43
43
|
};
|
|
@@ -87,7 +87,7 @@ export type DashboardTableOptions = {
|
|
|
87
87
|
direction: 'asc' | 'desc';
|
|
88
88
|
};
|
|
89
89
|
pageSize?: number;
|
|
90
|
-
emptyMessage
|
|
90
|
+
emptyMessage?: string;
|
|
91
91
|
ariaLabel?: string;
|
|
92
92
|
hideUnnamed?: boolean;
|
|
93
93
|
dropped?: boolean;
|
|
@@ -108,7 +108,7 @@ export type DashboardTimeseriesOptions = {
|
|
|
108
108
|
series: {
|
|
109
109
|
dataKey: string;
|
|
110
110
|
label: string;
|
|
111
|
-
color
|
|
111
|
+
color?: DashboardChartColor;
|
|
112
112
|
emphasis?: boolean;
|
|
113
113
|
value: DashboardValueExpr;
|
|
114
114
|
rangeTotal?: DashboardValueExpr;
|
package/dist/dashboards.d.ts.map
CHANGED
|
@@ -1 +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,G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E,0BAA0B,CAAC,GACpE,QAAQ,CAAC,YAAY,EAAE,0BAA0B,CAAC,GAClD,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AAE/C,iFAAiF;AACjF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG;IAC1E,IAAI,EAAE;QAAE,OAAO,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"}
|
package/dist/dashboards.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-BsPT3Mon.js";
|
|
2
2
|
import { dashboardDefinitionSchema, dashboardWidgetSchema } from "@mastra/core/storage/dashboards";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
// src/dashboards.ts
|
package/dist/dashboards.js.map
CHANGED
|
@@ -1 +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"}
|
|
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 =\n | 'green'\n | 'sky'\n | 'violet'\n | 'teal'\n | 'indigo'\n | 'warning'\n | 'error'\n | 'neutral'\n | 'blue'\n | 'orange'\n | 'pink'\n | 'yellow'\n | 'red'\n | 'purple';\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: DashboardValueFormat;\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":";;;;AA0NA,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"}
|
package/dist/host.cjs
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_tool = require("./tool
|
|
2
|
+
const require_tool = require("./tool--nuX8qzb.cjs");
|
|
3
3
|
// src/host.ts
|
|
4
4
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
-
/** The app
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
if (!isRecord(
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
const range = isRecord(pin.customRange) ? pin.customRange : void 0;
|
|
5
|
+
/** The widget the app sends with a pin or settings click, checked by shape only: the widget itself is validated when it's drawn. */
|
|
6
|
+
function readDrawnWidget(value) {
|
|
7
|
+
if (!isRecord(value) || typeof value.datePreset !== "string") return void 0;
|
|
8
|
+
if (!isRecord(value.widget) || typeof value.widget.id !== "string") return void 0;
|
|
9
|
+
if (value.filters !== void 0 && !Array.isArray(value.filters)) return void 0;
|
|
10
|
+
const range = isRecord(value.customRange) ? value.customRange : void 0;
|
|
12
11
|
const customRange = range && {
|
|
13
12
|
...typeof range.from === "string" ? { from: range.from } : {},
|
|
14
13
|
...typeof range.to === "string" ? { to: range.to } : {}
|
|
15
14
|
};
|
|
16
15
|
return {
|
|
17
|
-
pinned: pin.pinned,
|
|
18
16
|
widget: {
|
|
19
|
-
...
|
|
20
|
-
id:
|
|
17
|
+
...value.widget,
|
|
18
|
+
id: value.widget.id
|
|
21
19
|
},
|
|
22
|
-
datePreset:
|
|
20
|
+
datePreset: value.datePreset,
|
|
23
21
|
...customRange ? { customRange } : {},
|
|
24
|
-
...
|
|
22
|
+
...value.filters ? { filters: value.filters } : {}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function readPin(structuredContent) {
|
|
26
|
+
const pin = structuredContent?.[require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];
|
|
27
|
+
if (!isRecord(pin) || typeof pin.pinned !== "boolean") return void 0;
|
|
28
|
+
const drawn = readDrawnWidget(pin);
|
|
29
|
+
return drawn && {
|
|
30
|
+
pinned: pin.pinned,
|
|
31
|
+
...drawn
|
|
25
32
|
};
|
|
26
33
|
}
|
|
27
34
|
const toIso = (date) => date instanceof Date ? date.toISOString() : date;
|
|
@@ -47,8 +54,10 @@ const toIso = (date) => date instanceof Date ? date.toISOString() : date;
|
|
|
47
54
|
*
|
|
48
55
|
* Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
|
|
49
56
|
* until the host's ids next change, so a host that turns a click down leaves it showing until then.
|
|
57
|
+
*
|
|
58
|
+
* Pass `onConfigure` to show a settings button on each widget, e.g. to open the host's own dialog for it.
|
|
50
59
|
*/
|
|
51
|
-
function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins }) {
|
|
60
|
+
function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, onConfigure }) {
|
|
52
61
|
const from = toIso(customRange?.from);
|
|
53
62
|
const to = toIso(customRange?.to);
|
|
54
63
|
const view = {
|
|
@@ -63,11 +72,14 @@ function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters
|
|
|
63
72
|
return {
|
|
64
73
|
hostContext: (app) => app.resourceUri === resourceUri ? {
|
|
65
74
|
[require_tool.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,
|
|
66
|
-
...pins ? { [require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {}
|
|
75
|
+
...pins ? { [require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {},
|
|
76
|
+
...onConfigure ? { [require_tool.OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY]: true } : {}
|
|
67
77
|
} : void 0,
|
|
68
|
-
onModelContext: pins ? (app, params) => {
|
|
78
|
+
onModelContext: pins || onConfigure ? (app, params) => {
|
|
69
79
|
if (app.resourceUri !== resourceUri) return;
|
|
70
|
-
const
|
|
80
|
+
const configure = onConfigure && readDrawnWidget(params.structuredContent?.["mastra.ai/observability-widget-configure"]);
|
|
81
|
+
if (configure) onConfigure(configure, app);
|
|
82
|
+
const pin = pins && readPin(params.structuredContent);
|
|
71
83
|
if (!pin) return;
|
|
72
84
|
if (pin.pinned) {
|
|
73
85
|
const { pinned: _pinned, ...pinned } = pin;
|
|
@@ -83,6 +95,8 @@ function observabilityWidgetPins({ resourceUri, ...pins }) {
|
|
|
83
95
|
pins
|
|
84
96
|
});
|
|
85
97
|
}
|
|
98
|
+
exports.OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY;
|
|
99
|
+
exports.OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY;
|
|
86
100
|
exports.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY;
|
|
87
101
|
exports.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY;
|
|
88
102
|
exports.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY;
|
package/dist/host.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.cjs","names":["OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY","OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY","OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY"],"sources":["../src/host.ts"],"sourcesContent":["import {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nimport type {\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type {\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\n/** The MCP App instance a host callback is about: one tool call's app. */\nexport type McpAppRef = { toolName: string; toolCallId: string; resourceUri: string };\n\n/**\n * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed\n * here by shape, so this package doesn't depend on the host's UI package.\n */\nexport type McpAppHostValue = {\n hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;\n onModelContext?: (\n app: McpAppRef,\n params: { content?: unknown[]; structuredContent?: Record<string, unknown> },\n ) => void;\n};\n\nexport type ObservabilityWidgetPins = {\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /**\n * The user pinned `pin.widget` over `pin.datePreset` (and `pin.customRange` when `custom`), under\n * `pin.filters` when it has them.\n */\n onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;\n /** The user unpinned the widget with this id. */\n onUnpin: (widgetId: string, app: McpAppRef) => void;\n};\n\nexport type ObservabilityWidgetHostOptions = Omit<ObservabilityWidgetView, 'customRange'> & {\n /** The window drawn when `datePreset` is `custom`: the Metrics page's `customRange` as is, or ISO strings. */\n customRange?: { from?: Date | string; to?: Date | string };\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** Lets the user pin widgets. Left out, the widgets show no pin button. */\n pins?: ObservabilityWidgetPins;\n};\n\nexport type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & { resourceUri: string };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The app
|
|
1
|
+
{"version":3,"file":"host.cjs","names":["OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY","OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY","OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY","OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY"],"sources":["../src/host.ts"],"sourcesContent":["import {\n OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nimport type {\n ObservabilityWidgetConfigure,\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type {\n ObservabilityWidgetConfigure,\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\n/** The MCP App instance a host callback is about: one tool call's app. */\nexport type McpAppRef = { toolName: string; toolCallId: string; resourceUri: string };\n\n/**\n * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed\n * here by shape, so this package doesn't depend on the host's UI package.\n */\nexport type McpAppHostValue = {\n hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;\n onModelContext?: (\n app: McpAppRef,\n params: { content?: unknown[]; structuredContent?: Record<string, unknown> },\n ) => void;\n};\n\nexport type ObservabilityWidgetPins = {\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /**\n * The user pinned `pin.widget` over `pin.datePreset` (and `pin.customRange` when `custom`), under\n * `pin.filters` when it has them.\n */\n onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;\n /** The user unpinned the widget with this id. */\n onUnpin: (widgetId: string, app: McpAppRef) => void;\n};\n\nexport type ObservabilityWidgetHostOptions = Omit<ObservabilityWidgetView, 'customRange'> & {\n /** The window drawn when `datePreset` is `custom`: the Metrics page's `customRange` as is, or ISO strings. */\n customRange?: { from?: Date | string; to?: Date | string };\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** Lets the user pin widgets. Left out, the widgets show no pin button. */\n pins?: ObservabilityWidgetPins;\n /**\n * The user clicked the settings button of `configure.widget`, drawn over `configure.datePreset` (and\n * `configure.customRange` when `custom`) under `configure.filters` when it has them. Left out, the\n * widgets show no settings button.\n */\n onConfigure?: (configure: ObservabilityWidgetConfigure, app: McpAppRef) => void;\n};\n\nexport type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & { resourceUri: string };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The widget the app sends with a pin or settings click, checked by shape only: the widget itself is validated when it's drawn. */\nfunction readDrawnWidget(value: unknown): ObservabilityWidgetConfigure | undefined {\n if (!isRecord(value) || typeof value.datePreset !== 'string') return undefined;\n if (!isRecord(value.widget) || typeof value.widget.id !== 'string') return undefined;\n if (value.filters !== undefined && !Array.isArray(value.filters)) return undefined;\n const range = isRecord(value.customRange) ? value.customRange : undefined;\n const customRange: ObservabilityWidgetDateRange | undefined = range && {\n ...(typeof range.from === 'string' ? { from: range.from } : {}),\n ...(typeof range.to === 'string' ? { to: range.to } : {}),\n };\n return {\n widget: { ...value.widget, id: value.widget.id },\n datePreset: value.datePreset,\n ...(customRange ? { customRange } : {}),\n ...(value.filters ? { filters: value.filters } : {}),\n };\n}\n\nfunction readPin(structuredContent: Record<string, unknown> | undefined): ObservabilityWidgetPin | undefined {\n const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];\n if (!isRecord(pin) || typeof pin.pinned !== 'boolean') return undefined;\n const drawn = readDrawnWidget(pin);\n return drawn && { pinned: pin.pinned, ...drawn };\n}\n\nconst toIso = (date: Date | string | undefined) => (date instanceof Date ? date.toISOString() : date);\n\n/**\n * What the host passes down to the observability widget app: the host page's `datePreset` (with its\n * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every\n * `queryObservability` call. The app redraws when any of them changes.\n *\n * ```tsx\n * const host = useMemo(\n * () =>\n * observabilityWidgetHost({\n * resourceUri: 'ui://mastra/observability-widget',\n * datePreset,\n * customRange,\n * filters,\n * projectId,\n * }),\n * [datePreset, customRange, filters, projectId],\n * );\n * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>\n * ```\n *\n * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds\n * until the host's ids next change, so a host that turns a click down leaves it showing until then.\n *\n * Pass `onConfigure` to show a settings button on each widget, e.g. to open the host's own dialog for it.\n */\nexport function observabilityWidgetHost({\n resourceUri,\n datePreset,\n customRange,\n filters,\n projectId,\n pins,\n onConfigure,\n}: ObservabilityWidgetHostOptions): McpAppHostValue {\n const from = toIso(customRange?.from);\n const to = toIso(customRange?.to);\n // Always sent, even empty, so a field the host stops setting is cleared in the app too.\n const view: ObservabilityWidgetView = {\n ...(datePreset ? { datePreset } : {}),\n ...(datePreset === 'custom' && customRange\n ? { customRange: { ...(from ? { from } : {}), ...(to ? { to } : {}) } }\n : {}),\n ...(filters ? { filters } : {}),\n ...(projectId ? { projectId } : {}),\n };\n return {\n hostContext: app =>\n app.resourceUri === resourceUri\n ? {\n [OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,\n ...(pins ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {}),\n ...(onConfigure ? { [OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY]: true } : {}),\n }\n : undefined,\n onModelContext:\n pins || onConfigure\n ? (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const configure =\n onConfigure && readDrawnWidget(params.structuredContent?.[OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY]);\n if (configure) onConfigure(configure, app);\n const pin = pins && readPin(params.structuredContent);\n if (!pin) return;\n if (pin.pinned) {\n const { pinned: _pinned, ...pinned } = pin;\n pins.onPin(pinned, app);\n } else pins.onUnpin(pin.widget.id, app);\n }\n : undefined,\n };\n}\n\n/** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */\nexport function observabilityWidgetPins({ resourceUri, ...pins }: ObservabilityWidgetPinsOptions): McpAppHostValue {\n return observabilityWidgetHost({ resourceUri, pins });\n}\n"],"mappings":";;;AAwEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,gBAAgB,OAA0D;CACjF,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,eAAe,UAAU,OAAO,KAAA;CACrE,IAAI,CAAC,SAAS,MAAM,MAAM,KAAK,OAAO,MAAM,OAAO,OAAO,UAAU,OAAO,KAAA;CAC3E,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,MAAM,Q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CAAC;CACnC;CACA,OAAO;EACL,cAAa,QACX,IAAI,gBAAgB,cAChB;IACGC,aAAAA,wCAAwC;GACzC,GAAI,OAAO,GAAGC,aAAAA,0CAA0C,KAAK,UAAU,IAAI,CAAC;GAC5E,GAAI,cAAc,GAAGC,aAAAA,gDAAgD,KAAK,IAAI,CAAC;EACjF,IACA,KAAA;EACN,gBACE,QAAQ,eACH,KAAK,WAAW;GACf,IAAI,IAAI,gBAAgB,aAAa;GACrC,MAAM,YACJ,eAAe,gBAAgB,OAAO,oBAAA,2CAA+D;GACvG,IAAI,WAAW,YAAY,WAAW,GAAG;GACzC,MAAM,MAAM,QAAQ,QAAQ,OAAO,iBAAiB;GACpD,IAAI,CAAC,KAAK;GACV,IAAI,IAAI,QAAQ;IACd,MAAM,EAAE,QAAQ,SAAS,GAAG,WAAW;IACvC,KAAK,MAAM,QAAQ,GAAG;GACxB,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,GAAG;EACxC,IACA,KAAA;CACR;AACF;;AAGA,SAAgB,wBAAwB,EAAE,aAAa,GAAG,QAAyD;CACjH,OAAO,wBAAwB;EAAE;EAAa;CAAK,CAAC;AACtD"}
|
package/dist/host.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ObservabilityWidgetPin, ObservabilityWidgetView } from './apps/observability-widget/tool.js';
|
|
2
|
-
export { OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY, } from './apps/observability-widget/tool.js';
|
|
3
|
-
export type { ObservabilityWidgetDateRange, ObservabilityWidgetPin, ObservabilityWidgetView, } from './apps/observability-widget/tool.js';
|
|
1
|
+
import type { ObservabilityWidgetConfigure, ObservabilityWidgetPin, ObservabilityWidgetView } from './apps/observability-widget/tool.js';
|
|
2
|
+
export { OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY, OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY, OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY, } from './apps/observability-widget/tool.js';
|
|
3
|
+
export type { ObservabilityWidgetConfigure, ObservabilityWidgetDateRange, ObservabilityWidgetPin, ObservabilityWidgetView, } from './apps/observability-widget/tool.js';
|
|
4
4
|
/** The MCP App instance a host callback is about: one tool call's app. */
|
|
5
5
|
export type McpAppRef = {
|
|
6
6
|
toolName: string;
|
|
@@ -39,6 +39,12 @@ export type ObservabilityWidgetHostOptions = Omit<ObservabilityWidgetView, 'cust
|
|
|
39
39
|
resourceUri: string;
|
|
40
40
|
/** Lets the user pin widgets. Left out, the widgets show no pin button. */
|
|
41
41
|
pins?: ObservabilityWidgetPins;
|
|
42
|
+
/**
|
|
43
|
+
* The user clicked the settings button of `configure.widget`, drawn over `configure.datePreset` (and
|
|
44
|
+
* `configure.customRange` when `custom`) under `configure.filters` when it has them. Left out, the
|
|
45
|
+
* widgets show no settings button.
|
|
46
|
+
*/
|
|
47
|
+
onConfigure?: (configure: ObservabilityWidgetConfigure, app: McpAppRef) => void;
|
|
42
48
|
};
|
|
43
49
|
export type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & {
|
|
44
50
|
resourceUri: string;
|
|
@@ -65,8 +71,10 @@ export type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & {
|
|
|
65
71
|
*
|
|
66
72
|
* Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
|
|
67
73
|
* until the host's ids next change, so a host that turns a click down leaves it showing until then.
|
|
74
|
+
*
|
|
75
|
+
* Pass `onConfigure` to show a settings button on each widget, e.g. to open the host's own dialog for it.
|
|
68
76
|
*/
|
|
69
|
-
export declare function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, }: ObservabilityWidgetHostOptions): McpAppHostValue;
|
|
77
|
+
export declare function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, onConfigure, }: ObservabilityWidgetHostOptions): McpAppHostValue;
|
|
70
78
|
/** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
|
|
71
79
|
export declare function observabilityWidgetPins({ resourceUri, ...pins }: ObservabilityWidgetPinsOptions): McpAppHostValue;
|
|
72
80
|
//# sourceMappingURL=host.d.ts.map
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAE5B,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,6CAA6C,EAC7C,0CAA0C,EAC1C,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EACV,4BAA4B,EAC5B,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAE1C,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACtE,cAAc,CAAC,EAAE,CACf,GAAG,EAAE,SAAS,EACd,MAAM,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;QAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KACz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1,33 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, i as OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY, o as OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, r as OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY, s as OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY } from "./tool-CKJgZfHk.js";
|
|
2
2
|
// src/host.ts
|
|
3
3
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
-
/** The app
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
if (!isRecord(
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
const range = isRecord(pin.customRange) ? pin.customRange : void 0;
|
|
4
|
+
/** The widget the app sends with a pin or settings click, checked by shape only: the widget itself is validated when it's drawn. */
|
|
5
|
+
function readDrawnWidget(value) {
|
|
6
|
+
if (!isRecord(value) || typeof value.datePreset !== "string") return void 0;
|
|
7
|
+
if (!isRecord(value.widget) || typeof value.widget.id !== "string") return void 0;
|
|
8
|
+
if (value.filters !== void 0 && !Array.isArray(value.filters)) return void 0;
|
|
9
|
+
const range = isRecord(value.customRange) ? value.customRange : void 0;
|
|
11
10
|
const customRange = range && {
|
|
12
11
|
...typeof range.from === "string" ? { from: range.from } : {},
|
|
13
12
|
...typeof range.to === "string" ? { to: range.to } : {}
|
|
14
13
|
};
|
|
15
14
|
return {
|
|
16
|
-
pinned: pin.pinned,
|
|
17
15
|
widget: {
|
|
18
|
-
...
|
|
19
|
-
id:
|
|
16
|
+
...value.widget,
|
|
17
|
+
id: value.widget.id
|
|
20
18
|
},
|
|
21
|
-
datePreset:
|
|
19
|
+
datePreset: value.datePreset,
|
|
22
20
|
...customRange ? { customRange } : {},
|
|
23
|
-
...
|
|
21
|
+
...value.filters ? { filters: value.filters } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function readPin(structuredContent) {
|
|
25
|
+
const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];
|
|
26
|
+
if (!isRecord(pin) || typeof pin.pinned !== "boolean") return void 0;
|
|
27
|
+
const drawn = readDrawnWidget(pin);
|
|
28
|
+
return drawn && {
|
|
29
|
+
pinned: pin.pinned,
|
|
30
|
+
...drawn
|
|
24
31
|
};
|
|
25
32
|
}
|
|
26
33
|
const toIso = (date) => date instanceof Date ? date.toISOString() : date;
|
|
@@ -46,8 +53,10 @@ const toIso = (date) => date instanceof Date ? date.toISOString() : date;
|
|
|
46
53
|
*
|
|
47
54
|
* Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
|
|
48
55
|
* until the host's ids next change, so a host that turns a click down leaves it showing until then.
|
|
56
|
+
*
|
|
57
|
+
* Pass `onConfigure` to show a settings button on each widget, e.g. to open the host's own dialog for it.
|
|
49
58
|
*/
|
|
50
|
-
function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins }) {
|
|
59
|
+
function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, onConfigure }) {
|
|
51
60
|
const from = toIso(customRange?.from);
|
|
52
61
|
const to = toIso(customRange?.to);
|
|
53
62
|
const view = {
|
|
@@ -62,11 +71,14 @@ function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters
|
|
|
62
71
|
return {
|
|
63
72
|
hostContext: (app) => app.resourceUri === resourceUri ? {
|
|
64
73
|
[OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,
|
|
65
|
-
...pins ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {}
|
|
74
|
+
...pins ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {},
|
|
75
|
+
...onConfigure ? { [OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY]: true } : {}
|
|
66
76
|
} : void 0,
|
|
67
|
-
onModelContext: pins ? (app, params) => {
|
|
77
|
+
onModelContext: pins || onConfigure ? (app, params) => {
|
|
68
78
|
if (app.resourceUri !== resourceUri) return;
|
|
69
|
-
const
|
|
79
|
+
const configure = onConfigure && readDrawnWidget(params.structuredContent?.["mastra.ai/observability-widget-configure"]);
|
|
80
|
+
if (configure) onConfigure(configure, app);
|
|
81
|
+
const pin = pins && readPin(params.structuredContent);
|
|
70
82
|
if (!pin) return;
|
|
71
83
|
if (pin.pinned) {
|
|
72
84
|
const { pinned: _pinned, ...pinned } = pin;
|
|
@@ -82,6 +94,6 @@ function observabilityWidgetPins({ resourceUri, ...pins }) {
|
|
|
82
94
|
pins
|
|
83
95
|
});
|
|
84
96
|
}
|
|
85
|
-
export { OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY, observabilityWidgetHost, observabilityWidgetPins };
|
|
97
|
+
export { OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY, OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY, OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY, observabilityWidgetHost, observabilityWidgetPins };
|
|
86
98
|
|
|
87
99
|
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nimport type {\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type {\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\n/** The MCP App instance a host callback is about: one tool call's app. */\nexport type McpAppRef = { toolName: string; toolCallId: string; resourceUri: string };\n\n/**\n * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed\n * here by shape, so this package doesn't depend on the host's UI package.\n */\nexport type McpAppHostValue = {\n hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;\n onModelContext?: (\n app: McpAppRef,\n params: { content?: unknown[]; structuredContent?: Record<string, unknown> },\n ) => void;\n};\n\nexport type ObservabilityWidgetPins = {\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /**\n * The user pinned `pin.widget` over `pin.datePreset` (and `pin.customRange` when `custom`), under\n * `pin.filters` when it has them.\n */\n onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;\n /** The user unpinned the widget with this id. */\n onUnpin: (widgetId: string, app: McpAppRef) => void;\n};\n\nexport type ObservabilityWidgetHostOptions = Omit<ObservabilityWidgetView, 'customRange'> & {\n /** The window drawn when `datePreset` is `custom`: the Metrics page's `customRange` as is, or ISO strings. */\n customRange?: { from?: Date | string; to?: Date | string };\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** Lets the user pin widgets. Left out, the widgets show no pin button. */\n pins?: ObservabilityWidgetPins;\n};\n\nexport type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & { resourceUri: string };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The app
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import {\n OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nimport type {\n ObservabilityWidgetConfigure,\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type {\n ObservabilityWidgetConfigure,\n ObservabilityWidgetDateRange,\n ObservabilityWidgetPin,\n ObservabilityWidgetView,\n} from './apps/observability-widget/tool';\n\n/** The MCP App instance a host callback is about: one tool call's app. */\nexport type McpAppRef = { toolName: string; toolCallId: string; resourceUri: string };\n\n/**\n * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed\n * here by shape, so this package doesn't depend on the host's UI package.\n */\nexport type McpAppHostValue = {\n hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;\n onModelContext?: (\n app: McpAppRef,\n params: { content?: unknown[]; structuredContent?: Record<string, unknown> },\n ) => void;\n};\n\nexport type ObservabilityWidgetPins = {\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /**\n * The user pinned `pin.widget` over `pin.datePreset` (and `pin.customRange` when `custom`), under\n * `pin.filters` when it has them.\n */\n onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;\n /** The user unpinned the widget with this id. */\n onUnpin: (widgetId: string, app: McpAppRef) => void;\n};\n\nexport type ObservabilityWidgetHostOptions = Omit<ObservabilityWidgetView, 'customRange'> & {\n /** The window drawn when `datePreset` is `custom`: the Metrics page's `customRange` as is, or ISO strings. */\n customRange?: { from?: Date | string; to?: Date | string };\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** Lets the user pin widgets. Left out, the widgets show no pin button. */\n pins?: ObservabilityWidgetPins;\n /**\n * The user clicked the settings button of `configure.widget`, drawn over `configure.datePreset` (and\n * `configure.customRange` when `custom`) under `configure.filters` when it has them. Left out, the\n * widgets show no settings button.\n */\n onConfigure?: (configure: ObservabilityWidgetConfigure, app: McpAppRef) => void;\n};\n\nexport type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & { resourceUri: string };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The widget the app sends with a pin or settings click, checked by shape only: the widget itself is validated when it's drawn. */\nfunction readDrawnWidget(value: unknown): ObservabilityWidgetConfigure | undefined {\n if (!isRecord(value) || typeof value.datePreset !== 'string') return undefined;\n if (!isRecord(value.widget) || typeof value.widget.id !== 'string') return undefined;\n if (value.filters !== undefined && !Array.isArray(value.filters)) return undefined;\n const range = isRecord(value.customRange) ? value.customRange : undefined;\n const customRange: ObservabilityWidgetDateRange | undefined = range && {\n ...(typeof range.from === 'string' ? { from: range.from } : {}),\n ...(typeof range.to === 'string' ? { to: range.to } : {}),\n };\n return {\n widget: { ...value.widget, id: value.widget.id },\n datePreset: value.datePreset,\n ...(customRange ? { customRange } : {}),\n ...(value.filters ? { filters: value.filters } : {}),\n };\n}\n\nfunction readPin(structuredContent: Record<string, unknown> | undefined): ObservabilityWidgetPin | undefined {\n const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];\n if (!isRecord(pin) || typeof pin.pinned !== 'boolean') return undefined;\n const drawn = readDrawnWidget(pin);\n return drawn && { pinned: pin.pinned, ...drawn };\n}\n\nconst toIso = (date: Date | string | undefined) => (date instanceof Date ? date.toISOString() : date);\n\n/**\n * What the host passes down to the observability widget app: the host page's `datePreset` (with its\n * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every\n * `queryObservability` call. The app redraws when any of them changes.\n *\n * ```tsx\n * const host = useMemo(\n * () =>\n * observabilityWidgetHost({\n * resourceUri: 'ui://mastra/observability-widget',\n * datePreset,\n * customRange,\n * filters,\n * projectId,\n * }),\n * [datePreset, customRange, filters, projectId],\n * );\n * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>\n * ```\n *\n * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds\n * until the host's ids next change, so a host that turns a click down leaves it showing until then.\n *\n * Pass `onConfigure` to show a settings button on each widget, e.g. to open the host's own dialog for it.\n */\nexport function observabilityWidgetHost({\n resourceUri,\n datePreset,\n customRange,\n filters,\n projectId,\n pins,\n onConfigure,\n}: ObservabilityWidgetHostOptions): McpAppHostValue {\n const from = toIso(customRange?.from);\n const to = toIso(customRange?.to);\n // Always sent, even empty, so a field the host stops setting is cleared in the app too.\n const view: ObservabilityWidgetView = {\n ...(datePreset ? { datePreset } : {}),\n ...(datePreset === 'custom' && customRange\n ? { customRange: { ...(from ? { from } : {}), ...(to ? { to } : {}) } }\n : {}),\n ...(filters ? { filters } : {}),\n ...(projectId ? { projectId } : {}),\n };\n return {\n hostContext: app =>\n app.resourceUri === resourceUri\n ? {\n [OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,\n ...(pins ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {}),\n ...(onConfigure ? { [OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY]: true } : {}),\n }\n : undefined,\n onModelContext:\n pins || onConfigure\n ? (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const configure =\n onConfigure && readDrawnWidget(params.structuredContent?.[OBSERVABILITY_WIDGET_CONFIGURE_CONTEXT_KEY]);\n if (configure) onConfigure(configure, app);\n const pin = pins && readPin(params.structuredContent);\n if (!pin) return;\n if (pin.pinned) {\n const { pinned: _pinned, ...pinned } = pin;\n pins.onPin(pinned, app);\n } else pins.onUnpin(pin.widget.id, app);\n }\n : undefined,\n };\n}\n\n/** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */\nexport function observabilityWidgetPins({ resourceUri, ...pins }: ObservabilityWidgetPinsOptions): McpAppHostValue {\n return observabilityWidgetHost({ resourceUri, pins });\n}\n"],"mappings":";;AAwEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,gBAAgB,OAA0D;CACjF,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,eAAe,UAAU,OAAO,KAAA;CACrE,IAAI,CAAC,SAAS,MAAM,MAAM,KAAK,OAAO,MAAM,OAAO,OAAO,UAAU,OAAO,KAAA;CAC3E,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,MAAM,OAAO,GAAG,OAAO,KAAA;CACzE,MAAM,QAAQ,SAAS,MAAM,WAAW,IAAI,MAAM,cAAc,KAAA;CAChE,MAAM,cAAwD,SAAS;EACrE,GAAI,OAAO,MAAM,SAAS,WAAW,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;EAC7D,GAAI,OAAO,MAAM,OAAO,WAAW,EAAE,IAAI,MAAM,GAAG,IAAI,CAAC;CACzD;CACA,OAAO;EACL,QAAQ;GAAE,GAAG,MAAM;GAAQ,IAAI,MAAM,OAAO;EAAG;EAC/C,YAAY,MAAM;EAClB,GAAI,cAAc,EAAE,YAAY,IAAI,CAAC;EACrC,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;CACpD;AACF;AAEA,SAAS,QAAQ,mBAA4F;CAC3G,MAAM,MAAM,oBAAo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