@dbx-tools/ui-mastra 0.1.9
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 +198 -0
- package/index.ts +32 -0
- package/package.json +62 -0
- package/src/react/bubbles.tsx +428 -0
- package/src/react/chat-view.tsx +574 -0
- package/src/react/data-grid.tsx +342 -0
- package/src/react/embed-slots.tsx +258 -0
- package/src/react/export-menu.tsx +71 -0
- package/src/react/feedback-controls.tsx +139 -0
- package/src/react/index.ts +42 -0
- package/src/react/markdown.tsx +387 -0
- package/src/react/mastra-chat.tsx +1376 -0
- package/src/react/suggestion-pills.tsx +46 -0
- package/src/react/suggestions.ts +109 -0
- package/src/react/thread-sidebar.tsx +315 -0
- package/src/react/tool-pill.tsx +684 -0
- package/src/react/types.ts +295 -0
- package/src/styles.css +22 -0
- package/src/support/chart-option.ts +130 -0
- package/src/support/export.ts +485 -0
- package/src/support/mastra-client.ts +883 -0
- package/src/support/mastra-stream.ts +66 -0
- package/src/support/shiki-plugin.ts +134 -0
- package/src/support/thread-sessions.ts +55 -0
- package/tsconfig.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @dbx-tools/ui-mastra
|
|
2
|
+
|
|
3
|
+
React chat UI for the AppKit-Mastra plugin.
|
|
4
|
+
|
|
5
|
+
Import this package when a Databricks App needs a production-ready chat surface
|
|
6
|
+
for [`@dbx-tools/node-appkit-mastra`](../../node/appkit-mastra): streaming
|
|
7
|
+
assistant responses, model selection, Genie progress events, inline charts/data
|
|
8
|
+
tables, tool approvals, conversation history, thread management, export, and
|
|
9
|
+
MLflow feedback.
|
|
10
|
+
|
|
11
|
+
Key features:
|
|
12
|
+
|
|
13
|
+
- Drop-in `MastraChat` component that discovers the plugin client config and
|
|
14
|
+
wires itself to the default agent.
|
|
15
|
+
- Headless `useMastraChat()` driver for apps that want the same transport logic
|
|
16
|
+
with custom layout.
|
|
17
|
+
- Controlled `ChatView` for hosts that own messages, streaming, model state, and
|
|
18
|
+
route calls themselves.
|
|
19
|
+
- `MastraPluginClient` wrapper around `@mastra/client-js` with AppKit-Mastra
|
|
20
|
+
routes for history, threads, model lists, suggestions, feedback, charts, and
|
|
21
|
+
statement data.
|
|
22
|
+
- Tool-approval support for suspended Mastra `requireApproval` calls, including
|
|
23
|
+
direct resumed-stream handling.
|
|
24
|
+
- Inline embed rendering for `[chart:<id>]` and `[data:<id>]` markers produced by
|
|
25
|
+
the server plugin.
|
|
26
|
+
- Conversation sidebar with new, select, rename, delete, active-thread, and
|
|
27
|
+
background-streaming states.
|
|
28
|
+
- Export menu for print/PDF and Markdown, resolving charts and tables so
|
|
29
|
+
exported conversations remain useful offline.
|
|
30
|
+
|
|
31
|
+
## Why Not Just AppKit UI?
|
|
32
|
+
|
|
33
|
+
Use native `@databricks/appkit-ui` when you need its general primitives, Genie
|
|
34
|
+
chat component, or Model Serving hooks directly against native AppKit plugins.
|
|
35
|
+
|
|
36
|
+
Use this package when the server is
|
|
37
|
+
[`@dbx-tools/node-appkit-mastra`](../../node/appkit-mastra) and the UI needs to
|
|
38
|
+
understand Mastra-specific behavior:
|
|
39
|
+
|
|
40
|
+
- `@mastra/client-js` agent streaming plus the plugin's custom history, threads,
|
|
41
|
+
models, suggestions, feedback, chart, and statement routes.
|
|
42
|
+
- Suspended `requireApproval` tool calls and resumed approve/deny streams.
|
|
43
|
+
- Genie writer events rendered as inline tool progress, not just a terminal
|
|
44
|
+
answer.
|
|
45
|
+
- `[chart:<id>]` and `[data:<id>]` assistant markers rendered as ECharts charts
|
|
46
|
+
and sortable tables.
|
|
47
|
+
- Conversation export that resolves those embeds into Markdown or print/PDF.
|
|
48
|
+
|
|
49
|
+
## Add The Styles
|
|
50
|
+
|
|
51
|
+
```css
|
|
52
|
+
@import "@databricks/appkit-ui/styles.css";
|
|
53
|
+
@import "@dbx-tools/ui-mastra/styles.css";
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The stylesheet imports the shared `@dbx-tools/ui-appkit` foundation and registers
|
|
57
|
+
this package's React files with Tailwind. It does not define design tokens; the
|
|
58
|
+
chat UI uses AppKit semantic tokens from the host app.
|
|
59
|
+
|
|
60
|
+
## Render A Drop-In Chat
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { MastraChat } from "@dbx-tools/ui-mastra/react";
|
|
64
|
+
|
|
65
|
+
export function App() {
|
|
66
|
+
return (
|
|
67
|
+
<MastraChat
|
|
68
|
+
agentId="analyst"
|
|
69
|
+
showModelPicker
|
|
70
|
+
enableThreads
|
|
71
|
+
enableExport
|
|
72
|
+
enableFeedback
|
|
73
|
+
className="h-dvh"
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`MastraChat` is the quickest client for the AppKit-Mastra plugin. It reads the
|
|
80
|
+
plugin's published client config, creates a `MastraPluginClient`, streams turns
|
|
81
|
+
through `agent.stream()`, hydrates the latest history page, and renders the
|
|
82
|
+
controlled `ChatView`.
|
|
83
|
+
|
|
84
|
+
Useful options:
|
|
85
|
+
|
|
86
|
+
- `agentId` selects a registered agent; defaults to the plugin default agent.
|
|
87
|
+
- `showModelPicker` fetches `/models` and sends `X-Mastra-Model` overrides.
|
|
88
|
+
- `suggestions` overrides Genie starter questions; omit it to auto-fetch
|
|
89
|
+
`/suggestions`, or pass `[]` to hide suggestions.
|
|
90
|
+
- `enableThreads` turns on persisted conversation selection and the sidebar.
|
|
91
|
+
- `enableExport` adds whole-conversation and per-message export affordances.
|
|
92
|
+
- `enableFeedback` enables thumbs/comment controls when the server reports
|
|
93
|
+
MLflow feedback is available and a turn produced a trace id.
|
|
94
|
+
|
|
95
|
+
## Use The Headless Driver
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { ChatView, useMastraChat } from "@dbx-tools/ui-mastra/react";
|
|
99
|
+
|
|
100
|
+
export function CustomChat() {
|
|
101
|
+
const chat = useMastraChat({
|
|
102
|
+
agentId: "analyst",
|
|
103
|
+
showModelPicker: true,
|
|
104
|
+
enableThreads: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return <ChatView {...chat} className="h-full" />;
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Use `useMastraChat()` when the stock behavior is right but the surrounding layout
|
|
112
|
+
belongs to your app. The hook owns streaming, aborts, history paging, thread
|
|
113
|
+
selection, model overrides, suggestions, exports, approvals, and feedback state.
|
|
114
|
+
|
|
115
|
+
## Build A Controlled Chat Surface
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import { ChatView, type ChatViewProps } from "@dbx-tools/ui-mastra/react";
|
|
119
|
+
|
|
120
|
+
export function ReviewChat(props: ChatViewProps) {
|
|
121
|
+
return <ChatView {...props} className="h-[640px]" />;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`ChatView` is presentational. It renders the header, model picker, conversation
|
|
126
|
+
sidebar, transcript, tool progress, approval cards, suggestions, export controls,
|
|
127
|
+
feedback controls, and composer from props. Use it when your app already has a
|
|
128
|
+
transport or needs to combine Mastra messages with another state model.
|
|
129
|
+
|
|
130
|
+
## Call Plugin Routes Directly
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import {
|
|
134
|
+
MastraPluginClient,
|
|
135
|
+
useMastraClient,
|
|
136
|
+
useMastraModels,
|
|
137
|
+
useMastraSuggestions,
|
|
138
|
+
useMastraThreads,
|
|
139
|
+
} from "@dbx-tools/ui-mastra/react";
|
|
140
|
+
|
|
141
|
+
const client = new MastraPluginClient(clientConfig);
|
|
142
|
+
client.setModelOverride("claude sonnet");
|
|
143
|
+
client.setThreadId(activeThreadId);
|
|
144
|
+
|
|
145
|
+
const models = await client.models();
|
|
146
|
+
const history = await client.history({ page: 0, perPage: 20 });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`MastraPluginClient` extends `@mastra/client-js` with the AppKit-Mastra custom
|
|
150
|
+
routes. It uses `credentials: "include"` so session cookies travel with streaming
|
|
151
|
+
and REST calls. The React hooks wrap common route calls for model catalogues,
|
|
152
|
+
suggestions, thread lists, chart fetches, and statement-data fetches.
|
|
153
|
+
|
|
154
|
+
## Approvals, Embeds, And Feedback
|
|
155
|
+
|
|
156
|
+
The UI understands the extra events produced by
|
|
157
|
+
[`@dbx-tools/node-appkit-mastra`](../../node/appkit-mastra):
|
|
158
|
+
|
|
159
|
+
- `tool-call-approval` chunks become inline approval cards and call
|
|
160
|
+
`approve-tool-call` / `decline-tool-call` when the user decides.
|
|
161
|
+
- Genie writer events render as tool progress, including thinking text, SQL, row
|
|
162
|
+
counts, result summaries, and chart/data markers.
|
|
163
|
+
- `[chart:<id>]` markers long-poll the chart cache and render ECharts inline.
|
|
164
|
+
- `[data:<id>]` markers fetch statement rows and render a sortable table with
|
|
165
|
+
column toggles and CSV export.
|
|
166
|
+
- MLflow trace headers enable per-message feedback controls when the server
|
|
167
|
+
reports feedback is available.
|
|
168
|
+
|
|
169
|
+
## Export Conversations
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
<MastraChat enableExport />
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Exports support Markdown downloads and print/PDF. Chart and data markers are
|
|
176
|
+
resolved during export: charts are rendered to inline SVG with ECharts' server
|
|
177
|
+
renderer, and data markers become real tables. Expired or missing embeds are
|
|
178
|
+
skipped so old transcripts still export cleanly.
|
|
179
|
+
|
|
180
|
+
## Modules
|
|
181
|
+
|
|
182
|
+
- `MastraChat` - self-contained drop-in chat component.
|
|
183
|
+
- `useMastraChat` - headless driver that returns `ChatView` props.
|
|
184
|
+
- `ChatView` - controlled presentational chat shell.
|
|
185
|
+
- `MastraPluginClient` - `@mastra/client-js` plus AppKit-Mastra custom routes.
|
|
186
|
+
- `useMastraClient`, `useMastraConfig`, `useMastraModels`,
|
|
187
|
+
`useMastraSuggestions`, `useMastraThreads`, `useChartFetch`,
|
|
188
|
+
`useStatementFetch` - route/config hooks for controlled clients.
|
|
189
|
+
- `ThreadSidebar` - controlled conversation list.
|
|
190
|
+
- `ExportMenu` - shared export format menu.
|
|
191
|
+
- Types - `ChatViewProps`, `MastraChatProps`, `UseMastraChatOptions`,
|
|
192
|
+
`ThreadSummary`, `ToolEvent`, `ToolProgress`, `PendingApproval`,
|
|
193
|
+
`FeedbackSubmission`, and related UI contract types.
|
|
194
|
+
|
|
195
|
+
Server-side routes and event production live in
|
|
196
|
+
[`@dbx-tools/node-appkit-mastra`](../../node/appkit-mastra). Browser-safe route,
|
|
197
|
+
marker, feedback, and wire schemas live in
|
|
198
|
+
[`@dbx-tools/shared-mastra`](../../shared/mastra).
|
package/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// GENERATED by projen watch - DO NOT EDIT.
|
|
2
|
+
// Regenerated from the exporting modules in ./src.
|
|
3
|
+
// Hand edits are overwritten on the next watch; this file is read-only.
|
|
4
|
+
|
|
5
|
+
export * as reactBubbles from "./src/react/bubbles";
|
|
6
|
+
export * as reactChatView from "./src/react/chat-view";
|
|
7
|
+
export * as reactDataGrid from "./src/react/data-grid";
|
|
8
|
+
export * as reactEmbedSlots from "./src/react/embed-slots";
|
|
9
|
+
export * as reactExportMenu from "./src/react/export-menu";
|
|
10
|
+
export * as reactFeedbackControls from "./src/react/feedback-controls";
|
|
11
|
+
export * as reactMarkdown from "./src/react/markdown";
|
|
12
|
+
export * as reactMastraChat from "./src/react/mastra-chat";
|
|
13
|
+
export * as reactSuggestionPills from "./src/react/suggestion-pills";
|
|
14
|
+
export * as reactSuggestions from "./src/react/suggestions";
|
|
15
|
+
export * as reactThreadSidebar from "./src/react/thread-sidebar";
|
|
16
|
+
export * as reactToolPill from "./src/react/tool-pill";
|
|
17
|
+
export * as reactTypes from "./src/react/types";
|
|
18
|
+
export * as supportChartOption from "./src/support/chart-option";
|
|
19
|
+
export * as supportExport from "./src/support/export";
|
|
20
|
+
export * as supportMastraClient from "./src/support/mastra-client";
|
|
21
|
+
export * as supportMastraStream from "./src/support/mastra-stream";
|
|
22
|
+
export * as supportShikiPlugin from "./src/support/shiki-plugin";
|
|
23
|
+
export * as supportThreadSessions from "./src/support/thread-sessions";
|
|
24
|
+
export type { DataRow } from "./src/react/data-grid";
|
|
25
|
+
export type { UseMastraChatOptions, MastraChatProps } from "./src/react/mastra-chat";
|
|
26
|
+
export type { SuggestionPillsProps } from "./src/react/suggestion-pills";
|
|
27
|
+
export type { ThreadSidebarProps } from "./src/react/thread-sidebar";
|
|
28
|
+
export type { ChatStatus, ToolEvent, ToolProgress, ChatModelOption, FeedbackValue, FeedbackSubmission, MessageFeedback, ThreadSummary, ChatViewProps, ApprovalDecision, PendingApproval } from "./src/react/types";
|
|
29
|
+
export type { ExportFormat, EmbedResolver, ExportChatOptions } from "./src/support/export";
|
|
30
|
+
export type { ByIdFetchState } from "./src/support/mastra-client";
|
|
31
|
+
export type { MastraStreamChunk, MastraStreamResponse } from "./src/support/mastra-stream";
|
|
32
|
+
export type { ThreadSession } from "./src/support/thread-sessions";
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dbx-tools/ui-mastra",
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "git+https://github.com/reggie-db/dbx-tools.git",
|
|
6
|
+
"directory": "workspaces/ui/mastra"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/node": "^24.6.0",
|
|
10
|
+
"@types/react": "^19.2.2",
|
|
11
|
+
"@types/react-dom": "^19.2.2",
|
|
12
|
+
"tsx": "^4.23.0",
|
|
13
|
+
"typescript": "^5.9.3"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@mastra/client-js": "^1.28.0",
|
|
17
|
+
"@tanstack/react-table": "^8.21.3",
|
|
18
|
+
"ai": "^5.0.0",
|
|
19
|
+
"echarts": "^6.0.0",
|
|
20
|
+
"echarts-for-react": "^3.0.2",
|
|
21
|
+
"lucide-react": "^0.554.0",
|
|
22
|
+
"marked": "^18.0.5",
|
|
23
|
+
"nanoid": "^5.1.6",
|
|
24
|
+
"react": "^19.2.4",
|
|
25
|
+
"react-dom": "^19.2.4",
|
|
26
|
+
"shiki": "^3.0.0",
|
|
27
|
+
"sql-formatter": "^15.6.9",
|
|
28
|
+
"streamdown": "^2.5.0",
|
|
29
|
+
"@dbx-tools/shared-core": "0.1.9",
|
|
30
|
+
"@dbx-tools/shared-mastra": "0.1.9",
|
|
31
|
+
"@dbx-tools/shared-genie": "0.1.9",
|
|
32
|
+
"@dbx-tools/shared-model": "0.1.9",
|
|
33
|
+
"@dbx-tools/ui-appkit": "0.1.9"
|
|
34
|
+
},
|
|
35
|
+
"main": "index.ts",
|
|
36
|
+
"license": "UNLICENSED",
|
|
37
|
+
"version": "0.1.9",
|
|
38
|
+
"types": "index.ts",
|
|
39
|
+
"type": "module",
|
|
40
|
+
"exports": {
|
|
41
|
+
"./react": "./src/react/index.ts",
|
|
42
|
+
"./styles.css": "./src/styles.css",
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"dbxToolsConfig": {
|
|
46
|
+
"tags": [
|
|
47
|
+
"ui"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"pnpm exec projen\".",
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "projen build",
|
|
53
|
+
"compile": "projen compile",
|
|
54
|
+
"default": "projen default",
|
|
55
|
+
"package": "projen package",
|
|
56
|
+
"post-compile": "projen post-compile",
|
|
57
|
+
"pre-compile": "projen pre-compile",
|
|
58
|
+
"test": "projen test",
|
|
59
|
+
"watch": "projen watch",
|
|
60
|
+
"projen": "projen"
|
|
61
|
+
}
|
|
62
|
+
}
|