@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/dist/window.d.ts CHANGED
@@ -4,6 +4,7 @@ type VoiceAgentWidget = {
4
4
  agentId: string;
5
5
  overrideConfig?: {
6
6
  chatId?: string | undefined;
7
+ overrideConfig?: Record<string, any>;
7
8
  } & Record<string, unknown>;
8
9
  theme?: {
9
10
  avatar?: string;
@@ -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;KAC7B,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"}
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clikvn/agent-widget-embedded",
3
3
  "description": "This is agent widget",
4
- "version": "0.0.1",
4
+ "version": "0.0.2-dev",
5
5
  "author": "Clik JSC",
6
6
  "license": "ISC",
7
7
  "type": "module",
@@ -3,146 +3,146 @@
3
3
  @tailwind utilities;
4
4
 
5
5
  :root {
6
- --foreground-rgb: 0, 0, 0;
7
- --background-start-rgb: 214, 219, 220;
8
- --background-end-rgb: 255, 255, 255;
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
- :root {
13
- --foreground-rgb: 255, 255, 255;
14
- --background-start-rgb: 0, 0, 0;
15
- --background-end-rgb: 0, 0, 0;
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
- .text-balance {
21
- text-wrap: balance;
22
- }
20
+ .text-balance {
21
+ text-wrap: balance;
22
+ }
23
23
  }
24
24
 
25
25
  @layer base {
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
- }
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
- @apply border-border;
100
- }
98
+ * {
99
+ @apply border-border;
100
+ }
101
101
 
102
- body {
103
- @apply bg-background text-foreground;
104
- }
102
+ body {
103
+ @apply bg-background text-foreground;
104
+ }
105
105
 
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
- }
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
- @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
- }
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
- pointer-events: none !important;
126
- }
124
+ * {
125
+ pointer-events: none !important;
126
+ }
127
127
 
128
- *[class^="text-"] {
129
- color: transparent;
130
- @apply rounded-md bg-foreground/20 select-none animate-pulse;
131
- }
128
+ *[class^='text-'] {
129
+ color: transparent;
130
+ @apply rounded-md bg-foreground/20 select-none animate-pulse;
131
+ }
132
132
 
133
- .skeleton-bg {
134
- @apply bg-foreground/10;
135
- }
133
+ .skeleton-bg {
134
+ @apply bg-foreground/10;
135
+ }
136
136
 
137
- .skeleton-div {
138
- @apply bg-foreground/20 animate-pulse;
139
- }
137
+ .skeleton-div {
138
+ @apply bg-foreground/20 animate-pulse;
139
+ }
140
140
  }
141
141
 
142
142
  .ProseMirror {
143
- outline: none;
143
+ outline: none;
144
144
  }
145
145
 
146
146
  .suggestion-highlight {
147
- @apply bg-blue-200 hover:bg-blue-300 dark:hover:bg-blue-400/50 dark:text-blue-50 dark:bg-blue-500/40;
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,6 +1,6 @@
1
1
  export const BE_API = '';
2
2
 
3
- export const LANGUAGE_HEADER: {[key: string]: string} = {
3
+ export const LANGUAGE_HEADER: { [key: string]: string } = {
4
4
  vi: 'vn',
5
5
  en: 'en',
6
6
  jp: 'jp',
@@ -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 <Chat agentId={agentId} id={chatId} />;
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 } : any) => {
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 />
@@ -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}
@@ -6,6 +6,7 @@ type ConfigurationData = {
6
6
  agentId: string;
7
7
  overrideConfig?: {
8
8
  chatId?: string | undefined;
9
+ overrideConfig?: Record<string, any>;
9
10
  } & Record<string, unknown>;
10
11
  theme?: {
11
12
  avatar?: string;
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;
@@ -139,7 +139,7 @@ export const createAttachments = async ({
139
139
  export const getById = async ({
140
140
  accessToken,
141
141
  id,
142
- apiHost
142
+ apiHost,
143
143
  }: {
144
144
  accessToken?: string;
145
145
  id: string;
package/src/window.ts CHANGED
@@ -9,6 +9,7 @@ type VoiceAgentWidget = {
9
9
  agentId: string;
10
10
  overrideConfig?: {
11
11
  chatId?: string | undefined;
12
+ overrideConfig?: Record<string, any>;
12
13
  } & Record<string, unknown>;
13
14
  theme?: {
14
15
  avatar?: string;
@@ -99,11 +99,11 @@ module.exports = {
99
99
  input: 'hsl(var(--input))',
100
100
  ring: 'hsl(var(--ring))',
101
101
  chart: {
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))',
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))',