@epam/ai-dial-chat-visualizer-connector 0.44.0-rc.2 → 0.44.0-rc.20

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.
package/README.md CHANGED
@@ -18,9 +18,15 @@ _Note: For development purposes you can set `*`_
18
18
  ALLOWED_IFRAME_SOURCES=http://localhost:8000
19
19
  ```
20
20
 
21
- Moreover, it needs to be configured some **Visualizer** properties:
21
+ ## Visualizer Configuration
22
22
 
23
- - `CUSTOM_VISUALIZERS` - list of the objects with custom visualizers properties. This properties are : `{ title, description, icon, contentType, url }`.
23
+ There are two ways to configure visualizers:
24
+
25
+ ### 1. CUSTOM_VISUALIZERS (Single Attachment Mode)
26
+
27
+ Each attachment is rendered in its own iframe based on MIME type.
28
+
29
+ - `CUSTOM_VISUALIZERS` - list of the objects with custom visualizers properties.
24
30
 
25
31
  ```typescript
26
32
  interface CustomVisualizer {
@@ -29,122 +35,128 @@ interface CustomVisualizer {
29
35
  icon: string;
30
36
  contentType: string;
31
37
  url: string;
38
+ passAuthInfo?: boolean;
32
39
  }
33
40
  ```
34
41
 
35
42
  ```json
36
43
  CUSTOM_VISUALIZERS=[
37
44
  {
38
- "title":"CUSTOM_VISUALIZER", // Visualizer title
39
- "description": "CUSTOM VISUALIZER to render images", // Short description for the Visualizer
40
- "icon":"data:image/svg+xml;base64,some-base64-image", // Icon for the Visualizer
41
- "contentType":"image/png,image/jpg", // List of MIME types that Visualizer could render separated by ","
42
- "url":"http://localhost:8000" // Visualizer host
43
- },
44
- {
45
- //Other Visualizer
45
+ "title":"CUSTOM_VISUALIZER",
46
+ "description": "CUSTOM VISUALIZER to render images",
47
+ "icon":"data:image/svg+xml;base64,some-base64-image",
48
+ "contentType":"image/png,image/jpg",
49
+ "url":"http://localhost:8000"
46
50
  }
47
-
48
51
  ]
49
-
50
52
  ```
51
53
 
52
- Futhermore, model or application should send data in **json**-like format which should include layout property. This layout object should have **width**, **height** and **themeId** properties. All other properties could be set to anything you need for your **Visualizer**.
53
-
54
- ```typescript
55
- export interface CustomVisualizerDataLayout {
56
- width: number;
57
- height: number;
58
- themeId: string;
59
- }
60
-
61
- export interface CustomVisualizerData {
62
- layout: CustomVisualizerDataLayout;
63
- }
64
- ```
54
+ ### 2. APPLICATION_VISUALIZERS (Grouped Attachments Mode)
65
55
 
66
- ## To integrate **Visualizer** with _DIAL CHAT_
56
+ All attachments from the same application are grouped and rendered in a single iframe.
67
57
 
68
- 1. Install library
58
+ - `APPLICATION_VISUALIZERS` - JSON dictionary mapping application IDs to visualizer configurations.
69
59
 
70
- ```bash
71
- npm i @epam/ai-dial-chat-visualizer-connector
60
+ ```typescript
61
+ interface ApplicationVisualizerConfig {
62
+ title: string;
63
+ description?: string;
64
+ icon?: string;
65
+ contentType: string;
66
+ url: string;
67
+ passAuthInfo?: boolean;
68
+ }
72
69
  ```
73
70
 
74
- 2. Add file to serving folder in your application or just import it in code
75
-
76
- ```typescript
77
- import { AttachmentData, ChatVisualizerConnector, CustomVisualizerDataLayout } from '@epam/ai-dial-chat-visualizer-connector';
71
+ ```json
72
+ APPLICATION_VISUALIZERS={
73
+ "applicationId": {
74
+ "title": "GROUPED_VISUALIZER",
75
+ "description": "Visualizer for grouped attachments",
76
+ "contentType": "application/vnd.custom+json",
77
+ "url": "http://localhost:8000"
78
+ }
79
+ }
78
80
  ```
79
81
 
80
- `ChatVisualizerConnector` - class which provides needed methods for the **Visualizer**(rendered in the iframe) to interact with **DIAL Chat** (receive data to visualize).
81
- Expects following required arguments:
82
+ **Key difference:** The key in `APPLICATION_VISUALIZERS` must match the `applicationId` (from `message.model.id`) that generates the attachments.
82
83
 
83
- ```typescript
84
- /**
85
- * Params for a ChatVisualizerConnector
86
- * @param dialHost {string | string[]} DIAL CHAT host
87
- * @param appName {string} name of the Visualizer same as in config
88
- * @param dataCallback {(visualizerData: AttachmentData) => void} callback to get data that will be used in the Visualizer
89
- */
90
-
91
- //instance example with single host
92
- new ChatVisualizerConnector('https://hosted-dial-chat-domain.com', 'CUSTOM_VISUALIZER', setData);
93
-
94
- //instance example with multiple hosts
95
- new ChatVisualizerConnector(['https://hosted-dial-chat-domain.com', 'https://backup-dial-chat-domain.com'], 'CUSTOM_VISUALIZER', setData);
96
- ```
84
+ ## Data Structures
97
85
 
98
- `AttachmentData` - interface for the payload you will get from the _DIAL CHAT_
86
+ ### Single Attachment Data (CUSTOM_VISUALIZERS)
99
87
 
100
88
  ```typescript
101
89
  export interface AttachmentData {
102
90
  mimeType: string;
103
91
  visualizerData: CustomVisualizerData;
104
92
  }
105
- ```
106
-
107
- `CustomVisualizerDataLayout` - interface for the layout you will get from the _DIAL CHAT_.
108
- Properties **width**, **height** and **themeId** is needed for the proper rendering in the _DIAL CHAT_.
109
93
 
110
- ```typescript
111
94
  export interface CustomVisualizerDataLayout {
112
95
  width: number;
113
96
  height: number;
114
- themeId: string;
97
+ themeId?: string;
98
+ logInHint?: string;
99
+ providerId?: string;
100
+ }
101
+
102
+ export interface CustomVisualizerData {
103
+ layout: CustomVisualizerDataLayout;
115
104
  }
116
105
  ```
117
106
 
118
- 3. Set `dialHost` to the _DIAL CHAT_ host you want to connect:
107
+ ### Grouped Attachments Data (APPLICATION_VISUALIZERS)
119
108
 
120
109
  ```typescript
121
- const dialHost = 'https://hosted-dial-chat-domain.com';
110
+ export interface GroupedAttachmentsData {
111
+ attachments: AttachmentItem[];
112
+ layout: CustomVisualizerDataLayout;
113
+ }
114
+
115
+ export interface AttachmentItem {
116
+ url: string;
117
+ mimeType: string;
118
+ contentType: string;
119
+ visualizerData: CustomVisualizerData;
120
+ }
121
+ ```
122
+
123
+ ## Integration Guide
124
+
125
+ ### 1. Install library
126
+
127
+ ```bash
128
+ npm i @epam/ai-dial-chat-visualizer-connector
122
129
  ```
123
130
 
124
- Or (new):
131
+ ### 2. Import required modules
125
132
 
126
133
  ```typescript
127
- const dialHost = ['https://hosted-dial-chat-domain.com', 'https://backup-dial-chat-domain.com'];
134
+ import { AttachmentData, ChatVisualizerConnector, CustomVisualizerDataLayout, GroupedAttachmentsData } from '@epam/ai-dial-chat-visualizer-connector';
128
135
  ```
129
136
 
130
- 4. Set `appName` same as `title` in the _DIAL CHAT_ configuration in the `CUSTOM_VISUALIZERS` environmental variable:
137
+ ### 3. Configure host and app name
131
138
 
132
139
  ```typescript
140
+ // DIAL CHAT host (one or multiple)
141
+ const dialHost = 'https://hosted-dial-chat-domain.com';
142
+ // Or multiple hosts:
143
+ // const dialHost = ['https://hosted-dial-chat-domain.com', 'https://backup-dial-chat-domain.com'];
144
+
145
+ // Visualizer title - must match 'title' in CUSTOM_VISUALIZERS or APPLICATION_VISUALIZERS
133
146
  const appName = 'CUSTOM_VISUALIZER';
134
147
  ```
135
148
 
136
- 5. Create an instance of `ChatVisualizerConnector` in your code.
149
+ ### 4. Create ChatVisualizerConnector instance
137
150
 
138
- `ChatVisualizerConnector:`
151
+ #### Option A: Single Attachment Mode (backward compatible)
139
152
 
140
153
  ```typescript
141
- //Here you store your data which you get from the DIAL CHAT
142
154
  const [data, setData] = useState<AttachmentData>();
143
-
144
155
  const chatVisualizerConnector = useRef<ChatVisualizerConnector | null>(null);
145
156
 
146
157
  useEffect(() => {
147
158
  if (!chatVisualizerConnector.current && dialHost && appName) {
159
+ // Pass callback function directly (original API)
148
160
  chatVisualizerConnector.current = new ChatVisualizerConnector(dialHost, appName, setData);
149
161
 
150
162
  return () => {
@@ -155,69 +167,99 @@ useEffect(() => {
155
167
  }, [appName, dialHost]);
156
168
  ```
157
169
 
158
- 6. Send 'READY' event via `sendReady()` to the _DIAL CHAT_ to inform that your **Visualizer** is ready (this action will hide loader). Then you could do some preparation (login, etc.) and, after that, send 'READY TO INTERACT' event via `sendReadyToInteract()` to inform _DIAL CHAT_ that **Visualizer** is ready to receive data.
170
+ #### Option B: Support Both Single and Grouped Attachments
171
+
172
+ ```typescript
173
+ const [data, setData] = useState<AttachmentData>();
174
+ const [groupedData, setGroupedData] = useState<GroupedAttachmentsData>();
175
+ const chatVisualizerConnector = useRef<ChatVisualizerConnector | null>(null);
176
+
177
+ useEffect(() => {
178
+ if (!chatVisualizerConnector.current && dialHost && appName) {
179
+ // Pass callbacks object to handle both modes
180
+ chatVisualizerConnector.current = new ChatVisualizerConnector(dialHost, appName, {
181
+ onData: setData, // Called for CUSTOM_VISUALIZERS (single attachment)
182
+ onGroupedData: setGroupedData, // Called for APPLICATION_VISUALIZERS (grouped)
183
+ });
184
+
185
+ return () => {
186
+ chatVisualizerConnector.current?.destroy();
187
+ chatVisualizerConnector.current = null;
188
+ };
189
+ }
190
+ }, [appName, dialHost]);
191
+ ```
192
+
193
+ ### 5. Send ready events
159
194
 
160
195
  ```typescript
161
196
  useEffect(() => {
162
197
  if (appName && dialHost) {
163
198
  chatVisualizerConnector.current?.sendReady();
164
- //Make some actions if needed
199
+ // Make some actions if needed (login, etc.)
165
200
  chatVisualizerConnector.current?.sendReadyToInteract();
166
201
  }
167
202
  }, [dialHost, appName]);
168
203
  ```
169
204
 
170
- 7. Make needed type assertion for the data from the _DIAL CHAT_
171
-
172
- _Note: Data send by model/application from DIAL CHAT should be the same type as you expect._
205
+ ### 6. Process received data
173
206
 
174
207
  ```typescript
175
- //layout should include width, height and themeId properties
176
- interface YourVisualizerLayout extends CustomVisualizerDataLayout {
177
- //any other layout properties expected from the model/application output
178
- }
179
- data.visualizerData as { dataToRender: string; layout: YourVisualizerLayout };
180
- ```
208
+ const content = useMemo(() => {
209
+ // Handle grouped attachments (APPLICATION_VISUALIZERS)
210
+ if (groupedData?.attachments) {
211
+ return groupedData.attachments.map((att) => ({
212
+ url: att.url,
213
+ mimeType: att.mimeType,
214
+ contentType: att.contentType,
215
+ data: att.visualizerData,
216
+ }));
217
+ }
181
218
 
182
- 8. Render data in your **Visualizer**;
219
+ // Handle single attachment (CUSTOM_VISUALIZERS)
220
+ if (data?.visualizerData) {
221
+ return [data];
222
+ }
183
223
 
184
- ```tsx
185
- <div>{typedVisualizerData.dataToRender}</div>
224
+ return [];
225
+ }, [data, groupedData]);
186
226
  ```
187
227
 
188
- ### Sending to a particular host when multiple were passed
228
+ ### 7. Render data
189
229
 
190
- ```typescript
191
- chatVisualizerConnector.current?.send({
192
- type: VisualizerConnectorEvents.sendMessage,
193
- payload: { message: 'hello from visualizer' },
194
- dialHost: 'https://hosted-dial-chat-domain.com',
195
- });
230
+ ```tsx
231
+ <div>
232
+ {content.map((item, index) => (
233
+ <div key={index}>{/* Render your visualization */}</div>
234
+ ))}
235
+ </div>
196
236
  ```
197
237
 
198
- If `dialHost` is **not** provided in `send(...)`, the connector will send the message to **all** hosts passed in the constructor.
199
-
200
- ### Full React code example to connect your custom visualizer
238
+ ## Full React Example (Supporting Both Modes)
201
239
 
202
240
  ```typescript
241
+ import { FC, useState, useRef, useEffect, useMemo } from 'react';
242
+ import {
243
+ AttachmentData,
244
+ GroupedAttachmentsData,
245
+ ChatVisualizerConnector,
246
+ CustomVisualizerDataLayout
247
+ } from '@epam/ai-dial-chat-visualizer-connector';
203
248
 
204
- import { AttachmentData, ChatVisualizerConnector, CustomVisualizerDataLayout } from '@epam/ai-dial-chat-visualizer-connector';
205
-
249
+ interface YourVisualizerLayout extends CustomVisualizerDataLayout {
250
+ // Add any additional layout properties
251
+ }
206
252
 
207
253
  export const Module: FC = () => {
208
254
  const [data, setData] = useState<AttachmentData>();
255
+ const [groupedData, setGroupedData] = useState<GroupedAttachmentsData>();
209
256
 
210
- const chatVisualizerConnector = useRef<ChatVisualizerConnector | null>(
211
- null
212
- );
257
+ const chatVisualizerConnector = useRef<ChatVisualizerConnector | null>(null);
213
258
 
214
- //DIAL CHAT host (one or multiple)
215
- const dialHost = [
216
- 'https://hosted-dial-chat-domain.com',
217
- 'https://backup-dial-chat-domain.com'
218
- ];
259
+ // DIAL CHAT host
260
+ const dialHost = 'https://hosted-dial-chat-domain.com';
219
261
 
220
- //Visualizer title. Should be same as in the DIAL CHAT configuration in CUSTOM_VISUALIZERS
262
+ // Visualizer title - must match configuration
221
263
  const appName = 'CUSTOM_VISUALIZER';
222
264
 
223
265
  useEffect(() => {
@@ -225,7 +267,16 @@ export const Module: FC = () => {
225
267
  chatVisualizerConnector.current = new ChatVisualizerConnector(
226
268
  dialHost,
227
269
  appName,
228
- setData
270
+ {
271
+ onData: (payload) => {
272
+ console.log('[Visualizer] Received single attachment:', payload);
273
+ setData(payload);
274
+ },
275
+ onGroupedData: (payload) => {
276
+ console.log('[Visualizer] Received grouped attachments:', payload);
277
+ setGroupedData(payload);
278
+ }
279
+ }
229
280
  );
230
281
 
231
282
  return () => {
@@ -242,32 +293,131 @@ export const Module: FC = () => {
242
293
  }
243
294
  }, [dialHost, appName]);
244
295
 
245
- const typedVisualizerData = useMemo(() => {
246
- return (
247
- data?.visualizerData && (data.visualizerData as unknown as { dataToRender: string; layout: YourVisualizerLayout })
248
- );
249
- }, [data?.visualizerData]);
296
+ // Process data from either mode
297
+ const items = useMemo(() => {
298
+ // Grouped mode (APPLICATION_VISUALIZERS)
299
+ if (groupedData?.attachments) {
300
+ return groupedData.attachments.map(att => ({
301
+ mimeType: att.mimeType,
302
+ visualizerData: att.visualizerData as unknown as {
303
+ dataToRender: string;
304
+ layout: YourVisualizerLayout;
305
+ }
306
+ }));
307
+ }
308
+
309
+ // Single mode (CUSTOM_VISUALIZERS)
310
+ if (data?.visualizerData) {
311
+ return [{
312
+ mimeType: data.mimeType,
313
+ visualizerData: data.visualizerData as unknown as {
314
+ dataToRender: string;
315
+ layout: YourVisualizerLayout;
316
+ }
317
+ }];
318
+ }
319
+
320
+ return [];
321
+ }, [data, groupedData]);
250
322
 
251
323
  return (
252
324
  <div>
253
- {!!typedVisualizerData?.dataToRender && (
254
- <div>
255
- {typedVisualizerData.dataToRender}
256
- </div>
257
- )}
325
+ {items.map((item, index) => (
326
+ <div key={index}>
327
+ {item.visualizerData?.dataToRender && (
328
+ <div>{item.visualizerData.dataToRender}</div>
329
+ )}
330
+ </div>
331
+ ))}
258
332
  </div>
259
333
  );
260
334
  };
335
+ ```
336
+
337
+ ## API Reference
338
+
339
+ ### ChatVisualizerConnector
340
+
341
+ #### Constructor
261
342
 
343
+ ```typescript
344
+ constructor(
345
+ dialHost: string | string[],
346
+ appName: string,
347
+ dataCallback: ((visualizerData: AttachmentData) => void) | ChatVisualizerCallbacks
348
+ )
262
349
  ```
263
350
 
264
- `index.ts`
351
+ **Parameters:**
352
+
353
+ - `dialHost` - DIAL CHAT host URL(s)
354
+ - `appName` - Visualizer name (must match `title` in configuration)
355
+ - `dataCallback` - Either a single callback function or a `ChatVisualizerCallbacks` object
356
+
357
+ #### ChatVisualizerCallbacks
265
358
 
266
359
  ```typescript
267
- //...other imports
268
- import { Module } from "./Module.tsx";
360
+ interface ChatVisualizerCallbacks {
361
+ onData?: (visualizerData: AttachmentData) => void;
362
+ onGroupedData?: (groupedData: GroupedAttachmentsData) => void;
363
+ }
364
+ ```
365
+
366
+ #### Methods
367
+
368
+ | Method | Description |
369
+ | ------------------------------------ | --------------------------------------------------------- |
370
+ | `sendReady()` | Notify DIAL Chat that visualizer is loaded (hides loader) |
371
+ | `sendReadyToInteract()` | Notify DIAL Chat that visualizer is ready to receive data |
372
+ | `sendMessage(content: string)` | Send a message to the chat |
373
+ | `send({ type, payload, dialHost? })` | Send custom event to DIAL Chat |
374
+ | `destroy()` | Clean up event listeners |
375
+
376
+ ### Sending to a particular host when multiple were passed
377
+
378
+ ```typescript
379
+ chatVisualizerConnector.current?.send({
380
+ type: VisualizerConnectorEvents.sendMessage,
381
+ payload: { message: 'hello from visualizer' },
382
+ dialHost: 'https://hosted-dial-chat-domain.com',
383
+ });
384
+ ```
269
385
 
270
- const root = createRoot(document.getElementById("root"));
271
- root.render(<Module />);
386
+ If `dialHost` is **not** provided in `send(...)`, the connector will send the message to **all** hosts passed in the constructor.
387
+
388
+ ## Troubleshooting
389
+
390
+ ### Timeout Error
272
391
 
273
392
  ```
393
+ [VisualizerConnector] Request APP_NAME/SEND_GROUPED_VISUALIZE_DATA failed. Timeout 10000
394
+ ```
395
+
396
+ **Cause:** The visualizer is not responding to the data request.
397
+
398
+ **Solutions:**
399
+
400
+ 1. Ensure `appName` matches the `title` in your configuration
401
+ 2. Verify you're using the callbacks object format with `onGroupedData` for grouped mode
402
+ 3. Check browser console for any errors in the visualizer
403
+
404
+ ### PostMessage Origin Error
405
+
406
+ ```
407
+ Failed to execute 'postMessage' on 'DOMWindow': The target origin provided does not match...
408
+ ```
409
+
410
+ **Cause:** The `dialHost` parameter doesn't match the actual DIAL Chat origin.
411
+
412
+ **Solutions:**
413
+
414
+ 1. Ensure `dialHost` is set to the DIAL Chat URL (not the visualizer URL)
415
+ 2. Verify the visualizer is running inside an iframe from DIAL Chat
416
+
417
+ ### No Data Received
418
+
419
+ **Checklist:**
420
+
421
+ 1. `appName` must match `title` in `CUSTOM_VISUALIZERS` or `APPLICATION_VISUALIZERS`
422
+ 2. For `APPLICATION_VISUALIZERS`, the key must match the `applicationId` from messages
423
+ 3. `sendReady()` and `sendReadyToInteract()` must be called after connector creation
package/index.esm.js CHANGED
@@ -40,7 +40,7 @@ class ChatVisualizerConnector {
40
40
  * Creates a ChatVisualizerConnector
41
41
  * @param dialHost {string | string[]} DIAL CHAT host(s)
42
42
  * @param appName {string} name of the Visualizer same as in config
43
- * @param dataCallback {(visualizerData: AttachmentData) => void} callback to get data that will be used in the Visualizer
43
+ * @param dataCallback {(visualizerData: AttachmentData) => void | ChatVisualizerCallbacks} callback(s) to get data
44
44
  */
45
45
  constructor(dialHost, appName, dataCallback) {
46
46
  const hosts = Array.isArray(dialHost) ? dialHost : [dialHost];
@@ -51,7 +51,18 @@ class ChatVisualizerConnector {
51
51
  // keep old field for backward compatibility
52
52
  this.dialHost = hosts[0];
53
53
  this.appName = appName;
54
- this.dataCallback = dataCallback;
54
+ // Support both old callback format and new callbacks object
55
+ if (typeof dataCallback === 'function') {
56
+ this.dataCallback = dataCallback;
57
+ }
58
+ else {
59
+ this.dataCallback =
60
+ dataCallback.onData ||
61
+ (() => {
62
+ console.warn('[ChatVisualizerConnector] No data callback provided');
63
+ });
64
+ this.groupedDataCallback = dataCallback.onGroupedData;
65
+ }
55
66
  this.postMessageListener = this.postMessageListener.bind(this);
56
67
  window.addEventListener('message', this.postMessageListener, false);
57
68
  }
@@ -93,6 +104,7 @@ class ChatVisualizerConnector {
93
104
  // check if there is a payload
94
105
  if (typeof event.data.payload !== 'object' || event.data.payload === null)
95
106
  return;
107
+ // Handle single attachment data (CUSTOM_VISUALIZERS)
96
108
  if (event.data.type ===
97
109
  `${this.appName}/${VisualizerConnectorRequests.sendVisualizeData}`) {
98
110
  const payload = Object.prototype.hasOwnProperty.call(event.data.payload, 'visualizerData') &&
@@ -105,6 +117,21 @@ class ChatVisualizerConnector {
105
117
  requestId: event.data.requestId,
106
118
  });
107
119
  }
120
+ // Handle grouped attachments data (APPLICATION_VISUALIZERS)
121
+ if (event.data.type ===
122
+ `${this.appName}/${VisualizerConnectorRequests.sendGroupedVisualizeData}`) {
123
+ const payload = Object.prototype.hasOwnProperty.call(event.data.payload, 'attachments') &&
124
+ Object.prototype.hasOwnProperty.call(event.data.payload, 'layout') &&
125
+ event.data.payload;
126
+ if (payload && this.groupedDataCallback) {
127
+ this.groupedDataCallback(payload);
128
+ }
129
+ this.sendPMResponse({
130
+ type: event.data.type,
131
+ dialHost: event.origin,
132
+ requestId: event.data.requestId,
133
+ });
134
+ }
108
135
  }
109
136
  /**
110
137
  * Sends 'READY' event via postMessage to the DIAL CHAT to notify that Visualizer loaded
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@epam/ai-dial-chat-visualizer-connector",
3
3
  "description": "Package for custom visualizer to connect with DIAL Chat",
4
4
  "homepage": "https://dialx.ai",
5
- "version": "0.44.0-rc.2",
5
+ "version": "0.44.0-rc.20",
6
6
  "dependencies": {
7
- "@epam/ai-dial-shared": "0.44.0-rc.2"
7
+ "@epam/ai-dial-shared": "0.44.0-rc.20"
8
8
  },
9
9
  "type": "module",
10
10
  "bugs": {
package/src/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './lib/ChatVisualizerConnector';
2
- export { type AttachmentData, type CustomVisualizerDataLayout, } from '@epam/ai-dial-shared';
2
+ export { type AttachmentData, type AttachmentItem, type CustomVisualizerDataLayout, type GroupedAttachmentsData, } from '@epam/ai-dial-shared';
@@ -1,4 +1,4 @@
1
- import { AttachmentData, VisualizerConnectorEvents, VisualizerConnectorRequests } from '@epam/ai-dial-shared';
1
+ import { AttachmentData, GroupedAttachmentsData, VisualizerConnectorEvents, VisualizerConnectorRequests } from '@epam/ai-dial-shared';
2
2
  interface RequestParams {
3
3
  type: VisualizerConnectorRequests;
4
4
  requestId: string;
@@ -7,6 +7,15 @@ interface RequestParams {
7
7
  export interface PostMessageRequestParams extends RequestParams {
8
8
  dialHost: string;
9
9
  }
10
+ /**
11
+ * Callback options for ChatVisualizerConnector
12
+ */
13
+ export interface ChatVisualizerCallbacks {
14
+ /** Callback for single attachment data (CUSTOM_VISUALIZERS) */
15
+ onData?: (visualizerData: AttachmentData) => void;
16
+ /** Callback for grouped attachments data (APPLICATION_VISUALIZERS) */
17
+ onGroupedData?: (groupedData: GroupedAttachmentsData) => void;
18
+ }
10
19
  /**
11
20
  * Class which creates connector with DIAL CHAT, allows to interact with it (send/receive data via post messages)
12
21
  */
@@ -20,13 +29,14 @@ export declare class ChatVisualizerConnector {
20
29
  protected dialHosts: string[];
21
30
  protected appName: string;
22
31
  protected dataCallback: (visualizerData: AttachmentData) => void;
32
+ protected groupedDataCallback?: (groupedData: GroupedAttachmentsData) => void;
23
33
  /**
24
34
  * Creates a ChatVisualizerConnector
25
35
  * @param dialHost {string | string[]} DIAL CHAT host(s)
26
36
  * @param appName {string} name of the Visualizer same as in config
27
- * @param dataCallback {(visualizerData: AttachmentData) => void} callback to get data that will be used in the Visualizer
37
+ * @param dataCallback {(visualizerData: AttachmentData) => void | ChatVisualizerCallbacks} callback(s) to get data
28
38
  */
29
- constructor(dialHost: string | string[], appName: string, dataCallback: (visualizerData: AttachmentData) => void);
39
+ constructor(dialHost: string | string[], appName: string, dataCallback: ((visualizerData: AttachmentData) => void) | ChatVisualizerCallbacks);
30
40
  /**
31
41
  * Sends the post message to the DIAL Chat
32
42
  * @param type Visualizer Event name