UNPKG

@botonic/react

Version:

Build Chatbots using React

42 lines 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getKnowledgeBaseEventConfig = exports.KnowledgeBase = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const core_1 = require("@botonic/core"); const react_1 = require("react"); const context_1 = require("../../../webchat/context"); const use_knowledge_base_info_1 = require("../hooks/use-knowledge-base-info"); const icons_1 = require("../icons"); const styles_1 = require("../styles"); const components_1 = require("./components"); const constants_1 = require("./constants"); const KnowledgeBase = (props) => { const { previewUtils } = (0, react_1.useContext)(context_1.WebchatContext); const { sources, chunks, chunksWithSources, getIconForSourceType, hasKnowledge, isFaithful, } = (0, use_knowledge_base_info_1.useKnowledgeBaseInfo)({ sourceIds: props.knowledgebase_sources_ids, chunkIds: props.knowledgebase_chunks_ids, messageId: props.messageId, existingChunksWithSources: props.knowledge_base_chunks_with_sources, failReason: props.knowledgebase_fail_reason, }); const showFailReason = !hasKnowledge || !isFaithful; const handleSeeChunks = () => { if (previewUtils === null || previewUtils === void 0 ? void 0 : previewUtils.onClickOpenChunks) { previewUtils.onClickOpenChunks(chunksWithSources); } }; return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(styles_1.StyledDebugDetail, { children: [(0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.QUERY }), (0, jsx_runtime_1.jsxs)(styles_1.StyledDebugValue, { children: ["\"", props.user_input, "\""] })] }), showFailReason ? ((0, jsx_runtime_1.jsxs)(styles_1.StyledDebugDetail, { children: [(0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.KNOWLEDGE_BASE_FAIL_REASON }), (0, jsx_runtime_1.jsx)(styles_1.StyledDebugValue, { children: props.knowledgebase_fail_reason })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(components_1.SourcesSection, { sources: sources, chunks: chunks, getIconForSourceType: getIconForSourceType, onSeeChunks: handleSeeChunks }), hasKnowledge && ((0, jsx_runtime_1.jsxs)(styles_1.StyledGuardrailItem, { children: [(0, jsx_runtime_1.jsx)(icons_1.CircleCheckSvg, {}), (0, jsx_runtime_1.jsx)(styles_1.StyledGuardrailLabel, { children: constants_1.LABELS.KNOWLEDGE_FOUND })] })), isFaithful && ((0, jsx_runtime_1.jsxs)(styles_1.StyledGuardrailItem, Object.assign({ "$isLastItem": true }, { children: [(0, jsx_runtime_1.jsx)(icons_1.CircleCheckSvg, {}), (0, jsx_runtime_1.jsx)(styles_1.StyledGuardrailLabel, { children: constants_1.LABELS.FAITHFUL_ANSWER })] })))] }))] })); }; exports.KnowledgeBase = KnowledgeBase; const getKnowledgeBaseEventConfig = (_data) => { const title = (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Knowledge Base triggered" }); return { action: core_1.EventAction.Knowledgebase, title, component: exports.KnowledgeBase, icon: (0, jsx_runtime_1.jsx)(icons_1.WandSvg, {}), collapsible: true, }; }; exports.getKnowledgeBaseEventConfig = getKnowledgeBaseEventConfig; //# sourceMappingURL=knowledge-base.js.map