@botonic/react
Version:
Build Chatbots using React
37 lines • 2.63 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { EventAction } from '@botonic/core';
import { useContext } from 'react';
import { WebchatContext } from '../../../webchat/context';
import { useKnowledgeBaseInfo } from '../hooks/use-knowledge-base-info';
import { CircleCheckSvg, WandSvg } from '../icons';
import { StyledDebugDetail, StyledDebugLabel, StyledDebugValue, StyledGuardrailItem, StyledGuardrailLabel, } from '../styles';
import { SourcesSection } from './components';
import { LABELS } from './constants';
export const KnowledgeBase = (props) => {
const { previewUtils } = useContext(WebchatContext);
const { sources, chunks, chunksWithSources, getIconForSourceType, hasKnowledge, isFaithful, } = 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 (_jsxs(_Fragment, { children: [_jsxs(StyledDebugDetail, { children: [_jsx(StyledDebugLabel, { children: LABELS.QUERY }), _jsxs(StyledDebugValue, { children: ["\"", props.user_input, "\""] })] }), showFailReason ? (_jsxs(StyledDebugDetail, { children: [_jsx(StyledDebugLabel, { children: LABELS.KNOWLEDGE_BASE_FAIL_REASON }), _jsx(StyledDebugValue, { children: props.knowledgebase_fail_reason })] })) : (_jsxs(_Fragment, { children: [_jsx(SourcesSection, { sources: sources, chunks: chunks, getIconForSourceType: getIconForSourceType, onSeeChunks: handleSeeChunks }), hasKnowledge && (_jsxs(StyledGuardrailItem, { children: [_jsx(CircleCheckSvg, {}), _jsx(StyledGuardrailLabel, { children: LABELS.KNOWLEDGE_FOUND })] })), isFaithful && (_jsxs(StyledGuardrailItem, Object.assign({ "$isLastItem": true }, { children: [_jsx(CircleCheckSvg, {}), _jsx(StyledGuardrailLabel, { children: LABELS.FAITHFUL_ANSWER })] })))] }))] }));
};
export const getKnowledgeBaseEventConfig = (_data) => {
const title = _jsx(_Fragment, { children: "Knowledge Base triggered" });
return {
action: EventAction.Knowledgebase,
title,
component: KnowledgeBase,
icon: _jsx(WandSvg, {}),
collapsible: true,
};
};
//# sourceMappingURL=knowledge-base.js.map