UNPKG

@botonic/plugin-flow-builder

Version:

Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.

69 lines 3.87 kB
import { __awaiter, __rest } from "tslib"; import { AiAgentType, EventAction, } from '@botonic/shared'; import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking'; import { getFlowBuilderPlugin } from '../utils'; import { FlowAiAgentBase } from './flow-ai-agent-base'; export class FlowAiAgent extends FlowAiAgentBase { constructor() { super(...arguments); this.activeTools = []; this.sources = []; } static fromHubtypeCMS(component) { const newAiAgent = new FlowAiAgent(component.id); newAiAgent.code = component.code; newAiAgent.name = component.content.name; newAiAgent.model = component.content.model; newAiAgent.verbosity = component.content.verbosity; newAiAgent.instructions = component.content.instructions; newAiAgent.activeTools = component.content.active_tools; newAiAgent.inputGuardrailRules = component.content.input_guardrail_rules || []; newAiAgent.sources = component.content.sources; newAiAgent.followUp = component.follow_up; return newAiAgent; } getAIAgentResponse(botonicContext, previousContents) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const flowBuilderPlugin = getFlowBuilderPlugin(botonicContext.plugins); const aiAgentResponse = yield ((_a = flowBuilderPlugin.getAiAgentResponse) === null || _a === void 0 ? void 0 : _a.call(flowBuilderPlugin, botonicContext, { type: AiAgentType.Specialist, name: this.name, instructions: this.instructions, model: this.model, verbosity: this.verbosity, activeTools: this.activeTools, inputGuardrailRules: this.getActiveInputGuardrailRules(this.inputGuardrailRules), sourceIds: (_b = this.sources) === null || _b === void 0 ? void 0 : _b.map(source => source.id), previousHubtypeMessages: this.getPreviousHubtypeContents(previousContents), })); return aiAgentResponse; }); } trackAiAgentResponse(botonicContext) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const { flowThreadId, flowId, flowName, flowNodeId } = yield getCommonFlowContentEventArgsForContentId(botonicContext, this.id); const event = { action: EventAction.AiAgent, flowThreadId: flowThreadId, flowId: flowId, flowName: flowName, flowNodeId: flowNodeId, flowNodeContentId: this.name, flowNodeIsMeaningful: true, toolsExecuted: (_b = (_a = this.aiAgentResponse) === null || _a === void 0 ? void 0 : _a.toolsExecuted) !== null && _b !== void 0 ? _b : [], memoryLength: (_d = (_c = this.aiAgentResponse) === null || _c === void 0 ? void 0 : _c.memoryLength) !== null && _d !== void 0 ? _d : 0, inputMessageId: botonicContext.input.dbId, exit: (_f = (_e = this.aiAgentResponse) === null || _e === void 0 ? void 0 : _e.exit) !== null && _f !== void 0 ? _f : true, inputGuardrailsTriggered: (_h = (_g = this.aiAgentResponse) === null || _g === void 0 ? void 0 : _g.inputGuardrailsTriggered) !== null && _h !== void 0 ? _h : [], outputGuardrailsTriggered: [], error: (_k = (_j = this.aiAgentResponse) === null || _j === void 0 ? void 0 : _j.error) !== null && _k !== void 0 ? _k : false, }; const { action } = event, eventArgs = __rest(event, ["action"]); yield trackEvent(botonicContext, action, eventArgs); }); } } //# sourceMappingURL=flow-ai-agent.js.map