@botonic/react
Version:
Build Chatbots using React
60 lines • 4.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAiAgentEventConfig = exports.AiAgent = 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 AiAgent = (props) => {
const { previewUtils } = (0, react_1.useContext)(context_1.WebchatContext);
// Collect all sources IDs, chunk IDs and query from all tools
const { allSourcesIds, allChunksIds, query } = (0, react_1.useMemo)(() => {
const allSourcesIds = [];
const allChunksIds = [];
let query;
props.tools_executed.forEach(tool => {
var _a;
if (((_a = tool.tool_arguments) === null || _a === void 0 ? void 0 : _a.query) &&
typeof tool.tool_arguments.query === 'string') {
query = tool.tool_arguments.query;
}
if (tool.knowledgebase_sources_ids) {
allSourcesIds.push(...tool.knowledgebase_sources_ids);
}
if (tool.knowledgebase_chunks_ids) {
allChunksIds.push(...tool.knowledgebase_chunks_ids);
}
});
return { allSourcesIds, allChunksIds, query };
}, [props.tools_executed]);
const { sources: allSources, chunks: allChunks, chunksWithSources, getIconForSourceType, } = (0, use_knowledge_base_info_1.useKnowledgeBaseInfo)({
sourceIds: allSourcesIds,
chunkIds: allChunksIds,
messageId: props.messageId,
existingChunksWithSources: props.knowledge_base_chunks_with_sources,
});
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: [query && ((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: ["\"", query, "\""] })] })), (0, jsx_runtime_1.jsx)(components_1.SourcesSection, { sources: allSources, chunks: allChunks, getIconForSourceType: getIconForSourceType, onSeeChunks: handleSeeChunks, label: constants_1.LABELS.KNOWLEDGE_GATHERED }), props.tools_executed.length > 0 && ((0, jsx_runtime_1.jsxs)(styles_1.StyledDebugDetail, { children: [(0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.EXECUTED_TOOLS }), props.tools_executed.map((tool, index) => ((0, jsx_runtime_1.jsxs)(styles_1.StyledDebugItemWithIcon, { children: [(0, jsx_runtime_1.jsx)(icons_1.ScrewdriverWrenchSvg, {}), tool.tool_name] }, `${tool.tool_name}-${index}`)))] })), props.tools_executed.length === 0 && ((0, jsx_runtime_1.jsx)(styles_1.StyledDebugDetail, { children: (0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.NO_TOOLS_EXECUTED }) })), (0, jsx_runtime_1.jsx)(components_1.GuardrailList, { keyPrefix: 'input', guardrails: props.input_guardrails_triggered }), (0, jsx_runtime_1.jsx)(components_1.GuardrailList, { keyPrefix: 'output', guardrails: props.output_guardrails_triggered, "$isLastItem": !props.exit && !props.error }), props.exit && ((0, jsx_runtime_1.jsx)(styles_1.StyledDebugDetail, { children: (0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.EXIT }) })), props.error && ((0, jsx_runtime_1.jsx)(styles_1.StyledDebugDetail, { children: (0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.ERROR }) }))] }));
};
exports.AiAgent = AiAgent;
const getAiAgentEventConfig = (data) => {
const title = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["AI Agent triggered ", (0, jsx_runtime_1.jsxs)("span", { children: ["- ", data.flow_node_content_id] })] }));
return {
action: core_1.EventAction.AiAgent,
title,
component: exports.AiAgent,
icon: (0, jsx_runtime_1.jsx)(icons_1.WandSvg, {}),
collapsible: true,
};
};
exports.getAiAgentEventConfig = getAiAgentEventConfig;
//# sourceMappingURL=ai-agent.js.map