@mastra/mcp-apps-components 0.0.0-agent-session-20261112221706

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.
@@ -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' | 'blue' | 'orange' | 'pink' | 'yellow' | 'red' | 'purple';
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: DashboardValueFormat;
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,EAC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AC,GAAG;IAClH,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,KAAK,QAAQ,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG;IACtG,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,yBAAyB,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;CACrD,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,qBAAqB,GAC7B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,GACtC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,EAAE,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"}
@@ -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-BsPT3Mon.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 =\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 ADDED
@@ -0,0 +1,106 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_tool = require("./tool--nuX8qzb.cjs");
3
+ // src/host.ts
4
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
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;
11
+ const customRange = range && {
12
+ ...typeof range.from === "string" ? { from: range.from } : {},
13
+ ...typeof range.to === "string" ? { to: range.to } : {}
14
+ };
15
+ return {
16
+ widget: {
17
+ ...value.widget,
18
+ id: value.widget.id
19
+ },
20
+ datePreset: value.datePreset,
21
+ ...customRange ? { customRange } : {},
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
32
+ };
33
+ }
34
+ const toIso = (date) => date instanceof Date ? date.toISOString() : date;
35
+ /**
36
+ * What the host passes down to the observability widget app: the host page's `datePreset` (with its
37
+ * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every
38
+ * `queryObservability` call. The app redraws when any of them changes.
39
+ *
40
+ * ```tsx
41
+ * const host = useMemo(
42
+ * () =>
43
+ * observabilityWidgetHost({
44
+ * resourceUri: 'ui://mastra/observability-widget',
45
+ * datePreset,
46
+ * customRange,
47
+ * filters,
48
+ * projectId,
49
+ * }),
50
+ * [datePreset, customRange, filters, projectId],
51
+ * );
52
+ * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
53
+ * ```
54
+ *
55
+ * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
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.
59
+ */
60
+ function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, onConfigure }) {
61
+ const from = toIso(customRange?.from);
62
+ const to = toIso(customRange?.to);
63
+ const view = {
64
+ ...datePreset ? { datePreset } : {},
65
+ ...datePreset === "custom" && customRange ? { customRange: {
66
+ ...from ? { from } : {},
67
+ ...to ? { to } : {}
68
+ } } : {},
69
+ ...filters ? { filters } : {},
70
+ ...projectId ? { projectId } : {}
71
+ };
72
+ return {
73
+ hostContext: (app) => app.resourceUri === resourceUri ? {
74
+ [require_tool.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,
75
+ ...pins ? { [require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {},
76
+ ...onConfigure ? { [require_tool.OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY]: true } : {}
77
+ } : void 0,
78
+ onModelContext: pins || onConfigure ? (app, params) => {
79
+ if (app.resourceUri !== resourceUri) return;
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);
83
+ if (!pin) return;
84
+ if (pin.pinned) {
85
+ const { pinned: _pinned, ...pinned } = pin;
86
+ pins.onPin(pinned, app);
87
+ } else pins.onUnpin(pin.widget.id, app);
88
+ } : void 0
89
+ };
90
+ }
91
+ /** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
92
+ function observabilityWidgetPins({ resourceUri, ...pins }) {
93
+ return observabilityWidgetHost({
94
+ resourceUri,
95
+ pins
96
+ });
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;
100
+ exports.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY;
101
+ exports.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY;
102
+ exports.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY;
103
+ exports.observabilityWidgetHost = observabilityWidgetHost;
104
+ exports.observabilityWidgetPins = observabilityWidgetPins;
105
+
106
+ //# sourceMappingURL=host.cjs.map
@@ -0,0 +1 @@
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,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;GAAE,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;GAAI,GAAI,KAAK,EAAE,GAAG,IAAI,CAAC;EAAG,EAAE,IACpE,CAAC;EACL,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,YAAY,EAAE,UAAU,IAAI,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 ADDED
@@ -0,0 +1,80 @@
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
+ /** The MCP App instance a host callback is about: one tool call's app. */
5
+ export type McpAppRef = {
6
+ toolName: string;
7
+ toolCallId: string;
8
+ resourceUri: string;
9
+ };
10
+ /**
11
+ * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed
12
+ * here by shape, so this package doesn't depend on the host's UI package.
13
+ */
14
+ export type McpAppHostValue = {
15
+ hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;
16
+ onModelContext?: (app: McpAppRef, params: {
17
+ content?: unknown[];
18
+ structuredContent?: Record<string, unknown>;
19
+ }) => void;
20
+ };
21
+ export type ObservabilityWidgetPins = {
22
+ /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */
23
+ pinnedIds: readonly string[];
24
+ /**
25
+ * The user pinned `pin.widget` over `pin.datePreset` (and `pin.customRange` when `custom`), under
26
+ * `pin.filters` when it has them.
27
+ */
28
+ onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;
29
+ /** The user unpinned the widget with this id. */
30
+ onUnpin: (widgetId: string, app: McpAppRef) => void;
31
+ };
32
+ export type ObservabilityWidgetHostOptions = Omit<ObservabilityWidgetView, 'customRange'> & {
33
+ /** The window drawn when `datePreset` is `custom`: the Metrics page's `customRange` as is, or ISO strings. */
34
+ customRange?: {
35
+ from?: Date | string;
36
+ to?: Date | string;
37
+ };
38
+ /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */
39
+ resourceUri: string;
40
+ /** Lets the user pin widgets. Left out, the widgets show no pin button. */
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;
48
+ };
49
+ export type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & {
50
+ resourceUri: string;
51
+ };
52
+ /**
53
+ * What the host passes down to the observability widget app: the host page's `datePreset` (with its
54
+ * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every
55
+ * `queryObservability` call. The app redraws when any of them changes.
56
+ *
57
+ * ```tsx
58
+ * const host = useMemo(
59
+ * () =>
60
+ * observabilityWidgetHost({
61
+ * resourceUri: 'ui://mastra/observability-widget',
62
+ * datePreset,
63
+ * customRange,
64
+ * filters,
65
+ * projectId,
66
+ * }),
67
+ * [datePreset, customRange, filters, projectId],
68
+ * );
69
+ * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
70
+ * ```
71
+ *
72
+ * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
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.
76
+ */
77
+ export declare function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, onConfigure, }: ObservabilityWidgetHostOptions): McpAppHostValue;
78
+ /** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
79
+ export declare function observabilityWidgetPins({ resourceUri, ...pins }: ObservabilityWidgetPinsOptions): McpAppHostValue;
80
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
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,EAC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AuB,CAAC;IAC/B;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,4BAA4B,EAAE,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC;CACjF,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,uBAAuB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAgC/F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,SAAS,EACT,IAAI,EACJ,WAAW,GACZ,EAAE,8BAA8B,GAAG,eAAe,CAqClD;AAED,yGAAyG;AACzG,wBAAgB,uBAAuB,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,EAAE,8BAA8B,GAAG,eAAe,CAEjH"}
package/dist/host.js ADDED
@@ -0,0 +1,99 @@
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
+ // src/host.ts
3
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
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;
10
+ const customRange = range && {
11
+ ...typeof range.from === "string" ? { from: range.from } : {},
12
+ ...typeof range.to === "string" ? { to: range.to } : {}
13
+ };
14
+ return {
15
+ widget: {
16
+ ...value.widget,
17
+ id: value.widget.id
18
+ },
19
+ datePreset: value.datePreset,
20
+ ...customRange ? { customRange } : {},
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
31
+ };
32
+ }
33
+ const toIso = (date) => date instanceof Date ? date.toISOString() : date;
34
+ /**
35
+ * What the host passes down to the observability widget app: the host page's `datePreset` (with its
36
+ * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every
37
+ * `queryObservability` call. The app redraws when any of them changes.
38
+ *
39
+ * ```tsx
40
+ * const host = useMemo(
41
+ * () =>
42
+ * observabilityWidgetHost({
43
+ * resourceUri: 'ui://mastra/observability-widget',
44
+ * datePreset,
45
+ * customRange,
46
+ * filters,
47
+ * projectId,
48
+ * }),
49
+ * [datePreset, customRange, filters, projectId],
50
+ * );
51
+ * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
52
+ * ```
53
+ *
54
+ * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
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.
58
+ */
59
+ function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, onConfigure }) {
60
+ const from = toIso(customRange?.from);
61
+ const to = toIso(customRange?.to);
62
+ const view = {
63
+ ...datePreset ? { datePreset } : {},
64
+ ...datePreset === "custom" && customRange ? { customRange: {
65
+ ...from ? { from } : {},
66
+ ...to ? { to } : {}
67
+ } } : {},
68
+ ...filters ? { filters } : {},
69
+ ...projectId ? { projectId } : {}
70
+ };
71
+ return {
72
+ hostContext: (app) => app.resourceUri === resourceUri ? {
73
+ [OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,
74
+ ...pins ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {},
75
+ ...onConfigure ? { [OBSERVABILITY_WIDGET_CONFIGURABLE_CONTEXT_KEY]: true } : {}
76
+ } : void 0,
77
+ onModelContext: pins || onConfigure ? (app, params) => {
78
+ if (app.resourceUri !== resourceUri) return;
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);
82
+ if (!pin) return;
83
+ if (pin.pinned) {
84
+ const { pinned: _pinned, ...pinned } = pin;
85
+ pins.onPin(pinned, app);
86
+ } else pins.onUnpin(pin.widget.id, app);
87
+ } : void 0
88
+ };
89
+ }
90
+ /** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
91
+ function observabilityWidgetPins({ resourceUri, ...pins }) {
92
+ return observabilityWidgetHost({
93
+ resourceUri,
94
+ pins
95
+ });
96
+ }
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 };
98
+
99
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
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,oBAAoB;CAChC,IAAI,CAAC,SAAS,GAAG,KAAK,OAAO,IAAI,WAAW,WAAW,OAAO,KAAA;CAC9D,MAAM,QAAQ,gBAAgB,GAAG;CACjC,OAAO,SAAS;EAAE,QAAQ,IAAI;EAAQ,GAAG;CAAM;AACjD;AAEA,MAAM,SAAS,SAAqC,gBAAgB,OAAO,KAAK,YAAY,IAAI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