@opencx/widget 3.0.42 → 3.0.44

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 +4 -0
  2. package/dist/designs.cjs +51 -51
  3. package/dist/designs.cjs.map +1 -1
  4. package/dist/designs.js +3116 -3090
  5. package/dist/designs.js.map +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/react.cjs +1 -1
  9. package/dist/react.js +2 -2
  10. package/dist/src/designs/translation/translation.types.d.ts +1 -1
  11. package/dist/src/headless/core/context/contact.ctx.d.ts +2 -1
  12. package/dist/src/headless/core/context/message.ctx.d.ts +8 -3
  13. package/dist/src/headless/core/index.d.ts +1 -1
  14. package/dist/src/headless/core/types/helpers.d.ts +0 -2
  15. package/dist/src/headless/core/types/widget-config.d.ts +67 -15
  16. package/dist/src/headless/react/hooks/useContact.d.ts +2 -1
  17. package/dist/src/headless/react/hooks/useMessages.d.ts +4 -1
  18. package/dist/{useUploadFiles-BmEispgd.js → useUploadFiles-BPZLXbFK.js} +3 -3
  19. package/dist/{useUploadFiles-BmEispgd.js.map → useUploadFiles-BPZLXbFK.js.map} +1 -1
  20. package/dist/{useUploadFiles-eYRjtkaZ.cjs → useUploadFiles-Bt32Tf5N.cjs} +2 -2
  21. package/dist/{useUploadFiles-eYRjtkaZ.cjs.map → useUploadFiles-Bt32Tf5N.cjs.map} +1 -1
  22. package/dist/{widget.ctx-DIcAO9ZA.js → widget.ctx-Db_LSB7d.js} +81 -64
  23. package/dist/widget.ctx-Db_LSB7d.js.map +1 -0
  24. package/dist/widget.ctx-Z3nrC8tP.cjs +5 -0
  25. package/dist/widget.ctx-Z3nrC8tP.cjs.map +1 -0
  26. package/dist-embed/script.js +43 -40
  27. package/dist-embed/script.js.map +1 -1
  28. package/package.json +1 -1
  29. package/dist/widget.ctx-DB_VxiMQ.cjs +0 -2
  30. package/dist/widget.ctx-DB_VxiMQ.cjs.map +0 -1
  31. package/dist/widget.ctx-DIcAO9ZA.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./widget.ctx-DB_VxiMQ.cjs");exports.PrimitiveState=t.PrimitiveState;exports.WidgetCtx=t.WidgetCtx;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./widget.ctx-Z3nrC8tP.cjs");exports.PrimitiveState=t.PrimitiveState;exports.WidgetCtx=t.WidgetCtx;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { P as i, W as a } from "./widget.ctx-DIcAO9ZA.js";
1
+ import { P as i, W as a } from "./widget.ctx-Db_LSB7d.js";
2
2
  export {
3
3
  i as PrimitiveState,
4
4
  a as WidgetCtx
package/dist/react.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useUploadFiles-eYRjtkaZ.cjs");function a(t,s,u){const{widgetCtx:{api:i}}=e.useWidget();return e._default(async o=>i.vote({action:o==="up"?"upvote":"downvote",messagePublicId:t,sessionId:s}).then(u),[i,t,s,u])}exports.WidgetProvider=e.WidgetProvider;exports.useConfig=e.useConfig;exports.useContact=e.useContact;exports.useIsAwaitingBotReply=e.useIsAwaitingBotReply;exports.useMessages=e.useMessages;exports.usePreludeData=e.usePreludeData;exports.usePrimitiveState=e.usePrimitiveState;exports.useSessions=e.useSessions;exports.useUploadFiles=e.useUploadFiles;exports.useWidget=e.useWidget;exports.useWidgetRouter=e.useWidgetRouter;exports.useVote=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useUploadFiles-Bt32Tf5N.cjs");function a(t,s,u){const{widgetCtx:{api:i}}=e.useWidget();return e._default(async o=>i.vote({action:o==="up"?"upvote":"downvote",messagePublicId:t,sessionId:s}).then(u),[i,t,s,u])}exports.WidgetProvider=e.WidgetProvider;exports.useConfig=e.useConfig;exports.useContact=e.useContact;exports.useIsAwaitingBotReply=e.useIsAwaitingBotReply;exports.useMessages=e.useMessages;exports.usePreludeData=e.usePreludeData;exports.usePrimitiveState=e.usePrimitiveState;exports.useSessions=e.useSessions;exports.useUploadFiles=e.useUploadFiles;exports.useWidget=e.useWidget;exports.useWidgetRouter=e.useWidgetRouter;exports.useVote=a;
2
2
  //# sourceMappingURL=react.cjs.map
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
- import { u as o, _ as i } from "./useUploadFiles-BmEispgd.js";
2
- import { W as p, a as f, b as l, c, d as m, e as v, f as P, g as W, i as w, h as x } from "./useUploadFiles-BmEispgd.js";
1
+ import { u as o, _ as i } from "./useUploadFiles-BPZLXbFK.js";
2
+ import { W as p, a as f, b as l, c, d as m, e as v, f as P, g as W, i as w, h as x } from "./useUploadFiles-BPZLXbFK.js";
3
3
  function n(e, s, t) {
4
4
  const {
5
5
  widgetCtx: { api: a }
@@ -1,4 +1,4 @@
1
- export type TranslationKeysU = "ok" | "yes" | "no" | "agree" | "cancel" | "yes-exit" | "yes-reset" | "no-cancel" | "are-you-sure" | "recording" | "thank-you" | "sorry-try-again" | "error-occurred" | "please-try-again" | "write-a-message" | "send-message" | "connected" | "connecting" | "reconnecting" | "reconnected" | "disconnecting" | "disconnected" | "error" | "persist-session" | "settings" | "close" | "help" | "chat" | "send" | "copy" | "copied" | "sound-effects" | "language" | "select" | "agent" | "user" | "bot" | "close-widget" | "got-any-questions" | "typical-response-time" | "session-closed-lead" | "create-new-ticket" | "exit" | "reset-conversation" | "new-conversation" | "welcome-title" | "welcome-description" | "your-name" | "your-email" | "start-chat" | "starting-chat" | "hello-greeting" | "i-need-more-help" | "this-was-helpful";
1
+ export type TranslationKeysU = "ok" | "yes" | "no" | "agree" | "cancel" | "yes-exit" | "yes-reset" | "no-cancel" | "are-you-sure" | "recording" | "thank-you" | "sorry-try-again" | "error-occurred" | "please-try-again" | "write-a-message" | "send-message" | "connected" | "connecting" | "reconnecting" | "reconnected" | "disconnecting" | "disconnected" | "error" | "persist-session" | "settings" | "close" | "help" | "chat" | "send" | "copy" | "copied" | "sound-effects" | "language" | "select" | "agent" | "user" | "bot" | "close-widget" | "got-any-questions" | "typical-response-time" | "session-closed-lead" | "create-new-ticket" | "exit" | "reset-conversation" | "new-conversation" | "welcome-title" | "welcome-description" | "your-name" | "your-email" | "start-chat" | "starting-chat" | "hello-greeting" | "i-need-more-help" | "this-was-helpful" | "optional";
2
2
  export type TranslationInterface = {
3
3
  [K in TranslationKeysU]: string;
4
4
  };
@@ -8,6 +8,7 @@ type ContactState = {
8
8
  token: string;
9
9
  externalId: string | undefined;
10
10
  } | null;
11
+ extraCollectedData: Record<string, string> | undefined;
11
12
  isCreatingUnverifiedContact: boolean;
12
13
  isErrorCreatingUnverifiedContact: boolean;
13
14
  };
@@ -23,7 +24,7 @@ export declare class ContactCtx {
23
24
  });
24
25
  shouldCollectData: () => boolean;
25
26
  private autoCreateUnverifiedUserIfNotExists;
26
- createUnverifiedContact: (payload: Dto["CreateUnverifiedContactDto"]) => Promise<void>;
27
+ createUnverifiedContact: (payload: Dto["CreateUnverifiedContactDto"], extraCollectedData?: Record<string, string>) => Promise<void>;
27
28
  setUnverifiedContact: (token: string) => Promise<void>;
28
29
  }
29
30
  export {};
@@ -1,10 +1,10 @@
1
1
  import { ApiCaller } from '../api/api-caller';
2
2
  import { WidgetConfig } from '../types/widget-config';
3
- import { SafeOmit, SomeOptional } from '../types/helpers';
4
3
  import { MessageType } from '../types/messages';
5
4
  import { SendMessageDto } from '../types/schemas';
6
5
  import { PrimitiveState } from '../utils/PrimitiveState';
7
6
  import { SessionCtx } from './session.ctx';
7
+ import { ContactCtx } from './contact.ctx';
8
8
  type MessageCtxState = {
9
9
  messages: MessageType[];
10
10
  isSendingMessage: boolean;
@@ -14,16 +14,21 @@ type MessageCtxState = {
14
14
  export declare class MessageCtx {
15
15
  private config;
16
16
  private api;
17
+ private contactCtx;
17
18
  private sessionCtx;
18
19
  state: PrimitiveState<MessageCtxState>;
19
20
  private sendMessageAbortController;
20
- constructor({ config, api, sessionCtx, }: {
21
+ constructor({ config, api, sessionCtx, contactCtx, }: {
21
22
  config: WidgetConfig;
22
23
  api: ApiCaller;
23
24
  sessionCtx: SessionCtx;
25
+ contactCtx: ContactCtx;
24
26
  });
25
27
  reset: () => void;
26
- sendMessage: (input: SomeOptional<SafeOmit<SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
28
+ sendMessage: (input: {
29
+ content: SendMessageDto["content"];
30
+ attachments?: SendMessageDto["attachments"];
31
+ }) => Promise<void>;
27
32
  private toUserMessage;
28
33
  private toBotMessage;
29
34
  private toBotErrorMessage;
@@ -1,5 +1,5 @@
1
1
  export type { AgentOrBotType } from './types/agent-or-bot';
2
- export type { SafeExtract, SafeOmit, SomeOptional, StringOrLiteral, } from './types/helpers';
2
+ export type { SafeExtract, StringOrLiteral, } from './types/helpers';
3
3
  export type { WidgetComponentKey, UserMessageType, AgentMessageType, BotMessageType, MessageType, } from './types/messages';
4
4
  export type { MessageAttachmentType, MessageDto, PreludeDto, SendMessageDto, SendMessageOutputDto, SessionDto, VoteInputDto, VoteOutputDto, } from './types/schemas';
5
5
  export type { WidgetConfig } from './types/widget-config';
@@ -1,4 +1,2 @@
1
- export type SomeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
2
- export type SafeOmit<T, K extends keyof T> = Omit<T, K>;
3
1
  export type SafeExtract<T, K extends T> = Extract<T, K>;
4
2
  export type StringOrLiteral<T extends string> = T | (string & {});
@@ -20,28 +20,80 @@ export type UserConfig = UserBaseConfig & {
20
20
  externalId?: string;
21
21
  };
22
22
  export interface WidgetConfig {
23
+ /**
24
+ * Your organization's widget token.
25
+ * Can be found in the dashboard in the web widget page.
26
+ */
23
27
  token: string;
24
- apiUrl?: string;
25
- headers?: Record<string, string>;
26
- queryParams?: Record<string, string>;
27
- collectUserData?: boolean;
28
- debug?: boolean;
29
- initialMessages?: string[];
28
+ /**
29
+ * The language of the widget.
30
+ * Translations are available in the default non-headless widget.
31
+ * Check available translations in `src/designs/translation`
32
+ * @default en
33
+ */
30
34
  language?: string;
31
- user?: UserConfig;
32
- bot?: AgentOrBotType;
33
- soundEffectsUrls?: {
34
- messageArrived?: string;
35
- };
35
+ /**
36
+ * A name and an avatar for the bot.
37
+ */
38
+ bot?: Pick<AgentOrBotType, "name" | "avatar">;
36
39
  theme?: {
37
40
  primaryColor?: string;
38
41
  };
39
- settings?: {
40
- persistSession?: boolean;
41
- playSoundEffects?: boolean;
42
- };
43
42
  assets?: {
44
43
  organizationLogo?: string;
45
44
  };
45
+ /**
46
+ * Initial messages that the contact sees in a new chat session.
47
+ * These messages will disappear once the contact sends their first message.
48
+ */
49
+ initialMessages?: string[];
50
+ /**
51
+ * If turned on, the widget will have a login-like screen to collect user's name and email.
52
+ * A non-verified contact will be created based on the provided information.
53
+ * @default false
54
+ */
55
+ collectUserData?: boolean;
56
+ /**
57
+ * Extra data collection fields besides `name` and `email`.
58
+ * For this setting to take effect, `collectUserData` must be set to `true`.
59
+ *
60
+ * Not to be confused with `WidgetConfig.user.data.customData`,
61
+ * the purpose of `extraDataCollectionFields` is to provide context to the session,
62
+ * the data collected will be prepended in the first contact message in a session.
63
+ *
64
+ * @default undefined
65
+ */
66
+ extraDataCollectionFields?: string[];
67
+ /**
68
+ * Verified or non-verified contact data.
69
+ * To know more, check the README
70
+ * @default undefined
71
+ */
72
+ user?: UserConfig;
73
+ /**
74
+ * Headers to be sent with each send-message request from the widget.
75
+ * These headers will be sent with each AI action (AI tools) that the LLM can call.
76
+ * This is useful if your AI actions require authentication specific to each contact.
77
+ * @default undefined
78
+ */
79
+ headers?: Record<string, string>;
80
+ /**
81
+ * Query params to be sent with each send-message request from the widget.
82
+ * These query params will be sent with each AI action (AI tools) that the LLM can call.
83
+ * This is useful if you want to send extra information with each AI action.
84
+ * @default undefined
85
+ */
86
+ queryParams?: Record<string, string>;
87
+ /**
88
+ * Turn on to see the debug info attached to the AI responses.
89
+ * @default false
90
+ */
91
+ debug?: boolean;
92
+ /**
93
+ * An apiUrl to override production backend.
94
+ * This is for us to test the widget locally, you don't need to play with this option 😊.
95
+ * @default https://api.open.cx
96
+ */
97
+ apiUrl?: string;
46
98
  }
47
99
  export {};
@@ -4,8 +4,9 @@ export declare function useContact(): {
4
4
  token: string;
5
5
  externalId: string | undefined;
6
6
  } | null;
7
+ extraCollectedData: Record<string, string> | undefined;
7
8
  isCreatingUnverifiedContact: boolean;
8
9
  isErrorCreatingUnverifiedContact: boolean;
9
10
  };
10
- createUnverifiedContact: (payload: import('../../core/api/client').Dto["CreateUnverifiedContactDto"]) => Promise<void>;
11
+ createUnverifiedContact: (payload: import('../../core/api/client').Dto["CreateUnverifiedContactDto"], extraCollectedData?: Record<string, string>) => Promise<void>;
11
12
  };
@@ -5,5 +5,8 @@ export declare function useMessages(): {
5
5
  lastAIResMightSolveUserIssue: boolean;
6
6
  isInitialFetchLoading: boolean;
7
7
  };
8
- sendMessage: (input: import('../../core').SomeOptional<import('../../core').SafeOmit<import('../../core').SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
8
+ sendMessage: (input: {
9
+ content: import('../../core').SendMessageDto["content"];
10
+ attachments?: import('../../core').SendMessageDto["attachments"];
11
+ }) => Promise<void>;
9
12
  };
@@ -3,7 +3,7 @@ var Yt = (e, t, n) => t in e ? zt(e, t, { enumerable: !0, configurable: !0, writ
3
3
  var Je = (e, t, n) => Yt(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import z, { createContext as ot, useContext as st, useRef as H, useState as it, useMemo as Ve, useEffect as Me, useSyncExternalStore as kt, useLayoutEffect as Jt, useCallback as Ee, useDebugValue as Xt } from "react";
5
5
  import { jsx as Qt } from "react/jsx-runtime";
6
- import { W as Zt } from "./widget.ctx-DIcAO9ZA.js";
6
+ import { W as Zt } from "./widget.ctx-Db_LSB7d.js";
7
7
  import { v4 as en } from "uuid";
8
8
  class tn {
9
9
  constructor(t) {
@@ -39,7 +39,7 @@ function nn(e) {
39
39
  return r;
40
40
  }, t.Provider];
41
41
  }
42
- const rn = "3.0.42", [Y, on] = nn();
42
+ const rn = "3.0.44", [Y, on] = nn();
43
43
  function tr({
44
44
  options: e,
45
45
  children: t,
@@ -1339,4 +1339,4 @@ export {
1339
1339
  At as n,
1340
1340
  Y as u
1341
1341
  };
1342
- //# sourceMappingURL=useUploadFiles-BmEispgd.js.map
1342
+ //# sourceMappingURL=useUploadFiles-BPZLXbFK.js.map