@botonic/react
Version:
Build Chatbots using React
49 lines • 3.82 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 executed_tools_1 = require("./executed-tools");
const parse_tools_1 = require("./parse-tools");
const AiAgent = ({ tools_executed, input_guardrails_triggered, output_guardrails_triggered, exit, error, messageId, knowledge_base_chunks_with_sources, }) => {
const { previewUtils } = (0, react_1.useContext)(context_1.WebchatContext);
const { otherTools, allSourcesIds, allChunksIds, query } = (0, react_1.useMemo)(() => (0, parse_tools_1.parseTools)(tools_executed), [tools_executed]);
const { sources: allSources, chunks: allChunks, chunksWithSources, getIconForSourceType, } = (0, use_knowledge_base_info_1.useKnowledgeBaseInfo)({
sourceIds: allSourcesIds,
chunkIds: allChunksIds,
messageId,
existingChunksWithSources: knowledge_base_chunks_with_sources,
});
const handleSeeChunks = () => {
previewUtils?.onClickOpenChunks?.(chunksWithSources);
};
const handleSeeToolDetails = (tool) => {
const toolExecution = {
toolName: tool.tool_name,
toolArguments: tool.tool_arguments ?? {},
toolResults: tool.tool_results ?? '',
};
previewUtils?.onClickOpenToolResults?.(toolExecution);
};
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_SOURCES }), (0, jsx_runtime_1.jsx)(executed_tools_1.ExecutedTools, { tools: otherTools, onSeeToolDetails: handleSeeToolDetails }), !tools_executed.length && ((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: input_guardrails_triggered }), (0, jsx_runtime_1.jsx)(components_1.GuardrailList, { keyPrefix: 'output', guardrails: output_guardrails_triggered, "$isLastItem": !exit && !error }), exit && ((0, jsx_runtime_1.jsx)(styles_1.StyledDebugDetail, { children: (0, jsx_runtime_1.jsx)(styles_1.StyledDebugLabel, { children: constants_1.LABELS.EXIT }) })), 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