open-chat-studio-widget 0.5.2 → 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 (34) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/{index-Ctja7z-R.js → index-CcvroTR_.js} +3 -3
  3. package/dist/cjs/{index-Ctja7z-R.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 +45 -11
  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/chat-session-service.js +14 -6
  12. package/dist/collection/services/chat-session-service.js.map +1 -1
  13. package/dist/collection/services/file-attachment-manager.js +2 -1
  14. package/dist/collection/services/file-attachment-manager.js.map +1 -1
  15. package/dist/components/open-chat-studio-widget.js +46 -10
  16. package/dist/components/open-chat-studio-widget.js.map +1 -1
  17. package/dist/esm/{index-BbCwiO7g.js → index-BKVXO_5E.js} +3 -3
  18. package/dist/esm/{index-BbCwiO7g.js.map → index-BKVXO_5E.js.map} +1 -1
  19. package/dist/esm/loader.js +3 -3
  20. package/dist/esm/open-chat-studio-widget.entry.js +45 -11
  21. package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
  22. package/dist/esm/open-chat-studio-widget.js +3 -3
  23. package/dist/open-chat-studio-widget/open-chat-studio-widget.entry.esm.js.map +1 -1
  24. package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
  25. package/dist/open-chat-studio-widget/{p-BbCwiO7g.js → p-BKVXO_5E.js} +2 -2
  26. package/dist/open-chat-studio-widget/{p-BbCwiO7g.js.map → p-BKVXO_5E.js.map} +1 -1
  27. package/dist/open-chat-studio-widget/p-a0d04423.entry.js +4 -0
  28. package/dist/open-chat-studio-widget/p-a0d04423.entry.js.map +1 -0
  29. package/dist/types/components/ocs-chat/ocs-chat.d.ts +12 -0
  30. package/dist/types/components.d.ts +8 -0
  31. package/dist/types/services/chat-session-service.d.ts +1 -0
  32. package/package.json +1 -1
  33. package/dist/open-chat-studio-widget/p-96920183.entry.js +0 -4
  34. package/dist/open-chat-studio-widget/p-96920183.entry.js.map +0 -1
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-Ctja7z-R.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-Ctja7z-R.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 = () => {
@@ -4935,7 +4935,9 @@ class ChatSessionService {
4935
4935
  return response.json();
4936
4936
  }
4937
4937
  async pollTaskOnce(sessionId, taskId) {
4938
- const response = await fetch(`${this.apiBaseUrl}/api/chat/${sessionId}/${taskId}/poll/`);
4938
+ const response = await fetch(`${this.apiBaseUrl}/api/chat/${sessionId}/${taskId}/poll/`, {
4939
+ headers: this.getCommonHeaders(),
4940
+ });
4939
4941
  if (!response.ok) {
4940
4942
  throw new Error(`Failed to poll task: ${response.statusText}`);
4941
4943
  }
@@ -4993,7 +4995,9 @@ class ChatSessionService {
4993
4995
  if (since) {
4994
4996
  url.searchParams.set('since', since);
4995
4997
  }
4996
- const response = await fetch(url.toString());
4998
+ const response = await fetch(url.toString(), {
4999
+ headers: this.getCommonHeaders(),
5000
+ });
4997
5001
  if (!response.ok) {
4998
5002
  throw new Error(`Failed to poll messages: ${response.statusText}`);
4999
5003
  }
@@ -5030,14 +5034,18 @@ class ChatSessionService {
5030
5034
  }
5031
5035
  }
5032
5036
  getJsonHeaders() {
5033
- const headers = {
5034
- 'Content-Type': 'application/json',
5035
- 'x-ocs-widget-version': this.widgetVersion,
5036
- };
5037
+ const headers = this.getCommonHeaders();
5038
+ headers['Content-Type'] = 'application/json';
5037
5039
  const csrfToken = this.csrfTokenProvider(this.apiBaseUrl);
5038
5040
  if (csrfToken) {
5039
5041
  headers['X-CSRFToken'] = csrfToken;
5040
5042
  }
5043
+ return headers;
5044
+ }
5045
+ getCommonHeaders() {
5046
+ const headers = {
5047
+ 'x-ocs-widget-version': this.widgetVersion,
5048
+ };
5041
5049
  if (this.embedKey) {
5042
5050
  headers['X-Embed-Key'] = this.embedKey;
5043
5051
  }
@@ -5057,7 +5065,8 @@ class FileAttachmentManager {
5057
5065
  let totalSize = existingFiles.reduce((sum, f) => sum + f.file.size, 0);
5058
5066
  for (const file of fileArray) {
5059
5067
  const extension = this.getFileExtension(file.name);
5060
- if (!this.supportedExtensions.includes(extension)) {
5068
+ const contentType = file.type.split("/")[0];
5069
+ if (contentType != "text" && !this.supportedExtensions.includes(extension)) {
5061
5070
  newSelected.push({ file, error: `File type ${extension} not supported` });
5062
5071
  continue;
5063
5072
  }
@@ -5391,6 +5400,7 @@ const OcsChat = class {
5391
5400
  }
5392
5401
  this.parseWelcomeMessages();
5393
5402
  this.parseStarterQuestions();
5403
+ this.loadInternalPageContext();
5394
5404
  }
5395
5405
  componentDidLoad() {
5396
5406
  const computedStyle = getComputedStyle(this.host);
@@ -5483,6 +5493,16 @@ const OcsChat = class {
5483
5493
  }
5484
5494
  this.translationManager = new TranslationManager(this.language, customTranslationsObj);
5485
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
+ }
5486
5506
  async loadTranslationsFromUrl(url) {
5487
5507
  try {
5488
5508
  const response = await fetch(url);
@@ -5615,10 +5635,14 @@ const OcsChat = class {
5615
5635
  if (this.allowAttachments && attachmentIds.length > 0) {
5616
5636
  requestBody.attachment_ids = attachmentIds;
5617
5637
  }
5638
+ if (this.internalPageContext) {
5639
+ requestBody.context = this.internalPageContext;
5640
+ }
5618
5641
  const data = await this.getChatService().sendMessage(this.sessionId, requestBody);
5619
5642
  if (data.status === 'error') {
5620
5643
  throw new Error(data.error || 'Failed to send message');
5621
5644
  }
5645
+ this.internalPageContext = undefined;
5622
5646
  this.startTaskPolling(data.task_id);
5623
5647
  }
5624
5648
  catch (error) {
@@ -5705,6 +5729,14 @@ const OcsChat = class {
5705
5729
  toggleWindowVisibility() {
5706
5730
  this.visible = !this.visible;
5707
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
+ }
5708
5740
  /**
5709
5741
  * Watch for changes to the `visible` attribute and update accordingly.
5710
5742
  *
@@ -6264,12 +6296,13 @@ const OcsChat = class {
6264
6296
  if (el) {
6265
6297
  this.fileInputRef = el;
6266
6298
  }
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()
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()
6268
6300
  ? 'send-button-enabled'
6269
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"))))))));
6270
6302
  }
6271
6303
  get host() { return index.getElement(this); }
6272
6304
  static get watchers() { return {
6305
+ "pageContext": ["pageContextHandler"],
6273
6306
  "visible": ["visibilityHandler"]
6274
6307
  }; }
6275
6308
  };
@@ -6283,8 +6316,9 @@ OcsChat.WINDOW_MARGIN = 20;
6283
6316
  OcsChat.LOCALSTORAGE_TEST_KEY = '__ocs_test__';
6284
6317
  OcsChat.MAX_FILE_SIZE_MB = 50;
6285
6318
  OcsChat.MAX_TOTAL_SIZE_MB = 50;
6286
- OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg', '.jpeg',
6287
- '.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'];
6288
6322
  OcsChat.style = ocsChatCss;
6289
6323
 
6290
6324
  exports.open_chat_studio_widget = OcsChat;