UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

128 lines 4.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowsApi = void 0; const FlowMetadata_1 = require("../models/FlowMetadata"); const InvalidParamValueException_1 = require("../exceptions/InvalidParamValueException"); class FlowsApi { constructor(donobuFlowsManager) { this.donobuFlowsManager = donobuFlowsManager; } /** * Attempts to create a Node.js Microsoft Playwright script to replay the * given flow. */ async getFlowAsCode(req, res) { const flowId = req.params.flowId; const draftedPlaywrightScript = await this.donobuFlowsManager.getFlowAsPlaywrightScript(flowId); res.send({ script: draftedPlaywrightScript }); } /** * Get a given flow by ID as an appropriately formatted * {@link CreateDonobuFlow} object fit for direct replay by calling the * {@link FlowsApi.createFlow} endpoint. */ async getFlowAsRerun(req, res) { const flowId = req.params.flowId; const createDonobuFlow = await this.donobuFlowsManager.getFlowAsRerun(flowId); res.json(createDonobuFlow); } /** * Serves up flows' metadata as JSON with optional filtering. */ async getFlows(req, res) { const query = { pageToken: req.query.pageToken, limit: this.parseLimit(req.query.limit), name: req.query.name, runMode: req.query.runMode, state: req.query.state, startedAfter: req.query.startedAfter ? parseInt(req.query.startedAfter) : undefined, startedBefore: req.query.startedBefore ? parseInt(req.query.startedBefore) : undefined, }; // Validate numeric startedAfter. if (req.query.startedAfter && query.startedAfter && isNaN(query.startedAfter)) { throw new InvalidParamValueException_1.InvalidParamValueException('startedAfter', '' + req.query.startedAfter); } // Validate numeric startedBefore. if (req.query.startedBefore && query.startedBefore && isNaN(query.startedBefore)) { throw new InvalidParamValueException_1.InvalidParamValueException('startedBefore', '' + req.query.startedBefore); } // Validate that runMode is a valid enum value. if (query.runMode && !FlowMetadata_1.RunModes.includes(query.runMode)) { throw new InvalidParamValueException_1.InvalidParamValueException('runMode', query.runMode); } // Validate that state is a valid enum value. if (query.state && !FlowMetadata_1.States.includes(query.state)) { throw new InvalidParamValueException_1.InvalidParamValueException('state', query.state); } const flows = await this.donobuFlowsManager.getFlowsMetadata(query); res.json({ flows: flows.items, nextPageToken: flows.nextPageToken }); } /** * Creates a new DonobuFlow flow. */ async createFlow(req, res) { const flowParams = req.body; const flow = (await this.donobuFlowsManager.createFlow(flowParams)) .donobuFlow; res.json({ id: flow.metadata.id }); } /** * Delete a given flow by ID. */ async deleteFlow(req, res) { const flowId = req.params.flowId; await this.donobuFlowsManager.deleteFlowById(flowId); res.sendStatus(200); } async getFlowMetadata(req, res) { const flowId = req.params.flowId; const metadata = await this.donobuFlowsManager.getFlowMetadata(flowId); res.json(metadata); } /** * Pause the active flow by ID. */ async pauseFlow(req, res) { const flowId = req.params.flowId; const flow = this.donobuFlowsManager.getActiveFlow(flowId); if (!(0, FlowMetadata_1.isComplete)(flow.metadata.state)) { flow.metadata.nextState = 'PAUSED'; } res.json(flow.metadata); } /** * Resume the paused active flow by ID. */ async resumeFlow(req, res) { const flowId = req.params.flowId; const flow = this.donobuFlowsManager.getActiveFlow(flowId); if (flow.metadata.state === 'PAUSED') { flow.metadata.nextState = 'RESUMING'; } res.json(flow.metadata); } async cancelFlow(req, res) { const flowId = req.params.flowId; const metadata = await this.donobuFlowsManager.cancelFlow(flowId); res.json(metadata); } parseLimit(limit) { try { return limit ? parseInt(limit) : Number.MAX_SAFE_INTEGER; } catch { return Number.MAX_SAFE_INTEGER; } } } exports.FlowsApi = FlowsApi; //# sourceMappingURL=FlowsApi.js.map