@clikvn/agent-widget-embedded 0.0.10-dev → 0.0.12-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.
Files changed (73) hide show
  1. package/dist/commons/constants/variables.d.ts +4 -0
  2. package/dist/commons/constants/variables.d.ts.map +1 -1
  3. package/dist/components/Chat/Icons.d.ts +19 -1
  4. package/dist/components/Chat/Icons.d.ts.map +1 -1
  5. package/dist/components/Chat/Message.d.ts.map +1 -1
  6. package/dist/components/Chat/MultimodalInput.d.ts +1 -1
  7. package/dist/components/Chat/MultimodalInput.d.ts.map +1 -1
  8. package/dist/components/Chat/SuggestedActions.d.ts +12 -0
  9. package/dist/components/Chat/SuggestedActions.d.ts.map +1 -0
  10. package/dist/features/AgentWidget/index.d.ts +8 -2
  11. package/dist/features/AgentWidget/index.d.ts.map +1 -1
  12. package/dist/hooks/useConfiguration.d.ts +8 -1
  13. package/dist/hooks/useConfiguration.d.ts.map +1 -1
  14. package/dist/index.html +45 -44
  15. package/dist/types/common.type.d.ts +6 -0
  16. package/dist/types/common.type.d.ts.map +1 -1
  17. package/dist/web.js +1 -1
  18. package/package.json +3 -2
  19. package/.eslintrc +0 -34
  20. package/.prettierrc +0 -8
  21. package/dist/components/Chat/AudioRecording.d.ts +0 -9
  22. package/dist/components/Chat/AudioRecording.d.ts.map +0 -1
  23. package/dist/hooks/useConnection.d.ts +0 -15
  24. package/dist/hooks/useConnection.d.ts.map +0 -1
  25. package/dist/services/user.service.d.ts +0 -3
  26. package/dist/services/user.service.d.ts.map +0 -1
  27. package/dist/types/agentType.d.ts +0 -11
  28. package/dist/types/agentType.d.ts.map +0 -1
  29. package/src/assets/common.css +0 -148
  30. package/src/assets/tailwindcss.css +0 -3
  31. package/src/commons/constants/index.ts +0 -1
  32. package/src/commons/constants/variables.ts +0 -20
  33. package/src/components/Agent/index.tsx +0 -14
  34. package/src/components/Chat/AudioPlayer.tsx +0 -44
  35. package/src/components/Chat/Chat.tsx +0 -91
  36. package/src/components/Chat/Icons.tsx +0 -930
  37. package/src/components/Chat/Markdown.tsx +0 -335
  38. package/src/components/Chat/Message.tsx +0 -191
  39. package/src/components/Chat/MultimodalInput.tsx +0 -479
  40. package/src/components/Chat/Overview.tsx +0 -46
  41. package/src/components/Chat/PreviewAttachment.tsx +0 -46
  42. package/src/components/Chat/ui/Button.tsx +0 -55
  43. package/src/components/Chat/ui/Textarea.tsx +0 -23
  44. package/src/constants.ts +0 -1
  45. package/src/env.d.ts +0 -10
  46. package/src/features/AgentWidget/index.tsx +0 -57
  47. package/src/global.d.ts +0 -1
  48. package/src/hooks/useAudioRecording.ts +0 -50
  49. package/src/hooks/useChat.ts +0 -262
  50. package/src/hooks/useChatData.tsx +0 -68
  51. package/src/hooks/useConfiguration.tsx +0 -56
  52. package/src/hooks/useScrollToBottom.ts +0 -31
  53. package/src/index.ts +0 -1
  54. package/src/models/FlowiseClient.ts +0 -103
  55. package/src/models.ts +0 -1
  56. package/src/register.tsx +0 -85
  57. package/src/services/apis.ts +0 -12
  58. package/src/services/bot.service.ts +0 -15
  59. package/src/services/chat.service.ts +0 -199
  60. package/src/types/bot.type.ts +0 -10
  61. package/src/types/chat.type.ts +0 -11
  62. package/src/types/common.type.ts +0 -17
  63. package/src/types/flowise.type.ts +0 -108
  64. package/src/types/user.type.ts +0 -15
  65. package/src/types.ts +0 -0
  66. package/src/utils/audioRecording.ts +0 -371
  67. package/src/utils/commonUtils.ts +0 -47
  68. package/src/utils/functionUtils.ts +0 -17
  69. package/src/utils/requestUtils.ts +0 -113
  70. package/src/utils/streamUtils.ts +0 -18
  71. package/src/web.ts +0 -6
  72. package/src/window.ts +0 -43
  73. package/tsconfig.json +0 -24
package/src/register.tsx DELETED
@@ -1,85 +0,0 @@
1
- import { agentWidgetElementName } from './constants';
2
- import * as ReactDom from 'react-dom';
3
- import AgentWidget from './features/AgentWidget';
4
- import { EVENT_TYPE } from './models';
5
- import { SuggestionType } from './types/common.type';
6
-
7
- export type AgentWidgetType = {
8
- apiHost: string;
9
- agentId: string;
10
- overrideConfig?: {
11
- chatId?: string | undefined;
12
- overrideConfig?: Record<string, unknown>;
13
- suggestedActions?: SuggestionType[];
14
- } & Record<string, unknown>;
15
- theme?: {
16
- avatar?: string;
17
- input?: {
18
- placeholder?: string;
19
- };
20
- overview?: {
21
- title: string;
22
- description?: string;
23
- };
24
- } & Record<string, unknown>;
25
- listeners?: Record<EVENT_TYPE, (props: any) => void>;
26
- };
27
-
28
- export class AgentWidgetComponent extends HTMLElement {
29
- apiHost?: string;
30
- agentId?: string;
31
- overrideConfig?: {
32
- chatId?: string | undefined;
33
- overrideConfig?: Record<string, unknown>;
34
- suggestedActions?: SuggestionType[];
35
- } & Record<string, unknown>;
36
- theme?: {
37
- avatar?: string;
38
- input?: {
39
- placeholder?: string;
40
- };
41
- overview?: {
42
- title: string;
43
- description?: string;
44
- };
45
- } & Record<string, unknown>;
46
- listeners?: Record<EVENT_TYPE, (props: any) => void>;
47
- constructor() {
48
- super();
49
- this.updateAttributes = this.updateAttributes.bind(this);
50
- }
51
-
52
- updateAttributes(attributes: AgentWidgetType) {
53
- this.apiHost = attributes.apiHost;
54
- this.agentId = attributes.agentId;
55
- this.overrideConfig = attributes.overrideConfig;
56
- this.listeners = attributes.listeners;
57
- this.theme = attributes.theme;
58
- this.render();
59
- }
60
-
61
- connectedCallback() {
62
- if (this.apiHost) {
63
- this.render();
64
- }
65
- }
66
-
67
- render() {
68
- ReactDom.render(
69
- <AgentWidget
70
- apiHost={this.apiHost || ''}
71
- agentId={this.agentId || ''}
72
- overrideConfig={this.overrideConfig}
73
- listeners={this.listeners}
74
- theme={this.theme}
75
- />,
76
- this
77
- );
78
- }
79
- }
80
- export const registerWebComponents = () => {
81
- if (typeof window === 'undefined') return;
82
- if (!customElements.get(agentWidgetElementName)) {
83
- customElements.define(agentWidgetElementName, AgentWidgetComponent);
84
- }
85
- };
@@ -1,12 +0,0 @@
1
- export const API_VERSION = '/ext/v1';
2
- export const API_CHATS = `/chats`;
3
-
4
- export const API_CHAT_MESSAGE = `${API_CHATS}/chatmessage`;
5
-
6
- export const API_PREDICTION = `${API_CHATS}/prediction`;
7
-
8
- export const API_CHATBOTS = `${API_VERSION}/bots`;
9
-
10
- export const API_CREATE_ATTACHMENTS = `${API_CHATS}/attachments`;
11
-
12
- export const API_SUGGESTIONS = `${API_CHATS}/suggestions`;
@@ -1,15 +0,0 @@
1
- import { API_CHATBOTS } from './apis';
2
- import { BotType } from '../types/bot.type';
3
- import { request } from '../utils/requestUtils';
4
-
5
- export const getBot = async (id: string, apiHost: string): Promise<BotType> => {
6
- const headers = {
7
- 'Content-Type': 'application/json',
8
- };
9
-
10
- return request({
11
- host: apiHost,
12
- url: `${API_CHATBOTS}/${id}`,
13
- headers,
14
- });
15
- };
@@ -1,199 +0,0 @@
1
- import FlowiseClient, { StreamResponse } from '../models/FlowiseClient';
2
- import {
3
- API_CHAT_MESSAGE,
4
- API_CHATS,
5
- API_CREATE_ATTACHMENTS,
6
- API_PREDICTION,
7
- API_SUGGESTIONS,
8
- API_VERSION,
9
- } from './apis';
10
- import { ChatRequestType, ChatType } from '../types/chat.type';
11
- import { CommonChatType, SuggestionType } from '../types/common.type';
12
- import {
13
- AttachmentUploadResult,
14
- ChatMessageType,
15
- PredictionData,
16
- } from '../types/flowise.type';
17
- import { request } from '../utils/requestUtils';
18
-
19
- export const createChat = async ({
20
- accessToken,
21
- req,
22
- apiHost,
23
- }: {
24
- accessToken?: string;
25
- req: ChatRequestType;
26
- apiHost: string;
27
- }): Promise<ChatType> => {
28
- const url = accessToken ? `${API_CHATS}` : `${API_VERSION}${API_CHATS}`;
29
- let headers: any = {
30
- 'Content-Type': 'application/json',
31
- };
32
- if (accessToken) {
33
- headers = {
34
- ...headers,
35
- Authorization: `Bearer ${accessToken}`,
36
- };
37
- }
38
-
39
- return request({
40
- host: apiHost,
41
- url,
42
- headers,
43
- method: 'POST',
44
- body: JSON.stringify(req),
45
- });
46
- };
47
-
48
- export const predict = async ({
49
- accessToken,
50
- req,
51
- onUpdate,
52
- apiHost,
53
- }: {
54
- accessToken?: string;
55
- req: PredictionData;
56
- apiHost: string;
57
- onUpdate?: (chunk: StreamResponse) => void;
58
- }): Promise<StreamResponse[]> => {
59
- const url = accessToken
60
- ? `${API_PREDICTION}`
61
- : `${API_VERSION}${API_PREDICTION}`;
62
- const result: any[] = [];
63
- const flowise = new FlowiseClient({
64
- baseUrl: url,
65
- accessToken: accessToken,
66
- host: apiHost,
67
- });
68
-
69
- try {
70
- const completion: any = await flowise.createPrediction(req);
71
- for await (const chunk of completion) {
72
- result.push(chunk);
73
- onUpdate?.(chunk);
74
- }
75
- } catch (error) {
76
- console.error('Error:', error);
77
- }
78
-
79
- return result;
80
- };
81
-
82
- export const getChatMessage = async ({
83
- accessToken,
84
- chatId,
85
- apiHost,
86
- }: {
87
- accessToken?: string;
88
- chatId: string;
89
- apiHost: string;
90
- }): Promise<ChatMessageType[]> => {
91
- const headers = accessToken
92
- ? {
93
- Authorization: `Bearer ${accessToken}`,
94
- 'Content-Type': 'application/json',
95
- }
96
- : {};
97
-
98
- const url = accessToken
99
- ? `${API_CHAT_MESSAGE}/${chatId}`
100
- : `${API_VERSION}${API_CHAT_MESSAGE}/${chatId}`;
101
-
102
- return request({
103
- host: apiHost,
104
- url,
105
- headers,
106
- method: 'GET',
107
- });
108
- };
109
-
110
- export const createAttachments = async ({
111
- accessToken,
112
- chatId,
113
- body,
114
- apiHost,
115
- }: {
116
- accessToken?: string;
117
- chatId: string;
118
- apiHost: string;
119
- body: any;
120
- }): Promise<AttachmentUploadResult[]> => {
121
- const headers = accessToken
122
- ? {
123
- Authorization: `Bearer ${accessToken}`,
124
- // 'Content-Type': 'application/json',
125
- }
126
- : {};
127
- const url = accessToken
128
- ? `${API_CREATE_ATTACHMENTS}/${chatId}`
129
- : `${API_VERSION}${API_CREATE_ATTACHMENTS}/${chatId}`;
130
-
131
- return request({
132
- host: apiHost,
133
- url,
134
- headers,
135
- method: 'POST',
136
- body,
137
- });
138
- };
139
-
140
- export const getById = async ({
141
- accessToken,
142
- id,
143
- apiHost,
144
- }: {
145
- accessToken?: string;
146
- id: string;
147
- apiHost: string;
148
- }): Promise<CommonChatType> => {
149
- const headers = accessToken
150
- ? {
151
- Authorization: `Bearer ${accessToken}`,
152
- 'Content-Type': 'application/json',
153
- }
154
- : {};
155
- const url = accessToken
156
- ? `${API_CHATS}/${id}`
157
- : `${API_VERSION}${API_CHATS}/${id}`;
158
-
159
- return request({
160
- host: apiHost,
161
- url,
162
- headers,
163
- method: 'GET',
164
- });
165
- };
166
-
167
- export const getSuggestions = async ({
168
- accessToken,
169
- id,
170
- question,
171
- apiHost
172
- }: {
173
- accessToken?: string;
174
- id: string;
175
- question?: string;
176
- apiHost: string;
177
- }): Promise<SuggestionType[]> => {
178
- const headers = accessToken
179
- ? {
180
- Authorization: `Bearer ${accessToken}`,
181
- 'Content-Type': 'application/json',
182
- }
183
- : {};
184
- const url = accessToken
185
- ? `${API_SUGGESTIONS}/${id}`
186
- : `${API_VERSION}${API_SUGGESTIONS}/${id}`;
187
- const req = {
188
- question
189
- }
190
- const formData = new FormData();
191
- formData.append('question', `${question}`);
192
- return request({
193
- host: apiHost,
194
- url,
195
- headers,
196
- method: 'POST',
197
- body: formData,
198
- });
199
- };
@@ -1,10 +0,0 @@
1
- export interface BotType {
2
- id: string;
3
- created: string;
4
- lastModifiedDate: string;
5
- name: string;
6
- chatflowId: string;
7
- chatflowConfig: any;
8
- hidden: boolean;
9
- avatar: string;
10
- }
@@ -1,11 +0,0 @@
1
- import { CommonChatType } from './common.type';
2
- import { UserType } from './user.type';
3
-
4
- export interface ChatType extends CommonChatType {
5
- user: UserType;
6
- }
7
-
8
- export interface ChatRequestType {
9
- title: string;
10
- chatflowId?: string;
11
- }
@@ -1,17 +0,0 @@
1
- import { BotType } from './bot.type';
2
-
3
- export interface CommonChatType {
4
- id: string;
5
- created?: Date;
6
- lastModifiedDate?: Date;
7
- title: string;
8
- chatflowId: string;
9
- type: 'PRIVATE' | 'ANONYMOUS';
10
- bot: BotType;
11
- }
12
-
13
- export interface SuggestionType {
14
- title?: string;
15
- label?: string;
16
- action?: string;
17
- }
@@ -1,108 +0,0 @@
1
- export type MessageRoleType = 'apiMessage' | 'userMessage';
2
-
3
- export interface PredictionData {
4
- chatflowId?: string;
5
- question: string;
6
- overrideConfig?: Record<string, any>;
7
- chatId?: string;
8
- streaming?: boolean;
9
- history?: IMessage[];
10
- uploads?: IFileUpload[];
11
- leadEmail?: string;
12
- action?: IAction;
13
- language?: string;
14
- tts?: boolean;
15
- }
16
-
17
- export interface ChatMessageType {
18
- action?: IAction;
19
- artifacts?: any;
20
- chatId?: string;
21
- chatType?: string;
22
- chatflowid?: string;
23
- content?: string;
24
- createdDate?: string | Date;
25
- followUpPrompts?: any;
26
- id?: string;
27
- leadEmail?: string;
28
- role: MessageRoleType;
29
- sessionId?: string;
30
- usedTools?: ToolUsage[];
31
- sourceDocuments?: SourceDocument[];
32
- fileUploads?: IFileUpload[];
33
- fileAnnotations?: FileAnnotation[];
34
- agentReasoning?: AgentReasoning[];
35
- metaData?: ChatMessageMetadataType;
36
- ttsUrl?: string;
37
- }
38
-
39
- export interface ChatMessageMetadataType {
40
- chatId: string;
41
- chatMessageId?: string;
42
- question?: string;
43
- }
44
-
45
- export interface IAction {
46
- id?: string;
47
- elements?: Array<{
48
- type: string;
49
- label: string;
50
- }>;
51
- mapping?: {
52
- approve: string;
53
- reject: string;
54
- toolCalls: any[];
55
- };
56
- }
57
-
58
- export interface IFileUpload {
59
- tempId?: string;
60
- data?: string;
61
- type: string;
62
- name: string;
63
- mime: string;
64
- }
65
-
66
- export interface IMessage {
67
- message: string;
68
- type: MessageRoleType;
69
- role?: MessageRoleType;
70
- content?: string;
71
- }
72
-
73
- export interface ToolUsage {
74
- tool: string;
75
- toolInput: {
76
- input: string;
77
- };
78
- toolOutput: string;
79
- }
80
-
81
- export interface SourceDocument {
82
- pageContent: string;
83
- metadata: {
84
- author: string;
85
- date: string;
86
- };
87
- }
88
-
89
- export interface AgentReasoning {
90
- agentName: string;
91
- messages: string[];
92
- nodeName: string;
93
- nodeId: string;
94
- usedTools: ToolUsage[];
95
- sourceDocuments: SourceDocument[];
96
- }
97
-
98
- export interface FileAnnotation {
99
- filePath: string;
100
- fileName: string;
101
- }
102
-
103
- export interface AttachmentUploadResult {
104
- name: string;
105
- mimeType: string;
106
- size: string;
107
- content: string;
108
- }
@@ -1,15 +0,0 @@
1
- import { CommonChatType } from './common.type';
2
-
3
- export interface UserType {
4
- id: string;
5
- created?: Date;
6
- lastModifiedDate?: Date;
7
- phoneNumber?: string;
8
- name?: string;
9
- email: string;
10
- userClik: number;
11
- chats?: CommonChatType[];
12
-
13
- user?: number;
14
- authorities?: string[];
15
- }
package/src/types.ts DELETED
File without changes