open-chat-studio-widget 0.5.1 → 0.5.2
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/cjs/{index-Du0PBL6n.js → index-Ctja7z-R.js} +3 -3
- package/dist/cjs/{index-Du0PBL6n.js.map → index-Ctja7z-R.js.map} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/open-chat-studio-widget.cjs.entry.js +45 -38
- package/dist/cjs/open-chat-studio-widget.cjs.entry.js.map +1 -1
- package/dist/cjs/open-chat-studio-widget.cjs.js +1 -1
- package/dist/cjs/open-chat-studio-widget.entry.cjs.js.map +1 -1
- package/dist/collection/components/ocs-chat/ocs-chat.js +44 -37
- package/dist/collection/components/ocs-chat/ocs-chat.js.map +1 -1
- package/dist/collection/services/chat-session-service.js.map +1 -1
- package/dist/components/open-chat-studio-widget.js +44 -37
- package/dist/components/open-chat-studio-widget.js.map +1 -1
- package/dist/esm/{index-CX3v6rTy.js → index-BbCwiO7g.js} +3 -3
- package/dist/esm/{index-CX3v6rTy.js.map → index-BbCwiO7g.js.map} +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/open-chat-studio-widget.entry.js +45 -38
- package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
- package/dist/esm/open-chat-studio-widget.js +2 -2
- package/dist/open-chat-studio-widget/open-chat-studio-widget.entry.esm.js.map +1 -1
- package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
- package/dist/open-chat-studio-widget/{p-90719a8b.entry.js → p-96920183.entry.js} +4 -4
- package/dist/open-chat-studio-widget/p-96920183.entry.js.map +1 -0
- package/dist/open-chat-studio-widget/{p-CX3v6rTy.js → p-BbCwiO7g.js} +2 -2
- package/dist/open-chat-studio-widget/{p-CX3v6rTy.js.map → p-BbCwiO7g.js.map} +1 -1
- package/dist/types/components/ocs-chat/ocs-chat.d.ts +5 -1
- package/dist/types/services/chat-session-service.d.ts +0 -1
- package/package.json +2 -2
- package/dist/open-chat-studio-widget/p-90719a8b.entry.js.map +0 -1
package/dist/cjs/loader.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-Ctja7z-R.js');
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
6
|
const OcsWidgetAvatar = () => {
|
|
@@ -5402,17 +5402,16 @@ const OcsChat = class {
|
|
|
5402
5402
|
this.chatWindowFullscreenWidth = varToPixels(fullscreenWidthVar, window.innerWidth, this.chatWindowFullscreenWidth);
|
|
5403
5403
|
// Initialize button position from computed styles
|
|
5404
5404
|
this.initializeButtonPosition();
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
}
|
|
5405
|
+
// Defer position initialization to avoid state changes during componentDidLoad
|
|
5406
|
+
setTimeout(() => {
|
|
5407
|
+
if (this.visible) {
|
|
5408
|
+
this.initializePosition();
|
|
5409
|
+
}
|
|
5410
|
+
// Resume polling for existing session (don't auto-start new sessions)
|
|
5411
|
+
if (this.visible && this.sessionId) {
|
|
5412
|
+
this.startMessagePolling();
|
|
5413
|
+
}
|
|
5414
|
+
}, 0);
|
|
5416
5415
|
window.addEventListener('resize', this.handleWindowResize);
|
|
5417
5416
|
}
|
|
5418
5417
|
disconnectedCallback() {
|
|
@@ -5524,13 +5523,7 @@ const OcsChat = class {
|
|
|
5524
5523
|
const data = await this.getChatService().startSession(requestBody);
|
|
5525
5524
|
this.sessionId = data.session_id;
|
|
5526
5525
|
this.saveSessionToStorage();
|
|
5527
|
-
|
|
5528
|
-
if (data.seed_message_task_id) {
|
|
5529
|
-
this.startTaskPolling(data.seed_message_task_id);
|
|
5530
|
-
}
|
|
5531
|
-
else {
|
|
5532
|
-
this.startMessagePolling();
|
|
5533
|
-
}
|
|
5526
|
+
this.startMessagePolling();
|
|
5534
5527
|
}
|
|
5535
5528
|
catch (_error) {
|
|
5536
5529
|
this.handleError('Failed to start chat session');
|
|
@@ -5559,8 +5552,20 @@ const OcsChat = class {
|
|
|
5559
5552
|
}
|
|
5560
5553
|
}
|
|
5561
5554
|
async sendMessage(message) {
|
|
5562
|
-
if (!
|
|
5555
|
+
if (!message.trim())
|
|
5563
5556
|
return;
|
|
5557
|
+
// Start session if we don't have one yet
|
|
5558
|
+
if (!this.sessionId) {
|
|
5559
|
+
// Prevent concurrent session initialization
|
|
5560
|
+
if (this.isLoading) {
|
|
5561
|
+
return;
|
|
5562
|
+
}
|
|
5563
|
+
await this.startSession();
|
|
5564
|
+
// Check if session started successfully
|
|
5565
|
+
if (!this.sessionId) {
|
|
5566
|
+
return; // startSession already handled the error
|
|
5567
|
+
}
|
|
5568
|
+
}
|
|
5564
5569
|
try {
|
|
5565
5570
|
let attachmentIds = [];
|
|
5566
5571
|
if (this.allowAttachments && this.selectedFiles.length > 0) {
|
|
@@ -5575,10 +5580,11 @@ const OcsChat = class {
|
|
|
5575
5580
|
}
|
|
5576
5581
|
// If this is the first user message and there are welcome messages,
|
|
5577
5582
|
// add them to chat history as assistant messages
|
|
5578
|
-
|
|
5583
|
+
const welcomeMessagesToAdd = this.getWelcomeMessages();
|
|
5584
|
+
if (this.messages.length === 0 && welcomeMessagesToAdd.length > 0) {
|
|
5579
5585
|
const now = new Date();
|
|
5580
|
-
const welcomeMessages =
|
|
5581
|
-
created_at: new Date(now.getTime() - (
|
|
5586
|
+
const welcomeMessages = welcomeMessagesToAdd.map((welcomeMsg, index) => ({
|
|
5587
|
+
created_at: new Date(now.getTime() - (welcomeMessagesToAdd.length - index) * 1000).toISOString(),
|
|
5582
5588
|
role: 'assistant',
|
|
5583
5589
|
content: welcomeMsg,
|
|
5584
5590
|
attachments: []
|
|
@@ -5712,16 +5718,14 @@ const OcsChat = class {
|
|
|
5712
5718
|
}
|
|
5713
5719
|
if (visible) {
|
|
5714
5720
|
this.initializePosition();
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
this.stopMessagePolling();
|
|
5721
|
+
// Resume polling for existing session (don't auto-start new sessions)
|
|
5722
|
+
if (this.sessionId) {
|
|
5723
|
+
this.scrollToBottom(true);
|
|
5724
|
+
this.startMessagePolling();
|
|
5725
|
+
}
|
|
5721
5726
|
}
|
|
5722
5727
|
else {
|
|
5723
|
-
this.
|
|
5724
|
-
this.startMessagePolling();
|
|
5728
|
+
this.stopMessagePolling();
|
|
5725
5729
|
}
|
|
5726
5730
|
}
|
|
5727
5731
|
startTaskPolling(taskId) {
|
|
@@ -6224,9 +6228,13 @@ const OcsChat = class {
|
|
|
6224
6228
|
}
|
|
6225
6229
|
async confirmNewChat() {
|
|
6226
6230
|
this.hideConfirmationDialog();
|
|
6227
|
-
await this.
|
|
6231
|
+
await this.clearSession();
|
|
6228
6232
|
}
|
|
6229
|
-
|
|
6233
|
+
/**
|
|
6234
|
+
* This clears out all data related to the previous session. A new session
|
|
6235
|
+
* will start when the user sends a message.
|
|
6236
|
+
*/
|
|
6237
|
+
async clearSession() {
|
|
6230
6238
|
this.clearSessionStorage();
|
|
6231
6239
|
this.sessionId = undefined;
|
|
6232
6240
|
this.messages = [];
|
|
@@ -6236,7 +6244,6 @@ const OcsChat = class {
|
|
|
6236
6244
|
this.selectedFiles = [];
|
|
6237
6245
|
}
|
|
6238
6246
|
this.cleanup();
|
|
6239
|
-
await this.startSession();
|
|
6240
6247
|
}
|
|
6241
6248
|
toggleFullscreen() {
|
|
6242
6249
|
this.isFullscreen = !this.isFullscreen;
|
|
@@ -6248,18 +6255,18 @@ const OcsChat = class {
|
|
|
6248
6255
|
if (this.error && !this.sessionId) {
|
|
6249
6256
|
return (index.h(index.Host, null, index.h("p", { class: "error-message" }, this.error)));
|
|
6250
6257
|
}
|
|
6251
|
-
return (index.h(index.Host, null, this.renderButton(), this.visible && (index.h("div", { ref: (el) => this.chatWindowRef = el, id: "ocs-chat-window", class: this.getPositionClasses(), style: this.getPositionStyles() }, index.h("div", { class: `chat-header ${this.isDragging ? 'chat-header-dragging' : 'chat-header-draggable'}`, onMouseDown: this.handleMouseDown, onTouchStart: this.handleTouchStart }, index.h("div", { class: "drag-indicator" }, index.h("div", { class: "drag-dots header-button" }, index.h(GripDotsVerticalIcon, null))), index.h("div", { class: "header-text" }, this.translationManager.get('branding.headerText', this.headerText)), index.h("div", { class: "header-buttons" }, this.messages.length > 0 && (index.h("button", { class: "header-button", onClick: () => this.showConfirmationDialog(), title: this.translationManager.get('window.newChat'), "aria-label": this.translationManager.get('window.newChat') }, index.h(PlusWithCircleIcon, null))), this.allowFullScreen && index.h("button", { class: "header-button fullscreen-button", onClick: () => this.toggleFullscreen(), title: this.isFullscreen ? this.translationManager.get('window.exitFullscreen') : this.translationManager.get('window.fullscreen'), "aria-label": this.isFullscreen ? this.translationManager.get('window.exitFullscreen') : this.translationManager.get('window.fullscreen') }, this.isFullscreen ? index.h(ArrowsPointingInIcon, null) : index.h(ArrowsPointingOutIcon, null)), index.h("button", { class: "header-button", onClick: () => this.visible = false, "aria-label": this.translationManager.get('window.close') }, index.h(XMarkIcon, null)))), this.showNewChatConfirmation && (index.h("div", { class: "confirmation-overlay" }, index.h("div", { class: "confirmation-dialog" }, index.h("div", { class: "confirmation-content" }, index.h("h3", { class: "confirmation-title" }, this.translationManager.get('modal.newChatTitle')), index.h("p", { class: "confirmation-message" }, this.translationManager.get('modal.newChatBody', this.newChatConfirmationMessage)), index.h("div", { class: "confirmation-buttons" }, index.h("button", { class: "confirmation-button confirmation-button-cancel", onClick: () => this.hideConfirmationDialog() }, this.translationManager.get('modal.cancel')), index.h("button", { class: "confirmation-button confirmation-button-confirm", onClick: () => this.confirmNewChat() }, this.translationManager.get('modal.confirm'))))))), index.h("div", { class: "chat-content" }, this.isLoading && !this.sessionId && (index.h("div", { class: "loading-container" }, index.h("div", { class: "loading-spinner" }), index.h("span", { class: "loading-text" }, this.translationManager.get('status.starting')))), (index.h("div", { ref: (el) => this.messageListRef = el, class: "messages-container" }, this.messages.length === 0 && this.
|
|
6258
|
+
return (index.h(index.Host, null, this.renderButton(), this.visible && (index.h("div", { ref: (el) => this.chatWindowRef = el, id: "ocs-chat-window", class: this.getPositionClasses(), style: this.getPositionStyles() }, index.h("div", { class: `chat-header ${this.isDragging ? 'chat-header-dragging' : 'chat-header-draggable'}`, onMouseDown: this.handleMouseDown, onTouchStart: this.handleTouchStart }, index.h("div", { class: "drag-indicator" }, index.h("div", { class: "drag-dots header-button" }, index.h(GripDotsVerticalIcon, null))), index.h("div", { class: "header-text" }, this.translationManager.get('branding.headerText', this.headerText)), index.h("div", { class: "header-buttons" }, this.messages.length > 0 && (index.h("button", { class: "header-button", onClick: () => this.showConfirmationDialog(), title: this.translationManager.get('window.newChat'), "aria-label": this.translationManager.get('window.newChat') }, index.h(PlusWithCircleIcon, null))), this.allowFullScreen && index.h("button", { class: "header-button fullscreen-button", onClick: () => this.toggleFullscreen(), title: this.isFullscreen ? this.translationManager.get('window.exitFullscreen') : this.translationManager.get('window.fullscreen'), "aria-label": this.isFullscreen ? this.translationManager.get('window.exitFullscreen') : this.translationManager.get('window.fullscreen') }, this.isFullscreen ? index.h(ArrowsPointingInIcon, null) : index.h(ArrowsPointingOutIcon, null)), index.h("button", { class: "header-button", onClick: () => this.visible = false, "aria-label": this.translationManager.get('window.close') }, index.h(XMarkIcon, null)))), this.showNewChatConfirmation && (index.h("div", { class: "confirmation-overlay" }, index.h("div", { class: "confirmation-dialog" }, index.h("div", { class: "confirmation-content" }, index.h("h3", { class: "confirmation-title" }, this.translationManager.get('modal.newChatTitle')), index.h("p", { class: "confirmation-message" }, this.translationManager.get('modal.newChatBody', this.newChatConfirmationMessage)), index.h("div", { class: "confirmation-buttons" }, index.h("button", { class: "confirmation-button confirmation-button-cancel", onClick: () => this.hideConfirmationDialog() }, this.translationManager.get('modal.cancel')), index.h("button", { class: "confirmation-button confirmation-button-confirm", onClick: () => this.confirmNewChat() }, this.translationManager.get('modal.confirm'))))))), index.h("div", { class: "chat-content" }, this.isLoading && !this.sessionId && (index.h("div", { class: "loading-container" }, index.h("div", { class: "loading-spinner" }), index.h("span", { class: "loading-text" }, this.translationManager.get('status.starting')))), (index.h("div", { ref: (el) => this.messageListRef = el, class: "messages-container" }, this.messages.length === 0 && this.getWelcomeMessages().length > 0 && (index.h("div", { class: "welcome-messages" }, this.getWelcomeMessages().map((message, index$1) => (index.h("div", { key: `welcome-${index$1}`, class: "message-row message-row-assistant" }, index.h("div", { class: "message-bubble message-bubble-assistant" }, index.h("div", { class: "chat-markdown", innerHTML: renderMarkdownSync(message) }))))))), this.messages.map((message, index$1) => (index.h("div", { key: index$1, class: `message-row ${message.role === 'user' ? 'message-row-user' : 'message-row-assistant'}` }, index.h("div", { class: `message-bubble ${message.role === 'user'
|
|
6252
6259
|
? 'message-bubble-user'
|
|
6253
6260
|
: message.role === 'assistant'
|
|
6254
6261
|
? 'message-bubble-assistant'
|
|
6255
|
-
: 'message-bubble-system'}` }, index.h("div", { class: "chat-markdown", innerHTML: renderMarkdownSync(message.content) }), message.attachments && message.attachments.length > 0 && (index.h("div", { class: "message-attachments" }, message.attachments.map((attachment, attachmentIndex) => (index.h("div", { key: attachmentIndex, class: "flex items-center gap-[0.5em]" }, index.h("span", { class: "message-attachment-icon" }, index.h(PaperClipIcon, null)), index.h("span", { class: "message-attachment-name" }, attachment.name)))))), index.h("div", { class: "message-timestamp" }, this.formatTime(message.created_at)))))), this.isTyping && (index.h("div", null, index.h("div", { class: "typing-indicator" }, index.h("div", { class: "typing-progress" })), index.h("div", { class: "typing-text" }, index.h("span", null, this.translationManager.get('status.typing', this.typingIndicatorText)), index.h("span", { class: "typing-dots loading" })))))), this.messages.length === 0 && this.
|
|
6262
|
+
: 'message-bubble-system'}` }, index.h("div", { class: "chat-markdown", innerHTML: renderMarkdownSync(message.content) }), message.attachments && message.attachments.length > 0 && (index.h("div", { class: "message-attachments" }, message.attachments.map((attachment, attachmentIndex) => (index.h("div", { key: attachmentIndex, class: "flex items-center gap-[0.5em]" }, index.h("span", { class: "message-attachment-icon" }, index.h(PaperClipIcon, null)), index.h("span", { class: "message-attachment-name" }, attachment.name)))))), index.h("div", { class: "message-timestamp" }, this.formatTime(message.created_at)))))), this.isTyping && (index.h("div", null, index.h("div", { class: "typing-indicator" }, index.h("div", { class: "typing-progress" })), index.h("div", { class: "typing-text" }, index.h("span", null, this.translationManager.get('status.typing', this.typingIndicatorText)), index.h("span", { class: "typing-dots loading" })))))), this.messages.length === 0 && this.getStarterQuestions().length > 0 && (index.h("div", { class: "starter-questions" }, this.getStarterQuestions().map((question, index$1) => (index.h("div", { key: `starter-${index$1}`, class: "starter-question-row" }, index.h("button", { class: "starter-question", onClick: () => this.handleStarterQuestionClick(question) }, question)))))), this.allowAttachments && this.selectedFiles.length > 0 && (index.h("div", { class: "selected-files-container" }, index.h("div", { class: "space-y-[0.25em]" }, this.selectedFiles.map((selectedFile, index$1) => (index.h("div", { key: index$1, class: "selected-file-item" }, index.h("div", { class: "flex items-center gap-[0.5em]" }, index.h("span", { class: "selected-file-icon" }, index.h(PaperClipIcon, null)), index.h("span", null, selectedFile.file.name), index.h("span", { class: "selected-file-size" }, "(", this.formatFileSize(selectedFile.file.size), ")"), selectedFile.error && (index.h("span", { class: "selected-file-error" }, selectedFile.error)), selectedFile.uploaded && (index.h("span", { class: "selected-file-success-icon" }, index.h(CheckDocumentIcon, null)))), index.h("button", { onClick: () => this.removeSelectedFile(index$1), class: "selected-file-remove-button", "aria-label": this.translationManager.get('attach.remove') }, index.h(XIcon, null)))))))), index.h("div", { class: "input-area" }, index.h("div", { class: "input-container" }, index.h("textarea", { ref: (el) => this.textareaRef = el, class: "message-textarea", rows: 1, placeholder: this.translationManager.get('composer.placeholder'), value: this.messageInput, onInput: (e) => this.handleInputChange(e), onKeyPress: (e) => this.handleKeyPress(e), disabled: this.isTyping || this.isUploadingFiles || this.isLoading }), this.allowAttachments && (index.h("input", { ref: (el) => {
|
|
6256
6263
|
// Unclear why but after removing all attachments this is being set to `null`.
|
|
6257
6264
|
if (el) {
|
|
6258
6265
|
this.fileInputRef = el;
|
|
6259
6266
|
}
|
|
6260
|
-
}, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(','), onChange: (e) => this.handleFileSelect(e), class: "hidden" })), this.allowAttachments && (index.h("button", { class: "file-attachment-button", onClick: () => { var _a; return (_a = this.fileInputRef) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: this.isTyping || this.isUploadingFiles, title: this.translationManager.get('attach.add'), "aria-label": this.translationManager.get('attach.add') }, index.h(PaperClipIcon, null))), index.h("button", { class: `send-button ${!this.isTyping && !!this.messageInput.trim()
|
|
6267
|
+
}, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(','), onChange: (e) => this.handleFileSelect(e), class: "hidden" })), this.allowAttachments && (index.h("button", { class: "file-attachment-button", onClick: () => { var _a; return (_a = this.fileInputRef) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: this.isTyping || this.isUploadingFiles || this.isLoading, title: this.translationManager.get('attach.add'), "aria-label": this.translationManager.get('attach.add') }, index.h(PaperClipIcon, null))), index.h("button", { class: `send-button ${!this.isTyping && !this.isLoading && !!this.messageInput.trim()
|
|
6261
6268
|
? 'send-button-enabled'
|
|
6262
|
-
: 'send-button-disabled'}`, onClick: () => this.sendMessage(this.messageInput), disabled: this.isTyping || this.isUploadingFiles || !this.messageInput.trim() }, this.isUploadingFiles ? `${this.translationManager.get('status.uploading')}...` : this.translationManager.get('composer.send'))))
|
|
6269
|
+
: 'send-button-disabled'}`, onClick: () => this.sendMessage(this.messageInput), disabled: this.isTyping || this.isUploadingFiles || this.isLoading || !this.messageInput.trim() }, this.isUploadingFiles ? `${this.translationManager.get('status.uploading')}...` : this.translationManager.get('composer.send')))), index.h("div", { class: "flex items-center justify-center text-[0.8em] font-light w-full text-slate-500 py-[2px]" }, index.h("p", null, this.translationManager.get('branding.poweredBy'), ' ', " ", index.h("a", { class: "underline", href: "https://www.dimagi.com", target: "_blank" }, "Dimagi"))))))));
|
|
6263
6270
|
}
|
|
6264
6271
|
get host() { return index.getElement(this); }
|
|
6265
6272
|
static get watchers() { return {
|