open-chat-studio-widget 0.4.7 → 0.5.0
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 +23 -20
- package/dist/cjs/app-globals-V2Kpy_OQ.js +8 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js.map +1 -0
- package/dist/cjs/{index-c9203be6.js → index-CC3Krx2K.js} +331 -238
- package/dist/cjs/index-CC3Krx2K.js.map +1 -0
- package/dist/cjs/index.cjs.js +1 -0
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +4 -5
- package/dist/cjs/loader.cjs.js.map +1 -1
- package/dist/cjs/open-chat-studio-widget.cjs.entry.js +5124 -4272
- package/dist/cjs/open-chat-studio-widget.cjs.entry.js.map +1 -1
- package/dist/cjs/open-chat-studio-widget.cjs.js +8 -7
- package/dist/cjs/open-chat-studio-widget.cjs.js.map +1 -1
- package/dist/cjs/open-chat-studio-widget.entry.cjs.js.map +1 -0
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/ocs-chat/{heroicons.js → icons.js} +23 -1
- package/dist/collection/components/ocs-chat/icons.js.map +1 -0
- package/dist/collection/components/ocs-chat/ocs-chat.css +596 -1947
- package/dist/collection/components/ocs-chat/ocs-chat.js +521 -293
- package/dist/collection/components/ocs-chat/ocs-chat.js.map +1 -1
- package/dist/collection/services/chat-session-service.js +145 -0
- package/dist/collection/services/chat-session-service.js.map +1 -0
- package/dist/collection/services/file-attachment-manager.js +125 -0
- package/dist/collection/services/file-attachment-manager.js.map +1 -0
- package/dist/collection/utils/cookies.js +5 -12
- package/dist/collection/utils/cookies.js.map +1 -1
- package/dist/collection/utils/markdown.js +1 -1
- package/dist/collection/utils/markdown.js.map +1 -1
- package/dist/collection/utils/translations.js +99 -0
- package/dist/collection/utils/translations.js.map +1 -0
- package/dist/components/index.js +2 -1
- package/dist/components/open-chat-studio-widget.js +5125 -4266
- package/dist/components/open-chat-studio-widget.js.map +1 -1
- package/dist/esm/app-globals-DQuL1Twl.js +6 -0
- package/dist/esm/app-globals-DQuL1Twl.js.map +1 -0
- package/dist/esm/{index-0349ca51.js → index-BF7CYZiN.js} +329 -217
- package/dist/esm/index-BF7CYZiN.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loader.js +5 -4
- package/dist/esm/loader.js.map +1 -1
- package/dist/esm/open-chat-studio-widget.entry.js +5125 -4271
- package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
- package/dist/esm/open-chat-studio-widget.js +7 -5
- package/dist/esm/open-chat-studio-widget.js.map +1 -1
- package/dist/open-chat-studio-widget/index.esm.js.map +1 -1
- package/dist/open-chat-studio-widget/loader.esm.js.map +1 -0
- package/dist/open-chat-studio-widget/open-chat-studio-widget.entry.esm.js.map +1 -0
- package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
- package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js.map +1 -1
- package/dist/open-chat-studio-widget/p-400b1f47.entry.js +4 -0
- package/dist/open-chat-studio-widget/p-400b1f47.entry.js.map +1 -0
- package/dist/open-chat-studio-widget/p-BF7CYZiN.js +3 -0
- package/dist/open-chat-studio-widget/p-BF7CYZiN.js.map +1 -0
- package/dist/open-chat-studio-widget/p-DQuL1Twl.js +2 -0
- package/dist/open-chat-studio-widget/p-DQuL1Twl.js.map +1 -0
- package/dist/types/components/ocs-chat/{heroicons.d.ts → icons.d.ts} +19 -0
- package/dist/types/components/ocs-chat/ocs-chat.d.ts +57 -36
- package/dist/types/components.d.ts +36 -2
- package/dist/types/services/chat-session-service.d.ts +78 -0
- package/dist/types/services/file-attachment-manager.d.ts +40 -0
- package/dist/types/stencil-public-runtime.d.ts +35 -6
- package/dist/types/utils/translations.d.ts +23 -0
- package/package.json +9 -4
- package/dist/cjs/app-globals-3a1e7e63.js +0 -7
- package/dist/cjs/app-globals-3a1e7e63.js.map +0 -1
- package/dist/cjs/index-c9203be6.js.map +0 -1
- package/dist/collection/components/ocs-chat/heroicons.js.map +0 -1
- package/dist/esm/app-globals-0f993ce5.js +0 -5
- package/dist/esm/app-globals-0f993ce5.js.map +0 -1
- package/dist/esm/index-0349ca51.js.map +0 -1
- package/dist/open-chat-studio-widget/p-3dc66a9a.js +0 -3
- package/dist/open-chat-studio-widget/p-3dc66a9a.js.map +0 -1
- package/dist/open-chat-studio-widget/p-6b9a332c.entry.js +0 -4
- package/dist/open-chat-studio-widget/p-6b9a332c.entry.js.map +0 -1
- package/dist/open-chat-studio-widget/p-e1255160.js +0 -2
- package/dist/open-chat-studio-widget/p-e1255160.js.map +0 -1
- package/loader/package.json +0 -11
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
content: string;
|
|
5
|
-
metadata?: any;
|
|
6
|
-
attachments?: ChatAttachment[];
|
|
7
|
-
}
|
|
8
|
-
interface ChatAttachment {
|
|
9
|
-
name: string;
|
|
10
|
-
content_type: string;
|
|
11
|
-
size: number;
|
|
12
|
-
}
|
|
13
|
-
interface UploadedFile {
|
|
14
|
-
id: number;
|
|
15
|
-
name: string;
|
|
16
|
-
size: number;
|
|
17
|
-
content_type: string;
|
|
18
|
-
}
|
|
19
|
-
interface SelectedFile {
|
|
20
|
-
file: File;
|
|
21
|
-
uploaded?: UploadedFile;
|
|
22
|
-
error?: string;
|
|
23
|
-
}
|
|
1
|
+
import { TranslationManager } from '../../utils/translations';
|
|
2
|
+
import { ChatMessage } from '../../services/chat-session-service';
|
|
3
|
+
import { SelectedFile } from '../../services/file-attachment-manager';
|
|
24
4
|
export declare class OcsChat {
|
|
25
5
|
private static readonly TASK_POLLING_MAX_ATTEMPTS;
|
|
26
6
|
private static readonly TASK_POLLING_INTERVAL_MS;
|
|
@@ -38,7 +18,7 @@ export declare class OcsChat {
|
|
|
38
18
|
*/
|
|
39
19
|
chatbotId: string;
|
|
40
20
|
/**
|
|
41
|
-
* The base URL for the API
|
|
21
|
+
* The base URL for the API.
|
|
42
22
|
*/
|
|
43
23
|
apiBaseUrl?: string;
|
|
44
24
|
/**
|
|
@@ -49,6 +29,10 @@ export declare class OcsChat {
|
|
|
49
29
|
* URL of the icon to display on the button. If not provided, uses the default OCS logo.
|
|
50
30
|
*/
|
|
51
31
|
iconUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Authentication key for embedded channels
|
|
34
|
+
*/
|
|
35
|
+
embedKey?: string;
|
|
52
36
|
/**
|
|
53
37
|
* The shape of the chat button. 'round' makes it circular, 'square' keeps it rectangular.
|
|
54
38
|
*/
|
|
@@ -106,6 +90,11 @@ export declare class OcsChat {
|
|
|
106
90
|
* The text to display while the assistant is typing/preparing a response.
|
|
107
91
|
*/
|
|
108
92
|
typingIndicatorText?: string;
|
|
93
|
+
/**
|
|
94
|
+
* The language code for the widget UI (e.g., 'en', 'es', 'fr'). Defaults to en
|
|
95
|
+
*/
|
|
96
|
+
language?: string;
|
|
97
|
+
translationsUrl?: string;
|
|
109
98
|
error: string;
|
|
110
99
|
messages: ChatMessage[];
|
|
111
100
|
sessionId?: string;
|
|
@@ -132,37 +121,50 @@ export declare class OcsChat {
|
|
|
132
121
|
showNewChatConfirmation: boolean;
|
|
133
122
|
selectedFiles: SelectedFile[];
|
|
134
123
|
isUploadingFiles: boolean;
|
|
135
|
-
private
|
|
124
|
+
private buttonPosition;
|
|
125
|
+
private buttonHorizontalSide;
|
|
126
|
+
private buttonVerticalSide;
|
|
127
|
+
isButtonDragging: boolean;
|
|
128
|
+
buttonWasDragged: boolean;
|
|
129
|
+
translationManager: TranslationManager;
|
|
130
|
+
private chatService?;
|
|
131
|
+
private messagePollingHandle?;
|
|
132
|
+
private taskPollingHandle?;
|
|
133
|
+
private attachmentManager;
|
|
136
134
|
private messageListRef?;
|
|
137
135
|
private textareaRef?;
|
|
138
136
|
private chatWindowRef?;
|
|
139
137
|
private fileInputRef?;
|
|
138
|
+
private buttonRef?;
|
|
139
|
+
private buttonDragOffset;
|
|
140
|
+
private rafId;
|
|
141
|
+
private buttonListenersAttached;
|
|
140
142
|
private chatWindowHeight;
|
|
141
143
|
private chatWindowWidth;
|
|
142
144
|
private chatWindowFullscreenWidth;
|
|
143
145
|
private positionInitialized;
|
|
144
146
|
host: HTMLElement;
|
|
145
|
-
componentWillLoad(): void
|
|
147
|
+
componentWillLoad(): Promise<void>;
|
|
146
148
|
componentDidLoad(): void;
|
|
147
149
|
disconnectedCallback(): void;
|
|
150
|
+
private getChatService;
|
|
148
151
|
private addErrorMessage;
|
|
149
152
|
private handleError;
|
|
150
153
|
private parseJSONProp;
|
|
151
154
|
private parseWelcomeMessages;
|
|
152
155
|
private parseStarterQuestions;
|
|
156
|
+
private initializeTranslations;
|
|
157
|
+
private loadTranslationsFromUrl;
|
|
153
158
|
private cleanup;
|
|
154
|
-
private getApiBaseUrl;
|
|
155
|
-
private getApiHeaders;
|
|
156
159
|
private startSession;
|
|
157
|
-
private markPendingFilesWithError;
|
|
158
160
|
private uploadFiles;
|
|
159
161
|
private sendMessage;
|
|
160
162
|
private handleStarterQuestionClick;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Scroll the message container to the bottom.
|
|
165
|
+
* @param forceEnd When `false`, scroll the top of the last message into view.
|
|
166
|
+
* When `true`, scroll all the way to the end of the last message.
|
|
167
|
+
*/
|
|
166
168
|
private scrollToBottom;
|
|
167
169
|
private focusInput;
|
|
168
170
|
private handleKeyPress;
|
|
@@ -178,6 +180,9 @@ export declare class OcsChat {
|
|
|
178
180
|
* @param visible - The new value for the field.
|
|
179
181
|
*/
|
|
180
182
|
visibilityHandler(visible: boolean): Promise<void>;
|
|
183
|
+
private startTaskPolling;
|
|
184
|
+
private startMessagePolling;
|
|
185
|
+
private stopMessagePolling;
|
|
181
186
|
setPosition(position: 'left' | 'center' | 'right'): void;
|
|
182
187
|
getPositionClasses(): string;
|
|
183
188
|
private getFullscreenBounds;
|
|
@@ -204,7 +209,24 @@ export declare class OcsChat {
|
|
|
204
209
|
private handleTouchMove;
|
|
205
210
|
private handleTouchEnd;
|
|
206
211
|
private handleWindowResize;
|
|
207
|
-
private
|
|
212
|
+
private initializeButtonPosition;
|
|
213
|
+
private updateHostPosition;
|
|
214
|
+
private isButtonDraggable;
|
|
215
|
+
private handleButtonMouseDown;
|
|
216
|
+
private handleButtonTouchStart;
|
|
217
|
+
private handleButtonMouseMove;
|
|
218
|
+
private handleButtonTouchMove;
|
|
219
|
+
private updateButtonPosition;
|
|
220
|
+
private handleButtonMouseUp;
|
|
221
|
+
private handleButtonTouchEnd;
|
|
222
|
+
private handleButtonClick;
|
|
223
|
+
private addButtonEventListeners;
|
|
224
|
+
private removeButtonEventListeners;
|
|
225
|
+
private isAutoPosition;
|
|
226
|
+
private parsePixelValue;
|
|
227
|
+
private getNumericPositionValue;
|
|
228
|
+
private getWelcomeMessages;
|
|
229
|
+
private getStarterQuestions;
|
|
208
230
|
private getButtonClasses;
|
|
209
231
|
private renderButton;
|
|
210
232
|
private getStorageKeys;
|
|
@@ -220,4 +242,3 @@ export declare class OcsChat {
|
|
|
220
242
|
private toggleFullscreen;
|
|
221
243
|
render(): any;
|
|
222
244
|
}
|
|
223
|
-
export {};
|
|
@@ -9,18 +9,22 @@ export namespace Components {
|
|
|
9
9
|
interface OpenChatStudioWidget {
|
|
10
10
|
/**
|
|
11
11
|
* Allow the user to attach files to their messages.
|
|
12
|
+
* @default false
|
|
12
13
|
*/
|
|
13
14
|
"allowAttachments": boolean;
|
|
14
15
|
/**
|
|
15
16
|
* Allow the user to make the chat window full screen.
|
|
17
|
+
* @default true
|
|
16
18
|
*/
|
|
17
19
|
"allowFullScreen": boolean;
|
|
18
20
|
/**
|
|
19
|
-
* The base URL for the API
|
|
21
|
+
* The base URL for the API.
|
|
22
|
+
* @default "https://www.openchatstudio.com"
|
|
20
23
|
*/
|
|
21
24
|
"apiBaseUrl"?: string;
|
|
22
25
|
/**
|
|
23
26
|
* The shape of the chat button. 'round' makes it circular, 'square' keeps it rectangular.
|
|
27
|
+
* @default 'square'
|
|
24
28
|
*/
|
|
25
29
|
"buttonShape": 'round' | 'square';
|
|
26
30
|
/**
|
|
@@ -31,6 +35,10 @@ export namespace Components {
|
|
|
31
35
|
* The ID of the chatbot to connect to.
|
|
32
36
|
*/
|
|
33
37
|
"chatbotId": string;
|
|
38
|
+
/**
|
|
39
|
+
* Authentication key for embedded channels
|
|
40
|
+
*/
|
|
41
|
+
"embedKey"?: string;
|
|
34
42
|
/**
|
|
35
43
|
* The text to place in the header.
|
|
36
44
|
*/
|
|
@@ -39,26 +47,34 @@ export namespace Components {
|
|
|
39
47
|
* URL of the icon to display on the button. If not provided, uses the default OCS logo.
|
|
40
48
|
*/
|
|
41
49
|
"iconUrl"?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The language code for the widget UI (e.g., 'en', 'es', 'fr'). Defaults to en
|
|
52
|
+
*/
|
|
53
|
+
"language"?: string;
|
|
42
54
|
/**
|
|
43
55
|
* The message to display in the new chat confirmation dialog.
|
|
44
56
|
*/
|
|
45
57
|
"newChatConfirmationMessage"?: string;
|
|
46
58
|
/**
|
|
47
59
|
* Whether to persist session data to local storage to allow resuming previous conversations after page reload.
|
|
60
|
+
* @default true
|
|
48
61
|
*/
|
|
49
62
|
"persistentSession": boolean;
|
|
50
63
|
/**
|
|
51
64
|
* Minutes since the most recent message after which the session data in local storage will expire. Set this to `0` to never expire.
|
|
65
|
+
* @default 60 * 24
|
|
52
66
|
*/
|
|
53
67
|
"persistentSessionExpire": number;
|
|
54
68
|
/**
|
|
55
69
|
* The initial position of the chat widget on the screen.
|
|
70
|
+
* @default 'right'
|
|
56
71
|
*/
|
|
57
72
|
"position": 'left' | 'center' | 'right';
|
|
58
73
|
/**
|
|
59
74
|
* Array of starter questions that users can click to send (JSON array of strings)
|
|
60
75
|
*/
|
|
61
76
|
"starterQuestions"?: string;
|
|
77
|
+
"translationsUrl"?: string;
|
|
62
78
|
/**
|
|
63
79
|
* The text to display while the assistant is typing/preparing a response.
|
|
64
80
|
*/
|
|
@@ -73,6 +89,7 @@ export namespace Components {
|
|
|
73
89
|
"userName"?: string;
|
|
74
90
|
/**
|
|
75
91
|
* Whether the chat widget is visible on load.
|
|
92
|
+
* @default false
|
|
76
93
|
*/
|
|
77
94
|
"visible": boolean;
|
|
78
95
|
/**
|
|
@@ -96,18 +113,22 @@ declare namespace LocalJSX {
|
|
|
96
113
|
interface OpenChatStudioWidget {
|
|
97
114
|
/**
|
|
98
115
|
* Allow the user to attach files to their messages.
|
|
116
|
+
* @default false
|
|
99
117
|
*/
|
|
100
118
|
"allowAttachments"?: boolean;
|
|
101
119
|
/**
|
|
102
120
|
* Allow the user to make the chat window full screen.
|
|
121
|
+
* @default true
|
|
103
122
|
*/
|
|
104
123
|
"allowFullScreen"?: boolean;
|
|
105
124
|
/**
|
|
106
|
-
* The base URL for the API
|
|
125
|
+
* The base URL for the API.
|
|
126
|
+
* @default "https://www.openchatstudio.com"
|
|
107
127
|
*/
|
|
108
128
|
"apiBaseUrl"?: string;
|
|
109
129
|
/**
|
|
110
130
|
* The shape of the chat button. 'round' makes it circular, 'square' keeps it rectangular.
|
|
131
|
+
* @default 'square'
|
|
111
132
|
*/
|
|
112
133
|
"buttonShape"?: 'round' | 'square';
|
|
113
134
|
/**
|
|
@@ -118,6 +139,10 @@ declare namespace LocalJSX {
|
|
|
118
139
|
* The ID of the chatbot to connect to.
|
|
119
140
|
*/
|
|
120
141
|
"chatbotId": string;
|
|
142
|
+
/**
|
|
143
|
+
* Authentication key for embedded channels
|
|
144
|
+
*/
|
|
145
|
+
"embedKey"?: string;
|
|
121
146
|
/**
|
|
122
147
|
* The text to place in the header.
|
|
123
148
|
*/
|
|
@@ -126,26 +151,34 @@ declare namespace LocalJSX {
|
|
|
126
151
|
* URL of the icon to display on the button. If not provided, uses the default OCS logo.
|
|
127
152
|
*/
|
|
128
153
|
"iconUrl"?: string;
|
|
154
|
+
/**
|
|
155
|
+
* The language code for the widget UI (e.g., 'en', 'es', 'fr'). Defaults to en
|
|
156
|
+
*/
|
|
157
|
+
"language"?: string;
|
|
129
158
|
/**
|
|
130
159
|
* The message to display in the new chat confirmation dialog.
|
|
131
160
|
*/
|
|
132
161
|
"newChatConfirmationMessage"?: string;
|
|
133
162
|
/**
|
|
134
163
|
* Whether to persist session data to local storage to allow resuming previous conversations after page reload.
|
|
164
|
+
* @default true
|
|
135
165
|
*/
|
|
136
166
|
"persistentSession"?: boolean;
|
|
137
167
|
/**
|
|
138
168
|
* Minutes since the most recent message after which the session data in local storage will expire. Set this to `0` to never expire.
|
|
169
|
+
* @default 60 * 24
|
|
139
170
|
*/
|
|
140
171
|
"persistentSessionExpire"?: number;
|
|
141
172
|
/**
|
|
142
173
|
* The initial position of the chat widget on the screen.
|
|
174
|
+
* @default 'right'
|
|
143
175
|
*/
|
|
144
176
|
"position"?: 'left' | 'center' | 'right';
|
|
145
177
|
/**
|
|
146
178
|
* Array of starter questions that users can click to send (JSON array of strings)
|
|
147
179
|
*/
|
|
148
180
|
"starterQuestions"?: string;
|
|
181
|
+
"translationsUrl"?: string;
|
|
149
182
|
/**
|
|
150
183
|
* The text to display while the assistant is typing/preparing a response.
|
|
151
184
|
*/
|
|
@@ -160,6 +193,7 @@ declare namespace LocalJSX {
|
|
|
160
193
|
"userName"?: string;
|
|
161
194
|
/**
|
|
162
195
|
* Whether the chat widget is visible on load.
|
|
196
|
+
* @default false
|
|
163
197
|
*/
|
|
164
198
|
"visible"?: boolean;
|
|
165
199
|
/**
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type ChatRole = 'system' | 'user' | 'assistant';
|
|
2
|
+
export interface ChatAttachment {
|
|
3
|
+
name: string;
|
|
4
|
+
content_type: string;
|
|
5
|
+
size: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ChatMessage {
|
|
8
|
+
created_at: string;
|
|
9
|
+
role: ChatRole;
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: unknown;
|
|
12
|
+
attachments?: ChatAttachment[];
|
|
13
|
+
}
|
|
14
|
+
export interface ChatStartSessionResponse {
|
|
15
|
+
session_id: string;
|
|
16
|
+
chatbot: unknown;
|
|
17
|
+
participant: unknown;
|
|
18
|
+
seed_message_task_id?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ChatSendMessageResponse {
|
|
21
|
+
task_id: string;
|
|
22
|
+
status: 'processing' | 'completed' | 'error';
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ChatTaskPollResponse {
|
|
26
|
+
message?: ChatMessage;
|
|
27
|
+
status: 'processing' | 'complete';
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ChatPollResponse {
|
|
31
|
+
messages: ChatMessage[];
|
|
32
|
+
has_more: boolean;
|
|
33
|
+
session_status: 'active' | 'ended';
|
|
34
|
+
}
|
|
35
|
+
export interface ChatSessionServiceOptions {
|
|
36
|
+
apiBaseUrl: string;
|
|
37
|
+
embedKey?: string;
|
|
38
|
+
widgetVersion: string;
|
|
39
|
+
csrfTokenProvider?: (apiBaseUrl: string) => string | undefined;
|
|
40
|
+
taskPollingIntervalMs?: number;
|
|
41
|
+
taskPollingMaxAttempts?: number;
|
|
42
|
+
messagePollingIntervalMs?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface TaskPollingCallbacks {
|
|
45
|
+
onMessage: (message: ChatMessage) => void;
|
|
46
|
+
onTimeout?: () => void;
|
|
47
|
+
onError?: (error: Error) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface TaskPollingHandle {
|
|
50
|
+
cancel: () => void;
|
|
51
|
+
}
|
|
52
|
+
export interface MessagePollingCallbacks {
|
|
53
|
+
getSince: () => string | undefined;
|
|
54
|
+
onMessages: (messages: ChatMessage[]) => void;
|
|
55
|
+
onError?: (error: Error) => void;
|
|
56
|
+
}
|
|
57
|
+
export interface MessagePollingHandle {
|
|
58
|
+
stop: () => void;
|
|
59
|
+
}
|
|
60
|
+
export declare class ChatSessionService {
|
|
61
|
+
private readonly apiBaseUrl;
|
|
62
|
+
private readonly embedKey?;
|
|
63
|
+
private readonly widgetVersion;
|
|
64
|
+
private readonly csrfTokenProvider;
|
|
65
|
+
private readonly taskPollingIntervalMs;
|
|
66
|
+
private readonly taskPollingMaxAttempts;
|
|
67
|
+
private readonly messagePollingIntervalMs;
|
|
68
|
+
private messagePollingTimer?;
|
|
69
|
+
constructor(options: ChatSessionServiceOptions);
|
|
70
|
+
startSession(requestBody: Record<string, unknown>): Promise<ChatStartSessionResponse>;
|
|
71
|
+
sendMessage(sessionId: string, payload: Record<string, unknown>): Promise<ChatSendMessageResponse>;
|
|
72
|
+
pollTaskOnce(sessionId: string, taskId: string): Promise<ChatTaskPollResponse>;
|
|
73
|
+
pollTask(sessionId: string, taskId: string, callbacks: TaskPollingCallbacks): TaskPollingHandle;
|
|
74
|
+
fetchMessages(sessionId: string, since?: string): Promise<ChatPollResponse>;
|
|
75
|
+
startMessagePolling(sessionId: string, callbacks: MessagePollingCallbacks): MessagePollingHandle;
|
|
76
|
+
stopMessagePolling(): void;
|
|
77
|
+
private getJsonHeaders;
|
|
78
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface UploadedFile {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
size: number;
|
|
5
|
+
content_type: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SelectedFile {
|
|
8
|
+
file: File;
|
|
9
|
+
uploaded?: UploadedFile;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AttachmentValidationConfig {
|
|
13
|
+
supportedExtensions: string[];
|
|
14
|
+
maxFileSizeMb: number;
|
|
15
|
+
maxTotalSizeMb: number;
|
|
16
|
+
}
|
|
17
|
+
export interface UploadContext {
|
|
18
|
+
apiBaseUrl: string;
|
|
19
|
+
sessionId: string;
|
|
20
|
+
participantId: string;
|
|
21
|
+
participantName?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface UploadResult {
|
|
24
|
+
selectedFiles: SelectedFile[];
|
|
25
|
+
uploadedIds: number[];
|
|
26
|
+
errorMessage?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class FileAttachmentManager {
|
|
29
|
+
private readonly supportedExtensions;
|
|
30
|
+
private readonly maxFileSizeMb;
|
|
31
|
+
private readonly maxTotalSizeMb;
|
|
32
|
+
constructor(config: AttachmentValidationConfig);
|
|
33
|
+
addFiles(existingFiles: SelectedFile[], files: FileList | File[]): SelectedFile[];
|
|
34
|
+
removeFile(existingFiles: SelectedFile[], index: number): SelectedFile[];
|
|
35
|
+
markPendingFilesWithError(existingFiles: SelectedFile[], errorMessage: string): SelectedFile[];
|
|
36
|
+
uploadPendingFiles(existingFiles: SelectedFile[], context: UploadContext): Promise<UploadResult>;
|
|
37
|
+
private bytesToMb;
|
|
38
|
+
private getFileExtension;
|
|
39
|
+
private safeJson;
|
|
40
|
+
}
|
|
@@ -260,6 +260,25 @@ export declare function setPlatformHelpers(helpers: {
|
|
|
260
260
|
* @returns the base path
|
|
261
261
|
*/
|
|
262
262
|
export declare function getAssetPath(path: string): string;
|
|
263
|
+
/**
|
|
264
|
+
* Method to render a virtual DOM tree to a container element.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```tsx
|
|
268
|
+
* import { render } from '@stencil/core';
|
|
269
|
+
*
|
|
270
|
+
* const vnode = (
|
|
271
|
+
* <div>
|
|
272
|
+
* <h1>Hello, world!</h1>
|
|
273
|
+
* </div>
|
|
274
|
+
* );
|
|
275
|
+
* render(vnode, document.body);
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @param vnode - The virtual DOM tree to render
|
|
279
|
+
* @param container - The container element to render the virtual DOM tree to
|
|
280
|
+
*/
|
|
281
|
+
export declare function render(vnode: VNode, container: Element): void;
|
|
263
282
|
/**
|
|
264
283
|
* Used to manually set the base path where assets can be found. For lazy-loaded
|
|
265
284
|
* builds the asset path is automatically set and assets copied to the correct
|
|
@@ -826,7 +845,8 @@ export declare namespace JSXBase {
|
|
|
826
845
|
}
|
|
827
846
|
interface DetailsHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
828
847
|
open?: boolean;
|
|
829
|
-
|
|
848
|
+
name?: string;
|
|
849
|
+
onToggle?: (event: ToggleEvent) => void;
|
|
830
850
|
}
|
|
831
851
|
interface DelHTMLAttributes<T> extends HTMLAttributes<T> {
|
|
832
852
|
cite?: string;
|
|
@@ -1532,6 +1552,13 @@ export declare namespace JSXBase {
|
|
|
1532
1552
|
z?: number | string;
|
|
1533
1553
|
zoomAndPan?: string;
|
|
1534
1554
|
}
|
|
1555
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent) */
|
|
1556
|
+
interface ToggleEvent extends Event {
|
|
1557
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/newState) */
|
|
1558
|
+
readonly newState: string;
|
|
1559
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ToggleEvent/oldState) */
|
|
1560
|
+
readonly oldState: string;
|
|
1561
|
+
}
|
|
1535
1562
|
interface DOMAttributes<T> extends JSXAttributes<T> {
|
|
1536
1563
|
slot?: string;
|
|
1537
1564
|
part?: string;
|
|
@@ -1548,6 +1575,10 @@ export declare namespace JSXBase {
|
|
|
1548
1575
|
onCompositionstartCapture?: (event: CompositionEvent) => void;
|
|
1549
1576
|
onCompositionupdate?: (event: CompositionEvent) => void;
|
|
1550
1577
|
onCompositionupdateCapture?: (event: CompositionEvent) => void;
|
|
1578
|
+
onBeforeToggle?: (event: ToggleEvent) => void;
|
|
1579
|
+
onBeforeToggleCapture?: (event: ToggleEvent) => void;
|
|
1580
|
+
onToggle?: (event: ToggleEvent) => void;
|
|
1581
|
+
onToggleCapture?: (event: ToggleEvent) => void;
|
|
1551
1582
|
onFocus?: (event: FocusEvent) => void;
|
|
1552
1583
|
onFocusCapture?: (event: FocusEvent) => void;
|
|
1553
1584
|
onFocusin?: (event: FocusEvent) => void;
|
|
@@ -1566,10 +1597,6 @@ export declare namespace JSXBase {
|
|
|
1566
1597
|
onSubmitCapture?: (event: Event) => void;
|
|
1567
1598
|
onInvalid?: (event: Event) => void;
|
|
1568
1599
|
onInvalidCapture?: (event: Event) => void;
|
|
1569
|
-
onBeforeToggle?: (event: Event) => void;
|
|
1570
|
-
onBeforeToggleCapture?: (event: Event) => void;
|
|
1571
|
-
onToggle?: (event: Event) => void;
|
|
1572
|
-
onToggleCapture?: (event: Event) => void;
|
|
1573
1600
|
onLoad?: (event: Event) => void;
|
|
1574
1601
|
onLoadCapture?: (event: Event) => void;
|
|
1575
1602
|
onError?: (event: Event) => void;
|
|
@@ -1581,7 +1608,7 @@ export declare namespace JSXBase {
|
|
|
1581
1608
|
onKeyUp?: (event: KeyboardEvent) => void;
|
|
1582
1609
|
onKeyUpCapture?: (event: KeyboardEvent) => void;
|
|
1583
1610
|
onAuxClick?: (event: MouseEvent) => void;
|
|
1584
|
-
onClick?: (event:
|
|
1611
|
+
onClick?: (event: PointerEvent) => void;
|
|
1585
1612
|
onClickCapture?: (event: MouseEvent) => void;
|
|
1586
1613
|
onContextMenu?: (event: MouseEvent) => void;
|
|
1587
1614
|
onContextMenuCapture?: (event: MouseEvent) => void;
|
|
@@ -1661,6 +1688,8 @@ export declare namespace JSXBase {
|
|
|
1661
1688
|
onTransitionRunCapture?: (event: TransitionEvent) => void;
|
|
1662
1689
|
onTransitionStart?: (event: TransitionEvent) => void;
|
|
1663
1690
|
onTransitionStartCapture?: (event: TransitionEvent) => void;
|
|
1691
|
+
[key: `aria-${string}`]: string | boolean | undefined;
|
|
1692
|
+
[key: `aria${string}`]: string | boolean | undefined;
|
|
1664
1693
|
}
|
|
1665
1694
|
}
|
|
1666
1695
|
export interface JSXAttributes<T = Element> {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation utilities for the chat widget
|
|
3
|
+
*/
|
|
4
|
+
import en from '../assets/translations/en.json';
|
|
5
|
+
export type TranslationStrings = typeof en;
|
|
6
|
+
export declare const defaultTranslations: TranslationStrings;
|
|
7
|
+
export declare function getBrowserLanguage(): string;
|
|
8
|
+
export declare function resolveLanguage(langProp?: string): string;
|
|
9
|
+
export declare function loadTranslations(language: string): Promise<TranslationStrings>;
|
|
10
|
+
/**
|
|
11
|
+
* Overrides matching keys
|
|
12
|
+
*/
|
|
13
|
+
export declare function mergeTranslations(baseTranslations: TranslationStrings, customTranslations: Partial<TranslationStrings>): TranslationStrings;
|
|
14
|
+
export declare class TranslationManager {
|
|
15
|
+
private translations;
|
|
16
|
+
private language;
|
|
17
|
+
constructor(language?: string, customTranslations?: Partial<TranslationStrings>);
|
|
18
|
+
private loadTranslations;
|
|
19
|
+
get(key: keyof TranslationStrings, override?: string | null): string | undefined;
|
|
20
|
+
getAll(): TranslationStrings;
|
|
21
|
+
getArray(key: keyof TranslationStrings): string[];
|
|
22
|
+
getLanguage(): string;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "open-chat-studio-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Chat component for Open Chat Studio",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"exports": "./dist/esm/open-chat-studio-widget.js",
|
|
@@ -20,16 +20,19 @@
|
|
|
20
20
|
"loader/"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
+
"test": "stencil test --spec",
|
|
23
24
|
"build": "stencil build --docs",
|
|
24
25
|
"start": "stencil build --dev --watch --serve",
|
|
25
26
|
"generate": "stencil generate",
|
|
26
27
|
"use:npmReadme": "mv 'README.md' 'git.README.md' && cp 'src/components/ocs-chat/readme.md' 'README.md'",
|
|
27
28
|
"use:gitReadme": "mv 'git.README.md' 'README.md'",
|
|
28
29
|
"prepublishOnly": "run-s build use:npmReadme",
|
|
29
|
-
"postpublish": "npm run use:gitReadme"
|
|
30
|
+
"postpublish": "npm run use:gitReadme",
|
|
31
|
+
"type-check": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint --fix src"
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"@stencil/core": "^4.
|
|
35
|
+
"@stencil/core": "^4.27.0",
|
|
33
36
|
"dompurify": "^3.0.5",
|
|
34
37
|
"js-cookie": "^3.0.5",
|
|
35
38
|
"marked": "^4.3.0",
|
|
@@ -37,6 +40,7 @@
|
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@stencil-community/postcss": "^2.2.0",
|
|
43
|
+
"@tailwindcss/postcss": "^4.1.12",
|
|
40
44
|
"@tailwindcss/typography": "^0.5.16",
|
|
41
45
|
"@types/jest": "^29.5.14",
|
|
42
46
|
"@types/node": "^22.13.4",
|
|
@@ -46,7 +50,8 @@
|
|
|
46
50
|
"npm-run-all": "^4.1.5",
|
|
47
51
|
"postcss-import": "^16.1.0",
|
|
48
52
|
"puppeteer": "^24.2.0",
|
|
49
|
-
"
|
|
53
|
+
"stencil-tailwind-plugin": "^2.0.5",
|
|
54
|
+
"tailwindcss": "^4.1.12",
|
|
50
55
|
"typescript": "^5.7.3"
|
|
51
56
|
},
|
|
52
57
|
"license": "MIT"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"app-globals-3a1e7e63.js","mappings":";;AAAY,MAAC,aAAa,GAAG,MAAM;;;;","names":[],"sources":["@stencil/core/internal/app-globals"],"sourcesContent":["export const globalScripts = () => {};\n"],"version":3}
|