@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
35 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContentsByAiAgent = void 0;
const tslib_1 = require("tslib");
const flow_ai_agent_1 = require("../content-fields/flow-ai-agent");
function getContentsByAiAgent({ cmsApi, flowBuilderPlugin, request, }) {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const startNodeAiAgentFlow = cmsApi.getStartNodeAiAgentFlow();
const isAiAgentEnabled = cmsApi.isAiAgentEnabled();
if (!startNodeAiAgentFlow || !isAiAgentEnabled) {
return [];
}
const contents = yield flowBuilderPlugin.getContentsByNode(startNodeAiAgentFlow);
const aiAgentContent = contents.find(content => content instanceof flow_ai_agent_1.FlowAiAgent);
if (!aiAgentContent) {
return [];
}
const aiAgentResponse = yield ((_a = flowBuilderPlugin.getAiAgentResponse) === null || _a === void 0 ? void 0 : _a.call(flowBuilderPlugin, request, {
name: aiAgentContent.name,
instructions: aiAgentContent.instructions,
activeTools: aiAgentContent.activeTools,
}));
if (!aiAgentResponse) {
return [];
}
if (aiAgentResponse.length === 1 && aiAgentResponse[0].type === 'exit') {
return [];
}
aiAgentContent.responses = aiAgentResponse;
return contents;
});
}
exports.getContentsByAiAgent = getContentsByAiAgent;
//# sourceMappingURL=ai-agent.js.map