@thoughtspot/visual-embed-sdk 1.39.2 → 1.39.3
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/cjs/package.json +1 -1
- package/cjs/src/config.spec.js +9 -0
- package/cjs/src/config.spec.js.map +1 -1
- package/cjs/src/embed/app.d.ts +19 -15
- package/cjs/src/embed/app.d.ts.map +1 -1
- package/cjs/src/embed/app.js +23 -2
- package/cjs/src/embed/app.js.map +1 -1
- package/cjs/src/embed/app.spec.js +56 -8
- package/cjs/src/embed/app.spec.js.map +1 -1
- package/cjs/src/embed/bodyless-conversation.d.ts +23 -7
- package/cjs/src/embed/bodyless-conversation.d.ts.map +1 -1
- package/cjs/src/embed/bodyless-conversation.js +31 -5
- package/cjs/src/embed/bodyless-conversation.js.map +1 -1
- package/cjs/src/embed/bodyless-conversation.spec.js +8 -190
- package/cjs/src/embed/bodyless-conversation.spec.js.map +1 -1
- package/cjs/src/embed/conversation.spec.js +28 -0
- package/cjs/src/embed/conversation.spec.js.map +1 -1
- package/cjs/src/embed/embedConfig.d.ts +9 -7
- package/cjs/src/embed/embedConfig.d.ts.map +1 -1
- package/cjs/src/embed/embedConfig.js +9 -7
- package/cjs/src/embed/embedConfig.js.map +1 -1
- package/cjs/src/embed/liveboard.d.ts +0 -17
- package/cjs/src/embed/liveboard.d.ts.map +1 -1
- package/cjs/src/embed/liveboard.js +2 -4
- package/cjs/src/embed/liveboard.js.map +1 -1
- package/cjs/src/embed/liveboard.spec.js +12 -11
- package/cjs/src/embed/liveboard.spec.js.map +1 -1
- package/cjs/src/errors.d.ts +1 -0
- package/cjs/src/errors.d.ts.map +1 -1
- package/cjs/src/errors.js +1 -0
- package/cjs/src/errors.js.map +1 -1
- package/cjs/src/index.d.ts +2 -2
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/index.js +2 -1
- package/cjs/src/index.js.map +1 -1
- package/cjs/src/react/all-types-export.d.ts +1 -1
- package/cjs/src/react/all-types-export.d.ts.map +1 -1
- package/cjs/src/react/all-types-export.js +3 -2
- package/cjs/src/react/all-types-export.js.map +1 -1
- package/cjs/src/react/index.d.ts +73 -20
- package/cjs/src/react/index.d.ts.map +1 -1
- package/cjs/src/react/index.js +79 -42
- package/cjs/src/react/index.js.map +1 -1
- package/cjs/src/react/index.spec.js +438 -100
- package/cjs/src/react/index.spec.js.map +1 -1
- package/cjs/src/types.d.ts +262 -6
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js +228 -2
- package/cjs/src/types.js.map +1 -1
- package/cjs/src/utils/global-styles.js +1 -1
- package/cjs/src/utils/graphql/nlsService/conversation-service.d.ts.map +1 -1
- package/cjs/src/utils/graphql/nlsService/conversation-service.js +7 -1
- package/cjs/src/utils/graphql/nlsService/conversation-service.js.map +1 -1
- package/cjs/src/utils.spec.js +25 -0
- package/cjs/src/utils.spec.js.map +1 -1
- package/dist/{index-CmEQfuE3.js → index-ZrE8YYq8.js} +1 -1
- package/dist/src/embed/app.d.ts +19 -15
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/bodyless-conversation.d.ts +23 -7
- package/dist/src/embed/bodyless-conversation.d.ts.map +1 -1
- package/dist/src/embed/embedConfig.d.ts +9 -7
- package/dist/src/embed/embedConfig.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +0 -17
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/errors.d.ts +1 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/react/all-types-export.d.ts +1 -1
- package/dist/src/react/all-types-export.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +73 -20
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/types.d.ts +262 -6
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/graphql/nlsService/conversation-service.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +385 -71
- package/dist/tsembed-react.js +385 -69
- package/dist/tsembed.es.js +303 -24
- package/dist/tsembed.js +301 -22
- package/dist/visual-embed-sdk-react-full.d.ts +386 -72
- package/dist/visual-embed-sdk-react.d.ts +386 -72
- package/dist/visual-embed-sdk.d.ts +314 -53
- package/lib/package.json +1 -1
- package/lib/src/config.spec.js +9 -0
- package/lib/src/config.spec.js.map +1 -1
- package/lib/src/embed/app.d.ts +19 -15
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +22 -1
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/app.spec.js +58 -10
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/bodyless-conversation.d.ts +23 -7
- package/lib/src/embed/bodyless-conversation.d.ts.map +1 -1
- package/lib/src/embed/bodyless-conversation.js +30 -5
- package/lib/src/embed/bodyless-conversation.js.map +1 -1
- package/lib/src/embed/bodyless-conversation.spec.js +9 -191
- package/lib/src/embed/bodyless-conversation.spec.js.map +1 -1
- package/lib/src/embed/conversation.spec.js +30 -2
- package/lib/src/embed/conversation.spec.js.map +1 -1
- package/lib/src/embed/embedConfig.d.ts +9 -7
- package/lib/src/embed/embedConfig.d.ts.map +1 -1
- package/lib/src/embed/embedConfig.js +9 -7
- package/lib/src/embed/embedConfig.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +0 -17
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +2 -4
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +12 -11
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/errors.d.ts +1 -0
- package/lib/src/errors.d.ts.map +1 -1
- package/lib/src/errors.js +1 -0
- package/lib/src/errors.js.map +1 -1
- package/lib/src/index.d.ts +2 -2
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +2 -2
- package/lib/src/index.js.map +1 -1
- package/lib/src/react/all-types-export.d.ts +1 -1
- package/lib/src/react/all-types-export.d.ts.map +1 -1
- package/lib/src/react/all-types-export.js +1 -1
- package/lib/src/react/all-types-export.js.map +1 -1
- package/lib/src/react/index.d.ts +73 -20
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +79 -43
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/react/index.spec.js +441 -103
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/types.d.ts +262 -6
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +228 -2
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/global-styles.js +1 -1
- package/lib/src/utils/graphql/nlsService/conversation-service.d.ts.map +1 -1
- package/lib/src/utils/graphql/nlsService/conversation-service.js +7 -1
- package/lib/src/utils/graphql/nlsService/conversation-service.js.map +1 -1
- package/lib/src/utils.spec.js +26 -1
- package/lib/src/utils.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +315 -54
- package/package.json +1 -1
- package/src/config.spec.ts +11 -0
- package/src/embed/app.spec.ts +90 -23
- package/src/embed/app.ts +27 -15
- package/src/embed/bodyless-conversation.spec.ts +9 -203
- package/src/embed/bodyless-conversation.ts +34 -10
- package/src/embed/conversation.spec.ts +40 -2
- package/src/embed/embedConfig.ts +10 -8
- package/src/embed/liveboard.spec.ts +5 -4
- package/src/embed/liveboard.ts +2 -22
- package/src/errors.ts +1 -0
- package/src/index.ts +2 -0
- package/src/react/all-types-export.ts +2 -1
- package/src/react/index.spec.tsx +558 -157
- package/src/react/index.tsx +117 -51
- package/src/types.ts +301 -44
- package/src/utils/global-styles.ts +1 -1
- package/src/utils/graphql/nlsService/conversation-service.ts +7 -1
- package/src/utils.spec.ts +29 -0
package/src/react/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { useRef } from 'react';
|
|
3
|
+
import React, { useRef, useCallback } from 'react';
|
|
4
4
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
|
5
5
|
import { AuthEventEmitter } from '../auth';
|
|
6
6
|
import { deepMerge } from '../utils';
|
|
@@ -10,12 +10,13 @@ import { SearchEmbed as _SearchEmbed, SearchViewConfig } from '../embed/search';
|
|
|
10
10
|
import { AppEmbed as _AppEmbed, AppViewConfig } from '../embed/app';
|
|
11
11
|
import { LiveboardEmbed as _LiveboardEmbed, LiveboardViewConfig } from '../embed/liveboard';
|
|
12
12
|
import { TsEmbed } from '../embed/ts-embed';
|
|
13
|
-
import { SpotterAgentEmbed as _SpotterAgentEmbed, SpotterAgentEmbedViewConfig } from '../embed/bodyless-conversation';
|
|
13
|
+
import { SpotterAgentEmbed as _SpotterAgentEmbed, SpotterAgentEmbedViewConfig, ConversationMessage as _ConversationMessage, SpotterAgentMessageViewConfig } from '../embed/bodyless-conversation';
|
|
14
14
|
|
|
15
15
|
import { EmbedConfig, EmbedEvent, AllEmbedViewConfig } from '../types';
|
|
16
16
|
import { EmbedProps, getViewPropsAndListeners } from './util';
|
|
17
17
|
import { SpotterEmbed as _SpotterEmbed, SpotterEmbedViewConfig, ConversationEmbed as _ConversationEmbed, ConversationViewConfig } from '../embed/conversation';
|
|
18
18
|
import { init } from '../embed/base';
|
|
19
|
+
import { ERROR_MESSAGE } from '../errors';
|
|
19
20
|
|
|
20
21
|
const componentFactory = <T extends typeof TsEmbed, U extends EmbedProps, V extends AllEmbedViewConfig>(
|
|
21
22
|
EmbedConstructor: T,
|
|
@@ -383,62 +384,61 @@ export const ConversationEmbed = componentFactory<
|
|
|
383
384
|
ConversationViewConfig
|
|
384
385
|
>(_ConversationEmbed);
|
|
385
386
|
|
|
386
|
-
|
|
387
|
+
/**
|
|
388
|
+
* React component for individual conversation messages from SpotterAgent.
|
|
389
|
+
* This component is used internally by the useSpotterAgent hook.
|
|
390
|
+
* @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl
|
|
391
|
+
*/
|
|
392
|
+
interface ConversationMessageProps extends EmbedProps, SpotterAgentMessageViewConfig {}
|
|
393
|
+
|
|
394
|
+
export const ConversationMessage = componentFactory<
|
|
395
|
+
typeof _ConversationMessage,
|
|
396
|
+
ConversationMessageProps,
|
|
397
|
+
SpotterAgentMessageViewConfig
|
|
398
|
+
>(_ConversationMessage);
|
|
399
|
+
|
|
400
|
+
type SpotterMessageProps = {
|
|
401
|
+
message: SpotterAgentMessageViewConfig;
|
|
402
|
+
query?: string;
|
|
403
|
+
} & Omit<EmbedProps, keyof SpotterAgentMessageViewConfig>;
|
|
387
404
|
|
|
388
405
|
/**
|
|
389
|
-
* React component for
|
|
390
|
-
*
|
|
406
|
+
* React component for displaying individual conversation messages from SpotterAgent.
|
|
407
|
+
*
|
|
408
|
+
* This component renders a single message response from your ThoughtSpot conversation,
|
|
409
|
+
* showing charts, visualizations, or text responses based on the user's query.
|
|
410
|
+
*
|
|
391
411
|
* @example
|
|
392
412
|
* ```tsx
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* <SpotterAgentEmbed ref={ref} worksheetId="worksheetId" />
|
|
406
|
-
* <button onClick={handleSendMessage}>Send Message</button>
|
|
407
|
-
* </div>
|
|
408
|
-
* );
|
|
413
|
+
* const { sendMessage } = useSpotterAgent({ worksheetId: 'worksheetId' });
|
|
414
|
+
* const result = await sendMessage('show me sales by region');
|
|
415
|
+
*
|
|
416
|
+
* if (!result.error) {
|
|
417
|
+
* // Simple usage - just pass the message data
|
|
418
|
+
* <SpotterMessage message={result.message} />
|
|
419
|
+
*
|
|
420
|
+
* // With optional query for context
|
|
421
|
+
* <SpotterMessage
|
|
422
|
+
* message={result.message}
|
|
423
|
+
* query={result.query}
|
|
424
|
+
* />
|
|
409
425
|
* }
|
|
410
426
|
* ```
|
|
427
|
+
* @version SDK: 1.39.0 | ThoughtSpot: 10.11.0.cl
|
|
411
428
|
*/
|
|
412
|
-
export const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (serviceRef.current) {
|
|
418
|
-
serviceRef.current = null;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const configProps = {
|
|
422
|
-
...restProps,
|
|
423
|
-
...(className ? { containerClassName: className } : {})
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
serviceRef.current = new _SpotterAgentEmbed(configProps);
|
|
429
|
+
export const SpotterMessage = React.forwardRef<
|
|
430
|
+
React.ComponentRef<typeof ConversationMessage>,
|
|
431
|
+
SpotterMessageProps
|
|
432
|
+
>((props, ref) => {
|
|
433
|
+
const { message, query: _, ...otherProps } = props;
|
|
427
434
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return () => {
|
|
437
|
-
serviceRef.current = null;
|
|
438
|
-
};
|
|
439
|
-
}, [props]);
|
|
440
|
-
|
|
441
|
-
return null;
|
|
435
|
+
return (
|
|
436
|
+
<ConversationMessage
|
|
437
|
+
ref={ref}
|
|
438
|
+
{...message}
|
|
439
|
+
{...otherProps}
|
|
440
|
+
/>
|
|
441
|
+
);
|
|
442
442
|
});
|
|
443
443
|
|
|
444
444
|
/**
|
|
@@ -470,7 +470,8 @@ type EmbedComponent = typeof SearchEmbed
|
|
|
470
470
|
| typeof LiveboardEmbed
|
|
471
471
|
| typeof SearchBarEmbed
|
|
472
472
|
| typeof SageEmbed
|
|
473
|
-
| typeof
|
|
473
|
+
| typeof ConversationMessage
|
|
474
|
+
| typeof SpotterMessage
|
|
474
475
|
| typeof SpotterEmbed
|
|
475
476
|
| typeof ConversationEmbed;
|
|
476
477
|
|
|
@@ -518,6 +519,71 @@ export function useInit(config: EmbedConfig) {
|
|
|
518
519
|
return ref;
|
|
519
520
|
}
|
|
520
521
|
|
|
522
|
+
/**
|
|
523
|
+
* React hook for interacting with SpotterAgent AI conversations.
|
|
524
|
+
*
|
|
525
|
+
* This hook provides a sendMessage function that allows you to send natural language
|
|
526
|
+
* queries to your data and get back AI-generated responses with visualizations.
|
|
527
|
+
*
|
|
528
|
+
* @param config - Configuration object containing worksheetId and other options
|
|
529
|
+
* @returns Object with sendMessage function that returns conversation results
|
|
530
|
+
* @example
|
|
531
|
+
* ```tsx
|
|
532
|
+
* const { sendMessage } = useSpotterAgent({ worksheetId: 'worksheetId' });
|
|
533
|
+
*
|
|
534
|
+
* const handleQuery = async () => {
|
|
535
|
+
* const result = await sendMessage('show me sales by region');
|
|
536
|
+
*
|
|
537
|
+
* if (!result.error) {
|
|
538
|
+
* // Display the message response
|
|
539
|
+
* <SpotterMessage message={result.message} />
|
|
540
|
+
* } else {
|
|
541
|
+
* console.error('Error:', result.error);
|
|
542
|
+
* }
|
|
543
|
+
* };
|
|
544
|
+
* ```
|
|
545
|
+
* @version SDK: 1.39.0 | ThoughtSpot: 10.11.0.cl
|
|
546
|
+
*/
|
|
547
|
+
export function useSpotterAgent(config: SpotterAgentEmbedViewConfig) {
|
|
548
|
+
const serviceRef = useRef<_SpotterAgentEmbed | null>(null);
|
|
549
|
+
|
|
550
|
+
useDeepCompareEffect(() => {
|
|
551
|
+
if (serviceRef.current) {
|
|
552
|
+
serviceRef.current = null;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
serviceRef.current = new _SpotterAgentEmbed(config);
|
|
556
|
+
|
|
557
|
+
return () => {
|
|
558
|
+
serviceRef.current = null;
|
|
559
|
+
};
|
|
560
|
+
}, [config]);
|
|
561
|
+
|
|
562
|
+
const sendMessage = useCallback(async (query: string) => {
|
|
563
|
+
if (!serviceRef.current) {
|
|
564
|
+
return { error: new Error(ERROR_MESSAGE.SPOTTER_AGENT_NOT_INITIALIZED) };
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const result = await serviceRef.current.sendMessageData(query);
|
|
568
|
+
|
|
569
|
+
if (result.error) {
|
|
570
|
+
return { error: result.error };
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return {
|
|
574
|
+
query: query,
|
|
575
|
+
message: {
|
|
576
|
+
...result.data,
|
|
577
|
+
worksheetId: config.worksheetId,
|
|
578
|
+
},
|
|
579
|
+
};
|
|
580
|
+
}, [config.worksheetId]);
|
|
581
|
+
|
|
582
|
+
return {
|
|
583
|
+
sendMessage,
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
521
587
|
export {
|
|
522
588
|
LiveboardViewConfig,
|
|
523
589
|
SearchViewConfig,
|