UNPKG

@autobe/agent

Version:

AI backend server code generator

130 lines 5.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.orchestrateTest = void 0; const uuid_1 = require("uuid"); const predicateStateMessage_1 = require("../../utils/predicateStateMessage"); const orchestrateTestAuthorize_1 = require("./orchestrateTestAuthorize"); const orchestrateTestGenerate_1 = require("./orchestrateTestGenerate"); const orchestrateTestOperation_1 = require("./orchestrateTestOperation"); const orchestrateTestPrepare_1 = require("./orchestrateTestPrepare"); const orchestrateTestScenario_1 = require("./orchestrateTestScenario"); const AutoBeTestAuthorizeProgrammer_1 = require("./programmers/AutoBeTestAuthorizeProgrammer"); const AutoBeTestGenerateProgrammer_1 = require("./programmers/AutoBeTestGenerateProgrammer"); const AutoBeTestPrepareProgrammer_1 = require("./programmers/AutoBeTestPrepareProgrammer"); const orchestrateTest = (ctx) => (props) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e; // PREDICATION const start = new Date(); const predicate = (0, predicateStateMessage_1.predicateStateMessage)(ctx.state(), "test"); if (predicate !== null) return ctx.assistantMessage({ type: "assistantMessage", id: (0, uuid_1.v7)(), created_at: start.toISOString(), text: predicate, completed_at: new Date().toISOString(), }); ctx.dispatch({ type: "testStart", id: (0, uuid_1.v7)(), created_at: start.toISOString(), reason: props.instruction, step: (_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : 0, }); const document = (_c = ctx.state().interface) === null || _c === void 0 ? void 0 : _c.document; if (document === undefined) throw new Error("No document found. Please check the logs."); else if (document.operations.length === 0) return ctx.assistantMessage({ id: (0, uuid_1.v7)(), type: "assistantMessage", created_at: start.toISOString(), completed_at: new Date().toISOString(), text: "Unable to write test code because there are no Operations, " + "please check if the Interface agent is called.", }); // SCENARIO PLANNING const scenarios = yield (0, orchestrateTestScenario_1.orchestrateTestScenario)(ctx, props.instruction); if (scenarios.length === 0) throw new Error("No scenarios generated. Please check the logs."); const writeProgress = { completed: 0, total: AutoBeTestAuthorizeProgrammer_1.AutoBeTestAuthorizeProgrammer.size(document) + AutoBeTestPrepareProgrammer_1.AutoBeTestPrepareProgrammer.size(document) + AutoBeTestGenerateProgrammer_1.AutoBeTestGenerateProgrammer.size(document) + scenarios.length, }; const correctProgress = { total: 0, completed: 0, }; // AUTHORIZE const authorizes = yield (0, orchestrateTestAuthorize_1.orchestrateTestAuthorize)(ctx, { instruction: props.instruction, document, writeProgress, validateProgress: correctProgress, }); // DATA COMPOSER const prepares = yield (0, orchestrateTestPrepare_1.orchestrateTestPrepare)(ctx, { instruction: props.instruction, document, writeProgress, validateProgress: correctProgress, }); // GENERATOR FUNCTIONS (C of CRUD) const generates = yield (0, orchestrateTestGenerate_1.orchestrateTestGenerate)(ctx, { instruction: props.instruction, document, prepares, writeProgress, validateProgress: correctProgress, }); // ACTUAL TEST FUNCTION const operations = yield (0, orchestrateTestOperation_1.orchestrateTestOperation)(ctx, { instruction: props.instruction, document, scenarios, authorizes, prepares, generates, writeProgress, validateProgress: correctProgress, }); // FINALIZE WITH COMPILATION const compiler = yield ctx.compiler(); const functions = [ ...authorizes, ...prepares, ...generates, ...operations, ]; return ctx.dispatch({ type: "testComplete", id: (0, uuid_1.v7)(), functions, compiled: yield compiler.typescript.compile({ files: Object.fromEntries([ ...Object.entries(yield ctx.files({ dbms: "sqlite", })).filter(([key]) => key.endsWith(".ts") && key.startsWith("test/features") === false), ...functions.map((f) => [f.location, f.content]), ]), }), aggregates: ctx.getCurrentAggregates("test"), step: (_e = (_d = ctx.state().analyze) === null || _d === void 0 ? void 0 : _d.step) !== null && _e !== void 0 ? _e : 0, elapsed: new Date().getTime() - start.getTime(), created_at: new Date().toISOString(), }); }); exports.orchestrateTest = orchestrateTest; //# sourceMappingURL=orchestrateTest.js.map