@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.
@@ -20,6 +20,6 @@ const Message = /*#__PURE__*/ memo(({ messageId })=>{
20
20
  isAnimating: isStreaming && 'assistant' === message.role,
21
21
  children: part?.text
22
22
  })
23
- }, messageId) : null;
23
+ }) : null;
24
24
  });
25
25
  export { Message };
@@ -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;
@@ -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
- const Root = ({ children, scrollAreaProps, withScrollButton = true, ...props })=>{
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__*/ jsx(Paper, {
7
- withBorder: true,
8
- radius: "md",
9
- ...props,
10
- children: /*#__PURE__*/ jsxs(ScrollArea, {
11
- autoScroll: true,
12
- scrollToBottomOnInit: true,
13
- p: "md",
14
- ...scrollAreaProps,
15
- children: [
16
- children,
17
- withScrollButton && /*#__PURE__*/ jsx(ScrollArea.ScrollButton, {})
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 };
@@ -68,10 +68,6 @@ ${fileContent}
68
68
  } catch (error) {
69
69
  fileErrorNotificaton(error);
70
70
  }
71
- console.log('onSubmit', onSubmit, {
72
- text,
73
- file
74
- });
75
71
  if (onSubmit) onSubmit({
76
72
  text,
77
73
  file: fileUIPart
@@ -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 useChatMessageIds: <T extends UIMessage>(props?: UseChatOptions<T> & ChatInit<T>) => string[];
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 useChatMessageIds = (props)=>{
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolder/kit",
3
- "version": "3.0.0-alpha.46",
3
+ "version": "3.0.0-alpha.48",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {