@rolder/kit 3.0.0-alpha.5 → 3.0.0-alpha.51
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/index.d.ts +2 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/ui/{conversation → chat}/Empty.js +5 -4
- package/dist/ai/ui/chat/File.d.ts +3 -0
- package/dist/ai/ui/{conversation → chat}/File.js +10 -8
- package/dist/ai/ui/chat/FileIcon.js +43 -0
- package/dist/ai/ui/{conversation → chat}/Loader.js +4 -3
- package/dist/ai/ui/chat/Message.d.ts +3 -0
- package/dist/ai/ui/chat/Message.js +25 -0
- package/dist/ai/ui/chat/Messages.d.ts +7 -0
- package/dist/ai/ui/chat/Messages.js +12 -0
- package/dist/ai/ui/chat/Root.d.ts +11 -0
- package/dist/ai/ui/chat/Root.js +34 -0
- package/dist/ai/ui/chat/chatInput/File.js +72 -0
- package/dist/ai/ui/chat/chatInput/FileIcon.js +43 -0
- package/dist/ai/ui/{promptInput → chat/chatInput}/Footer.js +4 -1
- package/dist/ai/ui/chat/chatInput/Root.d.ts +9 -0
- package/dist/ai/ui/chat/chatInput/Root.js +25 -0
- package/dist/ai/ui/chat/chatInput/Submit.js +24 -0
- package/dist/ai/ui/{promptInput → chat/chatInput}/Textarea.js +9 -7
- package/dist/ai/ui/{promptInput → chat/chatInput}/index.d.ts +2 -3
- package/dist/ai/ui/{promptInput → chat/chatInput}/index.js +2 -2
- package/dist/ai/ui/chat/chatInput/store/file.d.ts +8 -0
- package/dist/ai/ui/chat/chatInput/store/file.js +32 -0
- package/dist/ai/ui/chat/chatInput/store/fileErrorNotificaton.d.ts +2 -0
- package/dist/ai/ui/chat/chatInput/store/fileErrorNotificaton.js +21 -0
- package/dist/ai/ui/chat/chatInput/store/index.d.ts +2 -0
- package/dist/ai/ui/chat/chatInput/store/index.js +2 -0
- package/dist/ai/ui/chat/chatInput/store/input.d.ts +13 -0
- package/dist/ai/ui/chat/chatInput/store/input.js +81 -0
- package/dist/ai/ui/chat/chatInput/store/parseFile.d.ts +2 -0
- package/dist/ai/ui/chat/chatInput/store/parseFile.js +23 -0
- package/dist/ai/ui/chat/index.d.ts +16 -0
- package/dist/ai/ui/{conversation → chat}/index.js +6 -3
- package/dist/ai/ui/chat/store/index.d.ts +5 -0
- package/dist/ai/ui/chat/store/index.js +5 -0
- package/dist/ai/ui/chat/store/messageIds.d.ts +8 -0
- package/dist/ai/ui/chat/store/messageIds.js +43 -0
- package/dist/ai/ui/chat/store/messagesMap.d.ts +5 -0
- package/dist/ai/ui/chat/store/messagesMap.js +15 -0
- package/dist/ai/ui/chat/store/send.d.ts +14 -0
- package/dist/ai/ui/chat/store/send.js +16 -0
- package/dist/ai/ui/chat/store/states.d.ts +11 -0
- package/dist/ai/ui/chat/store/states.js +17 -0
- package/dist/ai/ui/chat/store/useInitChat.d.ts +3 -0
- package/dist/ai/ui/chat/store/useInitChat.js +40 -0
- package/dist/ai/ui/index.d.ts +1 -0
- package/dist/ai/ui/index.js +1 -0
- package/dist/ai/utils/index.d.ts +2 -0
- package/dist/ai/utils/index.js +2 -0
- package/dist/app/AppDefaults.js +1 -1
- package/dist/app/DefaultApp.js +1 -1
- package/dist/app/cookieColorSchemeManager.js +1 -1
- package/dist/app/defaultTheme.d.ts +1 -1
- package/dist/app/index.d.ts +4 -0
- package/dist/app/index.js +4 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/index.d.ts +5 -26
- package/dist/index.js +5 -26
- package/dist/styles.css +3 -3
- package/dist/tanstackFunctions/cookie/index.d.ts +3 -0
- package/dist/tanstackFunctions/cookie/index.js +4 -0
- package/dist/tanstackFunctions/index.d.ts +2 -0
- package/dist/tanstackFunctions/index.js +2 -0
- package/dist/tanstackFunctions/s3/getS3Client.d.ts +2 -0
- package/dist/tanstackFunctions/s3/getS3Client.js +18 -0
- package/dist/tanstackFunctions/s3/getSignedFileUrlFn.d.ts +4 -0
- package/dist/tanstackFunctions/s3/getSignedFileUrlFn.js +21 -0
- package/dist/tanstackFunctions/s3/index.d.ts +2 -0
- package/dist/tanstackFunctions/s3/index.js +2 -0
- package/dist/tanstackFunctions/s3/uploadRequest.d.ts +3 -0
- package/dist/tanstackFunctions/s3/uploadRequest.js +21 -0
- package/dist/ui/AnimatedChevron.d.ts +2 -2
- package/dist/ui/AnimatedChevron.js +7 -25
- package/dist/ui/JsonInput.js +1 -1
- package/dist/ui/editor/Toolbar.js +4 -22
- package/dist/ui/form/buttons/CancelButton.js +4 -26
- package/dist/ui/form/buttons/SubmitButton.js +4 -29
- package/dist/ui/form/fields/TextPassowrdField.js +4 -26
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/scrollArea/ScrollArea.d.ts +1 -1
- package/dist/ui/scrollArea/ScrollAreaButton.d.ts +1 -1
- package/dist/ui/scrollArea/ScrollAreaButton.js +7 -28
- package/package.json +40 -28
- package/dist/ai/ui/conversation/ConversationContext.d.ts +0 -7
- package/dist/ai/ui/conversation/ConversationContext.js +0 -8
- package/dist/ai/ui/conversation/ConversationProvider.d.ts +0 -2
- package/dist/ai/ui/conversation/ConversationProvider.js +0 -14
- package/dist/ai/ui/conversation/File.d.ts +0 -4
- package/dist/ai/ui/conversation/FileIcon.js +0 -225
- package/dist/ai/ui/conversation/Message.d.ts +0 -4
- package/dist/ai/ui/conversation/Message.js +0 -25
- package/dist/ai/ui/conversation/Root.d.ts +0 -2
- package/dist/ai/ui/conversation/Root.js +0 -26
- package/dist/ai/ui/conversation/index.d.ts +0 -13
- package/dist/ai/ui/conversation/types.d.ts +0 -7
- package/dist/ai/ui/conversation/types.js +0 -0
- package/dist/ai/ui/conversation/useChatMessage.d.ts +0 -2
- package/dist/ai/ui/conversation/useChatMessage.js +0 -12
- package/dist/ai/ui/promptInput/File.js +0 -117
- package/dist/ai/ui/promptInput/FileIcon.js +0 -225
- package/dist/ai/ui/promptInput/PromptInputContext.d.ts +0 -12
- package/dist/ai/ui/promptInput/PromptInputContext.js +0 -8
- package/dist/ai/ui/promptInput/PromptInputProvider.d.ts +0 -2
- package/dist/ai/ui/promptInput/PromptInputProvider.js +0 -50
- package/dist/ai/ui/promptInput/Root.d.ts +0 -3
- package/dist/ai/ui/promptInput/Root.js +0 -17
- package/dist/ai/ui/promptInput/Submit.js +0 -40
- package/dist/ai/ui/promptInput/types.d.ts +0 -11
- package/dist/ai/ui/promptInput/types.js +0 -0
- package/dist/surreal/connection.d.ts +0 -9
- package/dist/surreal/connection.js +0 -49
- package/dist/surreal/deafaultCrud.d.ts +0 -2
- package/dist/surreal/deafaultCrud.js +0 -18
- package/dist/surreal/deserialize.d.ts +0 -17
- package/dist/surreal/deserialize.js +0 -46
- package/dist/surreal/encryption.d.ts +0 -6
- package/dist/surreal/encryption.js +0 -30
- /package/dist/ai/ui/{conversation → chat}/Empty.d.ts +0 -0
- /package/dist/ai/ui/{conversation → chat}/FileIcon.d.ts +0 -0
- /package/dist/ai/ui/{conversation → chat}/Loader.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/File.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/FileIcon.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Footer.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Submit.d.ts +0 -0
- /package/dist/ai/ui/{promptInput → chat/chatInput}/Textarea.d.ts +0 -0
- /package/dist/{functions → tanstackFunctions/cookie}/getCookie.d.ts +0 -0
- /package/dist/{functions → tanstackFunctions/cookie}/getCookie.js +0 -0
- /package/dist/{functions → tanstackFunctions/cookie}/setCookie.d.ts +0 -0
- /package/dist/{functions → tanstackFunctions/cookie}/setCookie.js +0 -0
- /package/dist/{functions → tanstackFunctions/cookie}/setCookies.d.ts +0 -0
- /package/dist/{functions → tanstackFunctions/cookie}/setCookies.js +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { uploadFile } from "@better-upload/client";
|
|
2
|
+
import { useStore } from "@nanostores/react";
|
|
3
|
+
import { nanoid } from "nanoid";
|
|
4
|
+
import { atom } from "nanostores";
|
|
5
|
+
import { getSignedFileUrlFn } from "../../../../../tanstackFunctions/index.js";
|
|
6
|
+
import { addChatMessage, sendMessage } from "../../store/index.js";
|
|
7
|
+
import { getFile } from "./file.js";
|
|
8
|
+
import { fileErrorNotificaton } from "./fileErrorNotificaton.js";
|
|
9
|
+
import { parseExcel, parseWord } from "./parseFile.js";
|
|
10
|
+
const $text = atom('');
|
|
11
|
+
const getText = ()=>$text.get();
|
|
12
|
+
const useText = ()=>useStore($text);
|
|
13
|
+
const setText = (text)=>$text.set(text);
|
|
14
|
+
const $isComposing = atom(false);
|
|
15
|
+
const getIsComposing = ()=>$isComposing.get();
|
|
16
|
+
const setIsComposing = (isComposing)=>$isComposing.set(isComposing);
|
|
17
|
+
const $onSubmit = atom();
|
|
18
|
+
const getOnSubmit = ()=>$onSubmit.get();
|
|
19
|
+
const setOnSubmit = (onSubmit)=>$onSubmit.set(onSubmit);
|
|
20
|
+
const input_onSubmit = async ()=>{
|
|
21
|
+
const onSubmit = getOnSubmit();
|
|
22
|
+
const text = getText();
|
|
23
|
+
const file = getFile();
|
|
24
|
+
let fileUIPart;
|
|
25
|
+
if (file) if ([
|
|
26
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
27
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
28
|
+
].includes(file.type)) {
|
|
29
|
+
let fileContent;
|
|
30
|
+
let type;
|
|
31
|
+
if ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' === file.type) {
|
|
32
|
+
fileContent = await parseExcel(file);
|
|
33
|
+
type = 'excel';
|
|
34
|
+
} else if ('application/vnd.openxmlformats-officedocument.wordprocessingml.document' === file.type) {
|
|
35
|
+
fileContent = await parseWord(file);
|
|
36
|
+
type = 'word';
|
|
37
|
+
}
|
|
38
|
+
if (fileContent && type) addChatMessage({
|
|
39
|
+
id: `file-${type}-${nanoid()}`,
|
|
40
|
+
role: 'system',
|
|
41
|
+
parts: [
|
|
42
|
+
{
|
|
43
|
+
type: 'text',
|
|
44
|
+
text: `Пользователь загрузил файл типа "${type}" c содержимым:
|
|
45
|
+
\`\`\`
|
|
46
|
+
${fileContent}
|
|
47
|
+
\`\`\``
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
} else try {
|
|
52
|
+
const result = await uploadFile({
|
|
53
|
+
file,
|
|
54
|
+
route: 'upload'
|
|
55
|
+
});
|
|
56
|
+
const url = await getSignedFileUrlFn({
|
|
57
|
+
data: {
|
|
58
|
+
s3Key: result.file.objectInfo.key
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
fileUIPart = {
|
|
62
|
+
id: nanoid(),
|
|
63
|
+
type: 'file',
|
|
64
|
+
url,
|
|
65
|
+
mediaType: file.type,
|
|
66
|
+
filename: file.name
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
fileErrorNotificaton(error);
|
|
70
|
+
}
|
|
71
|
+
if (onSubmit) onSubmit({
|
|
72
|
+
text,
|
|
73
|
+
file: fileUIPart
|
|
74
|
+
});
|
|
75
|
+
sendMessage({
|
|
76
|
+
text,
|
|
77
|
+
file: fileUIPart
|
|
78
|
+
});
|
|
79
|
+
setText('');
|
|
80
|
+
};
|
|
81
|
+
export { getIsComposing, getOnSubmit, getText, input_onSubmit as onSubmit, setIsComposing, setOnSubmit, setText, useText };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import mammoth from "mammoth";
|
|
2
|
+
import { read, utils } from "xlsx";
|
|
3
|
+
const parseExcel = async (file)=>{
|
|
4
|
+
const buffer = await file.arrayBuffer();
|
|
5
|
+
const workbook = read(buffer, {
|
|
6
|
+
type: 'array',
|
|
7
|
+
cellDates: true
|
|
8
|
+
});
|
|
9
|
+
const sheetName = workbook.SheetNames[0];
|
|
10
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
11
|
+
const jsonData = utils.sheet_to_json(worksheet, {
|
|
12
|
+
dateNF: 'yyyy-mm-dd'
|
|
13
|
+
});
|
|
14
|
+
return JSON.stringify(jsonData, null, 2);
|
|
15
|
+
};
|
|
16
|
+
const parseWord = async (file)=>{
|
|
17
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
18
|
+
const { value } = await mammoth.convertToHtml({
|
|
19
|
+
arrayBuffer
|
|
20
|
+
});
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
export { parseExcel, parseWord };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const Chat: {
|
|
2
|
+
Root: ({ children, scrollAreaProps, withScrollButton, chatOptions, ...props }: import("./Root").ConversationRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
Messages: ({ children, ...props }: Omit<import("@mantine/core").StackProps, "children"> & {
|
|
4
|
+
children: (messageId: string) => import("react").ReactNode;
|
|
5
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
Message: import("react").MemoExoticComponent<({ messageId }: {
|
|
7
|
+
messageId: string;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element | null>;
|
|
9
|
+
File: ({ messageId }: {
|
|
10
|
+
messageId: string;
|
|
11
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
Loader: (props: import("@mantine/core").LoaderProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
13
|
+
Empty: () => import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
};
|
|
15
|
+
export { ChatInput } from './chatInput';
|
|
16
|
+
export * from './store';
|
|
@@ -2,13 +2,16 @@ import { Empty } from "./Empty.js";
|
|
|
2
2
|
import { File } from "./File.js";
|
|
3
3
|
import { Loader } from "./Loader.js";
|
|
4
4
|
import { Message } from "./Message.js";
|
|
5
|
+
import { Messages } from "./Messages.js";
|
|
5
6
|
import { Root } from "./Root.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
7
|
+
import { ChatInput } from "./chatInput/index.js";
|
|
8
|
+
export * from "./store/index.js";
|
|
9
|
+
const Chat = {
|
|
8
10
|
Root: Root,
|
|
11
|
+
Messages: Messages,
|
|
9
12
|
Message: Message,
|
|
10
13
|
File: File,
|
|
11
14
|
Loader: Loader,
|
|
12
15
|
Empty: Empty
|
|
13
16
|
};
|
|
14
|
-
export {
|
|
17
|
+
export { Chat, ChatInput };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UIMessage } from 'ai';
|
|
2
|
+
export declare const $chatMessageIds: import("nanostores").PreinitializedWritableAtom<string[]> & object;
|
|
3
|
+
export declare const getChatMessages: <T extends UIMessage>() => T[];
|
|
4
|
+
export declare const useChatMessageIds: () => string[];
|
|
5
|
+
export declare const addChatMessage: (newMessage: UIMessage) => void;
|
|
6
|
+
export declare const setChatMessages: <T extends UIMessage>(messages: T[]) => void;
|
|
7
|
+
export declare const getIsEmpty: () => boolean;
|
|
8
|
+
export declare const useIsEmpty: () => boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useStore } from "@nanostores/react";
|
|
2
|
+
import { atom, computed, onSet } from "nanostores";
|
|
3
|
+
import { $chatMessages } from "./messagesMap.js";
|
|
4
|
+
const $chatMessageIds = atom([]);
|
|
5
|
+
const getChatMessages = ()=>$chatMessageIds.get().map((id)=>$chatMessages.get()[id]);
|
|
6
|
+
const useChatMessageIds = ()=>useStore($chatMessageIds);
|
|
7
|
+
onSet($chatMessageIds, ({ newValue, abort })=>{
|
|
8
|
+
const currentValue = $chatMessageIds.get();
|
|
9
|
+
if (currentValue.length === newValue.length && currentValue.every((id, index)=>id === newValue[index])) abort();
|
|
10
|
+
});
|
|
11
|
+
const addChatMessage = (newMessage)=>{
|
|
12
|
+
$chatMessageIds.set([
|
|
13
|
+
...$chatMessageIds.get(),
|
|
14
|
+
newMessage.id
|
|
15
|
+
]);
|
|
16
|
+
$chatMessages.set({
|
|
17
|
+
...$chatMessages.get(),
|
|
18
|
+
[newMessage.id]: newMessage
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const setChatMessages = (messages)=>{
|
|
22
|
+
const newIds = messages.map((msg)=>msg.id);
|
|
23
|
+
$chatMessageIds.set(newIds);
|
|
24
|
+
const lastNewMessage = messages[messages.length - 1];
|
|
25
|
+
const currentMessage = $chatMessages.get()[lastNewMessage.id];
|
|
26
|
+
if (currentMessage && 'assistant' === lastNewMessage.role) {
|
|
27
|
+
const currentTextParts = currentMessage.parts.filter((part)=>'text' === part.type);
|
|
28
|
+
const newTextParts = lastNewMessage.parts.filter((part)=>'text' === part.type);
|
|
29
|
+
if (newTextParts.length > 0) {
|
|
30
|
+
let isChanged = false;
|
|
31
|
+
for(let i = 0; i < newTextParts.length; i++){
|
|
32
|
+
const newTextPart = newTextParts[i];
|
|
33
|
+
const currentTextPart = currentTextParts[i];
|
|
34
|
+
if (newTextPart.text !== currentTextPart.text) isChanged = true;
|
|
35
|
+
}
|
|
36
|
+
if (isChanged) $chatMessages.setKey(lastNewMessage.id, lastNewMessage);
|
|
37
|
+
}
|
|
38
|
+
} else $chatMessages.setKey(lastNewMessage.id, lastNewMessage);
|
|
39
|
+
};
|
|
40
|
+
const $isEmpty = computed($chatMessageIds, (messages)=>0 === messages.length);
|
|
41
|
+
const getIsEmpty = ()=>$isEmpty.get();
|
|
42
|
+
const useIsEmpty = ()=>useStore($isEmpty);
|
|
43
|
+
export { $chatMessageIds, addChatMessage, getChatMessages, getIsEmpty, setChatMessages, useChatMessageIds, useIsEmpty };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { UIDataTypes, UIMessage, UIMessagePart, UITools } from 'ai';
|
|
2
|
+
export declare const $chatMessages: import("nanostores").PreinitializedMapStore<Record<string, UIMessage<unknown, UIDataTypes, UITools>>> & object;
|
|
3
|
+
export declare const getChatMessage: (messageId: string) => UIMessage<unknown, UIDataTypes, UITools>;
|
|
4
|
+
export declare const useChatMessage: <T extends UIMessage>(messageId: string) => T;
|
|
5
|
+
export declare const useChatMessagePart: <M extends UIMessage, T extends UIMessagePart<UIDataTypes, UITools>>(messageId: string, type?: T["type"]) => T | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useStore } from "@nanostores/react";
|
|
2
|
+
import { map } from "nanostores";
|
|
3
|
+
const $chatMessages = map({});
|
|
4
|
+
const getChatMessage = (messageId)=>$chatMessages.get()[messageId];
|
|
5
|
+
const useChatMessage = (messageId)=>useStore($chatMessages, {
|
|
6
|
+
keys: [
|
|
7
|
+
messageId
|
|
8
|
+
]
|
|
9
|
+
})[messageId];
|
|
10
|
+
const useChatMessagePart = (messageId, type)=>{
|
|
11
|
+
const message = useChatMessage(messageId);
|
|
12
|
+
const part = message?.parts?.find((i)=>i.type === type);
|
|
13
|
+
return part;
|
|
14
|
+
};
|
|
15
|
+
export { $chatMessages, getChatMessage, useChatMessage, useChatMessagePart };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FileUIPart } from 'ai';
|
|
2
|
+
export type SendMessage = ({ text, file }: {
|
|
3
|
+
text: string;
|
|
4
|
+
file?: FileUIPart;
|
|
5
|
+
}, data?: Record<string, unknown>) => Promise<void>;
|
|
6
|
+
type SendSdkMessage = ({ text, files }: {
|
|
7
|
+
text: string;
|
|
8
|
+
files?: FileUIPart[];
|
|
9
|
+
}, { body }: {
|
|
10
|
+
body?: Record<string, unknown>;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
export declare const setChatSendMessage: (sendMessage: SendSdkMessage) => void;
|
|
13
|
+
export declare const sendMessage: SendMessage;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { atom } from "nanostores";
|
|
2
|
+
const $chatSendMessage = atom();
|
|
3
|
+
const getChatSendMessage = ()=>$chatSendMessage.get();
|
|
4
|
+
const setChatSendMessage = (sendMessage)=>$chatSendMessage.set(sendMessage);
|
|
5
|
+
const send_sendMessage = async ({ text, file }, data)=>{
|
|
6
|
+
const files = file ? [
|
|
7
|
+
file
|
|
8
|
+
] : [];
|
|
9
|
+
await getChatSendMessage()?.({
|
|
10
|
+
text,
|
|
11
|
+
files
|
|
12
|
+
}, {
|
|
13
|
+
body: data
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export { send_sendMessage as sendMessage, setChatSendMessage };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChatStatus } from 'ai';
|
|
2
|
+
export declare const getChatStatus: () => ChatStatus;
|
|
3
|
+
export declare const setChatStatus: (status: ChatStatus) => void;
|
|
4
|
+
export declare const useChatStatus: () => ChatStatus;
|
|
5
|
+
export declare const getIsLoading: () => boolean;
|
|
6
|
+
export declare const useIsLoading: () => boolean;
|
|
7
|
+
export declare const getIsStreaming: () => boolean;
|
|
8
|
+
export declare const useIsStreaming: () => boolean;
|
|
9
|
+
export declare const getChatError: () => string | undefined;
|
|
10
|
+
export declare const setChatError: (error: string | undefined) => void;
|
|
11
|
+
export declare const useChatError: () => string | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useStore } from "@nanostores/react";
|
|
2
|
+
import { atom, computed } from "nanostores";
|
|
3
|
+
const $chatStatus = atom('ready');
|
|
4
|
+
const getChatStatus = ()=>$chatStatus.get();
|
|
5
|
+
const setChatStatus = (status)=>$chatStatus.set(status);
|
|
6
|
+
const useChatStatus = ()=>useStore($chatStatus);
|
|
7
|
+
const $isLoading = computed($chatStatus, (status)=>'ready' !== status);
|
|
8
|
+
const getIsLoading = ()=>$isLoading.get();
|
|
9
|
+
const useIsLoading = ()=>useStore($isLoading);
|
|
10
|
+
const $isStreaming = computed($chatStatus, (status)=>'streaming' === status);
|
|
11
|
+
const getIsStreaming = ()=>$isStreaming.get();
|
|
12
|
+
const useIsStreaming = ()=>useStore($isStreaming);
|
|
13
|
+
const $chatError = atom();
|
|
14
|
+
const getChatError = ()=>$chatError.get();
|
|
15
|
+
const setChatError = (error)=>$chatError.set(error);
|
|
16
|
+
const useChatError = ()=>useStore($chatError);
|
|
17
|
+
export { getChatError, getChatStatus, getIsLoading, getIsStreaming, setChatError, setChatStatus, useChatError, useChatStatus, useIsLoading, useIsStreaming };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useChat } from "@ai-sdk/react";
|
|
2
|
+
import { notifications } from "@mantine/notifications";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { setChatMessages } from "./messageIds.js";
|
|
5
|
+
import { setChatSendMessage } from "./send.js";
|
|
6
|
+
import { setChatError, setChatStatus } from "./states.js";
|
|
7
|
+
const useInitChat = (props)=>{
|
|
8
|
+
const { messages, status, error, sendMessage } = useChat({
|
|
9
|
+
onError: (e)=>{
|
|
10
|
+
notifications.show({
|
|
11
|
+
title: 'Ошибка сервера ИИ',
|
|
12
|
+
message: e.message,
|
|
13
|
+
color: 'red',
|
|
14
|
+
autoClose: false
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
...props
|
|
18
|
+
});
|
|
19
|
+
useEffect(()=>{
|
|
20
|
+
setChatStatus(status);
|
|
21
|
+
}, [
|
|
22
|
+
status
|
|
23
|
+
]);
|
|
24
|
+
useEffect(()=>{
|
|
25
|
+
setChatError(error?.message);
|
|
26
|
+
}, [
|
|
27
|
+
error?.message
|
|
28
|
+
]);
|
|
29
|
+
useEffect(()=>{
|
|
30
|
+
setChatSendMessage(sendMessage);
|
|
31
|
+
}, [
|
|
32
|
+
sendMessage
|
|
33
|
+
]);
|
|
34
|
+
useEffect(()=>{
|
|
35
|
+
setChatMessages(messages);
|
|
36
|
+
}, [
|
|
37
|
+
messages
|
|
38
|
+
]);
|
|
39
|
+
};
|
|
40
|
+
export { useInitChat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './chat';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./chat/index.js";
|
package/dist/app/AppDefaults.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useComputedColorScheme } from "@mantine/core";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
import { setCookies } from "../
|
|
3
|
+
import { setCookies } from "../tanstackFunctions/index.js";
|
|
4
4
|
const AppDefaults = ({ saveColorScheme })=>{
|
|
5
5
|
const colorScheme = useComputedColorScheme();
|
|
6
6
|
useEffect(()=>{
|
package/dist/app/DefaultApp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { ColorSchemeScript, MantineProvider } from "@mantine/core";
|
|
3
3
|
import { HeadContent, Scripts } from "@tanstack/react-router";
|
|
4
|
-
import { getCookie } from "../
|
|
4
|
+
import { getCookie } from "../tanstackFunctions/index.js";
|
|
5
5
|
import { AppDefaults } from "./AppDefaults.js";
|
|
6
6
|
import { cookieColorSchemeManager } from "./cookieColorSchemeManager.js";
|
|
7
7
|
import { defaultTheme } from "./defaultTheme.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isMantineColorScheme } from "@mantine/core";
|
|
2
2
|
import { atom } from "nanostores";
|
|
3
|
-
import { setCookie } from "../
|
|
3
|
+
import { setCookie } from "../tanstackFunctions/index.js";
|
|
4
4
|
const $colorScheme = atom();
|
|
5
5
|
let unsubscribeSystemTheme;
|
|
6
6
|
const cookieColorSchemeManager = ({ key = 'colorScheme' } = {})=>({
|
|
@@ -6,9 +6,9 @@ export declare const defaultTheme: {
|
|
|
6
6
|
black?: string | undefined;
|
|
7
7
|
colors?: {
|
|
8
8
|
[x: string & {}]: import("@mantine/core").MantineColorsTuple | undefined;
|
|
9
|
+
red?: import("@mantine/core").MantineColorsTuple | undefined;
|
|
9
10
|
dark?: import("@mantine/core").MantineColorsTuple | undefined;
|
|
10
11
|
gray?: import("@mantine/core").MantineColorsTuple | undefined;
|
|
11
|
-
red?: import("@mantine/core").MantineColorsTuple | undefined;
|
|
12
12
|
pink?: import("@mantine/core").MantineColorsTuple | undefined;
|
|
13
13
|
grape?: import("@mantine/core").MantineColorsTuple | undefined;
|
|
14
14
|
violet?: import("@mantine/core").MantineColorsTuple | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export { DefaultApp } from './app/DefaultApp';
|
|
7
|
-
export { defaultRequestMiddlewares } from './app/defaultRequestMiddlewares';
|
|
8
|
-
export { defaultTheme } from './app/defaultTheme';
|
|
9
|
-
export { getCookie } from './functions/getCookie';
|
|
10
|
-
export { setCookie } from './functions/setCookie';
|
|
11
|
-
export { setCookies } from './functions/setCookies';
|
|
12
|
-
export { useMutation } from './hooks/useMutation';
|
|
13
|
-
export { useMutationWithInvalidate } from './hooks/useMutationWithInvalidate';
|
|
14
|
-
export { getDB } from './surreal/connection';
|
|
15
|
-
export { surrealDeleteFn, surrealUnsubscribeFn } from './surreal/deafaultCrud';
|
|
16
|
-
export { deserialize } from './surreal/deserialize';
|
|
17
|
-
export { encryptionFn } from './surreal/encryption';
|
|
18
|
-
export { Editor, useEditor } from './ui/editor';
|
|
19
|
-
export { DefaultError, DefaultNotFound, defaultErrorNotification, Forbidden, } from './ui/error';
|
|
20
|
-
export { AnimatedChevron } from './ui/AnimatedChevron';
|
|
21
|
-
export { useAppForm, useFieldContext, withForm, blurOnError, fieldsSchema, } from './ui/form';
|
|
22
|
-
export { HoverPaper, usePaperHover } from './ui/hoverPaper';
|
|
23
|
-
export { JsonInput } from './ui/JsonInput';
|
|
24
|
-
export { RouterLink } from './ui/RouterLink';
|
|
25
|
-
export { SaveInput } from './ui/saveInput';
|
|
26
|
-
export { ScrollArea, useScrollArea, type ScrollAreaContextValue, type ScrollAreaHook, type ScrollAreaProps, type ScrollAreaState, type ScrollButtonProps, type ScrollPosition, } from './ui/scrollArea';
|
|
1
|
+
export * from './ai';
|
|
2
|
+
export * from './app';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
export * from './tanstackFunctions';
|
|
5
|
+
export * from './ui';
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { defaultRequestMiddlewares } from "./app/defaultRequestMiddlewares.js";
|
|
7
|
-
import { defaultTheme } from "./app/defaultTheme.js";
|
|
8
|
-
import { getCookie } from "./functions/getCookie.js";
|
|
9
|
-
import { setCookie } from "./functions/setCookie.js";
|
|
10
|
-
import { setCookies } from "./functions/setCookies.js";
|
|
11
|
-
import { useMutation } from "./hooks/useMutation.js";
|
|
12
|
-
import { useMutationWithInvalidate } from "./hooks/useMutationWithInvalidate.js";
|
|
13
|
-
import { getDB } from "./surreal/connection.js";
|
|
14
|
-
import { surrealDeleteFn, surrealUnsubscribeFn } from "./surreal/deafaultCrud.js";
|
|
15
|
-
import { deserialize } from "./surreal/deserialize.js";
|
|
16
|
-
import { encryptionFn } from "./surreal/encryption.js";
|
|
17
|
-
import { Editor, useEditor } from "./ui/editor/index.js";
|
|
18
|
-
import { DefaultError, DefaultNotFound, Forbidden, defaultErrorNotification } from "./ui/error/index.js";
|
|
19
|
-
import { AnimatedChevron } from "./ui/AnimatedChevron.js";
|
|
20
|
-
import { blurOnError, fieldsSchema, useAppForm, useFieldContext, withForm } from "./ui/form/index.js";
|
|
21
|
-
import { HoverPaper, usePaperHover } from "./ui/hoverPaper/index.js";
|
|
22
|
-
import { JsonInput } from "./ui/JsonInput.js";
|
|
23
|
-
import { RouterLink } from "./ui/RouterLink.js";
|
|
24
|
-
import { SaveInput } from "./ui/saveInput/index.js";
|
|
25
|
-
import { ScrollArea, useScrollArea } from "./ui/scrollArea/index.js";
|
|
26
|
-
export { AnimatedChevron, Conversation, DefaultApp, DefaultError, DefaultNotFound, Editor, Forbidden, HoverPaper, JsonInput, PromptInput, RouterLink, SaveInput, ScrollArea, blurOnError, convertFileUIPartBlobToDataURL, defaultErrorNotification, defaultRequestMiddlewares, defaultTheme, deserialize, encryptionFn, fieldsSchema, getCookie, getDB, parseAiMessagePart, setCookie, setCookies, surrealDeleteFn, surrealUnsubscribeFn, useAppForm, useChatMessage, useEditor, useFieldContext, useMutation, useMutationWithInvalidate, usePaperHover, useScrollArea, withForm };
|
|
1
|
+
export * from "./ai/index.js";
|
|
2
|
+
export * from "./app/index.js";
|
|
3
|
+
export * from "./hooks/index.js";
|
|
4
|
+
export * from "./tanstackFunctions/index.js";
|
|
5
|
+
export * from "./ui/index.js";
|
package/dist/styles.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.rolder-
|
|
1
|
+
.rolder-chat-input-root {
|
|
2
2
|
background-color: light-dark(var(--mantine-color-white), var(--mantine-color-dark-6));
|
|
3
3
|
|
|
4
4
|
&:focus-within {
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
.rolder-
|
|
11
|
+
.rolder-chat-input-textarea {
|
|
12
12
|
border: 0;
|
|
13
13
|
border-radius: 8px;
|
|
14
14
|
overflow: hidden;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
.rolder-
|
|
17
|
+
.rolder-chat-input-file-action-action {
|
|
18
18
|
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-dark-1));
|
|
19
19
|
|
|
20
20
|
&[data-disabled] {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { custom } from "@better-upload/server/clients";
|
|
2
|
+
const getS3Client = ()=>{
|
|
3
|
+
const host = process.env.S3_HOST;
|
|
4
|
+
if (!host) throw new Error('S3_HOST environment variable is not set');
|
|
5
|
+
const region = process.env.S3_REGION;
|
|
6
|
+
if (!region) throw new Error('S3_REGION environment variable is not set');
|
|
7
|
+
const accessKeyId = process.env.S3_ACCESS_KEY_ID;
|
|
8
|
+
if (!accessKeyId) throw new Error('S3_ACCESS_KEY_ID environment variable is not set');
|
|
9
|
+
const accessKeySecret = process.env.S3_ACCESS_KEY_SECRET;
|
|
10
|
+
if (!accessKeySecret) throw new Error('S3_ACCESS_KEY_SECRET environment variable is not set');
|
|
11
|
+
return custom({
|
|
12
|
+
host,
|
|
13
|
+
region,
|
|
14
|
+
accessKeyId,
|
|
15
|
+
secretAccessKey: accessKeySecret
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export { getS3Client };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { presignGetObject } from "@better-upload/server/helpers";
|
|
2
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
3
|
+
import v4 from "zod/v4";
|
|
4
|
+
import { getS3Client } from "./getS3Client.js";
|
|
5
|
+
const Schema = v4.object({
|
|
6
|
+
s3Key: v4.string()
|
|
7
|
+
});
|
|
8
|
+
const getSignedFileUrlFn = createServerFn({
|
|
9
|
+
method: 'POST'
|
|
10
|
+
}).inputValidator(Schema).handler(async ({ data: { s3Key } })=>{
|
|
11
|
+
const bucket = process.env.S3_BUCKET_NAME;
|
|
12
|
+
if (!bucket) throw new Error('S3_BUCKET_NAME environment variable is not set');
|
|
13
|
+
const s3 = getS3Client();
|
|
14
|
+
const url = await presignGetObject(s3, {
|
|
15
|
+
bucket,
|
|
16
|
+
key: s3Key,
|
|
17
|
+
expiresIn: 300
|
|
18
|
+
});
|
|
19
|
+
return url;
|
|
20
|
+
});
|
|
21
|
+
export { getSignedFileUrlFn };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { handleRequest, route } from "@better-upload/server";
|
|
2
|
+
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
3
|
+
import { getS3Client } from "./getS3Client.js";
|
|
4
|
+
const getRouter = createServerOnlyFn(()=>{
|
|
5
|
+
const bucket = process.env.BUCKET_NAME;
|
|
6
|
+
if (!bucket) throw new Error('BUCKET_NAME environment variable is not set');
|
|
7
|
+
const s3 = getS3Client();
|
|
8
|
+
const router = {
|
|
9
|
+
client: s3,
|
|
10
|
+
bucketName: bucket,
|
|
11
|
+
routes: {
|
|
12
|
+
upload: route({
|
|
13
|
+
multipleFiles: false,
|
|
14
|
+
maxFileSize: 52428800
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return router;
|
|
19
|
+
});
|
|
20
|
+
const uploadRequest = async ({ request })=>handleRequest(request, getRouter());
|
|
21
|
+
export { uploadRequest };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
interface Props extends
|
|
1
|
+
import { type IconProps } from '@tabler/icons-react';
|
|
2
|
+
interface Props extends IconProps {
|
|
3
3
|
expanded?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare const AnimatedChevron: ({ expanded, style, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
|