@lota-sdk/ui 0.1.46 → 0.1.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lota-sdk/ui",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -25,7 +25,7 @@
25
25
  "registry": "https://registry.npmjs.org/"
26
26
  },
27
27
  "dependencies": {
28
- "@lota-sdk/shared": "0.1.46",
28
+ "@lota-sdk/shared": "0.1.47",
29
29
  "ai": "^6.0.141"
30
30
  },
31
31
  "peerDependencies": {
@@ -12,6 +12,7 @@ export interface UseThreadChatOptions<UI_MESSAGE extends UIMessage> {
12
12
  transport: ChatTransport<UI_MESSAGE>
13
13
  messageMetadataSchema?: ChatInit<UI_MESSAGE>['messageMetadataSchema']
14
14
  dataPartSchemas?: ChatInit<UI_MESSAGE>['dataPartSchemas']
15
+ onData?: ChatInit<UI_MESSAGE>['onData']
15
16
  onMessagesSettled?: () => void
16
17
  setThreadRunningState?: (isRunning: boolean) => void
17
18
  notifyError?: (message: string, error: Error) => void
@@ -44,6 +45,7 @@ export function useThreadChat<UI_MESSAGE extends UIMessage>({
44
45
  transport,
45
46
  messageMetadataSchema,
46
47
  dataPartSchemas,
48
+ onData,
47
49
  onMessagesSettled,
48
50
  setThreadRunningState,
49
51
  notifyError,
@@ -53,9 +55,14 @@ export function useThreadChat<UI_MESSAGE extends UIMessage>({
53
55
  resume = false,
54
56
  idPrefix = 'thread',
55
57
  }: UseThreadChatOptions<UI_MESSAGE>): UseThreadChatReturn<UI_MESSAGE> {
58
+ const onDataRef = useRef(onData)
56
59
  const onMessagesSettledRef = useRef(onMessagesSettled)
57
60
  const setThreadRunningStateRef = useRef(setThreadRunningState)
58
61
 
62
+ useEffect(() => {
63
+ onDataRef.current = onData
64
+ }, [onData])
65
+
59
66
  useEffect(() => {
60
67
  onMessagesSettledRef.current = onMessagesSettled
61
68
  }, [onMessagesSettled])
@@ -83,6 +90,9 @@ export function useThreadChat<UI_MESSAGE extends UIMessage>({
83
90
  messages: initialMessages,
84
91
  messageMetadataSchema,
85
92
  dataPartSchemas,
93
+ onData: (dataPart) => {
94
+ onDataRef.current?.(dataPart)
95
+ },
86
96
  // TODO: Replace with stable `throttle` once AI SDK promotes it from experimental.
87
97
  // Tracked at: https://github.com/vercel/ai/issues — currently still `experimental_throttle` in @ai-sdk/react v3.x.
88
98
  experimental_throttle: experimentalThrottle,