@clikvn/agent-widget-embedded 0.0.11-dev → 0.0.13-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 (53) hide show
  1. package/dist/components/Chat/MultimodalInput.d.ts.map +1 -1
  2. package/dist/index.html +52 -12
  3. package/dist/web.js +1 -1
  4. package/package.json +23 -19
  5. package/rollup.config.js +1 -0
  6. package/.eslintrc +0 -34
  7. package/.prettierrc +0 -8
  8. package/src/assets/common.css +0 -148
  9. package/src/assets/tailwindcss.css +0 -3
  10. package/src/commons/constants/index.ts +0 -1
  11. package/src/commons/constants/variables.ts +0 -25
  12. package/src/components/Agent/index.tsx +0 -14
  13. package/src/components/Chat/AudioPlayer.tsx +0 -44
  14. package/src/components/Chat/Chat.tsx +0 -91
  15. package/src/components/Chat/Icons.tsx +0 -1796
  16. package/src/components/Chat/Markdown.tsx +0 -335
  17. package/src/components/Chat/Message.tsx +0 -217
  18. package/src/components/Chat/MultimodalInput.tsx +0 -505
  19. package/src/components/Chat/Overview.tsx +0 -46
  20. package/src/components/Chat/PreviewAttachment.tsx +0 -46
  21. package/src/components/Chat/SuggestedActions.tsx +0 -99
  22. package/src/components/Chat/ui/Button.tsx +0 -55
  23. package/src/components/Chat/ui/Textarea.tsx +0 -23
  24. package/src/constants.ts +0 -1
  25. package/src/env.d.ts +0 -10
  26. package/src/features/AgentWidget/index.tsx +0 -63
  27. package/src/global.d.ts +0 -1
  28. package/src/hooks/useAudioRecording.ts +0 -50
  29. package/src/hooks/useChat.ts +0 -262
  30. package/src/hooks/useChatData.tsx +0 -68
  31. package/src/hooks/useConfiguration.tsx +0 -63
  32. package/src/hooks/useScrollToBottom.ts +0 -31
  33. package/src/index.ts +0 -1
  34. package/src/models/FlowiseClient.ts +0 -103
  35. package/src/models.ts +0 -1
  36. package/src/register.tsx +0 -85
  37. package/src/services/apis.ts +0 -12
  38. package/src/services/bot.service.ts +0 -15
  39. package/src/services/chat.service.ts +0 -199
  40. package/src/types/bot.type.ts +0 -10
  41. package/src/types/chat.type.ts +0 -11
  42. package/src/types/common.type.ts +0 -24
  43. package/src/types/flowise.type.ts +0 -108
  44. package/src/types/user.type.ts +0 -15
  45. package/src/types.ts +0 -0
  46. package/src/utils/audioRecording.ts +0 -371
  47. package/src/utils/commonUtils.ts +0 -47
  48. package/src/utils/functionUtils.ts +0 -17
  49. package/src/utils/requestUtils.ts +0 -113
  50. package/src/utils/streamUtils.ts +0 -18
  51. package/src/web.ts +0 -6
  52. package/src/window.ts +0 -43
  53. package/tsconfig.json +0 -24
@@ -1,103 +0,0 @@
1
- import { PredictionData } from '../types/flowise.type';
2
- import { BE_API, LANGUAGE_HEADER } from '../commons/constants';
3
-
4
- interface FlowiseClientOptions {
5
- baseUrl: string;
6
- accessToken?: string;
7
- host?: string;
8
- }
9
-
10
- export interface StreamResponse {
11
- event: string;
12
- data: unknown;
13
- }
14
-
15
- type PredictionResponse<T extends PredictionData> = T['streaming'] extends true
16
- ? AsyncGenerator<StreamResponse, void, unknown> // Streaming returns an async generator
17
- : Record<string, any>;
18
-
19
- export default class FlowiseClient {
20
- private baseUrl: string;
21
- private accessToken: string | undefined;
22
- private host: string | undefined;
23
-
24
- constructor(options: FlowiseClientOptions) {
25
- this.baseUrl = options.baseUrl;
26
- this.accessToken = options.accessToken || '';
27
- this.host = options.host || BE_API;
28
- }
29
-
30
- // Method to create a new prediction and handle streaming response
31
- async createPrediction<T extends PredictionData>(
32
- data: T
33
- ): Promise<PredictionResponse<T>> {
34
- const { chatId, streaming = true, language } = data;
35
-
36
- const predictionUrl = `${this.host}${this.baseUrl}/${chatId}`;
37
- let apiLanguage: string = LANGUAGE_HEADER.en;
38
- if (language) {
39
- apiLanguage = LANGUAGE_HEADER[language];
40
- }
41
-
42
- const options: any = {
43
- method: 'POST',
44
- headers: {
45
- 'Content-Type': 'application/json',
46
- },
47
- body: JSON.stringify(data),
48
- language: apiLanguage,
49
- };
50
-
51
- if (this.accessToken) {
52
- options.headers['Authorization'] = `Bearer ${this.accessToken}`;
53
- }
54
-
55
- if (streaming) {
56
- return {
57
- async *[Symbol.asyncIterator]() {
58
- const response = await fetch(predictionUrl, options);
59
-
60
- if (!response.ok) {
61
- throw new Error(`HTTP error! status: ${response.status}`);
62
- }
63
-
64
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
- // @ts-ignore
66
- const reader = response.body.getReader();
67
- const decoder = new TextDecoder();
68
- let buffer = '';
69
-
70
- try {
71
- while (true) {
72
- const { done, value } = await reader.read();
73
- if (done) break;
74
-
75
- buffer += decoder.decode(value, { stream: true });
76
- const lines = buffer.split('\n');
77
- buffer = lines.pop() || '';
78
-
79
- for (const line of lines) {
80
- if (line.trim() === '') continue;
81
- if (line.startsWith('data:')) {
82
- const stringifiedJson = line.replace('data:', '');
83
- const event = JSON.parse(stringifiedJson);
84
- yield event;
85
- }
86
- }
87
- }
88
- } finally {
89
- reader.releaseLock();
90
- }
91
- },
92
- } as unknown as Promise<PredictionResponse<T>>;
93
- } else {
94
- try {
95
- const response = await fetch(predictionUrl, options);
96
- const resp = await response.json();
97
- return resp as Promise<PredictionResponse<T>>;
98
- } catch (error) {
99
- throw new Error('Error creating prediction');
100
- }
101
- }
102
- }
103
- }
package/src/models.ts DELETED
@@ -1 +0,0 @@
1
- export type EVENT_TYPE = 'CONNECT' | 'DISCONNECT';
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,24 +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
- }
18
-
19
- export interface ConfigMessageType {
20
- backgroundColor?: string;
21
- textColor?: string;
22
- showAvatar?: boolean;
23
- avatarSrc?: string;
24
- }
@@ -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