@clikvn/agent-widget-embedded 0.0.1 → 0.0.2-dev
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/README.md +3 -3
- package/dist/commons/constants/variables.d.ts.map +1 -1
- package/dist/components/Agent/index.d.ts.map +1 -1
- package/dist/features/AgentWidget/index.d.ts +1 -0
- package/dist/features/AgentWidget/index.d.ts.map +1 -1
- package/dist/hooks/useChat.d.ts.map +1 -1
- package/dist/hooks/useChatData.d.ts +2 -3
- package/dist/hooks/useChatData.d.ts.map +1 -1
- package/dist/hooks/useConfiguration.d.ts +1 -0
- package/dist/hooks/useConfiguration.d.ts.map +1 -1
- package/dist/register.d.ts +2 -0
- package/dist/register.d.ts.map +1 -1
- package/dist/services/chat.service.d.ts +1 -1
- package/dist/services/chat.service.d.ts.map +1 -1
- package/dist/web.d.ts +1 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +1 -1
- package/dist/window.d.ts +1 -0
- package/dist/window.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/assets/common.css +115 -115
- package/src/commons/constants/variables.ts +1 -1
- package/src/components/Agent/index.tsx +5 -3
- package/src/components/Chat/Markdown.tsx +1 -1
- package/src/features/AgentWidget/index.tsx +1 -1
- package/src/hooks/useChat.ts +3 -1
- package/src/hooks/useChatData.tsx +27 -5
- package/src/hooks/useConfiguration.tsx +1 -0
- package/src/register.tsx +2 -0
- package/src/services/chat.service.ts +1 -1
- package/src/window.ts +1 -0
- package/tailwind.config.cjs +5 -5
package/dist/window.d.ts
CHANGED
package/dist/window.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../src/window.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE;QACf,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../src/window.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE;QACf,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACtC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;CACtD,CAAC;AACF,eAAO,MAAM,UAAU,UAAW,gBAAgB,GAAG;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,SAYnE,CAAC;AAEF,eAAO,MAAM,OAAO,YAEnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,OAAO,EAAE,OAAO,OAAO,CAAC;CACzB,CAAC;AAQF,eAAO,MAAM,eAAe;wBA7BM,gBAAgB,GAAG;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE;;CAgClE,CAAC;AAEH,eAAO,MAAM,wBAAwB,UAAW,WAAW,SAG1D,CAAC"}
|
package/package.json
CHANGED
package/src/assets/common.css
CHANGED
|
@@ -3,146 +3,146 @@
|
|
|
3
3
|
@tailwind utilities;
|
|
4
4
|
|
|
5
5
|
:root {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
--foreground-rgb: 0, 0, 0;
|
|
7
|
+
--background-start-rgb: 214, 219, 220;
|
|
8
|
+
--background-end-rgb: 255, 255, 255;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
@media (prefers-color-scheme: dark) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
:root {
|
|
13
|
+
--foreground-rgb: 255, 255, 255;
|
|
14
|
+
--background-start-rgb: 0, 0, 0;
|
|
15
|
+
--background-end-rgb: 0, 0, 0;
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
@layer utilities {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
.text-balance {
|
|
21
|
+
text-wrap: balance;
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
@layer base {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
26
|
+
:root {
|
|
27
|
+
--background: 0 0% 100%;
|
|
28
|
+
--foreground: 240 10% 3.9%;
|
|
29
|
+
--card: 0 0% 100%;
|
|
30
|
+
--card-foreground: 240 10% 3.9%;
|
|
31
|
+
--popover: 0 0% 100%;
|
|
32
|
+
--popover-foreground: 240 10% 3.9%;
|
|
33
|
+
--primary: 217 100% 45%;
|
|
34
|
+
--primary-foreground: 0 0% 98%;
|
|
35
|
+
--secondary: 213 100% 96%;
|
|
36
|
+
--secondary-foreground: 240 5.9% 10%;
|
|
37
|
+
--muted: 240 4.8% 95.9%;
|
|
38
|
+
--muted-foreground: 240 3.8% 46.1%;
|
|
39
|
+
--accent: 240 4.8% 95.9%;
|
|
40
|
+
--accent-foreground: 240 5.9% 10%;
|
|
41
|
+
--destructive: 0 84.2% 60.2%;
|
|
42
|
+
--destructive-foreground: 0 0% 98%;
|
|
43
|
+
--border: 214 32% 91%;
|
|
44
|
+
--input: 240 5.9% 90%;
|
|
45
|
+
--ring: 240 10% 3.9%;
|
|
46
|
+
--chart-1: 12 76% 61%;
|
|
47
|
+
--chart-2: 173 58% 39%;
|
|
48
|
+
--chart-3: 197 37% 24%;
|
|
49
|
+
--chart-4: 43 74% 66%;
|
|
50
|
+
--chart-5: 27 87% 67%;
|
|
51
|
+
--radius: 0.5rem;
|
|
52
|
+
--sidebar-background: 0 0% 98%;
|
|
53
|
+
--sidebar-foreground: 240 10% 3.9%;
|
|
54
|
+
--sidebar-primary: 240 5.9% 10%;
|
|
55
|
+
--sidebar-primary-foreground: 0 0% 98%;
|
|
56
|
+
--sidebar-accent: 240 5.9% 94%;
|
|
57
|
+
--sidebar-accent-foreground: 240 5.9% 10%;
|
|
58
|
+
--sidebar-border: 220 13% 91%;
|
|
59
|
+
--sidebar-ring: 217.2 91.2% 59.8%;
|
|
60
|
+
}
|
|
61
|
+
.dark {
|
|
62
|
+
--background: 240 10% 3.9%;
|
|
63
|
+
--foreground: 0 0% 98%;
|
|
64
|
+
--card: 240 10% 3.9%;
|
|
65
|
+
--card-foreground: 0 0% 98%;
|
|
66
|
+
--popover: 240 10% 3.9%;
|
|
67
|
+
--popover-foreground: 0 0% 98%;
|
|
68
|
+
--primary: 208.69 100% 24.18%;
|
|
69
|
+
--primary-foreground: 207 100% 96%;
|
|
70
|
+
--secondary: 240 3.7% 15.9%;
|
|
71
|
+
--secondary-foreground: 0 0% 98%;
|
|
72
|
+
--muted: 240 3.7% 15.9%;
|
|
73
|
+
--muted-foreground: 240 5% 64.9%;
|
|
74
|
+
--accent: 240 3.7% 15.9%;
|
|
75
|
+
--accent-foreground: 0 0% 98%;
|
|
76
|
+
--destructive: 0 62.8% 30.6%;
|
|
77
|
+
--destructive-foreground: 0 0% 98%;
|
|
78
|
+
--border: 240 3.7% 15.9%;
|
|
79
|
+
--input: 240 3.7% 15.9%;
|
|
80
|
+
--ring: 240 4.9% 83.9%;
|
|
81
|
+
--chart-1: 220 70% 50%;
|
|
82
|
+
--chart-2: 160 60% 45%;
|
|
83
|
+
--chart-3: 30 80% 55%;
|
|
84
|
+
--chart-4: 280 65% 60%;
|
|
85
|
+
--chart-5: 340 75% 55%;
|
|
86
|
+
--sidebar-background: 240 5.9% 10%;
|
|
87
|
+
--sidebar-foreground: 240 4.8% 95.9%;
|
|
88
|
+
--sidebar-primary: 224.3 76.3% 48%;
|
|
89
|
+
--sidebar-primary-foreground: 0 0% 100%;
|
|
90
|
+
--sidebar-accent: 240 3.7% 15.9%;
|
|
91
|
+
--sidebar-accent-foreground: 240 4.8% 95.9%;
|
|
92
|
+
--sidebar-border: 240 3.7% 15.9%;
|
|
93
|
+
--sidebar-ring: 217.2 91.2% 59.8%;
|
|
94
|
+
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
@layer base {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
* {
|
|
99
|
+
@apply border-border;
|
|
100
|
+
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
body {
|
|
103
|
+
@apply bg-background text-foreground;
|
|
104
|
+
}
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
@font-face {
|
|
107
|
+
/*font-family: "geist";*/
|
|
108
|
+
font-family: 'Be Vietnam Pro', sans-serif;
|
|
109
|
+
font-style: normal;
|
|
110
|
+
font-weight: 100 900;
|
|
111
|
+
/*src: url(/fonts/geist.woff2) format("woff2");*/
|
|
112
|
+
}
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
@font-face {
|
|
115
|
+
/*font-family: "geist-mono";*/
|
|
116
|
+
font-family: 'Be Vietnam Pro', sans-serif;
|
|
117
|
+
font-style: normal;
|
|
118
|
+
font-weight: 100 900;
|
|
119
|
+
/*src: url(/fonts/geist-mono.woff2) format("woff2");*/
|
|
120
|
+
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
.skeleton {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
* {
|
|
125
|
+
pointer-events: none !important;
|
|
126
|
+
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
*[class^='text-'] {
|
|
129
|
+
color: transparent;
|
|
130
|
+
@apply rounded-md bg-foreground/20 select-none animate-pulse;
|
|
131
|
+
}
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
.skeleton-bg {
|
|
134
|
+
@apply bg-foreground/10;
|
|
135
|
+
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
.skeleton-div {
|
|
138
|
+
@apply bg-foreground/20 animate-pulse;
|
|
139
|
+
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
.ProseMirror {
|
|
143
|
-
|
|
143
|
+
outline: none;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
.suggestion-highlight {
|
|
147
|
-
|
|
147
|
+
@apply bg-blue-200 hover:bg-blue-300 dark:hover:bg-blue-400/50 dark:text-blue-50 dark:bg-blue-500/40;
|
|
148
148
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { useChatData } from '../../hooks/useChatData';
|
|
1
2
|
import { useConfiguration } from '../../hooks/useConfiguration';
|
|
2
3
|
import { Chat } from '../Chat/Chat';
|
|
3
|
-
import { useChatData } from '../../hooks/useChatData';
|
|
4
4
|
|
|
5
5
|
const Agent = () => {
|
|
6
6
|
const { agentId } = useConfiguration();
|
|
7
|
-
const { chatId } = useChatData();
|
|
7
|
+
const { chatId, initialMessages } = useChatData();
|
|
8
8
|
|
|
9
|
-
return
|
|
9
|
+
return (
|
|
10
|
+
<Chat agentId={agentId} id={chatId} initialMessages={initialMessages} />
|
|
11
|
+
);
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
export default Agent;
|
|
@@ -164,7 +164,7 @@ const NonMemoizedMarkdown: FC<{
|
|
|
164
164
|
const { children: content, usedTools } = props;
|
|
165
165
|
const components: Partial<Components> = useMemo(() => {
|
|
166
166
|
return {
|
|
167
|
-
code: ({ node, inline, className, children, ...rest }
|
|
167
|
+
code: ({ node, inline, className, children, ...rest }: any) => {
|
|
168
168
|
const match = /language-(\w+)/.exec(className || '');
|
|
169
169
|
return !inline && match ? (
|
|
170
170
|
<pre
|
|
@@ -11,6 +11,7 @@ export type AgentWidgetType = {
|
|
|
11
11
|
agentId: string;
|
|
12
12
|
overrideConfig?: {
|
|
13
13
|
chatId?: string | undefined;
|
|
14
|
+
overrideConfig?: Record<string, unknown>;
|
|
14
15
|
} & Record<string, unknown>;
|
|
15
16
|
theme?: {
|
|
16
17
|
avatar?: string;
|
|
@@ -34,7 +35,6 @@ const AgentWidget: FC<AgentWidgetType> = (props: AgentWidgetType) => {
|
|
|
34
35
|
<ChatDataProvider
|
|
35
36
|
data={{
|
|
36
37
|
chatId: props.overrideConfig?.chatId,
|
|
37
|
-
theme: props.theme,
|
|
38
38
|
}}
|
|
39
39
|
>
|
|
40
40
|
<Agent />
|
package/src/hooks/useChat.ts
CHANGED
|
@@ -36,7 +36,7 @@ type ReturnType = {
|
|
|
36
36
|
|
|
37
37
|
export const useChat = (props: PropsType): ReturnType => {
|
|
38
38
|
const { id, initialMessages, initialInput, agentId } = props;
|
|
39
|
-
const { apiHost } = useConfiguration();
|
|
39
|
+
const { apiHost, overrideConfig } = useConfiguration();
|
|
40
40
|
|
|
41
41
|
const idKey = id ?? generateUUID();
|
|
42
42
|
const chatIdRef = useRef<string>(idKey);
|
|
@@ -162,6 +162,7 @@ export const useChat = (props: PropsType): ReturnType => {
|
|
|
162
162
|
chatId: chatIdRef.current,
|
|
163
163
|
question: message.content,
|
|
164
164
|
chatflowId: bot?.id,
|
|
165
|
+
overrideConfig: overrideConfig?.overrideConfig,
|
|
165
166
|
});
|
|
166
167
|
setInput('');
|
|
167
168
|
};
|
|
@@ -204,6 +205,7 @@ export const useChat = (props: PropsType): ReturnType => {
|
|
|
204
205
|
question: input,
|
|
205
206
|
uploads: files || [],
|
|
206
207
|
chatflowId: bot?.id,
|
|
208
|
+
overrideConfig: overrideConfig?.overrideConfig,
|
|
207
209
|
});
|
|
208
210
|
setInput('');
|
|
209
211
|
},
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React, { createContext, useEffect, useState } from 'react';
|
|
2
2
|
import { EVENT_TYPE } from '../models';
|
|
3
|
+
import { getChatMessage } from '../services/chat.service';
|
|
4
|
+
import { ChatMessageType } from '../types/flowise.type';
|
|
3
5
|
import { generateUUID } from '../utils/commonUtils';
|
|
6
|
+
import { useConfiguration } from './useConfiguration';
|
|
4
7
|
|
|
5
8
|
type ChatData = {
|
|
6
9
|
chatId?: string | undefined;
|
|
7
|
-
theme?: {
|
|
8
|
-
avatar?: string;
|
|
9
|
-
} & Record<string, unknown>;
|
|
10
10
|
listeners?: Record<EVENT_TYPE, (props: any) => void>;
|
|
11
|
+
initialMessages?: ChatMessageType[];
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
const ChatDataContext = createContext<ChatData | undefined>(undefined);
|
|
@@ -20,13 +21,34 @@ export const ChatDataProvider = ({
|
|
|
20
21
|
data: ChatData;
|
|
21
22
|
}) => {
|
|
22
23
|
const [chatData, setChatData] = useState<ChatData>({
|
|
23
|
-
chatId: generateUUID(),
|
|
24
|
+
chatId: data.chatId || generateUUID(),
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
const { apiHost } = useConfiguration();
|
|
28
|
+
|
|
29
|
+
const fetchHistory = async () => {
|
|
30
|
+
if (!chatData?.chatId) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const initialMessages = await getChatMessage({
|
|
35
|
+
chatId: chatData.chatId!,
|
|
36
|
+
apiHost,
|
|
37
|
+
});
|
|
38
|
+
setChatData({
|
|
39
|
+
...chatData,
|
|
40
|
+
initialMessages,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
26
44
|
useEffect(() => {
|
|
27
|
-
setChatData(data);
|
|
45
|
+
setChatData({ ...data, chatId: chatData.chatId });
|
|
28
46
|
}, [data]);
|
|
29
47
|
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
fetchHistory();
|
|
50
|
+
}, [chatData?.chatId]);
|
|
51
|
+
|
|
30
52
|
return (
|
|
31
53
|
<ChatDataContext.Provider value={chatData}>
|
|
32
54
|
{children}
|
package/src/register.tsx
CHANGED
|
@@ -8,6 +8,7 @@ type AgentType = {
|
|
|
8
8
|
agentId: string;
|
|
9
9
|
overrideConfig?: {
|
|
10
10
|
chatId?: string | undefined;
|
|
11
|
+
overrideConfig?: Record<string, unknown>;
|
|
11
12
|
} & Record<string, unknown>;
|
|
12
13
|
theme?: {
|
|
13
14
|
avatar?: string;
|
|
@@ -20,6 +21,7 @@ export class AgentWidgetComponent extends HTMLElement {
|
|
|
20
21
|
agentId?: string;
|
|
21
22
|
overrideConfig?: {
|
|
22
23
|
chatId?: string | undefined;
|
|
24
|
+
overrideConfig?: Record<string, unknown>;
|
|
23
25
|
} & Record<string, unknown>;
|
|
24
26
|
theme?: {
|
|
25
27
|
avatar?: string;
|
package/src/window.ts
CHANGED
package/tailwind.config.cjs
CHANGED
|
@@ -99,11 +99,11 @@ module.exports = {
|
|
|
99
99
|
input: 'hsl(var(--input))',
|
|
100
100
|
ring: 'hsl(var(--ring))',
|
|
101
101
|
chart: {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
1: 'hsl(var(--chart-1))',
|
|
103
|
+
2: 'hsl(var(--chart-2))',
|
|
104
|
+
3: 'hsl(var(--chart-3))',
|
|
105
|
+
4: 'hsl(var(--chart-4))',
|
|
106
|
+
5: 'hsl(var(--chart-5))',
|
|
107
107
|
},
|
|
108
108
|
sidebar: {
|
|
109
109
|
DEFAULT: 'hsl(var(--sidebar-background))',
|