open-chat-studio-widget 0.5.3 → 0.6.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.
Files changed (31) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/{index-D8A4RBzq.js → index-CcvroTR_.js} +3 -3
  3. package/dist/cjs/{index-D8A4RBzq.js.map → index-CcvroTR_.js.map} +1 -1
  4. package/dist/cjs/loader.cjs.js +2 -2
  5. package/dist/cjs/open-chat-studio-widget.cjs.entry.js +31 -5
  6. package/dist/cjs/open-chat-studio-widget.cjs.entry.js.map +1 -1
  7. package/dist/cjs/open-chat-studio-widget.cjs.js +2 -2
  8. package/dist/cjs/open-chat-studio-widget.entry.cjs.js.map +1 -1
  9. package/dist/collection/components/ocs-chat/ocs-chat.js +53 -3
  10. package/dist/collection/components/ocs-chat/ocs-chat.js.map +1 -1
  11. package/dist/collection/services/file-attachment-manager.js +2 -1
  12. package/dist/collection/services/file-attachment-manager.js.map +1 -1
  13. package/dist/components/open-chat-studio-widget.js +32 -4
  14. package/dist/components/open-chat-studio-widget.js.map +1 -1
  15. package/dist/esm/{index-C53whb-B.js → index-BKVXO_5E.js} +3 -3
  16. package/dist/esm/{index-C53whb-B.js.map → index-BKVXO_5E.js.map} +1 -1
  17. package/dist/esm/loader.js +3 -3
  18. package/dist/esm/open-chat-studio-widget.entry.js +31 -5
  19. package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
  20. package/dist/esm/open-chat-studio-widget.js +3 -3
  21. package/dist/open-chat-studio-widget/open-chat-studio-widget.entry.esm.js.map +1 -1
  22. package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
  23. package/dist/open-chat-studio-widget/{p-C53whb-B.js → p-BKVXO_5E.js} +2 -2
  24. package/dist/open-chat-studio-widget/{p-C53whb-B.js.map → p-BKVXO_5E.js.map} +1 -1
  25. package/dist/open-chat-studio-widget/p-a0d04423.entry.js +4 -0
  26. package/dist/open-chat-studio-widget/p-a0d04423.entry.js.map +1 -0
  27. package/dist/types/components/ocs-chat/ocs-chat.d.ts +12 -0
  28. package/dist/types/components.d.ts +8 -0
  29. package/package.json +1 -1
  30. package/dist/open-chat-studio-widget/p-b9556259.entry.js +0 -4
  31. package/dist/open-chat-studio-widget/p-b9556259.entry.js.map +0 -1
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-D8A4RBzq.js');
3
+ var index = require('./index-CcvroTR_.js');
4
4
  var appGlobals = require('./app-globals-V2Kpy_OQ.js');
5
5
 
6
6
  const defineCustomElements = async (win, options) => {
7
7
  if (typeof window === 'undefined') return undefined;
8
8
  await appGlobals.globalScripts();
9
- return index.bootstrapLazy([["open-chat-studio-widget.cjs",[[257,"open-chat-studio-widget",{"chatbotId":[1,"chatbot-id"],"apiBaseUrl":[1,"api-base-url"],"buttonText":[1,"button-text"],"iconUrl":[1,"icon-url"],"embedKey":[1,"embed-key"],"buttonShape":[1,"button-shape"],"headerText":[1,"header-text"],"newChatConfirmationMessage":[1,"new-chat-confirmation-message"],"visible":[1028],"position":[1025],"welcomeMessages":[1,"welcome-messages"],"starterQuestions":[1,"starter-questions"],"userId":[1,"user-id"],"userName":[1,"user-name"],"persistentSession":[4,"persistent-session"],"persistentSessionExpire":[2,"persistent-session-expire"],"allowFullScreen":[4,"allow-full-screen"],"allowAttachments":[4,"allow-attachments"],"typingIndicatorText":[1,"typing-indicator-text"],"language":[1],"translationsUrl":[1,"translations-url"],"error":[32],"messages":[32],"sessionId":[32],"isLoading":[32],"isTyping":[32],"messageInput":[32],"currentPollTaskId":[32],"isDragging":[32],"dragOffset":[32],"windowPosition":[32],"fullscreenPosition":[32],"parsedWelcomeMessages":[32],"parsedStarterQuestions":[32],"generatedUserId":[32],"isFullscreen":[32],"showNewChatConfirmation":[32],"selectedFiles":[32],"isUploadingFiles":[32],"isButtonDragging":[32],"buttonWasDragged":[32]},null,{"visible":["visibilityHandler"]}]]]], options);
9
+ return index.bootstrapLazy([["open-chat-studio-widget.cjs",[[257,"open-chat-studio-widget",{"chatbotId":[1,"chatbot-id"],"apiBaseUrl":[1,"api-base-url"],"buttonText":[1,"button-text"],"iconUrl":[1,"icon-url"],"embedKey":[1,"embed-key"],"buttonShape":[1,"button-shape"],"headerText":[1,"header-text"],"newChatConfirmationMessage":[1,"new-chat-confirmation-message"],"visible":[1028],"position":[1025],"welcomeMessages":[1,"welcome-messages"],"starterQuestions":[1,"starter-questions"],"userId":[1,"user-id"],"userName":[1,"user-name"],"persistentSession":[4,"persistent-session"],"persistentSessionExpire":[2,"persistent-session-expire"],"allowFullScreen":[4,"allow-full-screen"],"allowAttachments":[4,"allow-attachments"],"typingIndicatorText":[1,"typing-indicator-text"],"language":[1],"translationsUrl":[1,"translations-url"],"pageContext":[1040,"page-context"],"error":[32],"messages":[32],"sessionId":[32],"isLoading":[32],"isTyping":[32],"messageInput":[32],"currentPollTaskId":[32],"isDragging":[32],"dragOffset":[32],"windowPosition":[32],"fullscreenPosition":[32],"parsedWelcomeMessages":[32],"parsedStarterQuestions":[32],"generatedUserId":[32],"isFullscreen":[32],"showNewChatConfirmation":[32],"selectedFiles":[32],"isUploadingFiles":[32],"isButtonDragging":[32],"buttonWasDragged":[32]},null,{"pageContext":["pageContextHandler"],"visible":["visibilityHandler"]}]]]], options);
10
10
  };
11
11
 
12
12
  exports.setNonce = index.setNonce;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-D8A4RBzq.js');
3
+ var index = require('./index-CcvroTR_.js');
4
4
 
5
5
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
6
  const OcsWidgetAvatar = () => {
@@ -5065,7 +5065,8 @@ class FileAttachmentManager {
5065
5065
  let totalSize = existingFiles.reduce((sum, f) => sum + f.file.size, 0);
5066
5066
  for (const file of fileArray) {
5067
5067
  const extension = this.getFileExtension(file.name);
5068
- if (!this.supportedExtensions.includes(extension)) {
5068
+ const contentType = file.type.split("/")[0];
5069
+ if (contentType != "text" && !this.supportedExtensions.includes(extension)) {
5069
5070
  newSelected.push({ file, error: `File type ${extension} not supported` });
5070
5071
  continue;
5071
5072
  }
@@ -5399,6 +5400,7 @@ const OcsChat = class {
5399
5400
  }
5400
5401
  this.parseWelcomeMessages();
5401
5402
  this.parseStarterQuestions();
5403
+ this.loadInternalPageContext();
5402
5404
  }
5403
5405
  componentDidLoad() {
5404
5406
  const computedStyle = getComputedStyle(this.host);
@@ -5491,6 +5493,16 @@ const OcsChat = class {
5491
5493
  }
5492
5494
  this.translationManager = new TranslationManager(this.language, customTranslationsObj);
5493
5495
  }
5496
+ loadInternalPageContext() {
5497
+ if (this.pageContext === undefined || this.pageContext === null) {
5498
+ return;
5499
+ }
5500
+ if (typeof this.pageContext !== 'object' || Array.isArray(this.pageContext)) {
5501
+ console.error("pageContext is expected to be a plain JavaScript object.");
5502
+ return;
5503
+ }
5504
+ this.internalPageContext = this.pageContext;
5505
+ }
5494
5506
  async loadTranslationsFromUrl(url) {
5495
5507
  try {
5496
5508
  const response = await fetch(url);
@@ -5623,10 +5635,14 @@ const OcsChat = class {
5623
5635
  if (this.allowAttachments && attachmentIds.length > 0) {
5624
5636
  requestBody.attachment_ids = attachmentIds;
5625
5637
  }
5638
+ if (this.internalPageContext) {
5639
+ requestBody.context = this.internalPageContext;
5640
+ }
5626
5641
  const data = await this.getChatService().sendMessage(this.sessionId, requestBody);
5627
5642
  if (data.status === 'error') {
5628
5643
  throw new Error(data.error || 'Failed to send message');
5629
5644
  }
5645
+ this.internalPageContext = undefined;
5630
5646
  this.startTaskPolling(data.task_id);
5631
5647
  }
5632
5648
  catch (error) {
@@ -5713,6 +5729,14 @@ const OcsChat = class {
5713
5729
  toggleWindowVisibility() {
5714
5730
  this.visible = !this.visible;
5715
5731
  }
5732
+ /**
5733
+ * Watch for changes to the `pageContext` prop and sync to internal variable.
5734
+ *
5735
+ * @param pageContext - The new value for the field.
5736
+ */
5737
+ pageContextHandler() {
5738
+ this.loadInternalPageContext();
5739
+ }
5716
5740
  /**
5717
5741
  * Watch for changes to the `visible` attribute and update accordingly.
5718
5742
  *
@@ -6272,12 +6296,13 @@ const OcsChat = class {
6272
6296
  if (el) {
6273
6297
  this.fileInputRef = el;
6274
6298
  }
6275
- }, 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()
6299
+ }, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(',') + ',text/*', 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()
6276
6300
  ? 'send-button-enabled'
6277
6301
  : '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"))))))));
6278
6302
  }
6279
6303
  get host() { return index.getElement(this); }
6280
6304
  static get watchers() { return {
6305
+ "pageContext": ["pageContextHandler"],
6281
6306
  "visible": ["visibilityHandler"]
6282
6307
  }; }
6283
6308
  };
@@ -6291,8 +6316,9 @@ OcsChat.WINDOW_MARGIN = 20;
6291
6316
  OcsChat.LOCALSTORAGE_TEST_KEY = '__ocs_test__';
6292
6317
  OcsChat.MAX_FILE_SIZE_MB = 50;
6293
6318
  OcsChat.MAX_TOTAL_SIZE_MB = 50;
6294
- OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg', '.jpeg',
6295
- '.png', '.gif', '.bmp', '.webp', '.svg', '.mp4', '.mov', '.avi', '.mp3', '.wav'];
6319
+ OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg',
6320
+ '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.mp4', '.mov', '.avi', '.mp3', '.wav', '.html', '.htm', '.css',
6321
+ '.js', '.xml', '.md', '.ics', '.vcf', '.rtf', '.tsv', '.yaml', '.yml', '.py', '.c'];
6296
6322
  OcsChat.style = ocsChatCss;
6297
6323
 
6298
6324
  exports.open_chat_studio_widget = OcsChat;