@rolder/kit 3.0.0-alpha.55 → 3.0.0-alpha.57

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.
@@ -2,11 +2,11 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { Paper } from "@mantine/core";
3
3
  import { memo } from "react";
4
4
  import { Streamdown } from "streamdown";
5
- import { useChatMessage, useChatMessagePart, useIsStreaming } from "./store/index.js";
5
+ import { useChatMessage, useChatMessagePart, useIsMessageStreaming } from "./store/index.js";
6
6
  const Message = /*#__PURE__*/ memo(({ messageId })=>{
7
7
  const message = useChatMessage(messageId);
8
8
  const part = useChatMessagePart(messageId, 'text');
9
- const isStreaming = useIsStreaming();
9
+ const isStreaming = useIsMessageStreaming(messageId);
10
10
  console.log('Message render', part?.text);
11
11
  return part ? /*#__PURE__*/ jsx(Paper, {
12
12
  radius: "md",
@@ -6,6 +6,9 @@ export declare const getIsLoading: () => boolean;
6
6
  export declare const useIsLoading: () => boolean;
7
7
  export declare const getIsStreaming: () => boolean;
8
8
  export declare const useIsStreaming: () => boolean;
9
+ export declare const getStreamingMessageId: () => string | undefined;
10
+ export declare const useStreamingMessageId: () => string | undefined;
11
+ export declare const useIsMessageStreaming: (messageId: string) => boolean;
9
12
  export declare const getChatError: () => string | undefined;
10
13
  export declare const setChatError: (error: string | undefined) => void;
11
14
  export declare const useChatError: () => string | undefined;
@@ -1,5 +1,6 @@
1
1
  import { useStore } from "@nanostores/react";
2
2
  import { atom, computed } from "nanostores";
3
+ import { $chatMessageIds } from "./messageIds.js";
3
4
  const $chatStatus = atom('ready');
4
5
  const getChatStatus = ()=>$chatStatus.get();
5
6
  const setChatStatus = (status)=>$chatStatus.set(status);
@@ -10,8 +11,21 @@ const useIsLoading = ()=>useStore($isLoading);
10
11
  const $isStreaming = computed($chatStatus, (status)=>'streaming' === status);
11
12
  const getIsStreaming = ()=>$isStreaming.get();
12
13
  const useIsStreaming = ()=>useStore($isStreaming);
14
+ const $streamingMessageId = computed([
15
+ $isStreaming,
16
+ $chatMessageIds
17
+ ], (isStreaming, messageIds)=>{
18
+ if (!isStreaming || 0 === messageIds.length) return;
19
+ return messageIds[messageIds.length - 1];
20
+ });
21
+ const getStreamingMessageId = ()=>$streamingMessageId.get();
22
+ const useStreamingMessageId = ()=>useStore($streamingMessageId);
23
+ const useIsMessageStreaming = (messageId)=>{
24
+ const streamingMessageId = useStreamingMessageId();
25
+ return streamingMessageId === messageId;
26
+ };
13
27
  const $chatError = atom();
14
28
  const getChatError = ()=>$chatError.get();
15
29
  const setChatError = (error)=>$chatError.set(error);
16
30
  const useChatError = ()=>useStore($chatError);
17
- export { getChatError, getChatStatus, getIsLoading, getIsStreaming, setChatError, setChatStatus, useChatError, useChatStatus, useIsLoading, useIsStreaming };
31
+ export { getChatError, getChatStatus, getIsLoading, getIsStreaming, getStreamingMessageId, setChatError, setChatStatus, useChatError, useChatStatus, useIsLoading, useIsMessageStreaming, useIsStreaming, useStreamingMessageId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolder/kit",
3
- "version": "3.0.0-alpha.55",
3
+ "version": "3.0.0-alpha.57",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {