UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

40 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowAiAgent = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("@botonic/react"); const constants_1 = require("../constants"); const content_fields_base_1 = require("./content-fields-base"); const flow_element_1 = require("./flow-element"); class FlowAiAgent extends content_fields_base_1.ContentFieldsBase { constructor() { super(...arguments); this.code = ''; this.name = ''; this.instructions = ''; this.responses = []; } static fromHubtypeCMS(component) { const newAiAgent = new FlowAiAgent(component.id); newAiAgent.name = component.content.name; newAiAgent.instructions = component.content.instructions; newAiAgent.activeTools = component.content.active_tools; return newAiAgent; } toBotonic(id) { return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: this.responses.map(response => { if (response.type === 'text') { return (0, jsx_runtime_1.jsx)(react_1.Text, { children: response.content.text }, id); } if (response.type === 'textWithButtons') { return ((0, jsx_runtime_1.jsxs)(react_1.Text, { children: [response.content.text, response.content.buttons.map((button, buttonIndex) => ((0, jsx_runtime_1.jsx)(react_1.Button, Object.assign({ payload: `do-nothing${constants_1.SOURCE_INFO_SEPARATOR}${buttonIndex}` }, { children: button }), buttonIndex)))] }, id)); } if (response.type === 'carousel') { return ((0, jsx_runtime_1.jsx)(react_1.Carousel, { children: response.content.elements.map(element => flow_element_1.FlowElement.fromAIAgent(id, element).toBotonic(id)) }, id)); } return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}); }) })); } } exports.FlowAiAgent = FlowAiAgent; //# sourceMappingURL=flow-ai-agent.js.map