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,11 +1,11 @@
1
- import { b as bootstrapLazy } from './index-C53whb-B.js';
2
- export { s as setNonce } from './index-C53whb-B.js';
1
+ import { b as bootstrapLazy } from './index-BKVXO_5E.js';
2
+ export { s as setNonce } from './index-BKVXO_5E.js';
3
3
  import { g as globalScripts } from './app-globals-DQuL1Twl.js';
4
4
 
5
5
  const defineCustomElements = async (win, options) => {
6
6
  if (typeof window === 'undefined') return undefined;
7
7
  await globalScripts();
8
- return bootstrapLazy([["open-chat-studio-widget",[[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);
8
+ return bootstrapLazy([["open-chat-studio-widget",[[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);
9
9
  };
10
10
 
11
11
  export { defineCustomElements };
@@ -1,4 +1,4 @@
1
- import { h, r as registerInstance, E as Env, H as Host, g as getElement } from './index-C53whb-B.js';
1
+ import { h, r as registerInstance, E as Env, H as Host, g as getElement } from './index-BKVXO_5E.js';
2
2
 
3
3
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
4
  const OcsWidgetAvatar = () => {
@@ -5063,7 +5063,8 @@ class FileAttachmentManager {
5063
5063
  let totalSize = existingFiles.reduce((sum, f) => sum + f.file.size, 0);
5064
5064
  for (const file of fileArray) {
5065
5065
  const extension = this.getFileExtension(file.name);
5066
- if (!this.supportedExtensions.includes(extension)) {
5066
+ const contentType = file.type.split("/")[0];
5067
+ if (contentType != "text" && !this.supportedExtensions.includes(extension)) {
5067
5068
  newSelected.push({ file, error: `File type ${extension} not supported` });
5068
5069
  continue;
5069
5070
  }
@@ -5397,6 +5398,7 @@ const OcsChat = class {
5397
5398
  }
5398
5399
  this.parseWelcomeMessages();
5399
5400
  this.parseStarterQuestions();
5401
+ this.loadInternalPageContext();
5400
5402
  }
5401
5403
  componentDidLoad() {
5402
5404
  const computedStyle = getComputedStyle(this.host);
@@ -5489,6 +5491,16 @@ const OcsChat = class {
5489
5491
  }
5490
5492
  this.translationManager = new TranslationManager(this.language, customTranslationsObj);
5491
5493
  }
5494
+ loadInternalPageContext() {
5495
+ if (this.pageContext === undefined || this.pageContext === null) {
5496
+ return;
5497
+ }
5498
+ if (typeof this.pageContext !== 'object' || Array.isArray(this.pageContext)) {
5499
+ console.error("pageContext is expected to be a plain JavaScript object.");
5500
+ return;
5501
+ }
5502
+ this.internalPageContext = this.pageContext;
5503
+ }
5492
5504
  async loadTranslationsFromUrl(url) {
5493
5505
  try {
5494
5506
  const response = await fetch(url);
@@ -5621,10 +5633,14 @@ const OcsChat = class {
5621
5633
  if (this.allowAttachments && attachmentIds.length > 0) {
5622
5634
  requestBody.attachment_ids = attachmentIds;
5623
5635
  }
5636
+ if (this.internalPageContext) {
5637
+ requestBody.context = this.internalPageContext;
5638
+ }
5624
5639
  const data = await this.getChatService().sendMessage(this.sessionId, requestBody);
5625
5640
  if (data.status === 'error') {
5626
5641
  throw new Error(data.error || 'Failed to send message');
5627
5642
  }
5643
+ this.internalPageContext = undefined;
5628
5644
  this.startTaskPolling(data.task_id);
5629
5645
  }
5630
5646
  catch (error) {
@@ -5711,6 +5727,14 @@ const OcsChat = class {
5711
5727
  toggleWindowVisibility() {
5712
5728
  this.visible = !this.visible;
5713
5729
  }
5730
+ /**
5731
+ * Watch for changes to the `pageContext` prop and sync to internal variable.
5732
+ *
5733
+ * @param pageContext - The new value for the field.
5734
+ */
5735
+ pageContextHandler() {
5736
+ this.loadInternalPageContext();
5737
+ }
5714
5738
  /**
5715
5739
  * Watch for changes to the `visible` attribute and update accordingly.
5716
5740
  *
@@ -6270,12 +6294,13 @@ const OcsChat = class {
6270
6294
  if (el) {
6271
6295
  this.fileInputRef = el;
6272
6296
  }
6273
- }, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(','), onChange: (e) => this.handleFileSelect(e), class: "hidden" })), this.allowAttachments && (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') }, h(PaperClipIcon, null))), h("button", { class: `send-button ${!this.isTyping && !this.isLoading && !!this.messageInput.trim()
6297
+ }, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(',') + ',text/*', onChange: (e) => this.handleFileSelect(e), class: "hidden" })), this.allowAttachments && (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') }, h(PaperClipIcon, null))), h("button", { class: `send-button ${!this.isTyping && !this.isLoading && !!this.messageInput.trim()
6274
6298
  ? 'send-button-enabled'
6275
6299
  : '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')))), h("div", { class: "flex items-center justify-center text-[0.8em] font-light w-full text-slate-500 py-[2px]" }, h("p", null, this.translationManager.get('branding.poweredBy'), ' ', " ", h("a", { class: "underline", href: "https://www.dimagi.com", target: "_blank" }, "Dimagi"))))))));
6276
6300
  }
6277
6301
  get host() { return getElement(this); }
6278
6302
  static get watchers() { return {
6303
+ "pageContext": ["pageContextHandler"],
6279
6304
  "visible": ["visibilityHandler"]
6280
6305
  }; }
6281
6306
  };
@@ -6289,8 +6314,9 @@ OcsChat.WINDOW_MARGIN = 20;
6289
6314
  OcsChat.LOCALSTORAGE_TEST_KEY = '__ocs_test__';
6290
6315
  OcsChat.MAX_FILE_SIZE_MB = 50;
6291
6316
  OcsChat.MAX_TOTAL_SIZE_MB = 50;
6292
- OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg', '.jpeg',
6293
- '.png', '.gif', '.bmp', '.webp', '.svg', '.mp4', '.mov', '.avi', '.mp3', '.wav'];
6317
+ OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg',
6318
+ '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.mp4', '.mov', '.avi', '.mp3', '.wav', '.html', '.htm', '.css',
6319
+ '.js', '.xml', '.md', '.ics', '.vcf', '.rtf', '.tsv', '.yaml', '.yml', '.py', '.c'];
6294
6320
  OcsChat.style = ocsChatCss;
6295
6321
 
6296
6322
  export { OcsChat as open_chat_studio_widget };