@dbx-tools/ui-mastra 0.9.161 → 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 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
@@ -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.161";
6
+ export const PACKAGE_VERSION = "0.9.165";
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.161",
36
- "@dbx-tools/shared-core": "^0.9.161",
37
- "@dbx-tools/shared-genie": "^0.9.161",
38
- "@dbx-tools/shared-mastra": "^0.9.161",
39
- "@dbx-tools/shared-model": "^0.9.161",
40
- "@dbx-tools/ui": "^0.9.161",
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.161",
58
+ "version": "0.9.165",
59
59
  "types": "index.ts",
60
60
  "dbxToolsConfig": {
61
61
  "tags": [
@@ -1,5 +1,10 @@
1
1
  import { log, toError, trimToUndefined } from "@dbx-tools/shared-core";
2
- import { MLFLOW_TRACE_ID_HEADER, isStaleMastraResumeError } from "@dbx-tools/shared-mastra";
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 traceId = readMlflowTraceId(stream);
99
- if (traceId) {
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(stream.stream, () => {
124
- terminalReceived = true;
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();