@dbx-tools/ui-mastra 0.9.163 → 0.9.165
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 +1 -1
- package/index.ts +1 -1
- package/package.json +7 -7
- package/src/react/chat-stream.ts +26 -7
package/index.react.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type { GenieFeedbackTarget } 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 { closeOnTerminalChunk, waitForTerminalChunk, useChatStream } from "./src/react/chat-stream.ts";
|
|
36
|
+
export { readMlflowTracePart, 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
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.165",
|
|
36
|
+
"@dbx-tools/shared-core": "^0.9.165",
|
|
37
|
+
"@dbx-tools/shared-genie": "^0.9.165",
|
|
38
|
+
"@dbx-tools/shared-mastra": "^0.9.165",
|
|
39
|
+
"@dbx-tools/shared-model": "^0.9.165",
|
|
40
|
+
"@dbx-tools/ui": "^0.9.165",
|
|
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.165",
|
|
59
59
|
"types": "index.ts",
|
|
60
60
|
"dbxToolsConfig": {
|
|
61
61
|
"tags": [
|
package/src/react/chat-stream.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { log, toError, trimToUndefined } from "@dbx-tools/shared-core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
MLFLOW_TRACE_ID_HEADER,
|
|
4
|
+
MLFLOW_TRACE_PART_TYPE,
|
|
5
|
+
MlflowTracePartDataSchema,
|
|
6
|
+
isStaleMastraResumeError,
|
|
7
|
+
} from "@dbx-tools/shared-mastra";
|
|
3
8
|
import { readUIMessageStream, type UIMessage, type UIMessageChunk } from "ai";
|
|
4
9
|
import { useCallback } from "react";
|
|
5
10
|
import type {
|
|
@@ -17,12 +22,20 @@ const readMlflowTraceId = (stream: unknown): string | undefined => {
|
|
|
17
22
|
return trimToUndefined(headers?.get?.(MLFLOW_TRACE_ID_HEADER));
|
|
18
23
|
};
|
|
19
24
|
|
|
25
|
+
/** Read the trace-id fallback carried by one transient AI SDK data part. */
|
|
26
|
+
export const readMlflowTracePart = (chunk: UIMessageChunk): string | undefined => {
|
|
27
|
+
if ((chunk as { type?: string }).type !== MLFLOW_TRACE_PART_TYPE) return undefined;
|
|
28
|
+
const parsed = MlflowTracePartDataSchema.safeParse((chunk as { data?: unknown }).data);
|
|
29
|
+
return parsed.success ? parsed.data.traceId : undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
20
32
|
class StreamAborted extends Error {}
|
|
21
33
|
|
|
22
34
|
/** Stop reading a background run once the AI SDK has delivered its terminal chunk. */
|
|
23
35
|
export function closeOnTerminalChunk(
|
|
24
36
|
stream: ReadableStream<UIMessageChunk>,
|
|
25
37
|
onTerminal?: () => void,
|
|
38
|
+
onChunk?: (chunk: UIMessageChunk) => void,
|
|
26
39
|
): ReadableStream<UIMessageChunk> {
|
|
27
40
|
let reader: ReadableStreamDefaultReader<UIMessageChunk> | undefined;
|
|
28
41
|
let cancelled = false;
|
|
@@ -36,6 +49,7 @@ export function closeOnTerminalChunk(
|
|
|
36
49
|
controller.close();
|
|
37
50
|
return;
|
|
38
51
|
}
|
|
52
|
+
onChunk?.(value);
|
|
39
53
|
controller.enqueue(value);
|
|
40
54
|
if (value.type === "finish" || value.type === "abort") {
|
|
41
55
|
onTerminal?.();
|
|
@@ -95,8 +109,8 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
95
109
|
runIdRef: { current: string | null },
|
|
96
110
|
signal: AbortSignal,
|
|
97
111
|
) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
112
|
+
const recordTraceId = (traceId: string | undefined): void => {
|
|
113
|
+
if (!traceId) return;
|
|
100
114
|
updateSession(threadId, (session) =>
|
|
101
115
|
session.feedbackByMessage[assistantId]?.traceId === traceId
|
|
102
116
|
? session
|
|
@@ -111,7 +125,8 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
111
125
|
},
|
|
112
126
|
},
|
|
113
127
|
);
|
|
114
|
-
}
|
|
128
|
+
};
|
|
129
|
+
recordTraceId(readMlflowTraceId(stream));
|
|
115
130
|
|
|
116
131
|
try {
|
|
117
132
|
let terminalReceived = false;
|
|
@@ -120,9 +135,13 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
120
135
|
);
|
|
121
136
|
for await (const message of readUIMessageStream({
|
|
122
137
|
...(existing ? { message: existing } : {}),
|
|
123
|
-
stream: closeOnTerminalChunk(
|
|
124
|
-
|
|
125
|
-
|
|
138
|
+
stream: closeOnTerminalChunk(
|
|
139
|
+
stream.stream,
|
|
140
|
+
() => {
|
|
141
|
+
terminalReceived = true;
|
|
142
|
+
},
|
|
143
|
+
(chunk) => recordTraceId(readMlflowTracePart(chunk)),
|
|
144
|
+
),
|
|
126
145
|
terminateOnError: true,
|
|
127
146
|
})) {
|
|
128
147
|
if (signal.aborted) throw new StreamAborted();
|