@carbon/ai-chat 0.1.6 → 0.1.7-test-no-cjs

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 (144) hide show
  1. package/dist/es/{cds-aichat-internal.js → AppContainer.js} +50756 -18310
  2. package/dist/es/Carousel.js +14 -8
  3. package/dist/es/GenesysMessengerServiceDesk.js +17 -11
  4. package/dist/es/HumanAgentServiceImpl.js +17 -12
  5. package/dist/es/NiceDFOServiceDesk.js +17 -12
  6. package/dist/es/PDFViewerContainer.js +15 -108
  7. package/dist/es/ReactPlayer.js +2 -2
  8. package/dist/es/SFServiceDesk.js +18 -11
  9. package/dist/es/ServiceDeskImpl.js +2 -2
  10. package/dist/es/Table.js +429 -315
  11. package/dist/es/ZendeskServiceDesk.js +17 -11
  12. package/dist/es/_node-resolve_empty.js +2 -2
  13. package/dist/es/aiChatEntry.js +137 -120
  14. package/dist/es/ar-dz.js +3 -4
  15. package/dist/es/ar-kw.js +3 -4
  16. package/dist/es/ar-ly.js +3 -4
  17. package/dist/es/ar-ma.js +3 -4
  18. package/dist/es/ar-sa.js +3 -4
  19. package/dist/es/ar-tn.js +3 -4
  20. package/dist/es/ar.js +3 -4
  21. package/dist/es/ar2.js +2 -2
  22. package/dist/es/cds-aichat-container.js +104 -18
  23. package/dist/es/cds-aichat-custom-element.js +31 -21
  24. package/dist/es/cs.js +3 -4
  25. package/dist/es/cs2.js +2 -2
  26. package/dist/es/de-at.js +3 -4
  27. package/dist/es/de-ch.js +3 -4
  28. package/dist/es/de.js +3 -4
  29. package/dist/es/de2.js +2 -2
  30. package/dist/es/en-au.js +3 -4
  31. package/dist/es/en-ca.js +3 -4
  32. package/dist/es/en-gb.js +3 -4
  33. package/dist/es/en-ie.js +3 -4
  34. package/dist/es/en-il.js +3 -4
  35. package/dist/es/en-nz.js +3 -4
  36. package/dist/es/es-do.js +3 -4
  37. package/dist/es/es-us.js +3 -4
  38. package/dist/es/es.js +3 -4
  39. package/dist/es/es2.js +2 -2
  40. package/dist/es/export.js +3 -3
  41. package/dist/es/export.legacy.js +3 -3
  42. package/dist/es/fontUtils.js +2 -2
  43. package/dist/es/fr-ca.js +3 -4
  44. package/dist/es/fr-ch.js +3 -4
  45. package/dist/es/fr.js +3 -4
  46. package/dist/es/fr2.js +2 -2
  47. package/dist/es/it-ch.js +3 -4
  48. package/dist/es/it.js +3 -4
  49. package/dist/es/it2.js +2 -2
  50. package/dist/es/ja.js +3 -4
  51. package/dist/es/ja2.js +2 -2
  52. package/dist/es/ko.js +3 -4
  53. package/dist/es/ko2.js +2 -2
  54. package/dist/es/mockServiceDesk.js +17 -11
  55. package/dist/es/nl.js +3 -4
  56. package/dist/es/nl2.js +2 -2
  57. package/dist/es/pt-br.js +3 -4
  58. package/dist/es/pt-br2.js +2 -2
  59. package/dist/es/pt.js +3 -4
  60. package/dist/es/render.js +25 -12
  61. package/dist/es/zh-cn.js +3 -4
  62. package/dist/es/zh-tw.js +3 -4
  63. package/dist/es/zh-tw2.js +2 -2
  64. package/dist/es/zh.js +2 -2
  65. package/dist/types/aiChatEntry.d.ts +599 -11
  66. package/package.json +29 -21
  67. package/dist/cjs/Carousel.js +0 -5711
  68. package/dist/cjs/Chat.js +0 -8838
  69. package/dist/cjs/GenesysMessengerServiceDesk.js +0 -598
  70. package/dist/cjs/HumanAgentServiceImpl.js +0 -1145
  71. package/dist/cjs/NiceDFOServiceDesk.js +0 -2116
  72. package/dist/cjs/PDFViewerContainer.js +0 -83227
  73. package/dist/cjs/ReactPlayer.js +0 -57
  74. package/dist/cjs/SFServiceDesk.js +0 -1031
  75. package/dist/cjs/ServiceDeskImpl.js +0 -74
  76. package/dist/cjs/Table.js +0 -3146
  77. package/dist/cjs/ZendeskServiceDesk.js +0 -670
  78. package/dist/cjs/_node-resolve_empty.js +0 -27
  79. package/dist/cjs/agentActions.js +0 -214
  80. package/dist/cjs/aiChatEntry.js +0 -354
  81. package/dist/cjs/anonymousUserIDStorage.js +0 -254
  82. package/dist/cjs/ar-dz.js +0 -57
  83. package/dist/cjs/ar-kw.js +0 -57
  84. package/dist/cjs/ar-ly.js +0 -57
  85. package/dist/cjs/ar-ma.js +0 -57
  86. package/dist/cjs/ar-sa.js +0 -57
  87. package/dist/cjs/ar-tn.js +0 -57
  88. package/dist/cjs/ar.js +0 -57
  89. package/dist/cjs/ar2.js +0 -763
  90. package/dist/cjs/cds-aichat-container.js +0 -143
  91. package/dist/cjs/cds-aichat-custom-element.js +0 -200
  92. package/dist/cjs/cds-aichat-internal.js +0 -39150
  93. package/dist/cjs/cs.js +0 -57
  94. package/dist/cjs/cs2.js +0 -763
  95. package/dist/cjs/de-at.js +0 -57
  96. package/dist/cjs/de-ch.js +0 -57
  97. package/dist/cjs/de.js +0 -57
  98. package/dist/cjs/de2.js +0 -763
  99. package/dist/cjs/en-au.js +0 -57
  100. package/dist/cjs/en-ca.js +0 -57
  101. package/dist/cjs/en-gb.js +0 -57
  102. package/dist/cjs/en-ie.js +0 -57
  103. package/dist/cjs/en-il.js +0 -57
  104. package/dist/cjs/en-nz.js +0 -57
  105. package/dist/cjs/es-do.js +0 -57
  106. package/dist/cjs/es-us.js +0 -57
  107. package/dist/cjs/es.js +0 -57
  108. package/dist/cjs/es2.js +0 -763
  109. package/dist/cjs/export.js +0 -27
  110. package/dist/cjs/export.legacy.js +0 -27
  111. package/dist/cjs/fontUtils.js +0 -1038
  112. package/dist/cjs/fr-ca.js +0 -57
  113. package/dist/cjs/fr-ch.js +0 -57
  114. package/dist/cjs/fr.js +0 -57
  115. package/dist/cjs/fr2.js +0 -763
  116. package/dist/cjs/highlight_js.js +0 -15325
  117. package/dist/cjs/it-ch.js +0 -57
  118. package/dist/cjs/it.js +0 -57
  119. package/dist/cjs/it2.js +0 -763
  120. package/dist/cjs/ja.js +0 -57
  121. package/dist/cjs/ja2.js +0 -763
  122. package/dist/cjs/jstz.min.js +0 -43
  123. package/dist/cjs/ko.js +0 -57
  124. package/dist/cjs/ko2.js +0 -763
  125. package/dist/cjs/markdown.js +0 -8505
  126. package/dist/cjs/markdown_attrs.js +0 -805
  127. package/dist/cjs/mockServiceDesk.js +0 -887
  128. package/dist/cjs/nl.js +0 -57
  129. package/dist/cjs/nl2.js +0 -763
  130. package/dist/cjs/pt-br.js +0 -57
  131. package/dist/cjs/pt-br2.js +0 -763
  132. package/dist/cjs/pt.js +0 -57
  133. package/dist/cjs/render.js +0 -94
  134. package/dist/cjs/zh-cn.js +0 -57
  135. package/dist/cjs/zh-tw.js +0 -57
  136. package/dist/cjs/zh-tw2.js +0 -763
  137. package/dist/cjs/zh.js +0 -763
  138. package/dist/es/Chat.js +0 -8836
  139. package/dist/es/agentActions.js +0 -186
  140. package/dist/es/anonymousUserIDStorage.js +0 -249
  141. package/dist/es/highlight_js.js +0 -15320
  142. package/dist/es/jstz.min.js +0 -41
  143. package/dist/es/markdown.js +0 -8501
  144. package/dist/es/markdown_attrs.js +0 -803
@@ -1,887 +0,0 @@
1
- /*
2
-
3
-
4
- (C) Copyright IBM Corp. 2017, 2025. All Rights Reserved.
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
- in compliance with the License. You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software distributed under the License
12
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
- or implied. See the License for the specific language governing permissions and limitations under
14
- the License.
15
-
16
- @carbon/ai-chat 0.1.6
17
-
18
- Built: Feb 3 2025 9:58 am -05:00
19
-
20
-
21
-
22
- */
23
- 'use strict';
24
-
25
- var cdsAichatInternal = require('./cds-aichat-internal.js');
26
- require('lit');
27
- require('lit/decorators.js');
28
- require('react');
29
- require('react-dom');
30
- require('./highlight_js.js');
31
- require('@carbon/react');
32
- require('react-intl');
33
- require('react-redux');
34
- require('./markdown.js');
35
- require('./markdown_attrs.js');
36
- require('@carbon/web-components/es/components/button/index.js');
37
- require('@carbon/web-components/es/components/overflow-menu/index.js');
38
- require('lit/directives/unsafe-html.js');
39
- require('@carbon/web-components/es/components/slug/index.js');
40
- require('@carbon/web-components/es/components/popover/defs.js');
41
- require('@carbon/web-components/es/components/slug/defs.js');
42
- require('@carbon/web-components/es/components/slug/slug-action-button.js');
43
- require('@carbon/web-components/es/components/slug/slug.js');
44
- require('@carbon/web-components/es/components/textarea/index.js');
45
- require('@carbon/web-components/es/components/icon-button/index.js');
46
- require('lit/directives/unsafe-svg.js');
47
- require('@carbon/web-components/es/components/tag/index.js');
48
- require('@carbon/web-components/es/components/chat-button/index.js');
49
- require('@carbon/web-components/es/components/button/button.js');
50
- require('@carbon/web-components/es/components/layer/index.js');
51
-
52
- /**
53
- *
54
- * IBM Confidential
55
- *
56
- * (C) Copyright IBM Corp. 2020, 2023
57
- *
58
- * The source code for this program is not published or otherwise
59
- * divested of its trade secrets, irrespective of what has been
60
- * deposited with the U. S. Copyright Office
61
- *
62
- * US Government Users Restricted Rights - Use, duplication or
63
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
64
- *
65
- */
66
- exports.ConnectInfoType = void 0;
67
- (function (ConnectInfoType) {
68
- /**
69
- * The connecting status will not show any information.
70
- */
71
- ConnectInfoType[ConnectInfoType["NONE"] = 1] = "NONE";
72
- /**
73
- * The connecting status will show information about the user's position in a queue.
74
- */
75
- ConnectInfoType[ConnectInfoType["LINE"] = 2] = "LINE";
76
- /**
77
- * The connecting status will show information about the wait time in minutes for the user.
78
- */
79
- ConnectInfoType[ConnectInfoType["MINUTES"] = 3] = "MINUTES";
80
- /**
81
- * The connecting status will show a series of custom messages.
82
- */
83
- ConnectInfoType[ConnectInfoType["MESSAGE"] = 4] = "MESSAGE";
84
- /**
85
- * Starting a chat will result in a connecting error {@link ErrorType.CONNECTING}.
86
- */
87
- ConnectInfoType[ConnectInfoType["CONNECTING_ERROR"] = 5] = "CONNECTING_ERROR";
88
- /**
89
- * Starting a chat will just fail with the service desk throwing an error.
90
- */
91
- ConnectInfoType[ConnectInfoType["THROW_ERROR"] = 6] = "THROW_ERROR";
92
- })(exports.ConnectInfoType || (exports.ConnectInfoType = {}));
93
- const HELLO_TEXT = (userName) => `Hi${userName ? ` ${userName}` : ''}, I'm Shepard! I'm a **mock** service desk agent. Type *"help"* to see a list of messages you can mock me with. <script>alert("If you see this, it is a serious bug!");</script>`;
94
- const TEXT_LONG = 'The biggest problem that teams encounter when dealing with coding standards is the ' +
95
- 'variety of opinions on the subject or the introduction of new team members who are familiar with a' +
96
- " different standard. The first point I would make to address this is that I don't believe that what" +
97
- ' exactly is in your coding standard is nearly as important as having a standard and using it consistently.' +
98
- " It doesn't matter if you want braces to be on the following line or the same line as long as whatever you" +
99
- ' do is consistent.\n\nBut those who don\'t agree to a specific point are likely to feel that it\'s "wrong"' +
100
- ' and not just "different." Over my career I have worked on a lot of different projects with a wide range' +
101
- ' of coding standards and in my experience, it takes relatively little time to adopt a new standard once' +
102
- ' you\'ve set aside your resistance to it. You may feel that putting braces on the same line is "wrong"' +
103
- ' but I bet that if you try it, in just a few days you will begin to feel that the new style is "right"' +
104
- ' and it\'s now your old style that\'s "wrong".\n\nAs an example, I spent 20 years of my life believing that' +
105
- ' you were supposed to end a sentence with two spaces instead of one. Then one day I started to notice in ' +
106
- 'javadoc comments that other members of my team used just one. I decided to go look up the best practices for ' +
107
- "this and concluded that the two spaces were outdated and it's now generally accepted to use just one. I made a " +
108
- 'few weak attempts to change but I just found it hard to switch a habit that I had had for so long. One day I ' +
109
- 'finally decided to practice what I preach and made a serious attempt to relegate that extra space to history ' +
110
- 'and sure enough, within a couple of days I no longer had any difficulty typing one space instead of two and in ' +
111
- 'not much time after that, I found myself occasionally noticing the two spaces in old code of mine and found that ' +
112
- 'it did indeed look odd now...\n\n' +
113
- '[More](https://medium.com/@damon.lundin/on-coding-standards-4420e3fa281f)\n\n<script>alert("If you see this, it is a serious bug!")</script>';
114
- const PROFILE_URL_PREFIX = 'https://web-chat.assistant.test.watson.cloud.ibm.com';
115
- const MOCK_AGENT_PROFILE_SHEPARD = {
116
- id: 'CommanderShepard-id',
117
- nickname: 'Shepard',
118
- profile_picture_url: `${PROFILE_URL_PREFIX}/assets/example_avatar_1.png`,
119
- };
120
- const MOCK_AGENT_PROFILE_GARRUS = {
121
- id: 'GarrusVakarian-id',
122
- nickname: 'Garrus',
123
- profile_picture_url: `${PROFILE_URL_PREFIX}/assets/example_avatar_2.png`,
124
- };
125
- const MOCK_AGENT_PROFILE_LEGION = {
126
- id: 'Legion-id',
127
- nickname: 'Legion',
128
- profile_picture_url: `${PROFILE_URL_PREFIX}/assets/example_avatar_missing.png`,
129
- };
130
- const MOCK_AGENT_PROFILE_EMPTY = {
131
- id: null,
132
- nickname: null,
133
- };
134
- // The agent we're currently talking to.
135
- class MockServiceDesk {
136
- constructor(parameters) {
137
- /**
138
- * The current internal state for the mock service desk. This object is exported by this module and these values may
139
- * be controlled by external code.
140
- */
141
- this.mockState = {
142
- connectDelayFactor: 1,
143
- connectInfoType: exports.ConnectInfoType.LINE,
144
- agentAvailabilityDelay: 0,
145
- agentAvailability: true,
146
- showStateChanges: false,
147
- currentAgent: MOCK_AGENT_PROFILE_SHEPARD,
148
- };
149
- console.log('Creating MockServiceDesk');
150
- this.factoryParameters = parameters;
151
- this.chatInstance = parameters.instance;
152
- this.callback = parameters.callback;
153
- this.callback.updateCapabilities({
154
- allowFileUploads: true,
155
- allowedFileUploadTypes: 'image/*,.txt',
156
- allowMultipleFileUploads: true,
157
- });
158
- window.watsonAssistantChat = window.watsonAssistantChat || {};
159
- window.watsonAssistantChat.mockServiceDesk = this;
160
- }
161
- getName() {
162
- return 'wac mock service desk';
163
- }
164
- updateState(state) {
165
- this.state = state;
166
- if (this.hasStarted && this.mockState.showStateChanges) {
167
- runSteps(this, STATE_CHANGED(state));
168
- }
169
- }
170
- startChat(connectMessage, startChatOptions) {
171
- console.log(`MockServiceDesk [startChat]: connectMessage`, connectMessage);
172
- console.log(`MockServiceDesk [startChat]: startChatOptions`, startChatOptions);
173
- this.preStartChatPayload = startChatOptions.preStartChatPayload || {};
174
- if (this.mockState.connectInfoType === exports.ConnectInfoType.CONNECTING_ERROR) {
175
- return runSteps(this, START_CHAT_CONNECT_ERROR(this.mockState));
176
- }
177
- if (this.mockState.connectInfoType === exports.ConnectInfoType.THROW_ERROR) {
178
- throw new Error('The mock service desk threw an error during startChat!');
179
- }
180
- if (this.mockState.connectDelayFactor === 0) {
181
- return runSteps(this, START_CHAT_IMMEDIATELY(this.preStartChatPayload.userName));
182
- }
183
- if (this.mockState.connectInfoType === exports.ConnectInfoType.NONE) {
184
- return runSteps(this, START_CHAT_NO_INFO(this.preStartChatPayload.userName, this.mockState));
185
- }
186
- this.hasStarted = true;
187
- return runSteps(this, START_CHAT(this.preStartChatPayload.userName, this.mockState));
188
- }
189
- endChat(info) {
190
- console.log(`MockServiceDesk [endChat]`, info);
191
- let surveyResponse;
192
- if (info.preEndChatPayload?.wasAgentHelpful === true) {
193
- surveyResponse = 'We understand that you found the agent helpful. He will be given a cookie!';
194
- }
195
- else if (info.preEndChatPayload?.wasAgentHelpful === false) {
196
- surveyResponse = 'We are sorry that the agent was not helpful. He will be reassigned to Siberia.';
197
- }
198
- if (surveyResponse) {
199
- const text = `Thank you for responding to our survey. ${surveyResponse}`;
200
- this.sendMessageToUser(cdsAichatInternal.createMessageResponseForText(text), this.mockState.currentAgent.id);
201
- }
202
- return Promise.resolve();
203
- }
204
- userTyping(isTyping) {
205
- console.log(`MockServiceDesk [userTyping]: isTyping=${isTyping}`);
206
- return Promise.resolve();
207
- }
208
- sendMessageToAgent(message, _messageID, additionalData) {
209
- console.log(`MockServiceDesk [sendMessageToAgent]`, message, additionalData);
210
- const { text } = message.input;
211
- // Send a message back whenever we get a message from the user.
212
- let steps;
213
- if (!text) ;
214
- else {
215
- const textLower = text.toLowerCase();
216
- if (textLower.includes('help')) {
217
- steps = MESSAGE_TO_AGENT_HELP();
218
- }
219
- else if (textLower.includes('blank')) {
220
- steps = null;
221
- }
222
- else if (textLower.includes('joke')) {
223
- steps = MESSAGE_TO_AGENT_JOKE();
224
- }
225
- else if (textLower.includes('someone else')) {
226
- if (this.mockState.currentAgent === MOCK_AGENT_PROFILE_SHEPARD ||
227
- this.mockState.currentAgent === MOCK_AGENT_PROFILE_EMPTY) {
228
- steps = TRANSFER_TO_GARRUS();
229
- }
230
- else if (this.mockState.currentAgent === MOCK_AGENT_PROFILE_GARRUS) {
231
- steps = TRANSFER_TO_LEGION();
232
- }
233
- else {
234
- steps = TRANSFER_TO_EMPTY();
235
- }
236
- }
237
- else if (textLower.includes('text long')) {
238
- steps = MESSAGE_TO_AGENT_TEXT(TEXT_LONG);
239
- }
240
- else if (textLower.includes('text medium')) {
241
- steps = MESSAGE_TO_AGENT_TEXT("Thanks for being so interesting! I'm sure we're going to have a *wonderful* conversation. Let's get started...");
242
- }
243
- else if (textLower.includes('markdown')) {
244
- steps = MESSAGE_TO_AGENT_TEXT(MARKDOWN);
245
- }
246
- else if (textLower.includes('multiple')) {
247
- steps = MESSAGE_TO_AGENT_MULTIPLE();
248
- }
249
- else if (textLower.includes('hide')) {
250
- steps = MESSAGE_TO_AGENT_TEXT('Session history will hide this message!');
251
- }
252
- else if (textLower.includes('secret')) {
253
- steps = MESSAGE_TO_AGENT_TEXT("I'm afraid I don't know any secrets!");
254
- }
255
- else if (textLower.includes('version')) {
256
- steps = MESSAGE_TO_AGENT_TEXT(`Web chat version: ${this.factoryParameters.instance.getWidgetVersion()}`);
257
- }
258
- else if (textLower.includes('intl')) {
259
- const message = this.factoryParameters.instance.getIntl().formatMessage({ id: 'input_placeholder' });
260
- steps = MESSAGE_TO_AGENT_TEXT(`Intl string (input_placeholder): *${message}*`);
261
- }
262
- else if (textLower.includes('leave')) {
263
- steps = MESSAGE_TO_AGENT_LEAVE_CHAT();
264
- }
265
- else if (textLower.includes('text')) {
266
- steps = MESSAGE_TO_AGENT_TEXT("TypeScript is awesome! I don't know how anyone can live without it. Seriously?!");
267
- }
268
- else if (textLower.includes('upload')) {
269
- steps = MESSAGE_TO_AGENT_TEXT('Alright, you can upload some files. But only .png files please.', 0, false);
270
- }
271
- else if (textLower.includes('message throw')) {
272
- steps = MESSAGE_THROW();
273
- }
274
- else if (textLower.includes('image')) {
275
- steps = MESSAGE_IMAGE();
276
- }
277
- else if (textLower.includes('files')) {
278
- steps = MESSAGE_FILES();
279
- }
280
- else if (textLower.includes('video')) {
281
- steps = MESSAGE_VIDEO();
282
- }
283
- else if (textLower.includes('custom')) {
284
- steps = MESSAGE_CUSTOM();
285
- }
286
- else if (textLower.includes('hang')) {
287
- steps = HANG_MESSAGE();
288
- }
289
- else {
290
- steps = MESSAGE_TO_AGENT_TEXT('If you say so. Type *"help"* for a list of other things you can say.');
291
- }
292
- }
293
- // Handle any file uploads we may have.
294
- if (additionalData.filesToUpload) {
295
- additionalData.filesToUpload.forEach(file => {
296
- // Use a setTimeout to simulate a random amount of time it takes to upload a file.
297
- setTimeout(() => {
298
- let errorMessage;
299
- if (!file.file.name.endsWith('.png')) {
300
- errorMessage = 'Only .png files may be uploaded.';
301
- }
302
- this.callback.setFileUploadStatus(file.id, Boolean(errorMessage), errorMessage);
303
- }, Math.random() * 5000 + 1);
304
- });
305
- }
306
- return runSteps(this, steps);
307
- }
308
- filesSelectedForUpload(uploads) {
309
- console.log(`MockServiceDesk [filesSelectedForUpload]`, uploads);
310
- uploads.forEach(file => {
311
- if (file.file.name.toLowerCase().startsWith('a')) {
312
- this.callback.setFileUploadStatus(file.id, true, 'You may not upload files that start with the letter "A"! Duh.');
313
- }
314
- });
315
- }
316
- userReadMessages() {
317
- console.log(`MockServiceDesk [userReadMessages]`);
318
- return Promise.resolve();
319
- }
320
- sendMessageToUser(message, agentID) {
321
- // As soon as the agent sends a message, make sure to clear the "isTyping" event for the agent.
322
- this.callback.agentTyping(false);
323
- this.callback.sendMessageToUser(message, agentID);
324
- }
325
- async areAnyAgentsOnline() {
326
- if (this.mockState.agentAvailabilityDelay) {
327
- await cdsAichatInternal.sleep(this.mockState.agentAvailabilityDelay * 1000);
328
- }
329
- return this.mockState.agentAvailability;
330
- }
331
- async screenShareStop() {
332
- this.callback.sendMessageToUser('Alright, you have stopped sharing your screen.', this.mockState.currentAgent.id);
333
- }
334
- async reconnect() {
335
- await cdsAichatInternal.sleep(2000);
336
- this.hasStarted = true;
337
- return true;
338
- }
339
- }
340
- /**
341
- * This function will run a series of steps to simulate some interaction between the agent and a user.
342
- */
343
- function runSteps(instance, steps) {
344
- if (steps) {
345
- let totalTime = 0;
346
- steps.forEach(step => {
347
- totalTime += step.delay || 0;
348
- setTimeout(() => {
349
- step.callback(instance);
350
- }, totalTime);
351
- });
352
- const lastStep = steps[steps.length - 1];
353
- // If the last step has some extra work to do in a Promise, then return that Promise. Otherwise, return a no-op.
354
- return lastStep.returnPromise || Promise.resolve();
355
- }
356
- return Promise.resolve();
357
- }
358
- // Immediately start a chat with no delays.
359
- function START_CHAT_IMMEDIATELY(userName) {
360
- return [
361
- {
362
- delay: 0,
363
- callback: (instance) => {
364
- instance.mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
365
- instance.callback.agentJoined(MOCK_AGENT_PROFILE_SHEPARD);
366
- instance.sendMessageToUser(HELLO_TEXT(userName), instance.mockState.currentAgent.id);
367
- },
368
- },
369
- ];
370
- }
371
- function START_CHAT_NO_INFO(userName, mockState) {
372
- return [
373
- {
374
- delay: 1000 * mockState.connectDelayFactor,
375
- callback: (instance) => {
376
- mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
377
- instance.callback.agentJoined(MOCK_AGENT_PROFILE_SHEPARD);
378
- },
379
- },
380
- {
381
- delay: 1000,
382
- callback: (instance) => {
383
- instance.callback.agentTyping(true);
384
- },
385
- },
386
- {
387
- delay: 1000,
388
- callback: (instance) => {
389
- instance.sendMessageToUser(HELLO_TEXT(userName), MOCK_AGENT_PROFILE_SHEPARD.id);
390
- },
391
- },
392
- ];
393
- }
394
- function START_CHAT_CONNECT_ERROR(mockState) {
395
- return [
396
- {
397
- delay: 1000 * mockState.connectDelayFactor,
398
- callback: (instance) => {
399
- mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
400
- instance.callback.setErrorStatus({
401
- type: cdsAichatInternal.ErrorType.CONNECTING,
402
- logInfo: 'Error!',
403
- messageToUser: 'Apparently all our agents are taking naps',
404
- });
405
- },
406
- },
407
- ];
408
- }
409
- // Starts a chat with a standard sequence of events with low delays on them.
410
- function START_CHAT(userName, mockState) {
411
- let availability;
412
- switch (mockState?.connectInfoType) {
413
- case exports.ConnectInfoType.MESSAGE: {
414
- availability = [
415
- { message: 'Agent getting on a *plane*...' },
416
- { message: 'Agent getting on a *train*...' },
417
- { message: 'Agent getting into a *car*...' },
418
- ];
419
- break;
420
- }
421
- case exports.ConnectInfoType.MINUTES: {
422
- availability = [{ estimated_wait_time: 30 }, { estimated_wait_time: 2 }, { estimated_wait_time: 1 }];
423
- break;
424
- }
425
- default: {
426
- availability = [{ position_in_queue: 30 }, { position_in_queue: 2 }, { position_in_queue: 1 }];
427
- break;
428
- }
429
- }
430
- return [
431
- {
432
- delay: 1000,
433
- callback: (instance) => {
434
- instance.callback.updateAgentAvailability(availability[0]);
435
- },
436
- },
437
- {
438
- delay: 500 * mockState.connectDelayFactor,
439
- callback: (instance) => {
440
- instance.callback.updateAgentAvailability(availability[1]);
441
- },
442
- },
443
- {
444
- delay: 1000 * mockState.connectDelayFactor,
445
- callback: (instance) => {
446
- instance.callback.updateAgentAvailability(availability[2]);
447
- },
448
- },
449
- {
450
- delay: 1000,
451
- callback: (instance) => {
452
- mockState.currentAgent = MOCK_AGENT_PROFILE_SHEPARD;
453
- instance.callback.agentJoined(MOCK_AGENT_PROFILE_SHEPARD);
454
- },
455
- },
456
- {
457
- delay: 1000,
458
- callback: (instance) => {
459
- instance.callback.agentTyping(true);
460
- },
461
- },
462
- {
463
- delay: 1000,
464
- callback: (instance) => {
465
- instance.sendMessageToUser(HELLO_TEXT(userName), mockState.currentAgent.id);
466
- },
467
- },
468
- ];
469
- }
470
- // Help messages
471
- const HELP_TEXT = `You can send me the messages below to get a specific response from me.\n\n
472
- **text**: I will say something pithy.
473
- **text medium**: I will send you a few lines of text.
474
- **text long**: I will bore you with a treatise on coding standards.
475
- **joke**: I will tell you a joke with after a longer pause with multiple pauses in between messages.
476
- **someone else**: I will transfer you to someone not as nice as I am.
477
- **multiple**: I will output a response with multiple items in it.
478
- **version**: I will output the version of web chat being used.
479
- **intl**: I will output the current value for a translatable string.
480
- **message throw**: This will throw an error while sending this message.
481
- **hang**: The service desk will never respond to this message.
482
- **leave**: I will leave the chat without ending it.
483
- **hide**: I will send a message that should get hidden from session history.
484
- **hide this message**: The user message should be hidden from session history.
485
- **secret**: I will send you a message with the word "secret" in it.
486
- **image**: I will insert an image response.
487
- **files**: I will insert some file responses.
488
- **video**: I will insert a video response.
489
- **custom**: I will insert a custom response.
490
- **markdown**: I will insert some markdown.`;
491
- function MESSAGE_TO_AGENT_HELP() {
492
- return [
493
- {
494
- delay: 0,
495
- callback: (instance) => {
496
- instance.sendMessageToUser('***These messages must be sent to an agent and not to the bot.***', instance.mockState.currentAgent.id);
497
- instance.sendMessageToUser(HELP_TEXT, instance.mockState.currentAgent.id);
498
- },
499
- },
500
- ];
501
- }
502
- // A message to the agent to respond with some simple text.
503
- function MESSAGE_TO_AGENT_TEXT(text, delay = 1000, showTyping = true) {
504
- const steps = [];
505
- if (showTyping) {
506
- steps.push({
507
- delay,
508
- callback: (instance) => {
509
- instance.callback.agentReadMessages();
510
- instance.callback.agentTyping(true);
511
- },
512
- });
513
- }
514
- steps.push({
515
- delay,
516
- callback: (instance) => {
517
- instance.sendMessageToUser(text, instance.mockState.currentAgent.id);
518
- },
519
- });
520
- return steps;
521
- }
522
- // A response to talk to someone else.
523
- function TRANSFER_TO_GARRUS() {
524
- return [
525
- {
526
- delay: 1000,
527
- callback: (instance) => {
528
- instance.callback.agentReadMessages();
529
- instance.callback.agentTyping(true);
530
- },
531
- },
532
- {
533
- delay: 1000,
534
- callback: (instance) => {
535
- instance.sendMessageToUser('Noooooo! I thought we were getting along so well!', instance.mockState.currentAgent.id);
536
- },
537
- },
538
- {
539
- delay: 500,
540
- callback: (instance) => {
541
- instance.callback.agentReadMessages();
542
- instance.callback.agentTyping(true);
543
- },
544
- },
545
- {
546
- delay: 500,
547
- callback: (instance) => {
548
- instance.sendMessageToUser("Okay, I'll find **someone else** you can talk to.", instance.mockState.currentAgent.id);
549
- },
550
- },
551
- {
552
- delay: 1000,
553
- callback: (instance) => {
554
- instance.callback.beginTransferToAnotherAgent();
555
- },
556
- },
557
- {
558
- delay: 1000,
559
- callback: (instance) => {
560
- instance.mockState.currentAgent = MOCK_AGENT_PROFILE_GARRUS;
561
- instance.callback.agentJoined(MOCK_AGENT_PROFILE_GARRUS);
562
- },
563
- },
564
- {
565
- delay: 1000,
566
- callback: (instance) => {
567
- instance.callback.agentReadMessages();
568
- instance.callback.agentTyping(true);
569
- },
570
- },
571
- {
572
- delay: 500,
573
- callback: (instance) => {
574
- instance.sendMessageToUser("Hi! I'm **Garrus** and I'm nicer than **Shepard**!", instance.mockState.currentAgent.id);
575
- },
576
- },
577
- ];
578
- }
579
- // A response to talk to a third agent.
580
- function TRANSFER_TO_LEGION() {
581
- return [
582
- {
583
- delay: 0,
584
- callback: (instance) => {
585
- instance.sendMessageToUser("You'll regret this.", instance.mockState.currentAgent.id);
586
- },
587
- },
588
- {
589
- delay: 0,
590
- callback: (instance) => {
591
- instance.callback.agentReadMessages();
592
- instance.callback.agentTyping(true);
593
- },
594
- },
595
- {
596
- delay: 1000,
597
- callback: (instance) => {
598
- instance.mockState.currentAgent = MOCK_AGENT_PROFILE_LEGION;
599
- instance.callback.beginTransferToAnotherAgent(MOCK_AGENT_PROFILE_LEGION);
600
- instance.callback.agentJoined(MOCK_AGENT_PROFILE_LEGION);
601
- },
602
- },
603
- {
604
- delay: 0,
605
- callback: (instance) => {
606
- instance.sendMessageToUser('Shepard-Commander.', instance.mockState.currentAgent.id);
607
- },
608
- },
609
- ];
610
- }
611
- // A response to trigger the agent leaving the chat.
612
- function MESSAGE_TO_AGENT_LEAVE_CHAT() {
613
- return [
614
- {
615
- delay: 0,
616
- callback: (instance) => {
617
- instance.sendMessageToUser('I am leaving now!', instance.mockState.currentAgent.id);
618
- instance.callback.agentLeftChat();
619
- },
620
- },
621
- ];
622
- }
623
- // A response to talk to an agent with no name.
624
- function TRANSFER_TO_EMPTY() {
625
- return [
626
- {
627
- delay: 0,
628
- callback: (instance) => {
629
- instance.sendMessageToUser('Transferring you to a no-name.', instance.mockState.currentAgent.id);
630
- instance.mockState.currentAgent = MOCK_AGENT_PROFILE_EMPTY;
631
- instance.callback.agentJoined(MOCK_AGENT_PROFILE_EMPTY);
632
- instance.sendMessageToUser('Hi.', instance.mockState.currentAgent.id);
633
- },
634
- },
635
- ];
636
- }
637
- // A message from the user that fails.
638
- function MESSAGE_THROW() {
639
- return [
640
- {
641
- delay: 0,
642
- callback: () => { },
643
- returnPromise: Promise.reject(),
644
- },
645
- ];
646
- }
647
- function MESSAGE_IMAGE() {
648
- return [
649
- {
650
- delay: 0,
651
- callback: (instance) => {
652
- const message = {
653
- id: null,
654
- output: {
655
- generic: [
656
- cdsAichatInternal.assertType({
657
- response_type: cdsAichatInternal.MessageResponseTypes.IMAGE,
658
- source: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg',
659
- title: 'Grump cat',
660
- }),
661
- ],
662
- },
663
- };
664
- instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
665
- },
666
- },
667
- ];
668
- }
669
- function MESSAGE_FILES() {
670
- return [
671
- {
672
- delay: 0,
673
- callback: (instance) => {
674
- const message = {
675
- id: null,
676
- output: {
677
- generic: [
678
- cdsAichatInternal.assertType({
679
- response_type: cdsAichatInternal.MessageResponseTypes.BUTTON,
680
- kind: cdsAichatInternal.ButtonItemKind.LINK,
681
- button_type: cdsAichatInternal.ButtonItemType.URL,
682
- url: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg',
683
- label: 'Grump Cat.png',
684
- target: '_blank',
685
- }),
686
- cdsAichatInternal.assertType({
687
- response_type: cdsAichatInternal.MessageResponseTypes.BUTTON,
688
- kind: cdsAichatInternal.ButtonItemKind.LINK,
689
- button_type: cdsAichatInternal.ButtonItemType.URL,
690
- url: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/maine-coon-694730_1280.jpg',
691
- target: '_blank',
692
- }),
693
- ],
694
- },
695
- };
696
- instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
697
- },
698
- },
699
- ];
700
- }
701
- function MESSAGE_VIDEO() {
702
- return [
703
- {
704
- delay: 0,
705
- callback: (instance) => {
706
- const message = {
707
- id: null,
708
- output: {
709
- generic: [
710
- cdsAichatInternal.assertType({
711
- response_type: cdsAichatInternal.MessageResponseTypes.VIDEO,
712
- title: 'The video title',
713
- source: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/lake%20(720p).mp4',
714
- alt_text: 'The video alternate text',
715
- description: 'The video description',
716
- }),
717
- ],
718
- },
719
- };
720
- instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
721
- },
722
- },
723
- ];
724
- }
725
- // A custom response.
726
- function MESSAGE_CUSTOM() {
727
- return [
728
- {
729
- delay: 0,
730
- callback: (instance) => {
731
- const message = {
732
- id: null,
733
- output: {
734
- generic: [
735
- cdsAichatInternal.assertType({
736
- response_type: cdsAichatInternal.MessageResponseTypes.TEXT,
737
- text: 'Below is a custom response but you may not see it if no handler has been created.',
738
- }),
739
- cdsAichatInternal.assertType({
740
- response_type: cdsAichatInternal.MessageResponseTypes.USER_DEFINED,
741
- user_defined: { user_defined_type: 'agent_custom' },
742
- }),
743
- ],
744
- },
745
- };
746
- instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
747
- },
748
- },
749
- ];
750
- }
751
- function MESSAGE_TO_AGENT_MULTIPLE() {
752
- return [
753
- {
754
- delay: 0,
755
- callback: (instance) => {
756
- const message = {
757
- id: null,
758
- output: {
759
- generic: [
760
- cdsAichatInternal.assertType({
761
- response_type: cdsAichatInternal.MessageResponseTypes.TEXT,
762
- text: 'This is a text item in this response.',
763
- }),
764
- cdsAichatInternal.assertType({
765
- response_type: cdsAichatInternal.MessageResponseTypes.TEXT,
766
- text: 'This is a second text item.',
767
- }),
768
- cdsAichatInternal.assertType({
769
- response_type: cdsAichatInternal.MessageResponseTypes.IMAGE,
770
- source: 'https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg',
771
- }),
772
- ],
773
- },
774
- };
775
- instance.sendMessageToUser(message, instance.mockState.currentAgent.id);
776
- },
777
- },
778
- ];
779
- }
780
- // A message from the user that hangs.
781
- function HANG_MESSAGE() {
782
- return [
783
- {
784
- delay: 0,
785
- callback: () => { },
786
- returnPromise: new Promise(() => { }),
787
- },
788
- ];
789
- }
790
- // A response to a user asking for a joke.
791
- function MESSAGE_TO_AGENT_JOKE() {
792
- return [
793
- {
794
- delay: 1000,
795
- callback: (instance) => {
796
- instance.callback.agentReadMessages();
797
- instance.callback.agentTyping(true);
798
- },
799
- },
800
- {
801
- delay: 5000,
802
- callback: (instance) => {
803
- instance.sendMessageToUser("One atom says to another atom: I think I've lost an electron.", instance.mockState.currentAgent.id);
804
- },
805
- },
806
- {
807
- delay: 2000,
808
- callback: (instance) => {
809
- instance.sendMessageToUser('The second atom says: are you sure?', instance.mockState.currentAgent.id);
810
- },
811
- },
812
- {
813
- delay: 2000,
814
- callback: (instance) => {
815
- instance.sendMessageToUser("The first atom says: I'm positive.", instance.mockState.currentAgent.id);
816
- },
817
- },
818
- ];
819
- }
820
- // A message from the user that fails.
821
- function STATE_CHANGED(state) {
822
- return [
823
- {
824
- delay: 0,
825
- callback: (instance) => {
826
- instance.sendMessageToUser(`The web chat state has changed: ${JSON.stringify(state)}`, instance.mockState.currentAgent.id);
827
- },
828
- },
829
- ];
830
- }
831
- const FENCE_BLOCK = `
832
- \`\`\`
833
- const example = {
834
- value: true,
835
- };
836
- \`\`\`
837
- `;
838
- // Note, blockquote is not supported. Our HTML sanitization turns the ">" into "&gt;" which prevents the markdown
839
- // library from turning it into a blockquote.
840
- const MARKDOWN = `
841
- This is **bold**, ***bold and italics***, **bold *italics inside***, *italics **bold inside***, and ~~strikethrough~~.
842
-
843
- # H1
844
- H1 Text
845
- ## H2
846
- H2 Text
847
-
848
- 1. Ordered List 1
849
- 2. Ordered List 2
850
-
851
- - Unordered List 1
852
- - Unordered List 2
853
-
854
- \`Inline code\`
855
-
856
- ${FENCE_BLOCK}
857
-
858
- | Header 1 | Header 2 |
859
- | ----------- | ----------- |
860
- | Text 1 | Text 2 |
861
- | Text 3 | Text 4 |
862
-
863
- ---
864
-
865
- [IBM's HomePage 1 (new tab)](https://ibm.com)
866
-
867
- [IBM's HomePage 1 (same tab)](https://ibm.com){{target=_self}}
868
-
869
- ibm.com (autolink, new tab)
870
-
871
- ![Cute kitten!](https://web-chat.global.assistant.test.watson.appdomain.cloud/assets/cat-1950632_1280.jpg)
872
- `;
873
-
874
- exports.MARKDOWN = MARKDOWN;
875
- exports.MESSAGE_CUSTOM = MESSAGE_CUSTOM;
876
- exports.MESSAGE_FILES = MESSAGE_FILES;
877
- exports.MESSAGE_IMAGE = MESSAGE_IMAGE;
878
- exports.MESSAGE_TO_AGENT_MULTIPLE = MESSAGE_TO_AGENT_MULTIPLE;
879
- exports.MESSAGE_TO_AGENT_TEXT = MESSAGE_TO_AGENT_TEXT;
880
- exports.MESSAGE_VIDEO = MESSAGE_VIDEO;
881
- exports.MOCK_AGENT_PROFILE_EMPTY = MOCK_AGENT_PROFILE_EMPTY;
882
- exports.MOCK_AGENT_PROFILE_GARRUS = MOCK_AGENT_PROFILE_GARRUS;
883
- exports.MOCK_AGENT_PROFILE_LEGION = MOCK_AGENT_PROFILE_LEGION;
884
- exports.MOCK_AGENT_PROFILE_SHEPARD = MOCK_AGENT_PROFILE_SHEPARD;
885
- exports.MockServiceDesk = MockServiceDesk;
886
- exports.TEXT_LONG = TEXT_LONG;
887
- exports.runSteps = runSteps;