@rolder/kit 3.0.0-alpha.46 → 3.0.0-alpha.48
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/dist/ai/ui/chat/Message.js +1 -1
- package/dist/ai/ui/chat/Root.d.ts +4 -1
- package/dist/ai/ui/chat/Root.js +28 -16
- package/dist/ai/ui/chat/chatInput/store/input.js +0 -4
- package/dist/ai/ui/chat/index.d.ts +1 -1
- package/dist/ai/ui/chat/store/messages.d.ts +2 -1
- package/dist/ai/ui/chat/store/messages.js +8 -6
- package/package.json +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { UseChatOptions } from '@ai-sdk/react';
|
|
1
2
|
import { type PaperProps } from '@mantine/core';
|
|
3
|
+
import type { ChatInit, UIMessage } from 'ai';
|
|
2
4
|
import { type ScrollAreaProps } from '../../../ui';
|
|
3
5
|
export interface ConversationRootProps extends PaperProps {
|
|
4
6
|
children?: React.ReactNode;
|
|
5
7
|
scrollAreaProps?: ScrollAreaProps;
|
|
6
8
|
withScrollButton?: boolean;
|
|
9
|
+
chatOptions?: UseChatOptions<UIMessage> & ChatInit<UIMessage>;
|
|
7
10
|
}
|
|
8
|
-
export declare const Root: ({ children, scrollAreaProps, withScrollButton, ...props }: ConversationRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const Root: ({ children, scrollAreaProps, withScrollButton, chatOptions, ...props }: ConversationRootProps) => import("react/jsx-runtime").JSX.Element;
|
package/dist/ai/ui/chat/Root.js
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Paper } from "@mantine/core";
|
|
3
3
|
import { ScrollArea } from "../../../ui/index.js";
|
|
4
|
-
|
|
4
|
+
import { useInitChat } from "./store/index.js";
|
|
5
|
+
const ChatInitializer = ({ chatOptions })=>{
|
|
6
|
+
useInitChat(chatOptions);
|
|
7
|
+
return null;
|
|
8
|
+
};
|
|
9
|
+
const Root = ({ children, scrollAreaProps, withScrollButton = true, chatOptions, ...props })=>{
|
|
5
10
|
console.log('Root render');
|
|
6
|
-
return /*#__PURE__*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
12
|
+
children: [
|
|
13
|
+
/*#__PURE__*/ jsx(ChatInitializer, {
|
|
14
|
+
chatOptions: chatOptions
|
|
15
|
+
}),
|
|
16
|
+
/*#__PURE__*/ jsx(Paper, {
|
|
17
|
+
withBorder: true,
|
|
18
|
+
radius: "md",
|
|
19
|
+
...props,
|
|
20
|
+
children: /*#__PURE__*/ jsxs(ScrollArea, {
|
|
21
|
+
autoScroll: true,
|
|
22
|
+
scrollToBottomOnInit: true,
|
|
23
|
+
p: "md",
|
|
24
|
+
...scrollAreaProps,
|
|
25
|
+
children: [
|
|
26
|
+
children,
|
|
27
|
+
withScrollButton && /*#__PURE__*/ jsx(ScrollArea.ScrollButton, {})
|
|
28
|
+
]
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
]
|
|
20
32
|
});
|
|
21
33
|
};
|
|
22
34
|
export { Root };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const Chat: {
|
|
2
|
-
Root: ({ children, scrollAreaProps, withScrollButton, ...props }: import("./Root").ConversationRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
Root: ({ children, scrollAreaProps, withScrollButton, chatOptions, ...props }: import("./Root").ConversationRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
Messages: ({ children, ...props }: Omit<import("@mantine/core").StackProps, "children"> & {
|
|
4
4
|
children: (messageId: string) => import("react").ReactNode;
|
|
5
5
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -8,7 +8,8 @@ export declare const getChatMessages: <T extends UIMessage>() => T[];
|
|
|
8
8
|
export declare const setChatMessages: <T extends UIMessage>(messages: T[]) => void;
|
|
9
9
|
export declare const getIsEmpty: () => boolean;
|
|
10
10
|
export declare const useIsEmpty: () => boolean;
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const useInitChat: <T extends UIMessage>(props?: UseChatOptions<T> & ChatInit<T>) => void;
|
|
12
|
+
export declare const useChatMessageIds: () => string[];
|
|
12
13
|
export declare const useChatMessage: <T extends UIMessage>(messageId: string) => T;
|
|
13
14
|
export declare const useChatMessagePart: <M extends UIMessage, T extends UIMessagePart<UIDataTypes, UITools>>(messageId: string, type?: T["type"]) => T | undefined;
|
|
14
15
|
export type SendMessage = ({ text, file }: {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { useChat } from "@ai-sdk/react";
|
|
2
2
|
import { notifications } from "@mantine/notifications";
|
|
3
3
|
import { useStore } from "@nanostores/react";
|
|
4
|
-
import { atom, computed, map } from "nanostores";
|
|
4
|
+
import { atom, computed, map, onSet } from "nanostores";
|
|
5
5
|
import { useEffect } from "react";
|
|
6
6
|
import { setChatError, setChatStatus } from "./states.js";
|
|
7
7
|
const $chatMessageIds = atom([]);
|
|
8
|
+
onSet($chatMessageIds, ({ newValue, abort })=>{
|
|
9
|
+
const currentValue = $chatMessageIds.get();
|
|
10
|
+
if (currentValue.length === newValue.length && currentValue.every((id, index)=>id === newValue[index])) abort();
|
|
11
|
+
});
|
|
8
12
|
const $chatMessages = map({});
|
|
9
13
|
const getChatMessage = (messageId)=>$chatMessages.get()[messageId];
|
|
10
14
|
const addChatMessage = (newMessage)=>{
|
|
@@ -27,7 +31,7 @@ const setChatMessages = (messages)=>{
|
|
|
27
31
|
const $isEmpty = computed($chatMessageIds, (messages)=>0 === messages.length);
|
|
28
32
|
const getIsEmpty = ()=>$isEmpty.get();
|
|
29
33
|
const useIsEmpty = ()=>useStore($isEmpty);
|
|
30
|
-
const
|
|
34
|
+
const useInitChat = (props)=>{
|
|
31
35
|
const { messages, status, error, sendMessage } = useChat({
|
|
32
36
|
onError: (e)=>{
|
|
33
37
|
notifications.show({
|
|
@@ -59,8 +63,8 @@ const useChatMessageIds = (props)=>{
|
|
|
59
63
|
}, [
|
|
60
64
|
messages
|
|
61
65
|
]);
|
|
62
|
-
return useStore($chatMessageIds);
|
|
63
66
|
};
|
|
67
|
+
const useChatMessageIds = ()=>useStore($chatMessageIds);
|
|
64
68
|
const useChatMessage = (messageId)=>useStore($chatMessages, {
|
|
65
69
|
keys: [
|
|
66
70
|
messageId
|
|
@@ -68,7 +72,6 @@ const useChatMessage = (messageId)=>useStore($chatMessages, {
|
|
|
68
72
|
})[messageId];
|
|
69
73
|
const useChatMessagePart = (messageId, type)=>{
|
|
70
74
|
const message = useChatMessage(messageId);
|
|
71
|
-
console.log(messageId, message);
|
|
72
75
|
const part = message?.parts?.find((i)=>i.type === type);
|
|
73
76
|
return part;
|
|
74
77
|
};
|
|
@@ -79,7 +82,6 @@ const messages_sendMessage = async ({ text, file }, data)=>{
|
|
|
79
82
|
const files = file ? [
|
|
80
83
|
file
|
|
81
84
|
] : [];
|
|
82
|
-
console.log(getChatSendMessage());
|
|
83
85
|
await getChatSendMessage()?.({
|
|
84
86
|
text,
|
|
85
87
|
files
|
|
@@ -87,4 +89,4 @@ const messages_sendMessage = async ({ text, file }, data)=>{
|
|
|
87
89
|
body: data
|
|
88
90
|
});
|
|
89
91
|
};
|
|
90
|
-
export { $chatMessageIds, $chatMessages, addChatMessage, getChatMessage, getChatMessages, getIsEmpty, messages_sendMessage as sendMessage, setChatMessages, useChatMessage, useChatMessageIds, useChatMessagePart, useIsEmpty };
|
|
92
|
+
export { $chatMessageIds, $chatMessages, addChatMessage, getChatMessage, getChatMessages, getIsEmpty, messages_sendMessage as sendMessage, setChatMessages, useChatMessage, useChatMessageIds, useChatMessagePart, useInitChat, useIsEmpty };
|