UNPKG

donobu

Version:

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

86 lines 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestsApi = void 0; const CreateTest_1 = require("../models/CreateTest"); const TestMetadata_1 = require("../models/TestMetadata"); /** * API controller for managing tests. */ class TestsApi { constructor(testsManager, flowsManager) { this.testsManager = testsManager; this.flowsManager = flowsManager; } /** * GET /api/tests — list tests with optional filtering and pagination. */ async getTests(req, res) { const query = TestMetadata_1.TestsQuerySchema.parse(req.query); const result = await this.testsManager.getTests(query); res.json({ tests: result.items, nextPageToken: result.nextPageToken }); } /** * POST /api/tests — create a new test. */ async createTest(req, res) { const params = CreateTest_1.CreateTestSchema.parse(req.body); const test = await this.testsManager.createTest(params); res.json(test); } /** * GET /api/tests/:testId — get a test by ID. */ async getTest(req, res) { const testId = String(req.params.testId); const test = await this.testsManager.getTestById(testId); res.json(test); } /** * PUT /api/tests/:testId — update an existing test. */ async updateTest(req, res) { const testId = String(req.params.testId); const testMetadata = TestMetadata_1.TestMetadataSchema.parse({ ...req.body, id: testId, }); await this.testsManager.updateTest(testMetadata); res.json(testMetadata); } /** * DELETE /api/tests/:testId — delete a test and all its flows. */ async deleteTest(req, res) { const testId = String(req.params.testId); await this.testsManager.deleteTest(testId); res.status(200).json({ deleted: true }); } /** * GET /api/tests/:testId/flows — list flows for a test. */ async getTestFlows(req, res) { const testId = String(req.params.testId); const flows = await this.flowsManager.getFlows({ testId }); res.json({ flows: flows.items, nextPageToken: flows.nextPageToken }); } /** * POST /api/tests/:testId/run — execute a test (create a new flow from it). */ async runTest(req, res) { const testId = String(req.params.testId); const newFlowConfig = await this.testsManager.getNewFlowFromTest(testId); const flowHandle = await this.flowsManager.createFlow(newFlowConfig); // After starting an autonomous run, switch the test to deterministic // so subsequent runs replay the recorded actions. if (newFlowConfig.initialRunMode === 'AUTONOMOUS') { const test = await this.testsManager.getTestById(testId); await this.testsManager.updateTest({ ...test, nextRunMode: 'DETERMINISTIC', }); } res.json(flowHandle.donobuFlow.metadata); } } exports.TestsApi = TestsApi; //# sourceMappingURL=TestsApi.js.map