@opencx/widget 2.6.3 → 3.0.1

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 (154) hide show
  1. package/dist/basic.cjs +89 -89
  2. package/dist/basic.cjs.map +1 -1
  3. package/dist/basic.d.ts +1 -1
  4. package/dist/basic.js +34088 -34127
  5. package/dist/basic.js.map +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +3 -22
  9. package/dist/react.cjs +1 -1
  10. package/dist/react.cjs.map +1 -1
  11. package/dist/react.d.ts +1 -1
  12. package/dist/react.js +20 -10
  13. package/dist/react.js.map +1 -1
  14. package/dist/src/designs/react/basic/index.d.ts +10 -0
  15. package/dist/src/designs/{basic → react/basic}/utils/group-messages-by-type.d.ts +1 -1
  16. package/dist/src/{@components → designs/react/components}/BotOrAgentMessage.d.ts +1 -1
  17. package/dist/src/{@components → designs/react/components}/BotOrAgentMessageGroup.d.ts +2 -2
  18. package/dist/src/designs/react/components/BotOrAgentMessageWrapper.d.ts +7 -0
  19. package/dist/src/{@components → designs/react/components}/Fallback.component.d.ts +2 -2
  20. package/dist/src/{components → designs/react/components}/RenderFile.d.ts +2 -2
  21. package/dist/src/{components/keyboard.d.ts → designs/react/components/SuggestedReplies.d.ts} +2 -2
  22. package/dist/src/{@components → designs/react/components}/Text.component.d.ts +1 -1
  23. package/dist/src/{components → designs/react/components}/UserMessageGroup.d.ts +1 -1
  24. package/dist/src/{components → designs/react/components}/VoteButtons.d.ts +1 -1
  25. package/dist/src/{components → designs/react/components/lib}/button.d.ts +1 -1
  26. package/dist/src/{components → designs/react/components/lib}/dialog.d.ts +7 -7
  27. package/dist/src/{components → designs/react/components/lib}/dropdown-menu.d.ts +2 -2
  28. package/dist/src/designs/{constants.d.ts → react/constants.d.ts} +2 -4
  29. package/dist/src/designs/react/hooks/useLocale.d.ts +6 -0
  30. package/dist/src/{index.d.ts → designs/react/index.d.ts} +2 -2
  31. package/dist/src/designs/translation/ar.locale.d.ts +2 -0
  32. package/dist/src/designs/translation/de.locale.d.ts +2 -0
  33. package/dist/src/designs/translation/en.locale.d.ts +2 -0
  34. package/dist/src/designs/translation/fr.locale.d.ts +2 -0
  35. package/dist/src/designs/translation/index.d.ts +14 -0
  36. package/dist/src/designs/translation/nl.locale.d.ts +2 -0
  37. package/dist/src/designs/translation/pt.locale.d.ts +2 -0
  38. package/dist/src/designs/translation/translation.types.d.ts +4 -0
  39. package/dist/{core/client → src/headless/core}/api.d.ts +49 -103
  40. package/dist/src/headless/core/context/contact.d.ts +24 -0
  41. package/dist/src/headless/core/context/message.d.ts +42 -0
  42. package/dist/src/headless/core/context/session.d.ts +74 -0
  43. package/dist/src/headless/core/context/widget.d.ts +16 -0
  44. package/dist/src/headless/core/index.d.ts +10 -0
  45. package/dist/src/headless/core/types/WidgetConfig.d.ts +34 -0
  46. package/dist/src/headless/core/types/agent-or-bot.d.ts +6 -0
  47. package/dist/src/headless/core/types/helpers.d.ts +4 -0
  48. package/dist/{core → src/headless/core}/types/messages.d.ts +11 -31
  49. package/dist/src/headless/core/types/schemas.d.ts +9 -0
  50. package/dist/src/headless/core/utils/Poller.d.ts +12 -0
  51. package/dist/{core/types/pub-sub.d.ts → src/headless/core/utils/PubSub.d.ts} +6 -9
  52. package/dist/{react-web/core-integration/components.d.ts → src/headless/react/ComponentRegistry.d.ts} +1 -1
  53. package/dist/src/headless/react/WidgetProvider.d.ts +17 -0
  54. package/dist/src/headless/react/hooks/useConfig.d.ts +1 -0
  55. package/dist/src/headless/react/hooks/useContact.d.ts +10 -0
  56. package/dist/src/headless/react/hooks/useIsAwaitingBotReply.d.ts +3 -0
  57. package/dist/src/headless/react/hooks/useMessages.d.ts +8 -0
  58. package/dist/{react-web/core-integration → src/headless/react}/hooks/usePreludeData.d.ts +2 -2
  59. package/dist/{react-web/core-integration → src/headless/react}/hooks/usePubsub.d.ts +1 -1
  60. package/dist/src/headless/react/hooks/useSession.d.ts +6 -0
  61. package/dist/{react-web/core-integration → src/headless/react}/hooks/useVote.d.ts +2 -2
  62. package/dist/src/headless/react/index.d.ts +10 -0
  63. package/dist/{react-web → src/headless/react}/types/components.d.ts +6 -5
  64. package/dist/style.css +1 -1
  65. package/dist/useUploadFiles-CEd5c5iE.js +1336 -0
  66. package/dist/useUploadFiles-CEd5c5iE.js.map +1 -0
  67. package/dist/useUploadFiles-CNkahO3s.cjs +18 -0
  68. package/dist/useUploadFiles-CNkahO3s.cjs.map +1 -0
  69. package/dist/widget-BeNOCqB5.js +517 -0
  70. package/dist/widget-BeNOCqB5.js.map +1 -0
  71. package/dist/widget-DlAUwHzU.cjs +2 -0
  72. package/dist/widget-DlAUwHzU.cjs.map +1 -0
  73. package/dist-embed/script.js +137 -157
  74. package/dist-embed/script.js.map +1 -1
  75. package/package.json +9 -4
  76. package/dist/api-CAm3rFZk.js +0 -1070
  77. package/dist/api-CAm3rFZk.js.map +0 -1
  78. package/dist/api-oIDR-KZx.cjs +0 -2
  79. package/dist/api-oIDR-KZx.cjs.map +0 -1
  80. package/dist/core/client/chat.d.ts +0 -101
  81. package/dist/core/client/config.d.ts +0 -43
  82. package/dist/core/client/contact.d.ts +0 -29
  83. package/dist/core/client/index.d.ts +0 -4
  84. package/dist/core/errors/index.d.ts +0 -27
  85. package/dist/core/index.d.ts +0 -9
  86. package/dist/core/platform/audio.d.ts +0 -38
  87. package/dist/core/platform/index.d.ts +0 -15
  88. package/dist/core/platform/logger.d.ts +0 -14
  89. package/dist/core/platform/storage.d.ts +0 -52
  90. package/dist/core/tests/platform/logger.test.d.ts +0 -1
  91. package/dist/core/tests/platform/storage.test.d.ts +0 -1
  92. package/dist/core/tests/test-utils.d.ts +0 -2
  93. package/dist/core/tests/types/pub-sub.test.d.ts +0 -1
  94. package/dist/core/types/contact.d.ts +0 -2
  95. package/dist/core/types/helpers.d.ts +0 -20
  96. package/dist/core/types/index.d.ts +0 -52
  97. package/dist/core/types/prelude.d.ts +0 -14
  98. package/dist/core/types/schemas-v2.d.ts +0 -10
  99. package/dist/index-CSptf_Dw.cjs +0 -18
  100. package/dist/index-CSptf_Dw.cjs.map +0 -1
  101. package/dist/index-cUkS-tdv.js +0 -1232
  102. package/dist/index-cUkS-tdv.js.map +0 -1
  103. package/dist/react-web/core-integration/ChatProvider.d.ts +0 -107
  104. package/dist/react-web/core-integration/hooks/useChatMessages.d.ts +0 -70
  105. package/dist/react-web/core-integration/hooks/useChatSession.d.ts +0 -83
  106. package/dist/react-web/core-integration/hooks/useConfig.d.ts +0 -1
  107. package/dist/react-web/core-integration/hooks/useContact.d.ts +0 -17
  108. package/dist/react-web/core-integration/hooks/useLocale.d.ts +0 -4
  109. package/dist/react-web/core-integration/hooks.d.ts +0 -9
  110. package/dist/react-web/core-integration/index.d.ts +0 -2
  111. package/dist/react-web/core-integration/locales/ar.locale.d.ts +0 -2
  112. package/dist/react-web/core-integration/locales/de.locale.d.ts +0 -2
  113. package/dist/react-web/core-integration/locales/en.locale.d.ts +0 -55
  114. package/dist/react-web/core-integration/locales/fr.locale.d.ts +0 -2
  115. package/dist/react-web/core-integration/locales/helper.d.ts +0 -65
  116. package/dist/react-web/core-integration/locales/index.d.ts +0 -3
  117. package/dist/react-web/core-integration/locales/nl.locale.d.ts +0 -2
  118. package/dist/react-web/core-integration/locales/pt.locale.d.ts +0 -2
  119. package/dist/react-web/hooks/useScrollTo.d.ts +0 -2
  120. package/dist/react-web/index.d.ts +0 -4
  121. package/dist/react-web/types/index.d.ts +0 -8
  122. package/dist/react-web/types/options.d.ts +0 -17
  123. package/dist/src/@components/BotOrAgentMessageWrapper.d.ts +0 -9
  124. package/dist/src/@components/ChatEvent.component.d.ts +0 -9
  125. package/dist/src/@components/index.d.ts +0 -6
  126. package/dist/src/designs/basic/index.d.ts +0 -8
  127. /package/dist/src/designs/{basic → react/basic}/WidgetPopoverTrigger.d.ts +0 -0
  128. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatFooter.d.ts +0 -0
  129. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatHeader.d.ts +0 -0
  130. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatMain.d.ts +0 -0
  131. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatScreen.d.ts +0 -0
  132. /package/dist/src/designs/{basic → react/basic}/screens/root-screen.d.ts +0 -0
  133. /package/dist/src/designs/{basic → react/basic}/screens/welcome-screen/WelcomeScreen.d.ts +0 -0
  134. /package/dist/{core/tests/client/integration-perisitance.test.d.ts → src/designs/react/basic/widget-interaction-tests/widget.test.d.ts} +0 -0
  135. /package/dist/src/{@components → designs/react/components}/Loading.component.d.ts +0 -0
  136. /package/dist/src/{@components → designs/react/components}/OpenLogoSvg.d.ts +0 -0
  137. /package/dist/src/{components → designs/react/components/lib}/MotionDiv.d.ts +0 -0
  138. /package/dist/src/{components → designs/react/components/lib}/avatar.d.ts +0 -0
  139. /package/dist/src/{components → designs/react/components/lib}/input.d.ts +0 -0
  140. /package/dist/src/{components → designs/react/components/lib}/popover.d.ts +0 -0
  141. /package/dist/src/{components → designs/react/components/lib}/skeleton.d.ts +0 -0
  142. /package/dist/src/{components → designs/react/components/lib}/switch.d.ts +0 -0
  143. /package/dist/src/{components → designs/react/components/lib}/tooltip.d.ts +0 -0
  144. /package/dist/src/{utils.d.ts → designs/react/components/lib/utils/cn.d.ts} +0 -0
  145. /package/dist/src/{components → designs/react/components/lib}/wobble.d.ts +0 -0
  146. /package/dist/src/{@components → designs/react/components}/markdown.d.ts +0 -0
  147. /package/dist/{react-web → src/designs/react}/hooks/useWidgetContentHeight.d.ts +0 -0
  148. /package/dist/src/{render.d.ts → designs/react/render.d.ts} +0 -0
  149. /package/dist/{core → src/headless/core}/sdk/index.d.ts +0 -0
  150. /package/dist/{core/tests/client/integration.test.d.ts → src/headless/core/utils/PubSub.test.d.ts} +0 -0
  151. /package/dist/{core/utils/genUuid.d.ts → src/headless/core/utils/uuid.d.ts} +0 -0
  152. /package/dist/{react-web/core-integration → src/headless/react}/hooks/useUploadFiles.d.ts +0 -0
  153. /package/dist/{react-web → src/headless/react}/utils/create-safe-context.d.ts +0 -0
  154. /package/dist/{core/tests/platform/audio.test.d.ts → vitest/setup.d.ts} +0 -0
@@ -1,81 +1,18 @@
1
- import { User } from '../types';
2
- import { SendChatDto, WidgetVoteDto } from '../types/schemas-v2';
3
- import { NormalizedConfig } from './config';
4
- import { Dto } from '../sdk';
5
- import { AxiosInstance, AxiosRequestConfig } from 'axios';
6
- export interface ApiCallerOptions {
7
- config: NormalizedConfig;
8
- }
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { Dto } from './sdk';
3
+ import { WidgetConfig } from './types/WidgetConfig';
4
+ import { SendMessageDto, VoteInputDto } from './types/schemas';
9
5
  export declare class ApiCaller {
10
- #private;
11
- private readonly options;
12
- constructor(options: ApiCallerOptions);
13
- constructClientOptions: (user: User) => {
14
- baseUrl: string;
15
- headers: {
16
- "X-Bot-Token": string;
17
- "X-Consumer-Id": string;
18
- "Content-Type": string;
19
- Accept: string;
20
- Authorization: string | undefined;
21
- };
22
- };
23
- createOpenAPIClient: ({ baseUrl, headers, }: ReturnType<typeof this.constructClientOptions>) => import('openapi-fetch').Client<import('../sdk/schema').paths, `${string}/${string}`>;
24
- createAxiosUploadClient: ({ baseUrl, headers, }: ReturnType<typeof this.constructClientOptions>) => AxiosInstance;
25
- setUser: (user: User) => void;
26
- me: () => Promise<import('openapi-fetch').FetchResponse<{
27
- parameters: {
28
- query?: never;
29
- header?: never;
30
- path?: never;
31
- cookie?: never;
32
- };
33
- requestBody?: never;
34
- responses: {
35
- 200: {
36
- headers: {
37
- [name: string]: unknown;
38
- };
39
- content: {
40
- "application/json": import('../sdk/schema').components["schemas"]["WidgetContactDto"];
41
- };
42
- };
43
- 500: {
44
- headers: {
45
- [name: string]: unknown;
46
- };
47
- content: {
48
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
49
- };
50
- };
51
- };
52
- }, import('openapi-fetch').FetchOptions<{
53
- parameters: {
54
- query?: never;
55
- header?: never;
56
- path?: never;
57
- cookie?: never;
58
- };
59
- requestBody?: never;
60
- responses: {
61
- 200: {
62
- headers: {
63
- [name: string]: unknown;
64
- };
65
- content: {
66
- "application/json": import('../sdk/schema').components["schemas"]["WidgetContactDto"];
67
- };
68
- };
69
- 500: {
70
- headers: {
71
- [name: string]: unknown;
72
- };
73
- content: {
74
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
75
- };
76
- };
77
- };
78
- }> | undefined, `${string}/${string}`>>;
6
+ private client;
7
+ private uploadFileClient;
8
+ private config;
9
+ constructor({ config, }: {
10
+ config: WidgetConfig;
11
+ });
12
+ private constructClientOptions;
13
+ private createOpenAPIClient;
14
+ private createAxiosUploadClient;
15
+ setAuthToken: (token: string) => void;
79
16
  widgetPrelude: () => Promise<import('openapi-fetch').FetchResponse<{
80
17
  parameters: {
81
18
  query?: never;
@@ -92,7 +29,7 @@ export declare class ApiCaller {
92
29
  [name: string]: unknown;
93
30
  };
94
31
  content: {
95
- "application/json": import('../sdk/schema').components["schemas"]["WidgetPreludeDto"];
32
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetPreludeDto"];
96
33
  };
97
34
  };
98
35
  500: {
@@ -100,7 +37,7 @@ export declare class ApiCaller {
100
37
  [name: string]: unknown;
101
38
  };
102
39
  content: {
103
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
40
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
104
41
  };
105
42
  };
106
43
  };
@@ -111,7 +48,7 @@ export declare class ApiCaller {
111
48
  };
112
49
  };
113
50
  }, `${string}/${string}`>>;
114
- handleMessage: (body: SendChatDto, abortSignal?: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
51
+ sendMessage: (body: SendMessageDto, abortSignal?: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
115
52
  parameters: {
116
53
  query?: never;
117
54
  header?: never;
@@ -120,7 +57,7 @@ export declare class ApiCaller {
120
57
  };
121
58
  requestBody: {
122
59
  content: {
123
- "application/json": import('../sdk/schema').components["schemas"]["HttpChatInputDto"];
60
+ "application/json": import('./sdk/schema').components["schemas"]["HttpChatInputDto"];
124
61
  };
125
62
  };
126
63
  responses: {
@@ -129,7 +66,7 @@ export declare class ApiCaller {
129
66
  [name: string]: unknown;
130
67
  };
131
68
  content: {
132
- "application/json": import('../sdk/schema').components["schemas"]["HandleContactMessageOutputDto"];
69
+ "application/json": import('./sdk/schema').components["schemas"]["HandleContactMessageOutputDto"];
133
70
  };
134
71
  };
135
72
  500: {
@@ -137,7 +74,7 @@ export declare class ApiCaller {
137
74
  [name: string]: unknown;
138
75
  };
139
76
  content: {
140
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
77
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
141
78
  };
142
79
  };
143
80
  };
@@ -173,7 +110,11 @@ export declare class ApiCaller {
173
110
  };
174
111
  signal: AbortSignal | undefined;
175
112
  }, `${string}/${string}`>>;
176
- getSessionHistory: (sessionId: string, lastMessageTimestamp?: string) => Promise<import('openapi-fetch').FetchResponse<{
113
+ getSessionHistory: ({ sessionId, lastMessageTimestamp, abortSignal, }: {
114
+ sessionId: string;
115
+ lastMessageTimestamp?: string;
116
+ abortSignal: AbortSignal;
117
+ }) => Promise<import('openapi-fetch').FetchResponse<{
177
118
  parameters: {
178
119
  query?: {
179
120
  lastMessageTimestamp?: string;
@@ -191,7 +132,7 @@ export declare class ApiCaller {
191
132
  [name: string]: unknown;
192
133
  };
193
134
  content: {
194
- "application/json": import('../sdk/schema').components["schemas"]["WidgetHistoryDto"][];
135
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetHistoryDto"][];
195
136
  };
196
137
  };
197
138
  500: {
@@ -199,7 +140,7 @@ export declare class ApiCaller {
199
140
  [name: string]: unknown;
200
141
  };
201
142
  content: {
202
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
143
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
203
144
  };
204
145
  };
205
146
  };
@@ -212,8 +153,9 @@ export declare class ApiCaller {
212
153
  lastMessageTimestamp: string;
213
154
  } | undefined;
214
155
  };
156
+ signal: AbortSignal;
215
157
  }, `${string}/${string}`>>;
216
- createContact: (body: Dto["CreateContactDto"]) => Promise<import('openapi-fetch').FetchResponse<{
158
+ createUnverifiedContact: (body: Dto["CreateUnverifiedContactDto"]) => Promise<import('openapi-fetch').FetchResponse<{
217
159
  parameters: {
218
160
  query?: never;
219
161
  header: {
@@ -224,7 +166,7 @@ export declare class ApiCaller {
224
166
  };
225
167
  requestBody: {
226
168
  content: {
227
- "application/json": import('../sdk/schema').components["schemas"]["CreateContactDto"];
169
+ "application/json": import('./sdk/schema').components["schemas"]["CreateUnverifiedContactDto"];
228
170
  };
229
171
  };
230
172
  responses: {
@@ -233,7 +175,7 @@ export declare class ApiCaller {
233
175
  [name: string]: unknown;
234
176
  };
235
177
  content: {
236
- "application/json": import('../sdk/schema').components["schemas"]["WidgetContactDto"];
178
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetContactTokenResponseDto"];
237
179
  };
238
180
  };
239
181
  500: {
@@ -241,7 +183,7 @@ export declare class ApiCaller {
241
183
  [name: string]: unknown;
242
184
  };
243
185
  content: {
244
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
186
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
245
187
  };
246
188
  };
247
189
  };
@@ -252,8 +194,8 @@ export declare class ApiCaller {
252
194
  };
253
195
  };
254
196
  body: {
255
- email: string;
256
- name: string;
197
+ email?: string;
198
+ name?: string;
257
199
  };
258
200
  }, `${string}/${string}`>>;
259
201
  createSession: () => Promise<import('openapi-fetch').FetchResponse<{
@@ -270,7 +212,7 @@ export declare class ApiCaller {
270
212
  [name: string]: unknown;
271
213
  };
272
214
  content: {
273
- "application/json": import('../sdk/schema').components["schemas"]["WidgetSessionDto"];
215
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetSessionDto"];
274
216
  };
275
217
  };
276
218
  500: {
@@ -278,7 +220,7 @@ export declare class ApiCaller {
278
220
  [name: string]: unknown;
279
221
  };
280
222
  content: {
281
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
223
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
282
224
  };
283
225
  };
284
226
  };
@@ -296,7 +238,7 @@ export declare class ApiCaller {
296
238
  [name: string]: unknown;
297
239
  };
298
240
  content: {
299
- "application/json": import('../sdk/schema').components["schemas"]["WidgetSessionDto"];
241
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetSessionDto"];
300
242
  };
301
243
  };
302
244
  500: {
@@ -304,12 +246,15 @@ export declare class ApiCaller {
304
246
  [name: string]: unknown;
305
247
  };
306
248
  content: {
307
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
249
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
308
250
  };
309
251
  };
310
252
  };
311
253
  }> | undefined, `${string}/${string}`>>;
312
- getSession: (sessionId: string) => Promise<import('openapi-fetch').FetchResponse<{
254
+ getSession: ({ sessionId, abortSignal, }: {
255
+ sessionId: string;
256
+ abortSignal: AbortSignal;
257
+ }) => Promise<import('openapi-fetch').FetchResponse<{
313
258
  parameters: {
314
259
  query?: never;
315
260
  header?: never;
@@ -325,7 +270,7 @@ export declare class ApiCaller {
325
270
  [name: string]: unknown;
326
271
  };
327
272
  content: {
328
- "application/json": import('../sdk/schema').components["schemas"]["WidgetSessionDto"];
273
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetSessionDto"];
329
274
  };
330
275
  };
331
276
  500: {
@@ -333,7 +278,7 @@ export declare class ApiCaller {
333
278
  [name: string]: unknown;
334
279
  };
335
280
  content: {
336
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
281
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
337
282
  };
338
283
  };
339
284
  };
@@ -343,6 +288,7 @@ export declare class ApiCaller {
343
288
  sessionId: string;
344
289
  };
345
290
  };
291
+ signal: AbortSignal;
346
292
  }, `${string}/${string}`>>;
347
293
  uploadFile: (file: {
348
294
  id: string;
@@ -351,7 +297,7 @@ export declare class ApiCaller {
351
297
  fileName: string;
352
298
  fileUrl: string;
353
299
  }>;
354
- vote: (body: WidgetVoteDto) => Promise<import('openapi-fetch').FetchResponse<{
300
+ vote: (body: VoteInputDto) => Promise<import('openapi-fetch').FetchResponse<{
355
301
  parameters: {
356
302
  query?: never;
357
303
  header?: never;
@@ -360,7 +306,7 @@ export declare class ApiCaller {
360
306
  };
361
307
  requestBody: {
362
308
  content: {
363
- "application/json": import('../sdk/schema').components["schemas"]["WidgetVoteDto"];
309
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetVoteDto"];
364
310
  };
365
311
  };
366
312
  responses: {
@@ -369,7 +315,7 @@ export declare class ApiCaller {
369
315
  [name: string]: unknown;
370
316
  };
371
317
  content: {
372
- "application/json": import('../sdk/schema').components["schemas"]["WidgetVoteResponseDto"];
318
+ "application/json": import('./sdk/schema').components["schemas"]["WidgetVoteResponseDto"];
373
319
  };
374
320
  };
375
321
  500: {
@@ -377,7 +323,7 @@ export declare class ApiCaller {
377
323
  [name: string]: unknown;
378
324
  };
379
325
  content: {
380
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
326
+ "application/json": import('./sdk/schema').components["schemas"]["ErrorDto"];
381
327
  };
382
328
  };
383
329
  };
@@ -0,0 +1,24 @@
1
+ import { PubSub } from '../utils/PubSub';
2
+ import { ApiCaller } from '../api';
3
+ import { WidgetConfig } from '../types/WidgetConfig';
4
+ import { Dto } from '../sdk';
5
+ type ContactState = {
6
+ contact: {
7
+ token: string;
8
+ } | null;
9
+ isCreatingUnverifiedContact: boolean;
10
+ isErrorCreatingUnverifiedContact: boolean;
11
+ };
12
+ export declare class ContactCtx {
13
+ private config;
14
+ private api;
15
+ state: PubSub<ContactState>;
16
+ constructor({ config, api, }: {
17
+ api: ApiCaller;
18
+ config: WidgetConfig;
19
+ });
20
+ shouldCollectData: () => boolean;
21
+ autoCreateUnverifiedUser: () => Promise<void>;
22
+ createUnverifiedContact: (payload: Dto["CreateUnverifiedContactDto"]) => Promise<void>;
23
+ }
24
+ export {};
@@ -0,0 +1,42 @@
1
+ import { ApiCaller } from '../api';
2
+ import { WidgetConfig } from '../types/WidgetConfig';
3
+ import { SafeOmit, SomeOptional } from '../types/helpers';
4
+ import { BotMessageType, MessageType, UserMessageType } from '../types/messages';
5
+ import { MessageAttachmentType, MessageDto, SendMessageDto, SendMessageOutputDto } from '../types/schemas';
6
+ import { PubSub } from '../utils/PubSub';
7
+ import { SessionCtx } from './session';
8
+ export declare class MessageCtx {
9
+ private config;
10
+ private api;
11
+ private sessionCtx;
12
+ private poller;
13
+ state: PubSub<{
14
+ messages: MessageType[];
15
+ isSendingMessage: boolean;
16
+ suggestedReplies: string[] | null;
17
+ }>;
18
+ private sendMessageAbortController;
19
+ constructor({ config, api, sessionCtx, }: {
20
+ config: WidgetConfig;
21
+ api: ApiCaller;
22
+ sessionCtx: SessionCtx;
23
+ });
24
+ reset: () => void;
25
+ registerPolling: () => void;
26
+ sendMessage: (input: SomeOptional<SafeOmit<SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
27
+ fetchAndSetHistory: (sessionId: string, abortSignal: AbortSignal) => Promise<void>;
28
+ /** Not the best name but whatever */
29
+ static mapHistoryToMessage(history: MessageDto): MessageType;
30
+ static toUserMessage(content: string, attachments?: MessageAttachmentType[]): UserMessageType;
31
+ static toBotMessage(response: SendMessageOutputDto): BotMessageType | null;
32
+ static toErrorMessage(message: string): {
33
+ type: "FROM_BOT";
34
+ id: string;
35
+ timestamp: string;
36
+ component: string;
37
+ data: {
38
+ message: string;
39
+ variant: string;
40
+ };
41
+ };
42
+ }
@@ -0,0 +1,74 @@
1
+ import { ApiCaller } from '../api';
2
+ import { SessionDto } from '../types/schemas';
3
+ import { PubSub } from '../utils/PubSub';
4
+ export declare class SessionCtx {
5
+ private api;
6
+ private poller;
7
+ state: PubSub<{
8
+ session: SessionDto | null;
9
+ isCreatingSession: boolean;
10
+ }>;
11
+ constructor(api: ApiCaller);
12
+ /** Clears the session and stops polling */
13
+ reset: () => Promise<void>;
14
+ registerPolling: () => void;
15
+ /**
16
+ * Creates a new session
17
+ * @returns The session
18
+ */
19
+ createSession: () => Promise<{
20
+ id: string;
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ isHandedOff: boolean;
24
+ isOpened: boolean;
25
+ assignee: {
26
+ kind: "human" | "ai" | "none" | "unknown";
27
+ name: string | null;
28
+ avatarUrl: string | null;
29
+ };
30
+ channel: string;
31
+ isVerified: boolean;
32
+ } | null>;
33
+ /**
34
+ * Fetches the session from the API
35
+ * @param id - The ID of the session to fetch
36
+ * @returns The session
37
+ */
38
+ fetch: (sessionId: string, abortSignal: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
39
+ parameters: {
40
+ query?: never;
41
+ header?: never;
42
+ path: {
43
+ sessionId: string;
44
+ };
45
+ cookie?: never;
46
+ };
47
+ requestBody?: never;
48
+ responses: {
49
+ 200: {
50
+ headers: {
51
+ [name: string]: unknown;
52
+ };
53
+ content: {
54
+ "application/json": import('../sdk/schema').components["schemas"]["WidgetSessionDto"];
55
+ };
56
+ };
57
+ 500: {
58
+ headers: {
59
+ [name: string]: unknown;
60
+ };
61
+ content: {
62
+ "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
63
+ };
64
+ };
65
+ };
66
+ }, {
67
+ params: {
68
+ path: {
69
+ sessionId: string;
70
+ };
71
+ };
72
+ signal: AbortSignal;
73
+ }, `${string}/${string}`>>;
74
+ }
@@ -0,0 +1,16 @@
1
+ import { ApiCaller } from '../api';
2
+ import { WidgetConfig } from '../types/WidgetConfig';
3
+ import { ContactCtx } from './contact';
4
+ import { MessageCtx } from './message';
5
+ import { SessionCtx } from './session';
6
+ export declare class WidgetCtx {
7
+ config: WidgetConfig;
8
+ api: ApiCaller;
9
+ contactCtx: ContactCtx;
10
+ sessionCtx: SessionCtx;
11
+ messageCtx: MessageCtx;
12
+ constructor({ config }: {
13
+ config: WidgetConfig;
14
+ });
15
+ resetChat: () => void;
16
+ }
@@ -0,0 +1,10 @@
1
+ export type { AgentOrBotType } from './types/agent-or-bot';
2
+ export type { SafeExtract, SafeOmit, SomeOptional, StringOrLiteral, } from './types/helpers';
3
+ export type { AgentMessageType, BotMessageType, MessageType, UserMessageType, } from './types/messages';
4
+ export type { MessageAttachmentType, MessageDto, PreludeDto, SendMessageDto, SendMessageOutputDto, SessionDto, VoteInputDto, VoteOutputDto, } from './types/schemas';
5
+ export type { WidgetConfig } from './types/WidgetConfig';
6
+ export { WidgetCtx } from './context/widget';
7
+ export type { ContactCtx } from './context/contact';
8
+ export type { SessionCtx } from './context/session';
9
+ export type { MessageCtx } from './context/message';
10
+ export { PubSub } from './utils/PubSub';
@@ -0,0 +1,34 @@
1
+ import { AgentOrBotType } from './agent-or-bot';
2
+ export interface WidgetConfig {
3
+ token: string;
4
+ apiUrl?: string;
5
+ headers?: Record<string, string>;
6
+ queryParams?: Record<string, string>;
7
+ collectUserData?: boolean;
8
+ debug?: boolean;
9
+ initialMessages?: string[];
10
+ language?: string;
11
+ user?: {
12
+ external_id?: string;
13
+ name?: string;
14
+ email?: string;
15
+ phone?: string;
16
+ customData?: Record<string, string>;
17
+ avatarUrl?: string;
18
+ };
19
+ contactToken?: string;
20
+ bot?: AgentOrBotType;
21
+ soundEffectsUrls?: {
22
+ messageArrived?: string;
23
+ };
24
+ theme?: {
25
+ primaryColor?: string;
26
+ };
27
+ settings?: {
28
+ persistSession?: boolean;
29
+ playSoundEffects?: boolean;
30
+ };
31
+ assets?: {
32
+ organizationLogo?: string;
33
+ };
34
+ }
@@ -0,0 +1,6 @@
1
+ export type AgentOrBotType = {
2
+ isAi: boolean;
3
+ id: string | null;
4
+ name: string;
5
+ avatar: string | null;
6
+ };
@@ -0,0 +1,4 @@
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
+ export type SafeExtract<T, K extends T> = Extract<T, K>;
4
+ export type StringOrLiteral<T extends string> = T | (string & {});
@@ -1,18 +1,13 @@
1
- import { DefaultTextComponentBaseProps, WidgetLiteralComponentKey } from '../../react-web/types';
2
- import { ChatAttachmentType, WidgetHistoryDto } from './schemas-v2';
1
+ import { MessageAttachmentType, MessageDto } from './schemas';
3
2
  import { SafeExtract, StringOrLiteral } from './helpers';
4
- export type AgentType = {
5
- isAi: boolean;
6
- id: string | null;
7
- name: string;
8
- avatar: string | null;
9
- };
3
+ import { AgentOrBotType } from './agent-or-bot';
4
+ import { DefaultTextComponentBaseProps, WidgetLiteralComponentKey } from '../../react/types/components';
10
5
  export type UserMessageType = {
11
6
  id: string;
12
7
  type: "FROM_USER";
13
8
  content: string;
14
9
  deliveredAt: string | null;
15
- attachments?: ChatAttachmentType[] | null;
10
+ attachments?: MessageAttachmentType[] | null;
16
11
  timestamp: string;
17
12
  user?: {
18
13
  name?: string;
@@ -31,9 +26,9 @@ export type BotMessageType<TData = DefaultTextComponentBaseProps | unknown> = {
31
26
  component: StringOrLiteral<SafeExtract<WidgetLiteralComponentKey, "bot_message">>;
32
27
  data: TData;
33
28
  timestamp: string;
34
- original?: WidgetHistoryDto;
35
- agent?: AgentType;
36
- attachments?: ChatAttachmentType[];
29
+ original?: MessageDto;
30
+ agent?: AgentOrBotType;
31
+ attachments?: MessageAttachmentType[];
37
32
  };
38
33
  export type AgentMessageType = {
39
34
  id: string;
@@ -41,24 +36,9 @@ export type AgentMessageType = {
41
36
  component: SafeExtract<WidgetLiteralComponentKey, "agent_message">;
42
37
  data: DefaultTextComponentBaseProps;
43
38
  timestamp?: string;
44
- original?: WidgetHistoryDto;
45
- agent?: AgentType;
46
- attachments?: ChatAttachmentType[];
39
+ original?: MessageDto;
40
+ agent?: AgentOrBotType;
41
+ attachments?: MessageAttachmentType[];
47
42
  };
43
+ /** Find a better name for this thing */
48
44
  export type MessageType = UserMessageType | BotMessageType | AgentMessageType;
49
- export interface SendMessageInput {
50
- content: {
51
- text: string;
52
- };
53
- attachments?: ChatAttachmentType[];
54
- id?: string;
55
- language?: string;
56
- user?: {
57
- external_id?: string;
58
- name?: string;
59
- email?: string;
60
- phone?: string;
61
- customData?: Record<string, string>;
62
- avatarUrl?: string;
63
- };
64
- }
@@ -0,0 +1,9 @@
1
+ import { Dto } from '../sdk';
2
+ export type VoteInputDto = Dto["WidgetVoteDto"];
3
+ export type VoteOutputDto = Dto["WidgetVoteResponseDto"];
4
+ export type SendMessageDto = Dto["HttpChatInputDto"];
5
+ export type SendMessageOutputDto = Dto["HandleContactMessageOutputDto"];
6
+ export type SessionDto = Dto["WidgetSessionDto"];
7
+ export type MessageDto = Dto["WidgetHistoryDto"];
8
+ export type PreludeDto = Dto["WidgetPreludeDto"];
9
+ export type MessageAttachmentType = NonNullable<Dto["WidgetHistoryDto"]["attachments"]>[number];
@@ -0,0 +1,12 @@
1
+ import { PubSub } from './PubSub';
2
+ export type PollingState = {
3
+ isPolling: boolean;
4
+ isError: boolean;
5
+ };
6
+ export declare class Poller {
7
+ state: PubSub<PollingState>;
8
+ private abortController;
9
+ reset: () => void;
10
+ stopPolling: (() => void) | null;
11
+ startPolling: (cb: (abortSignal: AbortSignal) => Promise<void>, interval: number) => void;
12
+ }
@@ -25,18 +25,16 @@ export declare class PubSub<S> {
25
25
  * @param callback Function to call when state changes
26
26
  * @returns Unsubscribe function
27
27
  */
28
- subscribe: (callback: Subscriber<S>) => () => void;
29
- onLifecycle: (event: LifecycleEvent, listener: LifecycleListener) => () => void;
30
- /**
31
- * Get the current state
32
- */
33
- getState: () => S;
28
+ subscribe: (callback: Subscriber<S>) => (() => void);
29
+ onLifecycle: (event: LifecycleEvent, listener: LifecycleListener) => (() => void);
30
+ /** Get the current state */
31
+ get: () => S;
34
32
  /**
35
33
  * Set the state and notify subscribers if the state changes
36
34
  * @param newState The new state to set
37
35
  */
38
- setState: (newState: S) => void;
39
- setStatePartial: (_s: Partial<S>) => void;
36
+ set: (newState: S) => void;
37
+ setPartial: (_s: Partial<S>) => void;
40
38
  /**
41
39
  * Clear all subscriptions
42
40
  */
@@ -44,5 +42,4 @@ export declare class PubSub<S> {
44
42
  reset: () => void;
45
43
  lastUpdated: () => number | null;
46
44
  }
47
- export declare function createPubSub<S>(state: S): PubSub<S>;
48
45
  export {};