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,11 +1,11 @@
1
- import { b as bootstrapLazy } from './index-BbCwiO7g.js';
2
- export { s as setNonce } from './index-BbCwiO7g.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-BbCwiO7g.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 = () => {
@@ -4933,7 +4933,9 @@ class ChatSessionService {
4933
4933
  return response.json();
4934
4934
  }
4935
4935
  async pollTaskOnce(sessionId, taskId) {
4936
- const response = await fetch(`${this.apiBaseUrl}/api/chat/${sessionId}/${taskId}/poll/`);
4936
+ const response = await fetch(`${this.apiBaseUrl}/api/chat/${sessionId}/${taskId}/poll/`, {
4937
+ headers: this.getCommonHeaders(),
4938
+ });
4937
4939
  if (!response.ok) {
4938
4940
  throw new Error(`Failed to poll task: ${response.statusText}`);
4939
4941
  }
@@ -4991,7 +4993,9 @@ class ChatSessionService {
4991
4993
  if (since) {
4992
4994
  url.searchParams.set('since', since);
4993
4995
  }
4994
- const response = await fetch(url.toString());
4996
+ const response = await fetch(url.toString(), {
4997
+ headers: this.getCommonHeaders(),
4998
+ });
4995
4999
  if (!response.ok) {
4996
5000
  throw new Error(`Failed to poll messages: ${response.statusText}`);
4997
5001
  }
@@ -5028,14 +5032,18 @@ class ChatSessionService {
5028
5032
  }
5029
5033
  }
5030
5034
  getJsonHeaders() {
5031
- const headers = {
5032
- 'Content-Type': 'application/json',
5033
- 'x-ocs-widget-version': this.widgetVersion,
5034
- };
5035
+ const headers = this.getCommonHeaders();
5036
+ headers['Content-Type'] = 'application/json';
5035
5037
  const csrfToken = this.csrfTokenProvider(this.apiBaseUrl);
5036
5038
  if (csrfToken) {
5037
5039
  headers['X-CSRFToken'] = csrfToken;
5038
5040
  }
5041
+ return headers;
5042
+ }
5043
+ getCommonHeaders() {
5044
+ const headers = {
5045
+ 'x-ocs-widget-version': this.widgetVersion,
5046
+ };
5039
5047
  if (this.embedKey) {
5040
5048
  headers['X-Embed-Key'] = this.embedKey;
5041
5049
  }
@@ -5055,7 +5063,8 @@ class FileAttachmentManager {
5055
5063
  let totalSize = existingFiles.reduce((sum, f) => sum + f.file.size, 0);
5056
5064
  for (const file of fileArray) {
5057
5065
  const extension = this.getFileExtension(file.name);
5058
- if (!this.supportedExtensions.includes(extension)) {
5066
+ const contentType = file.type.split("/")[0];
5067
+ if (contentType != "text" && !this.supportedExtensions.includes(extension)) {
5059
5068
  newSelected.push({ file, error: `File type ${extension} not supported` });
5060
5069
  continue;
5061
5070
  }
@@ -5389,6 +5398,7 @@ const OcsChat = class {
5389
5398
  }
5390
5399
  this.parseWelcomeMessages();
5391
5400
  this.parseStarterQuestions();
5401
+ this.loadInternalPageContext();
5392
5402
  }
5393
5403
  componentDidLoad() {
5394
5404
  const computedStyle = getComputedStyle(this.host);
@@ -5481,6 +5491,16 @@ const OcsChat = class {
5481
5491
  }
5482
5492
  this.translationManager = new TranslationManager(this.language, customTranslationsObj);
5483
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
+ }
5484
5504
  async loadTranslationsFromUrl(url) {
5485
5505
  try {
5486
5506
  const response = await fetch(url);
@@ -5613,10 +5633,14 @@ const OcsChat = class {
5613
5633
  if (this.allowAttachments && attachmentIds.length > 0) {
5614
5634
  requestBody.attachment_ids = attachmentIds;
5615
5635
  }
5636
+ if (this.internalPageContext) {
5637
+ requestBody.context = this.internalPageContext;
5638
+ }
5616
5639
  const data = await this.getChatService().sendMessage(this.sessionId, requestBody);
5617
5640
  if (data.status === 'error') {
5618
5641
  throw new Error(data.error || 'Failed to send message');
5619
5642
  }
5643
+ this.internalPageContext = undefined;
5620
5644
  this.startTaskPolling(data.task_id);
5621
5645
  }
5622
5646
  catch (error) {
@@ -5703,6 +5727,14 @@ const OcsChat = class {
5703
5727
  toggleWindowVisibility() {
5704
5728
  this.visible = !this.visible;
5705
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
+ }
5706
5738
  /**
5707
5739
  * Watch for changes to the `visible` attribute and update accordingly.
5708
5740
  *
@@ -6262,12 +6294,13 @@ const OcsChat = class {
6262
6294
  if (el) {
6263
6295
  this.fileInputRef = el;
6264
6296
  }
6265
- }, 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()
6266
6298
  ? 'send-button-enabled'
6267
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"))))))));
6268
6300
  }
6269
6301
  get host() { return getElement(this); }
6270
6302
  static get watchers() { return {
6303
+ "pageContext": ["pageContextHandler"],
6271
6304
  "visible": ["visibilityHandler"]
6272
6305
  }; }
6273
6306
  };
@@ -6281,8 +6314,9 @@ OcsChat.WINDOW_MARGIN = 20;
6281
6314
  OcsChat.LOCALSTORAGE_TEST_KEY = '__ocs_test__';
6282
6315
  OcsChat.MAX_FILE_SIZE_MB = 50;
6283
6316
  OcsChat.MAX_TOTAL_SIZE_MB = 50;
6284
- OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg', '.jpeg',
6285
- '.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'];
6286
6320
  OcsChat.style = ocsChatCss;
6287
6321
 
6288
6322
  export { OcsChat as open_chat_studio_widget };