@dbx-tools/ui-mastra 0.9.176 → 0.9.178
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 +4 -3
- package/index.ts +1 -1
- package/package.json +7 -7
- package/src/react/_assistant-response-status.tsx +2 -2
- package/src/react/bubbles.tsx +9 -8
- package/src/react/chat-composer.tsx +4 -3
- package/src/react/chat-feedback.ts +32 -14
- package/src/react/chat-stream.ts +37 -5
- package/src/react/chat-transcript.tsx +13 -15
- package/src/react/chat-view.tsx +4 -4
- package/src/react/feedback-controls.tsx +30 -122
- package/src/react/mastra-chat.tsx +75 -16
- package/src/react/tool-pill.tsx +4 -4
- package/src/react/types.ts +16 -4
- package/src/support/genie-client.ts +2 -1
- package/src/support/mastra-client.ts +29 -19
- package/src/support/thread-sessions.ts +9 -3
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, 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, 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";
|
|
@@ -57,5 +57,6 @@ export { ThreadActions, ThreadTabs } from "./src/react/thread-tabs.tsx";
|
|
|
57
57
|
export type { ThreadTabsProps, ThreadActionsProps } from "./src/react/thread-tabs.tsx";
|
|
58
58
|
export { humanizeToolName, formatRawToolPayload, structuredToolPayload, detectToolSourceLanguage, toolInputPresentation, toolOutputPresentation, webSearchProgressGroups, webSearchQueryLabel, webSearchResultLabel, ToolSessionPill } from "./src/react/tool-pill.tsx";
|
|
59
59
|
export type { ToolInputPresentation, WebSearchProgressGroup } from "./src/react/tool-pill.tsx";
|
|
60
|
+
export { isActiveChatStatus, isRespondingChatStatus } from "./src/react/types.ts";
|
|
60
61
|
export type { ChatStatus, ToolEvent, ToolProgress, ChatModelOption, ChatInputMessage, QueuedSteer, FeedbackValue, FeedbackSubmission, MessageFeedback, ThreadSummary, ThreadPlacement, ChatViewProps, ApprovalDecision, PendingApproval } from "./src/react/types.ts";
|
|
61
62
|
export { useChatThreadQuery } from "./src/react/use-chat-thread-query.ts";
|
package/index.ts
CHANGED
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.
|
|
36
|
-
"@dbx-tools/shared-core": "^0.9.
|
|
37
|
-
"@dbx-tools/shared-genie": "^0.9.
|
|
38
|
-
"@dbx-tools/shared-mastra": "^0.9.
|
|
39
|
-
"@dbx-tools/shared-model": "^0.9.
|
|
40
|
-
"@dbx-tools/ui": "^0.9.
|
|
35
|
+
"@dbx-tools/shared-auth": "^0.9.178",
|
|
36
|
+
"@dbx-tools/shared-core": "^0.9.178",
|
|
37
|
+
"@dbx-tools/shared-genie": "^0.9.178",
|
|
38
|
+
"@dbx-tools/shared-mastra": "^0.9.178",
|
|
39
|
+
"@dbx-tools/shared-model": "^0.9.178",
|
|
40
|
+
"@dbx-tools/ui": "^0.9.178",
|
|
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.
|
|
58
|
+
"version": "0.9.178",
|
|
59
59
|
"types": "index.ts",
|
|
60
60
|
"dbxToolsConfig": {
|
|
61
61
|
"tags": [
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Spinner } from "@databricks/appkit-ui/react";
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import { isRespondingChatStatus, type ChatStatus } from "./types.ts";
|
|
4
4
|
|
|
5
5
|
/** Whether an assistant bubble should show its active-response status. */
|
|
6
6
|
export const shouldShowAssistantResponseStatus = (
|
|
7
7
|
isLast: boolean,
|
|
8
8
|
status: ChatStatus,
|
|
9
9
|
hasVisibleResponse: boolean,
|
|
10
|
-
): boolean => isLast && hasVisibleResponse && (status
|
|
10
|
+
): boolean => isLast && hasVisibleResponse && isRespondingChatStatus(status);
|
|
11
11
|
|
|
12
12
|
/** Compact progress affordance for an active assistant response. */
|
|
13
13
|
export const AssistantResponseSpinner = () => (
|
package/src/react/bubbles.tsx
CHANGED
|
@@ -36,13 +36,14 @@ import { ExportMenu } from "./export-menu.tsx";
|
|
|
36
36
|
import { FeedbackControls } from "./feedback-controls.tsx";
|
|
37
37
|
import { ToolMarkdown } from "./markdown.tsx";
|
|
38
38
|
import { ToolSessionPill, humanizeToolName } from "./tool-pill.tsx";
|
|
39
|
-
import
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
import {
|
|
40
|
+
isRespondingChatStatus,
|
|
41
|
+
type ApprovalDecision,
|
|
42
|
+
type ChatStatus,
|
|
43
|
+
type FeedbackSubmission,
|
|
44
|
+
type FeedbackValue,
|
|
45
|
+
type PendingApproval,
|
|
46
|
+
type ToolEvent,
|
|
46
47
|
} from "./types.ts";
|
|
47
48
|
import { copyText } from "../support/clipboard.ts";
|
|
48
49
|
import type { ExportFormat } from "../support/export.ts";
|
|
@@ -390,7 +391,7 @@ export const AssistantBubble = ({
|
|
|
390
391
|
// pop in mid-stream. A bubble is "settled" if it isn't the active
|
|
391
392
|
// streaming target - either the agent has returned to `ready` /
|
|
392
393
|
// `error`, or a newer message has taken over the `isLast` slot.
|
|
393
|
-
const isStreamingThisBubble = isLast && (status
|
|
394
|
+
const isStreamingThisBubble = isLast && isRespondingChatStatus(status);
|
|
394
395
|
const showResponseStatus = shouldShowAssistantResponseStatus(
|
|
395
396
|
isLast,
|
|
396
397
|
status,
|
|
@@ -34,7 +34,7 @@ import { imageFileToUIPart, MAX_COMPOSER_IMAGES } from "./_image-attachments.ts"
|
|
|
34
34
|
import { ModelSelector } from "./_model-selector.tsx";
|
|
35
35
|
import { ExportMenu } from "./export-menu.tsx";
|
|
36
36
|
import { SuggestionPills } from "./suggestion-pills.tsx";
|
|
37
|
-
import type
|
|
37
|
+
import { isActiveChatStatus, isRespondingChatStatus, type ChatViewProps } from "./types.ts";
|
|
38
38
|
|
|
39
39
|
type QueuedSteerListProps = {
|
|
40
40
|
queuedSteers: NonNullable<ChatViewProps["queuedSteers"]>;
|
|
@@ -316,7 +316,8 @@ export const ChatComposer = ({
|
|
|
316
316
|
return observeComposerWidth(group, resizeTextarea);
|
|
317
317
|
}, [resizeTextarea]);
|
|
318
318
|
|
|
319
|
-
const isRunning = status
|
|
319
|
+
const isRunning = isActiveChatStatus(status);
|
|
320
|
+
const canStop = isRespondingChatStatus(status);
|
|
320
321
|
const hasDraft = Boolean(input.trim() || files.length > 0);
|
|
321
322
|
const submit = () => {
|
|
322
323
|
const text = input.trim();
|
|
@@ -560,7 +561,7 @@ export const ChatComposer = ({
|
|
|
560
561
|
)}
|
|
561
562
|
</span>
|
|
562
563
|
))}
|
|
563
|
-
{
|
|
564
|
+
{canStop && onStop && !hasDraft ? (
|
|
564
565
|
<InputGroupButton
|
|
565
566
|
type="button"
|
|
566
567
|
size="icon-sm"
|
|
@@ -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 {
|
|
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
|
-
|
|
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,23 @@ export function genieFeedbackTarget(message: UIMessage): GenieFeedbackTarget | u
|
|
|
48
53
|
return undefined;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
/**
|
|
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
|
+
/** Submit feedback to the destination selected for the assistant message. */
|
|
52
69
|
export function useChatFeedback({
|
|
53
70
|
activeKey,
|
|
54
71
|
feedbackByMessage,
|
|
55
|
-
|
|
72
|
+
feedbackModes,
|
|
56
73
|
mastraClient,
|
|
57
74
|
updateSession,
|
|
58
75
|
}: UseChatFeedbackOptions) {
|
|
@@ -62,8 +79,8 @@ export function useChatFeedback({
|
|
|
62
79
|
return useCallback(
|
|
63
80
|
async (message: UIMessage, submission: FeedbackSubmission) => {
|
|
64
81
|
const traceId = feedbackByMessageRef.current[message.id]?.traceId;
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
82
|
+
const destination = messageFeedbackDestination(message, feedbackModes, traceId);
|
|
83
|
+
if (!destination) return;
|
|
67
84
|
|
|
68
85
|
if (submission.value) {
|
|
69
86
|
updateSession(activeKey, (session) => ({
|
|
@@ -79,38 +96,39 @@ export function useChatFeedback({
|
|
|
79
96
|
}
|
|
80
97
|
try {
|
|
81
98
|
let result;
|
|
82
|
-
if (
|
|
83
|
-
if (!
|
|
99
|
+
if (destination.mode === "genie") {
|
|
100
|
+
if (!submission.value || !submission.request) return;
|
|
84
101
|
result = await mastraClient.feedback({
|
|
85
102
|
mode: "genie",
|
|
86
|
-
|
|
103
|
+
spaceId: destination.spaceId,
|
|
104
|
+
conversationId: destination.conversationId,
|
|
105
|
+
messageId: destination.messageId,
|
|
87
106
|
rating: submission.value === "up" ? "POSITIVE" : "NEGATIVE",
|
|
88
107
|
request: submission.request,
|
|
89
108
|
...(submission.comment ? { comment: submission.comment } : {}),
|
|
90
109
|
});
|
|
91
110
|
} else {
|
|
92
|
-
if (!traceId) return;
|
|
93
111
|
result = await mastraClient.feedback({
|
|
94
112
|
mode: "mlflow",
|
|
95
|
-
traceId,
|
|
113
|
+
traceId: destination.traceId,
|
|
96
114
|
...(submission.value !== undefined ? { value: submission.value === "up" } : {}),
|
|
97
115
|
...(submission.comment ? { comment: submission.comment } : {}),
|
|
98
116
|
});
|
|
99
117
|
}
|
|
100
118
|
if (!result.ok) {
|
|
101
119
|
logger.warn("feedback not recorded", {
|
|
102
|
-
feedbackMode,
|
|
120
|
+
feedbackMode: destination.mode,
|
|
103
121
|
...(traceId ? { traceId } : {}),
|
|
104
122
|
});
|
|
105
123
|
}
|
|
106
124
|
} catch (error) {
|
|
107
125
|
logger.error("feedback error", {
|
|
108
|
-
feedbackMode,
|
|
126
|
+
feedbackMode: destination.mode,
|
|
109
127
|
...(traceId ? { traceId } : {}),
|
|
110
128
|
error: toError(error),
|
|
111
129
|
});
|
|
112
130
|
}
|
|
113
131
|
},
|
|
114
|
-
[activeKey,
|
|
132
|
+
[activeKey, feedbackModes, mastraClient, updateSession],
|
|
115
133
|
);
|
|
116
134
|
}
|
package/src/react/chat-stream.ts
CHANGED
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
MLFLOW_TRACE_ID_HEADER,
|
|
4
4
|
MLFLOW_TRACE_PART_TYPE,
|
|
5
5
|
MlflowTracePartDataSchema,
|
|
6
|
+
RESPONSE_COMPLETE_PART_TYPE,
|
|
7
|
+
THREAD_TITLE_PART_TYPE,
|
|
8
|
+
ThreadTitlePartDataSchema,
|
|
6
9
|
isStaleMastraResumeError,
|
|
7
10
|
} from "@dbx-tools/shared-mastra";
|
|
8
11
|
import { readUIMessageStream, type UIMessage, type UIMessageChunk } from "ai";
|
|
@@ -12,6 +15,7 @@ import type {
|
|
|
12
15
|
ThreadSessionReader,
|
|
13
16
|
ThreadSessionUpdater,
|
|
14
17
|
} from "./chat-sessions.ts";
|
|
18
|
+
import type { ChatStatus } from "./types.ts";
|
|
15
19
|
import type { MastraStreamResponse } from "../support/mastra-client.ts";
|
|
16
20
|
|
|
17
21
|
const logger = log.logger("ui-mastra/chat");
|
|
@@ -29,6 +33,20 @@ export const readMlflowTracePart = (chunk: UIMessageChunk): string | undefined =
|
|
|
29
33
|
return parsed.success ? parsed.data.traceId : undefined;
|
|
30
34
|
};
|
|
31
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
|
+
|
|
43
|
+
/** Map lifecycle-only chunks onto the UI's active-turn state. */
|
|
44
|
+
export const chatStatusForChunk = (chunk: UIMessageChunk): ChatStatus | undefined => {
|
|
45
|
+
if ((chunk as { type?: string }).type === RESPONSE_COMPLETE_PART_TYPE) return "finishing";
|
|
46
|
+
if (chunk.type === "finish" || chunk.type === "abort") return "finishing";
|
|
47
|
+
return undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
32
50
|
class StreamAborted extends Error {}
|
|
33
51
|
|
|
34
52
|
/** Stop reading a background run once the AI SDK has delivered its terminal chunk. */
|
|
@@ -46,7 +64,7 @@ export function closeOnTerminalChunk(
|
|
|
46
64
|
while (true) {
|
|
47
65
|
const { done, value } = await reader.read();
|
|
48
66
|
if (done) {
|
|
49
|
-
controller.
|
|
67
|
+
controller.error(new Error("Chat stream ended before a terminal AI SDK chunk"));
|
|
50
68
|
return;
|
|
51
69
|
}
|
|
52
70
|
onChunk?.(value);
|
|
@@ -130,6 +148,7 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
130
148
|
|
|
131
149
|
try {
|
|
132
150
|
let terminalReceived = false;
|
|
151
|
+
let threadTitle: string | undefined;
|
|
133
152
|
const existing = getSession(threadId).messages.find(
|
|
134
153
|
(message) => message.id === assistantId,
|
|
135
154
|
);
|
|
@@ -140,7 +159,16 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
140
159
|
() => {
|
|
141
160
|
terminalReceived = true;
|
|
142
161
|
},
|
|
143
|
-
(chunk) =>
|
|
162
|
+
(chunk) => {
|
|
163
|
+
recordTraceId(readMlflowTracePart(chunk));
|
|
164
|
+
threadTitle = readThreadTitlePart(chunk) ?? threadTitle;
|
|
165
|
+
const status = chatStatusForChunk(chunk);
|
|
166
|
+
if (!status) return;
|
|
167
|
+
updateSession(threadId, (current) => ({
|
|
168
|
+
...current,
|
|
169
|
+
status,
|
|
170
|
+
}));
|
|
171
|
+
},
|
|
144
172
|
),
|
|
145
173
|
terminateOnError: true,
|
|
146
174
|
})) {
|
|
@@ -150,16 +178,20 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
150
178
|
updateSession(threadId, (current) => ({
|
|
151
179
|
...current,
|
|
152
180
|
runId: runIdRef.current,
|
|
153
|
-
status:
|
|
181
|
+
status:
|
|
182
|
+
terminalReceived || current.status === "finishing"
|
|
183
|
+
? "finishing"
|
|
184
|
+
: "streaming",
|
|
154
185
|
}));
|
|
155
186
|
}
|
|
187
|
+
return threadTitle;
|
|
156
188
|
} catch (error) {
|
|
157
|
-
if (error instanceof StreamAborted || signal.aborted) return;
|
|
189
|
+
if (error instanceof StreamAborted || signal.aborted) return undefined;
|
|
158
190
|
if (isStaleMastraResumeError(error)) {
|
|
159
191
|
logger.warn("ignored stale mastra resume", {
|
|
160
192
|
error: toError(error),
|
|
161
193
|
});
|
|
162
|
-
return;
|
|
194
|
+
return undefined;
|
|
163
195
|
}
|
|
164
196
|
throw error;
|
|
165
197
|
}
|
|
@@ -15,9 +15,9 @@ 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 {
|
|
18
|
+
import { messageFeedbackDestination } from "./chat-feedback.ts";
|
|
19
19
|
import { SuggestionPills } from "./suggestion-pills.tsx";
|
|
20
|
-
import type
|
|
20
|
+
import { isRespondingChatStatus, type ChatViewProps } from "./types.ts";
|
|
21
21
|
import { messageText } from "../support/export.ts";
|
|
22
22
|
|
|
23
23
|
const BOTTOM_THRESHOLD_PX = 24;
|
|
@@ -160,7 +160,7 @@ type ChatTranscriptProps = {
|
|
|
160
160
|
pendingApprovalsByMessage: NonNullable<ChatViewProps["pendingApprovalsByMessage"]>;
|
|
161
161
|
onExportMessage: ChatViewProps["onExportMessage"];
|
|
162
162
|
feedbackByMessage: NonNullable<ChatViewProps["feedbackByMessage"]>;
|
|
163
|
-
|
|
163
|
+
feedbackModes: NonNullable<ChatViewProps["feedbackModes"]>;
|
|
164
164
|
onFeedback: ChatViewProps["onFeedback"];
|
|
165
165
|
mlflowExperimentUrl: ChatViewProps["mlflowExperimentUrl"];
|
|
166
166
|
};
|
|
@@ -182,11 +182,11 @@ export const ChatTranscript = ({
|
|
|
182
182
|
pendingApprovalsByMessage,
|
|
183
183
|
onExportMessage,
|
|
184
184
|
feedbackByMessage,
|
|
185
|
-
|
|
185
|
+
feedbackModes,
|
|
186
186
|
onFeedback,
|
|
187
187
|
mlflowExperimentUrl,
|
|
188
188
|
}: ChatTranscriptProps) => {
|
|
189
|
-
const isRunning = status
|
|
189
|
+
const isRunning = isRespondingChatStatus(status);
|
|
190
190
|
const lastMessage = messages.at(-1);
|
|
191
191
|
const lastEvents = lastMessage ? toolEventsByMessage[lastMessage.id] : undefined;
|
|
192
192
|
const lastAssistantParts = lastMessage?.role === "assistant" ? lastMessage.parts : [];
|
|
@@ -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,15 @@ 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
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
: Boolean(genieTarget);
|
|
239
|
+
const feedbackDestination = messageFeedbackDestination(
|
|
240
|
+
message,
|
|
241
|
+
feedbackModes,
|
|
242
|
+
messageFeedback?.traceId,
|
|
243
|
+
);
|
|
245
244
|
const requestMessage = [...messages.slice(0, index)]
|
|
246
245
|
.reverse()
|
|
247
246
|
.find((candidate) => candidate.role === "user");
|
|
248
247
|
const feedbackRequest = requestMessage ? messageText(requestMessage) : "";
|
|
249
|
-
const bubbleFeedbackMode = feedbackMode === "genie" ? "genie" : "mlflow";
|
|
250
248
|
return (
|
|
251
249
|
<AssistantBubble
|
|
252
250
|
key={message.id}
|
|
@@ -260,10 +258,10 @@ export const ChatTranscript = ({
|
|
|
260
258
|
{...(onExportMessage
|
|
261
259
|
? { onExport: (format) => onExportMessage(message, format) }
|
|
262
260
|
: {})}
|
|
263
|
-
{...(onFeedback &&
|
|
261
|
+
{...(onFeedback && feedbackDestination
|
|
264
262
|
? {
|
|
265
263
|
onFeedback: (submission) => onFeedback(message, submission),
|
|
266
|
-
feedbackMode:
|
|
264
|
+
feedbackMode: feedbackDestination.mode,
|
|
267
265
|
...(feedbackRequest ? { feedbackRequest } : {}),
|
|
268
266
|
...(messageFeedback?.value
|
|
269
267
|
? { feedbackValue: messageFeedback.value }
|
package/src/react/chat-view.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { ChatComposer } from "./chat-composer.tsx";
|
|
|
2
2
|
import { ChatThreadLayout } from "./chat-thread-layout.tsx";
|
|
3
3
|
import { ChatTranscript, useChatTranscriptController } from "./chat-transcript.tsx";
|
|
4
4
|
import { collectSuggestions } from "./suggestions.ts";
|
|
5
|
-
import type
|
|
5
|
+
import { isActiveChatStatus, type ChatViewProps } from "./types.ts";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Controlled chat facade for hosts that own message and transport state.
|
|
@@ -67,7 +67,7 @@ export const ChatView = ({
|
|
|
67
67
|
onExportConversation,
|
|
68
68
|
onExportMessage,
|
|
69
69
|
feedbackByMessage = {},
|
|
70
|
-
|
|
70
|
+
feedbackModes = [],
|
|
71
71
|
onFeedback,
|
|
72
72
|
mlflowExperimentUrl,
|
|
73
73
|
}: ChatViewProps) => {
|
|
@@ -81,7 +81,7 @@ export const ChatView = ({
|
|
|
81
81
|
});
|
|
82
82
|
const latestMessage = messages[messages.length - 1];
|
|
83
83
|
const latestAssistant = latestMessage?.role === "assistant" ? latestMessage : undefined;
|
|
84
|
-
const running = status
|
|
84
|
+
const running = isActiveChatStatus(status);
|
|
85
85
|
const followUpQuestions =
|
|
86
86
|
latestAssistant && !running
|
|
87
87
|
? collectSuggestions(
|
|
@@ -130,7 +130,7 @@ export const ChatView = ({
|
|
|
130
130
|
pendingApprovalsByMessage={pendingApprovalsByMessage}
|
|
131
131
|
onExportMessage={onExportMessage}
|
|
132
132
|
feedbackByMessage={feedbackByMessage}
|
|
133
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
60
|
-
|
|
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:
|
|
65
|
-
|
|
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={() =>
|
|
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={() =>
|
|
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
|
|
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>
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
|
328
|
-
const feedbackAvailable =
|
|
329
|
-
const { url: mlflowExperimentUrl } = useMastraMlflowExperiment(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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 (
|
|
997
|
-
|
|
1056
|
+
if (expectsTitle) {
|
|
1057
|
+
provisionalTitle = deriveThreadTitle(
|
|
998
1058
|
text || files.map((file) => file.filename || "Image").join(", "),
|
|
999
1059
|
);
|
|
1000
|
-
if (
|
|
1060
|
+
if (provisionalTitle) {
|
|
1001
1061
|
setProvisionalTitles((prev) =>
|
|
1002
|
-
prev[activeThreadId] ? prev : { ...prev, [activeThreadId]:
|
|
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,
|
|
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:
|
|
1492
|
-
//
|
|
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
|
-
|
|
1554
|
+
feedbackModes: [...feedbackModes],
|
|
1496
1555
|
feedbackByMessage: activeSession.feedbackByMessage,
|
|
1497
1556
|
onFeedback: submitFeedback,
|
|
1498
1557
|
...(mlflowExperimentUrl ? { mlflowExperimentUrl } : {}),
|
package/src/react/tool-pill.tsx
CHANGED
|
@@ -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
|
|
408
|
-
<CollapsibleTrigger className="group flex w-full min-w-0 items-center gap-1.5
|
|
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="
|
|
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
|
|
422
|
+
className="max-w-full bg-transparent text-foreground [&_pre]:rounded-none [&_pre]:bg-transparent"
|
|
423
423
|
/>
|
|
424
424
|
)}
|
|
425
425
|
</div>
|
package/src/react/types.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
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";
|
|
@@ -10,7 +14,15 @@ import type { ExportFormat } from "../support/export.ts";
|
|
|
10
14
|
// layer and the `useMastraChat` driver can share them.
|
|
11
15
|
|
|
12
16
|
/** User-visible lifecycle state of the active chat turn. */
|
|
13
|
-
export type ChatStatus = "submitted" | "streaming" | "ready" | "error";
|
|
17
|
+
export type ChatStatus = "submitted" | "streaming" | "finishing" | "ready" | "error";
|
|
18
|
+
|
|
19
|
+
/** Whether a turn still owns its session and queues new messages. */
|
|
20
|
+
export const isActiveChatStatus = (status: ChatStatus): boolean =>
|
|
21
|
+
status === "submitted" || status === "streaming" || status === "finishing";
|
|
22
|
+
|
|
23
|
+
/** Whether the assistant is still visibly producing its response. */
|
|
24
|
+
export const isRespondingChatStatus = (status: ChatStatus): boolean =>
|
|
25
|
+
status === "submitted" || status === "streaming";
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
28
|
* Lifecycle of a single tool invocation surfaced inline in the assistant
|
|
@@ -367,8 +379,8 @@ export type ChatViewProps = {
|
|
|
367
379
|
* response header when MLflow logging is enabled.
|
|
368
380
|
*/
|
|
369
381
|
feedbackByMessage?: Record<string, MessageFeedback>;
|
|
370
|
-
/**
|
|
371
|
-
|
|
382
|
+
/** Feedback destinations the server can accept for per-message routing. */
|
|
383
|
+
feedbackModes?: readonly FeedbackDestination[];
|
|
372
384
|
/**
|
|
373
385
|
* Submit thumbs / comment feedback for an assistant message. When
|
|
374
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
|
|
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
|
|
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
|
-
/**
|
|
90
|
-
readonly
|
|
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.
|
|
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
|
-
|
|
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
|
-
}, [
|
|
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
|
/**
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { RequestContext } from "@mastra/client-js";
|
|
2
2
|
import type { UIMessage } from "ai";
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
isActiveChatStatus,
|
|
5
|
+
type ChatStatus,
|
|
6
|
+
type MessageFeedback,
|
|
7
|
+
type PendingApproval,
|
|
8
|
+
type QueuedSteer,
|
|
9
|
+
} from "../react/types.ts";
|
|
4
10
|
|
|
5
11
|
/** A queued steer plus the application context captured when it was submitted. */
|
|
6
12
|
export type SessionQueuedSteer = QueuedSteer & {
|
|
@@ -60,9 +66,9 @@ export function createThreadSession(): ThreadSession {
|
|
|
60
66
|
};
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
/** Return whether a thread
|
|
69
|
+
/** Return whether a thread still owns an active run. */
|
|
64
70
|
export function isSessionRunning(session: ThreadSession): boolean {
|
|
65
|
-
return session.status
|
|
71
|
+
return isActiveChatStatus(session.status);
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
/** Return the newest user message in a transcript or turn. */
|