@dbx-tools/ui-mastra 0.9.177 → 0.9.179

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/index.react.ts CHANGED
@@ -28,12 +28,12 @@ export * as types from "./src/react/types.ts";
28
28
  export { AssistantBubble, UserBubble } from "./src/react/bubbles.tsx";
29
29
  export { resolveApprovalContinuation, useChatApprovals } from "./src/react/chat-approvals.ts";
30
30
  export { ChatComposer } from "./src/react/chat-composer.tsx";
31
- export { genieFeedbackTarget, useChatFeedback } from "./src/react/chat-feedback.ts";
32
- export type { GenieFeedbackTarget } from "./src/react/chat-feedback.ts";
31
+ export { genieFeedbackTarget, messageFeedbackDestination, mlflowTraceUrl, useChatFeedback } from "./src/react/chat-feedback.ts";
32
+ export type { GenieFeedbackTarget, MessageFeedbackDestination } from "./src/react/chat-feedback.ts";
33
33
  export { useChatHistory } from "./src/react/chat-history.ts";
34
34
  export { useChatSessions } from "./src/react/chat-sessions.ts";
35
35
  export type { ThreadSessionReader, ThreadSessionUpdater, ThreadMessageWriter } from "./src/react/chat-sessions.ts";
36
- export { readMlflowTracePart, chatStatusForChunk, closeOnTerminalChunk, waitForTerminalChunk, useChatStream } from "./src/react/chat-stream.ts";
36
+ export { readMlflowTracePart, readThreadTitlePart, chatStatusForChunk, closeOnTerminalChunk, waitForTerminalChunk, useChatStream } from "./src/react/chat-stream.ts";
37
37
  export { ChatThreadLayout } from "./src/react/chat-thread-layout.tsx";
38
38
  export { useChatTranscriptController, ChatTranscript } from "./src/react/chat-transcript.tsx";
39
39
  export type { ChatTranscriptController } from "./src/react/chat-transcript.tsx";
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.177";
6
+ export const PACKAGE_VERSION = "0.9.179";
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.177",
36
- "@dbx-tools/shared-core": "^0.9.177",
37
- "@dbx-tools/shared-genie": "^0.9.177",
38
- "@dbx-tools/shared-mastra": "^0.9.177",
39
- "@dbx-tools/shared-model": "^0.9.177",
40
- "@dbx-tools/ui": "^0.9.177",
35
+ "@dbx-tools/shared-auth": "^0.9.179",
36
+ "@dbx-tools/shared-core": "^0.9.179",
37
+ "@dbx-tools/shared-genie": "^0.9.179",
38
+ "@dbx-tools/shared-mastra": "^0.9.179",
39
+ "@dbx-tools/shared-model": "^0.9.179",
40
+ "@dbx-tools/ui": "^0.9.179",
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.177",
58
+ "version": "0.9.179",
59
59
  "types": "index.ts",
60
60
  "dbxToolsConfig": {
61
61
  "tags": [
@@ -339,8 +339,8 @@ type AssistantBubbleProps = {
339
339
  feedbackRequest?: string;
340
340
  /** Last thumbs the user left on this message, for highlighting. */
341
341
  feedbackValue?: FeedbackValue;
342
- /** MLflow experiment link shown only to viewers with `CAN_MANAGE`. */
343
- mlflowExperimentUrl?: string;
342
+ /** MLflow trace link shown only to viewers with `CAN_MANAGE`. */
343
+ mlflowTraceUrl?: string;
344
344
  };
345
345
 
346
346
  /** Render one assistant message with tool progress, actions, and optional feedback. */
@@ -357,7 +357,7 @@ export const AssistantBubble = ({
357
357
  feedbackMode,
358
358
  feedbackRequest,
359
359
  feedbackValue,
360
- mlflowExperimentUrl,
360
+ mlflowTraceUrl,
361
361
  }: AssistantBubbleProps) => {
362
362
  const pendingApprovals = mergePendingApprovals(
363
363
  collectPendingApprovals(message.parts),
@@ -398,7 +398,7 @@ export const AssistantBubble = ({
398
398
  hasText || activityItems.length > 0 || pendingApprovals.length > 0,
399
399
  );
400
400
  const hasFooterActions =
401
- hasText && (isLast || Boolean(onExport) || Boolean(onFeedback) || Boolean(mlflowExperimentUrl));
401
+ hasText && (isLast || Boolean(onExport) || Boolean(onFeedback) || Boolean(mlflowTraceUrl));
402
402
  const showFooter = showResponseStatus || hasFooterActions;
403
403
  // Charts and tables are placed at inline marker positions in
404
404
  // the assistant's prose. `prepare_chart` / `render_data` mint
@@ -499,21 +499,21 @@ export const AssistantBubble = ({
499
499
  {...(feedbackValue ? { value: feedbackValue } : {})}
500
500
  />
501
501
  )}
502
- {hasText && mlflowExperimentUrl && (
502
+ {hasText && mlflowTraceUrl && (
503
503
  <Tooltip>
504
504
  <TooltipTrigger asChild>
505
505
  <Button asChild type="button" size="icon" variant="ghost" className="size-7">
506
506
  <a
507
- href={mlflowExperimentUrl}
507
+ href={mlflowTraceUrl}
508
508
  target="_blank"
509
509
  rel="noreferrer"
510
- aria-label="Open MLflow experiment"
510
+ aria-label="Open MLflow trace"
511
511
  >
512
512
  <BugIcon className="size-3" />
513
513
  </a>
514
514
  </Button>
515
515
  </TooltipTrigger>
516
- <TooltipContent>Open MLflow experiment</TooltipContent>
516
+ <TooltipContent>Open MLflow trace</TooltipContent>
517
517
  </Tooltip>
518
518
  )}
519
519
  {showResponseStatus && (
@@ -1,6 +1,6 @@
1
1
  import { log, toError } from "@dbx-tools/shared-core";
2
2
  import { GenieMessageSchema } from "@dbx-tools/shared-genie";
3
- import type { FeedbackMode } from "@dbx-tools/shared-mastra";
3
+ import type { FeedbackDestination } from "@dbx-tools/shared-mastra";
4
4
  import type { UIMessage } from "ai";
5
5
  import { useCallback, useRef } from "react";
6
6
  import type { ThreadSessionUpdater } from "./chat-sessions.ts";
@@ -13,7 +13,7 @@ const logger = log.logger("ui-mastra/chat");
13
13
  interface UseChatFeedbackOptions {
14
14
  activeKey: string;
15
15
  feedbackByMessage: Record<string, MessageFeedback>;
16
- feedbackMode: FeedbackMode;
16
+ feedbackModes: readonly FeedbackDestination[];
17
17
  mastraClient: MastraPluginClient;
18
18
  updateSession: ThreadSessionUpdater;
19
19
  }
@@ -25,6 +25,11 @@ export interface GenieFeedbackTarget {
25
25
  messageId: string;
26
26
  }
27
27
 
28
+ /** Per-message feedback destination and optional Genie identity. */
29
+ export type MessageFeedbackDestination =
30
+ | { mode: "mlflow"; traceId: string }
31
+ | ({ mode: "genie" } & GenieFeedbackTarget);
32
+
28
33
  /** Read the latest Genie target from an assistant message's tool results. */
29
34
  export function genieFeedbackTarget(message: UIMessage): GenieFeedbackTarget | undefined {
30
35
  for (const event of [...toolEventsFromParts(message.parts)].reverse()) {
@@ -48,11 +53,34 @@ export function genieFeedbackTarget(message: UIMessage): GenieFeedbackTarget | u
48
53
  return undefined;
49
54
  }
50
55
 
51
- /** Submit feedback to the single destination selected by the server. */
56
+ /** Select Genie for a Genie result, otherwise MLflow for a traced response. */
57
+ export function messageFeedbackDestination(
58
+ message: UIMessage,
59
+ feedbackModes: readonly FeedbackDestination[],
60
+ traceId?: string,
61
+ ): MessageFeedbackDestination | undefined {
62
+ const genieTarget = feedbackModes.includes("genie") ? genieFeedbackTarget(message) : undefined;
63
+ if (genieTarget) return { mode: "genie", ...genieTarget };
64
+ if (traceId && feedbackModes.includes("mlflow")) return { mode: "mlflow", traceId };
65
+ return undefined;
66
+ }
67
+
68
+ /** Build the Databricks MLflow detail URL for one captured trace. */
69
+ export function mlflowTraceUrl(experimentUrl: string, traceId?: string): string | undefined {
70
+ const resolvedTraceId = traceId?.trim();
71
+ if (!resolvedTraceId) return undefined;
72
+ const url = new URL(experimentUrl);
73
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}/traces/${encodeURIComponent(resolvedTraceId)}`;
74
+ url.search = "";
75
+ url.hash = "";
76
+ return url.toString();
77
+ }
78
+
79
+ /** Submit feedback to the destination selected for the assistant message. */
52
80
  export function useChatFeedback({
53
81
  activeKey,
54
82
  feedbackByMessage,
55
- feedbackMode,
83
+ feedbackModes,
56
84
  mastraClient,
57
85
  updateSession,
58
86
  }: UseChatFeedbackOptions) {
@@ -62,8 +90,8 @@ export function useChatFeedback({
62
90
  return useCallback(
63
91
  async (message: UIMessage, submission: FeedbackSubmission) => {
64
92
  const traceId = feedbackByMessageRef.current[message.id]?.traceId;
65
- const target = feedbackMode === "genie" ? genieFeedbackTarget(message) : undefined;
66
- if (feedbackMode === "none") return;
93
+ const destination = messageFeedbackDestination(message, feedbackModes, traceId);
94
+ if (!destination) return;
67
95
 
68
96
  if (submission.value) {
69
97
  updateSession(activeKey, (session) => ({
@@ -79,38 +107,39 @@ export function useChatFeedback({
79
107
  }
80
108
  try {
81
109
  let result;
82
- if (feedbackMode === "genie") {
83
- if (!target || !submission.value || !submission.request) return;
110
+ if (destination.mode === "genie") {
111
+ if (!submission.value || !submission.request) return;
84
112
  result = await mastraClient.feedback({
85
113
  mode: "genie",
86
- ...target,
114
+ spaceId: destination.spaceId,
115
+ conversationId: destination.conversationId,
116
+ messageId: destination.messageId,
87
117
  rating: submission.value === "up" ? "POSITIVE" : "NEGATIVE",
88
118
  request: submission.request,
89
119
  ...(submission.comment ? { comment: submission.comment } : {}),
90
120
  });
91
121
  } else {
92
- if (!traceId) return;
93
122
  result = await mastraClient.feedback({
94
123
  mode: "mlflow",
95
- traceId,
124
+ traceId: destination.traceId,
96
125
  ...(submission.value !== undefined ? { value: submission.value === "up" } : {}),
97
126
  ...(submission.comment ? { comment: submission.comment } : {}),
98
127
  });
99
128
  }
100
129
  if (!result.ok) {
101
130
  logger.warn("feedback not recorded", {
102
- feedbackMode,
131
+ feedbackMode: destination.mode,
103
132
  ...(traceId ? { traceId } : {}),
104
133
  });
105
134
  }
106
135
  } catch (error) {
107
136
  logger.error("feedback error", {
108
- feedbackMode,
137
+ feedbackMode: destination.mode,
109
138
  ...(traceId ? { traceId } : {}),
110
139
  error: toError(error),
111
140
  });
112
141
  }
113
142
  },
114
- [activeKey, feedbackMode, mastraClient, updateSession],
143
+ [activeKey, feedbackModes, mastraClient, updateSession],
115
144
  );
116
145
  }
@@ -4,6 +4,8 @@ import {
4
4
  MLFLOW_TRACE_PART_TYPE,
5
5
  MlflowTracePartDataSchema,
6
6
  RESPONSE_COMPLETE_PART_TYPE,
7
+ THREAD_TITLE_PART_TYPE,
8
+ ThreadTitlePartDataSchema,
7
9
  isStaleMastraResumeError,
8
10
  } from "@dbx-tools/shared-mastra";
9
11
  import { readUIMessageStream, type UIMessage, type UIMessageChunk } from "ai";
@@ -31,10 +33,17 @@ export const readMlflowTracePart = (chunk: UIMessageChunk): string | undefined =
31
33
  return parsed.success ? parsed.data.traceId : undefined;
32
34
  };
33
35
 
36
+ /** Read a generated title synchronized onto the terminal chat stream. */
37
+ export const readThreadTitlePart = (chunk: UIMessageChunk): string | undefined => {
38
+ if ((chunk as { type?: string }).type !== THREAD_TITLE_PART_TYPE) return undefined;
39
+ const parsed = ThreadTitlePartDataSchema.safeParse((chunk as { data?: unknown }).data);
40
+ return parsed.success ? parsed.data.title : undefined;
41
+ };
42
+
34
43
  /** Map lifecycle-only chunks onto the UI's active-turn state. */
35
44
  export const chatStatusForChunk = (chunk: UIMessageChunk): ChatStatus | undefined => {
36
45
  if ((chunk as { type?: string }).type === RESPONSE_COMPLETE_PART_TYPE) return "finishing";
37
- if (chunk.type === "finish" || chunk.type === "abort") return "ready";
46
+ if (chunk.type === "finish" || chunk.type === "abort") return "finishing";
38
47
  return undefined;
39
48
  };
40
49
 
@@ -139,6 +148,7 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
139
148
 
140
149
  try {
141
150
  let terminalReceived = false;
151
+ let threadTitle: string | undefined;
142
152
  const existing = getSession(threadId).messages.find(
143
153
  (message) => message.id === assistantId,
144
154
  );
@@ -151,6 +161,7 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
151
161
  },
152
162
  (chunk) => {
153
163
  recordTraceId(readMlflowTracePart(chunk));
164
+ threadTitle = readThreadTitlePart(chunk) ?? threadTitle;
154
165
  const status = chatStatusForChunk(chunk);
155
166
  if (!status) return;
156
167
  updateSession(threadId, (current) => ({
@@ -169,19 +180,18 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
169
180
  runId: runIdRef.current,
170
181
  status:
171
182
  terminalReceived || current.status === "finishing"
172
- ? terminalReceived
173
- ? "ready"
174
- : "finishing"
183
+ ? "finishing"
175
184
  : "streaming",
176
185
  }));
177
186
  }
187
+ return threadTitle;
178
188
  } catch (error) {
179
- if (error instanceof StreamAborted || signal.aborted) return;
189
+ if (error instanceof StreamAborted || signal.aborted) return undefined;
180
190
  if (isStaleMastraResumeError(error)) {
181
191
  logger.warn("ignored stale mastra resume", {
182
192
  error: toError(error),
183
193
  });
184
- return;
194
+ return undefined;
185
195
  }
186
196
  throw error;
187
197
  }
@@ -15,7 +15,7 @@ import { isToolUIPart } from "ai";
15
15
  import { ArrowDownIcon, MessageSquareIcon, RefreshCwIcon, TriangleAlertIcon } from "lucide-react";
16
16
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
17
17
  import { AssistantBubble, UserBubble } from "./bubbles.tsx";
18
- import { genieFeedbackTarget } from "./chat-feedback.ts";
18
+ import { messageFeedbackDestination, mlflowTraceUrl } from "./chat-feedback.ts";
19
19
  import { SuggestionPills } from "./suggestion-pills.tsx";
20
20
  import { isRespondingChatStatus, type ChatViewProps } from "./types.ts";
21
21
  import { messageText } from "../support/export.ts";
@@ -160,7 +160,7 @@ type ChatTranscriptProps = {
160
160
  pendingApprovalsByMessage: NonNullable<ChatViewProps["pendingApprovalsByMessage"]>;
161
161
  onExportMessage: ChatViewProps["onExportMessage"];
162
162
  feedbackByMessage: NonNullable<ChatViewProps["feedbackByMessage"]>;
163
- feedbackMode: NonNullable<ChatViewProps["feedbackMode"]>;
163
+ feedbackModes: NonNullable<ChatViewProps["feedbackModes"]>;
164
164
  onFeedback: ChatViewProps["onFeedback"];
165
165
  mlflowExperimentUrl: ChatViewProps["mlflowExperimentUrl"];
166
166
  };
@@ -182,7 +182,7 @@ export const ChatTranscript = ({
182
182
  pendingApprovalsByMessage,
183
183
  onExportMessage,
184
184
  feedbackByMessage,
185
- feedbackMode,
185
+ feedbackModes,
186
186
  onFeedback,
187
187
  mlflowExperimentUrl,
188
188
  }: ChatTranscriptProps) => {
@@ -198,7 +198,7 @@ export const ChatTranscript = ({
198
198
  isToolUIPart(part) ||
199
199
  part.type === "data-tool-call-approval",
200
200
  ) || (lastEvents?.length ?? 0) > 0;
201
- const showWaitingIndicator = isRunning && !lastAssistantHasContent;
201
+ const showWaitingIndicator = status === "finishing" || (isRunning && !lastAssistantHasContent);
202
202
 
203
203
  return (
204
204
  <div className="relative flex min-w-0 max-w-full flex-1 flex-col overflow-hidden">
@@ -236,17 +236,18 @@ export const ChatTranscript = ({
236
236
  const isLast = index === messages.length - 1;
237
237
  if (message.role === "assistant") {
238
238
  const messageFeedback = feedbackByMessage[message.id];
239
- const genieTarget =
240
- feedbackMode === "genie" ? genieFeedbackTarget(message) : undefined;
241
- const canSubmitFeedback =
242
- feedbackMode === "mlflow"
243
- ? Boolean(messageFeedback?.traceId)
244
- : Boolean(genieTarget);
239
+ const feedbackDestination = messageFeedbackDestination(
240
+ message,
241
+ feedbackModes,
242
+ messageFeedback?.traceId,
243
+ );
244
+ const traceUrl = mlflowExperimentUrl
245
+ ? mlflowTraceUrl(mlflowExperimentUrl, messageFeedback?.traceId)
246
+ : undefined;
245
247
  const requestMessage = [...messages.slice(0, index)]
246
248
  .reverse()
247
249
  .find((candidate) => candidate.role === "user");
248
250
  const feedbackRequest = requestMessage ? messageText(requestMessage) : "";
249
- const bubbleFeedbackMode = feedbackMode === "genie" ? "genie" : "mlflow";
250
251
  return (
251
252
  <AssistantBubble
252
253
  key={message.id}
@@ -260,17 +261,17 @@ export const ChatTranscript = ({
260
261
  {...(onExportMessage
261
262
  ? { onExport: (format) => onExportMessage(message, format) }
262
263
  : {})}
263
- {...(onFeedback && canSubmitFeedback
264
+ {...(onFeedback && feedbackDestination
264
265
  ? {
265
266
  onFeedback: (submission) => onFeedback(message, submission),
266
- feedbackMode: bubbleFeedbackMode,
267
+ feedbackMode: feedbackDestination.mode,
267
268
  ...(feedbackRequest ? { feedbackRequest } : {}),
268
269
  ...(messageFeedback?.value
269
270
  ? { feedbackValue: messageFeedback.value }
270
271
  : {}),
271
272
  }
272
273
  : {})}
273
- {...(mlflowExperimentUrl ? { mlflowExperimentUrl } : {})}
274
+ {...(traceUrl ? { mlflowTraceUrl: traceUrl } : {})}
274
275
  />
275
276
  );
276
277
  }
@@ -67,7 +67,7 @@ export const ChatView = ({
67
67
  onExportConversation,
68
68
  onExportMessage,
69
69
  feedbackByMessage = {},
70
- feedbackMode = "none",
70
+ feedbackModes = [],
71
71
  onFeedback,
72
72
  mlflowExperimentUrl,
73
73
  }: ChatViewProps) => {
@@ -130,7 +130,7 @@ export const ChatView = ({
130
130
  pendingApprovalsByMessage={pendingApprovalsByMessage}
131
131
  onExportMessage={onExportMessage}
132
132
  feedbackByMessage={feedbackByMessage}
133
- feedbackMode={feedbackMode}
133
+ feedbackModes={feedbackModes}
134
134
  onFeedback={onFeedback}
135
135
  mlflowExperimentUrl={mlflowExperimentUrl}
136
136
  />
@@ -2,7 +2,6 @@ import {
2
2
  Button,
3
3
  Dialog,
4
4
  DialogContent,
5
- DialogDescription,
6
5
  DialogFooter,
7
6
  DialogHeader,
8
7
  DialogTitle,
@@ -17,13 +16,7 @@ import { MessageSquareTextIcon, ThumbsDownIcon, ThumbsUpIcon } from "lucide-reac
17
16
  import { useState } from "react";
18
17
  import type { FeedbackSubmission, FeedbackValue } from "./types.ts";
19
18
 
20
- // Per-message feedback action row: thumbs up/down that log immediately,
21
- // plus a separate comment affordance that opens a modal for freeform
22
- // text. Rendered inside the assistant bubble's action row when the host
23
- // wires feedback (which only happens when MLflow logging is enabled and
24
- // the turn has a captured trace id).
25
-
26
- /** Render per-message rating and comment controls for an MLflow-backed trace. */
19
+ /** Render per-message rating controls and a dedicated written-feedback modal. */
27
20
  export const FeedbackControls = ({
28
21
  mode = "mlflow",
29
22
  request,
@@ -32,7 +25,7 @@ export const FeedbackControls = ({
32
25
  }: {
33
26
  /** Server-selected feedback destination. */
34
27
  mode?: "mlflow" | "genie";
35
- /** Original user request shown in Genie feedback. */
28
+ /** Original user request required by Genie feedback. */
36
29
  request?: string;
37
30
  /** Last thumbs the user chose, so the active button stays highlighted. */
38
31
  value?: FeedbackValue;
@@ -40,119 +33,36 @@ export const FeedbackControls = ({
40
33
  }) => {
41
34
  const [open, setOpen] = useState(false);
42
35
  const [comment, setComment] = useState("");
43
- const [rating, setRating] = useState<FeedbackValue | undefined>(value);
44
36
  const [sending, setSending] = useState(false);
37
+ const genieRequest = request?.trim();
38
+ const canComment = mode === "mlflow" || Boolean(value && genieRequest);
45
39
 
46
- const submitComment = async () => {
47
- const text = comment.trim();
48
- if (!text || sending) return;
49
- setSending(true);
50
- try {
51
- await onSubmit({ comment: text });
52
- setComment("");
53
- setOpen(false);
54
- } finally {
55
- setSending(false);
40
+ const submitRating = (rating: FeedbackValue) => {
41
+ if (mode === "genie") {
42
+ if (!genieRequest) return;
43
+ void onSubmit({ value: rating, request: genieRequest });
44
+ return;
56
45
  }
46
+ void onSubmit({ value: rating });
57
47
  };
58
48
 
59
- const submitGenieFeedback = async () => {
60
- if (!rating || !request?.trim() || sending) return;
49
+ const submitComment = async () => {
50
+ const text = comment.trim();
51
+ if (!text || sending) return;
52
+ if (mode === "genie" && (!value || !genieRequest)) return;
61
53
  setSending(true);
62
54
  try {
63
55
  await onSubmit({
64
- value: rating,
65
- request: request.trim(),
66
- ...(comment.trim() ? { comment: comment.trim() } : {}),
56
+ ...(mode === "genie" ? { value, request: genieRequest } : {}),
57
+ comment: text,
67
58
  });
59
+ setComment("");
68
60
  setOpen(false);
69
61
  } finally {
70
62
  setSending(false);
71
63
  }
72
64
  };
73
65
 
74
- if (mode === "genie") {
75
- return (
76
- <Dialog open={open} onOpenChange={setOpen}>
77
- <Tooltip>
78
- <TooltipTrigger asChild>
79
- <DialogTrigger asChild>
80
- <Button
81
- type="button"
82
- size="icon"
83
- variant="ghost"
84
- className="size-7"
85
- aria-label="Give feedback"
86
- >
87
- <MessageSquareTextIcon className="size-3" />
88
- </Button>
89
- </DialogTrigger>
90
- </TooltipTrigger>
91
- <TooltipContent>Give feedback</TooltipContent>
92
- </Tooltip>
93
- <DialogContent className="sm:max-w-md">
94
- <DialogHeader>
95
- <DialogTitle>Feedback</DialogTitle>
96
- <DialogDescription>Send feedback directly to this Genie response.</DialogDescription>
97
- </DialogHeader>
98
- <div className="space-y-4">
99
- <fieldset className="space-y-2">
100
- <legend className="text-sm font-medium">Rating</legend>
101
- <div className="flex gap-2">
102
- <Button
103
- type="button"
104
- variant={rating === "up" ? "default" : "outline"}
105
- aria-pressed={rating === "up"}
106
- onClick={() => setRating("up")}
107
- >
108
- <ThumbsUpIcon className="size-4" />
109
- Good
110
- </Button>
111
- <Button
112
- type="button"
113
- variant={rating === "down" ? "destructive" : "outline"}
114
- aria-pressed={rating === "down"}
115
- onClick={() => setRating("down")}
116
- >
117
- <ThumbsDownIcon className="size-4" />
118
- Bad
119
- </Button>
120
- </div>
121
- </fieldset>
122
- <div className="space-y-1.5">
123
- <p className="text-sm font-medium">Request</p>
124
- <p className="rounded-md border bg-muted/40 px-3 py-2 text-sm text-foreground">
125
- {request}
126
- </p>
127
- </div>
128
- <label className="block space-y-1.5 text-sm font-medium">
129
- <span>Comment</span>
130
- <Textarea
131
- value={comment}
132
- maxLength={5_000}
133
- onChange={(event) => setComment(event.target.value)}
134
- placeholder="Optional details"
135
- rows={4}
136
- />
137
- </label>
138
- </div>
139
- <DialogFooter>
140
- <Button type="button" variant="ghost" onClick={() => setOpen(false)}>
141
- Cancel
142
- </Button>
143
- <Button
144
- type="button"
145
- disabled={!rating || !request?.trim() || sending}
146
- onClick={() => void submitGenieFeedback()}
147
- >
148
- {sending ? "Sending..." : "Send feedback"}
149
- </Button>
150
- </DialogFooter>
151
- </DialogContent>
152
- </Dialog>
153
- );
154
- }
155
-
156
66
  return (
157
67
  <>
158
68
  <Tooltip>
@@ -164,7 +74,7 @@ export const FeedbackControls = ({
164
74
  className={cn("size-7", value === "up" && "text-success")}
165
75
  aria-label="Good response"
166
76
  aria-pressed={value === "up"}
167
- onClick={() => void onSubmit({ value: "up" })}
77
+ onClick={() => submitRating("up")}
168
78
  >
169
79
  <ThumbsUpIcon className="size-3" />
170
80
  </Button>
@@ -180,7 +90,7 @@ export const FeedbackControls = ({
180
90
  className={cn("size-7", value === "down" && "text-destructive")}
181
91
  aria-label="Bad response"
182
92
  aria-pressed={value === "down"}
183
- onClick={() => void onSubmit({ value: "down" })}
93
+ onClick={() => submitRating("down")}
184
94
  >
185
95
  <ThumbsDownIcon className="size-3" />
186
96
  </Button>
@@ -190,33 +100,34 @@ export const FeedbackControls = ({
190
100
  <Dialog open={open} onOpenChange={setOpen}>
191
101
  <Tooltip>
192
102
  <TooltipTrigger asChild>
193
- <DialogTrigger asChild>
103
+ <DialogTrigger asChild disabled={!canComment}>
194
104
  <Button
195
105
  type="button"
196
106
  size="icon"
197
107
  variant="ghost"
198
108
  className="size-7"
199
- aria-label="Leave a comment"
109
+ aria-label={canComment ? "Leave written feedback" : "Rate the response first"}
110
+ disabled={!canComment}
200
111
  >
201
112
  <MessageSquareTextIcon className="size-3" />
202
113
  </Button>
203
114
  </DialogTrigger>
204
115
  </TooltipTrigger>
205
- <TooltipContent>Leave a comment</TooltipContent>
116
+ <TooltipContent>
117
+ {canComment ? "Leave written feedback" : "Rate the response first"}
118
+ </TooltipContent>
206
119
  </Tooltip>
207
120
  <DialogContent className="sm:max-w-md">
208
121
  <DialogHeader>
209
122
  <DialogTitle>Share feedback</DialogTitle>
210
- <DialogDescription>
211
- Tell us what worked well or what could be improved.
212
- </DialogDescription>
213
123
  </DialogHeader>
214
124
  <Textarea
215
125
  value={comment}
216
- onChange={(e) => setComment(e.target.value)}
217
- onKeyDown={(e) => {
218
- if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
219
- e.preventDefault();
126
+ maxLength={5_000}
127
+ onChange={(event) => setComment(event.target.value)}
128
+ onKeyDown={(event) => {
129
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
130
+ event.preventDefault();
220
131
  void submitComment();
221
132
  }
222
133
  }}
@@ -225,9 +136,6 @@ export const FeedbackControls = ({
225
136
  autoFocus
226
137
  />
227
138
  <DialogFooter>
228
- <Button type="button" variant="ghost" onClick={() => setOpen(false)}>
229
- Cancel
230
- </Button>
231
139
  <Button
232
140
  type="button"
233
141
  disabled={!comment.trim() || sending}
@@ -324,9 +324,11 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
324
324
  // Feedback defaults to automatic server capability detection. An explicit
325
325
  // false hides it; true keeps it requested but cannot bypass the server gate.
326
326
  const enableFeedback = options.enableFeedback !== false;
327
- const feedbackMode = enableFeedback ? mastraClient.feedbackMode : "none";
328
- const feedbackAvailable = feedbackMode !== "none";
329
- const { url: mlflowExperimentUrl } = useMastraMlflowExperiment(feedbackMode === "mlflow");
327
+ const feedbackModes = enableFeedback ? mastraClient.feedbackModes : [];
328
+ const feedbackAvailable = feedbackModes.length > 0;
329
+ const { url: mlflowExperimentUrl } = useMastraMlflowExperiment(
330
+ feedbackModes.includes("mlflow"),
331
+ );
330
332
  const [resourceScope, setResourceScope] = useState<string | null>(null);
331
333
  useEffect(() => {
332
334
  let cancelled = false;
@@ -402,6 +404,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
402
404
  loading: isLoadingThreads,
403
405
  error: threadsError,
404
406
  refresh: refreshThreads,
407
+ sync: syncThreads,
405
408
  } = useMastraThreads(options.agentId, enableThreads, genieClient);
406
409
  // Persist the active thread id so a reload reopens the same
407
410
  // conversation. Best-effort; storage may be unavailable.
@@ -573,7 +576,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
573
576
  const submitFeedback = useChatFeedback({
574
577
  activeKey,
575
578
  feedbackByMessage: activeSession.feedbackByMessage,
576
- feedbackMode,
579
+ feedbackModes,
577
580
  mastraClient,
578
581
  updateSession,
579
582
  });
@@ -636,6 +639,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
636
639
  // The session's key; changes when the server assigns the thread its id.
637
640
  let sessionThreadId = threadId;
638
641
  let openedStream: MastraStreamResponse | undefined;
642
+ let streamedTitle: string | undefined;
639
643
  const adoptAssignedThreadId = () => {
640
644
  const assigned = openedStream?.threadId?.();
641
645
  if (!assigned || assigned === sessionThreadId) return;
@@ -645,7 +649,13 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
645
649
  try {
646
650
  try {
647
651
  openedStream = await open(controller.signal);
648
- await processStream(threadId, openedStream, assistantId, runIdRef, controller.signal);
652
+ streamedTitle = await processStream(
653
+ threadId,
654
+ openedStream,
655
+ assistantId,
656
+ runIdRef,
657
+ controller.signal,
658
+ );
649
659
  adoptAssignedThreadId();
650
660
  } catch (initialError) {
651
661
  const runId = runIdRef.current;
@@ -675,12 +685,56 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
675
685
  threadId: streamThreadId,
676
686
  signal: controller.signal,
677
687
  });
678
- await processStream(threadId, stream, assistantId, runIdRef, controller.signal);
688
+ streamedTitle = await processStream(
689
+ threadId,
690
+ stream,
691
+ assistantId,
692
+ runIdRef,
693
+ controller.signal,
694
+ );
679
695
  } catch (reconnectError) {
680
696
  writeMessages(threadId, messagesBeforeReplay);
681
697
  throw reconnectError;
682
698
  }
683
699
  }
700
+ if (streamedTitle) {
701
+ const title = streamedTitle;
702
+ setProvisionalTitles((prev) => ({ ...prev, [sessionThreadId]: title }));
703
+ setOptimisticThreads((prev) =>
704
+ prev[sessionThreadId]
705
+ ? {
706
+ ...prev,
707
+ [sessionThreadId]: {
708
+ ...prev[sessionThreadId],
709
+ title,
710
+ },
711
+ }
712
+ : prev,
713
+ );
714
+ }
715
+ if (enableThreads) {
716
+ const synchronized = await syncThreads();
717
+ const generatedTitle = synchronized
718
+ .find((thread) => thread.id === sessionThreadId)
719
+ ?.title?.trim();
720
+ if (generatedTitle) {
721
+ setProvisionalTitles((prev) => ({
722
+ ...prev,
723
+ [sessionThreadId]: generatedTitle,
724
+ }));
725
+ setOptimisticThreads((prev) =>
726
+ prev[sessionThreadId]
727
+ ? {
728
+ ...prev,
729
+ [sessionThreadId]: {
730
+ ...prev[sessionThreadId],
731
+ title: generatedTitle,
732
+ },
733
+ }
734
+ : prev,
735
+ );
736
+ }
737
+ }
684
738
  updateSession(sessionThreadId, (session) => {
685
739
  if (session.runToken !== token) return session;
686
740
  return {
@@ -694,7 +748,6 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
694
748
  if (getSession(sessionThreadId).runToken === token) {
695
749
  const completedRunId = runIdRef.current;
696
750
  if (completedRunId) removeStoredActiveRun(activeRunsKey, completedRunId);
697
- refreshThreadsSoon();
698
751
  // Turn finished on its own: start the oldest queued steer, if any.
699
752
  drainQueueRef.current(sessionThreadId);
700
753
  }
@@ -742,10 +795,12 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
742
795
  adoptThreadId,
743
796
  agentId,
744
797
  activeRunsKey,
798
+ enableThreads,
745
799
  getSession,
746
800
  mastraClient,
747
801
  processStream,
748
802
  refreshThreadsSoon,
803
+ syncThreads,
749
804
  updateSession,
750
805
  writeMessages,
751
806
  ],
@@ -991,26 +1046,30 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
991
1046
  text: string,
992
1047
  files: FileUIPart[] = [],
993
1048
  ): { message: UIMessage; next: UIMessage[] } => {
1049
+ const session = getSession(threadId);
1050
+ const expectsTitle =
1051
+ enableThreads &&
1052
+ !threads.some((thread) => thread.id === threadId && Boolean(thread.title?.trim()));
1053
+ let provisionalTitle: string | undefined;
994
1054
  if (activeThreadId) {
995
1055
  noteThreadActivity(activeThreadId);
996
- if (getSession(threadId).messages.length === 0) {
997
- const provisional = deriveThreadTitle(
1056
+ if (expectsTitle) {
1057
+ provisionalTitle = deriveThreadTitle(
998
1058
  text || files.map((file) => file.filename || "Image").join(", "),
999
1059
  );
1000
- if (provisional) {
1060
+ if (provisionalTitle) {
1001
1061
  setProvisionalTitles((prev) =>
1002
- prev[activeThreadId] ? prev : { ...prev, [activeThreadId]: provisional },
1062
+ prev[activeThreadId] ? prev : { ...prev, [activeThreadId]: provisionalTitle! },
1003
1063
  );
1004
1064
  }
1005
1065
  }
1006
1066
  }
1007
- const session = getSession(threadId);
1008
1067
  const message = makeUserMessage(text, files);
1009
1068
  const next = [...session.messages, message];
1010
1069
  writeMessages(threadId, next);
1011
1070
  return { message, next };
1012
1071
  },
1013
- [activeThreadId, getSession, noteThreadActivity, updateSession, writeMessages],
1072
+ [activeThreadId, enableThreads, getSession, noteThreadActivity, threads, writeMessages],
1014
1073
  );
1015
1074
 
1016
1075
  // Send a message on the active thread. Submitting while a turn is already
@@ -1488,11 +1547,11 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
1488
1547
  onExportMessage: exportMessage,
1489
1548
  }
1490
1549
  : {}),
1491
- // Feedback: expose one server-selected destination. MLflow messages still
1492
- // require trace state; Genie messages derive their target from ask_genie.
1550
+ // Feedback: choose per message. Genie results use their message identity;
1551
+ // other responses require an MLflow trace id.
1493
1552
  ...(feedbackAvailable
1494
1553
  ? {
1495
- feedbackMode,
1554
+ feedbackModes: [...feedbackModes],
1496
1555
  feedbackByMessage: activeSession.feedbackByMessage,
1497
1556
  onFeedback: submitFeedback,
1498
1557
  ...(mlflowExperimentUrl ? { mlflowExperimentUrl } : {}),
@@ -404,8 +404,8 @@ const RawToolPayload = ({
404
404
  }) => {
405
405
  const structured = structuredToolPayload(value);
406
406
  return (
407
- <Collapsible className="min-w-0 max-w-full overflow-hidden rounded border border-border/60 bg-background/40">
408
- <CollapsibleTrigger className="group flex w-full min-w-0 items-center gap-1.5 px-2 py-1 text-left text-xs uppercase tracking-wide text-muted-foreground hover:text-foreground">
407
+ <Collapsible className="min-w-0 max-w-full overflow-hidden">
408
+ <CollapsibleTrigger className="group flex w-full min-w-0 items-center gap-1.5 py-1 text-left text-xs uppercase tracking-wide text-muted-foreground hover:text-foreground">
409
409
  <ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
410
410
  <span>{label}</span>
411
411
  </CollapsibleTrigger>
@@ -414,12 +414,12 @@ const RawToolPayload = ({
414
414
  {structured === undefined ? (
415
415
  <JsonBlock
416
416
  json={formatRawToolPayload(value)}
417
- className="border-t border-border/50 px-2 py-2 leading-tight text-foreground sm:leading-relaxed"
417
+ className="py-2 leading-tight text-foreground sm:leading-relaxed"
418
418
  />
419
419
  ) : (
420
420
  <RecordPreview
421
421
  value={structured}
422
- className="max-w-full border-t border-border/50 bg-transparent text-foreground"
422
+ className="max-w-full bg-transparent text-foreground [&_pre]:rounded-none [&_pre]:bg-transparent"
423
423
  />
424
424
  )}
425
425
  </div>
@@ -1,4 +1,8 @@
1
- import type { FollowUpSuggestionMode, ToolProgressEvent } from "@dbx-tools/shared-mastra";
1
+ import type {
2
+ FeedbackDestination,
3
+ FollowUpSuggestionMode,
4
+ ToolProgressEvent,
5
+ } from "@dbx-tools/shared-mastra";
2
6
  import type { ReasoningEffort, ServingEndpointSummary } from "@dbx-tools/shared-model";
3
7
  import type { FileUIPart, UIMessage } from "ai";
4
8
  import type { ReactNode } from "react";
@@ -375,8 +379,8 @@ export type ChatViewProps = {
375
379
  * response header when MLflow logging is enabled.
376
380
  */
377
381
  feedbackByMessage?: Record<string, MessageFeedback>;
378
- /** Resolved feedback destination selected by the server. */
379
- feedbackMode?: "none" | "mlflow" | "genie";
382
+ /** Feedback destinations the server can accept for per-message routing. */
383
+ feedbackModes?: readonly FeedbackDestination[];
380
384
  /**
381
385
  * Submit thumbs / comment feedback for an assistant message. When
382
386
  * provided (and the message has a {@link feedbackByMessage} entry),
@@ -34,7 +34,7 @@ export class GenieChatClient extends MastraPluginClient {
34
34
  /** Genie space alias every route is scoped to. */
35
35
  readonly alias: string;
36
36
  override readonly backgroundTurns = false;
37
- override readonly feedbackMode = "none";
37
+ override readonly feedbackModes: readonly "genie"[];
38
38
  override readonly threadRename = false;
39
39
  override readonly attachments = false;
40
40
  override readonly followUpSuggestions: "none" | "genie";
@@ -46,6 +46,7 @@ export class GenieChatClient extends MastraPluginClient {
46
46
  constructor(config: MastraClientConfig, alias: string) {
47
47
  super(config);
48
48
  this.alias = alias;
49
+ this.feedbackModes = config.feedbackModes?.includes("genie") ? ["genie"] : [];
49
50
  this.followUpSuggestions =
50
51
  config.followUpSuggestions === "genie" || config.followUpSuggestions === "auto"
51
52
  ? "genie"
@@ -8,7 +8,7 @@ import {
8
8
  type MastraFeedbackResponse,
9
9
  type MastraMlflowExperimentResponse,
10
10
  type StatementData,
11
- type FeedbackMode,
11
+ type FeedbackDestination,
12
12
  MastraFeedbackResponseSchema,
13
13
  MastraMlflowExperimentResponseSchema,
14
14
  MODEL_OVERRIDE_HEADER,
@@ -86,8 +86,8 @@ export class MastraPluginClient extends MastraClient {
86
86
  readonly defaultAgent: string;
87
87
  /** Registered agent ids, surfaced for pickers. */
88
88
  readonly agents: readonly string[];
89
- /** Resolved feedback destination published by the server. */
90
- readonly feedbackMode: FeedbackMode;
89
+ /** Feedback destinations published by the server for per-message routing. */
90
+ readonly feedbackModes: readonly FeedbackDestination[];
91
91
  /**
92
92
  * Whether the agents run their Databricks calls as the app service principal
93
93
  * rather than on-behalf-of the signed-in user. When `true` the chat works for
@@ -117,7 +117,7 @@ export class MastraPluginClient extends MastraClient {
117
117
  this.basePath = config.basePath;
118
118
  this.defaultAgent = config.defaultAgent;
119
119
  this.agents = config.agents;
120
- this.feedbackMode = config.feedbackMode ?? "none";
120
+ this.feedbackModes = config.feedbackModes ?? [];
121
121
  this.chatAlwaysAvailable = config.chatAlwaysAvailable ?? false;
122
122
  this.backgroundTurns = config.backgroundTurns ?? false;
123
123
  this.followUpSuggestions = config.followUpSuggestions ?? "none";
@@ -936,6 +936,7 @@ export const useMastraThreads = (
936
936
  loading: boolean;
937
937
  error: Error | null;
938
938
  refresh: () => void;
939
+ sync: () => Promise<MastraMemoryThread[]>;
939
940
  } => {
940
941
  const defaultClient = useMastraClient();
941
942
  const client = clientOverride ?? defaultClient;
@@ -948,6 +949,27 @@ export const useMastraThreads = (
948
949
  const refresh = useCallback(() => setNonce((n) => n + 1), []);
949
950
  const hasLoadedRef = useRef(false);
950
951
 
952
+ const load = useCallback(
953
+ async (signal?: AbortSignal): Promise<MastraMemoryThread[]> => {
954
+ if (!enabled) return [];
955
+ try {
956
+ const res = await client.threads({ agentId, ...(signal ? { signal } : {}) });
957
+ if (signal?.aborted) return [];
958
+ hasLoadedRef.current = true;
959
+ setThreads(res.threads);
960
+ setError(null);
961
+ return res.threads;
962
+ } catch (caught) {
963
+ if (signal?.aborted || (caught as { name?: string }).name === "AbortError") return [];
964
+ setError(toError(caught));
965
+ setThreads([]);
966
+ return [];
967
+ }
968
+ },
969
+ [agentId, client, enabled],
970
+ );
971
+ const sync = useCallback(() => load(), [load]);
972
+
951
973
  useEffect(() => {
952
974
  if (!enabled) {
953
975
  hasLoadedRef.current = false;
@@ -957,26 +979,14 @@ export const useMastraThreads = (
957
979
  }
958
980
  const controller = new AbortController();
959
981
  if (!hasLoadedRef.current) setLoading(true);
960
- client
961
- .threads({ agentId, signal: controller.signal })
962
- .then((res) => {
963
- if (controller.signal.aborted) return;
964
- hasLoadedRef.current = true;
965
- setThreads(res.threads);
966
- setError(null);
967
- })
968
- .catch((e: unknown) => {
969
- if (controller.signal.aborted || (e as { name?: string }).name === "AbortError") return;
970
- setError(toError(e));
971
- setThreads([]);
972
- })
982
+ void load(controller.signal)
973
983
  .finally(() => {
974
984
  if (!controller.signal.aborted) setLoading(false);
975
985
  });
976
986
  return () => controller.abort();
977
- }, [client, agentId, enabled, nonce]);
987
+ }, [enabled, load, nonce]);
978
988
 
979
- return { threads, loading, error, refresh };
989
+ return { threads, loading, error, refresh, sync };
980
990
  };
981
991
 
982
992
  /**