@mastra/mcp-apps-components 0.1.0-alpha.1 → 0.1.0-alpha.3

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 CHANGED
@@ -53,50 +53,71 @@ export const greetingServer = new MCPServer({
53
53
  });
54
54
  ```
55
55
 
56
- ### Observability widget
56
+ ### Observability dashboard
57
57
 
58
- `observabilityWidgetApp` draws one Studio dashboard widget (KPIs, time series, table or scores) with the same components Studio uses.
58
+ `observabilityDashboardApp` draws a Studio dashboard (rows of KPIs, time series, tables and scores widgets) with the same components Studio uses. Each widget loads and fails on its own.
59
59
 
60
- 1. The model calls the tool that opens the app. That tool must declare an `outputSchema` so its result reaches the app as structured content: `{ widget, datePreset? }`, where `widget` is a stored dashboard widget and `datePreset` is one of `24h` (default), `3d`, `7d`, `14d` or `30d`. The window ends when the app opens.
61
- 2. The app reads its data through the app-only `queryObservability` tool (exported as `QUERY_OBSERVABILITY_TOOL`). It calls it once per read with `{ action, args }`, where `action` is a `MastraClient` observability method (`getMetricAggregate`, `getMetricTimeSeries`, `listScores`, `aggregateTraces`, …) and `args` are that method's arguments, with dates as ISO strings. The tool returns `{ data }`, the method's result; if it throws, the widget shows as failed.
60
+ 1. The model calls the tool that opens the app. That tool must declare an `outputSchema` so its result reaches the app as structured content: `{ dashboard, datePreset? }`, where `dashboard` passes `dashboardDefinitionSchema` from `@mastra/core/storage/dashboards` and `datePreset` is one of `24h`, `3d`, `7d`, `14d` or `30d`. Without `datePreset`, the app uses the dashboard's `defaults.datePreset` when it is one of those, else `24h`. The window ends when the app opens. The dashboard's top-level `defaults.filters` chips filter every widget.
61
+ 2. The app reads its data through the app-only `queryObservability` tool (exported as `QUERY_OBSERVABILITY_TOOL`). It calls it once per read with `{ action, args, projectId? }`, where `action` is one of `OBSERVABILITY_READ_ACTIONS`, the `MastraClient` observability reads the app sends (`aggregateTraces`, `getMetricBreakdown`, `getScoreTimeSeries`, `listScores`, …), `args` are that method's arguments, with dates as ISO strings, and `projectId` is the project the host passed, if any (see [Drawing over the host page's selection](#drawing-over-the-host-pages-selection)). The tool returns `{ data }`, the method's result; if it throws, that widget shows as failed.
62
62
 
63
- The tool runs on your server, so you decide which Mastra server the widget reads from and how it authenticates. Only allow read actions:
63
+ Use `observabilityDashboardInputSchema` as the opening tool's input and `toObservabilityDashboard` as its `execute`:
64
+
65
+ - The schema advertises every widget kind's options to the model, so the model can write its own widgets, and a wrong one fails input validation with errors the model can act on.
66
+ - The schema names the metrics Mastra records, but leaves metric names free: a name that doesn't exist reads as zero rather than failing. To make the model pick only metrics that have data, build the schema with `createObservabilityDashboardInputSchema({ metricNames })`, passing the names from `MastraClient#getMetricNames`. Unknown names are then rejected with the list of valid ones. Past `OBSERVABILITY_CATALOG_MAX_METRIC_NAMES` (200) names, or with none, they stay free. The schema is a snapshot, so rebuild the tool (`server.toolActions.add`) when the names change; `examples/agent` does this before each agent run.
67
+ - Label keys and values aren't listed. Give the model a tool that looks them up (for example with `MastraClient#getMetricLabelKeys` and `getMetricLabelValues`).
68
+ - Widgets without an `id` get a fresh UUID on every open, so the host can pin each one by an id that stays stable when the result is shown again.
69
+
70
+ The tools run on your server, so you decide which Mastra server the dashboard reads from and how it authenticates. Allow `OBSERVABILITY_READ_ACTIONS` and nothing else: a widget whose read is missing from the list fails.
64
71
 
65
72
  ```typescript
66
73
  import { MastraClient } from '@mastra/client-js';
67
74
  import { createTool } from '@mastra/core/tools';
68
75
  import { MCPServer } from '@mastra/mcp';
69
- import { QUERY_OBSERVABILITY_TOOL, observabilityWidgetApp } from '@mastra/mcp-apps-components';
76
+ import {
77
+ OBSERVABILITY_READ_ACTIONS,
78
+ QUERY_OBSERVABILITY_TOOL,
79
+ observabilityDashboardApp,
80
+ observabilityDashboardInputSchema,
81
+ observabilityDashboardOutputSchema,
82
+ toObservabilityDashboard,
83
+ } from '@mastra/mcp-apps-components';
70
84
  import { z } from 'zod';
71
85
 
72
86
  const uri = 'ui://mastra/observability-widget';
73
87
  const client = new MastraClient({ baseUrl: process.env.MASTRA_URL! });
74
- const ACTIONS = ['getMetricAggregate', 'getMetricTimeSeries'] as const;
88
+ // Yours to write: checks the caller can access `projectId`, throws if not, and returns a client
89
+ // whose reads stay in that project.
90
+ declare function projectClient(projectId: string, context: unknown): Promise<MastraClient>;
75
91
 
76
92
  export const observabilityServer = new MCPServer({
77
93
  id: 'observability',
78
94
  name: 'Observability',
79
95
  version: '1.0.0',
80
- appResources: { [uri]: observabilityWidgetApp },
96
+ appResources: { [uri]: observabilityDashboardApp },
81
97
  tools: {
82
- // Visible to the model: opens the app with a widget.
83
- showObservabilityWidget: createTool({
84
- id: 'showObservabilityWidget',
85
- description: 'Shows agent runs over time',
86
- inputSchema: z.object({ datePreset: z.enum(['24h', '3d', '7d', '14d', '30d']).default('24h') }),
87
- outputSchema: z.object({ widget: z.unknown(), datePreset: z.string() }),
98
+ // Visible to the model: opens the app with a dashboard.
99
+ showObservabilityDashboard: createTool({
100
+ id: 'showObservabilityDashboard',
101
+ description: 'Shows an observability dashboard of kpis, timeseries, table and scores widgets.',
102
+ inputSchema: observabilityDashboardInputSchema,
103
+ outputSchema: observabilityDashboardOutputSchema,
88
104
  mcp: { _meta: { ui: { resourceUri: uri } } },
89
- execute: async ({ datePreset }) => ({ widget: agentRunsWidget, datePreset }),
105
+ execute: async input => toObservabilityDashboard(input),
90
106
  }),
91
107
  // Visible to the app only: runs one read on the server's client.
92
108
  [QUERY_OBSERVABILITY_TOOL]: createTool({
93
109
  id: QUERY_OBSERVABILITY_TOOL,
94
110
  description: 'Runs one observability read',
95
- inputSchema: z.object({ action: z.enum(ACTIONS), args: z.record(z.string(), z.unknown()) }),
111
+ inputSchema: z.object({
112
+ action: z.enum(OBSERVABILITY_READ_ACTIONS),
113
+ args: z.record(z.string(), z.unknown()),
114
+ projectId: z.string().optional(),
115
+ }),
96
116
  outputSchema: z.object({ data: z.unknown() }),
97
117
  mcp: { _meta: { ui: { resourceUri: uri, visibility: ['app'] } } },
98
- execute: async ({ action, args }) => {
99
- const read = client[action].bind(client) as (args: unknown) => Promise<unknown>;
118
+ execute: async ({ action, args, projectId }, context) => {
119
+ const reader = projectId ? await projectClient(projectId, context) : client;
120
+ const read = reader[action].bind(reader) as (args: unknown) => Promise<unknown>;
100
121
  return { data: await read(args) };
101
122
  },
102
123
  }),
@@ -104,11 +125,30 @@ export const observabilityServer = new MCPServer({
104
125
  });
105
126
  ```
106
127
 
107
- `examples/agent` has a complete version with every read action, a set of preset widgets and an agent that opens them.
128
+ `projectId` comes from the app's iframe, so the server can't trust it: check that the caller can access that project before reading. A read that throws shows its widget as failed.
129
+
130
+ The input names each widget, read and column type by a key instead of a `kind`, `source` or `type` field, so a validation error points at the part that's wrong. Each number holds the read it comes from, so nothing points at a query by id:
131
+
132
+ ```ts
133
+ {
134
+ span: 6,
135
+ timeseries: {
136
+ chart: 'stackedBar',
137
+ format: 'count',
138
+ series: [{ label: 'Runs', color: 'green', value: { metricTimeSeries: { name: ['mastra_agent_duration_ms'], aggregation: 'count' } } }],
139
+ },
140
+ }
141
+ ```
142
+
143
+ `toObservabilityDashboard` gathers the reads into each view's queries, one per distinct read, and fills in what the stored definition points at: series keys, a chart's whole-range totals, a table's default sort.
144
+
145
+ A host can also build a dashboard itself: `toObservabilityDashboard({ dashboard: { rows: [{ widgets: [runsWidget] }] }, datePreset: '7d' })` returns `{ dashboard, datePreset? }` as a regular `dashboardDefinitionSchema` definition and throws when the input is invalid.
146
+
147
+ `examples/agent` has a complete version with every read action and an agent that opens dashboards.
108
148
 
109
149
  #### Pinning widgets
110
150
 
111
- When the chat host supports it, the widget shows a pin button. The host owns the pinned widgets: it sends their ids to the app, and the app reports each pin and unpin through `ui/update-model-context`. In a host built on `@mastra/playground-ui`, pass `observabilityWidgetPins` from `@mastra/mcp-apps-components/host` to `McpAppHostProvider`:
151
+ When the chat host supports it, each widget shows a pin button. The host owns the pinned widgets: it sends their ids to the app, and the app reports each pin and unpin through `ui/update-model-context`. In a host built on `@mastra/playground-ui`, pass `observabilityWidgetPins` from `@mastra/mcp-apps-components/host` to `McpAppHostProvider`:
112
152
 
113
153
  ```tsx
114
154
  import { McpAppHostProvider } from '@mastra/playground-ui/domains/mcps';
@@ -119,7 +159,7 @@ const host = useMemo(
119
159
  observabilityWidgetPins({
120
160
  resourceUri: 'ui://mastra/observability-widget',
121
161
  pinnedIds,
122
- onPin: ({ widget, datePreset }) => savePin(widget, datePreset),
162
+ onPin: ({ widget, datePreset, filters }) => savePin(widget, datePreset, filters),
123
163
  onUnpin: widgetId => removePin(widgetId),
124
164
  }),
125
165
  [pinnedIds],
@@ -128,7 +168,34 @@ const host = useMemo(
128
168
  <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>;
129
169
  ```
130
170
 
131
- The button only shows when the host sends pinned ids and accepts structured model context. A click shows right away and holds until the host sends new ids.
171
+ A pin carries the widget, the date preset it was drawn over (with its `customRange` when `custom`) and, when it had any, the filters it was drawn under (the host's, else the dashboard's `defaults.filters`). The button only shows when the host sends pinned ids and accepts structured model context. A click shows right away and holds until the host sends new ids.
172
+
173
+ #### Drawing over the host page's selection
174
+
175
+ A host page with its own project, date range and filters, such as Studio's Metrics page, passes them down with `observabilityWidgetHost`. Pinning isn't needed for this:
176
+
177
+ ```tsx
178
+ import { McpAppHostProvider } from '@mastra/playground-ui/domains/mcps';
179
+ import { observabilityWidgetHost } from '@mastra/mcp-apps-components/host';
180
+
181
+ const host = useMemo(
182
+ () =>
183
+ observabilityWidgetHost({
184
+ resourceUri: 'ui://mastra/observability-widget',
185
+ projectId,
186
+ datePreset, // '24h' | '3d' | '7d' | '14d' | '30d' | 'custom'
187
+ customRange, // { from?, to? } as Dates or ISO strings, drawn when datePreset is 'custom'
188
+ filters, // FilterNode[], as a dashboard's defaults.filters
189
+ }),
190
+ [projectId, datePreset, customRange, filters],
191
+ );
192
+
193
+ <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>;
194
+ ```
195
+
196
+ `projectId` is sent with every `queryObservability` call, so your server can scope the reads to that project. It also sets the widgets' scope, as on the Metrics page: with a `projectId`, they show at project scope; without one, at org scope. Widgets, views and columns tagged for the other scope are hidden. The host's `datePreset` and `filters` replace the tool result's and the dashboard's defaults. The Metrics page's `datePreset`, `customRange` and `filterTokens` can be passed as they are. With `datePreset: 'custom'`, the widgets read over `customRange`, like the Metrics page: without `from`, the window starts 24 hours before now, and without `to`, it ends now. A value the app can't read (filters that fail the dashboard schema, an unknown preset, a range that ends before it starts) shows an error instead of the dashboard, so the widgets never draw data the host page didn't ask for. When any value changes, the app reads again; a preset window then ends at that moment. Each value is optional: leave one out to fall back to the dashboard's.
197
+
198
+ To let the user pin widgets too, add `pins: { pinnedIds, onPin, onUnpin }`. `observabilityWidgetPins` is the same helper with only pins.
132
199
 
133
200
  ## Documentation
134
201
 
@@ -1,5 +1,15 @@
1
+ import type { FilterNode } from '@mastra/core/storage/dashboards';
1
2
  /** The app-only tool the observability widget calls, on the server that opened it, for every read. */
2
3
  export declare const QUERY_OBSERVABILITY_TOOL = "queryObservability";
4
+ /**
5
+ * Every `MastraClient` method the app sends as a `queryObservability` action. All are reads; allow
6
+ * these and nothing else (`z.enum(OBSERVABILITY_READ_ACTIONS)`).
7
+ */
8
+ export declare const OBSERVABILITY_READ_ACTIONS: readonly ['aggregateTraces', 'aggregateSpans', 'getMetricAggregate', 'getMetricBreakdown', 'getMetricTimeSeries', 'getMetricPercentiles', 'getScoreAggregate', 'getScoreBreakdown', 'getScoreTimeSeries', 'getScorePercentiles', 'listScores'];
9
+ export type ObservabilityReadAction = (typeof OBSERVABILITY_READ_ACTIONS)[number];
10
+ /** The windows the widget can show, ending when it opens; the same presets as Studio's metrics. */
11
+ export declare const OBSERVABILITY_DATE_PRESETS: readonly ['24h', '3d', '7d', '14d', '30d'];
12
+ export type ObservabilityDatePreset = (typeof OBSERVABILITY_DATE_PRESETS)[number];
3
13
  /**
4
14
  * Host context key holding the ids of the widgets the host has pinned (`string[]`). The pin button
5
15
  * only shows when the host sends it and supports `updateModelContext.structuredContent`.
@@ -7,6 +17,27 @@ export declare const QUERY_OBSERVABILITY_TOOL = "queryObservability";
7
17
  export declare const OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = "mastra.ai/observability-widget-pinned";
8
18
  /** `structuredContent` key of the model context update the app sends when the user (un)pins. */
9
19
  export declare const OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = "mastra.ai/observability-widget-pin";
20
+ /** Host context key holding what the host's page draws the widgets over (`ObservabilityWidgetView`). */
21
+ export declare const OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY = "mastra.ai/observability-widget-view";
22
+ /** A custom window, as ISO date strings. A missing `from` is 24h before `to`; a missing `to` is now. */
23
+ export type ObservabilityWidgetDateRange = {
24
+ from?: string;
25
+ to?: string;
26
+ };
27
+ /**
28
+ * What the host's page draws the widgets over, e.g. the Metrics page's date range and filter bar.
29
+ * Each field the host sets wins over the opening tool's result and the dashboard's `defaults`.
30
+ */
31
+ export type ObservabilityWidgetView = {
32
+ /** One of the presets, or `custom` to draw over `customRange`. */
33
+ datePreset?: ObservabilityDatePreset | 'custom';
34
+ /** The window drawn when `datePreset` is `custom`, as the Metrics page's custom range. */
35
+ customRange?: ObservabilityWidgetDateRange;
36
+ /** Replaces the dashboard's `defaults.filters`; only top-level chips filter, as on the Metrics page. */
37
+ filters?: FilterNode[];
38
+ /** Sent with every `queryObservability` call, so the server reads that project's data. */
39
+ projectId?: string;
40
+ };
10
41
  /** What the app sends under `OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY`: the state the user asked for. */
11
42
  export type ObservabilityWidgetPin = {
12
43
  pinned: boolean;
@@ -16,5 +47,9 @@ export type ObservabilityWidgetPin = {
16
47
  [key: string]: unknown;
17
48
  };
18
49
  datePreset: string;
50
+ /** The window the widget was drawn over, when `datePreset` is `custom`. */
51
+ customRange?: ObservabilityWidgetDateRange;
52
+ /** The filters the widget was drawn under (the host's, else the dashboard's `defaults.filters`), when any. */
53
+ filters?: unknown[];
19
54
  };
20
55
  //# 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,sGAAsG;AACtG,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,uCAAuC,0CAA0C,CAAC;AAE/F,gGAAgG;AAChG,eAAO,MAAM,oCAAoC,uCAAuC,CAAC;AAEzF,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;CACpB,CAAC"}
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,CAAC,MAAM,CAAC,CAAC;AAElF,mGAAmG;AACnG,eAAO,MAAM,0BAA0B,YAAI,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAU,CAAC;AAErF,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAElF;;;GAGG;AACH,eAAO,MAAM,uCAAuC,0CAA0C,CAAC;AAE/F,gGAAgG;AAChG,eAAO,MAAM,oCAAoC,uCAAuC,CAAC;AAEzF,wGAAwG;AACxG,eAAO,MAAM,qCAAqC,wCAAwC,CAAC;AAE3F,wGAAwG;AACxG,MAAM,MAAM,4BAA4B,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,kEAAkE;IAClE,UAAU,CAAC,EAAE,uBAAuB,GAAG,QAAQ,CAAC;IAChD,0FAA0F;IAC1F,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,wGAAwG;IACxG,OAAO,CAAC,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"}
package/dist/host.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_tool = require("./tool-C6_-nIOM.cjs");
2
+ const require_tool = require("./tool-B9qpVU16.cjs");
3
3
  // src/host.ts
4
4
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5
5
  /** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */
@@ -7,47 +7,86 @@ function readPin(structuredContent) {
7
7
  const pin = structuredContent?.[require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];
8
8
  if (!isRecord(pin) || typeof pin.pinned !== "boolean" || typeof pin.datePreset !== "string") return void 0;
9
9
  if (!isRecord(pin.widget) || typeof pin.widget.id !== "string") return void 0;
10
+ if (pin.filters !== void 0 && !Array.isArray(pin.filters)) return void 0;
11
+ const range = isRecord(pin.customRange) ? pin.customRange : void 0;
12
+ const customRange = range && {
13
+ ...typeof range.from === "string" ? { from: range.from } : {},
14
+ ...typeof range.to === "string" ? { to: range.to } : {}
15
+ };
10
16
  return {
11
17
  pinned: pin.pinned,
12
18
  widget: {
13
19
  ...pin.widget,
14
20
  id: pin.widget.id
15
21
  },
16
- datePreset: pin.datePreset
22
+ datePreset: pin.datePreset,
23
+ ...customRange ? { customRange } : {},
24
+ ...pin.filters ? { filters: pin.filters } : {}
17
25
  };
18
26
  }
27
+ const toIso = (date) => date instanceof Date ? date.toISOString() : date;
19
28
  /**
20
- * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it
21
- * sends their ids to each widget app, and hears each pin and unpin.
29
+ * What the host passes down to the observability widget app: the host page's `datePreset` (with its
30
+ * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every
31
+ * `queryObservability` call. The app redraws when any of them changes.
22
32
  *
23
33
  * ```tsx
24
34
  * const host = useMemo(
25
- * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),
26
- * [pinnedIds, onPin, onUnpin],
35
+ * () =>
36
+ * observabilityWidgetHost({
37
+ * resourceUri: 'ui://mastra/observability-widget',
38
+ * datePreset,
39
+ * customRange,
40
+ * filters,
41
+ * projectId,
42
+ * }),
43
+ * [datePreset, customRange, filters, projectId],
27
44
  * );
28
45
  * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
29
46
  * ```
30
47
  *
31
- * A click shows on the button right away and holds until the host's ids next change, so a host
32
- * that turns a click down leaves it showing until then.
48
+ * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
49
+ * until the host's ids next change, so a host that turns a click down leaves it showing until then.
33
50
  */
34
- function observabilityWidgetPins({ resourceUri, pinnedIds, onPin, onUnpin }) {
51
+ function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins }) {
52
+ const from = toIso(customRange?.from);
53
+ const to = toIso(customRange?.to);
54
+ const view = {
55
+ ...datePreset ? { datePreset } : {},
56
+ ...datePreset === "custom" && customRange ? { customRange: {
57
+ ...from ? { from } : {},
58
+ ...to ? { to } : {}
59
+ } } : {},
60
+ ...filters ? { filters } : {},
61
+ ...projectId ? { projectId } : {}
62
+ };
35
63
  return {
36
- hostContext: (app) => app.resourceUri === resourceUri ? { [require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : void 0,
37
- onModelContext: (app, params) => {
64
+ hostContext: (app) => app.resourceUri === resourceUri ? {
65
+ [require_tool.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,
66
+ ...pins ? { [require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {}
67
+ } : void 0,
68
+ onModelContext: pins ? (app, params) => {
38
69
  if (app.resourceUri !== resourceUri) return;
39
70
  const pin = readPin(params.structuredContent);
40
71
  if (!pin) return;
41
- if (pin.pinned) onPin({
42
- widget: pin.widget,
43
- datePreset: pin.datePreset
44
- }, app);
45
- else onUnpin(pin.widget.id, app);
46
- }
72
+ if (pin.pinned) {
73
+ const { pinned: _pinned, ...pinned } = pin;
74
+ pins.onPin(pinned, app);
75
+ } else pins.onUnpin(pin.widget.id, app);
76
+ } : void 0
47
77
  };
48
78
  }
79
+ /** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
80
+ function observabilityWidgetPins({ resourceUri, ...pins }) {
81
+ return observabilityWidgetHost({
82
+ resourceUri,
83
+ pins
84
+ });
85
+ }
49
86
  exports.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY;
50
87
  exports.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY;
88
+ exports.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY;
89
+ exports.observabilityWidgetHost = observabilityWidgetHost;
51
90
  exports.observabilityWidgetPins = observabilityWidgetPins;
52
91
 
53
92
  //# sourceMappingURL=host.cjs.map
package/dist/host.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"host.cjs","names":["OBSERVABILITY_WIDGET_PIN_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} from './apps/observability-widget/tool';\nimport type { ObservabilityWidgetPin } from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type { ObservabilityWidgetPin } 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 ObservabilityWidgetPinsOptions = {\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /** The user pinned `pin.widget` over `pin.datePreset`. */\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\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */\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' || typeof pin.datePreset !== 'string') return undefined;\n if (!isRecord(pin.widget) || typeof pin.widget.id !== 'string') return undefined;\n return { pinned: pin.pinned, widget: { ...pin.widget, id: pin.widget.id }, datePreset: pin.datePreset };\n}\n\n/**\n * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it\n * sends their ids to each widget app, and hears each pin and unpin.\n *\n * ```tsx\n * const host = useMemo(\n * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),\n * [pinnedIds, onPin, onUnpin],\n * );\n * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>\n * ```\n *\n * A click shows on the button right away and holds until the host's ids next change, so a host\n * that turns a click down leaves it showing until then.\n */\nexport function observabilityWidgetPins({\n resourceUri,\n pinnedIds,\n onPin,\n onUnpin,\n}: ObservabilityWidgetPinsOptions): McpAppHostValue {\n return {\n hostContext: app =>\n app.resourceUri === resourceUri ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : undefined,\n onModelContext: (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const pin = readPin(params.structuredContent);\n if (!pin) return;\n if (pin.pinned) onPin({ widget: pin.widget, datePreset: pin.datePreset }, app);\n else onUnpin(pin.widget.id, app);\n },\n };\n}\n"],"mappings":";;;AAsCA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,QAAQ,mBAA4F;CAC3G,MAAM,MAAM,oBAAoBA,aAAAA;CAChC,IAAI,CAAC,SAAS,GAAG,KAAK,OAAO,IAAI,WAAW,aAAa,OAAO,IAAI,eAAe,UAAU,OAAO,KAAA;CACpG,IAAI,CAAC,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,UAAU,OAAO,KAAA;CACvE,OAAO;EAAE,QAAQ,IAAI;EAAQ,QAAQ;GAAE,GAAG,IAAI;GAAQ,IAAI,IAAI,OAAO;EAAG;EAAG,YAAY,IAAI;CAAW;AACxG;;;;;;;;;;;;;;;;AAiBA,SAAgB,wBAAwB,EACtC,aACA,WACA,OACA,WACkD;CAClD,OAAO;EACL,cAAa,QACX,IAAI,gBAAgB,cAAc,GAAGC,aAAAA,0CAA0C,UAAU,IAAI,KAAA;EAC/F,iBAAiB,KAAK,WAAW;GAC/B,IAAI,IAAI,gBAAgB,aAAa;GACrC,MAAM,MAAM,QAAQ,OAAO,iBAAiB;GAC5C,IAAI,CAAC,KAAK;GACV,IAAI,IAAI,QAAQ,MAAM;IAAE,QAAQ,IAAI;IAAQ,YAAY,IAAI;GAAW,GAAG,GAAG;QACxE,QAAQ,IAAI,OAAO,IAAI,GAAG;EACjC;CACF;AACF"}
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's pin update, checked by shape only: the widget itself is validated when it's drawn. */\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' || typeof pin.datePreset !== 'string') return undefined;\n if (!isRecord(pin.widget) || typeof pin.widget.id !== 'string') return undefined;\n if (pin.filters !== undefined && !Array.isArray(pin.filters)) return undefined;\n const range = isRecord(pin.customRange) ? pin.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 pinned: pin.pinned,\n widget: { ...pin.widget, id: pin.widget.id },\n datePreset: pin.datePreset,\n ...(customRange ? { customRange } : {}),\n ...(pin.filters ? { filters: pin.filters } : {}),\n };\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 */\nexport function observabilityWidgetHost({\n resourceUri,\n datePreset,\n customRange,\n filters,\n projectId,\n pins,\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 }\n : undefined,\n onModelContext: pins\n ? (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const pin = 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":";;;AA4DA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,QAAQ,mBAA4F;CAC3G,MAAM,MAAM,oBAAoBA,aAAAA;CAChC,IAAI,CAAC,SAAS,GAAG,KAAK,OAAO,IAAI,WAAW,aAAa,OAAO,IAAI,eAAe,UAAU,OAAO,KAAA;CACpG,IAAI,CAAC,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,UAAU,OAAO,KAAA;CACvE,IAAI,IAAI,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,IAAI,OAAO,GAAG,OAAO,KAAA;CACrE,MAAM,QAAQ,SAAS,IAAI,WAAW,IAAI,IAAI,cAAc,KAAA;CAC5D,MAAM,cAAwD,SAAS;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GAAG,WAAW;IACvC,KAAK,MAAM,QAAQ,GAAG;GACxB,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,GAAG;EACxC,IACA,KAAA;CACN;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,72 @@
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';
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
+ export type ObservabilityWidgetPinsOptions = ObservabilityWidgetPins & {
44
+ resourceUri: string;
45
+ };
46
+ /**
47
+ * What the host passes down to the observability widget app: the host page's `datePreset` (with its
48
+ * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every
49
+ * `queryObservability` call. The app redraws when any of them changes.
50
+ *
51
+ * ```tsx
52
+ * const host = useMemo(
53
+ * () =>
54
+ * observabilityWidgetHost({
55
+ * resourceUri: 'ui://mastra/observability-widget',
56
+ * datePreset,
57
+ * customRange,
58
+ * filters,
59
+ * projectId,
60
+ * }),
61
+ * [datePreset, customRange, filters, projectId],
62
+ * );
63
+ * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
64
+ * ```
65
+ *
66
+ * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
67
+ * until the host's ids next change, so a host that turns a click down leaves it showing until then.
68
+ */
69
+ export declare function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins, }: ObservabilityWidgetHostOptions): McpAppHostValue;
70
+ /** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
71
+ export declare function observabilityWidgetPins({ resourceUri, ...pins }: ObservabilityWidgetPinsOptions): McpAppHostValue;
72
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,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AM,CAAA;KAAE,CAAC;IAC3D,mGAAmG;IACnG,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,uBAAuB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AA2B/F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,SAAS,EACT,IAAI,GACL,EAAE,8BAA8B,GAAG,eAAe,CAgClD;AAED,yGAAyG;AACzG,wBAAgB,uBAAuB,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,EAAE,8BAA8B,GAAG,eAAe,CAEjH"}
package/dist/host.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, t as OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY } from "./tool-BD-7EJf2.js";
1
+ import { a as OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY, i as OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, r as OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY } from "./tool-HqUC6iks.js";
2
2
  // src/host.ts
3
3
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
4
  /** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */
@@ -6,45 +6,82 @@ function readPin(structuredContent) {
6
6
  const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];
7
7
  if (!isRecord(pin) || typeof pin.pinned !== "boolean" || typeof pin.datePreset !== "string") return void 0;
8
8
  if (!isRecord(pin.widget) || typeof pin.widget.id !== "string") return void 0;
9
+ if (pin.filters !== void 0 && !Array.isArray(pin.filters)) return void 0;
10
+ const range = isRecord(pin.customRange) ? pin.customRange : void 0;
11
+ const customRange = range && {
12
+ ...typeof range.from === "string" ? { from: range.from } : {},
13
+ ...typeof range.to === "string" ? { to: range.to } : {}
14
+ };
9
15
  return {
10
16
  pinned: pin.pinned,
11
17
  widget: {
12
18
  ...pin.widget,
13
19
  id: pin.widget.id
14
20
  },
15
- datePreset: pin.datePreset
21
+ datePreset: pin.datePreset,
22
+ ...customRange ? { customRange } : {},
23
+ ...pin.filters ? { filters: pin.filters } : {}
16
24
  };
17
25
  }
26
+ const toIso = (date) => date instanceof Date ? date.toISOString() : date;
18
27
  /**
19
- * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it
20
- * sends their ids to each widget app, and hears each pin and unpin.
28
+ * What the host passes down to the observability widget app: the host page's `datePreset` (with its
29
+ * `customRange` when `custom`) and `filters`, drawn instead of the dashboard's own, and the `projectId` sent with every
30
+ * `queryObservability` call. The app redraws when any of them changes.
21
31
  *
22
32
  * ```tsx
23
33
  * const host = useMemo(
24
- * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),
25
- * [pinnedIds, onPin, onUnpin],
34
+ * () =>
35
+ * observabilityWidgetHost({
36
+ * resourceUri: 'ui://mastra/observability-widget',
37
+ * datePreset,
38
+ * customRange,
39
+ * filters,
40
+ * projectId,
41
+ * }),
42
+ * [datePreset, customRange, filters, projectId],
26
43
  * );
27
44
  * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
28
45
  * ```
29
46
  *
30
- * A click shows on the button right away and holds until the host's ids next change, so a host
31
- * that turns a click down leaves it showing until then.
47
+ * Pass `pins` to let the user pin widgets too. A click shows on the button right away and holds
48
+ * until the host's ids next change, so a host that turns a click down leaves it showing until then.
32
49
  */
33
- function observabilityWidgetPins({ resourceUri, pinnedIds, onPin, onUnpin }) {
50
+ function observabilityWidgetHost({ resourceUri, datePreset, customRange, filters, projectId, pins }) {
51
+ const from = toIso(customRange?.from);
52
+ const to = toIso(customRange?.to);
53
+ const view = {
54
+ ...datePreset ? { datePreset } : {},
55
+ ...datePreset === "custom" && customRange ? { customRange: {
56
+ ...from ? { from } : {},
57
+ ...to ? { to } : {}
58
+ } } : {},
59
+ ...filters ? { filters } : {},
60
+ ...projectId ? { projectId } : {}
61
+ };
34
62
  return {
35
- hostContext: (app) => app.resourceUri === resourceUri ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : void 0,
36
- onModelContext: (app, params) => {
63
+ hostContext: (app) => app.resourceUri === resourceUri ? {
64
+ [OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY]: view,
65
+ ...pins ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pins.pinnedIds } : {}
66
+ } : void 0,
67
+ onModelContext: pins ? (app, params) => {
37
68
  if (app.resourceUri !== resourceUri) return;
38
69
  const pin = readPin(params.structuredContent);
39
70
  if (!pin) return;
40
- if (pin.pinned) onPin({
41
- widget: pin.widget,
42
- datePreset: pin.datePreset
43
- }, app);
44
- else onUnpin(pin.widget.id, app);
45
- }
71
+ if (pin.pinned) {
72
+ const { pinned: _pinned, ...pinned } = pin;
73
+ pins.onPin(pinned, app);
74
+ } else pins.onUnpin(pin.widget.id, app);
75
+ } : void 0
46
76
  };
47
77
  }
48
- export { OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, observabilityWidgetPins };
78
+ /** Lets the user pin observability widgets from the chat: `observabilityWidgetHost` with only `pins`. */
79
+ function observabilityWidgetPins({ resourceUri, ...pins }) {
80
+ return observabilityWidgetHost({
81
+ resourceUri,
82
+ pins
83
+ });
84
+ }
85
+ export { OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, OBSERVABILITY_WIDGET_VIEW_CONTEXT_KEY, observabilityWidgetHost, observabilityWidgetPins };
49
86
 
50
87
  //# 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} from './apps/observability-widget/tool';\nimport type { ObservabilityWidgetPin } from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type { ObservabilityWidgetPin } 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 ObservabilityWidgetPinsOptions = {\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /** The user pinned `pin.widget` over `pin.datePreset`. */\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\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */\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' || typeof pin.datePreset !== 'string') return undefined;\n if (!isRecord(pin.widget) || typeof pin.widget.id !== 'string') return undefined;\n return { pinned: pin.pinned, widget: { ...pin.widget, id: pin.widget.id }, datePreset: pin.datePreset };\n}\n\n/**\n * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it\n * sends their ids to each widget app, and hears each pin and unpin.\n *\n * ```tsx\n * const host = useMemo(\n * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),\n * [pinnedIds, onPin, onUnpin],\n * );\n * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>\n * ```\n *\n * A click shows on the button right away and holds until the host's ids next change, so a host\n * that turns a click down leaves it showing until then.\n */\nexport function observabilityWidgetPins({\n resourceUri,\n pinnedIds,\n onPin,\n onUnpin,\n}: ObservabilityWidgetPinsOptions): McpAppHostValue {\n return {\n hostContext: app =>\n app.resourceUri === resourceUri ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : undefined,\n onModelContext: (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const pin = readPin(params.structuredContent);\n if (!pin) return;\n if (pin.pinned) onPin({ widget: pin.widget, datePreset: pin.datePreset }, app);\n else onUnpin(pin.widget.id, app);\n },\n };\n}\n"],"mappings":";;AAsCA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,QAAQ,mBAA4F;CAC3G,MAAM,MAAM,oBAAoB;CAChC,IAAI,CAAC,SAAS,GAAG,KAAK,OAAO,IAAI,WAAW,aAAa,OAAO,IAAI,eAAe,UAAU,OAAO,KAAA;CACpG,IAAI,CAAC,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,UAAU,OAAO,KAAA;CACvE,OAAO;EAAE,QAAQ,IAAI;EAAQ,QAAQ;GAAE,GAAG,IAAI;GAAQ,IAAI,IAAI,OAAO;EAAG;EAAG,YAAY,IAAI;CAAW;AACxG;;;;;;;;;;;;;;;;AAiBA,SAAgB,wBAAwB,EACtC,aACA,WACA,OACA,WACkD;CAClD,OAAO;EACL,cAAa,QACX,IAAI,gBAAgB,cAAc,GAAG,0CAA0C,UAAU,IAAI,KAAA;EAC/F,iBAAiB,KAAK,WAAW;GAC/B,IAAI,IAAI,gBAAgB,aAAa;GACrC,MAAM,MAAM,QAAQ,OAAO,iBAAiB;GAC5C,IAAI,CAAC,KAAK;GACV,IAAI,IAAI,QAAQ,MAAM;IAAE,QAAQ,IAAI;IAAQ,YAAY,IAAI;GAAW,GAAG,GAAG;QACxE,QAAQ,IAAI,OAAO,IAAI,GAAG;EACjC;CACF;AACF"}
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's pin update, checked by shape only: the widget itself is validated when it's drawn. */\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' || typeof pin.datePreset !== 'string') return undefined;\n if (!isRecord(pin.widget) || typeof pin.widget.id !== 'string') return undefined;\n if (pin.filters !== undefined && !Array.isArray(pin.filters)) return undefined;\n const range = isRecord(pin.customRange) ? pin.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 pinned: pin.pinned,\n widget: { ...pin.widget, id: pin.widget.id },\n datePreset: pin.datePreset,\n ...(customRange ? { customRange } : {}),\n ...(pin.filters ? { filters: pin.filters } : {}),\n };\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 */\nexport function observabilityWidgetHost({\n resourceUri,\n datePreset,\n customRange,\n filters,\n projectId,\n pins,\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 }\n : undefined,\n onModelContext: pins\n ? (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const pin = 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 }: Ob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