@dbx-tools/ui-mastra 0.9.187 → 0.9.189

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
@@ -226,6 +226,13 @@ supervisor agent:
226
226
  <MastraChat genieSpace="sales" threadPlacement="auto" enableExport />
227
227
  ```
228
228
 
229
+ Set `genieVisualization="image"` to show Genie's original rendered PNG in the
230
+ Chart tab while keeping the linked query result in the Table tab:
231
+
232
+ ```tsx
233
+ <MastraChat genieSpace="sales" genieVisualization="image" />
234
+ ```
235
+
229
236
  The alias comes from the server plugin's `genieSpaces`. The client still uses
230
237
  AI SDK `UIMessage` streams and the same `ChatView`. Genie conversations replace
231
238
  Mastra threads and Genie messages remain the visible history. When Mastra
@@ -236,8 +243,9 @@ Turns and history require the Genie Agent API and never fall back to classic
236
243
  Genie message polling. The sidebar filters the Genie conversation listing to
237
244
  Agent Mode conversations. Genie decides whether a query should be visualized.
238
245
  Visualization attachments render through AppKit UI's native
239
- `GenieQueryVisualization`, with Chart and Table tabs. This does not invoke a
240
- supervisor or the Mastra Model Serving chart planner. Queries without a
246
+ `GenieQueryVisualization`, with Chart and Table tabs, unless image mode is
247
+ selected. This does not invoke a supervisor or the Mastra Model Serving chart
248
+ planner. Queries without a
241
249
  visualization attachment render through the existing sortable data table.
242
250
 
243
251
  Direct mode requires the signed-in user's Databricks OBO context. It supports
package/index.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  // Hand edits are overwritten on the next watch; this file is read-only.
4
4
 
5
5
  export const PACKAGE_IDENTIFIER = "@dbx-tools/ui-mastra";
6
- export const PACKAGE_VERSION = "0.9.187";
6
+ export const PACKAGE_VERSION = "0.9.189";
package/package.json CHANGED
@@ -32,12 +32,12 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@databricks/appkit-ui": "0.81.0",
35
- "@dbx-tools/shared-auth": "^0.9.187",
36
- "@dbx-tools/shared-core": "^0.9.187",
37
- "@dbx-tools/shared-genie": "^0.9.187",
38
- "@dbx-tools/shared-mastra": "^0.9.187",
39
- "@dbx-tools/shared-model": "^0.9.187",
40
- "@dbx-tools/ui": "^0.9.187",
35
+ "@dbx-tools/shared-auth": "0.9.189",
36
+ "@dbx-tools/shared-core": "0.9.189",
37
+ "@dbx-tools/shared-genie": "0.9.189",
38
+ "@dbx-tools/shared-mastra": "0.9.189",
39
+ "@dbx-tools/shared-model": "0.9.189",
40
+ "@dbx-tools/ui": "0.9.189",
41
41
  "@mastra/client-js": "1.50.0",
42
42
  "@mastra/core": "1.71.0",
43
43
  "@tanstack/react-table": "^8.21.3",
@@ -55,7 +55,7 @@
55
55
  "publishConfig": {
56
56
  "access": "public"
57
57
  },
58
- "version": "0.9.187",
58
+ "version": "0.9.189",
59
59
  "types": "index.ts",
60
60
  "dbxToolsConfig": {
61
61
  "tags": [
@@ -0,0 +1,132 @@
1
+ import {
2
+ Dialog,
3
+ DialogContent,
4
+ DialogTitle,
5
+ DialogTrigger,
6
+ Spinner,
7
+ Tabs,
8
+ TabsContent,
9
+ TabsList,
10
+ TabsTrigger,
11
+ } from "@databricks/appkit-ui/react";
12
+ import type { GenieVisualizationEmbed, StatementData } from "@dbx-tools/shared-mastra";
13
+ import { useEffect, useState } from "react";
14
+ import { DataGrid } from "./data-grid.tsx";
15
+ import { useMastraClient, useVisualizationFetch } from "../support/mastra-client.ts";
16
+
17
+ const GENIE_IMAGE_LOADING_HEIGHT_PX = 320;
18
+ const GENIE_IMAGE_MAX_SCALE = 2;
19
+
20
+ interface ImageDimensions {
21
+ height: number;
22
+ width: number;
23
+ }
24
+
25
+ const GenieImageLoading = () => (
26
+ <div
27
+ className="flex items-center justify-center rounded border border-border bg-card"
28
+ style={{ height: GENIE_IMAGE_LOADING_HEIGHT_PX, width: "100%" }}
29
+ >
30
+ <Spinner className="size-5 text-muted-foreground" />
31
+ <span className="sr-only">Loading Genie chart</span>
32
+ </div>
33
+ );
34
+
35
+ /** Chart/Table presentation for Genie's server-processed PNG. */
36
+ export function GenieImageTabs({
37
+ src,
38
+ data,
39
+ tableLoading = false,
40
+ }: {
41
+ src: string;
42
+ data?: StatementData;
43
+ tableLoading?: boolean;
44
+ }) {
45
+ const [imageState, setImageState] = useState<"loading" | "loaded" | "error">("loading");
46
+ const [imageDimensions, setImageDimensions] = useState<ImageDimensions>();
47
+ useEffect(() => {
48
+ setImageState("loading");
49
+ setImageDimensions(undefined);
50
+ }, [src]);
51
+ return (
52
+ <Tabs defaultValue="chart" className="not-prose my-3 min-w-0 max-w-full">
53
+ <TabsList>
54
+ <TabsTrigger value="chart">Chart</TabsTrigger>
55
+ <TabsTrigger value="table">Table</TabsTrigger>
56
+ </TabsList>
57
+ <TabsContent value="chart">
58
+ {imageState === "error" ? (
59
+ <p role="status" className="py-3 text-sm text-muted-foreground">
60
+ Genie chart unavailable. Open Table to view the query result.
61
+ </p>
62
+ ) : (
63
+ <>
64
+ {imageState === "loading" ? <GenieImageLoading /> : null}
65
+ <Dialog>
66
+ <DialogTrigger asChild>
67
+ <button
68
+ type="button"
69
+ aria-label="Open Genie visualization"
70
+ className="block max-w-full cursor-zoom-in appearance-none rounded border border-border bg-transparent p-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
71
+ style={imageState === "loaded" ? undefined : { display: "none" }}
72
+ >
73
+ <img
74
+ src={src}
75
+ alt="Genie query visualization"
76
+ className="block h-auto max-w-full rounded"
77
+ onLoad={(event) => {
78
+ setImageDimensions({
79
+ height: event.currentTarget.naturalHeight,
80
+ width: event.currentTarget.naturalWidth,
81
+ });
82
+ setImageState("loaded");
83
+ }}
84
+ onError={() => setImageState("error")}
85
+ />
86
+ </button>
87
+ </DialogTrigger>
88
+ <DialogContent className="max-h-[calc(100dvh-1rem)] w-fit max-w-[calc(100dvw-1rem)] gap-0 overflow-hidden p-2 sm:max-w-[calc(100dvw-1rem)]">
89
+ <DialogTitle className="sr-only">Genie query visualization</DialogTitle>
90
+ <img
91
+ src={src}
92
+ alt="Genie query visualization"
93
+ className="block h-auto max-h-[calc(100dvh-2rem)] max-w-[calc(100dvw-2rem)] object-contain"
94
+ style={
95
+ imageDimensions
96
+ ? {
97
+ aspectRatio: `${imageDimensions.width} / ${imageDimensions.height}`,
98
+ width: imageDimensions.width * GENIE_IMAGE_MAX_SCALE,
99
+ }
100
+ : undefined
101
+ }
102
+ />
103
+ </DialogContent>
104
+ </Dialog>
105
+ </>
106
+ )}
107
+ </TabsContent>
108
+ <TabsContent value="table" forceMount className="data-[state=inactive]:hidden">
109
+ {data ? (
110
+ <DataGrid
111
+ columns={data.columns}
112
+ rows={data.rows}
113
+ rowCount={data.rowCount}
114
+ truncated={data.truncated}
115
+ />
116
+ ) : (
117
+ <p role="status" className="py-3 text-sm text-muted-foreground">
118
+ {tableLoading ? "Loading query result…" : "Query result unavailable."}
119
+ </p>
120
+ )}
121
+ </TabsContent>
122
+ </Tabs>
123
+ );
124
+ }
125
+
126
+ /** Resolve a durable image reference through the caller's authenticated app routes. */
127
+ export function GenieImageSlot({ reference }: { reference: GenieVisualizationEmbed }) {
128
+ const client = useMastraClient();
129
+ const { data, loading } = useVisualizationFetch(reference.statementId);
130
+ const src = client.genieVisualizationImageUrl(reference);
131
+ return <GenieImageTabs key={src} src={src} data={data} tableLoading={loading} />;
132
+ }
@@ -4,9 +4,13 @@ import {
4
4
  isUuid,
5
5
  parseMarkers,
6
6
  stripIncompleteMarkerTail,
7
+ type GenieVisualizationEmbed,
8
+ GENIE_VISUALIZATION_MARKER,
9
+ parseGenieVisualizationEmbed,
7
10
  } from "@dbx-tools/shared-mastra";
8
11
  import { ClockIcon } from "lucide-react";
9
12
  import { lazy, Suspense, useMemo, useRef } from "react";
13
+ import { GenieImageSlot } from "./_genie-image.tsx";
10
14
  import { DataGrid, humanizeLabel } from "./data-grid.tsx";
11
15
  import { AssistantMarkdown } from "./markdown.tsx";
12
16
  import { normalizeChartOption } from "../support/chart-option.ts";
@@ -199,6 +203,7 @@ type RenderSegment =
199
203
  | { kind: "text"; text: string }
200
204
  | { kind: "chart"; chartId: string }
201
205
  | { kind: "data"; statementId: string }
206
+ | { kind: "genie-image"; reference: GenieVisualizationEmbed }
202
207
  | { kind: "visualization"; statementId: string };
203
208
 
204
209
  /**
@@ -213,6 +218,10 @@ type RenderSegment =
213
218
  * known, renderable type resolves to a slot.
214
219
  */
215
220
  const markerSegment = (marker: ParsedMarker): RenderSegment => {
221
+ if (marker.type === GENIE_VISUALIZATION_MARKER) {
222
+ const reference = parseGenieVisualizationEmbed(marker.id);
223
+ return reference ? { kind: "genie-image", reference } : { kind: "text", text: "" };
224
+ }
216
225
  if (!isUuid(marker.id)) return { kind: "text", text: "" };
217
226
  switch (marker.type) {
218
227
  case "chart":
@@ -292,6 +301,9 @@ export const MarkdownWithEmbeds = ({
292
301
  if (seg.kind === "chart") {
293
302
  return <ChartSlot key={`c-${i}-${seg.chartId}`} chartId={seg.chartId} />;
294
303
  }
304
+ if (seg.kind === "genie-image") {
305
+ return <GenieImageSlot key={`g-${i}`} reference={seg.reference} />;
306
+ }
295
307
  if (seg.kind === "visualization") {
296
308
  return (
297
309
  <GenieVisualizationSlot
@@ -1,6 +1,6 @@
1
1
  import { getAuthStatus } from "@dbx-tools/shared-auth";
2
2
  import { hash, log, toError } from "@dbx-tools/shared-core";
3
- import { isStaleMastraResumeError } from "@dbx-tools/shared-mastra";
3
+ import { isStaleMastraResumeError, type GenieVisualizationMode } from "@dbx-tools/shared-mastra";
4
4
  import type { ReasoningEffort } from "@dbx-tools/shared-model";
5
5
  import { useBrand } from "@dbx-tools/ui/branding/react";
6
6
  import type { RequestContext } from "@mastra/client-js";
@@ -176,6 +176,12 @@ export interface UseMastraChatOptions<
176
176
  * cannot be renamed, turns take no attachments, and feedback is unavailable.
177
177
  */
178
178
  genieSpace?: string;
179
+ /**
180
+ * Direct Genie visualization renderer. `"appkit"` keeps the current local
181
+ * Chart/Table rendering; `"image"` displays the PNG produced by Genie while
182
+ * retaining the backing Table tab.
183
+ */
184
+ genieVisualization?: GenieVisualizationMode;
179
185
  /**
180
186
  * Surface the built-in model picker in the header, letting the user
181
187
  * override the serving endpoint per turn (via `X-Mastra-Model`).
@@ -271,10 +277,12 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
271
277
  const pluginClient = useMastraClient();
272
278
  const mastraConfig = useMastraConfig();
273
279
  const genieSpace = options.genieSpace?.trim() || undefined;
280
+ const genieVisualization = options.genieVisualization;
274
281
  const genieClient = useMemo(
275
- () => (genieSpace ? new GenieChatClient(mastraConfig, genieSpace) : undefined),
282
+ () =>
283
+ genieSpace ? new GenieChatClient(mastraConfig, genieSpace, genieVisualization) : undefined,
276
284
  // Same scalars `useMastraClient` keys on; `mastraConfig` identity churns.
277
- [genieSpace, mastraConfig.basePath, mastraConfig.defaultAgent],
285
+ [genieSpace, genieVisualization, mastraConfig.basePath, mastraConfig.defaultAgent],
278
286
  );
279
287
  const mastraClient = genieClient ?? pluginClient;
280
288
  // Genie chats key persisted state (active thread, sidebar) by space alias.
@@ -24,7 +24,14 @@
24
24
  */
25
25
 
26
26
  import { capitalize, toLabel, toSlugWithOptions, escapeHtml } from "@dbx-tools/shared-core";
27
- import { type Chart, type StatementData, parseMarkers, isUuid } from "@dbx-tools/shared-mastra";
27
+ import {
28
+ type Chart,
29
+ type StatementData,
30
+ parseMarkers,
31
+ isUuid,
32
+ GENIE_VISUALIZATION_MARKER,
33
+ parseGenieVisualizationEmbed,
34
+ } from "@dbx-tools/shared-mastra";
28
35
  import type { UIMessage } from "ai";
29
36
  import type { EChartsCoreOption } from "echarts";
30
37
  import { normalizeChartOption } from "./chart-option.ts";
@@ -203,7 +210,10 @@ function splitSegments(text: string): Segment[] {
203
210
  if (marker.start > last) {
204
211
  segments.push({ kind: "text", text: text.slice(last, marker.start) });
205
212
  }
206
- if (isUuid(marker.id) && marker.type === "chart") {
213
+ if (marker.type === GENIE_VISUALIZATION_MARKER) {
214
+ const reference = parseGenieVisualizationEmbed(marker.id);
215
+ if (reference) segments.push({ kind: "visualization", id: reference.statementId });
216
+ } else if (isUuid(marker.id) && marker.type === "chart") {
207
217
  segments.push({ kind: "chart", id: marker.id });
208
218
  } else if (isUuid(marker.id) && marker.type === "data") {
209
219
  segments.push({ kind: "data", id: marker.id });
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  type MastraClientConfig,
3
+ type GenieVisualizationMode,
3
4
  genieRoutePath,
4
5
  MASTRA_ROUTES,
5
6
  GENIE_CONVERSATION_PART_TYPE,
@@ -38,14 +39,17 @@ export class GenieChatClient extends MastraPluginClient {
38
39
  override readonly threadRename = false;
39
40
  override readonly attachments = false;
40
41
  override readonly followUpSuggestions: "none" | "genie";
42
+ /** Renderer requested for direct Genie visualization markers. */
43
+ readonly visualizationMode: GenieVisualizationMode | undefined;
41
44
  /** Local and resolved thread ids mapped to their Genie conversation id. */
42
45
  readonly #conversationIds = new Map<string, string>();
43
46
  /** Transcript message id to Genie message id, for regenerate cleanup. */
44
47
  readonly #genieMessageIds = new Map<string, string>();
45
48
 
46
- constructor(config: MastraClientConfig, alias: string) {
49
+ constructor(config: MastraClientConfig, alias: string, visualization?: GenieVisualizationMode) {
47
50
  super(config);
48
51
  this.alias = alias;
52
+ this.visualizationMode = visualization;
49
53
  this.feedbackModes = config.feedbackModes?.includes("genie") ? ["genie"] : [];
50
54
  this.followUpSuggestions =
51
55
  config.followUpSuggestions === "genie" || config.followUpSuggestions === "auto"
@@ -99,6 +103,7 @@ export class GenieChatClient extends MastraPluginClient {
99
103
  question,
100
104
  ...(conversationId ? { conversationId } : {}),
101
105
  ...(params.requestContext ? { requestContext: params.requestContext } : {}),
106
+ ...(this.visualizationMode ? { visualization: this.visualizationMode } : {}),
102
107
  },
103
108
  routing: {},
104
109
  signal: params.signal,
@@ -188,8 +193,12 @@ export class GenieChatClient extends MastraPluginClient {
188
193
  const page = options.page ?? 0;
189
194
  let messages: UIMessage[] = [];
190
195
  if (page === 0) {
196
+ const url = this.#url(MASTRA_ROUTES.threads, options.threadId, MASTRA_ROUTES.messages);
197
+ const historyUrl = this.visualizationMode
198
+ ? `${url}?${new URLSearchParams({ visualization: this.visualizationMode })}`
199
+ : url;
191
200
  const payload = await this.getJson(
192
- this.#url(MASTRA_ROUTES.threads, options.threadId, MASTRA_ROUTES.messages),
201
+ historyUrl,
193
202
  GenieThreadMessagesResponseSchema,
194
203
  options.signal,
195
204
  );
@@ -20,6 +20,8 @@ import {
20
20
  MastraSuggestionsResponseSchema,
21
21
  ChartSchema,
22
22
  StatementDataSchema,
23
+ type GenieVisualizationEmbed,
24
+ genieVisualizationImagePath,
23
25
  } from "@dbx-tools/shared-mastra";
24
26
  import type { ReasoningEffort, ServingEndpointSummary } from "@dbx-tools/shared-model";
25
27
  import {
@@ -565,6 +567,11 @@ export class MastraPluginClient extends MastraClient {
565
567
  return this.#embed("visualization", id, StatementDataSchema.parse, signal);
566
568
  }
567
569
 
570
+ /** Same-origin image URL; the app's OBO route owns workspace authentication. */
571
+ genieVisualizationImageUrl(reference: GenieVisualizationEmbed): string {
572
+ return `${this.basePath}${genieVisualizationImagePath(reference)}`;
573
+ }
574
+
568
575
  /**
569
576
  * Compose an agent-scoped URL: `${basePath}${segment}` for the
570
577
  * default agent (the mount that does not require an `:agentId`), or