@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
140 lines • 6.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConversationEmbed = exports.SpotterEmbed = void 0;
const errors_1 = require("../errors");
const types_1 = require("../types");
const ts_embed_1 = require("./ts-embed");
const spotter_utils_1 = require("./spotter-utils");
const utils_1 = require("../utils");
/**
* Embed ThoughtSpot AI Conversation.
* @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl
* @group Embed components
* @example
* ```js
* const conversation = new SpotterEmbed('#tsEmbed', {
* worksheetId: 'worksheetId',
* searchOptions: {
* searchQuery: 'searchQuery',
* },
* });
* conversation.render();
* ```
*/
class SpotterEmbed extends ts_embed_1.TsEmbed {
constructor(container, viewConfig) {
viewConfig = {
embedComponentType: 'conversation',
excludeRuntimeFiltersfromURL: true,
excludeRuntimeParametersfromURL: true,
...viewConfig,
};
super(container, viewConfig);
this.viewConfig = viewConfig;
}
/**
* Extends the default APP_INIT payload with `embedParams.spotterSidebarConfig`
* so the conv-assist app can read sidebar configuration on initialisation.
*
* Precedence for `enablePastConversationsSidebar`:
* `spotterSidebarConfig.enablePastConversationsSidebar` wins over the
* deprecated top-level `enablePastConversationsSidebar` flag; if the former
* is absent the latter is used as a fallback.
*
* An invalid `spotterDocumentationUrl` triggers a validation error and is
* excluded from the payload rather than forwarded to the app.
*/
async getAppInitData() {
const defaultAppInitData = await super.getAppInitData();
return (0, spotter_utils_1.buildSpotterSidebarAppInitData)(defaultAppInitData, this.viewConfig, this.handleError.bind(this));
}
getEmbedParamsObject() {
const { worksheetId, searchOptions, disableSourceSelection, hideSourceSelection, dataPanelV2, showSpotterLimitations, hideSampleQuestions, runtimeFilters, excludeRuntimeFiltersfromURL, runtimeParameters, excludeRuntimeParametersfromURL, updatedSpotterChatPrompt, enableStopAnswerGenerationEmbed, spotterChatConfig, } = this.viewConfig;
if (!worksheetId) {
this.handleError({
errorType: types_1.ErrorDetailsTypes.VALIDATION_ERROR,
message: errors_1.ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND,
code: types_1.EmbedErrorCodes.WORKSHEET_ID_NOT_FOUND,
error: errors_1.ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND,
});
}
const queryParams = this.getBaseQueryParams();
queryParams[types_1.Param.SpotterEnabled] = true;
// Boolean params
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.DisableSourceSelection, disableSourceSelection, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.HideSourceSelection, hideSourceSelection, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.DataPanelV2Enabled, dataPanelV2, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.ShowSpotterLimitations, showSpotterLimitations, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.HideSampleQuestions, hideSampleQuestions, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.UpdatedSpotterChatPrompt, updatedSpotterChatPrompt, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.EnableStopAnswerGenerationEmbed, enableStopAnswerGenerationEmbed, true);
// Handle spotterChatConfig params
if (spotterChatConfig) {
const { hideToolResponseCardBranding, toolResponseCardBrandingLabel, } = spotterChatConfig;
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.HideToolResponseCardBranding, hideToolResponseCardBranding, true);
(0, utils_1.setParamIfDefined)(queryParams, types_1.Param.ToolResponseCardBrandingLabel, toolResponseCardBrandingLabel);
}
return queryParams;
}
getIframeSrc() {
const { worksheetId, searchOptions, runtimeFilters, excludeRuntimeFiltersfromURL, runtimeParameters, excludeRuntimeParametersfromURL, } = this.viewConfig;
const path = 'insights/conv-assist';
const queryParams = this.getEmbedParamsObject();
let query = '';
const queryParamsString = (0, utils_1.getQueryParamString)(queryParams, true);
if (queryParamsString) {
query = `?${queryParamsString}`;
}
const filterQuery = (0, utils_1.getFilterQuery)(runtimeFilters || []);
if (filterQuery && !excludeRuntimeFiltersfromURL) {
query += `&${filterQuery}`;
}
const parameterQuery = (0, utils_1.getRuntimeParameters)(runtimeParameters || []);
if (parameterQuery && !excludeRuntimeParametersfromURL) {
query += `&${parameterQuery}`;
}
const tsPostHashParams = this.getThoughtSpotPostUrlParams({
worksheet: worksheetId,
query: (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchQuery) || '',
});
return `${this.getEmbedBasePath(query)}/embed/${path}${tsPostHashParams}`;
}
async render() {
await super.render();
const src = this.getIframeSrc();
await this.renderIFrame(src);
return this;
}
}
exports.SpotterEmbed = SpotterEmbed;
/**
* Embed ThoughtSpot AI Conversation.
* Use {@link SpotterEmbed} instead
* @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl
* @deprecated from SDK: 1.39.0 | ThoughtSpot: 10.10.0.cl
* @group Embed components
* @example
* ```js
* const conversation = new SpotterEmbed('#tsEmbed', {
* worksheetId: 'worksheetId',
* searchOptions: {
* searchQuery: 'searchQuery',
* },
* });
* conversation.render();
* ```
*/
class ConversationEmbed extends SpotterEmbed {
constructor(container, viewConfig) {
viewConfig = {
embedComponentType: 'conversation',
excludeRuntimeFiltersfromURL: true,
excludeRuntimeParametersfromURL: true,
...viewConfig,
};
super(container, viewConfig);
this.viewConfig = viewConfig;
}
}
exports.ConversationEmbed = ConversationEmbed;
//# sourceMappingURL=conversation.js.map